<commit_before><?php
/*------------------------------------------------------------------------------
    File: php/classes/TemplateEngine.class.php
 Project: MUN Computer Science Society Website
 Version: 0.1.0
      By: <NAME>
 Website: http://society.cs.mun.ca
   Email: <EMAIL>
 Purpose: Class that extends dwoo object and sets some default data and
          settings.
 Depends: Dwoo Template Engine
------------------------------------------------------------------------------*/

class TemplateEngine {

	private static $template_dir;
	private static $debug_flag = false;
	
	// the instance of this class, used similar to a singleton
	private static $instance;
	// this is a singleton like class
	private function __construct(){}

	// initiate this class
	public static function init($template_dir = null, $compiled_dir = null, $cache_dir = null) {
		if (!self::$instance instanceof DwooEngine) {


			if($template_dir != null){
				self::$template_dir = $template_dir;
			}
			else{
				self::$template_dir = realpath(dirname(__FILE__) .
				                               '/../templates/');
			}
			self::$instance = new DwooEngine(self::$template_dir);
			
			if($cache_dir != null){
				self::$instance->setCacheDir($cache_dir);
			}
			
			if($compiled_dir != null){
				self::$instance->setCompileDir($compiled_dir);
			}
		}
	}
	
	// put the template engine into debug mode
	public static function setDebug(){
		self::$debug_flag = true;
		if (self::$instance instanceof DwooEngine) {
			self::$instance->setDebug();
		}
	}

	// create a template from a template file name
	public static function templateFromFile($name, $cache_time = null,
	                                      $cache_id = null, $compile_id = null){
	    self::init();
		if(self::$debug_flag){
			$cache_time = 0;
		}
		
		if(is_null($compile_id)){
			$compile_id = str_replace('/', '_', $name);
		}
		
		if(file_exists(self::$template_dir . $name . '.dwoo')){
		    $file = self::$template_dir . $name . '.dwoo';
		}
		else{
			throw new NoTemplateException('No template found ' . $name .
			                 '.dwoo from ' . self::$template_dir, E_USER_ERROR);
		}
		return new Dwoo_Template_File($file, $cache_time, $cache_id,
		                              $compile_id);
	}

	// create a template from a template as a string, great for loading
	// templates from a database
	public static function templateFromString($template, $cache_time = null,
	                                      $cache_id = null, $compile_id = null){
	    self::init();
		if(self::$debug_flag){
			$cache_time = 0;
		}
	                                      
		if(is_null($compile_id)){
			$compile_id = str_replace('/', '_', $name);
		}<commit_msg>Added a template exists method to the template class<commit_after><?php
/*------------------------------------------------------------------------------
    File: php/classes/TemplateEngine.class.php
 Project: MUN Computer Science Society Website
 Version: 0.1.0
      By: <NAME>
 Website: http://society.cs.mun.ca
   Email: <EMAIL>
 Purpose: Class that extends dwoo object and sets some default data and
          settings.
 Depends: Dwoo Template Engine
------------------------------------------------------------------------------*/

class TemplateEngine {

	private static $template_dir;
	private static $debug_flag = false;
	
	// the instance of this class, used similar to a singleton
	private static $instance;
	// this is a singleton like class
	private function __construct(){}

	// initiate this class
	public static function init($template_dir = null, $compiled_dir = null, $cache_dir = null) {
		if (!self::$instance instanceof DwooEngine) {


			if($template_dir != null){
				self::$template_dir = $template_dir;
			}
			else{
				self::$template_dir = realpath(dirname(__FILE__) .
				                               '/../templates/');
			}
			self::$instance = new DwooEngine(self::$template_dir);
			
			if($cache_dir != null){
				self::$instance->setCacheDir($cache_dir);
			}
			
			if($compiled_dir != null){
				self::$instance->setCompileDir($compiled_dir);
			}
		}
	}
	
	// put the template engine into debug mode
	public static function setDebug(){
		self::$debug_flag = true;
		if (self::$instance instanceof DwooEngine) {
			self::$instance->setDebug();
		}
	}

	
	// check if a template exists
	public static function templateExists($name){
		return file_exists(self::$template_dir . $name . '.dwoo');
	}
	
	
	// create a template from a template file name
	public static function templateFromFile($name, $cache_time = null,
	                                      $cache_id = null, $compile_id = null){
	    self::init();
		if(self::$debug_flag){
			$cache_time = 0;
		}
		
		if(is_null($compile_id)){
			$compile_id = str_replace('/', '_', $name);
		}
		
		if(file_exists(self::$template_dir . $name . '.dwoo')){
		    $file = self::$template_dir . $name . '.dwoo';
		}
		else{
			throw new NoTemplateException('No template found ' . $name .
			                 '.dwoo from ' . self::$template_dir, E_USER_ERROR);
		}
		return new Dwoo_Template_File($file, $cache_time, $cache_id,
		                              $compile_id);
	}
	
	// create a template from a template as a string, great for loading
	// templates from a database
	public static function templateFromString($template, $cache_time = null,
	                                      $cache_id = null, $compile_id = null){
	    self::init();
		if(self::$debug_flag){
			$cache_time = 0;
		}
	                                      
		if(is_null($compile_id)){
			$compile_id = str_replace('/', '_', $name);
		}
{'fraction_non_alphanumeric': 0.17736185383244207, 'fraction_numerical': 0.0017825311942959, 'mean_word_length': 2.2007986309184258, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '349387', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1604, 'n_words': 421}