[ Index ]

PHP Cross Reference of Nucleus CMS 3.32

title

Body

[close]

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

   1  <?php
   2  /*
   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
   4   * Copyright (C) 2002-2007 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-2007 The Nucleus Group
  15   * @version $Id: PAGEFACTORY.php 1187 2007-08-06 14:43:00Z kaigreve $
  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          );
  81  
  82          // TODO: maybe add 'skin' later on?
  83          // TODO: maybe add other pages from admin area
  84          $this->allowedTypes = Array('bookmarklet','admin');
  85      }
  86  
  87      /**
  88       * creates a "add item" form for a given type of page
  89       *
  90       * @param type
  91       *        'admin' or 'bookmarklet'
  92       */
  93  	function createAddForm($type, $contents = array()) {
  94          if (!in_array($type, $this->allowedTypes))
  95              return;
  96          $this->type = $type;
  97          $this->method = 'add';
  98  
  99          global $manager;
 100          $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));
 101  
 102          $this->createForm($contents);
 103      }
 104  
 105      /**
 106       * creates a "add item" form for a given type of page
 107       *
 108       * @param type
 109       *        'admin' or 'bookmarklet'
 110       * @param contents
 111       *        An associative array
 112       *            'author' => author
 113       *            '' =>
 114       */
 115  	function createEditForm($type, $contents) {
 116          if (!in_array($type, $this->allowedTypes))
 117              return;
 118          $this->type = $type;
 119          $this->method = 'edit';
 120          $this->createForm($contents);
 121      }
 122  
 123      /**
 124       * (private) creates a form for a given type of page
 125       */
 126  	function createForm($contents) {
 127          // save contents
 128          $this->variables = $contents;
 129  
 130          // get template to use
 131          $template = $this->getTemplateFor($this->type);
 132  
 133          // use the PARSER engine to parse that template
 134          $parser =& new PARSER($this->actions, $this);
 135          $parser->parse($template);
 136      }
 137  
 138      /**
 139       * returns an appropriate template
 140       */
 141  	function getTemplateFor($type) {
 142          global $DIR_LIBS;
 143  
 144          $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';
 145  
 146          if (!file_exists($filename))
 147              return '';
 148  
 149          $fsize = filesize($filename);
 150          if ($fsize <= 0)
 151              return '';
 152  
 153          // read file and return it
 154          $fd = fopen ($filename, 'r');
 155          $contents = fread ($fd, $fsize);
 156          fclose ($fd);
 157  
 158          return $contents;
 159  
 160      }
 161  
 162      // create category dropdown box
 163  	function parse_categories($startidx = 0) {
 164              if ($this->variables['catid'])
 165                  $catid = $this->variables['catid'];                // on edit item
 166              else
 167                  $catid = $this->blog->getDefaultCategory();        // on add item
 168  
 169              ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());
 170      }
 171  
 172  	function parse_blogid() {
 173          echo $this->blog->getID();
 174      }
 175  
 176  	function parse_blogname() {
 177          echo $this->blog->getName();
 178      }
 179  
 180  	function parse_bloglink() {
 181          echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.htmlspecialchars($this->blog->getName()).'</a>';
 182      }
 183  
 184  	function parse_authorname() {
 185          // don't use on add item?
 186          global $member;
 187          echo $member->getDisplayName();
 188      }
 189  
 190  	function parse_title() {
 191          echo $this->contents['title'];
 192      }
 193  
 194      /**
 195       * Indicates the start of a conditional block of data. It will be added to
 196       * the output only if the blogsetting with the given name equals the
 197       * given value (default for value = 1 = true)
 198       *
 199       * the name of the blogsetting is the column name in the nucleus_blog table
 200       *
 201       * the conditional block ends with an <endif> var
 202       */
 203  	function parse_ifblogsetting($name,$value=1) {
 204          $this->_addIfCondition(($this->blog->getSetting($name) == $value));
 205      }
 206  
 207  	function parse_ifitemproperty($name,$value=1) {
 208          $this->_addIfCondition(($this->variables[$name] == $value));
 209      }
 210  
 211  	function parse_helplink($topic) {
 212          help($topic);
 213      }
 214  
 215      // for future items
 216  	function parse_currenttime($what) {
 217          $nu = getdate($this->blog->getCorrectTime());
 218          echo $nu[$what];
 219      }
 220  
 221      // date change on edit item
 222  	function parse_itemtime($what) {
 223          $itemtime = getdate($this->variables['timestamp']);
 224          echo $itemtime[$what];
 225      }
 226  
 227      // some init stuff for all forms
 228  	function parse_init() {
 229          $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
 230          $this->blog->insertJavaScriptInfo($authorid);
 231      }
 232  
 233      // on bookmarklets only: insert extra html header information (by plugins)
 234  	function parse_extrahead() {
 235          global $manager;
 236  
 237          $extrahead = '';
 238  
 239          $manager->notify(
 240              'BookmarkletExtraHead',
 241              array(
 242                  'extrahead' => &$extrahead
 243              )
 244          );
 245  
 246          echo $extrahead;
 247      }
 248  
 249      // inserts some localized text
 250  	function parse_text($which) {
 251          // constant($which) only available from 4.0.4 :(
 252          if (defined($which)) {
 253              eval("echo $which;");
 254          } else {
 255              echo $which;    // this way we see where definitions are missing
 256          }
 257  
 258      }
 259  
 260  	function parse_contents($which) {
 261          echo htmlspecialchars($this->variables[$which],ENT_QUOTES);
 262      }
 263  
 264  	function parse_checkedonval($value, $name) {
 265          if ($this->variables[$name] == $value)
 266              echo "checked='checked'";
 267      }
 268  
 269      // extra javascript for input and textarea fields
 270  	function parse_jsinput($which) {
 271          global $CONF;
 272      ?>
 273              name="<?php echo $which?>"
 274              id="input<?php echo $which?>"
 275      <?php
 276          if ($CONF['DisableJsTools'] != 1) {
 277      ?>
 278              onkeyup="storeCaret(this); updPreview('<?php echo $which?>'); doMonitor();"
 279              onclick="storeCaret(this);"
 280              onselect="storeCaret(this);"
 281  
 282      <?php
 283          }
 284          else if ($CONF['DisableJsTools'] == 0) {
 285      ?>
 286              onkeyup="doMonitor();"
 287              onkeypress="shortCuts();"
 288      <?php
 289          }
 290          else {
 291      ?>
 292              onkeyup="doMonitor();"
 293      <?php
 294          }
 295      }
 296  
 297      // shows the javascript button bar
 298  	function parse_jsbuttonbar($extrabuttons = "") {
 299          global $CONF;
 300          switch($CONF['DisableJsTools'])    {
 301  
 302              case "0":
 303                  echo '<div class="jsbuttonbar">';
 304  
 305                      $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");
 306                      $this->_jsbutton('copy','copyThis()',_ADD_COPY_TT . " (Ctrl + C)");
 307                      $this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT . " (Ctrl + V)");
 308                      $this->_jsbuttonspacer();
 309                      $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
 310                      $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
 311                      $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
 312                      $this->_jsbuttonspacer();
 313                      $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
 314                      $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
 315                      $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
 316                      $this->_jsbuttonspacer();
 317                      $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
 318                      $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
 319  
 320  
 321                      if ($extrabuttons) {
 322                          $btns = explode('+',$extrabuttons);
 323                          $this->_jsbuttonspacer();
 324                          foreach ($btns as $button) {
 325                              switch($button) {
 326                                  case "media":
 327                                      $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT .    " (Ctrl + Shift + M)");
 328                                      break;
 329                                  case "preview":
 330                                      $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
 331                                      break;
 332                              }
 333                          }
 334                      }
 335  
 336                  echo '</div>';
 337  
 338                  break;
 339              case "2":
 340                  echo '<div class="jsbuttonbar">';
 341  
 342                      $this->_jsbutton('bold',"boldThis()",'');
 343                      $this->_jsbutton('italic',"italicThis()",'');
 344                      $this->_jsbutton('link',"ahrefThis()",'');
 345                      $this->_jsbuttonspacer();
 346                      $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
 347                      $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
 348                      $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
 349                      $this->_jsbuttonspacer();
 350                      $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
 351                      $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
 352  
 353  
 354                      if ($extrabuttons) {
 355                          $btns = explode('+',$extrabuttons);
 356                          $this->_jsbuttonspacer();
 357                          foreach ($btns as $button) {
 358                              switch($button) {
 359                                  case "media":
 360                                      $this->_jsbutton('media',"addMedia()",'');
 361                                      break;
 362                              }
 363                          }
 364                      }
 365  
 366                  echo '</div>';
 367  
 368                  break;
 369          }
 370      }
 371  
 372      /**
 373       * Allows plugins to add their own custom fields
 374       */
 375  	function parse_pluginextras() {
 376          global $manager;
 377  
 378          switch ($this->method) {
 379              case 'add':
 380                  $manager->notify('AddItemFormExtras',
 381                          array(
 382                              'blog' => &$this->blog
 383                          )
 384                  );
 385                  break;
 386              case 'edit':
 387                  $manager->notify('EditItemFormExtras',
 388                          array(
 389                              'variables' => $this->variables,
 390                              'blog' => &$this->blog,
 391                              'itemid' => $this->variables['itemid']
 392                          )
 393                  );
 394                  break;
 395          }
 396      }
 397  
 398      /**
 399       * Adds the itemOptions of a plugin to a page
 400       * @author TeRanEX
 401       */
 402  	function parse_itemoptions() {
 403          global $itemid;
 404          ADMIN::_insertPluginOptions('item', $itemid);
 405      }
 406  
 407  	function parse_ticket() {
 408          global $manager;
 409          $manager->addTicketHidden();
 410      }
 411  
 412      /**
 413       * convenience method
 414       */
 415  	function _jsbutton($type, $code ,$tooltip) {
 416      ?>
 417              <span class="jsbutton"
 418                  onmouseover="BtnHighlight(this);"
 419                  onmouseout="BtnNormal(this);"
 420                  onclick="<?php echo $code?>" >
 421                  <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" width="16" height="16"/>
 422              </span>
 423      <?php    }
 424  
 425  	function _jsbuttonspacer() {
 426          echo '<span class="jsbuttonspacer"></span>';
 427      }
 428  
 429  }
 430  
 431   ?>


Generated: Tue Feb 12 15:34:36 2008 Cross-referenced by PHPXref 0.7