3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2007 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-2007 The Nucleus Group
17 * @version $Id: COMMENTACTIONS.php,v 1.2 2007-04-20 08:45:05 kimitake Exp $
18 * @version $NucleusJP: COMMENTACTIONS.php,v 1.1 2007/04/04 07:52:08 kimitake Exp $
21 class COMMENTACTIONS extends BaseActions {
23 // ref to COMMENTS object which is using this object to handle
27 // template to use to parse the comments
30 // comment currenlty being handled (mysql result assoc array; see COMMENTS::showComments())
33 function COMMENTACTIONS(&$comments) {
34 // call constructor of superclass first
37 // reference to the comments object
38 $this->setCommentsObj($comments);
41 function getDefinedActions() {
77 function setParser(&$parser) {
78 $this->parser =& $parser;
81 function setCommentsObj(&$commentsObj) {
82 $this->commentsObj =& $commentsObj;
85 function setTemplate($template) {
86 $this->template =& $template;
89 function setCurrentComment(&$comment) {
91 if ($comment['memberid'] != 0) {
92 $comment['authtext'] = $template['COMMENTS_AUTH'];
94 $mem =& $manager->getMember($comment['memberid']);
95 $comment['user'] = $mem->getDisplayName();
97 $comment['userid'] = $mem->getURL();
99 $comment['userid'] = $mem->getEmail();
101 $comment['userlinkraw'] = createLink(
104 'memberid' => $comment['memberid'],
105 'name' => $mem->getDisplayName(),
106 'extra' => $this->commentsObj->itemActions->linkparams
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'];
129 $this->currentComment =& $comment;
132 function parse_blogurl() {
134 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);
135 $blog =& $manager->getBlog($blogid);
136 echo $blog->getURL();
139 function parse_commentcount() {
140 echo $this->commentsObj->commentcount;
143 function parse_commentword() {
144 if ($this->commentsObj->commentcount == 1)
145 echo $this->template['COMMENTS_ONE'];
147 echo $this->template['COMMENTS_MANY'];
150 function parse_itemlink() {
154 'itemid' => $this->commentsObj->itemid,
155 'timestamp' => $this->commentsObj->itemActions->currentItem->timestamp,
156 'title' => $this->commentsObj->itemActions->currentItem->title,
157 'extra' => $this->commentsObj->itemActions->linkparams
162 function parse_itemid() {
163 echo $this->commentsObj->itemid;
166 function parse_itemtitle($maxLength = 0) {
168 $this->commentsObj->itemActions->parse_title();
170 $this->commentsObj->itemActions->parse_syndicate_title($maxLength);
173 function parse_date($format = '') {
174 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog);
177 function parse_time($format = '') {
179 ($format == '') ? $this->template['FORMAT_TIME'] : $format,
180 $this->currentComment['timestamp']
184 function parse_commentid() {
185 echo $this->currentComment['commentid'];
188 function parse_body() {
189 echo $this->highlight($this->currentComment['body']);
192 function parse_memberid() {
193 echo $this->currentComment['memberid'];
196 function parse_timestamp() {
197 echo $this->currentComment['timestamp'];
200 function parse_host() {
201 echo $this->currentComment['host'];
204 function parse_ip() {
205 echo $this->currentComment['ip'];
208 function parse_blogid() {
209 echo $this->currentComment['blogid'];
212 // function parse_user() {
213 function parse_user($mode='') {
215 if ($mode == 'realname' && $this->currentComment['memberid'] > 0) {
216 $member =& $manager->getMember($this->currentComment['memberid']);
217 echo $member->getRealName();
219 echo $this->currentComment['user'];
223 function parse_userid() {
224 echo $this->currentComment['userid'];
227 function parse_email() {
228 $email = $this->currentComment['email'];
229 $email = str_replace('@', ' (at) ', $email);
230 $email = str_replace('.', ' (dot) ', $email);
234 function parse_userlinkraw() {
235 echo $this->currentComment['userlinkraw'];
238 function parse_userlink() {
239 if ($this->currentComment['userlinkraw']) {
240 echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
242 echo $this->currentComment['user'];
246 function parse_useremail() {
248 if ($this->currentComment['memberid'] > 0)
250 $member =& $manager->getMember($this->currentComment['memberid']);
252 if ($member->email != '')
257 if (isValidMailAddress($this->currentComment['email']))
258 echo $this->currentComment['email'];
259 elseif (isValidMailAddress($this->currentComment['userid']))
260 echo $this->currentComment['userid'];
261 // if (!(strpos($this->currentComment['userlinkraw'], 'mailto:') === false))
262 // echo str_replace('mailto:', '', $this->currentComment['userlinkraw']);
266 function parse_userwebsite() {
267 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false))
268 echo $this->currentComment['userlinkraw'];
271 function parse_excerpt() {
272 echo stringToXML(shorten($this->currentComment['body'], 60, '...'));
275 function parse_short() {
276 $tmp = strtok($this->currentComment['body'],"\n");
277 $tmp = str_replace('<br />','',$tmp);
279 if ($tmp != $this->currentComment['body'])
280 $this->parser->parse($this->template['COMMENTS_CONTINUED']);
283 function parse_authtext() {
284 if ($this->currentComment['memberid'] != 0)
285 $this->parser->parse($this->template['COMMENTS_AUTH']);
289 * Executes a plugin templatevar
291 * @param pluginName name of plugin (without the NP_)
293 * extra parameters can be added
295 function parse_plugin($pluginName) {
298 // only continue when the plugin is really installed
299 if (!$manager->pluginInstalled('NP_' . $pluginName))
302 $plugin =& $manager->getPlugin('NP_' . $pluginName);
303 if (!$plugin) return;
306 $params = func_get_args();
308 // remove plugin name
309 array_shift($params);
311 // pass info on current item and current comment as well
312 $params = array_merge(array(&$this->currentComment),$params);
313 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params);
315 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);