Exemplo n.º 1
0
 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;
 }
 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;
 }
Exemplo n.º 3
0
 /**
  * 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';
     }
 }
Exemplo n.º 4
0
 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;
 }
 public function getBlogCategoriesMoreLink()
 {
     if (Config::inst()->get('BlogCategory', 'limit_to_holder')) {
         $parent = $this->owner->Parent();
     } else {
         $parent = BlogTree::get()->filter('ClassName', 'BlogTree')->First();
         if (!$parent) {
             $parent = BlogHolder::get()->First();
         }
     }
     return $parent->Link('categoryindex');
 }
 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;
 }
Exemplo n.º 7
0
 /**
  * Create default blog setup
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $blogHolder = DataObject::get_one('BlogHolder');
     //TODO: This does not check for whether this blogholder is an orphan or not
     if (!$blogHolder) {
         $blogholder = new BlogHolder();
         $blogholder->Title = "Blog";
         $blogholder->URLSegment = "blog";
         $blogholder->Status = "Published";
         $widgetarea = new WidgetArea();
         $widgetarea->write();
         $blogholder->SideBarID = $widgetarea->ID;
         $blogholder->write();
         $blogholder->publish("Stage", "Live");
         $managementwidget = new BlogManagementWidget();
         $managementwidget->ParentID = $widgetarea->ID;
         $managementwidget->write();
         $tagcloudwidget = new TagCloudWidget();
         $tagcloudwidget->ParentID = $widgetarea->ID;
         $tagcloudwidget->write();
         $archivewidget = new ArchiveWidget();
         $archivewidget->ParentID = $widgetarea->ID;
         $archivewidget->write();
         $widgetarea->write();
         $blog = new BlogEntry();
         $blog->Title = _t('BlogHolder.SUCTITLE', "SilverStripe blog module successfully installed");
         $blog->URLSegment = 'sample-blog-entry';
         $blog->Tags = _t('BlogHolder.SUCTAGS', "silverstripe, blog");
         $blog->Content = _t('BlogHolder.SUCCONTENT', "<p>Congratulations, the SilverStripe blog module has been successfully installed. This blog entry can be safely deleted. You can configure aspects of your blog (such as the widgets displayed in the sidebar) in <a href=\"admin\">the CMS</a>.</p>");
         $blog->Status = "Published";
         $blog->ParentID = $blogholder->ID;
         $blog->write();
         $blog->publish("Stage", "Live");
         DB::alteration_message("Blog page created", "created");
     }
 }
 function PostLink()
 {
     $container = BlogTree::current();
     return $container && $container->ClassName != "BlogTree" ? $container->Link('post') : false;
 }
Exemplo n.º 9
0
 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');
 }
 /**
  * @return BlogHolder
  */
 protected function getHolder($record)
 {
     $filter = new URLSegmentFilter();
     $urlSegment = $filter->filter($record['blog_path']);
     $tree = $this->_cache_tree;
     if (!$tree) {
         $tree = BlogTree::get()->filter(array('Title' => 'Blogs'))->First();
         if (!$tree) {
             $tree = new BlogTree(array('Title' => 'Blogs', 'ParentID' => $this->parentId));
             $tree->write();
             if ($this->publish) {
                 $tree->publish('Stage', 'Live');
             }
         }
         $this->_cache_tree = $tree;
     }
     $holder = isset($this->_cache_holders[$urlSegment]) ? $this->_cache_holders[$urlSegment] : null;
     if (!$holder) {
         $holder = BlogHolder::get()->filter(array('URLSegment' => $urlSegment, 'ParentID' => $tree->ID))->First();
         if (!$holder) {
             $holder = new BlogHolder(array('Title' => $record['blog_title'], 'URLSegment' => $urlSegment, 'ParentID' => $tree->ID));
             $holder->write();
             if ($this->publish) {
                 $holder->publish('Stage', 'Live');
             }
         }
         $this->_cache_holders[$urlSegment] = $holder;
     }
     return $holder;
 }