Source for file ConfigurationModel.php
Documentation is available at ConfigurationModel.php
* ConfigurationModel class
* @author Felix Rupp <kontakt@felixrupp.com>
* @copyright Copyright (c) 2011, Felix Rupp, Nicole Reinhardt
* @license http://www.opensource.org/licenses/mit-license.php MIT-License
* @license http://www.gnu.org/licenses/gpl.html GNU GPL
* @var ConfigurationModel $_configurator Contains single instance of our ConfigurationModel
* @staticvar $_configurator
private static $_configurator =
NULL;
* @var SimpleXMLExtended $_configFile Contains the SimpleXMLExtended of our xml-configfile
* @var SimpleXMLExtended $_adminConfigFile Contains the SimpleXMLExtended of our admin configfile
private $_adminConfigFile;
* @var SimpleXMLExtended $_adminLangFile Contains the SimpleXMLExtended of our xml-languagefile for admin
* @var string $_backendLang Contains iso language-code of the backend language
* @var array $_backendLangugeData Contains SimpleXMLExtended object with backend language data
private $_backendLangugeData;
* @var array $_allBackendLanguages Contains an array with alle existing backend languages
private $_allBackendLanguages;
* @var array $_isoLangCodes Contains all ISO language codes and respective language names
private $_isoLangCodes =
array(
'bo' =>
'Tibetan Standard, Tibetan, Central',
'ca' =>
'Catalan; Valencian',
'cu' =>
'Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic',
'dv' =>
'Divehi; Dhivehi; Maldivian;',
'es' =>
'Spanish; Castilian',
'ff' =>
'Fula; Fulah; Pulaar; Pular',
'fy' =>
'Western Frisian',
'gd' =>
'Scottish Gaelic; Gaelic',
'he' =>
'Hebrew (modern)',
'ht' =>
'Haitian; Haitian Creole',
'ki' =>
'Kikuyu, Gikuyu',
'kj' =>
'Kwanyama, Kuanyama',
'kl' =>
'Kalaallisut, Greenlandic',
'ky' =>
'Kirghiz, Kyrgyz',
'lb' =>
'Luxembourgish, Letzeburgesch',
'li' =>
'Limburgish, Limburgan, Limburger',
'mr' =>
'Marathi (Mara?hi)',
'nb' =>
'Norwegian Bokmål',
'nn' =>
'Norwegian Nynorsk',
'nv' =>
'Navajo, Navaho',
'ny' =>
'Chichewa; Chewa; Nyanja',
'oj' =>
'Ojibwe, Ojibwa',
'os' =>
'Ossetian, Ossetic',
'pa' =>
'Panjabi, Punjabi',
'ps' =>
'Pashto, Pushto',
'ro' =>
'Romanian, Moldavian, Moldovan',
'sa' =>
'Sanskrit (Sa?sk?ta)',
'si' =>
'Sinhala, Sinhalese',
'st' =>
'Southern Sotho',
'to' =>
'Tonga (Tonga Islands)',
'ug' =>
'Uighur, Uyghur',
'za' =>
'Zhuang, Chuang',
* Configurator class-constructor
private function ConfigurationModel() {
$this->reloadConfigFile();
$this->reloadAdminConfigFile();
$this->reloadAdminLangFile();
$this->_backendLang =
$this->getAdminConfigString("BACKEND_LANGUAGE");
$this->_backendLangugeData =
$this->getBackendLanguage($this->_backendLang);
$this->_allBackendLanguages =
$this->getAllBackendLanguages();
} // End of constructor declaration
* Singleton-create-method
* @return ConfigurationModel Single instance of ConfigurationModel
if (self::$_configurator ===
NULL) {
self::$_configurator =
new self();
return self::$_configurator;
} // End of method declaration
* Overwrite __clone() method to prevent instance-cloning
private function __clone() {
* This method returns an ordered array with all global settings
* @return Array with all global settings
$configArray =
$this->getConfig($this->_configFile);
$languageArray =
array();
foreach($this->_backendLangugeData as $xmlNode) {
$languageArray[(string)
$xmlNode["key"]] = (string)
$xmlNode;
foreach($configArray as $node) {
$globals[strtolower((string)
$node["key"])] =
array("label" =>
$languageArray[(string)
$node["key"]], "value" =>
stripslashes((string)
$node), "type" => (string)
$node["type"], "blank" => (string)
$node["blank"], "validate" => (string)
$node["validate"]);
# Provide languages for default frontend language
foreach($this->_isoLangCodes as $langCode =>
$langValue) {
$globals["default_language"]["acceptedValues"][$langCode] =
$langValue;
# Set Robot and navigation active marker positions
$globals["robots"]["acceptedValues"] =
array("index,follow"=>
"index,follow", "index,nofollow"=>
"index,nofollow", "noindex,follow"=>
"noindex,follow", "noindex,nofollow"=>
"noindex,nofollow");
$globals["navigation_active_marker_position"]["acceptedValues"] =
array("disabled"=>
"disabled", "before"=>
"before", "after"=>
"after");
# Remove template settings:
if(isset
($globals["template"])) {unset
($globals["template"]);}
"website_title" => array("label" => "Global website-title:", "value" => stripslashes($this->getConfigString("WEBSITE_TITLE")), "blank" => false),
"website_title_seperator" => array("label" => "Website-title seperator:", "value" => stripslashes($this->getConfigString("WEBSITE_TITLE_SEPERATOR")), "blank" => false),
"startpage" => array("label" => "Homepage:", "value" => stripslashes($this->getConfigString("STARTPAGE")), "acceptedValues" => array(), "blank" => false),
"base" => array("label" => "Basepath:", "value" => stripslashes($this->getConfigString("BASE")), "blank" => false),
"robots" => array("label" => "Robot settings:", "value" => stripslashes($this->getConfigString("ROBOTS")), "acceptedValues" => array(), "blank" => false),
"speaking_urls" => array("label" => "Speaking URLs:", "value" => stripslashes($this->getConfigString("SPEAKING_URLS")), "blank" => false),
"navigation_active_marker_position" => array("label" => "Position of active-navigation-marker:", "value" => stripslashes($this->getConfigString("NAVIGATION_ACTIVE_MARKER_POSITION")), "blank" => false),
"navigation_active_marker" => array("label" => "Marker for active-navigation:", "value" => stripslashes($this->getConfigString("NAVIGATION_ACTIVE_MARKER")), "blank" => true),
"navigation_active_class" => array("label" => "Class for active-navigation links:", "value" => stripslashes($this->getConfigString("NAVIGATION_ACTIVE_CLASS")), "blank" => true),
"navigation_class" => array("label" => "Navigation class:", "value" => stripslashes($this->getConfigString("NAVIGATION_CLASS")), "blank" => true),
"language_selector_in_footer" => array("label" => "Language selector in footer:", "value" => stripslashes($this->getConfigString("LANGUAGE_SELECTOR_IN_FOOTER")), "blank" => false),
"language_selector_seperator" => array("label" => "Language selector seperator:", "value" => stripslashes($this->getConfigString("LANGUAGE_SELECTOR_SEPERATOR")), "blank" => false),
"default_language" => array("label" => "Default language for frontend:", "value" => stripslashes($this->getConfigString("DEFAULT_LANGUAGE")), "blank" => false),
} // End of method declaration
* Method to save global config
* @param array $globals Array that contains all global settings
* @throws CaramelException
foreach($globals as $key =>
$valueArray) {
$result =
$this->setConfigString($key, $valueArray);
} // End of method declaration
* Method to return the base admin login information
* @throws CaramelException
* @return Simple array with admin login info to check while logging in
$loginInformation =
array();
$loginInformation["username"] =
$this->getAdminConfigString("ADMIN_USERNAME");
$loginInformation["password"] =
$this->getAdminConfigString("ADMIN_PASSWORD");
$loginInformation["email"] =
$this->getAdminConfigString("ADMIN_EMAIL");
return $loginInformation;
} // End of method declaration
* This method returns an ordered array with all admin settings
* @param string $lang Language to fetch options for
* @throws CaramelException
* @return Array with all admin settings
$adminConfigArray =
$this->getConfig($this->_adminConfigFile);
$languageArray =
array();
foreach($this->_backendLangugeData as $xmlNode) {
$languageArray[(string)
$xmlNode["key"]] = (string)
$xmlNode;
foreach($adminConfigArray as $node) {
$admin[strtolower((string)
$node["key"])] =
array("label" =>
$languageArray[(string)
$node["key"]], "value" =>
stripslashes((string)
$node), "type" => (string)
$node["type"], "blank" => (string)
$node["blank"], "validate" => (string)
$node["validate"]);
$admin["admin_password"]["value"] =
"";
# Provide all language which are in our lang_admin.xml file for html select-tag:
$admin["backend_language"]["acceptedValues"] =
array();
foreach($this->_allBackendLanguages as $langCode) {
$admin["backend_language"]["acceptedValues"][$langCode] =
$this->_isoLangCodes[$langCode];
} // End of method declaration
* Method to save admin config
* @param array $globals Array that contains all admin settings
* @throws CaramelException
* @return Result of file_put_contents
foreach($admin as $key =>
$valueArray) {
$result =
$this->setAdminConfigString($key, $valueArray);
} // End of method declaration
* Method to get current active template
* @throws CaramelException
* @return The current template set in template settings
return $this->getConfigString("TEMPLATE");
} // End of method declaration
* Method to set new template file for frontend
* @param string $newTemplate New template to set
* @throws CaramelException
* @return Result of file_put_contents
$this->setConfigString("TEMPLATE", $newTemplate);
} // End of method declaration
* Wrapper for getConfigString
* @param string $key Key to lookup in config-file
* @throws CaramelException
* @return string Value for given key
return $this->getConfigString($key);
} // End of method declaration
* Wrapper for getAdminConfigString
* @see getAdminConfigString
* @param string $key Key to lookup in config-file
* @throws CaramelException
* @return string Value for given key
return $this->getAdminConfigString($key);
} // End of method declaration
* Wrapper for getBackendLanguagestring
* @see getBackendLanguagestring
* @param string $key Key to lookup in config-file
* @throws CaramelException
* @return Value for given key
return $this->getBackendLanguageString($this->_backendLang, $key);
} // End of method declaration
############################################################################
############################################################################
* Get full config from passed config file
* @throws CaramelException
* @return SimpleXMLExtended node mathing the $key
private function getConfig($configFile) {
$setting =
$configFile->xpath('setting');
} // End of method declaration
* Get String from key of config-file
* @param string $key Key to lookup in config-file
* @throws CaramelException
* @return Value for given key
private function getConfigString($key) {
$setting =
$this->_configFile->xpath('//setting[@key="'.
$key.
'"]');
return (string)
$setting[0];
} // End of method declaration
* Set String from key of config-file
* @param string $key Key of the setting to change
* @param string $newValue New value for the setting
* @throws CaramelException
* @return Result of file_put_contents
private function setConfigString($key, $newValue) {
$setting =
$this->_configFile->xpath('//setting[@key="'.
$key.
'"]');
$setting[0][0]->addCData($newValue);
} // End of method declaration
* Get String from key of admin configfile
* @param string $key Key to lookup in config-file
* @throws CaramelException
* @return Value for given key
private function getAdminConfigString($key) {
$setting =
$this->_adminConfigFile->xpath('//setting[@key="'.
$key.
'"]');
return (string)
$setting[0];
} // End of method declaration
* Set String from key of admin config-file
* @param string $key Key of the setting to change
* @param string $newValue New value for the setting
* @throws CaramelException
* @return Result of file_put_contents
private function setAdminConfigString($key, $newValue) {
$setting =
$this->_adminConfigFile->xpath('//setting[@key="'.
$key.
'"]');
$setting[0][0]->addCData($newValue);
} // End of method declaration
* Get string from backend languagefile
* @param string $lang The language to fetch the string for
* @param string $key The key of the language setting
* @throws CaramelException
* @return Value mathing the $lang and the $key
private function getBackendLanguageString($lang, $key) {
$setting =
$this->_adminLangFile->xpath('//lang[@code="'.
$lang.
'"]/setting[@key="'.
$key.
'"]');
return (string)
$setting[0];
} // End of method declaration
* Get string from backend languagefile
* @param string $lang The language to fetch the string for
* @throws CaramelException
* @return Value mathing the $lang and the $key
private function getBackendLanguage($lang) {
$setting =
$this->_adminLangFile->xpath('//lang[@code="'.
$lang.
'"]/setting');
} // End of method declaration
* Get all languages in lang file
* @throws CaramelException
* @return Value mathing the $lang and the $key
private function getAllBackendLanguages() {
$setting =
$this->_adminLangFile->xpath('//@code');
foreach($setting as $langCode) {
array_push($allLanguages, (string)
$langCode); # Convert SimpleXMLElements into strings
} // End of method declaration
* This method updates the contents of the local configFile in our singleton.
* @throws CaramelException
private function reloadConfigFile() {
} // End of method declaration
* This method updates the contents of the local adminConfigFile in our singleton.
* @throws CaramelException
private function reloadAdminConfigFile() {
} // End of method declaration
* This method updates the contents of the local langFile in our singleton.
* @throws CaramelException
private function reloadAdminLangFile() {
} // End of method declaration