Example #1
0
 /**
  * method to get the config
  *
  * @return array config values
  */
 function &getConfig()
 {
     if (is_null($this->config)) {
         $registry = Config::getRoot();
         $this->config = $registry->toArray();
         $hidden = array('host', 'user', 'password', 'ftp_user', 'ftp_pass', 'smtpuser', 'smtppass');
         foreach ($hidden as $key) {
             $this->config[$key] = 'xxxxxx';
         }
     }
     return $this->config;
 }
Example #2
0
 /**
  * @return string[]
  */
 public static function findInstalledBuilds($stripPrefix = true)
 {
     $path = Config::getRoot() . DIRECTORY_SEPARATOR . 'php';
     if (!file_exists($path)) {
         throw new Exception($path . ' does not exist.');
     }
     $names = scandir($path);
     $names = array_filter($names, function ($name) use($path) {
         return $name != '.' && $name != '..' && file_exists($path . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'php');
     });
     if ($names == null || empty($names)) {
         return array();
     }
     if ($stripPrefix) {
         $names = array_map(function ($name) {
             return preg_replace('/^php-(?=(\\d+\\.\\d+\\.\\d+((alpha|beta|RC)\\d+)?)$)/', '', $name);
         }, $names);
     }
     uasort($names, 'version_compare');
     // ordering version name ascending... 5.5.17, 5.5.12
     return array_reverse($names);
     // make it descending... since there is no sort function for user-define in reverse order.
 }
Example #3
0
 /**
  * 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);
 }
$conf['storage']['params']['username'] = '******';
$conf['storage']['params']['password'] = '******';
$conf['menu']['apps'] = array('imp', 'turba');
$conf['stdcontent']['para'][0] = 'This is really cool !';
$conf['stdcontent']['para'][1] = 'It just rocks...';
$c = new Config();
$root =& $c->parseConfig($conf, 'phparray');
$storage =& $root->getItem('section', 'storage');
$storage->removeItem();
$root->addItem($storage);
echo '<pre>' . $root->toString('phparray', array('name' => 'test')) . '</pre>';
if ($c->writeConfig('/tmp/Config_Test.php', 'phparray', array('name' => 'test')) === true) {
    echo 'Config written into /tmp/Config_Test.php';
}
// Making a php ini file with $storage only
$ini = new Config();
$iniRoot =& $ini->getRoot();
$iniRoot->addItem($storage);
$comment =& new Config_Container('comment', null, 'This is the php ini version of storage');
$iniRoot->addItem($comment, 'top');
$iniRoot->createBlank('after', $comment);
echo '<pre>' . $iniRoot->toString('inicommented') . '</pre>';
// Gonna make an array with it
echo '<pre>';
var_dump($iniRoot->toArray());
echo '</pre>';
// Now, I'll parse you php.ini file and make it a php array
$phpIni = new Config();
$phpIni->parseConfig('/usr/local/lib/php.ini', 'inifile');
$root =& $phpIni->getRoot();
echo '<pre>' . $root->toString('phparray', array('name' => 'php_ini')) . '</pre>';
Example #5
0
 /**
  * Creating the config file
  *
  * @param array $answers The $answers passed over from the run() method.
  *
  * @return bool True on success, otherwise false.
  */
 function setupEnvironment($answers)
 {
     $this->_ui->outputData('Writing config file');
     $config = new Config();
     $root = $config->getRoot();
     $root->createItem('directive', strtoupper('path_include'), '@php-dir@');
     foreach ($this->settings as $setting) {
         $root->createItem('directive', strtoupper($setting), $answers[$setting]);
     }
     $error_check = $config->writeConfig($this->_config_file, 'phpconstants', array('name' => 'config'));
     if (PEAR::isError($error_check)) {
         $this->_ui->outputData($error_check->getMessage());
         return false;
     }
     $this->_ui->outputData('Config file written: ' . $this->_config_file);
     return true;
 }
Example #6
0
 public function __construct()
 {
     $this->root = Config::getRoot();
     $this->baseDir = $this->root . DIRECTORY_SEPARATOR . 'registry';
 }