1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: $plugin_is_filter = 5 | CLASS_PLUGIN;
18: $plugin_description = gettext("Provides a unified comment handling facility.");
19: $plugin_author = "Stephen Billard (sbillard)";
20:
21: $option_interface = 'comment_form';
22:
23: zp_register_filter('admin_toolbox_global', 'comment_form::toolbox');
24:
25: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/comment_form/class-comment.php');
26: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/comment_form/functions.php');
27:
28: if (OFFSET_PATH) {
29: zp_register_filter('admin_overview', 'comment_form_print10Most');
30: zp_register_filter('admin_tabs', 'comment_form::admin_tabs');
31: } else {
32: zp_register_filter('handle_comment', 'comment_form_postcomment');
33: zp_register_filter('object_addComment', 'comment_form_addComment');
34: if (getOption('comment_form_pagination')) {
35: zp_register_filter('theme_head', 'comment_form_PaginationJS');
36: }
37: if (getOption('tinymce4_comments')) {
38: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/tinymce4.php');
39: zp_register_filter('theme_head', 'comment_form_visualEditor');
40: }
41: }
42:
43: class comment_form {
44:
45: 46: 47: 48:
49: function __construct() {
50: setOptionDefault('email_new_comments', 1);
51: setOptionDefault('comment_name_required', 'required');
52: setOptionDefault('comment_email_required', 'required');
53: setOptionDefault('comment_web_required', 'show');
54: setOptionDefault('Use_Captcha', false);
55: setOptionDefault('comment_form_addresses', 0);
56: setOptionDefault('comment_form_require_addresses', 0);
57: setOptionDefault('comment_form_members_only', 0);
58: setOptionDefault('comment_form_albums', 1);
59: setOptionDefault('comment_form_images', 1);
60: setOptionDefault('comment_form_articles', 1);
61: setOptionDefault('comment_form_pages', 1);
62: setOptionDefault('comment_form_rss', 1);
63: setOptionDefault('comment_form_private', 1);
64: setOptionDefault('comment_form_anon', 1);
65: setOptionDefault('comment_form_showURL', 1);
66: setOptionDefault('comment_form_comments_per_page', 10);
67: setOptionDefault('comment_form_pagination', true);
68: setOptionDefault('comment_form_toggle', 1);
69: setOptionDefault('tinymce4_comments', null);
70: }
71:
72: 73: 74: 75: 76:
77: function getOptionsSupported() {
78: global $_zp_captcha;
79: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/tinymce4.php');
80: $checkboxes = array(gettext('Albums') => 'comment_form_albums', gettext('Images') => 'comment_form_images');
81: if (extensionEnabled('zenpage')) {
82: $checkboxes = array_merge($checkboxes, array(gettext('Pages') => 'comment_form_pages', gettext('News') => 'comment_form_articles'));
83: }
84: $configarray = getTinyMCE4ConfigFiles('comment');
85:
86: $options = array(
87: gettext('Enable comment notification') => array('key' => 'email_new_comments', 'type' => OPTION_TYPE_CHECKBOX,
88: 'order' => 0,
89: 'desc' => gettext('Email the Admin when new comments are posted')),
90: gettext('Name field') => array('key' => 'comment_name_required', 'type' => OPTION_TYPE_RADIO,
91: 'order' => 0.1,
92: 'buttons' => array(gettext('Omit') => 0, gettext('Show') => 1, gettext('Require') => 'required'),
93: 'desc' => gettext('If the <em>Name</em> field is required, the poster must provide a name.')),
94: gettext('Email field') => array('key' => 'comment_email_required', 'type' => OPTION_TYPE_RADIO,
95: 'order' => 0.2,
96: 'buttons' => array(gettext('Omit') => 0, gettext('Show') => 1, gettext('Require') => 'required'),
97: 'desc' => gettext('If the <em>Email</em> field is required, the poster must provide an email address.')),
98: gettext('Website field') => array('key' => 'comment_web_required', 'type' => OPTION_TYPE_RADIO,
99: 'order' => 0.3,
100: 'buttons' => array(gettext('Omit') => 0, gettext('Show') => 1, gettext('Require') => 'required'),
101: 'desc' => gettext('If the <em>Website</em> field is required, the poster must provide a website.')),
102: gettext('Captcha field') => array('key' => 'Use_Captcha', 'type' => OPTION_TYPE_RADIO,
103: 'order' => 0.4,
104: 'buttons' => array(gettext('Omit') => 0, gettext('For guests') => 2, gettext('Require') => 1),
105: 'desc' => ($_zp_captcha->name) ? gettext('If <em>Captcha</em> is required, the form will include a Captcha verification.') : '<span class="notebox">' . gettext('No captcha handler is enabled.') . '</span>'),
106: gettext('Address fields') => array('key' => 'comment_form_addresses', 'type' => OPTION_TYPE_RADIO,
107: 'order' => 7,
108: 'buttons' => array(gettext('Omit') => 0, gettext('Show') => 1, gettext('Require') => 'required'),
109: 'desc' => gettext('If <em>Address fields</em> are shown or required, the form will include positions for address information. If required, the poster must supply data in each address field.')),
110: gettext('Allow comments on') => array('key' => 'comment_form_allowed', 'type' => OPTION_TYPE_CHECKBOX_ARRAY,
111: 'order' => 0.9,
112: 'checkboxes' => $checkboxes,
113: 'desc' => gettext('Comment forms will be presented on the checked pages.')),
114: gettext('Toggled comment block') => array('key' => 'comment_form_toggle', 'type' => OPTION_TYPE_CHECKBOX,
115: 'order' => 2,
116: 'desc' => gettext('If checked, existing comments will be initially hidden. Clicking on the provided button will show them.')),
117: gettext('Show author URL') => array('key' => 'comment_form_showURL', 'type' => OPTION_TYPE_CHECKBOX,
118: 'order' => 7,
119: 'desc' => gettext('To discourage SPAM, uncheck this box and the author URL will not be revealed.')),
120: gettext('Only members can comment') => array('key' => 'comment_form_members_only', 'type' => OPTION_TYPE_CHECKBOX,
121: 'order' => 4,
122: 'desc' => gettext('If checked, only logged in users will be allowed to post comments.')),
123: gettext('Allow private postings') => array('key' => 'comment_form_private', 'type' => OPTION_TYPE_CHECKBOX,
124: 'order' => 6,
125: 'desc' => gettext('If checked, posters may mark their comments as private (not for publishing).')),
126: gettext('Allow anonymous posting') => array('key' => 'comment_form_anon', 'type' => OPTION_TYPE_CHECKBOX,
127: 'order' => 5,
128: 'desc' => gettext('If checked, posters may exclude their personal information from the published post.')),
129: gettext('Include RSS link') => array('key' => 'comment_form_rss', 'type' => OPTION_TYPE_CHECKBOX,
130: 'order' => 8,
131: 'desc' => gettext('If checked, an RSS link will be included at the bottom of the comment section.')),
132: gettext('Comments per page') => array('key' => 'comment_form_comments_per_page', 'type' => OPTION_TYPE_TEXTBOX,
133: 'order' => 9,
134: 'desc' => gettext('The comments that should show per page on the admin tab and when using the jQuery pagination')),
135: gettext('Comment editor configuration') => array('key' => 'tinymce4_comments', 'type' => OPTION_TYPE_SELECTOR,
136: 'order' => 1,
137: 'selections' => $configarray,
138: 'null_selection' => gettext('Disabled'),
139: 'desc' => gettext('Configuration file for TinyMCE when used for comments. Set to <code>Disabled</code> to disable visual editing.')),
140: gettext('Pagination') => array('key' => 'comment_form_pagination', 'type' => OPTION_TYPE_CHECKBOX,
141: 'order' => 3,
142: 'desc' => gettext('Uncheck to disable the jQuery pagination of comments. Enabled by default.')),
143: );
144: return $options;
145: }
146:
147: function handleOption($option, $currentValue) {
148:
149: }
150:
151: static function admin_tabs($tabs) {
152: if (zp_loggedin(COMMENT_RIGHTS)) {
153: $add = true;
154: $newtabs = array();
155: foreach ($tabs as $key => $tab) {
156: if ($add && !in_array($key, array('overview', 'edit', 'upload', 'pages', 'news', 'tags', 'menu'))) {
157: $newtabs['comments'] = array('text' => gettext("comments"),
158: 'link' => WEBPATH . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER . '/' . 'comment_form/admin-comments.php?page=comments&tab=' . gettext('comments'),
159: 'subtabs' => NULL);
160: $add = false;
161: }
162: $newtabs[$key] = $tab;
163: }
164: return $newtabs;
165: }
166: return $tabs;
167: }
168:
169: static function toolbox() {
170: if (zp_loggedin(COMMENT_RIGHTS)) {
171: ?>
172: <li>
173: <?php printLinkHTML(WEBPATH . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER . '/' . 'comment_form/admin-comments.php?page=comments&tab=' . gettext('comments'), gettext("Comments"), NULL, NULL, NULL); ?>
174: </li>
175: <?php
176: }
177: }
178:
179: }
180:
181: 182: 183: 184: 185: 186: 187: 188: 189:
190: function printCommentForm($showcomments = true, $addcommenttext = NULL, $addheader = true, $comment_commententry_mod = '', $desc_order = false) {
191: global $_zp_gallery_page, $_zp_current_admin_obj, $_zp_current_comment, $_zp_captcha, $_zp_authority, $_zp_HTML_cache, $_zp_current_image, $_zp_current_album, $_zp_current_zenpage_page, $_zp_current_zenpage_news;
192:
193: if (getOption('email_new_comments')) {
194: $email_list = $_zp_authority->getAdminEmail();
195: if (empty($email_list)) {
196: setOption('email_new_comments', 0);
197: }
198: }
199: if (is_null($addcommenttext))
200: $addcommenttext = '<h3>' . gettext('Add a comment:') . '</h3>';
201: switch ($_zp_gallery_page) {
202: case 'album.php':
203: if (!getOption('comment_form_albums'))
204: return;
205: $obj = $_zp_current_album;
206: break;
207: case 'image.php':
208: if (!getOption('comment_form_images'))
209: return;
210: $obj = $_zp_current_image;
211: break;
212: case 'pages.php':
213: if (!getOption('comment_form_pages'))
214: return;
215: $obj = $_zp_current_zenpage_page;
216: break;
217: case 'news.php':
218: if (!getOption('comment_form_articles') || !is_NewsArticle())
219: return;
220: $obj = $_zp_current_zenpage_news;
221: break;
222: default:
223: return;
224: break;
225: }
226: $comments_open = $obj->getCommentsAllowed();
227: ?>
228: <!-- printCommentForm -->
229: <div id="commentcontent">
230: <?php
231: $num = getCommentCount();
232: if ($showcomments) {
233: if ($num == 0) {
234: if ($addheader)
235: echo '<h3 class="empty">' . gettext('No Comments') . '</h3>';
236: $display = '';
237: } else {
238: if ($addheader)
239: echo '<h3>' . sprintf(ngettext('%u Comment', '%u Comments', $num), $num) . '</h3>';
240: if (getOption('comment_form_toggle')) {
241: ?>
242: <div id="comment_toggle"><!-- place holder for toggle button --></div>
243: <script type="text/javascript">
244:
245: function toggleComments(hide) {
246: if (hide) {
247: $('div.comment').hide();
248: $('.Pagination').hide();
249: $('#comment_toggle').html('<button class="button buttons" onclick="javascript:toggleComments(false);"><?php echo gettext('show comments'); ?></button>');
250: } else {
251: $('div.comment').show();
252: $('.Pagination').show();
253: $('#comment_toggle').html('<button class="button buttons" onclick="javascript:toggleComments(true);"><?php echo gettext('hide comments'); ?></button>');
254: }
255: }
256: $(document).ready(function() {
257: toggleComments(window.location.hash.search(/
258: });
259:
260: </script>
261: <?php
262: $display = ' style="display:none"';
263: } else {
264: $display = '';
265: }
266: }
267: $hideoriginalcomments = '';
268: if (getOption('comment_form_pagination') && COMMENTS_PER_PAGE < $num) {
269: $hideoriginalcomments = ' style="display:none"';
270: }
271: if (getOption('comment_form_pagination') && COMMENTS_PER_PAGE < $num) {
272: ?>
273: <div class="Pagination"></div><!-- this is the jquery pagination nav placeholder -->
274: <div id="Commentresult"></div>
275: <?php
276: }
277: ?>
278: <div id="comments"<?php echo $hideoriginalcomments; ?>>
279: <?php
280: while (next_comment($desc_order)) {
281: if (!getOption('comment_form_showURL')) {
282: $_zp_current_comment['website'] = '';
283: }
284: ?>
285: <div class="comment" <?php echo $display; ?>>
286: <div class="commentinfo">
287: <h4 id="zp_comment_id_<?php echo $_zp_current_comment['id']; ?>"><?php printCommentAuthorLink(); ?>: <?php echo gettext('on'); ?> <?php
288: echo getCommentDateTime();
289: printEditCommentLink(gettext('Edit'), ', ', '');
290: ?></h4>
291: </div><!-- class "commentinfo" -->
292: <div class="commenttext"><?php echo html_encodeTagged(getCommentBody(), false); ?></div><!-- class "commenttext" -->
293: </div><!-- class "comment" -->
294: <?php
295: }
296: ?>
297: </div><!-- id "comments" -->
298: <?php
299: }
300: if (getOption('comment_form_pagination') && COMMENTS_PER_PAGE < $num) {
301: ?>
302: <div class="Pagination"></div><!-- this is the jquery pagination nav placeholder -->
303: <?php
304: }
305: ?>
306: <!-- Comment Box -->
307: <?php
308: if ($comments_open) {
309: if (MEMBERS_ONLY_COMMENTS && !zp_loggedin(POST_COMMENT_RIGHTS)) {
310: echo gettext('Only registered users may post comments.');
311: } else {
312: $disabled = array('name' => '', 'website' => '', 'anon' => '', 'private' => '', 'comment' => '',
313: 'street' => '', 'city' => '', 'state' => '', 'country' => '', 'postal' => '');
314: $stored = array_merge(array('email' => '', 'custom' => ''), $disabled, getCommentStored());
315: $custom = getSerializedArray($stored['custom']);
316: foreach ($custom as $key => $value) {
317: if (!empty($value))
318: $stored[$key] = $value;
319: }
320:
321: foreach ($stored as $key => $value) {
322: $disabled[$key] = false;
323: }
324:
325: if (zp_loggedin()) {
326: if (extensionEnabled('userAddressFields')) {
327: $address = userAddressFields::getCustomData($_zp_current_admin_obj);
328: foreach ($address as $key => $value) {
329: if (!empty($value)) {
330: $disabled[$key] = true;
331: $stored[$key] = $value;
332: }
333: }
334: }
335: $name = $_zp_current_admin_obj->getName();
336: if (!empty($name)) {
337: $stored['name'] = $name;
338: $disabled['name'] = ' disabled="disabled"';
339: } else {
340: $user = $_zp_current_admin_obj->getUser();
341: if (!empty($user)) {
342: $stored['name'] = $user;
343: $disabled['name'] = ' disabled="disabled"';
344: }
345: }
346: $email = $_zp_current_admin_obj->getEmail();
347: if (!empty($email)) {
348: $stored['email'] = $email;
349: $disabled['email'] = ' disabled="disabled"';
350: }
351: if (!empty($address['website'])) {
352: $stored['website'] = $address['website'];
353: $disabled['website'] = ' disabled="disabled"';
354: }
355: }
356: $data = zp_apply_filter('comment_form_data', array('data' => $stored, 'disabled' => $disabled));
357: $disabled = $data['disabled'];
358: $stored = $data['data'];
359:
360: foreach ($data as $check) {
361: foreach ($check as $v) {
362: if ($v) {
363: $_zp_HTML_cache->disable();
364: break 2;
365: }
366: }
367: }
368:
369: if (!empty($addcommenttext)) {
370: echo $addcommenttext;
371: }
372: ?>
373: <div id="commententry" <?php echo $comment_commententry_mod; ?>>
374: <?php
375: $theme = getCurrentTheme();
376: $form = getPlugin('comment_form/comment_form.php', $theme);
377: require($form);
378: ?>
379: </div><!-- id="commententry" -->
380: <?php
381: }
382: } else {
383: ?>
384: <div id="commententry">
385: <h3><?php echo gettext('Closed for comments.'); ?></h3>
386: </div><!-- id="commententry" -->
387: <?php
388: }
389: ?>
390: </div><!-- id="commentcontent" -->
391: <?php
392: if (getOption('comment_form_rss') && getOption('RSS_comments')) {
393: ?>
394: <br class="clearall" />
395: <?php
396: if (class_exists('RSS')) {
397: switch ($_zp_gallery_page) {
398: case "image.php":
399: printRSSLink("Comments-image", "", gettext("Subscribe to comments"), "");
400: break;
401: case "album.php":
402: printRSSLink("Comments-album", "", gettext("Subscribe to comments"), "");
403: break;
404: case "news.php":
405: printRSSLink("Comments-news", "", gettext("Subscribe to comments"), "");
406: break;
407: case "pages.php":
408: printRSSLink("Comments-page", "", gettext("Subscribe to comments"), "");
409: break;
410: }
411: }
412: }
413: ?>
414: <!-- end printCommentForm -->
415: <?php
416: }
417: ?>