<commit_before><?php
/**
 * xBoilerplate: Xodoa Boilerplate package
 *
 * @category Xodoa
 * @package  xBoilerplate
 * @copyright Copyright (c) 2007-2012 Xodoa (http://xodoa.com)
 * @author   <NAME> <<EMAIL>>
 **/

class xBoilerplate {

	/**
	 * @var string Page title
	 */
	public $title = null;

	/**
	 * @var string Page description
	 */
	public $description = null;

	/**
	 * @var string Page keywords
	 */
	public $keywords = null;

	protected $_params = array();

	/**
	 * @var string Base path to load content files
	 */
	protected $_basePath = '';

	/**
	 * @var array Config array
	 */
	protected $_config = null;

	/**
	 * @param string $page Page path
	 * @param array $params Params list
	 */
	public function __construct($page, $params) {
		// Remove first slash
		$page = substr($page, 1);

		// Removes slash at the end
		if (substr($page, -1, 1) == '/') {
			$page = substr($page, 0, strlen($page) - 1);
		}

		// Default page is always index
		if (empty($page)) {
			$page = 'index';
		}

		$this->_page = $page;
		$this->_params = $params;

		// Content is loaded from httpdocs
		$this->_basePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'httpdocs' . DIRECTORY_SEPARATOR;
	}

	/**
	 * Renders the page template
	 *
	 * @return string Returns the rendered page
	 */
	public function render() {

		try {
			$body = $this->loadLayout('template.php');
		} catch(UnexpectedValueException $e) {
			$this->_page = 'page-not-found';
			$body = $this->loadLayout('template.php');
		}

		if ($this->getConfig()->raw) {
			$page = $this->loadPage();
		} else {
			// Template has be loaded first to set title, description, keywords first
			$header = $this->loadLayout('header.php');
			$footer = $this->loadLayout('footer.php');

			$page = $header . $body . $footer;
		}

		return $page;
	}

	/**
	 * Loads the content of the given component. Component path without .php
	 *
	 * @param string $component Component path / name
	 * @return string
	 */
	public function loadComponent($component) {
		$file = 'component/' . $component . '.php';
		return $this->_loadFile($file);
	}

	/**
	 * Loads the content for a specific page
	 *
	 * If the page is not found, content of page page-not-found is returned
	 *
	 * @return string Page content
	 */
	public function loadPage() {
		$file = 'page/' . $this->_page . '.php';
		return $this->_loadFile($file);
	}

	/**
	 * Loads a file relative to the base path
	 *
	 * @param strin $file Path to file
	 * @return string
	 * @throws Exception If invalid file
	 */
	protected function _loadFile($file) {
		// TODO: add more security checks
		if (strpos($file, '..') !== false || substr($file, 0, 1) == '/') {
			throw new UnexpectedValueException('Invalid file path:' . $file);
		}

		$file = $this->_basePath . $file;

		if (!file_exists($file)) {
			throw new UnexpectedValueException('File does not exist: ' . $file);
		}

		ob_start();
		include($file);
		$content = ob_get_contents();
		ob_end_clean();

		return $content;
	}

	public function getCategory($category = '') {
		$c = $this->_getParam('c');

		if (!empty($category)) {
			$c = $category;
		}

		if (empty($c)) {
			$c = 'index';
		}

		// For security reasons
		$c = $this->_filterParam($c);

		return $c;
	}

	/**
	 * Loads layout files
	 *
	 * @param string $name Loads a layout file
	 * @return string Layout content
	 */<commit_msg>getCategory removed as not needed anymore<commit_after><?php
/**
 * xBoilerplate: Xodoa Boilerplate package
 *
 * @category Xodoa
 * @package  xBoilerplate
 * @copyright Copyright (c) 2007-2012 Xodoa (http://xodoa.com)
 * @author   <NAME> <<EMAIL>>
 **/

class xBoilerplate {

	/**
	 * @var string Page title
	 */
	public $title = null;

	/**
	 * @var string Page description
	 */
	public $description = null;

	/**
	 * @var string Page keywords
	 */
	public $keywords = null;

	protected $_params = array();

	/**
	 * @var string Base path to load content files
	 */
	protected $_basePath = '';

	/**
	 * @var array Config array
	 */
	protected $_config = null;

	/**
	 * @param string $page Page path
	 * @param array $params Params list
	 */
	public function __construct($page, $params) {
		// Remove first slash
		$page = substr($page, 1);

		// Removes slash at the end
		if (substr($page, -1, 1) == '/') {
			$page = substr($page, 0, strlen($page) - 1);
		}

		// Default page is always index
		if (empty($page)) {
			$page = 'index';
		}

		$this->_page = $page;
		$this->_params = $params;

		// Content is loaded from httpdocs
		$this->_basePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'httpdocs' . DIRECTORY_SEPARATOR;
	}

	/**
	 * Renders the page template
	 *
	 * @return string Returns the rendered page
	 */
	public function render() {

		try {
			$body = $this->loadLayout('template.php');
		} catch(UnexpectedValueException $e) {
			$this->_page = 'page-not-found';
			$body = $this->loadLayout('template.php');
		}

		if ($this->getConfig()->raw) {
			$page = $this->loadPage();
		} else {
			// Template has be loaded first to set title, description, keywords first
			$header = $this->loadLayout('header.php');
			$footer = $this->loadLayout('footer.php');

			$page = $header . $body . $footer;
		}

		return $page;
	}

	/**
	 * Loads the content of the given component. Component path without .php
	 *
	 * @param string $component Component path / name
	 * @return string
	 */
	public function loadComponent($component) {
		$file = 'component/' . $component . '.php';
		return $this->_loadFile($file);
	}

	/**
	 * Loads the content for a specific page
	 *
	 * If the page is not found, content of page page-not-found is returned
	 *
	 * @return string Page content
	 */
	public function loadPage() {
		$file = 'page/' . $this->_page . '.php';
		return $this->_loadFile($file);
	}

	/**
	 * Loads a file relative to the base path
	 *
	 * @param strin $file Path to file
	 * @return string
	 * @throws Exception If invalid file
	 */
	protected function _loadFile($file) {
		// TODO: add more security checks
		if (strpos($file, '..') !== false || substr($file, 0, 1) == '/') {
			throw new UnexpectedValueException('Invalid file path:' . $file);
		}

		$file = $this->_basePath . $file;

		if (!file_exists($file)) {
			throw new UnexpectedValueException('File does not exist: ' . $file);
		}

		ob_start();
		include($file);
		$content = ob_get_contents();
		ob_end_clean();

		return $content;
	}

	/**
	 * Loads layout files
	 *
	 * @param string $name Loads a layout file
	 * @return string Layout content
	 */
{'fraction_non_alphanumeric': 0.15850277264325324, 'fraction_numerical': 0.0046210720887245845, 'mean_word_length': 3.0379353233830844, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '4512771', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2056, 'n_words': 625}