3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 The Nucleus Group
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)
13 * This class is used to parse item templates
15 * @license http://nucleuscms.org/license.txt GNU General Public License
16 * @copyright Copyright (C) 2002-2009 The Nucleus Group
18 * @version $NucleusJP: ITEMACTIONS.php,v 1.5.2.3 2007/10/30 19:05:20 kmorimatsu Exp $
20 class ITEMACTIONS extends BaseActions {
\r
22 // contains an assoc array with parameters that need to be included when
\r
23 // generating links to items/archives/... (e.g. catid)
\r
26 // true when the current user is a blog admin (and thus allowed to edit all items)
\r
29 // timestamp of last visit
\r
32 // item currently being handled (mysql result object, see BLOG::showUsingQuery)
\r
35 // reference to the blog currently being displayed
\r
38 // associative array with template info (part name => contents)
\r
41 // true when comments need to be displayed
\r
44 function ITEMACTIONS(&$blog) {
\r
45 // call constructor of superclass first
\r
46 $this->BaseActions();
\r
48 // extra parameters for created links
\r
51 $this->linkparams = array('catid' => $catid);
\r
53 // check if member is blog admin (and thus allowed to edit all items)
\r
55 $this->allowEditAll = ($member->isLoggedIn() && $member->blogAdminRights($blog->getID()));
\r
56 $this->setBlog($blog);
\r
60 * Returns an array with the actions that are defined
\r
61 * in the ITEMACTIONS class
\r
63 function getDefinedActions() {
\r
86 'syndicate_description',
\r
115 function setLastVisit($lastVisit) {
\r
116 $this->lastVisit = $lastVisit;
\r
119 function setParser(&$parser) {
\r
120 $this->parser =& $parser;
\r
123 function setCurrentItem(&$item) {
\r
124 $this->currentItem =& $item;
\r
127 function setBlog(&$blog) {
\r
128 $this->blog =& $blog;
\r
131 function setTemplate($template) {
\r
132 $this->template =& $template;
\r
135 function setShowComments($val) {
\r
136 $this->showComments = $val;
\r
139 // methods used by parser to insert content
\r
143 * Parse templatevar blogid
\r
145 function parse_blogid() {
\r
146 echo $this->blog->getID();
\r
150 * Parse templatevar body
\r
152 function parse_body() {
\r
153 $this->highlightAndParse($this->currentItem->body);
\r
157 * Parse templatevar more
\r
159 function parse_more() {
\r
160 $this->highlightAndParse($this->currentItem->more);
\r
164 * Parse templatevar itemid
\r
166 function parse_itemid() {
\r
167 echo $this->currentItem->itemid;
\r
171 * Parse templatevar category
\r
173 function parse_category() {
\r
174 echo $this->currentItem->category;
\r
178 * Parse templatevar categorylink
\r
180 function parse_categorylink() {
\r
181 echo createLink('category', array('catid' => $this->currentItem->catid, 'name' => $this->currentItem->category));
\r
185 * Parse templatevar catid
\r
187 function parse_catid() {
\r
188 echo $this->currentItem->catid;
\r
192 * Parse templatevar authorid
\r
194 function parse_authorid() {
\r
195 echo $this->currentItem->authorid;
\r
199 * Parse templatevar authorlink
\r
201 function parse_authorlink() {
\r
205 'memberid' => $this->currentItem->authorid,
\r
206 'name' => $this->currentItem->author,
\r
207 'extra' => $this->linkparams
\r
213 * Parse templatevar query
\r
215 function parse_query() {
\r
216 echo $this->strHighlight;
\r
220 * Parse templatevar itemlink
\r
222 function parse_itemlink() {
\r
226 'itemid' => $this->currentItem->itemid,
\r
227 'title' => $this->currentItem->title,
\r
228 'timestamp' => $this->currentItem->timestamp,
\r
229 'extra' => $this->linkparams
\r
235 * Parse templatevar blogurl
\r
237 function parse_blogurl() {
\r
238 echo $this->blog->getURL();
\r
242 * Parse templatevar closed
\r
244 function parse_closed() {
\r
245 echo $this->currentItem->closed;
\r
249 * Parse templatevar relevance
\r
251 function parse_relevance() {
\r
252 echo round($this->currentItem->score,2);
\r
256 * Parse templatevar title
\r
258 * @param string $format defines in which format the title is shown
\r
260 function parse_title($format = '') {
\r
261 if (is_array($this->currentItem)) {
\r
262 $itemtitle = $this->currentItem['title'];
\r
263 } elseif (is_object($this->currentItem)) {
\r
264 $itemtitle = $this->currentItem->title;
\r
268 // echo stringToXML ($this->currentItem->title);
\r
269 echo stringToXML ($itemtitle);
\r
272 // echo stringToAttribute ($this->currentItem->title);
\r
273 echo stringToAttribute ($itemtitle);
\r
276 // echo $this->currentItem->title;
\r
280 // $this->highlightAndParse($this->currentItem->title);
\r
281 $this->highlightAndParse($itemtitle);
\r
287 * Parse templatevar karma
\r
289 function parse_karma($type = 'totalscore') {
\r
292 // get karma object
\r
293 $karma =& $manager->getKarma($this->currentItem->itemid);
\r
297 echo $karma->getNbPosVotes();
\r
300 echo $karma->getNbNegVotes();
\r
303 echo $karma->getNbOfVotes();
\r
306 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50;
\r
307 echo number_format($percentage,2), '%';
\r
310 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50;
\r
311 echo number_format($percentage,2), '%';
\r
315 echo $karma->getTotalScore();
\r
322 * Parse templatevar author
\r
324 function parse_author($which = '') {
\r
328 echo $this->currentItem->authorname;
\r
331 echo $this->currentItem->authorid;
\r
334 echo $this->currentItem->authormail;
\r
337 echo $this->currentItem->authorurl;
\r
341 echo $this->currentItem->author;
\r
346 * Parse templatevar smartbody
\r
348 function parse_smartbody() {
\r
349 if (!$this->currentItem->more) {
\r
350 $this->highlightAndParse($this->currentItem->body);
\r
352 $this->highlightAndParse($this->currentItem->more);
\r
357 * Parse templatevar morelink
\r
359 function parse_morelink() {
\r
360 if ($this->currentItem->more)
\r
361 $this->parser->parse($this->template['MORELINK']);
\r
365 * Parse templatevar date
\r
367 * @param format optional strftime format
\r
369 function parse_date($format = '') {
\r
370 echo formatDate($format, $this->currentItem->timestamp, $this->template['FORMAT_DATE'], $this->blog);
\r
374 * Parse templatevar time
\r
376 * @param format optional strftime format
\r
378 function parse_time($format = '') {
\r
379 echo strftime($format ? $format : $this->template['FORMAT_TIME'],$this->currentItem->timestamp);
\r
383 * Parse templatevar syndicate_title
\r
385 * @param maxLength optional maximum length
\r
387 function parse_syndicate_title($maxLength = 100) {
\r
388 $syndicated = strip_tags($this->currentItem->title);
\r
389 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES);
\r
393 * Parse templatevar syndicate_description
\r
395 * @param maxLength optional maximum length
\r
397 function parse_syndicate_description($maxLength = 250, $addHighlight = 0) {
\r
398 $syndicated = strip_tags($this->currentItem->body);
\r
399 if ($addHighlight) {
\r
400 $tmp_highlight = htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES);
\r
401 echo $this->highlightAndParse($tmp_highlight);
\r
403 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES);
\r
408 * Parse templatevar karmaposlink
\r
410 * @param string text
\r
412 function parse_karmaposlink($text = '') {
\r
414 $link = $CONF['ActionURL'] . '?action=votepositive&itemid='.$this->currentItem->itemid;
\r
415 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;
\r
419 * Parse templatevar karmaneglink
\r
421 * @param string text
\r
423 function parse_karmaneglink($text = '') {
\r
425 $link = $CONF['ActionURL'] . '?action=votenegative&itemid='.$this->currentItem->itemid;
\r
426 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;
\r
430 * Parse templatevar new
\r
432 function parse_new() {
\r
433 if (($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit))
\r
434 echo $this->template['NEW'];
\r
438 * Parse templatevar daylink
\r
440 function parse_daylink() {
\r
441 echo createArchiveLink($this->blog->getID(), strftime('%Y-%m-%d',$this->currentItem->timestamp), $this->linkparams);
\r
445 * Parse templatevar comments
\r
447 function parse_comments($maxToShow = 0) {
\r
448 if ($maxToShow == 0)
\r
449 $maxToShow = $this->blog->getMaxComments();
\r
452 if ($this->showComments && $this->blog->commentsEnabled()) {
\r
453 $comments =& new COMMENTS($this->currentItem->itemid);
\r
454 $comments->setItemActions($this);
\r
455 $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight);
\r
460 * Executes a plugin templatevar
\r
462 * @param pluginName name of plugin (without the NP_)
\r
464 * extra parameters can be added
\r
466 function parse_plugin($pluginName) {
\r
469 // should be already tested from the parser (PARSER.php)
\r
470 // only continue when the plugin is really installed
\r
471 /*if (!$manager->pluginInstalled('NP_' . $pluginName))
\r
474 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
475 if (!$plugin) return;
\r
478 $params = func_get_args();
\r
480 // remove plugin name
\r
481 array_shift($params);
\r
483 // add item reference (array_unshift didn't work)
\r
484 $params = array_merge(array(&$this->currentItem),$params);
\r
486 call_user_func_array(array(&$plugin,'doTemplateVar'), $params);
\r
490 * Parse templatevar edit
\r
492 function parse_edit() {
\r
493 global $member, $CONF;
\r
494 if ($this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) ) {
\r
495 $this->parser->parse($this->template['EDITLINK']);
\r
500 * Parse templatevar editlink
\r
502 function parse_editlink() {
\r
504 echo $CONF['AdminURL'],'bookmarklet.php?action=edit&itemid=',$this->currentItem->itemid;
\r
508 * Parse templatevar editpopupcode
\r
510 function parse_editpopupcode() {
\r
511 echo "if (event && event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');winbm.focus();return false;";
\r
514 // helper functions
\r
517 * Parses highlighted text, with limited actions only (to prevent not fully trusted team members
\r
518 * from hacking your weblog.
\r
519 * 'plugin variables in items' implementation by Andy
\r
521 function highlightAndParse(&$data) {
\r
522 $actions =& new BODYACTIONS($this->blog);
\r
523 $parser =& new PARSER($actions->getDefinedActions(), $actions);
\r
524 $actions->setTemplate($this->template);
\r
525 $actions->setHighlight($this->strHighlight);
\r
526 $actions->setCurrentItem($this->currentItem);
\r
527 //$actions->setParser($parser);
\r
528 $parser->parse($actions->highlight($data));
\r
532 // this is the function previous to the 'plugin variables in items' implementation by Andy
\r
533 function highlightAndParse(&$data) {
\r
534 // allow only a limited subset of actions (do not allow includes etc, they might be evil)
\r
535 $this->parser->actions = array('image','media','popup');
\r
536 $tmp_highlight = $this->highlight($data);
\r
537 $this->parser->parse($tmp_highlight);
\r
538 $this->parser->actions = $this->getDefinedActions();
\r