| [ Index ] |
PHP Cross Reference of Nucleus CMS v3.51 code documentation |
[Summary view] [Print] [Text view]
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 is used when parsing comment templates 14 * 15 * @license http://nucleuscms.org/license.txt GNU General Public License 16 * @copyright Copyright (C) 2002-2009 The Nucleus Group 17 * @version $Id: COMMENTACTIONS.php 1405 2009-08-14 15:56:06Z ftruscot $ 18 */ 19 20 class COMMENTACTIONS extends BaseActions { 21 22 // ref to COMMENTS object which is using this object to handle 23 // its templatevars 24 var $commentsObj; 25 26 // template to use to parse the comments 27 var $template; 28 29 // comment currenlty being handled (mysql result assoc array; see COMMENTS::showComments()) 30 var $currentComment; 31 32 function COMMENTACTIONS(&$comments) { 33 // call constructor of superclass first 34 $this->BaseActions(); 35 36 // reference to the comments object 37 $this->setCommentsObj($comments); 38 } 39 40 function getDefinedActions() { 41 return array( 42 'blogurl', 43 'commentcount', 44 'commentword', 45 'email', 46 'itemlink', 47 'itemid', 48 'itemtitle', 49 'date', 50 'time', 51 'commentid', 52 'body', 53 'memberid', 54 'timestamp', 55 'host', 56 'ip', 57 'blogid', 58 'authtext', 59 'user', 60 'userid', 61 'userlinkraw', 62 'userlink', 63 'useremail', 64 'userwebsite', 65 'userwebsitelink', 66 'excerpt', 67 'short', 68 'skinfile', 69 'set', 70 'plugin', 71 'include', 72 'phpinclude', 73 'parsedinclude' 74 ); 75 } 76 77 function setParser(&$parser) { 78 $this->parser =& $parser; 79 } 80 81 function setCommentsObj(&$commentsObj) { 82 $this->commentsObj =& $commentsObj; 83 } 84 85 function setTemplate($template) { 86 $this->template =& $template; 87 } 88 89 function setCurrentComment(&$comment) { 90 global $manager; 91 if ($comment['memberid'] != 0) { 92 $comment['authtext'] = $template['COMMENTS_AUTH']; 93 94 $mem =& $manager->getMember($comment['memberid']); 95 $comment['user'] = $mem->getDisplayName(); 96 if ($mem->getURL()) 97 $comment['userid'] = $mem->getURL(); 98 else 99 $comment['userid'] = $mem->getEmail(); 100 101 $comment['userlinkraw'] = createLink( 102 'member', 103 array( 104 'memberid' => $comment['memberid'], 105 'name' => $mem->getDisplayName(), 106 'extra' => $this->commentsObj->itemActions->linkparams 107 ) 108 ); 109 110 } else { 111 112 // create smart links 113 /* if (isValidMailAddress($comment['userid'])) 114 $comment['userlinkraw'] = 'mailto:'.$comment['userid']; 115 elseif (strstr($comment['userid'],'http://') != false) 116 $comment['userlinkraw'] = $comment['userid']; 117 elseif (strstr($comment['userid'],'www') != false) 118 $comment['userlinkraw'] = 'http://'.$comment['userid'];*/ 119 if (strstr($comment['userid'],'http://') != false) 120 $comment['userlinkraw'] = $comment['userid']; 121 elseif (strstr($comment['userid'],'www') != false) 122 $comment['userlinkraw'] = 'http://'.$comment['userid']; 123 elseif (isValidMailAddress($comment['email'])) 124 $comment['userlinkraw'] = 'mailto:'.$comment['email']; 125 elseif (isValidMailAddress($comment['userid'])) 126 $comment['userlinkraw'] = 'mailto:'.$comment['userid']; 127 } 128 129 $this->currentComment =& $comment; 130 } 131 132 /** 133 * Parse templatevar authtext 134 */ 135 function parse_authtext() { 136 if ($this->currentComment['memberid'] != 0) 137 $this->parser->parse($this->template['COMMENTS_AUTH']); 138 } 139 140 /** 141 * Parse templatevar blogid 142 */ 143 function parse_blogid() { 144 echo $this->currentComment['blogid']; 145 } 146 147 /** 148 * Parse templatevar blogurl 149 */ 150 function parse_blogurl() { 151 global $manager; 152 $blogid = getBlogIDFromItemID($this->commentsObj->itemid); 153 $blog =& $manager->getBlog($blogid); 154 echo $blog->getURL(); 155 } 156 157 /** 158 * Parse templatevar body 159 */ 160 function parse_body() { 161 echo $this->highlight($this->currentComment['body']); 162 } 163 164 /** 165 * Parse templatevar commentcount 166 */ 167 function parse_commentcount() { 168 echo $this->commentsObj->commentcount; 169 } 170 171 /** 172 * Parse templatevar commentid 173 */ 174 function parse_commentid() { 175 echo $this->currentComment['commentid']; 176 } 177 178 /** 179 * Parse templatevar commentword 180 */ 181 function parse_commentword() { 182 if ($this->commentsObj->commentcount == 1) 183 echo $this->template['COMMENTS_ONE']; 184 else 185 echo $this->template['COMMENTS_MANY']; 186 } 187 188 /** 189 * Parse templatevar date 190 */ 191 function parse_date($format = '') { 192 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog); 193 } 194 195 /** 196 * Parse templatevar email 197 */ 198 function parse_email() { 199 $email = $this->currentComment['email']; 200 $email = str_replace('@', ' (at) ', $email); 201 $email = str_replace('.', ' (dot) ', $email); 202 echo $email; 203 } 204 205 /** 206 * Parse templatevar excerpt 207 */ 208 function parse_excerpt() { 209 echo stringToXML(shorten($this->currentComment['body'], 60, '...')); 210 } 211 212 /** 213 * Parse templatevar host 214 */ 215 function parse_host() { 216 echo $this->currentComment['host']; 217 } 218 219 /** 220 * Parse templatevar ip 221 */ 222 function parse_ip() { 223 echo $this->currentComment['ip']; 224 } 225 226 /** 227 * Parse templatevar itemid 228 */ 229 function parse_itemid() { 230 echo $this->commentsObj->itemid; 231 } 232 233 /** 234 * Parse templatevar itemlink 235 */ 236 function parse_itemlink() { 237 echo createLink( 238 'item', 239 array( 240 'itemid' => $this->commentsObj->itemid, 241 'timestamp' => $this->commentsObj->itemActions->currentItem->timestamp, 242 'title' => $this->commentsObj->itemActions->currentItem->title, 243 'extra' => $this->commentsObj->itemActions->linkparams 244 ) 245 ); 246 } 247 248 /** 249 * Parse templatevar itemtitle 250 */ 251 function parse_itemtitle($maxLength = 0) { 252 if ($maxLength == 0) 253 $this->commentsObj->itemActions->parse_title(); 254 else 255 $this->commentsObj->itemActions->parse_syndicate_title($maxLength); 256 } 257 258 /** 259 * Parse templatevar memberid 260 */ 261 function parse_memberid() { 262 echo $this->currentComment['memberid']; 263 } 264 265 /** 266 * Parse templatevar short 267 */ 268 function parse_short() { 269 $tmp = strtok($this->currentComment['body'],"\n"); 270 $tmp = str_replace('<br />','',$tmp); 271 echo $tmp; 272 if ($tmp != $this->currentComment['body']) 273 $this->parser->parse($this->template['COMMENTS_CONTINUED']); 274 } 275 276 /** 277 * Parse templatevar time 278 */ 279 function parse_time($format = '') { 280 echo strftime( 281 ($format == '') ? $this->template['FORMAT_TIME'] : $format, 282 $this->currentComment['timestamp'] 283 ); 284 } 285 286 /** 287 * Parse templatevar timestamp 288 */ 289 function parse_timestamp() { 290 echo $this->currentComment['timestamp']; 291 } 292 293 /** 294 * Executes a plugin templatevar 295 * 296 * @param pluginName name of plugin (without the NP_) 297 * 298 * extra parameters can be added 299 */ 300 function parse_plugin($pluginName) { 301 global $manager; 302 303 // only continue when the plugin is really installed 304 if (!$manager->pluginInstalled('NP_' . $pluginName)) 305 return; 306 307 $plugin =& $manager->getPlugin('NP_' . $pluginName); 308 if (!$plugin) return; 309 310 // get arguments 311 $params = func_get_args(); 312 313 // remove plugin name 314 array_shift($params); 315 316 // pass info on current item and current comment as well 317 $params = array_merge(array(&$this->currentComment),$params); 318 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params); 319 320 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params); 321 } 322 323 /** 324 * Parse templatevar user 325 */ 326 function parse_user($mode='') { 327 global $manager; 328 if ($mode == 'realname' && $this->currentComment['memberid'] > 0) { 329 $member =& $manager->getMember($this->currentComment['memberid']); 330 echo $member->getRealName(); 331 } else { 332 echo $this->currentComment['user']; 333 } 334 } 335 336 /** 337 * Parse templatevar useremail 338 */ 339 function parse_useremail() { 340 global $manager; 341 if ($this->currentComment['memberid'] > 0) 342 { 343 $member =& $manager->getMember($this->currentComment['memberid']); 344 345 if ($member->email != '') 346 echo $member->email; 347 } 348 else 349 { 350 if (isValidMailAddress($this->currentComment['email'])) 351 echo $this->currentComment['email']; 352 elseif (isValidMailAddress($this->currentComment['userid'])) 353 echo $this->currentComment['userid']; 354 // if (!(strpos($this->currentComment['userlinkraw'], 'mailto:') === false)) 355 // echo str_replace('mailto:', '', $this->currentComment['userlinkraw']); 356 } 357 } 358 359 /** 360 * Parse templatevar userid 361 */ 362 function parse_userid() { 363 echo $this->currentComment['userid']; 364 } 365 366 367 /** 368 * Parse templatevar userlink 369 */ 370 function parse_userlink() { 371 if ($this->currentComment['userlinkraw']) { 372 echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>'; 373 } else { 374 echo $this->currentComment['user']; 375 } 376 } 377 378 /** 379 * Parse templatevar userlinkraw 380 */ 381 function parse_userlinkraw() { 382 echo $this->currentComment['userlinkraw']; 383 } 384 385 /** 386 * Parse templatevar userwebsite 387 */ 388 function parse_userwebsite() { 389 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false)) 390 echo $this->currentComment['userlinkraw']; 391 } 392 393 /** 394 * Parse templatevar userwebsitelink 395 */ 396 function parse_userwebsitelink() { 397 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false)) { 398 echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>'; 399 } else { 400 echo $this->currentComment['user']; 401 } 402 } 403 404 } 405 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 03:56:06 2010 |