[Cs-content-commits] SF.net SVN: cs-content:[357] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-02-05 23:22:12
|
Revision: 357
http://cs-content.svn.sourceforge.net/cs-content/?rev=357&view=rev
Author: crazedsanity
Date: 2009-02-05 22:04:03 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
Fix issue about not including all include files (#246).
NOTE::: a good way to test it is to create a script that will run the content
system (see example file included with project), then build levels of includes
in the appropriate includes directory; each level should have index.inc,
shared.inc, and {pwd}.inc. That helps find problems with handling includes at
the root level and at much deeper levels. Testing URLs that go beyond the level
of includes is also a great idea.
/contentSystem.class.php:
* __parse_section():
-- added a TODO about arbitrarily handling "/" as "content/index"
* load_includes():
-- special handling in the case that the last section is called "index"
-- after it's done, attempt to load a final index.inc and shared.inc
using new method "add_include()"
* load_dir_includes():
-- use new method "add_include()" instead of manually doing so.
* add_include() [NEW]:
-- adds items to the internal includesList array.
/cs_genericPage.class.php:
* initialize_locals():
-- strip multiple "/" characters to avoid logic problems.
-- strip leading "/" if there is only one "/" in the string (#247)
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-02-04 17:31:19 UTC (rev 356)
+++ trunk/1.0/contentSystem.class.php 2009-02-05 22:04:03 UTC (rev 357)
@@ -262,6 +262,8 @@
* Rips apart the "section" string, setting $this->section and $this->sectionArr.
*/
private function parse_section() {
+
+ //TODO::: this should be an OPTIONAL THING as to how to handle "/" (i.e. CSCONTENT_HANDLE_ROOTURL='content/index')
if($this->section === 0 || is_null($this->section) || !strlen($this->section)) {
$this->section = "content/index";
}
@@ -652,7 +654,16 @@
//okay, now loop through $this->sectionArr & see if we can include anything else.
if(($this->fileSystemObj->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) {
- foreach($this->sectionArr as $mySection) {
+
+ //if the last item in the array is "index", disregard it...
+ $loopThis = $this->sectionArr;
+ $lastSection = $this->sectionArr[(count($this->sectionArr) -1)];
+ if($lastSection == 'index') {
+ array_pop($loopThis);
+ }
+
+
+ foreach($loopThis as $mySection) {
//Run includes.
$this->load_dir_includes($mySection);
@@ -664,6 +675,14 @@
}
}
+ //include the final shared & index files.
+ $lsData = $this->fileSystemObj->ls();
+ if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) {
+ $this->add_include('shared.inc');
+ }
+ if(isset($lsData['index.inc']) && is_array($lsData['index.inc'])) {
+ $this->add_include('index.inc');
+ }
}//end load_includes()
//------------------------------------------------------------------------
@@ -679,13 +698,13 @@
//attempt to load the shared includes file.
if(isset($lsData['shared.inc']) && $lsData['shared.inc']['type'] == 'file') {
- $this->includesList[] = $this->fileSystemObj->realcwd .'/shared.inc';
+ $this->add_include('shared.inc');
}
//attempt to load the section's includes file.
$myFile = $section .'.inc';
if(isset($lsData[$myFile]) && $lsData[$myFile]['type'] == 'file') {
- $this->includesList[] = $this->fileSystemObj->realcwd .'/'. $myFile;
+ $this->add_include($myFile);
}
if(isset($lsData[$section]) && !count($this->sectionArr)) {
@@ -850,5 +869,25 @@
//------------------------------------------------------------------------
+
+ //------------------------------------------------------------------------
+ private final function add_include($file) {
+ $myFile = $this->fileSystemObj->realcwd .'/'. $file;
+ if(array_search($myFile, $this->includesList)) {
+ $this->gfObj->debug_print("<h1><font color='red'>". __METHOD__ .": file (". $myFile .") already exists... </h1>". cs_debug_backtrace(0) ."</font>");
+ #exit;
+ }
+ else {
+ $this->includesList[] = $myFile;
+
+ $this->gfObj->debug_print("<h1>". __METHOD__ .": included (". $myFile .")</h1>");
+ }
+ if($file == 'index.inc') {
+ cs_debug_backtrace(1);
+ }
+ }//end add_include()
+ //------------------------------------------------------------------------
+
+
}//end contentSystem{}
?>
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-02-04 17:31:19 UTC (rev 356)
+++ trunk/1.0/cs_genericPage.class.php 2009-02-05 22:04:03 UTC (rev 357)
@@ -61,7 +61,13 @@
*/
protected function initialize_locals($mainTemplateFile) {
+ //replace multiple slashes with a single one to avoid confusing other logic...
+ $mainTemplateFile = preg_replace('/(\/){2,}/', '/', $mainTemplateFile);
+ if(preg_match('/\//', $mainTemplateFile) == 1 && preg_match('/^/', $mainTemplateFile)) {
+ $mainTemplateFile = preg_replace('/^\//', '', $mainTemplateFile);
+ }
+
if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/' && !preg_match('/^\./', dirname($mainTemplateFile))) {
$this->tmplDir = dirname($mainTemplateFile);
$this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|