<commit_before><?php

/*
 * This file is part of Fork CMS.
 *
 * For the full copyright and license information, please view the license
 * file that was distributed with this source code.
 */

/**
 * This is the archive-action
 *
 * @author <NAME> <<EMAIL>>
 */
class FrontendBlogArchive extends FrontendBaseBlock
{
	/**
	 * The articles
	 *
	 * @var	array
	 */
	private $items;

	/**
	 * The dates for the archive
	 *
	 * @var	int
	 */
	private $startDate, $endDate;

	/**
	 * The pagination array
	 * It will hold all needed parameters, some of them need initialization
	 *
	 * @var	array
	 */
	protected $pagination = array('limit' => 10, 'offset' => 0, 'requested_page' => 1, 'num_items' => null, 'num_pages' => null);

	/**
	 * The requested year and month
	 *
	 * @var	int
	 */
	private $year, $month;

	/**
	 * Execute the extra
	 */
	public function execute()
	{
		parent::execute();
		$this->loadTemplate();
		$this->getData();
		$this->parse();
	}

	/**
	 * 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('knowledgebase', '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);<commit_msg>Fixed the blog archive, which redirected to a false (or non-existent) url if the parameters were invalid<commit_after><?php

/*
 * This file is part of Fork CMS.
 *
 * For the full copyright and license information, please view the license
 * file that was distributed with this source code.
 */

/**
 * This is the archive-action
 *
 * @author <NAME> <<EMAIL>>
 */
class FrontendBlogArchive extends FrontendBaseBlock
{
	/**
	 * The articles
	 *
	 * @var	array
	 */
	private $items;

	/**
	 * The dates for the archive
	 *
	 * @var	int
	 */
	private $startDate, $endDate;

	/**
	 * The pagination array
	 * It will hold all needed parameters, some of them need initialization
	 *
	 * @var	array
	 */
	protected $pagination = array('limit' => 10, 'offset' => 0, 'requested_page' => 1, 'num_items' => null, 'num_pages' => null);

	/**
	 * The requested year and month
	 *
	 * @var	int
	 */
	private $year, $month;

	/**
	 * Execute the extra
	 */
	public function execute()
	{
		parent::execute();
		$this->loadTemplate();
		$this->getData();
		$this->parse();
	}

	/**
	 * 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);
{'fraction_non_alphanumeric': 0.18673647469458987, 'fraction_numerical': 0.02050610820244328, 'mean_word_length': 3.5127952755905514, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3420951', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1519, 'n_words': 401}