OSDN Git Service

sync with original 3.3
[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.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 $
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                 }
120
121                 $this->currentComment =& $comment;
122         }
123
124         function parse_blogurl() {
125                 global $manager;
126                 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);
127                 $blog =& $manager->getBlog($blogid);
128                 echo $blog->getURL();
129         }
130
131         function parse_commentcount() {
132                         echo $this->commentsObj->commentcount;
133         }
134         
135         function parse_commentword() {
136                 if ($this->commentsObj->commentcount == 1)
137                         echo $this->template['COMMENTS_ONE'];
138                 else
139                         echo $this->template['COMMENTS_MANY'];
140         }
141
142         function parse_itemlink() {
143                 echo createLink(
144                         'item',
145                         array(
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
150                         )
151                 );
152         }
153         
154         function parse_itemid() {
155                 echo $this->commentsObj->itemid;
156         }
157         
158         function parse_itemtitle($maxLength = 0) {
159                 if ($maxLength == 0)
160                         $this->commentsObj->itemActions->parse_title();
161                 else
162                         $this->commentsObj->itemActions->parse_syndicate_title($maxLength);
163         }
164
165         function parse_date($format = '') {
166                 echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $this->commentsObj->itemActions->blog);
167         }
168         
169         function parse_time($format = '') {
170                 echo strftime(
171                                 ($format == '') ? $this->template['FORMAT_TIME'] : $format,
172                                 $this->currentComment['timestamp']
173                         );
174         }
175
176         function parse_commentid() {
177                 echo $this->currentComment['commentid'];
178         }
179         
180         function parse_body() {
181                 echo $this->highlight($this->currentComment['body']);
182         }
183         
184         function parse_memberid() {
185                 echo $this->currentComment['memberid'];
186         }
187         
188         function parse_timestamp() {
189                 echo $this->currentComment['timestamp'];
190         }
191         
192         function parse_host() {
193                 echo $this->currentComment['host'];
194         }
195         
196         function parse_ip() {
197                 echo $this->currentComment['ip'];
198         }
199         
200         function parse_blogid() {
201                 echo $this->currentComment['blogid'];
202         }
203
204         function parse_user() {
205                         echo $this->currentComment['user'];
206         }
207         
208         function parse_userid() {
209                         echo $this->currentComment['userid'];
210         }
211         
212         function parse_email() {
213                 $email = $this->currentComment['email'];
214                 $email = str_replace('@', ' (at) ', $email);
215                 $email = str_replace('.', ' (dot) ', $email);
216                 echo $email;
217         }
218         
219         function parse_userlinkraw() {
220                 echo $this->currentComment['userlinkraw'];
221         }
222         
223         function parse_userlink() {
224                 if ($this->currentComment['userlinkraw']) {
225                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
226                 } else {
227                         echo $this->currentComment['user'];
228                 }
229         }
230
231         function parse_useremail() {
232                 global $manager;
233                 if ($this->currentComment['memberid'] > 0)
234                 {
235                         $member =& $manager->getMember($this->currentComment['memberid']);
236
237                         if ($member->email != '')
238                                 echo $member->email;
239                 }
240                 else
241                 {
242                         if (!(strpos($this->currentComment['userlinkraw'], 'mailto:') === false))
243                                 echo str_replace('mailto:', '', $this->currentComment['userlinkraw']);
244                 }
245         }
246
247         function parse_userwebsite() {
248                 if (!(strpos($this->currentComment['userlinkraw'], 'http://') === false))
249                         echo $this->currentComment['userlinkraw'];
250         }
251
252         function parse_excerpt() {
253                 echo stringToXML(shorten($this->currentComment['body'], 60, '...'));
254         }
255         
256         function parse_short() {
257                 $tmp = strtok($this->currentComment['body'],"\n");
258                 $tmp = str_replace('<br />','',$tmp);
259                 echo $tmp;
260                 if ($tmp != $this->currentComment['body'])
261                         $this->parser->parse($this->template['COMMENTS_CONTINUED']);
262         }
263         
264         function parse_authtext() {
265                 if ($this->currentComment['memberid'] != 0)
266                         $this->parser->parse($this->template['COMMENTS_AUTH']);
267         }
268
269         /**
270           * Executes a plugin templatevar
271           *
272           * @param pluginName name of plugin (without the NP_)
273           *
274           * extra parameters can be added
275           */
276         function parse_plugin($pluginName) {
277                 global $manager;
278
279                 // only continue when the plugin is really installed
280                 if (!$manager->pluginInstalled('NP_' . $pluginName))
281                         return;
282
283                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
284                 if (!$plugin) return;
285
286                 // get arguments
287                 $params = func_get_args();
288
289                 // remove plugin name
290                 array_shift($params);
291
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);
295
296                 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);
297         }
298 }
299 ?>