2007-09-07 00:33:58 +02:00
|
|
|
<?php
|
2009-01-20 05:01:45 +01:00
|
|
|
/**
|
|
|
|
* Blog Management Widget
|
|
|
|
* @package blog
|
|
|
|
*/
|
2009-05-21 06:07:53 +02:00
|
|
|
class BlogManagementWidget extends Widget implements PermissionProvider {
|
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
static $db = array();
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $has_one = array();
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $has_many = array();
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $many_many = array();
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $belongs_many_many = array();
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $defaults = array();
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
static $title = "Blog Management";
|
|
|
|
static $cmsTitle = "Blog Management";
|
|
|
|
static $description = "Provide a number of links useful for administering a blog. Only shown if the user is an admin.";
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
function CommentText() {
|
|
|
|
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM PageComment WHERE NeedsModeration=1")->value();
|
|
|
|
if($unmoderatedcount == 1) {
|
2007-12-18 02:41:51 +01:00
|
|
|
return _t("BlogManagementWidget.UNM1", "You have 1 unmoderated comment");
|
2007-09-07 00:33:58 +02:00
|
|
|
} else if($unmoderatedcount > 1) {
|
2007-12-18 02:41:51 +01:00
|
|
|
return sprintf(_t("BlogManagementWidget.UNMM", "You have %i unmoderated comments"), $unmoderatedcount);
|
2007-09-07 00:33:58 +02:00
|
|
|
} else {
|
2007-12-18 02:41:51 +01:00
|
|
|
return _t("BlogManagementWidget.COMADM", "Comment administration");
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
}
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
function CommentLink() {
|
2009-02-07 03:19:27 +01:00
|
|
|
if(!Permission::check('ADMIN')) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM PageComment WHERE NeedsModeration=1")->value();
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
if($unmoderatedcount > 0) {
|
|
|
|
return "admin/comments/unmoderated";
|
|
|
|
} else {
|
|
|
|
return "admin/comments";
|
|
|
|
}
|
|
|
|
}
|
2009-05-21 06:07:53 +02:00
|
|
|
|
|
|
|
function providePermissions() {
|
|
|
|
return array("BLOGMANAGEMENTWIDGET_VIEW" => "View blog management widget");
|
|
|
|
}
|
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
function WidgetHolder() {
|
2009-05-21 06:07:53 +02:00
|
|
|
if(Permission::check("BLOGMANAGEMENTWIDGET_VIEW")) {
|
|
|
|
return $this->renderWith("WidgetHolder");
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
2009-05-21 06:07:53 +02:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
function PostLink() {
|
2009-05-01 00:05:54 +02:00
|
|
|
$container = BlogTree::current();
|
|
|
|
if ($container) return $container->Link('post');
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
2009-05-21 06:07:53 +02:00
|
|
|
|
|
|
|
function getBlogHolder() {
|
|
|
|
$page = Director::currentPage();
|
|
|
|
|
|
|
|
if($page->is_a("BlogHolder")) {
|
|
|
|
return $page;
|
|
|
|
} else if($page->is_a("BlogEntry") && $page->getParent()->is_a("BlogHolder")) {
|
|
|
|
return $page->getParent();
|
|
|
|
} else {
|
|
|
|
return DataObject::get_one("BlogHolder");
|
|
|
|
}
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 01:52:14 +02:00
|
|
|
?>
|