From 95985103ffbbd2e240e54725ca15ecb62003f278 Mon Sep 17 00:00:00 2001 From: sakamocchi Date: Tue, 7 Feb 2012 20:46:00 +0900 Subject: [PATCH] =?utf8?q?CHANGE:=20NucleusPlugin=E3=82=AF=E3=83=A9?= =?utf8?q?=E3=82=B9=E3=81=AE=E6=95=B4=E7=90=86=20CHANGE:=20maintainance=20?= =?utf8?q?NucleusPlugin=20abstract=20class.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 以下の4つをコミット。 NucleusPlugin::$plugidをprotectedメンバーに。 NucleusPlugin::setID()を追加。 NucleusPlugin::_applyPluginOptions()をNucleusPlugin::apply_plugin_options()に変更 ADMINクラス、ITEMクラス、MANAGERクラスとインストールスクリプトの上記に関連する修正 Commit these four modification, change NucleusPlugin::$plugid as protected member. add NucleusPlugin::setID(). rename NucleusPlugin::_applyPluginOptions() as apply_plugin_options(). change some codes in ADMIN, ITEM, MANAGER class and install script. --- install/index.php | 4 ++-- nucleus/libs/ADMIN.php | 8 ++++---- nucleus/libs/ITEM.php | 6 +++--- nucleus/libs/MANAGER.php | 28 +++++++++++++++------------- nucleus/libs/PLUGIN.php | 45 ++++++++++++++++++++++++++++++--------------- 5 files changed, 54 insertions(+), 37 deletions(-) diff --git a/install/index.php b/install/index.php index 748c4d2..f4060d5 100644 --- a/install/index.php +++ b/install/index.php @@ -1034,8 +1034,8 @@ function installCustomPlugs(&$manager) // get and install the plugin $manager->clearCachedInfo('installedPlugins'); $plugin =& $manager->getPlugin($plugName); - $plugin->plugid = $numCurrent; - + $plugin->setID($numCurrent); + if ( !$plugin ) { sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE `pfile` = \'' . addslashes($plugName) . '\''); diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index 8ab68da..de41381 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -2041,7 +2041,7 @@ class ADMIN { // store plugin options $aOptions = requestArray('plugoption'); - NucleusPlugin::_applyPluginOptions($aOptions); + NucleusPlugin::apply_plugin_options($aOptions); $manager->notify('PostPluginOptionsUpdate',array('context' => 'member', 'memberid' => $memberid, 'member' => &$mem)); // if email changed, generate new password @@ -2796,7 +2796,7 @@ class ADMIN { // store plugin options $aOptions = requestArray('plugoption'); - NucleusPlugin::_applyPluginOptions($aOptions); + NucleusPlugin::apply_plugin_options($aOptions); $manager->notify('PostPluginOptionsUpdate',array('context' => 'category', 'catid' => $catid)); @@ -3070,7 +3070,7 @@ class ADMIN { // store plugin options $aOptions = requestArray('plugoption'); - NucleusPlugin::_applyPluginOptions($aOptions); + NucleusPlugin::apply_plugin_options($aOptions); $manager->notify('PostPluginOptionsUpdate',array('context' => 'blog', 'blogid' => $blogid, 'blog' => &$blog)); $this->action_overview(_MSG_SETTINGSCHANGED); @@ -6564,7 +6564,7 @@ selector(); } $aOptions = requestArray('plugoption'); - NucleusPlugin::_applyPluginOptions($aOptions); + NucleusPlugin::apply_plugin_options($aOptions); $manager->notify('PostPluginOptionsUpdate',array('context' => 'global', 'plugid' => $pid)); diff --git a/nucleus/libs/ITEM.php b/nucleus/libs/ITEM.php index 13e2261..64132d5 100644 --- a/nucleus/libs/ITEM.php +++ b/nucleus/libs/ITEM.php @@ -210,7 +210,7 @@ class ITEM //Setting the itemOptions $aOptions = requestArray('plugoption'); - NucleusPlugin::_applyPluginOptions($aOptions, $itemid); + NucleusPlugin::apply_plugin_options($aOptions, $itemid); $manager->notify('PostPluginOptionsUpdate', array( 'context' => 'item', 'itemid' => $itemid, @@ -368,7 +368,7 @@ class ITEM //update the itemOptions $aOptions = requestArray('plugoption'); - NucleusPlugin::_applyPluginOptions($aOptions); + NucleusPlugin::apply_plugin_options($aOptions); $manager->notify('PostPluginOptionsUpdate', array( 'context' => 'item', 'itemid' => $itemid, @@ -552,7 +552,7 @@ class ITEM // No plugin support in AutoSaveDraft yet //Setting the itemOptions //$aOptions = requestArray('plugoption'); - //NucleusPlugin::_applyPluginOptions($aOptions, $itemid); + //NucleusPlugin::apply_plugin_options($aOptions, $itemid); //$manager->notify('PostPluginOptionsUpdate',array('context' => 'item', 'itemid' => $itemid, 'item' => array('title' => $i_title, 'body' => $i_body, 'more' => $i_more, 'closed' => $i_closed, 'catid' => $i_catid))); // success diff --git a/nucleus/libs/MANAGER.php b/nucleus/libs/MANAGER.php index 4be2099..0e41417 100644 --- a/nucleus/libs/MANAGER.php +++ b/nucleus/libs/MANAGER.php @@ -264,18 +264,20 @@ class MANAGER } /** - * A helper function to load a plugin - * - * private - */ + * MANAGER::_loadPlugin() + * loading a certain plugin + * + * @param string $name plugin name + * @return void + */ function _loadPlugin($name) { if ( !class_exists($name) ) { global $DIR_PLUGINS; - + $fileName = $DIR_PLUGINS . $name . '.php'; - + if ( !file_exists($fileName) ) { if ( !defined('_MANAGER_PLUGINFILE_NOTFOUND') ) @@ -285,23 +287,23 @@ class MANAGER ACTIONLOG::add(WARNING, sprintf(_MANAGER_PLUGINFILE_NOTFOUND, $name)); return 0; } - + // load plugin include($fileName); - + // check if class exists (avoid errors in eval'd code) if ( !class_exists($name) ) { ACTIONLOG::add(WARNING, sprintf(_MANAGER_PLUGINFILE_NOCLASS, $name)); return 0; } - + // add to plugin array eval('$this->plugins[$name] = new ' . $name . '();'); - + // get plugid - $this->plugins[$name]->plugid = $this->getPidFromName($name); - + $this->plugins[$name]->setID($this->getPidFromName($name)); + // unload plugin if a prefix is used and the plugin cannot handle this^ global $MYSQL_PREFIX; if ( ($MYSQL_PREFIX != '') @@ -321,7 +323,7 @@ class MANAGER ACTIONLOG::add(WARNING, sprintf(_MANAGER_PLUGINSQLAPI_NOTSUPPORT, $name)); return 0; } - + // call init method $this->plugins[$name]->init(); } diff --git a/nucleus/libs/PLUGIN.php b/nucleus/libs/PLUGIN.php index e21a013..ec81a95 100644 --- a/nucleus/libs/PLUGIN.php +++ b/nucleus/libs/PLUGIN.php @@ -262,7 +262,7 @@ abstract class NucleusPlugin $this->plugin_options = array(); $query = "SELECT d.oname as name, o.ovalue as value FROM %s o, %s d WHERE d.opid=%d AND d.oid=o.oid;"; - $query = sprintf($query, sql_table('plugin_option'), sql_table('plugin_option_desc'), (integer) $this->getID()); + $query = sprintf($query, sql_table('plugin_option'), sql_table('plugin_option_desc'), (integer) $this->plugid); $result = sql_query($query); while ( $row = sql_fetch_object($result) ) { @@ -348,13 +348,30 @@ abstract class NucleusPlugin } /** - * Returns the plugin ID - * - * public + * NucleusPlugin::getID() + * get id for this plugin + * + * @access public + * @param void + * @return integer this plugid id */ final public function getID() { - return $this->plugid; + return (integer) $this->plugid; + } + + /** + * NucleusPlugin::setID() + * set favorite id for this plugin + * + * @access public + * @param integer $plugid favorite id for plugin + * @return void + */ + final public function setID($plugid) + { + $this->plugid = (integer) $plugid; + return; } /** @@ -408,12 +425,10 @@ abstract class NucleusPlugin } // internal functions of the class starts here - protected $option_values; // oid_contextid => value - protected $option_info; // context_name => array('oid' => ..., 'default' => ...) + protected $option_info; // context_name => array('oid' => ..., 'default' => ...) protected $plugin_options; // see getOption() - /* TODO: This should be protected member */ - public $plugid; // plugin id + protected $plugid; // plugin id /** * Class constructor: Initializes some internal data @@ -834,7 +849,7 @@ abstract class NucleusPlugin */ public function subscribtionListIsUptodate() { - $res = sql_query('SELECT event FROM '.sql_table('plugin_event').' WHERE pid = '.$this->getID()); + $res = sql_query('SELECT event FROM '.sql_table('plugin_event').' WHERE pid = '.$this->plugid); $ev = array(); while( $a = sql_fetch_array($res) ) { @@ -854,26 +869,26 @@ abstract class NucleusPlugin } /** - * NucleusPlugin::_applyPluginOptions() + * NucleusPlugin::apply_plugin_options() * Update its entry in database table * * @static - * @param $aOptions: array ( 'oid' => array( 'contextid' => 'value')) + * @param $options: array ( 'oid' => array( 'contextid' => 'value')) * (taken from request using requestVar()) * @param $newContextid: integer (accepts a contextid when it is for a new * contextid there was no id available at the moment of writing the * formcontrols into the page (by ex: itemOptions for new item) * @return void */ - static public function _applyPluginOptions(&$aOptions, $newContextid = 0) + static public function apply_plugin_options(&$options, $newContextid = 0) { global $manager; - if ( !is_array($aOptions) ) + if ( !is_array($options) ) { return; } - foreach ( $aOptions as $oid => $values ) + foreach ( $options as $oid => $values ) { // get option type info $query = "SELECT opid, oname, ocontext, otype, oextra, odef FROM %s WHERE oid=%d;"; -- 2.11.0