diff --git a/config/dmsDefaults.php b/config/dmsDefaults.php index 7bcf9c6..892d665 100644 --- a/config/dmsDefaults.php +++ b/config/dmsDefaults.php @@ -455,36 +455,19 @@ class KTInit { // TODO: refactor when all the config settings are stored in the database // Check for the config cache $use_cache = false; - $store_cache = false; - $cachePathFile = KT_DIR . '/config/cache-path'; - if (file_exists($cachePathFile)) { - $store_cache = true; - // Get the path to the config cache - $cachePath = trim(file_get_contents($cachePathFile)); - $cachePath .= '/configcache'; - - $cachePath = (!KTUtil::isAbsolutePath($cachePath)) ? sprintf('%s/%s', KT_DIR, $cachePath) : $cachePath; - - // Get the path to the config file - $configPathFile = KT_DIR . '/config/config-path'; - $configPath = trim(file_get_contents($configPathFile)); - - $configPath = (!KTUtil::isAbsolutePath($configPath)) ? sprintf('%s/%s', KT_DIR, $configPath) : $configPath; - - // Remove any double slashes - $configPath = str_replace('//', '/', $configPath); - $configPath = str_replace('\\\\', '\\', $configPath); + $store_cache = true; + $cachePath = $oKTConfig->getCacheFilename(); + if (file_exists($cachePath)) { + $configPath = $oKTConfig->getConfigFilename(); // This check can be removed once all config settings are in the database // Check if the config file has been updated since the last time the cache file was generated. - if (file_exists($cachePath)) { - $cachestat = stat($cachePath); - $configstat = stat($configPath); - $tval = 9; - if ($cachestat[$tval] > $configstat[$tval]) { - $use_cache = true; - $store_cache = false; - } + $cachestat = stat($cachePath); + $configstat = stat($configPath); + $tval = 9; + if ($cachestat[$tval] > $configstat[$tval]) { + $use_cache = true; + $store_cache = false; } if ($use_cache) { diff --git a/lib/config/config.inc.php b/lib/config/config.inc.php index 9fef648..c9d9339 100644 --- a/lib/config/config.inc.php +++ b/lib/config/config.inc.php @@ -49,8 +49,36 @@ class KTConfig { var $expanded = array(); var $expanding = array(); + /** + * Get the path to the cache file for the config settings + * + * @return string + */ + static function getCacheFilename() + { + $pathFile = KT_DIR . '/config/cache-path'; + + if(!file_exists($pathFile)){ + return false; + } + + // Get the directory containing the file, append the file name + $cacheFile = trim(file_get_contents($pathFile)); + $cacheFile .= '/configcache'; + + // Ensure path is absolute + $cacheFile = (!KTUtil::isAbsolutePath($cacheFile)) ? sprintf('%s/%s', KT_DIR, $cacheFile) : $cacheFile; + + return $cacheFile; + } + // FIXME nbm: how do we cache errors here? - function loadCache($filename) { + function loadCache() { + $filename = $this->getCacheFilename(); + if($filename === false){ + return false; + } + $config_str = file_get_contents($filename); $config_cache = unserialize($config_str); $this->flat = $config_cache['flat']; @@ -60,7 +88,9 @@ class KTConfig { return true; } - function createCache($filename) { + function createCache() { + $filename = $this->getCacheFilename(); + $config_cache = array(); $config_cache['flat'] = $this->flat; $config_cache['flatns'] = $this->flatns; @@ -70,6 +100,19 @@ class KTConfig { file_put_contents($filename, serialize($config_cache)); } + /** + * Delete the cache so it can be refreshed on the next page load + * + * @param string $filename + */ + function clearCache() + { + $filename = $this->getCacheFilename(); + if($filename !== false && file_exists($filename)){ + @unlink($filename); + } + } + // {{{ readConfig function readConfig () { global $default; @@ -236,15 +279,22 @@ class KTConfig { */ static function getConfigFilename() { - $configPath = file_get_contents(KT_DIR . '/config/config-path'); + $pathFile = KT_DIR . '/config/config-path'; + $configFile = trim(file_get_contents($pathFile)); + + $configFile = (!KTUtil::isAbsolutePath($configFile)) ? sprintf('%s/%s', KT_DIR, $configFile) : $configFile; + + // Remove any double slashes + $configFile = str_replace('//', '/', $configFile); + $configFile = str_replace('\\\\', '\\', $configFile); - if (is_file($configPath)) + if (file_exists($configFile)) { - return $configPath; + return $configFile; } else { - return KT_DIR . '/' . $configPath; + return KT_DIR . DIRECTORY_SEPARATOR . $configFile; } } diff --git a/plugins/ktcore/admin/configSettings.php b/plugins/ktcore/admin/configSettings.php index 8f3f737..c1abc91 100644 --- a/plugins/ktcore/admin/configSettings.php +++ b/plugins/ktcore/admin/configSettings.php @@ -1,240 +1,243 @@ -. - * - * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, - * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): ______________________________________ - * - */ - -require_once(KT_LIB_DIR . '/dispatcher.inc.php'); -require_once(KT_LIB_DIR . '/templating/templating.inc.php'); - -class BaseConfigDispatcher extends KTAdminDispatcher -{ - function check() { - return parent::check(); - } - - function do_main($sQuery) - { - if(empty($sQuery)) - { - $sQuery = ''; - } - $aResults = DBUtil::getResultArray($sQuery); - - //populating paths correctly - $oKTConfig =& KTConfig::getSingleton(); - - for($i = 0; $i < count($aResults); $i++) - { - if(strstr($aResults[$i]['value'],'$') != false) - { - $aResults[$i]['value'] = $oKTConfig->get($aResults[$i]['group_name'].'/'.$aResults[$i]['item']); - } - } - - //If template has posted changes for config settings save all values to db. - if(isset($_POST['configArray'])) - { - - foreach ($aResults as $values) - { - - //IF current db entries id is in the array sent back by the page AND - //the values for the db and the page are different, update the db. - if(isset($_POST['configArray'][$values['id']]) && $_POST['configArray'][$values['id']] - != $values['value']) - { - //update entry - $aFields = array(); - if($values['type'] == 'boolean') - { - if($_POST['configArray'][$values['id']] == 'true') - { - $aFields['value'] = true; - - } - else - { - $aFields['value'] = false; - } - } - else - { - $aFields['value'] = $_POST['configArray'][$values['id']]; - } - $oUpdateResult = DBUtil::autoUpdate('config_settings', $aFields, $values['id']); - } - } - } - - //Get new results after any db change above - if(isset($_POST['configArray'])) - { - $aResults = DBUtil::getResultArray($sQuery); - for($i = 0; $i < count($aResults); $i++) - { - if(strstr($aResults[$i]['value'],'$') != false) - { - $aResults[$i]['value'] = $oKTConfig->get($aResults[$i]['group_name'].'/'.$aResults[$i]['item']); - } - } - } - - $oTemplating =& KTTemplating::getSingleton(); - - $oTemplate =& $oTemplating->loadTemplate('ktcore/configsettings'); - - //set db config data being sent to template - $oTemplate->setData(array( - 'results' => $aResults - - )); - return $oTemplate; - } -} - -class UIConfigPageDispatcher extends BaseConfigDispatcher -{ - function check() { - $this->aBreadcrumbs[] = array( - 'url' => $_SERVER['PHP_SELF'], - 'name' => _kt('User Interface Settings'), - ); - return parent::check(); - } - - function do_main() { - - //get config settings from db - $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where group_name = \'ui\'order by group_name'; - return parent::do_main($sQuery); - } -} - -class ClientSettingsConfigPageDispatcher extends BaseConfigDispatcher -{ - function check() { - $this->aBreadcrumbs[] = array( - 'url' => $_SERVER['PHP_SELF'], - 'name' => _kt('Client Tools Settings'), - ); - return parent::check(); - } - - function do_main() { - - //get config settings from db - $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where - group_name = \'KTWebDAVSettings\' or group_name = \'BaobabSettings\' or - group_name = \'webservice\' or group_name = \'clientToolPolicies\' order by group_name'; - return parent::do_main($sQuery); - } -} - -class EmailConfigPageDispatcher extends BaseConfigDispatcher -{ - function check() { - $this->aBreadcrumbs[] = array( - 'url' => $_SERVER['PHP_SELF'], - 'name' => _kt('Email Settings'), - ); - return parent::check(); - } - - function do_main() { - - //get config settings from db - $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where group_name = \'email\'order by group_name'; - return parent::do_main($sQuery); - } -} - -class GeneralConfigPageDispatcher extends BaseConfigDispatcher -{ - function check() { - $this->aBreadcrumbs[] = array( - 'url' => $_SERVER['PHP_SELF'], - 'name' => _kt('General Settings'), - ); - return parent::check(); - } - - function do_main() { - - //get config settings from db - $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where - item = \'schedulerInterval\' or item = \'fakeMimetype\' - or item = \'browseToUnitFolder\' order by group_name'; - return parent::do_main($sQuery); - } -} - -class i18nConfigPageDispatcher extends BaseConfigDispatcher -{ - function check() { - $this->aBreadcrumbs[] = array( - 'url' => $_SERVER['PHP_SELF'], - 'name' => _kt('Internationalisation Settings'), - ); - return parent::check(); - } - - function do_main() { - - //get config settings from db - $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where - group_name = \'i18n\' order by group_name'; - return parent::do_main($sQuery); - } -} - -class SearchAndIndexingConfigPageDispatcher extends BaseConfigDispatcher -{ - function check() { - $this->aBreadcrumbs[] = array( - 'url' => $_SERVER['PHP_SELF'], - 'name' => _kt('Search and Indexing Settings'), - ); - return parent::check(); - } - - function do_main() { - - //get config settings from db - $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where - group_name = \'search\' or group_name = \'indexer\'order by group_name'; - return parent::do_main($sQuery); - } -} -?> +. + * + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + +require_once(KT_LIB_DIR . '/dispatcher.inc.php'); +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); + +class BaseConfigDispatcher extends KTAdminDispatcher +{ + function check() { + return parent::check(); + } + + function do_main($sQuery) + { + if(empty($sQuery)) + { + $sQuery = ''; + } + $aResults = DBUtil::getResultArray($sQuery); + + //populating paths correctly + $oKTConfig =& KTConfig::getSingleton(); + + for($i = 0; $i < count($aResults); $i++) + { + if(strstr($aResults[$i]['value'],'$') != false) + { + $aResults[$i]['value'] = $oKTConfig->get($aResults[$i]['group_name'].'/'.$aResults[$i]['item']); + } + } + + //If template has posted changes for config settings save all values to db. + if(isset($_POST['configArray'])) + { + + foreach ($aResults as $values) + { + + //IF current db entries id is in the array sent back by the page AND + //the values for the db and the page are different, update the db. + if(isset($_POST['configArray'][$values['id']]) && $_POST['configArray'][$values['id']] + != $values['value']) + { + //update entry + $aFields = array(); + if($values['type'] == 'boolean') + { + if($_POST['configArray'][$values['id']] == 'true') + { + $aFields['value'] = true; + + } + else + { + $aFields['value'] = false; + } + } + else + { + $aFields['value'] = $_POST['configArray'][$values['id']]; + } + $oUpdateResult = DBUtil::autoUpdate('config_settings', $aFields, $values['id']); + } + } + + // Clear the cached settings + $oKTConfig->clearCache(); + } + + //Get new results after any db change above + if(isset($_POST['configArray'])) + { + $aResults = DBUtil::getResultArray($sQuery); + for($i = 0; $i < count($aResults); $i++) + { + if(strstr($aResults[$i]['value'],'$') != false) + { + $aResults[$i]['value'] = $oKTConfig->get($aResults[$i]['group_name'].'/'.$aResults[$i]['item']); + } + } + } + + $oTemplating =& KTTemplating::getSingleton(); + + $oTemplate =& $oTemplating->loadTemplate('ktcore/configsettings'); + + //set db config data being sent to template + $oTemplate->setData(array( + 'results' => $aResults + + )); + return $oTemplate; + } +} + +class UIConfigPageDispatcher extends BaseConfigDispatcher +{ + function check() { + $this->aBreadcrumbs[] = array( + 'url' => $_SERVER['PHP_SELF'], + 'name' => _kt('User Interface Settings'), + ); + return parent::check(); + } + + function do_main() { + + //get config settings from db + $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where group_name = \'ui\'order by group_name'; + return parent::do_main($sQuery); + } +} + +class ClientSettingsConfigPageDispatcher extends BaseConfigDispatcher +{ + function check() { + $this->aBreadcrumbs[] = array( + 'url' => $_SERVER['PHP_SELF'], + 'name' => _kt('Client Tools Settings'), + ); + return parent::check(); + } + + function do_main() { + + //get config settings from db + $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where + group_name = \'KTWebDAVSettings\' or group_name = \'BaobabSettings\' or + group_name = \'webservice\' or group_name = \'clientToolPolicies\' order by group_name'; + return parent::do_main($sQuery); + } +} + +class EmailConfigPageDispatcher extends BaseConfigDispatcher +{ + function check() { + $this->aBreadcrumbs[] = array( + 'url' => $_SERVER['PHP_SELF'], + 'name' => _kt('Email Settings'), + ); + return parent::check(); + } + + function do_main() { + + //get config settings from db + $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where group_name = \'email\'order by group_name'; + return parent::do_main($sQuery); + } +} + +class GeneralConfigPageDispatcher extends BaseConfigDispatcher +{ + function check() { + $this->aBreadcrumbs[] = array( + 'url' => $_SERVER['PHP_SELF'], + 'name' => _kt('General Settings'), + ); + return parent::check(); + } + + function do_main() { + + //get config settings from db + $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where + item = \'schedulerInterval\' or item = \'fakeMimetype\' + or item = \'browseToUnitFolder\' order by group_name'; + return parent::do_main($sQuery); + } +} + +class i18nConfigPageDispatcher extends BaseConfigDispatcher +{ + function check() { + $this->aBreadcrumbs[] = array( + 'url' => $_SERVER['PHP_SELF'], + 'name' => _kt('Internationalisation Settings'), + ); + return parent::check(); + } + + function do_main() { + + //get config settings from db + $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where + group_name = \'i18n\' order by group_name'; + return parent::do_main($sQuery); + } +} + +class SearchAndIndexingConfigPageDispatcher extends BaseConfigDispatcher +{ + function check() { + $this->aBreadcrumbs[] = array( + 'url' => $_SERVER['PHP_SELF'], + 'name' => _kt('Search and Indexing Settings'), + ); + return parent::check(); + } + + function do_main() { + + //get config settings from db + $sQuery = 'select id, group_name, item, type, value, helptext, default_value from config_settings where + group_name = \'search\' or group_name = \'indexer\'order by group_name'; + return parent::do_main($sQuery); + } +} +?>