[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_languages/models/ -> strings.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Administrator
   4   * @subpackage    com_languages
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // Check to ensure this file is included in Joomla!
  10  defined('_JEXEC') or die;
  11  
  12  jimport('joomla.application.component.modellist');
  13  
  14  /**
  15   * Languages Strings Model
  16   *
  17   * @package            Joomla.Administrator
  18   * @subpackage    com_languages
  19   * @since                2.5
  20   */
  21  class LanguagesModelStrings extends JModel
  22  {
  23      /**
  24       * Method for refreshing the cache in the database with the known language strings
  25       *
  26       * @return    boolean    True on success, Exception object otherwise
  27       *
  28       * @since        2.5
  29       */
  30  	public function refresh()
  31      {
  32          require_once  JPATH_COMPONENT.'/helpers/languages.php';
  33  
  34          $app = JFactory::getApplication();
  35  
  36          $app->setUserState('com_languages.overrides.cachedtime', null);
  37  
  38          // Empty the database cache first
  39          try
  40          {
  41              $this->_db->setQuery('TRUNCATE TABLE '.$this->_db->qn('#__overrider'));
  42              $this->_db->query();
  43          }
  44          catch (JDatabaseException $e)
  45          {
  46              return $e;
  47          }
  48  
  49          // Create the insert query
  50          $query = $this->_db->getQuery(true)
  51                      ->insert($this->_db->qn('#__overrider'))
  52                      ->columns('constant, string, file');
  53  
  54          // Initialize some variables
  55          $client        = $app->getUserState('com_languages.overrides.filter.client', 'site') ? 'administrator' : 'site';
  56          $language    = $app->getUserState('com_languages.overrides.filter.language', 'en-GB');
  57  
  58  
  59          $base = constant('JPATH_'.strtoupper($client));
  60          $path = $base.'/language/' . $language;
  61  
  62          $files = array();
  63  
  64          // Parse common language directory
  65          if(JFolder::exists($path))
  66          {
  67              $files = JFolder::files($path, $language.'.*ini$', false, true);
  68          }
  69  
  70          // Parse language directories of components
  71          $files = array_merge($files, JFolder::files($base.'/components', $language.'.*ini$', 3, true));
  72  
  73          // Parse language directories of modules
  74          $files = array_merge($files, JFolder::files($base.'/modules', $language.'.*ini$', 3, true));
  75  
  76          // Parse language directories of templates
  77          $files = array_merge($files, JFolder::files($base.'/templates', $language.'.*ini$', 3, true));
  78  
  79          // Parse language directories of plugins
  80          $files = array_merge($files, JFolder::files(JPATH_PLUGINS, $language.'.*ini$', 3, true));
  81  
  82          // Parse all found ini files and add the strings to the database cache
  83          foreach ($files as $file)
  84          {
  85              $strings = LanguagesHelper::parseFile($file);
  86              if ($strings && count($strings))
  87              {
  88                  $query->clear('values');
  89                  foreach ($strings as $key => $string)
  90                  {
  91                      $query->values($this->_db->q($key).','.$this->_db->q($string).','.$this->_db->q(JPath::clean($file)));;
  92                  }
  93  
  94                  try
  95                  {
  96                      $this->_db->setQuery($query);
  97                      if (!$this->_db->query())
  98                      {
  99                          return new Exception($this->_db->getErrorMsg());
 100                      }
 101                  }
 102                  catch (JDatabaseException $e)
 103                  {
 104                      return $e;
 105                  }
 106              }
 107          }
 108  
 109          // Update the cached time
 110          $app->setUserState('com_languages.overrides.cachedtime.'.$client.'.'.$language, time());
 111  
 112          return true;
 113      }
 114  
 115      /**
 116       * Method for searching language strings
 117       *
 118       * @return    array    Array of resuls on success, Exception object otherwise
 119       *
 120       * @since        2.5
 121       */
 122  	public function search()
 123      {
 124          $results = array();
 125  
 126          $limitstart = JRequest::getInt('more');
 127  
 128          try
 129          {
 130              $searchstring = $this->_db->q('%'.JRequest::getString('searchstring').'%');
 131  
 132              // Create the search query
 133              $query = $this->_db->getQuery(true)
 134                          ->select('constant, string, file')
 135                          ->from($this->_db->qn('#__overrider'));
 136              if (JRequest::getCmd('searchtype') == 'constant')
 137              {
 138                  $query->where('constant LIKE '.$searchstring);
 139              }
 140              else
 141              {
 142                  $query->where('string LIKE '.$searchstring);
 143              }
 144  
 145              // Consider the limitstart according to the 'more' parameter and load the results
 146              $this->_db->setQuery($query, $limitstart, 10);
 147              $results['results'] = $this->_db->loadObjectList();
 148  
 149              // Check whether there are more results than already loaded
 150              $query->clear('select')
 151                          ->select('COUNT(id)');
 152              $this->_db->setQuery($query);
 153  
 154              if ($this->_db->loadResult() > $limitstart + 10)
 155              {
 156                  // If this is set a 'More Results' link will be displayed in the view
 157                  $results['more'] = $limitstart + 10;
 158              }
 159          }
 160          catch (JDatabaseException $e)
 161          {
 162              return $e;
 163          }
 164  
 165          return $results;
 166      }
 167  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1