diff --git a/CommentingPlugin.php b/CommentingPlugin.php index f399ac9..7de3b45 100644 --- a/CommentingPlugin.php +++ b/CommentingPlugin.php @@ -1,30 +1,63 @@ 'a:0:{}', + 'commenting_moderate_roles' => 'a:0:{}', + 'commenting_reqapp_comment_roles' => 'a:0:{}', + 'commenting_view_roles' => 'a:0:{}', + 'commenting_comments_label' => 'Comments', + 'commenting_flag_email' => '', + 'commenting_threaded' => false, + 'commenting_legal_text' => '', + 'commenting_allow_public' => true, + 'commenting_require_public_moderation' => true, + 'commenting_allow_public_view' => true, + 'commenting_wpapi_key' => '', ); /** @@ -38,15 +71,18 @@ public function hookInitialize() public function setUp() { - if(plugin_is_active('SimplePages')) { + if (plugin_is_active('SimplePages')) { $this->_filters[] = 'api_extend_simple_pages'; } - if(plugin_is_active('ExhibitBuilder')) { + if (plugin_is_active('ExhibitBuilder')) { $this->_filters[] = 'api_extend_exhibit_pages'; } parent::setUp(); } + /** + * Install the plugin. + */ public function hookInstall() { $db = $this->_db; @@ -73,45 +109,53 @@ public function hookInstall() ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; "; $db->query($sql); - set_option('commenting_comment_roles', serialize(array())); - set_option('commenting_moderate_roles', serialize(array())); - set_option('commenting_reqapp_comment_roles', serialize(array())); - set_option('commenting_view_roles', serialize(array())); + $html = '
'; + $html .= __('I agree with %s terms of use %s and I accept to free my contribution under the licence %s CCÂ BY-SA %s.', + '', '', + '', '' + ); + $html .= '
'; + $this->_options['commenting_legal_text'] = $html; + + $this->_installOptions(); } + /** + * Upgrade the plugin. + */ public function hookUpgrade($args) { $db = $this->_db; $old = $args['old_version']; $new = $args['new_version']; - if(version_compare($old, '1.0', '<')) { - if(!get_option('commenting_comment_roles')) { + if (version_compare($old, '1.0', '<')) { + if (!get_option('commenting_comment_roles')) { $commentRoles = array('super'); set_option('commenting_comment_roles', serialize($commentRoles)); } - if(!get_option('commenting_moderate_roles')) { + if (!get_option('commenting_moderate_roles')) { $moderateRoles = array('super'); set_option('commenting_moderate_roles', serialize($moderateRoles)); } - if(!get_option('commenting_noapp_comment_roles')) { + if (!get_option('commenting_noapp_comment_roles')) { set_option('commenting_noapp_comment_roles', serialize(array())); } - if(!get_option('commenting_view_roles')) { + if (!get_option('commenting_view_roles')) { set_option('commenting_view_roles', serialize(array())); } } - if(version_compare($old, '2.0', '<')) { + if (version_compare($old, '2.0', '<')) { $sql = "ALTER TABLE `$db->Comment` ADD `flagged` BOOLEAN NOT NULL DEFAULT '0' AFTER `approved` "; $db->query($sql); } - if(version_compare($old, '2.1', '<')) { + if (version_compare($old, '2.1', '<')) { delete_option('commenting_noapp_comment_roles'); set_option('commenting_reqapp_comment_roles', serialize(array())); $sql = "ALTER TABLE `$db->Comment` CHANGE `flagged` `flagged` TINYINT( 1 ) NOT NULL DEFAULT '0'"; @@ -119,11 +163,16 @@ public function hookUpgrade($args) } } + /** + * Uninstall the plugin. + */ public function hookUninstall() { $db = get_db(); $sql = "DROP TABLE IF EXISTS `$db->Comment`"; $db->query($sql); + + $this->_uninstallOptions(); } public function hookPublicHead() @@ -143,33 +192,37 @@ public function hookAfterDeleteRecord($args) { $record = $args['record']; $type = get_class($record); - $comments = get_db()->getTable('Comment')->findBy(array('record_type'=>$type, 'record_id'=>$record->id)); - foreach($comments as $comment) { + $comments = get_db()->getTable('Comment')->findBy(array('record_type' => $type, 'record_id' => $record->id)); + foreach ($comments as $comment) { $comment->delete(); } } + /** + * Helper to append comments and comment form to a page. + */ public static function showComments($args = array()) { + $view = isset($args['view']) ? $args['view'] : get_view(); echo "reCAPTCHA', "" . __('security settings') . "");?>
- - - - + - \ No newline at end of file + diff --git a/views/admin/css/commenting.css b/views/admin/css/commenting.css index 47abeb1..339f30e 100644 --- a/views/admin/css/commenting.css +++ b/views/admin/css/commenting.css @@ -1,65 +1,68 @@ -a#batch-delete, a#batch-approve, a#batch-unapprove, a#batch-report-spam, a#batch-report-ham, a#batch-flag, a#batch-unflag { - padding: 3px 2px; - margin: 0 0 20px; +a#batch-delete, +a#batch-approve, +a#batch-unapprove, +a#batch-report-spam, +a#batch-report-ham, +a#batch-flag, +a#batch-unflag { + padding: 3px 2px; + margin: 0 0 20px; } li.delete { - float:left; - margin-right: 5px; + float: left; + margin-right: 5px; } form#comment-form { - clear:both; + clear:both; } div.comments { - + } div.comment-target { - margin: 0; - padding: 0; + margin: 0; + padding: 0; } div.comment-target p { - margin: 0; - padding; 0; + margin: 0; + padding: 0; } div.comment { - margin-left: 12px; - margin-top: 3px; - margin-bottom: 6px; - clear: both; - min-height: 120px; + margin-left: 12px; + margin-top: 3px; + margin-bottom: 6px; + clear: both; + min-height: 120px; } div.comment-author { - float: left; - margin: 6px; - width: 80px; + float: left; + margin: 6px; + width: 80px; } -div.comment-body { - min-height: 60px; +div.comment-body { + min-height: 60px; } - div.comment-flagged { - background-color: pink; + background-color: #F09999; } - div.comment-body p { - font-size: 1em; + font-size: 1em; } - div#commenting-batch-actions { - font-size: 1.2em; - line-height: 1em; - float: left; - margin-right: 5px; + font-size: 1.2em; + line-height: 1em; + float: left; + margin-right: 5px; } div#commenting-batch-actions a.disabled { @@ -68,24 +71,24 @@ div#commenting-batch-actions a.disabled { } ul.comment-admin-menu { - padding-left: 20px; - margin-top: 0; + padding-left: 20px; + margin-top: 0; } ul.comment-admin-menu li { - margin-bottom: .5em; - padding-left: 10px; - list-style: none; + margin-bottom: .5em; + padding-left: 10px; + list-style: none; } ul.comment-admin-menu span { - background-repeat: no-repeat; + background-repeat: no-repeat; } input.batch-select-comment { - float: left; - position: relative; - left: -12px; + float: left; + position: relative; + left: -12px; } span.status { @@ -96,29 +99,29 @@ span.status { } span.approved { - background-image: url('../../../../../application/views/scripts/images/silk-icons/tick.png'); + background-image: url('../../../../../application/views/scripts/images/silk-icons/tick.png'); } -span.unapproved { - background-image: url('../../../../../application/views/scripts/images/silk-icons/exclamation.png'); +span.unapproved { + background-image: url('../../../../../application/views/scripts/images/silk-icons/exclamation.png'); } span.ham { - background-image: url('../../../../../application/views/scripts/images/silk-icons/tick.png'); + background-image: url('../../../../../application/views/scripts/images/silk-icons/tick.png'); } span.spam { - background-image: url('../../../../../application/views/scripts/images/silk-icons/exclamation.png'); + background-image: url('../../../../../application/views/scripts/images/silk-icons/exclamation.png'); } - + span.flagged { - background-image: url('../../../../../application/views/scripts/images/silk-icons/exclamation.png'); -} - + background-image: url('../../../../../application/views/scripts/images/silk-icons/exclamation.png'); +} + span.not-flagged { - background-image: url('../../../../../application/views/scripts/images/silk-icons/tick.png'); -} - + background-image: url('../../../../../application/views/scripts/images/silk-icons/tick.png'); +} + .action { color: #338899; cursor: pointer; diff --git a/config_form.js b/views/admin/javascripts/commenting-config-form.js similarity index 80% rename from config_form.js rename to views/admin/javascripts/commenting-config-form.js index fe2ca27..5ff06a8 100644 --- a/config_form.js +++ b/views/admin/javascripts/commenting-config-form.js @@ -1,7 +1,7 @@ Commenting = { toggleCommentOptions: function() { jQuery('div#non-public-options').toggle(); - if(jQuery(this).attr('checked') == 'checked') { + if (jQuery(this).attr('checked') == 'checked') { jQuery('div#commenting-moderate-public').show(); } else { jQuery('div#commenting-moderate-public').removeAttr('checked'); @@ -15,9 +15,9 @@ Commenting = { }, toggleModerateOptions: function() { - if( jQuery('input#commenting_allow_public').attr('checked') == 'checked') { + if ( jQuery('input#commenting_allow_public').attr('checked') == 'checked') { jQuery('div#commenting-moderate-public').show(); - if(jQuery('input#commenting_require_public_moderation').attr('checked') == 'checked') { + if (jQuery('input#commenting_require_public_moderation').attr('checked') == 'checked') { jQuery('div#moderate-options').show(); } else { jQuery('div#moderate-options').hide(); @@ -36,7 +36,7 @@ jQuery(document).ready(function() { jQuery('input#commenting_require_public_moderation').click(Commenting.toggleModerateOptions); //if public commenting is on - if(jQuery('input#commenting_allow_public').attr('checked') == 'checked') { + if (jQuery('input#commenting_allow_public').attr('checked') == 'checked') { jQuery('div#non-public-options').hide(); jQuery('div#commenting-moderate-public').show(); } else { @@ -46,7 +46,7 @@ jQuery(document).ready(function() { } Commenting.toggleModerateOptions(); - if(jQuery('input#commenting_allow_public_view').attr('checked') == 'checked') { + if (jQuery('input#commenting_allow_public_view').attr('checked') == 'checked') { jQuery('div.view-options').hide(); } diff --git a/views/admin/javascripts/commenting.js b/views/admin/javascripts/commenting.js index cb4553e..8970ec2 100644 --- a/views/admin/javascripts/commenting.js +++ b/views/admin/javascripts/commenting.js @@ -1,72 +1,72 @@ var Commenting = { - - elements: [], - - flag: function() { + + elements: [], + + flag: function() { commentEl = jQuery(this).closest('div.comment'); id = commentEl.attr('id').substring(8); Commenting.elements = [commentEl]; json = {'ids': [id], 'flagged': 1}; jQuery.post("update-flagged", json, Commenting.flagResponseHandler); - }, - - unflag: function() { + }, + + unflag: function() { commentEl = jQuery(this).closest('div.comment'); id = commentEl.attr('id').substring(8); Commenting.elements = [commentEl]; json = {'ids': [id], 'flagged': 0}; - jQuery.post("update-flagged", json, Commenting.flagResponseHandler); - }, - - flagResponseHandler: function(response, textStatus, jqReq) { - if(response.status == 'ok') { + jQuery.post("update-flagged", json, Commenting.flagResponseHandler); + }, + + flagResponseHandler: function(response, textStatus, jqReq) { + if (response.status == 'ok') { for(var i=0; i < Commenting.elements.length; i++) { Commenting.elements[i].find('li.flagged').toggle(); Commenting.elements[i].find('li.not-flagged').toggle(); } } else { alert('Error trying to unapprove: ' + response.message); - } - }, - - approve: function() { - commentEl = jQuery(this).closest('div.comment'); - id = commentEl.attr('id').substring(8); - Commenting.elements = [commentEl]; - json = {'ids': [id], 'approved': 1}; - jQuery.post("update-approved", json, Commenting.approveResponseHandler); - }, - - unapprove: function() { - commentEl = jQuery(this).closest('div.comment'); - id = commentEl.attr('id').substring(8); - Commenting.elements = [commentEl]; - json = {'ids': [id], 'approved': 0}; - jQuery.post("update-approved", json, Commenting.approveResponseHandler); - }, - - - approveResponseHandler: function(response, textStatus, jqReq) { - if(response.status == 'ok') { - for(var i=0; i < Commenting.elements.length; i++) { - Commenting.elements[i].find('li.approved').toggle(); - Commenting.elements[i].find('li.unapproved').toggle(); - } - } else { - alert('Error trying to unapprove: ' + response.message); - } - }, - - deleteResponseHandler: function(response, textStatus, jqReq) { - window.location.reload(); - }, - - batchDelete: function() { - var ids = Commenting.getCheckedCommentIds(); + } + }, + + approve: function() { + commentEl = jQuery(this).closest('div.comment'); + id = commentEl.attr('id').substring(8); + Commenting.elements = [commentEl]; + json = {'ids': [id], 'approved': 1}; + jQuery.post("update-approved", json, Commenting.approveResponseHandler); + }, + + unapprove: function() { + commentEl = jQuery(this).closest('div.comment'); + id = commentEl.attr('id').substring(8); + Commenting.elements = [commentEl]; + json = {'ids': [id], 'approved': 0}; + jQuery.post("update-approved", json, Commenting.approveResponseHandler); + }, + + + approveResponseHandler: function(response, textStatus, jqReq) { + if (response.status == 'ok') { + for(var i=0; i < Commenting.elements.length; i++) { + Commenting.elements[i].find('li.approved').toggle(); + Commenting.elements[i].find('li.unapproved').toggle(); + } + } else { + alert('Error trying to unapprove: ' + response.message); + } + }, + + deleteResponseHandler: function(response, textStatus, jqReq) { + window.location.reload(); + }, + + batchDelete: function() { + var ids = Commenting.getCheckedCommentIds(); json = {'ids': ids}; jQuery.post("batch-delete", json, Commenting.deleteResponseHandler); - - }, + + }, batchFlag: function() { var ids = Commenting.getCheckedCommentIds(); @@ -78,106 +78,103 @@ var Commenting = { var ids = Commenting.getCheckedCommentIds(); json = {'ids': ids, 'flagged': 0}; jQuery.post("update-flagged", json, Commenting.flagResponseHandler); - }, + }, batchApprove: function() { - var ids = Commenting.getCheckedCommentIds(); - json = {'ids': ids, 'approved': 1}; - jQuery.post("update-approved", json, Commenting.approveResponseHandler); - }, - - batchUnapprove: function() { - var ids = Commenting.getCheckedCommentIds(); - json = {'ids': ids, 'approved': 0}; - jQuery.post("update-approved", json, Commenting.approveResponseHandler); - }, - - reportSpam: function() { + var ids = Commenting.getCheckedCommentIds(); + json = {'ids': ids, 'approved': 1}; + jQuery.post("update-approved", json, Commenting.approveResponseHandler); + }, + + batchUnapprove: function() { + var ids = Commenting.getCheckedCommentIds(); + json = {'ids': ids, 'approved': 0}; + jQuery.post("update-approved", json, Commenting.approveResponseHandler); + }, + + reportSpam: function() { commentEl = jQuery(this).closest('div.comment'); - id = commentEl.attr('id').substring(8); - Commenting.elements = [commentEl]; - json = {'ids': [id], 'spam': 1}; - jQuery.post("update-spam", json, Commenting.spamResponseHandler); - }, - - reportHam: function() { + id = commentEl.attr('id').substring(8); + Commenting.elements = [commentEl]; + json = {'ids': [id], 'spam': 1}; + jQuery.post("update-spam", json, Commenting.spamResponseHandler); + }, + + reportHam: function() { commentEl = jQuery(this).closest('div.comment'); - id = commentEl.attr('id').substring(8); - Commenting.elements = [commentEl]; - json = {'ids': [id], 'spam': 0}; - jQuery.post("update-spam", json, Commenting.spamResponseHandler); - }, - - batchReportSpam: function() { - var ids = Commenting.getCheckedCommentIds(); - json = {'ids': ids, 'spam': true}; - jQuery.post("update-spam", json, Commenting.spamResponseHandler); - }, - - batchReportHam: function() { - var ids = Commenting.getCheckedCommentIds(); - json = {'ids': ids, 'spam': false}; - jQuery.post("update-spam", json, Commenting.spamResponseHandler); - }, - - spamResponseHandler: function(response, textStatus, jqReq) - { - if(response.status == 'ok') { + id = commentEl.attr('id').substring(8); + Commenting.elements = [commentEl]; + json = {'ids': [id], 'spam': 0}; + jQuery.post("update-spam", json, Commenting.spamResponseHandler); + }, + + batchReportSpam: function() { + var ids = Commenting.getCheckedCommentIds(); + json = {'ids': ids, 'spam': true}; + jQuery.post("update-spam", json, Commenting.spamResponseHandler); + }, + + batchReportHam: function() { + var ids = Commenting.getCheckedCommentIds(); + json = {'ids': ids, 'spam': false}; + jQuery.post("update-spam", json, Commenting.spamResponseHandler); + }, + + spamResponseHandler: function(response, textStatus, jqReq) { + if (response.status == 'ok') { for(var i=0; i < Commenting.elements.length; i++) { Commenting.elements[i].find('li.spam').toggle(); Commenting.elements[i].find('li.ham').toggle(); } - } else { - alert('Error trying to submit ham: ' + response.message); - } - }, - - toggleSelected: function() { - if(jQuery(this).is(':checked')) { - Commenting.batchSelect(); - } else { - Commenting.batchUnselect(); - } - }, - - toggleActive: function() { - //toggle whether the bulk actions should be active - //check all in checkboxes, if any are checked, must be active - if(jQuery('.batch-select-comment:checked').length == 0) { - jQuery('#batch-delete').unbind('click'); - jQuery('#batch-approve').unbind('click'); - jQuery('#batch-unapprove').unbind('click'); - jQuery('#batch-report-spam').unbind('click'); - jQuery('#batch-report-ham').unbind('click'); - jQuery('#batch-flag').unbind('click'); - jQuery('#batch-unflag').unbind('click'); - jQuery('#commenting-batch-actions > a').addClass('disabled'); - } else { - jQuery('#batch-delete').click(Commenting.batchDelete); - jQuery('#batch-approve').click(Commenting.batchApprove); - jQuery('#batch-unapprove').click(Commenting.batchUnapprove); - jQuery('#batch-report-spam').click(Commenting.batchReportSpam); - jQuery('#batch-report-ham').click(Commenting.batchReportHam); + } else { + alert('Error trying to submit ham: ' + response.message); + } + }, + + toggleSelected: function() { + if (jQuery(this).is(':checked')) { + Commenting.batchSelect(); + } else { + Commenting.batchUnselect(); + } + }, + + toggleActive: function() { + //toggle whether the bulk actions should be active + //check all in checkboxes, if any are checked, must be active + if (jQuery('.batch-select-comment:checked').length == 0) { + jQuery('#batch-delete').unbind('click'); + jQuery('#batch-approve').unbind('click'); + jQuery('#batch-unapprove').unbind('click'); + jQuery('#batch-report-spam').unbind('click'); + jQuery('#batch-report-ham').unbind('click'); + jQuery('#batch-flag').unbind('click'); + jQuery('#batch-unflag').unbind('click'); + jQuery('#commenting-batch-actions > a').addClass('disabled'); + } else { + jQuery('#batch-delete').click(Commenting.batchDelete); + jQuery('#batch-approve').click(Commenting.batchApprove); + jQuery('#batch-unapprove').click(Commenting.batchUnapprove); + jQuery('#batch-report-spam').click(Commenting.batchReportSpam); + jQuery('#batch-report-ham').click(Commenting.batchReportHam); jQuery('#batch-flag').click(Commenting.batchFlag); - jQuery('#batch-unflag').click(Commenting.batchUnflag); - jQuery('#commenting-batch-actions > a').removeClass('disabled'); - } - - }, - - batchSelect: function() { - jQuery('input.batch-select-comment').attr('checked', 'checked'); - this.toggleActive(); - - }, - - batchUnselect: function() { - jQuery('input.batch-select-comment').removeAttr('checked'); - this.toggleActive(); - }, - - getCheckedCommentIds: function() { - var ids = new Array(); + jQuery('#batch-unflag').click(Commenting.batchUnflag); + jQuery('#commenting-batch-actions > a').removeClass('disabled'); + } + }, + + batchSelect: function() { + jQuery('input.batch-select-comment').attr('checked', 'checked'); + this.toggleActive(); + }, + + batchUnselect: function() { + jQuery('input.batch-select-comment').removeAttr('checked'); + this.toggleActive(); + }, + + getCheckedCommentIds: function() { + var ids = new Array(); Commenting.elements = []; jQuery('input.batch-select-comment:checked').each(function() { var commentEl = jQuery(this).closest('div.comment'); @@ -185,16 +182,16 @@ var Commenting = { Commenting.elements[Commenting.elements.length] = commentEl; }); return ids; - } -} + } +}; jQuery(document).ready(function() { - jQuery('.approve').click(Commenting.approve); - jQuery('.unapprove').click(Commenting.unapprove); - jQuery('.flag').click(Commenting.flag); - jQuery('.unflag').click(Commenting.unflag); - jQuery('#batch-select').click(Commenting.toggleSelected); - jQuery('.report-ham').click(Commenting.reportHam); - jQuery('.report-spam').click(Commenting.reportSpam); - jQuery('.batch-select-comment').click(Commenting.toggleActive); -}); \ No newline at end of file + jQuery('.approve').click(Commenting.approve); + jQuery('.unapprove').click(Commenting.unapprove); + jQuery('.flag').click(Commenting.flag); + jQuery('.unflag').click(Commenting.unflag); + jQuery('#batch-select').click(Commenting.toggleSelected); + jQuery('.report-ham').click(Commenting.reportHam); + jQuery('.report-spam').click(Commenting.reportSpam); + jQuery('.batch-select-comment').click(Commenting.toggleActive); +}); diff --git a/config_form.php b/views/admin/plugins/commenting-config-form.php similarity index 64% rename from config_form.php rename to views/admin/plugins/commenting-config-form.php index 31c74b2..5a5c66f 100644 --- a/config_form.php +++ b/views/admin/plugins/commenting-config-form.php @@ -1,24 +1,28 @@ - - ++ +
+reCAPTCHA', "" . __('security settings') . "");?>
flagged): ?> style='display:none;' >
-flagged): ?>style='display:none;' >
+flagged): ?> style='display:none;' >
+flagged): ?>style='display:none;' >
diff --git a/views/public/comments.php b/views/public/common/comments.php similarity index 50% rename from views/public/comments.php rename to views/public/common/comments.php index 42e440a..336532d 100644 --- a/views/public/comments.php +++ b/views/public/common/comments.php @@ -5,16 +5,17 @@ - - $comments)); ?> - - - partial('threaded-comments.php', array('comments' => $comments, 'parent_id'=>null)); ?> + + + + $comments)); ?> + + partial('common/threaded-comments.php', array('comments' => $comments, 'parent_id' => null)); ?> - +