<commit_before><?php
namespace wCommon;
/**
* Subclasses that expand the functionality of HTML_Template_Sigma.
*
* @copyright 2014-2015 <NAME>
*
* @license http://www.opensource.org/licenses/mit-license.html
*
* @author <NAME>
* @created 2014-03-04
*
* @version 1.0
*
*/

require_once 'HTML/Template/Sigma.php';

define('g_PAGE_TITLE', 'g_PAGE_TITLE');

function setPageTitle($title) { $GLOBALS[g_PAGE_TITLE] = $title; }

/** A subclass of HTML_Template_Sigma that adds some very convenient methods. */
class Template extends \HTML_Template_Sigma {

	/**
	* Constructor for Template.
	* It loads the template file $tfile.
	* Subclasses should override and provide defaults for $tdir and $cdir.
	* @param string $tfile template file
	* @param string $tdir template directory
	* @param string $cdir cache directory
	*/
	function __construct($tfile, $tdir, $cdir=null) {
		parent::__construct($tdir, $cdir);
		$this->loadTemplateFile($tfile);
	}

	/**
	* Sets variables and parses a block.
	* By default this parses the block, meaning placeholder variables are replaced and the block is written out.
	* You can prevent that with the $doParse parameter, for situations where you need to replace variables but delay parsing.
	* @param string $block the block in the template to parse; if `null`, the __global__ block will be used
	* @param array $varArray array of block variables mapped to replacement strings
	* @param bool $doParse indicates whether or not to parse the block
	*/
	function parseBlock($block, $varArray=null, $doParse=true) { // sets variables and parses the block
		if (!$block) { $block = '__global__'; }
		$this->setCurrentBlock($block);
		if (!is_null($varArray)) { $this->setVariable($varArray); }
		if ($doParse) { $this->parseCurrentBlock(); }
	}

	/**
	* Sets block variables but skips parsing.
	* @param string $block the block in the template to parse; if `null`, the __global__ block will be used
	* @param array $varArray array of block variables mapped to replacement strings
	*/
	function setBlockVariables($block, $varArray=null) {
		$this->parseBlock($block, $varArray, false);
	}

}

/** A subclass of Template that includes more convenience methods for common page elements. See the file `template.tmpl` for a sample template that works with these methods. */
class wTemplate extends Template {

	const SKEY_ERROR = 'tmpl-error';
	const SKEY_CONFIRM = 'tmpl-confirm';

	const CLASS_CP = '\wCommon\wHTMLComposer';

	public $cp; // A composer object for use by the template.

	/** Initializes the template and checks for any error or confirmation messages to be displayed. */
	function __construct($tfile, $tdir, $cdir=null) {
		parent::__construct($tfile, $tdir, $cdir);
		$cpClass = static::CLASS_CP;
		$this->cp = new $cpClass();
		$page_title = $this->getPageTitle();
		$this->setBlockVariables(null, [ 'HEAD-TITLE'=>$page_title, ]);
		if ($_SESSION[self::SKEY_ERROR]) { foreach ($_SESSION[self::SKEY_ERROR] as $msg) { $this->displayMessage($msg, 'error'); } unset($_SESSION[self::SKEY_ERROR]); }
		if ($_SESSION[self::SKEY_CONFIRM]) { foreach ($_SESSION[self::SKEY_CONFIRM] as $msg) { $this->displayMessage($msg); } unset($_SESSION[self::SKEY_CONFIRM]); }
	}

	function show() {
		if ($this->onloads) { $this->parseBlock('BLK-ONLOADS', [ 'ONLOAD'=>implode(' ', $this->onloads), ]); }
		parent::show();
	}

	function getPageTitle() {
		return $GLOBALS[g_PAGE_TITLE];<commit_msg>made template's show() method consistent with parent class<commit_after><?php
namespace wCommon;
/**
* Subclasses that expand the functionality of HTML_Template_Sigma.
*
* @copyright 2014-2015 <NAME>
*
* @license http://www.opensource.org/licenses/mit-license.html
*
* @author <NAME>
* @created 2014-03-04
*
* @version 1.0
*
*/

require_once 'HTML/Template/Sigma.php';

define('g_PAGE_TITLE', 'g_PAGE_TITLE');

function setPageTitle($title) { $GLOBALS[g_PAGE_TITLE] = $title; }

/** A subclass of HTML_Template_Sigma that adds some very convenient methods. */
class Template extends \HTML_Template_Sigma {

	/**
	* Constructor for Template.
	* It loads the template file $tfile.
	* Subclasses should override and provide defaults for $tdir and $cdir.
	* @param string $tfile template file
	* @param string $tdir template directory
	* @param string $cdir cache directory
	*/
	function __construct($tfile, $tdir, $cdir=null) {
		parent::__construct($tdir, $cdir);
		$this->loadTemplateFile($tfile);
	}

	/**
	* Sets variables and parses a block.
	* By default this parses the block, meaning placeholder variables are replaced and the block is written out.
	* You can prevent that with the $doParse parameter, for situations where you need to replace variables but delay parsing.
	* @param string $block the block in the template to parse; if `null`, the __global__ block will be used
	* @param array $varArray array of block variables mapped to replacement strings
	* @param bool $doParse indicates whether or not to parse the block
	*/
	function parseBlock($block, $varArray=null, $doParse=true) { // sets variables and parses the block
		if (!$block) { $block = '__global__'; }
		$this->setCurrentBlock($block);
		if (!is_null($varArray)) { $this->setVariable($varArray); }
		if ($doParse) { $this->parseCurrentBlock(); }
	}

	/**
	* Sets block variables but skips parsing.
	* @param string $block the block in the template to parse; if `null`, the __global__ block will be used
	* @param array $varArray array of block variables mapped to replacement strings
	*/
	function setBlockVariables($block, $varArray=null) {
		$this->parseBlock($block, $varArray, false);
	}

}

/** A subclass of Template that includes more convenience methods for common page elements. See the file `template.tmpl` for a sample template that works with these methods. */
class wTemplate extends Template {

	const SKEY_ERROR = 'tmpl-error';
	const SKEY_CONFIRM = 'tmpl-confirm';

	const CLASS_CP = '\wCommon\wHTMLComposer';

	public $cp; // A composer object for use by the template.

	/** Initializes the template and checks for any error or confirmation messages to be displayed. */
	function __construct($tfile, $tdir, $cdir=null) {
		parent::__construct($tfile, $tdir, $cdir);
		$cpClass = static::CLASS_CP;
		$this->cp = new $cpClass();
		$page_title = $this->getPageTitle();
		$this->setBlockVariables(null, [ 'HEAD-TITLE'=>$page_title, ]);
		if ($_SESSION[self::SKEY_ERROR]) { foreach ($_SESSION[self::SKEY_ERROR] as $msg) { $this->displayMessage($msg, 'error'); } unset($_SESSION[self::SKEY_ERROR]); }
		if ($_SESSION[self::SKEY_CONFIRM]) { foreach ($_SESSION[self::SKEY_CONFIRM] as $msg) { $this->displayMessage($msg); } unset($_SESSION[self::SKEY_CONFIRM]); }
	}

	function show($block = '__global__') {
		if ($this->onloads) { $this->parseBlock('BLK-ONLOADS', [ 'ONLOAD'=>implode(' ', $this->onloads), ]); }
		parent::show($block);
	}

	function getPageTitle() {
		return $GLOBALS[g_PAGE_TITLE];
{'fraction_non_alphanumeric': 0.1345707656612529, 'fraction_numerical': 0.005220417633410673, 'mean_word_length': 4.945689655172414, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1248088', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2150, 'n_words': 679}