3 class NP_EzComment2 extends NucleusPlugin
9 return 'Ez Comment II';
19 return 'http://japan.nucleuscms.org/wiki/plugins:ezcomment2';
27 function getDescription()
29 return _NP_EZCOMMENT2_DESC;
32 function supportsFeature($what)
35 case 'SqlTablePrefix':
42 function getEventList()
50 function event_ExternalAuth(&$data)
53 $authPlug =& $manager->getPlugin('NP_' . $data['externalauth']['source']);
54 if( $authPlug->isLoggedin() ){
55 $data['externalauth']['result'] = true;
56 $data['externalauth']['plugin'] = $this->getName();
62 if (!TEMPLATE::exists('EzCommentTemplateDefault')) {
64 include_once($DIR_LIBS . 'skinie.php');
65 $importer = new SKINIMPORT();
67 $template = $this->getDirectory() . 'skinbackup.xml';
68 if (!@file_exists($template)) {
69 $aErrors[] = 'Unable to import ' . $template . ' : file does not exist';
72 $error = $importer->readFile($template);
74 $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
77 $error = $importer->writeToDatabase(1);
79 $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
83 $message = implode("<br />\n", $aErrors);
86 createBlogOption('secret', 'Enable seacret comment ?', 'yesno', 'no');
87 createOption('tabledel', 'Database table drop when uninstall ?', 'yesno', 'no');
88 $sql = 'CREATE TABLE IF NOT EXISTS %s ('
89 . 'comid int(11) NOT NULL,'
90 . 'secflg int(11) NOT NULL,'
91 . 'PRIMARY KEY(comid) );';
92 sql_query(sprintf($sql, sql_table('plug_ezcomment2')));
98 if ($this->getOption('tabledel') == 'yes')
99 sql_query('DROP TABLE '.sql_table('plug_ezcomment2'));
104 $language = ereg_replace( '[\\|/]', '', getLanguageName());
105 if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
106 include_once($this->getDirectory() . 'language/' . $language . '.php');
108 include_once($this->getDirectory() . 'language/english.php');
113 function doTemplateVar(&$item,
116 $destinationurl = '',
117 $formTemplate = 'EzCommentTemplateDefault',
118 $listTemplate = 'EzCommentTemplateDefault')
120 $this->doSkinVar('template', $showType, $showMode, $destinationurl, $formTemplate, $listTemplate, $item);
123 function doSkinVar($skinType,
126 $destinationurl = '',
127 $formTemplate = 'EzCommentTemplateDefault',
128 $listTemplate = 'EzCommentTemplateDefault',
131 if ($skinType != 'item' && $skinType != 'template') return;
132 global $manager, $member, $itemid;
133 if (!$commentItem && $itemid) {
134 $commentItem = $manager->getItem($itemid, 0, 0);
135 if (is_array($commentItem)) {
136 $commentItem = (object)$commentItem;
139 if (!$commentItem || $commentItem->closed) {
140 echo _ERROR_ITEMCLOSED;
144 if (is_numeric($showType) || strpos($showType, '/') !== false) $showMode = $showType;
145 if ($showType != 'list' && $showType != 'form') {
151 list($maxToShow, $sortOrder, $commentOrder) = explode('/', $showMode);
152 if (!$maxToShow) $maxToShow = 5;
153 if (!$sortOrder) $sortOrder = 1;
154 if (!$commentOrder) $commentOrder = 1;
155 if (!$formTemplate) $formTemplate = 'EzCommentTemplateDefault';
156 if (!$listTemplate) $listTemplate = 'EzCommentTemplateDefault';
160 $listTemplate = TEMPLATE::read($listTemplate);
161 $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder);
164 $formTemplate = TEMPLATE::read($formTemplate);
165 $this->showForm($commentItem, $formTemplate, $destinationurl);
168 $listTemplate = TEMPLATE::read($listTemplate);
169 $formTemplate = TEMPLATE::read($formTemplate);
171 $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder);
172 $this->showForm($commentItem, $formTemplate, $destinationurl);
174 $this->showForm($commentItem, $formTemplate, $destinationurl);
175 $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder);
181 // FORM START ---------------------------------------
182 function showForm($commentItem, $template, $destinationurl)
184 global $CONF, $manager, $member, $catid, $subcatid;
185 $bid = getBlogIDFromItemID($commentItem->itemid);
186 $b =& $manager->getBlog($bid);
188 if (!$member->isLoggedIn() && !$b->commentsEnabled()) {
191 if (stristr($destinationurl, 'action.php') || empty($destinationurl)) {
192 if (stristr($destinationurl, 'action.php')) {
193 $logMessage = 'actionurl is not longer a parameter on commentform skinvars.'
194 . ' Moved to be a global setting instead.';
195 ACTIONLOG::add(WARNING, $logMessage);
198 $linkparams['catid'] = intval($catid);
200 if ($manager->pluginInstalled('NP_MultipleCategories') && $subcatid) {
201 $linkparams['subcatid'] = intval($subcatid);
203 $destinationurl = createItemLink($commentItem->itemid, $linkparams);
205 $destinationurl = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $destinationurl);
208 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
210 $user = postVar('user');
212 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
214 $userid = postVar('userid');
216 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
218 $email = postVar('email');
220 $body = postVar('body');
221 $checked = cookieVar($CONF['CookiePrefix'] .'comment_user') ? 'checked="checked" ' : '';
224 'self' => $this->_hsc(serverVar('REQUEST_URI')),
225 'destinationurl' => $this->_hsc($destinationurl),
226 'actionurl' => $this->_hsc($CONF['ActionURL']),
227 'itemid' => intval($commentItem->itemid),
228 'user' => $this->_hsc($user),
229 'userid' => $this->_hsc($userid),
230 'email' => $this->_hsc($email),
231 'body' => $this->_hsc($body),
232 // 'membername' => $this->_hsc($membername),
233 'rememberchecked' => $checked
235 if ($member && $member->isLoggedIn()) {
236 $formType = 'COMMENT_FORM_LOGGEDIN';
237 $loginMember = $member->createFromID($member->getID());
238 $formdata['membername'] = $this->_hsc($loginMember->getDisplayName());
240 $formType = 'COMMENT_FORM_NOTLOGGEDIN';
242 $contents = $template[$formType];
243 $formAction =& new EzCommentFormActions($commentItem, $formdata, $loginMember);
244 $parser =& new PARSER($formAction->getAllowedActions(), $formAction);
245 $parser->parse(&$contents);
248 // FORM END -----------------------------------------*/
250 // LIST START ---------------------------------------
251 function showComment($commentItem, $template, $maxToShow, $commentOrder)
254 $bid = getBlogIDFromItemID($commentItem->itemid);
255 $b =& $manager->getBlog($bid);
256 if (!$b->commentsEnabled()) return;
258 $maxToShow = $b->getMaxComments();
260 $itemActions =& new ITEMACTIONS($b);
261 $itemActions->setCurrentItem($commentItem);
262 $commentObj =& new COMMENTS($commentItem->itemid);
263 $commentObj->setItemActions($itemActions);
264 $commentObj->commentcount = $commentObj->amountComments();
265 // create parser object & action handler
266 $actions =& new EzCommentActions($commentObj);
267 $parser =& new PARSER($actions->getAllowedActions(), $actions);
268 $actions->setTemplate($template);
269 $actions->setParser($parser);
270 if ($commentObj->commentcount == 0) {
271 $parser->parse($template['COMMENTS_NONE']);
274 $actions->setPostnum($commentObj->commentcount);
275 if ($maxToShow && $maxToShow < $commentObj->commentcount && $commentOrder) {
276 $startnum = $commentObj->commentcount - $maxToShow;
280 $order = ($commentOrder) ? "DESC" : "ASC";
282 . 'c.citem as itemid, '
283 . 'c.cnumber as commentid, '
284 . 'c.cbody as body, '
285 . 'c.cuser as user, '
286 . 'c.cmail as userid, '
287 . 'c.cemail as email, '
288 . 'c.cmember as memberid, '
290 . 'c.chost as host, '
292 . 'c.cblog as blogid'
293 . ' FROM ' . sql_table('comment') . ' as c'
294 . ' WHERE c.citem=' . intval($commentItem->itemid)
295 . ' ORDER BY c.ctime '
298 if ($order == "DESC") {
299 $query .=' LIMIT ' . intval($maxToShow);
301 $query .=' LIMIT ' . intval($startnum) . ',' . intval($maxToShow);
304 $comments = sql_query($query);
305 $viewnum = mysql_num_rows($comments);
306 $actions->setViewnum($viewnum);
308 $parser->parse($template['COMMENTS_HEADER']);
310 while ( $comment = mysql_fetch_assoc($comments) ) {
311 $comment['timestamp'] = strtotime($comment['ctime']);
312 $actions->setCurrentComment($comment);
313 $manager->notify('PreComment', array('comment' => &$comment));
314 $parser->parse($template['COMMENTS_BODY']);
315 $manager->notify('PostComment', array('comment' => &$comment));
318 $parser->parse($template['COMMENTS_FOOTER']);
320 mysql_free_result($comments);
323 // LIST END -----------------------------------------
325 function getTemplateParts()
327 $this->languageInclude();
329 'COMMENT_FORM_LOGGEDIN' => _NP_EZCOMMENT2_FORM_LOGGEDIN,
330 'COMMENT_FORM_NOTLOGGEDIN' => _NP_EZCOMMENT2_FORM_NOTLOGGEDIN,
336 return htmlspecialchars($str, ENT_QUOTES, _CHARSET);
340 class EzCommentFormActions extends ACTIONS
347 function EzCommentFormActions(&$item, $formdata, $member)
349 $this->ACTIONS('item');
350 $this->commentItem =& $item;
351 $this->formdata = $formdata;
352 $this->loginMember = $member;
355 function getAllowedActions()
372 function parse_itemid() {
373 echo $this->commentItem->itemid;
376 function parse_itemlink($linktext = '') {
378 $this->_itemlink($this->commentItem->itemid, $linktext);
381 function parse_itemtitle($format = '') {
384 echo stringToXML ($this->commentItem->itemtitle);
387 echo stringToAttribute ($this->commentItem->itemtitle);
390 echo $this->commentItem->itemtitle;
393 echo $this->_hsc(strip_tags($this->commentItem->itemtitle));
398 function parse_membername($mode='')
400 if ($mode == 'realname') {
401 echo $this->_hsc($this->loginMember->getRealName());
403 echo $this->_hsc($this->loginMember->getDisplayName());
407 function parse_memberurl()
409 echo $this->_hsc($this->loginMember->getURL());
414 return htmlspecialchars($str, ENT_QUOTES, _CHARSET);
419 class EzCommentActions extends COMMENTACTIONS
426 function EzCommentActions(&$comments)
428 $this->COMMENTACTIONS($comments);
431 function getAllowedActions()
433 $allowedActions = $this->getDefinedActions();
434 $allowedActions[] = 'viewnum';
435 $allowedActions[] = 'postnum';
436 $allowedActions[] = 'viewparpost';
437 return $allowedActions;
440 function setPostnum($postnum)
442 $this->postnum = $postnum;
445 function setViewnum($viewnum)
447 $this->viewnum = $viewnum;
450 function parse_viewnum()
452 echo intval($this->viewnum);
455 function parse_postnum()
457 echo intval($this->postnum);
460 function parse_viewparpost()
462 echo intval($this->viewnum) . ' ';
463 if ($this->postnum > $this->viewnum) {
464 echo '/ ' . $this->postnum . ' ';
466 $this->parse_commentword();