OSDN Git Service

CHANGE: NucleusPluginクラスの整理
authorsakamocchi <o-takashi@sakamocchi.jp>
Tue, 7 Feb 2012 11:46:00 +0000 (20:46 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Tue, 7 Feb 2012 11:46:00 +0000 (20:46 +0900)
CHANGE: maintainance NucleusPlugin abstract class.

以下の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
nucleus/libs/ADMIN.php
nucleus/libs/ITEM.php
nucleus/libs/MANAGER.php
nucleus/libs/PLUGIN.php

index 748c4d2..f4060d5 100644 (file)
@@ -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) . '\'');
index 8ab68da..de41381 100644 (file)
@@ -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));
                
index 13e2261..64132d5 100644 (file)
@@ -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
index 4be2099..0e41417 100644 (file)
@@ -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();
                }
index e21a013..ec81a95 100644 (file)
@@ -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;";