From 1859e92e864e87bc2569b567a4fbb84cc7d9cf91 Mon Sep 17 00:00:00 2001 From: joyqi Date: Thu, 9 Jan 2014 00:56:51 +0800 Subject: [PATCH] fix #152 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加了插件优先级定义的支持,多个插件之间可以自行约定执行顺序,范例 Typecho_Plugin::factory('admin/menu.php')->navBar_1000 = array('HelloWorld_Plugin', 'render'); 这个插件的执行优先级就是1000,默认的执行顺序是10,越大的数字越靠后执行 --- var/Typecho/Plugin.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/var/Typecho/Plugin.php b/var/Typecho/Plugin.php index ace69ed7..ffded801 100644 --- a/var/Typecho/Plugin.php +++ b/var/Typecho/Plugin.php @@ -421,9 +421,38 @@ class Typecho_Plugin */ public function __set($component, $value) { + $weight = 0; + + if (strpos($component, '_') > 0) { + $parts = explode('_', $component, 2); + list($component, $weight) = $parts; + $weight = intval($weight) - 10; + } + $component = $this->_handle . ':' . $component; - self::$_plugins['handles'][$component][] = $value; + + if (!isset(self::$_plugins['handles'][$component])) { + self::$_plugins['handles'][$component] = array(); + } + + if (!isset(self::$_tmp['handles'][$component])) { + self::$_tmp['handles'][$component] = array(); + } + + foreach (self::$_plugins['handles'][$component] as $key => $val) { + $key = floatval($key); + + if ($weight > $key) { + break; + } else if ($weight == $key) { + $weight += 0.001; + } + } + + self::$_plugins['handles'][$component][strval($weight)] = $value; self::$_tmp['handles'][$component][] = $value; + + ksort(self::$_plugins['handles'][$component], SORT_NUMERIC); } /**