b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _class_plug.php

Documentation is available at _class_plug.php

  1. <?php
  2. /**
  3.  * This file implements the Plug class (EXPERIMENTAL)
  4.  *
  5.  * This is where you can plug-in some plug-ins :)
  6.  * 
  7.  * b2evolution - {@link http://b2evolution.net/}
  8.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  9.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *
  11.  * @package evocore
  12.  */
  13. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  14.  
  15. /**
  16.  * Includes:
  17.  */
  18. require_once dirname(__FILE__)."/$core_dirout/$plugins_subdir/plugin.class.php";
  19.  
  20. /**
  21.  * Plug Class
  22.  *
  23.  * @package evocore
  24.  */
  25. class Plug
  26. {
  27.     /**#@+
  28.      * @access private
  29.      */
  30.  
  31.     var $collection;
  32.  
  33.     /**
  34.      * Array of loaded plug-ins:
  35.      */
  36.     var $Plugins array();
  37.     var $index_Plugins array();
  38.  
  39.     /**
  40.      * Path to plug-ins:
  41.      */
  42.     var $plugins_path;
  43.  
  44.     /**
  45.      * Has the plug initialized? (plugins loaded?)
  46.      */
  47.     var $initialized false;
  48.     
  49.     /**
  50.      * Current object idx in array:
  51.      */
  52.     var $current_idx 0;
  53.     
  54.     /**#@-*/
  55.     
  56.     /* 
  57.      * Constructor
  58.      *
  59.      * {@internal Plug::Plug(-)}}
  60.      *
  61.      * @param string collection = name of plugins subdir
  62.      */
  63.     function Plug$collection )
  64.     {
  65.         global $core_dirout$plugins_subdir;
  66.         
  67.         $this->collection $collection;
  68.         // Set plugin path for this collection:
  69.         $this->plugins_path dirname(__FILE__).'/'.$core_dirout.'/'.$plugins_subdir.'/'.$collection.'s';
  70.          
  71.     }    
  72.  
  73.     /* 
  74.      * Initialize Plug if it has not been done before.
  75.      *
  76.      * Load the plugins.
  77.      *
  78.      * {@internal Plug::init(-)}}
  79.      */
  80.     function init)
  81.     {
  82.         if$this->initialized )
  83.         {
  84.             // Go through directory:
  85.             $this_dir dir$this->plugins_path );
  86.             while$this_file $this_dir->read())
  87.             {
  88.                 ifpreg_match'/^_.+\.'.$this->collection.'\.php$/'$this_file && is_file$this->plugins_path'/'$this_file ) )
  89.                 {    // Valid plugin file name:
  90.                     // echo 'Loading ', $this_file, '...<br />';
  91.                     // Load the plugin:
  92.                     require $this->plugins_path'/'$this_file;
  93.                 }
  94.             }
  95.         
  96.             // Sort array by priority:
  97.             usort$this->Plugins'sort_Plugin' );
  98.         
  99.             $this->initialized true;
  100.         }
  101.     }
  102.  
  103.     /* 
  104.      * Register a plugin.
  105.      *
  106.      * Will be called by plugin includes when they are called by init()
  107.      *
  108.      * {@internal Plug::register(-)}}
  109.      *
  110.      * @access private
  111.      */
  112.     function register$Plugin )
  113.     {
  114.         $this->Plugins[$Plugin;
  115.         $this->index_Plugins$Plugin->code $Plugin;
  116.     }
  117.     
  118.         
  119.     /* 
  120.      * Get next plugin in list:
  121.      *
  122.      * {@internal Plug::get_next(-)}}
  123.      *
  124.      * @return Plugin (false if no more plugin).
  125.      */
  126.     function get_next()
  127.     {
  128.         $this->init();    // Init if not done yet.
  129.  
  130.         if$this->current_idx >= count$this->Plugins ) )
  131.         {
  132.             return false;
  133.         }
  134.         
  135.         return $this->Plugins$this->current_idx++ ];
  136.     }
  137.  
  138.     /**
  139.      * Rewind iterator
  140.      *
  141.      * {@internal Plug::restart(-) }}
  142.      */
  143.     function restart()
  144.     {
  145.         $this->current_idx 0;
  146.     }
  147.     
  148. }
  149.  
  150. function sort_Plugin$a$b )
  151. {
  152.     return $a->priority $b->priority;
  153. }
  154. ?>

Documentation generated on Tue, 20 May 2008 01:53:17 +0200 by phpDocumentor 1.4.2