/** * Loads the configuration and works as singleton therefore called static. The call using the program cache * is 10 times faster then taking from the session. The session is still approx. 30 times faster then using the file. * The db is 10 times slower then the session. * * Performance: * * Fastest is * Program Cache: 1.5974044799805E-5 * Session Cache: 0.00016094612121582 * * First config db load: 0.00052118301391602 * Parsed and in session: 0.001554012298584 * * After install from file: 0.0040450096130371 * Parsed and in session: 0.0051419734954834 * * * Functions tests if already loaded in program cache, session cache, database and at last the file. * * Load the configuration values from the database into a session variable. * This step is done to prevent accessing the database for every configuration variable lookup. * * @author Max Milbers * @param $force boolean Forces the function to load the config from the db */ public static function loadConfig($force = FALSE, $fresh = FALSE) { if ($fresh) { self::$_jpConfig = new tsmConfig(); return self::$_jpConfig; } vmSetStartTime('loadConfig'); if (!$force) { if (!empty(self::$_jpConfig) && !empty(self::$_jpConfig->_params)) { return self::$_jpConfig; } } self::$_jpConfig = new tsmConfig(); if (!class_exists('tsmartModelConfig')) { require VMPATH_ADMIN . '/models/config.php'; } $configTable = tsmartModelConfig::checkConfigTableExists(); $app = JFactory::getApplication(); $db = JFactory::getDBO(); self::$installed = true; $install = vRequest::getInt('install', false); $redirected = vRequest::getInt('redirected', false); $link = ''; $msg = ''; if (empty($configTable)) { self::$installed = false; $jlang = JFactory::getLanguage(); $selectedLang = $jlang->getTag(); if (empty($selectedLang)) { $selectedLang = $jlang->setLanguage($selectedLang); } $q = 'SELECT `element` FROM `#__extensions` WHERE type = "language" and enabled = "1"'; $db->setQuery($q); $knownLangs = $db->loadColumn(); //vmdebug('Selected language '.$selectedLang.' $knownLangs ',$knownLangs); if ($app->isAdmin() and !$redirected and !in_array($selectedLang, $knownLangs)) { //$option = vRequest::getVar('option'); //VmConfig::$_debug=true; //vmdebug('my option',$option,$_REQUEST); //if($option!='com_languages'){ $msg = 'Install your selected language <b>' . $selectedLang . '</b> first in <a href="' . $link . '">joomla language manager</a>, just select then the component tsmart under menu "component", to proceed with the installation '; //$link = 'index.php?option=com_installer&view=languages&redirected=1'; //$app->redirect($link,$msg); //} $app->enqueueMessage($msg); } self::$installed = tsmartModelConfig::checktsmartInstalled(); /*if(!self::$installed){ if(!$redirected and !$install){ $link = 'index.php?option=com_tsmart&view=updatesmigration&redirected=1'; if($app->isSite()){ $link = JURI::root(true).'/administrator/'.$link; } else { if(empty($msg)) $msg = 'Install tsmart first, click on the menu component and select tsmart'; } } }*/ } else { $query = ' SELECT `config` FROM `#__tsmart_configs` WHERE `tsmart_config_id` = "1";'; $db->setQuery($query); self::$_jpConfig->_raw = $db->loadResult(); //vmTime('time to load config','loadConfig'); } if (empty(self::$_jpConfig->_raw)) { $_value = tsmartModelConfig::readConfigFile(); if (!$_value) { vmError('Serious error, config file could not be filled with data'); return FALSE; } $_value = join('|', $_value); self::$_jpConfig->_raw = $_value; self::$_jpConfig->setParams(self::$_jpConfig->_raw); self::$_jpConfig->storeConfig(); } else { self::$_jpConfig->setParams(self::$_jpConfig->_raw); } self::$_secret = JFactory::getConfig()->get('secret'); self::$_jpConfig->_params['sctime'] = microtime(TRUE); self::$_jpConfig->_params['vmlang'] = self::setdbLanguageTag(); vmTime('time to load config', 'loadConfig'); if ($app->isSite()) { // try plugins JPluginHelper::importPlugin('vmuserfield'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('plgVmInitialise', array()); } if (!self::$installed) { $user = JFactory::getUser(); if ($user->authorise('core.admin', 'com_tsmart') and ($install or $redirected)) { tsmConfig::$_jpConfig->set('dangeroustools', 1); } if (!empty($msg)) { $app->enqueueMessage($msg); } if (!empty($link)) { $app->redirect($link); } } return self::$_jpConfig; }
/** * Dangerous tools get disabled after execution an operation which needed that rights. * This is the function actually doing it. * * @author Max Milbers */ function setDangerousToolsOff() { $dangerousTools = tsmartModelConfig::readConfigFile(true); if ($dangerousTools) { $link = JURI::root() . 'administrator/index.php?option=com_tsmart&view=config'; $lang = tsmText::sprintf('com_tsmart_SYSTEM_DANGEROUS_TOOL_STILL_ENABLED', tsmText::_('com_tsmart_ADMIN_CFG_DANGEROUS_TOOLS'), $link); VmInfo($lang); } else { if (self::checkConfigTableExists()) { $data['dangeroustools'] = 0; $data['tsmart_config_id'] = 1; $this->store($data); } } }