silverstripe-blog/code/widgets/BlogManagementWidget.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2012-05-21 04:58:26 +02:00
<?php
2013-04-11 12:35:22 +02:00
if(class_exists('Widget')) {
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +02:00
/**
* Blog Management Widget
* @package blog
*/
class BlogManagementWidget extends Widget {
static $db = array();
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +02:00
static $has_one = array();
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +02:00
static $has_many = array();
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +02:00
static $many_many = array();
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +02:00
static $belongs_many_many = array();
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +02:00
static $defaults = array();
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +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.";
2012-05-21 05:58:40 +02:00
2013-04-11 12:35:22 +02:00
function CommentText() {
if(!class_exists('Comment')) return false;
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\"=1")->value();
if($unmoderatedcount == 1) {
return _t("BlogManagementWidget.UNM1", "You have 1 unmoderated comment");
} else if($unmoderatedcount > 1) {
return sprintf(_t("BlogManagementWidget.UNMM", "You have %i unmoderated comments"), $unmoderatedcount);
} else {
return _t("BlogManagementWidget.COMADM", "Comment administration");
}
2012-05-21 04:58:26 +02:00
}
2013-04-11 12:35:22 +02:00
function CommentLink() {
2012-05-21 05:58:40 +02:00
2013-04-11 12:35:22 +02:00
if(!Permission::check('BLOGMANAGEMENT') || !class_exists('Comment')) return false;
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\"=1")->value();
2012-05-21 04:58:26 +02:00
2013-04-11 12:35:22 +02:00
if($unmoderatedcount > 0) {
return "admin/comments/unmoderated";
} else {
return "admin/comments";
}
2012-05-21 04:58:26 +02:00
}
}
2013-04-11 12:35:22 +02:00
class BlogManagementWidget_Controller extends Widget_Controller {
function WidgetHolder() {
if(Permission::check("BLOGMANAGEMENT")) {
return $this->renderWith("WidgetHolder");
}
}
function PostLink() {
$container = BlogTree::current();
return ($container && $container->ClassName != "BlogTree") ? $container->Link('post') : false;
}
2012-05-21 04:58:26 +02:00
}
2013-04-11 12:35:22 +02:00
}