Merge branch '0.5' into 0.6

This commit is contained in:
Daniel Hensby 2018-02-20 13:24:43 +00:00
commit e2cf6421c6
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 134 additions and 119 deletions

View File

@ -15,15 +15,15 @@ class BlogHolder extends BlogTree implements PermissionProvider {
static $icon = "blog/images/blogholder-file.png";
static $description = "Displays listings of blog entries";
static $singular_name = 'Blog Holder Page';
static $plural_name = 'Blog Holder Pages';
static $db = array(
'TrackBacksEnabled' => 'Boolean',
'AllowCustomAuthors' => 'Boolean',
'ShowFullEntry' => 'Boolean',
'ShowFullEntry' => 'Boolean',
);
static $has_one = array(
@ -35,14 +35,14 @@ class BlogHolder extends BlogTree implements PermissionProvider {
);
function getCMSFields() {
$blogOwners = $this->blogOwners();
$blogOwners = $this->blogOwners();
SiteTree::disableCMSFieldsExtensions();
$fields = parent::getCMSFields();
SiteTree::enableCMSFieldsExtensions();
$fields->addFieldToTab(
'Root.Main',
'Root.Main',
DropdownField::create('OwnerID', 'Blog owner', $blogOwners->map('ID', 'Name')->toArray())
->setEmptyString('(None)')
->setHasEmptyDefault(true),
@ -51,9 +51,9 @@ class BlogHolder extends BlogTree implements PermissionProvider {
$fields->addFieldToTab('Root.Main', new CheckboxField('TrackBacksEnabled', 'Enable TrackBacks'), "Content");
$fields->addFieldToTab('Root.Main', new CheckboxField('AllowCustomAuthors', 'Allow non-admins to have a custom author field'), "Content");
$fields->addFieldToTab(
"Root.Main",
"Root.Main",
CheckboxField::create("ShowFullEntry", "Show Full Entry")
->setDescription('Show full content in overviews rather than summary'),
->setDescription('Show full content in overviews rather than summary'),
"Content"
);
@ -61,18 +61,17 @@ class BlogHolder extends BlogTree implements PermissionProvider {
return $fields;
}
/**
* Get members who have BLOGMANAGEMENT and ADMIN permission
*/
*/
function blogOwners($sort = array('FirstName'=>'ASC','Surname'=>'ASC'), $direction = null) {
$members = Permission::get_members_by_permission(array('ADMIN','BLOGMANAGEMENT'));
$members = Permission::get_members_by_permission(array('ADMIN','BLOGMANAGEMENT'));
$members->sort($sort);
$this->extend('extendBlogOwners', $members);
return $members;
}
@ -156,7 +155,7 @@ class BlogHolder extends BlogTree implements PermissionProvider {
$archivewidget->ParentID = $widgetarea->ID;
$archivewidget->write();
$widgetarea->write();
$widgetarea->write();
break; // only apply to one
}
@ -183,6 +182,7 @@ class BlogHolder extends BlogTree implements PermissionProvider {
}
class BlogHolder_Controller extends BlogTree_Controller {
static $allowed_actions = array(
'index',
'tag',
@ -192,7 +192,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
'post',
'BlogEntryForm' => 'BLOGMANAGEMENT',
);
function init() {
parent::init();
Requirements::themedCSS("bbcodehelp");
@ -221,9 +221,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')) {
@ -250,7 +250,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
} else {
$tagfield = new TextField('Tags');
}
$field = 'TextField';
if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
$field = 'ReadonlyField';
@ -264,7 +264,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 FieldList($submitAction);
@ -304,6 +304,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
}
$form->saveInto($blogentry);
$blogentry->ParentID = $this->ID;
$blogentry->Content = str_replace("\r\n", "\n", $form->Fields()->fieldByName('BlogPost')->dataValue());

View File

@ -5,7 +5,7 @@
*/
/**
* Blog tree is a way to group Blogs. It allows a tree of "Blog Holders".
* Blog tree is a way to group Blogs. It allows a tree of "Blog Holders".
* Viewing branch nodes shows all blog entries from all blog holder children
*/
@ -14,18 +14,25 @@ class BlogTree extends Page {
static $icon = "blog/images/blogtree-file.png";
static $description = "A grouping of blogs";
static $singular_name = 'Blog Tree Page';
static $plural_name = 'Blog Tree Pages';
// 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(
'LandingPageFreshness' => 'Varchar',
);
static $allowed_children = array(
'BlogTree', 'BlogHolder'
);
@ -40,7 +47,7 @@ class BlogTree extends Page {
* uses current
*/
static function current($page = null) {
if (!$page) {
$controller = Controller::curr();
if($controller) $page = $controller->data();
@ -78,35 +85,35 @@ class BlogTree extends Page {
if ($freshness == "INHERIT") $freshness = '';
return $freshness;
}
/* ----------- CMS CONTROL -------------- */
function getSettingsFields() {
$fields = parent::getSettingsFields();
$fields->addFieldToTab(
'Root.Settings',
'Root.Settings',
new DropdownField(
'LandingPageFreshness',
'When you first open the blog, how many entries should I show',
array(
"" => "All entries",
"1" => "Last month's entries",
"2" => "Last 2 months' entries",
"3" => "Last 3 months' entries",
"4" => "Last 4 months' entries",
"5" => "Last 5 months' entries",
"6" => "Last 6 months' entries",
"7" => "Last 7 months' entries",
"8" => "Last 8 months' entries",
"9" => "Last 9 months' entries",
"10" => "Last 10 months' entries",
"11" => "Last 11 months' entries",
"12" => "Last year's entries",
'LandingPageFreshness',
'When you first open the blog, how many entries should I show',
array(
"" => "All entries",
"1" => "Last month's entries",
"2" => "Last 2 months' entries",
"3" => "Last 3 months' entries",
"4" => "Last 4 months' entries",
"5" => "Last 5 months' entries",
"6" => "Last 6 months' entries",
"7" => "Last 7 months' entries",
"8" => "Last 8 months' entries",
"9" => "Last 9 months' entries",
"10" => "Last 10 months' entries",
"11" => "Last 11 months' entries",
"12" => "Last year's entries",
"INHERIT" => "Take value from parent Blog Tree"
)
)
);
);
return $fields;
}
@ -144,7 +151,6 @@ class BlogTree extends Page {
* @return DataObjectSet
*/
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') {
$tagCheck = '';
$dateCheck = '';
@ -157,12 +163,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;
@ -185,7 +191,6 @@ class BlogTree extends Page {
}
}
}
// Build a list of all IDs for BlogHolders that are children of us
$holderIDs = $this->BlogHolderIDs();
@ -210,7 +215,7 @@ class BlogTree extends Page {
}
class BlogTree_Controller extends Page_Controller {
static $allowed_actions = array(
'index',
'rss',
@ -221,22 +226,24 @@ class BlogTree_Controller extends Page_Controller {
function init() {
parent::init();
$this->IncludeBlogRSS();
if(BlogTree::$include_rss_link) {
$this->IncludeBlogRSS();
}
Requirements::themedCSS("blog","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)
if ($this->LandingPageFreshness && !$this->request->param('Action')) {
$d = new Zend_Date(SS_Datetime::now()->getValue());
$d->sub($this->LandingPageFreshness, Zend_Date::MONTH);
$d->sub(intval($this->LandingPageFreshness, Zend_Date::MONTH), Zend_Date::MONTH);
$date = $d->toString('YYYY-MM-dd');
$filter = "\"BlogEntry\".\"Date\" > '$date'";
} else {
$filter = '';
@ -246,7 +253,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'])) {
@ -257,7 +264,7 @@ class BlogTree_Controller extends Page_Controller {
}
$date = $this->SelectedDate();
return $this->Entries($limit, $this->SelectedTag(), ($date) ? $date : '', null, $filter);
}
@ -267,7 +274,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
*/
@ -284,7 +291,7 @@ class BlogTree_Controller extends Page_Controller {
return $rss->outputToBrowser();
}
}
/**
* Protection against infinite loops when an RSS widget pointing to this page is added to this page
*/
@ -293,16 +300,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
*
@ -312,18 +319,18 @@ 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;
}
@ -350,14 +357,14 @@ class BlogTree_Controller extends Page_Controller {
}
}
}
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

@ -3,67 +3,66 @@ if(class_exists('Widget')) {
/**
* Shows a widget with viewing blog entries
* by months or years.
*
*
* @package blog
*/
class ArchiveWidget extends Widget {
static $db = array(
'DisplayMode' => 'Varchar'
);
static $has_one = array();
static $has_many = array();
static $many_many = array();
static $belongs_many_many = array();
static $defaults = array(
'DisplayMode' => 'month'
);
static $title = 'Browse by Date';
static $cmsTitle = 'Blog Archive';
static $cmsTitle = 'Blog Archive';
static $description = 'Show a list of months or years in which there are blog posts, and provide links to them.';
function getCMSFields() {
$fields = parent::getCMSFields();
static $description = 'Show a list of months or years in which there are blog posts, and provide links to them.';
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->merge(
new FieldList(
new OptionsetField(
'DisplayMode',
_t('ArchiveWidget.DispBY', 'Display by'),
array(
'month' => _t('ArchiveWidget.MONTH', 'month'),
'year' => _t('ArchiveWidget.YEAR', 'year')
)
$fields->merge(
new FieldList(
new OptionsetField(
'DisplayMode',
_t('ArchiveWidget.DispBY', 'Display by'),
array(
'month' => _t('ArchiveWidget.MONTH', 'month'),
'year' => _t('ArchiveWidget.YEAR', 'year')
)
)
);
$this->extend('updateCMSFields', $fields);
return $fields;
}
function getDates() {
Requirements::themedCSS('archivewidget');
$results = new ArrayList();
$container = BlogTree::current();
$ids = $container->BlogHolderIDs();
$stage = Versioned::current_stage();
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";
)
)
);
$this->extend('updateCMSFields', $fields);
return $fields;
}
function getDates() {
Requirements::themedCSS('archivewidget');
$results = new ArrayList();
$container = BlogTree::current();
$ids = $container->BlogHolderIDs();
if(empty($ids)) return $results;$stage = Versioned::current_stage();
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";
$monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")';
$yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")';
if($this->DisplayMode == 'month') {
$sqlResults = DB::query("
SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", $yearclause AS \"Year\"
@ -79,34 +78,34 @@ if(class_exists('Widget')) {
ORDER BY \"Year\" DESC"
);
}
if($sqlResults) foreach($sqlResults as $sqlResult) {
$isMonthDisplay = $this->DisplayMode == 'month';
$monthVal = (isset($sqlResult['Month'])) ? (int) $sqlResult['Month'] : 1;
$month = ($isMonthDisplay) ? $monthVal : 1;
$year = ($sqlResult['Year']) ? (int) $sqlResult['Year'] : date('Y');
$date = DBField::create_field('Date', array(
'Day' => 1,
'Month' => $month,
'Year' => $year
));
if($isMonthDisplay) {
$link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal);
} else {
$link = $container->Link('date') . '/' . $sqlResult['Year'];
}
$results->push(new ArrayData(array(
'Date' => $date,
'Link' => $link
)));
}
return $results;
}
}
}
}

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');