| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 4 * @license GNU General Public License version 2 or later; see LICENSE.txt 5 */ 6 7 // Check to ensure this file is included in Joomla! 8 defined('_JEXEC') or die; 9 10 jimport('joomla.application.component.modellist'); 11 12 /** 13 * Languages Component Languages Model 14 * 15 * @package Joomla.Administrator 16 * @subpackage com_languages 17 * @since 1.6 18 */ 19 class LanguagesModelInstalled extends JModelList 20 { 21 /** 22 * @var object client object 23 */ 24 protected $client = null; 25 26 /** 27 * @var object user object 28 */ 29 protected $user = null; 30 31 /** 32 * @var boolean|JExeption True, if FTP settings should be shown, or an exeption 33 */ 34 protected $ftp = null; 35 36 /** 37 * @var string option name 38 */ 39 protected $option = null; 40 41 /** 42 * @var array languages description 43 */ 44 protected $data = null; 45 46 /** 47 * @var int total number pf languages 48 */ 49 protected $total = null; 50 51 /** 52 * @var int total number pf languages installed 53 */ 54 protected $langlist = null; 55 56 /** 57 * @var string language path 58 */ 59 protected $path = null; 60 61 /** 62 * Method to auto-populate the model state. 63 * 64 * Note. Calling getState in this method will result in recursion. 65 * 66 * @return void 67 * @since 1.6 68 */ 69 protected function populateState($ordering = null, $direction = null) 70 { 71 // Initialise variables. 72 $app = JFactory::getApplication('administrator'); 73 74 // Load the filter state. 75 $clientId = JRequest::getInt('client'); 76 $this->setState('filter.client_id', $clientId); 77 78 // Load the parameters. 79 $params = JComponentHelper::getParams('com_languages'); 80 $this->setState('params', $params); 81 82 // List state information. 83 parent::populateState('a.name', 'asc'); 84 } 85 86 /** 87 * Method to get a store id based on model configuration state. 88 * 89 * This is necessary because the model is used by the component and 90 * different modules that might need different sets of data or different 91 * ordering requirements. 92 * 93 * @param string $id A prefix for the store id. 94 * 95 * @return string A store id. 96 * @since 1.6 97 */ 98 protected function getStoreId($id = '') 99 { 100 // Compile the store id. 101 $id .= ':'.$this->getState('filter.client_id'); 102 103 return parent::getStoreId($id); 104 } 105 106 /** 107 * Method to get the client object 108 * 109 * @return object 110 * @since 1.6 111 */ 112 public function &getClient() 113 { 114 if (is_null($this->client)) { 115 $this->client = JApplicationHelper::getClientInfo($this->getState('filter.client_id', 0)); 116 } 117 118 return $this->client; 119 } 120 121 /** 122 * Method to get the ftp credentials 123 * 124 * @return object 125 * @since 1.6 126 */ 127 public function &getFtp() 128 { 129 if (is_null($this->ftp)) { 130 $this->ftp = JClientHelper::setCredentialsFromRequest('ftp'); 131 } 132 133 return $this->ftp; 134 } 135 136 /** 137 * Method to get the option 138 * 139 * @return object 140 * @since 1.6 141 */ 142 public function &getOption() 143 { 144 $option = $this->getState('option'); 145 146 return $option; 147 } 148 149 /** 150 * Method to get Languages item data 151 * 152 * @return array 153 * @since 1.6 154 */ 155 public function &getData() 156 { 157 if (is_null($this->data)) { 158 159 // Get information 160 $path = $this->getPath(); 161 $client = $this->getClient(); 162 $langlist = $this->getLanguageList(); 163 164 // Compute all the languages 165 $data = array (); 166 167 foreach($langlist as $lang){ 168 $file = $path . '/' . $lang . '/' . $lang.'.xml'; 169 $info = JApplicationHelper::parseXMLLangMetaFile($file); 170 $row = new JObject(); 171 $row->language = $lang; 172 173 if (!is_array($info)) { 174 continue; 175 } 176 177 foreach($info as $key => $value) 178 { 179 $row->$key = $value; 180 } 181 182 // if current than set published 183 $params = JComponentHelper::getParams('com_languages'); 184 if ($params->get($client->name, 'en-GB') == $row->language) { 185 $row->published = 1; 186 } 187 else { 188 $row->published = 0; 189 } 190 191 $row->checked_out = 0; 192 $data[] = $row; 193 } 194 usort($data, array($this, 'compareLanguages')); 195 196 // Prepare data 197 $limit = $this->getState('list.limit'); 198 $start = $this->getState('list.start'); 199 $total = $this->getTotal(); 200 201 if ($limit == 0) { 202 $start = 0; 203 $end = $total; 204 } 205 else { 206 if ($start > $total) { 207 $start = $total - $total % $limit; 208 } 209 $end = $start + $limit; 210 211 if ($end > $total) { 212 $end = $total; 213 } 214 } 215 216 // Compute the displayed languages 217 $this->data = array(); 218 for ($i = $start;$i < $end;$i++) 219 { 220 $this->data[] = & $data[$i]; 221 } 222 } 223 224 return $this->data; 225 } 226 227 /** 228 * Method to get installed languages data. 229 * 230 * @return string An SQL query 231 * @since 1.6 232 */ 233 protected function getLanguageList() 234 { 235 // Create a new db object. 236 $db = $this->getDbo(); 237 $query = $db->getQuery(true); 238 $client = $this->getState('filter.client_id'); 239 $type = "language"; 240 // Select field element from the extensions table. 241 $query->select($this->getState('list.select', 'a.element')); 242 $query->from('#__extensions AS a'); 243 244 $type = $db->Quote($type); 245 $query->where('(a.type = '.$type.')'); 246 247 $query->where('state = 0'); 248 $query->where('enabled = 1'); 249 250 $query->where('client_id=' . intval($client)); 251 252 // for client_id = 1 do we need to check language table also ? 253 $db->setQuery($query); 254 255 $this->langlist = $db->loadColumn(); 256 257 return $this->langlist; 258 } 259 260 /** 261 * Method to get the total number of Languages items 262 * 263 * @return integer 264 * @since 1.6 265 */ 266 public function getTotal() 267 { 268 if (is_null($this->total)) { 269 $langlist = $this->getLanguageList(); 270 $this->total = count($langlist); 271 } 272 273 return $this->total; 274 } 275 276 /** 277 * Method to set the default language 278 * 279 * @return boolean 280 * @since 1.6 281 */ 282 public function publish($cid) 283 { 284 if ($cid) { 285 $client = $this->getClient(); 286 287 $params = JComponentHelper::getParams('com_languages'); 288 $params->set($client->name, $cid); 289 290 $table = JTable::getInstance('extension'); 291 $id = $table->find(array('element' => 'com_languages')); 292 293 // Load 294 if (!$table->load($id)) { 295 $this->setError($table->getError()); 296 return false; 297 } 298 299 $table->params = (string)$params; 300 // pre-save checks 301 if (!$table->check()) { 302 $this->setError($table->getError()); 303 return false; 304 } 305 306 // save the changes 307 if (!$table->store()) { 308 $this->setError($table->getError()); 309 return false; 310 } 311 } 312 else { 313 $this->setError(JText::_('COM_LANGUAGES_ERR_NO_LANGUAGE_SELECTED')); 314 return false; 315 } 316 317 // Clean the cache. 318 $this->cleanCache(); 319 $this->cleanCache('_system', 0); 320 $this->cleanCache('_system', 1); 321 322 return true; 323 } 324 325 /** 326 * Method to get the folders 327 * 328 * @return array Languages folders 329 * @since 1.6 330 */ 331 protected function getFolders() 332 { 333 if (is_null($this->folders)) { 334 $path = $this->getPath(); 335 jimport('joomla.filesystem.folder'); 336 $this->folders = JFolder::folders($path, '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); 337 } 338 339 return $this->folders; 340 } 341 342 /** 343 * Method to get the path 344 * 345 * @return string The path to the languages folders 346 * @since 1.6 347 */ 348 protected function getPath() 349 { 350 if (is_null($this->path)) { 351 $client = $this->getClient(); 352 $this->path = JLanguage::getLanguagePath($client->path); 353 } 354 355 return $this->path; 356 } 357 358 /** 359 * Method to compare two languages in order to sort them 360 * 361 * @param object $lang1 the first language 362 * @param object $lang2 the second language 363 * 364 * @return integer 365 * @since 1.6 366 */ 367 protected function compareLanguages($lang1, $lang2) 368 { 369 return strcmp($lang1->name, $lang2->name); 370 } 371 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |