mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
BUGFIX
reduced the hungriness to process a simple date difference avoided an API CHANGE (fixes 6247#comment:2)
This commit is contained in:
parent
86c3e987f7
commit
1218713332
@ -44,10 +44,7 @@ class BlogTree extends Page {
|
|||||||
|
|
||||||
if (!$page) {
|
if (!$page) {
|
||||||
$controller = Controller::curr();
|
$controller = Controller::curr();
|
||||||
if($controller) {
|
if($controller) $page = $controller->data();
|
||||||
if (!isset($controller->data)) return false;
|
|
||||||
$page = $controller->data();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we _are_ a BlogTree, use us
|
// If we _are_ a BlogTree, use us
|
||||||
@ -64,14 +61,13 @@ class BlogTree extends Page {
|
|||||||
if($top) return $top;
|
if($top) return $top;
|
||||||
|
|
||||||
// Try to find any BlogTree that is not inside another BlogTree
|
// Try to find any BlogTree that is not inside another BlogTree
|
||||||
if($blogTrees=DataObject::get('BlogTree')) foreach($blogTrees as $tree) {
|
foreach(DataObject::get('BlogTree') as $tree) {
|
||||||
if(!($tree->getParent() instanceof BlogTree)) return $tree;
|
if(!($tree->getParent() instanceof BlogTree)) return $tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This shouldn't be possible, but assuming the above fails, just return anything you can get
|
// This shouldn't be possible, but assuming the above fails, just return anything you can get
|
||||||
return $blogTrees;
|
return DataObject::get_one('BlogTree');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------- ACCESSOR OVERRIDES -------------- */
|
/* ----------- ACCESSOR OVERRIDES -------------- */
|
||||||
|
|
||||||
@ -102,18 +98,18 @@ class BlogTree extends Page {
|
|||||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Name", "Name of blog"));
|
$fields->addFieldToTab("Root.Content.Main", new TextField("Name", "Name of blog"));
|
||||||
$fields->addFieldToTab('Root.Content.Main', new DropdownField('LandingPageFreshness', 'When you first open the blog, how many entries should I show', array(
|
$fields->addFieldToTab('Root.Content.Main', new DropdownField('LandingPageFreshness', 'When you first open the blog, how many entries should I show', array(
|
||||||
"" => "All entries",
|
"" => "All entries",
|
||||||
"1" => "Last month's entries",
|
"1 MONTH" => "Last month's entries",
|
||||||
"2" => "Last 2 months' entries",
|
"2 MONTH" => "Last 2 months' entries",
|
||||||
"3" => "Last 3 months' entries",
|
"3 MONTH" => "Last 3 months' entries",
|
||||||
"4" => "Last 4 months' entries",
|
"4 MONTH" => "Last 4 months' entries",
|
||||||
"5" => "Last 5 months' entries",
|
"5 MONTH" => "Last 5 months' entries",
|
||||||
"6" => "Last 6 months' entries",
|
"6 MONTH" => "Last 6 months' entries",
|
||||||
"7" => "Last 7 months' entries",
|
"7 MONTH" => "Last 7 months' entries",
|
||||||
"8" => "Last 8 months' entries",
|
"8 MONTH" => "Last 8 months' entries",
|
||||||
"9" => "Last 9 months' entries",
|
"9 MONTH" => "Last 9 months' entries",
|
||||||
"10" => "Last 10 months' entries",
|
"10 MONTH" => "Last 10 months' entries",
|
||||||
"11" => "Last 11 months' entries",
|
"11 MONTH" => "Last 11 months' entries",
|
||||||
"12" => "Last year's entries",
|
"12 MONTH" => "Last year's entries",
|
||||||
"INHERIT" => "Take value from parent Blog Tree"
|
"INHERIT" => "Take value from parent Blog Tree"
|
||||||
)));
|
)));
|
||||||
|
|
||||||
@ -126,14 +122,16 @@ class BlogTree extends Page {
|
|||||||
/* ----------- New accessors -------------- */
|
/* ----------- New accessors -------------- */
|
||||||
|
|
||||||
public function loadDescendantBlogHolderIDListInto(&$idList) {
|
public function loadDescendantBlogHolderIDListInto(&$idList) {
|
||||||
if ($children = $this->AllChildren()) foreach($children as $child) {
|
if ($children = $this->AllChildren()) {
|
||||||
if(in_array($child->ID, $idList)) continue;
|
foreach($children as $child) {
|
||||||
|
if(in_array($child->ID, $idList)) continue;
|
||||||
if($child instanceof BlogHolder) {
|
|
||||||
$idList[] = $child->ID;
|
if($child instanceof BlogHolder) {
|
||||||
} elseif($child instanceof BlogTree) {
|
$idList[] = $child->ID;
|
||||||
$child->loadDescendantBlogHolderIDListInto($idList);
|
} elseif($child instanceof BlogTree) {
|
||||||
}
|
$child->loadDescendantBlogHolderIDListInto($idList);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,8 +210,7 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
static $allowed_actions = array(
|
static $allowed_actions = array(
|
||||||
'index',
|
'index',
|
||||||
'rss',
|
'rss',
|
||||||
'tag',
|
'tag'
|
||||||
'date'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@ -231,11 +228,7 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
|
|
||||||
// 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)
|
||||||
if ($this->LandingPageFreshness && !$this->request->param('Action')) {
|
if ($this->LandingPageFreshness && !$this->request->param('Action')) {
|
||||||
$d = new Zend_Date(SS_Datetime::now()->getValue());
|
$filter = "\"BlogEntry\".\"Date\" > '".date('Y-m-d', strtotime("-{$this->LandingPageFreshness}"))."'";
|
||||||
if(strlen($this->LandingPageFreshness)>2)$this->LandingPageFreshness=rtrim(substr($this->LandingPageFreshness, 0, 2)); //For backcompatibility
|
|
||||||
$d->sub($this->LandingPageFreshness,Zend_Date::MONTH);
|
|
||||||
$date = $d->toString('YYYY-MM-dd');
|
|
||||||
$filter = "\"BlogEntry\".\"Date\" > '$date'";
|
|
||||||
} else {
|
} else {
|
||||||
$filter = '';
|
$filter = '';
|
||||||
}
|
}
|
||||||
@ -247,19 +240,17 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
$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'])) {
|
|
||||||
$filter .= " \"BlogEntry\".\"Author\" LIKE '". Convert::raw2sql($_GET['author']) . "'";
|
$filter .= " \"BlogEntry\".\"Author\" LIKE '". Convert::raw2sql($_GET['author']) . "'";
|
||||||
}
|
} else if(isset($_GET['authorID'])) {
|
||||||
else if(isset($_GET['authorID'])) {
|
|
||||||
$filter .= " \"BlogEntry\".\"AuthorID\" = '". Convert::raw2sql($_GET['authorID']). "'";
|
$filter .= " \"BlogEntry\".\"AuthorID\" = '". Convert::raw2sql($_GET['authorID']). "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
$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->Format('Y-m') : '', null, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,7 +272,7 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
$entries = $this->Entries(20);
|
$entries = $this->Entries(20);
|
||||||
|
|
||||||
if($entries) {
|
if($entries) {
|
||||||
$rss = new RSSFeed($entries, $this->Link(), ($blogName ? $blogName : $altBlogName), "", "Title", "RSSContent");
|
$rss = new RSSFeed($entries, $this->Link(), ($blogName ? $blogName : $altBlogName), "", "Title", "ParsedContent");
|
||||||
$rss->outputToBrowser();
|
$rss->outputToBrowser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,7 +282,6 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
*/
|
*/
|
||||||
function defaultAction($action) {
|
function defaultAction($action) {
|
||||||
if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) return $this->rss();
|
if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) return $this->rss();
|
||||||
|
|
||||||
return parent::defaultAction($action);
|
return parent::defaultAction($action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +291,7 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
* @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')) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -315,27 +305,13 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
$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 = $year .'-'. $month;
|
$date->setValue($year .'-'. $month);
|
||||||
return $date;
|
|
||||||
|
|
||||||
} else {
|
return $date;
|
||||||
if(is_numeric($year)) return $year;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user