<commit_before><?php
/*
 * FILE INFORMATION: 
 * $HeadURL$
 * $Id$
 * $LastChangedDate$
 * $LastChangedRevision$
 * $LastChangedBy$
 * 
 * HOW THE SYSTEM WORKS:::
 * 	TEMPLATE FILES:
 * 	Automatically loads templates based on the URL, and optionally includes scripts in the includes directory.
 * 
 * 		MAIN SECTION:
 *	 		For the main section, i.e. "/content", it requires a template in a directory of that name beneath 
 * 			/templates, with a file called "index.content.tmpl"... i.e. /templatee/content/index.content.tmpl.
 * 		SUB SECTIONS:
 * 			For any subsection to be valid, i.e. "/content/members", it must have an associated template, i.e. 
 * 			"/templates/content/members.content.tmpl". If a subdirectory with an index.content.tmpl file exists, it will
 * 			be used instead of the file in the sub directory (i.e. "/templates/content/members/index.content.tmpl").
 * 		SUB SECTION TEMPLATE INHERITANCE:
 * 			All pages load the base set of "shared" templates, which are in the form "<section>.shared.tmpl" in
 * 			the root of the templates directory.
 * 	
 * 			Shared files within each directory, in the form "<section>.shared.tmpl", will be loaded for ANY subsection.
 *	 
 *	 		For any subsection, it inherits a previous section's templates in the following manner (any "content" 
 * 			templates are ignored for inheritance, as they're require for page load).
 * 				/content							---> /templates/content/index.*.tmpl
 *	 
 * 				/content/members					|--> /templates/content/index.*.tmpl
 * 													`--> /templates/content/members.*.tmpl
 *	 
 * 				/content/members/test				|--> /templates/content/index.*.tmpl
 * 													|--> /templates/content/members.*.tmpl
 * 													|--> /templates/content/members/index.*.tmpl
 * 													`--> /templates/content/members/test.*.tmpl
 * 	AUTOMATIC INCLUDES:
 * 	Much in the same way templates are included, so are scripts, from the /includes directory, though the logic
 * 	is decidedly simpler: all scripts must have the extension of ".inc", and must have either the section's name
 * 	as the first part of the filename, or "shared".  Shared scripts will be loaded for ALL subsections.
 * 
 * 		INCLUDES INHERITANCE:
 * 			The template inheritance scheme is as laid-out below.  The content system will go as far into the
 * 			includes directory as it can for the given section, regardless of if any intermediate files are missing.
 * 
 * 			It is important to note that the content system will NOT regard a section as valid if there are include
 * 			scripts but no templates.
 * 			
 * 				/content							|--> /includes/shared.inc
 * 													`--> /includes/content.inc
 * 
 * 				/content/members					|--> /includes/shared.inc
 * 													|--> /includes/content.inc
 * 													|--> /includes/content/shared.inc
 * 													`--> /includes/content/members.inc
 * 
 * 				/content/members/test				|--> /includes/shared.inc
 * 													|--> /includes/content.inc
 * 													|--> /includes/content/shared.inc
 * 													|--> /includes/content/members.inc
 * 													|--> /includes/content/members/shared.inc
 * 													|--> /includes/content/members/test.inc
 */

//TODO: remove this terrible little hack.
if(!isset($GLOBALS['SITE_ROOT'])) {
	//define where our scripts are located.
	$GLOBALS['SITE_ROOT'] = $_SERVER['DOCUMENT_ROOT'];
	$GLOBALS['SITE_ROOT'] = str_replace("/public_html", "", $GLOBALS['SITE_ROOT']);
}

require_once(dirname(__FILE__) ."/cs_globalFunctions.php");
require_once(dirname(__FILE__) ."/cs_fileSystemClass.php");
require_once(dirname(__FILE__) ."/cs_sessionClass.php");
require_once(dirname(__FILE__) ."/cs_genericPageClass.php");
require_once(dirname(__FILE__) ."/cs_tabsClass.php");
require_once(dirname(__FILE__) ."/cs_versionAbstract.class.php");

class contentSystem extends cs_versionAbstract {
	
	protected $baseDir			= NULL;			//base directory for templates & includes.			
	protected $section			= NULL;			//section string, derived from the URL.		
	protected $sectionArr		= array();		//array of items, for figuring out where templates & includes are.
	protected $fileSystemObj	= NULL;			//the object used to access the filesystem.
	protected $ignoredList		= array(		//array of files & folders that are implicitely ignored.
									'file'	=> array('.htaccess'),
									'dir'	=> array('.svn','CVS'
									)
								);
	protected $templateList		= array();
	protected $includesList		= array();
	public $templateObj		= NULL;
	protected $gfObj			= NULL;
	protected $tabs				= NULL;
	
	protected $finalSection;
	
	private $isValid=FALSE;
	private $reason=NULL;
	
	//------------------------------------------------------------------------
	/**
	 * The CONSTRUCTOR.  Duh.
	 */
	public function __construct($testOnly=FALSE) {
		if($testOnly === 'unit_test') {
			//It's just a test, don't do anything we might regret later.
			$this->isTest = TRUE;
		}
		else {
			$this->get_version();
			$this->get_project();
			//make a cs_globalFunctions{} object.
			$this->gfObj = new cs_globalFunctions();
			
			//setup the section stuff...
			$repArr = array($_SERVER['SCRIPT_NAME'], "/");
			$_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']);
			
			//figure out the section & subsection stuff.
			$this->section = $this->clean_url($_SERVER['REQUEST_URI']);
			
			$this->initialize_locals();
		}
	}//end __construct()
	//------------------------------------------------------------------------
	
	
	
	//------------------------------------------------------------------------
	/**
	 * Creates internal objects & prepares for later usage.
	 */
	private function initialize_locals() {
		//build the templating engine: this may cause an immediate redirect, if they need to be logged-in.
		//TODO: find a way to define this on a per-page basis.  Possibly have templateObj->check_login()
		//	run during the "finish" stage... probably using GenericPage{}->check_login().
		$this->templateObj = new cs_genericPage(FALSE, "main.shared.tmpl");
		
		//setup some default template vars.
		$this->templateObj->add_template_var('date', date('m-d-Y'));
		$this->templateObj->add_template_var('time', date('H:i:s'));
		$this->templateObj->add_template_var('CURRENT_URL', '/'. $this->section);
		
		//create a fileSystem object.
		$this->fileSystemObj = new cs_fileSystemClass();
		
		//create a tabs object, in case they want to load tabs on the page.
		$this->tabs = new cs_tabs($this->templateObj);
		
		//check versions, make sure they're all the same.<commit_msg>Fix CURRENT_URL template var, in the case that it's not set...<commit_after><?php
/*
 * FILE INFORMATION: 
 * $HeadURL$
 * $Id$
 * $LastChangedDate$
 * $LastChangedRevision$
 * $LastChangedBy$
 * 
 * HOW THE SYSTEM WORKS:::
 * 	TEMPLATE FILES:
 * 	Automatically loads templates based on the URL, and optionally includes scripts in the includes directory.
 * 
 * 		MAIN SECTION:
 *	 		For the main section, i.e. "/content", it requires a template in a directory of that name beneath 
 * 			/templates, with a file called "index.content.tmpl"... i.e. /templatee/content/index.content.tmpl.
 * 		SUB SECTIONS:
 * 			For any subsection to be valid, i.e. "/content/members", it must have an associated template, i.e. 
 * 			"/templates/content/members.content.tmpl". If a subdirectory with an index.content.tmpl file exists, it will
 * 			be used instead of the file in the sub directory (i.e. "/templates/content/members/index.content.tmpl").
 * 		SUB SECTION TEMPLATE INHERITANCE:
 * 			All pages load the base set of "shared" templates, which are in the form "<section>.shared.tmpl" in
 * 			the root of the templates directory.
 * 	
 * 			Shared files within each directory, in the form "<section>.shared.tmpl", will be loaded for ANY subsection.
 *	 
 *	 		For any subsection, it inherits a previous section's templates in the following manner (any "content" 
 * 			templates are ignored for inheritance, as they're require for page load).
 * 				/content							---> /templates/content/index.*.tmpl
 *	 
 * 				/content/members					|--> /templates/content/index.*.tmpl
 * 													`--> /templates/content/members.*.tmpl
 *	 
 * 				/content/members/test				|--> /templates/content/index.*.tmpl
 * 													|--> /templates/content/members.*.tmpl
 * 													|--> /templates/content/members/index.*.tmpl
 * 													`--> /templates/content/members/test.*.tmpl
 * 	AUTOMATIC INCLUDES:
 * 	Much in the same way templates are included, so are scripts, from the /includes directory, though the logic
 * 	is decidedly simpler: all scripts must have the extension of ".inc", and must have either the section's name
 * 	as the first part of the filename, or "shared".  Shared scripts will be loaded for ALL subsections.
 * 
 * 		INCLUDES INHERITANCE:
 * 			The template inheritance scheme is as laid-out below.  The content system will go as far into the
 * 			includes directory as it can for the given section, regardless of if any intermediate files are missing.
 * 
 * 			It is important to note that the content system will NOT regard a section as valid if there are include
 * 			scripts but no templates.
 * 			
 * 				/content							|--> /includes/shared.inc
 * 													`--> /includes/content.inc
 * 
 * 				/content/members					|--> /includes/shared.inc
 * 													|--> /includes/content.inc
 * 													|--> /includes/content/shared.inc
 * 													`--> /includes/content/members.inc
 * 
 * 				/content/members/test				|--> /includes/shared.inc
 * 													|--> /includes/content.inc
 * 													|--> /includes/content/shared.inc
 * 													|--> /includes/content/members.inc
 * 													|--> /includes/content/members/shared.inc
 * 													|--> /includes/content/members/test.inc
 */

//TODO: remove this terrible little hack.
if(!isset($GLOBALS['SITE_ROOT'])) {
	//define where our scripts are located.
	$GLOBALS['SITE_ROOT'] = $_SERVER['DOCUMENT_ROOT'];
	$GLOBALS['SITE_ROOT'] = str_replace("/public_html", "", $GLOBALS['SITE_ROOT']);
}

require_once(dirname(__FILE__) ."/cs_globalFunctions.php");
require_once(dirname(__FILE__) ."/cs_fileSystemClass.php");
require_once(dirname(__FILE__) ."/cs_sessionClass.php");
require_once(dirname(__FILE__) ."/cs_genericPageClass.php");
require_once(dirname(__FILE__) ."/cs_tabsClass.php");
require_once(dirname(__FILE__) ."/cs_versionAbstract.class.php");

class contentSystem extends cs_versionAbstract {
	
	protected $baseDir			= NULL;			//base directory for templates & includes.			
	protected $section			= NULL;			//section string, derived from the URL.		
	protected $sectionArr		= array();		//array of items, for figuring out where templates & includes are.
	protected $fileSystemObj	= NULL;			//the object used to access the filesystem.
	protected $ignoredList		= array(		//array of files & folders that are implicitely ignored.
									'file'	=> array('.htaccess'),
									'dir'	=> array('.svn','CVS'
									)
								);
	protected $templateList		= array();
	protected $includesList		= array();
	public $templateObj		= NULL;
	protected $gfObj			= NULL;
	protected $tabs				= NULL;
	
	protected $finalSection;
	
	private $isValid=FALSE;
	private $reason=NULL;
	
	//------------------------------------------------------------------------
	/**
	 * The CONSTRUCTOR.  Duh.
	 */
	public function __construct($testOnly=FALSE) {
		if($testOnly === 'unit_test') {
			//It's just a test, don't do anything we might regret later.
			$this->isTest = TRUE;
		}
		else {
			$this->get_version();
			$this->get_project();
			//make a cs_globalFunctions{} object.
			$this->gfObj = new cs_globalFunctions();
			
			//setup the section stuff...
			$repArr = array($_SERVER['SCRIPT_NAME'], "/");
			$_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']);
			
			//figure out the section & subsection stuff.
			$this->section = $this->clean_url($_SERVER['REQUEST_URI']);
			
			$this->initialize_locals();
		}
	}//end __construct()
	//------------------------------------------------------------------------
	
	
	
	//------------------------------------------------------------------------
	/**
	 * Creates internal objects & prepares for later usage.
	 */
	private function initialize_locals() {
		//build the templating engine: this may cause an immediate redirect, if they need to be logged-in.
		//TODO: find a way to define this on a per-page basis.  Possibly have templateObj->check_login()
		//	run during the "finish" stage... probably using GenericPage{}->check_login().
		$this->templateObj = new cs_genericPage(FALSE, "main.shared.tmpl");
		
		//setup some default template vars.
		$this->templateObj->add_template_var('date', date('m-d-Y'));
		$this->templateObj->add_template_var('time', date('H:i:s'));
		
		$myUrl = '/';
		if(strlen($this->section) && $this->section !== 0) {
			$myUrl = '/'. $this->section;
		}
		$this->templateObj->add_template_var('CURRENT_URL', $myUrl);
		
		//create a fileSystem object.
		$this->fileSystemObj = new cs_fileSystemClass();
		
		//create a tabs object, in case they want to load tabs on the page.
		$this->tabs = new cs_tabs($this->templateObj);
		
		//check versions, make sure they're all the same.
{'fraction_non_alphanumeric': 0.16410100856904528, 'fraction_numerical': 7.58322590429969e-05, 'mean_word_length': 2.6350606394707827, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 91, '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': '4208315', 'n_tokens_mistral': 4637, 'n_tokens_neox': 3922, 'n_words': 1133}