OSDN Git Service

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