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 when parsing comment templates
15 * @license http://nucleuscms.org/license.txt GNU General Public License
16 * @copyright Copyright (C) 2002-2009 The Nucleus Group
18 * @version $NucleusJP: COMMENTACTIONS.php,v 1.5.2.1 2007/08/08 05:31:31 kimitake Exp $
21 class COMMENTACTIONS extends BaseActions {
\r
23 // ref to COMMENTS object which is using this object to handle
\r
27 // template to use to parse the comments
\r
30 // comment currenlty being handled (mysql result assoc array; see COMMENTS::showComments())
\r
31 var $currentComment;
\r
33 function COMMENTACTIONS(&$comments) {
\r
34 // call constructor of superclass first
\r
35 $this->BaseActions();
\r
37 // reference to the comments object
\r
38 $this->setCommentsObj($comments);
\r
41 function getDefinedActions() {
\r
77 function setParser(&$parser) {
\r
78 $this->parser =& $parser;
\r
81 function setCommentsObj(&$commentsObj) {
\r
82 $this->commentsObj =& $commentsObj;
\r
85 function setTemplate($template) {
\r
86 $this->template =& $template;
\r
89 function setCurrentComment(&$comment) {
\r
91 if ($comment['memberid'] != 0) {
\r
92 $comment['authtext'] = $template['COMMENTS_AUTH'];
\r
94 $mem =& $manager->getMember($comment['memberid']);
\r
95 $comment['user'] = $mem->getDisplayName();
\r
97 $comment['userid'] = $mem->getURL();
\r
99 $comment['userid'] = $mem->getEmail();
\r
101 $comment['userlinkraw'] = createLink(
\r
104 'memberid' => $comment['memberid'],
\r
105 'name' => $mem->getDisplayName(),
\r
106 'extra' => $this->commentsObj->itemActions->linkparams
\r
112 // create smart links
\r
113 /* if (isValidMailAddress($comment['userid']))
\r
114 $comment['userlinkraw'] = 'mailto:'.$comment['userid'];
\r
115 elseif (strstr($comment['userid'],'http://') != false)
\r
116 $comment['userlinkraw'] = $comment['userid'];
\r
117 elseif (strstr($comment['userid'],'www') != false)
\r
118 $comment['userlinkraw'] = 'http://'.$comment['userid'];*/
\r
119 if (strstr($comment['userid'],'http://') != false)
\r
120 $comment['userlinkraw'] = $comment['userid'];
\r
121 elseif (strstr($comment['userid'],'www') != false)
\r
122 $comment['userlinkraw'] = 'http://'.$comment['userid'];
\r
123 elseif (isValidMailAddress($comment['email']))
\r
124 $comment['userlinkraw'] = 'mailto:'.$comment['email'];
\r
125 elseif (isValidMailAddress($comment['userid']))
\r
126 $comment['userlinkraw'] = 'mailto:'.$comment['userid'];
\r
129 $this->currentComment =& $comment;
\r
133 * Parse templatevar authtext
\r
135 function parse_authtext() {
\r
136 if ($this->currentComment['memberid'] != 0)
\r
137 $this->parser->parse($this->template['COMMENTS_AUTH']);
\r
141 * Parse templatevar blogid
\r
143 function parse_blogid() {
\r
144 echo $this->currentComment['blogid'];
\r
148 * Parse templatevar blogurl
\r
150 function parse_blogurl() {
\r
152 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);
\r
153 $blog =& $manager->getBlog($blogid);
\r
154 echo $blog->getURL();
\r
158 * Parse templatevar body
\r
160 function parse_body() {
\r
161 echo $this->highlight($this->currentComment['body']);
\r
165 * Parse templatevar commentcount
\r
167 function parse_commentcount() {
\r
168 echo $this->commentsObj->commentcount;
\r
172 * Parse templatevar commentid
\r
174 function parse_commentid() {
\r
175 echo $this->currentComment['commentid'];
\r
179 * Parse templatevar commentword
\r
181 function parse_commentword() {
\r
182 if ($this->commentsObj->commentcount == 1)
\r
183 echo $this->template['COMMENTS_ONE'];
\r
185 echo $this->template['COMMENTS_MANY'];
\r
189 * Parse templatevar date
\r
191 function parse_date($format = '') {
\r
192 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog);
\r
196 * Parse templatevar email
\r
198 function parse_email() {
\r
199 $email = $this->currentComment['email'];
\r
200 $email = str_replace('@', ' (at) ', $email);
\r
201 $email = str_replace('.', ' (dot) ', $email);
\r
206 * Parse templatevar excerpt
\r
208 function parse_excerpt() {
\r
209 echo stringToXML(shorten($this->currentComment['body'], 60, '...'));
\r
213 * Parse templatevar host
\r
215 function parse_host() {
\r
216 echo $this->currentComment['host'];
\r
220 * Parse templatevar ip
\r
222 function parse_ip() {
\r
223 echo $this->currentComment['ip'];
\r
227 * Parse templatevar itemid
\r
229 function parse_itemid() {
\r
230 echo $this->commentsObj->itemid;
\r
234 * Parse templatevar itemlink
\r
236 function parse_itemlink() {
\r
240 'itemid' => $this->commentsObj->itemid,
\r
241 'timestamp' => $this->commentsObj->itemActions->currentItem->timestamp,
\r
242 'title' => $this->commentsObj->itemActions->currentItem->title,
\r
243 'extra' => $this->commentsObj->itemActions->linkparams
\r
249 * Parse templatevar itemtitle
\r
251 function parse_itemtitle($maxLength = 0) {
\r
252 if ($maxLength == 0)
\r
253 $this->commentsObj->itemActions->parse_title();
\r
255 $this->commentsObj->itemActions->parse_syndicate_title($maxLength);
\r
259 * Parse templatevar memberid
\r
261 function parse_memberid() {
\r
262 echo $this->currentComment['memberid'];
\r
266 * Parse templatevar short
\r
268 function parse_short() {
\r
269 $tmp = strtok($this->currentComment['body'],"\n");
\r
270 $tmp = str_replace('<br />','',$tmp);
\r
272 if ($tmp != $this->currentComment['body'])
\r
273 $this->parser->parse($this->template['COMMENTS_CONTINUED']);
\r
277 * Parse templatevar time
\r
279 function parse_time($format = '') {
\r
281 ($format == '') ? $this->template['FORMAT_TIME'] : $format,
\r
282 $this->currentComment['timestamp']
\r
287 * Parse templatevar timestamp
\r
289 function parse_timestamp() {
\r
290 echo $this->currentComment['timestamp'];
\r
294 * Executes a plugin templatevar
\r
296 * @param pluginName name of plugin (without the NP_)
\r
298 * extra parameters can be added
\r
300 function parse_plugin($pluginName) {
\r
303 // only continue when the plugin is really installed
\r
304 if (!$manager->pluginInstalled('NP_' . $pluginName))
\r
307 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
308 if (!$plugin) return;
\r
311 $params = func_get_args();
\r
313 // remove plugin name
\r
314 array_shift($params);
\r
316 // pass info on current item and current comment as well
\r
317 $params = array_merge(array(&$this->currentComment),$params);
\r
318 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params);
\r
320 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);
\r
324 * Parse templatevar user
\r
326 function parse_user($mode='') {
\r
328 if ($mode == 'realname' && $this->currentComment['memberid'] > 0) {
\r
329 $member =& $manager->getMember($this->currentComment['memberid']);
\r
330 echo $member->getRealName();
\r
332 echo $this->currentComment['user'];
\r
337 * Parse templatevar useremail
\r
339 function parse_useremail() {
\r
341 if ($this->currentComment['memberid'] > 0)
\r
343 $member =& $manager->getMember($this->currentComment['memberid']);
\r
345 if ($member->email != '')
\r
346 echo $member->email;
\r
350 if (isValidMailAddress($this->currentComment['email']))
\r
351 echo $this->currentComment['email'];
\r
352 elseif (isValidMailAddress($this->currentComment['userid']))
\r
353 echo $this->currentComment['userid'];
\r
354 // if (!(strpos($this->currentComment['userlinkraw'], 'mailto:') === false))
\r
355 // echo str_replace('mailto:', '', $this->currentComment['userlinkraw']);
\r
360 * Parse templatevar userid
\r
362 function parse_userid() {
\r
363 echo $this->currentComment['userid'];
\r
368 * Parse templatevar userlink
\r
370 function parse_userlink() {
\r
371 if ($this->currentComment['userlinkraw']) {
\r
372 echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
\r
374 echo $this->currentComment['user'];
\r
379 * Parse templatevar userlinkraw
\r
381 function parse_userlinkraw() {
\r
382 echo $this->currentComment['userlinkraw'];
\r
386 * Parse templatevar userwebsite
\r
388 function parse_userwebsite() {
\r
389 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false))
\r
390 echo $this->currentComment['userlinkraw'];
\r