cs-content-commits Mailing List for CS-Content [Dynamic Content System] (Page 7)
PHP Templating & Includes System
Brought to you by:
crazedsanity
You can subscribe to this list here.
| 2009 |
Jan
(32) |
Feb
(24) |
Mar
(5) |
Apr
(1) |
May
(14) |
Jun
(16) |
Jul
(11) |
Aug
(43) |
Sep
(9) |
Oct
(5) |
Nov
(1) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
(4) |
Jun
|
Jul
(5) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2011 |
Jan
(6) |
Feb
(3) |
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
(5) |
Aug
|
Sep
|
Oct
(2) |
Nov
(8) |
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <cra...@us...> - 2009-02-06 20:40:49
|
Revision: 361
http://cs-content.svn.sourceforge.net/cs-content/?rev=361&view=rev
Author: crazedsanity
Date: 2009-02-06 20:40:44 +0000 (Fri, 06 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA7 ***
SUMMARY OF CHANGES:::
* functionality for stripping undefined template vars from text
* fix problem with not including all includes (#246)
Modified Paths:
--------------
trunk/1.0/VERSION
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-02-06 20:38:40 UTC (rev 360)
+++ trunk/1.0/VERSION 2009-02-06 20:40:44 UTC (rev 361)
@@ -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-ALPHA7
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-06 20:38:44
|
Revision: 360
http://cs-content.svn.sourceforge.net/cs-content/?rev=360&view=rev
Author: crazedsanity
Date: 2009-02-06 20:38:40 +0000 (Fri, 06 Feb 2009)
Log Message:
-----------
Remove debug_print statement.
/contentSystem.class.php:
* add_include():
-- remove debug_print statement (for testing).
Modified Paths:
--------------
trunk/1.0/contentSystem.class.php
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2009-02-06 16:47:03 UTC (rev 359)
+++ trunk/1.0/contentSystem.class.php 2009-02-06 20:38:40 UTC (rev 360)
@@ -883,7 +883,6 @@
private final function add_include($file) {
$myFile = $this->fileSystemObj->realcwd .'/'. $file;
if(!array_search($myFile, $this->includesList)) {
- $this->gfObj->debug_print(__METHOD__ .": adding (". $myFile .")");
$this->includesList[] = $myFile;
}
}//end add_include()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-06 16:47:06
|
Revision: 359
http://cs-content.svn.sourceforge.net/cs-content/?rev=359&view=rev
Author: crazedsanity
Date: 2009-02-06 16:47:03 +0000 (Fri, 06 Feb 2009)
Log Message:
-----------
Another related to issue #246 where index.inc included invalidly.
/contentSystem.class.php:
* load_includes():
-- added a local variable, $addIndex
-- set $addIndex to true if it can cd() into the final section's dir.
-- set $addIndex to false if the code can't cd() into that final dir.
-- code that checks for index.inc also checks $addIndex to be true.
Modified Paths:
--------------
trunk/1.0/contentSystem.class.php
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2009-02-06 15:10:43 UTC (rev 358)
+++ trunk/1.0/contentSystem.class.php 2009-02-06 16:47:03 UTC (rev 359)
@@ -652,6 +652,7 @@
$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) {
@@ -670,8 +671,13 @@
//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;
+ }
}
}
@@ -680,7 +686,7 @@
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'])) {
+ if(isset($lsData['index.inc']) && is_array($lsData['index.inc']) && $addIndex==true) {
$this->add_include('index.inc');
}
}//end load_includes()
@@ -877,6 +883,7 @@
private final function add_include($file) {
$myFile = $this->fileSystemObj->realcwd .'/'. $file;
if(!array_search($myFile, $this->includesList)) {
+ $this->gfObj->debug_print(__METHOD__ .": adding (". $myFile .")");
$this->includesList[] = $myFile;
}
}//end add_include()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-06 15:10:47
|
Revision: 358
http://cs-content.svn.sourceforge.net/cs-content/?rev=358&view=rev
Author: crazedsanity
Date: 2009-02-06 15:10:43 +0000 (Fri, 06 Feb 2009)
Log Message:
-----------
Remove debugging code from last commit.
/contentSystem.class.php:
* add_include():
-- added header to explain what it does
-- removed debugging information
-- silently ignores duplicate includes (this should potentially cause
an exception...)
Modified Paths:
--------------
trunk/1.0/contentSystem.class.php
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2009-02-05 22:04:03 UTC (rev 357)
+++ trunk/1.0/contentSystem.class.php 2009-02-06 15:10:43 UTC (rev 358)
@@ -871,20 +871,14 @@
//------------------------------------------------------------------------
+ /**
+ * 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->gfObj->debug_print("<h1><font color='red'>". __METHOD__ .": file (". $myFile .") already exists... </h1>". cs_debug_backtrace(0) ."</font>");
- #exit;
- }
- else {
+ if(!array_search($myFile, $this->includesList)) {
$this->includesList[] = $myFile;
-
- $this->gfObj->debug_print("<h1>". __METHOD__ .": included (". $myFile .")</h1>");
}
- if($file == 'index.inc') {
- cs_debug_backtrace(1);
- }
}//end add_include()
//------------------------------------------------------------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <cra...@us...> - 2009-02-04 17:31:25
|
Revision: 356
http://cs-content.svn.sourceforge.net/cs-content/?rev=356&view=rev
Author: crazedsanity
Date: 2009-02-04 17:31:19 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
Changes for stripping undefined template vars.
NOTE::: these changes are mostly for ease in processing when returning parsed
templates via ajax (CS-Project does this).
/cs_genericPage.class.php:
* strip_undef_template_vars():
-- ARG CHANGE: RENAMED ARG: #1 (now is "$templateContents")
-- template contents must be fed to it instead of specifying a section
to retrieve template contents.
* strip_undef_template_vars_from_section() [NEW]:
-- similar to what strip_undef_template_vars() was previously, except it
this one applies changes to that section before returning the new value.
/tests/testOfCSContent.php:
* test_genericPage():
-- updated tests to handle change in the two methods listed above.
Modified Paths:
--------------
trunk/1.0/cs_genericPage.class.php
trunk/1.0/tests/testOfCSContent.php
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-02-04 17:04:36 UTC (rev 355)
+++ trunk/1.0/cs_genericPage.class.php 2009-02-04 17:31:19 UTC (rev 356)
@@ -640,32 +640,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: trunk/1.0/tests/testOfCSContent.php
===================================================================
--- trunk/1.0/tests/testOfCSContent.php 2009-02-04 17:04:36 UTC (rev 355)
+++ trunk/1.0/tests/testOfCSContent.php 2009-02-04 17:31:19 UTC (rev 356)
@@ -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.
|
|
From: <cra...@us...> - 2009-02-04 17:04:42
|
Revision: 355
http://cs-content.svn.sourceforge.net/cs-content/?rev=355&view=rev
Author: crazedsanity
Date: 2009-02-04 17:04:36 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA6 ***
SUMMARY OF CHANGES:::
* fix minor logic problem in previous release.
SVN COMMAND:::
merge --depth=infinity -r352:HEAD https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/1.0
Modified Paths:
--------------
releases/1.0/VERSION
releases/1.0/cs_genericPage.class.php
Modified: releases/1.0/VERSION
===================================================================
--- releases/1.0/VERSION 2009-02-04 17:02:47 UTC (rev 354)
+++ releases/1.0/VERSION 2009-02-04 17:04:36 UTC (rev 355)
@@ -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-ALPHA5
+VERSION: 1.0-ALPHA6
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
Modified: releases/1.0/cs_genericPage.class.php
===================================================================
--- releases/1.0/cs_genericPage.class.php 2009-02-04 17:02:47 UTC (rev 354)
+++ releases/1.0/cs_genericPage.class.php 2009-02-04 17:04:36 UTC (rev 355)
@@ -62,14 +62,15 @@
protected function initialize_locals($mainTemplateFile) {
- if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/') {
+ if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/' && !preg_match('/^\./', dirname($mainTemplateFile))) {
$this->tmplDir = dirname($mainTemplateFile);
+ $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir);
}
else {
//NOTE: this **requires** that the global variable "SITE_ROOT" is already set.
$this->siteRoot = preg_replace('/\/public_html/', '', $_SERVER['DOCUMENT_ROOT']);
+ $this->tmplDir = $this->siteRoot .'/templates';
}
- $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir);
$this->libDir = $this->siteRoot .'/lib';
//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.
|
|
From: <cra...@us...> - 2009-02-04 17:02:50
|
Revision: 354
http://cs-content.svn.sourceforge.net/cs-content/?rev=354&view=rev
Author: crazedsanity
Date: 2009-02-04 17:02:47 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA6 ***
SUMMARY OF CHANGES:::
* fix minor logic problem in previous release.
Modified Paths:
--------------
trunk/1.0/VERSION
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-02-04 16:54:59 UTC (rev 353)
+++ trunk/1.0/VERSION 2009-02-04 17:02:47 UTC (rev 354)
@@ -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-ALPHA5
+VERSION: 1.0-ALPHA6
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-04 16:55:02
|
Revision: 353
http://cs-content.svn.sourceforge.net/cs-content/?rev=353&view=rev
Author: crazedsanity
Date: 2009-02-04 16:54:59 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
Fix minor logic problem missed in last commit.
/cs_genericPage.class.php:
* initialize_locals():
-- sanity checking of dirname for mainTemplateFile before using it
-- set siteRoot AND tmplDir no matter how they're derived.
Modified Paths:
--------------
trunk/1.0/cs_genericPage.class.php
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-02-04 16:42:52 UTC (rev 352)
+++ trunk/1.0/cs_genericPage.class.php 2009-02-04 16:54:59 UTC (rev 353)
@@ -62,14 +62,15 @@
protected function initialize_locals($mainTemplateFile) {
- if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/') {
+ if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/' && !preg_match('/^\./', dirname($mainTemplateFile))) {
$this->tmplDir = dirname($mainTemplateFile);
+ $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir);
}
else {
//NOTE: this **requires** that the global variable "SITE_ROOT" is already set.
$this->siteRoot = preg_replace('/\/public_html/', '', $_SERVER['DOCUMENT_ROOT']);
+ $this->tmplDir = $this->siteRoot .'/templates';
}
- $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir);
$this->libDir = $this->siteRoot .'/lib';
//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.
|
|
From: <cra...@us...> - 2009-02-04 16:42:56
|
Revision: 352
http://cs-content.svn.sourceforge.net/cs-content/?rev=352&view=rev
Author: crazedsanity
Date: 2009-02-04 16:42:52 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA5 ***
SUMMARY OF CHANGES:::
* better handling of block rows and template vars.
* a few more methods for testing & stripping undefined template vars.
* fixed problem with mainTemplate getting an invalid prefix when an absolute
path is defined (#236)
SVN COMMAND:::
merge --depth=infinity -r349:HEAD https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/1.0
Modified Paths:
--------------
releases/1.0/VERSION
releases/1.0/cs_genericPage.class.php
releases/1.0/tests/testOfCSContent.php
Added Paths:
-----------
releases/1.0/tests/files/gptest_all-together.txt
releases/1.0/tests/files/templates/
releases/1.0/tests/files/templates/content.shared.tmpl
releases/1.0/tests/files/templates/footer.shared.tmpl
releases/1.0/tests/files/templates/infobar.shared.tmpl
releases/1.0/tests/files/templates/main.shared.tmpl
releases/1.0/tests/files/templates/menubar.shared.tmpl
releases/1.0/tests/files/templates/title.shared.tmpl
Removed Paths:
-------------
releases/1.0/tests/files/templates/content.shared.tmpl
releases/1.0/tests/files/templates/footer.shared.tmpl
releases/1.0/tests/files/templates/infobar.shared.tmpl
releases/1.0/tests/files/templates/main.shared.tmpl
releases/1.0/tests/files/templates/menubar.shared.tmpl
releases/1.0/tests/files/templates/title.shared.tmpl
Property Changed:
----------------
releases/1.0/tests/files/sampleConfig.xml
Modified: releases/1.0/VERSION
===================================================================
--- releases/1.0/VERSION 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/VERSION 2009-02-04 16:42:52 UTC (rev 352)
@@ -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-ALPHA4
+VERSION: 1.0-ALPHA5
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
Modified: releases/1.0/cs_genericPage.class.php
===================================================================
--- releases/1.0/cs_genericPage.class.php 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/cs_genericPage.class.php 2009-02-04 16:42:52 UTC (rev 352)
@@ -11,9 +11,10 @@
require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
class cs_genericPage extends cs_contentAbstract {
- var $templateObj; //template object to parse the pages
- var $templateVars = array(); //our copy of the global templateVars
- var $mainTemplate; //the default layout of the site
+ public $templateObj; //template object to parse the pages
+ public $templateVars = array(); //our copy of the global templateVars
+ public $mainTemplate; //the default layout of the site
+ public $unhandledVars=array();
private $tmplDir;
private $libDir;
@@ -60,9 +61,15 @@
*/
protected function initialize_locals($mainTemplateFile) {
- //NOTE: this **requires** that the global variable "SITE_ROOT" is already set.
- $this->siteRoot = preg_replace('/\/public_html/', '', $_SERVER['DOCUMENT_ROOT']);
- $this->tmplDir = $this->siteRoot .'/templates';
+
+ if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/') {
+ $this->tmplDir = dirname($mainTemplateFile);
+ }
+ else {
+ //NOTE: this **requires** that the global variable "SITE_ROOT" is already set.
+ $this->siteRoot = preg_replace('/\/public_html/', '', $_SERVER['DOCUMENT_ROOT']);
+ }
+ $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir);
$this->libDir = $this->siteRoot .'/lib';
//if there have been some global template vars (or files) set, read 'em in here.
@@ -81,7 +88,7 @@
//build a new instance of the template library (from PHPLib)
$this->templateObj=new Template($this->tmplDir,"keep"); //initialize a new template parser
- if(preg_match('/^\//', $mainTemplateFile)) {
+ if(!preg_match('/^\//', $mainTemplateFile)) {
$mainTemplateFile = $this->tmplDir ."/". $mainTemplateFile;
}
$this->mainTemplate=$mainTemplateFile; //load the default layout
@@ -199,7 +206,7 @@
$name = $handle;
$str = $this->templateVars[$parent];
- $reg = "/<!-- BEGIN $handle -->.+<!-- END $handle -->/sU";
+ $reg = "/<!-- BEGIN $handle -->(.+){0,}<!-- END $handle -->/sU";
preg_match_all($reg, $str, $m);
if(!is_string($m[0][0])) {
#exit("set_block_row(): couldn't find '$handle' in var '$parent'");
@@ -273,6 +280,7 @@
if(!$this->templateVars[$str2] && $stripUndefVars) {
//TODO: set an internal pointer or something to use here, so they can see what was missed.
$this->templateObj->varvals[out] = str_replace($str, '', $this->templateObj->varvals[out]);
+ $this->unhandledVars[$str2]++;
}
}
$this->templateObj->parse("out", "out");
@@ -524,10 +532,10 @@
//cast $retArr as an array, so it's clean.
$retArr = array();
- //NOTE: the value 31 isn't just a randomly chosen length; it's the minimum
- // number of characters to have a block row. EG: "<!-- BEGIN x -->o<!-- END x -->"
+ //NOTE: the value 30 isn't just a randomly chosen length; it's the minimum
+ // number of characters to have a block row. EG: "<!-- BEGIN x --><!-- END x -->"
$templateContents = $this->templateVars[$templateVar];
- if(strlen($templateContents) >= 31) {
+ if(strlen($templateContents) >= 30) {
//looks good to me. Run the regex...
$flags = PREG_PATTERN_ORDER;
$reg = "/<!-- BEGIN (\S{1,}) -->/";
@@ -615,6 +623,48 @@
return($this->allowInvalidUrls);
}//end allow_invalid_urls()
//---------------------------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function return_printed_page($stripUndefVars=1) {
+ ob_start();
+ $this->print_page($stripUndefVars);
+ $retval = ob_get_contents();
+ ob_end_clean();
+ return($retval);
+ }//end return_printed_page()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function strip_undef_template_vars($section='content') {
+ $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);
+ }
+ }
+ $this->templateObj->parse("out", "out");
+ $numLoops++;
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": section (". $section .") does not exist");
+ }
+ return($templateContents);
+ //-------------------------------------------------------------------------
+ }
}//end cs_genericPage{}
?>
Copied: releases/1.0/tests/files/gptest_all-together.txt (from rev 351, trunk/1.0/tests/files/gptest_all-together.txt)
===================================================================
--- releases/1.0/tests/files/gptest_all-together.txt (rev 0)
+++ releases/1.0/tests/files/gptest_all-together.txt 2009-02-04 16:42:52 UTC (rev 352)
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <title>This is the title.</title>
+ </head>
+<body>
+ <table>This is the infobar.</table>
+ --- the menubar (DATE: 2009-01-01)
+---+++ CONTENT STARTS HERE +++---
+ <!-- BEGIN blockRow1 -->This is a TEST<!-- comment --><!-- END blockRow1 -->
+ <!-- BEGIN blockRow2 -->This
+ is second blockRow<!-- END blockRow2 -->
+<!-- BEGIN blockRow3 --> Some data In here...
+ <!-- END blockRow3 -->
+
+ <!-- BEGIN blockRow4 --><!-- END blockRow4 -->
+---+++ CONTENT ENDS HERE +++---
+ --- the footer.
+</body>
+</html>
\ No newline at end of file
Property changes on: releases/1.0/tests/files/sampleConfig.xml
___________________________________________________________________
Added: svn:eol-style
+ native
Deleted: releases/1.0/tests/files/templates/content.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/content.shared.tmpl 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/tests/files/templates/content.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -1,8 +0,0 @@
-
- <!-- BEGIN blockRow1 -->This is a TEST<!-- comment --><!-- END blockRow1 -->
- <!-- BEGIN blockRow2 -->This
- is second blockRow<!-- END blockRow2 -->
-<!-- BEGIN blockRow{blockRowTestVal} --> Some data In here...
- <!-- END blockRow3 -->
-
- <!-- BEGIN blockRow4 --><!-- END blockRow4 -->{invisibleTemplateVar}
Copied: releases/1.0/tests/files/templates/content.shared.tmpl (from rev 351, trunk/1.0/tests/files/templates/content.shared.tmpl)
===================================================================
--- releases/1.0/tests/files/templates/content.shared.tmpl (rev 0)
+++ releases/1.0/tests/files/templates/content.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -0,0 +1,8 @@
+
+ <!-- BEGIN blockRow1 -->This is a TEST<!-- comment --><!-- END blockRow1 -->
+ <!-- BEGIN blockRow2 -->This
+ is second blockRow<!-- END blockRow2 -->
+<!-- BEGIN blockRow{blockRowTestVal} --> Some data In here...
+ <!-- END blockRow3 -->
+
+ <!-- BEGIN blockRow4 --><!-- END blockRow4 -->{invisibleTemplateVar}
Deleted: releases/1.0/tests/files/templates/footer.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/footer.shared.tmpl 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/tests/files/templates/footer.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -1 +0,0 @@
---- the footer.
\ No newline at end of file
Copied: releases/1.0/tests/files/templates/footer.shared.tmpl (from rev 351, trunk/1.0/tests/files/templates/footer.shared.tmpl)
===================================================================
--- releases/1.0/tests/files/templates/footer.shared.tmpl (rev 0)
+++ releases/1.0/tests/files/templates/footer.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -0,0 +1 @@
+--- the footer.
\ No newline at end of file
Deleted: releases/1.0/tests/files/templates/infobar.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/infobar.shared.tmpl 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/tests/files/templates/infobar.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -1 +0,0 @@
-<table>This is the infobar.</table>
\ No newline at end of file
Copied: releases/1.0/tests/files/templates/infobar.shared.tmpl (from rev 351, trunk/1.0/tests/files/templates/infobar.shared.tmpl)
===================================================================
--- releases/1.0/tests/files/templates/infobar.shared.tmpl (rev 0)
+++ releases/1.0/tests/files/templates/infobar.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -0,0 +1 @@
+<table>This is the infobar.</table>
\ No newline at end of file
Deleted: releases/1.0/tests/files/templates/main.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/main.shared.tmpl 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/tests/files/templates/main.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -1,11 +0,0 @@
-<html>
- <head>
- <title>{title}</title>
- </head>
-<body>
- {infobar}
- {menubar}
----+++ CONTENT STARTS HERE +++---{content}---+++ CONTENT ENDS HERE +++---
- {footer}
-</body>
-</html>
\ No newline at end of file
Copied: releases/1.0/tests/files/templates/main.shared.tmpl (from rev 351, trunk/1.0/tests/files/templates/main.shared.tmpl)
===================================================================
--- releases/1.0/tests/files/templates/main.shared.tmpl (rev 0)
+++ releases/1.0/tests/files/templates/main.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -0,0 +1,11 @@
+<html>
+ <head>
+ <title>{title}</title>
+ </head>
+<body>
+ {infobar}
+ {menubar}
+---+++ CONTENT STARTS HERE +++---{content}---+++ CONTENT ENDS HERE +++---
+ {footer}
+</body>
+</html>
\ No newline at end of file
Deleted: releases/1.0/tests/files/templates/menubar.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/menubar.shared.tmpl 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/tests/files/templates/menubar.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -1 +0,0 @@
---- the menubar (DATE: {date})
\ No newline at end of file
Copied: releases/1.0/tests/files/templates/menubar.shared.tmpl (from rev 351, trunk/1.0/tests/files/templates/menubar.shared.tmpl)
===================================================================
--- releases/1.0/tests/files/templates/menubar.shared.tmpl (rev 0)
+++ releases/1.0/tests/files/templates/menubar.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -0,0 +1 @@
+--- the menubar (DATE: {date})
\ No newline at end of file
Deleted: releases/1.0/tests/files/templates/title.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/title.shared.tmpl 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/tests/files/templates/title.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -1 +0,0 @@
-This is the title.
\ No newline at end of file
Copied: releases/1.0/tests/files/templates/title.shared.tmpl (from rev 351, trunk/1.0/tests/files/templates/title.shared.tmpl)
===================================================================
--- releases/1.0/tests/files/templates/title.shared.tmpl (rev 0)
+++ releases/1.0/tests/files/templates/title.shared.tmpl 2009-02-04 16:42:52 UTC (rev 352)
@@ -0,0 +1 @@
+This is the title.
\ No newline at end of file
Modified: releases/1.0/tests/testOfCSContent.php
===================================================================
--- releases/1.0/tests/testOfCSContent.php 2009-02-04 16:41:11 UTC (rev 351)
+++ releases/1.0/tests/testOfCSContent.php 2009-02-04 16:42:52 UTC (rev 352)
@@ -22,8 +22,8 @@
require_once(dirname(__FILE__) .'/../cs_globalFunctions.class.php');
require_once(dirname(__FILE__) .'/../cs_siteConfig.class.php');
- $this->gf = new cs_globalFunctions;
- $this->gf->debugPrintOpt=1;
+ $this->gfObj = new cs_globalFunctions;
+ $this->gfObj->debugPrintOpt=1;
}//end __construct()
//-------------------------------------------------------------------------
@@ -245,6 +245,63 @@
+ //-------------------------------------------------------------------------
+ function test_genericPage() {
+ $filesDir = dirname(__FILE__) .'/files';
+
+ $page = new cs_genericPage(false, $filesDir .'/templates/main.shared.tmpl', false);
+ $fs = new cs_fileSystem($filesDir .'/templates');
+
+ $lsData = $fs->ls();
+
+ foreach($lsData as $index=>$value) {
+ $filenameBits = explode('.', $index);
+ $page->add_template_var($filenameBits[0], $page->file_to_string($index));
+ }
+
+ $page->add_template_var('blockRowTestVal', 3);
+ $page->add_template_var('date', '2009-01-01');
+
+ $checkThis = $page->return_printed_page();
+
+
+ $this->assertEqual($checkThis, file_get_contents($filesDir .'/gptest_all-together.txt'));
+
+ //now let's rip all the template rows out & add them back in.
+ $rowDefs = $page->get_block_row_defs('content');
+ $rippedRows = $page->rip_all_block_rows('content');
+
+ $this->assertEqual($rowDefs['ordered'], array_keys($rippedRows));
+ $remainingRows = $page->rip_all_block_rows('content');
+ $this->assertEqual(array(), $remainingRows, "ERROR: some block rows exist after ripping: ".
+ $this->gfObj->string_from_array(array_keys($remainingRows), 'null', ','));
+
+
+ foreach($rippedRows as $name=>$data) {
+ $page->add_template_var($name, $data);
+ }
+ $checkThis2 = $page->return_printed_page();
+
+ $this->assertEqual($checkThis, $checkThis2);
+
+ $checkThis = $page->return_printed_page(0);
+ $this->assertTrue(preg_match('/\{.\S+?\}/', $checkThis));
+
+ //clone the page object so we can change stuff & not affect the original.
+ $page2 = clone $page;
+ unset($page2->templateVars);
+ $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->assertEqual($page->return_printed_page(1), $page2->return_printed_page(1));
+ }//end test_genericPage
+ //-------------------------------------------------------------------------
+
+
+
}//end TestOfCSContent
//=============================================================================
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-04 16:41:15
|
Revision: 351
http://cs-content.svn.sourceforge.net/cs-content/?rev=351&view=rev
Author: crazedsanity
Date: 2009-02-04 16:41:11 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA5 ***
SUMMARY OF CHANGES:::
* better handling of block rows and template vars.
* a few more methods for testing & stripping undefined template vars.
* fixed problem with mainTemplate getting an invalid prefix when an absolute
path is defined (#236)
Modified Paths:
--------------
trunk/1.0/VERSION
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-02-04 16:34:29 UTC (rev 350)
+++ trunk/1.0/VERSION 2009-02-04 16:41:11 UTC (rev 351)
@@ -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-ALPHA4
+VERSION: 1.0-ALPHA5
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-04 16:34:34
|
Revision: 350
http://cs-content.svn.sourceforge.net/cs-content/?rev=350&view=rev
Author: crazedsanity
Date: 2009-02-04 16:34:29 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
Unit testing for template/block row handling & minor feature additions.
/cs_genericPage.class.php:
* MAIN:::
-- changed "var" definitions into public definitions
-- added "unhandledVars=array()" definition
* initialize_locals():
-- creates the tmplDir from the dirname of the "mainTemplateFile", if it
is determinable (i.e. if a path to the template was given).
-- siteRoot is taken from tmplDir after dropping the ending "/templates"
part off the path. NOTE::: siteRoot should eventually be able to be set
independently of the tmplDir... this should eventually use constants as
default values.
-- tmplDir is only appended to the mainTemplateFile var when it does NOT
begin with a slash (old logic was inverted).
* set_block_row():
-- allows blank block rows to be removed instead of requiring at least
one character between definitions (get_block_row_defs() would see the
row, but it would not get removed).
* print_page():
-- updates internal "unhandledVars" array when stripping undefined vars
(mostly for debugging purposes)
* get_block_row_defs():
-- changed minimum length of block row from 31 to 30 to match changes in
set_block_row() method.
* return_printed_page() [NEW]:
-- uses output buffering when calling print_page() to return the page
without printing it.
* strip_undef_template_vars() [NEW]:
-- strip undefined vars from a part of the page & return that parsed
section (does not affect given section directly).
/tests/testOfCSContent.php:
* __construct():
-- create internal cs_globalFunctions{} object, turn debug printing on.
* test_genericPage() [NEW]:
-- runs some basic tests to make sure that template parsing & block row
handling all work exactly as they are expected to.
/tests/files/:
* added some files to support unit tests for cs_genericPage{}.
Modified Paths:
--------------
trunk/1.0/cs_genericPage.class.php
trunk/1.0/tests/testOfCSContent.php
Added Paths:
-----------
trunk/1.0/tests/files/gptest_all-together.txt
trunk/1.0/tests/files/templates/
trunk/1.0/tests/files/templates/content.shared.tmpl
trunk/1.0/tests/files/templates/footer.shared.tmpl
trunk/1.0/tests/files/templates/infobar.shared.tmpl
trunk/1.0/tests/files/templates/main.shared.tmpl
trunk/1.0/tests/files/templates/menubar.shared.tmpl
trunk/1.0/tests/files/templates/title.shared.tmpl
Property Changed:
----------------
trunk/1.0/tests/files/sampleConfig.xml
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-02-03 19:28:36 UTC (rev 349)
+++ trunk/1.0/cs_genericPage.class.php 2009-02-04 16:34:29 UTC (rev 350)
@@ -11,9 +11,10 @@
require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
class cs_genericPage extends cs_contentAbstract {
- var $templateObj; //template object to parse the pages
- var $templateVars = array(); //our copy of the global templateVars
- var $mainTemplate; //the default layout of the site
+ public $templateObj; //template object to parse the pages
+ public $templateVars = array(); //our copy of the global templateVars
+ public $mainTemplate; //the default layout of the site
+ public $unhandledVars=array();
private $tmplDir;
private $libDir;
@@ -60,9 +61,15 @@
*/
protected function initialize_locals($mainTemplateFile) {
- //NOTE: this **requires** that the global variable "SITE_ROOT" is already set.
- $this->siteRoot = preg_replace('/\/public_html/', '', $_SERVER['DOCUMENT_ROOT']);
- $this->tmplDir = $this->siteRoot .'/templates';
+
+ if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/') {
+ $this->tmplDir = dirname($mainTemplateFile);
+ }
+ else {
+ //NOTE: this **requires** that the global variable "SITE_ROOT" is already set.
+ $this->siteRoot = preg_replace('/\/public_html/', '', $_SERVER['DOCUMENT_ROOT']);
+ }
+ $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir);
$this->libDir = $this->siteRoot .'/lib';
//if there have been some global template vars (or files) set, read 'em in here.
@@ -81,7 +88,7 @@
//build a new instance of the template library (from PHPLib)
$this->templateObj=new Template($this->tmplDir,"keep"); //initialize a new template parser
- if(preg_match('/^\//', $mainTemplateFile)) {
+ if(!preg_match('/^\//', $mainTemplateFile)) {
$mainTemplateFile = $this->tmplDir ."/". $mainTemplateFile;
}
$this->mainTemplate=$mainTemplateFile; //load the default layout
@@ -199,7 +206,7 @@
$name = $handle;
$str = $this->templateVars[$parent];
- $reg = "/<!-- BEGIN $handle -->.+<!-- END $handle -->/sU";
+ $reg = "/<!-- BEGIN $handle -->(.+){0,}<!-- END $handle -->/sU";
preg_match_all($reg, $str, $m);
if(!is_string($m[0][0])) {
#exit("set_block_row(): couldn't find '$handle' in var '$parent'");
@@ -273,6 +280,7 @@
if(!$this->templateVars[$str2] && $stripUndefVars) {
//TODO: set an internal pointer or something to use here, so they can see what was missed.
$this->templateObj->varvals[out] = str_replace($str, '', $this->templateObj->varvals[out]);
+ $this->unhandledVars[$str2]++;
}
}
$this->templateObj->parse("out", "out");
@@ -524,10 +532,10 @@
//cast $retArr as an array, so it's clean.
$retArr = array();
- //NOTE: the value 31 isn't just a randomly chosen length; it's the minimum
- // number of characters to have a block row. EG: "<!-- BEGIN x -->o<!-- END x -->"
+ //NOTE: the value 30 isn't just a randomly chosen length; it's the minimum
+ // number of characters to have a block row. EG: "<!-- BEGIN x --><!-- END x -->"
$templateContents = $this->templateVars[$templateVar];
- if(strlen($templateContents) >= 31) {
+ if(strlen($templateContents) >= 30) {
//looks good to me. Run the regex...
$flags = PREG_PATTERN_ORDER;
$reg = "/<!-- BEGIN (\S{1,}) -->/";
@@ -615,6 +623,48 @@
return($this->allowInvalidUrls);
}//end allow_invalid_urls()
//---------------------------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function return_printed_page($stripUndefVars=1) {
+ ob_start();
+ $this->print_page($stripUndefVars);
+ $retval = ob_get_contents();
+ ob_end_clean();
+ return($retval);
+ }//end return_printed_page()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function strip_undef_template_vars($section='content') {
+ $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);
+ }
+ }
+ $this->templateObj->parse("out", "out");
+ $numLoops++;
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": section (". $section .") does not exist");
+ }
+ return($templateContents);
+ //-------------------------------------------------------------------------
+ }
}//end cs_genericPage{}
?>
Added: trunk/1.0/tests/files/gptest_all-together.txt
===================================================================
--- trunk/1.0/tests/files/gptest_all-together.txt (rev 0)
+++ trunk/1.0/tests/files/gptest_all-together.txt 2009-02-04 16:34:29 UTC (rev 350)
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <title>This is the title.</title>
+ </head>
+<body>
+ <table>This is the infobar.</table>
+ --- the menubar (DATE: 2009-01-01)
+---+++ CONTENT STARTS HERE +++---
+ <!-- BEGIN blockRow1 -->This is a TEST<!-- comment --><!-- END blockRow1 -->
+ <!-- BEGIN blockRow2 -->This
+ is second blockRow<!-- END blockRow2 -->
+<!-- BEGIN blockRow3 --> Some data In here...
+ <!-- END blockRow3 -->
+
+ <!-- BEGIN blockRow4 --><!-- END blockRow4 -->
+---+++ CONTENT ENDS HERE +++---
+ --- the footer.
+</body>
+</html>
\ No newline at end of file
Property changes on: trunk/1.0/tests/files/gptest_all-together.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on: trunk/1.0/tests/files/sampleConfig.xml
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/1.0/tests/files/templates/content.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/content.shared.tmpl (rev 0)
+++ trunk/1.0/tests/files/templates/content.shared.tmpl 2009-02-04 16:34:29 UTC (rev 350)
@@ -0,0 +1,8 @@
+
+ <!-- BEGIN blockRow1 -->This is a TEST<!-- comment --><!-- END blockRow1 -->
+ <!-- BEGIN blockRow2 -->This
+ is second blockRow<!-- END blockRow2 -->
+<!-- BEGIN blockRow{blockRowTestVal} --> Some data In here...
+ <!-- END blockRow3 -->
+
+ <!-- BEGIN blockRow4 --><!-- END blockRow4 -->{invisibleTemplateVar}
Property changes on: trunk/1.0/tests/files/templates/content.shared.tmpl
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/1.0/tests/files/templates/footer.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/footer.shared.tmpl (rev 0)
+++ trunk/1.0/tests/files/templates/footer.shared.tmpl 2009-02-04 16:34:29 UTC (rev 350)
@@ -0,0 +1 @@
+--- the footer.
\ No newline at end of file
Property changes on: trunk/1.0/tests/files/templates/footer.shared.tmpl
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/1.0/tests/files/templates/infobar.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/infobar.shared.tmpl (rev 0)
+++ trunk/1.0/tests/files/templates/infobar.shared.tmpl 2009-02-04 16:34:29 UTC (rev 350)
@@ -0,0 +1 @@
+<table>This is the infobar.</table>
\ No newline at end of file
Property changes on: trunk/1.0/tests/files/templates/infobar.shared.tmpl
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/1.0/tests/files/templates/main.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/main.shared.tmpl (rev 0)
+++ trunk/1.0/tests/files/templates/main.shared.tmpl 2009-02-04 16:34:29 UTC (rev 350)
@@ -0,0 +1,11 @@
+<html>
+ <head>
+ <title>{title}</title>
+ </head>
+<body>
+ {infobar}
+ {menubar}
+---+++ CONTENT STARTS HERE +++---{content}---+++ CONTENT ENDS HERE +++---
+ {footer}
+</body>
+</html>
\ No newline at end of file
Property changes on: trunk/1.0/tests/files/templates/main.shared.tmpl
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/1.0/tests/files/templates/menubar.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/menubar.shared.tmpl (rev 0)
+++ trunk/1.0/tests/files/templates/menubar.shared.tmpl 2009-02-04 16:34:29 UTC (rev 350)
@@ -0,0 +1 @@
+--- the menubar (DATE: {date})
\ No newline at end of file
Property changes on: trunk/1.0/tests/files/templates/menubar.shared.tmpl
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/1.0/tests/files/templates/title.shared.tmpl
===================================================================
--- trunk/1.0/tests/files/templates/title.shared.tmpl (rev 0)
+++ trunk/1.0/tests/files/templates/title.shared.tmpl 2009-02-04 16:34:29 UTC (rev 350)
@@ -0,0 +1 @@
+This is the title.
\ No newline at end of file
Property changes on: trunk/1.0/tests/files/templates/title.shared.tmpl
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/1.0/tests/testOfCSContent.php
===================================================================
--- trunk/1.0/tests/testOfCSContent.php 2009-02-03 19:28:36 UTC (rev 349)
+++ trunk/1.0/tests/testOfCSContent.php 2009-02-04 16:34:29 UTC (rev 350)
@@ -22,8 +22,8 @@
require_once(dirname(__FILE__) .'/../cs_globalFunctions.class.php');
require_once(dirname(__FILE__) .'/../cs_siteConfig.class.php');
- $this->gf = new cs_globalFunctions;
- $this->gf->debugPrintOpt=1;
+ $this->gfObj = new cs_globalFunctions;
+ $this->gfObj->debugPrintOpt=1;
}//end __construct()
//-------------------------------------------------------------------------
@@ -245,6 +245,63 @@
+ //-------------------------------------------------------------------------
+ function test_genericPage() {
+ $filesDir = dirname(__FILE__) .'/files';
+
+ $page = new cs_genericPage(false, $filesDir .'/templates/main.shared.tmpl', false);
+ $fs = new cs_fileSystem($filesDir .'/templates');
+
+ $lsData = $fs->ls();
+
+ foreach($lsData as $index=>$value) {
+ $filenameBits = explode('.', $index);
+ $page->add_template_var($filenameBits[0], $page->file_to_string($index));
+ }
+
+ $page->add_template_var('blockRowTestVal', 3);
+ $page->add_template_var('date', '2009-01-01');
+
+ $checkThis = $page->return_printed_page();
+
+
+ $this->assertEqual($checkThis, file_get_contents($filesDir .'/gptest_all-together.txt'));
+
+ //now let's rip all the template rows out & add them back in.
+ $rowDefs = $page->get_block_row_defs('content');
+ $rippedRows = $page->rip_all_block_rows('content');
+
+ $this->assertEqual($rowDefs['ordered'], array_keys($rippedRows));
+ $remainingRows = $page->rip_all_block_rows('content');
+ $this->assertEqual(array(), $remainingRows, "ERROR: some block rows exist after ripping: ".
+ $this->gfObj->string_from_array(array_keys($remainingRows), 'null', ','));
+
+
+ foreach($rippedRows as $name=>$data) {
+ $page->add_template_var($name, $data);
+ }
+ $checkThis2 = $page->return_printed_page();
+
+ $this->assertEqual($checkThis, $checkThis2);
+
+ $checkThis = $page->return_printed_page(0);
+ $this->assertTrue(preg_match('/\{.\S+?\}/', $checkThis));
+
+ //clone the page object so we can change stuff & not affect the original.
+ $page2 = clone $page;
+ unset($page2->templateVars);
+ $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->assertEqual($page->return_printed_page(1), $page2->return_printed_page(1));
+ }//end test_genericPage
+ //-------------------------------------------------------------------------
+
+
+
}//end TestOfCSContent
//=============================================================================
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-03 19:28:41
|
Revision: 349
http://cs-content.svn.sourceforge.net/cs-content/?rev=349&view=rev
Author: crazedsanity
Date: 2009-02-03 19:28:36 +0000 (Tue, 03 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA4 ***
SUMMARY OF CHANGES:::
* rename cs_sessionClass.php to cs_session.class.php to match naming conventions.
* minor change to contentSystem so version parsing always works.
* minor require_once statement for session class so version stuff works.
SVN COMMAND:::
merge --depth=infinity -r343: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
Added Paths:
-----------
releases/1.0/cs_session.class.php
Removed Paths:
-------------
releases/1.0/cs_sessionClass.php
Modified: releases/1.0/VERSION
===================================================================
--- releases/1.0/VERSION 2009-02-03 19:25:44 UTC (rev 348)
+++ releases/1.0/VERSION 2009-02-03 19:28:36 UTC (rev 349)
@@ -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-ALPHA3
+VERSION: 1.0-ALPHA4
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-03 19:25:44 UTC (rev 348)
+++ releases/1.0/contentSystem.class.php 2009-02-03 19:28:36 UTC (rev 349)
@@ -72,7 +72,7 @@
require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
require_once(dirname(__FILE__) ."/cs_fileSystem.class.php");
-require_once(dirname(__FILE__) ."/cs_sessionClass.php");
+require_once(dirname(__FILE__) ."/cs_session.class.php");
require_once(dirname(__FILE__) ."/cs_genericPage.class.php");
require_once(dirname(__FILE__) ."/cs_tabs.class.php");
@@ -103,12 +103,12 @@
* The CONSTRUCTOR. Duh.
*/
public function __construct($testOnly=FALSE) {
+ parent::__construct();
if($testOnly === 'unit_test') {
//It's just a test, don't do anything we might regret later.
$this->isTest = TRUE;
}
else {
- parent::__construct();
//setup the section stuff...
$repArr = array($_SERVER['SCRIPT_NAME'], "/");
Copied: releases/1.0/cs_session.class.php (from rev 348, trunk/1.0/cs_session.class.php)
===================================================================
--- releases/1.0/cs_session.class.php (rev 0)
+++ releases/1.0/cs_session.class.php 2009-02-03 19:28:36 UTC (rev 349)
@@ -0,0 +1,145 @@
+<?php
+/*
+ * FILE INFORMATION:
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
+require_once(dirname(__FILE__) ."/../cs-versionparse/cs_version.abstract.class.php");
+
+class cs_session extends cs_contentAbstract {
+
+ protected $db;
+ public $uid;
+ public $sid;
+ public $sid_check = 1;
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * The constructor.
+ *
+ * @param $createSession (mixed,optional) determines if a session will be started or not; if
+ * this parameter is non-null and non-numeric, the value will be
+ * used as the session name.
+ */
+ function __construct($createSession=1) {
+ parent::__construct(false);
+ if($createSession) {
+ if(!is_null($createSession) && strlen($createSession) && !is_numeric($createSession)) {
+ session_name($createSession);
+ }
+
+ //now actually create the session.
+ session_start();
+ }
+
+ //check if there's a uid in the session already.
+ //TODO: need a setting somewhere that says what the name of this var should be,
+ // instead of always forcing "uid".
+ $this->uid = 0;
+ if($_SESSION['uid']) {
+ $this->uid = $_SESSION['uid'];
+ }
+
+ //grab what our session_id is...
+ $this->sid = session_id();
+
+ }//end __construct()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Required method, so passing the object to contentSystem::handle_session()
+ * will work properly.
+ *
+ * @param (none)
+ *
+ * @return FALSE FAIL: user is not authenticated (hard-coded this way).
+ */
+ public function is_authenticated() {
+ return(FALSE);
+ }//end is_authenticated()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Retrieve data for an existing cookie.
+ *
+ * @param $name (string) Name of cookie to retrieve value for.
+ *
+ * @return NULL FAIL (?): cookie doesn't exist or has NULL value.
+ * @return (string) PASS: value of cookie.
+ */
+ public function get_cookie($name) {
+ $retval = NULL;
+ if(isset($_COOKIE) && $_COOKIE[$name]) {
+ $retval = $_COOKIE[$name];
+ }
+ return($retval);
+ }//end get_cookie()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Create a new cookie.
+ *
+ * @param $name (string) Name of cookie
+ * @param $value (string) value of cookie
+ * @param $expiration (string/number) unix timestamp or value for strtotime().
+ */
+ public function create_cookie($name, $value, $expiration=NULL) {
+
+ $expTime = NULL;
+ if(!is_null($expiration)) {
+ if(is_numeric($expiration)) {
+ $expTime = $expiration;
+ }
+ elseif(preg_match('/ /', $expiration)) {
+ $expTime = strtotime($expiration);
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid timestamp given (". $expiration .")");
+ }
+ }
+
+ $retval = setcookie($name, $value, $expTime, '/');
+ return($retval);
+
+ }//end create_cookie()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Destroy (expire) an existing cookie.
+ *
+ * @param $name (string) Name of cookie to destroy
+ *
+ * @return FALSE FAIL: no cookie by that name.
+ * @return TRUE PASS: cookie destroyed.
+ */
+ public function drop_cookie($name) {
+ $retval = FALSE;
+ if(isset($_COOKIE[$name])) {
+ setcookie($name, $_COOKIE[$name], time() -10000, '/');
+ unset($_COOKIE[$name]);
+ $retval = TRUE;
+ }
+ return($retval);
+ }//end drop_cookie()
+ //---------------------------------------------------------------------------------------------
+
+
+}//end cs_session{}
+?>
\ No newline at end of file
Deleted: releases/1.0/cs_sessionClass.php
===================================================================
--- releases/1.0/cs_sessionClass.php 2009-02-03 19:25:44 UTC (rev 348)
+++ releases/1.0/cs_sessionClass.php 2009-02-03 19:28:36 UTC (rev 349)
@@ -1,144 +0,0 @@
-<?php
-/*
- * FILE INFORMATION:
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-require_once(dirname(__FILE__) ."/../cs-versionparse/cs_version.abstract.class.php");
-
-class cs_session extends cs_contentAbstract {
-
- protected $db;
- public $uid;
- public $sid;
- public $sid_check = 1;
-
- //---------------------------------------------------------------------------------------------
- /**
- * The constructor.
- *
- * @param $createSession (mixed,optional) determines if a session will be started or not; if
- * this parameter is non-null and non-numeric, the value will be
- * used as the session name.
- */
- function __construct($createSession=1) {
- parent::__construct(false);
- if($createSession) {
- if(!is_null($createSession) && strlen($createSession) && !is_numeric($createSession)) {
- session_name($createSession);
- }
-
- //now actually create the session.
- session_start();
- }
-
- //check if there's a uid in the session already.
- //TODO: need a setting somewhere that says what the name of this var should be,
- // instead of always forcing "uid".
- $this->uid = 0;
- if($_SESSION['uid']) {
- $this->uid = $_SESSION['uid'];
- }
-
- //grab what our session_id is...
- $this->sid = session_id();
-
- }//end __construct()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Required method, so passing the object to contentSystem::handle_session()
- * will work properly.
- *
- * @param (none)
- *
- * @return FALSE FAIL: user is not authenticated (hard-coded this way).
- */
- public function is_authenticated() {
- return(FALSE);
- }//end is_authenticated()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Retrieve data for an existing cookie.
- *
- * @param $name (string) Name of cookie to retrieve value for.
- *
- * @return NULL FAIL (?): cookie doesn't exist or has NULL value.
- * @return (string) PASS: value of cookie.
- */
- public function get_cookie($name) {
- $retval = NULL;
- if(isset($_COOKIE) && $_COOKIE[$name]) {
- $retval = $_COOKIE[$name];
- }
- return($retval);
- }//end get_cookie()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Create a new cookie.
- *
- * @param $name (string) Name of cookie
- * @param $value (string) value of cookie
- * @param $expiration (string/number) unix timestamp or value for strtotime().
- */
- public function create_cookie($name, $value, $expiration=NULL) {
-
- $expTime = NULL;
- if(!is_null($expiration)) {
- if(is_numeric($expiration)) {
- $expTime = $expiration;
- }
- elseif(preg_match('/ /', $expiration)) {
- $expTime = strtotime($expiration);
- }
- else {
- throw new exception(__METHOD__ .": invalid timestamp given (". $expiration .")");
- }
- }
-
- $retval = setcookie($name, $value, $expTime, '/');
- return($retval);
-
- }//end create_cookie()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Destroy (expire) an existing cookie.
- *
- * @param $name (string) Name of cookie to destroy
- *
- * @return FALSE FAIL: no cookie by that name.
- * @return TRUE PASS: cookie destroyed.
- */
- public function drop_cookie($name) {
- $retval = FALSE;
- if(isset($_COOKIE[$name])) {
- setcookie($name, $_COOKIE[$name], time() -10000, '/');
- unset($_COOKIE[$name]);
- $retval = TRUE;
- }
- return($retval);
- }//end drop_cookie()
- //---------------------------------------------------------------------------------------------
-
-
-}//end cs_session{}
-?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-03 19:25:46
|
Revision: 348
http://cs-content.svn.sourceforge.net/cs-content/?rev=348&view=rev
Author: crazedsanity
Date: 2009-02-03 19:25:44 +0000 (Tue, 03 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA4 ***
SUMMARY OF CHANGES:::
* rename cs_sessionClass.php to cs_session.class.php to match naming conventions.
* minor change to contentSystem so version parsing always works.
* minor require_once statement for session class so version stuff works.
Modified Paths:
--------------
trunk/1.0/VERSION
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-02-03 19:23:25 UTC (rev 347)
+++ trunk/1.0/VERSION 2009-02-03 19:25:44 UTC (rev 348)
@@ -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-ALPHA3
+VERSION: 1.0-ALPHA4
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-03 19:23:27
|
Revision: 347
http://cs-content.svn.sourceforge.net/cs-content/?rev=347&view=rev
Author: crazedsanity
Date: 2009-02-03 19:23:25 +0000 (Tue, 03 Feb 2009)
Log Message:
-----------
Modified Paths:
--------------
trunk/1.0/VERSION
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-02-03 19:22:53 UTC (rev 346)
+++ trunk/1.0/VERSION 2009-02-03 19:23:25 UTC (rev 347)
@@ -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-ALPHA4
+VERSION: 1.0-ALPHA3
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-03 19:22:59
|
Revision: 346
http://cs-content.svn.sourceforge.net/cs-content/?rev=346&view=rev
Author: crazedsanity
Date: 2009-02-03 19:22:53 +0000 (Tue, 03 Feb 2009)
Log Message:
-----------
Fix location of cs_session from last commit.
Modified Paths:
--------------
trunk/1.0/VERSION
trunk/1.0/contentSystem.class.php
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-02-03 19:08:45 UTC (rev 345)
+++ trunk/1.0/VERSION 2009-02-03 19:22:53 UTC (rev 346)
@@ -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-ALPHA3
+VERSION: 1.0-ALPHA4
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2009-02-03 19:08:45 UTC (rev 345)
+++ trunk/1.0/contentSystem.class.php 2009-02-03 19:22:53 UTC (rev 346)
@@ -72,7 +72,7 @@
require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
require_once(dirname(__FILE__) ."/cs_fileSystem.class.php");
-require_once(dirname(__FILE__) ."/cs_sessionClass.php");
+require_once(dirname(__FILE__) ."/cs_session.class.php");
require_once(dirname(__FILE__) ."/cs_genericPage.class.php");
require_once(dirname(__FILE__) ."/cs_tabs.class.php");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-03 19:08:54
|
Revision: 345
http://cs-content.svn.sourceforge.net/cs-content/?rev=345&view=rev
Author: crazedsanity
Date: 2009-02-03 19:08:45 +0000 (Tue, 03 Feb 2009)
Log Message:
-----------
Rename cs_sessionClass.php to cs_session.class.php to match naming conventions.
Added Paths:
-----------
trunk/1.0/cs_session.class.php
Removed Paths:
-------------
trunk/1.0/cs_sessionClass.php
Copied: trunk/1.0/cs_session.class.php (from rev 344, trunk/1.0/cs_sessionClass.php)
===================================================================
--- trunk/1.0/cs_session.class.php (rev 0)
+++ trunk/1.0/cs_session.class.php 2009-02-03 19:08:45 UTC (rev 345)
@@ -0,0 +1,145 @@
+<?php
+/*
+ * FILE INFORMATION:
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
+require_once(dirname(__FILE__) ."/../cs-versionparse/cs_version.abstract.class.php");
+
+class cs_session extends cs_contentAbstract {
+
+ protected $db;
+ public $uid;
+ public $sid;
+ public $sid_check = 1;
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * The constructor.
+ *
+ * @param $createSession (mixed,optional) determines if a session will be started or not; if
+ * this parameter is non-null and non-numeric, the value will be
+ * used as the session name.
+ */
+ function __construct($createSession=1) {
+ parent::__construct(false);
+ if($createSession) {
+ if(!is_null($createSession) && strlen($createSession) && !is_numeric($createSession)) {
+ session_name($createSession);
+ }
+
+ //now actually create the session.
+ session_start();
+ }
+
+ //check if there's a uid in the session already.
+ //TODO: need a setting somewhere that says what the name of this var should be,
+ // instead of always forcing "uid".
+ $this->uid = 0;
+ if($_SESSION['uid']) {
+ $this->uid = $_SESSION['uid'];
+ }
+
+ //grab what our session_id is...
+ $this->sid = session_id();
+
+ }//end __construct()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Required method, so passing the object to contentSystem::handle_session()
+ * will work properly.
+ *
+ * @param (none)
+ *
+ * @return FALSE FAIL: user is not authenticated (hard-coded this way).
+ */
+ public function is_authenticated() {
+ return(FALSE);
+ }//end is_authenticated()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Retrieve data for an existing cookie.
+ *
+ * @param $name (string) Name of cookie to retrieve value for.
+ *
+ * @return NULL FAIL (?): cookie doesn't exist or has NULL value.
+ * @return (string) PASS: value of cookie.
+ */
+ public function get_cookie($name) {
+ $retval = NULL;
+ if(isset($_COOKIE) && $_COOKIE[$name]) {
+ $retval = $_COOKIE[$name];
+ }
+ return($retval);
+ }//end get_cookie()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Create a new cookie.
+ *
+ * @param $name (string) Name of cookie
+ * @param $value (string) value of cookie
+ * @param $expiration (string/number) unix timestamp or value for strtotime().
+ */
+ public function create_cookie($name, $value, $expiration=NULL) {
+
+ $expTime = NULL;
+ if(!is_null($expiration)) {
+ if(is_numeric($expiration)) {
+ $expTime = $expiration;
+ }
+ elseif(preg_match('/ /', $expiration)) {
+ $expTime = strtotime($expiration);
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid timestamp given (". $expiration .")");
+ }
+ }
+
+ $retval = setcookie($name, $value, $expTime, '/');
+ return($retval);
+
+ }//end create_cookie()
+ //---------------------------------------------------------------------------------------------
+
+
+
+ //---------------------------------------------------------------------------------------------
+ /**
+ * Destroy (expire) an existing cookie.
+ *
+ * @param $name (string) Name of cookie to destroy
+ *
+ * @return FALSE FAIL: no cookie by that name.
+ * @return TRUE PASS: cookie destroyed.
+ */
+ public function drop_cookie($name) {
+ $retval = FALSE;
+ if(isset($_COOKIE[$name])) {
+ setcookie($name, $_COOKIE[$name], time() -10000, '/');
+ unset($_COOKIE[$name]);
+ $retval = TRUE;
+ }
+ return($retval);
+ }//end drop_cookie()
+ //---------------------------------------------------------------------------------------------
+
+
+}//end cs_session{}
+?>
\ No newline at end of file
Property changes on: trunk/1.0/cs_session.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:keywords
+ HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Deleted: trunk/1.0/cs_sessionClass.php
===================================================================
--- trunk/1.0/cs_sessionClass.php 2009-02-03 19:06:49 UTC (rev 344)
+++ trunk/1.0/cs_sessionClass.php 2009-02-03 19:08:45 UTC (rev 345)
@@ -1,145 +0,0 @@
-<?php
-/*
- * FILE INFORMATION:
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
-require_once(dirname(__FILE__) ."/../cs-versionparse/cs_version.abstract.class.php");
-
-class cs_session extends cs_contentAbstract {
-
- protected $db;
- public $uid;
- public $sid;
- public $sid_check = 1;
-
- //---------------------------------------------------------------------------------------------
- /**
- * The constructor.
- *
- * @param $createSession (mixed,optional) determines if a session will be started or not; if
- * this parameter is non-null and non-numeric, the value will be
- * used as the session name.
- */
- function __construct($createSession=1) {
- parent::__construct(false);
- if($createSession) {
- if(!is_null($createSession) && strlen($createSession) && !is_numeric($createSession)) {
- session_name($createSession);
- }
-
- //now actually create the session.
- session_start();
- }
-
- //check if there's a uid in the session already.
- //TODO: need a setting somewhere that says what the name of this var should be,
- // instead of always forcing "uid".
- $this->uid = 0;
- if($_SESSION['uid']) {
- $this->uid = $_SESSION['uid'];
- }
-
- //grab what our session_id is...
- $this->sid = session_id();
-
- }//end __construct()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Required method, so passing the object to contentSystem::handle_session()
- * will work properly.
- *
- * @param (none)
- *
- * @return FALSE FAIL: user is not authenticated (hard-coded this way).
- */
- public function is_authenticated() {
- return(FALSE);
- }//end is_authenticated()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Retrieve data for an existing cookie.
- *
- * @param $name (string) Name of cookie to retrieve value for.
- *
- * @return NULL FAIL (?): cookie doesn't exist or has NULL value.
- * @return (string) PASS: value of cookie.
- */
- public function get_cookie($name) {
- $retval = NULL;
- if(isset($_COOKIE) && $_COOKIE[$name]) {
- $retval = $_COOKIE[$name];
- }
- return($retval);
- }//end get_cookie()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Create a new cookie.
- *
- * @param $name (string) Name of cookie
- * @param $value (string) value of cookie
- * @param $expiration (string/number) unix timestamp or value for strtotime().
- */
- public function create_cookie($name, $value, $expiration=NULL) {
-
- $expTime = NULL;
- if(!is_null($expiration)) {
- if(is_numeric($expiration)) {
- $expTime = $expiration;
- }
- elseif(preg_match('/ /', $expiration)) {
- $expTime = strtotime($expiration);
- }
- else {
- throw new exception(__METHOD__ .": invalid timestamp given (". $expiration .")");
- }
- }
-
- $retval = setcookie($name, $value, $expTime, '/');
- return($retval);
-
- }//end create_cookie()
- //---------------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------------
- /**
- * Destroy (expire) an existing cookie.
- *
- * @param $name (string) Name of cookie to destroy
- *
- * @return FALSE FAIL: no cookie by that name.
- * @return TRUE PASS: cookie destroyed.
- */
- public function drop_cookie($name) {
- $retval = FALSE;
- if(isset($_COOKIE[$name])) {
- setcookie($name, $_COOKIE[$name], time() -10000, '/');
- unset($_COOKIE[$name]);
- $retval = TRUE;
- }
- return($retval);
- }//end drop_cookie()
- //---------------------------------------------------------------------------------------------
-
-
-}//end cs_session{}
-?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-03 19:06:54
|
Revision: 344
http://cs-content.svn.sourceforge.net/cs-content/?rev=344&view=rev
Author: crazedsanity
Date: 2009-02-03 19:06:49 +0000 (Tue, 03 Feb 2009)
Log Message:
-----------
Minor problems with version parser & including proper files.
/contentSystem.class.php:
* __construct():
-- call parent::__construct() to ensure version parse stuff is always
available...
/cs_sessionClass.php:
* MAIN:::
-- require cs_content.abstract.class.php
Modified Paths:
--------------
trunk/1.0/contentSystem.class.php
trunk/1.0/cs_sessionClass.php
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2009-02-01 18:12:51 UTC (rev 343)
+++ trunk/1.0/contentSystem.class.php 2009-02-03 19:06:49 UTC (rev 344)
@@ -103,12 +103,12 @@
* The CONSTRUCTOR. Duh.
*/
public function __construct($testOnly=FALSE) {
+ parent::__construct();
if($testOnly === 'unit_test') {
//It's just a test, don't do anything we might regret later.
$this->isTest = TRUE;
}
else {
- parent::__construct();
//setup the section stuff...
$repArr = array($_SERVER['SCRIPT_NAME'], "/");
Modified: trunk/1.0/cs_sessionClass.php
===================================================================
--- trunk/1.0/cs_sessionClass.php 2009-02-01 18:12:51 UTC (rev 343)
+++ trunk/1.0/cs_sessionClass.php 2009-02-03 19:06:49 UTC (rev 344)
@@ -8,6 +8,7 @@
* $LastChangedRevision$
*/
+require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
require_once(dirname(__FILE__) ."/../cs-versionparse/cs_version.abstract.class.php");
class cs_session extends cs_contentAbstract {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-01 18:12:56
|
Revision: 343
http://cs-content.svn.sourceforge.net/cs-content/?rev=343&view=rev
Author: crazedsanity
Date: 2009-02-01 18:12:51 +0000 (Sun, 01 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA3 ***
SUMMARY OF CHANGES:
* fix problem with begin+end definition for block row on same line (#230)
SVN COMMAND:
merge --depth=infinity -r340:HEAD https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/1.0
Modified Paths:
--------------
releases/1.0/VERSION
releases/1.0/cs_genericPage.class.php
Modified: releases/1.0/VERSION
===================================================================
--- releases/1.0/VERSION 2009-02-01 17:54:01 UTC (rev 342)
+++ releases/1.0/VERSION 2009-02-01 18:12:51 UTC (rev 343)
@@ -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-ALPHA2
+VERSION: 1.0-ALPHA3
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
Modified: releases/1.0/cs_genericPage.class.php
===================================================================
--- releases/1.0/cs_genericPage.class.php 2009-02-01 17:54:01 UTC (rev 342)
+++ releases/1.0/cs_genericPage.class.php 2009-02-01 18:12:51 UTC (rev 343)
@@ -530,14 +530,14 @@
if(strlen($templateContents) >= 31) {
//looks good to me. Run the regex...
$flags = PREG_PATTERN_ORDER;
- $reg = "/<!-- BEGIN (.+) -->/";
+ $reg = "/<!-- BEGIN (\S{1,}) -->/";
preg_match_all($reg, $templateContents, $beginArr, $flags);
$beginArr = $beginArr[1];
- $endReg = "/<!-- END (.+) -->/";
+ $endReg = "/<!-- END (\S{1,}) -->/";
preg_match_all($endReg, $templateContents, $endArr, $flags);
$endArr = $endArr[1];
-
+
//create a part of the array that shows any orphaned "BEGIN" statements (no matching "END"
// statement), and orphaned "END" statements (no matching "BEGIN" statements)
// NOTE::: by doing this, should easily be able to tell if the block rows were defined
@@ -577,6 +577,7 @@
$rowDefs = $this->get_block_row_defs($templateVar);
$useTheseBlockRows = $rowDefs['ordered'];
+
$retval = array();
if(is_array($useTheseBlockRows)) {
foreach($useTheseBlockRows as $blockRowName)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-02-01 17:54:05
|
Revision: 342
http://cs-content.svn.sourceforge.net/cs-content/?rev=342&view=rev
Author: crazedsanity
Date: 2009-02-01 17:54:01 +0000 (Sun, 01 Feb 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA3 ***
SUMMARY OF CHANGES:
* fix problem with begin+end definition for block row on same line (#230)
SVN COMMAND:
merge --depth=infinity -r340:HEAD https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/1.0
Modified Paths:
--------------
trunk/1.0/VERSION
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-01-30 20:40:25 UTC (rev 341)
+++ trunk/1.0/VERSION 2009-02-01 17:54:01 UTC (rev 342)
@@ -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-ALPHA2
+VERSION: 1.0-ALPHA3
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-01-30 20:40:30
|
Revision: 341
http://cs-content.svn.sourceforge.net/cs-content/?rev=341&view=rev
Author: crazedsanity
Date: 2009-01-30 20:40:25 +0000 (Fri, 30 Jan 2009)
Log Message:
-----------
Fix parsing of block rows (#230).
/cs_genericPage.class.php:
* get_block_row_defs():
-- fix regex for begin and end statements so the entire definition can
be put onto a single line.
Modified Paths:
--------------
trunk/1.0/cs_genericPage.class.php
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-01-30 14:32:17 UTC (rev 340)
+++ trunk/1.0/cs_genericPage.class.php 2009-01-30 20:40:25 UTC (rev 341)
@@ -530,14 +530,14 @@
if(strlen($templateContents) >= 31) {
//looks good to me. Run the regex...
$flags = PREG_PATTERN_ORDER;
- $reg = "/<!-- BEGIN (.+) -->/";
+ $reg = "/<!-- BEGIN (\S{1,}) -->/";
preg_match_all($reg, $templateContents, $beginArr, $flags);
$beginArr = $beginArr[1];
- $endReg = "/<!-- END (.+) -->/";
+ $endReg = "/<!-- END (\S{1,}) -->/";
preg_match_all($endReg, $templateContents, $endArr, $flags);
$endArr = $endArr[1];
-
+
//create a part of the array that shows any orphaned "BEGIN" statements (no matching "END"
// statement), and orphaned "END" statements (no matching "BEGIN" statements)
// NOTE::: by doing this, should easily be able to tell if the block rows were defined
@@ -577,6 +577,7 @@
$rowDefs = $this->get_block_row_defs($templateVar);
$useTheseBlockRows = $rowDefs['ordered'];
+
$retval = array();
if(is_array($useTheseBlockRows)) {
foreach($useTheseBlockRows as $blockRowName)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-01-30 14:32:23
|
Revision: 340
http://cs-content.svn.sourceforge.net/cs-content/?rev=340&view=rev
Author: crazedsanity
Date: 2009-01-30 14:32:17 +0000 (Fri, 30 Jan 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA2 ***
SUMMARY OF CHANGES:::
* added abstract class for cs_phpDB{} to hold duplicated code.
* added abstract class for all libs for some basic functionality.
* renamed all classes & filenames to match "(className).class.php" convention.
NOTE: the mass renaming of files (and some class names) was to facilitate the
ability to use the magic PHP __autoload() function.
Modified Paths:
--------------
releases/1.0/VERSION
releases/1.0/cs_bbCodeParser.class.php
releases/1.0/cs_sessionClass.php
releases/1.0/cs_siteConfig.class.php
releases/1.0/db_types/cs_phpDB__mysql.class.php
releases/1.0/db_types/cs_phpDB__pgsql.class.php
releases/1.0/db_types/cs_phpDB__sqlite.class.php
releases/1.0/sample_files/public_html/content
releases/1.0/sample_files/public_html/index.php
releases/1.0/tests/testOfCSContent.php
Added Paths:
-----------
releases/1.0/abstract/
releases/1.0/abstract/cs_content.abstract.class.php
releases/1.0/abstract/cs_phpDB.abstract.class.php
releases/1.0/contentSystem.class.php
releases/1.0/cs_fileSystem.class.php
releases/1.0/cs_genericPage.class.php
releases/1.0/cs_globalFunctions.class.php
releases/1.0/cs_phpDB.class.php
releases/1.0/cs_tabs.class.php
releases/1.0/required/
releases/1.0/required/template.inc
Removed Paths:
-------------
releases/1.0/abstract/cs_content.abstract.class.php
releases/1.0/abstract/cs_phpDB.abstract.class.php
releases/1.0/contentSystemClass.php
releases/1.0/cs_fileSystemClass.php
releases/1.0/cs_genericPageClass.php
releases/1.0/cs_globalFunctions.php
releases/1.0/cs_phpDB.php
releases/1.0/cs_tabsClass.php
releases/1.0/required/template.inc
releases/1.0/template.inc
Property Changed:
----------------
releases/1.0/db_types/cs_phpDB__mysql.class.php
releases/1.0/db_types/cs_phpDB__pgsql.class.php
releases/1.0/db_types/cs_phpDB__sqlite.class.php
Modified: releases/1.0/VERSION
===================================================================
--- releases/1.0/VERSION 2009-01-29 21:57:59 UTC (rev 339)
+++ releases/1.0/VERSION 2009-01-30 14:32:17 UTC (rev 340)
@@ -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-ALPHA1
+VERSION: 1.0-ALPHA2
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
Deleted: releases/1.0/abstract/cs_content.abstract.class.php
===================================================================
--- trunk/1.0/abstract/cs_content.abstract.class.php 2009-01-29 21:57:59 UTC (rev 339)
+++ releases/1.0/abstract/cs_content.abstract.class.php 2009-01-30 14:32:17 UTC (rev 340)
@@ -1,36 +0,0 @@
-<?php
-/*
- * Created on Jan 29, 2009
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-require_once(dirname(__FILE__) ."/../../cs-versionparse/cs_version.abstract.class.php");
-
-
-abstract class cs_contentAbstract extends cs_versionAbstract {
-
- //-------------------------------------------------------------------------
- function __construct($makeGfObj=true) {
- $this->set_version_file_location(dirname(__FILE__) . '/../VERSION');
- $this->get_version();
- $this->get_project();
-
- if($makeGfObj === true) {
- //make a cs_globalFunctions{} object.
- require_once(dirname(__FILE__) ."/../cs_globalFunctions.class.php");
- $this->gfObj = new cs_globalFunctions();
- }
- }//end __construct()
- //-------------------------------------------------------------------------
-
-
-
-}
-?>
\ No newline at end of file
Copied: releases/1.0/abstract/cs_content.abstract.class.php (from rev 339, trunk/1.0/abstract/cs_content.abstract.class.php)
===================================================================
--- releases/1.0/abstract/cs_content.abstract.class.php (rev 0)
+++ releases/1.0/abstract/cs_content.abstract.class.php 2009-01-30 14:32:17 UTC (rev 340)
@@ -0,0 +1,36 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+require_once(dirname(__FILE__) ."/../../cs-versionparse/cs_version.abstract.class.php");
+
+
+abstract class cs_contentAbstract extends cs_versionAbstract {
+
+ //-------------------------------------------------------------------------
+ function __construct($makeGfObj=true) {
+ $this->set_version_file_location(dirname(__FILE__) . '/../VERSION');
+ $this->get_version();
+ $this->get_project();
+
+ if($makeGfObj === true) {
+ //make a cs_globalFunctions{} object.
+ require_once(dirname(__FILE__) ."/../cs_globalFunctions.class.php");
+ $this->gfObj = new cs_globalFunctions();
+ }
+ }//end __construct()
+ //-------------------------------------------------------------------------
+
+
+
+}
+?>
\ No newline at end of file
Deleted: releases/1.0/abstract/cs_phpDB.abstract.class.php
===================================================================
--- trunk/1.0/abstract/cs_phpDB.abstract.class.php 2009-01-29 21:57:59 UTC (rev 339)
+++ releases/1.0/abstract/cs_phpDB.abstract.class.php 2009-01-30 14:32:17 UTC (rev 340)
@@ -1,166 +0,0 @@
-<?php
-/*
- * Created on Jan 29, 2009
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-abstract class cs_phpDBAbstract {
-
- /** Internal result set pointer. */
- protected $result = NULL;
-
- /** Internal error code. */
- protected $errorCode = 0;
-
- /** Status of the current transaction. */
- protected $transStatus = NULL;
-
- /** Whether there is a transaction in progress or not. */
- protected $inTrans = FALSE;
-
- /** Holds the last query performed. */
- protected $lastQuery = NULL;
-
- /** List of queries that have been run */
- protected $queryList=array();
-
- /** How many seconds to wait for a query before cancelling it. */
- protected $timeOutSeconds = NULL;
-
- /** Internal check to determine if a connection has been established. */
- protected $isConnected=FALSE;
-
- /** Internal check to determine if the parameters have been set. */
- protected $paramsAreSet=FALSE;
-
- /** Resource handle. */
- protected $connectionID = -1;
-
- /** Hostname or IP to connect to */
- protected $host;
-
- /** Port to connect to (default for Postgres is 5432) */
- protected $port;
-
- /** Name of the database */
- protected $dbname;
-
- /** Username to connect to the database */
- protected $user;
-
- /** password to connect to the database */
- protected $password;
-
- /** Row counter for looping through records */
- protected $row = -1;
-
- /** cs_globalFunctions object, for string stuff. */
- protected $gfObj;
-
- /** Internal check to ensure the object has been properly created. */
- protected $isInitialized=FALSE;
-
- /** List of prepared statements, indexed off the name, with the sub-array being fieldname=>dataType. */
- protected $preparedStatements = array();
-
- /** Set to TRUE to save all queries into an array. */
- protected $useQueryList=FALSE;
-
- /** array that essentially remembers how many times beginTrans() was called. */
- protected $transactionTree = NULL;
-
-
-
- //Define some abstract methods so they MUST be provided in order for things to work.
- abstract public function set_db_info(array $params);
- abstract public function close();
- abstract public function connect(array $dbParams=NULL, $forceNewConnection=FALSE);
- abstract public function exec($query);
- abstract public function errorMsg($setMessage=null, $logError=null);
- abstract public function fobject();
- abstract public function farray();
- abstract public function farray_fieldnames($index=null, $numbered=null,$unsetIndex=1);
- abstract public function farray_nvp($name, $value);
- abstract public function farray_numbered();
- abstract public function numAffected();
- abstract public function numRows();
- abstract public function is_connected();
-
-
- //=========================================================================
- public function __construct() {
- $this->gfObj = new cs_globalFunctions;
- $this->isInitialized = true;
- }//end __construct()
- //=========================================================================
-
-
-
- //=========================================================================
- /**
- * Make sure the object is sane.
- */
- final protected function sanity_check() {
- if($this->isInitialized !== TRUE) {
- throw new exception(__METHOD__ .": not properly initialized");
- }
- }//end sanity_check()
- //=========================================================================
-
-
-
- //=========================================================================
- /**
- * Disconnect from the database (calls internal "close()" method).
- */
- public function disconnect() {
- return($this->close());
- }//end disconnect()
- //=========================================================================
-
-
-
- //=========================================================================
- public function affectedRows() {
- return($this->numAffected());
- }//end affectedRows()
- //=========================================================================
-
-
-
- //=========================================================================
- public function currRow() {
- return($this->row);
- }//end currRow()
- //=========================================================================
-
-
-
- //=========================================================================
- public function querySafe($string) {
- return($this->gfObj->cleanString($string,"query"));
- }//end querySafe()
- //=========================================================================
-
-
-
- //=========================================================================
- /**
- * Make it SQL safe.
- */
- public function sqlSafe($string) {
- return($this->gfObj->cleanString($string,"sql"));
- }//end sqlSafe()
- //=========================================================================
-
-
-
-}
-?>
\ No newline at end of file
Copied: releases/1.0/abstract/cs_phpDB.abstract.class.php (from rev 339, trunk/1.0/abstract/cs_phpDB.abstract.class.php)
===================================================================
--- releases/1.0/abstract/cs_phpDB.abstract.class.php (rev 0)
+++ releases/1.0/abstract/cs_phpDB.abstract.class.php 2009-01-30 14:32:17 UTC (rev 340)
@@ -0,0 +1,166 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_phpDBAbstract {
+
+ /** Internal result set pointer. */
+ protected $result = NULL;
+
+ /** Internal error code. */
+ protected $errorCode = 0;
+
+ /** Status of the current transaction. */
+ protected $transStatus = NULL;
+
+ /** Whether there is a transaction in progress or not. */
+ protected $inTrans = FALSE;
+
+ /** Holds the last query performed. */
+ protected $lastQuery = NULL;
+
+ /** List of queries that have been run */
+ protected $queryList=array();
+
+ /** How many seconds to wait for a query before cancelling it. */
+ protected $timeOutSeconds = NULL;
+
+ /** Internal check to determine if a connection has been established. */
+ protected $isConnected=FALSE;
+
+ /** Internal check to determine if the parameters have been set. */
+ protected $paramsAreSet=FALSE;
+
+ /** Resource handle. */
+ protected $connectionID = -1;
+
+ /** Hostname or IP to connect to */
+ protected $host;
+
+ /** Port to connect to (default for Postgres is 5432) */
+ protected $port;
+
+ /** Name of the database */
+ protected $dbname;
+
+ /** Username to connect to the database */
+ protected $user;
+
+ /** password to connect to the database */
+ protected $password;
+
+ /** Row counter for looping through records */
+ protected $row = -1;
+
+ /** cs_globalFunctions object, for string stuff. */
+ protected $gfObj;
+
+ /** Internal check to ensure the object has been properly created. */
+ protected $isInitialized=FALSE;
+
+ /** List of prepared statements, indexed off the name, with the sub-array being fieldname=>dataType. */
+ protected $preparedStatements = array();
+
+ /** Set to TRUE to save all queries into an array. */
+ protected $useQueryList=FALSE;
+
+ /** array that essentially remembers how many times beginTrans() was called. */
+ protected $transactionTree = NULL;
+
+
+
+ //Define some abstract methods so they MUST be provided in order for things to work.
+ abstract public function set_db_info(array $params);
+ abstract public function close();
+ abstract public function connect(array $dbParams=NULL, $forceNewConnection=FALSE);
+ abstract public function exec($query);
+ abstract public function errorMsg($setMessage=null, $logError=null);
+ abstract public function fobject();
+ abstract public function farray();
+ abstract public function farray_fieldnames($index=null, $numbered=null,$unsetIndex=1);
+ abstract public function farray_nvp($name, $value);
+ abstract public function farray_numbered();
+ abstract public function numAffected();
+ abstract public function numRows();
+ abstract public function is_connected();
+
+
+ //=========================================================================
+ public function __construct() {
+ $this->gfObj = new cs_globalFunctions;
+ $this->isInitialized = true;
+ }//end __construct()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ /**
+ * Make sure the object is sane.
+ */
+ final protected function sanity_check() {
+ if($this->isInitialized !== TRUE) {
+ throw new exception(__METHOD__ .": not properly initialized");
+ }
+ }//end sanity_check()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ /**
+ * Disconnect from the database (calls internal "close()" method).
+ */
+ public function disconnect() {
+ return($this->close());
+ }//end disconnect()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ public function affectedRows() {
+ return($this->numAffected());
+ }//end affectedRows()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ public function currRow() {
+ return($this->row);
+ }//end currRow()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ public function querySafe($string) {
+ return($this->gfObj->cleanString($string,"query"));
+ }//end querySafe()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ /**
+ * Make it SQL safe.
+ */
+ public function sqlSafe($string) {
+ return($this->gfObj->cleanString($string,"sql"));
+ }//end sqlSafe()
+ //=========================================================================
+
+
+
+}
+?>
\ No newline at end of file
Copied: releases/1.0/contentSystem.class.php (from rev 339, trunk/1.0/contentSystem.class.php)
===================================================================
--- releases/1.0/contentSystem.class.php (rev 0)
+++ releases/1.0/contentSystem.class.php 2009-01-30 14:32:17 UTC (rev 340)
@@ -0,0 +1,854 @@
+<?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__) ."/abstract/cs_content.abstract.class.php");
+require_once(dirname(__FILE__) ."/cs_fileSystem.class.php");
+require_once(dirname(__FILE__) ."/cs_sessionClass.php");
+require_once(dirname(__FILE__) ."/cs_genericPage.class.php");
+require_once(dirname(__FILE__) ."/cs_tabs.class.php");
+
+class contentSystem extends cs_contentAbstract {
+
+ 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 {
+ parent::__construct();
+
+ //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_fileSystem();
+
+ //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.
+ $myVersion = $this->get_version();
+ if($this->templateObj->get_version() !== $myVersion) {
+ throw new exception(__METHOD__ .": ". get_class($this->templateObj) ." has mismatched version (". $this->templateObj->get_version() ." does not equal ". $myVersion .")");
+ }
+ if($this->fileSystemObj->get_version() !== $myVersion) {
+ throw new exception(__METHOD__ .": ". get_class($this->fileSystemObj) ." has mismatched version (". $this->fileSystemObj->get_version() ." does not equal ". $myVersion .")");
+ }
+ if($this->gfObj->get_version() !== $myVersion) {
+ throw new exception(__METHOD__ .": ". get_class($this->gfObj) ." has mismatched version (". $this->gfObj->get_version() ." does not equal ". $myVersion .")");
+ }
+ if($this->tabs->get_version() !== $myVersion) {
+ throw new exception(__METHOD__ .": ". get_class($this->tabs) ." has mismatched version (". $this->tabs->get_version() ." does not equal ". $myVersion .")");
+ }
+
+ //split apart the section so we can do stuff with it later.
+ $this->parse_section();
+
+ //get ready for when we have to load templates & such.
+ $this->prepare();
+ }//end initialize_locals()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ private function get_template_dirs() {
+ if(is_array($this->sectionArr)) {
+ $this->fileSystemObj->cd("/templates/". $this->baseDir);
+ $retval = array();
+ $retval[] = $this->fileSystemObj->cwd;
+ foreach($this->sectionArr as $index=>$name) {
+ if($this->fileSystemObj->cd($name)) {
+ $retval[] = $this->fileSystemObj->cwd;
+ }
+ else {
+ break;
+ }
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": section array is invalid");
+ }
+
+ return($retval);
+ }//end get_template_dirs()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Call this to require that users accessing the given URL are authenticated;
+ * if they're not, this will cause them to be redirected to another URL
+ * (generally, so they can login).
+ */
+ public function force_authentication($redirectToUrl, $destinationArg='loginDestination') {
+ if(is_object($this->session) && method_exists($this->session, 'is_authenticated')) {
+ if(strlen($redirectToUrl)) {
+ $cleanedRedirect = $this->clean_url($redirectToUrl);
+ if($this->section != $cleanedRedirect) {
+ if(!$this->session->is_authenticated()) {
+ //run the redirect.
+ if(strlen($destinationArg)) {
+ $redirectToUrl .= '?'. $destinationArg .'=/'. urlencode($_SERVER['REQUEST_URI']);
+ }
+ $this->gfObj->conditional_header($redirectToUrl, TRUE);
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": redirect url (". $redirectToUrl .") matches current URL");
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": failed to provide proper redirection URL");
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": cannot force authentication (missing method)");
+ }
+ }//end force_authentication()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Used to determine if contentSystem{} should handle creating the session.
+ */
+ public function handle_session(&$sessionObj=NULL) {
+ if(is_object($sessionObj)) {
+ //they want us to use a different class... fine.
+ $this->session = $sessionObj;
+ }
+ else {
+ //use our own session handler.
+ $this->session = new cs_session;
+ }
+
+ if(!method_exists($this->session, 'is_authenticated')) {
+ throw new exception(__METHOD__ .": session class ('". get_class($this->session) ."') is missing method is_authenticated()");
+ }
+ }//end handle_session()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Rips apart the "section" string, setting $this->section and $this->sectionArr.
+ */
+ private function parse_section() {
+ if($this->section === 0 || is_null($this->section) || !strlen($this->section)) {
+ $this->section = "content/index";
+ }
+ $myArr = split('/', $this->section);
+
+ //if we've got something in the array, keep going.
+ if(is_array($myArr) && count($myArr) && ($myArr[0] !== 0)) {
+ $this->baseDir = array_shift($myArr);
+ $this->sectionArr = $myArr;
+ }
+ }//end parse_section()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Removes all the crap from the url, so we can figure out what section we
+ * need to load templates & includes for.
+ */
+ private function clean_url($section=NULL) {
+ if(!strlen($section) && strlen($this->section)) {
+ //if argument wasn't given, use internal pointer.
+ $section = $this->section;
+ }
+
+ //make sure we've still got something valid to work with.
+ if(!strlen($section)) {
+ //TODO: remove the extra return statement (should only be one at the bottom of the method).
+ return(NULL);
+ }
+ else {
+ //check the string to make sure it doesn't begin or end with a "/"
+ if($section[0] == '/') {
+ $section = substr($section, 1, strlen($section));
+ }
+
+ //check the last char for a "/"...
+ if($section[strlen($section) -1] == '/') {
+ //last char is a '/'... kill it.
+ $section = substr($section, 0, strlen($section) -1);
+ }
+
+ //if we've been sent a query, kill it off the string...
+ if(preg_match('/\?/', $section)) {
+ $section = split('\?', $section);
+ $section = $section[0];
+ }
+
+ if(ereg("\.", $section)) {
+ //disregard file extensions, but keep everything else...
+ // i.e. "index.php/yermom.html" becomes "index/yermom"
+ $tArr = split('/', $section);
+ foreach($tArr as $tSecName) {
+ $temp = split("\.", $tSecName);
+ if(strlen($temp[0]) > 1) {
+ $tSecName = $temp[0];
+ }
+ $tSection = $this->gfObj->create_list($tSection, $tSecName, '/');
+ }
+ $section = $tSection;
+ }
+ }
+
+ return($section);
+ }//end clean_url()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Retrieves the list of templates & includes in preparation for later work.
+ */
+ private function prepare() {
+ //attempt to load any includes...
+ if($this->fileSystemObj->cd('/includes')) {
+ $this->load_includes();
+ }
+ $foundIncludes = count($this->includesList);
+
+ //cd() in to the templates directory.
+ $cdResult = $this->fileSystemObj->cd('/templates');
+ $validatePageRes = $this->validate_page();
+ if($foundIncludes || ($cdResult && $validatePageRes)) {
+
+ //okay, get template directories & start loading
+ $tmplDirs = $this->get_template_dirs();
+
+ $this->load_shared_templates();
+ foreach($tmplDirs as $myPath) {
+ //load shared templates.
+ $this->load_shared_templates($myPath);
+ }
+
+ //load templates for the main section.
+ $this->load_main_templates();
+
+ //load templates for the page.
+ $this->load_page_templates();
+
+ //now cd() all the way back.
+ $this->fileSystemObj->cd('/');
+ }
+ else {
+ //couldn't find the templates directory, and no includes... it's dead.
+ $this->die_gracefully(__METHOD__ .": unable to find the templates directory, or non-valid page [". $this->validate_page() ."]");
+ }
+ }//end prepare()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Ensures the page we're on would actually load, so other methods don't have to do
+ * so much extra checking.
+ */
+ private function validate_page() {
+ $valid = FALSE;
+ //if we've got a non-basedir page, (instead of "/whatever", we have "/whatever/x"), see
+ // if there are templates that make it good... or just check the base template.
+ if((count($this->sectionArr) > 0) && !((count($this->sectionArr) == 1) && ($this->sectionArr[0] == 'index'))) {
+ //got more than just a baseDir url... see if the template is good.
+ $finalLink = $this->gfObj->string_from_array($this->sectionArr, NULL, '/');
+ $this->fileSystemObj->cd($this->baseDir);
+ $mySectionArr = $this->sectionArr;
+ $finalSection = array_pop($mySectionArr);
+ $this->finalSection = $finalSection;
+ if(count($mySectionArr) > 0) {
+ foreach($mySectionArr as $dir) {
+ if(!$this->fileSystemObj->cd($dir)) {
+ break;
+ }
+ }
+ }
+
+ //check for the file & the directory...
+ $indexFilename = $finalSection ."/index.content.tmpl";
+ if(!strlen($finalSection)) {
+ $indexFilename = 'index.content.tmpl';
+ }
+
+ $lsDir = $this->fileSystemObj->ls($indexFilename);
+ $lsDirVals = array_values($lsDir);
+ $lsFile = $this->fileSystemObj->ls("$finalSection.content.tmpl");
+
+ if(is_array(array_values($lsFile)) && is_array($lsFile[$finalSection .".content.tmpl"])) {
+ //it's the file ("{finalSection}.content.tmpl", like "mySection.content.tmpl")
+ $myIndex = $finalSection .".content.tmpl";
+ }
+ elseif(is_array(array_values($lsDir)) && (is_array($lsDir[$indexFilename]))) {
+ $myIndex = $indexFilename;
+ }
+ else {
+ //nothin' doin'.
+ $myIndex = NULL;
+ }
+
+ //check the index file for validity... this is kind of a dirty hack... but it works.
+ $checkMe = $this->fileSystemObj->ls($myIndex);
+ if(!is_array($checkMe[$myIndex])) {
+ unset($myIndex);
+ }
+
+ if(isset($myIndex)) {
+ $valid = TRUE;
+ $this->fileSystemObj->cd('/templates');
+ }
+ else {
+ $this->reason = __METHOD__ .": couldn't find page template for ". $this->section;
+ }
+ }
+ else {
+ //if the baseDir is "help", this would try to use "/help/index.content.tmpl"
+ $myFile = $this->baseDir .'/index.content.tmpl';
+ $sectionLsData = $this->fileSystemObj->ls($myFile);
+
+ //if the baseDir is "help", this would try to use "/help.content.tmpl"
+ $sectionFile = $this->baseDir .'.content.tmpl';
+ $lsData = $this->fileSystemObj->ls();
+
+ if(isset($lsData[$sectionFile]) && is_array($lsData[$sectionFile])) {
+ $valid = TRUE;
+ $this->finalSection = $this->baseDir;
+ }
+ elseif(isset($sectionLsData[$myFile]) && $sectionLsData[$myFile]['type'] == 'file') {
+ //we're good.
+ $valid = TRUE;
+ $this->finalSection = $this->baseDir;
+ }
+ else {
+ $this->reason = __METHOD__ .": couldn't find base template.";
+ }
+ }
+ $this->isValid = $valid;
+
+ return($valid);
+ }//end validate_page()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Loads the templates for the current page (performs template inheritance, too).
+ */
+ private function load_page_templates() {
+ //should already be in the proper directory, start looping through sectionArr,
+ // looking for templates.
+ $mySectionArr = $this->sectionArr;
+
+ $finalSection = $this->sectionArr[(count($this->sectionArr) -1)];
+ foreach($mySectionArr as $index=>$value) {
+ $tmplList = $this->arrange_directory_contents('name', 'section');
+ if(isset($tmplList[$value])) {
+ foreach($tmplList[$value] as $mySection=>$myTmpl) {
+ //
+ $this->templateList[$mySection] = $myTmpl;
+ }
+ }
+ if(!$this->fileSystemObj->cd($value)) {
+ break;
+ }
+ }
+
+ //load the final template(s).
+ $finalTmplList = $this->arrange_directory_contents('name', 'section');
+ if(isset($finalTmplList[$finalSection])) {
+ foreach($finalTmplList[$finalSection] as $mySection => $myTmpl) {
+ $this->templateList[$mySection] = $myTmpl;
+ }
+ }
+ elseif(is_array($finalTmplList)) {
+ foreach($finalTmplList as $mySection => $subArr) {
+ foreach($subArr as $internalSection => $myTmpl) {
+ $this->templateList[$mySection] = $myTmpl;
+ }
+ }
+ }
+ if($this->fileSystemObj->cd($finalSection)) {
+ //load the index stuff.
+ $tmplList = $this->arrange_directory_contents('name', 'section');
+ if(isset($tmplList['index'])) {
+ foreach($tmplList['index'] as $mySection => $myTmpl) {
+ $this->templateList[$mySection] = $myTmpl;
+ }
+ }
+ if(isset($tmplList[$this->baseDir]['content'])) {
+ //load template for the main page (if $this->baseDir == "help", this would load "/help.content.tmpl" as content)
+ $this->templateList['content'] = $tmplList[$this->baseDir]['content'];
+ }
+ }
+ }//end load_page_templates()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * loads templates for the main section they're on.
+ */
+ private function load_main_templates() {
+ $this->fileSystemObj->cd('/templates');
+ //check to see if the present section is valid.
+ $this->fileSystemObj->cd($this->baseDir);
+ $dirContents = $this->arrange_directory_contents('name', 'section');
+ if(is_array($dirContents)) {
+ foreach($dirContents as $mySection => $subArr) {
+ foreach($subArr as $subIndex=>$templateFilename) {
+ $this->templateList[$mySection] = $templateFilename;
+ }
+ }
+ }
+ }//end load_main_templates()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Loads any shared templates: these can be overwritten later.
+ */
+ private function load_shared_templates($path=NULL) {
+
+ if(!is_null($path)) {
+ $this->fileSystemObj->cd($path);
+ }
+ else {
+ $this->fileSystemObj->cd('/templates');
+ }
+
+ //pull a list of the files.
+ $dirContents = $this->arrange_directory_contents();
+ if(count($dirContents['shared'])) {
+
+ foreach($dirContents['shared'] as $section => $template) {
+ $this->templateList[$section] = $template;
+ }
+ }
+ }//end load_shared_templates()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Pulls a list of files in the current directory, & arranges them by section &
+ * name, or vice-versa.
+ */
+ private function arrange_directory_contents($primaryIndex='section', $secondaryIndex='name') {
+ $directoryInfo = $this->fileSystemObj->ls();
+ $arrangedArr = array();
+ if(is_array($directoryInfo)) {
+ foreach($directoryInfo as $index=>$data) {
+ $myType = $data['type'];
+ if(($myType == 'file') && !in_array($index, $this->ignoredList[$myType])) {
+ $filename = $this->gfObj->create_list($this->fileSystemObj->cwd, $index, '/');
+ $filename = preg_replace('/^\/templates/', '', $filename);
+ $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];
+ if(strlen($myPriIndex) && strlen($mySecIndex)) {
+ //only load if it's got BOTH parts of the filename.
+ $arrangedArr[$myPriIndex][$mySecIndex] = $filename;
+ }
+ }
+ }
+ }
+
+ return($arrangedArr);
+ }//end arrange_directory_contents()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Takes a filename (string) and breaks it down into the "type", "section", and
+ * "name". I.E. for the filename "test.content.tmpl", type=tmpl, section="content",
+ * and "name"=test.
+ * TODO: set a way to define how the filenames are setup, so filenames can be "name.section.type" or "section.name.type".
+ */
+ private function parse_filename($filename) {
+ //break it into it's various parts.
+ $myParts = explode('.', $filename);
+ $retval = array();
+ $count = count($myParts);
+ if($count >= 3) {
+ //"type" is the last element of the array, and "section" is the second-to-last.
+ $type = array_pop($myParts);
+
+ //define what types of files that are accepted: if it's not one of them, don't bother.
+ $acceptedTypes = array("tmpl");
+ if(in_array($type, $acceptedTypes)) {
+ $section = array_pop($myParts);
+
+ //just in case we want to allow templates with "."'s in them, rip off the
+ // last two parts, and use what's left as the name.
+ $stripThis = '.'. $section .'\.'. $type .'$';
+ $name = preg_replace('/'. $stripThis .'/', '', $filename);
+
+ $retval = array(
+ 'name' => $name,
+ 'section' => $section,
+ 'type' => $type
+ );
+ }
+ }
+
+ return($retval);
+ }//end parse_filename()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Finds all scripts in the /inlcudes directory, & adds them to the includesList array.
+ */
+ private function load_includes() {
+
+ //first load includes for the base directory.
+ $this->load_dir_includes($this->baseDir);
+
+ //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) {
+ //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.
+ break;
+ }
+ }
+ }
+
+ }//end load_includes()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Attempts to add a shared include & the given section's include file: used
+ * solely by load_includes().
+ */
+ private function load_dir_includes($section) {
+ $lsData = $this->fileSystemObj->ls();
+
+ //attempt to load the shared includes file.
+ if(isset($lsData['shared.inc']) && $lsData['shared.inc']['type'] == 'file') {
+ $this->includesList[] = $this->fileSystemObj->realcwd .'/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;
+ }
+
+ if(isset($lsData[$section]) && !count($this->sectionArr)) {
+ $this->fileSystemObj->cd($section);
+ $lsData = $this->fileSystemObj->ls();
+ if(isset($lsData['index.inc'])) {
+ $this->includesList[] = $this->fileSystemObj->realcwd .'/index.inc';
+ }
+ }
+ }//end load_dir_includes()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * 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')) {
+ //Simple "Page Not Found" error... show 'em.
+ $this->templateObj->add_template_var('main', $this->templateObj->file_to_string('system/404.shared.tmpl'));
+ $this->templateObj->add_template_var('details', $details);
+ $this->templateObj->add_template_var('datetime', date('m-d-Y H:i:s'));
+ $this->templateObj->print_page();
+ 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);
+ }
+ }//end die_gracefully()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * The super-magical method that includes files & finalizes things using
+ * the given templating engine.
+ * NOTE: the local variable "$page" is made so that the included scripts
+ * can make calls to the templating engine, just like they used to. It's
+ * AWESOME.
+ */
+ function finish() {
+ //Avoid problems when REGISTER_GLOBALS is on...
+ $badUrlVars = array('page', 'this');
+ foreach($badUrlVars as $badVarName) {
+ unset($_GET[$badVarName], $_POST[$badVarName]);
+ }
+
+ $page =& $this->templateObj;
+ if(is_object($this->session)) {
+ $page->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->templateList['content'] = $this->templateList['index'];
+ unset($this->templateList['index']);
+ }
+
+ foreach($this->templateList as $mySection => $myTmpl) {
+ $myTmpl = preg_replace("/\/\//", "/", $myTmpl);
+ $page->add_template_file($mySection, $myTmpl);
+ }
+ unset($mySection);
+ unset($myTmpl);
+
+ //make the "final section" available to scripts.
+ $finalSection = $this->finalSection;
+ $sectionArr = $this->sectionArr;
+ array_unshift($sectionArr, $this->baseDir);
+ $finalURL = $this->gfObj->string_from_array($sectionArr, NULL, '/');
+
+ //now include the includes scripts, if there are any.
+ if(is_array($this->includesList) && count($this->includesList)) {
+ try {
+ foreach($this->includesList as $myInternalIndex=>$myInternalScriptName) {
+ $this->myLastInclude = $myInternalScriptName;
+ include_once($this->myLastInclude);
+ }
+ }
+ catch(exception $e) {
+ $myRoot = preg_replace('/\//', '\\\/', $this->fileSystemObj->root);
+ $displayableInclude = preg_replace('/^'. $myRoot .'/', '', $this->myLastInclude);
+ $this->templateObj->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(),
+ 'type' => "fatal"
+ ));
+
+ //try to pass the error on to the user's exception handler, if there is one.
+ if(function_exists('exception_handler')) {
+ exception_handler($e);
+ }
+ }
+ unset($myInternalIndex);
+ unset($myInternalScriptName);
+ }
+
+ if(is_bool($this->templateObj->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) {
+ $this->isValid = $this->templateObj->allow_invalid_urls();
+ }
+
+ if($this->isValid === TRUE) {
+ $page->print_page();
+ }
+ else {
+ $this->die_gracefully($this->reason);
+ }
+ }//end finish()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Method for accessing the protected $this->sectionArr array.
+ */
+ public function get_sectionArr() {
+ //give 'em what they want.
+ return($this->sectionArr);
+ }//end get_sectionArr()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Method for accessing the protected member $this->finalSection.
+ */
+ public function get_finalSection() {
+ //give 'em what they want.
+ return($this->finalSection);
+ }//end get_finalSection()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Method for accessing "baseDir", only referenced as the base section.
+ */
+ public function get_baseSection() {
+ return($this->baseDir);
+ }//end get_baseSection()
+ //------------------------------------------------------------------------
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * The destructor... does nothing, right now.
+ */
+ public function __destruct() {
+ }//end __destruct()
+ //------------------------------------------------------------------------
+
+
+}//end contentSystem{}
+?>
Deleted: releases/1.0/contentSystemClass.php
===================================================================
--- releases/1.0/contentSystemClass.php 2009-01-29 21:57:59 UTC (rev 339)
+++ releases/1.0/contentSystemClass.php 2009-01-30 14:32:17 UTC (rev 340)
@@ -1,859 +0,0 @@
-<?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-versionparse/cs_version.abstract.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->set_version_file_location(dirname(__FILE__) . '/VERSION');
- $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.
- $myVersion = $this->get_version();
- if($this->templateObj->get_version() !== $myVersion) {
- throw new exception(__METHOD__ .": ". get_class($this->templateObj) ." has mismatched version (". $this->templateObj->get_version() ." does not equal ". $myVersion .")");
- }
- if($this->fileSystemObj->get_version() !== $myVersion) {
- throw new exception(__METHOD__ .": ". get_class($this->fileSystemObj) ." has mismatched version (". $this->fileSystemObj->get_version() ." does not equal ". $myVersion .")");
- }
- if($this->gfObj->get_version() !== $myVersion) {
- throw new exception(__METHOD__ .": ". get_class($this->gfObj) ." has mismatched version (". $this->gfObj->get_version() ." does not equal ". $myVersion .")");
- }
- if($this->tabs->get_version() !== $myVersion) {
- throw new exception(__METHOD__ .": ". get_class($this->tabs) ." has mismatched version (". $this->tabs->get_version() ." does not equal ". $myVersion .")");
- }
-
- //split apart the section so we can do stuff with it later.
- $this->parse_section();
-
- //get ready for when we have to load templates & such.
- $this->prepare();
- }//end initialize_locals()
- //------------------------------------------------------------------------
-
-
-
- //------------------------------------------------------------------------
- private function get_template_dirs() {
- if(is_array($this->sectionArr)) {
- $this->fileSystemObj->cd("/templates/". $this->baseDir);
- $retval = array();
- $retval[] = $this->fileSystemObj->cwd;
- foreach($this->sectionArr as $index=>$name) {
- if($this->fileSystemObj->cd($name)) {
- $retval[] = $this->fileSystemObj->cwd;
- }
- else {
- break;
- }
- }
- }
- else {
- throw new exception(__METHOD__ .": section array is invalid");
- }
-
- return($retval);
- }//end get_template_dirs()
- //------------------------------------------------------------------------
-
-
-
- //------------------------------------------------------------------------
- /**
- * Call this to require that users accessing the given URL are authenticated;
- * if they're not, this will cause them to be redirected to another URL
- * (generally, so they can login).
- */
- public function force_authentication($redirectToUrl, $destinationArg='loginDestination') {
- if(is_object($this->session) && method_exists($this->session, 'is_authenticated')) {
- if(strlen($redirectToUrl)) {
- $cleanedRedirect = $this->clean_url($redirectToUrl);
- if($this->section != $cleanedRedirect) {
- if(!$this->session->is_authenticated()) {
- //run the redirect.
- if(strlen($destinationArg)) {
- $redirectToUrl .= '?'. $destinationArg .'=/'. urlencode($_SERVER['REQUEST_URI']);
- }
- $this->gfObj->conditional_header($redirectToUrl, TRUE);
- }
- }
- else {
- throw new exception(__METHOD__ .": redirect url (". $redirectToUrl .") matches current URL");
- }
- }
- else {
- throw new exception(__METHOD__ .": failed to provide proper redirection URL");
- }
- }
- else {
- throw new exception(__METHOD__ .": cannot force authentication (missing method)");
- }
- }//end force_authentication()
- //------------------------------------------------------------------------
-
-
-
- //------------------------------------------------------------------------
- /**
- * Used to determine if contentSystem{} should handle creating the session.
- */
- public function handle_session(&$sessionObj=NULL) {
- if(is_object($sessionObj)) {
- //they want us to use a different class... fine.
- $this->session = $sessionObj;
- }
- else {
- //use our own session handler.
- $this->session = new cs_session;
- }
-
- if(!method_exists($this->session, 'is_authenticated')) {
- throw new exception(__METHOD__ .": session class ('". get_class($this->session) ."') is missing method is_authenticated()");
- }
- }//end handle_session()
- //------------------------------------------------------------------------
-
-
-
- //------------------------------------------------------------------------
- /**
- * Rips apart the "section" string, setting $this->section and $this->sectionArr.
- */
- private function parse_section() {
- if($this->section === 0 || is_null($this->section) || !strlen($this->section)) {
- $this->section = "content/index";
- }
- $myArr = split('/', $this->section);
-
- //if we've got something in the array, keep going.
- if(is_array($myArr) && count($myArr) && ($myArr[0] !== 0)) {
- $this->baseDir = array_shift($myArr);
- $this->sectionArr = $myArr;
- }
- }//end parse_section()
- //------------------------------------------------------------------------
-
-
-
- //------------------------------------------------------------------------
- /**
- * Removes all the crap from the url, so we can figure out what section we
- * need to load templates & includes for.
- */
- private function clean_url($section=NULL) {
- if(!strlen($section) && strlen($this->section)) {
- //if argument wasn't given, use internal pointer.
- $section = $this->section;
- }
-
- //make sure we've still got something valid to work with.
- if(!strlen($section)) {
- //TODO: remove the extra return statement (should only be one at the bottom of the method).
- return(NULL);
- }
- else {
- //check the string to make sure it doesn't begin or end with a "/"
- if($section[0] == '/') {
- $section = substr($section, 1, strlen($section));
- }
-
- //check the last char for a "/"...
- if($section[strlen($section) -1] == '/') {
- //last char is a '/'... kill it.
- $section = substr($section, 0, strlen($section) -1);
- }
-
- //if we've been sent a query, kill it off the string...
- if(preg_match('/\?/', $section)) {
- $section = split('\?', $section);
- $section = $section[0];
- }
-
- if(ereg("\.", $section)) {
- //disregard file extensions, but keep everything else...
- // i.e. "index.php/yermom.html" becomes "index/yermom"
- $tArr = split('/', $section);
- foreach($tArr as $tSecName) {
- $temp = split("\.", $tSecName);
- if(strlen($temp[0]) > 1) {
- $tSecName = $temp[0];
- }
- $tSection = $this->gfObj->create_list($tSection, $tSecName, '/');
- }
- $section = $tSection;
- }
- }
-
- return($section);
- }//end clean_url()
- //---------------------------...
[truncated message content] |
|
From: <cra...@us...> - 2009-01-29 22:49:43
|
Revision: 336
http://cs-content.svn.sourceforge.net/cs-content/?rev=336&view=rev
Author: crazedsanity
Date: 2009-01-29 21:45:51 +0000 (Thu, 29 Jan 2009)
Log Message:
-----------
Renamed cs_phpDB.php to cs_phpDB.class.php.
/cs_phpDB.class.php [RENAMED FROM cs_phpDB.php]
/cs_phpDB.php [RENAMED TO cs_phpDB.class.php]
Added Paths:
-----------
trunk/1.0/cs_phpDB.class.php
Removed Paths:
-------------
trunk/1.0/cs_phpDB.php
Copied: trunk/1.0/cs_phpDB.class.php (from rev 333, trunk/1.0/cs_phpDB.php)
===================================================================
--- trunk/1.0/cs_phpDB.class.php (rev 0)
+++ trunk/1.0/cs_phpDB.class.php 2009-01-29 21:45:51 UTC (rev 336)
@@ -0,0 +1,74 @@
+<?php
+
+/*
+ * A class for generic PostgreSQL database access.
+ *
+ * SVN INFORMATION:::
+ * SVN Signature:::::::: $Id$
+ * Last Committted Date: $Date$
+ * Last Committed Path:: $HeadURL$
+ *
+ */
+
+///////////////////////
+// ORIGINATION INFO:
+// Author: Trevin Chow (with contributions from Lee Pang, wle...@ho...)
+// Email: t1...@ma...
+// Date: February 21, 2000
+// Last Updated: August 14, 2001
+//
+// Description:
+// Abstracts both the php function calls and the server information to POSTGRES
+// databases. Utilizes class variables to maintain connection information such
+// as number of rows, result id of last operation, etc.
+//
+///////////////////////
+
+require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
+require_once(dirname(__FILE__) ."/abstract/cs_phpDB.abstract.class.php");
+
+class cs_phpDB extends cs_contentAbstract {
+
+ private $dbLayerObj;
+ private $dbType;
+
+ //=========================================================================
+ public function __construct($type='pgsql') {
+
+ if(strlen($type)) {
+
+ require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php');
+ $className = __CLASS__ .'__'. $type;
+ $this->dbLayerObj = new $className;
+ $this->dbType = $type;
+
+ parent::__construct();
+
+ $this->isInitialized = TRUE;
+ }
+ else {
+ throw new exception(__METHOD__ .": failed to give a type (". $type .")");
+ }
+ }//end __construct()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ /**
+ * Magic method to call methods within the database abstraction layer ($this->dbLayerObj).
+ */
+ public function __call($methodName, $args) {
+ if(method_exists($this->dbLayerObj, $methodName)) {
+ $retval = call_user_func_array(array($this->dbLayerObj, $methodName), $args);
+ }
+ else {
+ throw new exception(__METHOD__ .': unsupported method ('. $methodName .') for database of type ('. $this->dbType .')');
+ }
+ return($retval);
+ }//end __call()
+ //=========================================================================
+
+} // end class phpDB
+
+?>
Property changes on: trunk/1.0/cs_phpDB.class.php
___________________________________________________________________
Added: svn:eol
+ native
Added: svn:keywords
+ Id
HeadURL
Date
Revision
Author
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Deleted: trunk/1.0/cs_phpDB.php
===================================================================
--- trunk/1.0/cs_phpDB.php 2009-01-29 21:25:58 UTC (rev 335)
+++ trunk/1.0/cs_phpDB.php 2009-01-29 21:45:51 UTC (rev 336)
@@ -1,74 +0,0 @@
-<?php
-
-/*
- * A class for generic PostgreSQL database access.
- *
- * SVN INFORMATION:::
- * SVN Signature:::::::: $Id$
- * Last Committted Date: $Date$
- * Last Committed Path:: $HeadURL$
- *
- */
-
-///////////////////////
-// ORIGINATION INFO:
-// Author: Trevin Chow (with contributions from Lee Pang, wle...@ho...)
-// Email: t1...@ma...
-// Date: February 21, 2000
-// Last Updated: August 14, 2001
-//
-// Description:
-// Abstracts both the php function calls and the server information to POSTGRES
-// databases. Utilizes class variables to maintain connection information such
-// as number of rows, result id of last operation, etc.
-//
-///////////////////////
-
-require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
-require_once(dirname(__FILE__) ."/abstract/cs_phpDB.abstract.class.php");
-
-class cs_phpDB extends cs_contentAbstract {
-
- private $dbLayerObj;
- private $dbType;
-
- //=========================================================================
- public function __construct($type='pgsql') {
-
- if(strlen($type)) {
-
- require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php');
- $className = __CLASS__ .'__'. $type;
- $this->dbLayerObj = new $className;
- $this->dbType = $type;
-
- parent::__construct();
-
- $this->isInitialized = TRUE;
- }
- else {
- throw new exception(__METHOD__ .": failed to give a type (". $type .")");
- }
- }//end __construct()
- //=========================================================================
-
-
-
- //=========================================================================
- /**
- * Magic method to call methods within the database abstraction layer ($this->dbLayerObj).
- */
- public function __call($methodName, $args) {
- if(method_exists($this->dbLayerObj, $methodName)) {
- $retval = call_user_func_array(array($this->dbLayerObj, $methodName), $args);
- }
- else {
- throw new exception(__METHOD__ .': unsupported method ('. $methodName .') for database of type ('. $this->dbType .')');
- }
- return($retval);
- }//end __call()
- //=========================================================================
-
-} // end class phpDB
-
-?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-01-29 22:49:40
|
Revision: 339
http://cs-content.svn.sourceforge.net/cs-content/?rev=339&view=rev
Author: crazedsanity
Date: 2009-01-29 21:57:59 +0000 (Thu, 29 Jan 2009)
Log Message:
-----------
*** RELEASE 1.0-ALPHA2 ***
SUMMARY OF CHANGES:::
* added abstract class for cs_phpDB{} to hold duplicated code.
* added abstract class for all libs for some basic functionality.
* renamed all classes & filenames to match "(className).class.php" convention.
NOTE: the mass renaming of files (and some class names) was to facilitate the
ability to use the magic PHP __autoload() function.
Modified Paths:
--------------
trunk/1.0/VERSION
Modified: trunk/1.0/VERSION
===================================================================
--- trunk/1.0/VERSION 2009-01-29 21:50:55 UTC (rev 338)
+++ trunk/1.0/VERSION 2009-01-29 21:57:59 UTC (rev 339)
@@ -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-ALPHA1
+VERSION: 1.0-ALPHA2
PROJECT: cs-content
$HeadURL$
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-01-29 22:49:35
|
Revision: 338
http://cs-content.svn.sourceforge.net/cs-content/?rev=338&view=rev
Author: crazedsanity
Date: 2009-01-29 21:50:55 +0000 (Thu, 29 Jan 2009)
Log Message:
-----------
Move the "template.inc" file into a "required" folder to cleanup the main directory just a bit.
Modified Paths:
--------------
trunk/1.0/cs_genericPage.class.php
Added Paths:
-----------
trunk/1.0/required/
trunk/1.0/required/template.inc
Removed Paths:
-------------
trunk/1.0/template.inc
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-01-29 21:48:59 UTC (rev 337)
+++ trunk/1.0/cs_genericPage.class.php 2009-01-29 21:50:55 UTC (rev 338)
@@ -7,7 +7,7 @@
* $LastChangedBy$
* $LastChangedRevision$
*/
-require_once(dirname(__FILE__) ."/template.inc");
+require_once(dirname(__FILE__) ."/required/template.inc");
require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php");
class cs_genericPage extends cs_contentAbstract {
Copied: trunk/1.0/required/template.inc (from rev 333, trunk/1.0/template.inc)
===================================================================
--- trunk/1.0/required/template.inc (rev 0)
+++ trunk/1.0/required/template.inc 2009-01-29 21:50:55 UTC (rev 338)
@@ -0,0 +1,1013 @@
+<?php
+/*
+ * Session Management for PHP3
+ *
+ * (C) Copyright 1999-2000 NetUSE GmbH
+ * Kristian Koehntopp
+ *
+ * $Id: template.inc,v 1.15 2004/07/23 20:36:29 layne_weathers Exp $
+ *
+ */
+
+/*
+ * Change log since version 7.2c
+ *
+ * Bug fixes to version 7.2c compiled by Richard Archer <rh...@ju...>:
+ * (credits given to first person to post a diff to phplib mailing list)
+ *
+ * Normalised all comments and whitespace (rha)
+ * replaced "$handle" with "$varname" and "$h" with "$v" throughout (from phplib-devel)
+ * added braces around all one-line if statements in: get_undefined, loadfile and halt (rha)
+ * set_var was missing two sets of braces (rha)
+ * added a couple of "return true" statements (rha)
+ * set_unknowns had "keep" as default instead of "remove" (from phplib-devel)
+ * set_file failed to check for empty strings if passed an array of filenames (phplib-devel)
+ * remove @ from call to preg_replace in subst -- report errors if there are any (NickM)
+ * set_block unnecessarily required a newline in the template file (Marc Tardif)
+ * pparse now calls this->finish to replace undefined vars (Layne Weathers)
+ * get_var now checks for unset varnames (NickM & rha)
+ * get_var when passed an array used the array key instead of the value (rha)
+ * get_vars now uses a call to get_var rather than this->varvals to prevent undefined var warning (rha)
+ * in finish, the replacement string referenced an unset variable (rha)
+ * loadfile would try to load a file if the varval had been set to "" (rha)
+ * in get_undefined, only match non-whitespace in variable tags as in finish (Layne Weathers & rha)
+ * more elegant fix to the problem of subst stripping '$n', '\n' and '\\' strings (rha)
+ * parse uses get_var to obtain return value (Jordi via SF)
+ * set_block reports an error if the block could not be extracted (rha)
+ * filename is now windows-pathname aware (krabu @ SF)
+ *
+ *
+ * Changes in functionality which go beyond bug fixes:
+ *
+ * added ability for filename comments to be output (from phplib-users layne)
+ * changed debug handling so set, get and internals can be tracked separately (rha)
+ * added debug statements throughout to track most function calls (rha)
+ * debug output contained raw HTML -- is now escaped with htmlentities (rha)
+ * Alter regex in set_block to remove more whitespace around BEGIN/END tags to improve HTML layout (rha)
+ * Add "append" option to set_var, works just like append in parse (dale at linuxwebpro.com, rha)
+ * Altered parse so that append is honored if passed an array (Brian)
+ * Converted comments and documentation to phpdoc style (rha)
+ * Added clear_var to set the value of variables to "" (rha)
+ * Added unset_var to usset variables (rha)
+ *
+ */
+
+/**
+ * The template class allows you to keep your HTML code in some external files
+ * which are completely free of PHP code, but contain replacement fields.
+ * The class provides you with functions which can fill in the replacement fields
+ * with arbitrary strings. These strings can become very large, e.g. entire tables.
+ *
+ * Note: If you think that this is like FastTemplates, read carefully. It isn't.
+ */
+
+class Template
+{
+ /**
+ * Serialization helper, the name of this class.
+ *
+ * @var string
+ * @access public
+ */
+ var $classname = "Template";
+
+ /**
+ * Determines how much debugging output Template will produce.
+ * This is a bitwise mask of available debug levels:
+ * 0 = no debugging
+ * 1 = debug variable assignments
+ * 2 = debug calls to get variable
+ * 4 = debug internals (outputs all function calls with parameters).
+ *
+ * Note: setting $this->debug = true will enable debugging of variable
+ * assignments only which is the same behaviour as versions up to release 7.2d.
+ *
+ * @var int
+ * @access public
+ */
+ var $debug = false;
+
+ /**
+ * Determines whether Template outputs filename comments.
+ * false = no filename outputs
+ * true = HTML comments (e.g. <!-- START FILE $filename -->) placed in output
+ *
+ * @var int
+ * @access public
+ */
+ var $filename_comments = false;
+
+ /**
+ * Determines the regular expression used to find unknown variable tags.
+ * "loose" = traditional match all curly braces with no whitespace between
+ * "strict" = adopts PHP's variable naming rules
+ * ("loose" has a nasty habit of deleting JavaScript RegEx components)
+ * (should future major version releases of PHPLib default this "strict"?)
+ *
+ * @var string
+ * @access public
+ */
+ var $unknown_regexp = "loose";
+
+ /**
+ * The base directory from which template files are loaded.
+ *
+ * @var string
+ * @access private
+ * @see set_root
+ */
+ var $root = ".";
+
+ /**
+ * A hash of strings forming a translation table which translates variable names
+ * into names of files containing the variable content.
+ * $file[varname] = "filename";
+ *
+ * @var array
+ * @access private
+ * @see set_file
+ */
+ var $file = array();
+
+ /**
+ * A hash of strings forming a translation table which translates variable names
+ * into regular expressions for themselves.
+ * $varkeys[varname] = "/varname/"
+ *
+ * @var array
+ * @access private
+ * @see set_var
+ */
+ var $varkeys = array();
+
+ /**
+ * A hash of strings forming a translation table which translates variable names
+ * into values for their respective varkeys.
+ * $varvals[varname] = "value"
+ *
+ * @var array
+ * @access private
+ * @see set_var
+ */
+ var $varvals = array();
+
+ /**
+ * Determines how to output variable tags with no assigned value in templates.
+ *
+ * @var string
+ * @access private
+ * @see set_unknowns
+ */
+ var $unknowns = "remove";
+
+ /**
+ * Determines how Template handles error conditions.
+ * "yes" = the error is reported, then execution is halted
+ * "report" = the error is reported, then execution continues by returning "false"
+ * "no" = errors are silently ignored, and execution resumes reporting "false"
+ *
+ * @var string
+ * @access public
+ * @see halt
+ */
+ var $halt_on_error = "yes";
+
+ /**
+ * The last error message is retained in this variable.
+ *
+ * @var string
+ * @access public
+ * @see halt
+ */
+ var $last_error = "";
+
+ /******************************************************************************
+ * Class constructor. May be called with two optional parameters.
+ * The first parameter sets the template directory the second parameter
+ * sets the policy regarding handling of unknown variables.
+ *
+ * usage: Template([string $root = "."], [string $unknowns = "remove"])
+ *
+ * @param $root path to template directory
+ * @param $string what to do with undefined variables
+ * @see set_root
+ * @see set_unknowns
+ * @access public
+ * @return void
+ */
+ function Template($root = ".", $unknowns = "remove") {
+ if ($this->debug & 4) {
+ echo "<p><b>Template:</b> root = $root, unknowns = $unknowns</p>\n";
+ }
+ $this->set_root($root);
+ $this->set_unknowns($unknowns);
+ }
+
+
+ /******************************************************************************
+ * Checks that $root is a valid directory and if so sets this directory as the
+ * base directory from which templates are loaded by storing the value in
+ * $this->root. Relative filenames are prepended with the path in $this->root.
+ *
+ * Returns true on success, false on error.
+ *
+ * usage: set_root(string $root)
+ *
+ * @param $root string containing new template directory
+ * @see root
+ * @access public
+ * @return boolean
+ */
+ function set_root($root) {
+ if(ereg('/$', $root)) {
+ $root = substr($root, 0, -1);
+ }
+ if ($this->debug & 4) {
+ echo "<p><b>set_root:</b> root = $root</p>\n";
+ }
+ if (!is_dir($root)) {
+ $this->halt("set_root: $root is not a directory.");
+ return false;
+ }
+
+ $this->root = $root;
+ return true;
+ }
+
+
+ /******************************************************************************
+ * Sets the policy for dealing with unresolved variable names.
+ *
+ * unknowns defines what to do with undefined template variables
+ * "remove" = remove undefined variables
+ * "comment" = replace undefined variables with comments
+ * "keep" = keep undefined variables
+ *
+ * Note: "comment" can cause unexpected results when the variable tag is embedded
+ * inside an HTML tag, for example a tag which is expected to be replaced with a URL.
+ *
+ * usage: set_unknowns(string $unknowns)
+ *
+ * @param $unknowns new value for unknowns
+ * @see unknowns
+ * @access public
+ * @return void
+ */
+ function set_unknowns($unknowns = "remove") {
+ if ($this->debug & 4) {
+ echo "<p><b>unknowns:</b> unknowns = $unknowns</p>\n";
+ }
+ $this->unknowns = $unknowns;
+ }
+
+
+ /******************************************************************************
+ * Defines a filename for the initial value of a variable.
+ *
+ * It may be passed either a varname and a file name as two strings or
+ * a hash of strings with the key being the varname and the value
+ * being the file name.
+ *
+ * The new mappings are stored in the array $this->file.
+ * The files are not loaded yet, but only when needed.
+ *
+ * Returns true on success, false on error.
+ *
+ * usage: set_file(array $filelist = (string $varname => string $filename))
+ * or
+ * usage: set_file(string $varname, string $filename)
+ *
+ * @param $varname either a string containing a varname or a hash of varname/file name pairs.
+ * @param $filename if varname is a string this is the filename otherwise filename is not required
+ * @access public
+ * @return boolean
+ */
+ function set_file($varname, $filename = "") {
+ if (!is_array($varname)) {
+ if ($this->debug & 4) {
+ echo "<p><b>set_file:</b> (with scalar) varname = $varname, filename = $filename</p>\n";
+ }
+ if ($filename == "") {
+ $this->halt("set_file: For varname $varname filename is empty.");
+ return false;
+ }
+ $this->file[$varname] = $this->filename($filename);
+ } else {
+ reset($varname);
+ while (list($v, $f) = each($varname)) {
+ if ($this->debug & 4) {
+ echo "<p><b>set_file:</b> (with array) varname = $v, filename = $f</p>\n";
+ }
+ if ($f == "") {
+ $this->halt("set_file: For varname $v filename is empty.");
+ return false;
+ }
+ $this->file[$v] = $this->filename($f);
+ }
+ }
+ return true;
+ }
+
+
+ /******************************************************************************
+ * A variable $parent may contain a variable block defined by:
+ * <!-- BEGIN $varname --> content <!-- END $varname -->. This function removes
+ * that block from $parent and replaces it with a variable reference named $name.
+ * The block is inserted into the varkeys and varvals hashes. If $name is
+ * omitted, it is assumed to be the same as $varname.
+ *
+ * Blocks may be nested but care must be taken to extract the blocks in order
+ * from the innermost block to the outermost block.
+ *
+ * Returns true on success, false on error.
+ *
+ * usage: set_block(string $parent, string $varname, [string $name = ""])
+ *
+ * @param $parent a string containing the name of the parent variable
+ * @param $varname a string containing the name of the block to be extracted
+ * @param $name the name of the variable in which to store the block
+ * @access public
+ * @return boolean
+ */
+ function set_block($parent, $varname, $name = "") {
+ if ($this->debug & 4) {
+ echo "<p><b>set_block:</b> parent = $parent, varname = $varname, name = $name</p>\n";
+ }
+ if (!$this->loadfile($parent)) {
+ $this->halt("set_block: unable to load $parent.");
+ return false;
+ }
+ if ($name == "") {
+ $name = $varname;
+ }
+
+ $str = $this->get_var($parent);
+ $reg = "/[ \t]*<!--\s+BEGIN $varname\s+-->\s*?\n?(\s*.*?\n?)\s*<!--\s+END $varname\s+-->\s*?\n?/sm";
+ preg_match_all($reg, $str, $m);
+ if (!isset($m[1][0])) {
+ $this->halt("set_block: unable to set block $varname.");
+ return false;
+ }
+ $str = preg_replace($reg, "{" . $name . "}", $str);
+ $this->set_var($varname, $m[1][0]);
+ $this->set_var($parent, $str);
+ return true;
+ }
+
+
+ /******************************************************************************
+ * This functions sets the value of a variable.
+ *
+ * It may be called with either a varname and a value as two strings or an
+ * an associative array with the key being the varname and the value being
+ * the new variable value.
+ *
+ * The function inserts the new value of the variable into the $varkeys and
+ * $varvals hashes. It is not necessary for a variable to exist in these hashes
+ * before calling this function.
+ *
+ * An optional third parameter allows the value for each varname to be appended
+ * to the existing variable instead of replacing it. The default is to replace.
+ * This feature was introduced after the 7.2d release.
+ *
+ *
+ * usage: set_var(string $varname, [string $value = ""], [boolean $append = false])
+ * or
+ * usage: set_var(array $varname = (string $varname => string $value), [mixed $dummy_var], [boolean $append = false])
+ *
+ * @param $varname either a string containing a varname or a hash of varname/value pairs.
+ * @param $value if $varname is a string this contains the new value for the variable otherwise this parameter is ignored
+ * @param $append if true, the value is appended to the variable's existing value
+ * @access public
+ * @return void
+ */
+ function set_var($varname, $value = "", $append = false) {
+ if (!is_array($varname)) {
+ if (!empty($varname)) {
+ if ($this->debug & 1) {
+ printf("<b>set_var:</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($value));
+ }
+ $this->varkeys[$varname] = "/".$this->varname($varname)."/";
+ if ($append && isset($this->varvals[$varname])) {
+ $this->varvals[$varname] .= $value;
+ } else {
+ $this->varvals[$varname] = $value;
+ }
+ }
+ } else {
+ reset($varname);
+ while (list($k, $v) = each($varname)) {
+ if (!empty($k)) {
+ if ($this->debug & 1) {
+ printf("<b>set_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $k, htmlentities($v));
+ }
+ $this->varkeys[$k] = "/".$this->varname($k)."/";
+ if ($append && isset($this->varvals[$k])) {
+ $this->varvals[$k] .= $v;
+ } else {
+ $this->varvals[$k] = $v;
+ }
+ }
+ }
+ }
+ }
+
+
+ /******************************************************************************
+ * This functions clears the value of a variable.
+ *
+ * It may be called with either a varname as a string or an array with the
+ * values being the varnames to be cleared.
+ *
+ * The function sets the value of the variable in the $varkeys and $varvals
+ * hashes to "". It is not necessary for a variable to exist in these hashes
+ * before calling this function.
+ *
+ *
+ * usage: clear_var(string $varname)
+ * or
+ * usage: clear_var(array $varname = (string $varname))
+ *
+ * @param $varname either a string containing a varname or an array of varnames.
+ * @access public
+ * @return void
+ */
+ function clear_var($varname) {
+ if (!is_array($varname)) {
+ if (!empty($varname)) {
+ if ($this->debug & 1) {
+ printf("<b>clear_var:</b> (with scalar) <b>%s</b><br>\n", $varname);
+ }
+ $this->set_var($varname, "");
+ }
+ } else {
+ reset($varname);
+ while (list($k, $v) = each($varname)) {
+ if (!empty($v)) {
+ if ($this->debug & 1) {
+ printf("<b>clear_var:</b> (with array) <b>%s</b><br>\n", $v);
+ }
+ $this->set_var($v, "");
+ }
+ }
+ }
+ }
+
+
+ /******************************************************************************
+ * This functions unsets a variable completely.
+ *
+ * It may be called with either a varname as a string or an array with the
+ * values being the varnames to be cleared.
+ *
+ * The function removes the variable from the $varkeys and $varvals hashes.
+ * It is not necessary for a variable to exist in these hashes before calling
+ * this function.
+ *
+ *
+ * usage: unset_var(string $varname)
+ * or
+ * usage: unset_var(array $varname = (string $varname))
+ *
+ * @param $varname either a string containing a varname or an array of varnames.
+ * @access public
+ * @return void
+ */
+ function unset_var($varname) {
+ if (!is_array($varname)) {
+ if (!empty($varname)) {
+ if ($this->debug & 1) {
+ printf("<b>unset_var:</b> (with scalar) <b>%s</b><br>\n", $varname);
+ }
+ unset($this->varkeys[$varname]);
+ unset($this->varvals[$varname]);
+ }
+ } else {
+ reset($varname);
+ while (list($k, $v) = each($varname)) {
+ if (!empty($v)) {
+ if ($this->debug & 1) {
+ printf("<b>unset_var:</b> (with array) <b>%s</b><br>\n", $v);
+ }
+ unset($this->varkeys[$v]);
+ unset($this->varvals[$v]);
+ }
+ }
+ }
+ }
+
+
+ /******************************************************************************
+ * This function fills in all the variables contained within the variable named
+ * $varname. The resulting value is returned as the function result and the
+ * original value of the variable varname is not changed. The resulting string
+ * is not "finished", that is, the unresolved variable name policy has not been
+ * applied yet.
+ *
+ * Returns: the value of the variable $varname with all variables substituted.
+ *
+ * usage: subst(string $varname)
+ *
+ * @param $varname the name of the variable within which variables are to be substituted
+ * @access public
+ * @return string
+ */
+ function subst($varname) {
+ $varvals_quoted = array();
+ if ($this->debug & 4) {
+ echo "<p><b>subst:</b> varname = $varname</p>\n";
+ }
+ if (!$this->loadfile($varname)) {
+ $this->halt("subst: unable to load $varname.");
+ return false;
+ }
+
+ // quote the replacement strings to prevent bogus stripping of special chars
+ reset($this->varvals);
+ while (list($k, $v) = each($this->varvals)) {
+ $varvals_quoted[$k] = preg_replace(array('/\\\\/', '/\$/'), array('\\\\\\\\', '\\\\$'), $v);
+ }
+
+ $str = $this->get_var($varname);
+ $str = preg_replace($this->varkeys, $varvals_quoted, $str);
+ return $str;
+ }
+
+
+ /******************************************************************************
+ * This is shorthand for print $this->subst($varname). See subst for further
+ * details.
+ *
+ * Returns: always returns false.
+ *
+ * usage: psubst(string $varname)
+ *
+ * @param $varname the name of the variable within which variables are to be substituted
+ * @access public
+ * @return false
+ * @see subst
+ */
+ function psubst($varname) {
+ if ($this->debug & 4) {
+ echo "<p><b>psubst:</b> varname = $varname</p>\n";
+ }
+ print $this->subst($varname);
+
+ return false;
+ }
+
+
+ /******************************************************************************
+ * The function substitutes the values of all defined variables in the variable
+ * named $varname and stores or appends the result in the variable named $target.
+ *
+ * It may be called with either a target and a varname as two strings or a
+ * target as a string and an array of variable names in varname.
+ *
+ * The function inserts the new value of the variable into the $varkeys and
+ * $varvals hashes. It is not necessary for a variable to exist in these hashes
+ * before calling this function.
+ *
+ * An optional third parameter allows the value for each varname to be appended
+ * to the existing target variable instead of replacing it. The default is to
+ * replace.
+ *
+ * If $target and $varname are both strings, the substituted value of the
+ * variable $varname is inserted into or appended to $target.
+ *
+ * If $handle is an array of variable names the variables named by $handle are
+ * sequentially substituted and the result of each substitution step is
+ * inserted into or appended to in $target. The resulting substitution is
+ * available in the variable named by $target, as is each intermediate step
+ * for the next $varname in sequence. Note that while it is possible, it
+ * is only rarely desirable to call this function with an array of varnames
+ * and with $append = true. This append feature was introduced after the 7.2d
+ * release.
+ *
+ * Returns: the last value assigned to $target.
+ *
+ * usage: parse(string $target, string $varname, [boolean $append])
+ * or
+ * usage: parse(string $target, array $varname = (string $varname), [boolean $append])
+ *
+ * @param $target a string containing the name of the variable into which substituted $varnames are to be stored
+ * @param $varname if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted
+ * @param $append if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced
+ * @access public
+ * @return string
+ * @see subst
+ */
+ function parse($target, $varname, $append = false) {
+ if (!is_array($varname)) {
+ if ($this->debug & 4) {
+ echo "<p><b>parse:</b> (with scalar) target = $target, varname = $varname, append = $append</p>\n";
+ }
+ $str = $this->subst($varname);
+ if ($append) {
+ $this->set_var($target, $this->get_var($target) . $str);
+ } else {
+ $this->set_var($target, $str);
+ }
+ } else {
+ reset($varname);
+ while (list($i, $v) = each($varname)) {
+ if ($this->debug & 4) {
+ echo "<p><b>parse:</b> (with array) target = $target, i = $i, varname = $v, append = $append</p>\n";
+ }
+ $str = $this->subst($v);
+ if ($append) {
+ $this->set_var($target, $this->get_var($target) . $str);
+ } else {
+ $this->set_var($target, $str);
+ }
+ }
+ }
+
+ if ($this->debug & 4) {
+ echo "<p><b>parse:</b> completed</p>\n";
+ }
+ return $this->get_var($target);
+ }
+
+
+ /******************************************************************************
+ * This is shorthand for print $this->parse(...) and is functionally identical.
+ * See parse for further details.
+ *
+ * Returns: always returns false.
+ *
+ * usage: pparse(string $target, string $varname, [boolean $append])
+ * or
+ * usage: pparse(string $target, array $varname = (string $varname), [boolean $append])
+ *
+ * @param $target a string containing the name of the variable into which substituted $varnames are to be stored
+ * @param $varname if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted
+ * @param $append if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced
+ * @access public
+ * @return false
+ * @see parse
+ */
+ function pparse($target, $varname, $append = false) {
+ if ($this->debug & 4) {
+ echo "<p><b>pparse:</b> passing parameters to parse...</p>\n";
+ }
+ print $this->finish($this->parse($target, $varname, $append));
+ return false;
+ }
+
+
+ /******************************************************************************
+ * This function returns an associative array of all defined variables with the
+ * name as the key and the value of the variable as the value.
+ *
+ * This is mostly useful for debugging. Also note that $this->debug can be used
+ * to echo all variable assignments as they occur and to trace execution.
+ *
+ * Returns: a hash of all defined variable values keyed by their names.
+ *
+ * usage: get_vars()
+ *
+ * @access public
+ * @return array
+ * @see $debug
+ */
+ function get_vars() {
+ if ($this->debug & 4) {
+ echo "<p><b>get_vars:</b> constructing array of vars...</p>\n";
+ }
+ reset($this->varkeys);
+ while (list($k, $v) = each($this->varkeys)) {
+ $result[$k] = $this->get_var($k);
+ }
+ return $result;
+ }
+
+
+ /******************************************************************************
+ * This function returns the value of the variable named by $varname.
+ * If $varname references a file and that file has not been loaded yet, the
+ * variable will be reported as empty.
+ *
+ * When called with an array of variable names this function will return a a
+ * hash of variable values keyed by their names.
+ *
+ * Returns: a string or an array containing the value of $varname.
+ *
+ * usage: get_var(string $varname)
+ * or
+ * usage: get_var(array $varname)
+ *
+ * @param $varname if a string, the name the name of the variable to get the value of, or if an array a list of variables to return the value of
+ * @access public
+ * @return string or array
+ */
+ function get_var($varname) {
+ if (!is_array($varname)) {
+ if (isset($this->varvals[$varname])) {
+ $str = $this->varvals[$varname];
+ } else {
+ $str = "";
+ }
+ if ($this->debug & 2) {
+ printf ("<b>get_var</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($str));
+ }
+ return $str;
+ } else {
+ reset($varname);
+ while (list($k, $v) = each($varname)) {
+ if (isset($this->varvals[$v])) {
+ $str = $this->varvals[$v];
+ } else {
+ $str = "";
+ }
+ if ($this->debug & 2) {
+ printf ("<b>get_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $v, htmlentities($str));
+ }
+ $result[$v] = $str;
+ }
+ return $result;
+ }
+ }
+
+
+ /******************************************************************************
+ * This function returns a hash of unresolved variable names in $varname, keyed
+ * by their names (that is, the hash has the form $a[$name] = $name).
+ *
+ * Returns: a hash of varname/varname pairs or false on error.
+ *
+ * usage: get_undefined(string $varname)
+ *
+ * @param $varname a string containing the name the name of the variable to scan for unresolved variables
+ * @access public
+ * @return array
+ */
+ function get_undefined($varname) {
+ if ($this->debug & 4) {
+ echo "<p><b>get_undefined:</b> varname = $varname</p>\n";
+ }
+ if (!$this->loadfile($varname)) {
+ $this->halt("get_undefined: unable to load $varname.");
+ return false;
+ }
+
+ preg_match_all(
+ (("loose" == $this->unknown_regexp) ? "/{([^ \t\r\n}]+)}/" : "/{([_a-zA-Z]\\w+)}/"),
+ $this->get_var($varname),
+ $m);
+ $m = $m[1];
+ if (!is_array($m)) {
+ return false;
+ }
+
+ reset($m);
+ while (list($k, $v) = each($m)) {
+ if (!isset($this->varkeys[$v])) {
+ if ($this->debug & 4) {
+ echo "<p><b>get_undefined:</b> undefined: $v</p>\n";
+ }
+ $result[$v] = $v;
+ }
+ }
+
+ if (count($result)) {
+ return $result;
+ } else {
+ return false;
+ }
+ }
+
+
+ /******************************************************************************
+ * This function returns the finished version of $str. That is, the policy
+ * regarding unresolved variable names will be applied to $str.
+ *
+ * Returns: a finished string derived from $str and $this->unknowns.
+ *
+ * usage: finish(string $str)
+ *
+ * @param $str a string to which to apply the unresolved variable policy
+ * @access public
+ * @return string
+ * @see set_unknowns
+ */
+ function finish($str) {
+ switch ($this->unknowns) {
+ case "keep":
+ break;
+
+ case "remove":
+ $str = preg_replace(
+ (("loose" == $this->unknown_regexp) ? "/{([^ \t\r\n}]+)}/" : "/{([_a-zA-Z]\\w+)}/"),
+ "",
+ $str);
+ break;
+
+ case "comment":
+ $str = preg_replace(
+ (("loose" == $this->unknown_regexp) ? "/{([^ \t\r\n}]+)}/" : "/{([_a-zA-Z]\\w+)}/"),
+ "<!-- Template variable \\1 undefined -->",
+ $str);
+ break;
+ }
+
+ return $str;
+ }
+
+
+ /******************************************************************************
+ * This function prints the finished version of the value of the variable named
+ * by $varname. That is, the policy regarding unresolved variable names will be
+ * applied to the variable $varname then it will be printed.
+ *
+ * usage: p(string $varname)
+ *
+ * @param $varname a string containing the name of the variable to finish and print
+ * @access public
+ * @return void
+ * @see set_unknowns
+ * @see finish
+ */
+ function p($varname) {
+ print $this->finish($this->get_var($varname));
+ }
+
+
+ /******************************************************************************
+ * This function returns the finished version of the value of the variable named
+ * by $varname. That is, the policy regarding unresolved variable names will be
+ * applied to the variable $varname and the result returned.
+ *
+ * Returns: a finished string derived from the variable $varname.
+ *
+ * usage: get(string $varname)
+ *
+ * @param $varname a string containing the name of the variable to finish
+ * @access public
+ * @return void
+ * @see set_unknowns
+ * @see finish
+ */
+ function get($varname) {
+ return $this->finish($this->get_var($varname));
+ }
+
+
+ /******************************************************************************
+ * When called with a relative pathname, this function will return the pathname
+ * with $this->root prepended. Absolute pathnames are returned unchanged.
+ *
+ * Returns: a string containing an absolute pathname.
+ *
+ * usage: filename(string $filename)
+ *
+ * @param $filename a string containing a filename
+ * @access private
+ * @return string
+ * @see set_root
+ */
+ function filename($filename) {
+ if ($this->debug & 4) {
+ echo "<p><b>filename:</b> filename = $filename</p>\n";
+ }
+ if (substr($filename, 0, 1) != "/"
+ && substr($filename, 0, 1) != "\\"
+ && substr($filename, 1, 2) != ":\\"
+ && substr($filename, 1, 2) != ":/"
+ ) {
+ $filename = $this->root."/".$filename;
+ }
+
+ if (!file_exists($filename)) {
+ $this->halt("filename: file $filename does not exist.");
+ }
+ return $filename;
+ }
+
+
+ /******************************************************************************
+ * This function will construct a regexp for a given variable name with any
+ * special chars quoted.
+ *
+ * Returns: a string containing an escaped variable name.
+ *
+ * usage: varname(string $varname)
+ *
+ * @param $varname a string containing a variable name
+ * @access private
+ * @return string
+ */
+ function varname($varname) {
+ return preg_quote("{" . $varname . "}");
+ }
+
+
+ /******************************************************************************
+ * If a variable's value is undefined and the variable has a filename stored in
+ * $this->file[$varname] then the backing file will be loaded and the file's
+ * contents will be assigned as the variable's value.
+ *
+ * Note that the behaviour of this function changed slightly after the 7.2d
+ * release. Where previously a variable was reloaded from file if the value
+ * was empty, now this is not done. This allows a variable to be loaded then
+ * set to "", and also prevents attempts to load empty variables. Files are
+ * now only loaded if $this->varvals[$varname] is unset.
+ *
+ * Returns: true on success, false on error.
+ *
+ * usage: loadfile(string $varname)
+ *
+ * @param $varname a string containing the name of a variable to load
+ * @access private
+ * @return boolean
+ * @see set_file
+ */
+ function loadfile($varname) {
+ if ($this->debug & 4) {
+ echo "<p><b>loadfile:</b> varname = $varname</p>\n";
+ }
+
+ if (!isset($this->file[$varname])) {
+ // $varname does not reference a file so return
+ if ($this->debug & 4) {
+ echo "<p><b>loadfile:</b> varname $varname does not reference a file</p>\n";
+ }
+ return true;
+ }
+
+ if (isset($this->varvals[$varname])) {
+ // will only be unset if varname was created with set_file and has never been loaded
+ // $varname has already been loaded so return
+ if ($this->debug & 4) {
+ echo "<p><b>loadfile:</b> varname $varname is already loaded</p>\n";
+ }
+ return true;
+ }
+ $filename = $this->file[$varname];
+
+ /* use @file here to avoid leaking filesystem information if there is an error */
+ $str = implode("", @file($filename));
+ if (empty($str)) {
+ $this->halt("loadfile: While loading $varname, $filename does not exist or is empty.");
+ return false;
+ }
+
+ if ($this->filename_comments) {
+ $str = "<!-- START FILE $filename -->\n$str<!-- END FILE $filename -->\n";
+ }
+ if ($this->debug & 4) {
+ printf("<b>loadfile:</b> loaded $filename into $varname<br>\n");
+ }
+ $this->set_var($varname, $str);
+
+ return true;
+ }
+
+
+ /******************************************************************************
+ * This function is called whenever an error occurs and will handle the error
+ * according to the policy defined in $this->halt_on_error. Additionally the
+ * error message will be saved in $this->last_error.
+ *
+ * Returns: always returns false.
+ *
+ * usage: halt(string $msg)
+ *
+ * @param $msg a string containing an error message
+ * @access private
+ * @return void
+ * @see $halt_on_error
+ */
+ function halt($msg) {
+ $this->last_error = $msg;
+
+ if ($this->halt_on_error != "no") {
+ $this->haltmsg($msg);
+ }
+
+ if ($this->halt_on_error == "yes") {
+ die("<b>Halted.</b>");
+ }
+
+ return false;
+ }
+
+
+ /******************************************************************************
+ * This function prints an error message.
+ * It can be overridden by your subclass of Template. It will be called with an
+ * error message to display.
+ *
+ * usage: haltmsg(string $msg)
+ *
+ * @param $msg a string containing the error message to display
+ * @access public
+ * @return void
+ * @see halt
+ */
+ function haltmsg($msg) {
+ printf("<b>Template Error:</b> %s<br>\n", $msg);
+ }
+
+}
+?>
Property changes on: trunk/1.0/required/template.inc
___________________________________________________________________
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Deleted: trunk/1.0/template.inc
===================================================================
--- trunk/1.0/template.inc 2009-01-29 21:48:59 UTC (rev 337)
+++ trunk/1.0/template.inc 2009-01-29 21:50:55 UTC (rev 338)
@@ -1,1013 +0,0 @@
-<?php
-/*
- * Session Management for PHP3
- *
- * (C) Copyright 1999-2000 NetUSE GmbH
- * Kristian Koehntopp
- *
- * $Id: template.inc,v 1.15 2004/07/23 20:36:29 layne_weathers Exp $
- *
- */
-
-/*
- * Change log since version 7.2c
- *
- * Bug fixes to version 7.2c compiled by Richard Archer <rh...@ju...>:
- * (credits given to first person to post a diff to phplib mailing list)
- *
- * Normalised all comments and whitespace (rha)
- * replaced "$handle" with "$varname" and "$h" with "$v" throughout (from phplib-devel)
- * added braces around all one-line if statements in: get_undefined, loadfile and halt (rha)
- * set_var was missing two sets of braces (rha)
- * added a couple of "return true" statements (rha)
- * set_unknowns had "keep" as default instead of "remove" (from phplib-devel)
- * set_file failed to check for empty strings if passed an array of filenames (phplib-devel)
- * remove @ from call to preg_replace in subst -- report errors if there are any (NickM)
- * set_block unnecessarily required a newline in the template file (Marc Tardif)
- * pparse now calls this->finish to replace undefined vars (Layne Weathers)
- * get_var now checks for unset varnames (NickM & rha)
- * get_var when passed an array used the array key instead of the value (rha)
- * get_vars now uses a call to get_var rather than this->varvals to prevent undefined var warning (rha)
- * in finish, the replacement string referenced an unset variable (rha)
- * loadfile would try to load a file if the varval had been set to "" (rha)
- * in get_undefined, only match non-whitespace in variable tags as in finish (Layne Weathers & rha)
- * more elegant fix to the problem of subst stripping '$n', '\n' and '\\' strings (rha)
- * parse uses get_var to obtain return value (Jordi via SF)
- * set_block reports an error if the block could not be extracted (rha)
- * filename is now windows-pathname aware (krabu @ SF)
- *
- *
- * Changes in functionality which go beyond bug fixes:
- *
- * added ability for filename comments to be output (from phplib-users layne)
- * changed debug handling so set, get and internals can be tracked separately (rha)
- * added debug statements throughout to track most function calls (rha)
- * debug output contained raw HTML -- is now escaped with htmlentities (rha)
- * Alter regex in set_block to remove more whitespace around BEGIN/END tags to improve HTML layout (rha)
- * Add "append" option to set_var, works just like append in parse (dale at linuxwebpro.com, rha)
- * Altered parse so that append is honored if passed an array (Brian)
- * Converted comments and documentation to phpdoc style (rha)
- * Added clear_var to set the value of variables to "" (rha)
- * Added unset_var to usset variables (rha)
- *
- */
-
-/**
- * The template class allows you to keep your HTML code in some external files
- * which are completely free of PHP code, but contain replacement fields.
- * The class provides you with functions which can fill in the replacement fields
- * with arbitrary strings. These strings can become very large, e.g. entire tables.
- *
- * Note: If you think that this is like FastTemplates, read carefully. It isn't.
- */
-
-class Template
-{
- /**
- * Serialization helper, the name of this class.
- *
- * @var string
- * @access public
- */
- var $classname = "Template";
-
- /**
- * Determines how much debugging output Template will produce.
- * This is a bitwise mask of available debug levels:
- * 0 = no debugging
- * 1 = debug variable assignments
- * 2 = debug calls to get variable
- * 4 = debug internals (outputs all function calls with parameters).
- *
- * Note: setting $this->debug = true will enable debugging of variable
- * assignments only which is the same behaviour as versions up to release 7.2d.
- *
- * @var int
- * @access public
- */
- var $debug = false;
-
- /**
- * Determines whether Template outputs filename comments.
- * false = no filename outputs
- * true = HTML comments (e.g. <!-- START FILE $filename -->) placed in output
- *
- * @var int
- * @access public
- */
- var $filename_comments = false;
-
- /**
- * Determines the regular expression used to find unknown variable tags.
- * "loose" = traditional match all curly braces with no whitespace between
- * "strict" = adopts PHP's variable naming rules
- * ("loose" has a nasty habit of deleting JavaScript RegEx components)
- * (should future major version releases of PHPLib default this "strict"?)
- *
- * @var string
- * @access public
- */
- var $unknown_regexp = "loose";
-
- /**
- * The base directory from which template files are loaded.
- *
- * @var string
- * @access private
- * @see set_root
- */
- var $root = ".";
-
- /**
- * A hash of strings forming a translation table which translates variable names
- * into names of files containing the variable content.
- * $file[varname] = "filename";
- *
- * @var array
- * @access private
- * @see set_file
- */
- var $file = array();
-
- /**
- * A hash of strings forming a translation table which translates variable names
- * into regular expressions for themselves.
- * $varkeys[varname] = "/varname/"
- *
- * @var array
- * @access private
- * @see set_var
- */
- var $varkeys = array();
-
- /**
- * A hash of strings forming a translation table which translates variable names
- * into values for their respective varkeys.
- * $varvals[varname] = "value"
- *
- * @var array
- * @access private
- * @see set_var
- */
- var $varvals = array();
-
- /**
- * Determines how to output variable tags with no assigned value in templates.
- *
- * @var string
- * @access private
- * @see set_unknowns
- */
- var $unknowns = "remove";
-
- /**
- * Determines how Template handles error conditions.
- * "yes" = the error is reported, then execution is halted
- * "report" = the error is reported, then execution continues by returning "false"
- * "no" = errors are silently ignored, and execution resumes reporting "false"
- *
- * @var string
- * @access public
- * @see halt
- */
- var $halt_on_error = "yes";
-
- /**
- * The last error message is retained in this variable.
- *
- * @var string
- * @access public
- * @see halt
- */
- var $last_error = "";
-
- /******************************************************************************
- * Class constructor. May be called with two optional parameters.
- * The first parameter sets the template directory the second parameter
- * sets the policy regarding handling of unknown variables.
- *
- * usage: Template([string $root = "."], [string $unknowns = "remove"])
- *
- * @param $root path to template directory
- * @param $string what to do with undefined variables
- * @see set_root
- * @see set_unknowns
- * @access public
- * @return void
- */
- function Template($root = ".", $unknowns = "remove") {
- if ($this->debug & 4) {
- echo "<p><b>Template:</b> root = $root, unknowns = $unknowns</p>\n";
- }
- $this->set_root($root);
- $this->set_unknowns($unknowns);
- }
-
-
- /******************************************************************************
- * Checks that $root is a valid directory and if so sets this directory as the
- * base directory from which templates are loaded by storing the value in
- * $this->root. Relative filenames are prepended with the path in $this->root.
- *
- * Returns true on success, false on error.
- *
- * usage: set_root(string $root)
- *
- * @param $root string containing new template directory
- * @see root
- * @access public
- * @return boolean
- */
- function set_root($root) {
- if(ereg('/$', $root)) {
- $root = substr($root, 0, -1);
- }
- if ($this->debug & 4) {
- echo "<p><b>set_root:</b> root = $root</p>\n";
- }
- if (!is_dir($root)) {
- $this->halt("set_root: $root is not a directory.");
- return false;
- }
-
- $this->root = $root;
- return true;
- }
-
-
- /******************************************************************************
- * Sets the policy for dealing with unresolved variable names.
- *
- * unknowns defines what to do with undefined template variables
- * "remove" = remove undefined variables
- * "comment" = replace undefined variables with comments
- * "keep" = keep undefined variables
- *
- * Note: "comment" can cause unexpected results when the variable tag is embedded
- * inside an HTML tag, for example a tag which is expected to be replaced with a URL.
- *
- * usage: set_unknowns(string $unknowns)
- *
- * @param $unknowns new value for unknowns
- * @see unknowns
- * @access public
- * @return void
- */
- function set_unknowns($unknowns = "remove") {
- if ($this->debug & 4) {
- echo "<p><b>unknowns:</b> unknowns = $unknowns</p>\n";
- }
- $this->unknowns = $unknowns;
- }
-
-
- /******************************************************************************
- * Defines a filename for the initial value of a variable.
- *
- * It may be passed either a varname and a file name as two strings or
- * a hash of strings with the key being the varname and the value
- * being the file name.
- *
- * The new mappings are stored in the array $this->file.
- * The files are not loaded yet, but only when needed.
- *
- * Returns true on success, false on error.
- *
- * usage: set_file(array $filelist = (string $varname => string $filename))
- * or
- * usage: set_file(string $varname, string $filename)
- *
- * @param $varname either a string containing a varname or a hash of varname/file name pairs.
- * @param $filename if varname is a string this is the filename otherwise filename is not required
- * @access public
- * @return boolean
- */
- function set_file($varname, $filename = "") {
- if (!is_array($varname)) {
- if ($this->debug & 4) {
- echo "<p><b>set_file:</b> (with scalar) varname = $varname, filename = $filename</p>\n";
- }
- if ($filename == "") {
- $this->halt("set_file: For varname $varname filename is empty.");
- return false;
- }
- $this->file[$varname] = $this->filename($filename);
- } else {
- reset($varname);
- while (list($v, $f) = each($varname)) {
- if ($this->debug & 4) {
- echo "<p><b>set_file:</b> (with array) varname = $v, filename = $f</p>\n";
- }
- if ($f == "") {
- $this->halt("set_file: For varname $v filename is empty.");
- return false;
- }
- $this->file[$v] = $this->filename($f);
- }
- }
- return true;
- }
-
-
- /******************************************************************************
- * A variable $parent may contain a variable block defined by:
- * <!-- BEGIN $varname --> content <!-- END $varname -->. This function removes
- * that block from $parent and replaces it with a variable reference named $name.
- * The block is inserted into the varkeys and varvals hashes. If $name is
- * omitted, it is assumed to be the same as $varname.
- *
- * Blocks may be nested but care must be taken to extract the blocks in order
- * from the innermost block to the outermost block.
- *
- * Returns true on success, false on error.
- *
- * usage: set_block(string $parent, string $varname, [string $name = ""])
- *
- * @param $parent a string containing the name of the parent variable
- * @param $varname a string containing the name of the block to be extracted
- * @param $name the name of the variable in which to store the block
- * @access public
- * @return boolean
- */
- function set_block($parent, $varname, $name = "") {
- if ($this->debug & 4) {
- echo "<p><b>set_block:</b> parent = $parent, varname = $varname, name = $name</p>\n";
- }
- if (!$this->loadfile($parent)) {
- $this->halt("set_block: unable to load $parent.");
- return false;
- }
- if ($name == "") {
- $name = $varname;
- }
-
- $str = $this->get_var($parent);
- $reg = "/[ \t]*<!--\s+BEGIN $varname\s+-->\s*?\n?(\s*.*?\n?)\s*<!--\s+END $varname\s+-->\s*?\n?/sm";
- preg_match_all($reg, $str, $m);
- if (!isset($m[1][0])) {
- $this->halt("set_block: unable to set block $varname.");
- return false;
- }
- $str = preg_replace($reg, "{" . $name . "}", $str);
- $this->set_var($varname, $m[1][0]);
- $this->set_var($parent, $str);
- return true;
- }
-
-
- /******************************************************************************
- * This functions sets the value of a variable.
- *
- * It may be called with either a varname and a value as two strings or an
- * an associative array with the key being the varname and the value being
- * the new variable value.
- *
- * The function inserts the new value of the variable into the $varkeys and
- * $varvals hashes. It is not necessary for a variable to exist in these hashes
- * before calling this function.
- *
- * An optional third parameter allows the value for each varname to be appended
- * to the existing variable instead of replacing it. The default is to replace.
- * This feature was introduced after the 7.2d release.
- *
- *
- * usage: set_var(string $varname, [string $value = ""], [boolean $append = false])
- * or
- * usage: set_var(array $varname = (string $varname => string $value), [mixed $dummy_var], [boolean $append = false])
- *
- * @param $varname either a string containing a varname or a hash of varname/value pairs.
- * @param $value if $varname is a string this contains the new value for the variable otherwise this parameter is ignored
- * @param $append if true, the value is appended to the variable's existing value
- * @access public
- * @return void
- */
- function set_var($varname, $value = "", $append = false) {
- if (!is_array($varname)) {
- if (!empty($varname)) {
- if ($this->debug & 1) {
- printf("<b>set_var:</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($value));
- }
- $this->varkeys[$varname] = "/".$this->varname($varname)."/";
- if ($append && isset($this->varvals[$varname])) {
- $this->varvals[$varname] .= $value;
- } else {
- $this->varvals[$varname] = $value;
- }
- }
- } else {
- reset($varname);
- while (list($k, $v) = each($varname)) {
- if (!empty($k)) {
- if ($this->debug & 1) {
- printf("<b>set_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $k, htmlentities($v));
- }
- $this->varkeys[$k] = "/".$this->varname($k)."/";
- if ($append && isset($this->varvals[$k])) {
- $this->varvals[$k] .= $v;
- } else {
- $this->varvals[$k] = $v;
- }
- }
- }
- }
- }
-
-
- /******************************************************************************
- * This functions clears the value of a variable.
- *
- * It may be called with either a varname as a string or an array with the
- * values being the varnames to be cleared.
- *
- * The function sets the value of the variable in the $varkeys and $varvals
- * hashes to "". It is not necessary for a variable to exist in these hashes
- * before calling this function.
- *
- *
- * usage: clear_var(string $varname)
- * or
- * usage: clear_var(array $varname = (string $varname))
- *
- * @param $varname either a string containing a varname or an array of varnames.
- * @access public
- * @return void
- */
- function clear_var($varname) {
- if (!is_array($varname)) {
- if (!empty($varname)) {
- if ($this->debug & 1) {
- printf("<b>clear_var:</b> (with scalar) <b>%s</b><br>\n", $varname);
- }
- $this->set_var($varname, "");
- }
- } else {
- reset($varname);
- while (list($k, $v) = each($varname)) {
- if (!empty($v)) {
- if ($this->debug & 1) {
- printf("<b>clear_var:</b> (with array) <b>%s</b><br>\n", $v);
- }
- $this->set_var($v, "");
- }
- }
- }
- }
-
-
- /******************************************************************************
- * This functions unsets a variable completely.
- *
- * It may be called with either a varname as a string or an array with the
- * values being the varnames to be cleared.
- *
- * The function removes the variable from the $varkeys and $varvals hashes.
- * It is not necessary for a variable to exist in these hashes before calling
- * this function.
- *
- *
- * usage: unset_var(string $varname)
- * or
- * usage: unset_var(array $varname = (string $varname))
- *
- * @param $varname either a string containing a varname or an array of varnames.
- * @access public
- * @return void
- */
- function unset_var($varname) {
- if (!is_array($varname)) {
- if (!empty($varname)) {
- if ($this->debug & 1) {
- printf("<b>unset_var:</b> (with scalar) <b>%s</b><br>\n", $varname);
- }
- unset($this->varkeys[$varname]);
- unset($this->varvals[$varname]);
- }
- } else {
- reset($varname);
- while (list($k, $v) = each($varname)) {
- if (!empty($v)) {
- if ($this->debug & 1) {
- printf("<b>unset_var:</b> (with array) <b>%s</b><br>\n", $v);
- }
- unset($this->varkeys[$v]);
- unset($this->varvals[$v]);
- }
- }
- }
- }
-
-
- /******************************************************************************
- * This function fills in all the variables contained within the variable named
- * $varname. The resulting value is returned as the function result and the
- * original value of the variable varname is not changed. The resulting string
- * is not "finished", that is, the unresolved variable name policy has not been
- * applied yet.
- *
- * Returns: the value of the variable $varname with all variables substituted.
- *
- * usage: subst(string $varname)
- *
- * @param $varname the name of the variable within which variables are to be substituted
- * @access public
- * @return string
- */
- function subst($varname) {
- $varvals_quoted = array();
- if ($this->debug & 4) {
- echo "<p><b>subst:</b> varname = $varname</p>\n";
- }
- if (!$this->loadfile($varname)) {
- $this->halt("subst: unable to load $varname.");
- return false;
- }
-
- // quote the replacement strings to prevent bogus stripping of special chars
- reset($this->varvals);
- while (list($k, $v) = each($this->varvals)) {
- $varvals_quoted[$k] = preg_replace(array('/\\\\/', '/\$/'), array('\\\\\\\\', '\\\\$'), $v);
- }
-
- $str = $this->get_var($varname);
- $str = preg_replace($this->varkeys, $varvals_quoted, $str);
- return $str;
- }
-
-
- /******************************************************************************
- * This is shorthand for print $this->subst($varname). See subst for further
- * details.
- *
- * Returns: always returns false.
- *
- * usage: psubst(string $varname)
- *
- * @param $varname the name of the variable within which variables are to be substituted
- * @access public
- * @return false
- * @see subst
- */
- function psubst($varname) {
- if ($this->debug & 4) {
- echo "<p><b>psubst:</b> varname = $varname</p>\n";
- }
- print $this->subst($varname);
-
- return false;
- }
-
-
- /******************************************************************************
- * The function substitutes the values of all defined variables in the variable
- * named $varname and stores or appends the result in the variable named $target.
- *
- * It may be called with either a target and a varname as two strings or a
- * target as a string and an array of variable names in varname.
- *
- * The function inserts the new value of the variable into the $varkeys and
- * $varvals hashes. It is not necessary for a variable to exist in these hashes
- * before calling this function.
- *
- * An optional third parameter allows the value for each varname to be appended
- * to the existing target variable instead of replacing it. The default is to
- * replace.
- *
- * If $target and $varname are both strings, the substituted value of the
- * variable $varname is inserted into or appended to $target.
- *
- * If $handle is an array of variable names the variables named by $handle are
- * sequentially substituted and the result of each substitution step is
- * inserted into or appended to in $target. The resulting substitution is
- * available in the variable named by $target, as is each intermediate step
- * for the next $varname in sequence. Note that while it is possible, it
- * is only rarely desirable to call this function with an array of varnames
- * and with $append = true. This append feature was introduced after the 7.2d
- * release.
- *
- * Returns: the last value assigned to $target.
- *
- * usage: parse(string $target, string $varname, [boolean $append])
- * or
- * usage: parse(string $target, array $varname = (string $varname), [boolean $append])
- *
- * @param $target a string containing the name of the variable into which substituted $varnames are to be stored
- * @param $varname if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted
- * @param $append if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced
- * @access public
- * @return string
- * @see subst
- */
- function parse($target, $varname, $append = false) {
- if (!is_array($varname)) {
- if ($this->debug & 4) {
- echo "<p><b>parse:</b> (with scalar) target = $target, varname = $varname, append = $append</p>\n";
- }
- $str = $this->subst($varname);
- if ($append) {
- $this->set_var($target, $this->get_var($target) . $str);
- } else {
- $this->set_var($target, $str);
- }
- } else {
- reset($varname);
- while (list($i, $v) = each($varname)) {
- if ($this->debug & 4) {
- echo "<p><b>parse:</b> (with array) target = $target, i = $i, varname = $v, append = $append</p>\n";
- }
- $str = $this->subst($v);
- if ($append) {
- $this->set_var($target, $this->get_var($target) . $str);
- } else {
- $this->set_var($target, $str);
- }
- }
- }
-
- if ($this->debug & 4) {
- echo "<p><b>parse:</b> completed</p>\n";
- }
- return $this->get_var($target);
- }
-
-
- /******************************************************************************
- * This is shorthand for print $this->parse(...) and is functionally identical.
- * See parse for further details.
- *
- * Returns: always returns false.
- *
- * usage: pparse(string...
[truncated message content] |