Source for file plugin.php

Documentation is available at plugin.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Plugin
  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.  * JPlugin Class
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Plugin
  17.  * @since       1.5
  18.  */
  19. abstract class JPlugin extends JEvent
  20. {
  21.     /**
  22.      * A JRegistry object holding the parameters for the plugin
  23.      *
  24.      * @var    JRegistry 
  25.      * @since  1.5
  26.      */
  27.     public $params = null;
  28.  
  29.     /**
  30.      * The name of the plugin
  31.      *
  32.      * @var    string 
  33.      * @since  1.5
  34.      */
  35.     protected $_name = null;
  36.  
  37.     /**
  38.      * The plugin type
  39.      *
  40.      * @var    string 
  41.      * @since  1.5
  42.      */
  43.     protected $_type = null;
  44.  
  45.     /**
  46.      * Affects constructor behavior. If true, language files will be loaded automatically.
  47.      *
  48.      * @var    boolean 
  49.      * @since  3.1
  50.      */
  51.     protected $autoloadLanguage = false;
  52.  
  53.     /**
  54.      * Constructor
  55.      *
  56.      * @param   object  &$subject  The object to observe
  57.      * @param   array   $config    An optional associative array of configuration settings.
  58.      *                              Recognized key values include 'name', 'group', 'params', 'language'
  59.      *                              (this list is not meant to be comprehensive).
  60.      *
  61.      * @since   1.5
  62.      */
  63.     public function __construct(&$subject$config array())
  64.     {
  65.         // Get the parameters.
  66.         if (isset($config['params']))
  67.         {
  68.             if ($config['params'instanceof JRegistry)
  69.             {
  70.                 $this->params = $config['params'];
  71.             }
  72.             else
  73.             {
  74.                 $this->params = new JRegistry;
  75.                 $this->params->loadString($config['params']);
  76.             }
  77.         }
  78.  
  79.         // Get the plugin name.
  80.         if (isset($config['name']))
  81.         {
  82.             $this->_name = $config['name'];
  83.         }
  84.  
  85.         // Get the plugin type.
  86.         if (isset($config['type']))
  87.         {
  88.             $this->_type = $config['type'];
  89.         }
  90.  
  91.         // Load the language files if needed.
  92.         if ($this->autoloadLanguage)
  93.         {
  94.             $this->loadLanguage();
  95.         }
  96.  
  97.         if (property_exists($this'app'))
  98.         {
  99.             $reflection new ReflectionClass($this);
  100.             $appProperty $reflection->getProperty('app');
  101.  
  102.             if ($appProperty->isPrivate(=== false && is_null($this->app))
  103.             {
  104.                 $this->app JFactory::getApplication();
  105.             }
  106.         }
  107.  
  108.         if (property_exists($this'db'))
  109.         {
  110.             $reflection new ReflectionClass($this);
  111.             $dbProperty $reflection->getProperty('db');
  112.  
  113.             if ($dbProperty->isPrivate(=== false && is_null($this->db))
  114.             {
  115.                 $this->db JFactory::getDbo();
  116.             }
  117.         }
  118.  
  119.         parent::__construct($subject);
  120.     }
  121.  
  122.     /**
  123.      * Loads the plugin language file
  124.      *
  125.      * @param   string  $extension  The extension for which a language file should be loaded
  126.      * @param   string  $basePath   The basepath to use
  127.      *
  128.      * @return  boolean  True, if the file has successfully loaded.
  129.      *
  130.      * @since   1.5
  131.      */
  132.     public function loadLanguage($extension ''$basePath JPATH_ADMINISTRATOR)
  133.     {
  134.         if (empty($extension))
  135.         {
  136.             $extension 'plg_' $this->_type . '_' $this->_name;
  137.         }
  138.  
  139.         $lang JFactory::getLanguage();
  140.  
  141.         return $lang->load(strtolower($extension)$basePathnullfalsetrue)
  142.             || $lang->load(strtolower($extension)JPATH_PLUGINS '/' $this->_type . '/' $this->_namenullfalsetrue);
  143.     }
  144. }

Documentation generated on Tue, 19 Nov 2013 15:10:43 +0100 by phpDocumentor 1.4.3