You've already forked joomla_test
							
							first commit
This commit is contained in:
		| @ -0,0 +1 @@ | ||||
| <!DOCTYPE html><title></title> | ||||
							
								
								
									
										113
									
								
								administrator/components/com_languages/models/forms/language.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								administrator/components/com_languages/models/forms/language.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,113 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <form> | ||||
| 	<fieldset> | ||||
| 		<field name="lang_id" type="text" | ||||
| 			class="readonly" | ||||
| 			description="JGLOBAL_FIELD_ID_DESC" | ||||
| 			label="JGLOBAL_FIELD_ID_LABEL" | ||||
| 			default="0" | ||||
| 			readonly="true" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="lang_code" type="text" | ||||
| 			class="inputbox" | ||||
| 			description="COM_LANGUAGES_FIELD_LANG_TAG_DESC" | ||||
| 			label="COM_LANGUAGES_FIELD_LANG_TAG_LABEL" | ||||
| 			maxlength="7" | ||||
| 			required="true" | ||||
| 			size="10" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="title" type="text" | ||||
| 			class="inputbox" | ||||
| 			description="COM_LANGUAGES_FIELD_TITLE_DESC" | ||||
| 			label="JGLOBAL_TITLE" | ||||
| 			maxlength="50" | ||||
| 			required="true" | ||||
| 			size="40" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="title_native" type="text" | ||||
| 			class="inputbox" | ||||
| 			description="COM_LANGUAGES_FIELD_TITLE_NATIVE_DESC" | ||||
| 			label="COM_LANGUAGES_FIELD_TITLE_NATIVE_LABEL" | ||||
| 			maxlength="50" | ||||
| 			required="true" | ||||
| 			size="40" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="sef" type="text" | ||||
| 			class="inputbox" | ||||
| 			description="COM_LANGUAGES_FIELD_LANG_CODE_DESC" | ||||
| 			label="COM_LANGUAGES_FIELD_LANG_CODE_LABEL" | ||||
| 			maxlength="7" | ||||
| 			required="true" | ||||
| 			size="10" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="image" type="filelist" | ||||
| 			class="inputbox" | ||||
| 			description="COM_LANGUAGES_FIELD_IMAGE_DESC" | ||||
| 			label="COM_LANGUAGES_FIELD_IMAGE_LABEL" | ||||
| 			stripext="1" | ||||
| 			directory="media/mod_languages/images/" | ||||
| 			hide_none="1" | ||||
| 			hide_default="1" | ||||
| 			required="true" | ||||
| 			filter="\.gif$" | ||||
| 			size="10" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="description" type="textarea" | ||||
| 			class="inputbox" | ||||
| 			cols="80" | ||||
| 			description="COM_LANGUAGES_FIELD_DESCRIPTION_DESC" | ||||
| 			label="JGLOBAL_DESCRIPTION" | ||||
| 			rows="5" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="published" type="list" | ||||
| 			class="inputbox" | ||||
| 			default="1" | ||||
| 			description="COM_LANGUAGES_FIELD_PUBLISHED_DESC" | ||||
| 			label="JSTATUS" | ||||
| 			size="1" | ||||
| 		> | ||||
| 			<option value="1">JPUBLISHED</option> | ||||
| 			<option value="0">JUNPUBLISHED</option> | ||||
| 			<option value="-2">JTRASHED</option> | ||||
| 		</field> | ||||
| 		 | ||||
| 		<field name="access" type="accesslevel" | ||||
| 		class="inputbox" | ||||
| 		size="1" | ||||
| 		label="JFIELD_ACCESS_LABEL" | ||||
| 		description="JFIELD_ACCESS_DESC" | ||||
| 		/> | ||||
| 	</fieldset> | ||||
| 	<fieldset name="metadata" label="JGLOBAL_FIELDSET_METADATA_OPTIONS"> | ||||
| 		<field name="metakey" type="textarea" | ||||
| 			class="inputbox" | ||||
| 			description="JFIELD_META_KEYWORDS_DESC" | ||||
| 			label="JFIELD_META_KEYWORDS_LABEL" | ||||
| 			rows="3" | ||||
| 			cols="30" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="metadesc" type="textarea" | ||||
| 			class="inputbox" | ||||
| 			description="JFIELD_META_DESCRIPTION_DESC" | ||||
| 			label="JFIELD_META_DESCRIPTION_LABEL" | ||||
| 			rows="3" | ||||
| 			cols="30" | ||||
| 		/> | ||||
| 	</fieldset> | ||||
| 	<fieldset name="site_name" label="COM_LANGUAGES_FIELDSET_SITE_NAME_LABEL"> | ||||
| 		<field name="sitename" type="text" | ||||
| 			description="COM_LANGUAGES_FIELD_SITE_NAME_DESC" | ||||
| 			label="COM_LANGUAGES_FIELD_SITE_NAME_LABEL" | ||||
| 			filter="string" | ||||
| 			size="50" | ||||
| 		/> | ||||
| 	</fieldset> | ||||
| </form> | ||||
| @ -0,0 +1,83 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <form> | ||||
| 	<fieldset> | ||||
| 		<field | ||||
| 			name="key" | ||||
| 			type="text" | ||||
| 			class="inputbox" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_KEY_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_KEY_DESC" | ||||
| 			size="60" | ||||
| 			required="true" | ||||
| 			filter="LanguagesHelper::filterKey" /> | ||||
|  | ||||
| 		<field | ||||
| 			name="override" | ||||
| 			type="textarea" | ||||
| 			class="inputbox" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_OVERRIDE_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_OVERRIDE_DESC" | ||||
| 			cols="50" | ||||
| 			rows="5" | ||||
| 			filter="LanguagesHelper::filterText" /> | ||||
|  | ||||
| 		<field | ||||
| 			name="both" | ||||
| 			type="checkbox" | ||||
| 			class="inputbox" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_BOTH_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_BOTH_DESC" | ||||
| 			value="true" | ||||
| 			filter="boolean" /> | ||||
|  | ||||
| 		<field | ||||
| 			name="searchstring" | ||||
| 			type="text" | ||||
| 			class="inputbox" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_SEARCHSTRING_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_SEARCHSTRING_DESC" | ||||
| 			size="50" /> | ||||
|  | ||||
| 		<field | ||||
| 			name="searchtype" | ||||
| 			type="radio" | ||||
| 			class="btn-group" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_DESC" | ||||
| 			default="value"> | ||||
| 			<option value="constant">COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_CONSTANT</option> | ||||
| 			<option value="value">COM_LANGUAGES_OVERRIDE_FIELD_SEARCHTYPE_TEXT</option> | ||||
| 		</field> | ||||
|  | ||||
| 		<field name="language" type="text" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_LANGUAGE_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_LANGUAGE_DESC" | ||||
| 			filter="unset" | ||||
| 			readonly="true" | ||||
| 			class="readonly" | ||||
| 			size="50" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="client" type="text" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_CLIENT_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_CLIENT_DESC" | ||||
| 			filter="unset" | ||||
| 			readonly="true" | ||||
| 			class="readonly" | ||||
| 			size="50" | ||||
| 		/> | ||||
|  | ||||
| 		<field name="file" type="text" | ||||
| 			label="COM_LANGUAGES_OVERRIDE_FIELD_FILE_LABEL" | ||||
| 			description="COM_LANGUAGES_OVERRIDE_FIELD_FILE_DESC" | ||||
| 			filter="unset" | ||||
| 			readonly="true" | ||||
| 			class="readonly" | ||||
| 			size="80" | ||||
| 		/> | ||||
|  | ||||
| 		<field | ||||
| 			name="id" | ||||
| 			type="hidden" /> | ||||
| 	</fieldset> | ||||
| </form> | ||||
							
								
								
									
										1
									
								
								administrator/components/com_languages/models/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								administrator/components/com_languages/models/index.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| <!DOCTYPE html><title></title> | ||||
							
								
								
									
										384
									
								
								administrator/components/com_languages/models/installed.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										384
									
								
								administrator/components/com_languages/models/installed.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,384 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Languages Component Languages Model | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * @since       1.6 | ||||
|  */ | ||||
| class LanguagesModelInstalled extends JModelList | ||||
| { | ||||
| 	/** | ||||
| 	 * @var object client object | ||||
| 	 */ | ||||
| 	protected $client = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var object user object | ||||
| 	 */ | ||||
| 	protected $user = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var boolean|JExeption True, if FTP settings should be shown, or an exeption | ||||
| 	 */ | ||||
| 	protected $ftp = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var string option name | ||||
| 	 */ | ||||
| 	protected $option = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var array languages description | ||||
| 	 */ | ||||
| 	protected $data = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var int total number pf languages | ||||
| 	 */ | ||||
| 	protected $total = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var int total number pf languages installed | ||||
| 	 */ | ||||
| 	protected $langlist = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var string language path | ||||
| 	 */ | ||||
| 	protected $path = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * 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($ordering = null, $direction = null) | ||||
| 	{ | ||||
| 		$app = JFactory::getApplication('administrator'); | ||||
|  | ||||
| 		// Load the filter state. | ||||
| 		$clientId = $app->input->getInt('client'); | ||||
| 		$this->setState('filter.client_id', $clientId); | ||||
|  | ||||
| 		// Load the parameters. | ||||
| 		$params = JComponentHelper::getParams('com_languages'); | ||||
| 		$this->setState('params', $params); | ||||
|  | ||||
| 		// List state information. | ||||
| 		parent::populateState('a.name', 'asc'); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get a store id based on model configuration state. | ||||
| 	 * | ||||
| 	 * This is necessary because the model is used by the component and | ||||
| 	 * different modules that might need different sets of data or different | ||||
| 	 * ordering requirements. | ||||
| 	 * | ||||
| 	 * @param   string  $id	A prefix for the store id. | ||||
| 	 * | ||||
| 	 * @return  string  A store id. | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getStoreId($id = '') | ||||
| 	{ | ||||
| 		// Compile the store id. | ||||
| 		$id	.= ':'.$this->getState('filter.client_id'); | ||||
|  | ||||
| 		return parent::getStoreId($id); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the client object | ||||
| 	 * | ||||
| 	 * @return  object | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function &getClient() | ||||
| 	{ | ||||
| 		if (is_null($this->client)) | ||||
| 		{ | ||||
| 			$this->client = JApplicationHelper::getClientInfo($this->getState('filter.client_id', 0)); | ||||
| 		} | ||||
|  | ||||
| 		return $this->client; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the ftp credentials | ||||
| 	 * | ||||
| 	 * @return  object | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function &getFtp() | ||||
| 	{ | ||||
| 		if (is_null($this->ftp)) | ||||
| 		{ | ||||
| 			$this->ftp = JClientHelper::setCredentialsFromRequest('ftp'); | ||||
| 		} | ||||
|  | ||||
| 		return $this->ftp; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the option | ||||
| 	 * | ||||
| 	 * @return  object | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function &getOption() | ||||
| 	{ | ||||
| 		$option = $this->getState('option'); | ||||
|  | ||||
| 		return $option; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get Languages item data | ||||
| 	 * | ||||
| 	 * @return  array | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function &getData() | ||||
| 	{ | ||||
| 		if (is_null($this->data)) { | ||||
|  | ||||
| 			// Get information | ||||
| 			$path		= $this->getPath(); | ||||
| 			$client		= $this->getClient(); | ||||
| 			$langlist   = $this->getLanguageList(); | ||||
|  | ||||
| 			// Compute all the languages | ||||
| 			$data	= array (); | ||||
|  | ||||
| 			foreach ($langlist as $lang) { | ||||
| 				$file = $path . '/' . $lang . '/' . $lang.'.xml'; | ||||
| 				$info = JApplicationHelper::parseXMLLangMetaFile($file); | ||||
| 				$row = new JObject; | ||||
| 				$row->language = $lang; | ||||
|  | ||||
| 				if (!is_array($info)) | ||||
| 				{ | ||||
| 					continue; | ||||
| 				} | ||||
|  | ||||
| 				foreach ($info as $key => $value) | ||||
| 				{ | ||||
| 					$row->$key = $value; | ||||
| 				} | ||||
|  | ||||
| 				// if current than set published | ||||
| 				$params = JComponentHelper::getParams('com_languages'); | ||||
| 				if ($params->get($client->name, 'en-GB') == $row->language) | ||||
| 				{ | ||||
| 					$row->published	= 1; | ||||
| 				} | ||||
| 				else { | ||||
| 					$row->published = 0; | ||||
| 				} | ||||
|  | ||||
| 				$row->checked_out = 0; | ||||
| 				$data[] = $row; | ||||
| 			} | ||||
| 			usort($data, array($this, 'compareLanguages')); | ||||
|  | ||||
| 			// Prepare data | ||||
| 			$limit = $this->getState('list.limit'); | ||||
| 			$start = $this->getState('list.start'); | ||||
| 			$total = $this->getTotal(); | ||||
|  | ||||
| 			if ($limit == 0) | ||||
| 			{ | ||||
| 				$start = 0; | ||||
| 				$end = $total; | ||||
| 			} | ||||
| 			else { | ||||
| 				if ($start > $total) | ||||
| 				{ | ||||
| 					$start = $total - $total % $limit; | ||||
| 				} | ||||
| 				$end = $start + $limit; | ||||
|  | ||||
| 				if ($end > $total) | ||||
| 				{ | ||||
| 					$end = $total; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			// Compute the displayed languages | ||||
| 			$this->data	= array(); | ||||
| 			for ($i = $start;$i < $end;$i++) | ||||
| 			{ | ||||
| 				$this->data[] = & $data[$i]; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		return $this->data; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get installed languages data. | ||||
| 	 * | ||||
| 	 * @return  string	An SQL query | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getLanguageList() | ||||
| 	{ | ||||
| 		// Create a new db object. | ||||
| 		$db = $this->getDbo(); | ||||
| 		$query = $db->getQuery(true); | ||||
| 		$client = $this->getState('filter.client_id'); | ||||
| 		$type = "language"; | ||||
| 		// Select field element from the extensions table. | ||||
| 		$query->select($this->getState('list.select', 'a.element')) | ||||
| 			->from('#__extensions AS a'); | ||||
|  | ||||
| 		$type = $db->quote($type); | ||||
| 		$query->where('(a.type = '.$type.')') | ||||
|  | ||||
| 			->where('state = 0') | ||||
| 			->where('enabled = 1') | ||||
|  | ||||
| 			->where('client_id=' . (int) $client); | ||||
|  | ||||
| 		// for client_id = 1 do we need to check language table also ? | ||||
| 		$db->setQuery($query); | ||||
|  | ||||
| 		$this->langlist = $db->loadColumn(); | ||||
|  | ||||
| 		return $this->langlist; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the total number of Languages items | ||||
| 	 * | ||||
| 	 * @return  integer | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function getTotal() | ||||
| 	{ | ||||
| 		if (is_null($this->total)) | ||||
| 		{ | ||||
| 			$langlist = $this->getLanguageList(); | ||||
| 			$this->total = count($langlist); | ||||
| 		} | ||||
|  | ||||
| 		return $this->total; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to set the default language | ||||
| 	 * | ||||
| 	 * @return  boolean | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function publish($cid) | ||||
| 	{ | ||||
| 		if ($cid) | ||||
| 		{ | ||||
| 			$client	= $this->getClient(); | ||||
|  | ||||
| 			$params = JComponentHelper::getParams('com_languages'); | ||||
| 			$params->set($client->name, $cid); | ||||
|  | ||||
| 			$table = JTable::getInstance('extension'); | ||||
| 			$id = $table->find(array('element' => 'com_languages')); | ||||
|  | ||||
| 			// Load | ||||
| 			if (!$table->load($id)) | ||||
| 			{ | ||||
| 				$this->setError($table->getError()); | ||||
| 				return false; | ||||
| 			} | ||||
|  | ||||
| 			$table->params = (string) $params; | ||||
| 			// pre-save checks | ||||
| 			if (!$table->check()) | ||||
| 			{ | ||||
| 				$this->setError($table->getError()); | ||||
| 				return false; | ||||
| 			} | ||||
|  | ||||
| 			// save the changes | ||||
| 			if (!$table->store()) | ||||
| 			{ | ||||
| 				$this->setError($table->getError()); | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			$this->setError(JText::_('COM_LANGUAGES_ERR_NO_LANGUAGE_SELECTED')); | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// Clean the cache of com_languages and component cache. | ||||
| 		$this->cleanCache(); | ||||
| 		$this->cleanCache('_system'); | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the folders | ||||
| 	 * | ||||
| 	 * @return  array  Languages folders | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getFolders() | ||||
| 	{ | ||||
| 		if (is_null($this->folders)) | ||||
| 		{ | ||||
| 			$path = $this->getPath(); | ||||
| 			jimport('joomla.filesystem.folder'); | ||||
| 			$this->folders = JFolder::folders($path, '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); | ||||
| 		} | ||||
|  | ||||
| 		return $this->folders; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the path | ||||
| 	 * | ||||
| 	 * @return  string	The path to the languages folders | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getPath() | ||||
| 	{ | ||||
| 		if (is_null($this->path)) | ||||
| 		{ | ||||
| 			$client = $this->getClient(); | ||||
| 			$this->path = JLanguage::getLanguagePath($client->path); | ||||
| 		} | ||||
|  | ||||
| 		return $this->path; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to compare two languages in order to sort them | ||||
| 	 * | ||||
| 	 * @param   object	$lang1 the first language | ||||
| 	 * @param   object	$lang2 the second language | ||||
| 	 * | ||||
| 	 * @return  integer | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function compareLanguages($lang1, $lang2) | ||||
| 	{ | ||||
| 		return strcmp($lang1->name, $lang2->name); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										204
									
								
								administrator/components/com_languages/models/language.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										204
									
								
								administrator/components/com_languages/models/language.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,204 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * 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 = $app->input->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) | ||||
| 	{ | ||||
| 		$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; | ||||
| 		} | ||||
|  | ||||
| 		$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(); | ||||
| 		} | ||||
|  | ||||
| 		$this->preprocessData('com_languages.language', $data); | ||||
|  | ||||
| 		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 = JEventDispatcher::getInstance(); | ||||
| 		JPluginHelper::importPlugin('extension'); | ||||
|  | ||||
| 		$table = $this->getTable(); | ||||
|  | ||||
| 		// Load the row if saving an existing item. | ||||
| 		if ($langId > 0) | ||||
| 		{ | ||||
| 			$table->load($langId); | ||||
| 			$isNew = false; | ||||
| 		} | ||||
|  | ||||
| 		// 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'); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										215
									
								
								administrator/components/com_languages/models/languages.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										215
									
								
								administrator/components/com_languages/models/languages.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,215 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Languages Model Class | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * @since       1.6 | ||||
|  */ | ||||
| class LanguagesModelLanguages extends JModelList | ||||
| { | ||||
| 	/** | ||||
| 	 * Constructor. | ||||
| 	 * | ||||
| 	 * @param   array  An optional associative array of configuration settings. | ||||
| 	 * @see     JController | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function __construct($config = array()) | ||||
| 	{ | ||||
| 		if (empty($config['filter_fields'])) | ||||
| 		{ | ||||
| 			$config['filter_fields'] = array( | ||||
| 				'lang_id', 'a.lang_id', | ||||
| 				'lang_code', 'a.lang_code', | ||||
| 				'title', 'a.title', | ||||
| 				'title_native', 'a.title_native', | ||||
| 				'sef', 'a.sef', | ||||
| 				'image', 'a.image', | ||||
| 				'published', 'a.published', | ||||
| 				'ordering', 'a.ordering', | ||||
| 				'access', 'a.access', 'access_level', | ||||
| 				'home', 'l.home', | ||||
| 			); | ||||
| 		} | ||||
|  | ||||
| 		parent::__construct($config); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to auto-populate the model state. | ||||
| 	 * | ||||
| 	 * Note. Calling getState in this method will result in recursion. | ||||
| 	 * | ||||
| 	 * @param   string  $ordering   An optional ordering field. | ||||
| 	 * @param   string  $direction  An optional direction (asc|desc). | ||||
| 	 * | ||||
| 	 * @return  void | ||||
| 	 * | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function populateState($ordering = null, $direction = null) | ||||
| 	{ | ||||
| 		// Load the filter state. | ||||
| 		$search = $this->getUserStateFromRequest($this->context . '.search', 'filter_search'); | ||||
| 		$this->setState('filter.search', $search); | ||||
|  | ||||
| 		$accessId = $this->getUserStateFromRequest($this->context . '.access', 'filter_access', null, 'int'); | ||||
| 		$this->setState('filter.access', $accessId); | ||||
|  | ||||
| 		$published = $this->getUserStateFromRequest($this->context . '.published', 'filter_published', ''); | ||||
| 		$this->setState('filter.published', $published); | ||||
|  | ||||
| 		// Load the parameters. | ||||
| 		$params = JComponentHelper::getParams('com_languages'); | ||||
| 		$this->setState('params', $params); | ||||
|  | ||||
| 		// List state information. | ||||
| 		parent::populateState('a.title', 'asc'); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get a store id based on model configuration state. | ||||
| 	 * | ||||
| 	 * This is necessary because the model is used by the component and | ||||
| 	 * different modules that might need different sets of data or different | ||||
| 	 * ordering requirements. | ||||
| 	 * | ||||
| 	 * @param   string  $id    A prefix for the store id. | ||||
| 	 * | ||||
| 	 * @return  string  A store id. | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getStoreId($id = '') | ||||
| 	{ | ||||
| 		// Compile the store id. | ||||
| 		$id .= ':' . $this->getState('filter.search'); | ||||
| 		$id .= ':' . $this->getState('filter.access'); | ||||
| 		$id .= ':' . $this->getState('filter.published'); | ||||
|  | ||||
| 		return parent::getStoreId($id); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to build an SQL query to load the list data. | ||||
| 	 * | ||||
| 	 * @return  string    An SQL query | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getListQuery() | ||||
| 	{ | ||||
| 		// Create a new query object. | ||||
| 		$db = $this->getDbo(); | ||||
| 		$query = $db->getQuery(true); | ||||
|  | ||||
| 		// Select all fields from the languages table. | ||||
| 		$query->select($this->getState('list.select', 'a.*', 'l.home')) | ||||
| 			->from($db->quoteName('#__languages') . ' AS a'); | ||||
|  | ||||
| 		// Join over the asset groups. | ||||
| 		$query->select('ag.title AS access_level') | ||||
| 			->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); | ||||
|  | ||||
| 		// Select the language home pages | ||||
| 		$query->select('l.home AS home') | ||||
| 			->join('LEFT', $db->quoteName('#__menu') . ' AS l  ON  l.language = a.lang_code AND l.home=1  AND l.language <> ' . $db->quote('*')); | ||||
|  | ||||
| 		// Filter on the published state. | ||||
| 		$published = $this->getState('filter.published'); | ||||
| 		if (is_numeric($published)) | ||||
| 		{ | ||||
| 			$query->where('a.published = ' . (int) $published); | ||||
| 		} | ||||
| 		elseif ($published === '') | ||||
| 		{ | ||||
| 			$query->where('(a.published IN (0, 1))'); | ||||
| 		} | ||||
|  | ||||
| 		// Filter by search in title | ||||
| 		$search = $this->getState('filter.search'); | ||||
| 		if (!empty($search)) | ||||
| 		{ | ||||
| 			$search = $db->quote('%' . $db->escape($search, true) . '%', false); | ||||
| 			$query->where('(a.title LIKE ' . $search . ')'); | ||||
| 		} | ||||
|  | ||||
| 		// Filter by access level. | ||||
| 		if ($access = $this->getState('filter.access')) | ||||
| 		{ | ||||
| 			$query->where('a.access = ' . (int) $access); | ||||
| 		} | ||||
|  | ||||
| 		// Add the list ordering clause. | ||||
| 		$query->order($db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); | ||||
|  | ||||
| 		return $query; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the published language(s) | ||||
| 	 * | ||||
| 	 * @param   array    $cid      An array of language IDs. | ||||
| 	 * @param   integer  $value    The value of the published state. | ||||
| 	 * | ||||
| 	 * @return  boolean  True on success, false otherwise. | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function setPublished($cid, $value = 0) | ||||
| 	{ | ||||
| 		return JTable::getInstance('Language')->publish($cid, $value); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to delete records. | ||||
| 	 * | ||||
| 	 * @param   array  An array of item primary keys. | ||||
| 	 * | ||||
| 	 * @return  boolean  Returns true on success, false on failure. | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function delete($pks) | ||||
| 	{ | ||||
| 		// Sanitize the array. | ||||
| 		$pks = (array) $pks; | ||||
|  | ||||
| 		// Get a row instance. | ||||
| 		$table = JTable::getInstance('Language'); | ||||
|  | ||||
| 		// Iterate the items to delete each one. | ||||
| 		foreach ($pks as $itemId) | ||||
| 		{ | ||||
| 			if (!$table->delete((int) $itemId)) | ||||
| 			{ | ||||
| 				$this->setError($table->getError()); | ||||
|  | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		// Clean the cache. | ||||
| 		$this->cleanCache(); | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Custom clean cache method, 2 places for 2 clients | ||||
| 	 * | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function cleanCache($group = null, $client_id = 0) | ||||
| 	{ | ||||
| 		parent::cleanCache('_system'); | ||||
| 		parent::cleanCache('com_languages'); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										204
									
								
								administrator/components/com_languages/models/override.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										204
									
								
								administrator/components/com_languages/models/override.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,204 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Languages Override Model | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * @since       2.5 | ||||
|  */ | ||||
| class LanguagesModelOverride extends JModelAdmin | ||||
| { | ||||
| 	/** | ||||
| 	 * Method to get the record 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		2.5 | ||||
| 	 */ | ||||
| 	public function getForm($data = array(), $loadData = true) | ||||
| 	{ | ||||
| 		// Get the form | ||||
| 		$form = $this->loadForm('com_languages.override', 'override', array('control' => 'jform', 'load_data' => $loadData)); | ||||
| 		if (empty($form)) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		$client		= $this->getState('filter.client', 'site'); | ||||
| 		$language	= $this->getState('filter.language', 'en-GB'); | ||||
| 		$langName	= JLanguage::getInstance($language)->getName(); | ||||
| 		if (!$langName) | ||||
| 		{ | ||||
| 			// If a language only exists in frontend, it's meta data cannot be | ||||
| 			// loaded in backend at the moment, so fall back to the language tag | ||||
| 			$langName = $language; | ||||
| 		} | ||||
| 		$form->setValue('client', null, JText::_('COM_LANGUAGES_VIEW_OVERRIDE_CLIENT_'.strtoupper($client))); | ||||
| 		$form->setValue('language', null, JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDE_LANGUAGE', $langName, $language)); | ||||
| 		$form->setValue('file', null, JPath::clean(constant('JPATH_'.strtoupper($client)) . '/language/overrides/' . $language . '.override.ini')); | ||||
|  | ||||
| 		return $form; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the data that should be injected in the form. | ||||
| 	 * | ||||
| 	 * @return  mixed The data for the form | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	protected function loadFormData() | ||||
| 	{ | ||||
| 		// Check the session for previously entered form data. | ||||
| 		$data = JFactory::getApplication()->getUserState('com_languages.edit.override.data', array()); | ||||
|  | ||||
| 		if (empty($data)) | ||||
| 		{ | ||||
| 			$data = $this->getItem(); | ||||
| 		} | ||||
|  | ||||
| 		$this->preprocessData('com_languages.override', $data); | ||||
|  | ||||
| 		return $data; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get a single record. | ||||
| 	 * | ||||
| 	 * @param   	string	$pk	The key name. | ||||
| 	 * | ||||
| 	 * @return  mixed  	Object on success, false otherwise. | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	public function getItem($pk = null) | ||||
| 	{ | ||||
| 		require_once JPATH_COMPONENT.'/helpers/languages.php'; | ||||
|  | ||||
| 		$input = JFactory::getApplication()->input; | ||||
| 		$pk	= (!empty($pk)) ? $pk : $input->get('id'); | ||||
| 		$filename = constant('JPATH_'.strtoupper($this->getState('filter.client'))) . '/language/overrides/' . $this->getState('filter.language', 'en-GB').'.override.ini'; | ||||
| 		$strings = LanguagesHelper::parseFile($filename); | ||||
|  | ||||
| 		$result = new stdClass; | ||||
| 		$result->key      = ''; | ||||
| 		$result->override = ''; | ||||
| 		if (isset($strings[$pk])) | ||||
| 		{ | ||||
| 			$result->key      = $pk; | ||||
| 			$result->override = $strings[$pk]; | ||||
| 		} | ||||
|  | ||||
| 		return $result; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to save the form data. | ||||
| 	 * | ||||
| 	 * @param   	array		$data							The form data. | ||||
| 	 * @param   	boolean	$opposite_client	Indicates whether the override should not be created for the current client | ||||
| 	 * | ||||
| 	 * @return  boolean  True on success, false otherwise. | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	public function save($data, $opposite_client = false) | ||||
| 	{ | ||||
| 		$app = JFactory::getApplication(); | ||||
| 		require_once JPATH_COMPONENT.'/helpers/languages.php'; | ||||
| 		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); | ||||
|  | ||||
| 		if (!JFile::write($filename, $registry->toString('INI'))) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// If the override should be stored for both clients save | ||||
| 		// it also for the other one and prevent endless recursion | ||||
| 		if (isset($data['both']) && $data['both'] && !$opposite_client) | ||||
| 		{ | ||||
| 			return $this->save($data, true); | ||||
| 		} | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to auto-populate the model state. | ||||
| 	 * | ||||
| 	 * Note. Calling getState in this method will result in recursion. | ||||
| 	 * | ||||
| 	 * @return  void | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	protected function populateState() | ||||
| 	{ | ||||
| 		$app = JFactory::getApplication(); | ||||
|  | ||||
| 		$client = $app->getUserStateFromRequest('com_languages.overrides.filter.client', 'filter_client', 0, 'int') ? 'administrator' : 'site'; | ||||
| 		$this->setState('filter.client', $client); | ||||
|  | ||||
| 		$language = $app->getUserStateFromRequest('com_languages.overrides.filter.language', 'filter_language', 'en-GB', 'cmd'); | ||||
| 		$this->setState('filter.language', $language); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										264
									
								
								administrator/components/com_languages/models/overrides.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										264
									
								
								administrator/components/com_languages/models/overrides.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,264 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Languages Overrides Model | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * @since       2.5 | ||||
|  */ | ||||
| class LanguagesModelOverrides extends JModelList | ||||
| { | ||||
| 	/** | ||||
| 	 * Constructor | ||||
| 	 * | ||||
| 	 * @param   	array	An optional associative array of configuration settings | ||||
| 	 * | ||||
| 	 * @return  void | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	public function __construct($config = array()) | ||||
| 	{ | ||||
| 		parent::__construct($config); | ||||
|  | ||||
| 		$this->filter_fields = array('key', 'text'); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Retrieves the overrides data | ||||
| 	 * | ||||
| 	 * @param   	boolean	True if all overrides shall be returned without considering pagination, defaults to false | ||||
| 	 * | ||||
| 	 * @return  array  	Array of objects containing the overrides of the override.ini file | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	public function getOverrides($all = false) | ||||
| 	{ | ||||
| 		// Get a storage key | ||||
| 		$store = $this->getStoreId(); | ||||
|  | ||||
| 		// Try to load the data from internal storage | ||||
| 		if (!empty($this->cache[$store])) | ||||
| 		{ | ||||
| 			return $this->cache[$store]; | ||||
| 		} | ||||
|  | ||||
| 		// Parse the override.ini file in oder to get the keys and strings | ||||
| 		$filename = constant('JPATH_' . strtoupper($this->getState('filter.client'))) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini'; | ||||
| 		$strings = LanguagesHelper::parseFile($filename); | ||||
|  | ||||
| 		// Consider the odering | ||||
| 		if ($this->getState('list.ordering') == 'text') | ||||
| 		{ | ||||
| 			if (strtoupper($this->getState('list.direction')) == 'DESC') | ||||
| 			{ | ||||
| 				arsort($strings); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				asort($strings); | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			if (strtoupper($this->getState('list.direction')) == 'DESC') | ||||
| 			{ | ||||
| 				krsort($strings); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				ksort($strings); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		// Consider the pagination | ||||
| 		if (!$all && $this->getState('list.limit') && $this->getTotal() > $this->getState('list.limit')) | ||||
| 		{ | ||||
| 			$strings = array_slice($strings, $this->getStart(), $this->getState('list.limit'), true); | ||||
| 		} | ||||
|  | ||||
| 		// Add the items to the internal cache | ||||
| 		$this->cache[$store] = $strings; | ||||
|  | ||||
| 		return $this->cache[$store]; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the total number of overrides | ||||
| 	 * | ||||
| 	 * @return  int	The total number of overrides | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	public function getTotal() | ||||
| 	{ | ||||
| 		// Get a storage key | ||||
| 		$store = $this->getStoreId('getTotal'); | ||||
|  | ||||
| 		// Try to load the data from internal storage | ||||
| 		if (!empty($this->cache[$store])) | ||||
| 		{ | ||||
| 			return $this->cache[$store]; | ||||
| 		} | ||||
|  | ||||
| 		// Add the total to the internal cache | ||||
| 		$this->cache[$store] = count($this->getOverrides(true)); | ||||
|  | ||||
| 		return $this->cache[$store]; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to auto-populate the model state. | ||||
| 	 * | ||||
| 	 * Note. Calling getState in this method will result in recursion. | ||||
| 	 * | ||||
| 	 * @param   	string	An optional ordering field. | ||||
| 	 * @param   	string	An optional direction (asc|desc). | ||||
| 	 * | ||||
| 	 * @return  void | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	protected function populateState($ordering = null, $direction = null) | ||||
| 	{ | ||||
| 		$app = JFactory::getApplication(); | ||||
|  | ||||
| 		// Use default language of frontend for default filter | ||||
| 		$default	= JComponentHelper::getParams('com_languages')->get('site').'0'; | ||||
|  | ||||
| 		$old_language_client	= $app->getUserState('com_languages.overrides.filter.language_client', ''); | ||||
| 		$language_client			= $this->getUserStateFromRequest('com_languages.overrides.filter.language_client', 'filter_language_client', $default, 'cmd'); | ||||
|  | ||||
| 		if ($old_language_client != $language_client) | ||||
| 		{ | ||||
| 			$client		= substr($language_client, -1); | ||||
| 			$language	= substr($language_client, 0, -1); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			$client		= $app->getUserState('com_languages.overrides.filter.client', 0); | ||||
| 			$language	= $app->getUserState('com_languages.overrides.filter.language', 'en-GB'); | ||||
| 		} | ||||
|  | ||||
| 		$this->setState('filter.language_client', $language.$client); | ||||
| 		$this->setState('filter.client', $client ? 'administrator' : 'site'); | ||||
| 		$this->setState('filter.language', $language); | ||||
|  | ||||
| 		// Add filters to the session because they won't be stored there | ||||
| 		// by 'getUserStateFromRequest' if they aren't in the current request | ||||
| 		$app->setUserState('com_languages.overrides.filter.client', $client); | ||||
| 		$app->setUserState('com_languages.overrides.filter.language', $language); | ||||
|  | ||||
| 		// List state information | ||||
| 		parent::populateState('key', 'asc'); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get all found languages of frontend and backend. | ||||
| 	 * | ||||
| 	 * The resulting array has entries of the following style: | ||||
| 	 * <Language Tag>0|1 => <Language Name> - <Client Name> | ||||
| 	 * | ||||
| 	 * @return  array  Sorted associative array of languages | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	public function getLanguages() | ||||
| 	{ | ||||
| 		// Try to load the data from internal storage | ||||
| 		if (!empty($this->cache['languages'])) | ||||
| 		{ | ||||
| 			return $this->cache['languages']; | ||||
| 		} | ||||
|  | ||||
| 		// Get all languages of frontend and backend | ||||
| 		$languages 				= array(); | ||||
| 		$site_languages 	= JLanguage::getKnownLanguages(JPATH_SITE); | ||||
| 		$admin_languages	= JLanguage::getKnownLanguages(JPATH_ADMINISTRATOR); | ||||
|  | ||||
| 		// Create a single array of them | ||||
| 		foreach ($site_languages as $tag => $language) | ||||
| 		{ | ||||
| 			$languages[$tag.'0'] = JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDES_LANGUAGES_BOX_ITEM', $language['name'], JText::_('JSITE')); | ||||
| 		} | ||||
| 		foreach ($admin_languages as $tag => $language) | ||||
| 		{ | ||||
| 			$languages[$tag.'1'] = JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDES_LANGUAGES_BOX_ITEM', $language['name'], JText::_('JADMINISTRATOR')); | ||||
| 		} | ||||
|  | ||||
| 		// Sort it by language tag and by client after that | ||||
| 		ksort($languages); | ||||
|  | ||||
| 		// Add the languages to the internal cache | ||||
| 		$this->cache['languages'] = $languages; | ||||
|  | ||||
| 		return $this->cache['languages']; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to delete one or more overrides | ||||
| 	 * | ||||
| 	 * @param   	array		Array of keys to delete | ||||
| 	 * | ||||
| 	 * @return  integer   	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'; | ||||
|  | ||||
| 		// Parse the override.ini file in oder to get the keys and strings | ||||
| 		$filename = constant('JPATH_' . strtoupper($this->getState('filter.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 JRegistry; | ||||
| 		$registry->loadObject($strings); | ||||
|  | ||||
| 		$filename = constant('JPATH_' . strtoupper($this->getState('filter.client'))) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini'; | ||||
|  | ||||
| 		if (!JFile::write($filename, $registry->toString('INI'))) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		$this->cleanCache(); | ||||
|  | ||||
| 		return count($cids); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										163
									
								
								administrator/components/com_languages/models/strings.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										163
									
								
								administrator/components/com_languages/models/strings.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,163 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Languages Strings Model | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_languages | ||||
|  * @since       2.5 | ||||
|  */ | ||||
| class LanguagesModelStrings extends JModelLegacy | ||||
| { | ||||
| 	/** | ||||
| 	 * 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->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 for searching language strings | ||||
| 	 * | ||||
| 	 * @return  array  Array of resuls on success, Exception object otherwise | ||||
| 	 * | ||||
| 	 * @since		2.5 | ||||
| 	 */ | ||||
| 	public function search() | ||||
| 	{ | ||||
| 		$results = array(); | ||||
| 		$input   = JFactory::getApplication()->input; | ||||
|  | ||||
| 		$limitstart = $input->getInt('more'); | ||||
|  | ||||
| 		try | ||||
| 		{ | ||||
| 			$searchstring = $this->_db->quote('%' . $input->getString('searchstring') . '%'); | ||||
|  | ||||
| 			// Create the search query | ||||
| 			$query = $this->_db->getQuery(true) | ||||
| 				->select('constant, string, file') | ||||
| 				->from($this->_db->quoteName('#__overrider')); | ||||
| 			if ($input->get('searchtype') == 'constant') | ||||
| 			{ | ||||
| 				$query->where('constant LIKE '.$searchstring); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				$query->where('string LIKE '.$searchstring); | ||||
| 			} | ||||
|  | ||||
| 			// Consider the limitstart according to the 'more' parameter and load the results | ||||
| 			$this->_db->setQuery($query, $limitstart, 10); | ||||
| 			$results['results'] = $this->_db->loadObjectList(); | ||||
|  | ||||
| 			// Check whether there are more results than already loaded | ||||
| 			$query->clear('select') | ||||
| 						->select('COUNT(id)'); | ||||
| 			$this->_db->setQuery($query); | ||||
|  | ||||
| 			if ($this->_db->loadResult() > $limitstart + 10) | ||||
| 			{ | ||||
| 				// If this is set a 'More Results' link will be displayed in the view | ||||
| 				$results['more'] = $limitstart + 10; | ||||
| 			} | ||||
| 		} | ||||
| 		catch (RuntimeException $e) | ||||
| 		{ | ||||
| 			return $e; | ||||
| 		} | ||||
|  | ||||
| 		return $results; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 alazhar
					alazhar