Merge branch '0.3' into 0.4

This commit is contained in:
Daniel Hensby 2018-02-20 13:17:23 +00:00
commit dfaa974697
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
3 changed files with 46 additions and 36 deletions

View File

@ -28,7 +28,7 @@ class BlogHolder extends BlogTree implements PermissionProvider {
); );
function getCMSFields() { function getCMSFields() {
$blogOwners = $this->blogOwners(); $blogOwners = $this->blogOwners();
SiteTree::disableCMSFieldsExtensions(); SiteTree::disableCMSFieldsExtensions();
$fields = parent::getCMSFields(); $fields = parent::getCMSFields();
@ -42,22 +42,22 @@ class BlogHolder extends BlogTree implements PermissionProvider {
return $fields; return $fields;
} }
/** /**
* Get members who have BLOGMANAGEMENT and ADMIN permission * Get members who have BLOGMANAGEMENT and ADMIN permission
*/ */
function blogOwners($sort = 'Name', $direction = "ASC") { function blogOwners($sort = 'Name', $direction = "ASC") {
$adminMembers = Permission::get_members_by_permission('ADMIN'); $adminMembers = Permission::get_members_by_permission('ADMIN');
$blogOwners = Permission::get_members_by_permission('BLOGMANAGEMENT'); $blogOwners = Permission::get_members_by_permission('BLOGMANAGEMENT');
if(!$adminMembers) $adminMembers = new DataObjectSet(); if(!$adminMembers) $adminMembers = new DataObjectSet();
if(!$blogOwners) $blogOwners = new DataObjectSet(); if(!$blogOwners) $blogOwners = new DataObjectSet();
$blogOwners->merge($adminMembers); $blogOwners->merge($adminMembers);
$blogOwners->sort($sort, $direction); $blogOwners->sort($sort, $direction);
$this->extend('extendBlogOwners', $blogOwners); $this->extend('extendBlogOwners', $blogOwners);
return $blogOwners; return $blogOwners;
} }
@ -152,6 +152,7 @@ class BlogHolder extends BlogTree implements PermissionProvider {
} }
class BlogHolder_Controller extends BlogTree_Controller { class BlogHolder_Controller extends BlogTree_Controller {
static $allowed_actions = array( static $allowed_actions = array(
'index', 'index',
'tag', 'tag',
@ -161,7 +162,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
'post' => 'BLOGMANAGEMENT', 'post' => 'BLOGMANAGEMENT',
'BlogEntryForm' => 'BLOGMANAGEMENT', 'BlogEntryForm' => 'BLOGMANAGEMENT',
); );
function init() { function init() {
parent::init(); parent::init();
Requirements::themedCSS("bbcodehelp"); Requirements::themedCSS("bbcodehelp");
@ -194,9 +195,9 @@ class BlogHolder_Controller extends BlogTree_Controller {
/** /**
* A simple form for creating blog entries * A simple form for creating blog entries
*/ */
function BlogEntryForm() { function BlogEntryForm() {
if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure(); if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();
$id = 0; $id = 0;
if($this->request->latestParam('ID')) { if($this->request->latestParam('ID')) {
@ -221,7 +222,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
} else { } else {
$tagfield = new TextField('Tags'); $tagfield = new TextField('Tags');
} }
$field = 'TextField'; $field = 'TextField';
if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) { if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
$field = 'ReadonlyField'; $field = 'ReadonlyField';
@ -235,7 +236,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
new LiteralField("Tagsnote"," <label id='tagsnote'>"._t('BlogHolder.TE', "For example: sport, personal, science fiction")."<br/>" . new LiteralField("Tagsnote"," <label id='tagsnote'>"._t('BlogHolder.TE', "For example: sport, personal, science fiction")."<br/>" .
_t('BlogHolder.SPUC', "Please separate tags using commas.")."</label>") _t('BlogHolder.SPUC', "Please separate tags using commas.")."</label>")
); );
$submitAction = new FormAction('postblog', _t('BlogHolder.POST', 'Post blog entry')); $submitAction = new FormAction('postblog', _t('BlogHolder.POST', 'Post blog entry'));
$actions = new FieldSet($submitAction); $actions = new FieldSet($submitAction);
$validator = new RequiredFields('Title','BlogPost'); $validator = new RequiredFields('Title','BlogPost');
@ -273,12 +274,12 @@ class BlogHolder_Controller extends BlogTree_Controller {
} }
$form->saveInto($blogentry); $form->saveInto($blogentry);
$blogentry->ParentID = $this->ID; $blogentry->ParentID = $this->ID;
$blogentry->Content = $form->datafieldByName('BlogPost')->dataValue(); $blogentry->Content = $form->datafieldByName('BlogPost')->dataValue();
if(Object::hasExtension('Translatable')) { if(Object::hasExtension('Translatable')) {
$blogentry->Locale = $this->Locale; $blogentry->Locale = $this->Locale;
} }
$blogentry->Status = "Published"; $blogentry->Status = "Published";

View File

@ -13,6 +13,13 @@ class BlogTree extends Page {
// Default number of blog entries to show // Default number of blog entries to show
static $default_entries_limit = 10; static $default_entries_limit = 10;
/**
* @var bool Include an automatic link to the rss feed for
* the browser. Disabling this will allow you to include your
* own feedburner link
*/
static $include_rss_link = true;
static $db = array( static $db = array(
'Name' => 'Varchar', 'Name' => 'Varchar',
'InheritSideBar' => 'Boolean', 'InheritSideBar' => 'Boolean',
@ -41,7 +48,7 @@ class BlogTree extends Page {
* uses current * uses current
*/ */
static function current($page = null) { static function current($page = null) {
if (!$page) { if (!$page) {
$controller = Controller::curr(); $controller = Controller::curr();
if($controller) $page = $controller->data(); if($controller) $page = $controller->data();
@ -152,7 +159,6 @@ class BlogTree extends Page {
* @return DataObjectSet * @return DataObjectSet
*/ */
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') { public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') {
$tagCheck = ''; $tagCheck = '';
$dateCheck = ''; $dateCheck = '';
@ -185,7 +191,6 @@ class BlogTree extends Page {
} }
} }
} }
// Build a list of all IDs for BlogHolders that are children of us // Build a list of all IDs for BlogHolders that are children of us
$holderIDs = $this->BlogHolderIDs(); $holderIDs = $this->BlogHolderIDs();
@ -206,7 +211,7 @@ class BlogTree extends Page {
} }
class BlogTree_Controller extends Page_Controller { class BlogTree_Controller extends Page_Controller {
static $allowed_actions = array( static $allowed_actions = array(
'index', 'index',
'rss', 'rss',
@ -216,14 +221,16 @@ class BlogTree_Controller extends Page_Controller {
function init() { function init() {
parent::init(); parent::init();
$this->IncludeBlogRSS(); if(BlogTree::$include_rss_link) {
$this->IncludeBlogRSS();
}
Requirements::themedCSS("blog"); Requirements::themedCSS("blog");
} }
function BlogEntries($limit = null) { function BlogEntries($limit = null) {
require_once('Zend/Date.php'); require_once('Zend/Date.php');
if($limit === null) $limit = BlogTree::$default_entries_limit; if($limit === null) $limit = BlogTree::$default_entries_limit;
// only use freshness if no action is present (might be displaying tags or rss) // only use freshness if no action is present (might be displaying tags or rss)
@ -231,7 +238,7 @@ class BlogTree_Controller extends Page_Controller {
$d = new Zend_Date(SS_Datetime::now()->getValue()); $d = new Zend_Date(SS_Datetime::now()->getValue());
$d->sub($this->LandingPageFreshness); $d->sub($this->LandingPageFreshness);
$date = $d->toString('YYYY-MM-dd'); $date = $d->toString('YYYY-MM-dd');
$filter = "\"BlogEntry\".\"Date\" > '$date'"; $filter = "\"BlogEntry\".\"Date\" > '$date'";
} else { } else {
$filter = ''; $filter = '';
@ -241,7 +248,7 @@ class BlogTree_Controller extends Page_Controller {
if(isset($_GET['author']) && isset($_GET['authorID'])) { if(isset($_GET['author']) && isset($_GET['authorID'])) {
$author = Convert::raw2sql($_GET['author']); $author = Convert::raw2sql($_GET['author']);
$id = Convert::raw2sql($_GET['authorID']); $id = Convert::raw2sql($_GET['authorID']);
$filter .= " \"BlogEntry\".\"Author\" LIKE '". $author . "' OR \"BlogEntry\".\"AuthorID\" = '". $id ."'"; $filter .= " \"BlogEntry\".\"Author\" LIKE '". $author . "' OR \"BlogEntry\".\"AuthorID\" = '". $id ."'";
} }
else if(isset($_GET['author'])) { else if(isset($_GET['author'])) {
@ -252,9 +259,9 @@ class BlogTree_Controller extends Page_Controller {
} }
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0; $start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
$date = $this->SelectedDate(); $date = $this->SelectedDate();
return $this->Entries("$start,$limit", $this->SelectedTag(), ($date) ? $date->Format('Y-m') : '', null, $filter); return $this->Entries("$start,$limit", $this->SelectedTag(), ($date) ? $date->Format('Y-m') : '', null, $filter);
} }
@ -264,7 +271,7 @@ class BlogTree_Controller extends Page_Controller {
function IncludeBlogRSS() { function IncludeBlogRSS() {
RSSFeed::linkToFeed($this->Link() . "rss", _t('BlogHolder.RSSFEED',"RSS feed of these blogs")); RSSFeed::linkToFeed($this->Link() . "rss", _t('BlogHolder.RSSFEED',"RSS feed of these blogs"));
} }
/** /**
* Get the rss feed for this blog holder's entries * Get the rss feed for this blog holder's entries
*/ */
@ -281,7 +288,7 @@ class BlogTree_Controller extends Page_Controller {
$rss->outputToBrowser(); $rss->outputToBrowser();
} }
} }
/** /**
* Protection against infinite loops when an RSS widget pointing to this page is added to this page * Protection against infinite loops when an RSS widget pointing to this page is added to this page
*/ */
@ -290,16 +297,16 @@ class BlogTree_Controller extends Page_Controller {
return parent::defaultAction($action); return parent::defaultAction($action);
} }
/** /**
* Return the currently viewing tag used in the template as $Tag * Return the currently viewing tag used in the template as $Tag
* *
* @return String * @return String
*/ */
function SelectedTag() { function SelectedTag() {
return ($this->request->latestParam('Action') == 'tag') ? Convert::raw2xml($this->request->latestParam('ID')) : ''; return ($this->request->latestParam('Action') == 'tag') ? Convert::raw2xml($this->request->latestParam('ID')) : '';
} }
/** /**
* Return the selected date from the blog tree * Return the selected date from the blog tree
* *
@ -309,15 +316,15 @@ class BlogTree_Controller extends Page_Controller {
if($this->request->latestParam('Action') == 'date') { if($this->request->latestParam('Action') == 'date') {
$year = $this->request->latestParam('ID'); $year = $this->request->latestParam('ID');
$month = $this->request->latestParam('OtherID'); $month = $this->request->latestParam('OtherID');
if(is_numeric($year) && is_numeric($month) && $month < 13) { if(is_numeric($year) && is_numeric($month) && $month < 13) {
$date = new Date(); $date = new Date();
$date->setValue($year .'-'. $month); $date->setValue($year .'-'. $month);
return $date; return $date;
} }
} }
return false; return false;
} }
} }

View File

@ -52,6 +52,8 @@ class ArchiveWidget extends Widget {
$container = BlogTree::current(); $container = BlogTree::current();
$ids = $container->BlogHolderIDs(); $ids = $container->BlogHolderIDs();
if(empty($ids)) return $results;
$stage = Versioned::current_stage(); $stage = Versioned::current_stage();
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage"; $suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";