/** * 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; }
/** * 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; }
/** * 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 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; }
/** * 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; }