1: <?php
  2: define('COMMENTS_PER_PAGE', max(1, getOption('comment_form_comments_per_page')));
  3: 
  4: $_zp_comment_stored = array();
  5: 
  6: function comment_form_PaginationJS() {
  7:     ?>
  8:     <script type="text/javascript" src="<?php echo WEBPATH . '/' . ZENFOLDER; ?>/js/jquery.pagination.js"></script>
  9:     <script type="text/javascript">
 10:         function pageselectCallback(page_index, jq) {
 11:             var items_per_page = <?php echo max(1, COMMENTS_PER_PAGE); ?>;
 12:             var max_elem = Math.min((page_index + 1) * items_per_page, $('#comments div.comment').length);
 13:             var newcontent = '';
 14:             for (var i = page_index * items_per_page; i < max_elem; i++) {
 15:                 newcontent += '<div class="comment">' + $('#comments div.comment:nth-child(' + (i + 1) + ')').html() + '</div>';
 16:             }
 17:             $('#Commentresult').html(newcontent);
 18:             return false;
 19:         }
 20:         function initPagination() {
 21:             var startPage;
 22:             if (Comm_ID_found) {
 23:                 startPage = Math.ceil(current_comment_N /<?php echo max(1, COMMENTS_PER_PAGE); ?>) - 1;
 24:             } else {
 25:                 startPage = 0;
 26:             }
 27:             var num_entries = $('#comments div.comment').length;
 28:             if (num_entries) {
 29:                 $(".Pagination").pagination(num_entries, {
 30:                     prev_text: "<?php echo gettext('prev'); ?>",
 31:                     next_text: "<?php echo gettext('next'); ?>",
 32:                     callback: pageselectCallback,
 33:                     load_first_page: true,
 34:                     items_per_page:<?php echo max(1, getOption('comment_form_comments_per_page')); ?>, 
 35:                     current_page: startPage
 36:                 });
 37:             }
 38:         }
 39:         $(document).ready(function() {
 40:             current_comment_N = $('.comment h4').index($(addrBar_hash)) + 1;
 41:             initPagination();
 42:             if (Comm_ID_found) {
 43:                 $(addrBar_hash).scrollToMe();
 44:             }
 45:         });
 46:         var current_comment_N, addrBar_hash = window.location.hash, Comm_ID_found = !addrBar_hash.search(/
 47:         jQuery.fn.extend({
 48:             scrollToMe: function() {
 49:                 var x = jQuery(this).offset().top - 10;
 50:                 jQuery('html,body').animate({scrollTop: x}, 400);
 51:             }});
 52:     </script>
 53:     <?php
 54: }
 55: 
 56: function comment_form_visualEditor() {
 57:     zp_apply_filter('texteditor_config', 'comments');
 58: }
 59: 
 60:  61:  62: 
 63: function comment_form_print10Most() {
 64:     ?>
 65:     <div class="box overview-utility">
 66:         <h2 class="h2_bordered"><?php echo gettext("10 Most Recent Comments"); ?></h2>
 67:         <ul>
 68:             <?php
 69:             $comments = fetchComments(10);
 70:             foreach ($comments as $comment) {
 71:                 $id = $comment['id'];
 72:                 $author = $comment['name'];
 73:                 $email = $comment['email'];
 74:                 $link = gettext('<strong>database error</strong> '); 
 75:                 
 76:                 switch ($comment['type']) {
 77:                     case "albums":
 78:                         $album = getItemByID('albums', $comment['ownerid']);
 79:                         if ($album) {
 80:                             $link = "<a href=\"" . $album->getlink() . "\">" . $album->gettitle() . "</a>";
 81:                         }
 82:                         break;
 83:                     case "news": 
 84:                         if (extensionEnabled('zenpage')) {
 85:                             $news = getItemByID('news', $comment['ownerid']);
 86:                             if ($news) {
 87:                                 $link = "<a href=\"" . $news->getLink() . "\">" . $news->getTitle() . "</a> " . gettext("[news]");
 88:                             }
 89:                         }
 90:                         break;
 91:                     case "pages": 
 92:                         if (extensionEnabled('zenpage')) {
 93:                             $page = getItemByID('pages', $comment['ownerid']);
 94:                             if ($page) {
 95:                                 $link = "<a href=\"" . $page->getlink() . "\">" . $page->getTitle() . "</a> " . gettext("[page]");
 96:                             }
 97:                         }
 98:                         break;
 99:                     default: 
100:                         $image = getItemByID('images', $comment['ownerid']);
101:                         if ($image) {
102:                             $link = "<a href=\"" . $image->getLink() . "\">" . $image->getTitle() . "</a>";
103:                         }
104:                         break;
105:                 }
106:                 $comment = shortenContent($comment['comment'], 123, '...');
107:                 echo "<li><div class=\"commentmeta\">" . sprintf(gettext('<em>%1$s</em> commented on %2$s:'), $author, $link) . "</div><div class=\"commentbody\">$comment</div></li>";
108:             }
109:             ?>
110:         </ul>
111:     </div>
112:     <?php
113: }
114: 
115: 116: 117: 118: 119: 120: 
121: function getCommentAddress($i) {
122:     $result = array();
123:     if (isset($_POST[$i . '-comment_form_website']))
124:         $result['website'] = sanitize($_POST[$i . '-comment_form_website'], 1);
125:     if (isset($_POST[$i . '-comment_form_street']))
126:         $result['street'] = sanitize($_POST[$i . '-comment_form_street'], 1);
127:     if (isset($_POST[$i . '-comment_form_city']))
128:         $result['city'] = sanitize($_POST[$i . '-comment_form_city'], 1);
129:     if (isset($_POST[$i . '-comment_form_state']))
130:         $result['state'] = sanitize($_POST[$i . '-comment_form_state'], 1);
131:     if (isset($_POST[$i . '-comment_form_country']))
132:         $result['country'] = sanitize($_POST[$i . '-comment_form_country'], 1);
133:     if (isset($_POST[$i . '-comment_form_postal']))
134:         $result['postal'] = sanitize($_POST[$i . '-comment_form_postal'], 1);
135:     return $result;
136: }
137: 
138: 139: 140: 141: 142: 
143: function getCommentErrors() {
144:     global $_zp_comment_error;
145:     return $_zp_comment_error;
146: }
147: 
148: 149: 150: 
151: function printCommentErrors() {
152:     global $_zp_comment_error, $_zp_comment_on_hold;
153:     if ($_zp_comment_on_hold) {
154:         $s = trim(str_replace($_zp_comment_on_hold, '', trim($_zp_comment_error)));
155:         ?>
156:         <p class="notebox"><?php echo $_zp_comment_on_hold; ?></p>
157:         <?php
158:     } else {
159:         $s = trim($_zp_comment_error);
160:     }
161:     if ($s) {
162:         $lines = explode('.', $s);
163:         foreach ($lines as $key => $line) {
164:             if (empty($line) || $line == gettext('Mail send failed')) {
165:                 unset($lines[$key]);
166:             }
167:         }
168:         ?>
169:         <div class="errorbox">
170:             <h2><?php echo ngettext('Error posting comment:', 'Errors posting comment:', count($lines)); ?></h2>
171:             <ul class="errorlist">
172:                 <?php
173:                 foreach ($lines as $line) {
174:                     echo '<li>' . trim($line) . '</li>';
175:                 }
176:                 ?>
177:             </ul>
178:         </div>
179:         <?php
180:     }
181: }
182: 
183: define('COMMENT_EMAIL_REQUIRED', 1);
184: define('COMMENT_NAME_REQUIRED', 2);
185: define('COMMENT_WEB_REQUIRED', 4);
186: define('USE_CAPTCHA', 8);
187: define('COMMENT_BODY_REQUIRED', 16);
188: define('COMMENT_SEND_EMAIL', 32);
189: 
190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 
211: function comment_form_addComment($name, $email, $website, $comment, $code, $code_ok, $receiver, $ip, $private, $anon, $customdata, $check = false) {
212:     global $_zp_captcha, $_zp_gallery, $_zp_authority, $_zp_comment_on_hold, $_zp_spamFilter;
213:     if ($check === false) {
214:         $whattocheck = 0;
215:         if (getOption('comment_email_required') == 'required')
216:             $whattocheck = $whattocheck | COMMENT_EMAIL_REQUIRED;
217:         if (getOption('comment_name_required'))
218:             $whattocheck = $whattocheck | COMMENT_NAME_REQUIRED;
219:         if (getOption('comment_web_required') == 'required')
220:             $whattocheck = $whattocheck | COMMENT_WEB_REQUIRED;
221:         switch (getOption('Use_Captcha')) {
222:             case 0:
223:                 break;
224:             case 2:
225:                 if (zp_loggedin(POST_COMMENT_RIGHTS)) {
226:                     break;
227:                 }
228:             default:
229:                 $whattocheck = $whattocheck | USE_CAPTCHA;
230:                 break;
231:         }
232:         if (getOption('comment_body_requiired'))
233:             $whattocheck = $whattocheck | COMMENT_BODY_REQUIRED;
234:         IF (getOption('email_new_comments'))
235:             $whattocheck = $whattocheck | COMMENT_SEND_EMAIL;
236:     } else {
237:         $whattocheck = $check;
238:     }
239:     $type = $receiver->table;
240:     $receiver->getComments();
241:     $name = trim($name);
242:     $email = trim($email);
243:     $website = trim($website);
244: 
245: 
246:     $comment = trim($comment);
247:     $receiverid = $receiver->getID();
248:     $goodMessage = 2;
249:     if ($private)
250:         $private = 1;
251:     else
252:         $private = 0;
253:     if ($anon)
254:         $anon = 1;
255:     else
256:         $anon = 0;
257:     $commentobj = new Comment();
258:     $commentobj->transient = false; 
259:     $commentobj->setOwnerID($receiverid);
260:     $commentobj->setName($name);
261:     $commentobj->setEmail($email);
262:     $commentobj->setWebsite($website);
263:     $commentobj->setComment($comment);
264:     $commentobj->setType($type);
265:     $commentobj->setIP($ip);
266:     $commentobj->setPrivate($private);
267:     $commentobj->setAnon($anon);
268:     $commentobj->setInModeration(0);
269:     $commentobj->setCustomData($customdata);
270:     if (($whattocheck & COMMENT_EMAIL_REQUIRED) && (empty($email) || !is_valid_email_zp($email))) {
271:         $commentobj->setInModeration(-2);
272:         $commentobj->comment_error_text .= ' ' . gettext("You must supply an e-mail address.");
273:         $goodMessage = false;
274:     }
275:     if (($whattocheck & COMMENT_NAME_REQUIRED) && empty($name)) {
276:         $commentobj->setInModeration(-3);
277:         $commentobj->comment_error_text .= ' ' . gettext("You must enter your name.");
278:         $goodMessage = false;
279:     }
280:     if (($whattocheck & COMMENT_WEB_REQUIRED) && (empty($website) || !isValidURL($website))) {
281:         $commentobj->setInModeration(-4);
282:         $commentobj->comment_error_text .= ' ' . gettext("You must supply a WEB page URL.");
283:         $goodMessage = false;
284:     }
285:     if (($whattocheck & USE_CAPTCHA)) {
286:         if (!$_zp_captcha->checkCaptcha($code, $code_ok)) {
287:             $commentobj->setInModeration(-5);
288:             $commentobj->comment_error_text .= ' ' . gettext("CAPTCHA verification failed.");
289:             $goodMessage = false;
290:         }
291:     }
292:     if (($whattocheck & COMMENT_BODY_REQUIRED) && empty($comment)) {
293:         $commentobj->setInModeration(-6);
294:         $commentobj->comment_error_text .= ' ' . gettext("You must enter something in the comment text.");
295:         $goodMessage = false;
296:     }
297:     $moderate = 0;
298:     if ($goodMessage && isset($_zp_spamFilter)) {
299:         $goodMessage = $_zp_spamFilter->filterMessage($name, $email, $website, $comment, $receiver, $ip);
300:         switch ($goodMessage) {
301:             case 0:
302:                 $commentobj->setInModeration(2);
303:                 $commentobj->comment_error_text .= sprintf(gettext('Your comment was rejected by the <em>%s</em> SPAM filter.'), $_zp_spamFilter->name);
304:                 $goodMessage = false;
305:                 break;
306:             case 1:
307:                 $_zp_comment_on_hold = sprintf(gettext('Your comment has been marked for moderation by the <em>%s</em> SPAM filter.'), $_zp_spamFilter->name);
308:                 $commentobj->comment_error_text .= $_zp_comment_on_hold;
309:                 $commentobj->setInModeration(1);
310:                 $moderate = 1;
311:                 break;
312:             case 2:
313:                 $commentobj->setInModeration(0);
314:                 break;
315:         }
316:     }
317:     $localerrors = $commentobj->getInModeration();
318:     zp_apply_filter('comment_post', $commentobj, $receiver);
319:     if ($check === false) {
320:         
321:         $localerrors = $commentobj->getInModeration();
322:     }
323:     if ($goodMessage && $localerrors >= 0) {
324:         
325:         $commentobj->save();
326:         
327:         if (!$moderate) {
328:             $receiver->comments[] = array('name'                 => $commentobj->getname(),
329:                             'email'              => $commentobj->getEmail(),
330:                             'website'            => $commentobj->getWebsite(),
331:                             'comment'            => $commentobj->getComment(),
332:                             'date'               => $commentobj->getDateTime(),
333:                             'custom_data'    => $commentobj->getCustomData());
334:         }
335:         switch ($type) {
336:             case "albums":
337:                 $url = "album=" . pathurlencode($receiver->name);
338:                 $ur_album = getUrAlbum($receiver);
339:                 if ($moderate) {
340:                     $action = sprintf(gettext('A comment has been placed in moderation on your album “%1$s”.'), $receiver->name);
341:                 } else {
342:                     $action = sprintf(gettext('A comment has been posted on your album “%1$s”.'), $receiver->name);
343:                 }
344:                 break;
345:             case "news":
346:                 $url = "p=news&title=" . urlencode($receiver->getTitlelink());
347:                 if ($moderate) {
348:                     $action = sprintf(gettext('A comment has been placed in moderation on your article “%1$s”.'), $receiver->getTitlelink());
349:                 } else {
350:                     $action = sprintf(gettext('A comment has been posted on your article “%1$s”.'), $receiver->getTitlelink());
351:                 }
352:                 break;
353:             case "pages":
354:                 $url = "p=pages&title=" . urlencode($receiver->getTitlelink());
355:                 if ($moderate) {
356:                     $action = sprintf(gettext('A comment has been placed in moderation on your page “%1$s”.'), $receiver->getTitlelink());
357:                 } else {
358:                     $action = sprintf(gettext('A comment has been posted on your page “%1$s”.'), $receiver->getTitlelink());
359:                 }
360:                 break;
361:             default: 
362:                 $album = $receiver->getAlbum();
363:                 $url = "album=" . pathurlencode($album->name) . "&image=" . urlencode($receiver->filename);
364:                 $ur_album = getUrAlbum($album);
365:                 if ($moderate) {
366:                     $action = sprintf(gettext('A comment has been placed in moderation on your image “%1$s” in the album “%2$s”.'), $receiver->getTitle(), $album->name);
367:                 } else {
368:                     $action = sprintf(gettext('A comment has been posted on your image “%1$s” in the album “%2$s”.'), $receiver->getTitle(), $album->name);
369:                 }
370:                 break;
371:         }
372:         if (($whattocheck & COMMENT_SEND_EMAIL)) {
373:             $message = $action . "\n\n" .
374:                             sprintf(gettext('Author: %1$s' . "\n" . 'Email: %2$s' . "\n" . 'Website: %3$s' . "\n" . 'Comment:' . "\n\n" . '%4$s'), $commentobj->getname(), $commentobj->getEmail(), $commentobj->getWebsite(), $commentobj->getComment()) . "\n\n" .
375:                             sprintf(gettext('You can view all comments about this item here:' . "\n" . '%1$s'), 'http://' . $_SERVER['SERVER_NAME'] . WEBPATH . '/index.php?' . $url) . "\n\n" .
376:                             sprintf(gettext('You can edit the comment here:' . "\n" . '%1$s'), 'http://' . $_SERVER['SERVER_NAME'] . WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/comment_form/admin-comments.php?page=editcomment&id=' . $commentobj->getID());
377:             $emails = array();
378:             $admin_users = $_zp_authority->getAdministrators();
379:             foreach ($admin_users as $admin) {
380:                 
381:                 if (!empty($admin['email']) && (($admin['rights'] & ADMIN_RIGHTS) ||
382:                                 (($admin['rights'] & (MANAGE_ALL_ALBUM_RIGHTS | COMMENT_RIGHTS)) == (MANAGE_ALL_ALBUM_RIGHTS | COMMENT_RIGHTS)))) {
383:                     $emails[] = $admin['email'];
384:                     unset($admin_users[$admin['id']]);
385:                 }
386:             }
387:             if ($type === "images" OR $type === "albums") {
388:                 
389:                 $id = $ur_album->getID();
390:                 $sql = 'SELECT `adminid` FROM ' . prefix('admin_to_object') . ' WHERE `objectid`=' . $id . ' AND `type` LIKE "album%"';
391:                 $result = query($sql);
392:                 if ($result) {
393:                     while ($anadmin = db_fetch_assoc($result)) {
394:                         $id = $anadmin['adminid'];
395:                         if (array_key_exists($id, $admin_users)) {
396:                             $admin = $admin_users[$id];
397:                             if (($admin['rights'] & COMMENT_RIGHTS) && !empty($admin['email'])) {
398:                                 $emails[] = $admin['email'];
399:                             }
400:                         }
401:                     }
402:                     db_free_result($result);
403:                 }
404:             }
405:             $on = gettext('Comment posted');
406:             $result = zp_mail("[" . $_zp_gallery->getTitle() . "] $on", $message, $emails);
407:             if ($result) {
408:                 $commentobj->setInModeration(-12);
409:                 $commentobj->comment_error_text = $result;
410:             }
411:         }
412:     }
413:     return $commentobj;
414: }
415: 
416: 417: 418: 419: 
420: function commentFormUseCaptcha() {
421:     switch (getOption('Use_Captcha')) {
422:         case 0:
423:             return false;
424:         case 2:
425:             return !zp_loggedin(POST_COMMENT_RIGHTS);
426:         default:
427:             return true;
428:     }
429: }
430: 
431: 432: 433: 434: 435: 
436: function comment_form_postcomment($error) {
437:     global $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_news, $_zp_current_zenpage_page;
438:     if (( (commentsAllowed('comment_form_albums') && in_context(ZP_ALBUM) && !in_context(ZP_IMAGE) && $_zp_current_album->getCommentsAllowed()) ||
439:                     (commentsAllowed('comment_form_images') && in_context(ZP_IMAGE) && $_zp_current_image->getCommentsAllowed()) ||
440:                     (commentsAllowed('comment_form_articles') && in_context(ZP_ZENPAGE_NEWS_ARTICLE) && $_zp_current_zenpage_news->getCommentsAllowed()) ||
441:                     (commentsAllowed('comment_form_pages') && in_context(ZP_ZENPAGE_PAGE) && $_zp_current_zenpage_page->getCommentsAllowed()))
442:     ) {
443:         $error = comment_form_handle_comment();
444:     }
445:     return $error;
446: }
447: 
448: 449: 450: 451: 452: 
453: function comment_form_handle_comment() {
454:     global $_zp_current_image, $_zp_current_album, $_zp_comment_stored, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_HTML_cache;
455:     $comment_error = 0;
456:     $cookie = zp_getCookie('zenphoto_comment');
457:     if (isset($_POST['comment']) && (!isset($_POST['username']) || empty($_POST['username']))) { 
458:         459: 460: 461: 462: 
463:         $_zp_HTML_cache->disable();
464:         if (in_context(ZP_IMAGE)) {
465:             $commentobject = $_zp_current_image;
466:             $redirectTo = $_zp_current_image->getLink();
467:         } else if (in_context(ZP_ALBUM)) {
468:             $commentobject = $_zp_current_album;
469:             $redirectTo = $_zp_current_album->getLink();
470:         } else if (in_context(ZP_ZENPAGE_NEWS_ARTICLE)) {
471:             $commentobject = $_zp_current_zenpage_news;
472:             $redirectTo = FULLWEBPATH . '/index.php?p=news&title=' . $_zp_current_zenpage_news->getTitlelink();
473:         } else if (in_context(ZP_ZENPAGE_PAGE)) {
474:             $commentobject = $_zp_current_zenpage_page;
475:             $redirectTo = FULLWEBPATH . '/index.php?p=pages&title=' . $_zp_current_zenpage_page->getTitlelink();
476:         } else {
477:             $commentobject = NULL;
478:             $error = gettext('Comment posted on unknown page!');
479:         }
480:         if (is_object($commentobject)) {
481:             if (isset($_POST['name'])) {
482:                 $p_name = sanitize($_POST['name'], 3);
483:             } else {
484:                 $p_name = NULL;
485:             }
486:             if (isset($_POST['email'])) {
487:                 $p_email = sanitize($_POST['email'], 3);
488:                 if (!is_valid_email_zp($p_email)) {
489:                     $p_email = NULL;
490:                 }
491:             } else {
492:                 $p_email = NULL;
493:             }
494:             if (isset($_POST['website'])) {
495:                 $p_website = sanitize($_POST['website'], 3);
496:                 if ($p_website && strpos($p_website, 'http') !== 0) {
497:                     $p_website = 'http://' . $p_website;
498:                 }
499:                 if (!isValidURL($p_website)) {
500:                     $p_website = NULL;
501:                 }
502:             } else {
503:                 $p_website = NULL;
504:             }
505:             if (isset($_POST['comment'])) {
506:                 $p_comment = sanitize($_POST['comment'], 1);
507:             } else {
508:                 $p_comment = '';
509:             }
510:             $p_server = getUserIP();
511:             if (isset($_POST['code'])) {
512:                 $code1 = sanitize($_POST['code'], 3);
513:                 $code2 = sanitize($_POST['code_h'], 3);
514:             } else {
515:                 $code1 = '';
516:                 $code2 = '';
517:             }
518:             $p_private = isset($_POST['private']);
519:             $p_anon = isset($_POST['anon']);
520: 
521:             $commentadded = $commentobject->addComment($p_name, $p_email, $p_website, $p_comment, $code1, $code2, $p_server, $p_private, $p_anon, serialize(getCommentAddress(0)));
522: 
523:             $comment_error = $commentadded->getInModeration();
524:             $_zp_comment_stored = array('name'       => $commentadded->getName(),
525:                             'email'      => $commentadded->getEmail(),
526:                             'website'    => $commentadded->getWebsite(),
527:                             'comment'    => $commentadded->getComment(),
528:                             'saved'      => isset($_POST['remember']),
529:                             'private'    => $commentadded->getPrivate(),
530:                             'anon'       => $commentadded->getAnon(),
531:                             'custom'     => $commentadded->getCustomData()
532:             );
533: 
534:             if ($comment_error) {
535:                 $error = $commentadded->comment_error_text;
536:                 $comment_error++;
537:             } else {
538:                 $_zp_HTML_cache->clearHtmlCache();
539:                 $error = NULL;
540:                 if (isset($_POST['remember'])) {
541:                     
542:                     $_zp_comment_stored['comment'] = ''; 
543:                     zp_setCookie('zenphoto_comment', serialize($_zp_comment_stored));
544:                 } else {
545:                     zp_clearCookie('zenphoto_comment');
546:                 }
547:                 
548:                 if (!isset($_SERVER['SERVER_SOFTWARE']) || strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'microsoft-iis') === false) {
549:                     
550:                     header('Location: ' . $redirectTo . '#zp_comment_id_' . $commentadded->getId());
551:                     exitZP();
552:                 }
553:             }
554:         }
555:         return $error;
556:     } else {
557:         if (!empty($cookie)) {
558:             $cookiedata = getSerializedArray($cookie);
559:             if (count($cookiedata) > 1) {
560:                 $_zp_comment_stored = $cookiedata;
561:             }
562:         }
563:     }
564:     return false;
565: }
566: 
567: 568: 569: 570: 571: 
572: function getCommentAuthorName() {
573:     global $_zp_current_comment;
574:     return $_zp_current_comment['name'];
575: }
576: 
577: 578: 579: 580: 581: 
582: function getCommentAuthorEmail() {
583:     global $_zp_current_comment;
584:     return $_zp_current_comment['email'];
585: }
586: 
587: 588: 589: 590: 591: 
592: function getCommentAuthorSite() {
593:     global $_zp_current_comment;
594:     return $_zp_current_comment['website'];
595: }
596: 
597: 598: 599: 600: 601: 602: 603: 
604: function getCommentAuthorLink($title = NULL, $class = NULL, $id = NULL) {
605:     global $_zp_current_comment;
606:     $name = $_zp_current_comment['name'];
607:     if ($_zp_current_comment['anon']) {
608:         $site = NULL;
609:     } else {
610:         $site = $_zp_current_comment['website'];
611:     }
612:     if (empty($site)) {
613:         return html_encode($_zp_current_comment['name']);
614:     } else {
615:         if (is_null($title)) {
616:             $title = "Visit " . $name;
617:         }
618:         return getLinkHTML($site, $_zp_current_comment['name'], $title, $class, $id);
619:     }
620: }
621: 
622: 623: 624: 625: 626: 627: 628: 
629: function printCommentAuthorLink($title = NULL, $class = NULL, $id = NULL) {
630:     echo getCommentAuthorLink($title, $class, $id);
631: }
632: 
633: 634: 635: 636: 637: 638: 639: 640: 
641: function getCommentDateTime($format = NULL) {
642:     if (is_null($format)) {
643:         $format = DATE_FORMAT;
644:     }
645:     global $_zp_current_comment;
646:     return myts_date($format, $_zp_current_comment['date']);
647: }
648: 
649: 650: 651: 652: 653: 
654: function getCommentBody() {
655:     global $_zp_current_comment;
656:     return str_replace("\n", "<br />", stripslashes($_zp_current_comment['comment']));
657: }
658: 
659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 
669: function printEditCommentLink($text, $before = '', $after = '', $title = NULL, $class = NULL, $id = NULL) {
670:     global $_zp_current_comment;
671:     if (zp_loggedin(COMMENT_RIGHTS)) {
672:         if ($before) {
673:             echo '<span class="beforetext">' . html_encode($before) . '</span>';
674:         }
675:         printLinkHTML(WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/comment_form//admin-comments.php?page=editcomment&id=' . $_zp_current_comment['id'], $text, $title, $class, $id);
676:         if ($after) {
677:             echo '<span class="aftertext">' . html_encode($after) . '</span>';
678:         }
679:     }
680: }
681: 
682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 
694: function getLatestComments($number, $type = "all", $id = NULL) {
695:     global $_zp_gallery;
696:     $albumcomment = $imagecomment = NULL;
697:     $comments = array();
698:     $whereclause = '';
699:     switch ($type) {
700:         case is_array($type):
701:             $whereclause = ' AND `type` IN ("' . implode('","', $type) . '")';
702:         case 'all':
703:             $sql = 'SELECT * FROM ' . prefix('comments') . ' WHERE `private`=0 AND `inmoderation`=0' . $whereclause . ' ORDER BY `date` DESC';
704:             $commentsearch = query($sql);
705:             if ($commentsearch) {
706:                 while ($number > 0 && $commentcheck = db_fetch_assoc($commentsearch)) {
707:                     $item = getItemByID($commentcheck['type'], $commentcheck['ownerid']);
708:                     if ($item && $item->checkAccess()) {
709:                         $number--;
710:                         $commentcheck['albumtitle'] = $commentcheck['titlelink'] = $commentcheck['folder'] = $commentcheck['filename'] = '';
711:                         $commentcheck['title'] = $item->getTitle('all');
712:                         switch ($item->table) {
713:                             case 'albums':
714:                                 $commentcheck['folder'] = $item->getFileName();
715:                                 $commentcheck['albumtitle'] = $commentcheck['title'];
716:                                 break;
717:                             case 'images':
718:                                 $commentcheck['filename'] = $item->filename;
719:                                 $commentcheck['folder'] = $item->album->name;
720:                                 $commentcheck['albumtitle'] = $item->album->getTitle('all');
721:                                 break;
722:                             case 'news':
723:                             case 'pages':
724:                                 $commentcheck['titlelink'] = $item->getTitlelink();
725:                                 break;
726:                         }
727:                         $commentcheck['pubdate'] = $commentcheck['date']; 
728:                         $comments[] = $commentcheck;
729:                     }
730:                 }
731:                 db_free_result($commentsearch);
732:             }
733:             return $comments;
734:         case 'album':
735:             if ($item = getItemByID('albums', $id)) {
736:                 $comments = array_slice($item->getComments(), 0, $number);
737:                 
738:                 foreach ($comments as $key => $comment) {
739:                     $comment['pubdate'] = $comment['date'];
740:                     $alb = getItemByID('albums', $comment['ownerid']);
741:                     $comment['folder'] = $alb->name;
742:                     $comment['albumtitle'] = $item->getTitle('all');
743:                     $comments[$key] = $comment;
744:                 }
745:                 return $comments;
746:             } else {
747:                 return array();
748:             }
749:         case 'image':
750:             if ($item = getItemByID('images', $id)) {
751:                 $comments = array_slice($item->getComments(), 0, $number);
752:                 
753:                 foreach ($comments as $key => $comment) {
754:                     $comment['pubdate'] = $comment['date'];
755:                     $img = getItemByID('images', $comment['ownerid']);
756:                     $comment['folder'] = $img->album->name;
757:                     $comment['filename'] = $img->filename;
758:                     $comment['title'] = $item->getTitle('all');
759:                     $comment['albumtitle'] = $img->album->getTitle('all');
760:                     $comments[$key] = $comment;
761:                 }
762:                 return $comments;
763:             } else {
764:                 return array();
765:             }
766:         case 'news':
767:             if ($item = getItemByID('news', $id)) {
768:                 $comments = array_slice($item->getComments(), 0, $number);
769:                 
770:                 foreach ($comments as $key => $comment) {
771:                     $comment['pubdate'] = $comment['date'];
772:                     $comment['titlelink'] = $item->getTitlelink();
773:                     $comment['title'] = $item->getTitle('all');
774:                     $comments[$key] = $comment;
775:                 }
776:                 return $comments;
777:             } else {
778:                 return array();
779:             }
780:         case 'page':
781:             if ($item = getItemByID('pages', $id)) {
782:                 $comments = array_slice($item->getComments(), 0, $number);
783:                 
784:                 foreach ($comments as $key => $comment) {
785:                     $comment['pubdate'] = $comment['date'];
786:                     $comment['titlelink'] = $item->getTitlelink();
787:                     $comment['title'] = $item->getTitle('all');
788:                     $comments[$key] = $comment;
789:                 }
790:                 return $comments;
791:             } else {
792:                 return array();
793:             }
794:     }
795: }
796: 
797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 
812: function printLatestComments($number, $shorten = '123', $type = "all", $item = NULL, $ulid = 'showlatestcomments', $shortenindicator = '...') {
813:     $comments = getLatestComments($number, $type, $item);
814:     echo '<ul id="' . $ulid . $item . "\">\n";
815:     foreach ($comments as $comment) {
816:         if ($comment['anon'] === "0") {
817:             $author = " " . gettext("by") . " " . $comment['name'];
818:         } else {
819:             $author = "";
820:         }
821:         $shortcomment = shortenContent($comment['comment'], $shorten, $shortenindicator);
822:         $website = $comment['website'];
823:         $date = $comment['date'];
824:         switch ($comment['type']) {
825:             case 'albums':
826:                 $album = getItemByID('albums', $comment['ownerid']);
827:                 if ($album) {
828:                     echo '<li><a href="' . $album->getLink() . '" class="commentmeta">' . $album->getTitle() . $author . "</a><br />\n";
829:                     echo '<span class="commentbody">' . $shortcomment . '</span></li>';
830:                 }
831:                 break;
832:             case 'images':
833:                 $image = getItemByID('images', $comment['ownerid']);
834:                 if ($image) {
835:                     echo '<li><a href="' . $image->getLink() . '" class="commentmeta">' . $image->album->gettitle() . ': ' . $image->getTitle() . $author . "</a><br />\n";
836:                     echo '<span class="commentbody">' . $shortcomment . '</span></li>';
837:                 }
838:                 break;
839:             case 'news':
840:                 $news = getItemByID('news', $comment['ownerid']);
841:                 if ($news) {
842:                     echo '<li><a href="' . $news->getLink() . '" class="commentmeta">' . gettext('News') . ':' . $news->getTitle() . $author . "</a><br />\n";
843:                     echo '<span class="commentbody">' . $shortcomment . '</span></li>';
844:                 }
845:                 break;
846:             case 'pages':
847:                 $page = getItemByID('news', $comment['ownerid']);
848:                 if ($page) {
849:                     echo '<li><a href="' . $page->getLink() . '" class="commentmeta">' . gettext('News') . ':' . $page->getTitle() . $author . "</a><br />\n";
850:                     echo '<span class="commentbody">' . $shortcomment . '</span></li>';
851:                 }
852:                 break;
853:         }
854:     }
855:     echo "</ul>\n";
856: }
857: 
858: 859: 860: 861: 862: 
863: function getCommentCount() {
864:     global $_zp_current_image, $_zp_current_album, $_zp_current_zenpage_page, $_zp_current_zenpage_news;
865:     if (in_context(ZP_IMAGE) && in_context(ZP_ALBUM)) {
866:         if (is_null($_zp_current_image))
867:             return false;
868:         return $_zp_current_image->getCommentCount();
869:     } else if (!in_context(ZP_IMAGE) && in_context(ZP_ALBUM)) {
870:         if (is_null($_zp_current_album))
871:             return false;
872:         return $_zp_current_album->getCommentCount();
873:     }
874:     if (function_exists('is_News')) {
875:         if (is_News()) {
876:             return $_zp_current_zenpage_news->getCommentCount();
877:         }
878:         if (is_Pages()) {
879:             return $_zp_current_zenpage_page->getCommentCount();
880:         }
881:     }
882: }
883: 
884: 885: 886: 887: 888: 889: 890: 
891: function next_comment($desc = false) {
892:     global $_zp_current_image, $_zp_current_album, $_zp_current_comment, $_zp_comments, $_zp_current_zenpage_page, $_zp_current_zenpage_news;
893: 
894:     if (is_null($_zp_current_comment)) {
895:         if (in_context(ZP_IMAGE) AND in_context(ZP_ALBUM)) {
896:             if (is_null($_zp_current_image))
897:                 return false;
898:             $_zp_comments = $_zp_current_image->getComments(false, false, $desc);
899:         } else if (!in_context(ZP_IMAGE) AND in_context(ZP_ALBUM)) {
900:             $_zp_comments = $_zp_current_album->getComments(false, false, $desc);
901:         }
902:         if (function_exists('is_NewsArticle')) {
903:             if (is_NewsArticle()) {
904:                 $_zp_comments = $_zp_current_zenpage_news->getComments(false, false, $desc);
905:             }
906:             if (is_Pages()) {
907:                 $_zp_comments = $_zp_current_zenpage_page->getComments(false, false, $desc);
908:             }
909:         }
910:         if (empty($_zp_comments)) {
911:             return false;
912:         }
913:     } else if (empty($_zp_comments)) {
914:         $_zp_comments = NULL;
915:         $_zp_current_comment = NULL;
916:         rem_context(ZP_COMMENT);
917:         return false;
918:     }
919:     $_zp_current_comment = array_shift($_zp_comments);
920:     if ($_zp_current_comment['anon']) {
921:         $_zp_current_comment['email'] = $_zp_current_comment['name'] = '<' . gettext("Anonymous") . '>';
922:     }
923:     add_context(ZP_COMMENT);
924:     return true;
925: }
926: 
927: 928: 929: 930: 931: 932: 
933: function getCommentStored($numeric = false) {
934:     global $_zp_comment_stored;
935:     if ($numeric) {
936:         return array_merge($_zp_comment_stored);
937:     }
938:     return $_zp_comment_stored;
939: }
940: 
941: 
942:     943: 944: 945: 946: 947: 948: 949: 
950:     function commentReply($obj, $author, $fullcomment) {
951:   if (is_object($obj)) {
952:     $comment = ": %0D%0A%0D%0A" . implode('%0D%0A', explode('\n', wordwrap(getBare($fullcomment), 75, '\n')));
953:     $message = '';
954:     switch ($obj->table) {
955:       case 'albums':
956:         $title = $obj->getTitle();
957:         $message = sprintf(gettext('%1$s commented on album %2$s%3$s'), $author, $obj->getTitle(),$comment);
958:         break;
959:       default:
960:       case 'images':
961:         $message = sprintf(gettext('%1$s commented on %2$s in album %3$s%4$s'), $author, $obj->getTitle(), $obj->getAlbum()->getTitle(), $comment);
962:         break;
963:       case 'news':
964:       case 'pages':
965:         $message = sprintf(gettext('%1$s commented on %2$s%3$s'), $author, $obj->getTitle(),$comment);
966:         break;
967:     }
968:     return $message;
969:   }
970: }
971: ?>