Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*********************************************\
- |****************** OPENCMS ******************|
- |*********************************************|
- |* @author Yannici *|
- |* @copyright Yannici *|
- |*********************************************|
- |* @since 04.11.2013 *|
- \*********************************************/
- class Plugin_system {
- private $_plugins = array();
- public function __construct() {
- $this->load_abstract_class();
- $this->load_plugins();
- }
- private function load_abstract_class() {
- require_once(APPPATH . '/libraries/abstract_plugin.php');
- require_once(APPPATH . '/libraries/abstract_admin_plugin.php');
- }
- public function load_plugin($name) {
- $ref_class = new ReflectionClass(ucfirst($name . '_plugin'));
- return $ref_class->newInstance();
- }
- private function load_plugins() {
- foreach($this->config->item('plugins') As $plugin => $class) {
- if( ! file_exists(APPPATH . '/plugins/' . $plugin . '/' . $plugin . '.php')) {
- show_error('Unable to load your plugin \'' . $plugin . '\'. Please check if this plugin, controller and view exists.');
- } else {
- require_once(APPPATH . '/plugins/' . $plugin . '/' . $plugin . '.php');
- if( ! class_exists($plugin . '_plugin')
- OR (get_parent_class($plugin . '_plugin') !== 'Abstract_plugin' && get_parent_class($plugin . '_plugin') !== 'Abstract_admin_plugin')) {
- 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');
- } else {
- $this->_plugins[$plugin] = array();
- $this->_plugins['class'] = $class;
- $this->set_plugin_properties($plugin);
- }
- }
- }
- }
- private function set_plugin_properties($name) {
- $ref_class = new ReflectionClass($name . '_plugin');
- foreach($ref_class->getDefaultProperties() As $p_name => $value) {
- switch($p_name) {
- case 'plugin_technical_name':
- $this->_plugins[$name]['technical_name'] = $value;
- break;
- case 'plugin_name':
- $this->_plugins[$name]['name'] = $value;
- break;
- case 'plugin_description':
- $this->_plugins[$name]['description'] = $value;
- break;
- case 'plugin_author':
- $this->_plugins[$name]['author'] = $value;
- break;
- case 'plugin_version':
- $this->_plugins[$name]['version'] = $value;
- break;
- }
- }
- }
- public function is_registered_plugin($name, $class) {
- if(isset($this->_plugins[$name])
- && $this->_plugins[$name]['class'] == strtolower($class)) {
- return TRUE;
- }
- return FALSE;
- }
- public function __get($key) {
- if(property_exists($this, $key)) {
- return $this->$key;
- }
- $CI =& get_instance();
- return $CI->$key;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement