[ Index ]

PHP Cross Reference of Nucleus CMS v3.51 code documentation

title

Body

[close]

/nucleus/libs/ -> ACTIONS.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   * This class contains the functions that get called by using

  14   * the special tags in the skins

  15   *

  16   * The allowed tags for a type of skinpart are defined by the

  17   * SKIN::getAllowedActionsForType($type) method

  18   *

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

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

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

  22   */
  23  
  24  class ACTIONS extends BaseActions {
  25  
  26      // part of the skin currently being parsed ('index', 'item', 'archive',

  27      // 'archivelist', 'member', 'search', 'error', 'imagepopup')

  28      var $skintype;
  29  
  30      // contains an assoc array with parameters that need to be included when

  31      // generating links to items/archives/... (e.g. catid)

  32      var $linkparams;
  33  
  34      // reference to the skin object for which a part is being parsed

  35      var $skin;
  36  
  37      // used when including templated forms from the include/ dir. The $formdata var

  38      // contains the values to fill out in there (assoc array name -> value)

  39      var $formdata;
  40  
  41      // filled out with the number of displayed items after calling one of the

  42      // (other)blog/(other)searchresults skinvars.

  43      var $amountfound;
  44  
  45      /**

  46       * Constructor for a new ACTIONS object

  47       */
  48  	function ACTIONS($type) {
  49          // call constructor of superclass first

  50          $this->BaseActions();
  51  
  52          $this->skintype = $type;
  53  
  54          global $catid;
  55          if ($catid)
  56              $this->linkparams = array('catid' => $catid);
  57      }
  58  
  59      /**

  60       *  Set the skin

  61       */
  62  	function setSkin(&$skin) {
  63          $this->skin =& $skin;
  64      }
  65  
  66      /**

  67       *  Set the parser

  68       */
  69  	function setParser(&$parser) {
  70          $this->parser =& $parser;
  71      }
  72  
  73      /**

  74       *    Forms get parsedincluded now, using an extra <formdata> skinvar

  75      */
  76  	function doForm($filename) {
  77          global $DIR_NUCLEUS;
  78          array_push($this->parser->actions,'formdata','text','callback','errordiv','ticket');
  79          $oldIncludeMode = PARSER::getProperty('IncludeMode');
  80          $oldIncludePrefix = PARSER::getProperty('IncludePrefix');
  81          PARSER::setProperty('IncludeMode','normal');
  82          PARSER::setProperty('IncludePrefix','');
  83          $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
  84          PARSER::setProperty('IncludeMode',$oldIncludeMode);
  85          PARSER::setProperty('IncludePrefix',$oldIncludePrefix);
  86          array_pop($this->parser->actions);        // errordiv

  87          array_pop($this->parser->actions);        // callback

  88          array_pop($this->parser->actions);        // text

  89          array_pop($this->parser->actions);        // formdata

  90          array_pop($this->parser->actions);        // ticket

  91      }
  92  
  93      /**

  94       * Checks conditions for if statements

  95       *

  96       * @param string $field type of <%if%>

  97       * @param string $name property of field

  98       * @param string $value value of property

  99       */
 100  	function checkCondition($field, $name='', $value = '') {
 101          global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
 102  
 103          $condition = 0;
 104          switch($field) {
 105              case 'category':
 106                  $condition = ($blog && $this->_ifCategory($name,$value));
 107                  break;
 108              case 'blogsetting':
 109                  $condition = ($blog && ($blog->getSetting($name) == $value));
 110                  break;
 111              case 'loggedin':
 112                  $condition = $member->isLoggedIn();
 113                  break;
 114              case 'onteam':
 115                  $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
 116                  break;
 117              case 'admin':
 118                  $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
 119                  break;
 120              case 'nextitem':
 121                  $condition = ($itemidnext != '');
 122                  break;
 123              case 'previtem':
 124                  $condition = ($itemidprev != '');
 125                  break;
 126              case 'archiveprevexists':
 127                  $condition = ($archiveprevexists == true);
 128                  break;
 129              case 'archivenextexists':
 130                  $condition = ($archivenextexists == true);
 131                  break;
 132              case 'skintype':
 133                  $condition = ($name == $this->skintype);
 134                  break;
 135              case 'hasplugin':
 136                  $condition = $this->_ifHasPlugin($name, $value);
 137                  break;
 138              default:
 139                  $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
 140                  break;
 141          }
 142          return $condition;
 143      }
 144  
 145      /**

 146       *    hasplugin,PlugName

 147       *       -> checks if plugin exists

 148       *    hasplugin,PlugName,OptionName

 149       *       -> checks if the option OptionName from plugin PlugName is not set to 'no'

 150       *    hasplugin,PlugName,OptionName=value

 151       *       -> checks if the option OptionName from plugin PlugName is set to value

 152       */
 153  	function _ifHasPlugin($name, $value) {
 154          global $manager;
 155          $condition = false;
 156          // (pluginInstalled method won't write a message in the actionlog on failure)

 157          if ($manager->pluginInstalled('NP_'.$name)) {
 158              $plugin =& $manager->getPlugin('NP_' . $name);
 159              if ($plugin != NULL) {
 160                  if ($value == "") {
 161                      $condition = true;
 162                  } else {
 163                      list($name2, $value2) = explode('=', $value, 2);
 164                      if ($value2 == "" && $plugin->getOption($name2) != 'no') {
 165                          $condition = true;
 166                      } else if ($plugin->getOption($name2) == $value2) {
 167                          $condition = true;
 168                      }
 169                  }
 170              }
 171          }
 172          return $condition;
 173      }
 174  
 175      /**

 176       * Checks if a plugin exists and call its doIf function

 177       */
 178  	function _ifPlugin($name, $key = '', $value = '') {
 179          global $manager;
 180  
 181          $plugin =& $manager->getPlugin('NP_' . $name);
 182          if (!$plugin) return;
 183  
 184          $params = func_get_args();
 185          array_shift($params);
 186  
 187          return call_user_func_array(array(&$plugin, 'doIf'), $params);
 188      }
 189  
 190      /**

 191       *  Different checks for a category

 192       */
 193  	function _ifCategory($name = '', $value='') {
 194          global $blog, $catid;
 195  
 196          // when no parameter is defined, just check if a category is selected

 197          if (($name != 'catname' && $name != 'catid') || ($value == ''))
 198              return $blog->isValidCategory($catid);
 199  
 200          // check category name

 201          if ($name == 'catname') {
 202              $value = $blog->getCategoryIdFromName($value);
 203              if ($value == $catid)
 204                  return $blog->isValidCategory($catid);
 205          }
 206  
 207          // check category id

 208          if (($name == 'catid') && ($value == $catid))
 209              return $blog->isValidCategory($catid);
 210  
 211          return false;
 212      }
 213  
 214      /**

 215       *  Checks if a member is on the team of a blog and return his rights

 216       */
 217  	function _ifOnTeam($blogName = '') {
 218          global $blog, $member, $manager;
 219  
 220          // when no blog found

 221          if (($blogName == '') && (!is_object($blog)))
 222              return 0;
 223  
 224          // explicit blog selection

 225          if ($blogName != '')
 226              $blogid = getBlogIDFromName($blogName);
 227  
 228          if (($blogName == '') || !$manager->existsBlogID($blogid))
 229              // use current blog

 230              $blogid = $blog->getID();
 231  
 232          return $member->teamRights($blogid);
 233      }
 234  
 235      /**

 236       *  Checks if a member is admin of a blog

 237       */
 238  	function _ifAdmin($blogName = '') {
 239          global $blog, $member, $manager;
 240  
 241          // when no blog found

 242          if (($blogName == '') && (!is_object($blog)))
 243              return 0;
 244  
 245          // explicit blog selection

 246          if ($blogName != '')
 247              $blogid = getBlogIDFromName($blogName);
 248  
 249          if (($blogName == '') || !$manager->existsBlogID($blogid))
 250              // use current blog

 251              $blogid = $blog->getID();
 252  
 253          return $member->isBlogAdmin($blogid);
 254      }
 255      
 256      /**

 257       * returns either

 258       *        - a raw link (html/xml encoded) when no linktext is provided

 259       *        - a (x)html <a href... link when a text is present (text htmlencoded)

 260       */
 261  	function _link($url, $linktext = '')
 262      {
 263          $u = htmlspecialchars($url);
 264          $u = preg_replace("/&amp;amp;/",'&amp;',$u); // fix URLs that already had encoded ampersands

 265          if ($linktext != '') 
 266              $l = '<a href="' . $u .'">'.htmlspecialchars($linktext).'</a>';
 267          else
 268              $l = $u;
 269          return $l;
 270      }
 271      
 272      /**

 273       * Outputs a next/prev link

 274       *

 275       * @param $maxresults

 276       *        The maximum amount of items shown per page (e.g. 10)

 277       * @param $startpos

 278       *        Current start position (requestVar('startpos'))

 279       * @param $direction

 280       *        either 'prev' or 'next'

 281       * @param $linktext

 282       *        When present, the output will be a full <a href...> link. When empty,

 283       *        only a raw link will be outputted

 284       */
 285  	function _searchlink($maxresults, $startpos, $direction, $linktext = '') {
 286          global $CONF, $blog, $query, $amount;
 287          // TODO: Move request uri to linkparams. this is ugly. sorry for that.

 288          $startpos    = intval($startpos);        // will be 0 when empty.

 289          $parsed        = parse_url(serverVar('REQUEST_URI'));
 290          $parsed        = $parsed['query'];
 291          $url        = '';
 292  
 293          switch ($direction) {
 294              case 'prev':
 295                  if ( intval($startpos) - intval($maxresults) >= 0) {
 296                      $startpos     = intval($startpos) - intval($maxresults);
 297                      $url        = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
 298                  }
 299                  break;
 300              case 'next':
 301                  $iAmountOnPage = $this->amountfound;
 302                  if ($iAmountOnPage == 0)
 303                  {
 304                      // [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]

 305                      // try a count query

 306                      switch ($this->skintype)
 307                      {
 308                          case 'index':
 309                              $sqlquery = $blog->getSqlBlog('', 'count');
 310                              break;
 311                          case 'search':
 312                              $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
 313                              break;
 314                      }
 315                      if ($sqlquery)
 316                          $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
 317                  }
 318                  if (intval($iAmountOnPage) >= intval($maxresults)) {
 319                      $startpos     = intval($startpos) + intval($maxresults);
 320                      $url        = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
 321                  }
 322                  break;
 323              default:
 324                  break;
 325          } // switch($direction)

 326  
 327          if ($url != '')
 328              echo $this->_link($url, $linktext);
 329      }
 330  
 331      /**

 332       *  Creates an item link and if no id is given a todaylink 

 333       */
 334  	function _itemlink($id, $linktext = '') {
 335          global $CONF;
 336          if ($id)
 337              echo $this->_link(createItemLink($id, $this->linkparams), $linktext);
 338          else
 339              $this->parse_todaylink($linktext);
 340      }
 341      
 342      /**

 343       *  Creates an archive link and if no id is given a todaylink 

 344       */
 345  	function _archivelink($id, $linktext = '') {
 346          global $CONF, $blog;
 347          if ($id)
 348              echo $this->_link(createArchiveLink($blog->getID(), $id, $this->linkparams), $linktext);
 349          else
 350              $this->parse_todaylink($linktext);
 351      }
 352      
 353      /**

 354        * Helper function that sets the category that a blog will need to use

 355        *

 356        * @param $blog

 357        *        An object of the blog class, passed by reference (we want to make changes to it)

 358        * @param $catname

 359        *        The name of the category to use

 360        */
 361  	function _setBlogCategory(&$blog, $catname) {
 362          global $catid;
 363          if ($catname != '')
 364              $blog->setSelectedCategoryByName($catname);
 365          else
 366              $blog->setSelectedCategory($catid);
 367      }
 368  
 369      /**

 370       *  Notifies the Manager that a PreBlogContent event occurs

 371       */
 372  	function _preBlogContent($type, &$blog) {
 373          global $manager;
 374          $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
 375      }
 376  
 377      /**

 378       *  Notifies the Manager that a PostBlogContent event occurs

 379       */
 380  	function _postBlogContent($type, &$blog) {
 381          global $manager;
 382          $manager->notify('PostBlogContent',array('blog' => &$blog, 'type' => $type));
 383      }
 384      
 385      /**

 386       * Parse skinvar additemform

 387       */
 388  	function parse_additemform() {
 389          global $blog, $CONF;
 390          $this->formdata = array(
 391              'adminurl' => htmlspecialchars($CONF['AdminURL'],ENT_QUOTES),
 392              'catid' => $blog->getDefaultCategory()
 393          );
 394          $blog->InsertJavaScriptInfo();
 395          $this->doForm('additemform');
 396      }
 397      
 398      /**

 399       * Parse skinvar addlink

 400       * A Link that allows to open a bookmarklet to add an item

 401       */
 402  	function parse_addlink() {
 403          global $CONF, $member, $blog;
 404          if ($member->isLoggedIn() && $member->isTeamMember($blog->blogid) ) {
 405              echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
 406          }
 407      }
 408      
 409      /**

 410       * Parse skinvar addpopupcode

 411       * Code that opens a bookmarklet in an popup window

 412       */
 413  	function parse_addpopupcode() {
 414          echo "if (event &amp;&amp; event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=yes,width=600,height=500,left=10,top=10,status=yes,resizable=yes');winbm.focus();return false;";
 415      }
 416      
 417      /**

 418       * Parse skinvar adminurl

 419       * (shortcut for admin url)     

 420       */
 421  	function parse_adminurl() {
 422          $this->parse_sitevar('adminurl');
 423      }
 424  
 425      /**

 426       * Parse skinvar archive

 427       */
 428  	function parse_archive($template, $category = '') {
 429          global $blog, $archive;
 430          // can be used with either yyyy-mm or yyyy-mm-dd

 431          sscanf($archive,'%d-%d-%d',$y,$m,$d);
 432          $this->_setBlogCategory($blog, $category);
 433          $this->_preBlogContent('achive',$blog);
 434          $blog->showArchive($template, $y, $m, $d);
 435          $this->_postBlogContent('achive',$blog);
 436  
 437      }
 438  
 439      /**

 440        * %archivedate(locale,date format)%

 441        */
 442  	function parse_archivedate($locale = '-def-') {
 443          global $archive;
 444  
 445          if ($locale == '-def-')
 446              setlocale(LC_TIME,$template['LOCALE']);
 447          else
 448              setlocale(LC_TIME,$locale);
 449  
 450          // get archive date

 451          sscanf($archive,'%d-%d-%d',$y,$m,$d);
 452  
 453          // get format

 454          $args = func_get_args();
 455          // format can be spread over multiple parameters

 456          if (sizeof($args) > 1) {
 457              // take away locale

 458              array_shift($args);
 459              // implode

 460              $format=implode(',',$args);
 461          } elseif ($d == 0 && $m !=0) {
 462              $format = '%B %Y';
 463          } elseif ($m == 0) {
 464              $format = '%Y';            
 465          } else {
 466              $format = '%d %B %Y';
 467          }
 468  
 469          echo strftime($format,mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
 470      }
 471  
 472      /**

 473       *  Parse skinvar archivedaylist

 474       */         
 475  	function parse_archivedaylist($template, $category = 'all', $limit = 0) {
 476          global $blog;
 477          if ($category == 'all') $category = '';
 478          $this->_preBlogContent('archivelist',$blog);
 479          $this->_setBlogCategory($blog, $category);
 480          $blog->showArchiveList($template, 'day', $limit);
 481          $this->_postBlogContent('archivelist',$blog);
 482      }
 483      
 484      /**

 485       *    A link to the archives for the current blog (or for default blog)

 486       */
 487  	function parse_archivelink($linktext = '') {
 488          global $blog, $CONF;
 489          if ($blog)
 490              echo $this->_link(createArchiveListLink($blog->getID(),$this->linkparams), $linktext);
 491          else
 492              echo $this->_link(createArchiveListLink(), $linktext);
 493      }
 494  
 495  	function parse_archivelist($template, $category = 'all', $limit = 0) {
 496          global $blog;
 497          if ($category == 'all') $category = '';
 498          $this->_preBlogContent('archivelist',$blog);
 499          $this->_setBlogCategory($blog, $category);
 500          $blog->showArchiveList($template, 'month', $limit);
 501          $this->_postBlogContent('archivelist',$blog);
 502      }
 503          
 504  	function parse_archiveyearlist($template, $category = 'all', $limit = 0) {
 505          global $blog;
 506          if ($category == 'all') $category = '';
 507          $this->_preBlogContent('archivelist',$blog);
 508          $this->_setBlogCategory($blog, $category);
 509          $blog->showArchiveList($template, 'year', $limit);
 510          $this->_postBlogContent('archivelist',$blog);
 511      }
 512      
 513      /**

 514       * Parse skinvar archivetype

 515       */
 516  	function parse_archivetype() {
 517          global $archivetype;
 518          echo $archivetype;
 519      }
 520  
 521      /**

 522       * Parse skinvar blog

 523       */
 524  	function parse_blog($template, $amount = 10, $category = '') {
 525          global $blog, $startpos;
 526  
 527          list($limit, $offset) = sscanf($amount, '%d(%d)');
 528          $this->_setBlogCategory($blog, $category);
 529          $this->_preBlogContent('blog',$blog);
 530          $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
 531          $this->_postBlogContent('blog',$blog);
 532      }
 533      
 534      /*

 535      *    Parse skinvar bloglist

 536      *    Shows a list of all blogs

 537      *    bnametype: whether 'name' or 'shortname' is used for the link text       

 538      *    orderby: order criteria

 539      *    direction: order ascending or descending          

 540      */
 541  	function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc') {
 542          BLOG::showBlogList($template, $bnametype, $orderby, $direction);
 543      }
 544      
 545      /**

 546       * Parse skinvar blogsetting

 547       */
 548  	function parse_blogsetting($which) {
 549          global $blog;
 550          switch($which) {
 551              case 'id':
 552                  echo htmlspecialchars($blog->getID(),ENT_QUOTES);
 553                  break;
 554              case 'url':
 555                  echo htmlspecialchars($blog->getURL(),ENT_QUOTES);
 556                  break;
 557              case 'name':
 558                  echo htmlspecialchars($blog->getName(),ENT_QUOTES);
 559                  break;
 560              case 'desc':
 561                  echo htmlspecialchars($blog->getDescription(),ENT_QUOTES);
 562                  break;
 563              case 'short':
 564                  echo htmlspecialchars($blog->getShortName(),ENT_QUOTES);
 565                  break;
 566          }
 567      }
 568      
 569      /**

 570       * Parse callback

 571       */
 572  	function parse_callback($eventName, $type)
 573      {
 574          global $manager;
 575          $manager->notify($eventName, array('type' => $type));
 576      }
 577      
 578      /**

 579       * Parse skinvar category

 580       */
 581  	function parse_category($type = 'name') {
 582          global $catid, $blog;
 583          if (!$blog->isValidCategory($catid))
 584              return;
 585  
 586          switch($type) {
 587              case 'name':
 588                  echo $blog->getCategoryName($catid);
 589                  break;
 590              case 'desc':
 591                  echo $blog->getCategoryDesc($catid);
 592                  break;
 593              case 'id':
 594                  echo $catid;
 595                  break;
 596          }
 597      }
 598      
 599      /**

 600       * Parse categorylist

 601       */
 602  	function parse_categorylist($template, $blogname = '') {
 603          global $blog, $manager;
 604  
 605          if ($blogname == '') {
 606              $this->_preBlogContent('categorylist',$blog);
 607              $blog->showCategoryList($template);
 608              $this->_postBlogContent('categorylist',$blog);
 609          } else {
 610              $b =& $manager->getBlog(getBlogIDFromName($blogname));
 611              $this->_preBlogContent('categorylist',$b);
 612              $b->showCategoryList($template);
 613              $this->_postBlogContent('categorylist',$b);
 614          }
 615      }
 616      
 617      /**

 618       * Parse skinvar charset

 619       */
 620  	function parse_charset() {
 621          echo _CHARSET;
 622      }
 623      
 624      /**

 625       * Parse skinvar commentform

 626       */
 627  	function parse_commentform($destinationurl = '') {
 628          global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
 629  
 630          // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)

 631          if (stristr($destinationurl, 'action.php')) {
 632              $args = func_get_args();
 633              $destinationurl = $args[1];
 634              ACTIONLOG::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
 635          }
 636  
 637          $actionurl = $CONF['ActionURL'];
 638  
 639          // if item is closed, show message and do nothing

 640          $item =& $manager->getItem($itemid,0,0);
 641          if ($item['closed'] || !$blog->commentsEnabled()) {
 642              $this->doForm('commentform-closed');
 643              return;
 644          }
 645  
 646          if (!$destinationurl)
 647          {
 648              $destinationurl = createLink(
 649                  'item',
 650                  array(
 651                      'itemid' => $itemid,
 652                      'title' => $item['title'],
 653                      'timestamp' => $item['timestamp'],
 654                      'extra' => $this->linkparams
 655                  )
 656              );
 657  
 658              // note: createLink returns an HTML encoded URL

 659          } else {
 660              // HTML encode URL

 661              $destinationurl = htmlspecialchars($destinationurl,ENT_QUOTES);
 662          }
 663  
 664          // values to prefill

 665          $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
 666          if (!$user) $user = postVar('user');
 667          $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
 668          if (!$userid) $userid = postVar('userid');
 669          $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
 670          if (!$email) {
 671              $email = postVar('email');
 672          }
 673          $body = postVar('body');
 674  
 675          $this->formdata = array(
 676              'destinationurl' => $destinationurl,    // url is already HTML encoded
 677              'actionurl' => htmlspecialchars($actionurl,ENT_QUOTES),
 678              'itemid' => $itemid,
 679              'user' => htmlspecialchars($user,ENT_QUOTES),
 680              'userid' => htmlspecialchars($userid,ENT_QUOTES),
 681              'email' => htmlspecialchars($email,ENT_QUOTES),
 682              'body' => htmlspecialchars($body,ENT_QUOTES),
 683              'membername' => $member->getDisplayName(),
 684              'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
 685          );
 686  
 687          if (!$member->isLoggedIn()) {
 688              $this->doForm('commentform-notloggedin');
 689          } else {
 690              $this->doForm('commentform-loggedin');
 691          }
 692      }
 693      
 694      /**

 695       * Parse skinvar comments

 696       * include comments for one item     

 697       */
 698  	function parse_comments($template) {
 699          global $itemid, $manager, $blog, $highlight;
 700          $template =& $manager->getTemplate($template);
 701  
 702          // create parser object & action handler

 703          $actions =& new ITEMACTIONS($blog);
 704          $parser =& new PARSER($actions->getDefinedActions(),$actions);
 705          $actions->setTemplate($template);
 706          $actions->setParser($parser);
 707          $item = ITEM::getitem($itemid, 0, 0);
 708          $actions->setCurrentItem($item);
 709  
 710          $comments =& new COMMENTS($itemid);
 711          $comments->setItemActions($actions);
 712          $comments->showComments($template, -1, 1, $highlight);    // shows ALL comments

 713      }
 714  
 715      /**

 716       * Parse errordiv

 717       */
 718  	function parse_errordiv() {
 719          global $errormessage;
 720          if ($errormessage)
 721              echo '<div class="error">', htmlspecialchars($errormessage),'</div>';
 722      }
 723      
 724      /**

 725       * Parse skinvar errormessage

 726       */
 727  	function parse_errormessage() {
 728          global $errormessage;
 729          echo $errormessage;
 730      }
 731      
 732      /**

 733       * Parse formdata

 734       */
 735  	function parse_formdata($what) {
 736          echo $this->formdata[$what];
 737      }
 738      
 739      /**

 740       * Parse ifcat

 741       */
 742  	function parse_ifcat($text = '') {
 743          if ($text == '') {
 744              // new behaviour

 745              $this->parse_if('category');
 746          } else {
 747              // old behaviour

 748              global $catid, $blog;
 749              if ($blog->isValidCategory($catid))
 750                  echo $text;
 751          }
 752      }
 753  
 754      /**

 755       * Parse skinvar image

 756       */
 757  	function parse_image($what = 'imgtag') {
 758          global $CONF;
 759  
 760          $imagetext     = htmlspecialchars(requestVar('imagetext'));
 761          $imagepopup = requestVar('imagepopup');
 762          $width         = intRequestVar('width');
 763          $height     = intRequestVar('height');
 764          $fullurl     = htmlspecialchars($CONF['MediaURL'] . $imagepopup);
 765  
 766          switch($what)
 767          {
 768              case 'url':
 769                  echo $fullurl;
 770                  break;
 771              case 'width':
 772                  echo $width;
 773                  break;
 774              case 'height':
 775                  echo $height;
 776                  break;
 777              case 'caption':
 778              case 'text':
 779                  echo $imagetext;
 780                  break;
 781              case 'imgtag':
 782              default:
 783                  echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
 784                  break;
 785          }
 786      }
 787      
 788      /**

 789       * Parse skinvar imagetext

 790       */
 791  	function parse_imagetext() {
 792          echo htmlspecialchars(requestVar('imagetext'),ENT_QUOTES);
 793      }
 794  
 795      /**

 796       * Parse skinvar item

 797       * include one item (no comments)     

 798       */
 799  	function parse_item($template) {
 800          global $blog, $itemid, $highlight;
 801          $this->_setBlogCategory($blog, '');    // need this to select default category

 802          $this->_preBlogContent('item',$blog);
 803          $r = $blog->showOneitem($itemid, $template, $highlight);
 804          if ($r == 0)
 805              echo _ERROR_NOSUCHITEM;
 806          $this->_postBlogContent('item',$blog);
 807      }
 808  
 809      /**

 810       * Parse skinvar itemid

 811       */
 812  	function parse_itemid() {
 813          global $itemid;
 814          echo $itemid;
 815      }
 816      
 817      /**

 818       * Parse skinvar itemlink

 819       */
 820  	function parse_itemlink($linktext = '') {
 821          global $itemid;
 822          $this->_itemlink($itemid, $linktext);
 823      }
 824  
 825      /**

 826       * Parse itemtitle

 827       */
 828  	function parse_itemtitle($format = '') {
 829          global $manager, $itemid;
 830          $item =& $manager->getItem($itemid,0,0);
 831  
 832          switch ($format) {
 833              case 'xml':
 834                  echo stringToXML ($item['title']);
 835                  break;
 836              case 'attribute':
 837                  echo stringToAttribute ($item['title']);
 838                  break;
 839              case 'raw':
 840                  echo $item['title'];
 841                  break;
 842              default:
 843                  echo htmlspecialchars(strip_tags($item['title']),ENT_QUOTES);
 844                  break;
 845          }
 846      }
 847  
 848      /**

 849       * Parse skinvar loginform

 850       */
 851  	function parse_loginform() {
 852          global $member, $CONF;
 853          if (!$member->isLoggedIn()) {
 854              $filename = 'loginform-notloggedin';
 855              $this->formdata = array();
 856          } else {
 857              $filename = 'loginform-loggedin';
 858              $this->formdata = array(
 859                  'membername' => $member->getDisplayName(),
 860              );
 861          }
 862          $this->doForm($filename);
 863      }
 864  
 865      /**

 866       * Parse skinvar member

 867       * (includes a member info thingie)     

 868       */
 869  	function parse_member($what) {
 870          global $memberinfo, $member;
 871  
 872          // 1. only allow the member-details-page specific variables on member pages

 873          if ($this->skintype == 'member') {
 874  
 875              switch($what) {
 876                  case 'name':
 877                      echo htmlspecialchars($memberinfo->getDisplayName(),ENT_QUOTES);
 878                      break;
 879                  case 'realname':
 880                      echo htmlspecialchars($memberinfo->getRealName(),ENT_QUOTES);
 881                      break;
 882                  case 'notes':
 883                      echo htmlspecialchars($memberinfo->getNotes(),ENT_QUOTES);
 884                      break;
 885                  case 'url':
 886                      echo htmlspecialchars($memberinfo->getURL(),ENT_QUOTES);
 887                      break;
 888                  case 'email':
 889                      echo htmlspecialchars($memberinfo->getEmail(),ENT_QUOTES);
 890                      break;
 891                  case 'id':
 892                      echo htmlspecialchars($memberinfo->getID(),ENT_QUOTES);
 893                      break;
 894              }
 895          }
 896  
 897          // 2. the next bunch of options is available everywhere, as long as the user is logged in

 898          if ($member->isLoggedIn())
 899          {
 900              switch($what) {
 901                  case 'yourname':
 902                      echo $member->getDisplayName();
 903                      break;
 904                  case 'yourrealname':
 905                      echo $member->getRealName();
 906                      break;
 907                  case 'yournotes':
 908                      echo $member->getNotes();
 909                      break;
 910                  case 'yoururl':
 911                      echo $member->getURL();
 912                      break;
 913                  case 'youremail':
 914                      echo $member->getEmail();
 915                      break;
 916                  case 'yourid':
 917                      echo $member->getID();
 918                      break;
 919              }
 920          }
 921  
 922      }
 923  
 924      /**

 925       * Parse skinvar membermailform

 926       */
 927  	function parse_membermailform($rows = 10, $cols = 40, $desturl = '') {
 928          global $member, $CONF, $memberid;
 929  
 930          if ($desturl == '') {
 931              if ($CONF['URLMode'] == 'pathinfo')
 932                  $desturl = createMemberLink($memberid);
 933              else
 934                  $desturl = $CONF['IndexURL'] . createMemberLink($memberid);
 935          }
 936  
 937          $message = postVar('message');
 938          $frommail = postVar('frommail');
 939  
 940          $this->formdata = array(
 941              'url' => htmlspecialchars($desturl),
 942              'actionurl' => htmlspecialchars($CONF['ActionURL'],ENT_QUOTES),
 943              'memberid' => $memberid,
 944              'rows' => $rows,
 945              'cols' => $cols,
 946              'message' => htmlspecialchars($message,ENT_QUOTES),
 947              'frommail' => htmlspecialchars($frommail,ENT_QUOTES)
 948          );
 949          if ($member->isLoggedIn()) {
 950              $this->doForm('membermailform-loggedin');
 951          } else if ($CONF['NonmemberMail']) {
 952              $this->doForm('membermailform-notloggedin');
 953          } else {
 954              $this->doForm('membermailform-disallowed');
 955          }
 956  
 957      }
 958      
 959      /**

 960       * Parse skinvar nextarchive

 961       */
 962  	function parse_nextarchive() {
 963          global $archivenext;
 964          echo $archivenext;
 965      }
 966  
 967      /**

 968       * Parse skinvar nextitem

 969       * (include itemid of next item)

 970       */
 971  	function parse_nextitem() {
 972          global $itemidnext;
 973          if (isset($itemidnext)) echo (int)$itemidnext;
 974      }
 975  
 976      /**

 977       * Parse skinvar nextitemtitle

 978       * (include itemtitle of next item)

 979       */
 980  	function parse_nextitemtitle($format = '') {
 981          global $itemtitlenext;
 982  
 983          switch ($format) {
 984              case 'xml':
 985                  echo stringToXML ($itemtitlenext);
 986                  break;
 987              case 'attribute':
 988                  echo stringToAttribute ($itemtitlenext);
 989                  break;
 990              case 'raw':
 991                  echo $itemtitlenext;
 992                  break;
 993              default:
 994                  echo htmlspecialchars($itemtitlenext,ENT_QUOTES);
 995                  break;
 996          }
 997      }
 998  
 999      /**

1000       * Parse skinvar nextlink

1001       */
1002  	function parse_nextlink($linktext = '', $amount = 10) {
1003          global $itemidnext, $archivenext, $startpos;
1004          if ($this->skintype == 'item')
1005              $this->_itemlink($itemidnext, $linktext);
1006          else if ($this->skintype == 'search' || $this->skintype == 'index')
1007              $this->_searchlink($amount, $startpos, 'next', $linktext);
1008          else
1009              $this->_archivelink($archivenext, $linktext);
1010      }
1011  
1012      /**

1013       * Parse skinvar nucleusbutton

1014       */
1015  	function parse_nucleusbutton($imgurl = '',
1016                                   $imgwidth = '85',
1017                                   $imgheight = '31') {
1018          global $CONF;
1019          if ($imgurl == '') {
1020              $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
1021          } else if (PARSER::getProperty('IncludeMode') == 'skindir'){
1022              // when skindit IncludeMode is used: start from skindir

1023              $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl;
1024          }
1025  
1026          $this->formdata = array(
1027              'imgurl' => $imgurl,
1028              'imgwidth' => $imgwidth,
1029              'imgheight' => $imgheight,
1030          );
1031          $this->doForm('nucleusbutton');
1032      }
1033      
1034      /**

1035       * Parse skinvar otherarchive

1036       */    
1037  	function parse_otherarchive($blogname, $template, $category = '') {
1038          global $archive, $manager;
1039          sscanf($archive,'%d-%d-%d',$y,$m,$d);
1040          $b =& $manager->getBlog(getBlogIDFromName($blogname));
1041          $this->_setBlogCategory($b, $category);
1042          $this->_preBlogContent('otherachive',$b);
1043          $b->showArchive($template, $y, $m, $d);
1044          $this->_postBlogContent('otherachive',$b);
1045      }
1046      
1047      /**

1048       * Parse skinvar otherarchivedaylist

1049       */
1050  	function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) {
1051          global $manager;
1052          if ($category == 'all') $category = '';
1053          $b =& $manager->getBlog(getBlogIDFromName($blogname));
1054          $this->_setBlogCategory($b, $category);
1055          $this->_preBlogContent('otherarchivelist',$b);
1056          $b->showArchiveList($template, 'day', $limit);
1057          $this->_postBlogContent('otherarchivelist',$b);
1058      }
1059      
1060      /**

1061       * Parse skinvar otherarchivelist

1062       */
1063  	function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) {
1064          global $manager;
1065          if ($category == 'all') $category = '';
1066          $b =& $manager->getBlog(getBlogIDFromName($blogname));
1067          $this->_setBlogCategory($b, $category);
1068          $this->_preBlogContent('otherarchivelist',$b);
1069          $b->showArchiveList($template, 'month', $limit);
1070          $this->_postBlogContent('otherarchivelist',$b);
1071      }
1072          
1073      /**

1074       * Parse skinvar otherarchiveyearlist

1075       */
1076  	function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0) {
1077          global $manager;
1078          if ($category == 'all') $category = '';
1079          $b =& $manager->getBlog(getBlogIDFromName($blogname));
1080          $this->_setBlogCategory($b, $category);
1081          $this->_preBlogContent('otherarchivelist',$b);
1082          $b->showArchiveList($template, 'year', $limit);
1083          $this->_postBlogContent('otherarchivelist',$b);
1084      }    
1085      
1086      /**

1087       * Parse skinvar otherblog

1088       */
1089  	function parse_otherblog($blogname, $template, $amount = 10, $category = '') {
1090          global $manager;
1091  
1092          list($limit, $offset) = sscanf($amount, '%d(%d)');
1093  
1094          $b =& $manager->getBlog(getBlogIDFromName($blogname));
1095          $this->_setBlogCategory($b, $category);
1096          $this->_preBlogContent('otherblog',$b);
1097          $this->amountfound = $b->readLog($template, $limit, $offset);
1098          $this->_postBlogContent('otherblog',$b);
1099      }
1100  
1101      /**

1102       * Parse skinvar othersearchresults

1103       */
1104  	function parse_othersearchresults($blogname, $template, $maxresults = 50) {
1105          global $query, $amount, $manager, $startpos;
1106          $b =& $manager->getBlog(getBlogIDFromName($blogname));
1107          $this->_setBlogCategory($b, '');    // need this to select default category

1108          $this->_preBlogContent('othersearchresults',$b);
1109          $b->search($query, $template, $amount, $maxresults, $startpos);
1110          $this->_postBlogContent('othersearchresults',$b);
1111      }
1112  
1113      /**

1114        * Executes a plugin skinvar

1115        *

1116        * @param pluginName name of plugin (without the NP_)

1117        *

1118        * extra parameters can be added

1119        */
1120  	function parse_plugin($pluginName) {
1121          global $manager;
1122  
1123          // should be already tested from the parser (PARSER.php)

1124          // only continue when the plugin is really installed

1125          /*if (!$manager->pluginInstalled('NP_' . $pluginName))

1126              return;*/
1127  
1128          $plugin =& $manager->getPlugin('NP_' . $pluginName);
1129          if (!$plugin) return;
1130  
1131          // get arguments

1132          $params = func_get_args();
1133  
1134          // remove plugin name

1135          array_shift($params);
1136  
1137          // add skin type on front

1138          array_unshift($params, $this->skintype);
1139  
1140          call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1141      }
1142      
1143      /**

1144       * Parse skinvar prevarchive

1145       */
1146  	function parse_prevarchive() {
1147          global $archiveprev;
1148          echo $archiveprev;
1149      }
1150  
1151      /**

1152       * Parse skinvar preview

1153       */
1154  	function parse_preview($template) {
1155          global $blog, $CONF, $manager;
1156  
1157          $template =& $manager->getTemplate($template);
1158          $row['body'] = '<span id="prevbody"></span>';
1159          $row['title'] = '<span id="prevtitle"></span>';
1160          $row['more'] = '<span id="prevmore"></span>';
1161          $row['itemlink'] = '';
1162          $row['itemid'] = 0; $row['blogid'] = $blog->getID();
1163          echo TEMPLATE::fill($template['ITEM_HEADER'],$row);
1164          echo TEMPLATE::fill($template['ITEM'],$row);
1165          echo TEMPLATE::fill($template['ITEM_FOOTER'],$row);
1166      }
1167  
1168      /*

1169       * Parse skinvar previtem

1170       * (include itemid of prev item)          

1171       */
1172  	function parse_previtem() {
1173          global $itemidprev;
1174          if (isset($itemidprev)) echo (int)$itemidprev;
1175      }
1176  
1177      /**

1178       * Parse skinvar previtemtitle

1179       * (include itemtitle of prev item)

1180       */
1181  	function parse_previtemtitle($format = '') {
1182          global $itemtitleprev;
1183  
1184          switch ($format) {
1185              case 'xml':
1186                  echo stringToXML ($itemtitleprev);
1187                  break;
1188              case 'attribute':
1189                  echo stringToAttribute ($itemtitleprev);
1190                  break;
1191              case 'raw':
1192                  echo $itemtitleprev;
1193                  break;
1194              default:
1195                  echo htmlspecialchars($itemtitleprev,ENT_QUOTES);
1196                  break;
1197          }
1198      }
1199  
1200      /**

1201       * Parse skinvar prevlink

1202       */
1203  	function parse_prevlink($linktext = '', $amount = 10) {
1204          global $itemidprev, $archiveprev, $startpos;
1205  
1206          if ($this->skintype == 'item')
1207              $this->_itemlink($itemidprev, $linktext);
1208          else if ($this->skintype == 'search' || $this->skintype == 'index')
1209              $this->_searchlink($amount, $startpos, 'prev', $linktext);
1210          else
1211              $this->_archivelink($archiveprev, $linktext);
1212      }
1213  
1214      /**

1215       * Parse skinvar query

1216       * (includes the search query)     

1217       */
1218  	function parse_query() {
1219          global $query;
1220          echo htmlspecialchars($query,ENT_QUOTES);
1221      }
1222      
1223      /**

1224       * Parse skinvar referer

1225       */
1226  	function parse_referer() {
1227          echo htmlspecialchars(serverVar('HTTP_REFERER'),ENT_QUOTES);
1228      }
1229  
1230      /**

1231       * Parse skinvar searchform

1232       */
1233  	function parse_searchform($blogname = '') {
1234          global $CONF, $manager, $maxresults;
1235          if ($blogname) {
1236              $blog =& $manager->getBlog(getBlogIDFromName($blogname));
1237          } else {
1238              global $blog;
1239          }
1240          // use default blog when no blog is selected

1241          $this->formdata = array(
1242              'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
1243              'query' => htmlspecialchars(getVar('query'),ENT_QUOTES),
1244          );
1245          $this->doForm('searchform');
1246      }
1247  
1248      /**

1249       * Parse skinvar searchresults

1250       */
1251  	function parse_searchresults($template, $maxresults = 50 ) {
1252          global $blog, $query, $amount, $startpos;
1253  
1254          $this->_setBlogCategory($blog, '');    // need this to select default category

1255          $this->_preBlogContent('searchresults',$blog);
1256          $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
1257          $this->_postBlogContent('searchresults',$blog);
1258      }
1259  
1260      /**

1261       * Parse skinvar self

1262       */
1263  	function parse_self() {
1264          global $CONF;
1265          echo $CONF['Self'];
1266      }
1267  
1268      /**

1269       * Parse skinvar sitevar

1270       * (include a sitevar)     

1271       */
1272  	function parse_sitevar($which) {
1273          global $CONF;
1274          switch($which) {
1275              case 'url':
1276                  echo $CONF['IndexURL'];
1277                  break;
1278              case 'name':
1279                  echo $CONF['SiteName'];
1280                  break;
1281              case 'admin':
1282                  echo $CONF['AdminEmail'];
1283                  break;
1284              case 'adminurl':
1285                  echo $CONF['AdminURL'];
1286          }
1287      }
1288  
1289      /**

1290       * Parse skinname

1291       */
1292  	function parse_skinname() {
1293          echo $this->skin->getName();
1294      }
1295      
1296      /**

1297       * Parse skintype (experimental)

1298       */
1299  	function parse_skintype() {
1300          echo $this->skintype;
1301      }
1302  
1303      /**

1304       * Parse text

1305       */
1306  	function parse_text($which) {
1307          // constant($which) only available from 4.0.4 :(

1308          if (defined($which)) {
1309              eval("echo $which;");
1310          }
1311      }
1312      
1313      /**

1314       * Parse ticket

1315       */
1316  	function parse_ticket() {
1317          global $manager;
1318          $manager->addTicketHidden();
1319      }
1320  
1321      /**

1322       *    Parse skinvar todaylink

1323       *    A link to the today page (depending on selected blog, etc...)

1324       */
1325  	function parse_todaylink($linktext = '') {
1326          global $blog, $CONF;
1327          if ($blog)
1328              echo $this->_link(createBlogidLink($blog->getID(),$this->linkparams), $linktext);
1329          else
1330              echo $this->_link($CONF['SiteUrl'], $linktext);
1331      }
1332  
1333      /**

1334       * Parse vars

1335       * When commentform is not used, to include a hidden field with itemid     

1336       */
1337  	function parse_vars() {
1338          global $itemid;
1339          echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';
1340      }
1341  
1342      /**

1343       * Parse skinvar version

1344       * (include nucleus versionnumber)     

1345       */
1346  	function parse_version() {
1347          global $nucleus;
1348          echo 'Nucleus CMS ' . $nucleus['version'];
1349      }
1350      
1351      /**

1352       * Parse skinvar sticky

1353       */
1354  	function parse_sticky($itemnumber = 0, $template = '') {
1355          global $manager;
1356          
1357          $itemnumber = intval($itemnumber);
1358          $itemarray = array($itemnumber);
1359  
1360          $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
1361          $this->_preBlogContent('sticky',$b);
1362          $this->amountfound = $b->readLogFromList($itemarray, $template);
1363          $this->_postBlogContent('sticky',$b);
1364      }
1365  
1366  
1367  }
1368  ?>


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