mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
BUGFIX Limiting BlogHolder->LandingPageFreshness to requests without a controller action only. Controller actions are not regarded as the "landing page", as they cause other views like 'tags' or 'rss', which shouldn't be filtered
This commit is contained in:
parent
eb1dc8019e
commit
1d2c96b6de
@ -143,9 +143,10 @@ class BlogTree extends Page {
|
||||
* @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'
|
||||
* @param callback retrieveCallback A function to call with pagetype, filter and limit for custom blog sorting or filtering
|
||||
* @param string $where
|
||||
* @return DataObjectSet
|
||||
*/
|
||||
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null) {
|
||||
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') {
|
||||
$tagCheck = '';
|
||||
$dateCheck = '';
|
||||
|
||||
@ -168,8 +169,6 @@ class BlogTree extends Page {
|
||||
$dateCheck = "AND YEAR(\"BlogEntry\".\"Date\") = '$year'";
|
||||
}
|
||||
}
|
||||
} elseif ($this->LandingPageFreshness) {
|
||||
$dateCheck = "AND \"BlogEntry\".\"Date\" > NOW() - INTERVAL " . $this->LandingPageFreshness;
|
||||
}
|
||||
|
||||
// Build a list of all IDs for BlogHolders that are children of us
|
||||
@ -179,13 +178,14 @@ class BlogTree extends Page {
|
||||
if(empty($holderIDs)) return false;
|
||||
|
||||
// Otherwise, do the actual query
|
||||
$where = '"ParentID" IN (' . implode(',', $holderIDs) . ") $tagCheck $dateCheck";
|
||||
if($filter) $filter .= ' AND ';
|
||||
$filter .= '"ParentID" IN (' . implode(',', $holderIDs) . ") $tagCheck $dateCheck";
|
||||
|
||||
$order = '"BlogEntry"."Date" DESC';
|
||||
|
||||
// By specifying a callback, you can alter the SQL, or sort on something other than date.
|
||||
if($retrieveCallback) return call_user_func($retrieveCallback, 'BlogEntry', $where, $limit, $order);
|
||||
else return DataObject::get('BlogEntry', $where, $order, '', $limit);
|
||||
if($retrieveCallback) return call_user_func($retrieveCallback, 'BlogEntry', $filter, $limit, $order);
|
||||
else return DataObject::get('BlogEntry', $filter, $order, '', $limit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,8 +228,15 @@ class BlogTree_Controller extends Page_Controller {
|
||||
function BlogEntries($limit = null) {
|
||||
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')) {
|
||||
$filter = "\"BlogEntry\".\"Date\" > NOW() - INTERVAL " . $this->LandingPageFreshness;
|
||||
} else {
|
||||
$filter = '';
|
||||
}
|
||||
|
||||
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
|
||||
return $this->Entries("$start,$limit", BlogTree_URL::tag(), BlogTree_URL::date());
|
||||
return $this->Entries("$start,$limit", BlogTree_URL::tag(), BlogTree_URL::date(), null, $filter);
|
||||
}
|
||||
|
||||
function IncludeBlogRSS() {
|
||||
|
Loading…
Reference in New Issue
Block a user