Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  Library
  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
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Library helper class
  14.  *
  15.  * @package     Joomla.Legacy
  16.  * @subpackage  Library
  17.  * @since       3.2
  18.  */
  19. {
  20.     /**
  21.      * The component list cache
  22.      *
  23.      * @var    array 
  24.      * @since  3.2
  25.      */
  26.     protected static $libraries array();
  27.  
  28.     /**
  29.      * Get the library information.
  30.      *
  31.      * @param   string   $element  Element of the library in the extensions table.
  32.      * @param   boolean  $strict   If set and the library does not exist, the enabled attribute will be set to false.
  33.      *
  34.      * @return  object   An object with the library's information.
  35.      *
  36.      * @since   3.2
  37.      */
  38.     public static function getLibrary($element$strict false)
  39.     {
  40.         // Is already cached ?
  41.         if (isset(static::$libraries[$element]))
  42.         {
  43.             return static::$libraries[$element];
  44.         }
  45.  
  46.         if (static::_load($element))
  47.         {
  48.             $result static::$libraries[$element];
  49.         }
  50.         else
  51.         {
  52.             $result new stdClass;
  53.             $result->enabled $strict false true;
  54.             $result->params new JRegistry;
  55.         }
  56.  
  57.         return $result;
  58.     }
  59.  
  60.     /**
  61.      * Checks if a library is enabled
  62.      *
  63.      * @param   string  $element  Element of the library in the extensions table.
  64.      *
  65.      * @return  boolean 
  66.      *
  67.      * @since   3.2
  68.      */
  69.     public static function isEnabled($element)
  70.     {
  71.         $result static::getLibrary($elementtrue);
  72.  
  73.         return $result->enabled;
  74.     }
  75.  
  76.     /**
  77.      * Gets the parameter object for the library
  78.      *
  79.      * @param   string   $element  Element of the library in the extensions table.
  80.      * @param   boolean  $strict   If set and the library does not exist, false will be returned
  81.      *
  82.      * @return  JRegistry  A JRegistry object.
  83.      *
  84.      * @see     JRegistry
  85.      * @since   3.2
  86.      */
  87.     public static function getParams($element$strict false)
  88.     {
  89.         $library static::getLibrary($element$strict);
  90.  
  91.         return $library->params;
  92.     }
  93.  
  94.     /**
  95.      * Save the parameters object for the library
  96.      *
  97.      * @param   string     $element  Element of the library in the extensions table.
  98.      * @param   JRegistry  $params   Params to save
  99.      *
  100.      * @return  JRegistry  A JRegistry object.
  101.      *
  102.      * @see     JRegistry
  103.      * @since   3.2
  104.      */
  105.     public static function saveParams($element$params)
  106.     {
  107.         if (static::isEnabled($element))
  108.         {
  109.             // Save params in DB
  110.             $db JFactory::getDbo();
  111.             $query $db->getQuery(true)
  112.                 ->update($db->quoteName('#__extensions'))
  113.                 ->set($db->quoteName('params'' = ' $db->quote($params->toString()))
  114.                 ->where($db->quoteName('type'' = ' $db->quote('library'))
  115.                 ->where($db->quoteName('element'' = ' $db->quote($element));
  116.             $db->setQuery($query);
  117.  
  118.             $result $db->execute();
  119.  
  120.             // Update params in libraries cache
  121.             if ($result && isset(static::$libraries[$element]))
  122.             {
  123.                 static::$libraries[$element]->params $params;
  124.             }
  125.  
  126.             return $result;
  127.         }
  128.  
  129.         return false;
  130.     }
  131.  
  132.     /**
  133.      * Load the installed libraryes into the libraries property.
  134.      *
  135.      * @param   string  $element  The element value for the extension
  136.      *
  137.      * @return  boolean  True on success
  138.      *
  139.      * @since   3.2
  140.      */
  141.     protected static function _load($element)
  142.     {
  143.         $db JFactory::getDbo();
  144.         $query $db->getQuery(true)
  145.             ->select('extension_id AS id, element AS "option", params, enabled')
  146.             ->from('#__extensions')
  147.             ->where($db->quoteName('type'' = ' $db->quote('library'))
  148.             ->where($db->quoteName('element'' = ' $db->quote($element));
  149.         $db->setQuery($query);
  150.  
  151.         $cache JFactory::getCache('_system''callback');
  152.  
  153.         try
  154.         {
  155.             static::$libraries[$element$cache->get(array($db'loadObject')null$elementfalse);
  156.         }
  157.         catch (RuntimeException $e)
  158.         {
  159.             // Fatal error.
  160.             JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_LIBRARY_NOT_LOADING'$element$e->getMessage())JLog::WARNING'jerror');
  161.  
  162.             return false;
  163.         }
  164.  
  165.         if (empty(static::$libraries[$element]))
  166.         {
  167.             // Fatal error.
  168.             $error JText::_('JLIB_APPLICATION_ERROR_LIBRARY_NOT_FOUND');
  169.             JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_LIBRARY_NOT_LOADING'$element$error)JLog::WARNING'jerror');
  170.  
  171.             return false;
  172.         }
  173.  
  174.         // Convert the params to an object.
  175.         if (is_string(static::$libraries[$element]->params))
  176.         {
  177.             $temp new JRegistry;
  178.             $temp->loadString(static::$libraries[$element]->params);
  179.             static::$libraries[$element]->params $temp;
  180.         }
  181.  
  182.         return true;
  183.     }
  184. }

Documentation generated on Tue, 19 Nov 2013 15:04:38 +0100 by phpDocumentor 1.4.3