Source for file strings.php

Documentation is available at strings.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 Strings Model
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_languages
  17.  * @since       2.5
  18.  */
  19. {
  20.     /**
  21.      * Method for refreshing the cache in the database with the known language strings
  22.      *
  23.      * @return  boolean  True on success, Exception object otherwise
  24.      *
  25.      * @since        2.5
  26.      */
  27.     public function refresh()
  28.     {
  29.         require_once JPATH_COMPONENT.'/helpers/languages.php';
  30.  
  31.         $app JFactory::getApplication();
  32.  
  33.         $app->setUserState('com_languages.overrides.cachedtime'null);
  34.  
  35.         // Empty the database cache first
  36.         try
  37.         {
  38.             $this->_db->setQuery('TRUNCATE TABLE '.$this->_db->quoteName('#__overrider'));
  39.             $this->_db->execute();
  40.         }
  41.         catch (RuntimeException $e)
  42.         {
  43.             return $e;
  44.         }
  45.  
  46.         // Create the insert query
  47.         $query $this->_db->getQuery(true)
  48.                     ->insert($this->_db->quoteName('#__overrider'))
  49.                     ->columns('constant, string, file');
  50.  
  51.         // Initialize some variables
  52.         $client        $app->getUserState('com_languages.overrides.filter.client''site''administrator' 'site';
  53.         $language    $app->getUserState('com_languages.overrides.filter.language''en-GB');
  54.  
  55.         $base constant('JPATH_'.strtoupper($client));
  56.         $path $base '/language/' $language;
  57.  
  58.         $files array();
  59.  
  60.         // Parse common language directory
  61.         jimport('joomla.filesystem.folder');
  62.         if (is_dir($path))
  63.         {
  64.             $files JFolder::files($path$language.'.*ini$'falsetrue);
  65.         }
  66.  
  67.         // Parse language directories of components
  68.         $files array_merge($filesJFolder::files($base.'/components'$language.'.*ini$'3true));
  69.  
  70.         // Parse language directories of modules
  71.         $files array_merge($filesJFolder::files($base.'/modules'$language.'.*ini$'3true));
  72.  
  73.         // Parse language directories of templates
  74.         $files array_merge($filesJFolder::files($base.'/templates'$language.'.*ini$'3true));
  75.  
  76.         // Parse language directories of plugins
  77.         $files array_merge($filesJFolder::files(JPATH_PLUGINS$language.'.*ini$'3true));
  78.  
  79.         // Parse all found ini files and add the strings to the database cache
  80.         foreach ($files as $file)
  81.         {
  82.             $strings LanguagesHelper::parseFile($file);
  83.             if ($strings && count($strings))
  84.             {
  85.                 $query->clear('values');
  86.                 foreach ($strings as $key => $string)
  87.                 {
  88.                     $query->values($this->_db->quote($key).','.$this->_db->quote($string).','.$this->_db->quote(JPath::clean($file)));
  89.                 }
  90.  
  91.                 try
  92.                 {
  93.                     $this->_db->setQuery($query);
  94.                     $this->_db->execute();
  95.                 }
  96.                 catch (RuntimeException $e)
  97.                 {
  98.                     return $e;
  99.                 }
  100.             }
  101.         }
  102.  
  103.         // Update the cached time
  104.         $app->setUserState('com_languages.overrides.cachedtime.'.$client.'.'.$languagetime());
  105.  
  106.         return true;
  107.     }
  108.  
  109.     /**
  110.      * Method for searching language strings
  111.      *
  112.      * @return  array  Array of resuls on success, Exception object otherwise
  113.      *
  114.      * @since        2.5
  115.      */
  116.     public function search()
  117.     {
  118.         $results array();
  119.         $input   JFactory::getApplication()->input;
  120.  
  121.         $limitstart $input->getInt('more');
  122.  
  123.         try
  124.         {
  125.             $searchstring $this->_db->quote('%' $input->getString('searchstring''%');
  126.  
  127.             // Create the search query
  128.             $query $this->_db->getQuery(true)
  129.                 ->select('constant, string, file')
  130.                 ->from($this->_db->quoteName('#__overrider'));
  131.             if ($input->get('searchtype'== 'constant')
  132.             {
  133.                 $query->where('constant LIKE '.$searchstring);
  134.             }
  135.             else
  136.             {
  137.                 $query->where('string LIKE '.$searchstring);
  138.             }
  139.  
  140.             // Consider the limitstart according to the 'more' parameter and load the results
  141.             $this->_db->setQuery($query$limitstart10);
  142.             $results['results'$this->_db->loadObjectList();
  143.  
  144.             // Check whether there are more results than already loaded
  145.             $query->clear('select')
  146.                         ->select('COUNT(id)');
  147.             $this->_db->setQuery($query);
  148.  
  149.             if ($this->_db->loadResult($limitstart 10)
  150.             {
  151.                 // If this is set a 'More Results' link will be displayed in the view
  152.                 $results['more'$limitstart 10;
  153.             }
  154.         }
  155.         catch (RuntimeException $e)
  156.         {
  157.             return $e;
  158.         }
  159.  
  160.         return $results;
  161.     }
  162. }

Documentation generated on Tue, 19 Nov 2013 15:14:36 +0100 by phpDocumentor 1.4.3