00001 <?php 00002 /* 00003 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 00004 * Copyright (C) 2002-2007 The Nucleus Group 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * (see nucleus/documentation/index.html#license for more info) 00011 */ 00020 class ITEMACTIONS extends BaseActions { 00021 00022 // contains an assoc array with parameters that need to be included when 00023 // generating links to items/archives/... (e.g. catid) 00024 var $linkparams; 00025 00026 // true when the current user is a blog admin (and thus allowed to edit all items) 00027 var $allowEditAll; 00028 00029 // timestamp of last visit 00030 var $lastVisit; 00031 00032 // item currently being handled (mysql result object, see BLOG::showUsingQuery) 00033 var $currentItem; 00034 00035 // reference to the blog currently being displayed 00036 var $blog; 00037 00038 // associative array with template info (part name => contents) 00039 var $template; 00040 00041 // true when comments need to be displayed 00042 var $showComments; 00043 00044 function ITEMACTIONS(&$blog) { 00045 // call constructor of superclass first 00046 $this->BaseActions(); 00047 00048 // extra parameters for created links 00049 global $catid; 00050 if ($catid) 00051 $this->linkparams = array('catid' => $catid); 00052 00053 // check if member is blog admin (and thus allowed to edit all items) 00054 global $member; 00055 $this->allowEditAll = ($member->isLoggedIn() && $member->blogAdminRights($blog->getID())); 00056 $this->setBlog($blog); 00057 } 00058 00059 function getDefinedActions() { 00060 return array( 00061 'blogid', 00062 'title', 00063 'body', 00064 'more', 00065 'smartbody', 00066 'itemid', 00067 'morelink', 00068 'category', 00069 'categorylink', 00070 'author', 00071 'authorid', 00072 'authorlink', 00073 'catid', 00074 'karma', 00075 'date', 00076 'time', 00077 'query', 00078 'itemlink', 00079 'blogurl', 00080 'closed', 00081 'syndicate_title', 00082 'syndicate_description', 00083 'karmaposlink', 00084 'karmaneglink', 00085 'new', 00086 'image', 00087 'popup', 00088 'media', 00089 'daylink', 00090 'query', 00091 'include', 00092 'phpinclude', 00093 'parsedinclude', 00094 'skinfile', 00095 'set', 00096 'plugin', 00097 'edit', 00098 'editlink', 00099 'editpopupcode', 00100 'comments', 00101 'relevance'/*, 00102 'if', 00103 'else', 00104 'endif', 00105 'elseif', 00106 'ifnot', 00107 'elseifnot'*/ 00108 ); 00109 } 00110 00111 function setLastVisit($lastVisit) { 00112 $this->lastVisit = $lastVisit; 00113 } 00114 00115 function setParser(&$parser) { 00116 $this->parser =& $parser; 00117 } 00118 00119 function setCurrentItem(&$item) { 00120 $this->currentItem =& $item; 00121 } 00122 00123 function setBlog(&$blog) { 00124 $this->blog =& $blog; 00125 } 00126 00127 function setTemplate($template) { 00128 $this->template =& $template; 00129 } 00130 00131 function setShowComments($val) { 00132 $this->showComments = $val; 00133 } 00134 00135 // methods used by parser to insert content 00136 00137 function parse_blogid() { 00138 echo $this->blog->getID(); 00139 } 00140 00141 function parse_body() { 00142 $this->highlightAndParse($this->currentItem->body); 00143 } 00144 00145 function parse_more() { 00146 $this->highlightAndParse($this->currentItem->more); 00147 } 00148 00149 function parse_itemid() { 00150 echo $this->currentItem->itemid; 00151 } 00152 00153 function parse_category() { 00154 echo $this->currentItem->category; 00155 } 00156 00157 function parse_categorylink() { 00158 echo createLink('category', array('catid' => $this->currentItem->catid, 'name' => $this->currentItem->category)); 00159 } 00160 00161 function parse_catid() { 00162 echo $this->currentItem->catid; 00163 } 00164 00165 function parse_authorid() { 00166 echo $this->currentItem->authorid; 00167 } 00168 00169 function parse_authorlink() { 00170 echo createLink( 00171 'member', 00172 array( 00173 'memberid' => $this->currentItem->authorid, 00174 'name' => $this->currentItem->author, 00175 'extra' => $this->linkparams 00176 ) 00177 ); 00178 } 00179 00180 function parse_query() { 00181 echo $this->strHighlight; 00182 } 00183 00184 function parse_itemlink() { 00185 echo createLink( 00186 'item', 00187 array( 00188 'itemid' => $this->currentItem->itemid, 00189 'title' => $this->currentItem->title, 00190 'timestamp' => $this->currentItem->timestamp, 00191 'extra' => $this->linkparams 00192 ) 00193 ); 00194 } 00195 00196 function parse_blogurl() { 00197 echo $this->blog->getURL(); 00198 } 00199 00200 function parse_closed() { 00201 echo $this->currentItem->closed; 00202 } 00203 00204 function parse_relevance() { 00205 echo round($this->currentItem->score,2); 00206 } 00207 00208 function parse_title($format = '') { 00209 if (is_array($this->currentItem)) { 00210 $itemtitle = $this->currentItem['title']; 00211 } elseif (is_object($this->currentItem)) { 00212 $itemtitle = $this->currentItem->title; 00213 } 00214 switch ($format) { 00215 case 'xml': 00216 // echo stringToXML ($this->currentItem->title); 00217 echo stringToXML ($itemtitle); 00218 break; 00219 case 'attribute': 00220 // echo stringToAttribute ($this->currentItem->title); 00221 echo stringToAttribute ($itemtitle); 00222 break; 00223 case 'raw': 00224 // echo $this->currentItem->title; 00225 echo $itemtitle; 00226 break; 00227 default: 00228 // $this->highlightAndParse($this->currentItem->title); 00229 $this->highlightAndParse($itemtitle); 00230 break; 00231 } 00232 } 00233 00234 function parse_karma($type = 'totalscore') { 00235 global $manager; 00236 00237 // get karma object 00238 $karma =& $manager->getKarma($this->currentItem->itemid); 00239 00240 switch($type) { 00241 case 'pos': 00242 echo $karma->getNbPosVotes(); 00243 break; 00244 case 'neg': 00245 echo $karma->getNbNegVotes(); 00246 break; 00247 case 'votes': 00248 echo $karma->getNbOfVotes(); 00249 break; 00250 case 'posp': 00251 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50; 00252 echo number_format($percentage,2), '%'; 00253 break; 00254 case 'negp': 00255 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50; 00256 echo number_format($percentage,2), '%'; 00257 break; 00258 case 'totalscore': 00259 default: 00260 echo $karma->getTotalScore(); 00261 break; 00262 } 00263 00264 } 00265 00266 function parse_author($which = '') { 00267 switch($which) 00268 { 00269 case 'realname': 00270 echo $this->currentItem->authorname; 00271 break; 00272 case 'id': 00273 echo $this->currentItem->authorid; 00274 break; 00275 case 'email': 00276 echo $this->currentItem->authormail; 00277 break; 00278 case 'url': 00279 echo $this->currentItem->authorurl; 00280 break; 00281 case 'name': 00282 default: 00283 echo $this->currentItem->author; 00284 } 00285 } 00286 00287 function parse_smartbody() { 00288 if (!$this->currentItem->more) { 00289 $this->highlightAndParse($this->currentItem->body); 00290 } else { 00291 $this->highlightAndParse($this->currentItem->more); 00292 } 00293 } 00294 00295 function parse_morelink() { 00296 if ($this->currentItem->more) 00297 $this->parser->parse($this->template['MORELINK']); 00298 } 00299 00300 function parse_date($format = '') { 00301 echo formatDate($format, $this->currentItem->timestamp, $this->template['FORMAT_DATE'], $this->blog); 00302 } 00303 00307 function parse_time($format = '') { 00308 echo strftime($format ? $format : $this->template['FORMAT_TIME'],$this->currentItem->timestamp); 00309 } 00310 00314 function parse_syndicate_title($maxLength = 100) { 00315 $syndicated = strip_tags($this->currentItem->title); 00316 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES); 00317 } 00318 00322 function parse_syndicate_description($maxLength = 250, $addHighlight = 0) { 00323 $syndicated = strip_tags($this->currentItem->body); 00324 if ($addHighlight) { 00325 $tmp_highlight = htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES); 00326 echo $this->highlightAndParse($tmp_highlight); 00327 } else { 00328 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES); 00329 } 00330 } 00331 00332 function parse_karmaposlink($text = '') { 00333 global $CONF; 00334 $link = $CONF['ActionURL'] . '?action=votepositive&itemid='.$this->currentItem->itemid; 00335 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link; 00336 } 00337 00338 function parse_karmaneglink($text = '') { 00339 global $CONF; 00340 $link = $CONF['ActionURL'] . '?action=votenegative&itemid='.$this->currentItem->itemid; 00341 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link; 00342 } 00343 00344 function parse_new() { 00345 if (($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit)) 00346 echo $this->template['NEW']; 00347 } 00348 00349 00350 function parse_daylink() { 00351 echo createArchiveLink($this->blog->getID(), strftime('%Y-%m-%d',$this->currentItem->timestamp), $this->linkparams); 00352 } 00353 00354 function parse_comments($maxToShow = 0) { 00355 if ($maxToShow == 0) 00356 $maxToShow = $this->blog->getMaxComments(); 00357 00358 // add comments 00359 if ($this->showComments && $this->blog->commentsEnabled()) { 00360 $comments =& new COMMENTS($this->currentItem->itemid); 00361 $comments->setItemActions($this); 00362 $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight); 00363 } 00364 } 00365 00373 function parse_plugin($pluginName) { 00374 global $manager; 00375 00376 // only continue when the plugin is really installed 00377 if (!$manager->pluginInstalled('NP_' . $pluginName)) 00378 return; 00379 00380 $plugin =& $manager->getPlugin('NP_' . $pluginName); 00381 if (!$plugin) return; 00382 00383 // get arguments 00384 $params = func_get_args(); 00385 00386 // remove plugin name 00387 array_shift($params); 00388 00389 // add item reference (array_unshift didn't work) 00390 $params = array_merge(array(&$this->currentItem),$params); 00391 00392 call_user_func_array(array(&$plugin,'doTemplateVar'), $params); 00393 } 00394 00395 function parse_edit() { 00396 global $member, $CONF; 00397 if ($this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) ) { 00398 $this->parser->parse($this->template['EDITLINK']); 00399 } 00400 } 00401 00402 function parse_editlink() { 00403 global $CONF; 00404 echo $CONF['AdminURL'],'bookmarklet.php?action=edit&itemid=',$this->currentItem->itemid; 00405 } 00406 00407 function parse_editpopupcode() { 00408 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;"; 00409 } 00410 00411 // helper functions 00412 00418 function highlightAndParse(&$data) { 00419 $actions =& new BODYACTIONS($this->blog); 00420 $parser =& new PARSER($actions->getDefinedActions(), $actions); 00421 $actions->setTemplate($this->template); 00422 $actions->setHighlight($this->strHighlight); 00423 $actions->setCurrentItem($this->currentItem); 00424 //$actions->setParser($parser); 00425 $parser->parse($actions->highlight($data)); 00426 } 00427 00428 /* 00429 // this is the function previous to the 'plugin variables in items' implementation by Andy 00430 function highlightAndParse(&$data) { 00431 // allow only a limited subset of actions (do not allow includes etc, they might be evil) 00432 $this->parser->actions = array('image','media','popup'); 00433 $tmp_highlight = $this->highlight($data); 00434 $this->parser->parse($tmp_highlight); 00435 $this->parser->actions = $this->getDefinedActions(); 00436 } 00437 */ 00438 00439 } 00440 00441 00442 00443 ?>