3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2011 The Nucleus Group
\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
13 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
14 * @copyright Copyright (C) 2002-2011 The Nucleus Group
\r
16 * $NucleusJP: PAGEFACTORY.php,v 1.8.2.2 2007/10/30 16:12:27 shizuki Exp $
\r
20 * The formfactory class can be used to insert add/edit item forms into
\r
21 * admin area, bookmarklet, skins or any other places where such a form
\r
24 class PAGEFACTORY extends BaseActions {
\r
26 // ref to the blog object for which an add:edit form is created
\r
29 // allowed actions (for parser)
\r
32 // allowed types of forms (bookmarklet/admin)
\r
34 var $type; // one of the types in $allowedTypes
\r
39 // info to fill out in the form (e.g. catid, itemid, ...)
\r
43 * creates a new PAGEFACTORY object
\r
45 function PAGEFACTORY($blogid) {
\r
46 // call constructor of superclass first
\r
47 $this->BaseActions();
\r
50 $this->blog =& $manager->getBlog($blogid);
\r
52 // TODO: move the definition of actions to the createXForm
\r
54 $this->actions = Array(
\r
86 // TODO: maybe add 'skin' later on?
\r
87 // TODO: maybe add other pages from admin area
\r
88 $this->allowedTypes = Array('bookmarklet','admin');
\r
92 * creates a "add item" form for a given type of page
\r
95 * 'admin' or 'bookmarklet'
\r
97 function createAddForm($type, $contents = array()) {
\r
98 if (!in_array($type, $this->allowedTypes))
\r
100 $this->type = $type;
\r
101 $this->method = 'add';
\r
104 $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));
\r
106 $this->createForm($contents);
\r
110 * creates a "add item" form for a given type of page
\r
113 * 'admin' or 'bookmarklet'
\r
115 * An associative array
\r
116 * 'author' => author
\r
119 function createEditForm($type, $contents) {
\r
120 if (!in_array($type, $this->allowedTypes))
\r
122 $this->type = $type;
\r
123 $this->method = 'edit';
\r
124 $this->createForm($contents);
\r
128 * (private) creates a form for a given type of page
\r
130 function createForm($contents) {
\r
132 $this->variables = $contents;
\r
134 // get template to use
\r
135 $template = $this->getTemplateFor($this->type);
\r
137 // use the PARSER engine to parse that template
\r
138 $parser =& new PARSER($this->actions, $this);
\r
139 $parser->parse($template);
\r
143 * returns an appropriate template
\r
145 function getTemplateFor($type) {
\r
148 $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';
\r
150 if (!file_exists($filename))
\r
153 $fsize = filesize($filename);
\r
157 // read file and return it
\r
158 $fd = fopen ($filename, 'r');
\r
159 $contents = fread ($fd, $fsize);
\r
166 // create category dropdown box
\r
167 function parse_categories($startidx = 0) {
\r
168 if ($this->variables['catid'])
\r
169 $catid = $this->variables['catid']; // on edit item
\r
171 $catid = $this->blog->getDefaultCategory(); // on add item
\r
173 ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());
\r
176 function parse_blogid() {
\r
177 echo $this->blog->getID();
\r
180 function parse_blogname() {
\r
181 echo $this->blog->getName();
\r
184 function parse_bloglink() {
\r
185 echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.htmlspecialchars($this->blog->getName()).'</a>';
\r
188 function parse_authorname() {
\r
189 // don't use on add item?
\r
191 echo $member->getDisplayName();
\r
194 function parse_title() {
\r
195 echo $this->contents['title'];
\r
199 * Indicates the start of a conditional block of data. It will be added to
\r
200 * the output only if the blogsetting with the given name equals the
\r
201 * given value (default for value = 1 = true)
\r
203 * the name of the blogsetting is the column name in the nucleus_blog table
\r
205 * the conditional block ends with an <endif> var
\r
207 function parse_ifblogsetting($name,$value=1) {
\r
208 $this->_addIfCondition(($this->blog->getSetting($name) == $value));
\r
211 function parse_ifitemproperty($name,$value=1) {
\r
212 $this->_addIfCondition(($this->variables[$name] == $value));
\r
215 function parse_ifautosave($name,$value=1) {
\r
217 $this->_addIfCondition($member->getAutosave() == $value);
\r
220 function parse_helplink($topic) {
\r
224 // for future items
\r
225 function parse_currenttime($what) {
\r
226 $nu = getdate($this->blog->getCorrectTime());
\r
230 // date change on edit item
\r
231 function parse_itemtime($what) {
\r
232 $itemtime = getdate($this->variables['timestamp']);
\r
233 echo $itemtime[$what];
\r
236 // some init stuff for all forms
\r
237 function parse_init() {
\r
238 $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
\r
239 $this->blog->insertJavaScriptInfo($authorid);
\r
242 // on bookmarklets only: insert extra html header information (by plugins)
\r
243 function parse_extrahead() {
\r
249 'BookmarkletExtraHead',
\r
251 'extrahead' => &$extrahead
\r
258 // inserts some localized text
\r
259 function parse_text($which) {
\r
260 // constant($which) only available from 4.0.4 :(
\r
261 if (defined($which)) {
\r
262 eval("echo $which;");
\r
264 echo $which; // this way we see where definitions are missing
\r
269 function parse_contents($which) {
\r
270 if (!isset($this->variables[$which])) $this->variables[$which] = '';
\r
271 echo htmlspecialchars($this->variables[$which],ENT_QUOTES);
\r
274 function parse_checkedonval($value, $name) {
\r
275 if (!isset($this->variables[$name])) $this->variables[$name] = '';
\r
276 if ($this->variables[$name] == $value)
\r
277 echo 'checked="checked"';
\r
280 // extra javascript for input and textarea fields
\r
281 function parse_jsinput($which) {
\r
282 global $CONF, $member;
\r
284 $attributes = " name=\"{$which}\"";
\r
285 $attributes .= " id=\"input{$which}\"";
\r
287 if ($CONF['DisableJsTools'] != 1) {
\r
288 $attributes .= ' onclick="storeCaret(this);"';
\r
289 $attributes .= ' onselect="storeCaret(this);"';
\r
290 if ($member->getAutosave()) {
\r
291 $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}'); doMonitor();\"";
\r
293 $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}');\"";
\r
297 if ($CONF['DisableJsTools'] == 0) {
\r
298 $attributes .= ' onkeypress="shortCuts();"';
\r
300 if ($member->getAutosave()) {
\r
301 $attributes .= ' onkeyup="doMonitor();"';
\r
307 // shows the javascript button bar
\r
308 function parse_jsbuttonbar($extrabuttons = "") {
\r
310 switch($CONF['DisableJsTools']) {
\r
313 echo '<div class="jsbuttonbar">';
\r
315 $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");
\r
316 $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");
\r
317 $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");
\r
318 $this->_jsbuttonspacer();
\r
319 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
\r
320 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
\r
321 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
\r
322 $this->_jsbuttonspacer();
\r
323 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
\r
324 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
\r
325 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
\r
326 $this->_jsbuttonspacer();
\r
327 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
\r
328 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
\r
331 if ($extrabuttons) {
\r
332 $btns = explode('+',$extrabuttons);
\r
333 $this->_jsbuttonspacer();
\r
334 foreach ($btns as $button) {
\r
337 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT . " (Ctrl + Shift + M)");
\r
340 $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
\r
350 echo '<div class="jsbuttonbar">';
\r
352 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT);
\r
353 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT);
\r
354 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT);
\r
355 $this->_jsbuttonspacer();
\r
356 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
\r
357 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
\r
358 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
\r
359 $this->_jsbuttonspacer();
\r
360 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
\r
361 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
\r
364 if ($extrabuttons) {
\r
365 $btns = explode('+',$extrabuttons);
\r
366 $this->_jsbuttonspacer();
\r
367 foreach ($btns as $button) {
\r
370 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT);
\r
383 * Allows plugins to add their own custom fields
\r
385 function parse_pluginextras() {
\r
388 switch ($this->method) {
\r
390 $manager->notify('AddItemFormExtras',
\r
392 'blog' => &$this->blog
\r
397 $manager->notify('EditItemFormExtras',
\r
399 'variables' => $this->variables,
\r
400 'blog' => &$this->blog,
\r
401 'itemid' => $this->variables['itemid']
\r
409 * Adds the itemOptions of a plugin to a page
\r
412 function parse_itemoptions() {
\r
414 ADMIN::_insertPluginOptions('item', $itemid);
\r
417 function parse_ticket() {
\r
419 $manager->addTicketHidden();
\r
423 * convenience method
\r
425 function _jsbutton($type, $code ,$tooltip) {
\r
427 <span class="jsbutton"
\r
428 onmouseover="BtnHighlight(this);"
\r
429 onmouseout="BtnNormal(this);"
\r
430 onclick="<?php echo $code?>" >
\r
431 <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" title="<?php echo $tooltip?>" width="16" height="16"/>
\r
435 function _jsbuttonspacer() {
\r
436 echo '<span class="jsbuttonspacer"> </span>';
\r