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