| [ Index ] |
PHP Cross Reference of MyBB 1.6.5 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: class_plugins.php 5624 2011-10-02 19:07:56Z ralgith $ 10 */ 11 12 class pluginSystem 13 { 14 15 /** 16 * The hooks to which plugins can be attached. 17 * 18 * @var array 19 */ 20 public $hooks; 21 22 /** 23 * The current hook which we're in (if any) 24 * 25 * @var string 26 */ 27 public $current_hook; 28 29 /** 30 * Load all plugins. 31 * 32 */ 33 function load() 34 { 35 global $cache, $plugins; 36 $pluginlist = $cache->read("plugins"); 37 if(is_array($pluginlist['active'])) 38 { 39 foreach($pluginlist['active'] as $plugin) 40 { 41 if($plugin != "" && file_exists(MYBB_ROOT."inc/plugins/".$plugin.".php")) 42 { 43 require_once MYBB_ROOT."inc/plugins/".$plugin.".php"; 44 } 45 } 46 } 47 } 48 49 /** 50 * Add a hook onto which a plugin can be attached. 51 * 52 * @param string The hook name. 53 * @param string The function of this hook. 54 * @param int The priority this hook has. 55 * @param string The optional file belonging to this hook. 56 * @return boolean Always true. 57 */ 58 function add_hook($hook, $function, $priority=10, $file="") 59 { 60 // Check to see if we already have this hook running at this priority 61 if(!empty($this->hooks[$hook][$priority][$function]) && is_array($this->hooks[$hook][$priority][$function])) 62 { 63 return true; 64 } 65 66 // Add the hook 67 $this->hooks[$hook][$priority][$function] = array( 68 "function" => $function, 69 "file" => $file 70 ); 71 return true; 72 } 73 74 /** 75 * Run the hooks that have plugins. 76 * 77 * @param string The name of the hook that is run. 78 * @param string The argument for the hook that is run. The passed value MUST be a variable 79 * @return string The arguments for the hook. 80 */ 81 function run_hooks($hook, $arguments="") 82 { 83 if(!is_array($this->hooks[$hook])) 84 { 85 return $arguments; 86 } 87 $this->current_hook = $hook; 88 ksort($this->hooks[$hook]); 89 foreach($this->hooks[$hook] as $priority => $hooks) 90 { 91 if(is_array($hooks)) 92 { 93 foreach($hooks as $hook) 94 { 95 if($hook['file']) 96 { 97 require_once $hook['file']; 98 } 99 100 $func = $hook['function']; 101 $returnargs = $func($arguments); 102 103 104 if($returnargs) 105 { 106 $arguments = $returnargs; 107 } 108 } 109 } 110 } 111 $this->current_hook = ''; 112 return $arguments; 113 } 114 115 /** 116 * Run the hooks that have plugins but passes REQUIRED argument that is received by reference. 117 * This argument must be received by reference in the plugin file! 118 * This is a separate function to allow by reference calls for things you cannot use the $var = $plugins->run_hooks("hook_name", $var) syntax. 119 * 120 * @param string The name of the hook that is run. 121 * @param string The argument for the hook that is run - passed by reference. The passed value MUST be a variable 122 */ 123 function run_hooks_by_ref($hook, &$arguments) 124 { 125 if(empty($this->hooks[$hook]) && !is_array($this->hooks[$hook])) 126 { 127 return $arguments; 128 } 129 $this->current_hook = $hook; 130 ksort($this->hooks[$hook]); 131 foreach($this->hooks[$hook] as $priority => $hooks) 132 { 133 if(is_array($hooks)) 134 { 135 foreach($hooks as $hook) 136 { 137 if($hook['file']) 138 { 139 require_once $hook['file']; 140 } 141 142 $func = $hook['function']; 143 $returnargs = $func($arguments); 144 } 145 } 146 } 147 $this->current_hook = ''; 148 } 149 150 /** 151 * Remove a specific hook. 152 * 153 * @param string The name of the hook. 154 * @param string The function of the hook. 155 * @param string The filename of the plugin. 156 * @param int The priority of the hook. 157 */ 158 function remove_hook($hook, $function, $file="", $priority=10) 159 { 160 // Check to see if we don't already have this hook running at this priority 161 if(!isset($this->hooks[$hook][$priority][$function])) 162 { 163 return true; 164 } 165 unset($this->hooks[$hook][$priority][$function]); 166 } 167 168 /** 169 * Establishes if a particular plugin is compatible with this version of MyBB. 170 * 171 * @param string The name of the plugin. 172 * @return boolean TRUE if compatible, FALSE if incompatible. 173 */ 174 function is_compatible($plugin) 175 { 176 global $mybb; 177 178 // Ignore potentially missing plugins. 179 if(!file_exists(MYBB_ROOT."inc/plugins/".$plugin.".php")) 180 { 181 return true; 182 } 183 184 require_once MYBB_ROOT."inc/plugins/".$plugin.".php"; 185 186 $info_func = "{$plugin}_info"; 187 if(!function_exists($info_func)) 188 { 189 return false; 190 } 191 $plugin_info = $info_func(); 192 193 // No compatibility set or compatibility = * - assume compatible 194 if(!$plugin_info['compatibility'] || $plugin_info['compatibility'] == "*") 195 { 196 return true; 197 } 198 $compatibility = explode(",", $plugin_info['compatibility']); 199 foreach($compatibility as $version) 200 { 201 $version = trim($version); 202 $version = str_replace("*", ".+", preg_quote($version)); 203 $version = str_replace("\.+", ".+", $version); 204 if(preg_match("#{$version}#i", $mybb->version_code)) 205 { 206 return true; 207 } 208 } 209 210 // Nothing matches 211 return false; 212 } 213 } 214 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Dec 11 14:16:27 2011 | Cross-referenced by PHPXref 0.7.1 |