Location: PHPKode > projects > Mac's MVC Framework > Application/Config.php
<?php
  /**
   * This class extends the MainConfig class and allows the developer to change config settings, without modifying the core
   *
   * @author Macdonald Terrence Robinson
   * @package Core
   *
   */

  require_once 'core/statics/MainConfig.php';

  class Config extends MainConfig
  {
    //Temp directory configuration
    public static $writableDir = 'writable';
    public static $cacheDir = 'writable/cache';
    public static $editInPlaceDir = 'writable/editInPlace';
    
    //Change this to your own controller name
    public static $defaultTemplate = 'blue_spring';
    public static $siteName = 'Mac\'s CMS';
    
    //All links that are generated by the framework will contain an index.php in the URL if this is set to true.
    //This is done because on some servers the .htaccess file is disallowed or the mod_rewrite module is
    //not installed or disabled
    public static $appendIndexPhpToURL = true;
    
    //Enable or Disable the CMS Feature, This is useful if you only want to use the MVC framework and not the CMS.
    //It goes without saying that disabling this will increase performance since the framework does not load the CMS plugin
    public static $enableEditInPlace = true;
    //Edit in place Admin login
    public static $editInPlaceAdmins = array();

    //Site Offline settings
    public static $isSiteOffline = false;
    public static $offlineFunctionName = 'siteOffline';


    //This name corresponds to the name of a folder in the views/contents directory
    public static $siteLanguage = 'english';
    
    //This setting tells the framework to connect to the DB automaticly
    public static $dbConnect = true;
    
    //Connect to MYSQL
    /*public static $dbSettings = array('dbType' => 'mysql',
                               'dbHost'=>'localhost',
                               'dbUser'=>'root',
                               'dbPassword'=>'',
                               'dbName'=>'test');*/

    //Connect to SQLite
    //IMPORTANT: Move the DB file above the webroot directory and change this setting when moving to production or lock the writable/db/ folder using .htaccess
    public static $dbSettings = array('dbType' => 'sqlite',
                               'connectionString'=> 'writable/db/macs-framework.db3');

    //Connect to MSSQL using ODBC
    /*public static $dbSettings = array('dbType' => 'odbc',
                               'connectionString'=> 'Driver={SQL Server};Server=HOME\SQLEXPRESS;Database=master',
                               'dbUser'=>'sa',
                               'dbPassword'=>'password');*/
                               
    //Connect MSAccess Using ODBC
    /*public static $dbSettings = array('dbType' => 'odbc',
                               'connectionString'=> 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;');*/

                               

    //Assigns a Friendly Key which redirects to a 'controller/function'
    public static $routingRules = array('products' => 'main/crawler');

    //Set the Error display and level
    public static $displayErrors = true;

    //Show how long the framework took to execute
    public static $showExecutionTime = true;
    
    //Turn on/off caching
    public static $enableCaching = false;
    
    //Duration for the Cache file, in seconds
    public static $cacheDuration = 31556926; //1 year!
    
    /*
      Set the 'controller(s)/function(s)' that you dont wan't caching for
      Usually these are pages that have form elements or are generated using info from the DB
      This will only be in effect if 'enableCaching' is turned on
    */
    public static $disableCaching = array('main/chat', 'main/formstate', 'main/cms', 'main/crawler', 'main/snippets', 'main/search');

    // Turns on auto XSS filter for the framework
    public static $enableAutoXSSFilter = true;
    // NOTE: Be careful with this setting, if you add keys which have large arrays associated with them for example _SERVER you will notice a huge performance hit
    public static $globalKeysToFilter = array('_POST', '_GET');
    
    public static $charset = 'ISO-8859-1';

    public static $showHomePageInMainMenu = true;

    public static $customConfigs = array();

    public static function init()
    {
      if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
      @date_default_timezone_set(@date_default_timezone_get());

      ini_set('display_errors', self::$displayErrors);
      error_reporting(E_ALL | E_STRICT);
      //error_reporting(E_ALL);

      self::autoDetectSiteDir();
      self::autoDetectSiteURL();

      self::$coreDir = self::$coreDir.self::$directorySeperator;
      self::$libsDir = self::$libsDir.self::$directorySeperator;
      self::$controllersDir = self::$controllersDir.self::$directorySeperator;
      self::$viewsDir = self::$viewsDir.self::$directorySeperator;
      self::$templatesDir = self::$templatesDir.self::$directorySeperator;
      self::$contentsDir = self::$contentsDir.self::$directorySeperator;
      self::$modelsDir = self::$modelsDir.self::$directorySeperator;
      self::$pluginsDir = self::$pluginsDir.self::$directorySeperator;
      self::$snippetsDir = self::$snippetsDir.self::$directorySeperator;
      self::$writableDir = self::$writableDir.self::$directorySeperator;     
      self::$cacheDir = self::$cacheDir.self::$directorySeperator;
      self::$editInPlaceDir = self::$editInPlaceDir.self::$directorySeperator;
      self::$mainContentsDir = self::$mainContentsDir.self::$directorySeperator;
      self::$contentBucketsDir = self::$contentBucketsDir.self::$directorySeperator;
      
      self::$configXML = self::$writableDir.'config'.self::$directorySeperator.self::$configXML;
      self::$siteMapXML = self::$writableDir.'config'.self::$directorySeperator.self::$siteMapXML;

      self::$siteLanguage = strtolower(self::$siteLanguage);

      if(!stristr(self::$siteEmailAddress, '@') )
      {
        $seg = parse_url(self::$siteURL);
        self::$customConfigs['commentsModeratorEmailAddress'] = self::$siteEmailAddress = self::$siteEmailAddress.'@'.$seg['host'];
      }

      if(self::$siteEmailName == '')
        self::$siteEmailName = self::$siteName;
    }

    public static function setLanguage($newLanguage)
    {      
      self::$siteLanguage = strtolower($newLanguage);
      Session::set('lang', self::$siteLanguage);
    }

    public static function getLanguagePath($language, $default = false)
    {
      $contentsDir = self::$contentsDir;

      if($default)
      {
        $defaults = get_class_vars('Config');
        $contentsDir = $defaults['contentsDir'].self::$directorySeperator;
      }

      $path = $contentsDir.$language.self::$directorySeperator;
      return $path;
    }

    private static function loadConfigXML()
    {
      if( !FileSystem::fileExists(self::$configXML) )
        return;

      $xmlContent = file_get_contents(self::$configXML);

      return XML::loadString($xmlContent);
    }

    public static function loadCustomConfig()
    {
      $customConfigSettings = self::loadConfigXML();

      if( isset($customConfigSettings->languages) )
      {
        self::$siteLanguages = array();

        foreach ($customConfigSettings->languages->children() as $key=>$value)
          self::$siteLanguages[] = (string)$value;
      }

      if( isset($customConfigSettings->configSettings) )
      {
        foreach ($customConfigSettings->configSettings->children() as $key=>$value)
        {
          switch($value['key'])
          {
            case 'siteLanguage':
              self::$defaultSiteLanguage = (string)$value['value'];

              if( !Session::isExists('lang') )
                self::setLanguage( (string)$value['value'] );
            break;
            default:
              if( isset(self::$$value['key']) )
                self::$$value['key'] = (string)$value['value'];
              else
                self::$customConfigs[(string)$value['key']] = (string)$value['value'];
            break;
          }
        }
      }
    }

    private static function saveCustomConfigSetting($customConfigSettingsNode, $key, $value)
    {
      XML::addNode($customConfigSettingsNode, 'config', '', array('key'=>$key, 'value'=>$value ));
    }

    private static function saveCustomLanguagesSetting($customLanguagesSettingsNode, $language)
    {
      XML::addNode($customLanguagesSettingsNode, 'language', $language);
    }

    public static function saveCustomConfig()
    {
      if( !FileSystem::fileExists(parent::$configXML) )
      {
        $configXML = '
        <site>
          <languages>
            <language>english</language>
          </languages>
        </site>
        ';
        $xmlObject = XML::loadString($configXML);
        XML::save($xmlObject, self::$configXML, false, 0777);
      }

      $customConfigSettings = XML::load(parent::$configXML, false);

      if( isset($customConfigSettings->languages) )
        XML::delete($customConfigSettings->languages);

      $customLanguagesSettingsNode = $customConfigSettings->addChild('languages');

      foreach(parent::$siteLanguages as $language)
        self::saveCustomLanguagesSetting($customLanguagesSettingsNode, $language);

      if( isset($customConfigSettings->configSettings) )
        XML::delete($customConfigSettings->configSettings);

      $customConfigSettingsNode = $customConfigSettings->addChild('configSettings');

      $configs = get_class_vars('Config');

      foreach($configs as $key=>$value)
      {
        if( isset(Config::$$key ) &&  is_string($value) && trim($value) !='' && (!isset(MainConfig::$$key) ) )
          self::saveCustomConfigSetting($customConfigSettingsNode, $key, self::$$key);
        else if( $key === 'customConfigs' )
        {
          foreach( $value as $customKey=>$customVal )
            self::saveCustomConfigSetting($customConfigSettingsNode, $customKey, $customVal);
        }
      }

      XML::save($customConfigSettings, self::$configXML, false, 0777);
    }

    public static function getProtocol()
    {
      if(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on'))
        $protocol = 'https';
      else
        $protocol = 'http';

      return $protocol;
    }

    public static function autoDetectSiteDir()
    {
      self::$siteDir = str_replace('\\', '/', getcwd().self::$directorySeperator);
    }

    public static function autoDetectSiteURL()
    {
      $scriptPath = '';
      if(isset($_SERVER['SCRIPT_NAME']))
      {
        $scriptPath = $_SERVER['SCRIPT_NAME'];
        $scriptPath = str_replace('/index.php', '', $scriptPath);
      }
      if(($scriptPath === '/') || ($scriptPath === '//'))
        $scriptPath = '';

      self::$protocol = self::getProtocol();
      self::$siteURL = self::$protocol.'://'.$_SERVER['HTTP_HOST'].$scriptPath.'/';
    }
  }
?>
Return current item: Mac's MVC Framework