protected function saveOldValues($data) { $app = JFactory::getApplication(); if (!$app->isAdmin()) { return false; } // An array name with the names of the arrays that contain parameters for components $comParams = array('nocache', 'skip', 'useJoomlaRouter', 'notTranslateURLList', 'notInsertIsoCodeList', 'shDoNotOverrideOwnSef', 'useJoomsefRouter', 'useAcesefRouter', 'compEnablePageId', 'defaultComponentStringList'); // Same thing for the language params $languageParams = array('pageTexts', 'shLangTranslateList', 'shLangInsertCodeList'); $newParams = array(); foreach ($data as $param => $val) { if (in_array($param, $comParams)) { //-->this will be mostly hardcoded and it's basically the reverse process of the one that loads the parameters from the json(database) //-->into the config class switch ($param) { case 'nocache': foreach ($val as $com) { $newParams['com_' . $com . '___manageURL'] = 1; } break; case 'skip': foreach ($val as $com) { $newParams['com_' . $com . '___manageURL'] = 2; } break; case 'useJoomlaRouter': foreach ($val as $com) { $newParams['com_' . $com . '___manageURL'] = 3; } break; case 'notTranslateURLList': foreach ($val as $com) { $newParams['com_' . $com . '___translateURL'] = 1; } break; case 'notInsertIsoCodeList': foreach ($val as $com) { $newParams['com_' . $com . '___insertIsoCode'] = 1; } break; case 'shDoNotOverrideOwnSef': foreach ($val as $com) { $newParams['com_' . $com . '___shDoNotOverrideOwnSef'] = 1; } break; case 'useJoomsefRouter': foreach ($val as $com) { $newParams['com_' . $com . '___shDoNotOverrideOwnSef'] = 30; } break; case 'useAcesefRouter': foreach ($val as $com) { $newParams['com_' . $com . '___shDoNotOverrideOwnSef'] = 40; } break; case 'compEnablePageId': foreach ($val as $com) { $newParams['com_' . $com . '___compEnablePageId'] = 1; } break; case 'defaultComponentStringList': foreach ($val as $com => $str) { $newParams['com_' . $com . '___defaultComponentString'] = $str; } break; } //--unseting the array param because he will be replaced the new parameters in the datas array that will become the json object unset($data[$param]); } elseif (in_array($param, $languageParams)) { switch ($param) { case 'pageTexts': foreach ($val as $lang => $paramval) { $newParams['languages_' . $lang . '_pageText'] = $paramval; } break; case 'shLangTranslateList': foreach ($val as $lang => $paramval) { $newParams['languages_' . $lang . '_translateURL'] = $paramval; } break; case 'shLangInsertCodeList': foreach ($val as $lang => $paramval) { $newParams['languages_' . $lang . '_insertCode'] = $paramval; } break; } //--unseting the array param because he will be replaced the new parameters in the datas array that will become the json object unset($data[$param]); } elseif ($val === false) { $data[$param] = 0; } elseif ($val === true) { $data[$param] = 1; } } // get plugins details $plugin = JPluginHelper::getPlugin('system', 'shmobile'); $params = new JRegistry(); $params->loadString($plugin->params); $newParams['mobile_switch_enabled'] = $params->get('mobile_switch_enabled', 0); $newParams['mobile_template'] = $params->get('mobile_template', ''); //merging the new parameters into the datas array that will become the json object; $data = array_merge($data, $newParams); //-->this code is running also on the site part, not only to the admin, so we need to check out if the JPATH_BASE is going to administrator side $comConfigModel = Sh404sefHelperGeneral::getComConfigComponentModel(); $component = $comConfigModel->getComponent(); if (empty($component->id)) { return false; } // Attempt to save the configuration. $configArray = array('params' => $data, 'id' => $component->id, 'option' => 'com_sh404sef'); $comConfigModel->save($configArray); }
public function getForm() { // import com_config model $comConfigModel = Sh404sefHelperGeneral::getComConfigComponentModel('com_sh404sef', JPATH_ADMINISTRATOR . '/components/com_sh404sef/configuration'); $form = $comConfigModel->getForm(); $component = $comConfigModel->getComponent(); // version prefix $this->joomlaVersionPrefix = Sh404sefHelperGeneral::getJoomlaVersionPrefix(); $method = '_getByComponentField' . $this->joomlaVersionPrefix; // inject the by components part in the form $field = $this->{$method}(); $form->setField($field); // inject the languages part in the form $method = '_getLanguagesField' . $this->joomlaVersionPrefix; $field = $this->{$method}(); $form->setField($field); // inject the current content of the 404 error page as default value in the txt404 form field $currentErrorPageContent = $this->_getErrorPageContent(); $form->setFieldAttribute('txt404', 'default', $currentErrorPageContent); // inject analytics group field in form $field = $this->_getAnalyticsGroupsField(); $form->setField($field); // merge categories in jooomla tab $field = $this->_getCategoriesField(); $form->setField($field); // Bind the form to the data. if ($form && $component->params) { $form->bind($component->params); } // make sure Analytics password is not visible in the source code of the page $form->setValue('analyticsPassword', null, '********'); // special processing for various parameters: turn string into an array // security $form->setValue('shSecOnlyNumVars', null, implode("\n", $form->getValue('shSecOnlyNumVars', null, array()))); $form->setValue('shSecAlphaNumVars', null, implode("\n", $form->getValue('shSecAlphaNumVars', null, array()))); $form->setValue('shSecNoProtocolVars', null, implode("\n", $form->getValue('shSecNoProtocolVars', null, array()))); $form->setValue('ipWhiteList', null, implode("\n", $form->getValue('ipWhiteList', null, array()))); $form->setValue('ipBlackList', null, implode("\n", $form->getValue('ipBlackList', null, array()))); $form->setValue('uAgentWhiteList', null, implode("\n", $form->getValue('uAgentWhiteList', null, array()))); $form->setValue('uAgentBlackList', null, implode("\n", $form->getValue('uAgentBlackList', null, array()))); // analytics $form->setValue('analyticsExcludeIP', null, implode("\n", $form->getValue('analyticsExcludeIP', null, array()))); // read mobile params from the mobile plugin, not from the component config, which only has a copy $plugin = JPluginHelper::getPlugin('system', 'shmobile'); $params = new JRegistry(); $params->loadString($plugin->params); $form->setValue('mobile_switch_enabled', null, $params->get('mobile_switch_enabled', 0)); $form->setValue('mobile_template', null, $params->get('mobile_template', '')); // inject a link to shLib plugin params for cache settings $form->setFieldAttribute('UrlCacheHandlerLink', 'additionaltext', '<span class = "btn sh404sef-textinput"><a href="' . Sh404sefHelperGeneral::getShLibPluginLink() . '" target="_blank">' . JText::_('COM_SH404SEF_CONFIGURE_SHLIB_PLUGIN') . '</a></span>'); return $form; }