Merge branch '0.6' into 1.0

This commit is contained in:
Daniel Hensby 2018-02-20 13:31:31 +00:00
commit bdea98a875
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
5 changed files with 123 additions and 117 deletions

View File

@ -64,7 +64,6 @@ class BlogHolder extends BlogTree implements PermissionProvider {
/**
* 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'));
@ -308,6 +307,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

@ -1,11 +1,11 @@
<?php
<?php
/**
* @package blog
*/
/**
* 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,26 +14,26 @@ class BlogTree extends Page {
private static $icon = "blog/images/blogtree-file.png";
private static $description = "A grouping of blogs";
private static $singular_name = 'Blog Tree Page';
private static $plural_name = 'Blog Tree Pages';
// Default number of blog entries to show
static $default_entries_limit = 10;
private static $db = array(
'Name' => 'Varchar(255)',
'LandingPageFreshness' => 'Varchar',
);
private static $defaults = array(
);
private static $has_one = array();
private static $has_many = array();
private static $allowed_children = array(
'BlogTree', 'BlogHolder'
);
@ -49,43 +49,43 @@ class BlogTree extends Page {
* @return BlogTree
*/
static function current($page = null) {
if (!$page && Controller::has_curr()) {
$controller = Controller::curr();
if ($controller->hasMethod('data')) {
$page = $controller->data();
}
}
if ($page) {
// If we _are_ a BlogTree, use us
if ($page instanceof BlogTree) return $page;
// If page is a virtual page use that
if($page instanceof VirtualPage && $page->CopyContentFrom() instanceof BlogTree) return $page;
// Or, if we a a BlogEntry underneath a BlogTree, use our parent
if($page->is_a("BlogEntry")) {
$parent = $page->getParent();
if($parent instanceof BlogTree) return $parent;
}
}
// Try to find a top-level BlogTree
$top = DataObject::get_one('BlogTree', "\"ParentID\" = '0'");
if($top) return $top;
// Try to find any BlogTree that is not inside another BlogTree
if($blogTrees=DataObject::get('BlogTree')) foreach($blogTrees as $tree) {
if(!($tree->getParent() instanceof BlogTree)) return $tree;
}
// This shouldn't be possible, but assuming the above fails, just return anything you can get
return $blogTrees->first();
}
/* ----------- ACCESSOR OVERRIDES -------------- */
public function getLandingPageFreshness() {
$freshness = $this->getField('LandingPageFreshness');
// If we want to inherit freshness, try that first
@ -94,65 +94,65 @@ 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;
}
/* ----------- New accessors -------------- */
public function loadDescendantBlogHolderIDListInto(&$idList) {
if ($children = $this->AllChildren()) {
foreach($children as $child) {
if(in_array($child->ID, $idList)) continue;
if($child instanceof BlogHolder) {
$idList[] = $child->ID;
$idList[] = $child->ID;
} elseif($child instanceof BlogTree) {
$child->loadDescendantBlogHolderIDListInto($idList);
}
}
}
}
}
// Build a list of all IDs for BlogHolders that are children of us
public function BlogHolderIDs() {
$holderIDs = array();
$this->loadDescendantBlogHolderIDListInto($holderIDs);
return $holderIDs;
}
/**
* Get entries in this blog.
*
*
* @param string $limit A clause to insert into the limit clause.
* @param string $tag Only get blog entries with this tag
* @param string $date Only get blog entries on this date - either a year, or a year-month eg '2008' or '2008-02'
@ -162,10 +162,9 @@ class BlogTree extends Page {
* @return PaginatedList The list of entries in a paginated list
*/
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') {
$tagCheck = '';
$dateCheck = '';
if($tag) {
$SQL_tag = Convert::raw2sql($tag);
$tagCheck = "AND \"BlogEntry\".\"Tags\" LIKE '%$SQL_tag%'";
@ -175,12 +174,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;
@ -203,13 +202,12 @@ class BlogTree extends Page {
}
}
}
// Build a list of all IDs for BlogHolders that are children of us
$holderIDs = $this->BlogHolderIDs();
// If no BlogHolders, no BlogEntries. So return false
if(empty($holderIDs)) return false;
// Otherwise, do the actual query
if($filter) $filter .= ' AND ';
$filter .= '"SiteTree"."ParentID" IN (' . implode(',', $holderIDs) . ") $tagCheck $dateCheck";
@ -228,44 +226,44 @@ class BlogTree extends Page {
}
class BlogTree_Controller extends Page_Controller {
private static $allowed_actions = array(
'index',
'rss',
'tag',
'date'
);
private static $casting = array(
'SelectedTag' => 'Text',
'SelectedAuthor' => 'Text'
);
function init() {
parent::init();
$this->IncludeBlogRSS();
Requirements::themedCSS("blog","blog");
}
/**
* Determine selected BlogEntry items to show on this page
*
*
* @param int $limit
* @return PaginatedList
*/
public 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 = '';
@ -275,7 +273,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'])) {
@ -286,7 +284,7 @@ class BlogTree_Controller extends Page_Controller {
}
$date = $this->SelectedDate();
return $this->Entries($limit, $this->SelectedTag(), ($date) ? $date : '', null, $filter);
}
@ -296,7 +294,7 @@ class BlogTree_Controller extends Page_Controller {
public 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
*/
@ -305,7 +303,7 @@ class BlogTree_Controller extends Page_Controller {
$blogName = $this->Title;
$altBlogName = $project_name . ' blog';
$entries = $this->Entries(20);
if($entries) {
@ -313,18 +311,18 @@ 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
*/
public function defaultAction($action) {
if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) return $this->rss();
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
*/
@ -335,7 +333,7 @@ class BlogTree_Controller extends Page_Controller {
}
return '';
}
/**
* Return the selected date from the blog tree
*
@ -345,18 +343,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;
}
@ -385,18 +383,17 @@ class BlogTree_Controller extends Page_Controller {
}
}
}
/**
*
* @return string
*/
public 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

@ -1,34 +1,34 @@
<?php
if(class_exists('Widget')) {
/**
* Shows a widget with viewing blog entries
* by months or years.
*
*
* @package blog
*/
class ArchiveWidget extends Widget {
private static $db = array(
'DisplayMode' => 'Varchar'
);
private static $defaults = array(
'DisplayMode' => 'month'
);
private static $title = 'Browse by Date';
private static $cmsTitle = 'Blog Archive';
private 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(
$fields = parent::getCMSFields();
$fields->merge(
new FieldList(
new OptionsetField(
@ -39,21 +39,21 @@ if(class_exists('Widget')) {
'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";
@ -64,9 +64,9 @@ if(class_exists('Widget')) {
$monthclause = 'MONTH("Date")';
$yearclause = 'YEAR("Date")';
}
// Changed the WHERE clause from where ParentID to WHERE SiteTree$suffix.ParentID as it was ambiguous.
if($this->DisplayMode == 'month') {
$sqlResults = DB::query("
SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ")
@ -86,33 +86,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

@ -1,14 +1,14 @@
<?php
if(class_exists('Widget')) {
/**
* A list of tags associated with blog posts
*
*
* @package blog
*/
class TagCloudWidget extends Widget {
private static $db = array(
"Title" => "Varchar",
"Limit" => "Int",
@ -22,7 +22,7 @@ if(class_exists('Widget')) {
);
private static $cmsTitle = "Tag Cloud";
private static $description = "Shows a tag cloud of tags on your blog.";
/**
@ -41,7 +41,7 @@ if(class_exists('Widget')) {
);
public function getCMSFields() {
$this->beforeUpdateCMSFields(function($fields) {
$fields->merge(
new FieldList(
@ -65,18 +65,18 @@ if(class_exists('Widget')) {
function Title() {
return $this->Title ? $this->Title : _t('TagCloudWidget.DEFAULTTITLE', 'Tag Cloud');
}
/**
* Current BlogTree used as the container for this tagcloud.
* Used by {@link TagCloudWidgetTest} for testing
*
*
* @var BlogTree
*/
public static $container = null;
/**
* Return all sorted tags in the system
*
*
* @return ArrayList
*/
function getTagsCollection() {
@ -114,7 +114,7 @@ if(class_exists('Widget')) {
return $b - $a;
});
}
// Apply limiting
if($this->Limit > 0) $tagCounts = array_slice($tagCounts, 0, $this->Limit, true);
@ -125,13 +125,13 @@ if(class_exists('Widget')) {
// If there are more frequencies than buckets, divide frequencies into buckets
if ($numsizes > $buckets) $numsizes = $buckets;
// Adjust offset to use central buckets (if using a subset of available buckets)
$offset = round(($buckets - $numsizes)/2);
$output = new ArrayList();
foreach($tagCounts as $tag => $count) {
// Find position of $count in the selected range, adjusted for bucket range used
if($maxCount == $minCount) {
$popularity = $offset;

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