OSDN Git Service

MERGE:リビジョン1668/1669をマージ。
authorsakamocchi <o-takashi@sakamocchi.jp>
Sun, 19 Feb 2012 14:48:15 +0000 (23:48 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sun, 19 Feb 2012 14:48:15 +0000 (23:48 +0900)
MERGE: merge revision 1668/1669

いくつかの関数がNucleusPlugin::_deleteOptionValues()を使っていたため、これをNucleusPlugin::delete_option_values()に修正。

FIX:  Some functions still uses
old NucleusPlugin::_deleteOptionValues().
http://nucleuscms.svn.sourceforge.net/viewvc/nucleuscms?view=revision&revision=1668

Oops. my previous commit has duplicate functions.
(ADMIN.php is hard to parse on my IDE because it uses much
short-open-tags...)
http://nucleuscms.svn.sourceforge.net/viewvc/nucleuscms?view=revision&revision=1669

nucleus/libs/ADMIN.php
nucleus/libs/ITEM.php
nucleus/libs/PLUGIN.php

index 505b155..5d84f43 100644 (file)
@@ -2874,124 +2874,68 @@ class ADMIN
 
         $this->action_blogsettings();
     }
-
-    /**
-     * @todo document this
-     */
-    function deleteOneCategory($catid) {
-        global $manager, $member;
-
-        $catid = intval($catid);
-
-        $blogid = getBlogIDFromCatID($catid);
-
-        if (!$member->blogAdminRights($blogid))
-            return ERROR_DISALLOWED;
-
-        // get blog
-        $blog =& $manager->getBlog($blogid);
-
-        // check if the category is valid
-        if (!$blog || !$blog->isValidCategory($catid))
-            return _ERROR_NOSUCHCATEGORY;
-
-        $destcatid = $blog->getDefaultCategory();
-
-        // don't allow deletion of default category
-        if ($blog->getDefaultCategory() == $catid)
-            return _ERROR_DELETEDEFCATEGORY;
-
-        // check if catid is the only category left for blogid
-        $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid;
-        $res = sql_query($query);
-        if (sql_num_rows($res) == 1)
-            return _ERROR_DELETELASTCATEGORY;
-
-        $manager->notify('PreDeleteCategory', array('catid' => $catid));
-
-        // change category for all items to the default category
-        $query = 'UPDATE '.sql_table('item')." SET icat=$destcatid WHERE icat=$catid";
-        sql_query($query);
-
-        // delete all associated plugin options
-        NucleusPlugin::_deleteOptionValues('category', $catid);
-
-        // delete category
-        $query = 'DELETE FROM '.sql_table('category').' WHERE catid=' .$catid;
-        sql_query($query);
-
-        $manager->notify('PostDeleteCategory', array('catid' => $catid));
-
-    }
-
-    /**
-     * @todo document this
-     */
-    function moveOneCategory($catid, $destblogid) {
-        global $manager, $member;
-
-        $catid = intval($catid);
-        $destblogid = intval($destblogid);
-
-        $blogid = getBlogIDFromCatID($catid);
-
-        // mover should have admin rights on both blogs
-        if (!$member->blogAdminRights($blogid))
-            return _ERROR_DISALLOWED;
-        if (!$member->blogAdminRights($destblogid))
-            return _ERROR_DISALLOWED;
-
-        // cannot move to self
-        if ($blogid == $destblogid)
-            return _ERROR_MOVETOSELF;
-
-        // get blogs
-        $blog =& $manager->getBlog($blogid);
-        $destblog =& $manager->getBlog($destblogid);
-
-        // check if the category is valid
-        if (!$blog || !$blog->isValidCategory($catid))
-            return _ERROR_NOSUCHCATEGORY;
-
-        // don't allow default category to be moved
-        if ($blog->getDefaultCategory() == $catid)
-            return _ERROR_MOVEDEFCATEGORY;
-
-        $manager->notify(
-            'PreMoveCategory',
-            array(
-                'catid' => &$catid,
-                'sourceblog' => &$blog,
-                'destblog' => &$destblog
-            )
-        );
-
-        // update comments table (cblog)
-        $query = 'SELECT inumber FROM '.sql_table('item').' WHERE icat='.$catid;
-        $items = sql_query($query);
-        while ($oItem = sql_fetch_object($items)) {
-            sql_query('UPDATE '.sql_table('comment').' SET cblog='.$destblogid.' WHERE citem='.$oItem->inumber);
-        }
-
-        // update items (iblog)
-        $query = 'UPDATE '.sql_table('item').' SET iblog='.$destblogid.' WHERE icat='.$catid;
-        sql_query($query);
-
-        // move category
-        $query = 'UPDATE '.sql_table('category').' SET cblog='.$destblogid.' WHERE catid='.$catid;
-        sql_query($query);
-
-        $manager->notify(
-            'PostMoveCategory',
-            array(
-                'catid' => &$catid,
-                'sourceblog' => &$blog,
-                'destblog' => $destblog
-            )
-        );
-
-    }
-
+       
+       /**
+        * ADMIN::deleteOneCategory()
+        * Delete a category by its id
+        * 
+        * @param       String  $catid  category id for deleting
+        * @return      Void
+        */
+       function deleteOneCategory($catid)
+       {
+               global $manager, $member;
+               
+               $catid = intval($catid);
+               $blogid = getBlogIDFromCatID($catid);
+               
+               if ( !$member->blogAdminRights($blogid) )
+               {
+                       return ERROR_DISALLOWED;
+               }
+               
+               // get blog
+               $blog =& $manager->getBlog($blogid);
+               
+               // check if the category is valid
+               if ( !$blog || !$blog->isValidCategory($catid) )
+               {
+                       return _ERROR_NOSUCHCATEGORY;
+               }
+               
+               $destcatid = $blog->getDefaultCategory();
+               
+               // don't allow deletion of default category
+               if ( $blog->getDefaultCategory() == $catid )
+               {
+                       return _ERROR_DELETEDEFCATEGORY;
+               }
+               
+               // check if catid is the only category left for blogid
+               $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid;
+               $res = sql_query($query);
+               if ( sql_num_rows($res) == 1 )
+               {
+                       return _ERROR_DELETELASTCATEGORY;
+               }
+               
+               $manager->notify('PreDeleteCategory', array('catid' => $catid));
+               
+               // change category for all items to the default category
+               $query = 'UPDATE '.sql_table('item')." SET icat=$destcatid WHERE icat=$catid";
+               sql_query($query);
+               
+               // delete all associated plugin options
+               NucleusPlugin::delete_option_values('category', $catid);
+               
+               // delete category
+               $query = 'DELETE FROM '.sql_table('category').' WHERE catid=' .$catid;
+               sql_query($query);
+               
+               $manager->notify('PostDeleteCategory', array('catid' => $catid));
+               return;
+       }
+       
        /**
         * ADMIN::action_blogsettingsupdate
         * Updating blog settings
@@ -3115,55 +3059,61 @@ class ADMIN
         <?php
         $this->pagefoot();
     }
-
-    /**
-     * @todo document this
-     */
-    function action_deleteblogconfirm() {
-        global $member, $CONF, $manager;
-
-        $blogid = intRequestVar('blogid');
-
-        $manager->notify('PreDeleteBlog', array('blogid' => $blogid));
-
-        $member->blogAdminRights($blogid) or $this->disallow();
-
-        // check if blog is default blog
-        if ($CONF['DefaultBlog'] == $blogid)
-            $this->error(_ERROR_DELDEFBLOG);
-
-        // delete all comments
-        $query = 'DELETE FROM '.sql_table('comment').' WHERE cblog='.$blogid;
-        sql_query($query);
-
-        // delete all items
-        $query = 'DELETE FROM '.sql_table('item').' WHERE iblog='.$blogid;
-        sql_query($query);
-
-        // delete all team members
-        $query = 'DELETE FROM '.sql_table('team').' WHERE tblog='.$blogid;
-        sql_query($query);
-
-        // delete all bans
-        $query = 'DELETE FROM '.sql_table('ban').' WHERE blogid='.$blogid;
-        sql_query($query);
-
-        // delete all categories
-        $query = 'DELETE FROM '.sql_table('category').' WHERE cblog='.$blogid;
-        sql_query($query);
-
-        // delete all associated plugin options
-        NucleusPlugin::_deleteOptionValues('blog', $blogid);
-
-        // delete the blog itself
-        $query = 'DELETE FROM '.sql_table('blog').' WHERE bnumber='.$blogid;
-        sql_query($query);
-
-        $manager->notify('PostDeleteBlog', array('blogid' => $blogid));
-
-        $this->action_overview(_DELETED_BLOG);
-    }
-
+       
+       /**
+        * ADMIN::action_deleteblogconfirm()
+        * Delete Blog
+        * 
+        * @param       Void
+        * @return      Void
+        */
+       function action_deleteblogconfirm()
+       {
+               global $member, $CONF, $manager;
+               
+               $blogid = intRequestVar('blogid');
+               $manager->notify('PreDeleteBlog', array('blogid' => $blogid));
+               $member->blogAdminRights($blogid) or $this->disallow();
+               
+               // check if blog is default blog
+               if ( $CONF['DefaultBlog'] == $blogid )
+               {
+                       $this->error(_ERROR_DELDEFBLOG);
+               }
+               
+               // delete all comments
+               $query = 'DELETE FROM '.sql_table('comment').' WHERE cblog='.$blogid;
+               sql_query($query);
+               
+               // delete all items
+               $query = 'DELETE FROM '.sql_table('item').' WHERE iblog='.$blogid;
+               sql_query($query);
+               
+               // delete all team members
+               $query = 'DELETE FROM '.sql_table('team').' WHERE tblog='.$blogid;
+               sql_query($query);
+               
+               // delete all bans
+               $query = 'DELETE FROM '.sql_table('ban').' WHERE blogid='.$blogid;
+               sql_query($query);
+               
+               // delete all categories
+               $query = 'DELETE FROM '.sql_table('category').' WHERE cblog='.$blogid;
+               sql_query($query);
+               
+               // delete all associated plugin options
+               NucleusPlugin::delete_option_values('blog', $blogid);
+               
+               // delete the blog itself
+               $query = 'DELETE FROM '.sql_table('blog').' WHERE bnumber='.$blogid;
+               sql_query($query);
+               
+               $manager->notify('PostDeleteBlog', array('blogid' => $blogid));
+               
+               $this->action_overview(_DELETED_BLOG);
+               return;
+       }
+       
     /**
      * @todo document this
      */
@@ -3216,46 +3166,54 @@ class ADMIN
         else
             $this->action_overview(_DELETED_MEMBER);
     }
-
-    /**
-     * @static
-     * @todo document this
-     */
-    function deleteOneMember($memberid) {
-        global $manager;
-
-        $memberid = intval($memberid);
-        $mem = MEMBER::createFromID($memberid);
-
-        if (!$mem->canBeDeleted())
-            return _ERROR_DELETEMEMBER;
-
-        $manager->notify('PreDeleteMember', array('member' => &$mem));
-
-        /* unlink comments from memberid */
-        if ($memberid) {
-            $query = 'UPDATE ' . sql_table('comment') . ' SET cmember="0", cuser="'. sql_real_escape_string($mem->getDisplayName())
-                        .'" WHERE cmember='.$memberid;
-            sql_query($query);
-        }
-
-        $query = 'DELETE FROM '.sql_table('member').' WHERE mnumber='.$memberid;
-        sql_query($query);
-
-        $query = 'DELETE FROM '.sql_table('team').' WHERE tmember='.$memberid;
-        sql_query($query);
-
-        $query = 'DELETE FROM '.sql_table('activation').' WHERE vmember='.$memberid;
-        sql_query($query);
-
-        // delete all associated plugin options
-        NucleusPlugin::_deleteOptionValues('member', $memberid);
-
-        $manager->notify('PostDeleteMember', array('member' => &$mem));
-
-        return '';
-    }
-
+       
+       /**
+        * ADMIN::deleteOneMember()
+        * Delete a member by id
+        * 
+        * @static
+        * @params      Integer $memberid       member id
+        * @return      String  null string or error messages
+        */
+       function deleteOneMember($memberid)
+       {
+               global $manager;
+               
+               $memberid = intval($memberid);
+               $mem = MEMBER::createFromID($memberid);
+               
+               if ( !$mem->canBeDeleted() )
+               {
+                       return _ERROR_DELETEMEMBER;
+               }
+               
+               $manager->notify('PreDeleteMember', array('member' => &$mem));
+               
+               /* unlink comments from memberid */
+               if ( $memberid )
+               {
+                       $query = "UPDATE %s SET cmember=0, cuser='%s' WHERE cmember=%d";
+                       $query = sprintf($query, sql_table('comment'), sql_real_escape_string($mem->getDisplayName()), $memberid);
+                       sql_query($query);
+               }
+               
+               $query = 'DELETE FROM '.sql_table('member').' WHERE mnumber='.$memberid;
+               sql_query($query);
+               
+               $query = 'DELETE FROM '.sql_table('team').' WHERE tmember='.$memberid;
+               sql_query($query);
+               
+               $query = 'DELETE FROM '.sql_table('activation').' WHERE vmember='.$memberid;
+               sql_query($query);
+               
+               // delete all associated plugin options
+               NucleusPlugin::delete_option_values('member', $memberid);
+               
+               $manager->notify('PostDeleteMember', array('member' => &$mem));
+               
+               return '';
+       }
+       
     /**
      * @todo document this
      */
index 64132d5..cac28be 100644 (file)
@@ -424,40 +424,45 @@ class ITEM
                        )
                );
        }
-
+       
        /**
-         * Deletes an item
-         */
-       function delete($itemid) {
+        * ITEM::delete()
+        * Deletes an item
+        * 
+        * @param       Void
+        * @return      Void
+        */
+       function delete($itemid)
+       {
                global $manager, $member;
-
-               $itemid = intval($itemid);
-
+               
+               $itemid = (integer) $itemid;
+               
                // check to ensure only those allow to alter the item can
                // proceed
-               if (!$member->canAlterItem($itemid)) {
+               if ( !$member->canAlterItem($itemid) )
+               {
                        return 1;
                }
-
-
+               
                $manager->notify('PreDeleteItem', array('itemid' => $itemid));
-
+               
                // delete item
                $query = 'DELETE FROM '.sql_table('item').' WHERE inumber=' . $itemid;
                sql_query($query);
-
+               
                // delete the comments associated with the item
                $query = 'DELETE FROM '.sql_table('comment').' WHERE citem=' . $itemid;
                sql_query($query);
-
+               
                // delete all associated plugin options
-               NucleusPlugin::_deleteOptionValues('item', $itemid);
-
+               NucleusPlugin::delete_option_values('item', $itemid);
+               
                $manager->notify('PostDeleteItem', array('itemid' => $itemid));
-
+               
                return 0;
        }
-
+       
        /**
         * Returns true if there is an item with the given ID
         *
index 2b2f881..0e21686 100644 (file)
@@ -760,12 +760,16 @@ abstract class NucleusPlugin
        }
        
        /**
+        * NucleusPlugin::delete_option_values()
         * Deletes all option values for a given context and contextid
         * (used when e.g. a blog, member or category is deleted)
         *
-        * (static method)
+        *@static
+        *@param        String  $context        global/blog/category/item/member
+        *@param        Integer $contextid              ID
+        *@return       Void
         */
-       final protected function delete_option_values($context, $contextid)
+       static public function delete_option_values($context, $contextid)
        {
                // delete all associated plugin options
                $aOIDs = array();