/** * Load the data, don't forget to validate the incoming data */ private function getData() { // get parameters $this->year = $this->URL->getParameter(1); $this->month = $this->URL->getParameter(2); // redirect /2010/6 to /2010/06 to avoid duplicate content if ($this->month !== null && mb_strlen($this->month) != 2) { $queryString = isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''; $this->redirect(FrontendNavigation::getURLForBlock('Blog', 'Archive') . '/' . $this->year . '/' . str_pad($this->month, 2, '0', STR_PAD_LEFT) . $queryString, 301); } if (mb_strlen($this->year) != 4) { $this->redirect(FrontendNavigation::getURL(404)); } // redefine $this->year = (int) $this->year; if ($this->month !== null) { $this->month = (int) $this->month; } // validate parameters if ($this->year == 0 || $this->month === 0) { $this->redirect(FrontendNavigation::getURL(404)); } // requested page $requestedPage = $this->URL->getParameter('page', 'int', 1); // rebuild url $url = $this->year; // build timestamp if ($this->month !== null) { $this->startDate = gmmktime(00, 00, 00, $this->month, 01, $this->year); $this->endDate = gmmktime(23, 59, 59, $this->month, gmdate('t', $this->startDate), $this->year); $url .= '/' . str_pad($this->month, 2, '0', STR_PAD_LEFT); } else { // year $this->startDate = gmmktime(00, 00, 00, 01, 01, $this->year); $this->endDate = gmmktime(23, 59, 59, 12, 31, $this->year); } // set URL and limit $this->pagination['url'] = FrontendNavigation::getURLForBlock('Blog', 'Archive') . '/' . $url; $this->pagination['limit'] = $this->get('fork.settings')->get('Blog', 'overview_num_items', 10); // populate count fields in pagination $this->pagination['num_items'] = FrontendBlogModel::getAllForDateRangeCount($this->startDate, $this->endDate); $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']); // redirect if the request page doesn't exists if ($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) { $this->redirect(FrontendNavigation::getURL(404)); } // populate calculated fields in pagination $this->pagination['requested_page'] = $requestedPage; $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit']; // get articles $this->items = FrontendBlogModel::getAllForDateRange($this->startDate, $this->endDate, $this->pagination['limit'], $this->pagination['offset']); }