Source for file installed.php

Documentation is available at installed.php

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

Documentation generated on Tue, 19 Nov 2013 15:05:40 +0100 by phpDocumentor 1.4.3