00001 <?php 00002 /* 00003 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 00004 * Copyright (C) 2002-2007 The Nucleus Group 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * (see nucleus/documentation/index.html#license for more info) 00011 */ 00024 class PAGEFACTORY extends BaseActions { 00025 00026 // ref to the blog object for which an add:edit form is created 00027 var $blog; 00028 00029 // allowed actions (for parser) 00030 var $actions; 00031 00032 // allowed types of forms (bookmarklet/admin) 00033 var $allowedTypes; 00034 var $type; // one of the types in $allowedTypes 00035 00036 // 'add' or 'edit' 00037 var $method; 00038 00039 // info to fill out in the form (e.g. catid, itemid, ...) 00040 var $variables; 00041 00045 function PAGEFACTORY($blogid) { 00046 // call constructor of superclass first 00047 $this->BaseActions(); 00048 00049 global $manager; 00050 $this->blog =& $manager->getBlog($blogid); 00051 00052 // TODO: move the definition of actions to the createXForm 00053 // methods 00054 $this->actions = Array( 00055 'actionurl', 00056 'title', 00057 'body', 00058 'more', 00059 'blogid', 00060 'bloglink', 00061 'blogname', 00062 'authorname', 00063 'checkedonval', 00064 'helplink', 00065 'currenttime', 00066 'itemtime', 00067 'init', 00068 'text', 00069 'jsinput', 00070 'jsbuttonbar', 00071 'categories', 00072 'contents', 00073 'ifblogsetting', 00074 'ifitemproperty', 00075 'else', 00076 'endif', 00077 'pluginextras', 00078 'itemoptions', 00079 'extrahead', 00080 'ticket' 00081 ); 00082 00083 // TODO: maybe add 'skin' later on? 00084 // TODO: maybe add other pages from admin area 00085 $this->allowedTypes = Array('bookmarklet','admin'); 00086 } 00087 00094 function createAddForm($type, $contents = array()) { 00095 if (!in_array($type, $this->allowedTypes)) 00096 return; 00097 $this->type = $type; 00098 $this->method = 'add'; 00099 00100 global $manager; 00101 $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog)); 00102 00103 $this->createForm($contents); 00104 } 00105 00116 function createEditForm($type, $contents) { 00117 if (!in_array($type, $this->allowedTypes)) 00118 return; 00119 $this->type = $type; 00120 $this->method = 'edit'; 00121 $this->createForm($contents); 00122 } 00123 00127 function createForm($contents) { 00128 // save contents 00129 $this->variables = $contents; 00130 00131 // get template to use 00132 $template = $this->getTemplateFor($this->type); 00133 00134 // use the PARSER engine to parse that template 00135 $parser =& new PARSER($this->actions, $this); 00136 $parser->parse($template); 00137 } 00138 00142 function getTemplateFor($type) { 00143 global $DIR_LIBS; 00144 00145 $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template'; 00146 00147 if (!file_exists($filename)) 00148 return ''; 00149 00150 $fsize = filesize($filename); 00151 if ($fsize <= 0) 00152 return ''; 00153 00154 // read file and return it 00155 $fd = fopen ($filename, 'r'); 00156 $contents = fread ($fd, $fsize); 00157 fclose ($fd); 00158 00159 return $contents; 00160 00161 } 00162 00163 // create category dropdown box 00164 function parse_categories($startidx = 0) { 00165 if ($this->variables['catid']) 00166 $catid = $this->variables['catid']; // on edit item 00167 else 00168 $catid = $this->blog->getDefaultCategory(); // on add item 00169 00170 ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID()); 00171 } 00172 00173 function parse_blogid() { 00174 echo $this->blog->getID(); 00175 } 00176 00177 function parse_blogname() { 00178 echo $this->blog->getName(); 00179 } 00180 00181 function parse_bloglink() { 00182 echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.htmlspecialchars($this->blog->getName()).'</a>'; 00183 } 00184 00185 function parse_authorname() { 00186 // don't use on add item? 00187 global $member; 00188 echo $member->getDisplayName(); 00189 } 00190 00191 function parse_title() { 00192 echo $this->contents['title']; 00193 } 00194 00204 function parse_ifblogsetting($name,$value=1) { 00205 $this->_addIfCondition(($this->blog->getSetting($name) == $value)); 00206 } 00207 00208 function parse_ifitemproperty($name,$value=1) { 00209 $this->_addIfCondition(($this->variables[$name] == $value)); 00210 } 00211 00212 function parse_helplink($topic) { 00213 help($topic); 00214 } 00215 00216 // for future items 00217 function parse_currenttime($what) { 00218 $nu = getdate($this->blog->getCorrectTime()); 00219 echo $nu[$what]; 00220 } 00221 00222 // date change on edit item 00223 function parse_itemtime($what) { 00224 $itemtime = getdate($this->variables['timestamp']); 00225 echo $itemtime[$what]; 00226 } 00227 00228 // some init stuff for all forms 00229 function parse_init() { 00230 $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : ''; 00231 $this->blog->insertJavaScriptInfo($authorid); 00232 } 00233 00234 // on bookmarklets only: insert extra html header information (by plugins) 00235 function parse_extrahead() { 00236 global $manager; 00237 00238 $extrahead = ''; 00239 00240 $manager->notify( 00241 'BookmarkletExtraHead', 00242 array( 00243 'extrahead' => &$extrahead 00244 ) 00245 ); 00246 00247 echo $extrahead; 00248 } 00249 00250 // inserts some localized text 00251 function parse_text($which) { 00252 // constant($which) only available from 4.0.4 :( 00253 if (defined($which)) { 00254 eval("echo $which;"); 00255 } else { 00256 echo $which; // this way we see where definitions are missing 00257 } 00258 00259 } 00260 00261 function parse_contents($which) { 00262 echo htmlspecialchars($this->variables[$which],ENT_QUOTES); 00263 } 00264 00265 function parse_checkedonval($value, $name) { 00266 if ($this->variables[$name] == $value) 00267 echo "checked='checked'"; 00268 } 00269 00270 // extra javascript for input and textarea fields 00271 function parse_jsinput($which) { 00272 global $CONF; 00273 ?> 00274 name="<?php echo $which?>" 00275 id="input<?php echo $which?>" 00276 <?php 00277 if ($CONF['DisableJsTools'] != 1) { 00278 ?> 00279 onkeyup="storeCaret(this); updPreview('<?php echo $which?>'); doMonitor();" 00280 onclick="storeCaret(this);" 00281 onselect="storeCaret(this);" 00282 00283 <?php 00284 } 00285 else if ($CONF['DisableJsTools'] == 0) { 00286 ?> 00287 onkeyup="doMonitor();" 00288 onkeypress="shortCuts();" 00289 <?php 00290 } 00291 else { 00292 ?> 00293 onkeyup="doMonitor();" 00294 <?php 00295 } 00296 } 00297 00298 // shows the javascript button bar 00299 function parse_jsbuttonbar($extrabuttons = "") { 00300 global $CONF; 00301 switch($CONF['DisableJsTools']) { 00302 00303 case "0": 00304 echo '<div class="jsbuttonbar">'; 00305 00306 $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)"); 00307 $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)"); 00308 $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)"); 00309 $this->_jsbuttonspacer(); 00310 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)"); 00311 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)"); 00312 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)"); 00313 $this->_jsbuttonspacer(); 00314 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT); 00315 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT); 00316 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT); 00317 $this->_jsbuttonspacer(); 00318 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT); 00319 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT); 00320 00321 00322 if ($extrabuttons) { 00323 $btns = explode('+',$extrabuttons); 00324 $this->_jsbuttonspacer(); 00325 foreach ($btns as $button) { 00326 switch($button) { 00327 case "media": 00328 $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT . " (Ctrl + Shift + M)"); 00329 break; 00330 case "preview": 00331 $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT); 00332 break; 00333 } 00334 } 00335 } 00336 00337 echo '</div>'; 00338 00339 break; 00340 case "2": 00341 echo '<div class="jsbuttonbar">'; 00342 00343 $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT); 00344 $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT); 00345 $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT); 00346 $this->_jsbuttonspacer(); 00347 $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT); 00348 $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT); 00349 $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT); 00350 $this->_jsbuttonspacer(); 00351 $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT); 00352 $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT); 00353 00354 00355 if ($extrabuttons) { 00356 $btns = explode('+',$extrabuttons); 00357 $this->_jsbuttonspacer(); 00358 foreach ($btns as $button) { 00359 switch($button) { 00360 case "media": 00361 $this->_jsbutton('media',"addMedia()",''); 00362 break; 00363 } 00364 } 00365 } 00366 00367 echo '</div>'; 00368 00369 break; 00370 } 00371 } 00372 00376 function parse_pluginextras() { 00377 global $manager; 00378 00379 switch ($this->method) { 00380 case 'add': 00381 $manager->notify('AddItemFormExtras', 00382 array( 00383 'blog' => &$this->blog 00384 ) 00385 ); 00386 break; 00387 case 'edit': 00388 $manager->notify('EditItemFormExtras', 00389 array( 00390 'variables' => $this->variables, 00391 'blog' => &$this->blog, 00392 'itemid' => $this->variables['itemid'] 00393 ) 00394 ); 00395 break; 00396 } 00397 } 00398 00403 function parse_itemoptions() { 00404 global $itemid; 00405 ADMIN::_insertPluginOptions('item', $itemid); 00406 } 00407 00408 function parse_ticket() { 00409 global $manager; 00410 $manager->addTicketHidden(); 00411 } 00412 00416 function _jsbutton($type, $code ,$tooltip) { 00417 ?> 00418 <span class="jsbutton" 00419 onmouseover="BtnHighlight(this);" 00420 onmouseout="BtnNormal(this);" 00421 onclick="<?php echo $code?>" > 00422 <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" width="16" height="16"/> 00423 </span> 00424 <?php } 00425 00426 function _jsbuttonspacer() { 00427 echo '<span class="jsbuttonspacer"></span>'; 00428 } 00429 00430 } 00431 00432 ?>