Merge branch '0.4' into 0.5

This commit is contained in:
Daniel Hensby 2018-02-20 13:20:46 +00:00
commit ded09bda7d
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 63 additions and 40 deletions

View File

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

View File

@ -13,6 +13,13 @@ class BlogTree extends Page {
// Default number of blog entries to show
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(
'Name' => 'Varchar',
'InheritSideBar' => 'Boolean',
@ -41,7 +48,7 @@ class BlogTree extends Page {
* uses current
*/
static function current($page = null) {
if (!$page) {
$controller = Controller::curr();
if($controller) $page = $controller->data();
@ -152,7 +159,6 @@ class BlogTree extends Page {
* @return DataObjectSet
*/
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') {
$tagCheck = '';
$dateCheck = '';
@ -165,12 +171,12 @@ class BlogTree extends Page {
// Some systems still use the / seperator for date presentation
if( strpos($date, '-') ) $seperator = '-';
elseif( strpos($date, '/') ) $seperator = '/';
if(isset($seperator) && !empty($seperator)) {
// The 2 in the explode argument will tell it to only create 2 elements
// i.e. in this instance the $year and $month fields respectively
list($year,$month) = explode( $seperator, $date, 2);
$year = (int)$year;
$month = (int)$month;
@ -193,7 +199,6 @@ class BlogTree extends Page {
}
}
}
// Build a list of all IDs for BlogHolders that are children of us
$holderIDs = $this->BlogHolderIDs();
@ -214,7 +219,7 @@ class BlogTree extends Page {
}
class BlogTree_Controller extends Page_Controller {
static $allowed_actions = array(
'index',
'rss',
@ -225,14 +230,16 @@ class BlogTree_Controller extends Page_Controller {
function init() {
parent::init();
$this->IncludeBlogRSS();
if(BlogTree::$include_rss_link) {
$this->IncludeBlogRSS();
}
Requirements::themedCSS("blog");
}
function BlogEntries($limit = null) {
require_once('Zend/Date.php');
if($limit === null) $limit = BlogTree::$default_entries_limit;
// only use freshness if no action is present (might be displaying tags or rss)
@ -240,7 +247,7 @@ class BlogTree_Controller extends Page_Controller {
$d = new Zend_Date(SS_Datetime::now()->getValue());
$d->sub(intval($this->LandingPageFreshness), Zend_Date::MONTH);
$date = $d->toString('YYYY-MM-dd');
$filter = "\"BlogEntry\".\"Date\" > '$date'";
} else {
$filter = '';
@ -250,7 +257,7 @@ class BlogTree_Controller extends Page_Controller {
if(isset($_GET['author']) && isset($_GET['authorID'])) {
$author = Convert::raw2sql($_GET['author']);
$id = Convert::raw2sql($_GET['authorID']);
$filter .= " \"BlogEntry\".\"Author\" LIKE '". $author . "' OR \"BlogEntry\".\"AuthorID\" = '". $id ."'";
}
else if(isset($_GET['author'])) {
@ -261,9 +268,9 @@ class BlogTree_Controller extends Page_Controller {
}
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
$date = $this->SelectedDate();
return $this->Entries("$start,$limit", $this->SelectedTag(), ($date) ? $date : '', null, $filter);
}
@ -273,7 +280,7 @@ class BlogTree_Controller extends Page_Controller {
function IncludeBlogRSS() {
RSSFeed::linkToFeed($this->Link('rss'), _t('BlogHolder.RSSFEED',"RSS feed of these blogs"));
}
/**
* Get the rss feed for this blog holder's entries
*/
@ -290,7 +297,7 @@ class BlogTree_Controller extends Page_Controller {
$rss->outputToBrowser();
}
}
/**
* Protection against infinite loops when an RSS widget pointing to this page is added to this page
*/
@ -299,16 +306,16 @@ class BlogTree_Controller extends Page_Controller {
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
*/
function SelectedTag() {
return ($this->request->latestParam('Action') == 'tag') ? Convert::raw2xml($this->request->latestParam('ID')) : '';
}
/**
* Return the selected date from the blog tree
*
@ -318,28 +325,28 @@ class BlogTree_Controller extends Page_Controller {
if($this->request->latestParam('Action') == 'date') {
$year = $this->request->latestParam('ID');
$month = $this->request->latestParam('OtherID');
if(is_numeric($year) && is_numeric($month) && $month < 13) {
$date = $year .'-'. $month;
return $date;
} else {
if(is_numeric($year)) return $year;
if(is_numeric($year)) return $year;
}
}
return false;
}
function SelectedNiceDate(){
$date = $this->SelectedDate();
if(strpos($date, '-')) {
$date = explode("-",$date);
return date("F", mktime(0, 0, 0, $date[1], 1, date('Y'))). " " .date("Y", mktime(0, 0, 0, date('m'), 1, $date[0]));
} else {
return date("Y", mktime(0, 0, 0, date('m'), 1, $date));
}

View File

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

View File

@ -6,9 +6,12 @@
class BlogHolderFunctionalTest extends FunctionalTest {
static $fixture_file = 'blog/tests/BlogHolderFunctionalTest.yml';
static $origlThemes;
function setUp() {
parent::setUp();
self::$origlThemes = SSViewer::current_theme();
SSViewer::set_theme(null);
$blogHolder = $this->objFromFixture('BlogHolder', 'blogholder');
$blogHolder->publish('Stage', 'Live');
@ -16,6 +19,11 @@ class BlogHolderFunctionalTest extends FunctionalTest {
$blogEntry->publish('Stage', 'Live');
}
function tearDown(){
SSViewer::set_theme(self::$origlThemes);
parent::tearDown();
}
function testFrontendBlogPostRequiresPermission() {
// get valid SecurityID (from comments form, would usually be copy/pasted)
$blogEntry = $this->objFromFixture('BlogEntry', 'entry1');