예제 #1
0
 public function viewAction()
 {
     if (!Mage::helper("blog")->isArchivesEnabled()) {
         $this->_forward('NoRoute');
         return;
     }
     $request = $this->getRequest();
     $date = $request->getParam("date");
     // strip off any query string parameters, and any trailing slashes
     $date = explode("?", $date);
     if (empty($date[0])) {
         $this->_forward('NoRoute');
         return;
     }
     $date = rtrim($date[0], "/");
     $dateParams = explode("/", $date);
     if (count($dateParams) == 0) {
         $this->_forward('Index');
         return;
     } elseif (count($dateParams) > 3) {
         // Stops the user from putting random strings on the end of the URL
         $this->_forward('NoRoute');
         return;
     }
     $archiveType = Fontis_Blog_Model_System_Archivetype::YEARLY;
     $year = $dateParams[0];
     if (isset($dateParams[1])) {
         $month = $dateParams[1];
         $archiveType = Fontis_Blog_Model_System_Archivetype::MONTHLY;
     } else {
         $month = 1;
     }
     if (isset($dateParams[2])) {
         $day = $dateParams[2];
         $archiveType = Fontis_Blog_Model_System_Archivetype::DAILY;
     } else {
         $day = 1;
     }
     if (!checkdate($month, $day, $year)) {
         $this->_forward("NoRoute");
         return;
     }
     $request->setParam("type", $archiveType);
     $request->setParam("date", $dateParams);
     $archiveLabel = Mage::helper("blog")->__("Archives");
     $dateString = Fontis_Blog_Model_System_Archivetype::getTypeFormat($archiveType);
     return $this->renderPage($archiveLabel . " - " . date($dateString, mktime(0, 0, 0, $month, $day, $year)));
 }
예제 #2
0
 public function getArchives()
 {
     if ($this->getBlogHelper()->isArchivesEnabled()) {
         $collection = Mage::getModel("blog/post")->getCollection()->addStoreFilter(Mage::app()->getStore()->getId())->setOrder("created_time", Mage::getStoreConfig("fontis_blog/archives/order"));
         Mage::getSingleton('blog/status')->addEnabledFilterToCollection($collection);
         $archiveType = Mage::getStoreConfig("fontis_blog/archives/type");
         if ($archiveType == Fontis_Blog_Model_System_Archivetype::YEARLY) {
             $columns = array(new Zend_Db_Expr("year(created_time) as year"));
             $group = "year(created_time)";
         } elseif ($archiveType == Fontis_Blog_Model_System_Archivetype::MONTHLY) {
             $columns = array(new Zend_Db_Expr("year(created_time) as year"), new Zend_Db_Expr("month(created_time) as month"));
             $group = "year(created_time), month(created_time)";
         } elseif ($archiveType == Fontis_Blog_Model_System_Archivetype::DAILY) {
             $columns = array(new Zend_Db_Expr("year(created_time) as year"), new Zend_Db_Expr("month(created_time) as month"), new Zend_Db_Expr("day(created_time) as day"));
             $group = "year(created_time), month(created_time), day(created_time)";
         }
         if ($this->showPostCount()) {
             $columns[] = new Zend_Db_Expr("count(main_table.post_id) as postcount");
         }
         $collection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns($columns)->group($group);
         if ($limit = Mage::getStoreConfig("fontis_blog/archives/limit")) {
             $collection->getSelect()->limit($limit);
         }
         $dateString = Fontis_Blog_Model_System_Archivetype::getTypeFormat($archiveType);
         $route = $this->getBlogHelper()->getBlogRoute();
         foreach ($collection as $item) {
             $archiveRoute = "archive/" . $item->getYear();
             if ($item->getMonth()) {
                 $archiveRoute .= "/" . $item->getMonth();
                 if ($item->getDay()) {
                     $archiveRoute .= "/" . $item->getDay();
                 }
             }
             $item->setAddress($this->getUrl($route) . $archiveRoute);
             if (!$item->getDay()) {
                 $item->setDay(1);
             }
             if (!$item->getMonth()) {
                 $item->setMonth(1);
             }
             $item->setDateString(date($dateString, mktime(0, 0, 0, $item->getMonth(), $item->getDay(), $item->getYear())));
         }
         return $collection;
     } else {
         return false;
     }
 }