OSDN Git Service

Merge branch 'skinnable-master' of ssh://shizuki@git.sourceforge.jp/gitroot/nucleus...
[nucleus-jp/nucleus-next.git] / nucleus / libs / PAGEFACTORY.php
1 <?php\r
2 /*\r
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
4  * Copyright (C) 2002-2012 The Nucleus Group\r
5  *\r
6  * This program is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU General Public License\r
8  * as published by the Free Software Foundation; either version 2\r
9  * of the License, or (at your option) any later version.\r
10  * (see nucleus/documentation/index.html#license for more info)\r
11  */\r
12 /**\r
13  * @license http://nucleuscms.org/license.txt GNU General Public License\r
14  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
15  * @version $Id: PAGEFACTORY.php 1626 2012-01-09 15:46:54Z sakamocchi $\r
16  */\r
17 \r
18 /**\r
19  * The formfactory class can be used to insert add/edit item forms into\r
20  * admin area, bookmarklet, skins or any other places where such a form\r
21  * might be needed\r
22  */\r
23 class PageFactory extends BaseActions\r
24 {\r
25         /**\r
26          * PageFactory::$blog\r
27          * Reference to the blog object for which an add:edit form is created\r
28          */\r
29         private $blog;\r
30         \r
31         /**\r
32          * PageFactory::$allowed_types\r
33          * Allowed types of forms (bookmarklet/admin)\r
34          */\r
35         private $allowed_types;\r
36         \r
37         /**\r
38          * PageFactory::$type\r
39          * One of the types in $allowed_types\r
40          */\r
41         private $type;\r
42         \r
43         /**\r
44          * PageFactory::$method\r
45          * 'add' or 'edit'\r
46          */\r
47         private $method;\r
48         \r
49         /**\r
50          * PageFactory::$variables\r
51          * Info to fill out in the form (e.g. catid, itemid, ...)\r
52          */\r
53         private $variables;\r
54         \r
55         /**\r
56          * PageFactory::$actions\r
57          * Allowed actions (for parser)\r
58          */\r
59         // TODO: move the definition of actions to the createXForm methods\r
60         static private $defined_actions = array(\r
61                 'actionurl',\r
62                 'title',\r
63                 'body',\r
64                 'more',\r
65                 'blogid',\r
66                 'bloglink',\r
67                 'blogname',\r
68                 'authorname',\r
69                 'checkedonval',\r
70                 'helplink',\r
71                 'currenttime',\r
72                 'itemtime',\r
73                 'init',\r
74                 'text',\r
75                 'jsinput',\r
76                 'jsbuttonbar',\r
77                 'categories',\r
78                 'contents',\r
79                 'ifblogsetting',\r
80                 'ifitemproperty',\r
81                 'else',\r
82                 'endif',\r
83                 'pluginextras',\r
84                 'itemoptions',\r
85                 'extrahead',\r
86                 'ticket',\r
87                 'autosave',\r
88                 'autosaveinfo',\r
89                 'ifautosave'\r
90         );\r
91         \r
92         /**\r
93          * Creates a new PAGEFACTORY object\r
94          * @param int $blog_id\r
95          */\r
96         public function __construct($type = '', $blogid, $skin = '')\r
97         {\r
98                 global $manager;\r
99                 # Call constructor of superclass first\r
100                 parent::__construct();\r
101                 \r
102                 if ( !$blogid && $type == 'itemedit' )\r
103                 {\r
104                         $itemid = intRequestVar('itemid');\r
105                         $blogid =  getBlogIDFromItemID($itemid);\r
106                         $item   = &$manager->getItem($itemid, 1, 1);\r
107                         $manager->notify('PrepareItemForEdit', array('item' => &$item));\r
108                 }\r
109                 \r
110                 $this->blog =& $manager->getBlog($blogid);\r
111                 \r
112                 if ( $item && $this->blog->convertBreaks() && $type == 'itemedit' )\r
113                 {\r
114                         $item['body'] = removeBreaks($item['body']);\r
115                         $item['more'] = removeBreaks($item['more']);\r
116                 }\r
117                 \r
118                 $contents = array();\r
119                 if ( $type == 'itemedit' )\r
120                 {\r
121                         $contents = $item;\r
122                 }\r
123                 elseif ( $type == 'createitem' )\r
124                 {\r
125                         $data = array(\r
126                                 'contents' => &$contents,\r
127                                 'blog'     => &$this->blog\r
128                         );\r
129                         $manager->notify('PreAddItemForm', $data);\r
130                 }\r
131                 $this->variables = $contents;\r
132                 \r
133                 $skin = new Skin($skin_id, 'AdminActions', 'AdminSkin');\r
134                 $allowed_action_types = $skin->getAllowedActionsForType($type);\r
135                 $this->actions = array_merge($skinActions, $formActions);\r
136                 return;\r
137         }\r
138 }\r