Starting a basic file setup, anyway to get this cleaner?

I’m trying to make a template that I can use for every website.
Is there any way I can get this cleaner?
Or is this done correctly?

<?php
$config                         = array();
// Put this in 'config.inc.php'
$config['lang']                 = "en";
$config['en']['title']          = "Website Title";
$config['en']['description']    = "Website Description";
$config['en']['keywords']       = "Website 1, Website 2";
$config['en']['author']         = "Name ([email protected])";
$config['sp']['title']          = "Título De La Página";
$config['sp']['description']    = "Descripcion del Sitio Web";
$config['sp']['keywords']       = "Sitio Web 1, Sitio Web 2";
$config['sp']['author']         = "Nombre ([email protected])";
$config['ar']['title']          = "عنوان الموقع";
$config['ar']['description']    = "وصف الموقع";
$config['ar']['keywords']       = "موقع الكتروني 1, موقع الكتروني 2";
$config['ar']['author']         = "اسم ([email protected])";
$config['ch']['title']          = "网站标题";
$config['ch']['description']    = "网站说明";
$config['ch']['keywords']       = "网站1, 网站2";
$config['ch']['author']         = "姓名 ([email protected])";


// Put this in 'CowPocalypse.class.php' 
class CowPocalypse {
	private function getConfig($q){
	  global $config;
	  $l = $config['lang'];
	  $x = $config[$l][$q];
	  return $x;
	}
    public function config($q){
      return $this->getConfig($q);
    }
    public function xCSSJS($d,$f,$t){
      $dirs   = $d;
      $file   = $f;
      if (file_exists($dirs) === true){
        if(is_dir($dirs)){
          $data = true;
        }else{
          $data = false;
        }
      }
      else{
        $data = false;
      }
      if (!$data){
        mkdir($dirs, 0777);
      }
      switch($t){
	    case "a":
        $return = "    <!-- Loading CSS Files -->\r\n";
        break;
	    case "b":
        $return = "    <!-- Loading JS Files -->\r\n";
	    break;
      }
      $files  = scandir($dirs, SCANDIR_SORT_ASCENDING);
      foreach ($files as $x){
        if (strpos($x, $file) !== false){
	      switch ($t){
            case "a":
            $return .= "    <link href=\"".$x."\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />\r\n";
	    	break;
    		case "b":
		    $return .= "    <script type=\"application/javascript\" language=\"javascript\" src=\"".$x."\"></script>\r\n";
	    	break;
    	  }
        }
      }
      unset($x); unset($dirs); unset($files); unset($data);
      if (!$return){
  	    $return = "    <!-- No Files Loaded -->\r\n";
      }
      return $return;
    }
}

// 'index.php' file
$cow = new CowPocalypse();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?=$cow->config("title");?></title>
    <meta name="description" content="<?=$cow->config("description");?>" />
    <meta name="keywords" content="<?=$cow->config("keywords");?>" />
    <meta name="author" content="<?=$cow->config("author");?>" />
<?php
echo $cow->xCSSJS("css", "css", "a");
echo $cow->xCSSJS("js", "js", "b");
?>
  </head>
  <body>
    Something
  </body>
</html>

Don’t know exactly what you’re trying to do and Arabic, Chinese and ? isn’t helping. Sorry though I would say no you aren’t doing this correctly. 🤷. Though using JSON my help you. Here’s an example →

$jsonString = file_get_contents('data.json');
$jsonData = json_decode($jsonString, true);

// Convert the PHP array back to a JSON string with pretty print
$prettyJsonData = json_encode($jsonData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

that is just an example and I don't think you would need to use a class if you did it that way?

I would also recommend going with json files. This is the simplest option as well.

Are you looking for a simple system with basic categories, or do you need a more elaborate setup with subfolders, tags, or metadata?

You can extend these functions to support features like setting default values, validating theme settings, or loading/saving themes from files.

Sponsor our Newsletter | Privacy Policy | Terms of Service