[Cs-content-commits] SF.net SVN: cs-content:[447] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-08-19 01:40:42
|
Revision: 447
http://cs-content.svn.sourceforge.net/cs-content/?rev=447&view=rev
Author: crazedsanity
Date: 2009-08-19 01:40:29 +0000 (Wed, 19 Aug 2009)
Log Message:
-----------
Pass siteRoot to contentSystem{}, fix pass-by-reference problems.
/contentSystem.class.php:
* __construct():
-- ARG CHANGE: ARG RENAMED: #1 ($testOnly=FALSE to $siteRoot=null)
-- removed unused $testOnly arg for $siteRoot, so the root can be set
dynamically & doesn't necessarily require SITE_ROOT as a defined
constant.
-- updated exception to hopefully denote options...
-- remove "if" statement for $testOnly
-- pass $siteRoot on to initialize_locals()
* initialize_locals():
-- ARG CHANGE: NEW ARG: #1 ($siteRoot=null)
-- test $siteRoot as the root directory before dealing with SITE_ROOT
-- when passing the default main template var to cs_genericPage{},
add "templates/" so it find the directory properly (this broken code
was fixed in cs_genericPage by requiring the constant SITE_ROOT).
-- use $root when setting the base directory for templates and
includes, so the use the same folder as cs_genericPage.
* finish():
-- create the copy of templateObj later, since it seems the object
isn't actually passed by reference.
-- after the local $page var is created, only use that reference
instead of working on the internal templateObj, since it is (at least
potentially) different.
/cs_genericPage.class.php:
* initialize_locals():
-- better exception message details.
Modified Paths:
--------------
trunk/1.0/contentSystem.class.php
trunk/1.0/cs_genericPage.class.php
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2009-08-18 20:43:12 UTC (rev 446)
+++ trunk/1.0/contentSystem.class.php 2009-08-19 01:40:29 UTC (rev 447)
@@ -103,27 +103,21 @@
/**
* The CONSTRUCTOR. Duh.
*/
- public function __construct($testOnly=FALSE) {
+ public function __construct($siteRoot=null) {
parent::__construct();
- if($testOnly === 'unit_test') {
- //It's just a test, don't do anything we might regret later.
- $this->isTest = TRUE;
+
+ if(is_null($siteRoot) && !defined('SITE_ROOT')) {
+ throw new exception(__METHOD__ .": must set siteRoot or constant 'SITE_ROOT'");
}
- else {
-
- if(!defined('SITE_ROOT')) {
- throw new exception(__METHOD__ .": must set required constant 'SITE_ROOT'");
- }
-
- //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();
- }
+
+ //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($siteRoot);
}//end __construct()
//------------------------------------------------------------------------
@@ -133,7 +127,7 @@
/**
* Creates internal objects & prepares for later usage.
*/
- private function initialize_locals() {
+ private function initialize_locals($siteRoot=null) {
//create a session that gets stored in a database if they so desire...
if(defined('SESSION_DBSAVE')) {
@@ -146,10 +140,13 @@
//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().
$root = $_SERVER['DOCUMENT_ROOT'];
- if(defined('SITE_ROOT')) {
+ if(!is_null($siteRoot) && is_dir($siteRoot)) {
+ $root = $siteRoot;
+ }
+ elseif(defined('SITE_ROOT') && is_dir(constant('SITE_ROOT'))) {
$root = constant('SITE_ROOT');
}
- $this->templateObj = new cs_genericPage(FALSE, $root ."/main.shared.tmpl");
+ $this->templateObj = new cs_genericPage(FALSE, $root ."/templates/main.shared.tmpl");
//setup some default template vars.
$this->templateObj->add_template_var('date', date('m-d-Y'));
@@ -168,18 +165,12 @@
}
//create a fileSystem object for templates.
- $tmplBaseDir = constant('SITE_ROOT') .'/templates';
- if(defined('TMPLDIR')) {
- $tmplBaseDir = constant('TMPLDIR');
- }
+ $tmplBaseDir = $root .'/templates';
$this->tmplFs = new cs_fileSystem($tmplBaseDir);
//create a fileSystem object for includes
- $incBaseDir = constant('SITE_ROOT') .'/includes';
- if(defined('INCLUDES_DIR')) {
- $incBaseDir = constant('INCLUDES_DIR');
- }
+ $incBaseDir = $root .'/includes';
$this->incFs = new cs_fileSystem($incBaseDir);
@@ -782,8 +773,6 @@
unset($_GET[$badVarName], $_POST[$badVarName]);
}
- $page =& $this->templateObj;
-
if(is_array($this->injectVars) && count($this->injectVars)) {
$definedVars = get_defined_vars();
foreach($this->injectVars as $myVarName=>$myVarVal) {
@@ -797,14 +786,13 @@
}
if(isset($this->session) && is_object($this->session)) {
- $page->session = $this->session;
+ $this->templateObj->session = $this->session;
}
//if we loaded an index, but there is no "content", then move 'em around so we have content.
- if(isset($this->templateList['index']) && !isset($this->templateList['content'])) {
- $this->add_template('content', $this->templateList['index']);
- unset($this->templateList['index']);
+ if(isset($this->templateObj->templateFiles['index']) && !isset($this->templateObj->templateFiles['content'])) {
+ $this->add_template('content', $this->templateObj->templateFiles['index']);
}
//make the "final section" available to scripts.
@@ -813,6 +801,9 @@
array_unshift($sectionArr, $this->baseDir);
$finalURL = $this->gfObj->string_from_array($sectionArr, NULL, '/');
+
+ $page = $this->templateObj;
+
//now include the includes scripts, if there are any.
if(is_array($this->includesList) && count($this->includesList)) {
try {
@@ -832,7 +823,7 @@
catch(exception $e) {
$myRoot = preg_replace('/\//', '\\\/', $this->incFs->root);
$displayableInclude = preg_replace('/^'. $myRoot .'/', '', $this->myLastInclude);
- $this->templateObj->set_message_wrapper(array(
+ $page->set_message_wrapper(array(
'title' => "Fatal Error",
'message' => __METHOD__ .": A fatal error occurred while processing <b>".
$displayableInclude ."</b>:<BR>\n<b>ERROR</b>: ". $e->getMessage(),
@@ -848,12 +839,12 @@
unset($myInternalScriptName);
}
- if(is_bool($this->templateObj->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) {
- $this->isValid = $this->templateObj->allow_invalid_urls();
+ if(is_bool($page->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) {
+ $this->isValid = $page->allow_invalid_urls();
}
if($this->isValid === TRUE) {
- if($this->templateObj->printOnFinish === true) {
+ if($page->printOnFinish === true) {
$page->print_page();
}
}
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-08-18 20:43:12 UTC (rev 446)
+++ trunk/1.0/cs_genericPage.class.php 2009-08-19 01:40:29 UTC (rev 447)
@@ -83,8 +83,7 @@
$this->libDir = $this->siteRoot .'/lib';
if(!is_dir($this->tmplDir)) {
- $this->gfObj->debug_print(func_get_args(),1);
- throw new exception(__METHOD__ .": invalid templates folder (". $this->tmplDir ."), pwd=(". getcwd() .")");
+ throw new exception(__METHOD__ .": invalid templates folder (". $this->tmplDir ."), siteRoot=(". $this->siteRoot .")");
}
//if there have been some global template vars (or files) set, read 'em in here.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|