diff --git a/administrator/components/com_languages/controllers/override.php b/administrator/components/com_languages/controllers/override.php new file mode 100644 index 0000000000000..9ddf30a8f646e --- /dev/null +++ b/administrator/components/com_languages/controllers/override.php @@ -0,0 +1,195 @@ +option.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 + * + * @return void + * + * @since 2.5 + */ + public function save() + { + // Check for request forgeries + JRequest::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 + * + * @return void + * + * @since 2.5 + */ + public function cancel() + { + JRequest::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)); + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/controllers/overrides.php b/administrator/components/com_languages/controllers/overrides.php new file mode 100644 index 0000000000000..32c44787d511e --- /dev/null +++ b/administrator/components/com_languages/controllers/overrides.php @@ -0,0 +1,69 @@ +setMessage(JText::_($this->text_prefix.'_NO_ITEM_SELECTED'), 'warning'); + } + else + { + // Get the model + $model = $this->getModel('overrides'); + + // Remove the items + if ($model->delete($cid)) + { + $this->setMessage(JText::plural($this->text_prefix.'_N_ITEMS_DELETED', count($cid))); + } + else + { + $this->setMessage($model->getError()); + } + } + + $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false)); + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/controllers/strings.json.php b/administrator/components/com_languages/controllers/strings.json.php new file mode 100644 index 0000000000000..aa5564789f3e3 --- /dev/null +++ b/administrator/components/com_languages/controllers/strings.json.php @@ -0,0 +1,63 @@ +getModel('strings')->refresh()); + } + + /** + * Method for searching language strings + * + * @return void + * + * @since 2.5 + */ + public function search() + { + echo new JJsonResponse($this->getModel('strings')->search()); + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/helpers/jsonresponse.php b/administrator/components/com_languages/helpers/jsonresponse.php new file mode 100644 index 0000000000000..9a8340432f9f1 --- /dev/null +++ b/administrator/components/com_languages/helpers/jsonresponse.php @@ -0,0 +1,127 @@ +success, + * so you can use both flags equivalently. + * + * @var boolean + * @since 2.5 + */ + public $error = false; + + /** + * The main response message + * + * @var string + * @since 2.5 + */ + public $message = null; + + /** + * Array of messages gathered in the JApplication object + * + * @var array + * @since 2.5 + */ + public $messages = null; + + /** + * The response data + * + * var array/object + * @since 2.5 + */ + public $data = null; + + /** + * Constructor + * + * @param array/object $response The Response data + * @param string $message The main response message + * @param boolean $error True, if the success flag shall be set to false, defaults to false + * + * @return void + * + * @since 2.5 + */ + public function __construct($response = null, $message = null, $error = false) + { + $this->message = $message; + + // Get the message queue + $messages = JFactory::getApplication()->getMessageQueue(); + + // Build the sorted messages list + if (is_array($messages) && count($messages)) + { + foreach ($messages as $message) + { + if (isset($message['type']) && isset($message['message'])) + { + $lists[$message['type']][] = $message['message']; + } + } + } + + // If messages exist add them to the output + if (isset($lists) && is_array($lists)) + { + $this->messages = $lists; + } + + // Check if we are dealing with an error + if ($response instanceof Exception) + { + // Prepare the error response + $this->success = false; + $this->error = true; + $this->message = $response->getMessage(); + } + else + { + // Prepare the response data + $this->success = !$error; + $this->error = $error; + $this->data = $response; + } + } + + /** + * Magic toString method for sending the response in JSON format + * + * @return string The response in JSON format + * + * @since 2.5 + */ + public function __toString() + { + return json_encode($this); + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/helpers/languages.php b/administrator/components/com_languages/helpers/languages.php index e5feac681ca0a..f2dad24fab379 100644 --- a/administrator/components/com_languages/helpers/languages.php +++ b/administrator/components/com_languages/helpers/languages.php @@ -39,6 +39,11 @@ public static function addSubmenu($vName) 'index.php?option=com_languages&view=languages', $vName == 'languages' ); + JSubMenuHelper::addEntry( + JText::_('COM_LANGUAGES_SUBMENU_OVERRIDES'), + 'index.php?option=com_languages&view=overrides', + $vName == 'overrides' + ); } /** @@ -62,4 +67,94 @@ public static function getActions() return $result; } -} + + /** + * Method for parsing ini files + * + * @param string $filename Path and name of the ini file to parse + * + * @return array Array of strings found in the file, the array indices will be the keys. On failure an empty array will be returned + * + * @since 2.5 + */ + public static function parseFile($filename) + { + jimport('joomla.filesystem.file'); + + if (!JFile::exists($filename)) + { + return array(); + } + + // Capture hidden PHP errors from the parsing + $version = phpversion(); + $php_errormsg = null; + $track_errors = ini_get('track_errors'); + ini_set('track_errors', true); + + if ($version >= '5.3.1') + { + $contents = file_get_contents($filename); + $contents = str_replace('_QQ_', '"\""', $contents); + $strings = @parse_ini_string($contents); + + if ($strings === false) + { + return array(); + } + } + else + { + $strings = @parse_ini_file($filename); + + if ($strings === false) + { + return array(); + } + + if ($version == '5.3.0' && is_array($strings)) + { + foreach ($strings as $key => $string) + { + $strings[$key] = str_replace('_QQ_', '"', $string); + } + } + } + + return $strings; + } + + /** + * Filter method for language keys. + * This method will be called by JForm while filtering the form data. + * + * @param string $value The language key to filter + * + * @return string The filtered language key + * + * @since 2.5 + */ + public static function filterKey($value) + { + $filter = JFilterInput::getInstance(null, null, 1, 1); + + return strtoupper($filter->clean($value, 'cmd')); + } + + /** + * Filter method for language strings. + * This method will be called by JForm while filtering the form data. + * + * @param string $value The language string to filter + * + * @return string The filtered language string + * + * @since 2.5 + */ + public static function filterText($value) + { + $filter = JFilterInput::getInstance(null, null, 1, 1); + + return str_replace('"', '"_QQ_"', $filter->clean($value)); + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/models/forms/override.xml b/administrator/components/com_languages/models/forms/override.xml new file mode 100644 index 0000000000000..53982b755d102 --- /dev/null +++ b/administrator/components/com_languages/models/forms/override.xml @@ -0,0 +1,75 @@ + + +
+
+ + + + + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/administrator/components/com_languages/models/override.php b/administrator/components/com_languages/models/override.php new file mode 100644 index 0000000000000..31f95f1b45ee9 --- /dev/null +++ b/administrator/components/com_languages/models/override.php @@ -0,0 +1,182 @@ +loadForm('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)).DS.'language'.DS.'overrides'.DS.$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'))).DS.'language'.DS.'overrides'.DS.$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. + * + * @return boolean True on success, false otherwise. + * + * @since 2.5 + */ + public function save($data) + { + $app = JFactory::getApplication(); + require_once JPATH_COMPONENT.'/helpers/languages.php'; + + $client = $app->getUserState('com_languages.overrides.filter.client', 0) ? 'administrator' : 'site'; + $language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB'); + + // Parse the override.ini file in oder to get the keys and strings + $filename = constant('JPATH_'.strtoupper($client)).DS.'language'.DS.'overrides'.DS.$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; + } + + // Write override.ini file with the strings + $registry = new JRegistry(); + $registry->loadObject($strings); + + if (!JFile::write($filename, $registry->toString('INI'))) + { + return false; + } + + 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); + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/models/overrides.php b/administrator/components/com_languages/models/overrides.php new file mode 100644 index 0000000000000..0824ca9a66fe3 --- /dev/null +++ b/administrator/components/com_languages/models/overrides.php @@ -0,0 +1,264 @@ +filter_fields = array('key', 'text'); + } + + /** + * Retrieves the overrides data + * + * @param boolean True if all overrides shall be returned without considering pagination, defaults to false + * + * @return array Array of objects containing the overrides of the override.ini file + * + * @since 2.5 + */ + public function getOverrides($all = false) + { + // Get a storage key + $store = $this->getStoreId(); + + // Try to load the data from internal storage + if (!empty($this->cache[$store])) + { + return $this->cache[$store]; + } + + // Parse the override.ini file in oder to get the keys and strings + $filename = constant('JPATH_'.strtoupper($this->getState('filter.client'))).DS.'language'.DS.'overrides'.DS.$this->getState('filter.language').'.override.ini'; + $strings = LanguagesHelper::parseFile($filename); + + // Consider the odering + if ($this->getState('list.ordering') == 'text') + { + if (strtoupper($this->getState('list.direction')) == 'DESC') + { + arsort($strings); + } + else + { + asort($strings); + } + } + else + { + if (strtoupper($this->getState('list.direction')) == 'DESC') + { + krsort($strings); + } + else + { + ksort($strings); + } + } + + // Consider the pagination + if (!$all && $this->getTotal() > $this->getState('list.limit')) + { + $strings = array_slice($strings, $this->getStart(), $this->getState('list.limit'), true); + } + + // Add the items to the internal cache + $this->cache[$store] = $strings; + + return $this->cache[$store]; + } + + /** + * Method to get the total number of overrides + * + * @return int The total number of overrides + * + * @since 2.5 + */ + public function getTotal() + { + // Get a storage key + $store = $this->getStoreId('getTotal'); + + // Try to load the data from internal storage + if (!empty($this->cache[$store])) + { + return $this->cache[$store]; + } + + // Add the total to the internal cache + $this->cache[$store] = count($this->getOverrides(true)); + + return $this->cache[$store]; + } + + /** + * Method to auto-populate the model state. + * + * Note. Calling getState in this method will result in recursion. + * + * @param string An optional ordering field. + * @param string An optional direction (asc|desc). + * + * @return void + * + * @since 2.5 + */ + protected function populateState($ordering = null, $direction = null) + { + $app = JFactory::getApplication(); + + // Use default language of frontend for default filter + $default = JComponentHelper::getParams('com_languages')->get('site').'0'; + + $old_language_client = $app->getUserState('com_languages.overrides.filter.language_client', ''); + $language_client = $this->getUserStateFromRequest('com_languages.overrides.filter.language_client', 'filter_language_client', $default, 'cmd'); + + if ($old_language_client != $language_client) + { + $client = substr($language_client, -1); + $language = substr($language_client, 0, -1); + } + else + { + $client = $app->getUserState('com_languages.overrides.filter.client', 0); + $language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB'); + } + + $this->setState('filter.language_client', $language.$client); + $this->setState('filter.client', $client ? 'administrator' : 'site'); + $this->setState('filter.language', $language); + + // Add filters to the session because they won't be stored there + // by 'getUserStateFromRequest' if they aren't in the current request + $app->setUserState('com_languages.overrides.filter.client', $client); + $app->setUserState('com_languages.overrides.filter.language', $language); + + // List state information + parent::populateState('key', 'asc'); + } + + /** + * Method to get all found languages of frontend and backend. + * + * The resulting array has entries of the following style: + * 0|1 => - + * + * @return array Sorted associative array of languages + * + * @since 2.5 + */ + public function getLanguages() + { + // Try to load the data from internal storage + if (!empty($this->cache['languages'])) + { + return $this->cache['languages']; + } + + // Get all languages of frontend and backend + $languages = array(); + $site_languages = JLanguage::getKnownLanguages(JPATH_SITE); + $admin_languages = JLanguage::getKnownLanguages(JPATH_ADMINISTRATOR); + + // Create a single array of them + foreach ($site_languages as $tag => $language) + { + $languages[$tag.'0'] = JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDES_LANGUAGES_BOX_ITEM', $language['name'], JText::_('JSITE')); + } + foreach ($admin_languages as $tag => $language) + { + $languages[$tag.'1'] = JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDES_LANGUAGES_BOX_ITEM', $language['name'], JText::_('JADMINISTRATOR')); + } + + // Sort it by language tag and by client after that + ksort($languages); + + // Add the languages to the internal cache + $this->cache['languages'] = $languages; + + return $this->cache['languages']; + } + + /** + * Method to delete one or more overrides + * + * @param array Array of keys to delete + * + * @return int 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'; + + $app = JFactory::getApplication(); + + // Parse the override.ini file in oder to get the keys and strings + $filename = constant('JPATH_'.strtoupper($this->getState('filter.client'))).DS.'language'.DS.'overrides'.DS.$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]); + } + } + + // Write override.ini file with the left strings + $registry = new JRegistry(); + $registry->loadObject($strings); + + $filename = constant('JPATH_'.strtoupper($this->getState('filter.client'))).DS.'language'.DS.'overrides'.DS.$this->getState('filter.language').'.override.ini'; + + if (!JFile::write($filename, $registry->toString('INI'))) + { + return false; + } + + $this->cleanCache(); + + return count($cids); + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/models/strings.php b/administrator/components/com_languages/models/strings.php new file mode 100644 index 0000000000000..9fd914cc594a9 --- /dev/null +++ b/administrator/components/com_languages/models/strings.php @@ -0,0 +1,174 @@ +setUserState('com_languages.overrides.cachedtime', null); + + // Empty the database cache first + try + { + $this->_db->setQuery('TRUNCATE TABLE '.$this->_db->qn('#__overrider')); + $this->_db->query(); + } + catch (JDatabaseException $e) + { + return $e; + } + + // Create the insert query + $query = $this->_db->getQuery(true) + ->insert($this->_db->qn('#__overrider')) + ->columns('constant, string, file'); + + // Initialize some variables + $client = $app->getUserState('com_languages.overrides.filter.client', 'site') ? 'administrator' : 'site'; + $language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB'); + + + $base = constant('JPATH_'.strtoupper($client)).DS; + $path = $base.'language'.DS.$language; + + $files = array(); + + // Parse common language directory + if(JFolder::exists($path)) + { + $files = JFolder::files($path, $language.'.*ini$', false, true); + } + + // Parse language directories of components + $path = $base.'components'; + $files = array_merge($files, JFolder::files($path, $language.'.*ini$', 3, true)); + + // Parse language directories of modules + $path = $base.'modules'; + $files = array_merge($files, JFolder::files($path, $language.'.*ini$', 3, true)); + + // Parse language directories of templates + $path = $base.'templates'; + $files = array_merge($files, JFolder::files($path, $language.'.*ini$', 3, true)); + + // Parse language directories of plugins + $path = JPATH_ROOT.DS.'plugins'; + $files = array_merge($files, JFolder::files($path, $language.'.*ini$', 3, true)); + + // Parse all found ini files and add the strings to the database cache + foreach ($files as $file) + { + $strings = LanguagesHelper::parseFile($file); + if ($strings && count($strings)) + { + //$query->clear('values'); + $values = array(); + foreach ($strings as $key => $string) + { + //$query->values($this->_db->q($key).','.$this->_db->q($string).','.$this->_db->q(JPath::clean($file))); + $values[] = '('.$this->_db->q($key).','.$this->_db->q($string).','.$this->_db->q(JPath::clean($file)).')'; + } + + try + { + $this->_db->setQuery($query.' (constant, string, file) VALUES '.implode(',',$values)); + if (!$this->_db->query()) + { + return new Exception($this->_db->getErrorMsg()); + } + } + catch (JDatabaseException $e) + { + return $e; + } + } + } + + // Update the cached time + $app->setUserState('com_languages.overrides.cachedtime.'.$client.'.'.$language, time()); + + return true; + } + + /** + * Method for searching language strings + * + * @return array Array of resuls on success, Exception object otherwise + * + * @since 2.5 + */ + public function search() + { + $results = array(); + + $limitstart = JRequest::getInt('more'); + + try + { + $searchstring = $this->_db->q('%'.JRequest::getString('searchstring').'%'); + + // Create the search query + $query = $this->_db->getQuery(true) + ->select('constant, string, file') + ->from($this->_db->qn('#__overrider')); + if (JRequest::getCmd('searchtype') == 'constant') + { + $query->where('constant LIKE '.$searchstring); + } + else + { + $query->where('string LIKE '.$searchstring); + } + + // Consider the limitstart according to the 'more' parameter and load the results + $this->_db->setQuery($query, $limitstart, 10); + $results['results'] = $this->_db->loadObjectList(); + + // Check whether there are more results than already loaded + $query->clear('select') + ->select('COUNT(id)'); + $this->_db->setQuery($query); + + if ($this->_db->loadResult() > $limitstart + 10) + { + // If this is set a 'More Results' link will be displayed in the view + $results['more'] = $limitstart + 10; + } + } + catch (JDatabaseException $e) + { + return $e; + } + + return $results; + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/views/installed/tmpl/default_navigation.php b/administrator/components/com_languages/views/installed/tmpl/default_navigation.php index 2b3da19903e84..14c02cbbed895 100644 --- a/administrator/components/com_languages/views/installed/tmpl/default_navigation.php +++ b/administrator/components/com_languages/views/installed/tmpl/default_navigation.php @@ -21,6 +21,8 @@
  • +
  • +
  • diff --git a/administrator/components/com_languages/views/override/index.html b/administrator/components/com_languages/views/override/index.html new file mode 100644 index 0000000000000..2efb97f319a35 --- /dev/null +++ b/administrator/components/com_languages/views/override/index.html @@ -0,0 +1 @@ + diff --git a/administrator/components/com_languages/views/override/tmpl/edit.php b/administrator/components/com_languages/views/override/tmpl/edit.php new file mode 100644 index 0000000000000..b6b25a7449e01 --- /dev/null +++ b/administrator/components/com_languages/views/override/tmpl/edit.php @@ -0,0 +1,89 @@ + + + +
    +
    +
    + item->key) ? JText::_('COM_LANGUAGES_VIEW_OVERRIDE_EDIT_NEW_OVERRIDE_LEGEND') : JText::_('COM_LANGUAGES_VIEW_OVERRIDE_EDIT_EDIT_OVERRIDE_LEGEND'); ?> +
      + +
    • form->getLabel('key'); ?> + form->getInput('key'); ?>
    • +
    • form->getLabel('override'); ?> + form->getInput('override'); ?>
    • +
    • form->getLabel('language'); ?> + form->getInput('language'); ?>
    • +
    • form->getLabel('client'); ?> + form->getInput('client'); ?>
    • +
    • form->getLabel('file'); ?> + form->getInput('file'); ?>
    • + +
    +
    +
    + +
    +
    + + +
    +
      + +
    • +
    • +
    • form->getInput('searchstring'); ?> +
    • +
    • form->getLabel('searchtype'); ?> + form->getInput('searchtype'); ?>
    • + +
    +
    +
    + + + + + +
    + + + +
    +
    +
    \ No newline at end of file diff --git a/administrator/components/com_languages/views/override/tmpl/index.html b/administrator/components/com_languages/views/override/tmpl/index.html new file mode 100644 index 0000000000000..2efb97f319a35 --- /dev/null +++ b/administrator/components/com_languages/views/override/tmpl/index.html @@ -0,0 +1 @@ + diff --git a/administrator/components/com_languages/views/override/view.html.php b/administrator/components/com_languages/views/override/view.html.php new file mode 100644 index 0000000000000..63266dee48fd5 --- /dev/null +++ b/administrator/components/com_languages/views/override/view.html.php @@ -0,0 +1,128 @@ +addStyleSheet(JURI::root().'media/overrider/css/overrider.css'); + JHTML::core(); + $doc->addScript(JURI::root().'media/overrider/js/overrider.js'); + + $this->form = $this->get('Form'); + $this->item = $this->get('Item'); + $this->state = $this->get('State'); + + // Check for errors + if (count($errors = $this->get('Errors'))) + { + throw new Exception(implode("\n", $errors)); + + return; + } + + // Check whether the cache has to be refreshed + $cached_time = JFactory::getApplication()->getUserState('com_languages.overrides.cachedtime.'.$this->state->get('filter.client').'.'.$this->state->get('filter.language'), 0); + if(time() - $cached_time > 60 * 5) + { + $this->state->set('cache_expired', true); + } + + // Add strings for translations in Javascript + JText::script('COM_LANGUAGES_VIEW_OVERRIDE_NO_RESULTS'); + JText::script('COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR'); + + $this->addToolbar(); + parent::display($tpl); + } + + /** + * Adds the page title and toolbar + * + * @return void + * + * @since 2.5 + */ + protected function addToolbar() + { + JRequest::setVar('hidemainmenu', true); + + $canDo = LanguagesHelper::getActions(); + + JToolBarHelper::title(JText::_('COM_LANGUAGES_VIEW_OVERRIDE_EDIT_TITLE'), 'langmanager'); + + if ($canDo->get('core.edit')) + { + JToolBarHelper::apply('override.apply'); + JToolBarHelper::save('override.save'); + } + + // This component does not support Save as Copy + + if ($canDo->get('core.edit') && $canDo->get('core.create')) + { + JToolBarHelper::save2new('override.save2new'); + } + + if (empty($this->item->key)) + { + JToolBarHelper::cancel('override.cancel'); + } + else + { + JToolBarHelper::cancel('override.cancel', 'JTOOLBAR_CLOSE'); + } + } +} \ No newline at end of file diff --git a/administrator/components/com_languages/views/overrides/index.html b/administrator/components/com_languages/views/overrides/index.html new file mode 100644 index 0000000000000..fa6d84e8055f5 --- /dev/null +++ b/administrator/components/com_languages/views/overrides/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/administrator/components/com_languages/views/overrides/tmpl/default.php b/administrator/components/com_languages/views/overrides/tmpl/default.php new file mode 100644 index 0000000000000..43616a87b229a --- /dev/null +++ b/administrator/components/com_languages/views/overrides/tmpl/default.php @@ -0,0 +1,105 @@ +state->get('filter.client') == 'site' ? JText::_('JSITE') : JText::_('JADMINISTRATOR'); +$language = $this->state->get('filter.language'); +$listOrder = $this->escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); ?> +
    +
    + +
    + +
    +
    + +
    + + + + + + + + + + + + + + + + + + + authorise('core.edit', 'com_languages'); + $i = 0; + foreach($this->items as $key => $text): ?> + + + + + + + + + + +
    + + + + + + + + + + + +
    + pagination->getListFooter(); ?> +
    + + + + escape($key); ?> + + escape($key); ?> + + + escape($text); ?> + + + + + + pagination->getRowOffset($i); ?> +
    +
    + + + + + +
    +
    \ No newline at end of file diff --git a/administrator/components/com_languages/views/overrides/tmpl/index.html b/administrator/components/com_languages/views/overrides/tmpl/index.html new file mode 100644 index 0000000000000..fa6d84e8055f5 --- /dev/null +++ b/administrator/components/com_languages/views/overrides/tmpl/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/administrator/components/com_languages/views/overrides/view.html.php b/administrator/components/com_languages/views/overrides/view.html.php new file mode 100644 index 0000000000000..8f898a59efaa6 --- /dev/null +++ b/administrator/components/com_languages/views/overrides/view.html.php @@ -0,0 +1,113 @@ +state = $this->get('State'); + $this->items = $this->get('Overrides'); + $this->languages = $this->get('Languages'); + $this->pagination = $this->get('Pagination'); + + // Check for errors + if (count($errors = $this->get('Errors'))) + { + throw new Exception(implode("\n", $errors)); + + return; + } + + $this->addToolbar(); + parent::display($tpl); + } + + /** + * Adds the page title and toolbar + * + * @return void + * + * @since 2.5 + */ + protected function addToolbar() + { + // Get the results for each action + $canDo = LanguagesHelper::getActions(); + + JToolBarHelper::title(JText::_('COM_LANGUAGES_VIEW_OVERRIDES_TITLE'), 'langmanager'); + + if ($canDo->get('core.create')) + { + JToolbarHelper::addNew('override.add'); + } + + if ($canDo->get('core.edit') && $this->pagination->total) + { + JToolbarHelper::editList('override.edit'); + } + + if ($canDo->get('core.delete') && $this->pagination->total) + { + JToolbarHelper::deleteList('', 'overrides.delete'); + } + + if ($canDo->get('core.admin')) + { + JToolBarHelper::preferences('com_languages'); + } + } +} \ No newline at end of file diff --git a/administrator/language/en-GB/en-GB.com_languages.ini b/administrator/language/en-GB/en-GB.com_languages.ini index a387931a378f5..8c06944a15671 100644 --- a/administrator/language/en-GB/en-GB.com_languages.ini +++ b/administrator/language/en-GB/en-GB.com_languages.ini @@ -14,6 +14,22 @@ COM_LANGUAGES_FIELD_IMAGE_DESC="Prefix of the image file for this language when COM_LANGUAGES_FIELD_IMAGE_LABEL="Image Prefix" COM_LANGUAGES_FIELD_LANG_TAG_DESC="Enter here the language tag – example: en-GB for English (UK). This should be the exact prefix used for the language installed or to be installed." COM_LANGUAGES_FIELD_LANG_TAG_LABEL="Language Tag" +COM_LANGUAGES_OVERRIDE_FIELD_CLIENT_LABEL="Location" +COM_LANGUAGES_OVERRIDE_FIELD_CLIENT_DESC="Indicates whether the override is created for the site (Frontend) or administrator (Backend) client." +COM_LANGUAGES_OVERRIDE_FIELD_FILE_LABEL="File" +COM_LANGUAGES_OVERRIDE_FIELD_FILE_DESC="Language overrides are stored in a specific INI file (as it's the case for the original texts, too). Here you can see in which file the current override is stored." +COM_LANGUAGES_OVERRIDE_FIELD_LANGUAGE_LABEL="Language" +COM_LANGUAGES_OVERRIDE_FIELD_LANGUAGE_DESC="Language for which the constant is overridden." +COM_LANGUAGES_OVERRIDE_FIELD_KEY_LABEL="Language Constant" +COM_LANGUAGES_OVERRIDE_FIELD_KEY_DESC="The language constant of the string you want to override.
    Each language output text on your site is identified by a specific language constant which you have to use for creating an override of the text.
    If you don't know the corresponding constant you can search for text you want to change on the right. By clicking on the desired result the correct constant will automatically be inserted into the form." +COM_LANGUAGES_OVERRIDE_FIELD_OVERRIDE_LABEL="Text" +COM_LANGUAGES_OVERRIDE_FIELD_OVERRIDE_DESC="Here you can enter the text which you want to be displayed instead of the overridden one.
    Please note that there may be placeholders (e.g. %s, %d or %1$s) in the text which could be important (they will be replaced by other texts afore displaying), so you should leave them in there." +COM_LANGUAGES_OVERRIDE_FIELD_SEARCHSTRING_LABEL="Search Text" +COM_LANGUAGES_OVERRIDE_FIELD_SEARCHSTRING_DESC="Please enter the text to search for here. It may be in any of the language files." +COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_LABEL="Search for" +COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_DESC="Here you can select whether you want to search for constant names or the values (thus the actual texts).
    It is also possible to search for language file names (and paths) in order to get all constants and texts of a language file." +COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_CONSTANT="Constant" +COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_TEXT="Value" COM_LANGUAGES_FIELD_PUBLISHED_DESC="Whether this content language is published or not. If published, it will display as a choice in the Language Switcher module in frontend." COM_LANGUAGES_FIELD_LANG_CODE_DESC="This Language Code will be appended to the site url. When SEF is enabled, one will get http://mysite.com/en/. If SEF is disabled the suffix &lang=en will be appended at the end of the URL. Note the Language Code must be unique among all the languages." COM_LANGUAGES_FIELD_LANG_CODE_LABEL="URL Language Code" @@ -63,9 +79,34 @@ COM_LANGUAGES_SEARCH_IN_TITLE="Search in title" COM_LANGUAGES_SUBMENU_CONTENT="Content" COM_LANGUAGES_SUBMENU_INSTALLED_ADMINISTRATOR="Installed - Administrator" COM_LANGUAGES_SUBMENU_INSTALLED_SITE="Installed - Site" +COM_LANGUAGES_SUBMENU_OVERRIDES="Overrides" COM_LANGUAGES_VIEW_INSTALLED_TITLE="Language Manager: Installed Languages" COM_LANGUAGES_VIEW_LANGUAGE_EDIT_EDIT_TITLE="Language Manager: Edit Content Language" COM_LANGUAGES_VIEW_LANGUAGE_EDIT_NEW_TITLE="Language Manager: New Content Language" COM_LANGUAGES_VIEW_LANGUAGES_TITLE="Language Manager: Content Languages" +COM_LANGUAGES_VIEW_OVERRIDE_CLIENT_SITE="Site" +COM_LANGUAGES_VIEW_OVERRIDE_CLIENT_ADMINISTRATOR="Administrator" +COM_LANGUAGES_VIEW_OVERRIDE_EDIT_TITLE="Language Manager: Edit Override" +COM_LANGUAGES_VIEW_OVERRIDE_EDIT_NEW_OVERRIDE_LEGEND="Create a New Override" +COM_LANGUAGES_VIEW_OVERRIDE_EDIT_EDIT_OVERRIDE_LEGEND="Edit this Override" +COM_LANGUAGES_VIEW_OVERRIDE_LANGUAGE="%1$s [%2$s]" +COM_LANGUAGES_VIEW_OVERRIDE_MORE_RESULTS="More Results" +COM_LANGUAGES_VIEW_OVERRIDE_NO_RESULTS="No matching texts found" +COM_LANGUAGES_VIEW_OVERRIDE_REFRESHING="Please wait while the cache is recreated." +COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR="Error while performing an Ajax request" +COM_LANGUAGES_VIEW_OVERRIDE_RESULTS_LEGEND="Search Results" +COM_LANGUAGES_VIEW_OVERRIDE_SAVE_SUCCESS="Language Override was saved successfully." +COM_LANGUAGES_VIEW_OVERRIDE_SEARCH_BUTTON="Search" +COM_LANGUAGES_VIEW_OVERRIDE_SEARCH_LEGEND="Search text you want to change" +COM_LANGUAGES_VIEW_OVERRIDE_SEARCH_TIP="

    A language string is composed of two parts: a specific language constant and its value.
    For example, in the string:

    COM_CONTENT_READ_MORE="_QQ_"Read more: "_QQ_"

    'COM_CONTENT_READ_MORE' is the constant and 'Read more: ' is the value.
    You have to use the specific language constant in order to create an override of the value.
    Therefore, you can search for the constant or the value you want to change with the search field below.
    By clicking on the desired result the correct constant will automatically be inserted into the form.

    " +COM_LANGUAGES_VIEW_OVERRIDE_SEARCH_TIP="A language string is composed of two parts: a specific language constant and its value.
    For example, in the string:
         COM_CONTENT_READ_MORE="_QQ_"Read more: "_QQ_"
    'COM_CONTENT_READ_MORE' is the constant and 'Read more: ' is the value.
    You have to use the specific language constant in order to create an override of the value.
    Therefore, you can search for the constant or the value you want to change with the search field below.
    By clicking on the desired result the correct constant will automatically be inserted into the form." +COM_LANGUAGES_VIEW_OVERRIDES_FILTER_SEARCH_DESC="Search constant or text." +COM_LANGUAGES_VIEW_OVERRIDES_KEY="Constant" +COM_LANGUAGES_VIEW_OVERRIDES_LANGUAGES_BOX_ITEM="%1$s - %2$s" +COM_LANGUAGES_VIEW_OVERRIDES_N_ITEMS_DELETED="%d language overrides were successfully deleted" +COM_LANGUAGES_VIEW_OVERRIDES_N_ITEMS_DELETED_1="%d language override was successfully deleted" +COM_LANGUAGES_VIEW_OVERRIDES_NO_ITEM_SELECTED="You haven't selected any overrides" +COM_LANGUAGES_VIEW_OVERRIDES_TEXT="Text" +COM_LANGUAGES_VIEW_OVERRIDES_TITLE="Language Manager: Language Overrides" COM_LANGUAGES_XML_DESCRIPTION="Component for language management" -JLIB_RULES_SETTING_NOTES="1. If you change the setting, it will apply to this component. Note that:
    Inherited means that the permissions from global configuration and parent group will be used.
    Denied means that no matter what the global configuration or parent group settings are, the group being edited cannot take this action on this component.
    Allowed means that the group being edited will be able to take this action for this component (but if this is in conflict with the global configuration or parent group it will have no impact; a conflict will be indicated by Not Allowed (Locked) under Calculated Settings).
    2. If you select a new setting, click Save to refresh the calculated settings." +JLIB_RULES_SETTING_NOTES="1. If you change the setting, it will apply to this component. Note that:
    Inherited means that the permissions from global configuration and parent group will be used.
    Denied means that no matter what the global configuration or parent group settings are, the group being edited cannot take this action on this component.
    Allowed means that the group being edited will be able to take this action for this component (but if this is in conflict with the global configuration or parent group it will have no impact; a conflict will be indicated by Not Allowed (Locked) under Calculated Settings).
    2. If you select a new setting, click Save to refresh the calculated settings." \ No newline at end of file diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 076c37e7b152f..2d0731394e15e 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -792,6 +792,21 @@ CREATE TABLE `#__newsfeeds` ( ) DEFAULT CHARSET=utf8; +# ------------------------------------------------------- + +# +# Table structure for table `#__overrider` +# + +CREATE TABLE IF NOT EXISTS `#__overrider` ( + `id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', + `constant` varchar(255) NOT NULL, + `string` text NOT NULL, + `file` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8; + + # ------------------------------------------------------- # diff --git a/media/overrider/css/index.html b/media/overrider/css/index.html new file mode 100644 index 0000000000000..2efb97f319a35 --- /dev/null +++ b/media/overrider/css/index.html @@ -0,0 +1 @@ + diff --git a/media/overrider/css/overrider.css b/media/overrider/css/overrider.css new file mode 100644 index 0000000000000..fd399985e4170 --- /dev/null +++ b/media/overrider/css/overrider.css @@ -0,0 +1,53 @@ +/** + * @version $Id$ + * @package Joomla.Administrator + * @subpackage com_languages + * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +.overrider-spinner { + background-image:url(../../system/images/modal/spinner.gif); + background-repeat:no-repeat; + background-position:center; +} + +#refresh-status{ + display:none; + height:16px; + padding-left:25px; + background-position:left; +} + +#results-container{ + display:none; + padding-bottom:10px; +} +#more-results{ + display:none; + height:16px; + padding:10px 0; +} +.row0{ + background-color:#f7f7f7; +} +.row1{ + background-color:#f0f0f0; + border-top:1px solid #ffffff; +} +.result{ + padding:5px 0px; + border:1px solid #ffffff; +} +.result:hover{ + background-color:#e8f6fe; + cursor:pointer; +} +.result-key{ + color:#666666; + padding-left:5px; +} +.result-string{ + padding-left:25px; + margin-top:5px; +} \ No newline at end of file diff --git a/media/overrider/index.html b/media/overrider/index.html new file mode 100644 index 0000000000000..2efb97f319a35 --- /dev/null +++ b/media/overrider/index.html @@ -0,0 +1 @@ + diff --git a/media/overrider/js/index.html b/media/overrider/js/index.html new file mode 100644 index 0000000000000..2efb97f319a35 --- /dev/null +++ b/media/overrider/js/index.html @@ -0,0 +1 @@ + diff --git a/media/overrider/js/overrider.js b/media/overrider/js/overrider.js new file mode 100644 index 0000000000000..2446d84b842f2 --- /dev/null +++ b/media/overrider/js/overrider.js @@ -0,0 +1,239 @@ +/** + * @version $Id$ + * @package Joomla.Administrator + * @subpackage com_languages + * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +/** + * Some state variables for the overrider + */ +Joomla.overrider = { + states : { + refreshing: false, + refreshed: false, + counter: 0, + searchstring: '', + searchtype: 'value' + } +}; + +/** + * Method for refreshing the database cache of known language strings via Ajax + * + * @return void + * + * @since 2.5 + */ +Joomla.overrider.refreshCache = function() +{ + var req = new Request.JSON({ + method: 'post', + url: 'index.php?option=com_languages&task=strings.refresh&format=json', + onRequest: function() + { + this.states.refreshing = true; + document.id('refresh-status').reveal(); + }.bind(this), + onSuccess: function(r) + { + if (r.error && r.message) + { + alert(r.message); + } + if (r.messages) + { + Joomla.renderMessages(r.messages); + } + document.id('refresh-status').dissolve(); + this.states.refreshing = false; + }.bind(this), + onFailure: function(xhr) + { + alert(Joomla.JText._('COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR')); + document.id('refresh-status').dissolve(); + }.bind(this), + onError: function(text, error) + { + alert(error + "\n\n" + text); + document.id('refresh-status').dissolve(); + }.bind(this) + }); + req.post(); +}; + +/** + * Method for searching known language strings via Ajax + * + * @param int more Determines the limit start of the results + * + * @return void + * + * @since 2.5 + */ +Joomla.overrider.searchStrings = function(more) +{ + // Prevent searching if the cache is refreshed at the moment + if (this.states.refreshing) + { + return; + } + + // Only update the used searchstring and searchtype if the search button + // was used to start the search (that will be the case if 'more' is null) + if (!more) + { + this.states.searchstring = document.id('jform_searchstring').value; + this.states.searchtype = 'value'; + if (document.id('jform_searchtype0').checked) + { + this.states.searchtype = 'constant'; + } + } + + if (!this.states.searchstring) + { + document.id('jform_searchstring').addClass('invalid'); + + return; + } + + var req = new Request.JSON({ + method: 'post', + url: 'index.php?option=com_languages&task=strings.search&format=json', + onRequest: function() + { + if (more) + { + // If 'more' is greater than 0 we have already displayed some results for + // the current searchstring, so display the spinner at the more link + document.id('more-results').addClass('overrider-spinner'); + } + else + { + // Otherwise it is a new searchstring and we have to remove all previous results first + document.id('more-results').set('style', 'display:none;'); + var children = $$('#results-container div.language-results'); + children.destroy(); + document.id('results-container').addClass('overrider-spinner').reveal(); + } + }.bind(this), + onSuccess: function(r) { + if (r.error && r.message) + { + alert(r.message); + } + if (r.messages) + { + Joomla.renderMessages(r.messages); + } + if(r.data) + { + if(r.data.results) + { + this.insertResults(r.data.results); + } + if(r.data.more) + { + // If there are more results than the sent ones + // display the more link + this.states.more = r.data.more; + document.id('more-results').reveal(); + } + else + { + document.id('more-results').set('style', 'display:none;'); + } + } + document.id('results-container').removeClass('overrider-spinner'); + document.id('more-results').removeClass('overrider-spinner'); + }.bind(this), + onFailure: function(xhr) + { + alert(Joomla.JText._('COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR')); + document.id('results-container').removeClass('overrider-spinner'); + document.id('more-results').removeClass('overrider-spinner'); + }.bind(this), + onError: function(text, error) + { + alert(error + "\n\n" + text); + document.id('results-container').removeClass('overrider-spinner'); + document.id('more-results').removeClass('overrider-spinner'); + }.bind(this) + }); + req.post('searchstring=' + this.states.searchstring + '&searchtype=' + this.states.searchtype + '&more=' + more); +}; + +/** + * Method inserting the received results into the results container + * + * @param array results An array of search result objects + * + * @return void + * + * @since 2.5 + */ +Joomla.overrider.insertResults = function(results) +{ + // For creating an individual ID for each result we use a counter + this.states.counter = this.states.counter + 1; + + // Create a container into which all the results will be inserted + var results_div = new Element('div', { + id: 'language-results' + this.states.counter, + 'class': 'language-results', + style: 'display:none;' + }); + + // Create some elements for each result and insert it into the container + Array.each(results, function (item, index) { + var div = new Element('div', { + 'class': 'result row' + index%2, + onclick: 'Joomla.overrider.selectString(' + this.states.counter + index + ');', + }); + var key = new Element('div', { + id: 'override_key' + this.states.counter + index, + 'class': 'result-key', + html: item.constant, + title: item.file + }); + key.inject(div); + var string = new Element('div', { + id: 'override_string' + this.states.counter + index, + 'class': 'result-string', + html: item.string + }); + string.inject(div); + div.inject(results_div); + }, this); + + // If there aren't any results display an appropriate message + if(!results.length) + { + var noresult = new Element('div', { + html: Joomla.JText._('COM_LANGUAGES_VIEW_OVERRIDE_NO_RESULTS') + }); + noresult.inject(results_div); + } + + // Finally insert the container afore the more link and reveal it + results_div.inject(document.id('more-results'), 'before'); + document.id('language-results' + this.states.counter).reveal(); +}; + +/** + * Inserts a specific constant/value pair into the form and scrolls the page back to the top + * + * @param int id The ID of the element which was selected for insertion + * + * @return void + * + * @since 2.5 + */ +Joomla.overrider.selectString = function(id) +{ + document.id('jform_key').value = document.id('override_key' + id).get('html'); + document.id('jform_override').value = document.id('override_string' + id).get('html'); + new Fx.Scroll(window).toTop(); +}; \ No newline at end of file