3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2012 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
12 * The formfactory class can be used to insert add/edit item forms into
\r
13 * admin area, bookmarklet, skins or any other places where such a form
\r
16 class PAGEFACTORY extends BaseActions {
\r
18 // ref to the blog object for which an add:edit form is created
\r
21 // allowed actions (for parser)
\r
24 // allowed types of forms (bookmarklet/admin)
\r
26 var $type; // one of the types in $allowedTypes
\r
31 // info to fill out in the form (e.g. catid, itemid, ...)
\r
35 * creates a new PAGEFACTORY object
\r
37 function PAGEFACTORY($blogid) {
\r
38 // call constructor of superclass first
\r
39 $this->BaseActions();
\r
42 $this->blog =& $manager->getBlog($blogid);
\r
44 // TODO: move the definition of actions to the createXForm
\r
46 $this->actions = Array(
\r
78 // TODO: maybe add 'skin' later on?
\r
79 // TODO: maybe add other pages from admin area
\r
80 $this->allowedTypes = Array('bookmarklet','admin');
\r
84 * creates a "add item" form for a given type of page
\r
87 * 'admin' or 'bookmarklet'
\r
89 function createAddForm($type, $contents = array()) {
\r
90 if (!in_array($type, $this->allowedTypes))
\r
92 $this->type = $type;
\r
93 $this->method = 'add';
\r
97 'contents' => &$contents,
\r
98 'blog' => &$this->blog
\r
100 $manager->notify('PreAddItemForm', $param);
\r
102 $this->createForm($contents);
\r
106 * creates a "add item" form for a given type of page
\r
109 * 'admin' or 'bookmarklet'
\r
111 * An associative array
\r
112 * 'author' => author
\r
115 function createEditForm($type, $contents) {
\r
116 if (!in_array($type, $this->allowedTypes))
\r
118 $this->type = $type;
\r
119 $this->method = 'edit';
\r
120 $this->createForm($contents);
\r
124 * (private) creates a form for a given type of page
\r
126 function createForm($contents) {
\r
128 $this->variables = $contents;
\r
130 // get template to use
\r
131 $template = $this->getTemplateFor($this->type);
\r
133 // use the PARSER engine to parse that template
\r
134 $parser = new PARSER($this->actions, $this);
\r
135 $parser->parse($template);
\r
139 * returns an appropriate template
\r
141 function getTemplateFor($type) {
\r
144 $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';
\r
146 if (!file_exists($filename))
\r
149 $fsize = filesize($filename);
\r
153 // read file and return it
\r
154 $fd = fopen ($filename, 'r');
\r
155 $contents = fread ($fd, $fsize);
\r
162 // create category dropdown box
\r
163 function parse_categories($startidx = 0) {
\r
164 if (array_key_exists('catid', $this->variables) && $this->variables['catid'])
\r
165 $catid = $this->variables['catid']; // on edit item
\r
167 $catid = $this->blog->getDefaultCategory(); // on add item
\r
169 ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());
\r
172 function parse_blogid() {
\r
173 echo $this->blog->getID();
\r
176 function parse_blogname() {
\r
177 echo $this->blog->getName();
\r
180 function parse_bloglink() {
\r
181 echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.htmlspecialchars($this->blog->getName()).'</a>';
\r
184 function parse_authorname() {
\r
185 // don't use on add item?
\r
187 echo $member->getDisplayName();
\r
190 function parse_title() {
\r
191 echo $this->contents['title'];
\r
195 * Indicates the start of a conditional block of data. It will be added to
\r
196 * the output only if the blogsetting with the given name equals the
\r
197 * given value (default for value = 1 = true)
\r
199 * the name of the blogsetting is the column name in the nucleus_blog table
\r
201 * the conditional block ends with an <endif> var
\r
203 function parse_ifblogsetting($name,$value=1) {
\r
204 $this->_addIfCondition(($this->blog->getSetting($name) == $value));
\r
207 function parse_ifitemproperty($name,$value=1) {
\r
208 $this->_addIfCondition(($this->variables[$name] == $value));
\r
211 function parse_ifautosave($name,$value=1) {
\r
213 $this->_addIfCondition($member->getAutosave() == $value);
\r
216 function parse_helplink($topic) {
\r
220 // for future items
\r
221 function parse_currenttime($what) {
\r
222 $nu = getdate($this->blog->getCorrectTime());
\r
226 // date change on edit item
\r
227 function parse_itemtime($what) {
\r
228 $itemtime = getdate($this->variables['timestamp']);
\r
229 echo $itemtime[$what];
\r
232 // some init stuff for all forms
\r
233 function parse_init() {
\r
234 $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
\r
235 $this->blog->insertJavaScriptInfo($authorid);
\r
238 // on bookmarklets only: insert extra html header information (by plugins)
\r
239 function parse_extrahead() {
\r
245 'extrahead' => &$extrahead
\r
247 $manager->notify('BookmarkletExtraHead', $param);
\r
252 // inserts some localized text
\r
253 function parse_text($which) {
\r
254 // constant($which) only available from 4.0.4 :(
\r
255 if (defined($which)) {
\r
256 eval("echo $which;");
\r
258 echo $which; // this way we see where definitions are missing
\r
263 function parse_contents($which) {
\r
264 if (!isset($this->variables[$which])) $this->variables[$which] = '';
\r
265 echo htmlspecialchars($this->variables[$which],ENT_QUOTES);
\r
268 function parse_checkedonval($value, $name) {
\r
269 if (!isset($this->variables[$name])) $this->variables[$name] = '';
\r
270 if ($this->variables[$name] == $value)
\r
271 echo 'checked="checked"';
\r
274 // extra javascript for input and textarea fields
\r
275 function parse_jsinput($which) {
\r
276 global $CONF, $member;
\r
278 $attributes = " name=\"{$which}\"";
\r
279 $attributes .= " id=\"input{$which}\"";
\r
281 if ($CONF['DisableJsTools'] != 1) {
\r
282 $attributes .= ' onclick="storeCaret(this);"';
\r
283 $attributes .= ' onselect="storeCaret(this);"';
\r
284 if ($member->getAutosave()) {
\r
285 $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}'); doMonitor();\"";
\r
287 $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}');\"";
\r
291 if ($CONF['DisableJsTools'] == 0) {
\r
292 $attributes .= ' onkeypress="shortCuts();"';
\r
294 if ($member->getAutosave()) {
\r
295 $attributes .= ' onkeyup="doMonitor();"';
\r
301 // shows the javascript button bar
\r
302 function parse_jsbuttonbar($extrabuttons = "") {
\r
304 switch($CONF['DisableJsTools']) {
\r
307 echo '<div class="jsbuttonbar">';
\r
309 $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");
\r
310 $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");
\r
311 $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");
\r
312 $this->_jsbuttonspacer();
\r
313 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
\r
314 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
\r
315 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
\r
316 $this->_jsbuttonspacer();
\r
317 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
\r
318 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
\r
319 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
\r
320 $this->_jsbuttonspacer();
\r
321 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
\r
322 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
\r
325 if ($extrabuttons) {
\r
326 $btns = explode('+',$extrabuttons);
\r
327 $this->_jsbuttonspacer();
\r
328 foreach ($btns as $button) {
\r
331 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT . " (Ctrl + Shift + M)");
\r
334 $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
\r
344 echo '<div class="jsbuttonbar">';
\r
346 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT);
\r
347 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT);
\r
348 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT);
\r
349 $this->_jsbuttonspacer();
\r
350 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
\r
351 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
\r
352 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
\r
353 $this->_jsbuttonspacer();
\r
354 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
\r
355 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
\r
358 if ($extrabuttons) {
\r
359 $btns = explode('+',$extrabuttons);
\r
360 $this->_jsbuttonspacer();
\r
361 foreach ($btns as $button) {
\r
364 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT);
\r
377 * Allows plugins to add their own custom fields
\r
379 function parse_pluginextras() {
\r
382 switch ($this->method) {
\r
385 'blog' => &$this->blog
\r
387 $manager->notify('AddItemFormExtras', $param);
\r
391 'variables' => $this->variables,
\r
392 'blog' => &$this->blog,
\r
393 'itemid' => $this->variables['itemid']
\r
395 $manager->notify('EditItemFormExtras', $param);
\r
401 * Adds the itemOptions of a plugin to a page
\r
404 function parse_itemoptions() {
\r
406 ADMIN::_insertPluginOptions('item', $itemid);
\r
409 function parse_ticket() {
\r
411 $manager->addTicketHidden();
\r
415 * convenience method
\r
417 function _jsbutton($type, $code ,$tooltip) {
\r
419 <span class="jsbutton"
\r
420 onmouseover="BtnHighlight(this);"
\r
421 onmouseout="BtnNormal(this);"
\r
422 onclick="<?php echo $code?>" >
\r
423 <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" title="<?php echo $tooltip?>" width="16" height="16"/>
\r
427 function _jsbuttonspacer() {
\r
428 echo '<span class="jsbuttonspacer"> </span>';
\r