<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.
 */

/**
 * FrontendAJAX
 * This class will handle AJAX-related stuff
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class FrontendAJAX extends KernelLoader implements ApplicationInterface
{
	/**
	 * The action
	 *
	 * @var	string
	 */
	private $action;

	/**
	 * @var FrontendAJAXAction
	 */
	private $ajaxAction;

	/**
	 * The language
	 *
	 * @var	string
	 */
	private $language;

	/**
	 * The module
	 *
	 * @var	string
	 */
	private $module;

	/**
	 * @return Symfony\Component\HttpFoundation\Response
	 */
	public function display()
	{
		return $this->ajaxAction->execute();
	}

	/**
	 * This method exists because the service container needs to be set before
	 * the request's functionality gets loaded.
	 */
	public function initialize()
	{
		// get vars
		$module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : '';
		if($module == '' && isset($_GET['module'])) $module = $_GET['module'];
		$action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : '';
		if($action == '' && isset($_GET['action'])) $action = $_GET['action'];
		$language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : '';
		if($language == '' && isset($_GET['language'])) $language = $_GET['language'];
		if($language == '') $language = SITE_DEFAULT_LANGUAGE;

		try
		{
			$this->setModule($module);
			$this->setAction($action);
			$this->setLanguage($language);

			$this->ajaxAction = new FrontendAJAXAction($this->getAction(), $this->getModule());
		}

		catch(Exception $e)
		{
			$this->ajaxAction = new FrontendBaseAJAXAction('', '');
			$this->ajaxAction->output(FrontendBaseAJAXAction::ERROR, null, $e->getMessage());
		}
	}

	/**
	 * Get the loaded action
	 *
	 * @return string
	 */
	public function getAction()
	{
		return $this->action;
	}

	/**
	 * Get the loaded module
	 *
	 * @return string
	 */
	public function getModule()
	{
		return $this->module;
	}

	/**<commit_msg>FrontendAjax: call execute inside the trycatch to catch exceptions thrown by the action itself<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.
 */

/**
 * FrontendAJAX
 * This class will handle AJAX-related stuff
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class FrontendAJAX extends KernelLoader implements ApplicationInterface
{
	/**
	 * The action
	 *
	 * @var	string
	 */
	private $action;

	/**
	 * @var FrontendAJAXAction
	 */
	private $ajaxAction;

	/**
	 * The language
	 *
	 * @var	string
	 */
	private $language;

	/**
	 * The module
	 *
	 * @var	string
	 */
	private $module;

	/**
	 * Output generated by the action.
	 *
	 * @var array
	 */
	private $output;

	/**
	 * @return array
	 */
	public function display()
	{
		return $this->output;
	}

	/**
	 * This method exists because the service container needs to be set before
	 * the request's functionality gets loaded.
	 */
	public function initialize()
	{
		// get vars
		$module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : '';
		if($module == '' && isset($_GET['module'])) $module = $_GET['module'];
		$action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : '';
		if($action == '' && isset($_GET['action'])) $action = $_GET['action'];
		$language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : '';
		if($language == '' && isset($_GET['language'])) $language = $_GET['language'];
		if($language == '') $language = SITE_DEFAULT_LANGUAGE;

		try
		{
			$this->setModule($module);
			$this->setAction($action);
			$this->setLanguage($language);

			$this->ajaxAction = new FrontendAJAXAction($this->getAction(), $this->getModule());
			$this->output = $this->ajaxAction->execute();
		}

		catch(Exception $e)
		{
			$this->ajaxAction = new FrontendBaseAJAXAction('', '');
			$this->ajaxAction->output(FrontendBaseAJAXAction::ERROR, null, $e->getMessage());
			$this->output = $this->ajaxAction->execute();
		}
	}

	/**
	 * Get the loaded action
	 *
	 * @return string
	 */
	public function getAction()
	{
		return $this->action;
	}

	/**
	 * Get the loaded module
	 *
	 * @return string
	 */
	public function getModule()
	{
		return $this->module;
	}

	/**
{'fraction_non_alphanumeric': 0.18719859710653222, 'fraction_numerical': 0.0, 'mean_word_length': 3.675204918032787, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 60, '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': '3076345', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1417, 'n_words': 356}