3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2007 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-2007 The Nucleus Group
15 * @version $Id: PAGEFACTORY.php,v 1.7 2007-02-04 06:28:46 kimitake Exp $
16 * $NucleusJP: PAGEFACTORY.php,v 1.6 2006/07/12 07:11:47 kimitake Exp $
20 * The formfactory class can be used to insert add/edit item forms into
21 * admin area, bookmarklet, skins or any other places where such a form
24 class PAGEFACTORY extends BaseActions {
26 // ref to the blog object for which an add:edit form is created
29 // allowed actions (for parser)
32 // allowed types of forms (bookmarklet/admin)
34 var $type; // one of the types in $allowedTypes
39 // info to fill out in the form (e.g. catid, itemid, ...)
43 * creates a new PAGEFACTORY object
45 function PAGEFACTORY($blogid) {
46 // call constructor of superclass first
50 $this->blog =& $manager->getBlog($blogid);
52 // TODO: move the definition of actions to the createXForm
54 $this->actions = Array(
83 // TODO: maybe add 'skin' later on?
84 // TODO: maybe add other pages from admin area
85 $this->allowedTypes = Array('bookmarklet','admin');
89 * creates a "add item" form for a given type of page
92 * 'admin' or 'bookmarklet'
94 function createAddForm($type, $contents = array()) {
95 if (!in_array($type, $this->allowedTypes))
98 $this->method = 'add';
101 $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));
103 $this->createForm($contents);
107 * creates a "add item" form for a given type of page
110 * 'admin' or 'bookmarklet'
112 * An associative array
116 function createEditForm($type, $contents) {
117 if (!in_array($type, $this->allowedTypes))
120 $this->method = 'edit';
121 $this->createForm($contents);
125 * (private) creates a form for a given type of page
127 function createForm($contents) {
129 $this->variables = $contents;
131 // get template to use
132 $template = $this->getTemplateFor($this->type);
134 // use the PARSER engine to parse that template
135 $parser =& new PARSER($this->actions, $this);
136 $parser->parse($template);
140 * returns an appropriate template
142 function getTemplateFor($type) {
145 $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';
147 if (!file_exists($filename))
150 $fsize = filesize($filename);
154 // read file and return it
155 $fd = fopen ($filename, 'r');
156 $contents = fread ($fd, $fsize);
163 // create category dropdown box
164 function parse_categories($startidx = 0) {
165 if ($this->variables['catid'])
166 $catid = $this->variables['catid']; // on edit item
168 $catid = $this->blog->getDefaultCategory(); // on add item
170 ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());
173 function parse_blogid() {
174 echo $this->blog->getID();
177 function parse_blogname() {
178 echo $this->blog->getName();
181 function parse_bloglink() {
182 echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.$this->blog->getName().'</a>';
185 function parse_authorname() {
186 // don't use on add item?
188 echo $member->getDisplayName();
191 function parse_title() {
192 echo $this->contents['title'];
196 * Indicates the start of a conditional block of data. It will be added to
197 * the output only if the blogsetting with the given name equals the
198 * given value (default for value = 1 = true)
200 * the name of the blogsetting is the column name in the nucleus_blog table
202 * the conditional block ends with an <endif> var
204 function parse_ifblogsetting($name,$value=1) {
205 $this->_addIfCondition(($this->blog->getSetting($name) == $value));
208 function parse_ifitemproperty($name,$value=1) {
209 $this->_addIfCondition(($this->variables[$name] == $value));
212 function parse_helplink($topic) {
217 function parse_currenttime($what) {
218 $nu = getdate($this->blog->getCorrectTime());
222 // date change on edit item
223 function parse_itemtime($what) {
224 $itemtime = getdate($this->variables['timestamp']);
225 echo $itemtime[$what];
228 // some init stuff for all forms
229 function parse_init() {
230 $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
231 $this->blog->insertJavaScriptInfo($authorid);
234 // on bookmarklets only: insert extra html header information (by plugins)
235 function parse_extrahead() {
241 'BookmarkletExtraHead',
243 'extrahead' => &$extrahead
250 // inserts some localized text
251 function parse_text($which) {
252 // constant($which) only available from 4.0.4 :(
253 if (defined($which)) {
254 eval("echo $which;");
256 echo $which; // this way we see where definitions are missing
261 function parse_contents($which) {
262 echo htmlspecialchars($this->variables[$which]);
265 function parse_checkedonval($value, $name) {
266 if ($this->variables[$name] == $value)
267 echo "checked='checked'";
270 // extra javascript for input and textarea fields
271 function parse_jsinput($which) {
274 name="<?php echo $which?>"
275 id="input<?php echo $which?>"
277 if ($CONF['DisableJsTools'] != 1) {
279 onkeyup="storeCaret(this); updPreview('<?php echo $which?>'); doMonitor();"
280 onclick="storeCaret(this);"
281 onselect="storeCaret(this);"
285 else if ($CONF['DisableJsTools'] == 0) {
287 onkeyup="doMonitor();"
288 onkeypress="shortCuts();"
293 onkeyup="doMonitor();"
298 // shows the javascript button bar
299 function parse_jsbuttonbar($extrabuttons = "") {
301 switch($CONF['DisableJsTools']) {
304 echo '<div class="jsbuttonbar">';
306 $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");
307 $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");
308 $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");
309 $this->_jsbuttonspacer();
310 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
311 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
312 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
313 $this->_jsbuttonspacer();
314 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
315 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
316 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
317 $this->_jsbuttonspacer();
318 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
319 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
323 $btns = explode('+',$extrabuttons);
324 $this->_jsbuttonspacer();
325 foreach ($btns as $button) {
328 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT . " (Ctrl + Shift + M)");
331 $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
341 echo '<div class="jsbuttonbar">';
343 $this->_jsbutton('bold',"boldThis()",'');
344 $this->_jsbutton('italic',"italicThis()",'');
345 $this->_jsbutton('link',"ahrefThis()",'');
346 $this->_jsbuttonspacer();
347 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
348 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
349 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
350 $this->_jsbuttonspacer();
351 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
352 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
356 $btns = explode('+',$extrabuttons);
357 $this->_jsbuttonspacer();
358 foreach ($btns as $button) {
361 $this->_jsbutton('media',"addMedia()",'');
374 * Allows plugins to add their own custom fields
376 function parse_pluginextras() {
379 switch ($this->method) {
381 $manager->notify('AddItemFormExtras',
383 'blog' => &$this->blog
388 $manager->notify('EditItemFormExtras',
390 'variables' => $this->variables,
391 'blog' => &$this->blog,
392 'itemid' => $this->variables['itemid']
400 * Adds the itemOptions of a plugin to a page
403 function parse_itemoptions() {
405 ADMIN::_insertPluginOptions('item', $itemid);
408 function parse_ticket() {
410 $manager->addTicketHidden();
416 function _jsbutton($type, $code ,$tooltip) {
418 <span class="jsbutton"
419 onmouseover="BtnHighlight(this);"
420 onmouseout="BtnNormal(this);"
421 onclick="<?php echo $code?>" >
422 <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" width="16" height="16"/>
426 function _jsbuttonspacer() {
427 echo '<span class="jsbuttonspacer"></span>';