OSDN Git Service

Merge branch 'skinnable-master' of ssh://shizuki@git.sourceforge.jp/gitroot/nucleus...
[nucleus-jp/nucleus-next.git] / nucleus / libs / PAGEFACTORY.php
index d578d3e..768c16e 100644 (file)
 class PageFactory extends BaseActions\r
 {\r
        /**\r
+        * PageFactory::$blog\r
         * Reference to the blog object for which an add:edit form is created\r
         */\r
        private $blog;\r
-\r
-       /**\r
-        * Allowed actions (for parser)\r
-        */\r
-       private $actions;\r
-\r
+       \r
        /**\r
+        * PageFactory::$allowed_types\r
         * Allowed types of forms (bookmarklet/admin)\r
         */\r
        private $allowed_types;\r
-\r
+       \r
        /**\r
+        * PageFactory::$type\r
         * One of the types in $allowed_types\r
         */\r
        private $type;\r
-\r
+       \r
        /**\r
+        * PageFactory::$method\r
         * 'add' or 'edit'\r
         */\r
        private $method;\r
-\r
+       \r
        /**\r
+        * PageFactory::$variables\r
         * Info to fill out in the form (e.g. catid, itemid, ...)\r
         */\r
        private $variables;\r
-\r
-       public $objAdmin;\r
+       \r
+       /**\r
+        * PageFactory::$actions\r
+        * Allowed actions (for parser)\r
+        */\r
+       // TODO: move the definition of actions to the createXForm methods\r
+       static private $defined_actions = array(\r
+               'actionurl',\r
+               'title',\r
+               'body',\r
+               'more',\r
+               'blogid',\r
+               'bloglink',\r
+               'blogname',\r
+               'authorname',\r
+               'checkedonval',\r
+               'helplink',\r
+               'currenttime',\r
+               'itemtime',\r
+               'init',\r
+               'text',\r
+               'jsinput',\r
+               'jsbuttonbar',\r
+               'categories',\r
+               'contents',\r
+               'ifblogsetting',\r
+               'ifitemproperty',\r
+               'else',\r
+               'endif',\r
+               'pluginextras',\r
+               'itemoptions',\r
+               'extrahead',\r
+               'ticket',\r
+               'autosave',\r
+               'autosaveinfo',\r
+               'ifautosave'\r
+       );\r
+       \r
        /**\r
         * Creates a new PAGEFACTORY object\r
         * @param int $blog_id\r
         */\r
-       public function __construct($blog_id, $type = '', $skin = '', $objAdmin = '')\r
+       public function __construct($type = '', $blogid, $skin = '')\r
        {\r
+               global $manager;\r
                # Call constructor of superclass first\r
                parent::__construct();\r
-\r
-               if ( $objAdmin )\r
-               {\r
-                       $this->objAdmin = $objAdmin;\r
-               }\r
-               else\r
-               {\r
-                       $this->objAdmin = new Admin();\r
-               }\r
-               global $manager;\r
-               $item = false;\r
-               if ( !$blogid && intRequestVar('itemid') && $type == 'itemedit' )\r
+               \r
+               if ( !$blogid && $type == 'itemedit' )\r
                {\r
-                       $itemid =  intRequestVar('itemid');\r
-                       $blogid =  getBlogIDFromItemID($itemid);\r
-                       $item   =& $manager->getItem($itemid, 1, 1);\r
-                       $manager->notify(\r
-                               'PrepareItemForEdit',\r
-                               array(\r
-                                       'item' => &$item\r
-                               )\r
-                       );\r
+                       $itemid = intRequestVar('itemid');\r
+                       $blogid =  getBlogIDFromItemID($itemid);\r
+                       $item   = &$manager->getItem($itemid, 1, 1);\r
+                       $manager->notify('PrepareItemForEdit', array('item' => &$item));\r
                }\r
-               $this->blog =& $manager->getBlog($blog_id);\r
+               \r
+               $this->blog =& $manager->getBlog($blogid);\r
+               \r
                if ( $item && $this->blog->convertBreaks() && $type == 'itemedit' )\r
                {\r
                        $item['body'] = removeBreaks($item['body']);\r
                        $item['more'] = removeBreaks($item['more']);\r
                }\r
+               \r
                $contents = array();\r
                if ( $type == 'itemedit' )\r
                {\r
@@ -97,542 +122,17 @@ class PageFactory extends BaseActions
                }\r
                elseif ( $type == 'createitem' )\r
                {\r
-                       $manager->notify(\r
-                               'PreAddItemForm',\r
-                               array(\r
-                                       'contents' => &$contents,\r
-                                       'blog'     => &$this->blog\r
-                               )\r
+                       $data = array(\r
+                               'contents' => &$contents,\r
+                               'blog'     => &$this->blog\r
                        );\r
+                       $manager->notify('PreAddItemForm', $data);\r
                }\r
                $this->variables = $contents;\r
                \r
-               // TODO: move the definition of actions to the createXForm methods\r
-               $this->actions = array(\r
-                                                       'actionurl',\r
-                                                       'title',\r
-                                                       'body',\r
-                                                       'more',\r
-                                                       'blogid',\r
-                                                       'bloglink',\r
-                                                       'blogname',\r
-                                                       'authorname',\r
-                                                       'checkedonval',\r
-                                                       'helplink',\r
-                                                       'currenttime',\r
-                                                       'itemtime',\r
-                                                       'init',\r
-                                                       'text',\r
-                                                       'jsinput',\r
-                                                       'jsbuttonbar',\r
-                                                       'categories',\r
-                                                       'contents',\r
-                                                       'ifblogsetting',\r
-                                                       'ifitemproperty',\r
-                                                       'else',\r
-                                                       'endif',\r
-                                                       'pluginextras',\r
-                                                       'itemoptions',\r
-                                                       'extrahead',\r
-                                                       'ticket',\r
-                                                       'autosave',\r
-                                                       'autosaveinfo',\r
-                                                       'ifautosave',\r
-                                               );\r
-\r
-               $skinActions   = AdminActions::get_allowed_actions_for_type($type);\r
+               $skin = new Skin($skin_id, 'AdminActions', 'AdminSkin');\r
+               $allowed_action_types = $skin->getAllowedActionsForType($type);\r
                $this->actions = array_merge($skinActions, $formActions);\r
-//             $adminActions  = skinableACTIONS::getDefinedActions();\r
-//             $this->actions = array_merge($skinActions, $adminActions, $formActions);\r
-\r
-               # TODO: maybe add 'skin' later on?\r
-               # TODO: maybe add other pages from admin area\r
-//             $this->allowed_types = array('bookmarklet', 'admin');\r
-       }\r
-\r
-\r
-/***** The bottom isn't used from here. *****/\r
-\r
-       /**\r
-        * Creates an "add item" form for a given type of page\r
-        * @param string $type - 'admin' or 'bookmarklet'\r
-        * @param array $contents\r
-        */\r
-       public function createAddForm($type, $contents = array())\r
-       {\r
-\r
-               // begin if: the $type is not in the allowed types array\r
-               if ( !in_array($type, $this->allowed_types) )\r
-               {\r
-                       return;\r
-               } // end if\r
-\r
-               $this->type = $type;\r
-               $this->method = 'add';\r
-\r
-               global $manager;\r
-               $manager->notify(\r
-                       'PreAddItemForm',\r
-                       array(\r
-                               'contents' => &$contents,\r
-                               'blog'     => &$this->blog\r
-                       )\r
-               );\r
-\r
-               $this->createForm($contents);\r
-       }\r
-\r
-\r
-       /**\r
-        * Creates an "edit item" form for a given type of page\r
-        * @param string $type 'admin' or 'bookmarklet'\r
-        * @param array $contents\r
-        */\r
-       public function createEditForm($type, $contents)\r
-       {\r
-\r
-               // begin if: the $type is not in the allowed types array\r
-               if ( !in_array($type, $this->allowed_types) )\r
-               {\r
-                       return;\r
-               } // end if\r
-\r
-               $this->type = $type;\r
-               $this->method = 'edit';\r
-               $this->createForm($contents);\r
-       }\r
-\r
-\r
-       /**\r
-        * (private) creates a form for a given type of page\r
-        * @param array $contents\r
-        */\r
-       private function createForm($contents)\r
-       {\r
-               # save contents\r
-               $this->variables = $contents;\r
-\r
-               # get template to use\r
-               $template = $this->getTemplateFor($this->type);\r
-\r
-               # use the PARSER engine to parse that template\r
-               $parser = new Parser($this->actions, $this);\r
-               $parser->parse($template);\r
-       }\r
-\r
-\r
-       /**\r
-        * Returns an appropriate template\r
-        * @param string $type\r
-        */\r
-       private function getTemplateFor($type)\r
-       {\r
-               global $DIR_LIBS;\r
-\r
-               $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';\r
-\r
-               // begin if: file doesn't exist\r
-               if ( !file_exists($filename) )\r
-               {\r
-                       return '';\r
-               } // end if\r
-\r
-               $filesize = filesize($filename);\r
-\r
-               // begin if: filesize is LTE zero\r
-               if ( $filesize <= 0 )\r
-               {\r
-                       return '';\r
-               } // end if\r
-\r
-               # read file and return it\r
-               $fd = fopen ($filename, 'r');\r
-               $contents = fread ($fd, $filesize);\r
-               fclose ($fd);\r
-\r
-               return $contents;\r
-       }\r
-\r
-\r
-       /**\r
-        * Create category dropdown box\r
-        * @param int $start_index\r
-        */\r
-       function parse_categories($start_index = 0)\r
-       {\r
-\r
-               // begin if: catid variable is set; use it to select the category\r
-               if ( $this->variables['catid'] )\r
-               {\r
-                       $category_id = $this->variables['catid'];\r
-               }\r
-               // else: get the default category\r
-               else\r
-               {\r
-                       $category_id = $this->blog->getDefaultCategory();\r
-               } // end if\r
-\r
-               Admin::selectBlogCategory('catid', $category_id, $start_index, 1, $this->blog->getID());\r
-       }\r
-\r
-\r
-       /**\r
-        * Displays the blog ID\r
-        */\r
-       function parse_blogid()\r
-       {\r
-               echo $this->blog->getID();\r
-       }\r
-\r
-\r
-       /**\r
-        * Displays the blog name\r
-        */\r
-       function parse_blogname()\r
-       {\r
-               echo $this->blog->getName();\r
-       }\r
-\r
-\r
-       /**\r
-        * Displays the blog link\r
-        */\r
-       function parse_bloglink()\r
-       {\r
-               echo '<a href="', Entity::hsc($this->blog->getURL()), '">', Entity::hsc($this->blog->getName()), '</a>';\r
-       }\r
-\r
-\r
-       /**\r
-        * Displays the author's name\r
-        */\r
-       function parse_authorname()\r
-       {\r
-               // don't use on add item?\r
-               global $member;\r
-               echo $member->getDisplayName();\r
-       }\r
-\r
-\r
-       /**\r
-        * Displays the title\r
-        */\r
-       function parse_title()\r
-       {\r
-               echo $this->contents['title'];\r
-       }\r
-\r
-\r
-       /**\r
-        * Indicates the start of a conditional block of data. It will be added to\r
-        * the output only if the blogsetting with the given name equals the\r
-        * given value (default for value = 1 = true)\r
-        *\r
-        * the name of the blogsetting is the column name in the nucleus_blog table\r
-        *\r
-        * the conditional block ends with an <endif> var\r
-        */\r
-       function parse_ifblogsetting($name,$value=1)\r
-       {\r
-               $this->_addIfCondition(($this->blog->getSetting($name) == $value));\r
-       }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       function parse_ifitemproperty($name,$value=1)\r
-       {\r
-               $this->_addIfCondition(($this->variables[$name] == $value));\r
-       }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       function parse_ifautosave($name,$value=1)\r
-       {\r
-               global $member;\r
-               $this->_addIfCondition($member->getAutosave() == $value);\r
-       }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       function parse_helplink($topic)\r
-       {\r
-               help($topic);\r
-       }\r
-\r
-\r
-       /**\r
-        * for future items\r
-        */\r
-       function parse_currenttime($what)\r
-       {\r
-               $nu = getdate($this->blog->getCorrectTime());\r
-               echo $nu[$what];\r
-       }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       // date change on edit item\r
-       function parse_itemtime($what)\r
-       {\r
-               $itemtime = getdate($this->variables['timestamp']);\r
-               echo $itemtime[$what];\r
-       }\r
-\r
-\r
-       /**\r
-        * some init stuff for all forms\r
-        */\r
-       function parse_init()\r
-       {\r
-               $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';\r
-               $this->blog->insertJavaScriptInfo($authorid);\r
-       }\r
-\r
-\r
-       /**\r
-        * on bookmarklets only: insert extra html header information (by plugins)\r
-        */\r
-       function parse_extrahead()\r
-       {\r
-               global $manager;\r
-\r
-               $extrahead = '';\r
-\r
-               $manager->notify(\r
-                       'BookmarkletExtraHead',\r
-                       array(\r
-                               'extrahead' => &$extrahead\r
-                       )\r
-               );\r
-\r
-               echo $extrahead;\r
-       }\r
-\r
-\r
-       /**\r
-        * inserts some localized text\r
-        */\r
-       function parse_text($which)\r
-       {\r
-               // constant($which) only available from 4.0.4 :(\r
-               if (defined($which)) {\r
-                       eval("echo $which;");\r
-               } else {\r
-                       echo $which;    // this way we see where definitions are missing\r
-               }\r
-\r
-       }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       function parse_contents($which)\r
-       {\r
-               if (!isset($this->variables[$which])) $this->variables[$which] = '';\r
-               echo Entity::hsc($this->variables[$which]);\r
-       }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       function parse_checkedonval($value, $name)\r
-       {\r
-               if (!isset($this->variables[$name])) $this->variables[$name] = '';\r
-               if ($this->variables[$name] == $value)\r
-                       echo "checked='checked'";\r
+               return;\r
        }\r
-\r
-\r
-       /**\r
-        * extra javascript for input and textarea fields\r
-        */\r
-       function parse_jsinput($which)\r
-       {\r
-               global $CONF, $member;\r
-\r
-               $attributes  = " name=\"{$which}\"";\r
-               $attributes .= " id=\"input{$which}\"";\r
-\r
-               if ($CONF['DisableJsTools'] != 1) {\r
-                       $attributes .= ' onclick="storeCaret(this);"';\r
-                       $attributes .= ' onselect="storeCaret(this);"';\r
-                       if ($member->getAutosave()) {\r
-                               $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}'); doMonitor();\"";\r
-                       } else {\r
-                               $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}');\"";\r
-                       }\r
-               }\r
-               else {\r
-                       if ($CONF['DisableJsTools'] == 0) {\r
-                               $attributes .= ' onkeypress="shortCuts();"';\r
-                       }\r
-                       if ($member->getAutosave()) {\r
-                               $attributes .= ' onkeyup="doMonitor();"';\r
-                       }\r
-               }\r
-               echo $attributes;\r
-       }\r
-\r
-\r
-       /**\r
-        * shows the javascript button bar\r
-        */\r
-       function parse_jsbuttonbar($extrabuttons = "")\r
-       {\r
-               global $CONF;\r
-               switch($CONF['DisableJsTools']) {\r
-\r
-                       case "0":\r
-                               echo '<div class="jsbuttonbar">';\r
-\r
-                                       $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");\r
-                                       $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");\r
-                                       $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");\r
-                                       $this->_jsbuttonspacer();\r
-                                       $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");\r
-                                       $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");\r
-                                       $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");\r
-                                       $this->_jsbuttonspacer();\r
-                                       $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);\r
-                                       $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);\r
-                                       $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);\r
-                                       $this->_jsbuttonspacer();\r
-                                       $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);\r
-                                       $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);\r
-\r
-\r
-                                       if ($extrabuttons) {\r
-                                               $btns = preg_split('#\+#',$extrabuttons);\r
-                                               $this->_jsbuttonspacer();\r
-                                               foreach ($btns as $button) {\r
-                                                       switch($button) {\r
-                                                               case "media":\r
-                                                                       $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT .   " (Ctrl + Shift + M)");\r
-                                                                       break;\r
-                                                               case "preview":\r
-                                                                       $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);\r
-                                                                       break;\r
-                                                       }\r
-                                               }\r
-                                       }\r
-\r
-                               echo '</div>';\r
-\r
-                               break;\r
-                       case "2":\r
-                               echo '<div class="jsbuttonbar">';\r
-\r
-                                       $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT);\r
-                                       $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT);\r
-                                       $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT);\r
-                                       $this->_jsbuttonspacer();\r
-                                       $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);\r
-                                       $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);\r
-                                       $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);\r
-                                       $this->_jsbuttonspacer();\r
-                                       $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);\r
-                                       $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);\r
-\r
-\r
-                                       if ($extrabuttons) {\r
-                                               $btns = preg_split('#\+#',$extrabuttons);\r
-                                               $this->_jsbuttonspacer();\r
-                                               foreach ($btns as $button) {\r
-                                                       switch($button) {\r
-                                                               case "media":\r
-                                                                       $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT);\r
-                                                                       break;\r
-                                                       }\r
-                                               }\r
-                                       }\r
-\r
-                               echo '</div>';\r
-\r
-                               break;\r
-               }\r
-       }\r
-\r
-\r
-       /**\r
-        * Allows plugins to add their own custom fields\r
-        */\r
-       function parse_pluginextras()\r
-       {\r
-               global $manager;\r
-\r
-               switch ($this->method) {\r
-                       case 'add':\r
-                               $manager->notify('AddItemFormExtras',\r
-                                               array(\r
-                                                       'blog' => &$this->blog\r
-                                               )\r
-                               );\r
-                               break;\r
-                       case 'edit':\r
-                               $manager->notify('EditItemFormExtras',\r
-                                               array(\r
-                                                       'variables' => $this->variables,\r
-                                                       'blog' => &$this->blog,\r
-                                                       'itemid' => $this->variables['itemid']\r
-                                               )\r
-                               );\r
-                               break;\r
-               }\r
-       }\r
-\r
-\r
-       /**\r
-        * Adds the itemOptions of a plugin to a page\r
-        * @author TeRanEX\r
-        */\r
-       function parse_itemoptions()\r
-       {\r
-               global $itemid;\r
-               Admin::_insertPluginOptions('item', $itemid);\r
-       }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       function parse_ticket()\r
-       {\r
-               global $manager;\r
-               $manager->addTicketHidden();\r
-       }\r
-\r
-\r
-       /**\r
-        * convenience method\r
-        */\r
-       function _jsbutton($type, $code, $tooltip)\r
-       {\r
-       ?>\r
-                       <span class="jsbutton"\r
-                               onmouseover="BtnHighlight(this);"\r
-                               onmouseout="BtnNormal(this);"\r
-                               onclick="<?php echo $code?>" >\r
-                               <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" title="<?php echo $tooltip?>" width="16" height="16"/>\r
-                       </span>\r
-       <?php   }\r
-\r
-\r
-       /**\r
-        *\r
-        */\r
-       function _jsbuttonspacer()\r
-       {\r
-               echo '<span class="jsbuttonspacer"></span>';\r
-       }\r
-\r
 }\r