3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2004 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
15 * The formfactory class can be used to insert add/edit item forms into
\r
16 * admin area, bookmarklet, skins or any other places where such a form
\r
19 class PAGEFACTORY extends BaseActions {
\r
21 // ref to the blog object for which an add:edit form is created
\r
24 // allowed actions (for parser)
\r
27 // allowed types of forms (bookmarklet/admin)
\r
29 var $type; // one of the types in $allowedTypes
\r
34 // info to fill out in the form (e.g. catid, itemid, ...)
\r
38 * creates a new PAGEFACTORY object
\r
40 function PAGEFACTORY($blogid) {
\r
41 // call constructor of superclass first
\r
42 $this->BaseActions();
\r
45 $this->blog =& $manager->getBlog($blogid);
\r
47 // TODO: move the definition of actions to the createXForm
\r
49 $this->actions = Array(
\r
76 // TODO: maybe add 'skin' later on?
\r
77 // TODO: maybe add other pages from admin area
\r
78 $this->allowedTypes = Array('bookmarklet','admin');
\r
82 * creates a "add item" form for a given type of page
\r
85 * 'admin' or 'bookmarklet'
\r
87 function createAddForm($type, $contents = array()) {
\r
88 if (!in_array($type, $this->allowedTypes))
\r
90 $this->type = $type;
\r
91 $this->method = 'add';
\r
94 $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));
\r
96 $this->createForm($contents);
\r
100 * creates a "add item" form for a given type of page
\r
103 * 'admin' or 'bookmarklet'
\r
105 * An associative array
\r
106 * 'author' => author
\r
109 function createEditForm($type, $contents) {
\r
110 if (!in_array($type, $this->allowedTypes))
\r
112 $this->type = $type;
\r
113 $this->method = 'edit';
\r
114 $this->createForm($contents);
\r
118 * (private) creates a form for a given type of page
\r
120 function createForm($contents) {
\r
122 $this->variables = $contents;
\r
124 // get template to use
\r
125 $template = $this->getTemplateFor($this->type);
\r
127 // use the PARSER engine to parse that template
\r
128 $parser = new PARSER($this->actions, $this);
\r
129 $parser->parse($template);
\r
133 * returns an appropriate template
\r
135 function getTemplateFor($type) {
\r
138 $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';
\r
140 if (!file_exists($filename))
\r
143 $fsize = filesize($filename);
\r
147 // read file and return it
\r
148 $fd = fopen ($filename, 'r');
\r
149 $contents = fread ($fd, $fsize);
\r
156 // create category dropdown box
\r
157 function parse_categories($startidx = 0) {
\r
158 if ($this->variables['catid'])
\r
159 $catid = $this->variables['catid']; // on edit item
\r
161 $catid = $this->blog->getDefaultCategory(); // on add item
\r
163 ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());
\r
166 function parse_blogid() {
\r
167 echo $this->blog->getID();
\r
170 function parse_blogname() {
\r
171 echo $this->blog->getName();
\r
174 function parse_bloglink() {
\r
175 echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.$this->blog->getName().'</a>';
\r
178 function parse_authorname() {
\r
179 // don't use on add item?
\r
181 echo $member->getDisplayName();
\r
184 function parse_title() {
\r
185 echo $this->contents['title'];
\r
189 * Indicates the start of a conditional block of data. It will be added to
\r
190 * the output only if the blogsetting with the given name equals the
\r
191 * given value (default for value = 1 = true)
\r
193 * the name of the blogsetting is the column name in the nucleus_blog table
\r
195 * the conditional block ends with an <endif> var
\r
197 function parse_ifblogsetting($name,$value=1) {
\r
198 $this->_addIfCondition(($this->blog->getSetting($name) == $value));
\r
201 function parse_ifitemproperty($name,$value=1) {
\r
202 $this->_addIfCondition(($this->variables[$name] == $value));
\r
205 function parse_helplink($topic) {
\r
209 // for future items
\r
210 function parse_currenttime($what) {
\r
211 $nu = getdate($this->blog->getCorrectTime());
\r
215 // date change on edit item
\r
216 function parse_itemtime($what) {
\r
217 $itemtime = getdate($this->variables['timestamp']);
\r
218 echo $itemtime[$what];
\r
221 // some init stuff for all forms
\r
222 function parse_init() {
\r
223 $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
\r
224 $this->blog->insertJavaScriptInfo($authorid);
\r
227 // on bookmarklets only: insert extra html header information (by plugins)
\r
228 function parse_extrahead() {
\r
234 'BookmarkletExtraHead',
\r
236 'extrahead' => &$extrahead
\r
243 // inserts some localized text
\r
244 function parse_text($which) {
\r
245 // constant($which) only available from 4.0.4 :(
\r
246 if (defined($which)) {
\r
247 eval("echo $which;");
\r
249 echo $which; // this way we see where definitions are missing
\r
254 function parse_contents($which) {
\r
255 echo htmlspecialchars($this->variables[$which]);
\r
258 function parse_checkedonval($value, $name) {
\r
259 if ($this->variables[$name] == $value)
\r
260 echo "checked='checked'";
\r
263 // extra javascript for input and textarea fields
\r
264 function parse_jsinput($which) {
\r
267 name="<?php echo $which?>"
\r
268 id="input<?php echo $which?>"
\r
270 if ($CONF['DisableJsTools'] != 1) {
\r
272 onkeyup="storeCaret(this); updPreview('<?php echo $which?>');"
\r
273 onclick="storeCaret(this);"
\r
274 onselect="storeCaret(this);"
\r
279 if ($CONF['DisableJsTools'] == 0) {
\r
281 onkeypress="shortCuts();"
\r
285 // shows the javascript button bar
\r
286 function parse_jsbuttonbar($extrabuttons = "") {
\r
288 switch($CONF['DisableJsTools']) {
\r
291 echo '<div class="jsbuttonbar">';
\r
293 $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");
\r
294 $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");
\r
295 $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");
\r
296 $this->_jsbuttonspacer();
\r
297 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
\r
298 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
\r
299 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
\r
300 $this->_jsbuttonspacer();
\r
301 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
\r
302 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
\r
303 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
\r
304 $this->_jsbuttonspacer();
\r
305 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
\r
306 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
\r
309 if ($extrabuttons) {
\r
310 $btns = explode('+',$extrabuttons);
\r
311 $this->_jsbuttonspacer();
\r
312 foreach ($btns as $button) {
\r
315 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT . " (Ctrl + Shift + M)");
\r
318 $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
\r
328 echo '<div class="jsbuttonbar">';
\r
330 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT .'');
\r
331 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT .'');
\r
332 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT .'');
\r
333 $this->_jsbuttonspacer();
\r
334 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
\r
335 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
\r
336 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
\r
337 $this->_jsbuttonspacer();
\r
338 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
\r
339 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
\r
342 if ($extrabuttons) {
\r
343 $btns = explode('+',$extrabuttons);
\r
344 $this->_jsbuttonspacer();
\r
345 foreach ($btns as $button) {
\r
348 $this->_jsbutton('media',"addMedia()",'');
\r
361 * Allows plugins to add their own custom fields
\r
363 function parse_pluginextras() {
\r
366 switch ($this->method) {
\r
368 $manager->notify('AddItemFormExtras',
\r
370 'blog' => &$this->blog
\r
375 $manager->notify('EditItemFormExtras',
\r
377 'variables' => $this->variables,
\r
378 'blog' => &$this->blog,
\r
379 'itemid' => $this->variables['itemid']
\r
387 * convenience method
\r
389 function _jsbutton($type, $code ,$tooltip) {
\r
391 <span class="jsbutton"
\r
392 onmouseover="BtnHighlight(this);"
\r
393 onmouseout="BtnNormal(this);"
\r
394 onclick="<?php echo $code?>" >
\r
395 <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" width="16" height="16"/>
\r
399 function _jsbuttonspacer() {
\r
400 echo '<span class="jsbuttonspacer"></span>';
\r