public static function getHandle() { if (!self::$dbh) { $cfg = new \Hubzero\Config\Repository(); self::$dbh = new PDO('mysql:host=localhost;dbname=' . $cfg->get('db'), $cfg->get('user'), $cfg->get('password'), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } return self::$dbh; }
/** * Create a new file cache store instance. * * @param array $options * @return void */ public function __construct(array $options = array()) { $this->options = array_merge($this->options, $options); if (!isset($this->options['client'])) { $this->options['client'] = ''; } if (!isset($this->options['language'])) { $this->options['language'] = 'en-GB'; } if (!isset($this->options['hash'])) { $config = new \Hubzero\Config\Repository('site'); $this->options['hash'] = md5($config->get('secret')); } }
/** * Test to see if the cache storage is available. * * @return boolean True on success, false otherwise. */ public static function isAvailable() { $conf = new \Hubzero\Config\Repository('site'); return is_writable($conf->get('cache_path', PATH_APP . '/cache')); }
/** * Method to save the configuration data. * * @param array An array containing all global config data. * @return bool True on success, false on failure. * @since 1.6 */ public function save($data) { // Save the rules if (isset($data['rules'])) { $rules = new JAccessRules($data['rules']); // Check that we aren't removing our Super User permission // Need to get groups from database, since they might have changed $myGroups = JAccess::getGroupsByUser(\User::get('id')); $myRules = $rules->getData(); $hasSuperAdmin = $myRules['core.admin']->allow($myGroups); if (!$hasSuperAdmin) { $this->setError(Lang::txt('COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN')); return false; } $asset = JTable::getInstance('asset'); if ($asset->loadByName('root.1')) { $asset->rules = (string) $rules; if (!$asset->check() || !$asset->store()) { Notify::error('SOME_ERROR_CODE', $asset->getError()); } } else { $this->setError(Lang::txt('COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND')); return false; } unset($data['rules']); } // Save the text filters if (isset($data['filters'])) { $registry = new Registry(array('filters' => $data['filters'])); $extension = JTable::getInstance('extension'); // Get extension_id $extension_id = $extension->find(array('name' => 'com_config')); if ($extension->load((int) $extension_id)) { $extension->params = (string) $registry; if (!$extension->check() || !$extension->store()) { Notify::error('SOME_ERROR_CODE', $extension->getError()); } } else { $this->setError(Lang::txt('COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND')); return false; } unset($data['filters']); } // Get the previous configuration. $config = new \Hubzero\Config\Repository('site'); $prev = $config->toArray(); /*$extras = array(); foreach ($prev as $key => $val) { $found = false; foreach ($data as $group => $values) { if (in_array($key, $values)) { $found = true; } } if (!$found) { $extras[$key] = $val; } } // Merge the new data in. We do this to preserve values that were not in the form. $data['app'] = array_merge($data['app'], $extras);*/ // Perform miscellaneous options based on configuration settings/changes. // Escape the offline message if present. if (isset($data['offline']['offline_message'])) { $data['offline']['offline_message'] = \Hubzero\Utility\String::ampReplace($data['offline']['offline_message']); } // Purge the database session table if we are changing to the database handler. if ($prev['session']['session_handler'] != 'database' && $data['session']['session_handler'] == 'database') { $table = JTable::getInstance('session'); $table->purge(-1); } if (empty($data['cache']['cache_handler'])) { $data['cache']['caching'] = 0; } // Clean the cache if disabled but previously enabled. if (!$data['cache']['caching'] && $prev['cache']['caching']) { \Cache::clean(); } foreach ($data as $group => $values) { foreach ($values as $key => $value) { if (!isset($prev[$group])) { $prev[$group] = array(); } $prev[$group][$key] = $value; } } // Create the new configuration object. //$config = new Registry($data); // Overwrite the old FTP credentials with the new ones. if (isset($data['ftp'])) { $temp = \Config::getRoot(); $temp->set('ftp.ftp_enable', $data['ftp']['ftp_enable']); $temp->set('ftp.ftp_host', $data['ftp']['ftp_host']); $temp->set('ftp.ftp_port', $data['ftp']['ftp_port']); $temp->set('ftp.ftp_user', $data['ftp']['ftp_user']); $temp->set('ftp.ftp_pass', $data['ftp']['ftp_pass']); $temp->set('ftp.ftp_root', $data['ftp']['ftp_root']); } // Clear cache of com_config component. $this->cleanCache('_system'); // Write the configuration file. return $this->writeConfigFile($prev); }