0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: language.php.tar
home/academiac/www/libraries/joomla/installer/adapters/language.php 0000644 00000047303 15137270435 0021556 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Installer * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.base.adapterinstance'); /** * Language installer * * @package Joomla.Platform * @subpackage Installer * @since 11.1 */ class JInstallerLanguage extends JAdapterInstance { /** * Core language pack flag * * @var boolean * @since 11.1 */ protected $_core = false; /** * Custom install method * * Note: This behaves badly due to hacks made in the middle of 1.5.x to add * the ability to install multiple distinct packs in one install. The * preferred method is to use a package to install multiple language packs. * * @return boolean True on success * * @since 11.1 */ public function install() { $source = $this->parent->getPath('source'); if (!$source) { $this->parent ->setPath( 'source', ($this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/language/' . $this->parent->extension->element ); } $this->manifest = $this->parent->getManifest(); $root = $this->manifest->document; // Get the client application target if ((string) $this->manifest->attributes()->client == 'both') { JError::raiseWarning(42, JText::_('JLIB_INSTALLER_ERROR_DEPRECATED_FORMAT')); $element = $this->manifest->site->files; if (!$this->_install('site', JPATH_SITE, 0, $element)) { return false; } $element = $this->manifest->administration->files; if (!$this->_install('administrator', JPATH_ADMINISTRATOR, 1, $element)) { return false; } // This causes an issue because we have two eid's, *sigh* nasty hacks! return true; } elseif ($cname = (string) $this->manifest->attributes()->client) { // Attempt to map the client to a base path $client = JApplicationHelper::getClientInfo($cname, true); if ($client === null) { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_UNKNOWN_CLIENT_TYPE', $cname))); return false; } $basePath = $client->path; $clientId = $client->id; $element = $this->manifest->files; return $this->_install($cname, $basePath, $clientId, $element); } else { // No client attribute was found so we assume the site as the client $cname = 'site'; $basePath = JPATH_SITE; $clientId = 0; $element = $this->manifest->files; return $this->_install($cname, $basePath, $clientId, $element); } } /** * Install function that is designed to handle individual clients * * @param string $cname Cname @todo: not used * @param string $basePath The base name. * @param integer $clientId The client id. * @param object &$element The XML element. * * @return boolean * * @since 11.1 */ protected function _install($cname, $basePath, $clientId, &$element) { $this->manifest = $this->parent->getManifest(); // Get the language name // Set the extensions name $name = JFilterInput::getInstance()->clean((string) $this->manifest->name, 'cmd'); $this->set('name', $name); // Get the Language tag [ISO tag, eg. en-GB] $tag = (string) $this->manifest->tag; // Check if we found the tag - if we didn't, we may be trying to install from an older language package if (!$tag) { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT', JText::_('JLIB_INSTALLER_ERROR_NO_LANGUAGE_TAG'))); return false; } $this->set('tag', $tag); // Set the language installation path $this->parent->setPath('extension_site', $basePath . '/language/' . $tag); // Do we have a meta file in the file list? In other words... is this a core language pack? if ($element && count($element->children())) { $files = $element->children(); foreach ($files as $file) { if ((string) $file->attributes()->file == 'meta') { $this->_core = true; break; } } } // Either we are installing a core pack or a core pack must exist for the language we are installing. if (!$this->_core) { if (!JFile::exists($this->parent->getPath('extension_site') . '/' . $this->get('tag') . '.xml')) { $this->parent ->abort(JText::sprintf('JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_NO_CORE_LANGUAGE', $this->get('tag')))); return false; } } // If the language directory does not exist, let's create it $created = false; if (!file_exists($this->parent->getPath('extension_site'))) { if (!$created = JFolder::create($this->parent->getPath('extension_site'))) { $this->parent ->abort( JText::sprintf( 'JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_CREATE_FOLDER_FAILED', $this->parent->getPath('extension_site')) ) ); return false; } } else { // Look for an update function or update tag $updateElement = $this->manifest->update; // Upgrade manually set or // Update function available or // Update tag detected if ($this->parent->isUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'update')) || $updateElement) { return $this->update(); // transfer control to the update function } elseif (!$this->parent->isOverwrite()) { // Overwrite is set // We didn't have overwrite set, find an update function or find an update tag so lets call it safe if (file_exists($this->parent->getPath('extension_site'))) { // If the site exists say so. JError::raiseWarning( 1, JText::sprintf( 'JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_site')) ) ); } else { // If the admin exists say so. JError::raiseWarning( 1, JText::sprintf( 'JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_administrator')) ) ); } return false; } } /* * If we created the language directory we will want to remove it if we * have to roll back the installation, so let's add it to the installation * step stack */ if ($created) { $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_site'))); } // Copy all the necessary files if ($this->parent->parseFiles($element) === false) { // Install failed, rollback changes $this->parent->abort(); return false; } // Parse optional tags $this->parent->parseMedia($this->manifest->media); // Copy all the necessary font files to the common pdf_fonts directory $this->parent->setPath('extension_site', $basePath . '/language/pdf_fonts'); $overwrite = $this->parent->setOverwrite(true); if ($this->parent->parseFiles($this->manifest->fonts) === false) { // Install failed, rollback changes $this->parent->abort(); return false; } $this->parent->setOverwrite($overwrite); // Get the language description $description = (string) $this->manifest->description; if ($description) { $this->parent->set('message', JText::_($description)); } else { $this->parent->set('message', ''); } // Add an entry to the extension table with a whole heap of defaults $row = JTable::getInstance('extension'); $row->set('name', $this->get('name')); $row->set('type', 'language'); $row->set('element', $this->get('tag')); // There is no folder for languages $row->set('folder', ''); $row->set('enabled', 1); $row->set('protected', 0); $row->set('access', 0); $row->set('client_id', $clientId); $row->set('params', $this->parent->getParams()); $row->set('manifest_cache', $this->parent->generateManifestCache()); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT', $row->getError())); return false; } // Clobber any possible pending updates $update = JTable::getInstance('update'); $uid = $update->find(array('element' => $this->get('tag'), 'type' => 'language', 'client_id' => '', 'folder' => '')); if ($uid) { $update->delete($uid); } return $row->get('extension_id'); } /** * Custom update method * * @return boolean True on success, false on failure * * @since 11.1 */ public function update() { $xml = $this->parent->getManifest(); $this->manifest = $xml; $cname = $xml->attributes()->client; // Attempt to map the client to a base path $client = JApplicationHelper::getClientInfo($cname, true); if ($client === null || (empty($cname) && $cname !== 0)) { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_UNKNOWN_CLIENT_TYPE', $cname))); return false; } $basePath = $client->path; $clientId = $client->id; // Get the language name // Set the extensions name $name = (string) $this->manifest->name; $name = JFilterInput::getInstance()->clean($name, 'cmd'); $this->set('name', $name); // Get the Language tag [ISO tag, eg. en-GB] $tag = (string) $xml->tag; // Check if we found the tag - if we didn't, we may be trying to install from an older language package if (!$tag) { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT', JText::_('JLIB_INSTALLER_ERROR_NO_LANGUAGE_TAG'))); return false; } $this->set('tag', $tag); $folder = $tag; // Set the language installation path $this->parent->setPath('extension_site', $basePath . '/language/' . $this->get('tag')); // Do we have a meta file in the file list? In other words... is this a core language pack? if (count($xml->files->children())) { foreach ($xml->files->children() as $file) { if ((string) $file->attributes()->file == 'meta') { $this->_core = true; break; } } } // Either we are installing a core pack or a core pack must exist for the language we are installing. if (!$this->_core) { if (!JFile::exists($this->parent->getPath('extension_site') . '/' . $this->get('tag') . '.xml')) { $this->parent ->abort(JText::sprintf('JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_NO_CORE_LANGUAGE', $this->get('tag')))); return false; } } // Copy all the necessary files if ($this->parent->parseFiles($xml->files) === false) { // Install failed, rollback changes $this->parent->abort(); return false; } // Parse optional tags $this->parent->parseMedia($xml->media); // Copy all the necessary font files to the common pdf_fonts directory $this->parent->setPath('extension_site', $basePath . '/language/pdf_fonts'); $overwrite = $this->parent->setOverwrite(true); if ($this->parent->parseFiles($xml->fonts) === false) { // Install failed, rollback changes $this->parent->abort(); return false; } $this->parent->setOverwrite($overwrite); // Get the language description and set it as message $this->parent->set('message', (string) $xml->description); // Finalization and Cleanup Section // Clobber any possible pending updates $update = JTable::getInstance('update'); $uid = $update->find(array('element' => $this->get('tag'), 'type' => 'language', 'client_id' => $clientId)); if ($uid) { $update->delete($uid); } // Update an entry to the extension table $row = JTable::getInstance('extension'); $eid = $row->find(array('element' => strtolower($this->get('tag')), 'type' => 'language', 'client_id' => $clientId)); if ($eid) { $row->load($eid); } else { // set the defaults $row->set('folder', ''); // There is no folder for language $row->set('enabled', 1); $row->set('protected', 0); $row->set('access', 0); $row->set('client_id', $clientId); $row->set('params', $this->parent->getParams()); } $row->set('name', $this->get('name')); $row->set('type', 'language'); $row->set('element', $this->get('tag')); $row->set('manifest_cache', $this->parent->generateManifestCache()); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT', $row->getError())); return false; } // And now we run the postflight ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight')) { $this->parent->manifestClass->postflight('update', $this); } $msg = ob_get_contents(); // append messages ob_end_clean(); if ($msg != '') { $this->parent->set('extension_message', $msg); } return $row->get('extension_id'); } /** * Custom uninstall method * * @param string $eid The tag of the language to uninstall * * @return mixed Return value for uninstall method in component uninstall file * * @since 11.1 */ public function uninstall($eid) { // Load up the extension details $extension = JTable::getInstance('extension'); $extension->load($eid); // Grab a copy of the client details $client = JApplicationHelper::getClientInfo($extension->get('client_id')); // Check the element isn't blank to prevent nuking the languages directory...just in case $element = $extension->get('element'); if (empty($element)) { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_ELEMENT_EMPTY')); return false; } // Check that the language is not protected, Normally en-GB. $protected = $extension->get('protected'); if ($protected == 1) { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_PROTECTED')); return false; } // Verify that it's not the default language for that client $params = JComponentHelper::getParams('com_languages'); if ($params->get($client->name) == $element) { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DEFAULT')); return false; } // Construct the path from the client, the language and the extension element name $path = $client->path . '/language/' . $element; // Get the package manifest object and remove media $this->parent->setPath('source', $path); // We do findManifest to avoid problem when uninstalling a list of extension: getManifest cache its manifest file $this->parent->findManifest(); $this->manifest = $this->parent->getManifest(); $this->parent->removeFiles($this->manifest->media); // Check it exists if (!JFolder::exists($path)) { // If the folder doesn't exist lets just nuke the row as well and presume the user killed it for us $extension->delete(); JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_PATH_EMPTY')); return false; } if (!JFolder::delete($path)) { // If deleting failed we'll leave the extension entry in tact just in case JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DIRECTORY')); return false; } // Remove the extension table entry $extension->delete(); // Setting the language of users which have this language as the default language $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->from('#__users'); $query->select('*'); $db->setQuery($query); $users = $db->loadObjectList(); if ($client->name == 'administrator') { $param_name = 'admin_language'; } else { $param_name = 'language'; } $count = 0; foreach ($users as $user) { $registry = new JRegistry; $registry->loadString($user->params); if ($registry->get($param_name) == $element) { $registry->set($param_name, ''); $query = $db->getQuery(true); $query->update('#__users'); $query->set('params=' . $db->quote($registry)); $query->where('id=' . (int) $user->id); $db->setQuery($query); $db->execute(); $count = $count + 1; } } if (!empty($count)) { JError::raiseNotice(500, JText::plural('JLIB_INSTALLER_NOTICE_LANG_RESET_USERS', $count)); } // All done! return true; } /** * Custom discover method * Finds language files * * @return boolean True on success * * @since 11.1 */ public function discover() { $results = array(); $site_languages = JFolder::folders(JPATH_SITE . '/language'); $admin_languages = JFolder::folders(JPATH_ADMINISTRATOR . '/language'); foreach ($site_languages as $language) { if (file_exists(JPATH_SITE . '/language/' . $language . '/' . $language . '.xml')) { $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_SITE . '/language/' . $language . '/' . $language . '.xml'); $extension = JTable::getInstance('extension'); $extension->set('type', 'language'); $extension->set('client_id', 0); $extension->set('element', $language); $extension->set('name', $language); $extension->set('state', -1); $extension->set('manifest_cache', json_encode($manifest_details)); $results[] = $extension; } } foreach ($admin_languages as $language) { if (file_exists(JPATH_ADMINISTRATOR . '/language/' . $language . '/' . $language . '.xml')) { $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_ADMINISTRATOR . '/language/' . $language . '/' . $language . '.xml'); $extension = JTable::getInstance('extension'); $extension->set('type', 'language'); $extension->set('client_id', 1); $extension->set('element', $language); $extension->set('name', $language); $extension->set('state', -1); $extension->set('manifest_cache', json_encode($manifest_details)); $results[] = $extension; } } return $results; } /** * Custom discover install method * Basically updates the manifest cache and leaves everything alone * * @return integer The extension id * * @since 11.1 */ public function discover_install() { // Need to find to find where the XML file is since we don't store this normally $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); $short_element = $this->parent->extension->element; $manifestPath = $client->path . '/language/' . $short_element . '/' . $short_element . '.xml'; $this->parent->manifest = $this->parent->isManifest($manifestPath); $this->parent->setPath('manifest', $manifestPath); $this->parent->setPath('source', $client->path . '/language/' . $short_element); $this->parent->setPath('extension_root', $this->parent->getPath('source')); $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest')); $this->parent->extension->manifest_cache = json_encode($manifest_details); $this->parent->extension->state = 0; $this->parent->extension->name = $manifest_details['name']; $this->parent->extension->enabled = 1; //$this->parent->extension->params = $this->parent->getParams(); try { $this->parent->extension->store(); } catch (JException $e) { JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_LANG_DISCOVER_STORE_DETAILS')); return false; } return $this->parent->extension->get('extension_id'); } /** * Refreshes the extension table cache * * @return boolean result of operation, true if updated, false on failure * * @since 11.1 */ public function refreshManifestCache() { $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); $manifestPath = $client->path . '/language/' . $this->parent->extension->element . '/' . $this->parent->extension->element . '.xml'; $this->parent->manifest = $this->parent->isManifest($manifestPath); $this->parent->setPath('manifest', $manifestPath); $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest')); $this->parent->extension->manifest_cache = json_encode($manifest_details); $this->parent->extension->name = $manifest_details['name']; if ($this->parent->extension->store()) { return true; } else { JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_MOD_REFRESH_MANIFEST_CACHE')); return false; } } } home/academiac/www/libraries/joomla/database/table/language.php 0000644 00000004066 15137271757 0020620 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Database * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.database.table'); /** * Languages table. * * @package Joomla.Platform * @subpackage Database * @since 11.1 */ class JTableLanguage extends JTable { /** * Constructor * * @param JDatabase &$db A database connector object * * @since 11.1 */ public function __construct(&$db) { parent::__construct('#__languages', 'lang_id', $db); } /** * Overloaded check method to ensure data integrity * * @return boolean True on success * * @since 11.1 */ public function check() { if (trim($this->title) == '') { $this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_NO_TITLE')); return false; } return true; } /** * Overrides JTable::store to check unique fields. * * @param boolean $updateNulls True to update fields even if they are null. * * @return boolean True on success. * * @since 11.4 */ public function store($updateNulls = false) { // Verify that the sef field is unique $table = JTable::getInstance('Language', 'JTable'); if ($table->load(array('sef' => $this->sef)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { $this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_SEF')); return false; } // Verify that the image field is unique if ($table->load(array('image' => $this->image)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { $this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_IMAGE')); return false; } // Verify that the language code is unique if ($table->load(array('lang_code' => $this->lang_code)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { $this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_LANG_CODE')); return false; } return parent::store($updateNulls); } } home/academiac/www/administrator/components/com_languages/models/language.php 0000644 00000011325 15137317423 0023647 0 ustar 00 <?php /** * @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('_JEXEC') or die; jimport('joomla.application.component.modeladmin'); /** * Languages Component Language Model * * @package Joomla.Administrator * @subpackage com_languages * @since 1.5 */ class LanguagesModelLanguage extends JModelAdmin { /** * Override to get the table * * @return JTable * @since 1.6 */ public function getTable($name = '', $prefix = '', $options = array()) { return JTable::getInstance('Language'); } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication('administrator'); $params = JComponentHelper::getParams('com_languages'); // Load the User state. $langId = (int) JRequest::getInt('lang_id'); $this->setState('language.id', $langId); // Load the parameters. $this->setState('params', $params); } /** * Method to get a member item. * * @param integer The id of the member to get. * * @return mixed User data object on success, false on failure. * @since 1.0 */ public function getItem($langId = null) { // Initialise variables. $langId = (!empty($langId)) ? $langId : (int) $this->getState('language.id'); $false = false; // Get a member row instance. $table = $this->getTable(); // Attempt to load the row. $return = $table->load($langId); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return $false; } // Set a valid accesslevel in case '0' is stored due to a bug in the installation SQL. if ($table->access == '0') { $table->access = (int) JFactory::getConfig()->get('access'); } $properties = $table->getProperties(1); $value = JArrayHelper::toObject($properties, 'JObject'); return $value; } /** * Method to get the group form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return mixed A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_languages.language', 'language', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } return $form; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_languages.edit.language.data', array()); if (empty($data)) { $data = $this->getItem(); } return $data; } /** * Method to save the form data. * * @param array The form data. * * @return boolean True on success. * @since 1.6 */ public function save($data) { $langId = (int) $this->getState('language.id'); $isNew = true; $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('extension'); $table = $this->getTable(); // Load the row if saving an existing item. if ($langId > 0) { $table->load($langId); $isNew = false; } // Prevent white spaces, including East Asian double bytes $spaces = array('/\xE3\x80\x80/', ' '); $data['lang_code'] = str_replace($spaces, '', $data['lang_code']); $data['sef'] = str_replace($spaces, '', $data['sef']); // Bind the data if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Check the data if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onExtensionBeforeSave event. $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_languages.language', &$table, $isNew)); // Check the event responses. if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data if (!$table->store()) { $this->setError($table->getError()); return false; } // Trigger the onExtensionAfterSave event. $dispatcher->trigger('onExtensionAfterSave', array('com_languages.language', &$table, $isNew)); $this->setState('language.id', $table->lang_id); // Clean the cache. $this->cleanCache(); return true; } /** * Custom clean cache method * * @since 1.6 */ protected function cleanCache($group = null, $client_id = 0) { parent::cleanCache('_system'); parent::cleanCache('com_languages'); } } home/academiac/www/administrator/components/com_languages/controllers/language.php 0000644 00000001652 15137322653 0024735 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.component.controllerform'); /** * Languages list actions controller. * * @package Joomla.Administrator * @subpackage com_languages * @version 1.6 */ class LanguagesControllerLanguage extends JControllerForm { // Define protected variables and custom methods if necessary. /** * Gets the URL arguments to append to an item redirect. * * @param int $recordId The primary key id for the item. * @param string $key The name of the primary key variable. * * @return string The arguments to append to the redirect URL. * @since 1.6 */ protected function getRedirectToItemAppend($recordId = null, $key = 'lang_id') { return parent::getRedirectToItemAppend($recordId, $key); } } home/academiac/www/libraries/joomla/form/fields/language.php 0000644 00000002426 15137513554 0020166 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Form * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; JFormHelper::loadFieldClass('list'); /** * Form Field class for the Joomla Platform. * Supports a list of installed application languages * * @package Joomla.Platform * @subpackage Form * @see JFormFieldContentLanguage for a select list of content languages. * @since 11.1 */ class JFormFieldLanguage extends JFormFieldList { /** * The form field type. * * @var string * @since 11.1 */ protected $type = 'Language'; /** * Method to get the field options. * * @return array The field option objects. * * @since 11.1 */ protected function getOptions() { // Initialize some field attributes. $client = (string) $this->element['client']; if ($client != 'site' && $client != 'administrator') { $client = 'site'; } // Merge any additional options in the XML definition. $options = array_merge( parent::getOptions(), JLanguageHelper::createLanguageList($this->value, constant('JPATH_' . strtoupper($client)), true, true) ); return $options; } } home/academiac/www/libraries/joomla/language/language.php 0000644 00000076153 15137562455 0017554 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Language * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; /** * Allows for quoting in language .ini files. */ define('_QQ_', '"'); // import some libraries jimport('joomla.filesystem.stream'); /** * Languages/translation handler class * * @package Joomla.Platform * @subpackage Language * @since 11.1 */ class JLanguage extends JObject { protected static $languages = array(); /** * Debug language, If true, highlights if string isn't found. * @var boolean * @since 11.1 */ protected $debug = false; /** * The default language, used when a language file in the requested language does not exist. * @var string * @since 11.1 */ protected $default = 'en-GB'; /** * An array of orphaned text. * @var array * @since 11.1 */ protected $orphans = array(); /** * Array holding the language metadata. * @var array * @since 11.1 */ protected $metadata = null; /** * Array holding the language locale or boolean null if none. * @var array|boolean * @since 11.1 */ protected $locale = null; /** * The language to load. * @var string * @since 11.1 */ protected $lang = null; /** * A nested array of language files that have been loaded * @var array * @since 11.1 */ protected $paths = array(); /** * List of language files that are in error state * @var array * @since 11.1 */ protected $errorfiles = array(); /** * Translations * @var array * @since 11.1 */ protected $strings = null; /** * An array of used text, used during debugging. * @var array * @since 11.1 */ protected $used = array(); /** * Counter for number of loads. * @var integer * @since 11.1 */ protected $counter = 0; /** * An array used to store overrides. * @var array * @since 11.1 */ protected $override = array(); /** * Name of the transliterator function for this language. * @var string * @since 11.1 */ protected $transliterator = null; /** * Name of the pluralSuffixesCallback function for this language. * @var string * @since 11.1 */ protected $pluralSuffixesCallback = null; /** * Name of the ignoredSearchWordsCallback function for this language. * @var string * @since 11.1 */ protected $ignoredSearchWordsCallback = null; /** * Name of the lowerLimitSearchWordCallback function for this language. * @var string * @since 11.1 */ protected $lowerLimitSearchWordCallback = null; /** * Name of the uppperLimitSearchWordCallback function for this language * @var string * @since 11.1 */ protected $upperLimitSearchWordCallback = null; /** * Name of the searchDisplayedCharactersNumberCallback function for this language. * @var string * @since 11.1 */ protected $searchDisplayedCharactersNumberCallback = null; /** * Constructor activating the default information of the language. * * @param string $lang The language * @param boolean $debug Indicates if language debugging is enabled. * * @since 11.1 */ public function __construct($lang = null, $debug = false) { $this->strings = array(); if ($lang == null) { $lang = $this->default; } $this->setLanguage($lang); $this->setDebug($debug); $filename = JPATH_BASE . "/language/overrides/$lang.override.ini"; if (file_exists($filename) && $contents = $this->parse($filename)) { if (is_array($contents)) { $this->override = $contents; } unset($contents); } // Look for a language specific localise class $class = str_replace('-', '_', $lang . 'Localise'); $paths = array(); if (defined('JPATH_SITE')) { // Note: Manual indexing to enforce load order. $paths[0] = JPATH_SITE . "/language/overrides/$lang.localise.php"; $paths[2] = JPATH_SITE . "/language/$lang/$lang.localise.php"; } if (defined('JPATH_ADMINISTRATOR')) { // Note: Manual indexing to enforce load order. $paths[1] = JPATH_ADMINISTRATOR . "/language/overrides/$lang.localise.php"; $paths[3] = JPATH_ADMINISTRATOR . "/language/$lang/$lang.localise.php"; } ksort($paths); $path = reset($paths); while (!class_exists($class) && $path) { if (file_exists($path)) { require_once $path; } $path = next($paths); } if (class_exists($class)) { /* Class exists. Try to find * -a transliterate method, * -a getPluralSuffixes method, * -a getIgnoredSearchWords method * -a getLowerLimitSearchWord method * -a getUpperLimitSearchWord method * -a getSearchDisplayCharactersNumber method */ if (method_exists($class, 'transliterate')) { $this->transliterator = array($class, 'transliterate'); } if (method_exists($class, 'getPluralSuffixes')) { $this->pluralSuffixesCallback = array($class, 'getPluralSuffixes'); } if (method_exists($class, 'getIgnoredSearchWords')) { $this->ignoredSearchWordsCallback = array($class, 'getIgnoredSearchWords'); } if (method_exists($class, 'getLowerLimitSearchWord')) { $this->lowerLimitSearchWordCallback = array($class, 'getLowerLimitSearchWord'); } if (method_exists($class, 'getUpperLimitSearchWord')) { $this->upperLimitSearchWordCallback = array($class, 'getUpperLimitSearchWord'); } if (method_exists($class, 'getSearchDisplayedCharactersNumber')) { $this->searchDisplayedCharactersNumberCallback = array($class, 'getSearchDisplayedCharactersNumber'); } } $this->load(); } /** * Returns a language object. * * @param string $lang The language to use. * @param boolean $debug The debug mode. * * @return JLanguage The Language object. * * @since 11.1 */ public static function getInstance($lang, $debug = false) { if (!isset(self::$languages[$lang . $debug])) { self::$languages[$lang . $debug] = new JLanguage($lang, $debug); } return self::$languages[$lang . $debug]; } /** * Translate function, mimics the php gettext (alias _) function. * * The function checks if $jsSafe is true, then if $interpretBackslashes is true. * * @param string $string The string to translate * @param boolean $jsSafe Make the result javascript safe * @param boolean $interpretBackSlashes Interpret \t and \n * * @return string The translation of the string * * @since 11.1 */ public function _($string, $jsSafe = false, $interpretBackSlashes = true) { // Detect empty string if ($string == '') { return ''; } $key = strtoupper($string); if (isset($this->strings[$key])) { $string = $this->debug ? '**' . $this->strings[$key] . '**' : $this->strings[$key]; // Store debug information if ($this->debug) { $caller = $this->getCallerInfo(); if (!array_key_exists($key, $this->used)) { $this->used[$key] = array(); } $this->used[$key][] = $caller; } } else { if ($this->debug) { $caller = $this->getCallerInfo(); $caller['string'] = $string; if (!array_key_exists($key, $this->orphans)) { $this->orphans[$key] = array(); } $this->orphans[$key][] = $caller; $string = '??' . $string . '??'; } } if ($jsSafe) { // Javascript filter $string = addslashes($string); } elseif ($interpretBackSlashes) { // Interpret \n and \t characters $string = str_replace(array('\\\\', '\t', '\n'), array("\\", "\t", "\n"), $string); } return $string; } /** * Transliterate function * * This method processes a string and replaces all accented UTF-8 characters by unaccented * ASCII-7 "equivalents". * * @param string $string The string to transliterate. * * @return string The transliteration of the string. * * @since 11.1 */ public function transliterate($string) { include_once dirname(__FILE__) . '/latin_transliterate.php'; if ($this->transliterator !== null) { return call_user_func($this->transliterator, $string); } $string = JLanguageTransliterate::utf8_latin_to_ascii($string); $string = JString::strtolower($string); return $string; } /** * Getter for transliteration function * * @return string Function name or the actual function for PHP 5.3. * * @since 11.1 */ public function getTransliterator() { return $this->transliterator; } /** * Set the transliteration function. * * @param mixed $function Function name (string) or the actual function for PHP 5.3 (function). * * @return mixed * * @since 11.1 */ public function setTransliterator($function) { $previous = $this->transliterator; $this->transliterator = $function; return $previous; } /** * Returns an array of suffixes for plural rules. * * @param integer $count The count number the rule is for. * * @return array The array of suffixes. * * @since 11.1 */ public function getPluralSuffixes($count) { if ($this->pluralSuffixesCallback !== null) { return call_user_func($this->pluralSuffixesCallback, $count); } else { return array((string) $count); } } /** * Getter for pluralSuffixesCallback function. * * @return mixed Function name (string) or the actual function for PHP 5.3 (function). * * @since 11.1 * * @deprecated 12.1 * @note Use JLanguage::getPluralSuffixesCallback method instead */ public function getPluralSufficesCallback() { // Deprecation warning. JLog::add('JLanguage::_getPluralSufficesCallback() is deprecated.', JLog::WARNING, 'deprecated'); return $this->getPluralSuffixesCallback(); } /** * Getter for pluralSuffixesCallback function. * * @return mixed Function name (string) or the actual function for PHP 5.3 (function). * * @since 11.1 */ public function getPluralSuffixesCallback() { return $this->pluralSuffixesCallback; } /** * Set the pluralSuffixes function. * * @param mixed $function Function name (string) or actual function for PHP 5.3 (function) * * @return mixed Function name or the actual function for PHP 5.3. * * @since 11.1 */ public function setPluralSuffixesCallback($function) { $previous = $this->pluralSuffixesCallback; $this->pluralSuffixesCallback = $function; return $previous; } /** * Returns an array of ignored search words * * @return array The array of ignored search words. * * @since 11.1 */ public function getIgnoredSearchWords() { if ($this->ignoredSearchWordsCallback !== null) { return call_user_func($this->ignoredSearchWordsCallback); } else { return array(); } } /** * Getter for ignoredSearchWordsCallback function. * * @return mixed Function name (string) or the actual function for PHP 5.3 (function). * * @since 11.1 */ public function getIgnoredSearchWordsCallback() { return $this->ignoredSearchWordsCallback; } /** * Setter for the ignoredSearchWordsCallback function * * @param mixed $function Function name (string) or actual function for PHP 5.3 (function) * * @return mixed Function name (string) or the actual function for PHP 5.3 (function) * * @since 11.1 */ public function setIgnoredSearchWordsCallback($function) { $previous = $this->ignoredSearchWordsCallback; $this->ignoredSearchWordsCallback = $function; return $previous; } /** * Returns a lower limit integer for length of search words * * @return integer The lower limit integer for length of search words (3 if no value was set for a specific language). * * @since 11.1 */ public function getLowerLimitSearchWord() { if ($this->lowerLimitSearchWordCallback !== null) { return call_user_func($this->lowerLimitSearchWordCallback); } else { return 3; } } /** * Getter for lowerLimitSearchWordCallback function * * @return mixed Function name (string) or the actual function for PHP 5.3 (function). * * @since 11.1 */ public function getLowerLimitSearchWordCallback() { return $this->lowerLimitSearchWordCallback; } /** * Setter for the lowerLimitSearchWordCallback function. * * @param mixed $function Function name (string) or actual function for PHP 5.3 (function) * * @return string|function Function name or the actual function for PHP 5.3. * * @since 11.1 */ public function setLowerLimitSearchWordCallback($function) { $previous = $this->lowerLimitSearchWordCallback; $this->lowerLimitSearchWordCallback = $function; return $previous; } /** * Returns an upper limit integer for length of search words * * @return integer The upper limit integer for length of search words (20 if no value was set for a specific language). * * @since 11.1 */ public function getUpperLimitSearchWord() { if ($this->upperLimitSearchWordCallback !== null) { return call_user_func($this->upperLimitSearchWordCallback); } else { return 20; } } /** * Getter for upperLimitSearchWordCallback function * * @return string|function Function name or the actual function for PHP 5.3. * * @since 11.1 */ public function getUpperLimitSearchWordCallback() { return $this->upperLimitSearchWordCallback; } /** * Setter for the upperLimitSearchWordCallback function * * @param string $function The name of the callback function. * * @return mixed Function name (string) or the actual function for PHP 5.3 (function). * * @since 11.1 */ public function setUpperLimitSearchWordCallback($function) { $previous = $this->upperLimitSearchWordCallback; $this->upperLimitSearchWordCallback = $function; return $previous; } /** * Returns the number of characters displayed in search results. * * @return integer The number of characters displayed (200 if no value was set for a specific language). * * @since 11.1 */ public function getSearchDisplayedCharactersNumber() { if ($this->searchDisplayedCharactersNumberCallback !== null) { return call_user_func($this->searchDisplayedCharactersNumberCallback); } else { return 200; } } /** * Getter for searchDisplayedCharactersNumberCallback function * * @return mixed Function name or the actual function for PHP 5.3. * * @since 11.1 */ public function getSearchDisplayedCharactersNumberCallback() { return $this->searchDisplayedCharactersNumberCallback; } /** * Setter for the searchDisplayedCharactersNumberCallback function. * * @param string $function The name of the callback. * * @return mixed Function name (string) or the actual function for PHP 5.3 (function). * * @since 11.1 */ public function setSearchDisplayedCharactersNumberCallback($function) { $previous = $this->searchDisplayedCharactersNumberCallback; $this->searchDisplayedCharactersNumberCallback = $function; return $previous; } /** * Checks if a language exists. * * This is a simple, quick check for the directory that should contain language files for the given user. * * @param string $lang Language to check. * @param string $basePath Optional path to check. * * @return boolean True if the language exists. * * @since 11.1 */ public static function exists($lang, $basePath = JPATH_BASE) { static $paths = array(); // Return false if no language was specified if (!$lang) { return false; } $path = "$basePath/language/$lang"; // Return previous check results if it exists if (isset($paths[$path])) { return $paths[$path]; } // Check if the language exists jimport('joomla.filesystem.folder'); $paths[$path] = JFolder::exists($path); return $paths[$path]; } /** * Loads a single language file and appends the results to the existing strings * * @param string $extension The extension for which a language file should be loaded. * @param string $basePath The basepath to use. * @param string $lang The language to load, default null for the current language. * @param boolean $reload Flag that will force a language to be reloaded if set to true. * @param boolean $default Flag that force the default language to be loaded if the current does not exist. * * @return boolean True if the file has successfully loaded. * * @since 11.1 */ public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = null, $reload = false, $default = true) { // Load the default language first if we're not debugging and a non-default language is requested to be loaded // with $default set to true if (!JFactory::getConfig()->get('debug_lang') && ($lang != $this->default) && $default) { $this->load($extension, $basePath, $this->default, false, true); } if (!$lang) { $lang = $this->lang; } $path = self::getLanguagePath($basePath, $lang); $internal = $extension == 'joomla' || $extension == ''; $filename = $internal ? $lang : $lang . '.' . $extension; $filename = "$path/$filename.ini"; $result = false; if (isset($this->paths[$extension][$filename]) && !$reload) { // This file has already been tested for loading. $result = $this->paths[$extension][$filename]; } else { // Load the language file $result = $this->loadLanguage($filename, $extension); // Check whether there was a problem with loading the file if ($result === false && $default) { // No strings, so either file doesn't exist or the file is invalid $oldFilename = $filename; // Check the standard file name $path = self::getLanguagePath($basePath, $this->default); $filename = $internal ? $this->default : $this->default . '.' . $extension; $filename = "$path/$filename.ini"; // If the one we tried is different than the new name, try again if ($oldFilename != $filename) { $result = $this->loadLanguage($filename, $extension, false); } } } return $result; } /** * Loads a language file. * * This method will not note the successful loading of a file - use load() instead. * * @param string $filename The name of the file. * @param string $extension The name of the extension. * @param boolean $overwrite Not used?? * * @return boolean True if new strings have been added to the language * * @see JLanguage::load() * @since 11.1 */ protected function loadLanguage($filename, $extension = 'unknown', $overwrite = true) { $this->counter++; $result = false; $strings = false; if (file_exists($filename)) { $strings = $this->parse($filename); } if ($strings) { if (is_array($strings)) { $this->strings = array_merge($this->strings, $strings); } if (is_array($strings) && count($strings)) { $this->strings = array_merge($this->strings, $this->override); $result = true; } } // Record the result of loading the extension's file. if (!isset($this->paths[$extension])) { $this->paths[$extension] = array(); } $this->paths[$extension][$filename] = $result; return $result; } /** * Parses a language file. * * @param string $filename The name of the file. * * @return array The array of parsed strings. * * @since 11.1 */ protected function parse($filename) { $version = phpversion(); // Capture hidden PHP errors from the parsing. $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); } else { $strings = @parse_ini_file($filename); if ($version == '5.3.0' && is_array($strings)) { foreach ($strings as $key => $string) { $strings[$key] = str_replace('_QQ_', '"', $string); } } } // Restore error tracking to what it was before. ini_set('track_errors', $track_errors); if (!is_array($strings)) { $strings = array(); } if ($this->debug) { // Initialise variables for manually parsing the file for common errors. $blacklist = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE'); $regex = '/^(|(\[[^\]]*\])|([A-Z][A-Z0-9_\-]*\s*=(\s*(("[^"]*")|(_QQ_)))+))\s*(;.*)?$/'; $this->debug = false; $errors = array(); $lineNumber = 0; // Open the file as a stream. $stream = new JStream; $stream->open($filename); while (!$stream->eof()) { $line = $stream->gets(); // Avoid BOM error as BOM is OK when using parse_ini if ($lineNumber == 0) { $line = str_replace("\xEF\xBB\xBF", '', $line); } $lineNumber++; // Check that the key is not in the blacklist and that the line format passes the regex. $key = strtoupper(trim(substr($line, 0, strpos($line, '=')))); if (!preg_match($regex, $line) || in_array($key, $blacklist)) { $errors[] = $lineNumber; } } $stream->close(); // Check if we encountered any errors. if (count($errors)) { if (basename($filename) != $this->lang . '.ini') { $this->errorfiles[$filename] = $filename . JText::sprintf('JERROR_PARSING_LANGUAGE_FILE', implode(', ', $errors)); } else { $this->errorfiles[$filename] = $filename . ' : error(s) in line(s) ' . implode(', ', $errors); } } elseif ($php_errormsg) { // We didn't find any errors but there's probably a parse notice. $this->errorfiles['PHP' . $filename] = 'PHP parser errors :' . $php_errormsg; } $this->debug = true; } return $strings; } /** * Get a metadata language property. * * @param string $property The name of the property. * @param mixed $default The default value. * * @return mixed The value of the property. * * @since 11.1 */ public function get($property, $default = null) { if (isset($this->metadata[$property])) { return $this->metadata[$property]; } return $default; } /** * Determine who called JLanguage or JText. * * @return array Caller information. * * @since 11.1 */ protected function getCallerInfo() { // Try to determine the source if none was provided if (!function_exists('debug_backtrace')) { return null; } $backtrace = debug_backtrace(); $info = array(); // Search through the backtrace to our caller $continue = true; while ($continue && next($backtrace)) { $step = current($backtrace); $class = @ $step['class']; // We're looking for something outside of language.php if ($class != 'JLanguage' && $class != 'JText') { $info['function'] = @ $step['function']; $info['class'] = $class; $info['step'] = prev($backtrace); // Determine the file and name of the file $info['file'] = @ $step['file']; $info['line'] = @ $step['line']; $continue = false; } } return $info; } /** * Getter for Name. * * @return string Official name element of the language. * * @since 11.1 */ public function getName() { return $this->metadata['name']; } /** * Get a list of language files that have been loaded. * * @param string $extension An optional extension name. * * @return array * * @since 11.1 */ public function getPaths($extension = null) { if (isset($extension)) { if (isset($this->paths[$extension])) { return $this->paths[$extension]; } return null; } else { return $this->paths; } } /** * Get a list of language files that are in error state. * * @return array * * @since 11.1 */ public function getErrorFiles() { return $this->errorfiles; } /** * Getter for the language tag (as defined in RFC 3066) * * @return string The language tag. * * @since 11.1 */ public function getTag() { return $this->metadata['tag']; } /** * Get the RTL property. * * @return boolean True is it an RTL language. * * @since 11.1 */ public function isRTL() { return $this->metadata['rtl']; } /** * Set the Debug property. * * @param boolean $debug The debug setting. * * @return boolean Previous value. * * @since 11.1 */ public function setDebug($debug) { $previous = $this->debug; $this->debug = $debug; return $previous; } /** * Get the Debug property. * * @return boolean True is in debug mode. * * @since 11.1 */ public function getDebug() { return $this->debug; } /** * Get the default language code. * * @return string Language code. * * @since 11.1 */ public function getDefault() { return $this->default; } /** * Set the default language code. * * @param string $lang The language code. * * @return string Previous value. * * @since 11.1 */ public function setDefault($lang) { $previous = $this->default; $this->default = $lang; return $previous; } /** * Get the list of orphaned strings if being tracked. * * @return array Orphaned text. * * @since 11.1 */ public function getOrphans() { return $this->orphans; } /** * Get the list of used strings. * * Used strings are those strings requested and found either as a string or a constant. * * @return array Used strings. * * @since 11.1 */ public function getUsed() { return $this->used; } /** * Determines is a key exists. * * @param string $string The key to check. * * @return boolean True, if the key exists. * * @since 11.1 */ public function hasKey($string) { $key = strtoupper($string); return isset($this->strings[$key]); } /** * Returns a associative array holding the metadata. * * @param string $lang The name of the language. * * @return mixed If $lang exists return key/value pair with the language metadata, otherwise return NULL. * * @since 11.1 */ public static function getMetadata($lang) { $path = self::getLanguagePath(JPATH_BASE, $lang); $file = "$lang.xml"; $result = null; if (is_file("$path/$file")) { $result = self::parseXMLLanguageFile("$path/$file"); } return $result; } /** * Returns a list of known languages for an area * * @param string $basePath The basepath to use * * @return array key/value pair with the language file and real name. * * @since 11.1 */ public static function getKnownLanguages($basePath = JPATH_BASE) { $dir = self::getLanguagePath($basePath); $knownLanguages = self::parseLanguageFiles($dir); return $knownLanguages; } /** * Get the path to a language * * @param string $basePath The basepath to use. * @param string $language The language tag. * * @return string language related path or null. * * @since 11.1 */ public static function getLanguagePath($basePath = JPATH_BASE, $language = null) { $dir = "$basePath/language"; if (!empty($language)) { $dir .= "/$language"; } return $dir; } /** * Set the language attributes to the given language. * * Once called, the language still needs to be loaded using JLanguage::load(). * * @param string $lang Language code. * * @return string Previous value. * * @since 11.1 */ public function setLanguage($lang) { $previous = $this->lang; $this->lang = $lang; $this->metadata = $this->getMetadata($this->lang); return $previous; } /** * Get the language locale based on current language. * * @return array The locale according to the language. * * @since 11.1 */ public function getLocale() { if (!isset($this->locale)) { $locale = str_replace(' ', '', isset($this->metadata['locale']) ? $this->metadata['locale'] : ''); if ($locale) { $this->locale = explode(',', $locale); } else { $this->locale = false; } } return $this->locale; } /** * Get the first day of the week for this language. * * @return integer The first day of the week according to the language * * @since 11.1 */ public function getFirstDay() { return (int) (isset($this->metadata['firstDay']) ? $this->metadata['firstDay'] : 0); } /** * Searches for language directories within a certain base dir. * * @param string $dir Directory of files. * * @return array Array holding the found languages as filename => real name pairs. * * @deprecated 12.1 * @note Use parseLanguageFiles instead. * @since 11.1 */ public static function _parseLanguageFiles($dir = null) { // Deprecation warning. JLog::add('JLanguage::_parseLanguageFiles() is deprecated.', JLog::WARNING, 'deprecated'); return self::parseLanguageFiles($dir); } /** * Searches for language directories within a certain base dir. * * @param string $dir directory of files. * * @return array Array holding the found languages as filename => real name pairs. * * @since 11.1 */ public static function parseLanguageFiles($dir = null) { jimport('joomla.filesystem.folder'); $languages = array(); $subdirs = JFolder::folders($dir); foreach ($subdirs as $path) { $langs = self::parseXMLLanguageFiles("$dir/$path"); $languages = array_merge($languages, $langs); } return $languages; } /** * Parses XML files for language information. * * @param string $dir Directory of files. * * @return array Array holding the found languages as filename => metadata array. * * @note Use parseXMLLanguageFiles instead. * @since 11.1 * * @deprecated 12.1 */ public static function _parseXMLLanguageFiles($dir = null) { // Deprecation warning. JLog::add('JLanguage::_parseXMLLanguageFiles() is deprecated.', JLog::WARNING, 'deprecated'); return self::parseXMLLanguageFiles($dir); } /** * Parses XML files for language information * * @param string $dir Directory of files. * * @return array Array holding the found languages as filename => metadata array. * * @since 11.1 */ public static function parseXMLLanguageFiles($dir = null) { if ($dir == null) { return null; } $languages = array(); jimport('joomla.filesystem.folder'); $files = JFolder::files($dir, '^([-_A-Za-z]*)\.xml$'); foreach ($files as $file) { if ($content = file_get_contents("$dir/$file")) { if ($metadata = self::parseXMLLanguageFile("$dir/$file")) { $lang = str_replace('.xml', '', $file); $languages[$lang] = $metadata; } } } return $languages; } /** * Parse XML file for language information. * * @param string $path Path to the XML files. * * @return array Array holding the found metadata as a key => value pair. * * @deprecated 12.1 * @note Use parseXMLLanguageFile instead. * @since 11.1 */ public static function _parseXMLLanguageFile($path) { return self::parseXMLLanguageFile($path); } /** * Parse XML file for language information. * * @param string $path Path to the XML files. * * @return array Array holding the found metadata as a key => value pair. * * @since 11.1 */ public static function parseXMLLanguageFile($path) { // Try to load the file if (!$xml = JFactory::getXML($path)) { return null; } // Check that it's a metadata file if ((string) $xml->getName() != 'metafile') { return null; } $metadata = array(); foreach ($xml->metadata->children() as $child) { $metadata[$child->getName()] = (string) $child; } return $metadata; } }
©
2018.