Skip to content

Commit

Permalink
Cleaned whitespaces and line endings.
Browse files Browse the repository at this point in the history
Conflicts:
	CommentingPlugin.php
  • Loading branch information
Daniel-KM committed Sep 25, 2014
1 parent 052d3bb commit 3b2397a
Show file tree
Hide file tree
Showing 16 changed files with 615 additions and 634 deletions.
179 changes: 99 additions & 80 deletions CommentingPlugin.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
<?php
/**
* CommentingPlugin class
*
* @copyright Copyright 2011-2013 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
* @package Commenting
*/

/**
* Commenting plugin.
*/
/**
* CommentingPlugin class
*
* @copyright Copyright 2011-2013 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
* @package Commenting
*/

/**
* Commenting plugin.
*/
class CommentingPlugin extends Omeka_Plugin_AbstractPlugin
{
/**
* @var array Hooks for the plugin.
*/
/**
* @var array Hooks for the plugin.
*/
protected $_hooks = array(
'initialize',
'install',
'upgrade',
'uninstall',
'public_items_show',
'public_collections_show',
'public_head',
'admin_head',
'config_form',
'config',
'define_acl',
'public_head',
'admin_head',
'public_items_show',
'public_collections_show',
'after_delete_record',
'upgrade',
'initialize'
'define_acl',
);

/**
* @var array Filters for the plugin.
*/
/**
* @var array Filters for the plugin.
*/
protected $_filters = array(
'admin_navigation_main',
'search_record_types',
'api_resources',
'api_extend_items',
'api_extend_collections'
'api_extend_collections',
);

/**
* @var array Options and their default values.
*/
protected $_options = array(
// serialize(array()) = 'a:0:{}'.
'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' => '',
);

/**
Expand All @@ -68,9 +80,9 @@ public function setUp()
parent::setUp();
}

/**
* Install the plugin.
*/
/**
* Install the plugin.
*/
public function hookInstall()
{
$db = $this->_db;
Expand All @@ -97,22 +109,21 @@ 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 = '<p>';
$html .= __('I agree with %s terms of use %s and I accept to free my contribution under the licence %s CC BY-SA %s.',
'<a href="#" target="_blank">', '</a>',
'<a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank">', '</a>'
'<a rel="licence" href="#" target="_blank">', '</a>',
'<a rel="licence" href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank">', '</a>'
);
$html .= '</p>';
$this->_options['commenting_legal_text'] = $html;

$this->_installOptions();
}

/**
* Upgrade the plugin.
*/
public function hookUpgrade($args)
{
$db = $this->_db;
Expand Down Expand Up @@ -152,13 +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();

$this->_uninstallOptions();
}

public function hookPublicHead()
Expand All @@ -184,25 +198,27 @@ public function hookAfterDeleteRecord($args)
}
}

/**
* 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 "<div id='comments-container'>";
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();
}

$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('common/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)
Expand All @@ -224,28 +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()
{
echo get_view()->partial(
'plugins/commenting-config-form.php'
);
}

public function hookDefineAcl($args)
{
$acl = $args['acl'];
Expand All @@ -271,13 +290,13 @@ public function hookDefineAcl($args)
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',
));
}
}

Expand Down Expand Up @@ -305,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;
}
Expand Down Expand Up @@ -337,20 +356,20 @@ 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;
}

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);
}
}
24 changes: 12 additions & 12 deletions controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Commenting_CommentController extends Omeka_Controller_AbstractActionContro
*/
public function init()
{
$this->_helper->db->setDefaultModelName('Comment');
$this->_helper->db->setDefaultModelName('Comment');
}

public function browseAction()
Expand All @@ -34,11 +34,11 @@ public function batchDeleteAction()
$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'])),
Expand All @@ -59,18 +59,18 @@ public function addAction()
$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
//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();
Expand Down Expand Up @@ -161,7 +161,7 @@ public function updateFlaggedAction()
{
$commentIds = $_POST['ids'];
$flagged = $_POST['flagged'];

if($commentIds) {
foreach($commentIds as $id) {
$comment = $this->_helper->db->getTable('Comment')->find($id);
Expand All @@ -179,7 +179,7 @@ public function updateFlaggedAction()
$response = array('status'=>'ok', 'action'=>$action, 'ids'=>$commentIds);
$this->_helper->json($response);
}

public function flagAction()
{
$commentId = $_POST['id'];
Expand All @@ -190,7 +190,7 @@ public function flagAction()
$response = array('status'=>'ok', 'id'=>$commentId, 'action'=>'flagged');
$this->_helper->json($response);
}

public function unflagAction()
{
$commentId = $_POST['id'];
Expand All @@ -200,7 +200,7 @@ public function unflagAction()
$response = array('status'=>'ok', 'id'=>$commentId, 'action'=>'unflagged');
$this->_helper->json($response);
}

private function emailFlagged($comment)
{
$mail = new Zend_Mail('UTF-8');
Expand All @@ -217,12 +217,12 @@ private function emailFlagged($comment)
} catch(Exception $e) {
_log($e);
}

}

private function _getForm()
{
require_once dirname(dirname(__FILE__)) . '/forms/CommentForm.php';
return new Commenting_CommentForm;
}
}
}
Loading

0 comments on commit 3b2397a

Please sign in to comment.