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.3 2007-02-04 06:28:46 kimitake Exp $
18 * @version $NucleusJP: COMMENTACTIONS.php,v 1.2 2006/07/20 08:01:52 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'];
121 $this->currentComment =& $comment;
124 function parse_blogurl() {
126 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);
127 $blog =& $manager->getBlog($blogid);
128 echo $blog->getURL();
131 function parse_commentcount() {
132 echo $this->commentsObj->commentcount;
135 function parse_commentword() {
136 if ($this->commentsObj->commentcount == 1)
137 echo $this->template['COMMENTS_ONE'];
139 echo $this->template['COMMENTS_MANY'];
142 function parse_itemlink() {
146 'itemid' => $this->commentsObj->itemid,
147 'timestamp' => $this->commentsObj->itemActions->currentItem->timestamp,
148 'title' => $this->commentsObj->itemActions->currentItem->title,
149 'extra' => $this->commentsObj->itemActions->linkparams
154 function parse_itemid() {
155 echo $this->commentsObj->itemid;
158 function parse_itemtitle($maxLength = 0) {
160 $this->commentsObj->itemActions->parse_title();
162 $this->commentsObj->itemActions->parse_syndicate_title($maxLength);
165 function parse_date($format = '') {
166 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog);
169 function parse_time($format = '') {
171 ($format == '') ? $this->template['FORMAT_TIME'] : $format,
172 $this->currentComment['timestamp']
176 function parse_commentid() {
177 echo $this->currentComment['commentid'];
180 function parse_body() {
181 echo $this->highlight($this->currentComment['body']);
184 function parse_memberid() {
185 echo $this->currentComment['memberid'];
188 function parse_timestamp() {
189 echo $this->currentComment['timestamp'];
192 function parse_host() {
193 echo $this->currentComment['host'];
196 function parse_ip() {
197 echo $this->currentComment['ip'];
200 function parse_blogid() {
201 echo $this->currentComment['blogid'];
204 function parse_user() {
205 echo $this->currentComment['user'];
208 function parse_userid() {
209 echo $this->currentComment['userid'];
212 function parse_email() {
213 $email = $this->currentComment['email'];
214 $email = str_replace('@', ' (at) ', $email);
215 $email = str_replace('.', ' (dot) ', $email);
219 function parse_userlinkraw() {
220 echo $this->currentComment['userlinkraw'];
223 function parse_userlink() {
224 if ($this->currentComment['userlinkraw']) {
225 echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
227 echo $this->currentComment['user'];
231 function parse_useremail() {
233 if ($this->currentComment['memberid'] > 0)
235 $member =& $manager->getMember($this->currentComment['memberid']);
237 if ($member->email != '')
242 if (!(strpos($this->currentComment['userlinkraw'], 'mailto:') === false))
243 echo str_replace('mailto:', '', $this->currentComment['userlinkraw']);
247 function parse_userwebsite() {
248 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false))
249 echo $this->currentComment['userlinkraw'];
252 function parse_excerpt() {
253 echo stringToXML(shorten($this->currentComment['body'], 60, '...'));
256 function parse_short() {
257 $tmp = strtok($this->currentComment['body'],"\n");
258 $tmp = str_replace('<br />','',$tmp);
260 if ($tmp != $this->currentComment['body'])
261 $this->parser->parse($this->template['COMMENTS_CONTINUED']);
264 function parse_authtext() {
265 if ($this->currentComment['memberid'] != 0)
266 $this->parser->parse($this->template['COMMENTS_AUTH']);
270 * Executes a plugin templatevar
272 * @param pluginName name of plugin (without the NP_)
274 * extra parameters can be added
276 function parse_plugin($pluginName) {
279 // only continue when the plugin is really installed
280 if (!$manager->pluginInstalled('NP_' . $pluginName))
283 $plugin =& $manager->getPlugin('NP_' . $pluginName);
284 if (!$plugin) return;
287 $params = func_get_args();
289 // remove plugin name
290 array_shift($params);
292 // pass info on current item and current comment as well
293 $params = array_merge(array(&$this->currentComment),$params);
294 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params);
296 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);