/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; JFactory::getApplication()->input->set('hidemainmenu', 1); $isNew = empty($this->item->lang_id); $canDo = LanguagesHelper::getActions(); JToolbarHelper::title(JText::_($isNew ? 'COM_LANGUAGES_VIEW_LANGUAGE_EDIT_NEW_TITLE' : 'COM_LANGUAGES_VIEW_LANGUAGE_EDIT_EDIT_TITLE'), 'langmanager.png'); // If a new item, can save. if ($isNew && $canDo->get('core.create')) { JToolbarHelper::save('language.save'); } //If an existing item, allow to Apply and Save. if (!$isNew && $canDo->get('core.edit')) { JToolbarHelper::apply('language.apply'); JToolbarHelper::save('language.save'); } // If an existing item, can save to a copy only if we have create rights. if ($canDo->get('core.create')) { JToolbarHelper::save2new('language.save2new'); } if ($isNew) { JToolbarHelper::cancel('language.cancel'); } else { JToolbarHelper::cancel('language.cancel', 'JTOOLBAR_CLOSE'); } JToolbarHelper::divider(); JToolbarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_EDIT'); $this->sidebar = JHtmlSidebar::render(); }
/** * Method for refreshing the cache in the database with the known language strings * * @return boolean True on success, Exception object otherwise * * @since 2.5 */ public function refresh() { require_once JPATH_COMPONENT . '/helpers/languages.php'; $app = JFactory::getApplication(); $app->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; }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; Request::setVar('hidemainmenu', 1); $isNew = empty($this->item->lang_id); $canDo = LanguagesHelper::getActions(); Toolbar::title(Lang::txt($isNew ? 'COM_LANGUAGES_VIEW_LANGUAGE_EDIT_NEW_TITLE' : 'COM_LANGUAGES_VIEW_LANGUAGE_EDIT_EDIT_TITLE'), 'langmanager.png'); // If a new item, can save. if ($isNew && $canDo->get('core.create')) { Toolbar::save('language.save'); } //If an existing item, allow to Apply and Save. if (!$isNew && $canDo->get('core.edit')) { Toolbar::apply('language.apply'); Toolbar::save('language.save'); } // If an existing item, can save to a copy only if we have create rights. if ($canDo->get('core.create')) { Toolbar::save2new('language.save2new'); } if ($isNew) { Toolbar::cancel('language.cancel'); } else { Toolbar::cancel('language.cancel', 'JTOOLBAR_CLOSE'); } Toolbar::divider(); Toolbar::help('language'); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; $canDo = LanguagesHelper::getActions(); JToolBarHelper::title(JText::_('COM_LANGUAGES_VIEW_LANGUAGES_TITLE'), 'langmanager.png'); if ($canDo->get('core.create')) { JToolBarHelper::addNew('language.add'); } if ($canDo->get('core.edit')) { JToolBarHelper::editList('language.edit'); JToolBarHelper::divider(); } if ($canDo->get('core.edit.state')) { if ($this->state->get('filter.published') != 2) { JToolBarHelper::publishList('languages.publish'); JToolBarHelper::unpublishList('languages.unpublish'); } } if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { JToolBarHelper::deleteList('', 'languages.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolBarHelper::divider(); } elseif ($canDo->get('core.edit.state')) { JToolBarHelper::trash('languages.trash'); JToolBarHelper::divider(); } if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_languages'); JToolBarHelper::divider(); } JToolBarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_CONTENT'); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; JRequest::setVar('hidemainmenu', 1); $isNew = empty($this->item->lang_id); $canDo = LanguagesHelper::getActions(); JToolBarHelper::title(JText::_($isNew ? 'COM_LANGUAGES_VIEW_LANGUAGE_EDIT_NEW_TITLE' : 'COM_LANGUAGES_VIEW_LANGUAGE_EDIT_EDIT_TITLE'), 'langmanager.png'); // If a new item, can save. if ($isNew && $canDo->get('core.create')) { JToolBarHelper::save('language.save', 'JTOOLBAR_SAVE'); } //If an existing item, allow to Apply and Save. if (!$isNew && $canDo->get('core.edit')) { JToolBarHelper::apply('language.apply', 'JTOOLBAR_APPLY'); JToolBarHelper::save('language.save', 'JTOOLBAR_SAVE'); } // If an existing item, can save to a copy only if we have create rights. if ($canDo->get('core.create')) { JToolBarHelper::custom('language.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false); } if ($isNew) { JToolBarHelper::cancel('language.cancel', 'JTOOLBAR_CANCEL'); } else { JToolBarHelper::cancel('language.cancel', 'JTOOLBAR_CLOSE'); } JToolBarHelper::divider(); JToolBarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_EDIT'); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; $canDo = LanguagesHelper::getActions(); JToolBarHelper::title(JText::_('COM_LANGUAGES_VIEW_LANGUAGES_TITLE'), 'langmanager.png'); if ($canDo->get('core.create')) { JToolBarHelper::addNew('language.add'); } if ($canDo->get('core.edit')) { JToolBarHelper::editList('language.edit'); JToolBarHelper::divider(); } if ($canDo->get('core.edit.state')) { if ($this->state->get('filter.published') != 2) { JToolBarHelper::publishList('languages.publish'); JToolBarHelper::unpublishList('languages.unpublish'); } } if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { JToolBarHelper::deleteList('', 'languages.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolBarHelper::divider(); } elseif ($canDo->get('core.edit.state')) { JToolBarHelper::trash('languages.trash'); JToolBarHelper::divider(); } if ($canDo->get('core.admin')) { // Add install languages link to the lang installer component $bar = JToolBar::getInstance('toolbar'); $bar->appendButton('Link', 'extension', 'COM_LANGUAGES_INSTALL', 'index.php?option=com_installer&view=languages'); JToolBarHelper::divider(); JToolBarHelper::preferences('com_languages'); JToolBarHelper::divider(); } JToolBarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_CONTENT'); }
/** * Method for refreshing the cache in the database with the known language strings. * * @return boolean True on success, Exception object otherwise. * * @since 2.5 */ public function refresh() { JLoader::register('LanguagesHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/languages.php'); $app = JFactory::getApplication(); $app->setUserState('com_languages.overrides.cachedtime', null); // Empty the database cache first. try { $this->_db->setQuery('TRUNCATE TABLE ' . $this->_db->quoteName('#__overrider')); $this->_db->execute(); } catch (RuntimeException $e) { return $e; } // Create the insert query. $query = $this->_db->getQuery(true)->insert($this->_db->quoteName('#__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)); $path = $base . '/language/' . $language; $files = array(); // Parse common language directory. jimport('joomla.filesystem.folder'); if (is_dir($path)) { $files = JFolder::files($path, $language . '.*ini$', false, true); } // Parse language directories of components. $files = array_merge($files, JFolder::files($base . '/components', $language . '.*ini$', 3, true)); // Parse language directories of modules. $files = array_merge($files, JFolder::files($base . '/modules', $language . '.*ini$', 3, true)); // Parse language directories of templates. $files = array_merge($files, JFolder::files($base . '/templates', $language . '.*ini$', 3, true)); // Parse language directories of plugins. $files = array_merge($files, JFolder::files(JPATH_PLUGINS, $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'); foreach ($strings as $key => $string) { $query->values($this->_db->quote($key) . ',' . $this->_db->quote($string) . ',' . $this->_db->quote(JPath::clean($file))); } try { $this->_db->setQuery($query); $this->_db->execute(); } catch (RuntimeException $e) { return $e; } } } // Update the cached time. $app->setUserState('com_languages.overrides.cachedtime.' . $client . '.' . $language, time()); return true; }
/** * Display the view */ public function display($tpl = null) { $this->ftp = $this->get('Ftp'); $this->option = $this->get('Option'); $this->pagination = $this->get('Pagination'); $this->rows = $this->get('Data'); $this->state = $this->get('State'); $client = (int) $this->state->get('filter.client_id', 0); LanguagesHelper::addSubmenu('installed', $client); $this->addToolbar(); parent::display($tpl); }
/** * Displays the view. * * @param string $tpl The name of the template file to parse. * * @return void * * @since 2.5 */ public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Overrides'); $this->languages = $this->get('Languages'); $this->pagination = $this->get('Pagination'); LanguagesHelper::addSubmenu('overrides'); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors)); } $this->addToolbar(); parent::display($tpl); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; $canDo = LanguagesHelper::getActions(); JToolBarHelper::title(JText::_('COM_LANGUAGES_VIEW_INSTALLED_TITLE'), 'langmanager.png'); if ($canDo->get('core.edit.state')) { JToolBarHelper::makeDefault('installed.setDefault'); JToolBarHelper::divider(); } if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_languages'); JToolBarHelper::divider(); } JToolBarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_INSTALLED'); }
/** * Display the view */ public function display($tpl = null) { $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); LanguagesHelper::addSubmenu('languages'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->addToolbar(); $this->sidebar = JHtmlSidebar::render(); parent::display($tpl); }
/** * Display the view. * * @param string $tpl The name of the template file to parse. * * @return void */ public function display($tpl = null) { $this->ftp = $this->get('Ftp'); $this->option = $this->get('Option'); $this->pagination = $this->get('Pagination'); $this->rows = $this->get('Data'); $this->state = $this->get('State'); $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); LanguagesHelper::addSubmenu('installed'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->addToolbar(); parent::display($tpl); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; $canDo = LanguagesHelper::getActions(); JToolBarHelper::title(JText::_('COM_LANGUAGES_VIEW_INSTALLED_TITLE'), 'langmanager.png'); if ($canDo->get('core.edit.state')) { JToolBarHelper::makeDefault('installed.setDefault'); JToolBarHelper::divider(); } if ($canDo->get('core.admin')) { // Add install languages link to the lang installer component $bar = JToolBar::getInstance('toolbar'); $bar->appendButton('Link', 'extension', 'COM_LANGUAGES_INSTALL', 'index.php?option=com_installer&view=languages'); JToolBarHelper::divider(); JToolBarHelper::preferences('com_languages'); JToolBarHelper::divider(); } JToolBarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_INSTALLED'); }
/** * Method to display a view. * * @param boolean If true, the view output will be cached * @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JController This object to support chaining. * @since 1.5 */ public function display($cachable = false, $urlparams = false) { require_once JPATH_COMPONENT . '/helpers/languages.php'; // Load the submenu. LanguagesHelper::addSubmenu(JRequest::getCmd('view', 'installed')); $view = JRequest::getCmd('view', 'languages'); $layout = JRequest::getCmd('layout', 'default'); $id = JRequest::getInt('id'); // Check for edit form. if ($view == 'language' && $layout == 'edit' && !$this->checkEditId('com_languages.edit.language', $id)) { // Somehow the person just went to the form - we don't allow that. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option=com_languages&view=languages', false)); return false; } parent::display(); return $this; }
/** * 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'); } JToolBarHelper::divider(); JToolBarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_OVERRIDES'); }
/** * Adds the page title and toolbar * * @return void * * @since 2.5 */ protected function addToolbar() { JFactory::getApplication()->input->set('hidemainmenu', true); $canDo = LanguagesHelper::getActions(); JToolbarHelper::title(JText::_('COM_LANGUAGES_VIEW_OVERRIDE_EDIT_TITLE'), 'comments-2 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'); } JToolbarHelper::divider(); JToolbarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_OVERRIDES_EDIT'); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/languages.php'; $canDo = LanguagesHelper::getActions(); JToolbarHelper::title(JText::_('COM_LANGUAGES_VIEW_LANGUAGES_TITLE'), 'langmanager.png'); if ($canDo->get('core.create')) { JToolbarHelper::addNew('language.add'); } if ($canDo->get('core.edit')) { JToolbarHelper::editList('language.edit'); JToolbarHelper::divider(); } if ($canDo->get('core.edit.state')) { if ($this->state->get('filter.published') != 2) { JToolbarHelper::publishList('languages.publish'); JToolbarHelper::unpublishList('languages.unpublish'); } } if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { JToolbarHelper::deleteList('', 'languages.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolbarHelper::divider(); } elseif ($canDo->get('core.edit.state')) { JToolbarHelper::trash('languages.trash'); JToolbarHelper::divider(); } if ($canDo->get('core.admin')) { // Add install languages link to the lang installer component $bar = JToolbar::getInstance('toolbar'); $bar->appendButton('Link', 'upload', 'COM_LANGUAGES_INSTALL', 'index.php?option=com_installer&view=languages'); JToolbarHelper::divider(); JToolbarHelper::preferences('com_languages'); JToolbarHelper::divider(); } JToolbarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_CONTENT'); JHtmlSidebar::setAction('index.php?option=com_languages&view=languages'); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true)); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_ACCESS'), 'filter_access', JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access'))); }
/** * task to display the view */ function display() { // Get the document object. $document =& JFactory::getDocument(); // Set the default view name and format from the Request. $vName = JRequest::getWord('view', 'installed'); $vFormat = $document->getType(); $lName = JRequest::getWord('layout', 'default'); // Get and render the view. if ($view =& $this->getView($vName, $vFormat)) { // Get the model for the view. $model =& $this->getModel($vName); // Push the model into the view (as default). $view->setModel($model, true); $view->setLayout($lName); // Push document object into the view. $view->assignRef('document', $document); $view->display(); // Load the submenu. require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'languages.php'; LanguagesHelper::addSubmenu($vName); } }
/** * 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'); } JToolbarHelper::divider(); JToolbarHelper::help('JHELP_EXTENSIONS_LANGUAGE_MANAGER_OVERRIDES'); JHtmlSidebar::setAction('index.php?option=com_languages&view=overrides'); JHtmlSidebar::addFilter('', 'filter_language_client', JHtml::_('select.options', $this->languages, null, 'text', $this->state->get('filter.language_client')), true); $this->sidebar = JHtmlSidebar::render(); }
<?php /** * @package Joomla.Administrator * @subpackage com_languages * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_HZEXEC_') or die; Html::addIncludePath(JPATH_COMPONENT . '/helpers/html'); Html::behavior('tooltip'); Html::behavior('formvalidation'); $canDo = LanguagesHelper::getActions(); ?> <script type="text/javascript"> Joomla.submitbutton = function(task) { if (task == 'language.cancel' || document.formvalidator.isValid($('#item-form'))) { Joomla.submitform(task, document.getElementById('item-form')); } } </script> <form action="<?php echo Route::url('index.php?option=com_languages&layout=edit&lang_id=' . (int) $this->item->lang_id); ?> " method="post" name="adminForm" id="item-form" class="form-validate"> <div class="grid"> <div class="col span7"> <fieldset class="adminform">
/** * Method to save the form data. * * @param array $data The form data. * @param boolean $opposite_client Indicates whether the override should not be created for the current client. * * @return boolean True on success, false otherwise. * * @since 2.5 */ public function save($data, $opposite_client = false) { JLoader::register('LanguagesHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/languages.php'); jimport('joomla.filesystem.file'); $app = JFactory::getApplication(); $client = $app->getUserState('com_languages.overrides.filter.client', 0); $language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB'); // If the override should be created for both. if ($opposite_client) { $client = 1 - $client; } // Return false if the constant is a reserved word, i.e. YES, NO, NULL, FALSE, ON, OFF, NONE, TRUE $blacklist = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE'); if (in_array($data['key'], $blacklist)) { $this->setError(JText::_('COM_LANGUAGES_OVERRIDE_ERROR_RESERVED_WORDS')); return false; } $client = $client ? 'administrator' : 'site'; // Parse the override.ini file in oder to get the keys and strings. $filename = constant('JPATH_' . strtoupper($client)) . '/language/overrides/' . $language . '.override.ini'; $strings = LanguagesHelper::parseFile($filename); if (isset($strings[$data['id']])) { // If an existent string was edited check whether // the name of the constant is still the same. if ($data['key'] == $data['id']) { // If yes, simply override it. $strings[$data['key']] = $data['override']; } else { // If no, delete the old string and prepend the new one. unset($strings[$data['id']]); $strings = array($data['key'] => $data['override']) + $strings; } } else { // If it is a new override simply prepend it. $strings = array($data['key'] => $data['override']) + $strings; } foreach ($strings as $key => $string) { $strings[$key] = str_replace('"', '"_QQ_"', $string); } // Write override.ini file with the strings. $registry = new Registry($strings); $reg = $registry->toString('INI'); if (!JFile::write($filename, $reg)) { return false; } // If the override should be stored for both clients save // it also for the other one and prevent endless recursion. if (isset($data['both']) && $data['both'] && !$opposite_client) { return $this->save($data, true); } return true; }
/** * 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]); } } foreach ($strings as $key => $string) { $strings[$key] = str_replace('"', '"_QQ_"', $string); } // 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); }
/** * 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 delete one or more overrides. * * @param array $cids Array of keys to delete. * * @return integer Number of successfully deleted overrides, boolean false if an error occurred. * * @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'); JLoader::register('LanguagesHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/languages.php'); $filterclient = JFactory::getApplication()->getUserState('com_languages.overrides.filter.client'); $client = $filterclient == 0 ? 'SITE' : 'ADMINISTRATOR'; // Parse the override.ini file in oder to get the keys and strings. $filename = constant('JPATH_' . $client) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini'; $strings = LanguagesHelper::parseFile($filename); // Unset strings that shall be deleted foreach ($cids as $key) { if (isset($strings[$key])) { unset($strings[$key]); } } foreach ($strings as $key => $string) { $strings[$key] = str_replace('"', '"_QQ_"', $string); } // Write override.ini file with the left strings. $registry = new Registry(); $registry->loadObject($strings); $reg = $registry->toString('INI'); $filename = constant('JPATH_' . $client) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini'; if (!JFile::write($filename, $reg)) { return false; } $this->cleanCache(); return count($cids); }
/** * 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'; jimport('joomla.filesystem.file'); $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); $reg = $registry->toString('INI'); if (!JFile::write($filename, $reg)) { return false; } // If the override should be stored for both clients save // it also for the other one and prevent endless recursion if (isset($data['both']) && $data['both'] && !$opposite_client) { return $this->save($data, true); } return true; }