[ Index ]

PHP Cross Reference of Nucleus CMS v3.51 code documentation

title

Body

[close]

/nucleus/libs/ -> PAGEFACTORY.php (source)

   1  <?php
   2  /*

   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)

   4   * Copyright (C) 2002-2009 The Nucleus Group

   5   *

   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)

  11   */
  12  /**

  13   * @license http://nucleuscms.org/license.txt GNU General Public License

  14   * @copyright Copyright (C) 2002-2009 The Nucleus Group

  15   * @version $Id: PAGEFACTORY.php 1388 2009-07-18 06:31:28Z shizuki $

  16   */
  17  
  18  /**

  19   * The formfactory class can be used to insert add/edit item forms into

  20   * admin area, bookmarklet, skins or any other places where such a form

  21   * might be needed

  22   */
  23  class PAGEFACTORY extends BaseActions {
  24  
  25      // ref to the blog object for which an add:edit form is created

  26      var $blog;
  27  
  28      // allowed actions (for parser)

  29      var $actions;
  30  
  31      // allowed types of forms (bookmarklet/admin)

  32      var $allowedTypes;
  33      var $type;        // one of the types in $allowedTypes

  34  
  35      // 'add' or 'edit'

  36      var $method;
  37  
  38      // info to fill out in the form (e.g. catid, itemid, ...)

  39      var $variables;
  40  
  41      /**

  42       * creates a new PAGEFACTORY object

  43       */
  44  	function PAGEFACTORY($blogid) {
  45          // call constructor of superclass first

  46          $this->BaseActions();
  47  
  48          global $manager;
  49          $this->blog =& $manager->getBlog($blogid);
  50  
  51          // TODO: move the definition of actions to the createXForm

  52          // methods

  53          $this->actions = Array(
  54              'actionurl',
  55              'title',
  56              'body',
  57              'more',
  58              'blogid',
  59              'bloglink',
  60              'blogname',
  61              'authorname',
  62              'checkedonval',
  63              'helplink',
  64              'currenttime',
  65              'itemtime',
  66              'init',
  67              'text',
  68              'jsinput',
  69              'jsbuttonbar',
  70              'categories',
  71              'contents',
  72              'ifblogsetting',
  73              'ifitemproperty',
  74              'else',
  75              'endif',
  76              'pluginextras',
  77              'itemoptions',
  78              'extrahead',
  79              'ticket',
  80              'autosave',
  81              'autosaveinfo',
  82              'ifautosave',
  83          );
  84  
  85          // TODO: maybe add 'skin' later on?

  86          // TODO: maybe add other pages from admin area

  87          $this->allowedTypes = Array('bookmarklet','admin');
  88      }
  89  
  90      /**

  91       * creates a "add item" form for a given type of page

  92       *

  93       * @param type

  94       *        'admin' or 'bookmarklet'

  95       */
  96  	function createAddForm($type, $contents = array()) {
  97          if (!in_array($type, $this->allowedTypes))
  98              return;
  99          $this->type = $type;
 100          $this->method = 'add';
 101  
 102          global $manager;
 103          $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));
 104  
 105          $this->createForm($contents);
 106      }
 107  
 108      /**

 109       * creates a "add item" form for a given type of page

 110       *

 111       * @param type

 112       *        'admin' or 'bookmarklet'

 113       * @param contents

 114       *        An associative array

 115       *            'author' => author

 116       *            '' =>

 117       */
 118  	function createEditForm($type, $contents) {
 119          if (!in_array($type, $this->allowedTypes))
 120              return;
 121          $this->type = $type;
 122          $this->method = 'edit';
 123          $this->createForm($contents);
 124      }
 125  
 126      /**

 127       * (private) creates a form for a given type of page

 128       */
 129  	function createForm($contents) {
 130          // save contents

 131          $this->variables = $contents;
 132  
 133          // get template to use

 134          $template = $this->getTemplateFor($this->type);
 135  
 136          // use the PARSER engine to parse that template

 137          $parser =& new PARSER($this->actions, $this);
 138          $parser->parse($template);
 139      }
 140  
 141      /**

 142       * returns an appropriate template

 143       */
 144  	function getTemplateFor($type) {
 145          global $DIR_LIBS;
 146  
 147          $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';
 148  
 149          if (!file_exists($filename))
 150              return '';
 151  
 152          $fsize = filesize($filename);
 153          if ($fsize <= 0)
 154              return '';
 155  
 156          // read file and return it

 157          $fd = fopen ($filename, 'r');
 158          $contents = fread ($fd, $fsize);
 159          fclose ($fd);
 160  
 161          return $contents;
 162  
 163      }
 164  
 165      // create category dropdown box

 166  	function parse_categories($startidx = 0) {
 167              if ($this->variables['catid'])
 168                  $catid = $this->variables['catid'];                // on edit item

 169              else
 170                  $catid = $this->blog->getDefaultCategory();        // on add item

 171  
 172              ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());
 173      }
 174  
 175  	function parse_blogid() {
 176          echo $this->blog->getID();
 177      }
 178  
 179  	function parse_blogname() {
 180          echo $this->blog->getName();
 181      }
 182  
 183  	function parse_bloglink() {
 184          echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.htmlspecialchars($this->blog->getName()).'</a>';
 185      }
 186  
 187  	function parse_authorname() {
 188          // don't use on add item?

 189          global $member;
 190          echo $member->getDisplayName();
 191      }
 192  
 193  	function parse_title() {
 194          echo $this->contents['title'];
 195      }
 196  
 197      /**

 198       * Indicates the start of a conditional block of data. It will be added to

 199       * the output only if the blogsetting with the given name equals the

 200       * given value (default for value = 1 = true)

 201       *

 202       * the name of the blogsetting is the column name in the nucleus_blog table

 203       *

 204       * the conditional block ends with an <endif> var

 205       */
 206  	function parse_ifblogsetting($name,$value=1) {
 207          $this->_addIfCondition(($this->blog->getSetting($name) == $value));
 208      }
 209  
 210  	function parse_ifitemproperty($name,$value=1) {
 211          $this->_addIfCondition(($this->variables[$name] == $value));
 212      }
 213  
 214  	function parse_ifautosave($name,$value=1) {
 215          global $member;
 216          $this->_addIfCondition($member->getAutosave() == $value);
 217      }
 218  
 219  	function parse_helplink($topic) {
 220          help($topic);
 221      }
 222  
 223      // for future items

 224  	function parse_currenttime($what) {
 225          $nu = getdate($this->blog->getCorrectTime());
 226          echo $nu[$what];
 227      }
 228  
 229      // date change on edit item

 230  	function parse_itemtime($what) {
 231          $itemtime = getdate($this->variables['timestamp']);
 232          echo $itemtime[$what];
 233      }
 234  
 235      // some init stuff for all forms

 236  	function parse_init() {
 237          $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
 238          $this->blog->insertJavaScriptInfo($authorid);
 239      }
 240  
 241      // on bookmarklets only: insert extra html header information (by plugins)

 242  	function parse_extrahead() {
 243          global $manager;
 244  
 245          $extrahead = '';
 246  
 247          $manager->notify(
 248              'BookmarkletExtraHead',
 249              array(
 250                  'extrahead' => &$extrahead
 251              )
 252          );
 253  
 254          echo $extrahead;
 255      }
 256  
 257      // inserts some localized text

 258  	function parse_text($which) {
 259          // constant($which) only available from 4.0.4 :(

 260          if (defined($which)) {
 261              eval("echo $which;");
 262          } else {
 263              echo $which;    // this way we see where definitions are missing

 264          }
 265  
 266      }
 267  
 268  	function parse_contents($which) {
 269          if (!isset($this->variables[$which])) $this->variables[$which] = '';
 270          echo htmlspecialchars($this->variables[$which],ENT_QUOTES);
 271      }
 272  
 273  	function parse_checkedonval($value, $name) {
 274          if (!isset($this->variables[$name])) $this->variables[$name] = '';
 275          if ($this->variables[$name] == $value)
 276              echo "checked='checked'";
 277      }
 278  
 279      // extra javascript for input and textarea fields

 280  	function parse_jsinput($which) {
 281          global $CONF;
 282      ?>
 283              name="<?php echo $which?>"
 284              id="input<?php echo $which?>"
 285      <?php
 286          if ($CONF['DisableJsTools'] != 1) {
 287      ?>
 288              onkeyup="storeCaret(this); updPreview('<?php echo $which?>'); doMonitor();"
 289              onclick="storeCaret(this);"
 290              onselect="storeCaret(this);"
 291  
 292      <?php
 293          }
 294          else if ($CONF['DisableJsTools'] == 0) {
 295      ?>
 296              onkeyup="doMonitor();"
 297              onkeypress="shortCuts();"
 298      <?php
 299          }
 300          else {
 301      ?>
 302              onkeyup="doMonitor();"
 303      <?php
 304          }
 305      }
 306  
 307      // shows the javascript button bar

 308  	function parse_jsbuttonbar($extrabuttons = "") {
 309          global $CONF;
 310          switch($CONF['DisableJsTools'])    {
 311  
 312              case "0":
 313                  echo '<div class="jsbuttonbar">';
 314  
 315                      $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");
 316                      $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");
 317                      $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");
 318                      $this->_jsbuttonspacer();
 319                      $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
 320                      $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
 321                      $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
 322                      $this->_jsbuttonspacer();
 323                      $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
 324                      $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
 325                      $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
 326                      $this->_jsbuttonspacer();
 327                      $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
 328                      $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
 329  
 330  
 331                      if ($extrabuttons) {
 332                          $btns = explode('+',$extrabuttons);
 333                          $this->_jsbuttonspacer();
 334                          foreach ($btns as $button) {
 335                              switch($button) {
 336                                  case "media":
 337                                      $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT .    " (Ctrl + Shift + M)");
 338                                      break;
 339                                  case "preview":
 340                                      $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
 341                                      break;
 342                              }
 343                          }
 344                      }
 345  
 346                  echo '</div>';
 347  
 348                  break;
 349              case "2":
 350                  echo '<div class="jsbuttonbar">';
 351  
 352                      $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT);
 353                      $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT);
 354                      $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT);
 355                      $this->_jsbuttonspacer();
 356                      $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
 357                      $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
 358                      $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
 359                      $this->_jsbuttonspacer();
 360                      $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
 361                      $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
 362  
 363  
 364                      if ($extrabuttons) {
 365                          $btns = explode('+',$extrabuttons);
 366                          $this->_jsbuttonspacer();
 367                          foreach ($btns as $button) {
 368                              switch($button) {
 369                                  case "media":
 370                                      $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT);
 371                                      break;
 372                              }
 373                          }
 374                      }
 375  
 376                  echo '</div>';
 377  
 378                  break;
 379          }
 380      }
 381  
 382      /**

 383       * Allows plugins to add their own custom fields

 384       */
 385  	function parse_pluginextras() {
 386          global $manager;
 387  
 388          switch ($this->method) {
 389              case 'add':
 390                  $manager->notify('AddItemFormExtras',
 391                          array(
 392                              'blog' => &$this->blog
 393                          )
 394                  );
 395                  break;
 396              case 'edit':
 397                  $manager->notify('EditItemFormExtras',
 398                          array(
 399                              'variables' => $this->variables,
 400                              'blog' => &$this->blog,
 401                              'itemid' => $this->variables['itemid']
 402                          )
 403                  );
 404                  break;
 405          }
 406      }
 407  
 408      /**

 409       * Adds the itemOptions of a plugin to a page

 410       * @author TeRanEX

 411       */
 412  	function parse_itemoptions() {
 413          global $itemid;
 414          ADMIN::_insertPluginOptions('item', $itemid);
 415      }
 416  
 417  	function parse_ticket() {
 418          global $manager;
 419          $manager->addTicketHidden();
 420      }
 421  
 422      /**

 423       * convenience method

 424       */
 425  	function _jsbutton($type, $code ,$tooltip) {
 426      ?>
 427              <span class="jsbutton"
 428                  onmouseover="BtnHighlight(this);"
 429                  onmouseout="BtnNormal(this);"
 430                  onclick="<?php echo $code?>" >
 431                  <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" title="<?php echo $tooltip?>" width="16" height="16"/>
 432              </span>
 433      <?php    }
 434  
 435  	function _jsbuttonspacer() {
 436          echo '<span class="jsbuttonspacer"></span>';
 437      }
 438  
 439  }
 440  
 441   ?>


Generated: Sun Aug 1 03:56:06 2010
Open Source related documentation for developers.