Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/application/plugin/helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3. * @version        $Id: helper.php 6748 2007-03-01 22:49:19Z hackwar $
  4. * @package        Joomla.Framework
  5. * @subpackage    Application
  6. * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. * @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE') or die();
  17.  
  18. /**
  19. * Plugin helper class
  20. *
  21. * @static
  22. * @author        Johan Janssens <[email protected]>
  23. * @package        Joomla.Framework
  24. * @subpackage    Application
  25. * @since        1.5
  26. */
  27. {
  28.     /**
  29.      * Get the plugin data of a group if no specific plugin is specified
  30.      * otherwise only the specific plugin data is returned
  31.      *
  32.      * @access public
  33.      * @param string     $group     The group name, relates to the sub-directory in the plugins directory
  34.      * @param string     $plugin    The plugin name
  35.      * @return mixed     An array of plugin data objects, or a plugin data object
  36.      */
  37.     function &getPlugin($group, $plugin = null)
  38.     {
  39.         $result = array();
  40.  
  41.         $plugins = JPluginHelper::_load();
  42.  
  43.         $total = count($plugins);
  44.         for($i = 0; $i < $total; $i++) {
  45.  
  46.             if(is_null($plugin))
  47.             {
  48.                 if($plugins[$i]->folder == $group) {
  49.                     $result[] = $plugins[$i];
  50.                 }
  51.             }
  52.             else
  53.             {
  54.                 if($plugins[$i]->folder == $group && $plugins[$i]->element == $plugin) {
  55.                     $result = $plugins[$i];
  56.                     break;
  57.                 }
  58.             }
  59.  
  60.         }
  61.  
  62.         return $result;
  63.     }
  64.  
  65.     /**
  66.     * Loads all the plugin files for a particular group if no specific plugin is specified
  67.     * otherwise only the specific pugin is loaded.
  68.     *
  69.     * @access public
  70.     * @param string     $group     The group name, relates to the sub-directory in the plugins directory
  71.     * @param string     $plugin    The plugin name
  72.     * @return boolean True if success
  73.     */
  74.     function importPlugin($group, $plugin = null)
  75.     {
  76.         $result = false;
  77.  
  78.         $plugins = JPluginHelper::_load();
  79.  
  80.         $total = count($plugins);
  81.         for($i = 0; $i < $total; $i++) {
  82.             if($plugins[$i]->folder == $group && ($plugins[$i]->element == $plugin ||  $plugin === null)) {
  83.                 JPluginHelper::_import( $plugins[$i]->folder, $plugins[$i]->element, $plugins[$i]->published, $plugins[$i]->params );
  84.                 $result = true;
  85.             }
  86.         }
  87.  
  88.         return $result;
  89.     }
  90.  
  91.     /**
  92.      * Loads the plugin file
  93.      *
  94.      * @access private
  95.      * @param string The folder (group)
  96.      * @param string The elements (name of file without extension)
  97.      * @param int Published state
  98.      * @param string The params for the bot
  99.      * @return boolean True if success
  100.      */
  101.     function _import( $folder, $element, $published, $params='' )
  102.     {
  103.         static $paths;
  104.  
  105.         if (!$paths) {
  106.             $paths = array();
  107.         }
  108.  
  109.         $result    = false;
  110.         $path    = JPATH_PLUGINS.DS.$folder.DS.$element.'.php';
  111.  
  112.         if (isset( $paths[$path] ))
  113.         {
  114.             $result = $paths[$path];
  115.         }
  116.         else
  117.         {
  118.             if (file_exists( $path ))
  119.             {
  120.                 //needed for backwards compatibility
  121.                 global $_MAMBOTS, $mainframe;
  122.  
  123.                 require_once( $path );
  124.  
  125.                 //Jinx :: if plugins need languages they need to load them themselves
  126.                 //$lang =& JFactory::getLanguage();
  127.                 //$lang->load( 'plg_'.trim( $folder ).'_'.trim( $element ), JPATH_ADMINISTRATOR );
  128.  
  129.                 $paths[$path] = true;
  130.             }
  131.             else
  132.             {
  133.                 $paths[$path] = false;
  134.             }
  135.         }
  136.         return $paths[$path];
  137.     }
  138.  
  139.     /**
  140.      * Loads the plugin data
  141.      *
  142.      * @access private
  143.      */
  144.     function _load()
  145.     {
  146.         static $plugins;
  147.  
  148.         if (isset($plugins)) {
  149.             return $plugins;
  150.         }
  151.  
  152.         $db        =& JFactory::getDBO();
  153.         $user    =& JFactory::getUser();
  154.  
  155.         if (isset($user)) 
  156.         {
  157.             $aid = $user->get('aid', 0);
  158.  
  159.             $query = 'SELECT id, name, folder, element, published, params'
  160.                 . ' FROM #__plugins'
  161.                 . ' WHERE published >= 1'
  162.                 . ' AND access <= ' . (int) $aid
  163.                 . ' ORDER BY ordering';
  164.         } 
  165.         else 
  166.         {
  167.             $query = 'SELECT id, name, folder, element, published, params'
  168.                 . ' FROM #__plugins'
  169.                 . ' WHERE published >= 1'
  170.                 . ' ORDER BY ordering';
  171.         }
  172.  
  173.         $db->setQuery( $query );
  174.  
  175.         if (!($plugins = $db->loadObjectList())) {
  176.             JError::raiseWarning( 'SOME_ERROR_CODE', "Error loading Plugins: " . $db->getErrorMsg());
  177.             return false;
  178.         }
  179.  
  180.         return $plugins;
  181.     }
  182.  
  183. }
  184. ?>

Documentation generated on Mon, 05 Mar 2007 21:05:33 +0000 by phpDocumentor 1.3.1