diff --git a/CommentForm.php b/CommentForm.php
deleted file mode 100644
index c9b7469..0000000
--- a/CommentForm.php
+++ /dev/null
@@ -1,138 +0,0 @@
-setAction(WEB_ROOT . '/commenting/comment/add');
- $this->setAttrib('id', 'comment-form');
- $user = current_user();
-
- //assume registered users are trusted and don't make them play recaptcha
- if(!$user && get_option('recaptcha_public_key') && get_option('recaptcha_private_key')) {
- $this->addElement('captcha', 'captcha', array(
- 'class' => 'hidden',
- 'label' => __("Please verify you're a human"),
- 'captcha' => array(
- '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:
- )
- ));
- }
-
- $urlOptions = array(
- 'label'=>__('Website'),
- );
- $emailOptions = array(
- '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')
- ),
- ),
- ),
- )
- );
-
- $request = Zend_Controller_Front::getInstance()->getRequest();
- $params = $request->getParams();
-
- $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_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'])) {
- 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'])) {
- $page = get_current_record('exhibit_page', false);
- $id = $page->id;
- } else if(!empty($params['item_id'])) {
- $id = $params['item_id'];
- } else {
-//todo: check the ifs for an exhibit showing an item
- }
- break;
-
- default:
- $id = $params['id'];
- break;
- }
- } else {
- $id = $params['id'];
- }
- return $id;
-
-
- }
-
- private function _getRecordType($params)
- {
- 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'])) {
- $page = get_current_record('exhibit_page', false);
- $model = 'ExhibitPage';
- } else if(!empty($params['item_id'])) {
- $model = 'Item';
- } else {
-//TODO: check for other possibilities
- }
- break;
-
- default:
- $model = Inflector::camelize($params['module']) . ucfirst( $params['controller'] );
- break;
- }
- } else {
- $model = ucfirst(Inflector::singularize($params['controller']));
- }
- return $model;
- }
-
-}
\ No newline at end of file
diff --git a/CommentingPlugin.php b/CommentingPlugin.php
index f399ac9..37af7d8 100644
--- a/CommentingPlugin.php
+++ b/CommentingPlugin.php
@@ -1,30 +1,65 @@
'a:2:{i:0;s:16:"collections/show";i:1;s:10:"items/show";}',
+ 'commenting_comment_roles' => '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 +73,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,138 +111,203 @@ 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()));
+ set_option('commenting_pages', $this->_options['commenting_pages']);
$sql = "ALTER TABLE `$db->Comment` CHANGE `flagged` `flagged` TINYINT( 1 ) NOT NULL DEFAULT '0'";
$db->query($sql);
}
}
+ /**
+ * Uninstall the plugin.
+ */
public function hookUninstall()
{
- $db = get_db();
+ $db = $this->_db;
$sql = "DROP TABLE IF EXISTS `$db->Comment`";
$db->query($sql);
+
+ $this->_uninstallOptions();
+ }
+
+ public function hookPublicHead($args)
+ {
+ if ($this->_isCommentingEnabled()) {
+ queue_css_file('commenting');
+ queue_js_file('commenting');
+ queue_js_file('tiny_mce', 'javascripts/vendor/tiny_mce');
+ queue_js_string("Commenting.pluginRoot = '" . WEB_ROOT . "/commenting/comment/'");
+ }
}
- public function hookPublicHead()
+ public function hookAdminHead($args)
{
- queue_css_file('commenting');
- queue_js_file('commenting');
- queue_js_file('tiny_mce', 'javascripts/vendor/tiny_mce');
- queue_js_string("Commenting.pluginRoot = '" . WEB_ROOT . "/commenting/comment/'");
+ if ($this->_isCommentingEnabled()) {
+ queue_css_file('commenting');
+ }
}
- public function hookAdminHead()
+ /**
+ * Helper to determine if comments are enabled on current page or not.
+ */
+ private function _isCommentingEnabled()
{
- queue_css_file('commenting');
+ static $isEnabled = null;
+ if (is_null($isEnabled)) {
+ $request = Zend_Controller_Front::getInstance()->getRequest();
+ $controller = $request->getControllerName();
+ $action = $request->getActionName();
+ $pages = get_option('commenting_pages');
+ $pages = empty($pages) ? array() : unserialize($pages);
+ $isEnabled = in_array($controller . '/' . $action, $pages);
+ }
+ return $isEnabled;
}
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();
}
}
- public static function showComments($args = array())
+ /**
+ * Helper to append comments and comment form to a page.
+ */
+ protected function _showComments($args = array())
{
- echo "';
+ echo $html;
}
public function hookPublicItemsShow($args)
{
- self::showComments($args);
+ $this->_showComments($args);
}
public function hookPublicCollectionsShow($args)
{
- self::showComments($args);
+ $this->_showComments($args);
}
- public function hookConfig($args)
+ /**
+ * This hook can be used in place of view helpers GetComments() and
+ * GetCommentForm().
+ */
+ public function hookCommentingComments($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);
- }
- set_option($key, $value);
- }
+ $this->_showComments($args);
}
public function hookConfigForm()
{
- include COMMENTING_PLUGIN_DIR . '/config_form.php';
+ echo get_view()->partial(
+ 'plugins/commenting-config-form.php'
+ );
+ }
+
+ public function hookConfig($args)
+ {
+ $post = $args['post'];
+ foreach (array(
+ 'commenting_pages',
+ '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 hookDefineAcl($args)
@@ -215,34 +318,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 +353,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 +369,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 +401,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 +412,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 53%
rename from README
rename to README.md
index a38241d..ab3331a 100644
--- a/README
+++ b/README.md
@@ -32,20 +32,88 @@ See USE CASES below for examples of configuration combinations
DISPLAYING COMMENTS
===================
-Commenting will automatically add commenting options to Item and Collection show pages. To enable commenting on other
-record types from modules (e.g. SimplePages or ExhibitBuilder), you will have to add the following lines
+Commenting will automatically add commenting options to Item and Collection show
+pages via default public hooks:
+
+```php
+fire_plugin_hook('public_items_show', array('view' => $this, 'item' => $item));
+```php
+
+or
+
+```php
+fire_plugin_hook('public_collections_show', array('view' => $this, 'collection' => $collection));
+```
+
+For flexibility and to enable commenting on other record types from modules
+(e.g. SimplePages or ExhibitBuilder), you will have to add the following lines
to the appropriate place in the plugin's public view script:
```php
-
+fire_plugin_hook('commenting_comments');
+```
+
+or with options:
+
+```php
+fire_plugin_hook('commenting_comments', array(
+ 'view' => $this,
+ 'display' => array('comments', 'comment_form'),
+ 'comments' => $comments,
+));
+```
+
+For example, to show comments on exhibit sections and pages, the file `/plugins/ExhibitBuilder/views/public/exhibits/show.php`
+could look like:
+
+```php
+ metadata('exhibit_page', 'title') . ' · ' . metadata('exhibit', 'title'),
+ 'bodyclass' => 'exhibits show'));
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
```
-Keep in mind that updating themes or plugins will clobber your addition of the commenting functions.
+Keep in mind that updating themes or plugins will clobber your addition of the
+commenting functions.
-The Commenting plugin knows how to work with SimplePages and ExhibitBuilder. Due to variability
-in how plugins store their data in the database, other record types and views supplied by other plugins
-might or might not work out of the box. Please ask on the forums or dev list if you would like Commenting
-to work with other plugins.
+The Commenting plugin knows how to work with SimplePages and ExhibitBuilder. Due
+to variability in how plugins store their data in the database, other record
+types and views supplied by other plugins might or might not work out of the
+box. Please ask on the forums or dev list if you would like Commenting to work
+with other plugins.
USE CASES
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/forms/CommentForm.php b/forms/CommentForm.php
new file mode 100644
index 0000000..a8da5b9
--- /dev/null
+++ b/forms/CommentForm.php
@@ -0,0 +1,222 @@
+_record = $record;
+
+ parent::__construct();
+ }
+
+ public function init()
+ {
+ parent::init();
+ $this->setAction(WEB_ROOT . '/commenting/comment/add');
+ $this->setAttrib('id', 'comment-form');
+ $user = current_user();
+
+ //assume registered users are trusted and don't make them play recaptcha
+ if (!$user && get_option('recaptcha_public_key') && get_option('recaptcha_private_key')) {
+ $this->addElement('captcha', 'captcha', array(
+ 'class' => 'hidden',
+ 'label' => __("Please verify you're a human"),
+ 'captcha' => array(
+ '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:
+ ),
+ 'decorators' => array(),
+ ));
+ }
+
+ $urlOptions = array(
+ 'label' => __('Website'),
+ );
+ $emailOptions = array(
+ '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'),
+ ),
+ ),
+ ),
+ ));
+
+ // 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();
+
+ $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_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')));
+ }
+
+ /**
+ * Helper to get record id from request params.
+ *
+ * @see plugins/Commenting/views/helpers/GetComments.php
+ *
+ * @todo To be merged.
+ */
+ private function _getRecordId($params)
+ {
+ if (!empty($this->_record)) {
+ return $this->_record->id;
+ }
+
+ if (isset($params['module'])
+ && $params['module'] == 'commenting'
+ && $params['controller'] == 'comment'
+ && $params['action'] == 'add'
+ ) {
+ return $params['record_id'];
+ }
+
+//@TODO: update exhibit-builder handling for 2.0
+ if (isset($params['module'])) {
+ switch ($params['module']) {
+ case 'exhibit-builder':
+ $view = get_view();
+ // ExhibitBuilder uses slugs in the params, so need to
+ // negotiate around those to dig up the record_id and model.
+ if (isset($view->exhibit) && isset($view->exhibit_pages)) {
+ $id = $view->exhibit->id;
+ }
+ elseif (isset($view->exhibit_page)) {
+ $id = $view->exhibit_page->id;
+ }
+//todo: check the ifs for an exhibit showing an item
+ elseif (isset($params['item_id'])) {
+ $id = $params['item_id'];
+ }
+ else {
+ $id = isset($params['id']) ? $params['id'] : null;
+ }
+ break;
+
+ default:
+ $id = isset($params['id']) ? $params['id'] : null;
+ break;
+ }
+ }
+ // Default for collections, items and files.
+ else {
+ $id = $params['id'];
+ }
+ return $id;
+ }
+
+ /**
+ * Helper to get record type from request params.
+ *
+ * @see plugins/Commenting/views/helpers/GetComments.php
+ *
+ * @todo To be merged.
+ */
+ private function _getRecordType($params)
+ {
+ if (!empty($this->_record)) {
+ return get_class($this->_record);
+ }
+
+ if (isset($params['module'])
+ && $params['module'] == 'commenting'
+ && $params['controller'] == 'comment'
+ && $params['action'] == 'add'
+ ) {
+ return $params['record_type'];
+ }
+
+//@TODO: update exhibit-builder handling for 2.0
+ if (isset($params['module'])) {
+ switch ($params['module']) {
+ case 'exhibit-builder':
+ $view = get_view();
+ // ExhibitBuilder uses slugs in the params, so need to
+ // negotiate around those to dig up the record_id and model.
+ if (isset($view->exhibit) && isset($view->exhibit_pages)) {
+ $model = 'Exhibit';
+ }
+ elseif (isset($view->exhibit_page)) {
+ $model = 'ExhibitPage';
+ }
+// Todo: check the ifs for an exhibit showing an item.
+ else {
+ $model = 'Item';
+ }
+ break;
+
+ default:
+ $model = Inflector::camelize($params['module']) . ucfirst( $params['controller'] );
+ break;
+ }
+ }
+ // Default for collections, items and files.
+ else {
+ $model = ucfirst(Inflector::singularize($params['controller']));
+ }
+ return $model;
+ }
+}
diff --git a/helpers/GetCommentForm.php b/helpers/GetCommentForm.php
deleted file mode 100644
index c7f3556..0000000
--- a/helpers/GetCommentForm.php
+++ /dev/null
@@ -1,19 +0,0 @@
-post) {
- $form->isValid(unserialize($commentSession->post));
- }
- unset($commentSession->post);
- return $form;
- }
- }
-}
\ No newline at end of file
diff --git a/helpers/GetComments.php b/helpers/GetComments.php
deleted file mode 100644
index 8b0c842..0000000
--- a/helpers/GetComments.php
+++ /dev/null
@@ -1,89 +0,0 @@
-view->exhibit_page)) {
- $id = $this->view->exhibit_page->id;
- } else {
- $id = $params['item_id'];
- }
- break;
-
- default:
- $id = $params['id'];
- break;
- }
- } else {
- $id = $params['id'];
- }
- return $id;
- }
-
- private function _getRecordType($params)
- {
- 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'])) {
- $model = 'ExhibitPage';
- } else {
- $model = 'Item';
- }
- break;
-
- default:
- $model = Inflector::camelize($params['module']) . ucfirst( $params['controller'] );
- break;
- }
- } 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);
- }
-}
\ 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') . " ");?>
-
-
-
-
+
-
\ 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 55%
rename from config_form.php
rename to views/admin/plugins/commenting-config-form.php
index 31c74b2..356f459 100644
--- a/config_form.php
+++ b/views/admin/plugins/commenting-config-form.php
@@ -1,24 +1,67 @@
-
-
+
+
+
-
+
@@ -27,25 +70,47 @@
formText('commenting_comments_label', get_option('commenting_comments_label')); ?>
-
+
-
-
+
+
+
+
-
+
+
+