3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * @license http://nucleuscms.org/license.txt GNU General Public License
14 * @copyright Copyright (C) 2002-2009 The Nucleus Group
15 * @version $Id: PAGEFACTORY.php 1626 2012-01-09 15:46:54Z sakamocchi $
19 * The formfactory class can be used to insert add/edit item forms into
20 * admin area, bookmarklet, skins or any other places where such a form
23 class PAGEFACTORY extends BaseActions
27 * Reference to the blog object for which an add:edit form is created
32 * Allowed actions (for parser)
37 * Allowed types of forms (bookmarklet/admin)
39 private $allowed_types;
42 * One of the types in $allowed_types
52 * Info to fill out in the form (e.g. catid, itemid, ...)
58 * Creates a new PAGEFACTORY object
61 public function __construct($blog_id)
63 # Call constructor of superclass first
64 parent::__construct();
67 $this->blog =& $manager->getBlog($blog_id);
69 // TODO: move the definition of actions to the createXForm methods
70 $this->actions = array(
102 # TODO: maybe add 'skin' later on?
103 # TODO: maybe add other pages from admin area
104 $this->allowed_types = array('bookmarklet', 'admin');
109 * Creates an "add item" form for a given type of page
110 * @param string $type - 'admin' or 'bookmarklet'
111 * @param array $contents
113 public function createAddForm($type, $contents = array())
116 // begin if: the $type is not in the allowed types array
117 if ( !in_array($type, $this->allowed_types) )
123 $this->method = 'add';
126 $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));
128 $this->createForm($contents);
133 * Creates an "edit item" form for a given type of page
134 * @param string $type 'admin' or 'bookmarklet'
135 * @param array $contents
137 public function createEditForm($type, $contents)
140 // begin if: the $type is not in the allowed types array
141 if ( !in_array($type, $this->allowed_types) )
147 $this->method = 'edit';
148 $this->createForm($contents);
153 * (private) creates a form for a given type of page
154 * @param array $contents
156 private function createForm($contents)
159 $this->variables = $contents;
161 # get template to use
162 $template = $this->getTemplateFor($this->type);
164 # use the PARSER engine to parse that template
165 $parser = new PARSER($this->actions, $this);
166 $parser->parse($template);
171 * Returns an appropriate template
172 * @param string $type
174 private function getTemplateFor($type)
178 $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';
180 // begin if: file doesn't exist
181 if ( !file_exists($filename) )
186 $filesize = filesize($filename);
188 // begin if: filesize is LTE zero
189 if ( $filesize <= 0 )
194 # read file and return it
195 $fd = fopen ($filename, 'r');
196 $contents = fread ($fd, $filesize);
204 * Create category dropdown box
205 * @param int $start_index
207 function parse_categories($start_index = 0)
210 // begin if: catid variable is set; use it to select the category
211 if ( $this->variables['catid'] )
213 $category_id = $this->variables['catid'];
215 // else: get the default category
218 $category_id = $this->blog->getDefaultCategory();
221 ADMIN::selectBlogCategory('catid', $category_id, $start_index, 1, $this->blog->getID());
226 * Displays the blog ID
228 function parse_blogid()
230 echo $this->blog->getID();
235 * Displays the blog name
237 function parse_blogname()
239 echo $this->blog->getName();
244 * Displays the blog link
246 function parse_bloglink()
248 echo '<a href="', ENTITY::hsc($this->blog->getURL()), '">', ENTITY::hsc($this->blog->getName()), '</a>';
253 * Displays the author's name
255 function parse_authorname()
257 // don't use on add item?
259 echo $member->getDisplayName();
266 function parse_title()
268 echo $this->contents['title'];
273 * Indicates the start of a conditional block of data. It will be added to
274 * the output only if the blogsetting with the given name equals the
275 * given value (default for value = 1 = true)
277 * the name of the blogsetting is the column name in the nucleus_blog table
279 * the conditional block ends with an <endif> var
281 function parse_ifblogsetting($name,$value=1)
283 $this->_addIfCondition(($this->blog->getSetting($name) == $value));
290 function parse_ifitemproperty($name,$value=1)
292 $this->_addIfCondition(($this->variables[$name] == $value));
299 function parse_ifautosave($name,$value=1)
302 $this->_addIfCondition($member->getAutosave() == $value);
309 function parse_helplink($topic)
318 function parse_currenttime($what)
320 $nu = getdate($this->blog->getCorrectTime());
328 // date change on edit item
329 function parse_itemtime($what)
331 $itemtime = getdate($this->variables['timestamp']);
332 echo $itemtime[$what];
337 * some init stuff for all forms
339 function parse_init()
341 $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
342 $this->blog->insertJavaScriptInfo($authorid);
347 * on bookmarklets only: insert extra html header information (by plugins)
349 function parse_extrahead()
356 'BookmarkletExtraHead',
358 'extrahead' => &$extrahead
367 * inserts some localized text
369 function parse_text($which)
371 // constant($which) only available from 4.0.4 :(
372 if (defined($which)) {
373 eval("echo $which;");
375 echo $which; // this way we see where definitions are missing
384 function parse_contents($which)
386 if (!isset($this->variables[$which])) $this->variables[$which] = '';
387 echo ENTITY::hsc($this->variables[$which]);
394 function parse_checkedonval($value, $name)
396 if (!isset($this->variables[$name])) $this->variables[$name] = '';
397 if ($this->variables[$name] == $value)
398 echo "checked='checked'";
403 * extra javascript for input and textarea fields
405 function parse_jsinput($which)
407 global $CONF, $member;
409 $attributes = " name=\"{$which}\"";
410 $attributes .= " id=\"input{$which}\"";
412 if ($CONF['DisableJsTools'] != 1) {
413 $attributes .= ' onclick="storeCaret(this);"';
414 $attributes .= ' onselect="storeCaret(this);"';
415 if ($member->getAutosave()) {
416 $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}'); doMonitor();\"";
418 $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}');\"";
422 if ($CONF['DisableJsTools'] == 0) {
423 $attributes .= ' onkeypress="shortCuts();"';
425 if ($member->getAutosave()) {
426 $attributes .= ' onkeyup="doMonitor();"';
434 * shows the javascript button bar
436 function parse_jsbuttonbar($extrabuttons = "")
439 switch($CONF['DisableJsTools']) {
442 echo '<div class="jsbuttonbar">';
444 $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");
445 $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");
446 $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");
447 $this->_jsbuttonspacer();
448 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
449 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
450 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
451 $this->_jsbuttonspacer();
452 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
453 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
454 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
455 $this->_jsbuttonspacer();
456 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
457 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
461 $btns = i18n::explode('+',$extrabuttons);
462 $this->_jsbuttonspacer();
463 foreach ($btns as $button) {
466 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT . " (Ctrl + Shift + M)");
469 $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
479 echo '<div class="jsbuttonbar">';
481 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT);
482 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT);
483 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT);
484 $this->_jsbuttonspacer();
485 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
486 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
487 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
488 $this->_jsbuttonspacer();
489 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
490 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
494 $btns = i18n::explode('+',$extrabuttons);
495 $this->_jsbuttonspacer();
496 foreach ($btns as $button) {
499 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT);
513 * Allows plugins to add their own custom fields
515 function parse_pluginextras()
519 switch ($this->method) {
521 $manager->notify('AddItemFormExtras',
523 'blog' => &$this->blog
528 $manager->notify('EditItemFormExtras',
530 'variables' => $this->variables,
531 'blog' => &$this->blog,
532 'itemid' => $this->variables['itemid']
541 * Adds the itemOptions of a plugin to a page
544 function parse_itemoptions()
547 ADMIN::_insertPluginOptions('item', $itemid);
554 function parse_ticket()
557 $manager->addTicketHidden();
564 function _jsbutton($type, $code, $tooltip)
567 <span class="jsbutton"
568 onmouseover="BtnHighlight(this);"
569 onmouseout="BtnNormal(this);"
570 onclick="<?php echo $code?>" >
571 <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" title="<?php echo $tooltip?>" width="16" height="16"/>
579 function _jsbuttonspacer()
581 echo '<span class="jsbuttonspacer"></span>';