OSDN Git Service

added NucleusJP keyword
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / PAGEFACTORY.php
1 <?php\r
2 /**\r
3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
4   * Copyright (C) 2002-2005 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   * $Id: PAGEFACTORY.php,v 1.4 2005-03-16 07:53:18 kimitake Exp $\r
13   * $NucleusJP$\r
14   */\r
15 \r
16 /**\r
17  * The formfactory class can be used to insert add/edit item forms into \r
18  * admin area, bookmarklet, skins or any other places where such a form\r
19  * might be needed\r
20  */\r
21 class PAGEFACTORY extends BaseActions {\r
22 \r
23         // ref to the blog object for which an add:edit form is created\r
24         var $blog;\r
25         \r
26         // allowed actions (for parser)\r
27         var $actions;\r
28         \r
29         // allowed types of forms (bookmarklet/admin)\r
30         var $allowedTypes;\r
31         var $type;              // one of the types in $allowedTypes\r
32         \r
33         // 'add' or 'edit'\r
34         var $method;\r
35         \r
36         // info to fill out in the form (e.g. catid, itemid, ...)\r
37         var $variables;\r
38 \r
39         /**\r
40          * creates a new PAGEFACTORY object\r
41          */\r
42         function PAGEFACTORY($blogid) {\r
43                 // call constructor of superclass first\r
44                 $this->BaseActions();                   \r
45                 \r
46                 global $manager;\r
47                 $this->blog =& $manager->getBlog($blogid);\r
48                 \r
49                 // TODO: move the definition of actions to the createXForm \r
50                 // methods\r
51                 $this->actions = Array(\r
52                         'actionurl', \r
53                         'title',\r
54                         'body',\r
55                         'more',\r
56                         'blogid',\r
57                         'bloglink',\r
58                         'blogname',\r
59                         'authorname',\r
60                         'checkedonval',\r
61                         'helplink',\r
62                         'currenttime',\r
63                         'itemtime',\r
64                         'init',\r
65                         'text',\r
66                         'jsinput',\r
67                         'jsbuttonbar',\r
68                         'categories',\r
69                         'contents',\r
70                         'ifblogsetting',\r
71                         'ifitemproperty',\r
72                         'else',\r
73                         'endif',\r
74                         'pluginextras',\r
75                         'itemoptions',\r
76                         'extrahead',\r
77                         'ticket'\r
78                 );\r
79                 \r
80                 // TODO: maybe add 'skin' later on?\r
81                 // TODO: maybe add other pages from admin area\r
82                 $this->allowedTypes = Array('bookmarklet','admin');     \r
83         }\r
84 \r
85         /**\r
86          * creates a "add item" form for a given type of page\r
87          *\r
88          * @param type\r
89          *              'admin' or 'bookmarklet' \r
90          */\r
91         function createAddForm($type, $contents = array()) {\r
92                 if (!in_array($type, $this->allowedTypes))\r
93                         return;\r
94                 $this->type = $type;\r
95                 $this->method = 'add';\r
96                 \r
97                 global $manager;\r
98                 $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));\r
99                 \r
100                 $this->createForm($contents);\r
101         }\r
102         \r
103         /**\r
104          * creates a "add item" form for a given type of page\r
105          *\r
106          * @param type\r
107          *              'admin' or 'bookmarklet' \r
108          * @param contents\r
109          *              An associative array\r
110          *                      'author' => author\r
111          *                      '' => \r
112          */\r
113         function createEditForm($type, $contents) {\r
114                 if (!in_array($type, $this->allowedTypes))\r
115                         return;\r
116                 $this->type = $type;\r
117                 $this->method = 'edit';\r
118                 $this->createForm($contents);\r
119         }\r
120         \r
121         /**\r
122          * (private) creates a form for a given type of page\r
123          */\r
124         function createForm($contents) {\r
125                 // save contents\r
126                 $this->variables = $contents;\r
127                 \r
128                 // get template to use\r
129                 $template = $this->getTemplateFor($this->type);\r
130                 \r
131                 // use the PARSER engine to parse that template\r
132                 $parser =& new PARSER($this->actions, $this);\r
133                 $parser->parse($template);\r
134         }\r
135         \r
136         /**\r
137          * returns an appropriate template\r
138          */\r
139         function getTemplateFor($type) {\r
140                 global $DIR_LIBS;\r
141                 \r
142                 $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';\r
143                 \r
144                 if (!file_exists($filename)) \r
145                         return '';\r
146 \r
147                 $fsize = filesize($filename);\r
148                 if ($fsize <= 0)\r
149                         return '';\r
150                         \r
151                 // read file and return it\r
152                 $fd = fopen ($filename, 'r');\r
153                 $contents = fread ($fd, $fsize);\r
154                 fclose ($fd);\r
155                 \r
156                 return $contents;\r
157                 \r
158         }\r
159         \r
160         // create category dropdown box\r
161         function parse_categories($startidx = 0) {\r
162                         if ($this->variables['catid']) \r
163                                 $catid = $this->variables['catid'];                             // on edit item\r
164                         else\r
165                                 $catid = $this->blog->getDefaultCategory();             // on add item\r
166                         \r
167                         ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());\r
168         }\r
169         \r
170         function parse_blogid() {\r
171                 echo $this->blog->getID();\r
172         }\r
173         \r
174         function parse_blogname() {\r
175                 echo $this->blog->getName();\r
176         }\r
177         \r
178         function parse_bloglink() {\r
179                 echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.$this->blog->getName().'</a>';\r
180         }\r
181         \r
182         function parse_authorname() {\r
183                 // don't use on add item?\r
184                 global $member;\r
185                 echo $member->getDisplayName();\r
186         }\r
187 \r
188         function parse_title() {\r
189                 echo $this->contents['title'];\r
190         }\r
191 \r
192         /**\r
193          * Indicates the start of a conditional block of data. It will be added to\r
194          * the output only if the blogsetting with the given name equals the \r
195          * given value (default for value = 1 = true)\r
196          *\r
197          * the name of the blogsetting is the column name in the nucleus_blog table\r
198          *\r
199          * the conditional block ends with an <endif> var\r
200          */\r
201         function parse_ifblogsetting($name,$value=1) {\r
202                 $this->_addIfCondition(($this->blog->getSetting($name) == $value));\r
203         }\r
204         \r
205         function parse_ifitemproperty($name,$value=1) {\r
206                 $this->_addIfCondition(($this->variables[$name] == $value));\r
207         }\r
208         \r
209         function parse_helplink($topic) {\r
210                 help($topic);\r
211         }\r
212         \r
213         // for future items\r
214         function parse_currenttime($what) {\r
215                 $nu = getdate($this->blog->getCorrectTime());\r
216                 echo $nu[$what];\r
217         }\r
218         \r
219         // date change on edit item\r
220         function parse_itemtime($what) {\r
221                 $itemtime = getdate($this->variables['timestamp']);\r
222                 echo $itemtime[$what];\r
223         }\r
224         \r
225         // some init stuff for all forms\r
226         function parse_init() {\r
227                 $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';\r
228                 $this->blog->insertJavaScriptInfo($authorid);           \r
229         }\r
230         \r
231         // on bookmarklets only: insert extra html header information (by plugins)\r
232         function parse_extrahead() {\r
233                 global $manager;\r
234                 \r
235                 $extrahead = '';\r
236                 \r
237                 $manager->notify(\r
238                         'BookmarkletExtraHead',\r
239                         array(\r
240                                 'extrahead' => &$extrahead\r
241                         )\r
242                 );\r
243                 \r
244                 echo $extrahead;\r
245         }\r
246         \r
247         // inserts some localized text\r
248         function parse_text($which) {\r
249                 // constant($which) only available from 4.0.4 :(\r
250                 if (defined($which)) {  \r
251                         eval("echo $which;");\r
252                 } else {\r
253                         echo $which;    // this way we see where definitions are missing\r
254                 }\r
255                 \r
256         }\r
257         \r
258         function parse_contents($which) {\r
259                 echo htmlspecialchars($this->variables[$which]);\r
260         }\r
261         \r
262         function parse_checkedonval($value, $name) {\r
263                 if ($this->variables[$name] == $value)\r
264                         echo "checked='checked'";\r
265         }\r
266         \r
267         // extra javascript for input and textarea fields\r
268         function parse_jsinput($which) {\r
269                 global $CONF;\r
270         ?>\r
271                         name="<?php echo $which?>" \r
272                         id="input<?php echo $which?>" \r
273         <?php\r
274                 if ($CONF['DisableJsTools'] != 1) {\r
275         ?>\r
276                         onkeyup="storeCaret(this); updPreview('<?php echo $which?>');"\r
277                         onclick="storeCaret(this);"\r
278                         onselect="storeCaret(this);" \r
279 \r
280         <?php           \r
281                 } \r
282                 \r
283                 if ($CONF['DisableJsTools'] == 0) {\r
284         ?>\r
285                     onkeypress="shortCuts();"                   \r
286         <?php           }\r
287         }\r
288         \r
289         // shows the javascript button bar\r
290         function parse_jsbuttonbar($extrabuttons = "") {\r
291                 global $CONF;\r
292                 switch($CONF['DisableJsTools']) {\r
293 \r
294                         case "0":       \r
295                                 echo '<div class="jsbuttonbar">';\r
296 \r
297                                         $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");\r
298                                         $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");\r
299                                         $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");\r
300                                         $this->_jsbuttonspacer();\r
301                                         $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");\r
302                                         $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");\r
303                                         $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");\r
304                                         $this->_jsbuttonspacer();                                       \r
305                                         $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);\r
306                                         $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);\r
307                                         $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);\r
308                                         $this->_jsbuttonspacer();                                       \r
309                                         $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);\r
310                                         $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);\r
311 \r
312                                 \r
313                                         if ($extrabuttons) {\r
314                                                 $btns = explode('+',$extrabuttons);\r
315                                                 $this->_jsbuttonspacer();\r
316                                                 foreach ($btns as $button) {\r
317                                                         switch($button) {\r
318                                                                 case "media":\r
319                                                                         $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT .   " (Ctrl + Shift + M)");                                                 \r
320                                                                         break;\r
321                                                                 case "preview":\r
322                                                                         $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);\r
323                                                                         break;\r
324                                                         }\r
325                                                 }\r
326                                         } \r
327                                         \r
328                                 echo '</div>';\r
329                                 \r
330                                 break;\r
331                         case "2":\r
332                                 echo '<div class="jsbuttonbar">';\r
333 \r
334                                         $this->_jsbutton('bold',"boldThis()",'');\r
335                                         $this->_jsbutton('italic',"italicThis()",'');\r
336                                         $this->_jsbutton('link',"ahrefThis()",'');\r
337                                         $this->_jsbuttonspacer();                                                                               \r
338                                         $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);\r
339                                         $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);\r
340                                         $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);\r
341                                         $this->_jsbuttonspacer();                                       \r
342                                         $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);\r
343                                         $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);\r
344                                         \r
345 \r
346                                         if ($extrabuttons) {\r
347                                                 $btns = explode('+',$extrabuttons);\r
348                                                 $this->_jsbuttonspacer();\r
349                                                 foreach ($btns as $button) {\r
350                                                         switch($button) {\r
351                                                                 case "media":\r
352                                                                         $this->_jsbutton('media',"addMedia()",'');                                                      \r
353                                                                         break;\r
354                                                         }\r
355                                                 }\r
356                                         } \r
357                                         \r
358                                 echo '</div>';\r
359                                 \r
360                                 break;                  \r
361                 }\r
362         }\r
363         \r
364         /**\r
365          * Allows plugins to add their own custom fields\r
366          */\r
367         function parse_pluginextras() {\r
368                 global $manager;\r
369                         \r
370                 switch ($this->method) {\r
371                         case 'add':\r
372                                 $manager->notify('AddItemFormExtras', \r
373                                                 array(\r
374                                                         'blog' => &$this->blog\r
375                                                 )\r
376                                 );\r
377                                 break;\r
378                         case 'edit':\r
379                                 $manager->notify('EditItemFormExtras', \r
380                                                 array(\r
381                                                         'variables' => $this->variables,\r
382                                                         'blog' => &$this->blog,\r
383                                                         'itemid' => $this->variables['itemid']\r
384                                                 )\r
385                                 );\r
386                                 break;\r
387                 }\r
388         }\r
389         \r
390         /**\r
391          * Adds the itemOptions of a plugin to a page\r
392          * @author TeRanEX\r
393          */\r
394     function parse_itemoptions() {\r
395                 global $itemid;\r
396                 ADMIN::_insertPluginOptions('item', $itemid);\r
397     }\r
398     \r
399     function parse_ticket() {\r
400         global $manager;\r
401         $manager->addTicketHidden();\r
402     }\r
403         \r
404         /**\r
405          * convenience method\r
406          */\r
407         function _jsbutton($type, $code ,$tooltip) {\r
408         ?>\r
409                         <span class="jsbutton"\r
410                                 onmouseover="BtnHighlight(this);" \r
411                                 onmouseout="BtnNormal(this);" \r
412                                 onclick="<?php echo $code?>" >                  \r
413                                 <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" width="16" height="16"/>\r
414                         </span>                         \r
415         <?php   }\r
416         \r
417         function _jsbuttonspacer() {\r
418                 echo '<span class="jsbuttonspacer"></span>';\r
419         }\r
420         \r
421 }\r
422  \r
423  ?>\r