mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge branch '0.4' into 0.5
This commit is contained in:
commit
ded09bda7d
@ -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,6 +274,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$form->saveInto($blogentry);
|
$form->saveInto($blogentry);
|
||||||
|
|
||||||
$blogentry->ParentID = $this->ID;
|
$blogentry->ParentID = $this->ID;
|
||||||
$blogentry->Content = str_replace("\r\n", "\n", $form->datafieldByName('BlogPost')->dataValue());
|
$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;
|
$blogentry->Locale = $this->Locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Object::hasExtension('Translatable')) {
|
||||||
|
$blogentry->Locale = $this->Locale;
|
||||||
|
}
|
||||||
|
|
||||||
$blogentry->Status = "Published";
|
$blogentry->Status = "Published";
|
||||||
$blogentry->writeToStage("Stage");
|
$blogentry->writeToStage("Stage");
|
||||||
$blogentry->publish("Stage", "Live");
|
$blogentry->publish("Stage", "Live");
|
||||||
|
@ -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 = '';
|
||||||
|
|
||||||
@ -165,12 +171,12 @@ class BlogTree extends Page {
|
|||||||
// Some systems still use the / seperator for date presentation
|
// Some systems still use the / seperator for date presentation
|
||||||
if( strpos($date, '-') ) $seperator = '-';
|
if( strpos($date, '-') ) $seperator = '-';
|
||||||
elseif( strpos($date, '/') ) $seperator = '/';
|
elseif( strpos($date, '/') ) $seperator = '/';
|
||||||
|
|
||||||
if(isset($seperator) && !empty($seperator)) {
|
if(isset($seperator) && !empty($seperator)) {
|
||||||
// The 2 in the explode argument will tell it to only create 2 elements
|
// 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
|
// i.e. in this instance the $year and $month fields respectively
|
||||||
list($year,$month) = explode( $seperator, $date, 2);
|
list($year,$month) = explode( $seperator, $date, 2);
|
||||||
|
|
||||||
$year = (int)$year;
|
$year = (int)$year;
|
||||||
$month = (int)$month;
|
$month = (int)$month;
|
||||||
|
|
||||||
@ -193,7 +199,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();
|
||||||
|
|
||||||
@ -214,7 +219,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',
|
||||||
@ -225,14 +230,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)
|
||||||
@ -240,7 +247,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(intval($this->LandingPageFreshness), Zend_Date::MONTH);
|
$d->sub(intval($this->LandingPageFreshness), Zend_Date::MONTH);
|
||||||
$date = $d->toString('YYYY-MM-dd');
|
$date = $d->toString('YYYY-MM-dd');
|
||||||
|
|
||||||
$filter = "\"BlogEntry\".\"Date\" > '$date'";
|
$filter = "\"BlogEntry\".\"Date\" > '$date'";
|
||||||
} else {
|
} else {
|
||||||
$filter = '';
|
$filter = '';
|
||||||
@ -250,7 +257,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'])) {
|
||||||
@ -261,9 +268,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 : '', null, $filter);
|
return $this->Entries("$start,$limit", $this->SelectedTag(), ($date) ? $date : '', null, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +280,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
|
||||||
*/
|
*/
|
||||||
@ -290,7 +297,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
|
||||||
*/
|
*/
|
||||||
@ -299,16 +306,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
|
||||||
*
|
*
|
||||||
@ -318,28 +325,28 @@ 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 = $year .'-'. $month;
|
$date = $year .'-'. $month;
|
||||||
return $date;
|
return $date;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(is_numeric($year)) return $year;
|
if(is_numeric($year)) return $year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectedNiceDate(){
|
function SelectedNiceDate(){
|
||||||
$date = $this->SelectedDate();
|
$date = $this->SelectedDate();
|
||||||
|
|
||||||
if(strpos($date, '-')) {
|
if(strpos($date, '-')) {
|
||||||
$date = explode("-",$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]));
|
return date("F", mktime(0, 0, 0, $date[1], 1, date('Y'))). " " .date("Y", mktime(0, 0, 0, date('m'), 1, $date[0]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return date("Y", mktime(0, 0, 0, date('m'), 1, $date));
|
return date("Y", mktime(0, 0, 0, date('m'), 1, $date));
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,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";
|
||||||
|
|
||||||
|
@ -6,9 +6,12 @@
|
|||||||
class BlogHolderFunctionalTest extends FunctionalTest {
|
class BlogHolderFunctionalTest extends FunctionalTest {
|
||||||
|
|
||||||
static $fixture_file = 'blog/tests/BlogHolderFunctionalTest.yml';
|
static $fixture_file = 'blog/tests/BlogHolderFunctionalTest.yml';
|
||||||
|
static $origlThemes;
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
self::$origlThemes = SSViewer::current_theme();
|
||||||
|
SSViewer::set_theme(null);
|
||||||
|
|
||||||
$blogHolder = $this->objFromFixture('BlogHolder', 'blogholder');
|
$blogHolder = $this->objFromFixture('BlogHolder', 'blogholder');
|
||||||
$blogHolder->publish('Stage', 'Live');
|
$blogHolder->publish('Stage', 'Live');
|
||||||
@ -16,6 +19,11 @@ class BlogHolderFunctionalTest extends FunctionalTest {
|
|||||||
$blogEntry->publish('Stage', 'Live');
|
$blogEntry->publish('Stage', 'Live');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tearDown(){
|
||||||
|
SSViewer::set_theme(self::$origlThemes);
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
function testFrontendBlogPostRequiresPermission() {
|
function testFrontendBlogPostRequiresPermission() {
|
||||||
// get valid SecurityID (from comments form, would usually be copy/pasted)
|
// get valid SecurityID (from comments form, would usually be copy/pasted)
|
||||||
$blogEntry = $this->objFromFixture('BlogEntry', 'entry1');
|
$blogEntry = $this->objFromFixture('BlogEntry', 'entry1');
|
||||||
|
Loading…
Reference in New Issue
Block a user