| [ Index ] |
PHP Cross Reference of Nucleus CMS 3.32 |
[Summary view] [Print] [Text view]
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 * This class to parse item templates 14 * 15 * @license http://nucleuscms.org/license.txt GNU General Public License 16 * @copyright Copyright (C) 2002-2007 The Nucleus Group 17 * @version $Id: ITEMACTIONS.php 1149 2007-05-19 23:16:15Z kaigreve $ 18 */ 19 class ITEMACTIONS extends BaseActions { 20 21 // contains an assoc array with parameters that need to be included when 22 // generating links to items/archives/... (e.g. catid) 23 var $linkparams; 24 25 // true when the current user is a blog admin (and thus allowed to edit all items) 26 var $allowEditAll; 27 28 // timestamp of last visit 29 var $lastVisit; 30 31 // item currently being handled (mysql result object, see BLOG::showUsingQuery) 32 var $currentItem; 33 34 // reference to the blog currently being displayed 35 var $blog; 36 37 // associative array with template info (part name => contents) 38 var $template; 39 40 // true when comments need to be displayed 41 var $showComments; 42 43 function ITEMACTIONS(&$blog) { 44 // call constructor of superclass first 45 $this->BaseActions(); 46 47 // extra parameters for created links 48 global $catid; 49 if ($catid) 50 $this->linkparams = array('catid' => $catid); 51 52 // check if member is blog admin (and thus allowed to edit all items) 53 global $member; 54 $this->allowEditAll = ($member->isLoggedIn() && $member->blogAdminRights($blog->getID())); 55 $this->setBlog($blog); 56 } 57 58 function getDefinedActions() { 59 return array( 60 'blogid', 61 'title', 62 'body', 63 'more', 64 'smartbody', 65 'itemid', 66 'morelink', 67 'category', 68 'categorylink', 69 'author', 70 'authorid', 71 'authorlink', 72 'catid', 73 'karma', 74 'date', 75 'time', 76 'query', 77 'itemlink', 78 'blogurl', 79 'closed', 80 'syndicate_title', 81 'syndicate_description', 82 'karmaposlink', 83 'karmaneglink', 84 'new', 85 'image', 86 'popup', 87 'media', 88 'daylink', 89 'query', 90 'include', 91 'phpinclude', 92 'parsedinclude', 93 'skinfile', 94 'set', 95 'plugin', 96 'edit', 97 'editlink', 98 'editpopupcode', 99 'comments', 100 'relevance'/*, 101 'if', 102 'else', 103 'endif', 104 'elseif', 105 'ifnot', 106 'elseifnot'*/ 107 ); 108 } 109 110 function setLastVisit($lastVisit) { 111 $this->lastVisit = $lastVisit; 112 } 113 114 function setParser(&$parser) { 115 $this->parser =& $parser; 116 } 117 118 function setCurrentItem(&$item) { 119 $this->currentItem =& $item; 120 } 121 122 function setBlog(&$blog) { 123 $this->blog =& $blog; 124 } 125 126 function setTemplate($template) { 127 $this->template =& $template; 128 } 129 130 function setShowComments($val) { 131 $this->showComments = $val; 132 } 133 134 // methods used by parser to insert content 135 136 function parse_blogid() { 137 echo $this->blog->getID(); 138 } 139 140 function parse_body() { 141 $this->highlightAndParse($this->currentItem->body); 142 } 143 144 function parse_more() { 145 $this->highlightAndParse($this->currentItem->more); 146 } 147 148 function parse_itemid() { 149 echo $this->currentItem->itemid; 150 } 151 152 function parse_category() { 153 echo $this->currentItem->category; 154 } 155 156 function parse_categorylink() { 157 echo createLink('category', array('catid' => $this->currentItem->catid, 'name' => $this->currentItem->category)); 158 } 159 160 function parse_catid() { 161 echo $this->currentItem->catid; 162 } 163 164 function parse_authorid() { 165 echo $this->currentItem->authorid; 166 } 167 168 function parse_authorlink() { 169 echo createLink( 170 'member', 171 array( 172 'memberid' => $this->currentItem->authorid, 173 'name' => $this->currentItem->author, 174 'extra' => $this->linkparams 175 ) 176 ); 177 } 178 179 function parse_query() { 180 echo $this->strHighlight; 181 } 182 183 function parse_itemlink() { 184 echo createLink( 185 'item', 186 array( 187 'itemid' => $this->currentItem->itemid, 188 'title' => $this->currentItem->title, 189 'timestamp' => $this->currentItem->timestamp, 190 'extra' => $this->linkparams 191 ) 192 ); 193 } 194 195 function parse_blogurl() { 196 echo $this->blog->getURL(); 197 } 198 199 function parse_closed() { 200 echo $this->currentItem->closed; 201 } 202 203 function parse_relevance() { 204 echo round($this->currentItem->score,2); 205 } 206 207 function parse_title($format = '') { 208 switch ($format) { 209 case 'xml': 210 echo stringToXML ($this->currentItem->title); 211 break; 212 case 'attribute': 213 echo stringToAttribute ($this->currentItem->title); 214 break; 215 case 'raw': 216 echo $this->currentItem->title; 217 break; 218 default: 219 $this->highlightAndParse($this->currentItem->title); 220 break; 221 } 222 } 223 224 function parse_karma($type = 'totalscore') { 225 global $manager; 226 227 // get karma object 228 $karma =& $manager->getKarma($this->currentItem->itemid); 229 230 switch($type) { 231 case 'pos': 232 echo $karma->getNbPosVotes(); 233 break; 234 case 'neg': 235 echo $karma->getNbNegVotes(); 236 break; 237 case 'votes': 238 echo $karma->getNbOfVotes(); 239 break; 240 case 'posp': 241 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50; 242 echo number_format($percentage,2), '%'; 243 break; 244 case 'negp': 245 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50; 246 echo number_format($percentage,2), '%'; 247 break; 248 case 'totalscore': 249 default: 250 echo $karma->getTotalScore(); 251 break; 252 } 253 254 } 255 256 function parse_author($which = '') { 257 switch($which) 258 { 259 case 'realname': 260 echo $this->currentItem->authorname; 261 break; 262 case 'id': 263 echo $this->currentItem->authorid; 264 break; 265 case 'email': 266 echo $this->currentItem->authormail; 267 break; 268 case 'url': 269 echo $this->currentItem->authorurl; 270 break; 271 case 'name': 272 default: 273 echo $this->currentItem->author; 274 } 275 } 276 277 function parse_smartbody() { 278 if (!$this->currentItem->more) { 279 $this->highlightAndParse($this->currentItem->body); 280 } else { 281 $this->highlightAndParse($this->currentItem->more); 282 } 283 } 284 285 function parse_morelink() { 286 if ($this->currentItem->more) 287 $this->parser->parse($this->template['MORELINK']); 288 } 289 290 function parse_date($format = '') { 291 echo formatDate($format, $this->currentItem->timestamp, $this->template['FORMAT_DATE'], $this->blog); 292 } 293 294 /** 295 * @param format optional strftime format 296 */ 297 function parse_time($format = '') { 298 echo strftime($format ? $format : $this->template['FORMAT_TIME'],$this->currentItem->timestamp); 299 } 300 301 /** 302 * @param maxLength optional maximum length 303 */ 304 function parse_syndicate_title($maxLength = 100) { 305 $syndicated = strip_tags($this->currentItem->title); 306 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES); 307 } 308 309 /** 310 * @param maxLength optional maximum length 311 */ 312 function parse_syndicate_description($maxLength = 250, $addHighlight = 0) { 313 $syndicated = strip_tags($this->currentItem->body); 314 if ($addHighlight) { 315 $tmp_highlight = htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES); 316 echo $this->highlightAndParse($tmp_highlight); 317 } else { 318 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES); 319 } 320 } 321 322 function parse_karmaposlink($text = '') { 323 global $CONF; 324 $link = $CONF['ActionURL'] . '?action=votepositive&itemid='.$this->currentItem->itemid; 325 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link; 326 } 327 328 function parse_karmaneglink($text = '') { 329 global $CONF; 330 $link = $CONF['ActionURL'] . '?action=votenegative&itemid='.$this->currentItem->itemid; 331 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link; 332 } 333 334 function parse_new() { 335 if (($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit)) 336 echo $this->template['NEW']; 337 } 338 339 340 function parse_daylink() { 341 echo createArchiveLink($this->blog->getID(), strftime('%Y-%m-%d',$this->currentItem->timestamp), $this->linkparams); 342 } 343 344 function parse_comments($maxToShow = 0) { 345 if ($maxToShow == 0) 346 $maxToShow = $this->blog->getMaxComments(); 347 348 // add comments 349 if ($this->showComments && $this->blog->commentsEnabled()) { 350 $comments =& new COMMENTS($this->currentItem->itemid); 351 $comments->setItemActions($this); 352 $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight); 353 } 354 } 355 356 /** 357 * Executes a plugin templatevar 358 * 359 * @param pluginName name of plugin (without the NP_) 360 * 361 * extra parameters can be added 362 */ 363 function parse_plugin($pluginName) { 364 global $manager; 365 366 // only continue when the plugin is really installed 367 if (!$manager->pluginInstalled('NP_' . $pluginName)) 368 return; 369 370 $plugin =& $manager->getPlugin('NP_' . $pluginName); 371 if (!$plugin) return; 372 373 // get arguments 374 $params = func_get_args(); 375 376 // remove plugin name 377 array_shift($params); 378 379 // add item reference (array_unshift didn't work) 380 $params = array_merge(array(&$this->currentItem),$params); 381 382 call_user_func_array(array(&$plugin,'doTemplateVar'), $params); 383 } 384 385 function parse_edit() { 386 global $member, $CONF; 387 if ($this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) ) { 388 $this->parser->parse($this->template['EDITLINK']); 389 } 390 } 391 392 function parse_editlink() { 393 global $CONF; 394 echo $CONF['AdminURL'],'bookmarklet.php?action=edit&itemid=',$this->currentItem->itemid; 395 } 396 397 function parse_editpopupcode() { 398 echo "if (event && 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;"; 399 } 400 401 // helper functions 402 403 /** 404 * Parses highlighted text, with limited actions only (to prevent not fully trusted team members 405 * from hacking your weblog. 406 * 'plugin variables in items' implementation by Andy 407 */ 408 function highlightAndParse(&$data) { 409 $actions =& new BODYACTIONS($this->blog); 410 $parser =& new PARSER($actions->getDefinedActions(), $actions); 411 $actions->setTemplate($this->template); 412 $actions->setHighlight($this->strHighlight); 413 $actions->setCurrentItem($this->currentItem); 414 //$actions->setParser($parser); 415 $parser->parse($actions->highlight($data)); 416 } 417 418 /* 419 // this is the function previous to the 'plugin variables in items' implementation by Andy 420 function highlightAndParse(&$data) { 421 // allow only a limited subset of actions (do not allow includes etc, they might be evil) 422 $this->parser->actions = array('image','media','popup'); 423 $tmp_highlight = $this->highlight($data); 424 $this->parser->parse($tmp_highlight); 425 $this->parser->actions = $this->getDefinedActions(); 426 } 427 */ 428 429 } 430 431 432 433 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Feb 12 15:34:36 2008 | Cross-referenced by PHPXref 0.7 |