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 */ 00021 class COMMENTACTIONS extends BaseActions { 00022 00023 // ref to COMMENTS object which is using this object to handle 00024 // its templatevars 00025 var $commentsObj; 00026 00027 // template to use to parse the comments 00028 var $template; 00029 00030 // comment currenlty being handled (mysql result assoc array; see COMMENTS::showComments()) 00031 var $currentComment; 00032 00033 function COMMENTACTIONS(&$comments) { 00034 // call constructor of superclass first 00035 $this->BaseActions(); 00036 00037 // reference to the comments object 00038 $this->setCommentsObj($comments); 00039 } 00040 00041 function getDefinedActions() { 00042 return array( 00043 'blogurl', 00044 'commentcount', 00045 'commentword', 00046 'email', 00047 'itemlink', 00048 'itemid', 00049 'itemtitle', 00050 'date', 00051 'time', 00052 'commentid', 00053 'body', 00054 'memberid', 00055 'timestamp', 00056 'host', 00057 'ip', 00058 'blogid', 00059 'authtext', 00060 'user', 00061 'userid', 00062 'userlinkraw', 00063 'userlink', 00064 'useremail', 00065 'userwebsite', 00066 'excerpt', 00067 'short', 00068 'skinfile', 00069 'set', 00070 'plugin', 00071 'include', 00072 'phpinclude', 00073 'parsedinclude' 00074 ); 00075 } 00076 00077 function setParser(&$parser) { 00078 $this->parser =& $parser; 00079 } 00080 00081 function setCommentsObj(&$commentsObj) { 00082 $this->commentsObj =& $commentsObj; 00083 } 00084 00085 function setTemplate($template) { 00086 $this->template =& $template; 00087 } 00088 00089 function setCurrentComment(&$comment) { 00090 global $manager; 00091 if ($comment['memberid'] != 0) { 00092 $comment['authtext'] = $template['COMMENTS_AUTH']; 00093 00094 $mem =& $manager->getMember($comment['memberid']); 00095 $comment['user'] = $mem->getDisplayName(); 00096 if ($mem->getURL()) 00097 $comment['userid'] = $mem->getURL(); 00098 else 00099 $comment['userid'] = $mem->getEmail(); 00100 00101 $comment['userlinkraw'] = createLink( 00102 'member', 00103 array( 00104 'memberid' => $comment['memberid'], 00105 'name' => $mem->getDisplayName(), 00106 'extra' => $this->commentsObj->itemActions->linkparams 00107 ) 00108 ); 00109 00110 } else { 00111 00112 // create smart links 00113 /* if (isValidMailAddress($comment['userid'])) 00114 $comment['userlinkraw'] = 'mailto:'.$comment['userid']; 00115 elseif (strstr($comment['userid'],'http://') != false) 00116 $comment['userlinkraw'] = $comment['userid']; 00117 elseif (strstr($comment['userid'],'www') != false) 00118 $comment['userlinkraw'] = 'http://'.$comment['userid'];*/ 00119 if (strstr($comment['userid'],'http://') != false) 00120 $comment['userlinkraw'] = $comment['userid']; 00121 elseif (strstr($comment['userid'],'www') != false) 00122 $comment['userlinkraw'] = 'http://'.$comment['userid']; 00123 elseif (isValidMailAddress($comment['email'])) 00124 $comment['userlinkraw'] = 'mailto:'.$comment['email']; 00125 elseif (isValidMailAddress($comment['userid'])) 00126 $comment['userlinkraw'] = 'mailto:'.$comment['userid']; 00127 } 00128 00129 $this->currentComment =& $comment; 00130 } 00131 00132 function parse_blogurl() { 00133 global $manager; 00134 $blogid = getBlogIDFromItemID($this->commentsObj->itemid); 00135 $blog =& $manager->getBlog($blogid); 00136 echo $blog->getURL(); 00137 } 00138 00139 function parse_commentcount() { 00140 echo $this->commentsObj->commentcount; 00141 } 00142 00143 function parse_commentword() { 00144 if ($this->commentsObj->commentcount == 1) 00145 echo $this->template['COMMENTS_ONE']; 00146 else 00147 echo $this->template['COMMENTS_MANY']; 00148 } 00149 00150 function parse_itemlink() { 00151 echo createLink( 00152 'item', 00153 array( 00154 'itemid' => $this->commentsObj->itemid, 00155 'timestamp' => $this->commentsObj->itemActions->currentItem->timestamp, 00156 'title' => $this->commentsObj->itemActions->currentItem->title, 00157 'extra' => $this->commentsObj->itemActions->linkparams 00158 ) 00159 ); 00160 } 00161 00162 function parse_itemid() { 00163 echo $this->commentsObj->itemid; 00164 } 00165 00166 function parse_itemtitle($maxLength = 0) { 00167 if ($maxLength == 0) 00168 $this->commentsObj->itemActions->parse_title(); 00169 else 00170 $this->commentsObj->itemActions->parse_syndicate_title($maxLength); 00171 } 00172 00173 function parse_date($format = '') { 00174 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog); 00175 } 00176 00177 function parse_time($format = '') { 00178 echo strftime( 00179 ($format == '') ? $this->template['FORMAT_TIME'] : $format, 00180 $this->currentComment['timestamp'] 00181 ); 00182 } 00183 00184 function parse_commentid() { 00185 echo $this->currentComment['commentid']; 00186 } 00187 00188 function parse_body() { 00189 echo $this->highlight($this->currentComment['body']); 00190 } 00191 00192 function parse_memberid() { 00193 echo $this->currentComment['memberid']; 00194 } 00195 00196 function parse_timestamp() { 00197 echo $this->currentComment['timestamp']; 00198 } 00199 00200 function parse_host() { 00201 echo $this->currentComment['host']; 00202 } 00203 00204 function parse_ip() { 00205 echo $this->currentComment['ip']; 00206 } 00207 00208 function parse_blogid() { 00209 echo $this->currentComment['blogid']; 00210 } 00211 00212 // function parse_user() { 00213 function parse_user($mode='') { 00214 global $manager; 00215 if ($mode == 'realname' && $this->currentComment['memberid'] > 0) { 00216 $member =& $manager->getMember($this->currentComment['memberid']); 00217 echo $member->getRealName(); 00218 } else { 00219 echo $this->currentComment['user']; 00220 } 00221 } 00222 00223 function parse_userid() { 00224 echo $this->currentComment['userid']; 00225 } 00226 00227 function parse_email() { 00228 $email = $this->currentComment['email']; 00229 $email = str_replace('@', ' (at) ', $email); 00230 $email = str_replace('.', ' (dot) ', $email); 00231 echo $email; 00232 } 00233 00234 function parse_userlinkraw() { 00235 echo $this->currentComment['userlinkraw']; 00236 } 00237 00238 function parse_userlink() { 00239 if ($this->currentComment['userlinkraw']) { 00240 echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>'; 00241 } else { 00242 echo $this->currentComment['user']; 00243 } 00244 } 00245 00246 function parse_useremail() { 00247 global $manager; 00248 if ($this->currentComment['memberid'] > 0) 00249 { 00250 $member =& $manager->getMember($this->currentComment['memberid']); 00251 00252 if ($member->email != '') 00253 echo $member->email; 00254 } 00255 else 00256 { 00257 if (isValidMailAddress($this->currentComment['email'])) 00258 echo $this->currentComment['email']; 00259 elseif (isValidMailAddress($this->currentComment['userid'])) 00260 echo $this->currentComment['userid']; 00261 // if (!(strpos($this->currentComment['userlinkraw'], 'mailto:') === false)) 00262 // echo str_replace('mailto:', '', $this->currentComment['userlinkraw']); 00263 } 00264 } 00265 00266 function parse_userwebsite() { 00267 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false)) 00268 echo $this->currentComment['userlinkraw']; 00269 } 00270 00271 function parse_excerpt() { 00272 echo stringToXML(shorten($this->currentComment['body'], 60, '...')); 00273 } 00274 00275 function parse_short() { 00276 $tmp = strtok($this->currentComment['body'],"\n"); 00277 $tmp = str_replace('<br />','',$tmp); 00278 echo $tmp; 00279 if ($tmp != $this->currentComment['body']) 00280 $this->parser->parse($this->template['COMMENTS_CONTINUED']); 00281 } 00282 00283 function parse_authtext() { 00284 if ($this->currentComment['memberid'] != 0) 00285 $this->parser->parse($this->template['COMMENTS_AUTH']); 00286 } 00287 00295 function parse_plugin($pluginName) { 00296 global $manager; 00297 00298 // only continue when the plugin is really installed 00299 if (!$manager->pluginInstalled('NP_' . $pluginName)) 00300 return; 00301 00302 $plugin =& $manager->getPlugin('NP_' . $pluginName); 00303 if (!$plugin) return; 00304 00305 // get arguments 00306 $params = func_get_args(); 00307 00308 // remove plugin name 00309 array_shift($params); 00310 00311 // pass info on current item and current comment as well 00312 $params = array_merge(array(&$this->currentComment),$params); 00313 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params); 00314 00315 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params); 00316 } 00317 } 00318 ?>