public function onExtensionAfterSave($context, $table, $isNew) { if (!($context == 'com_plugins.plugin' && $table->element == 'giftd')) { return true; } $app = JFactory::getApplication(); $code = $app->getUserState('plugins.system.giftd.code', ''); $token_prefix = $app->getUserState('plugins.system.giftd.token_prefix', ''); $app->setUserState('plugins.system.giftd.code', ''); $app->setUserState('plugins.system.giftd.token_prefix', ''); if (!empty($code) || !empty($token_prefix)) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select($db->quoteName('params'))->from($db->quoteName('#__extensions'))->where($db->quoteName('element') . ' = ' . $db->quote('giftd'))->where($db->quoteName('type') . ' = ' . $db->quote('plugin')); $params = new Registry($db->setQuery($query, 0, 1)->loadResult()); if (!empty($code)) { $params->set('partner_code', $code); } if (!empty($token_prefix)) { $params->set('partner_token_prefix', $token_prefix); } $query->clear()->update($db->quoteName('#__extensions')); $query->set($db->quoteName('params') . '= ' . $db->quote((string) $params)); $query->where($db->quoteName('element') . ' = ' . $db->quote('giftd')); $query->where($db->quoteName('type') . ' = ' . $db->quote('plugin')); $db->setQuery($query); $db->execute(); } return true; }
/** * Method to perform sanity checks on the JTable instance properties to ensure * they are safe to store in the database. Child classes should override this * method to make sure the data they are storing in the database is safe and * as expected before storage. * * @return boolean True if the instance is sane and able to be stored in the database. * * @since 2.5 */ public function check() { try { parent::check(); } catch (\Exception $e) { $this->setError($e->getMessage()); return false; } if (trim($this->alias) == '') { $this->alias = $this->title; } $this->alias = JApplicationHelper::stringURLSafe($this->alias); if (trim(str_replace('-', '', $this->alias)) == '') { $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s'); } $params = new Registry($this->params); $nullDate = $this->_db->getNullDate(); $d1 = $params->get('d1', $nullDate); $d2 = $params->get('d2', $nullDate); // Check the end date is not earlier than the start date. if ($d2 > $nullDate && $d2 < $d1) { // Swap the dates. $params->set('d1', $d2); $params->set('d2', $d1); $this->params = (string) $params; } return true; }
/** * Sets the state for the model object * * @param \JModel $model Model object * * @return Registry * * @since 2.0 */ protected function initializeState(\JModel $model) { $state = new Registry(); // Load the parameters. $params = \JComponentHelper::getParams('com_patchtester'); $state->set('github_user', $params->get('org', 'joomla')); $state->set('github_repo', $params->get('repo', 'joomla-cms')); return $state; }
/** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return Container Returns the container to support chaining. * * @since 1.0 * @throws \RuntimeException */ public function register(Container $container) { return $container->set('BabDev\\Transifex\\Transifex', function () use($container) { $options = new Registry(); /* @var \JTracker\Application $app */ $app = $container->get('app'); $options->set('api.username', $app->get('transifex.username')); $options->set('api.password', $app->get('transifex.password')); // Instantiate Transifex return new Transifex($options); })->alias('transifex', 'BabDev\\Transifex\\Transifex'); }
public function populateState() { //get states $app = \Cobalt\Container::fetch('app'); $filter_order = $app->getUserStateFromRequest('Categories.filter_order', 'filter_order', 'c.name'); $filter_order_Dir = $app->getUserStateFromRequest('Categories.filter_order_Dir', 'filter_order_Dir', 'asc'); $state = new Registry(); //set states $state->set('Categories.filter_order', $filter_order); $state->set('Categories.filter_order_Dir', $filter_order_Dir); $this->setState($state); }
/** * Gets a Github object. * * @param Container $c A DI container. * * @return Github * * @since 2.0 */ public function getGithub(Container $c) { /* @var $config Registry */ $config = $c->get('config'); /* @var $input Joomla\Input\Input */ $input = $c->get('input'); $options = new Registry(); $options->set('headers.Accept', 'application/vnd.github.html+json'); $options->set('api.username', $input->get('username', $config->get('api.username'))); $options->set('api.password', $input->get('password', $config->get('api.password'))); $options->set('api.url', $config->get('api.url')); $github = new Github($options); return $github; }
/** * Retrieves an instance of the GitHub object * * @param \Joomla\Application\AbstractApplication $app Application object * @param boolean $useBot Flag to use a bot account. * @param string $botUser The bot account user name. * @param string $botPassword The bot account password. * * @return GitHub * * @since 1.0 * @throws \RuntimeException */ public static function getInstance($app, $useBot = false, $botUser = '', $botPassword = '') { $options = new Registry(); // Check if we're in the web application and a token exists if ($app instanceof \JTracker\Application) { $session = $app->getSession(); $token = $session->get('gh_oauth_access_token'); } else { $token = false; } // If a token is active in the session (web app), and we haven't been instructed to use a bot account, use that for authentication if ($token && !$useBot) { $options->set('gh.token', $token); } else { // Check if credentials are supplied if ($botUser && $botPassword) { $user = $botUser; $password = $botPassword; } else { // Check for support for multiple accounts $accounts = $app->get('github.accounts'); if ($accounts) { $user = isset($accounts[0]->username) ? $accounts[0]->username : null; $password = isset($accounts[0]->password) ? $accounts[0]->password : null; // Store the other accounts $options->set('api.accounts', $accounts); } else { // Support for a single account $user = $app->get('github.username'); $password = $app->get('github.password'); } } // Add the username and password to the options object if both are set if ($user && $password) { // Set the options from the first account $options->set('api.username', $user); $options->set('api.password', $password); } } // The cURL extension is required to properly work. $transport = HttpFactory::getAvailableDriver($options, array('curl')); // Check if we *really* got a cURL transport... if (!$transport instanceof Curl) { throw new \RuntimeException('Please enable cURL.'); } $http = new Http($options, $transport); // Instantiate the object return new Github($options, $http); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void * * @since 3.0 */ protected function setUp() { parent::setUp(); // Store the factory state so we can mock the necessary objects $this->saveFactoryState(); JFactory::$application = $this->getMockCmsApp(); JFactory::$config = $this->getMockConfig(); JFactory::$session = $this->getMockSession(); JFactory::$language = JLanguage::getInstance('en-GB'); // Set up our mock config $this->config = JFactory::getConfig(); $this->config->set('helpurl', 'https://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}'); // Load the admin en-GB.ini language file JFactory::getLanguage()->load('', JPATH_ADMINISTRATOR); }
/** * Initializes the JGithub object * * @return \JGithub * * @since 2.0 */ public static function initializeGithub() { $params = \JComponentHelper::getParams('com_patchtester'); $options = new Registry(); // If an API token is set in the params, use it for authentication if ($params->get('gh_token', '')) { $options->set('gh.token', $params->get('gh_token', '')); } elseif ($params->get('gh_user', '') && $params->get('gh_password')) { $options->set('api.username', $params->get('gh_user', '')); $options->set('api.password', $params->get('gh_password', '')); } else { \JFactory::getApplication()->enqueueMessage(\JText::_('COM_PATCHTESTER_NO_CREDENTIALS'), 'notice'); } return new \JGithub($options); }
/** * Overrides JGithub constructor to initialise the api property. * * @param mixed $input An optional argument to provide dependency injection for the application's * input object. If the argument is a JInputCli object that object will become * the application's input object, otherwise a default input object is created. * @param mixed $config An optional argument to provide dependency injection for the application's * config object. If the argument is a JRegistry object that object will become * the application's config object, otherwise a default config object is created. * @param mixed $dispatcher An optional argument to provide dependency injection for the application's * event dispatcher. If the argument is a JDispatcher object that object will become * the application's event dispatcher, if it is null then the default event dispatcher * will be created based on the application's loadDispatcher() method. * * @see loadDispatcher() * @since 11.1 */ public function __construct() { parent::__construct(); $options = new Registry(); $options->set('headers.Accept', 'application/vnd.github.html+json'); $this->api = new Github($options); }
public function onExtensionBeforeSave($context, $table, $isNew) { if (!($context == 'com_plugins.plugin' && $table->element == 'giftd')) { return true; } $app = JFactory::getApplication(); $input = $app->input; $data = $input->get('jform', array(), 'array'); $params = $data['params']; $userId = $this->params->get('user_id', ''); $apiKey = $this->params->get('api_key', ''); if (empty($params['api_key']) && !empty($userId) || empty($params['api_key']) && !empty($apiKey)) { $client = new Giftd_Client($userId, $apiKey); $client->query("joomla/uninstall"); return true; } if (!empty($params['api_key']) && $params['api_key'] == $this->params->get('api_key') || empty($params['user_id'])) { return true; } $user = JFactory::getUser(); $jconfig = JFactory::getConfig(); $data = array('email' => $user->get('email', ''), 'phone' => '', 'name' => $user->get('name', ''), 'url' => JUri::root(), 'title' => $jconfig->get('sitename', ''), 'joomla_version' => JVERSION); $this->loadShopData($data); $client = new Giftd_Client($params['user_id'], $params['api_key']); $result = $client->query("joomla/install", $data); if ($result['type'] == 'data') { if (!empty($result['data'])) { $requestData = $result['data']; if (!empty($requestData['token_prefix']) && !empty($requestData['code'])) { $code = $requestData['code']; $token_prefix = $requestData['token_prefix']; $this->params->set('partner_token_prefix', $token_prefix); $this->params->set('partner_code', $code); $this->params->set('api_key', $params['api_key']); $this->params->set('user_id', $params['user_id']); $this->updateJavaScript(); $tableParams = new Registry($table->params); $tableParams->set('partner_token_prefix', $token_prefix); $tableParams->set('partner_code', $code); $table->params = (string) $tableParams; } } } else { $app->enqueueMessage(JText::_('PLG_SYSTEM_GIFT_ERROR_QUERY'), 'error'); } return true; }
/** * Display function * * @param string $tpl The name of the template file to parse; automatically searches through the template paths. * * @return mixed * * @since 1.7.2 */ public function display($tpl = null) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $state = $this->get('State'); $items = $this->get('Items'); $this->return = $this->get('ReturnPage'); // Get the parameters $params = JComponentHelper::getParams('com_churchdirectory'); $params->merge($state->params); // Check for errors. if (count($errors = $this->get('Errors'))) { $app->enqueueMessage(implode("\n", $errors), 'error'); return false; } $document = JFactory::getDocument(); $renderer = $document->loadRenderer('module'); $mod_params = ['style' => 'xhtml']; $contents = ''; $mod = JModuleHelper::getModule('mod_finder'); $registry = new Registry; $registry->loadString($mod->params); $registry->set('searchfilter', 'paramvalue'); $registry->set('show_advanced', '0'); $registry->set('opensearch', '1'); $registry->set('set_itemid', $app->input->getInt('Itemid')); $registry->set('size-lbl', '12'); $registry->set('show_button', '1'); $registry->set('button_pos', 'right'); $mod->params = (string) $registry; $contents .= $renderer->render($mod, $mod_params); $this->search = $contents; $this->renderHelper = new ChurchDirectoryRenderHelper; $this->params = & $params; $this->user = & $user; $this->items = & $items; $this->prepareDocument(); return parent::display($tpl); }
/** * Set data into the session store * * @param string $name Name of a variable. * @param mixed $value Value of a variable. * * @return mixed Old value of a variable. * * @since 4.0 */ public function set($name, $value = null) { if (!$this->isStarted()) { $this->start(); } $old = $this->data->get($name); $this->data->set($name, $value); return $old; }
/** * 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 } }
public static function getAjax() { $module = JModuleHelper::getModule('mod_' . JFactory::getApplication()->input->get('module')); if (empty($module)) { return false; } JFactory::getLanguage()->load($module->module); $params = new Registry($module->params); $params->set('ajax', 0); ob_start(); require JPATH_ROOT . '/modules/' . $module->module . '/' . $module->module . '.php'; return ob_get_clean(); }
/** * Constructor. * * @param \Windwalker\DI\Container $container * @param \CodeGenerator\IO\IOInterface $io * @param Registry $config */ public function __construct(Container $container, IOInterface $io, Registry $config = null) { // Get item & list name $ctrl = $config['ctrl'] ?: $io->getArgument(1); $ctrl = explode('.', $ctrl); $inflector = \JStringInflector::getInstance(); if (empty($ctrl[0])) { $ctrl[0] = 'item'; } if (empty($ctrl[1])) { $ctrl[1] = $inflector->toPlural($ctrl[0]); } list($itemName, $listName) = $ctrl; $this->replace['extension.element.lower'] = strtolower($config['element']); $this->replace['extension.element.upper'] = strtoupper($config['element']); $this->replace['extension.element.cap'] = ucfirst($config['element']); $this->replace['extension.name.lower'] = strtolower($config['name']); $this->replace['extension.name.upper'] = strtoupper($config['name']); $this->replace['extension.name.cap'] = ucfirst($config['name']); $this->replace['controller.list.name.lower'] = strtolower($listName); $this->replace['controller.list.name.upper'] = strtoupper($listName); $this->replace['controller.list.name.cap'] = ucfirst($listName); $this->replace['controller.item.name.lower'] = strtolower($itemName); $this->replace['controller.item.name.upper'] = strtoupper($itemName); $this->replace['controller.item.name.cap'] = ucfirst($itemName); // Set replace to config. foreach ($this->replace as $key => $val) { $config->set('replace.' . $key, $val); } // Set copy dir. $config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client'])); $config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']); $config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']); // Replace DS $config['dir.dest'] = Path::clean($config['dir.dest']); $config['dir.tmpl'] = Path::clean($config['dir.tmpl']); $config['dir.src'] = Path::clean($config['dir.src']); parent::__construct($container, $io, $config); }
/** * Method to set the value of a field. If the field does not exist in the form then the method * will return false. * * @param string $name The name of the field for which to set the value. * @param string $group The optional dot-separated form group path on which to find the field. * @param mixed $value The value to set for the field. * * @return boolean True on success. * * @since 11.1 */ public function setValue($name, $group = null, $value = null) { // If the field does not exist return false. if (!$this->findField($name, $group)) { return false; } // If a group is set use it. if ($group) { $this->data->set($group . '.' . $name, $value); } else { $this->data->set($name, $value); } return true; }
/** * 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; }
/** * Gets a configuration object. * * @param Container $c A DI container. * * @return Registry * * @since 2.0 * @throws \LogicException if the configuration file does not exist. * @throws \UnexpectedValueException if the configuration file could not be parsed. */ public function getConfig(Container $c) { if (!file_exists($this->path)) { throw new \LogicException('Configuration file does not exist.', 500); } /** @var \Joomla\Input\Input $input */ $input = $c->get('input'); $json = json_decode(file_get_contents($this->path)); if (null === $json) { throw new \UnexpectedValueException('Configuration file could not be parsed.', 500); } $temp = new Registry($json); $profile = $input->get('profile'); if ($temp->get('profiles.' . $profile)) { $config = new Registry($temp->get('profiles.' . $profile)); } else { $config = new Registry($temp->get('profiles.default')); } // Automatically set the path for `/etc/`. $config->set('path.etc', dirname($this->path)); return $config; }
/** * Initializes the GitHub object * * @return GitHub * * @since 2.0 */ public static function initializeGithub() { $params = \JComponentHelper::getParams('com_patchtester'); $options = new Registry(); // Set a user agent for the request $options->set('userAgent', 'PatchTester/3.0'); // Set the default timeout to 120 seconds $options->set('timeout', 120); // Set the API URL $options->set('api.url', 'https://api.github.com'); // If an API token is set in the params, use it for authentication if ($params->get('gh_token', '')) { $options->set('gh.token', $params->get('gh_token', '')); } elseif ($params->get('gh_user', '') && $params->get('gh_password')) { $options->set('api.username', $params->get('gh_user', '')); $options->set('api.password', $params->get('gh_password', '')); } else { \JFactory::getApplication()->enqueueMessage(\JText::_('COM_PATCHTESTER_NO_CREDENTIALS'), 'notice'); } return new GitHub($options); }
/** * New join make the group, group elements and formgroup entries for the join data * * @param string $tableKey table key * @param string $joinTableKey join to table key * @param string $joinType join type * @param string $joinTable join to table * @param string $joinTableFrom join table * @param bool $isRepeat is the group a repeat * * @return object $join returns new join object */ protected function makeNewJoin($tableKey, $joinTableKey, $joinType, $joinTable, $joinTableFrom, $isRepeat) { $groupData = FabrikWorker::formDefaults('group'); $groupData['name'] = $this->getTable()->label . '- [' . $joinTable . ']'; $groupData['label'] = $joinTable; $groupId = $this->createLinkedGroup($groupData, true, $isRepeat); $join = $this->getTable('Join'); $join->set('id', null); $join->set('list_id', $this->getState('list.id')); $join->set('join_from_table', $joinTableFrom); $join->set('table_join', $joinTable); $join->set('table_join_key', $joinTableKey); $join->set('table_key', str_replace('`', '', $tableKey)); $join->set('join_type', $joinType); $join->set('group_id', $groupId); /** * Create the 'pk' param. Can't just call front end setJoinPk() for gory * reasons, so do this by steam. */ $joinParams = new Registry(); /** * This is kind of expensive, as getPrimaryKeyAndExtra() method does a table lookup, * but I don't think we know what the PK of the joined table is any other * way at this point. */ $pk = $this->getFEModel()->getPrimaryKeyAndExtra($join->get('table_join')); if ($pk !== false) { // If it didn't return false, getPrimaryKeyAndExtra will have created and array with at least one key $pk_col = FArrayHelper::getValue($pk[0], 'colname', ''); if (!empty($pk_col)) { $db = FabrikWorker::getDbo(true); $pk_col = $join->table_join . '.' . $pk_col; $joinParams->set('pk', $db->qn($pk_col)); } } $join->set('params', (string) $joinParams); $join->store(); $this->createLinkedElements($groupId, $joinTable); return $join; }
/** * Tests the JApplicationWeb::redirect method with assorted URL's. * * @param string $url @todo * @param string $base @todo * @param string $request @todo * @param string $expected @todo * * @return void * * @dataProvider getRedirectData * @since 11.3 */ public function testRedirectWithUrl($url, $base, $request, $expected) { // Inject the client information. TestReflection::setValue($this->class, 'client', (object) array('engine' => JApplicationWebClient::GECKO)); // Inject the internal configuration. $config = new Registry(); $config->set('uri.base.full', $base); $config->set('uri.request', $request); TestReflection::setValue($this->class, 'config', $config); $this->class->redirect($url, false); $this->assertEquals('Location: ' . $expected, $this->class->headers[1][0]); }
/** * Tests the setState method with an invalid data object * * @return void * * @since 3.0 */ public function testSetStateBadData() { // Set up our test object $test = new Registry(); $test->set('string', 'Testing FinderIndexer::setState()'); // Attempt to set the state $this->assertFalse(FinderIndexer::setState($test), 'setState method is not compatible with Registry'); }
/** * Populate user state requests */ public function populateState() { //get states $app = \Cobalt\Container::fetch('app'); //determine view so we set correct states $view = $this->view; $layout = $this->layout; // if ( $view == "events" && ( $layout == "default" || $layout == "list" || $layout == null ) ) { // Get pagination request variables $limit = $app->getUserStateFromRequest("Event." . $view . '_' . $layout . '_limit', 'limit', 10); $limitstart = $app->getUserStateFromRequest("Event." . $view . '_' . $layout . '_limitstart', 'limitstart', 0); // In case limit has been changed, adjust it $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0; $state = new Registry(); $state->set("Event." . $view . '_limit', $limit); $state->set("Event." . $view . '_limitstart', $limitstart); //set default filter states for reports $filterOrder = "CASE e.type WHEN 'event' THEN e.start_time WHEN 'task' THEN e.due_date ELSE e.due_date END"; $filterOrderDir = "ASC"; $filter_order = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_filter_order', 'filter_order', $filterOrder); $filter_order_Dir = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_filter_order_Dir', 'filter_order_Dir', $filterOrderDir); $status_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_status', 'status', 0); $type_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_type', 'type', 'all'); $category_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_category', 'category', 'any'); $due_date_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_due_date', 'due_date', 'any'); $association_type_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_association_type', 'association_type', 'any'); $assignee_id_filter = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_assignee_id', 'assignee_id', UsersHelper::getUserId()); $assignee_filter_type = $app->getUserStateFromRequest('Event.' . $view . '_' . $layout . '_assignee_filter_type', 'assignee_filter_type', 'individual'); //set states for reports $state->set('Event.' . $view . '_' . $layout . '_filter_order', $filter_order); $state->set('Event.' . $view . '_' . $layout . '_filter_order_Dir', $filter_order_Dir); $state->set('Event.' . $view . '_' . $layout . '_status', $status_filter); $state->set('Event.' . $view . '_' . $layout . '_type', $type_filter); $state->set('Event.' . $view . '_' . $layout . '_category', $category_filter); $state->set('Event.' . $view . '_' . $layout . '_due_date', $due_date_filter); $state->set('Event.' . $view . '_' . $layout . '_association_type', $association_type_filter); $state->set('Event.' . $view . '_' . $layout . '_assignee_id', $assignee_id_filter); $state->set('Event.' . $view . '_' . $layout . '_assignee_filter_type', $assignee_filter_type); $this->setState($state); //} }
/** * Custom uninstall method * * @param string $eid The tag of the language to uninstall * * @return mixed Return value for uninstall method in component uninstall file * * @since 3.1 */ public function uninstall($eid) { // Load up the extension details $extension = JTable::getInstance('extension'); $extension->load($eid); // Grab a copy of the client details $client = JApplicationHelper::getClientInfo($extension->get('client_id')); // Check the element isn't blank to prevent nuking the languages directory...just in case $element = $extension->get('element'); if (empty($element)) { JLog::add(JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_ELEMENT_EMPTY'), JLog::WARNING, 'jerror'); return false; } // Check that the language is not protected, Normally en-GB. $protected = $extension->get('protected'); if ($protected == 1) { JLog::add(JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_PROTECTED'), JLog::WARNING, 'jerror'); return false; } // Verify that it's not the default language for that client $params = JComponentHelper::getParams('com_languages'); if ($params->get($client->name) == $element) { JLog::add(JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DEFAULT'), JLog::WARNING, 'jerror'); return false; } // Construct the path from the client, the language and the extension element name $path = $client->path . '/language/' . $element; // Get the package manifest object and remove media $this->parent->setPath('source', $path); // We do findManifest to avoid problem when uninstalling a list of extension: getManifest cache its manifest file $this->parent->findManifest(); $this->setManifest($this->parent->getManifest()); $this->parent->removeFiles($this->getManifest()->media); // Check it exists if (!JFolder::exists($path)) { // If the folder doesn't exist lets just nuke the row as well and presume the user killed it for us $extension->delete(); JLog::add(JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_PATH_EMPTY'), JLog::WARNING, 'jerror'); return false; } if (!JFolder::delete($path)) { // If deleting failed we'll leave the extension entry in tact just in case JLog::add(JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DIRECTORY'), JLog::WARNING, 'jerror'); return false; } // Remove the extension table entry $extension->delete(); // Setting the language of users which have this language as the default language $db = JFactory::getDbo(); $query = $db->getQuery(true)->from('#__users')->select('*'); $db->setQuery($query); $users = $db->loadObjectList(); if ($client->name == 'administrator') { $param_name = 'admin_language'; } else { $param_name = 'language'; } $count = 0; foreach ($users as $user) { $registry = new Registry(); $registry->loadString($user->params); if ($registry->get($param_name) == $element) { $registry->set($param_name, ''); $query->clear()->update('#__users')->set('params=' . $db->quote($registry))->where('id=' . (int) $user->id); $db->setQuery($query); $db->execute(); $count++; } } if (!empty($count)) { JLog::add(JText::plural('JLIB_INSTALLER_NOTICE_LANG_RESET_USERS', $count), JLog::NOTICE, 'jerror'); } // All done! return true; }
/** * Start a session. * * Creates a session (or resumes the current one based on the state of the session) * * @return boolean true on success * * @since 11.1 */ protected function _start() { $this->_handler->start(); // Ok let's unserialize the whole thing // Try loading data from the session if (isset($_SESSION['joomla']) && !empty($_SESSION['joomla'])) { $data = $_SESSION['joomla']; $data = base64_decode($data); $this->data = unserialize($data); } // Temporary, PARTIAL, data migration of existing session data to avoid logout on update from J < 3.4.7 if (isset($_SESSION['__default']) && !empty($_SESSION['__default'])) { $migratableKeys = array("user", "session.token", "session.counter", "session.timer.start", "session.timer.last", "session.timer.now"); foreach ($migratableKeys as $migratableKey) { if (!empty($_SESSION['__default'][$migratableKey])) { // Don't overwrite existing session data if (!is_null($this->data->get('__default.' . $migratableKey, null))) { continue; } $this->data->set('__default.' . $migratableKey, $_SESSION['__default'][$migratableKey]); unset($_SESSION['__default'][$migratableKey]); } } /** * Finally, empty the __default key since we no longer need it. Don't unset it completely, we need this * for the administrator/components/com_admin/script.php to detect upgraded sessions and perform a full * session cleanup. */ $_SESSION['__default'] = array(); } return true; }
/** * 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; }
/** * Method to save the configuration data. * * @param array $data An array containing all global config data. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function save($data) { $app = JFactory::getApplication(); // Check that we aren't setting wrong database configuration $options = array('driver' => $data['dbtype'], 'host' => $data['host'], 'user' => $data['user'], 'password' => JFactory::getConfig()->get('password'), 'database' => $data['db'], 'prefix' => $data['dbprefix']); try { $dbc = JDatabaseDriver::getInstance($options)->getVersion(); } catch (Exception $e) { $app->enqueueMessage(JText::_('JLIB_DATABASE_ERROR_DATABASE_CONNECT'), 'error'); return false; } // Check if we can set the Force SSL option if ((int) $data['force_ssl'] !== 0 && (int) $data['force_ssl'] !== (int) JFactory::getConfig()->get('force_ssl', '0')) { try { // Make an HTTPS request to check if the site is available in HTTPS. $host = JUri::getInstance()->getHost(); $options = new \Joomla\Registry\Registry(); $options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0'); $options->set('transport.curl', array(CURLOPT_SSL_VERIFYPEER => false)); $response = JHttpFactory::getHttp($options)->get('https://' . $host . JUri::root(true) . '/', array('Host' => $host), 10); // If available in HTTPS check also the status code. if (!in_array($response->code, array(200, 503, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310), true)) { throw new RuntimeException('HTTPS version of the site returned an invalid HTTP status code.'); } } catch (RuntimeException $e) { $data['force_ssl'] = 0; // Also update the user state $app->setUserState('com_config.config.global.data.force_ssl', 0); // Inform the user $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_SSL_NOT_AVAILABLE'), 'warning'); } } // 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(JFactory::getUser()->get('id')); $myRules = $rules->getData(); $hasSuperAdmin = $myRules['core.admin']->allow($myGroups); if (!$hasSuperAdmin) { $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN'), 'error'); return false; } $asset = JTable::getInstance('asset'); if ($asset->loadByName('root.1')) { $asset->rules = (string) $rules; if (!$asset->check() || !$asset->store()) { $app->enqueueMessage(JText::_('SOME_ERROR_CODE'), 'error'); return; } } else { $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND'), 'error'); return false; } unset($data['rules']); } // Save the text filters if (isset($data['filters'])) { $registry = new Registry(); $registry->loadArray(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()) { $app->enqueueMessage(JText::_('SOME_ERROR_CODE'), 'error'); return; } } else { $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND'), 'error'); return false; } unset($data['filters']); } // Get the previous configuration. $prev = new JConfig(); $prev = JArrayHelper::fromObject($prev); // Merge the new data in. We do this to preserve values that were not in the form. $data = array_merge($prev, $data); /* * Perform miscellaneous options based on configuration settings/changes. */ // Escape the offline message if present. if (isset($data['offline_message'])) { $data['offline_message'] = JFilterOutput::ampReplace($data['offline_message']); } // Purge the database session table if we are changing to the database handler. if ($prev['session_handler'] != 'database' && $data['session_handler'] == 'database') { $table = JTable::getInstance('session'); $table->purge(-1); } if (empty($data['cache_handler'])) { $data['caching'] = 0; } $path = JPATH_SITE . '/cache'; // Give a warning if the cache-folder can not be opened if ($data['caching'] > 0 && $data['cache_handler'] == 'file' && @opendir($path) == false) { JLog::add(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), JLog::WARNING, 'jerror'); $data['caching'] = 0; } // Clean the cache if disabled but previously enabled. if (!$data['caching'] && $prev['caching']) { $cache = JFactory::getCache(); $cache->clean(); } // Create the new configuration object. $config = new Registry('config'); $config->loadArray($data); // Overwrite the old FTP credentials with the new ones. $temp = JFactory::getConfig(); $temp->set('ftp_enable', $data['ftp_enable']); $temp->set('ftp_host', $data['ftp_host']); $temp->set('ftp_port', $data['ftp_port']); $temp->set('ftp_user', $data['ftp_user']); $temp->set('ftp_pass', $data['ftp_pass']); $temp->set('ftp_root', $data['ftp_root']); // Clear cache of com_config component. $this->cleanCache('_system', 0); $this->cleanCache('_system', 1); // Write the configuration file. return $this->writeConfigFile($config); }
/** * Set an option for the JOpenstreetmapObject instance. * * @param string $key The name of the option to set. * @param mixed $value The option value to set. * * @return JOpenstreetmapObject This object for method chaining. * * @since 13.1 */ public function setOption($key, $value) { $this->options->set($key, $value); return $this; }
/** * Overloaded bind function * * @param array $array Named array to bind * @param mixed $ignore An optional array or space separated list of properties to ignore while binding. * * @return mixed Null if operation was satisfactory, otherwise returns an error * * @since 1.5 */ public function bind($array, $ignore = array()) { if (isset($array['params']) && is_array($array['params'])) { $registry = new Registry(); $registry->loadArray($array['params']); if ((int) $registry->get('width', 0) < 0) { $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_WIDTH_LABEL'))); return false; } if ((int) $registry->get('height', 0) < 0) { $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_HEIGHT_LABEL'))); return false; } // Converts the width and height to an absolute numeric value: $width = abs((int) $registry->get('width', 0)); $height = abs((int) $registry->get('height', 0)); // Sets the width and height to an empty string if = 0 $registry->set('width', $width ? $width : ''); $registry->set('height', $height ? $height : ''); $array['params'] = (string) $registry; } if (isset($array['imptotal'])) { $array['imptotal'] = abs((int) $array['imptotal']); } return parent::bind($array, $ignore); }