Advertisement
Guest User

Plugin System

a guest
Nov 21st, 2013
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.43 KB | None | 0 0
  1. <?php
  2. /*********************************************\
  3. |****************** OPENCMS ******************|
  4. |*********************************************|
  5. |* @author Yannici                           *|
  6. |* @copyright Yannici                        *|
  7. |*********************************************|
  8. |* @since 04.11.2013                         *|
  9. \*********************************************/
  10.  
  11. class Plugin_system {
  12.    
  13.     private $_plugins = array();
  14.    
  15.     public function __construct() {
  16.         $this->load_abstract_class();
  17.         $this->load_plugins();
  18.     }
  19.    
  20.     private function load_abstract_class() {
  21.         require_once(APPPATH . '/libraries/abstract_plugin.php');
  22.         require_once(APPPATH . '/libraries/abstract_admin_plugin.php');
  23.     }
  24.    
  25.     public function load_plugin($name) {
  26.         $ref_class = new ReflectionClass(ucfirst($name . '_plugin'));
  27.         return $ref_class->newInstance();
  28.     }
  29.    
  30.     private function load_plugins() {
  31.         foreach($this->config->item('plugins') As $plugin => $class) {
  32.             if( ! file_exists(APPPATH . '/plugins/' . $plugin . '/' . $plugin . '.php')) {
  33.                 show_error('Unable to load your plugin \'' . $plugin . '\'. Please check if this plugin, controller and view exists.');
  34.             } else {
  35.                 require_once(APPPATH . '/plugins/' . $plugin . '/' . $plugin . '.php');
  36.                 if( ! class_exists($plugin . '_plugin')
  37.                    OR (get_parent_class($plugin . '_plugin') !== 'Abstract_plugin' && get_parent_class($plugin . '_plugin') !== 'Abstract_admin_plugin')) {
  38.                    
  39.                     show_error('Unable to load your plugin \'' . $plugin . '\'. Please check if the plugin is a class and Abstract_plugin or Abstract_admin_plugin is it parent');
  40.                 } else {
  41.                     $this->_plugins[$plugin] = array();
  42.                     $this->_plugins['class'] = $class;
  43.                    
  44.                     $this->set_plugin_properties($plugin);
  45.                 }
  46.             }
  47.         }
  48.     }
  49.    
  50.     private function set_plugin_properties($name) {
  51.         $ref_class = new ReflectionClass($name . '_plugin');
  52.        
  53.         foreach($ref_class->getDefaultProperties() As $p_name => $value) {
  54.             switch($p_name) {
  55.                 case 'plugin_technical_name':
  56.                     $this->_plugins[$name]['technical_name'] = $value;
  57.                     break;
  58.                 case 'plugin_name':
  59.                     $this->_plugins[$name]['name'] = $value;
  60.                     break;
  61.                 case 'plugin_description':
  62.                     $this->_plugins[$name]['description'] = $value;
  63.                     break;
  64.                 case 'plugin_author':
  65.                     $this->_plugins[$name]['author'] = $value;
  66.                     break;
  67.                 case 'plugin_version':
  68.                     $this->_plugins[$name]['version'] = $value;
  69.                     break;
  70.             }
  71.         }
  72.     }
  73.    
  74.     public function is_registered_plugin($name, $class) {
  75.         if(isset($this->_plugins[$name])
  76.            && $this->_plugins[$name]['class'] == strtolower($class)) {
  77.             return TRUE;
  78.         }
  79.        
  80.         return FALSE;
  81.     }
  82.  
  83.     public function __get($key) {
  84.         if(property_exists($this, $key)) {
  85.             return $this->$key;
  86.         }
  87.        
  88.         $CI =& get_instance();
  89.         return $CI->$key;
  90.     }
  91. }
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement