/** * calculates the array to display with the months * * @private */ function _getMonths() { $articles = new Articles(); $archiveStats = $articles->getNumberPostsPerMonthAdmin($this->_blogInfo->getId()); if (!$archiveStats) { return array(); } $result = array(); $t = new Timestamp(); $curyear = (int) $t->getYear(); $curmonth = (int) $t->getMonth(); $archiveDateFormat = $this->_locale->tr("archive_date_format"); if ($archiveDateFormat == "archive_date_format") { $archiveDateFormat = "%B %Y"; } foreach ($archiveStats as $yearName => $year) { foreach ($year as $monthName => $month) { // the next bit is so disgustingly ugly that I am ashamed of it... // what I'm trying to do here is that the getNumberPostsPerMonthAdmin() method // won't return the current month if there wasn't anything posted during it but // we still should show the current month even if there's nothing in it, because otherwise // when generating page where the posts are listed, it will end up saying "Date: All" // but no posts at all shown (it didn't have anything to show) This is a way of // "introducing" a month in the array without f*****g it up. In fact, PHP *was* // indeed f*****g it up... it didn't just want to keep the order! Oh well, it's a very // long and stupid story but we need this hack, ok? :) if ($archiveStats[$curyear][$curmonth] == "" && !$alreadyAdded) { // there goes the dirty hack :P if ($yearName == $curyear && $monthName < $curmonth) { $t = new Timestamp(); $name = $this->_locale->formatDate($t, $archiveDateFormat); $monthStr = array("name" => $name, "date" => $this->_locale->formatDate($t, "%Y%m")); array_push($result, $monthStr); $alreadyAdded = true; } } // we can use the Timestamp class to help us with this... $t = new Timestamp(""); $t->setYear($yearName); $t->setMonth($monthName); $name = $this->_locale->formatDate($t, $archiveDateFormat); $monthStr = array("name" => $name, "date" => $this->_locale->formatDate($t, "%Y%m")); array_push($result, $monthStr); } } return $result; }
/** * Fetches the stats for the archives * * @private */ function _getArchives() { $archiveStats = $this->articles->getNumberPostsPerMonth($this->_blogInfo->getId()); if ($archiveStats == '') { return false; } $links = array(); $locale = $this->_blogInfo->getLocale(); $urls = $this->_blogInfo->getBlogRequestGenerator(); // format of dates used in the archive, but it defaults to '%B %Y' if none specified $archiveDateFormat = $locale->tr('archive_date_format'); // need to check whether we got the same thing back, since that's the way Locale::tr() works instead of // returning an empty string if ($archiveDateFormat == "archive_date_format") { $archiveDateFormat = ARCHIVE_DEFAULT_DATE_FORMAT; } foreach ($archiveStats as $yearName => $year) { foreach ($year as $monthName => $month) { // we can use the Timestamp class to help us with this... $t = new Timestamp(); $t->setYear($yearName); $t->setMonth($monthName); $archiveUrl = $urls->getArchiveLink($t->getYear() . $t->getMonth()); $linkName = $locale->formatDate($t, $archiveDateFormat); $link = new ArchiveLink($linkName, '', $archiveUrl, $this->_blogInfo->getId(), 0, $month, 0); $links[] = $link; } } return $links; }