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 = '';
|
||||
|
||||
@ -153,7 +154,7 @@ class BlogTree extends Page {
|
||||
$SQL_tag = Convert::raw2sql($tag);
|
||||
$tagCheck = "AND \"BlogEntry\".\"Tags\" LIKE '%$SQL_tag%'";
|
||||
}
|
||||
|
||||
|
||||
if($date) {
|
||||
if(strpos($date, '-')) {
|
||||
$year = (int) substr($date, 0, strpos($date, '-'));
|
||||
@ -168,10 +169,8 @@ 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
|
||||
$holderIDs = $this->BlogHolderIDs();
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,9 +227,16 @@ 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() {
|
||||
@ -262,4 +269,4 @@ class BlogTree_Controller extends Page_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
Loading…
Reference in New Issue
Block a user