2009-01-07 09:08:53 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2011-01-21 23:01:06 -08:00
|
|
|
* Copyright (C) 2000-2011 Bharat Mediratta
|
2009-01-07 09:08:53 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
2010-05-16 22:53:19 -07:00
|
|
|
class Admin_Manage_Comments_Controller extends Admin_Controller {
|
2009-05-11 20:15:24 +00:00
|
|
|
private static $items_per_page = 20;
|
|
|
|
|
|
|
|
|
|
public function index() {
|
|
|
|
|
// Get rid of old deleted/spam comments once in a while
|
2009-11-26 12:54:07 -08:00
|
|
|
db::build()
|
|
|
|
|
->delete("comments")
|
|
|
|
|
->where("state", "IN", array("deleted", "spam"))
|
2010-12-28 23:10:05 -08:00
|
|
|
->where("updated", "<", db::expr("UNIX_TIMESTAMP() - 86400 * 7"))
|
2009-11-26 12:54:07 -08:00
|
|
|
->execute();
|
2009-05-11 20:15:24 +00:00
|
|
|
|
|
|
|
|
// Redirect to the appropriate queue
|
2010-05-16 22:53:19 -07:00
|
|
|
url::redirect("admin/manage_comments/queue/unpublished");
|
2009-05-11 20:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function menu_labels() {
|
|
|
|
|
$menu = $this->_menu($this->_counts());
|
2010-07-21 21:30:13 -07:00
|
|
|
json::reply(array((string) $menu->get("unpublished")->label,
|
2010-08-08 15:05:55 -07:00
|
|
|
(string) $menu->get("published")->label,
|
|
|
|
|
(string) $menu->get("spam")->label,
|
|
|
|
|
(string) $menu->get("deleted")->label));
|
2009-05-11 20:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function queue($state) {
|
|
|
|
|
$page = max(Input::instance()->get("page"), 1);
|
2009-01-07 09:08:53 +00:00
|
|
|
|
|
|
|
|
$view = new Admin_View("admin.html");
|
2010-04-30 00:08:37 -06:00
|
|
|
$view->page_title = t("Manage comments");
|
2011-04-26 09:48:21 -07:00
|
|
|
$view->page_type = "collection";
|
|
|
|
|
$view->page_subtype = "admin_comments";
|
2010-05-16 23:01:57 -07:00
|
|
|
$view->content = new View("admin_manage_comments.html");
|
2009-05-11 20:15:24 +00:00
|
|
|
$view->content->counts = $this->_counts();
|
|
|
|
|
$view->content->menu = $this->_menu($view->content->counts);
|
|
|
|
|
$view->content->state = $state;
|
|
|
|
|
$view->content->comments = ORM::factory("comment")
|
2009-11-25 19:26:52 -08:00
|
|
|
->order_by("created", "DESC")
|
2010-08-09 00:29:28 -07:00
|
|
|
->order_by("id", "DESC")
|
2009-11-26 12:09:04 -08:00
|
|
|
->where("state", "=", $state)
|
2010-08-09 00:29:28 -07:00
|
|
|
->limit(self::$items_per_page)
|
|
|
|
|
->offset(($page - 1) * self::$items_per_page)
|
2009-05-11 20:15:24 +00:00
|
|
|
->find_all();
|
|
|
|
|
|
2011-04-26 09:48:21 -07:00
|
|
|
// Pagination info
|
|
|
|
|
$view->page = $page;
|
|
|
|
|
$view->page_size = self::$items_per_page;
|
|
|
|
|
$view->children_count = $this->_counts()->$state;
|
|
|
|
|
$view->max_pages = ceil($view->children_count / $view->page_size);
|
2009-05-11 20:15:24 +00:00
|
|
|
print $view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function _menu($counts) {
|
|
|
|
|
return Menu::factory("root")
|
2009-01-07 09:08:53 +00:00
|
|
|
->append(Menu::factory("link")
|
|
|
|
|
->id("unpublished")
|
2009-01-15 10:02:41 +00:00
|
|
|
->label(t2("Awaiting Moderation (%count)",
|
|
|
|
|
"Awaiting Moderation (%count)",
|
2009-05-11 20:15:24 +00:00
|
|
|
$counts->unpublished))
|
2010-05-16 22:53:19 -07:00
|
|
|
->url(url::site("admin/manage_comments/queue/unpublished")))
|
2009-01-08 02:50:23 +00:00
|
|
|
->append(Menu::factory("link")
|
|
|
|
|
->id("published")
|
2009-01-15 10:02:41 +00:00
|
|
|
->label(t2("Approved (%count)",
|
|
|
|
|
"Approved (%count)",
|
2009-05-11 20:15:24 +00:00
|
|
|
$counts->published))
|
2010-05-16 22:53:19 -07:00
|
|
|
->url(url::site("admin/manage_comments/queue/published")))
|
2009-01-07 09:08:53 +00:00
|
|
|
->append(Menu::factory("link")
|
|
|
|
|
->id("spam")
|
2009-01-15 10:02:41 +00:00
|
|
|
->label(t2("Spam (%count)",
|
|
|
|
|
"Spam (%count)",
|
2009-05-11 20:15:24 +00:00
|
|
|
$counts->spam))
|
2010-05-16 22:53:19 -07:00
|
|
|
->url(url::site("admin/manage_comments/queue/spam")))
|
2009-01-10 11:11:24 +00:00
|
|
|
->append(Menu::factory("link")
|
|
|
|
|
->id("deleted")
|
2009-01-15 10:02:41 +00:00
|
|
|
->label(t2("Recently Deleted (%count)",
|
|
|
|
|
"Recently Deleted (%count)",
|
2009-05-11 20:15:24 +00:00
|
|
|
$counts->deleted))
|
2010-05-16 22:53:19 -07:00
|
|
|
->url(url::site("admin/manage_comments/queue/deleted")));
|
2009-01-07 09:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-11 20:15:24 +00:00
|
|
|
private function _counts() {
|
2010-01-31 16:07:41 -08:00
|
|
|
$counts = new stdClass();
|
2009-05-11 20:15:24 +00:00
|
|
|
$counts->unpublished = 0;
|
|
|
|
|
$counts->published = 0;
|
|
|
|
|
$counts->spam = 0;
|
|
|
|
|
$counts->deleted = 0;
|
2009-11-26 13:18:10 -08:00
|
|
|
foreach (db::build()
|
|
|
|
|
->select("state")
|
|
|
|
|
->select(array("c" => 'COUNT("*")'))
|
2009-05-11 20:15:24 +00:00
|
|
|
->from("comments")
|
2009-11-26 13:18:10 -08:00
|
|
|
->group_by("state")
|
|
|
|
|
->execute() as $row) {
|
2009-05-11 20:15:24 +00:00
|
|
|
$counts->{$row->state} = $row->c;
|
2009-01-08 02:50:23 +00:00
|
|
|
}
|
2009-05-11 20:15:24 +00:00
|
|
|
return $counts;
|
2009-01-07 09:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-08 02:50:23 +00:00
|
|
|
public function set_state($id, $state) {
|
|
|
|
|
access::verify_csrf();
|
2009-06-01 22:40:22 -07:00
|
|
|
|
2009-01-08 02:50:23 +00:00
|
|
|
$comment = ORM::factory("comment", $id);
|
|
|
|
|
$orig = clone $comment;
|
2009-11-25 13:22:24 -08:00
|
|
|
if ($comment->loaded()) {
|
2009-01-08 02:50:23 +00:00
|
|
|
$comment->state = $state;
|
|
|
|
|
$comment->save();
|
|
|
|
|
}
|
2009-01-07 09:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-08 02:50:23 +00:00
|
|
|
public function delete_all_spam() {
|
|
|
|
|
access::verify_csrf();
|
2009-06-01 22:40:22 -07:00
|
|
|
|
2010-01-09 23:57:16 -08:00
|
|
|
db::build()
|
|
|
|
|
->delete("comments")
|
2009-11-26 12:09:04 -08:00
|
|
|
->where("state", "=", "spam")
|
2010-01-09 23:57:16 -08:00
|
|
|
->execute();
|
2010-05-16 22:53:19 -07:00
|
|
|
url::redirect("admin/manage_comments/queue/spam");
|
2009-01-07 09:08:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|