Skip to content

Commit

Permalink
Provide a "default moderate" option for comments. The default behavior
Browse files Browse the repository at this point in the history
is unchanged, but you now have the option to set all new comments to
be unpublished and then moderate them through the Admin > Content >
Comments interface.

Fixes #2126.
  • Loading branch information
bharat committed May 28, 2014
1 parent 1637723 commit 9e0631a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
7 changes: 7 additions & 0 deletions modules/comment/controllers/admin_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function save() {
$form->comment_settings->access_permissions->value);
module::set_var("comment", "rss_visible",
$form->comment_settings->rss_visible->value);
module::set_var("comment", "initial_state",
$form->comment_settings->initial_state->value);
message::success(t("Comment settings updated"));
url::redirect("admin/comments");
}
Expand All @@ -47,6 +49,11 @@ private function _get_admin_form() {
->options(array("everybody" => t("Everybody"),
"registered_users" => t("Only registered users")))
->selected(module::get_var("comment", "access_permissions"));
$comment_settings->dropdown("initial_state")
->label(t("Are new comments published or unpublished by default?"))
->options(array("published" => t("Published"),
"unpublished" => t("Unpublished")))
->selected(module::get_var("comment", "initial_state"));
$comment_settings->dropdown("rss_visible")
->label(t("Which RSS feeds can users see?"))
->options(array("all" => t("All comment feeds"),
Expand Down
4 changes: 4 additions & 0 deletions modules/comment/css/comment.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
padding: .2em .6em;
}

.g-comment-state-unpublished {
font-style: italic;
color: #999;
}
6 changes: 6 additions & 0 deletions modules/comment/helpers/comment_installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static function install() {
module::set_var("comment", "spam_caught", 0);
module::set_var("comment", "access_permissions", "everybody");
module::set_var("comment", "rss_visible", "all");
module::set_var("comment", "initial_state", "published");
}

static function upgrade($version) {
Expand Down Expand Up @@ -99,6 +100,11 @@ static function upgrade($version) {
}
module::set_version("comment", $version = 7);
}

if ($version == 7) {
module::set_var("comment", "initial_state", "published");
module::set_version("comment", $version = 8);
}
}

static function uninstall() {
Expand Down
2 changes: 1 addition & 1 deletion modules/comment/models/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function save() {
// New comment
$this->created = $this->updated;
if (empty($this->state)) {
$this->state = "published";
$this->state = module::get_var("comment", "initial_state");
}

// These values are useful for spam fighting, so save them with the comment. It's painful to
Expand Down
2 changes: 1 addition & 1 deletion modules/comment/module.info
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Comments"
description = "Allows users and guests to leave comments on photos and albums."
version = 7
version = 8
author_name = "Gallery Team"
author_url = "http://codex.galleryproject.org/Gallery:Team"
info_url = "http://codex.galleryproject.org/Gallery3:Modules:comment"
Expand Down
5 changes: 4 additions & 1 deletion modules/comment/views/comment.html.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<li id="g-comment-<?= $comment->id; ?>">
<li id="g-comment-<?= $comment->id; ?>" class="g-comment-state-<?= $comment->state ?>">
<p class="g-author">
<a href="#">
<img src="<?= $comment->author()->avatar_url(40, $theme->url("images/avatar.jpg", true)) ?>"
Expand All @@ -22,4 +22,7 @@ class="g-avatar"
<div>
<?= nl2br(html::purify($comment->text)) ?>
</div>
<? if ($comment->state == "unpublished"): ?>
<b> <?= t("Your comment is held for moderation. The site moderator will review and publish it.") ?> </b>
<? endif ?>
</li>
5 changes: 4 additions & 1 deletion modules/comment/views/comments.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class="g-button ui-corner-all ui-icon-left ui-state-default">
<? if ($comments->count()): ?>
<ul>
<? foreach ($comments as $comment): ?>
<li id="g-comment-<?= $comment->id ?>">
<li id="g-comment-<?= $comment->id ?>" class="g-comment-state-<?= $comment->state ?>">
<p class="g-author">
<a href="#">
<img src="<?= $comment->author()->avatar_url(40, $theme->url("images/avatar.jpg", true)) ?>"
Expand All @@ -48,6 +48,9 @@ class="g-avatar"
<div>
<?= nl2br(html::purify($comment->text)) ?>
</div>
<? if ($comment->state == "unpublished"): ?>
<b> <?= t("Your comment is held for moderation. The site moderator will review and publish it.") ?> </b>
<? endif ?>
</li>
<? endforeach ?>
</ul>
Expand Down

1 comment on commit 9e0631a

@Urgulum
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a realy great change, wich helps me and hopfully others a lot.
It also shows me how some things that i didn't understand in the documentation works.
Thank You really much.

Please sign in to comment.