[Cs-content-commits] SF.net SVN: cs-content:[475] releases/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2010-05-18 15:49:54
|
Revision: 475
http://cs-content.svn.sourceforge.net/cs-content/?rev=475&view=rev
Author: crazedsanity
Date: 2010-05-18 15:49:47 +0000 (Tue, 18 May 2010)
Log Message:
-----------
*** RELEASE 1.0.0-RC1 ***
SUMMARY OF CHANGES:
* remove/suppress multiple PHP warnings.
* add "is_readable" and "is_writable" to cs_fileSystem::get_fileinfo().
* fix issue with trailing "/" on DOCUMENT_ROOT.
* changes for unit testing.
* add $fullSectionArr as a local variable available to includes scripts.
* fix output when called from CLI.
SVN COMMAND:::
svn merge -r463:HEAD https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/1.0 .
Modified Paths:
--------------
releases/1.0/VERSION
releases/1.0/contentSystem.class.php
releases/1.0/cs_fileSystem.class.php
releases/1.0/cs_genericPage.class.php
releases/1.0/cs_session.class.php
releases/1.0/tests/files/templates/system/message_box.tmpl
releases/1.0/tests/testOfCSContent.php
Added Paths:
-----------
releases/1.0/tests/files/includes/
releases/1.0/tests/files/includes/shared.inc
Removed Paths:
-------------
releases/1.0/tests/files/includes/shared.inc
Property Changed:
----------------
releases/1.0/
Property changes on: releases/1.0
___________________________________________________________________
Added: svn:mergeinfo
+ /trunk/1.0:464-474
Modified: releases/1.0/VERSION
===================================================================
--- releases/1.0/VERSION 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/VERSION 2010-05-18 15:49:47 UTC (rev 475)
@@ -1,5 +1,5 @@
## Stores the current version of the cs-content system, and it's source. Please do NOT modify this file.
-VERSION: 1.0-BETA1
+VERSION: 1.0-RC1
PROJECT: cs-content
-$HeadURL$
\ No newline at end of file
+$HeadURL$
Modified: releases/1.0/contentSystem.class.php
===================================================================
--- releases/1.0/contentSystem.class.php 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/contentSystem.class.php 2010-05-18 15:49:47 UTC (rev 475)
@@ -69,6 +69,7 @@
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 $fullsectionArr = array();
protected $tmplFs = NULL; //Object used to access the TEMPLATES filesystem
@@ -106,6 +107,8 @@
$_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']);
//figure out the section & subsection stuff.
+ $requestUri = preg_replace('/\/$/', '', $_SERVER['REQUEST_URI']);
+ $this->fullSectionArr = split('/', $requestUri); //TODO: will this cope with an APPURL being set?
$this->section = $this->clean_url($_SERVER['REQUEST_URI']);
$this->initialize_locals($siteRoot);
@@ -129,7 +132,8 @@
//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().
- $root = preg_replace('/\/public_html$/', '', $_SERVER['DOCUMENT_ROOT']);
+ $root = preg_replace('/\/$/', '', $_SERVER['DOCUMENT_ROOT']);
+ $root = preg_replace('/\/public_html$/', '', $root);
$root = preg_replace('/\/html/', '', $root);
if(!is_null($siteRoot) && is_dir($siteRoot)) {
@@ -149,7 +153,7 @@
'curMonth' => date("m"),
'timezone' => date("T"),
'DOMAIN' => $_SERVER['SERVER_NAME'],
- 'PHP_SELF' => $_SERVER['SCRIPT_NAME'],
+ //'PHP_SELF' => $_SERVER['SCRIPT_NAME'], // --> set in finish().
'REQUEST_URI' => $_SERVER['REQUEST_URI'],
'FULL_URL' => $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'],
'error_msg' => ""
@@ -546,7 +550,7 @@
//pull a list of the files.
$dirContents = $this->arrange_directory_contents();
- if(count($dirContents['shared'])) {
+ if(isset($dirContents['shared']) && count($dirContents['shared'])) {
foreach($dirContents['shared'] as $section => $template) {
$this->add_template($section, $template);
@@ -574,8 +578,8 @@
$filename = preg_replace('/^\/\//', '/', $filename);
//call another method to rip the filename apart properly, then arrange things as needed.
$pieces = $this->parse_filename($index);
- $myPriIndex = $pieces[$primaryIndex];
- $mySecIndex = $pieces[$secondaryIndex];
+ $myPriIndex = @$pieces[$primaryIndex];
+ $mySecIndex = @$pieces[$secondaryIndex];
if(strlen($myPriIndex) && strlen($mySecIndex)) {
//only load if it's got BOTH parts of the filename.
$arrangedArr[$myPriIndex][$mySecIndex] = $filename;
@@ -731,8 +735,8 @@
* Called when something is broken.
*/
private function die_gracefully($details=NULL) {
- header('HTTP/1.0 404 Not Found');
- if($this->templateObj->template_file_exists('system/404.shared.tmpl')) {
+ if(isset($_SERVER['SERVER_PROTOCOL']) && $this->templateObj->template_file_exists('system/404.shared.tmpl')) {
+ header('HTTP/1.0 404 Not Found');
//Simple "Page Not Found" error... show 'em.
$this->templateObj->add_template_var('main', $this->templateObj->file_to_string('system/404.shared.tmpl'));
@@ -748,7 +752,6 @@
exit;
}
else {
- //TODO: make it *actually* die gracefully... the way it works now looks more like puke than grace.
throw new exception(__METHOD__ .": Couldn't find 404 template, plus additional error... \nDETAILS::: $details" .
"\nREASON::: ". $this->reason);
}
@@ -771,6 +774,7 @@
foreach($badUrlVars as $badVarName) {
unset($_GET[$badVarName], $_POST[$badVarName]);
}
+ unset($badUrlVars, $badVarName);
if(is_array($this->injectVars) && count($this->injectVars)) {
$definedVars = get_defined_vars();
@@ -783,6 +787,7 @@
}
}
}
+ unset($definedVars, $myVarName, $myVarVal);
if(isset($this->session) && is_object($this->session)) {
$this->templateObj->session = $this->session;
@@ -797,8 +802,10 @@
//make the "final section" available to scripts.
$finalSection = $this->finalSection;
$sectionArr = $this->sectionArr;
+ $fullSectionArr = $this->fullSectionArr;
array_unshift($sectionArr, $this->baseDir);
$finalURL = $this->gfObj->string_from_array($sectionArr, NULL, '/');
+ $this->templateObj->add_template_var('PHP_SELF', '/'. $this->gfObj->string_from_array($sectionArr, NULL, '/'));
$page = $this->templateObj;
@@ -808,6 +815,7 @@
try {
foreach($this->includesList as $myInternalIndex=>$myInternalScriptName) {
$this->myLastInclude = $myInternalScriptName;
+ unset($myInternalScriptName, $myInternalIndex);
include_once($this->myLastInclude);
}
@@ -815,6 +823,7 @@
if(is_array($this->afterIncludesList)) {
foreach($this->afterIncludesList as $myInternalIndex=>$myInternalScriptName) {
$this->myLastInclude = $myInternalScriptName;
+ unset($myInternalScriptName, $myInternalIndex);
include_once($this->myLastInclude);
}
}
Modified: releases/1.0/cs_fileSystem.class.php
===================================================================
--- releases/1.0/cs_fileSystem.class.php 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/cs_fileSystem.class.php 2010-05-18 15:49:47 UTC (rev 475)
@@ -204,7 +204,9 @@
"group" => @$this->my_getuser_group(filegroup($tFile), 'gid'),
"gid" => @filegroup($tFile),
"perms" => @$this->translate_perms(fileperms($tFile)),
- "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4)
+ "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4),
+ "is_readable" => is_readable($tFile),
+ "is_writable" => is_writable($tFile)
);
return($retval);
Modified: releases/1.0/cs_genericPage.class.php
===================================================================
--- releases/1.0/cs_genericPage.class.php 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/cs_genericPage.class.php 2010-05-18 15:49:47 UTC (rev 475)
@@ -86,7 +86,7 @@
}
//if there have been some global template vars (or files) set, read 'em in here.
- if(is_array($GLOBALS['templateVars']) && count($GLOBALS['templateVars'])) {
+ if(isset($GLOBALS['templateVars']) && is_array($GLOBALS['templateVars']) && count($GLOBALS['templateVars'])) {
foreach($GLOBALS['templateVars'] as $key=>$value) {
$this->add_template_var($key, $value);
}
@@ -680,7 +680,7 @@
* Magic PHP method for retrieving the values of private/protected vars.
*/
public function __get($var) {
- return($this->$var);
+ return(@$this->$var);
}//end __get()
//-------------------------------------------------------------------------
Modified: releases/1.0/cs_session.class.php
===================================================================
--- releases/1.0/cs_session.class.php 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/cs_session.class.php 2010-05-18 15:49:47 UTC (rev 475)
@@ -30,7 +30,7 @@
}
//now actually create the session.
- session_start();
+ @session_start();
}
//check if there's a uid in the session already.
Deleted: releases/1.0/tests/files/includes/shared.inc
===================================================================
--- trunk/1.0/tests/files/includes/shared.inc 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/tests/files/includes/shared.inc 2010-05-18 15:49:47 UTC (rev 475)
@@ -1,40 +0,0 @@
-<?php
-/*
- * Created on Oct 21, 2009
- *
- * SVN INFORMATION:::
- * -------------------
- * Last Author::::::::: $Author$
- * Current Revision:::: $Revision$
- * Repository Location: $HeadURL$
- * Last Updated:::::::: $Date$
- */
-
-
-$page->gfObj->debugPrintOpt=1;
-$page->allow_invalid_urls(true);
-$page->printOnFinish=false;
-
-if(isset($testObj) && is_object($testObj) && get_class($testObj) == 'TestOfCSContent') {
-
- //start unit tests!!!
-
- $testObj->assertTrue(is_array($sectionArr));
- $testObj->assertTrue(is_array($fullSectionArr));
- if(!$testObj->assertEqual(count($sectionArr), count($fullSectionArr))) {
- $testObj->assertEqual(false, true, $page->gfObj->debug_print($fullSectionArr));
- }
-
- foreach(get_defined_vars() as $n=>$v) {
- $acceptableVars = array('testObj', 'page', 'sectionArr', 'fullSectionArr', 'finalURL', 'finalSection', 'this');
- $testObj->assertTrue(in_array($n, $acceptableVars), "local var '". $n ."' not allowed as a local var");
- unset($acceptableVars);
- }
-
-}
-else {
- throw new exception(__FILE__ .": failed to locate unit test object (testObj) while running include script unit tests");
-}
-
-
-?>
Copied: releases/1.0/tests/files/includes/shared.inc (from rev 474, trunk/1.0/tests/files/includes/shared.inc)
===================================================================
--- releases/1.0/tests/files/includes/shared.inc (rev 0)
+++ releases/1.0/tests/files/includes/shared.inc 2010-05-18 15:49:47 UTC (rev 475)
@@ -0,0 +1,40 @@
+<?php
+/*
+ * Created on Oct 21, 2009
+ *
+ * SVN INFORMATION:::
+ * -------------------
+ * Last Author::::::::: $Author$
+ * Current Revision:::: $Revision$
+ * Repository Location: $HeadURL$
+ * Last Updated:::::::: $Date$
+ */
+
+
+$page->gfObj->debugPrintOpt=1;
+$page->allow_invalid_urls(true);
+$page->printOnFinish=false;
+
+if(isset($testObj) && is_object($testObj) && get_class($testObj) == 'TestOfCSContent') {
+
+ //start unit tests!!!
+
+ $testObj->assertTrue(is_array($sectionArr));
+ $testObj->assertTrue(is_array($fullSectionArr));
+ if(!$testObj->assertEqual(count($sectionArr), count($fullSectionArr))) {
+ $testObj->assertEqual(false, true, $page->gfObj->debug_print($fullSectionArr));
+ }
+
+ foreach(get_defined_vars() as $n=>$v) {
+ $acceptableVars = array('testObj', 'page', 'sectionArr', 'fullSectionArr', 'finalURL', 'finalSection', 'this');
+ $testObj->assertTrue(in_array($n, $acceptableVars), "local var '". $n ."' not allowed as a local var");
+ unset($acceptableVars);
+ }
+
+}
+else {
+ throw new exception(__FILE__ .": failed to locate unit test object (testObj) while running include script unit tests");
+}
+
+
+?>
Modified: releases/1.0/tests/files/templates/system/message_box.tmpl
===================================================================
--- releases/1.0/tests/files/templates/system/message_box.tmpl 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/tests/files/templates/system/message_box.tmpl 2010-05-18 15:49:47 UTC (rev 475)
@@ -11,7 +11,7 @@
<table class="{messageType}" width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td valign="top">
- <p style="border-style: solid; border-width: 0px 0px 2px 0px" class="title1">{title}</p>
+ <p style="border-style: solid; border-width: 0px 0px 2px 0px" class="title1">TEST -- {title}</p>
<p style="margin: 5px 0px 5px 0px">{message}</p>
{redirect} </td>
</tr>
Modified: releases/1.0/tests/testOfCSContent.php
===================================================================
--- releases/1.0/tests/testOfCSContent.php 2010-05-18 13:29:42 UTC (rev 474)
+++ releases/1.0/tests/testOfCSContent.php 2010-05-18 15:49:47 UTC (rev 475)
@@ -24,7 +24,9 @@
$this->gfObj->debugPrintOpt=1;
$filesDir = dirname(__FILE__) ."/files";
- define('TEST_FILESDIR', $filesDir);
+ if(!defined('TEST_FILESDIR')) {
+ define('TEST_FILESDIR', $filesDir);
+ }
}//end __construct()
//-------------------------------------------------------------------------
@@ -68,7 +70,7 @@
foreach($sc->get_valid_sections() as $section) {
$sectionData = $sc->get_section($section);
foreach($sectionData as $name=>$value) {
- if(is_array($value['attributes'])) {
+ if(isset($value['attributes']) && is_array($value['attributes'])) {
if(isset($value['attributes']['SETGLOBAL'])) {
$setAsGlobals[$name] = $value['value'];
}
@@ -247,6 +249,17 @@
+ //-------------------------------------------------------------------------
+ public function test_contentSystem () {
+
+ $content = new contentSystem(dirname(__FILE__) .'/files');
+ $content->inject_var('testObj', $this);
+ $content->finish();
+ }//end test_contentSystem()
+ //-------------------------------------------------------------------------
+
+
+
}//end TestOfCSContent
//=============================================================================
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|