OSDN Git Service

351e2c31375e9ec1b5045890cda4215340cf7656
[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-2010 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-2010 The Nucleus Group
17  * @version $Id$
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                         'userwebsitelink',
67                         'excerpt',
68                         'short',
69                         'skinfile',
70                         'set',
71                         'plugin',
72                         'include',
73                         'phpinclude',
74                         'parsedinclude'
75                 );
76         }
77
78         function setParser(&$parser) {
79                 $this->parser =& $parser;
80         }
81         
82         function setCommentsObj(&$commentsObj) {
83                 $this->commentsObj =& $commentsObj;
84         }
85         
86         function setTemplate($template) {
87                 $this->template =& $template;
88         }
89         
90         function setCurrentComment(&$comment) {
91                 global $manager;
92                 if ($comment['memberid'] != 0) {
93                         $comment['authtext'] = $template['COMMENTS_AUTH'];
94
95                         $mem =& $manager->getMember($comment['memberid']);
96                         $comment['user'] = $mem->getDisplayName();
97                         if ($mem->getURL())
98                                 $comment['userid'] = $mem->getURL();
99                         else
100                                 $comment['userid'] = $mem->getEmail();
101
102                         $comment['userlinkraw'] = createLink(
103                                                                                 'member',
104                                                                                 array(
105                                                                                         'memberid' => $comment['memberid'],
106                                                                                         'name' => $mem->getDisplayName(),
107                                                                                         'extra' => $this->commentsObj->itemActions->linkparams
108                                                                                 )
109                                                                           );
110
111                 } else {
112
113                         // create smart links
114 /*                      if (isValidMailAddress($comment['userid']))
115                                 $comment['userlinkraw'] = 'mailto:'.$comment['userid'];
116                         elseif (strstr($comment['userid'],'http://') != false)
117                                 $comment['userlinkraw'] = $comment['userid'];
118                         elseif (strstr($comment['userid'],'www') != false)
119                                 $comment['userlinkraw'] = 'http://'.$comment['userid'];*/
120                         if (strstr($comment['userid'],'http://') != false)
121                                 $comment['userlinkraw'] = $comment['userid'];
122                         elseif (strstr($comment['userid'],'www') != false)
123                                 $comment['userlinkraw'] = 'http://'.$comment['userid'];
124                         elseif (isValidMailAddress($comment['email']))
125                                 $comment['userlinkraw'] = 'mailto:'.$comment['email'];
126                         elseif (isValidMailAddress($comment['userid']))
127                                 $comment['userlinkraw'] = 'mailto:'.$comment['userid'];
128                 }
129
130                 $this->currentComment =& $comment;
131         }
132
133         /**
134          * Parse templatevar authtext
135          */
136         function parse_authtext() {
137                 if ($this->currentComment['memberid'] != 0)
138                         $this->parser->parse($this->template['COMMENTS_AUTH']);
139         }
140
141         /**
142          * Parse templatevar blogid
143          */
144         function parse_blogid() {
145                 echo $this->currentComment['blogid'];
146         }
147
148         /**
149          * Parse templatevar blogurl
150          */
151         function parse_blogurl() {
152                 global $manager;
153                 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);
154                 $blog =& $manager->getBlog($blogid);
155                 echo $blog->getURL();
156         }
157
158         /**
159          * Parse templatevar body
160          */
161         function parse_body() {
162                 echo $this->highlight($this->currentComment['body']);
163         }
164
165         /**
166          * Parse templatevar commentcount
167          */
168         function parse_commentcount() {
169                         echo $this->commentsObj->commentcount;
170         }
171
172         /**
173          * Parse templatevar commentid
174          */
175         function parse_commentid() {
176                 echo $this->currentComment['commentid'];
177         }
178
179         /**
180          * Parse templatevar commentword
181          */
182         function parse_commentword() {
183                 if ($this->commentsObj->commentcount == 1)
184                         echo $this->template['COMMENTS_ONE'];
185                 else
186                         echo $this->template['COMMENTS_MANY'];
187         }
188
189         /**
190          * Parse templatevar date
191          */
192         function parse_date($format = '') {
193                 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog);
194         }
195         
196         /**
197          * Parse templatevar email
198          */
199         function parse_email() {
200                 $email = $this->currentComment['email'];
201                 $email = str_replace('@', ' (at) ', $email);
202                 $email = str_replace('.', ' (dot) ', $email);
203                 echo $email;
204         }
205
206         /**
207          * Parse templatevar excerpt
208          */
209         function parse_excerpt() {
210                 echo stringToXML(shorten($this->currentComment['body'], 60, '...'));
211         }
212
213         /**
214          * Parse templatevar host
215          */
216         function parse_host() {
217                 echo $this->currentComment['host'];
218         }
219
220         /**
221          * Parse templatevar ip
222          */
223         function parse_ip() {
224                 echo $this->currentComment['ip'];
225         }
226
227         /**
228          * Parse templatevar itemid
229          */
230         function parse_itemid() {
231                 echo $this->commentsObj->itemid;
232         }
233
234         /**
235          * Parse templatevar itemlink
236          */
237         function parse_itemlink() {
238                 echo createLink(
239                         'item',
240                         array(
241                                 'itemid' => $this->commentsObj->itemid,
242                                 'timestamp' => $this->commentsObj->itemActions->currentItem->timestamp,
243                                 'title' => $this->commentsObj->itemActions->currentItem->title,
244                                 'extra' => $this->commentsObj->itemActions->linkparams
245                         )
246                 );
247         }
248
249         /**
250          * Parse templatevar itemtitle
251          */
252         function parse_itemtitle($maxLength = 0) {
253                 if ($maxLength == 0)
254                         $this->commentsObj->itemActions->parse_title();
255                 else
256                         $this->commentsObj->itemActions->parse_syndicate_title($maxLength);
257         }
258
259         /**
260          * Parse templatevar memberid
261          */
262         function parse_memberid() {
263                 echo $this->currentComment['memberid'];
264         }
265
266         /**
267          * Parse templatevar short
268          */
269         function parse_short() {
270                 $tmp = strtok($this->currentComment['body'],"\n");
271                 $tmp = str_replace('<br />','',$tmp);
272                 echo $tmp;
273                 if ($tmp != $this->currentComment['body'])
274                         $this->parser->parse($this->template['COMMENTS_CONTINUED']);
275         }
276
277         /**
278          * Parse templatevar time
279          */
280         function parse_time($format = '') {
281                 echo strftime(
282                                 ($format == '') ? $this->template['FORMAT_TIME'] : $format,
283                                 $this->currentComment['timestamp']
284                         );
285         }
286
287         /**
288          * Parse templatevar timestamp
289          */
290         function parse_timestamp() {
291                 echo $this->currentComment['timestamp'];
292         }
293
294         /**
295           * Executes a plugin templatevar
296           *
297           * @param pluginName name of plugin (without the NP_)
298           *
299           * extra parameters can be added
300           */
301         function parse_plugin($pluginName) {
302                 global $manager;
303
304                 // only continue when the plugin is really installed
305                 if (!$manager->pluginInstalled('NP_' . $pluginName))
306                         return;
307
308                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
309                 if (!$plugin) return;
310
311                 // get arguments
312                 $params = func_get_args();
313
314                 // remove plugin name
315                 array_shift($params);
316
317                 // pass info on current item and current comment as well
318                 $params = array_merge(array(&$this->currentComment),$params);
319                 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params);
320
321                 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);
322         }
323
324         /**
325          * Parse templatevar user
326          */
327         function parse_user($mode='') {
328                 global $manager;
329                 if ($mode == 'realname' && $this->currentComment['memberid'] > 0) {
330                         $member =& $manager->getMember($this->currentComment['memberid']);
331                         echo $member->getRealName();
332                 } else {
333                         echo $this->currentComment['user'];
334                 }
335         }
336
337         /**
338          * Parse templatevar useremail
339          */
340         function parse_useremail() {
341                 global $manager;
342                 if ($this->currentComment['memberid'] > 0)
343                 {
344                         $member =& $manager->getMember($this->currentComment['memberid']);
345
346                         if ($member->email != '')
347                                 echo $member->email;
348                 }
349                 else
350                 {
351                         if (isValidMailAddress($this->currentComment['email']))
352                                 echo $this->currentComment['email'];
353                         elseif (isValidMailAddress($this->currentComment['userid']))
354                                 echo $this->currentComment['userid'];
355 //                      if (!(strpos($this->currentComment['userlinkraw'], 'mailto:') === false))
356 //                              echo str_replace('mailto:', '', $this->currentComment['userlinkraw']);
357                 }
358         }
359
360         /**
361          * Parse templatevar userid
362          */
363         function parse_userid() {
364                         echo $this->currentComment['userid'];
365         }
366
367
368         /**
369          * Parse templatevar userlink
370          */
371         function parse_userlink() {
372                 if ($this->currentComment['userlinkraw']) {
373                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
374                 } else {
375                         echo $this->currentComment['user'];
376                 }
377         }
378
379         /**
380          * Parse templatevar userlinkraw
381          */
382         function parse_userlinkraw() {
383                 echo $this->currentComment['userlinkraw'];
384         }
385         
386         /**
387          * Parse templatevar userwebsite
388          */
389         function parse_userwebsite() {
390                 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false))
391                         echo $this->currentComment['userlinkraw'];
392         }
393         
394         /**
395          * Parse templatevar userwebsitelink
396          */
397         function parse_userwebsitelink() {
398                 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false)) {
399                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
400                 } else {
401                         echo $this->currentComment['user'];
402                 }
403         }
404
405 }
406 ?>