[Cs-content-commits] SF.net SVN: cs-content:[364] releases/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-02-09 20:33:28
|
Revision: 364
http://cs-content.svn.sourceforge.net/cs-content/?rev=364&view=rev
Author: crazedsanity
Date: 2009-02-09 20:33:21 +0000 (Mon, 09 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA8 ***
NOTE:: this includes changes from ALPHA7, which was never committed to releases.
CHANGE LOG:::
* cs_siteConfig attempts to fix problems with invalid vars
* functionality for stripping undefined template vars from text
* fix problem with not including all includes (#246)
SVN COMMAND:::
merge --depth=infinity -r355: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_genericPage.class.php
releases/1.0/cs_siteConfig.class.php
releases/1.0/tests/testOfCSContent.php
Modified: releases/1.0/VERSION
===================================================================
--- releases/1.0/VERSION 2009-02-09 20:16:19 UTC (rev 363)
+++ releases/1.0/VERSION 2009-02-09 20:33:21 UTC (rev 364)
@@ -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-ALPHA6
+VERSION: 1.0-ALPHA8
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
Modified: releases/1.0/contentSystem.class.php
===================================================================
--- releases/1.0/contentSystem.class.php 2009-02-09 20:16:19 UTC (rev 363)
+++ releases/1.0/contentSystem.class.php 2009-02-09 20:33:21 UTC (rev 364)
@@ -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";
}
@@ -650,20 +652,43 @@
$this->load_dir_includes($this->baseDir);
//okay, now loop through $this->sectionArr & see if we can include anything else.
+ $addIndex=false;
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);
//attempt to cd() into the next directory, or die if we can't.
if(!$this->fileSystemObj->cd($mySection)) {
//no dice. Break the loop.
+ $addIndex = false;
break;
}
+ else {
+ //okay, we made it to the final directory; add the magic "index.inc" file if it exists.
+ $addIndex = true;
+ }
}
}
+ //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']) && $addIndex==true) {
+ $this->add_include('index.inc');
+ }
}//end load_includes()
//------------------------------------------------------------------------
@@ -679,13 +704,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 +875,19 @@
//------------------------------------------------------------------------
+
+ //------------------------------------------------------------------------
+ /**
+ * Method that appends filenames to the list of include scripts.
+ */
+ private final function add_include($file) {
+ $myFile = $this->fileSystemObj->realcwd .'/'. $file;
+ if(!array_search($myFile, $this->includesList)) {
+ $this->includesList[] = $myFile;
+ }
+ }//end add_include()
+ //------------------------------------------------------------------------
+
+
}//end contentSystem{}
?>
Modified: releases/1.0/cs_genericPage.class.php
===================================================================
--- releases/1.0/cs_genericPage.class.php 2009-02-09 20:16:19 UTC (rev 363)
+++ releases/1.0/cs_genericPage.class.php 2009-02-09 20:33:21 UTC (rev 364)
@@ -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);
@@ -640,32 +646,40 @@
//-------------------------------------------------------------------------
- public function strip_undef_template_vars($section='content') {
+ public function strip_undef_template_vars($templateContents) {
$numLoops = 0;
- if(isset($this->templateVars[$section])) {
- $templateContents = $this->templateVars[$section];
- while(preg_match_all('/\{.\S+?\}/', $templateContents, $tags) && $numLoops < 50) {
- $tags = $tags[0];
-
- //TODO: figure out why this works when running it twice.
- foreach($tags as $key=>$str) {
- $str2 = str_replace("{", "", $str);
- $str2 = str_replace("}", "", $str2);
- if(!$this->templateVars[$str2]) {
- //TODO: set an internal pointer or something to use here, so they can see what was missed.
- $templateContents = str_replace($str, '', $templateContents);
- }
+ while(preg_match_all('/\{.\S+?\}/', $templateContents, $tags) && $numLoops < 50) {
+ $tags = $tags[0];
+
+ //TODO: figure out why this works when running it twice.
+ foreach($tags as $key=>$str) {
+ $str2 = str_replace("{", "", $str);
+ $str2 = str_replace("}", "", $str2);
+ if(!$this->templateVars[$str2]) {
+ //TODO: set an internal pointer or something to use here, so they can see what was missed.
+ $templateContents = str_replace($str, '', $templateContents);
}
- $this->templateObj->parse("out", "out");
- $numLoops++;
}
+ $numLoops++;
}
+ return($templateContents);
+ }//end strip_undef_template_vars()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function strip_undef_template_vars_from_section($section='content') {
+ if(isset($this->templateVars[$section])) {
+ $this->templateVars[$section] = $this->strip_undef_template_vars($this->templateVars[$section]);
+ }
else {
throw new exception(__METHOD__ .": section (". $section .") does not exist");
}
- return($templateContents);
+
+ return($this->templateVars[$section]);
+ }//strip_undef_template_vars_from_section()
//-------------------------------------------------------------------------
- }
}//end cs_genericPage{}
?>
Modified: releases/1.0/cs_siteConfig.class.php
===================================================================
--- releases/1.0/cs_siteConfig.class.php 2009-02-09 20:16:19 UTC (rev 363)
+++ releases/1.0/cs_siteConfig.class.php 2009-02-09 20:33:21 UTC (rev 364)
@@ -180,9 +180,18 @@
$itemValue = $itemValue['value'];
if(preg_match("/{/", $itemValue)) {
$origVal = $itemValue;
+
+ //remove double-slashes (//)
+ $itemValue = preg_replace('/[\/]{2,}/', '\/', $itemValue);
+
+ //remove leading slash for string replaces (i.e. "{/MAIN/SITE_ROOT}" becomes "{MAIN/SITE_ROOT}")
+ $itemValue = preg_replace('/{\//', '{', $itemValue);
+
+ //replace special vars.
$itemValue = $this->gfObj->mini_parser($itemValue, $specialVars, '{', '}');
+
+ //replace internal vars.
$itemValue = $this->gfObj->mini_parser($itemValue, $parseThis, '{', '}');
- $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue);
}
if($attribs['CLEANPATH']) {
Modified: releases/1.0/tests/testOfCSContent.php
===================================================================
--- releases/1.0/tests/testOfCSContent.php 2009-02-09 20:16:19 UTC (rev 363)
+++ releases/1.0/tests/testOfCSContent.php 2009-02-09 20:33:21 UTC (rev 364)
@@ -293,9 +293,9 @@
$this->assertNotEqual($page->templateVars, $page2->templateVars);
$page2 = clone $page;
- $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars('content'));
- $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars('content'));
- $page2->templateVars['content'] = $page2->strip_undef_template_vars('content');
+ $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars($page2->templateVars['content']));
+ $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars($page2->templateVars['content']));
+ $page2->templateVars['content'] = $page2->strip_undef_template_vars($page2->templateVars['content']);
$this->assertEqual($page->return_printed_page(1), $page2->return_printed_page(1));
}//end test_genericPage
//-------------------------------------------------------------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|