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 "
"; - if( (get_option('commenting_allow_public') == 1) + if ((get_option('commenting_allow_public') == 1) || (get_option('commenting_allow_public_view') == 1) - || is_allowed('Commenting_Comment', 'show') ) { - if(isset($args['view'])) { - $view = $args['view']; - } else { - $view = get_view(); - } - - $view->addHelperPath(COMMENTING_PLUGIN_DIR . '/helpers', 'Commenting_View_Helper_'); - $options = array('threaded'=> get_option('commenting_threaded'), 'approved'=>true); + || is_allowed('Commenting_Comment', 'show') + ) { + $options = array( + 'threaded' => get_option('commenting_threaded'), + 'approved' => true, + ); $comments = isset($args['comments']) ? $args['comments'] : $view->getComments($options); - echo $view->partial('comments.php', array('comments'=>$comments, 'threaded'=>$options['threaded'])); + echo $view->partial('common/comments.php', array( + 'comments' => $comments, + 'threaded' => $options['threaded'], + )); } - if( (get_option('commenting_allow_public') == 1) - || is_allowed('Commenting_Comment', 'add') ) { + if ((get_option('commenting_allow_public') == 1) + || is_allowed('Commenting_Comment', 'add')) { echo "
"; echo $view->getCommentForm(); echo "
"; @@ -187,26 +240,31 @@ public function hookPublicCollectionsShow($args) self::showComments($args); } + public function hookConfigForm() + { + echo get_view()->partial( + 'plugins/commenting-config-form.php' + ); + } + public function hookConfig($args) { $post = $args['post']; - foreach($post as $key=>$value) { - if( ($key == 'commenting_comment_roles') || - ($key == 'commenting_moderate_roles') || - ($key == 'commenting_view_roles') || - ($key == 'commenting_reqapp_comment_roles') - ) { - $value = serialize($value); - } + foreach (array( + 'commenting_comment_roles', + 'commenting_moderate_roles', + 'commenting_view_roles', + 'commenting_reqapp_comment_roles', + ) as $posted) { + $post[$posted] = isset($post[$posted]) + ? serialize($post[$posted]) + : serialize(array()); + } + foreach ($post as $key => $value) { set_option($key, $value); } } - public function hookConfigForm() - { - include COMMENTING_PLUGIN_DIR . '/config_form.php'; - } - public function hookDefineAcl($args) { $acl = $args['acl']; @@ -215,34 +273,34 @@ public function hookDefineAcl($args) $moderateRoles = unserialize(get_option('commenting_moderate_roles')); $viewRoles = unserialize(get_option('commenting_view_roles')); $acl->allow(null, 'Commenting_Comment', array('flag')); - if($viewRoles !== false) { - foreach($viewRoles as $role) { + if ($viewRoles !== false) { + foreach ($viewRoles as $role) { //check that all the roles exist, in case a plugin-added role has been removed (e.g. GuestUser) - if($acl->hasRole($role)) { + if ($acl->hasRole($role)) { $acl->allow($role, 'Commenting_Comment', 'show'); } } - foreach($commentRoles as $role) { - if($acl->hasRole($role)) { + foreach ($commentRoles as $role) { + if ($acl->hasRole($role)) { $acl->allow($role, 'Commenting_Comment', 'add'); } } - foreach($moderateRoles as $role) { - if($acl->hasRole($role)) { + foreach ($moderateRoles as $role) { + if ($acl->hasRole($role)) { $acl->allow($role, 'Commenting_Comment', array( - 'update-approved', - 'update-spam', - 'update-flagged', - 'batch-delete', - 'browse', - 'delete' - )); + 'update-approved', + 'update-spam', + 'update-flagged', + 'batch-delete', + 'browse', + 'delete', + )); } } - if(get_option('commenting_allow_public')) { + if (get_option('commenting_allow_public')) { $acl->allow(null, 'Commenting_Comment', array('show', 'add')); } } @@ -250,8 +308,8 @@ public function hookDefineAcl($args) public function filterAdminNavigationMain($tabs) { - if(is_allowed('Commenting_Comment', 'update-approved') ) { - $tabs[] = array('uri'=> url('commenting/comment/browse'), 'label'=>__('Comments') ); + if (is_allowed('Commenting_Comment', 'update-approved')) { + $tabs[] = array('uri' => url('commenting/comment/browse'), 'label' => __('Comments')); } return $tabs; @@ -266,9 +324,9 @@ public function filterSearchRecordTypes($types) public function filterApiResources($apiResources) { $apiResources['comments'] = array( - 'record_type' => 'Comment', - 'actions' => array('get', 'index'), - 'index_params' => array('record_type', 'record_id') + 'record_type' => 'Comment', + 'actions' => array('get', 'index'), + 'index_params' => array('record_type', 'record_id'), ); return $apiResources; } @@ -298,10 +356,10 @@ private function _filterApiExtendRecords($extend, $args) $record = $args['record']; $recordClass = get_class($record); $extend['comments'] = array( - 'count' => $this->_countComments($record), - 'resource' => 'comments', - 'url' => Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl("/comments?record_type=$recordClass&record_id={$record->id}"), - ); + 'count' => $this->_countComments($record), + 'resource' => 'comments', + 'url' => Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl("/comments?record_type=$recordClass&record_id={$record->id}"), + ); return $extend; } @@ -309,9 +367,9 @@ private function _filterApiExtendRecords($extend, $args) private function _countComments($record) { $params = array( - 'record_type' => get_class($record), - 'record_id' => $record->id - ); + 'record_type' => get_class($record), + 'record_id' => $record->id + ); return get_db()->getTable('Comment')->count($params); } } diff --git a/README b/README.md similarity index 100% rename from README rename to README.md diff --git a/controllers/CommentController.php b/controllers/CommentController.php index c0895e7..2777dfc 100644 --- a/controllers/CommentController.php +++ b/controllers/CommentController.php @@ -4,19 +4,21 @@ class Commenting_CommentController extends Omeka_Controller_AbstractActionContro { protected $_browseRecordsPerPage = 10; - + /** + * Controller-wide initialization. Sets the underlying model to use. + */ public function init() { - $this->_helper->db->setDefaultModelName('Comment'); + $this->_helper->db->setDefaultModelName('Comment'); } public function browseAction() { - if(!$this->_hasParam('sort_field')) { + if (!$this->_hasParam('sort_field')) { $this->_setParam('sort_field', 'added'); } - if(!$this->_hasParam('sort_dir')) { + if (!$this->_hasParam('sort_dir')) { $this->_setParam('sort_dir', 'd'); } parent::browseAction(); @@ -25,50 +27,50 @@ public function browseAction() public function batchDeleteAction() { $ids = $_POST['ids']; - foreach($ids as $id) { + foreach ($ids as $id) { $record = $this->_helper->db->findById($id); $record->delete(); } - $response = array('status'=>'ok'); + $response = array('status' => 'ok'); $this->_helper->json($response); } - + public function addAction() { $destination = $_POST['path']; - $module = isset($_POST['module']) ? Inflector::camelize($_POST['module']) : ''; + $module = isset($_POST['module']) ? Inflector::camelize($_POST['module']) : ''; $destArray = array( 'module' => $module, - 'controller'=> strtolower(Inflector::pluralize($_POST['record_type'])), + 'controller' => strtolower(Inflector::pluralize($_POST['record_type'])), 'action' => 'show', 'id' => $_POST['record_id'] ); $comment = new Comment(); - if($user = current_user()) { + if ($user = current_user()) { $comment->user_id = $user->id; } $comment->flagged = 0; - $form = $this->getForm(); + $form = $this->_getForm(); $valid = $form->isValid($this->getRequest()->getPost()); - if(!$valid) { + if (!$valid) { $destination .= "#comment-form"; $commentSession = new Zend_Session_Namespace('commenting'); $commentSession->post = serialize($_POST); $this->_helper->redirector->gotoUrl($destination); } - + $role = current_user()->role; $reqAppCommentRoles = unserialize(get_option('commenting_reqapp_comment_roles')); $requiresApproval = in_array($role, $reqAppCommentRoles); //via Daniel Lind -- https://groups.google.com/forum/#!topic/omeka-dev/j-tOSAVdxqU $reqAppPublicComment = (bool) get_option('commenting_require_public_moderation'); $requiresApproval = $requiresApproval || (!is_object(current_user()) && $reqAppPublicComment); - //end Daniel Lind contribution - if($requiresApproval) { + //end Daniel Lind contribution + if ($requiresApproval) { $this->_helper->flashMessenger(__("Your comment is awaiting moderation"), 'success'); } - + //need getValue to run the filter $data = $_POST; $data['body'] = $form->getElement('body')->getValue(); @@ -89,11 +91,11 @@ public function updateSpamAction() $table = $this->_helper->db->getTable(); $wordPressAPIKey = get_option('commenting_wpapi_key'); $ak = new Zend_Service_Akismet($wordPressAPIKey, WEB_ROOT ); - $response = array('errors'=> array()); - foreach($commentIds as $commentId) { + $response = array('errors' => array()); + foreach ($commentIds as $commentId) { $comment = $table->find($commentId); $data = $comment->getAkismetData(); - if($spam) { + if ($spam) { $submitMethod = 'submitSpam'; } else { $submitMethod = 'submitHam'; @@ -106,7 +108,7 @@ public function updateSpamAction() $response['status'] = 'ok'; } catch (Exception $e){ $response['status'] = 'fail'; - $response['errors'][] = array('id'=>$comment->id); + $response['errors'][] = array('id' => $comment->id); $response['message'] = $e->getMessage(); _log($e); } @@ -120,32 +122,32 @@ public function updateApprovedAction() $commentIds = $_POST['ids']; $status = $_POST['approved']; $table = $this->_helper->db->getTable(); - if(! $commentIds) { + if (! $commentIds) { return; } - foreach($commentIds as $commentId) { + foreach ($commentIds as $commentId) { $comment = $table->find($commentId); $comment->approved = $status; //if approved, it isn't spam - if( ($status == 1) && ($comment->is_spam == 1) ) { + if (($status == 1) && ($comment->is_spam == 1)) { $comment->is_spam = 0; $ak = new Zend_Service_Akismet($wordPressAPIKey, WEB_ROOT ); $data = $comment->getAkismetData(); try { $ak->submitHam($data); - $response = array('status'=>'ok'); + $response = array('status' => 'ok'); $comment->save(); } catch (Exception $e) { _log($e->getMessage()); - $response = array('status'=>'fail', 'message'=>$e->getMessage()); + $response = array('status' => 'fail', 'message' => $e->getMessage()); } } else { try { $comment->save(); - $response = array('status'=>'ok'); + $response = array('status' => 'ok'); } catch(Exception $e) { - $response = array('status'=>'fail', 'message'=>$e->getMessage()); + $response = array('status' => 'fail', 'message' => $e->getMessage()); _log($e->getMessage()); } } @@ -159,44 +161,46 @@ public function updateFlaggedAction() { $commentIds = $_POST['ids']; $flagged = $_POST['flagged']; - - if($commentIds) { - foreach($commentIds as $id) { + + if ($commentIds) { + foreach ($commentIds as $id) { $comment = $this->_helper->db->getTable('Comment')->find($id); $comment->flagged = $flagged; $comment->save(); } } else { - $response = array('status'=>'empty', 'message'=>'No Comments Found'); + $response = array('status' => 'empty', 'message' => 'No Comments Found'); } - if($flagged) { + if ($flagged) { $action = 'flagged'; } else { $action = 'unflagged'; } - $response = array('status'=>'ok', 'action'=>$action, 'ids'=>$commentIds); + $response = array('status' => 'ok', 'action' => $action, 'ids' => $commentIds); $this->_helper->json($response); } - - public function flagAction() { + + public function flagAction() + { $commentId = $_POST['id']; $comment = $this->_helper->db->getTable('Comment')->find($commentId); $comment->flagged = true; $comment->save(); $this->emailFlagged($comment); - $response = array('status'=>'ok', 'id'=>$commentId, 'action'=>'flagged'); + $response = array('status' => 'ok', 'id' => $commentId, 'action' => 'flagged'); $this->_helper->json($response); } - - public function unflagAction() { + + public function unflagAction() + { $commentId = $_POST['id']; $comment = $this->_helper->db->getTable('Comment')->find($commentId); $comment->flagged = 0; $comment->save(); - $response = array('status'=>'ok', 'id'=>$commentId, 'action'=>'unflagged'); + $response = array('status' => 'ok', 'id' => $commentId, 'action' => 'unflagged'); $this->_helper->json($response); } - + private function emailFlagged($comment) { $mail = new Zend_Mail('UTF-8'); @@ -213,14 +217,12 @@ private function emailFlagged($comment) } catch(Exception $e) { _log($e); } - + } - - private function getForm() + private function _getForm() { - require_once(COMMENTING_PLUGIN_DIR . '/CommentForm.php'); - return new Commenting_CommentForm(); + require_once dirname(dirname(__FILE__)) . '/forms/CommentForm.php'; + return new Commenting_CommentForm; } - -} \ No newline at end of file +} diff --git a/CommentForm.php b/forms/CommentForm.php similarity index 51% rename from CommentForm.php rename to forms/CommentForm.php index c9b7469..a8d56d7 100644 --- a/CommentForm.php +++ b/forms/CommentForm.php @@ -1,9 +1,6 @@ addElement('captcha', 'captcha', array( 'class' => 'hidden', 'label' => __("Please verify you're a human"), @@ -20,46 +17,66 @@ public function init() 'captcha' => 'ReCaptcha', 'pubkey' => get_option('recaptcha_public_key'), 'privkey' => get_option('recaptcha_private_key'), - 'ssl' => true //make the connection secure so IE8 doesn't complain. if works, should branch around http: vs https: - ) + 'ssl' => true, //make the connection secure so IE8 doesn't complain. if works, should branch around http: vs https: + ), )); } $urlOptions = array( - 'label'=>__('Website'), - ); + 'label' => __('Website'), + ); $emailOptions = array( - 'label'=>__('Email (required)'), - 'required'=>true, - 'validators' => array( - array('validator' => 'EmailAddress' - ) - ) - ); - $nameOptions = array('label'=> __('Your name')); - - if($user) { + 'label' => __('Email (required)'), + 'required' => true, + 'validators' => array( + array( + 'validator' => 'EmailAddress', + ), + ), + ); + $nameOptions = array('label' => __('Your name')); + + if ($user) { $emailOptions['value'] = $user->email; $nameOptions['value'] = $user->name; } $this->addElement('text', 'author_name', $nameOptions); $this->addElement('text', 'author_url', $urlOptions); $this->addElement('text', 'author_email', $emailOptions); - $this->addElement('textarea', 'body', - array('label'=>__('Comment'), - 'description'=> __("Allowed tags:") . " <p>, <a>, <em>, <strong>, <ul>, <ol>, <li>", - 'id'=>'comment-form-body', - 'required'=>true, - - 'filters'=> array( - array('StripTags', - array('allowTags' => array('p', 'span', 'em', 'strong', 'a','ul','ol','li'), - 'allowAttribs' => array('style', 'href') - ), - ), - ), - ) - ); + $this->addElement('textarea', 'body', array( + 'label' => __('Comment'), + 'description' => __("Allowed tags:") . " <p>, <a>, <em>, <strong>, <ul>, <ol>, <li>", + 'id' => 'comment-form-body', + 'required' => true, + 'filters' => array( + array( + 'StripTags', + array( + 'allowTags' => array('p', 'span', 'em', 'strong', 'a','ul','ol','li'), + 'allowAttribs' => array('style', 'href'), + ), + ), + ), + )); + + // The legal agreement is checked by default for logged users. + if (get_option('commenting_legal_text')) { + $this->addElement('checkbox', 'commenting_legal_text', array( + 'label' => get_option('commenting_legal_text'), + 'value' => (boolean) $user, + 'required' => true, + 'uncheckedValue' => '', + 'checkedValue' => 'checked', + 'validators' => array( + array('notEmpty', true, array( + 'messages' => array( + 'isEmpty' => __('You must agree to the terms and conditions.'), + ), + )), + ), + 'decorators' => array('ViewHelper', 'Errors', array('label', array('escape' => false))), + )); + } $request = Zend_Controller_Front::getInstance()->getRequest(); $params = $request->getParams(); @@ -67,29 +84,29 @@ public function init() $record_id = $this->_getRecordId($params); $record_type = $this->_getRecordType($params); - $this->addElement('hidden', 'record_id', array('value'=>$record_id, 'decorators'=>array('ViewHelper') )); - $this->addElement('hidden', 'path', array('value'=> $request->getPathInfo(), 'decorators'=>array('ViewHelper'))); - if(isset($params['module'])) { - $this->addElement('hidden', 'module', array('value'=>$params['module'], 'decorators'=>array('ViewHelper'))); + $this->addElement('hidden', 'record_id', array('value' => $record_id, 'decorators' => array('ViewHelper'))); + $this->addElement('hidden', 'path', array('value' => $request->getPathInfo(), 'decorators' => array('ViewHelper'))); + if (isset($params['module'])) { + $this->addElement('hidden', 'module', array('value' => $params['module'], 'decorators' => array('ViewHelper'))); } - $this->addElement('hidden', 'record_type', array('value'=>$record_type, 'decorators'=>array('ViewHelper'))); - $this->addElement('hidden', 'parent_comment_id', array('id'=>'parent-id', 'value'=>null, 'decorators'=>array('ViewHelper'))); - fire_plugin_hook('commenting_form', array('comment_form' => $this) ); - $this->addElement('submit', 'submit', array('label'=>__('Submit'))); + $this->addElement('hidden', 'record_type', array('value' => $record_type, 'decorators' => array('ViewHelper'))); + $this->addElement('hidden', 'parent_comment_id', array('id' => 'parent-id', 'value' => null, 'decorators' => array('ViewHelper'))); + fire_plugin_hook('commenting_form', array('comment_form' => $this)); + $this->addElement('submit', 'submit', array('label' => __('Submit'))); } private function _getRecordId($params) { - if(isset($params['module'])) { + if (isset($params['module'])) { switch($params['module']) { case 'exhibit-builder': //ExhibitBuilder uses slugs in the params, so need to negotiate around those //to dig up the record_id and model - if(!empty($params['page_slug_1'])) { + if (!empty($params['page_slug_1'])) { $page = get_current_record('exhibit_page', false); $id = $page->id; - } else if(!empty($params['item_id'])) { + } elseif (!empty($params['item_id'])) { $id = $params['item_id']; } else { //todo: check the ifs for an exhibit showing an item @@ -110,15 +127,15 @@ private function _getRecordId($params) private function _getRecordType($params) { - if(isset($params['module'])) { + if (isset($params['module'])) { switch($params['module']) { case 'exhibit-builder': //ExhibitBuilder uses slugs in the params, so need to negotiate around those //to dig up the record_id and model - if(!empty($params['page_slug_1'])) { + if (!empty($params['page_slug_1'])) { $page = get_current_record('exhibit_page', false); $model = 'ExhibitPage'; - } else if(!empty($params['item_id'])) { + } elseif (!empty($params['item_id'])) { $model = 'Item'; } else { //TODO: check for other possibilities @@ -134,5 +151,4 @@ private function _getRecordType($params) } return $model; } - -} \ No newline at end of file +} diff --git a/models/Api/Comment.php b/models/Api/Comment.php index 03c78fd..0727e0d 100644 --- a/models/Api/Comment.php +++ b/models/Api/Comment.php @@ -2,80 +2,80 @@ class Api_Comment extends Omeka_Record_Api_AbstractRecordAdapter implements Zend_Acl_Resource_Interface { - // Get the REST representation of a record. - public function getRepresentation(Omeka_Record_AbstractRecord $comment) + // Get the REST representation of a record. + public function getRepresentation(Omeka_Record_AbstractRecord $comment) { $user = current_user(); - if($user->role == 'admin' || $user->role == 'super') { + if ($user->role == 'admin' || $user->role == 'super') { $allowAll = true; } else { $allowAll = false; } $representation = array( - 'id' => $comment->id, - 'url' => self::getResourceUrl("/comments/{$comment->id}"), - 'record_id' => $comment->record_id, - 'record_type' => $comment->record_type, - 'path' => $comment->path, - 'added' => self::getDate($comment->added), - 'body' => $comment->body, - 'author_name' => $comment->author_name, - 'author_url' => $comment->author_url, - 'approved' => (bool) $comment->approved, - ); + 'id' => $comment->id, + 'url' => self::getResourceUrl("/comments/{$comment->id}"), + 'record_id' => $comment->record_id, + 'record_type' => $comment->record_type, + 'path' => $comment->path, + 'added' => self::getDate($comment->added), + 'body' => $comment->body, + 'author_name' => $comment->author_name, + 'author_url' => $comment->author_url, + 'approved' => (bool) $comment->approved, + ); - if($allowAll) { + if ($allowAll) { $representation['ip'] = $comment->ip; $representation['user_agent'] = $comment->user_agent; $representation['flagged'] = $comment->flagged; $representation['is_spam'] = $comment->is_spam; } - - if($comment->parent_comment_id) { + + if ($comment->parent_comment_id) { $representation['parent_comment'] = array( - 'id' => $comment->parent_comment_id, - 'resource' => 'comments', - 'url' => self::getResourceUrl("/comments/{$comment->parent_comment_id}") - ); + 'id' => $comment->parent_comment_id, + 'resource' => 'comments', + 'url' => self::getResourceUrl("/comments/{$comment->parent_comment_id}"), + ); } else { $representation['parent_comment'] = null; } - + $typeResource = Inflector::tableize($comment->record_type); $representation['record_url'] = array( - 'id' => $comment->record_id, - 'resource' => $typeResource, - 'url' => self::getResourceUrl("/$typeResource/{$comment->record_id}") - ); - if($comment->user_id) { + 'id' => $comment->record_id, + 'resource' => $typeResource, + 'url' => self::getResourceUrl("/$typeResource/{$comment->record_id}"), + ); + if ($comment->user_id) { $representation['user'] = array( - 'id' => $comment->user_id, - 'url' => self::getResourceUrl("/users/{$comment->user_id}") - ); + 'id' => $comment->user_id, + 'url' => self::getResourceUrl("/users/{$comment->user_id}"), + ); } else { $representation['user'] = null; } - - if($user && is_allowed('Commenting_Comment', 'update-approved')) { + + if ($user && is_allowed('Commenting_Comment', 'update-approved')) { $representation['author_email'] = $comment->author_email; } - return $representation; + return $representation; } - + public function getResourceId() { return "Commenting_Comment"; - } - - // Set data to a record during a POST request. - public function setPostData(Omeka_Record_AbstractRecord $record, $data) - { - // Set properties directly to a new record. - } - - // Set data to a record during a PUT request. - public function setPutData(Omeka_Record_AbstractRecord $record, $data) - { - // Set properties directly to an existing record. - } -} \ No newline at end of file + } + + // Set data to a record during a POST request. + public function setPostData(Omeka_Record_AbstractRecord $record, $data) + { + // Set properties directly to a new record. + } + + // Set data to a record during a PUT request. + public function setPutData(Omeka_Record_AbstractRecord $record, $data) + { + // Set properties directly to an existing record. + } +} diff --git a/models/Comment.php b/models/Comment.php index 455646b..9bda96b 100644 --- a/models/Comment.php +++ b/models/Comment.php @@ -1,6 +1,4 @@ _mixins[] = new Mixin_Search($this); - } - + } + protected function afterSave($args) { // A record's search text is public by default, but there are times // when this is not desired, e.g. when an item is marked as // private. @todo: Make a check to see if the record is public or private. - + if (!$this->approved || $this->is_spam) { // Setting the search text to private makes it invisible to // most users. $this->setSearchTextPrivate(); } - + // Set the record's title. This will be used to identify the record // in the search results. - + //comments don't have titles $this->setSearchTextTitle(snippet($this->body, 0, 40)); - + // Set the record's search text. Records that implement the // Mixin_ElementText mixin during _initializeMixins() will // automatically have all element texts added. Note that you // can add multiple search texts, which simply appends them. //$this->addSearchText($recordTitle); - + $this->addSearchText($this->body); - } - + } + public function checkSpam() { $wordPressAPIKey = get_option('commenting_wpapi_key'); - if(!empty($wordPressAPIKey)) { + if (!empty($wordPressAPIKey)) { $ak = new Zend_Service_Akismet($wordPressAPIKey, WEB_ROOT ); $data = $this->getAkismetData(); try { @@ -81,26 +79,25 @@ public function getAkismetData() 'permalink' => $permalink, 'comment_type' => 'comment', 'comment_author_email' => $this->author_email, - 'comment_content' => $this->body - + 'comment_content' => $this->body, ); - if($this->author_url) { + if ($this->author_url) { $data['comment_author_url'] = $this->author_url; } - if($this->author_name) { + if ($this->author_name) { $data['comment_author_name'] = $this->author_name; } return $data; } - + protected function _validate() { - if(trim(strip_tags($this->body)) == '' ) { + if (trim(strip_tags($this->body)) == '' ) { $this->addError('body', "Can't leave an empty comment!"); } } - + public function getRecordUrl($action = 'show') { switch($action) { @@ -110,9 +107,9 @@ public function getRecordUrl($action = 'show') revert_theme_base_url(); return $url; break; - + default: - //sadly, I made the plugin name, and so the controller name, different + //sadly, I made the plugin name, and so the controller name, different //because of the extant, but not maintained, Comments plugin //return parent::getRecordUrl($action); return url("commenting/comment/$action/id/{$this->id}"); @@ -121,9 +118,9 @@ public function getRecordUrl($action = 'show') public function setArray($data) { - if(empty($data['parent_comment_id'])) { + if (empty($data['parent_comment_id'])) { $data['parent_comment_id'] = null; } parent::setArray($data); } -} \ No newline at end of file +} diff --git a/models/Table/Comment.php b/models/Table/Comment.php index a45053d..976265c 100644 --- a/models/Table/Comment.php +++ b/models/Table/Comment.php @@ -2,16 +2,16 @@ class Table_Comment extends Omeka_Db_Table { - public function getSelect() - { + public function getSelect() + { $select = parent::getSelect(); $request = Zend_Controller_Front::getInstance()->getRequest(); - //only show approved comments to api without a proper key - if($request && $request->getControllerName() == 'api') { - if(!is_allowed('Commenting_Comment', 'update-approved')) { + //only show approved comments to api without a proper key + if ($request && $request->getControllerName() == 'api') { + if (!is_allowed('Commenting_Comment', 'update-approved')) { $select->where('approved = ?', 1); } - } - return $select; + } + return $select; } -} \ No newline at end of file +} diff --git a/views/admin/comment.php b/views/admin/comment.php index 2f2457c..8a90746 100644 --- a/views/admin/comment.php +++ b/views/admin/comment.php @@ -1,38 +1,38 @@ -getTable($comment->record_type)->find($comment->record_id); // try hard to dig up a likely label from the metadata or properties try { $label = metadata($record, array('Dublin Core', 'Title')); } catch(BadMethodCallException $e) { - -} -if(empty($label)) { +} + +if (empty($label)) { try { $label = metadata($record, 'name'); } catch(InvalidArgumentException $e) { - + } } -if(empty($label)) { - try { - $label = metadata($record, 'title'); - } catch(InvalidArgumentException $e) { - - } +if (empty($label)) { + try { + $label = metadata($record, 'title'); + } catch(InvalidArgumentException $e) { + + } } -if(empty($label)) { - try { - $label = metadata($record, 'label'); - } catch(InvalidArgumentException $e) { - - } +if (empty($label)) { + try { + $label = metadata($record, 'label'); + } catch(InvalidArgumentException $e) { + + } } //sad trombone. couldn't find a label! -if(empty($label)) { +if (empty($label)) { $label = __('[Untitled]'); } ?> @@ -43,35 +43,35 @@
- +
body; ?>
- - \ No newline at end of file + + diff --git a/views/admin/comment/browse.php b/views/admin/comment/browse.php index 934f031..8dc38cc 100644 --- a/views/admin/comment/browse.php +++ b/views/admin/comment/browse.php @@ -10,19 +10,16 @@ - +

reCAPTCHA', "" . __('security settings') . "");?>

- - - - +
- + @@ -34,12 +31,12 @@
-partial('comment.php', array('comment' => $comment)); - } + } ?>
- \ 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 @@ - - +
- -
+ +

-
- formCheckbox('commenting_threaded', null, - array('checked'=> (bool) get_option('commenting_threaded') ? 'checked' : '' - - ) - ); ?> +
+ formCheckbox('commenting_threaded', null, array( + 'checked' => (bool) get_option('commenting_threaded') ? 'checked' : '', + )); ?>
- +
@@ -27,25 +31,47 @@

formText('commenting_comments_label', get_option('commenting_comments_label')); ?> -
+
+
+ + +
+
+
-
- +
+
+ formTextarea( + 'commenting_legal_text', + get_option('commenting_legal_text'), + array( + 'rows' => 5, + 'cols' => 60, + 'class' => array('textinput', 'html-editor'), + ) + ); ?> +

+ +

+
+
+ +
- -
+ +

-
- formCheckbox('commenting_allow_public', null, - array('checked'=> (bool) get_option('commenting_allow_public') ? 'checked' : '', - ) - ); ?> +
+ formCheckbox('commenting_allow_public', null, array( + 'checked' => (bool) get_option('commenting_allow_public') ? 'checked' : '', + )); ?>
-
- + +
@@ -53,31 +79,30 @@

- formCheckbox('commenting_require_public_moderation', null, - array('checked'=> (bool) get_option('commenting_require_public_moderation') ? 'checked' : '', - )); ?> + formCheckbox('commenting_require_public_moderation', null, array( + 'checked' => (bool) get_option('commenting_require_public_moderation') ? 'checked' : '', + )); ?>
-
- +
+
- -
+ +

-
+
'; - - foreach($userRoles as $role=>$label) { + foreach ($userRoles as $role => $label) { echo '
  • '; - echo $view->formCheckbox('commenting_moderate_roles[]', $role, - array('checked'=> in_array($role, $moderateRoles) ? 'checked' : '') - ); + echo $view->formCheckbox('commenting_moderate_roles[]', $role, array( + 'checked' => in_array($role, $moderateRoles) ? 'checked' : '', + )); echo $label; echo '
  • '; } @@ -91,49 +116,45 @@
    - -
    + +

    -
    +
    '; - - foreach($userRoles as $role=>$label) { + foreach ($userRoles as $role => $label) { echo '
  • '; - echo $view->formCheckbox('commenting_comment_roles[]', $role, - array('checked'=> in_array($role, $commentRoles) ? 'checked' : '') - ); + echo $view->formCheckbox('commenting_comment_roles[]', $role, array( + 'checked' => in_array($role, $commentRoles) ? 'checked' : '', + )); echo $label; echo '
  • '; - } echo ''; ?>
    - +
    - -
    + +

    -
    +
    '; - foreach($userRoles as $role=>$label) { + foreach ($userRoles as $role => $label) { echo '
  • '; - echo $view->formCheckbox('commenting_reqapp_comment_roles[]', $role, - array('checked'=> in_array($role, $reqAppCommentRoles) ? 'checked' : '') - ); + echo $view->formCheckbox('commenting_reqapp_comment_roles[]', $role, array( + 'checked' => in_array($role, $reqAppCommentRoles) ? 'checked' : '', + )); echo $label; echo '
  • '; - } echo ''; ?> @@ -143,15 +164,14 @@
    - -
    + +

    -
    - formCheckbox('commenting_allow_public_view', null, - array('checked'=> (bool) get_option('commenting_allow_public_view') ? 'checked' : '', - ) - ); ?> +
    + formCheckbox('commenting_allow_public_view', null, array( + 'checked' => (bool) get_option('commenting_allow_public_view') ? 'checked' : '', + )); ?>
    @@ -159,21 +179,21 @@
    - -
    + +
    -
    +
    '; - foreach($userRoles as $role=>$label) { + foreach ($userRoles as $role=> $label) { echo '
  • '; - echo $view->formCheckbox('commenting_view_roles[]', $role, - array('checked'=> in_array($role, $viewRoles) ? 'checked' : '') - ); + echo $view->formCheckbox('commenting_view_roles[]', $role, array( + 'checked' => in_array($role, $viewRoles) ? 'checked' : '', + )); echo $label; echo '
  • '; } @@ -182,22 +202,22 @@
    - - + +

    reCAPTCHA', "" . __('security settings') . "");?>

    - -
    + +

    -
    +
    formText('commenting_wpapi_key', get_option('commenting_wpapi_key'), - array('size'=> 45) - );?> + array('size' => 45) + );?>
    diff --git a/helpers/GetCommentForm.php b/views/helpers/GetCommentForm.php similarity index 60% rename from helpers/GetCommentForm.php rename to views/helpers/GetCommentForm.php index c7f3556..a60bbc0 100644 --- a/helpers/GetCommentForm.php +++ b/views/helpers/GetCommentForm.php @@ -1,19 +1,17 @@ post) { + if ($commentSession->post) { $form->isValid(unserialize($commentSession->post)); } unset($commentSession->post); return $form; - } + } } -} \ No newline at end of file +} diff --git a/helpers/GetComments.php b/views/helpers/GetComments.php similarity index 78% rename from helpers/GetComments.php rename to views/helpers/GetComments.php index 8b0c842..c7990bd 100644 --- a/helpers/GetComments.php +++ b/views/helpers/GetComments.php @@ -2,21 +2,55 @@ class Commenting_View_Helper_GetComments extends Zend_View_Helper_Abstract { - + public function getComments($options = array(), $record_id = null, $record_type = null) + { + $request = Zend_Controller_Front::getInstance()->getRequest(); + $params = $request->getParams(); + + if (!$record_id) { + $record_id = $this->_getRecordId($params); + } + + if (!$record_type) { + $record_type = $this->_getRecordType($params); + } + + $db = get_db(); + $commentTable = $db->getTable('Comment'); + $searchParams = array( + 'record_type' => $record_type, + 'record_id' => $record_id, + ); + if (isset($options['approved'])) { + $searchParams['approved'] = $options['approved']; + } + + if (!is_allowed('Commenting_Comment', 'update-approved')) { + $searchParams['flagged'] = 0; + $searchParams['is_spam'] = 0; + } + + $select = $commentTable->getSelectForFindBy($searchParams); + if (isset($options['order'])) { + $select->order("ORDER BY added " . $options['order']); + } + return $commentTable->fetchObjects($select); + } + private function _getRecordId($params) { - if(isset($params['module'])) { + if (isset($params['module'])) { switch($params['module']) { case 'exhibit-builder': //ExhibitBuilder uses slugs in the params, so need to negotiate around those //to dig up the record_id and model - if(isset($this->view->exhibit_page)) { + if (isset($this->view->exhibit_page)) { $id = $this->view->exhibit_page->id; } else { $id = $params['item_id']; } break; - + default: $id = $params['id']; break; @@ -24,23 +58,23 @@ private function _getRecordId($params) } else { $id = $params['id']; } - return $id; + return $id; } - + private function _getRecordType($params) { - if(isset($params['module'])) { + if (isset($params['module'])) { switch($params['module']) { case 'exhibit-builder': //ExhibitBuilder uses slugs in the params, so need to negotiate around those //to dig up the record_id and model - if(!empty($params['page_slug_1'])) { + if (!empty($params['page_slug_1'])) { $model = 'ExhibitPage'; } else { $model = 'Item'; } break; - + default: $model = Inflector::camelize($params['module']) . ucfirst( $params['controller'] ); break; @@ -48,42 +82,6 @@ private function _getRecordType($params) } else { $model = ucfirst(Inflector::singularize($params['controller'])); } - return $model; - } - - public function getComments($options = array(), $record_id = null, $record_type = null) - { - - $request = Zend_Controller_Front::getInstance()->getRequest(); - $params = $request->getParams(); - - if(!$record_id) { - $record_id = $this->_getRecordId($params); - } - - if(!$record_type) { - $record_type = $this->_getRecordType($params); - } - - $db = get_db(); - $commentTable = $db->getTable('Comment'); - $searchParams = array( - 'record_type' => $record_type, - 'record_id' => $record_id, - ); - if(isset($options['approved'])) { - $searchParams['approved'] = $options['approved']; - } - - if(!is_allowed('Commenting_Comment', 'update-approved')) { - $searchParams['flagged'] = 0; - $searchParams['is_spam'] = 0; - } - - $select = $commentTable->getSelectForFindBy($searchParams); - if(isset($options['order'])) { - $select->order("ORDER BY added " . $options['order']); - } - return $commentTable->fetchObjects($select); + return $model; } -} \ No newline at end of file +} diff --git a/views/public/comment.php b/views/public/common/comment.php similarity index 52% rename from views/public/comment.php rename to views/public/common/comment.php index a97bf58..6195165 100644 --- a/views/public/comment.php +++ b/views/public/common/comment.php @@ -1,7 +1,7 @@
    author_name)) { - if(empty($comment->author_url)) { + if (!empty($comment->author_name)) { + if (empty($comment->author_url)) { $authorText = $comment->author_name; } else { $authorText = "{$comment->author_name}"; @@ -17,9 +17,9 @@ echo ""; ?>
    -
    body; ?>
    - -

    flagged): ?> style='display:none;' >

    -

    flagged): ?>style='display:none;' >

    +
    body; ?>
    + +

    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)); ?> - +
    - partial('comment.php', array('comment' => $comment)); ?> + partial('common/comment.php', array('comment' => $comment)); ?>
    -
    \ No newline at end of file +
    diff --git a/views/public/common/threaded-comments.php b/views/public/common/threaded-comments.php new file mode 100644 index 0000000..ac4649e --- /dev/null +++ b/views/public/common/threaded-comments.php @@ -0,0 +1,11 @@ + + parent_comment_id == $parent_id): ?> +
    + partial('common/comment.php', array('comment' => $comment)); ?> +
    + partial('common/threaded-comments.php', array('comments' => $comments, 'parent_id' => $comment->id)); ?> +
    +
    + + diff --git a/views/public/css/commenting.css b/views/public/css/commenting.css index 823221f..a03a008 100644 --- a/views/public/css/commenting.css +++ b/views/public/css/commenting.css @@ -1,38 +1,38 @@ - /* desperate attempts to prevent crazy padding across themes */ div#comments-container div { - padding: 2px !important; - margin: 2px !important; - clear: both; + padding: 2px !important; + margin: 2px !important; + clear: both; } div#comments-container label { - padding: 2px !important; - margin: 2px !important; + padding: 2px !important; + margin: 2px !important; } div#comments-container div.comment-body { - margin-left: 100px !important; - margin-top: 12px !important; - min-height: 60px; - padding: 6px; + margin-left: 100px !important; + margin-top: 12px !important; + min-height: 60px; + padding: 6px; } /* end desperation */ form#comment-form { - clear:both; - line-height: 1em; + clear:both; + line-height: 1em; } -form#comment-form input, form#comment-form textarea { +form#comment-form input, +form#comment-form textarea { height: inherit; font-size: 14px; line-height: 1em; } div#comment-main-container { - max-width: 550px; + max-width: 550px; } div#comments-container div.comment-children { @@ -40,42 +40,42 @@ div#comments-container div.comment-children { } div.comment { - margin-left: 12px; - margin-top: 3px; - margin-bottom: 6px; - clear: both; - min-height: 80px; - width: 60%; - min-width: 400px; + margin-left: 12px; + margin-top: 3px; + margin-bottom: 6px; + clear: both; + min-height: 80px; + width: 60%; + min-width: 400px; } div.comment-author { - float: left; - margin: 0 6px; - width: 100px; + float: left; + margin: 0 6px; + width: 100px; } -.comment-flag , .comment-unflag { - float:left; +.comment-flag, +.comment-unflag { + float: left; cursor: pointer; } div.comment-flagged { - background-color: pink; + background-color: #F09999; } - div.comment-body p { - font-size: 1em; + font-size: 1em; } .comment-reply { - cursor: pointer; - float: right; + cursor: pointer; + float: right; } p.comment-author-name { - margin: 0; + margin: 0; } div.success { @@ -83,16 +83,16 @@ div.success { } input.hidden { - display:none; + display:none; } -span.comment-flag, span.comment-unflag { +span.comment-flag, +span.comment-unflag { padding-left: 6px; cursor: pointer; } a.mceButton { - overflow: inherit; - -} + overflow: inherit; +} diff --git a/views/public/javascripts/commenting.js b/views/public/javascripts/commenting.js index 36a566b..0ba8556 100644 --- a/views/public/javascripts/commenting.js +++ b/views/public/javascripts/commenting.js @@ -1,52 +1,51 @@ var Commenting = { - - handleReply: function(event) { - Commenting.moveForm(event); + handleReply: function(event) { + Commenting.moveForm(event); }, - + finalizeMove: function() { - jQuery('#comment-form-body_parent').attr('style', '') + jQuery('#comment-form-body_parent').attr('style', ''); + }, + + moveForm: function(event) { + //first make tinyMCE go away so it is safe to move around in the DOM + tinyMCE.execCommand('mceRemoveControl', false, 'comment-form-body'); + jQuery('#comment-form').insertAfter(event.target); + commentId = Commenting.getCommentId(event.target); + jQuery('#parent-id').val(commentId); + tinyMCE.execCommand('mceAddControl', false, 'comment-form-body'); + }, + + flag: function(event) { + var commentId = Commenting.getCommentId(event.target); + var json = {'id': commentId }; + jQuery.post(Commenting.pluginRoot + "flag", json, Commenting.flagResponseHandler); }, - - moveForm: function(event) { - //first make tinyMCE go away so it is safe to move around in the DOM - tinyMCE.execCommand('mceRemoveControl', false, 'comment-form-body'); - jQuery('#comment-form').insertAfter(event.target); - commentId = Commenting.getCommentId(event.target); - jQuery('#parent-id').val(commentId); - tinyMCE.execCommand('mceAddControl', false, 'comment-form-body'); - }, - - flag: function(event) { - var commentId = Commenting.getCommentId(event.target); - var json = {'id': commentId }; - jQuery.post(Commenting.pluginRoot + "flag", json, Commenting.flagResponseHandler); - }, unflag: function(event) { var commentId = Commenting.getCommentId(event.target); - var json = {'id': commentId }; + var json = {'id': commentId }; jQuery.post(Commenting.pluginRoot + "unflag", json, Commenting.flagResponseHandler); - }, - - flagResponseHandler: function(response, status, jqxhr) { - var comment = jQuery('#comment-' + response.id); - if(response.action == 'flagged') { - comment.find('div.comment-body').addClass('comment-flagged'); - comment.find('p.comment-flag').hide(); - comment.find('p.comment-unflag').show(); - } - - if(response.action == 'unflagged') { - comment.find('div.comment-body').removeClass('comment-flagged'); - comment.find('p.comment-flag').show(); - comment.find('p.comment-unflag').hide(); - } - }, - - getCommentId: function(el) { - return jQuery(el).parents('div.comment').first().attr('id').substring(8); - } + }, + + flagResponseHandler: function(response, status, jqxhr) { + var comment = jQuery('#comment-' + response.id); + if (response.action == 'flagged') { + comment.find('div.comment-body').addClass('comment-flagged'); + comment.find('p.comment-flag').hide(); + comment.find('p.comment-unflag').show(); + } + + if (response.action == 'unflagged') { + comment.find('div.comment-body').removeClass('comment-flagged'); + comment.find('p.comment-flag').show(); + comment.find('p.comment-unflag').hide(); + } + }, + + getCommentId: function(el) { + return jQuery(el).parents('div.comment').first().attr('id').substring(8); + } }; /** @@ -58,11 +57,11 @@ var Commenting = { * defaults. */ -if(typeof Omeka == 'undefined' ) { +if (typeof Omeka == 'undefined' ) { Omeka = {}; } -if(typeof Omeka.wysiwyg == 'undefined') { +if (typeof Omeka.wysiwyg == 'undefined') { Omeka.wysiwyg = function (params) { // Default parameters initParams = { @@ -79,7 +78,7 @@ if(typeof Omeka.wysiwyg == 'undefined') { media_strict: false, width: "100%" }; - + // Overwrite default params with user-passed ones. for (var attribute in params) { // Account for annoying scripts that mess with prototypes. @@ -89,21 +88,17 @@ if(typeof Omeka.wysiwyg == 'undefined') { } tinyMCE.init(initParams); }; - } -jQuery(document).ready(function() { - jQuery('.comment-reply').click(Commenting.handleReply); - jQuery('.comment-flag').click(Commenting.flag); - jQuery('.comment-unflag').click(Commenting.unflag); - var commentingWysiwyg = { - elements: 'comment-form-body', - mode: 'exact', - valid_child_elements: "ul[li],ol[li]", - theme_advanced_buttons1: "bold,italic,underline,link,bullist,numlist,|,code", - }; - Omeka.wysiwyg(commentingWysiwyg); +jQuery(document).ready(function() { + jQuery('.comment-reply').click(Commenting.handleReply); + jQuery('.comment-flag').click(Commenting.flag); + jQuery('.comment-unflag').click(Commenting.unflag); + var commentingWysiwyg = { + elements: 'comment-form-body', + mode: 'exact', + valid_child_elements: "ul[li],ol[li]", + theme_advanced_buttons1: "bold,italic,underline,link,bullist,numlist,|,code", + }; + Omeka.wysiwyg(commentingWysiwyg); }); - - - \ No newline at end of file diff --git a/views/public/threaded-comments.php b/views/public/threaded-comments.php deleted file mode 100644 index 24767cb..0000000 --- a/views/public/threaded-comments.php +++ /dev/null @@ -1,11 +0,0 @@ - - parent_comment_id == $parent_id): ?> -
    - partial('comment.php', array('comment' => $comment)); ?> -
    - partial('threaded-comments.php', array('comments' => $comments, 'parent_id'=>$comment->id)); ?> -
    -
    - - \ No newline at end of file