OSDN Git Service

MERGE: リビジョン1846。Itemクラスのコード整理。
authorsakamocchi <o-takashi@sakamocchi.jp>
Sun, 13 May 2012 11:32:02 +0000 (20:32 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sun, 13 May 2012 11:32:02 +0000 (20:32 +0900)
nucleus/libs/ITEM.php

index 2576efd..475f6a3 100644 (file)
@@ -28,14 +28,15 @@ class Item
         * \r
         * @static\r
         */\r
-       static private $actiontypes\r
-               = array('addnow', 'adddraft', 'addfuture', 'edit', 'changedate', 'backtodrafts', 'delete');\r
+       static private $actiontypes = array(\r
+               'addnow', 'adddraft', 'addfuture', 'edit',\r
+               'changedate', 'backtodrafts', 'delete'\r
+       );\r
        \r
        /**\r
         * Item::$itemid\r
         * item id\r
         * @deprecated\r
-        * \r
         */\r
        public $itemid;\r
        \r
@@ -56,12 +57,12 @@ class Item
        /**\r
         * Item::getitem()\r
         * Returns one item with the specific itemid\r
-        *\r
+        * \r
+        * @static\r
         * @param int $item_id\r
         * @param bool $allow_draft\r
         * @param bool $allow_future\r
         * @return mixed\r
-        * \r
         */\r
        static public function getitem($item_id, $allow_draft, $allow_future)\r
        {\r
@@ -110,10 +111,7 @@ class Item
                        $aItemInfo['timestamp'] = strtotime($aItemInfo['itime']);\r
                        return $aItemInfo;\r
                }\r
-               else\r
-               {\r
-                       return 0;\r
-               }\r
+               return 0;\r
        }\r
        \r
        /**\r
@@ -224,19 +222,20 @@ class Item
                //Setting the itemOptions\r
                $aOptions = requestArray('plugoption');\r
                NucleusPlugin::apply_plugin_options($aOptions, $itemid);\r
-               $manager->notify('PostPluginOptionsUpdate', array(\r
-                       'context' => 'item',\r
-                       'itemid' => $itemid,\r
-                       'item' => array(\r
-                               'title' => $i_title,\r
-                               'body' => $i_body,\r
-                               'more' => $i_more,\r
-                               'closed' => $i_closed,\r
-                               'catid' => $i_catid\r
-                               )\r
+               $data = array(\r
+                       'context'       => 'item',\r
+                       'itemid'        => $itemid,\r
+                       'item'          => array(\r
+                               'title'         => $i_title,\r
+                               'body'          => $i_body,\r
+                               'more'          => $i_more,\r
+                               'closed'        => $i_closed,\r
+                               'catid'         => $i_catid\r
                        )\r
                );\r
                \r
+               $manager->notify('PostPluginOptionsUpdate', $data);\r
+               \r
                if ( $i_draftid > 0 )\r
                {\r
                        // delete permission is checked inside Item::delete()\r
@@ -248,10 +247,8 @@ class Item
                {\r
                        return array('status' => 'newcategory', 'itemid' => $itemid, 'catid' => $i_catid);\r
                }\r
-               else\r
-               {\r
-                       return array('status' => 'added', 'itemid' => $itemid);\r
-               }\r
+               \r
+               return array('status' => 'added', 'itemid' => $itemid);\r
        }\r
        \r
        /**\r
@@ -269,7 +266,6 @@ class Item
         * @param       boolean $publish        published or not\r
         * @param       timestamp       $timestamp      timestamp\r
         * @return      void\r
-        * \r
         */\r
        static public function update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp = 0)\r
        {\r
@@ -299,7 +295,7 @@ class Item
                }\r
                \r
                // call plugins\r
-               $manager->notify('PreUpdateItem', array(\r
+               $data = array(\r
                        'itemid'        => $itemid,\r
                        'title'         => &$title,\r
                        'body'          => &$body,\r
@@ -307,8 +303,8 @@ class Item
                        'blog'          => &$blog,\r
                        'closed'        => &$closed,\r
                        'catid'         => &$catid\r
-                       )\r
                );\r
+               $manager->notify('PreUpdateItem', $data);\r
                \r
                // update item itself\r
                $query =  'UPDATE ' . sql_table('item')\r
@@ -319,7 +315,8 @@ class Item
                                . ' iclosed = ' . intval($closed) . ','\r
                                . ' icat = ' . intval($catid);\r
                \r
-               // if we received an updated timestamp that is in the past, but past posting is not allowed, reject that date change (timestamp = 0 will make sure the current date is kept)\r
+               // if we received an updated timestamp that is in the past, but past posting is not allowed,\r
+               // reject that date change (timestamp = 0 will make sure the current date is kept)\r
                if ( (!$blog->allowPastPosting()) && ($timestamp < $blog->getCorrectTime()) )\r
                {\r
                        $timestamp = 0;\r
@@ -387,18 +384,18 @@ class Item
                //update the itemOptions\r
                $aOptions = requestArray('plugoption');\r
                NucleusPlugin::apply_plugin_options($aOptions);\r
-               $manager->notify('PostPluginOptionsUpdate', array(\r
-                       'context' => 'item',\r
-                       'itemid' => $itemid,\r
-                       'item' => array(\r
-                               'title' => $title,\r
-                               'body' => $body,\r
-                               'more' => $more,\r
-                               'closed' => $closed,\r
-                               'catid' => $catid\r
-                               )\r
+               $data = array(\r
+                       'context'       => 'item',\r
+                       'itemid'        => $itemid,\r
+                       'item'          => array(\r
+                               'title'         => $title,\r
+                               'body'          => $body,\r
+                               'more'          => $more,\r
+                               'closed'        => $closed,\r
+                               'catid'         => $catid\r
                        )\r
                );\r
+               $manager->notify('PostPluginOptionsUpdate', $data);\r
                return;\r
        }\r
        \r
@@ -415,18 +412,16 @@ class Item
        {\r
                global $manager;\r
                \r
-               $itemid                 = (integer) $itemid;\r
-               $new_catid      = (integer) $new_catid;\r
-               $new_blogid     = getBlogIDFromCatID($new_catid);\r
+               $itemid = (integer) $itemid;\r
+               $new_catid = (integer) $new_catid;\r
+               $new_blogid = getBlogIDFromCatID($new_catid);\r
                \r
-               $manager->notify(\r
-                       'PreMoveItem',\r
-                       array(\r
-                               'itemid' => $itemid,\r
-                               'destblogid' => $new_blogid,\r
-                               'destcatid' => $new_catid\r
-                       )\r
+               $data = array(\r
+                       'itemid'                => $itemid,\r
+                       'destblogid'    => $new_blogid,\r
+                       'destcatid'             => $new_catid\r
                );\r
+               $manager->notify('PreMoveItem', $data);\r
                \r
                // update item table\r
                $query = "UPDATE %s SET iblog=%d, icat=%d WHERE inumber=%d";\r
@@ -438,14 +433,12 @@ class Item
                $query = sprintf($query, sql_table('comment'), $new_blogid, $itemid);\r
                DB::execute($query);\r
                \r
-               $manager->notify(\r
-                       'PostMoveItem',\r
-                       array(\r
-                               'itemid' => $itemid,\r
-                               'destblogid' => $new_blogid,\r
-                               'destcatid' => $new_catid\r
-                       )\r
+               $data = array(\r
+                       'itemid'                => $itemid,\r
+                       'destblogid'    => $new_blogid,\r
+                       'destcatid'             => $new_catid\r
                );\r
+               $manager->notify('PostMoveItem', $data);\r
                return;\r
        }\r
        \r
@@ -471,12 +464,12 @@ class Item
                $manager->notify('PreDeleteItem', array('itemid' => $itemid));\r
                \r
                // delete item\r
-               $query = "DELETE FROM %s WHERE inumber=%d";\r
+               $query = "DELETE FROM %s WHERE inumber=%d;";\r
                $query = sprintf($query, sql_table('item'), $itemid);\r
                DB::execute($query);\r
                \r
                // delete the comments associated with the item\r
-               $query = "DELETE FROM %s WHERE citem=%d";\r
+               $query = "DELETE FROM %s WHERE citem=%d;";\r
                $query = sprintf($query, sql_table('comment'), $itemid);\r
                DB::execute($query);\r
                \r
@@ -497,14 +490,15 @@ class Item
         * @param       boolean $future\r
         * @param       boolean $draft\r
         * @return      boolean exists or not\r
-        * \r
         */\r
        static public function exists($itemid, $future, $draft)\r
        {\r
                global $manager;\r
                \r
                $itemid = (integer) $itemid;\r
-               $query = 'select * FROM '.sql_table('item').' WHERE inumber='.$itemid;\r
+               \r
+               $query = 'SELECT * FROM %s WHERE inumber=%d';\r
+               $query = sprintf($query, sql_table('item'), $itemid);\r
                \r
                if ( !$future )\r
                {\r
@@ -514,12 +508,14 @@ class Item
                                return 0;\r
                        }\r
                        $blog =& $manager->getBlog($blogid);\r
-                       $query .= ' and itime<=' . DB::formatDateTime($blog->getCorrectTime());\r
+                       $query .= ' AND itime<=' . DB::formatDateTime($blog->getCorrectTime());\r
                }\r
+               \r
                if ( !$draft )\r
                {\r
-                       $query .= ' and idraft=0';\r
+                       $query .= ' AND idraft=0';\r
                }\r
+               \r
                $result = DB::getResult($query);\r
                return ( $result->rowCount() != 0 );\r
        }\r
@@ -536,7 +532,6 @@ class Item
         * @static\r
         * @param       void\r
         * @return      array   (status = added/error/newcategory, message)\r
-        *\r
         */\r
        static public function createDraftFromRequest()\r
        {\r
@@ -545,14 +540,14 @@ class Item
                /*\r
                 * TODO: these values from user agent should be validated but not implemented yet\r
                 */\r
-               $i_author               = $member->getID();\r
-               $i_body                 = postVar('body');\r
-               $i_title                = postVar('title');\r
-               $i_more                 = postVar('more');\r
-               $i_closed               = intPostVar('closed');\r
-               $i_catid                = postVar('catid');\r
-               $i_draft                = 1;\r
-               $type                           = postVar('type');\r
+               $i_author       = $member->getID();\r
+               $i_body         = postVar('body');\r
+               $i_title        = postVar('title');\r
+               $i_more         = postVar('more');\r
+               $i_closed       = intPostVar('closed');\r
+               $i_catid        = postVar('catid');\r
+               $i_draft        = 1;\r
+               $type           = postVar('type');\r
                $i_draftid      = intPostVar('draftid');\r
                \r
                if ( $type == 'edit' )\r