function Dates() { Requirements::themedCSS('archivewidget'); $results = new DataObjectSet(); $container = BlogTree::current(); $ids = $container->BlogHolderIDs(); $stage = Versioned::current_stage(); $suffix = !$stage || $stage == 'Stage' ? "" : "_{$stage}"; $monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")'; $yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")'; $sqlResults = DB::query("\n\t\t\tSELECT DISTINCT CAST({$monthclause} AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", {$yearclause} AS \"Year\"\n\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\tORDER BY \"Year\" DESC, \"Month\" DESC;"); if ($this->ShowLastYears == 0) { $cutOffYear = 0; } else { $cutOffYear = (int) date("Y") - $this->ShowLastYears; } $years = array(); if (Director::get_current_page()->ClassName == 'BlogHolder') { $urlParams = Director::urlParams(); $yearParam = $urlParams['ID']; $monthParam = $urlParams['OtherID']; } else { $date = new DateTime(Director::get_current_page()->Date); $yearParam = $date->format("Y"); $monthParam = $date->format("m"); } if ($sqlResults) { foreach ($sqlResults as $sqlResult) { $isMonthDisplay = true; $year = $sqlResult['Year'] ? (int) $sqlResult['Year'] : date('Y'); $isMonthDisplay = $year > $cutOffYear; // $dateFormat = 'Month'; else $dateFormat = 'Year'; $monthVal = isset($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1; $month = $isMonthDisplay ? $monthVal : 1; $date = DBField::create('Date', array('Day' => 1, 'Month' => $month, 'Year' => $year)); if ($isMonthDisplay) { $link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal); } else { $link = $container->Link('date') . '/' . $sqlResult['Year']; } if ($isMonthDisplay || !$isMonthDisplay && !in_array($year, $years)) { $years[] = $year; $current = false; $children = new DataObjectSet(); $LinkingMode = "link"; if ($isMonthDisplay && $yearParam == $year && $monthParam == $month || !$isMonthDisplay && $yearParam == $year) { $LinkingMode = "current"; $current = true; if ($this->ShowChildren && $isMonthDisplay) { $filter = $yearclause . ' = ' . $year . ' AND ' . $monthclause . ' = ' . $month; $children = DataObject::get('BlogEntry', $filter, "Date DESC"); } } $results->push(new ArrayData(array('Date' => $date, 'Year' => $year, 'Link' => $link, 'NoMonth' => !$isMonthDisplay, 'LinkingMode' => $LinkingMode, 'Children' => $children))); unset($children); } } } return $results; }
function Dates() { Requirements::themedCSS('archivewidget'); $results = new DataObjectSet(); $container = BlogTree::current(); $ids = $container->BlogHolderIDs(); $stage = Versioned::current_stage(); $suffix = !$stage || $stage == 'Stage' ? "" : "_{$stage}"; $monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")'; $yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")'; if ($this->DisplayMode == 'month') { $sqlResults = DB::query("\n\t\t\t\tSELECT DISTINCT CAST({$monthclause} AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", {$yearclause} AS \"Year\"\n\t\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\t\tORDER BY \"Year\" DESC, \"Month\" DESC;"); } else { $sqlResults = DB::query("\n\t\t\t\tSELECT DISTINCT {$yearclause} AS \"Year\" \n\t\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\t\tORDER BY \"Year\" DESC"); } if ($sqlResults) { foreach ($sqlResults as $sqlResult) { $isMonthDisplay = $this->DisplayMode == 'month'; $monthVal = isset($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1; $month = $isMonthDisplay ? $monthVal : 1; $year = $sqlResult['Year'] ? (int) $sqlResult['Year'] : date('Y'); $date = DBField::create('Date', array('Day' => 1, 'Month' => $month, 'Year' => $year)); if ($isMonthDisplay) { $link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal); } else { $link = $container->Link('date') . '/' . $sqlResult['Year']; } $results->push(new ArrayData(array('Date' => $date, 'Link' => $link))); } } return $results; }
/** * Return an absolute URL based on the BlogHolder * that this widget is located on. * * @return string */ function RSSLink() { Requirements::themedCSS('subscribersswidget'); $container = BlogTree::current(); if ($container) { return $container->Link() . 'rss'; } }
function TagsCollection() { Requirements::themedCSS("tagcloud"); $allTags = array(); $max = 0; $container = BlogTree::current(); $entries = $container->Entries(); if ($entries) { foreach ($entries as $entry) { $theseTags = split(" *, *", mb_strtolower(trim($entry->Tags))); foreach ($theseTags as $tag) { if ($tag != "") { $allTags[$tag] = isset($allTags[$tag]) ? $allTags[$tag] + 1 : 1; //getting the count into key => value map $max = $allTags[$tag] > $max ? $allTags[$tag] : $max; } } } if ($allTags) { //TODO: move some or all of the sorts to the database for more efficiency if ($this->Limit > 0) { $allTags = array_slice($allTags, 0, $this->Limit, true); } if ($this->Sortby == "alphabet") { $this->natksort($allTags); } else { uasort($allTags, array($this, "column_sort_by_popularity")); // sort by frequency } $sizes = array(); foreach ($allTags as $tag => $count) { $sizes[$count] = true; } $offset = 0; $numsizes = count($sizes) - 1; //Work out the number of different sizes $buckets = count(self::$popularities) - 1; // If there are more frequencies than buckets, divide frequencies into buckets if ($numsizes > $buckets) { $numsizes = $buckets; } else { $offset = round(($buckets - $numsizes) / 2); } foreach ($allTags as $tag => $count) { $popularity = round($count / $max * $numsizes) + $offset; $popularity = min($buckets, $popularity); $class = self::$popularities[$popularity]; $allTags[$tag] = array("Tag" => $tag, "Count" => $count, "Class" => $class, "Link" => $container->Link('tag') . '/' . urlencode($tag)); } } $output = new DataObjectSet(); foreach ($allTags as $tag => $fields) { $output->push(new ArrayData($fields)); } return $output; } return; }
function getBlogCategoryCloud($limit = 10) { $container = BlogTree::current(); $cloud = BlogCategoryCloud::create(); if (Config::inst()->get('BlogCategory', 'limit_to_holder')) { $cloud->setHolderId($container->ID); } if ($limit) { $cloud->setLimit($limit); } if ($this->Limit >= 1) { $cloud->setLimit($this->Limit); } return $cloud; }
function PostLink() { $container = BlogTree::current(); return $container && $container->ClassName != "BlogTree" ? $container->Link('post') : false; }
function testGettingAssociatedBlogTree() { $this->assertEquals(BlogTree::current($this->objFromFixture('BlogTree', 'root'))->Title, 'Root BlogTree'); $this->assertEquals(BlogTree::current($this->objFromFixture('BlogHolder', 'levelaa_blog2'))->Title, 'Level AA Blog 2'); $this->assertEquals(BlogTree::current($this->objFromFixture('BlogEntry', 'testpost3'))->Title, 'Level BA Blog'); }