Example #1
0
/**
 * Disables the unsupported eAccelerator caching method, replacing it with the
 * "file" caching method.
 *
 * @return  void
 *
 * @since   3.2
 */
function admin_postinstall_eaccelerator_action()
{
    $prev = new JConfig();
    $prev = JArrayHelper::fromObject($prev);
    $data = array('cacheHandler' => 'file');
    $data = array_merge($prev, $data);
    $config = new Registry('config');
    $config->loadArray($data);
    jimport('joomla.filesystem.path');
    jimport('joomla.filesystem.file');
    // Set the configuration file path.
    $file = JPATH_CONFIGURATION . '/configuration.php';
    // Get the new FTP credentials.
    $ftp = JClientHelper::getCredentials('ftp', true);
    // Attempt to make the file writeable if using FTP.
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) {
        JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'));
    }
    // Attempt to write the configuration file as a PHP class named JConfig.
    $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
    if (!JFile::write($file, $configuration)) {
        JFactory::getApplication()->enqueueMessage(JText::_('COM_CONFIG_ERROR_WRITE_FAILED'), 'error');
        return;
    }
    // Attempt to make the file unwriteable if using FTP.
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) {
        JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'));
    }
}
Example #2
0
 /**
  * Sets the value of multiple component configuration parameters at once
  *
  * @param   array  $params  The parameters to set
  *
  * @return  void
  */
 public static function setParams(array $params)
 {
     if (!is_object(self::$params)) {
         JLoader::import('joomla.application.component.helper');
         self::$params = JComponentHelper::getParams('com_ars');
     }
     foreach ($params as $key => $value) {
         self::$params->set($key, $value);
     }
     $db = JFactory::getDBO();
     $data = self::$params->toString();
     $sql = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('params') . ' = ' . $db->q($data))->where($db->qn('element') . ' = ' . $db->q('com_ars'))->where($db->qn('type') . ' = ' . $db->q('component'));
     $db->setQuery($sql);
     try {
         $db->execute();
     } catch (\Exception $e) {
         // Don't sweat if it fails
     }
 }
Example #3
0
 /**
  * Actually Save the params into the db
  */
 public function save()
 {
     $db = $this->container->db;
     $data = $this->params->toString();
     $sql = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('params') . ' = ' . $db->q($data))->where($db->qn('element') . ' = ' . $db->q($this->container->componentName))->where($db->qn('type') . ' = ' . $db->q('component'));
     $db->setQuery($sql);
     try {
         $db->execute();
     } catch (\Exception $e) {
         // Don't sweat if it fails
     }
 }
 /**
  * Store data used during process of payment.
  *
  * <code>
  * $paymentSessionId  = 1;
  * $orderId           = "ORDER2";
  *
  * $paymentSession    = new Crowdfunding\Payment\Session(\JFactory::getDbo());
  * $paymentSession->load($paymentSessionId);
  *
  * $paymentSession->setData('order_id', $orderId);
  * $paymentSession->storeData();
  * </code>
  *
  * @return self
  */
 public function storeData()
 {
     // Convert the gateway data to JSON format.
     $gatewayData = 'NULL';
     if ($this->gateway_data instanceof Registry) {
         $gatewayData = $this->gateway_data->toString();
     }
     $query = $this->db->getQuery(true);
     $query->update($this->db->quoteName('#__crowdf_payment_sessions'))->set($this->db->quoteName('gateway_data') . '=' . $this->db->quote($gatewayData))->where($this->db->quoteName('id') . '=' . $this->db->quote($this->id));
     $this->db->setQuery($query);
     $this->db->execute();
     return $this;
 }
 protected function insertObject()
 {
     $query = $this->db->getQuery(true);
     $query->insert($this->db->quoteName('#__gfy_badges'))->set($this->db->quoteName('title') . '=' . $this->db->quote($this->title))->set($this->db->quoteName('image') . '=' . $this->db->quote($this->image))->set($this->db->quoteName('published') . '=' . (int) $this->published)->set($this->db->quoteName('group_id') . '=' . (int) $this->group_id)->set($this->db->quoteName('points_number') . '=' . $this->db->quote($this->points_number))->set($this->db->quoteName('points_id') . '=' . $this->db->quote($this->points_id))->set($this->db->quoteName('params') . ' = ' . $this->db->quote($this->params->toString()))->set($this->db->quoteName('custom_data') . ' = ' . $this->db->quote($this->custom_data->toString()));
     if ($this->note !== null and $this->note !== '') {
         $query->set($this->db->quoteName('note') . '=' . $this->db->quote($this->note));
     }
     if ($this->description !== null and $this->description !== '') {
         $query->set($this->db->quoteName('description') . '=' . $this->db->quote($this->description));
     }
     if ($this->activity_text !== null and $this->activity_text !== '') {
         $query->set($this->db->quoteName('activity_text') . '=' . $this->db->quote($this->activity_text));
     }
     $this->db->setQuery($query);
     $this->db->execute();
     return $this->db->insertid();
 }
 /**
  * checkout
  *
  * @param $profile
  *
  * @return bool
  * @throws \Exception
  */
 public function checkout($profile)
 {
     $listModel = new ProfilesModel();
     $profiles = $listModel->getList();
     if (!in_array($profile, $profiles)) {
         throw new \Exception(sprintf('Profile "%s" not exists.', $name));
     }
     $profileConfig = new Registry();
     $file = JPATH_ROOT . '/tmp/sqlsync/config.yml';
     $profileConfig->loadFile($file);
     $profileConfig->set('profile', $profile);
     $content = $profileConfig->toString('yaml');
     if (!\JFile::write($file, $content)) {
         throw new \Exception('Writing profile config fail.');
     }
     return true;
 }
 protected function insertObject()
 {
     $customData = $this->custom_data instanceof Registry ? $this->custom_data->toString() : '{}';
     $rewards = $this->rewards instanceof Registry ? $this->rewards->toString() : '{}';
     // Create a new query object.
     $query = $this->db->getQuery(true);
     $query->insert($this->db->quoteName('#__gfy_achievements'))->set($this->db->quoteName('title') . '=' . $this->db->quote($this->title))->set($this->db->quoteName('context') . '=' . $this->db->quote($this->context))->set($this->db->quoteName('image') . '=' . $this->db->quote($this->image))->set($this->db->quoteName('image_small') . '=' . $this->db->quote($this->image_small))->set($this->db->quoteName('image_square') . '=' . $this->db->quote($this->image_square))->set($this->db->quoteName('published') . '=' . (int) $this->published)->set($this->db->quoteName('custom_data') . '=' . $this->db->quote($customData))->set($this->db->quoteName('rewards') . '=' . $this->db->quote($rewards))->set($this->db->quoteName('points_id') . '=' . (int) $this->points_id)->set($this->db->quoteName('points_number') . '=' . (int) $this->points_number)->set($this->db->quoteName('group_id') . '=' . (int) $this->group_id);
     if ($this->note !== null and $this->note !== '') {
         $query->set($this->db->quoteName('note') . ' = ' . $this->db->quote($this->note));
     }
     if ($this->description !== null and $this->description !== '') {
         $query->set($this->db->quoteName('description') . ' = ' . $this->db->quote($this->description));
     }
     if ($this->activity_text !== null and $this->activity_text !== '') {
         $query->set($this->db->quoteName('activity_text') . ' = ' . $this->db->quote($this->activity_text));
     }
     $this->db->setQuery($query);
     $this->db->execute();
     return $this->db->insertid();
 }
Example #8
0
 /**
  * Fix Joomla version in #__extensions table if wrong (doesn't equal JVersion short version).
  *
  * @return   mixed  string update version if success, false if fail.
  */
 public function fixUpdateVersion()
 {
     $table = JTable::getInstance('Extension');
     $table->load('700');
     $cache = new Registry($table->manifest_cache);
     $updateVersion = $cache->get('version');
     $cmsVersion = new JVersion();
     if ($updateVersion == $cmsVersion->getShortVersion()) {
         return $updateVersion;
     } else {
         $cache->set('version', $cmsVersion->getShortVersion());
         $table->manifest_cache = $cache->toString();
         if ($table->store()) {
             return $cmsVersion->getShortVersion();
         } else {
             return false;
         }
     }
 }
 /**
  * Test the Joomla\Registry\Registry::toString method.
  *
  * @return  void
  *
  * @covers  Joomla\Registry\Registry::toString
  * @since   1.0
  */
 public function testToString()
 {
     $a = new Registry();
     $a->set('foo1', 'testtostring1');
     $a->set('foo2', 'testtostring2');
     $a->set('config.foo3', 'testtostring3');
     $this->assertThat(trim($a->toString('JSON')), $this->equalTo('{"foo1":"testtostring1","foo2":"testtostring2","config":{"foo3":"testtostring3"}}'), 'Line: ' . __LINE__ . '.');
     $this->assertThat(trim($a->toString('INI')), $this->equalTo("foo1=\"testtostring1\"\nfoo2=\"testtostring2\"\n\n[config]\nfoo3=\"testtostring3\""), 'Line: ' . __LINE__ . '.');
 }
Example #10
0
$config = new Registry();
$config->loadObject(new JConfig());
$options = $this->input->getVar('install');
$options['select'] = false;
$options['driver'] = $config->get('driver');
$db = JDatabaseDriver::getInstance($options);
try {
    // Create
    $db->setQuery('CREATE DATABASE IF NOT EXISTS ' . $db->qn($options['database']) . ' CHARACTER SET = "utf8"')->execute();
    $db->select($options['database']);
    // Import
    $sql = new SplFileInfo(JPATH_BASE . '/ezset-sql-backup.sql');
    $queries = file_get_contents($sql->getPathname());
    $queries = $db->splitSql($queries);
    foreach ($queries as $query) {
        $db->setQuery($query)->execute();
    }
    $config->set('host', $options['host']);
    $config->set('db', $options['database']);
    $config->set('password', $options['password']);
    $config->set('user', $options['user']);
    $config->set('log_path', JPATH_BASE . '/logs');
    $config->set('tmp_path', JPATH_BASE . '/tmp');
    file_put_contents($configFile->getPathname(), $config->toString('php', array('class' => 'JConfig')));
    // Fix UTF-8 files
    \Ezset\Library\Backup\Backup::fix();
    $this->redirect('index.php?page=complete');
} catch (\Exception $e) {
    echo $e;
    exit;
}
Example #11
0
 /**
  * Method to create the configuration file
  *
  * @param   array  $options  The session options
  *
  * @return  boolean  True on success
  *
  * @since   3.1
  */
 public function _createConfiguration($options)
 {
     // Create a new registry to build the configuration options.
     $registry = new Registry();
     // Site settings.
     $registry->set('offline', $options->site_offline);
     $registry->set('offline_message', JText::_('INSTL_STD_OFFLINE_MSG'));
     $registry->set('display_offline_message', 1);
     $registry->set('offline_image', '');
     $registry->set('sitename', $options->site_name);
     $registry->set('editor', 'tinymce');
     $registry->set('captcha', '0');
     $registry->set('list_limit', 20);
     $registry->set('access', 1);
     // Debug settings.
     $registry->set('debug', 0);
     $registry->set('debug_lang', 0);
     // Database settings.
     $registry->set('dbtype', $options->db_type);
     $registry->set('host', $options->db_host);
     $registry->set('user', $options->db_user);
     $registry->set('password', $options->db_pass);
     $registry->set('db', $options->db_name);
     $registry->set('dbprefix', $options->db_prefix);
     // Server settings.
     $registry->set('live_site', '');
     $registry->set('secret', JUserHelper::genRandomPassword(16));
     $registry->set('gzip', 0);
     $registry->set('error_reporting', 'default');
     $registry->set('helpurl', $options->helpurl);
     $registry->set('ftp_host', isset($options->ftp_host) ? $options->ftp_host : '');
     $registry->set('ftp_port', isset($options->ftp_host) ? $options->ftp_port : '');
     $registry->set('ftp_user', isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_user) ? $options->ftp_user : '');
     $registry->set('ftp_pass', isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_pass) ? $options->ftp_pass : '');
     $registry->set('ftp_root', isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_root) ? $options->ftp_root : '');
     $registry->set('ftp_enable', isset($options->ftp_host) ? $options->ftp_enable : 0);
     // Locale settings.
     $registry->set('offset', 'UTC');
     // Mail settings.
     $registry->set('mailonline', 1);
     $registry->set('mailer', 'mail');
     $registry->set('mailfrom', $options->admin_email);
     $registry->set('fromname', $options->site_name);
     $registry->set('sendmail', '/usr/sbin/sendmail');
     $registry->set('smtpauth', 0);
     $registry->set('smtpuser', '');
     $registry->set('smtppass', '');
     $registry->set('smtphost', 'localhost');
     $registry->set('smtpsecure', 'none');
     $registry->set('smtpport', '25');
     // Cache settings.
     $registry->set('caching', 0);
     $registry->set('cache_handler', 'file');
     $registry->set('cachetime', 15);
     $registry->set('cache_platformprefix', 0);
     // Meta settings.
     $registry->set('MetaDesc', $options->site_metadesc);
     $registry->set('MetaKeys', '');
     $registry->set('MetaTitle', 1);
     $registry->set('MetaAuthor', 1);
     $registry->set('MetaVersion', 0);
     $registry->set('robots', '');
     // SEO settings.
     $registry->set('sef', 1);
     $registry->set('sef_rewrite', 0);
     $registry->set('sef_suffix', 0);
     $registry->set('unicodeslugs', 0);
     // Feed settings.
     $registry->set('feed_limit', 10);
     $registry->set('feed_email', 'none');
     $registry->set('log_path', JPATH_ADMINISTRATOR . '/logs');
     $registry->set('tmp_path', JPATH_ROOT . '/tmp');
     // Session setting.
     $registry->set('lifetime', 15);
     $registry->set('session_handler', 'database');
     // Generate the configuration class string buffer.
     $buffer = $registry->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
     // Build the configuration file path.
     $path = JPATH_CONFIGURATION . '/configuration.php';
     // Determine if the configuration file path is writable.
     if (file_exists($path)) {
         $canWrite = is_writable($path);
     } else {
         $canWrite = is_writable(JPATH_CONFIGURATION . '/');
     }
     /*
      * If the file exists but isn't writable OR if the file doesn't exist and the parent directory
      * is not writable we need to use FTP.
      */
     $useFTP = false;
     if (file_exists($path) && !is_writable($path) || !file_exists($path) && !is_writable(dirname($path) . '/')) {
         $useFTP = true;
     }
     // Check for safe mode.
     if (ini_get('safe_mode')) {
         $useFTP = true;
     }
     // Enable/Disable override.
     if (!isset($options->ftpEnable) || $options->ftpEnable != 1) {
         $useFTP = false;
     }
     if ($useFTP == true) {
         // Connect the FTP client.
         $ftp = JClientFtp::getInstance($options->ftp_host, $options->ftp_port);
         $ftp->login($options->ftp_user, $options->ftp_pass);
         // Translate path for the FTP account.
         $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/');
         // Use FTP write buffer to file.
         if (!$ftp->write($file, $buffer)) {
             // Set the config string to the session.
             $session = JFactory::getSession();
             $session->set('setup.config', $buffer);
         }
         $ftp->quit();
     } else {
         if ($canWrite) {
             file_put_contents($path, $buffer);
             $session = JFactory::getSession();
             $session->set('setup.config', null);
         } else {
             // Set the config string to the session.
             $session = JFactory::getSession();
             $session->set('setup.config', $buffer);
         }
     }
     return true;
 }
Example #12
0
 /**
  * Called at the end of a list save.
  * Update the created joins with the created list's id and db_table_name
  *
  * @param   FabrikTableList $row List data
  *
  * @return  void
  */
 public function finalise($row)
 {
     $source = $this->getSourceTableName();
     $targetTable = $row->get('db_table_name');
     foreach ($this->joinIds as $joinId) {
         $joinTable = FabTable::getInstance('Join', 'FabrikTable');
         $joinTable->load($joinId);
         if ((int) $joinTable->get('element_id') === 0) {
             // Group join
             $joinTable->set('list_id', $row->get('id'));
             $joinTable->set('join_from_table', $targetTable);
         } else {
             // Element join
             $tableLookUps = array('join_from_table', 'table_join', 'table_join_alias');
             foreach ($tableLookUps as $tableLookup) {
                 if ($joinTable->get($tableLookup) === $source) {
                     $joinTable->set($tableLookup, $targetTable);
                 }
             }
         }
         $joinTable->store();
     }
     // Update element params with source => target table name conversion
     foreach ($this->elementIds as $elementId) {
         /** @var FabrikTableElement $element */
         $element = FabTable::getInstance('Element', 'FabrikTable');
         $element->load($elementId);
         $elementParams = new Registry($element->params);
         if ($elementParams->get('join_db_name') === $source) {
             $elementParams->set('join_db_name', $targetTable);
             $element->set('params', $elementParams->toString());
             $element->store();
         }
     }
 }
 /**
  * Save data into the DB
  *
  * @param array $data The data about item
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \UnexpectedValueException
  *
  * @return  int
  */
 public function save($data)
 {
     $id = ArrayHelper::getValue($data, 'id');
     $title = ArrayHelper::getValue($data, 'title');
     $points = ArrayHelper::getValue($data, 'points_number');
     $pointsId = ArrayHelper::getValue($data, 'points_id');
     $groupId = ArrayHelper::getValue($data, 'group_id');
     $published = ArrayHelper::getValue($data, 'published');
     $note = ArrayHelper::getValue($data, 'note');
     $params = ArrayHelper::getValue($data, 'params', [], 'array');
     $description = ArrayHelper::getValue($data, 'description');
     $activityText = ArrayHelper::getValue($data, 'activity_text');
     $customData = Gamification\Helper::prepareCustomData($data);
     $params = new Registry($params);
     // Load a record from the database
     $row = $this->getTable();
     /** @var $row GamificationTableBadge */
     $row->load($id);
     $row->set('title', $title);
     $row->set('points_number', $points);
     $row->set('points_id', $pointsId);
     $row->set('group_id', $groupId);
     $row->set('published', $published);
     $row->set('note', $note);
     $row->set('description', $description);
     $row->set('activity_text', $activityText);
     $row->set('custom_data', $customData);
     $row->set('params', $params->toString());
     $this->prepareTable($row);
     $this->prepareImage($row, $data);
     $row->store(true);
     return $row->get('id');
 }
 /**
  * Fix Joomla version in #__extensions table if wrong (doesn't equal JVersion short version)
  *
  * @return   mixed  string update version if success, false if fail
  *
  * @since    1.7.0
  */
 public function fixUpdateVersion()
 {
     /** @var ChurchDirectoryTableMember $table */
     $table = JTable::getInstance('Extension');
     $table->load($this->getExtentionId());
     $cache = new Registry($table->manifest_cache);
     $updateVersion = $cache->get('version');
     if ($updateVersion == $this->getCompVersion()) {
         return $updateVersion;
     } else {
         $cache->set('version', $this->getCompVersion());
         $table->manifest_cache = $cache->toString();
         if ($table->store()) {
             return $this->getCompVersion();
         } else {
             return false;
         }
     }
 }
Example #15
0
 /**
  * Save the parameters object for the library
  *
  * @param   string    $element  Element of the library in the extensions table.
  * @param   Registry  $params   Params to save
  *
  * @return  Registry  A Registry object.
  *
  * @see     Registry
  * @since   3.2
  */
 public static function saveParams($element, $params)
 {
     if (static::isEnabled($element)) {
         // Save params in DB
         $db = JFactory::getDbo();
         $query = $db->getQuery(true)->update($db->quoteName('#__extensions'))->set($db->quoteName('params') . ' = ' . $db->quote($params->toString()))->where($db->quoteName('type') . ' = ' . $db->quote('library'))->where($db->quoteName('element') . ' = ' . $db->quote($element));
         $db->setQuery($query);
         $result = $db->execute();
         // Update params in libraries cache
         if ($result && isset(static::$libraries[$element])) {
             static::$libraries[$element]->params = $params;
         }
         return $result;
     }
     return false;
 }
 /**
  * Prepare rewards that will be given for accomplishing this unit.
  *
  * @param array  $data
  *
  * @throws \InvalidArgumentException
  * @return string
  */
 public static function prepareRewards($data)
 {
     $rewards = ArrayHelper::getValue($data, 'rewards', [], 'array');
     $rewards['points'] = trim($rewards['points']);
     $rewards['points_id'] = (int) $rewards['points_id'];
     // Prepare badge IDs.
     $results = array();
     foreach ($rewards['badge_id'] as $itemId) {
         $itemId = (int) $itemId;
         if (!$itemId) {
             continue;
         }
         $results[] = $itemId;
     }
     $rewards['badge_id'] = $results;
     // Prepare rank IDs.
     $results = array();
     foreach ($rewards['rank_id'] as $itemId) {
         $itemId = (int) $itemId;
         if (!$itemId) {
             continue;
         }
         $results[] = $itemId;
     }
     $rewards['rank_id'] = $results;
     // Prepare badge IDs.
     $results = array();
     foreach ($rewards['reward_id'] as $itemId) {
         $itemId = (int) $itemId;
         if (!$itemId) {
             continue;
         }
         $results[] = $itemId;
     }
     $rewards['reward_id'] = $results;
     $rewards = new Registry($rewards);
     return $rewards->toString();
 }
Example #17
0
 /**
  * Method to delete one or more overrides.
  *
  * @param   array  $cids  Array of keys to delete.
  *
  * @return  integer Number of successfully deleted overrides, boolean false if an error occured.
  *
  * @since		2.5
  */
 public function delete($cids)
 {
     // Check permissions first.
     if (!JFactory::getUser()->authorise('core.delete', 'com_languages')) {
         $this->setError(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'));
         return false;
     }
     jimport('joomla.filesystem.file');
     require_once JPATH_COMPONENT . '/helpers/languages.php';
     $filterclient = JFactory::getApplication()->getUserState('com_languages.overrides.filter.client');
     $client = $filterclient == 0 ? 'SITE' : 'ADMINISTRATOR';
     // Parse the override.ini file in oder to get the keys and strings.
     $filename = constant('JPATH_' . $client) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini';
     $strings = LanguagesHelper::parseFile($filename);
     // Unset strings that shall be deleted
     foreach ($cids as $key) {
         if (isset($strings[$key])) {
             unset($strings[$key]);
         }
     }
     foreach ($strings as $key => $string) {
         $strings[$key] = str_replace('"', '"_QQ_"', $string);
     }
     // Write override.ini file with the left strings.
     $registry = new Registry();
     $registry->loadObject($strings);
     $reg = $registry->toString('INI');
     $filename = constant('JPATH_' . $client) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini';
     if (!JFile::write($filename, $reg)) {
         return false;
     }
     $this->cleanCache();
     return count($cids);
 }
Example #18
0
 public function prepareTable($table)
 {
     if (isset($table->params) && is_array($table->params)) {
         $registry = new Registry();
         $registry->loadArray($table->params);
         $table->params = $registry->toString();
     }
     if (isset($table->value) && is_array($table->value)) {
         $table->value = json_encode($table->value);
     }
 }
Example #19
0
 /**
  * Method to write the configuration to a file.
  *
  * @param   Registry  $config  A Registry object containing all global config data.
  *
  * @return	boolean  True on success, false on failure.
  *
  * @since	2.5.4
  * @throws  RuntimeException
  */
 private function writeConfigFile(Registry $config)
 {
     jimport('joomla.filesystem.path');
     jimport('joomla.filesystem.file');
     // Set the configuration file path.
     $file = JPATH_CONFIGURATION . '/configuration.php';
     // Get the new FTP credentials.
     $ftp = JClientHelper::getCredentials('ftp', true);
     $app = JFactory::getApplication();
     // Attempt to make the file writeable if using FTP.
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) {
         $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'), 'notice');
     }
     // Attempt to write the configuration file as a PHP class named JConfig.
     $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
     if (!JFile::write($file, $configuration)) {
         throw new RuntimeException(JText::_('COM_CONFIG_ERROR_WRITE_FAILED'));
     }
     // Attempt to make the file unwriteable if using FTP.
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) {
         $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'), 'notice');
     }
     return true;
 }
Example #20
0
 /**
  * @param $uid
  * @param $itemid
  *
  * @return int
  */
 public function toggleItem($uid, $itemid)
 {
     $sitemap = $this->getItem();
     $items = $this->getItems();
     $extensions = $this->getExtensions();
     $displayer = new XmapDisplayerHtml($sitemap, $items, $extensions);
     $excludedItems = $displayer->getExcludedItems();
     if (isset($excludedItems[$itemid])) {
         $excludedItems[$itemid] = (array) $excludedItems[$itemid];
     }
     if (!$displayer->isExcluded($itemid, $uid)) {
         $excludedItems[$itemid][] = $uid;
         $state = 0;
     } else {
         if (is_array($excludedItems[$itemid]) && count($excludedItems[$itemid])) {
             // TODO refactor, create_function is bad
             $excludedItems[$itemid] = array_filter($excludedItems[$itemid], create_function('$var', 'return ($var != \'' . $uid . '\');'));
         } else {
             unset($excludedItems[$itemid]);
         }
         $state = 1;
     }
     $registry = new Registry();
     $registry->loadArray($excludedItems);
     $str = $registry->toString();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->update('#__xmap_sitemap AS s')->set('s.excluded_items = ' . $db->quote($str))->where('s.id = ' . $db->quote($sitemap->id));
     $db->setQuery($query);
     $db->execute();
     return $state;
 }
Example #21
0
 /**
  * Method to save the form data.
  *
  * @param   array    $data             The form data.
  * @param   boolean  $opposite_client  Indicates whether the override should not be created for the current client.
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   2.5
  */
 public function save($data, $opposite_client = false)
 {
     JLoader::register('LanguagesHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/languages.php');
     jimport('joomla.filesystem.file');
     $app = JFactory::getApplication();
     $client = $app->getUserState('com_languages.overrides.filter.client', 0);
     $language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB');
     // If the override should be created for both.
     if ($opposite_client) {
         $client = 1 - $client;
     }
     // Return false if the constant is a reserved word, i.e. YES, NO, NULL, FALSE, ON, OFF, NONE, TRUE
     $blacklist = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE');
     if (in_array($data['key'], $blacklist)) {
         $this->setError(JText::_('COM_LANGUAGES_OVERRIDE_ERROR_RESERVED_WORDS'));
         return false;
     }
     $client = $client ? 'administrator' : 'site';
     // Parse the override.ini file in oder to get the keys and strings.
     $filename = constant('JPATH_' . strtoupper($client)) . '/language/overrides/' . $language . '.override.ini';
     $strings = LanguagesHelper::parseFile($filename);
     if (isset($strings[$data['id']])) {
         // If an existent string was edited check whether
         // the name of the constant is still the same.
         if ($data['key'] == $data['id']) {
             // If yes, simply override it.
             $strings[$data['key']] = $data['override'];
         } else {
             // If no, delete the old string and prepend the new one.
             unset($strings[$data['id']]);
             $strings = array($data['key'] => $data['override']) + $strings;
         }
     } else {
         // If it is a new override simply prepend it.
         $strings = array($data['key'] => $data['override']) + $strings;
     }
     foreach ($strings as $key => $string) {
         $strings[$key] = str_replace('"', '"_QQ_"', $string);
     }
     // Write override.ini file with the strings.
     $registry = new Registry($strings);
     $reg = $registry->toString('INI');
     if (!JFile::write($filename, $reg)) {
         return false;
     }
     // If the override should be stored for both clients save
     // it also for the other one and prevent endless recursion.
     if (isset($data['both']) && $data['both'] && !$opposite_client) {
         return $this->save($data, true);
     }
     return true;
 }
Example #22
0
 /**
  * @testdox  The Registry can be converted to a string
  *
  * @covers   Joomla\Registry\Registry::toString
  */
 public function testTheRegistryCanBeConvertedToAString()
 {
     $a = new Registry(array('foo1' => 'testtostring1', 'foo2' => 'testtostring2', 'config' => array('foo3' => 'testtostring3')));
     $a->set('foo1', 'testtostring1');
     $a->set('foo2', 'testtostring2');
     $a->set('config.foo3', 'testtostring3');
     $this->assertSame('{"foo1":"testtostring1","foo2":"testtostring2","config":{"foo3":"testtostring3"}}', trim($a->toString('JSON')), 'The Registry is converted to a JSON string.');
 }