AAAAhome/academiac/www/administrator/components/com_languages/models/override.php000064400000013104151373174200023675 0ustar00loadForm('com_languages.override', 'override', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } $client = $this->getState('filter.client', 'site'); $language = $this->getState('filter.language', 'en-GB'); $langName = JLanguage::getInstance($language)->getName(); if (!$langName) { // If a language only exists in frontend, it's meta data cannot be // loaded in backend at the moment, so fall back to the language tag $langName = $language; } $form->setValue('client', null, JText::_('COM_LANGUAGES_VIEW_OVERRIDE_CLIENT_'.strtoupper($client))); $form->setValue('language', null, JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDE_LANGUAGE', $langName, $language)); $form->setValue('file', null, JPath::clean(constant('JPATH_'.strtoupper($client)) . '/language/overrides/' . $language . '.override.ini')); return $form; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form * * @since 2.5 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_languages.edit.override.data', array()); if (empty($data)) { $data = $this->getItem(); } return $data; } /** * Method to get a single record. * * @param string $pk The key name. * * @return mixed Object on success, false otherwise. * * @since 2.5 */ public function getItem($pk = null) { require_once JPATH_COMPONENT.'/helpers/languages.php'; $pk = (!empty($pk)) ? $pk : JRequest::getCmd('id'); $filename = constant('JPATH_'.strtoupper($this->getState('filter.client'))) . '/language/overrides/' . $this->getState('filter.language', 'en-GB').'.override.ini'; $strings = LanguagesHelper::parseFile($filename); $result = new stdClass(); $result->key = ''; $result->override = ''; if (isset($strings[$pk])) { $result->key = $pk; $result->override = $strings[$pk]; } return $result; } /** * 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) { $app = JFactory::getApplication(); require_once JPATH_COMPONENT.'/helpers/languages.php'; $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; } $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 JRegistry(); $registry->loadObject($strings); if (!JFile::write($filename, $registry->toString('INI'))) { 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; } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 2.5 */ protected function populateState() { $app = JFactory::getApplication(); $client = $app->getUserStateFromRequest('com_languages.overrides.filter.client', 'filter_client', 0, 'int') ? 'administrator' : 'site'; $this->setState('filter.client', $client); $language = $app->getUserStateFromRequest('com_languages.overrides.filter.language', 'filter_language', 'en-GB', 'cmd'); $this->setState('filter.language', $language); } } home/academiac/www/administrator/components/com_languages/controllers/override.php000064400000014036151373215630024770 0ustar00option.edit.$this->context"; // Get the constant name $recordId = (count($cid) ? $cid[0] : JRequest::getCmd('id')); // Access check if (!$this->allowEdit()) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED')); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false)); return; } $app->setUserState($context.'.data', null); $this->setRedirect('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id')); } /** * Method to save an override * * @param string $key The name of the primary key of the URL variable (not used here). * @param string $urlVar The name of the URL variable if different from the primary key (not used here). * * @return void * * @since 2.5 */ public function save($key = null, $urlVar = null) { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialize variables $app = JFactory::getApplication(); $model = $this->getModel(); $data = JRequest::getVar('jform', array(), 'post', 'array'); $context = "$this->option.edit.$this->context"; $task = $this->getTask(); $recordId = JRequest::getCmd('id'); $data['id'] = $recordId; // Access check if (!$this->allowSave($data, 'id')) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED')); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false)); return; } // Validate the posted data $form = $model->getForm($data, false); if (!$form) { $app->enqueueMessage($model->getError(), 'error'); return; } // Require helper for filter functions called by JForm require_once JPATH_COMPONENT.'/helpers/languages.php'; // Test whether the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { // Get the validation messages $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } // Save the data in the session $app->setUserState($context.'.data', $data); // Redirect back to the edit screen $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'), false)); return; } // Attempt to save the data if (!$model->save($validData)) { // Save the data in the session $app->setUserState($context.'.data', $validData); // Redirect back to the edit screen $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError())); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'), false)); return; } // Add message of success $this->setMessage(JText::_('COM_LANGUAGES_VIEW_OVERRIDE_SAVE_SUCCESS')); // Redirect the user and adjust session state based on the chosen task switch ($task) { case 'apply': // Set the record data in the session $recordId = $model->getState($this->context.'.id'); $app->setUserState($context.'.data', null); // Redirect back to the edit screen $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($validData['key'], 'id'), false)); break; case 'save2new': // Clear the record id and data from the session $app->setUserState($context.'.data', null); // Redirect back to the edit screen $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend(null, 'id'), false)); break; default: // Clear the record id and data from the session $app->setUserState($context.'.data', null); // Redirect to the list screen $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false)); break; } } /** * Method to cancel an edit * * @param string $key The name of the primary key of the URL variable (not used here). * * @return void * * @since 2.5 */ public function cancel($key = null, $test = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialize variables $app = JFactory::getApplication(); $context = "$this->option.edit.$this->context"; $app->setUserState($context.'.data', null); $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false)); } }