<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 detail-action
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class FrontendBlogDetail extends FrontendBaseBlock
{
	/**
	 * The comments
	 *
	 * @var	array
	 */
	private $comments;

	/**
	 * Form instance
	 *
	 * @var FrontendForm
	 */
	private $frm;

	/**
	 * The blogpost
	 *
	 * @var	array
	 */
	private $record;

	/**
	 * The settings
	 *
	 * @var	array
	 */
	private $settings;

	/**
	 * Execute the extra
	 */
	public function execute()
	{
		parent::execute();
		$this->tpl->assign('hideContentTitle', true);
		$this->loadTemplate();
		$this->getData();
		$this->loadForm();
		$this->validateForm();
		$this->parse();
	}

	/**
	 * Load the data, don't forget to validate the incoming data
	 */
	private function getData()
	{
		// validate incoming parameters
		if($this->URL->getParameter(1) === null) $this->redirect(FrontendNavigation::getURL(404));

		// load revision
		if($this->URL->getParameter('revision', 'int') != 0)
		{
			// get data
			$this->record = FrontendBlogModel::getRevision($this->URL->getParameter(1), $this->URL->getParameter('revision', 'int'));

			// add no-index, so the draft won't get accidentally indexed
			$this->header->addMetaData(array('name' => 'robots', 'content' => 'noindex, nofollow'), true);
		}

		// get by URL
		else $this->record = FrontendBlogModel::get($this->URL->getParameter(1));

		// anything found?
		if(empty($this->record)) $this->redirect(FrontendNavigation::getURL(404));

		// get comments
		$this->comments = FrontendBlogModel::getComments($this->record['id']);

		// get tags
		$this->record['tags'] = FrontendTagsModel::getForItem('blog', $this->record['id']);

		// get settings
		$this->settings = FrontendModel::getModuleSettings('blog');

		// overwrite URLs
		$this->record['category_full_url'] = FrontendNavigation::getURLForBlock('blog', 'category') . '/' . $this->record['category_url'];
		$this->record['full_url'] = FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $this->record['url'];
		$this->record['allow_comments'] = ($this->record['allow_comments'] == 'Y');
		$this->record['comments_count'] = count($this->comments);

		// reset allow comments
		if(!$this->settings['allow_comments']) $this->record['allow_comments'] = false;
	}

	/**
	 * Load the form
	 */
	private function loadForm()
	{
		// create form
		$this->frm = new FrontendForm('commentsForm');
		$this->frm->setAction($this->frm->getAction() . '#' . FL::act('Comment'));

		// init vars
		$author = (CommonCookie::exists('comment_author')) ? CommonCookie::get('comment_author') : null;
		$email = (CommonCookie::exists('comment_email') && SpoonFilter::isEmail(CommonCookie::get('comment_email'))) ? CommonCookie::get('comment_email') : null;
		$website = (CommonCookie::exists('comment_website') && SpoonFilter::isURL(CommonCookie::get('comment_website'))) ? CommonCookie::get('comment_website') : 'http://';

		// create elements
		$this->frm->addText('author', $author);
		$this->frm->addText('email', $email);
		$this->frm->addText('website', $website, null);
		$this->frm->addTextarea('message');
	}

	/**
	 * Parse the data into the template<commit_msg>Blog: use correct input-types & added required-attribute if needed<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 detail-action
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class FrontendBlogDetail extends FrontendBaseBlock
{
	/**
	 * The comments
	 *
	 * @var	array
	 */
	private $comments;

	/**
	 * Form instance
	 *
	 * @var FrontendForm
	 */
	private $frm;

	/**
	 * The blogpost
	 *
	 * @var	array
	 */
	private $record;

	/**
	 * The settings
	 *
	 * @var	array
	 */
	private $settings;

	/**
	 * Execute the extra
	 */
	public function execute()
	{
		parent::execute();
		$this->tpl->assign('hideContentTitle', true);
		$this->loadTemplate();
		$this->getData();
		$this->loadForm();
		$this->validateForm();
		$this->parse();
	}

	/**
	 * Load the data, don't forget to validate the incoming data
	 */
	private function getData()
	{
		// validate incoming parameters
		if($this->URL->getParameter(1) === null) $this->redirect(FrontendNavigation::getURL(404));

		// load revision
		if($this->URL->getParameter('revision', 'int') != 0)
		{
			// get data
			$this->record = FrontendBlogModel::getRevision($this->URL->getParameter(1), $this->URL->getParameter('revision', 'int'));

			// add no-index, so the draft won't get accidentally indexed
			$this->header->addMetaData(array('name' => 'robots', 'content' => 'noindex, nofollow'), true);
		}

		// get by URL
		else $this->record = FrontendBlogModel::get($this->URL->getParameter(1));

		// anything found?
		if(empty($this->record)) $this->redirect(FrontendNavigation::getURL(404));

		// get comments
		$this->comments = FrontendBlogModel::getComments($this->record['id']);

		// get tags
		$this->record['tags'] = FrontendTagsModel::getForItem('blog', $this->record['id']);

		// get settings
		$this->settings = FrontendModel::getModuleSettings('blog');

		// overwrite URLs
		$this->record['category_full_url'] = FrontendNavigation::getURLForBlock('blog', 'category') . '/' . $this->record['category_url'];
		$this->record['full_url'] = FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $this->record['url'];
		$this->record['allow_comments'] = ($this->record['allow_comments'] == 'Y');
		$this->record['comments_count'] = count($this->comments);

		// reset allow comments
		if(!$this->settings['allow_comments']) $this->record['allow_comments'] = false;
	}

	/**
	 * Load the form
	 */
	private function loadForm()
	{
		// create form
		$this->frm = new FrontendForm('commentsForm');
		$this->frm->setAction($this->frm->getAction() . '#' . FL::act('Comment'));

		// init vars
		$author = (CommonCookie::exists('comment_author')) ? CommonCookie::get('comment_author') : null;
		$email = (CommonCookie::exists('comment_email') && SpoonFilter::isEmail(CommonCookie::get('comment_email'))) ? CommonCookie::get('comment_email') : null;
		$website = (CommonCookie::exists('comment_website') && SpoonFilter::isURL(CommonCookie::get('comment_website'))) ? CommonCookie::get('comment_website') : 'http://';

		// create elements
		$this->frm->addText('author', $author)->setAttributes(array('required' => null));
		$this->frm->addText('email', $email)->setAttributes(array('required' => null, 'type' => 'email'));
		$this->frm->addText('website', $website, null);
		$this->frm->addTextarea('message')->setAttributes(array('required' => null));
	}

	/**
	 * Parse the data into the template
{'fraction_non_alphanumeric': 0.1979556579326231, 'fraction_numerical': 0.0028793550244745176, 'mean_word_length': 4.457187745483111, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 136, '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': '3506588', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2174, 'n_words': 443}