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:
Ingo Schommer 2009-12-22 20:55:23 +00:00
parent eb1dc8019e
commit 1d2c96b6de

View File

@ -143,9 +143,10 @@ class BlogTree extends Page {
* @param string tag Only get blog entries with this tag * @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 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 callback retrieveCallback A function to call with pagetype, filter and limit for custom blog sorting or filtering
* @param string $where
* @return DataObjectSet * @return DataObjectSet
*/ */
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null) { public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') {
$tagCheck = ''; $tagCheck = '';
$dateCheck = ''; $dateCheck = '';
@ -168,8 +169,6 @@ class BlogTree extends Page {
$dateCheck = "AND YEAR(\"BlogEntry\".\"Date\") = '$year'"; $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 // 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; if(empty($holderIDs)) return false;
// Otherwise, do the actual query // 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'; $order = '"BlogEntry"."Date" DESC';
// By specifying a callback, you can alter the SQL, or sort on something other than date. // 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); if($retrieveCallback) return call_user_func($retrieveCallback, 'BlogEntry', $filter, $limit, $order);
else return DataObject::get('BlogEntry', $where, $order, '', $limit); else return DataObject::get('BlogEntry', $filter, $order, '', $limit);
} }
} }
@ -228,8 +228,15 @@ class BlogTree_Controller extends Page_Controller {
function BlogEntries($limit = null) { function BlogEntries($limit = null) {
if($limit === null) $limit = BlogTree::$default_entries_limit; 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; $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() { function IncludeBlogRSS() {