From b066dce821d913c5bb5e268d5a552fb105572593 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sun, 16 May 2010 02:38:19 +0000 Subject: [PATCH] APICHANGE: removed BlogTree_URL class and its little static children. Changed to SelectedTag and SelectedDate to allow to be called in the template. SelectedDate now also returns a Date object rather than a string. BUGFIX: fixed missing Viewing posts by date text and added a viewing by post date text. --- code/BlogTree.php | 74 ++++++++++++++++++++-------------- templates/Layout/BlogHolder.ss | 6 ++- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/code/BlogTree.php b/code/BlogTree.php index b88bed8..4aad0f9 100644 --- a/code/BlogTree.php +++ b/code/BlogTree.php @@ -203,29 +203,8 @@ class BlogTree extends Page { } } -class BlogTree_URL { - static function tag() { - if (Director::urlParam('Action') == 'tag') return Director::urlParam('ID'); - return ''; - } - - static function date() { - if(Director::urlParam('Action') == 'date') { - $year = Director::urlParam('ID'); - $month = Director::urlParam('OtherID'); - - if($month && is_numeric($month) && $month >= 1 && $month <= 12 && is_numeric($year)) { - return "$year-$month"; - } elseif (is_numeric($year)) { - return $year; - } - - return ''; - } - } -} - class BlogTree_Controller extends Page_Controller { + static $allowed_actions = array( 'index', 'rss', @@ -250,11 +229,16 @@ class BlogTree_Controller extends Page_Controller { } $start = isset($_GET['start']) ? (int) $_GET['start'] : 0; - return $this->Entries("$start,$limit", BlogTree_URL::tag(), BlogTree_URL::date(), null, $filter); + + $date = $this->SelectedDate(); + + return $this->Entries("$start,$limit", $this->SelectedTag(), ($date) ? $date->Format('Y-m') : '', null, $filter); } + /** + * This will create a tag point to the RSS feed + */ function IncludeBlogRSS() { - // This will create a tag point to the RSS feed RSSFeed::linkToFeed($this->Link() . "rss", _t('BlogHolder.RSSFEED',"RSS feed of these blogs")); } @@ -274,13 +258,43 @@ class BlogTree_Controller extends Page_Controller { $rss->outputToBrowser(); } } - + + /** + * Protection against infinite loops when an RSS widget pointing to this page is added to this page + */ function defaultAction($action) { - // Protection against infinite loops when an RSS widget pointing to this page is added to this page if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) return $this->rss(); return parent::defaultAction($action); - } -} - -?> \ No newline at end of file + } + + /** + * Return the currently viewing tag used in the template as $Tag + * + * @return String + */ + function SelectedTag() { + return (Director::urlParam('Action') == 'tag') ? Director::urlParam('ID') : ''; + } + + /** + * Return the selected date from the blog tree + * + * @return Date + */ + function SelectedDate() { + if(Director::urlParam('Action') == 'date') { + $year = Director::urlParam('ID'); + $month = Director::urlParam('OtherID'); + + if(is_numeric($year) && is_numeric($month) && $month < 13) { + $date = new Date(); + $date->setValue($year .'-'. $month); + + return $date; + } + } + + return false; + } +} \ No newline at end of file diff --git a/templates/Layout/BlogHolder.ss b/templates/Layout/BlogHolder.ss index d0d3eec..e8e7779 100644 --- a/templates/Layout/BlogHolder.ss +++ b/templates/Layout/BlogHolder.ss @@ -4,8 +4,10 @@ <% include BreadCrumbs %> - <% if Tag %> -

<% _t('VIEWINGTAGGED', 'Viewing entries tagged with') %> '$Tag'

+ <% if SelectedTag %> +

<% _t('VIEWINGTAGGED', 'Viewing entries tagged with') %> '$SelectedTag'

+ <% else_if SelectedDate %> +

<% _t('VIEWINGPOSTEDIN', 'Viewing entries posted in') %> $SelectedDate.Month $SelectedDate.Year

<% end_if %> <% if BlogEntries %>