OSDN Git Service

merged from v3.31sp1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / COMMENTACTIONS.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2007 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-2007 The Nucleus Group
17  * @version $Id: COMMENTACTIONS.php,v 1.6 2008-02-08 09:31:22 kimitake Exp $
18  * @version $NucleusJP: COMMENTACTIONS.php,v 1.5.2.1 2007/08/08 05:31:31 kimitake Exp $
19  */
20
21 class COMMENTACTIONS extends BaseActions {
22
23         // ref to COMMENTS object which is using this object to handle
24         // its templatevars
25         var $commentsObj;
26
27         // template to use to parse the comments
28         var $template;
29
30         // comment currenlty being handled (mysql result assoc array; see COMMENTS::showComments())
31         var $currentComment;
32
33         function COMMENTACTIONS(&$comments) {
34                 // call constructor of superclass first
35                 $this->BaseActions();
36
37                 // reference to the comments object
38                 $this->setCommentsObj($comments);
39         }
40
41         function getDefinedActions() {
42                 return array(
43                         'blogurl',
44                         'commentcount',
45                         'commentword',
46                         'email',
47                         'itemlink',
48                         'itemid',
49                         'itemtitle',
50                         'date',
51                         'time',
52                         'commentid',
53                         'body',
54                         'memberid',
55                         'timestamp',
56                         'host',
57                         'ip',
58                         'blogid',
59                         'authtext',
60                         'user',
61                         'userid',
62                         'userlinkraw',
63                         'userlink',
64                         'useremail',
65                         'userwebsite',
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         function parse_blogurl() {
133                 global $manager;
134                 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);
135                 $blog =& $manager->getBlog($blogid);
136                 echo $blog->getURL();
137         }
138
139         function parse_commentcount() {
140                         echo $this->commentsObj->commentcount;
141         }
142         
143         function parse_commentword() {
144                 if ($this->commentsObj->commentcount == 1)
145                         echo $this->template['COMMENTS_ONE'];
146                 else
147                         echo $this->template['COMMENTS_MANY'];
148         }
149
150         function parse_itemlink() {
151                 echo createLink(
152                         'item',
153                         array(
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
158                         )
159                 );
160         }
161         
162         function parse_itemid() {
163                 echo $this->commentsObj->itemid;
164         }
165         
166         function parse_itemtitle($maxLength = 0) {
167                 if ($maxLength == 0)
168                         $this->commentsObj->itemActions->parse_title();
169                 else
170                         $this->commentsObj->itemActions->parse_syndicate_title($maxLength);
171         }
172
173         function parse_date($format = '') {
174                 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog);
175         }
176         
177         function parse_time($format = '') {
178                 echo strftime(
179                                 ($format == '') ? $this->template['FORMAT_TIME'] : $format,
180                                 $this->currentComment['timestamp']
181                         );
182         }
183
184         function parse_commentid() {
185                 echo $this->currentComment['commentid'];
186         }
187         
188         function parse_body() {
189                 echo $this->highlight($this->currentComment['body']);
190         }
191         
192         function parse_memberid() {
193                 echo $this->currentComment['memberid'];
194         }
195         
196         function parse_timestamp() {
197                 echo $this->currentComment['timestamp'];
198         }
199         
200         function parse_host() {
201                 echo $this->currentComment['host'];
202         }
203         
204         function parse_ip() {
205                 echo $this->currentComment['ip'];
206         }
207         
208         function parse_blogid() {
209                 echo $this->currentComment['blogid'];
210         }
211
212 //      function parse_user() {
213         function parse_user($mode='') {
214                 global $manager;
215                 if ($mode == 'realname' && $this->currentComment['memberid'] > 0) {
216                         $member =& $manager->getMember($this->currentComment['memberid']);
217                         echo $member->getRealName();
218                 } else {
219                         echo $this->currentComment['user'];
220                 }
221         }
222         
223         function parse_userid() {
224                         echo $this->currentComment['userid'];
225         }
226         
227         function parse_email() {
228                 $email = $this->currentComment['email'];
229                 $email = str_replace('@', ' (at) ', $email);
230                 $email = str_replace('.', ' (dot) ', $email);
231                 echo $email;
232         }
233         
234         function parse_userlinkraw() {
235                 echo $this->currentComment['userlinkraw'];
236         }
237         
238         function parse_userlink() {
239                 if ($this->currentComment['userlinkraw']) {
240                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
241                 } else {
242                         echo $this->currentComment['user'];
243                 }
244         }
245
246         function parse_useremail() {
247                 global $manager;
248                 if ($this->currentComment['memberid'] > 0)
249                 {
250                         $member =& $manager->getMember($this->currentComment['memberid']);
251
252                         if ($member->email != '')
253                                 echo $member->email;
254                 }
255                 else
256                 {
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']);
263                 }
264         }
265
266         function parse_userwebsite() {
267                 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false))
268                         echo $this->currentComment['userlinkraw'];
269         }
270
271         function parse_excerpt() {
272                 echo stringToXML(shorten($this->currentComment['body'], 60, '...'));
273         }
274         
275         function parse_short() {
276                 $tmp = strtok($this->currentComment['body'],"\n");
277                 $tmp = str_replace('<br />','',$tmp);
278                 echo $tmp;
279                 if ($tmp != $this->currentComment['body'])
280                         $this->parser->parse($this->template['COMMENTS_CONTINUED']);
281         }
282         
283         function parse_authtext() {
284                 if ($this->currentComment['memberid'] != 0)
285                         $this->parser->parse($this->template['COMMENTS_AUTH']);
286         }
287
288         /**
289           * Executes a plugin templatevar
290           *
291           * @param pluginName name of plugin (without the NP_)
292           *
293           * extra parameters can be added
294           */
295         function parse_plugin($pluginName) {
296                 global $manager;
297
298                 // only continue when the plugin is really installed
299                 if (!$manager->pluginInstalled('NP_' . $pluginName))
300                         return;
301
302                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
303                 if (!$plugin) return;
304
305                 // get arguments
306                 $params = func_get_args();
307
308                 // remove plugin name
309                 array_shift($params);
310
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);
314
315                 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);
316         }
317 }
318 ?>