diff --git a/code/BlogTree.php b/code/BlogTree.php index eb29177..6c8e6f7 100644 --- a/code/BlogTree.php +++ b/code/BlogTree.php @@ -44,10 +44,7 @@ class BlogTree extends Page { if (!$page) { $controller = Controller::curr(); - if($controller) { - if (!isset($controller->data)) return false; - $page = $controller->data(); - } + if($controller) $page = $controller->data(); } // If we _are_ a BlogTree, use us @@ -64,14 +61,13 @@ class BlogTree extends Page { if($top) return $top; // 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; } // 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 -------------- */ @@ -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 DropdownField('LandingPageFreshness', 'When you first open the blog, how many entries should I show', array( "" => "All entries", - "1" => "Last month's entries", - "2" => "Last 2 months' entries", - "3" => "Last 3 months' entries", - "4" => "Last 4 months' entries", - "5" => "Last 5 months' entries", - "6" => "Last 6 months' entries", - "7" => "Last 7 months' entries", - "8" => "Last 8 months' entries", - "9" => "Last 9 months' entries", - "10" => "Last 10 months' entries", - "11" => "Last 11 months' entries", - "12" => "Last year's entries", + "1 MONTH" => "Last month's entries", + "2 MONTH" => "Last 2 months' entries", + "3 MONTH" => "Last 3 months' entries", + "4 MONTH" => "Last 4 months' entries", + "5 MONTH" => "Last 5 months' entries", + "6 MONTH" => "Last 6 months' entries", + "7 MONTH" => "Last 7 months' entries", + "8 MONTH" => "Last 8 months' entries", + "9 MONTH" => "Last 9 months' entries", + "10 MONTH" => "Last 10 months' entries", + "11 MONTH" => "Last 11 months' entries", + "12 MONTH" => "Last year's entries", "INHERIT" => "Take value from parent Blog Tree" ))); @@ -126,14 +122,16 @@ class BlogTree extends Page { /* ----------- New accessors -------------- */ public function loadDescendantBlogHolderIDListInto(&$idList) { - if ($children = $this->AllChildren()) foreach($children as $child) { - if(in_array($child->ID, $idList)) continue; - - if($child instanceof BlogHolder) { - $idList[] = $child->ID; - } elseif($child instanceof BlogTree) { - $child->loadDescendantBlogHolderIDListInto($idList); - } + if ($children = $this->AllChildren()) { + foreach($children as $child) { + if(in_array($child->ID, $idList)) continue; + + if($child instanceof BlogHolder) { + $idList[] = $child->ID; + } elseif($child instanceof BlogTree) { + $child->loadDescendantBlogHolderIDListInto($idList); + } + } } } @@ -212,8 +210,7 @@ class BlogTree_Controller extends Page_Controller { static $allowed_actions = array( 'index', 'rss', - 'tag', - 'date' + 'tag' ); 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) if ($this->LandingPageFreshness && !$this->request->param('Action')) { - $d = new Zend_Date(SS_Datetime::now()->getValue()); - 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'"; + $filter = "\"BlogEntry\".\"Date\" > '".date('Y-m-d', strtotime("-{$this->LandingPageFreshness}"))."'"; } else { $filter = ''; } @@ -247,19 +240,17 @@ class BlogTree_Controller extends Page_Controller { $id = Convert::raw2sql($_GET['authorID']); $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']) . "'"; - } - else if(isset($_GET['authorID'])) { + } else if(isset($_GET['authorID'])) { $filter .= " \"BlogEntry\".\"AuthorID\" = '". Convert::raw2sql($_GET['authorID']). "'"; } $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); 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(); } } @@ -291,7 +282,6 @@ class BlogTree_Controller extends Page_Controller { */ function defaultAction($action) { if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) return $this->rss(); - return parent::defaultAction($action); } @@ -301,7 +291,7 @@ class BlogTree_Controller extends Page_Controller { * @return String */ 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'); if(is_numeric($year) && is_numeric($month) && $month < 13) { - - $date = $year .'-'. $month; - return $date; + $date = new Date(); + $date->setValue($year .'-'. $month); - } else { - if(is_numeric($year)) return $year; + return $date; } } 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)); - } - } } \ No newline at end of file