cs-content-commits Mailing List for CS-Content [Dynamic Content System] (Page 6)
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-06-01 14:50:02
|
Revision: 386 http://cs-content.svn.sourceforge.net/cs-content/?rev=386&view=rev Author: crazedsanity Date: 2009-06-01 14:49:57 +0000 (Mon, 01 Jun 2009) Log Message: ----------- Remove old code & consolidate how errors are displayed + use of APPURL. /contentSystem.class.php: * MAIN::: -- removed code that set SITE_ROOT globally * initialize_locals(): -- add APPURL as a template var, if it is defined. * die_gracefully(): -- push the message_box template into the 404 template and set all of the required template vars to make it appear properly. * add_template(): -- removed some debug_print() statements. /sample_files/: * updated 404 template to have a template var to stuff message_box into * update system templates to prefix image refs with {APPURL} * removed old templates (construction & db_error) * added images required to display message box. Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/sample_files/templates/system/404.shared.tmpl trunk/1.0/sample_files/templates/system/message_box.tmpl Added Paths: ----------- trunk/1.0/sample_files/public_html/images/ trunk/1.0/sample_files/public_html/images/clear.gif trunk/1.0/sample_files/public_html/images/frame/ trunk/1.0/sample_files/public_html/images/frame/crn-white-bl.gif trunk/1.0/sample_files/public_html/images/frame/crn-white-br.gif trunk/1.0/sample_files/public_html/images/frame/crn-white-tl.gif trunk/1.0/sample_files/public_html/images/frame/crn-white-tr.gif Removed Paths: ------------- trunk/1.0/sample_files/templates/system/construction.content.tmpl trunk/1.0/sample_files/templates/system/db_error.tmpl Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-31 21:22:05 UTC (rev 385) +++ trunk/1.0/contentSystem.class.php 2009-06-01 14:49:57 UTC (rev 386) @@ -63,13 +63,6 @@ * |--> /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_session.class.php"); @@ -157,6 +150,11 @@ } $this->templateObj->add_template_var('CURRENT_URL', $myUrl); + if(defined('APPURL')) { + //set the APPURL as a template var. + $this->templateObj->add_template_var('APPURL', constant('APPURL')); + } + //create a fileSystem object for templates. $tmplBaseDir = constant('SITE_ROOT') .'/templates'; if(defined('TMPLDIR')) { @@ -730,7 +728,14 @@ 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); + + //add the message box & required template vars to display the error. + $this->templateObj->add_template_var('content', $this->templateObj->file_to_string('system/message_box.tmpl')); + $this->templateObj->add_template_var('messageType', 'fatal'); + $this->templateObj->add_template_var('title', "Fatal Error"); + $this->templateObj->add_template_var('message', $details); + + $this->templateObj->add_template_var('datetime', date('m-d-Y H:i:s')); $this->templateObj->print_page(); exit; @@ -917,12 +922,9 @@ //------------------------------------------------------------------------ private final function add_template($var, $file, $allowIndex=false) { if($var == 'index' && $allowIndex !== true) { - $this->gfObj->debug_print(__METHOD__ .": set index invalidly (". $file ."), IGNORED"); + //$this->gfObj->debug_print(__METHOD__ .": set index invalidly (". $file ."), IGNORED"); } else { - if(isset($this->templateList[$var])) { - $this->gfObj->debug_print(__METHOD__ .": REPLACING [". $var ."], was (". $this->templateList[$var] .") with (". $file .")"); - } $this->templateList[$var] = $file; } }//end add_template() Added: trunk/1.0/sample_files/public_html/images/clear.gif =================================================================== (Binary files differ) Property changes on: trunk/1.0/sample_files/public_html/images/clear.gif ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/1.0/sample_files/public_html/images/frame/crn-white-bl.gif =================================================================== (Binary files differ) Property changes on: trunk/1.0/sample_files/public_html/images/frame/crn-white-bl.gif ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/1.0/sample_files/public_html/images/frame/crn-white-br.gif =================================================================== (Binary files differ) Property changes on: trunk/1.0/sample_files/public_html/images/frame/crn-white-br.gif ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/1.0/sample_files/public_html/images/frame/crn-white-tl.gif =================================================================== (Binary files differ) Property changes on: trunk/1.0/sample_files/public_html/images/frame/crn-white-tl.gif ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/1.0/sample_files/public_html/images/frame/crn-white-tr.gif =================================================================== (Binary files differ) Property changes on: trunk/1.0/sample_files/public_html/images/frame/crn-white-tr.gif ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Modified: trunk/1.0/sample_files/templates/system/404.shared.tmpl =================================================================== --- trunk/1.0/sample_files/templates/system/404.shared.tmpl 2009-05-31 21:22:05 UTC (rev 385) +++ trunk/1.0/sample_files/templates/system/404.shared.tmpl 2009-06-01 14:49:57 UTC (rev 386) @@ -8,37 +8,11 @@ --> <head> <title>Page Not Found</title> + <link rel="stylesheet" href="{APPURL}/css/site.css" type="text/css"> </head> <body> <table border=0 cellpadding=0 cellspacing=0 width="90%" align="center"> -<tr> - <!-- This row should span across the page. --> - - <td align="center" colspan=2> - <table border="0" cellpadding="0" cellspacing="0" width="100%"> -<tbody><tr> - <td align="center"> - <font face="Georgia, Times New Roman, Times, serif"> - - <table border="0" cellpadding="3" cellspacing="0"> - <tbody><tr valign="middle"> - <td align="right">Crazed</td> - <td align="center" width="118"><img border="0" src="http://crazedsanity.com/images/dev-logo.gif?from=404" width="118" width="67"></td> - - <td align="left">Sanity</td> - </tr> - <tr> - <td colspan="3" align="center"> - Dot Com<BR> - </td> - </tr> - </tbody></table> - - </font> - - </td> -</tr> <TR> <td align="center"><!-- This row should span across the page. --><hr>{datetime}<hr></td> </TR> @@ -46,23 +20,14 @@ <tr> <td> - Could not find the page requested...<BR> - <pre>{details}</pre> + + + {content} + + + </td> </tr> - <tr> - <td> - <hr> - <div align="center"><font size="1"> - All content is ©opyright CrazedSanity - Computer Industries, 1998-2007. <br> - CrazedSanity Computer Industries is a division of <a href="http://unlimited.buzzkill.org">BuzzKill - Productions Unlimited ®</a>. All rights reserved. <br> - For questions, to report a problem, or to offer your first born child as a sacrifice, - contact <a href="mailto:webmaster@127.0.0.1">webmaster -at- crazedsanity.com</a>.</font><br><br> -</div> - </td> - </tr> - </table> +</table> </body> </html> Deleted: trunk/1.0/sample_files/templates/system/construction.content.tmpl =================================================================== --- trunk/1.0/sample_files/templates/system/construction.content.tmpl 2009-05-31 21:22:05 UTC (rev 385) +++ trunk/1.0/sample_files/templates/system/construction.content.tmpl 2009-06-01 14:49:57 UTC (rev 386) @@ -1,5 +0,0 @@ -<!-- BEGIN content/construction_content.tmpl --> - <h2 align="center"><br> - <br> - It's broken. I don't know what to say, dude. -<!-- END content/construction_content.tmpl --> Deleted: trunk/1.0/sample_files/templates/system/db_error.tmpl =================================================================== --- trunk/1.0/sample_files/templates/system/db_error.tmpl 2009-05-31 21:22:05 UTC (rev 385) +++ trunk/1.0/sample_files/templates/system/db_error.tmpl 2009-06-01 14:49:57 UTC (rev 386) @@ -1,47 +0,0 @@ -<HTML> -<HEAD> - <title>CS - Database Error</title> -</HEAD> - -<body bgcolor="white" text="#666666" link="#006666" vlink="#006666" alink="#006666"> -<table border="0" cellpadding="0" cellspacing="0" width="100%"> -<tr><!-- This row should span across the page. --> - <td align="center"> - <font face="Georgia, Times New Roman, Times, serif"> - <table border=0 cellpadding=3 cellspacing=0> - <TR> - <td>Crazed</td> - <td><img border=0 src="/images/dev-logo.gif"></td> - <td>Sanity</td> - </TR> - <TR> - <td colspan="3" align="center">Dot Com</td> - </TR> - </table> - </font> - </td> -</tr> -</table> - -<hr> - -<!-- BEGIN excuse --> -<p align="center">If you're seeing this, that means something pretty bad is happening.<BR> -Either the database went down, or bigger issues have arisen.<BR> -Check back in awhile.</p> -<!-- END excuse --> - - - <hr> -<center> -<font size="1"> - <a href="http://www.buzzkill.org/"><img src="/images/Bk3dtext.jpg" width="474" height="40" border="0"></a><BR> -All content is copyright CrazedSanity.com, 1998-2004. <br> - CrazedSanity.com is a division of -<a href="http://www.buzzkill.org/">BuzzKill Productions Unlimited ®</a>. All rights reserved. <br> - For questions or to report a problem, contact -<a href="?emailLink=spam" onClick="invalidEmailLink('webmaster')">webmaster at crazedsanity dot com</a>.</font> -</center> -</body> - -</HTML> Modified: trunk/1.0/sample_files/templates/system/message_box.tmpl =================================================================== --- trunk/1.0/sample_files/templates/system/message_box.tmpl 2009-05-31 21:22:05 UTC (rev 385) +++ trunk/1.0/sample_files/templates/system/message_box.tmpl 2009-06-01 14:49:57 UTC (rev 386) @@ -1,12 +1,12 @@ -<!-- *** MESSAGE_BOX START (/help/messages/message_box.tmpl) *** --> +<!-- *** MESSAGE_BOX START (/system/message_box.tmpl) *** --> <table border="0" cellspacing="0" cellpadding="0" align="center"> <tr> - <td class="{messageType}" width="5" align="left" valign="top"><img src="/images/frame/crn-white-tl.gif" width="5" height="5" alt=""></td> - <td class="{messageType}"><img src="/images/clear.gif" width="20" height="2" alt=""></td> - <td class="{messageType}" width="5" align="right" valign="top"><img src="/images/frame/crn-white-tr.gif" width="5" height="5" alt=""></td> + <td class="{messageType}" width="5" align="left" valign="top"><img src="{APPURL}/images/frame/crn-white-tl.gif" width="5" height="5" alt=""></td> + <td class="{messageType}"><img src="{APPURL}/images/clear.gif" width="20" height="2" alt=""></td> + <td class="{messageType}" width="5" align="right" valign="top"><img src="{APPURL}/images/frame/crn-white-tr.gif" width="5" height="5" alt=""></td> </tr> <tr> - <td class="{messageType}" width="5"><img src="/images/clear.gif" width="5" height="20" alt=""></td> + <td class="{messageType}" width="5"><img src="{APPURL}/images/clear.gif" width="5" height="20" alt=""></td> <td> <table class="{messageType}" width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> @@ -16,14 +16,14 @@ {redirect} </td> </tr> </table></td> - <td class="{messageType}" width="5"><img src="/images/clear.gif" width="5" height="20" alt=""></td> + <td class="{messageType}" width="5"><img src="{APPURL}/images/clear.gif" width="5" height="20" alt=""></td> </tr> <tr> - <td class="{messageType}" width="5" align="left" valign="bottom"><img src="/images/frame/crn-white-bl.gif" width="5" height="5" alt=""></td> - <td class="{messageType}"><img src="/images/clear.gif" width="20" height="2" alt=""></td> - <td class="{messageType}" width="5" align="right" valign="bottom"><img src="/images/frame/crn-white-br.gif" width="5" height="5" alt=""></td> + <td class="{messageType}" width="5" align="left" valign="bottom"><img src="{APPURL}/images/frame/crn-white-bl.gif" width="5" height="5" alt=""></td> + <td class="{messageType}"><img src="{APPURL}/images/clear.gif" width="20" height="2" alt=""></td> + <td class="{messageType}" width="5" align="right" valign="bottom"><img src="{APPURL}/images/frame/crn-white-br.gif" width="5" height="5" alt=""></td> </tr> </table> <br> -<!-- *** MESSAGE_BOX END (/help/messages/message_box.tmpl) *** --> +<!-- *** MESSAGE_BOX END (/system/message_box.tmpl) *** --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-31 21:22:11
|
Revision: 385 http://cs-content.svn.sourceforge.net/cs-content/?rev=385&view=rev Author: crazedsanity Date: 2009-05-31 21:22:05 +0000 (Sun, 31 May 2009) Log Message: ----------- All setting of template vars in contentSystem occurs within one method. /contentSystem.class.php: * load_page_templates(); -- converted to using add_template(). * load_shared_templates(): -- use add_template(). * finish(): -- when swapping index into the "content" var, call add_template_var() * add_template_var() [NEW]: -- method for assigning template vars to files internally. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-28 13:56:42 UTC (rev 384) +++ trunk/1.0/contentSystem.class.php 2009-05-31 21:22:05 UTC (rev 385) @@ -469,8 +469,7 @@ $tmplList = $this->arrange_directory_contents('name', 'section'); if(isset($tmplList[$value])) { foreach($tmplList[$value] as $mySection=>$myTmpl) { - // - $this->templateList[$mySection] = $myTmpl; + $this->add_template($mySection, $myTmpl); } } if(!$this->tmplFs->cd($value)) { @@ -481,14 +480,14 @@ $finalTmplList = $this->arrange_directory_contents('name', 'section'); foreach($finalTmplList as $mySection => $subArr) { foreach($subArr as $internalSection => $myTmpl) { - $this->templateList[$mySection] = $myTmpl; + $this->add_template($mySection, $myTmpl); } } //go through the final section, if set, so the templates defined there are used. if(isset($finalTmplList[$finalSection])) { foreach($finalTmplList[$finalSection] as $mySection => $myTmpl) { - $this->templateList[$mySection] = $myTmpl; + $this->add_template($mySection, $myTmpl); } } @@ -497,12 +496,12 @@ $tmplList = $this->arrange_directory_contents('name', 'section'); if(isset($tmplList['index'])) { foreach($tmplList['index'] as $mySection => $myTmpl) { - $this->templateList[$mySection] = $myTmpl; + $this->add_template($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']; + $this->add_template('content', $tmplList[$this->baseDir]['content']); } } }//end load_page_templates() @@ -522,7 +521,7 @@ if(is_array($dirContents)) { foreach($dirContents as $mySection => $subArr) { foreach($subArr as $subIndex=>$templateFilename) { - $this->templateList[$mySection] = $templateFilename; + $this->add_template($mySection, $templateFilename); } } } @@ -549,7 +548,7 @@ if(count($dirContents['shared'])) { foreach($dirContents['shared'] as $section => $template) { - $this->templateList[$section] = $template; + $this->add_template($section, $template); } } }//end load_shared_templates() @@ -782,7 +781,7 @@ //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']; + $this->add_template('content', $this->templateList['index']); unset($this->templateList['index']); } @@ -916,6 +915,22 @@ //------------------------------------------------------------------------ + private final function add_template($var, $file, $allowIndex=false) { + if($var == 'index' && $allowIndex !== true) { + $this->gfObj->debug_print(__METHOD__ .": set index invalidly (". $file ."), IGNORED"); + } + else { + if(isset($this->templateList[$var])) { + $this->gfObj->debug_print(__METHOD__ .": REPLACING [". $var ."], was (". $this->templateList[$var] .") with (". $file .")"); + } + $this->templateList[$var] = $file; + } + }//end add_template() + //------------------------------------------------------------------------ + + + + //------------------------------------------------------------------------ public function inject_var($varName, $value) { $this->injectVars[$varName] = $value; }//end inject_var() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-28 14:23:08
|
Revision: 384 http://cs-content.svn.sourceforge.net/cs-content/?rev=384&view=rev Author: crazedsanity Date: 2009-05-28 13:56:42 +0000 (Thu, 28 May 2009) Log Message: ----------- Revert changes from previous commit: they're broken and based on released code which is vastly different than trunk... Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-28 04:19:30 UTC (rev 383) +++ trunk/1.0/contentSystem.class.php 2009-05-28 13:56:42 UTC (rev 384) @@ -378,17 +378,6 @@ * Retrieves the list of templates & includes in preparation for later work. */ private function prepare() { - - //Set the final section... - if(count($this->sectionArr)) { - $mySectionArr = $this->sectionArr; - $this->finalSection = array_pop($mySectionArr); - } - else { - throw new exception(__METHOD__ .": FATAL - section array is empty"); - } - - //attempt to load any includes... $this->load_includes(); $foundIncludes = count($this->includesList); @@ -443,24 +432,8 @@ $reasonText = "page template"; } 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; - } - elseif(isset($sectionLsData[$myFile]) && $sectionLsData[$myFile]['type'] == 'file') { - //we're good. - $valid = TRUE; - } - else { - $this->reason = __METHOD__ .": couldn't find base template."; - } + $this->finalSection = $this->baseDir; + $reasonText = "base template"; } $tmplFile1 = $this->section .".content.tmpl"; @@ -667,10 +640,6 @@ $this->load_dir_includes($this->baseDir); //okay, now loop through $this->sectionArr & see if we can include anything else. - $addIndex=false; - if($this->finalSection == 'index') { - $addIndex = true; - } if(($this->incFs->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) { @@ -689,9 +658,6 @@ //attempt to cd() into the next directory, or die if we can't. if(!$this->incFs->cd($mySection)) { //no dice. Break the loop. - if($this->finalSection == 'index') { - $addIndex = true; - } break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-28 04:19:31
|
Revision: 383 http://cs-content.svn.sourceforge.net/cs-content/?rev=383&view=rev Author: crazedsanity Date: 2009-05-28 04:19:30 +0000 (Thu, 28 May 2009) Log Message: ----------- Implemented changes that had been incorrectly commited to releases/1.0 @r380: *** ORIGINAL COMMIT LOG (releases/1.0@380) *** Fix problem where includes/content/index.inc wasn't loaded for the "/" URL. /contentSystem.class.php: * prepare(): -- sets the internal "finalSection" variable as the last element in the internal sectionArr (previously, it would be set as the last accessible directory in the includes directory). -- NOTE: finalSection was moved here because otherwise it was created too late for use in load_includes(). -- NOTE2: if the internal sectionArr is empty, it will now throw an exception... * validate_page(): -- no longer sets the internal finalSection value. * load_includes(): -- when considering inclusion of index.inc, has extra checks to allow it if finalSection is "index". Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-28 03:54:58 UTC (rev 382) +++ trunk/1.0/contentSystem.class.php 2009-05-28 04:19:30 UTC (rev 383) @@ -378,6 +378,17 @@ * Retrieves the list of templates & includes in preparation for later work. */ private function prepare() { + + //Set the final section... + if(count($this->sectionArr)) { + $mySectionArr = $this->sectionArr; + $this->finalSection = array_pop($mySectionArr); + } + else { + throw new exception(__METHOD__ .": FATAL - section array is empty"); + } + + //attempt to load any includes... $this->load_includes(); $foundIncludes = count($this->includesList); @@ -432,8 +443,24 @@ $reasonText = "page template"; } else { - $this->finalSection = $this->baseDir; - $reasonText = "base template"; + //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; + } + elseif(isset($sectionLsData[$myFile]) && $sectionLsData[$myFile]['type'] == 'file') { + //we're good. + $valid = TRUE; + } + else { + $this->reason = __METHOD__ .": couldn't find base template."; + } } $tmplFile1 = $this->section .".content.tmpl"; @@ -640,6 +667,10 @@ $this->load_dir_includes($this->baseDir); //okay, now loop through $this->sectionArr & see if we can include anything else. + $addIndex=false; + if($this->finalSection == 'index') { + $addIndex = true; + } if(($this->incFs->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) { @@ -658,6 +689,9 @@ //attempt to cd() into the next directory, or die if we can't. if(!$this->incFs->cd($mySection)) { //no dice. Break the loop. + if($this->finalSection == 'index') { + $addIndex = true; + } break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-28 03:55:00
|
Revision: 382 http://cs-content.svn.sourceforge.net/cs-content/?rev=382&view=rev Author: crazedsanity Date: 2009-05-28 03:54:58 +0000 (Thu, 28 May 2009) Log Message: ----------- Revert changes from r380 (accidentally committed to trunk). Modified Paths: -------------- releases/1.0/contentSystem.class.php Property Changed: ---------------- 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_session.class.php releases/1.0/cs_siteConfig.class.php releases/1.0/cs_tabs.class.php releases/1.0/required/template.inc Modified: releases/1.0/contentSystem.class.php =================================================================== --- releases/1.0/contentSystem.class.php 2009-05-27 16:06:18 UTC (rev 381) +++ releases/1.0/contentSystem.class.php 2009-05-28 03:54:58 UTC (rev 382) @@ -339,17 +339,6 @@ * Retrieves the list of templates & includes in preparation for later work. */ private function prepare() { - - //Set the final section... - if(count($this->sectionArr)) { - $mySectionArr = $this->sectionArr; - $this->finalSection = array_pop($mySectionArr); - } - else { - throw new exception(__METHOD__ .": FATAL - section array is empty"); - } - - //attempt to load any includes... if($this->fileSystemObj->cd('/includes')) { $this->load_includes(); @@ -459,10 +448,12 @@ 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."; @@ -662,9 +653,6 @@ //okay, now loop through $this->sectionArr & see if we can include anything else. $addIndex=false; - if($this->finalSection == 'index') { - $addIndex = true; - } if(($this->fileSystemObj->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) { @@ -684,9 +672,6 @@ if(!$this->fileSystemObj->cd($mySection)) { //no dice. Break the loop. $addIndex = false; - if($this->finalSection == 'index') { - $addIndex = true; - } break; } else { Property changes on: releases/1.0/contentSystem.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/cs_fileSystem.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/cs_genericPage.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/cs_globalFunctions.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/cs_phpDB.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/cs_session.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/cs_siteConfig.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/cs_tabs.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: releases/1.0/required/template.inc ___________________________________________________________________ Deleted: svn:mergeinfo - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-27 16:06:26
|
Revision: 381 http://cs-content.svn.sourceforge.net/cs-content/?rev=381&view=rev Author: crazedsanity Date: 2009-05-27 16:06:18 +0000 (Wed, 27 May 2009) Log Message: ----------- Fix for if contentSystem starts deeper in the URL (i.e. "/{app}/{content}") NOTE::: the "APPURL" constant is required for this behavior and may not be appropriately named, or may cause invalid assumptions by the developer. /contentSystem.class.php: * clean_url(): -- if "APPURL" is a valid constant, strip that from the beginning of the section string. -- EXAMPLE: if an app that uses cs-content is installed on a server where initial URL is "/apps/project/", set APPURL="/apps/project" so everything beyond that will work. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-27 04:54:31 UTC (rev 380) +++ trunk/1.0/contentSystem.class.php 2009-05-27 16:06:18 UTC (rev 381) @@ -327,7 +327,15 @@ return(NULL); } else { - //check the string to make sure it doesn't begin or end with a "/" + + //if there's an "APPURL" constant, drop that from the section. + if(defined('APPURL') && strlen(constant('APPURL'))) { + $dropThis = preg_replace('/^\//', '', constant('APPURL')); + $dropThis = preg_replace('/\//', '\\/', $dropThis); + $section = preg_replace('/^'. $dropThis .'/', '', $section); + } + + //check the string to make sure it doesn't begin with a "/" if($section[0] == '/') { $section = substr($section, 1, strlen($section)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-27 04:54:39
|
Revision: 380 http://cs-content.svn.sourceforge.net/cs-content/?rev=380&view=rev Author: crazedsanity Date: 2009-05-27 04:54:31 +0000 (Wed, 27 May 2009) Log Message: ----------- Fix problem where includes/content/index.inc wasn't loaded for the "/" URL. /contentSystem.class.php: * prepare(): -- sets the internal "finalSection" variable as the last element in the internal sectionArr (previously, it would be set as the last accessible directory in the includes directory). -- NOTE: finalSection was moved here because otherwise it was created too late for use in load_includes(). -- NOTE2: if the internal sectionArr is empty, it will now throw an exception... * validate_page(): -- no longer sets the internal finalSection value. * load_includes(): -- when considering inclusion of index.inc, has extra checks to allow it if finalSection is "index". Modified Paths: -------------- releases/1.0/contentSystem.class.php Modified: releases/1.0/contentSystem.class.php =================================================================== --- releases/1.0/contentSystem.class.php 2009-05-22 17:28:18 UTC (rev 379) +++ releases/1.0/contentSystem.class.php 2009-05-27 04:54:31 UTC (rev 380) @@ -339,6 +339,17 @@ * Retrieves the list of templates & includes in preparation for later work. */ private function prepare() { + + //Set the final section... + if(count($this->sectionArr)) { + $mySectionArr = $this->sectionArr; + $this->finalSection = array_pop($mySectionArr); + } + else { + throw new exception(__METHOD__ .": FATAL - section array is empty"); + } + + //attempt to load any includes... if($this->fileSystemObj->cd('/includes')) { $this->load_includes(); @@ -448,12 +459,10 @@ 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."; @@ -653,6 +662,9 @@ //okay, now loop through $this->sectionArr & see if we can include anything else. $addIndex=false; + if($this->finalSection == 'index') { + $addIndex = true; + } if(($this->fileSystemObj->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) { @@ -672,6 +684,9 @@ if(!$this->fileSystemObj->cd($mySection)) { //no dice. Break the loop. $addIndex = false; + if($this->finalSection == 'index') { + $addIndex = true; + } break; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-22 17:28:37
|
Revision: 379 http://cs-content.svn.sourceforge.net/cs-content/?rev=379&view=rev Author: crazedsanity Date: 2009-05-22 17:28:18 +0000 (Fri, 22 May 2009) Log Message: ----------- Added "curYear" template var, since it is used in an example template. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-22 16:29:11 UTC (rev 378) +++ trunk/1.0/contentSystem.class.php 2009-05-22 17:28:18 UTC (rev 379) @@ -149,6 +149,7 @@ //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')); + $this->templateObj->add_template_var('curYear', date('Y')); $myUrl = '/'; if(strlen($this->section) && $this->section !== 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-22 16:29:20
|
Revision: 378 http://cs-content.svn.sourceforge.net/cs-content/?rev=378&view=rev Author: crazedsanity Date: 2009-05-22 16:29:11 +0000 (Fri, 22 May 2009) Log Message: ----------- Implement feature request #273 (post-include file support). /contentSystem.class.php: * MAIN::: -- added new (protected) property, afterIncludesList=array() * load_includes(): -- check for that final "shared.after.inc" file (load_dir_includes() will not do this for the final section). * load_dir_includes(): -- initialize blank array for holding list of "after" includes. -- checks for shared.after.inc and {section}.after.inc -- NOTE::: if ordering works properly from inside add_include(), then the "after" includes should be done through add_include($file,true) as well to avoid confusion. * finish(): -- processes the "after" includes once the normal includes are done. * add_include(): -- ARG CHANGE: NEW ARG: #2 ($addAfter=false) -- support for adding includes to the "after" array (defaults to using the normal array)--each item is put to the TOP of the list for proper order of inclusion. -- NOTE::: see note for load_dir_includes() about this... Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-15 15:21:15 UTC (rev 377) +++ trunk/1.0/contentSystem.class.php 2009-05-22 16:29:11 UTC (rev 378) @@ -94,6 +94,7 @@ ); protected $templateList = array(); protected $includesList = array(); + protected $afterIncludesList= array(); public $templateObj = NULL; protected $gfObj = NULL; protected $tabs = NULL; @@ -659,6 +660,9 @@ if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { $this->add_include('shared.inc'); } + if(isset($lsData['shared.after.inc']) && is_array($lsData['shared.after.inc'])) { + $this->add_include('shared.after.inc',true); + } if(isset($lsData['index.inc']) && is_array($lsData['index.inc'])) { $this->add_include('index.inc'); } @@ -676,22 +680,32 @@ private function load_dir_includes($section) { $lsData = $this->incFs->ls(); + $addThese = array(); + //attempt to load the shared includes file. if(isset($lsData['shared.inc']) && $lsData['shared.inc']['type'] == 'file') { $this->add_include('shared.inc'); } + //add the shared "after" script. + if(isset($lsData['shared.after.inc'])) { + $addThese [] = 'shared.after.inc'; + } + //attempt to load the section's includes file. $myFile = $section .'.inc'; if(isset($lsData[$myFile]) && $lsData[$myFile]['type'] == 'file') { $this->add_include($myFile); } - if(isset($lsData[$section]) && !count($this->sectionArr)) { - $this->incFs->cd($section); - $lsData = $this->incFs->ls(); - if(isset($lsData['index.inc'])) { - $this->includesList[] = $this->incFs->realcwd .'/index.inc'; + //add the section "after" script. + if(isset($lsData[$section .'.after.inc'])) { + $addThese [] = $section .'.after.inc'; + } + + if(is_array($addThese) && count($addThese)) { + foreach($addThese as $f) { + $this->add_include($f,true); } } }//end load_dir_includes() @@ -783,6 +797,14 @@ $this->myLastInclude = $myInternalScriptName; include_once($this->myLastInclude); } + + //now load the "after" includes. + if(is_array($this->afterIncludesList)) { + foreach($this->afterIncludesList as $myInternalIndex=>$myInternalScriptName) { + $this->myLastInclude = $myInternalScriptName; + include_once($this->myLastInclude); + } + } } catch(exception $e) { $myRoot = preg_replace('/\//', '\\\/', $this->incFs->root); @@ -869,10 +891,15 @@ /** * Method that appends filenames to the list of include scripts. */ - private final function add_include($file) { + private final function add_include($file, $addAfter=false) { $myFile = preg_replace('/\/{2,}/', '/', $this->incFs->realcwd .'/'. $file); if(!is_numeric(array_search($myFile, $this->includesList))) { - $this->includesList[] = $myFile; + if($addAfter === true) { + array_unshift($this->afterIncludesList, $myFile); + } + else { + $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-05-15 15:21:17
|
Revision: 377 http://cs-content.svn.sourceforge.net/cs-content/?rev=377&view=rev Author: crazedsanity Date: 2009-05-15 15:21:15 +0000 (Fri, 15 May 2009) Log Message: ----------- Require SITE_ROOT constant (like contentSystem). /cs-content/cs_genericPage.class.php: * initialize_locals(): -- require SITE_ROOT to be a defined constant -- set tmplDir and libDir off those vars -- NOTE::: should tmplDir and libDir first check for constants??? 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-05-06 19:30:00 UTC (rev 376) +++ trunk/1.0/cs_genericPage.class.php 2009-05-15 15:21:15 UTC (rev 377) @@ -72,16 +72,13 @@ } - if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/' && !preg_match('/^\./', dirname($mainTemplateFile))) { - $this->tmplDir = dirname($mainTemplateFile); - $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir); + if(defined('SITE_ROOT')) { + $this->siteRoot = constant('SITE_ROOT'); } 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('/\/htdocs/', '', $_SERVER['DOCUMENT_ROOT']); - $this->tmplDir = $this->siteRoot .'/templates'; + throw new exception(__METHOD__ .": required constant 'SITE_ROOT' not set"); } + $this->tmplDir = $this->siteRoot .'/templates'; $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-05-06 19:30:08
|
Revision: 376 http://cs-content.svn.sourceforge.net/cs-content/?rev=376&view=rev Author: crazedsanity Date: 2009-05-06 19:30:00 +0000 (Wed, 06 May 2009) Log Message: ----------- Fix PHP warning, allow multiple tab block rows in same set. NOTE::: cs_tabs needs some work to make it more useful and extensible. There is some stuff to figure out with logic in load_tabs_template()--i.e. is it still needed? NOTE2:: cs_tabs will overwrite existing tabs of the same name, so duplicate tab names aren't allowed... but some apps may require this. Consider adding. /cs_genericPage.class.php: * get_block_row_defs(): -- check if the index in templateVars is set before evaluating it. /cs_tabs.class.php: * MAIN::: -- set tabsArray as an array() initially. -- NEW (private) VAR: $defaultSuffix='tab' (default if no block row suffix is given (i.e. this would require "selected_tab" and "unselected_tab" to function). * load_tabs_template(): -- no longer throws exceptions, nor does it do any real checking -- rips block rows for the given template var... * add_tab_array(): -- ARG CHANGE: NEW ARG: #2 ($useSuffix=null) -- passes $useSuffix when calling add_tab(). * add_tab(): -- ARG CHANGE: NEW ARG: #2 ($useSuffix=null) -- Now stores an array of data instead of just the text of the url: the "suffix" denotes what block row to use, allowing multiple different rows to be used within the same tab set. -- if no suffix is given, the default suffix is used. * display_tabs(): -- code to automatically select a tab if one is not already selected. -- instead of parsing a known templateRow (block row), it is dynamic, determined based on the "suffix" given. -- can throw an exception if referenced templateRow doesn't exist. -- updated exception (when no tabs present) to use magic __METHOD__ constant. * tab_exists() [NEW]: -- method to determine if the named tab exists or not. * rename_tab() [NEW]: -- rename existing tab to a new one. -- throws an exception if the named tab doesn't exist or if a tab named as the new name already exists. Modified Paths: -------------- trunk/1.0/cs_genericPage.class.php trunk/1.0/cs_tabs.class.php Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2009-05-06 15:23:00 UTC (rev 375) +++ trunk/1.0/cs_genericPage.class.php 2009-05-06 19:30:00 UTC (rev 376) @@ -551,8 +551,8 @@ //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) >= 30) { + if(isset($this->templateVars[$templateVar]) && strlen($this->templateVars[$templateVar]) >= 30) { + $templateContents = $this->templateVars[$templateVar]; //looks good to me. Run the regex... $flags = PREG_PATTERN_ORDER; $reg = "/<!-- BEGIN (\S{1,}) -->/"; Modified: trunk/1.0/cs_tabs.class.php =================================================================== --- trunk/1.0/cs_tabs.class.php 2009-05-06 15:23:00 UTC (rev 375) +++ trunk/1.0/cs_tabs.class.php 2009-05-06 19:30:00 UTC (rev 376) @@ -8,18 +8,15 @@ class cs_tabs extends cs_contentAbstract { - private $tabsArr; + private $tabsArr=array(); private $selectedTab; private $csPageObj; private $templateVar; - /** Block row with the "selected" tab */ - private $selectedTabContent; + /** This is the default suffix to use when none is given during the add_tab() call. */ + private $defaultSuffix='tab'; - /** Block row with the "unselected" tab */ - private $unselectedTabContent; - //--------------------------------------------------------------------------------------------- /** * Build the object, and parses the given template. Tabs must be added & selected manually. @@ -64,26 +61,21 @@ //now let's parse it for the proper block rows. $blockRows = $this->csPageObj->rip_all_block_rows($this->templateVar); - if(count($blockRows) < 2 || !isset($blockRows['selected_tab']) || !isset($blockRows['unselected_tab'])) { - //not enough blocks, or they're not properly named. - throw new exception("cs_tabs::load_tabs_template(): failed to retrieve the required block rows"); - } - else { - //got the rows. Yay! - $this->selectedTabContent = $blockRows['selected_tab']; - $this->unselectedTabContent = $blockRows['unselected_tab']; - } + #if(count($blockRows) < 2) { + # //not enough blocks, or they're not properly named. + # throw new exception("cs_tabs::load_tabs_template(): failed to retrieve the required block rows"); + #} }//end load_tabs_template() //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- - public function add_tab_array(array $tabs) { + public function add_tab_array(array $tabs, $useSuffix=null) { $retval = 0; foreach($tabs as $name=>$url) { //call an internal method to do it. - $retval += $this->add_tab($name, $url); + $retval += $this->add_tab($name, $url, $useSuffix); } return($retval); @@ -107,9 +99,18 @@ //--------------------------------------------------------------------------------------------- - public function add_tab($tabName, $url) { + public function add_tab($tabName, $url, $useSuffix=null) { + + //set the default suffix. + if(is_null($useSuffix)) { + $useSuffix = $this->defaultSuffix; + } + //add it to an array. - $this->tabsArr[$tabName] = $url; + $this->tabsArr[$tabName] = array( + 'url' => $url, + 'suffix' => $useSuffix + ); }//end add_tab() //--------------------------------------------------------------------------------------------- @@ -120,16 +121,33 @@ * Call this to add the parsed tabs into the page. */ public function display_tabs() { + + if(!strlen($this->selectedTab)) { + $keys = array_keys($this->tabsArr); + $this->select_tab($keys[0]); + } + if(is_array($this->tabsArr) && count($this->tabsArr)) { $this->load_tabs_template(); $finalString = ""; //loop through the array. - foreach($this->tabsArr as $tabName=>$url) { - $useTabContent = $this->unselectedTabContent; - if(strtolower($tabName) === strtolower($this->selectedTab)) { - //it's selected. - $useTabContent = $this->selectedTabContent; + foreach($this->tabsArr as $tabName=>$tabData) { + + $url = $tabData['url']; + $suffix = $tabData['suffix']; + + $blockRowName = 'unselected_'. $suffix; + if(strtolower($tabName) == strtolower($this->selectedTab)) { + $blockRowName = 'selected_'. $suffix; } + + if(isset($this->csPageObj->templateRows[$blockRowName])) { + $useTabContent = $this->csPageObj->templateRows[$blockRowName]; + } + else { + throw new exception(__METHOD__ ."(): failed to load block row (". $blockRowName .") for tab (". $tabName .")". $this->csPageObj->gfObj->debug_print($this->csPageObj->templateRows,0)); + } + $parseThis = array( 'title' => $tabName, 'url' => $url @@ -142,11 +160,40 @@ } else { //something bombed. - throw new exception("cs_tabs::display_tabs(): no tabs to add"); + throw new exception(__METHOD__ ."(): no tabs to add"); } }//end display_tabs() //--------------------------------------------------------------------------------------------- + + //--------------------------------------------------------------------------------------------- + /** + * Determine if the given named tab exists (returns boolean true/false) + */ + public function tab_exists($tabName) { + $retval = false; + if(isset($this->tabsArr[$tabName])) { + $retval = true; + } + return($retval); + }//end tab_exists() + //--------------------------------------------------------------------------------------------- + + + + //--------------------------------------------------------------------------------------------- + public function rename_tab($tabName, $newTabName) { + if($this->tab_exists($tabName) && !$this->tab_exists($newTabName)) { + $tabContents = $this->tabsArr[$tabName]; + unset($this->tabsArr[$tabName]); + $this->tabsArr[$newTabName] = $tabContents; + } + else { + throw new exception(__METHOD__ .": tried to rename non-existent tab (". $tabName .") to (". $newTabName .")"); + } + }//end rename_tab(); + //--------------------------------------------------------------------------------------------- + } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-06 15:23:07
|
Revision: 375 http://cs-content.svn.sourceforge.net/cs-content/?rev=375&view=rev Author: crazedsanity Date: 2009-05-06 15:23:00 +0000 (Wed, 06 May 2009) Log Message: ----------- Allow entire sections to be put into the GLOBALS array (request #271). /cs_siteConfig.class.php: * MAIN::: -- NEW (private) VAR: $setGlobalArrays=array() * parse_config(): -- check for "SETGLOBAL" on config sections (value disregarded), put into internal "setGlobalArrays" var for later. -- if there is anything in the internal "setGlobalArrays" var, loop through it and put that data into the $GLOBALS array using cs_arrayToPath::set_data(). Modified Paths: -------------- trunk/1.0/cs_siteConfig.class.php Modified: trunk/1.0/cs_siteConfig.class.php =================================================================== --- trunk/1.0/cs_siteConfig.class.php 2009-05-05 20:41:04 UTC (rev 374) +++ trunk/1.0/cs_siteConfig.class.php 2009-05-06 15:23:00 UTC (rev 375) @@ -60,6 +60,8 @@ /** Boolean flag to determine if the object has been properly initialized or not. */ private $isInitialized=false; + /** Store a list of items that need to be pushed into $GLOBALS on a given path. */ + private $setGlobalArrays=array(); //------------------------------------------------------------------------- /** @@ -172,6 +174,25 @@ //only handle UPPERCASE index names; lowercase indexes are special entries (i.e. "type" or "attributes" if($section == strtoupper($section)) { $this->configSections[] = $section; + + unset($secData['type']); + + if(is_array($secData['attributes'])) { + $sectionAttribs = $secData['attributes']; + unset($secData['attributes']); + + //put stuff into the globals scope... + if(isset($sectionAttribs['SETGLOBAL'])) { + $path = $section; + + $setPath = $path; + if(strlen($sectionAttribs['GLOBALARRAYLOCATION'])) { + $setPath = $sectionAttribs['GLOBALARRAYLOCATION']; + } + $this->setGlobalArrays[$path] = $setPath; + } + } + foreach($secData as $itemName=>$itemValue) { $attribs = array(); if(is_array($itemValue['attributes'])) { @@ -212,8 +233,25 @@ } } } + $this->a2p = new cs_arrayToPath($data); $this->isInitialized=true; + + if(count($this->setGlobalArrays)) { + $globA2p = new cs_arrayToPath(&$GLOBALS); + foreach($this->setGlobalArrays as $configPath=>$globalsPath) { + if($this->a2p->get_data($configPath)) { + $setMe = array(); + foreach($this->a2p->get_data($configPath) as $i=>$v) { + $setMe[$i] = $v['value']; + } + $globA2p->set_data($globalsPath, $setMe); + } + else { + throw new exception(__METHOD__ .": attempted to set global array from non-existent path (". $configPath .")"); + } + } + } } else { throw new exception(__METHOD__ .": xmlReader not created, object probably not initialized"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-05 20:41:10
|
Revision: 374 http://cs-content.svn.sourceforge.net/cs-content/?rev=374&view=rev Author: crazedsanity Date: 2009-05-05 20:41:04 +0000 (Tue, 05 May 2009) Log Message: ----------- Minor fix to avoid errors about undefined array indexes. /cs_genericPage.class.php: * print_page(): -- check if the index exists when tallying unhandledVars: set when it doesn't exists, increment when it does. -- NOTE: technically, the old way was just fine, but some web apps set error reporting very high, so nearly everything is printed. 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-05-01 19:24:49 UTC (rev 373) +++ trunk/1.0/cs_genericPage.class.php 2009-05-05 20:41:04 UTC (rev 374) @@ -292,7 +292,12 @@ if(!isset($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]++; + if(isset($this->unhandledVars[$str2])) { + $this->unhandledVars[$str2]++; + } + else { + $this->unhandledVars[$str2] = 1; + } } } $this->templateObj->parse("out", "out"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-01 19:24:50
|
Revision: 373 http://cs-content.svn.sourceforge.net/cs-content/?rev=373&view=rev Author: crazedsanity Date: 2009-05-01 19:24:49 +0000 (Fri, 01 May 2009) Log Message: ----------- Ability to inject vars into pages, make section retrieval case insensitive. /contentSystem.class.php: * MAIN::: -- new (private) var, $injectVars=array() * finish(): -- checks if the internal injectVars array has things in it, and will then inject variables with the given names into the local scope. * inject_var() [NEW]: -- inject a variable into the local scope. /cs_siteConfig.class.php: * get_section(): -- upper-case the given section so no errors are thrown when they ask for a lowercase section. Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/cs_siteConfig.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-05-01 13:42:14 UTC (rev 372) +++ trunk/1.0/contentSystem.class.php 2009-05-01 19:24:49 UTC (rev 373) @@ -103,6 +103,8 @@ private $isValid=FALSE; private $reason=NULL; + private $injectVars=array(); + //------------------------------------------------------------------------ /** * The CONSTRUCTOR. Duh. @@ -737,6 +739,19 @@ } $page =& $this->templateObj; + + if(is_array($this->injectVars) && count($this->injectVars)) { + $definedVars = get_defined_vars(); + foreach($this->injectVars as $myVarName=>$myVarVal) { + if(!isset($definedVars[$myVarName])) { + $$myVarName = $myVarVal; + } + else { + throw new exception(__METHOD__ .": attempt to inject already defined var '". $myVarName ."'"); + } + } + } + if(is_object($this->session)) { $page->session =& $this->session; } @@ -863,5 +878,13 @@ //------------------------------------------------------------------------ + + //------------------------------------------------------------------------ + public function inject_var($varName, $value) { + $this->injectVars[$varName] = $value; + }//end inject_var() + //------------------------------------------------------------------------ + + }//end contentSystem{} ?> Modified: trunk/1.0/cs_siteConfig.class.php =================================================================== --- trunk/1.0/cs_siteConfig.class.php 2009-05-01 13:42:14 UTC (rev 372) +++ trunk/1.0/cs_siteConfig.class.php 2009-05-01 19:24:49 UTC (rev 373) @@ -234,6 +234,7 @@ */ public function get_section($section) { if($this->isInitialized === true) { + $section = strtoupper($section); $data = $this->a2p->get_data($section); if(is_array($data) && count($data) && $data['type'] == 'open') { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-05-01 14:02:40
|
Revision: 372 http://cs-content.svn.sourceforge.net/cs-content/?rev=372&view=rev Author: crazedsanity Date: 2009-05-01 13:42:14 +0000 (Fri, 01 May 2009) Log Message: ----------- Fix missing array in set_message(). cs_genericPage.class.php: -- set_message(): * added missing $priorityArr in call to array_keys() when type isn't set (this supposedly sets the default type to "notice", or whatever is the first index in the $priorityArr). 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-04-22 20:43:39 UTC (rev 371) +++ trunk/1.0/cs_genericPage.class.php 2009-05-01 13:42:14 UTC (rev 372) @@ -419,7 +419,7 @@ ); if(!isset($type) || !isset($priorityArr[$type])) { //set a default type. - $arrayKeys = array_keys(); + $arrayKeys = array_keys($priorityArr); $type = $arrayKeys[0]; } @@ -593,7 +593,7 @@ //--------------------------------------------------------------------------------------------- - function rip_all_block_rows($templateVar="content", $exceptionArr=array()) { + function rip_all_block_rows($templateVar="content", $exceptionArr=array(), $removeDefs=0) { $rowDefs = $this->get_block_row_defs($templateVar); @@ -604,10 +604,10 @@ if(is_array($useTheseBlockRows)) { foreach($useTheseBlockRows as $blockRowName) { - if(!in_array($blockRowName, $exceptionArr)) + if(!is_array($exceptionArr) || !in_array($blockRowName, $exceptionArr)) { //remove the block row. - $rowData = $this->set_block_row($templateVar, $blockRowName); + $rowData = $this->set_block_row($templateVar, $blockRowName, $removeDefs); $retval[$blockRowName] = $rowData; } } @@ -621,9 +621,9 @@ //--------------------------------------------------------------------------------------------- - public function set_all_block_rows($templateVar="content", $exceptionArr=array()) + public function set_all_block_rows($templateVar="content", $exceptionArr=array(), $removeDefs=0) { - $retval = $this->rip_all_block_rows($templateVar, $exceptionArr); + $retval = $this->rip_all_block_rows($templateVar, $exceptionArr, $removeDefs); return($retval); }//end set_all_block_rows() //--------------------------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-04-22 20:43:44
|
Revision: 371 http://cs-content.svn.sourceforge.net/cs-content/?rev=371&view=rev Author: crazedsanity Date: 2009-04-22 20:43:39 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Fixes for PHP warnings, update for "htdocs" public folder, setting to stop printing from an include. contentSystem.class.php: * finish(): -- only print if templateObj->printOnFinish is true... helps for embedded XML interfaces. cs_genericPage.class.php: * MAIN::: -- new public var, $printOnFinish=true * initialize_locals(): -- also remove "htdocs" from siteRoot. * set_block_row(): -- minor change to fix PHP warnings about referencing non-existent array indexes. * print_page(): -- another minor change to fix PHP warnings on array indexes -- add quotes in reference to 'out' array index to avoid PHP warnings about constants. * rip_all_block_rows(): -- superficial change to avoid PHP warnings if no array was returned. 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-03-27 14:56:04 UTC (rev 370) +++ trunk/1.0/contentSystem.class.php 2009-04-22 20:43:39 UTC (rev 371) @@ -793,7 +793,9 @@ } if($this->isValid === TRUE) { - $page->print_page(); + if($this->templateObj->printOnFinish === true) { + $page->print_page(); + } } else { $this->die_gracefully($this->reason); Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2009-03-27 14:56:04 UTC (rev 370) +++ trunk/1.0/cs_genericPage.class.php 2009-04-22 20:43:39 UTC (rev 371) @@ -15,6 +15,7 @@ public $templateVars = array(); //our copy of the global templateVars public $mainTemplate; //the default layout of the site public $unhandledVars=array(); + public $printOnFinish=true; private $tmplDir; private $libDir; @@ -78,6 +79,7 @@ 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('/\/htdocs/', '', $_SERVER['DOCUMENT_ROOT']); $this->tmplDir = $this->siteRoot .'/templates'; } $this->libDir = $this->siteRoot .'/lib'; @@ -218,7 +220,7 @@ $reg = "/<!-- BEGIN $handle -->(.+){0,}<!-- END $handle -->/sU"; preg_match_all($reg, $str, $m); - if(!is_string($m[0][0])) { + if(!is_array($m) || !isset($m[0][0]) || !is_string($m[0][0])) { #exit("set_block_row(): couldn't find '$handle' in var '$parent'"); $retval = FALSE; } else { @@ -287,9 +289,9 @@ foreach($tags as $key=>$str) { $str2 = str_replace("{", "", $str); $str2 = str_replace("}", "", $str2); - if(!$this->templateVars[$str2] && $stripUndefVars) { + if(!isset($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->templateObj->varvals['out'] = str_replace($str, '', $this->templateObj->varvals['out']); $this->unhandledVars[$str2]++; } } @@ -594,17 +596,20 @@ function rip_all_block_rows($templateVar="content", $exceptionArr=array()) { $rowDefs = $this->get_block_row_defs($templateVar); - $useTheseBlockRows = $rowDefs['ordered']; $retval = array(); - if(is_array($useTheseBlockRows)) { - foreach($useTheseBlockRows as $blockRowName) - { - if(!in_array($blockRowName, $exceptionArr)) + + if(is_array($rowDefs) && isset($rowDefs['ordered'])) { + $useTheseBlockRows = $rowDefs['ordered']; + if(is_array($useTheseBlockRows)) { + foreach($useTheseBlockRows as $blockRowName) { - //remove the block row. - $rowData = $this->set_block_row($templateVar, $blockRowName); - $retval[$blockRowName] = $rowData; + if(!in_array($blockRowName, $exceptionArr)) + { + //remove the block row. + $rowData = $this->set_block_row($templateVar, $blockRowName); + $retval[$blockRowName] = $rowData; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-03-27 14:56:13
|
Revision: 370 http://cs-content.svn.sourceforge.net/cs-content/?rev=370&view=rev Author: crazedsanity Date: 2009-03-27 14:56:04 +0000 (Fri, 27 Mar 2009) Log Message: ----------- Minor additional method for debugging. /cs_globalFunctions.class.php: * debug_var_dump() [NEW]: -- similar to debug_print(), except it uses var_dump() instead of print_r() to display information. Allows for easy viewing of what data is in a variable in a web-centric sort of way (for live debugging). Modified Paths: -------------- trunk/1.0/cs_globalFunctions.class.php Modified: trunk/1.0/cs_globalFunctions.class.php =================================================================== --- trunk/1.0/cs_globalFunctions.class.php 2009-03-03 19:07:51 UTC (rev 369) +++ trunk/1.0/cs_globalFunctions.class.php 2009-03-27 14:56:04 UTC (rev 370) @@ -838,6 +838,19 @@ return($realVals[$index]); }//end interpret_bool() //########################################################################## + + + //########################################################################## + public function debug_var_dump($data, $printItForMe=null, $removeHr=null) { + + ob_start(); + var_dump($data); + $printThis = ob_get_contents(); + ob_end_clean(); + + return($this->debug_print($printThis, $printItForMe, $removeHr)); + }//end debug_var_dump() + //########################################################################## }//end cs_globalFunctions{} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-03-03 19:07:53
|
Revision: 369 http://cs-content.svn.sourceforge.net/cs-content/?rev=369&view=rev Author: crazedsanity Date: 2009-03-03 19:07:51 +0000 (Tue, 03 Mar 2009) Log Message: ----------- Fix problems from last commit & minor bug with adding includes. /contentSystem.class.php: * parse_section(): -- when checking the size of the $myArr var, don't check the value of the first (0) index. -- added a TODO about possible problems from an empty array -- throw an exception if no array is retrieved from section (shouldn't ever happen). * validate_page(): -- NOTE::: this method was very much overhauled to make it simpler. -- checks for two template files that would indicate it is a valid page instead of doing so much cd()'ing and such with a lot of duplicated and confusing code (I was even confused, and I wrote it). * load_page_templates(): -- instead of using the last item in the internal sectionArr, it uses the internal "finalSection" variable. -- always load the final template list followed by loading items for the final section instead of doing an if/else statement (which could cause some frustrating & unexpected bahaviour). * load_main_templates(): -- cd() into the baseDir again (allows the final content template to be loaded again; previous commit broke this). * load_includes(): -- cd() to the internal "finalSection" and include the index and shared files (but only if the cd() succeeds). * add_include(): -- fix problems with extra slashes in the filename causing files to be included multiple times -- only load a new include if the result of array_search() isn't numeric: previously, if the requested include was already in index 0, it would get included again. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-03-02 21:10:18 UTC (rev 368) +++ trunk/1.0/contentSystem.class.php 2009-03-03 19:07:51 UTC (rev 369) @@ -292,10 +292,15 @@ $myArr = split('/', $this->section); //if we've got something in the array, keep going. - if(is_array($myArr) && count($myArr) && ($myArr[0] !== 0)) { + if(is_array($myArr) && count($myArr) > 0) { + + //TODO: if there's only one section here, sectionArr becomes BLANK... does that cause unexpected behaviour? $this->baseDir = array_shift($myArr); $this->sectionArr = $myArr; } + else { + throw new exception(__METHOD__ .": failed to get an array from section (". $this->section .")"); + } }//end parse_section() //------------------------------------------------------------------------ @@ -400,84 +405,36 @@ /** * Ensures the page we're on would actually load, so other methods don't have to do * so much extra checking. + * + * TODO: the if & else should be consolidated as much as possible... */ 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. + + $this->tmplFs->cd('/'); + + $valid = false; + 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->tmplFs->cd('/'); $mySectionArr = $this->sectionArr; - $finalSection = array_pop($mySectionArr); - $this->finalSection = $finalSection; - if(count($mySectionArr) > 0) { - foreach($mySectionArr as $dir) { - if(!$this->tmplFs->cd($dir)) { - break; - } - } - } - - //check for the file & the directory... - $indexFilename = $finalSection ."/index.content.tmpl"; - if(!strlen($finalSection)) { - $indexFilename = 'index.content.tmpl'; - } - - $lsDir = $this->tmplFs->ls($indexFilename); - $lsDirVals = array_values($lsDir); - $lsFile = $this->tmplFs->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->tmplFs->ls($myIndex); - if(!is_array($checkMe[$myIndex])) { - unset($myIndex); - } - - if(isset($myIndex)) { - $valid = TRUE; - $this->tmplFs->cd('/'); - } - else { - $this->reason = __METHOD__ .": couldn't find page template for ". $this->section; - } + $this->finalSection = array_pop($mySectionArr); + $reasonText = "page template"; } else { - //if the baseDir is "help", this would try to use "/help/index.content.tmpl" - $myFile = $this->baseDir .'/index.content.tmpl'; - $sectionLsData = $this->tmplFs->ls($myFile); - - //if the baseDir is "help", this would try to use "/help.content.tmpl" - $sectionFile = $this->baseDir .'.content.tmpl'; - $lsData = $this->tmplFs->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->finalSection = $this->baseDir; + $reasonText = "base template"; } + + $tmplFile1 = $this->section .".content.tmpl"; + $tmplFile2 = $this->section ."/index.content.tmpl"; + + if(file_exists($this->tmplFs->realcwd ."/". $tmplFile2) || file_exists($this->tmplFs->realcwd ."/". $tmplFile1)) { + $valid = true; + $this->reason=null; + } + else { + $valid = false; + $this->reason=__METHOD__ .": couldn't find ". $reasonText; + } $this->isValid = $valid; return($valid); @@ -495,7 +452,7 @@ // looking for templates. $mySectionArr = $this->sectionArr; - $finalSection = $this->sectionArr[(count($this->sectionArr) -1)]; + $finalSection = $this->finalSection; foreach($mySectionArr as $index=>$value) { $tmplList = $this->arrange_directory_contents('name', 'section'); if(isset($tmplList[$value])) { @@ -509,20 +466,20 @@ } } - //load the final template(s). $finalTmplList = $this->arrange_directory_contents('name', 'section'); + foreach($finalTmplList as $mySection => $subArr) { + foreach($subArr as $internalSection => $myTmpl) { + $this->templateList[$mySection] = $myTmpl; + } + } + + //go through the final section, if set, so the templates defined there are used. 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->tmplFs->cd($finalSection)) { //load the index stuff. $tmplList = $this->arrange_directory_contents('name', 'section'); @@ -549,6 +506,7 @@ //check to see if the present section is valid. $this->tmplFs->cd('/'); $dirContents = $this->arrange_directory_contents('name', 'section'); + $this->tmplFs->cd($this->baseDir); if(is_array($dirContents)) { foreach($dirContents as $mySection => $subArr) { foreach($subArr as $subIndex=>$templateFilename) { @@ -694,13 +652,15 @@ } //include the final shared & index files. - $lsData = $this->incFs->ls(); - if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { - $this->add_include('shared.inc'); + if($this->incFs->cd($this->finalSection)) { + $lsData = $this->incFs->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'); + } } - if(isset($lsData['index.inc']) && is_array($lsData['index.inc'])) { - $this->add_include('index.inc'); - } }//end load_includes() //------------------------------------------------------------------------ @@ -893,8 +853,8 @@ * Method that appends filenames to the list of include scripts. */ private final function add_include($file) { - $myFile = $this->incFs->realcwd .'/'. $file; - if(!array_search($myFile, $this->includesList)) { + $myFile = preg_replace('/\/{2,}/', '/', $this->incFs->realcwd .'/'. $file); + if(!is_numeric(array_search($myFile, $this->includesList))) { $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-03-02 21:10:33
|
Revision: 368 http://cs-content.svn.sourceforge.net/cs-content/?rev=368&view=rev Author: crazedsanity Date: 2009-03-02 21:10:18 +0000 (Mon, 02 Mar 2009) Log Message: ----------- Fix problem with index.inc not always being included. /contentSystem.class.php: * parse_section(): -- remove leading slashes from the DEFAULT_SECTION value. * prepare(): -- remove reference to uninitialized var $cdResult * load_includes(): -- remove extra code ($addIndex) that determines if the index.inc file is included (breaking into two FS objects fixed the problem that the removed code bandaided): if the file exists, include it. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-03-02 20:33:06 UTC (rev 367) +++ trunk/1.0/contentSystem.class.php 2009-03-02 21:10:18 UTC (rev 368) @@ -287,7 +287,7 @@ //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)) && defined('DEFAULT_SECTION')) { - $this->section = constant('DEFAULT_SECTION'); + $this->section = preg_replace('/^\//', '', constant('DEFAULT_SECTION')); } $myArr = split('/', $this->section); @@ -366,7 +366,7 @@ $foundIncludes = count($this->includesList); $validatePageRes = $this->validate_page(); - if($foundIncludes || ($cdResult && $validatePageRes)) { + if($foundIncludes || $validatePageRes) { //okay, get template directories & start loading $tmplDirs = $this->get_template_dirs(); @@ -670,7 +670,6 @@ $this->load_dir_includes($this->baseDir); //okay, now loop through $this->sectionArr & see if we can include anything else. - $addIndex=false; if(($this->incFs->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) { @@ -689,13 +688,8 @@ //attempt to cd() into the next directory, or die if we can't. if(!$this->incFs->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; - } } } @@ -704,7 +698,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']) && $addIndex==true) { + if(isset($lsData['index.inc']) && is_array($lsData['index.inc'])) { $this->add_include('index.inc'); } }//end load_includes() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-03-02 20:33:27
|
Revision: 367 http://cs-content.svn.sourceforge.net/cs-content/?rev=367&view=rev Author: crazedsanity Date: 2009-03-02 20:33:06 +0000 (Mon, 02 Mar 2009) Log Message: ----------- Seperate cs_fileSystem objects for includes and template files. /contentSystem.class.php: * MAIN::: -- deleted protected var $fileSystemObj -- added protected var $tmplFs -- added protected var $incFs * __construct(): -- throws an exception if SITE_ROOT isn't defined. * initialize_locals(): -- create one object for handling templates and one for includes. -- use tmplFs object for checking versions. * get_template_dirs(): -- uses tmplFs instead of fileSystemObj * prepare(): -- call load_includes() unconditionally. -- don't cd() into "/templates" anymore; using two objects eliminates the need for this. -- set both FS objects back to their root directory. * validate_page(): -- uses tmplFs instead of fileSystemObj * load_page_templates(): -- uses tmplFs instead of fileSystemObj * load_main_templates(): -- use tmplFs instead of fileSystemObj -- remove extra unnecessary call to cd(). * load_shared_templates(): -- use tmplFs instead of fileSystemObj. * arrange_directory_contents(): -- use tmplFs instead of fileSystemObj * load_includes(): -- use incFs instead of fileSystemObj * load_dir_includes(): -- use incFs instead of fileSystemObj * finish(): -- use incFs instead of fileSystemObj when setting local "myRoot" * add_include(): -- use incFs instead of fileSystemObj Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-03-02 17:54:58 UTC (rev 366) +++ trunk/1.0/contentSystem.class.php 2009-03-02 20:33:06 UTC (rev 367) @@ -81,7 +81,12 @@ 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 $tmplFs = NULL; //Object used to access the TEMPLATES filesystem + protected $incFs = NULL; //Object used to access the INCLUDES filesystem + + protected $ignoredList = array( //array of files & folders that are implicitely ignored. 'file' => array('.htaccess'), 'dir' => array('.svn','CVS' @@ -110,6 +115,10 @@ } else { + if(!defined('SITE_ROOT')) { + throw new exception(__METHOD__ .": must set required constant 'SITE_ROOT'"); + } + //setup the section stuff... $repArr = array($_SERVER['SCRIPT_NAME'], "/"); $_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']); @@ -144,9 +153,22 @@ } $this->templateObj->add_template_var('CURRENT_URL', $myUrl); - //create a fileSystem object. - $this->fileSystemObj = new cs_fileSystem(); + //create a fileSystem object for templates. + $tmplBaseDir = constant('SITE_ROOT') .'/templates'; + if(defined('TMPLDIR')) { + $tmplBaseDir = constant('TMPLDIR'); + } + $this->tmplFs = new cs_fileSystem($tmplBaseDir); + + //create a fileSystem object for includes + $incBaseDir = constant('SITE_ROOT') .'/includes'; + if(defined('INCLUDES_DIR')) { + $incBaseDir = constant('INCLUDES_DIR'); + } + $this->incFs = new cs_fileSystem($incBaseDir); + + //create a tabs object, in case they want to load tabs on the page. $this->tabs = new cs_tabs($this->templateObj); @@ -155,8 +177,8 @@ 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->tmplFs->get_version() !== $myVersion) { + throw new exception(__METHOD__ .": ". get_class($this->tmplFs) ." has mismatched version (". $this->tmplFs->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 .")"); @@ -178,12 +200,12 @@ //------------------------------------------------------------------------ private function get_template_dirs() { if(is_array($this->sectionArr)) { - $this->fileSystemObj->cd("/templates/". $this->baseDir); + $this->tmplFs->cd('/'. $this->baseDir); $retval = array(); - $retval[] = $this->fileSystemObj->cwd; + $retval[] = $this->tmplFs->cwd; foreach($this->sectionArr as $index=>$name) { - if($this->fileSystemObj->cd($name)) { - $retval[] = $this->fileSystemObj->cwd; + if($this->tmplFs->cd($name)) { + $retval[] = $this->tmplFs->cwd; } else { break; @@ -340,13 +362,9 @@ */ private function prepare() { //attempt to load any includes... - if($this->fileSystemObj->cd('/includes')) { - $this->load_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)) { @@ -366,7 +384,8 @@ $this->load_page_templates(); //now cd() all the way back. - $this->fileSystemObj->cd('/'); + $this->tmplFs->cd('/'); + $this->incFs->cd('/'); } else { //couldn't find the templates directory, and no includes... it's dead. @@ -389,13 +408,13 @@ 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); + $this->tmplFs->cd('/'); $mySectionArr = $this->sectionArr; $finalSection = array_pop($mySectionArr); $this->finalSection = $finalSection; if(count($mySectionArr) > 0) { foreach($mySectionArr as $dir) { - if(!$this->fileSystemObj->cd($dir)) { + if(!$this->tmplFs->cd($dir)) { break; } } @@ -407,9 +426,9 @@ $indexFilename = 'index.content.tmpl'; } - $lsDir = $this->fileSystemObj->ls($indexFilename); + $lsDir = $this->tmplFs->ls($indexFilename); $lsDirVals = array_values($lsDir); - $lsFile = $this->fileSystemObj->ls("$finalSection.content.tmpl"); + $lsFile = $this->tmplFs->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") @@ -424,14 +443,14 @@ } //check the index file for validity... this is kind of a dirty hack... but it works. - $checkMe = $this->fileSystemObj->ls($myIndex); + $checkMe = $this->tmplFs->ls($myIndex); if(!is_array($checkMe[$myIndex])) { unset($myIndex); } if(isset($myIndex)) { $valid = TRUE; - $this->fileSystemObj->cd('/templates'); + $this->tmplFs->cd('/'); } else { $this->reason = __METHOD__ .": couldn't find page template for ". $this->section; @@ -440,11 +459,11 @@ 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); + $sectionLsData = $this->tmplFs->ls($myFile); //if the baseDir is "help", this would try to use "/help.content.tmpl" $sectionFile = $this->baseDir .'.content.tmpl'; - $lsData = $this->fileSystemObj->ls(); + $lsData = $this->tmplFs->ls(); if(isset($lsData[$sectionFile]) && is_array($lsData[$sectionFile])) { $valid = TRUE; @@ -485,7 +504,7 @@ $this->templateList[$mySection] = $myTmpl; } } - if(!$this->fileSystemObj->cd($value)) { + if(!$this->tmplFs->cd($value)) { break; } } @@ -504,7 +523,7 @@ } } } - if($this->fileSystemObj->cd($finalSection)) { + if($this->tmplFs->cd($finalSection)) { //load the index stuff. $tmplList = $this->arrange_directory_contents('name', 'section'); if(isset($tmplList['index'])) { @@ -527,9 +546,8 @@ * 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); + $this->tmplFs->cd('/'); $dirContents = $this->arrange_directory_contents('name', 'section'); if(is_array($dirContents)) { foreach($dirContents as $mySection => $subArr) { @@ -550,10 +568,10 @@ private function load_shared_templates($path=NULL) { if(!is_null($path)) { - $this->fileSystemObj->cd($path); + $this->tmplFs->cd($path); } else { - $this->fileSystemObj->cd('/templates'); + $this->tmplFs->cd('/'); } //pull a list of the files. @@ -575,13 +593,13 @@ * name, or vice-versa. */ private function arrange_directory_contents($primaryIndex='section', $secondaryIndex='name') { - $directoryInfo = $this->fileSystemObj->ls(); + $directoryInfo = $this->tmplFs->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 = $this->gfObj->create_list($this->tmplFs->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. @@ -653,7 +671,7 @@ //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) { + if(($this->incFs->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) { //if the last item in the array is "index", disregard it... @@ -669,7 +687,7 @@ $this->load_dir_includes($mySection); //attempt to cd() into the next directory, or die if we can't. - if(!$this->fileSystemObj->cd($mySection)) { + if(!$this->incFs->cd($mySection)) { //no dice. Break the loop. $addIndex = false; break; @@ -682,7 +700,7 @@ } //include the final shared & index files. - $lsData = $this->fileSystemObj->ls(); + $lsData = $this->incFs->ls(); if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { $this->add_include('shared.inc'); } @@ -700,7 +718,7 @@ * solely by load_includes(). */ private function load_dir_includes($section) { - $lsData = $this->fileSystemObj->ls(); + $lsData = $this->incFs->ls(); //attempt to load the shared includes file. if(isset($lsData['shared.inc']) && $lsData['shared.inc']['type'] == 'file') { @@ -714,10 +732,10 @@ } if(isset($lsData[$section]) && !count($this->sectionArr)) { - $this->fileSystemObj->cd($section); - $lsData = $this->fileSystemObj->ls(); + $this->incFs->cd($section); + $lsData = $this->incFs->ls(); if(isset($lsData['index.inc'])) { - $this->includesList[] = $this->fileSystemObj->realcwd .'/index.inc'; + $this->includesList[] = $this->incFs->realcwd .'/index.inc'; } } }//end load_dir_includes() @@ -798,7 +816,7 @@ } } catch(exception $e) { - $myRoot = preg_replace('/\//', '\\\/', $this->fileSystemObj->root); + $myRoot = preg_replace('/\//', '\\\/', $this->incFs->root); $displayableInclude = preg_replace('/^'. $myRoot .'/', '', $this->myLastInclude); $this->templateObj->set_message_wrapper(array( 'title' => "Fatal Error", @@ -881,7 +899,7 @@ * Method that appends filenames to the list of include scripts. */ private final function add_include($file) { - $myFile = $this->fileSystemObj->realcwd .'/'. $file; + $myFile = $this->incFs->realcwd .'/'. $file; if(!array_search($myFile, $this->includesList)) { $this->includesList[] = $myFile; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-03-02 17:55:00
|
Revision: 366 http://cs-content.svn.sourceforge.net/cs-content/?rev=366&view=rev Author: crazedsanity Date: 2009-03-02 17:54:58 +0000 (Mon, 02 Mar 2009) Log Message: ----------- Set default section, handle request for relative filename w/leading slash. /contentSystem.class.php: * parse_section(): -- if we encounter "/" as the section, potentially use "DEFAULT_SECTION" constant value instead of hard-coding "/content/index" (see #43) /cs_fileSystem.class.php: * filename2absolute(): -- special handling of requested file with single leading slash (treated as a file within the relative path instead of absolute). -- removed some extraneous commented-out debugging code. /tests/testOfCSContent.php: * __construct(): -- set constant for files directory * test_siteConfig(): -- use constant for files directory * test_genericPage(): -- use constant for files directory * test_cs_fileSystem() [NEW]: -- test handling of files with leading slashes, multiple slashes, dots, etc. to ensure it works as expected. -- this could stand to have many more tests... Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/cs_fileSystem.class.php trunk/1.0/tests/testOfCSContent.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-02-10 17:40:03 UTC (rev 365) +++ trunk/1.0/contentSystem.class.php 2009-03-02 17:54:58 UTC (rev 366) @@ -264,8 +264,8 @@ 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"; + if(($this->section === 0 || is_null($this->section) || !strlen($this->section)) && defined('DEFAULT_SECTION')) { + $this->section = constant('DEFAULT_SECTION'); } $myArr = split('/', $this->section); Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2009-02-10 17:40:03 UTC (rev 365) +++ trunk/1.0/cs_fileSystem.class.php 2009-03-02 17:54:58 UTC (rev 366) @@ -413,14 +413,19 @@ $filename = $this->resolve_path_with_dots($filename); - //see if it starts with a "/"... + //If it's a single filename beginning with a slash, strip the slash. + $x = array(); + $numSlashes = preg_match_all('/\//', $filename, $x); + if(preg_match('/^\/[\w]/', $filename) && !preg_match('/^\/\./', $filename) && $numSlashes == 1) { + $filename = preg_replace('/^\//', '', $filename); + } + + if(preg_match("/^\//", $filename)) { $retval = $filename; } else { $retval=$this->realcwd .'/'. $filename; $retval = $this->resolve_path_with_dots($retval); - #debug_print(__METHOD__ .": realcwd=(". $this->realcwd .")"); - #$this->resolve_path_with_dots($retval); } if(!$this->check_chroot($retval, FALSE)) { Modified: trunk/1.0/tests/testOfCSContent.php =================================================================== --- trunk/1.0/tests/testOfCSContent.php 2009-02-10 17:40:03 UTC (rev 365) +++ trunk/1.0/tests/testOfCSContent.php 2009-03-02 17:54:58 UTC (rev 366) @@ -24,6 +24,9 @@ $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt=1; + + $filesDir = dirname(__FILE__) ."/files"; + define('TEST_FILESDIR', $filesDir); }//end __construct() //------------------------------------------------------------------------- @@ -179,7 +182,7 @@ //------------------------------------------------------------------------- public function test_siteConfig() { - $configFile = dirname(__FILE__) .'/files/sampleConfig.xml'; + $configFile = constant('TEST_FILESDIR') .'/sampleConfig.xml'; $varPrefix = preg_replace("/:/", "_", __METHOD__ ."-"); $sc = new cs_siteConfig($configFile, 'main', $varPrefix); @@ -247,7 +250,7 @@ //------------------------------------------------------------------------- function test_genericPage() { - $filesDir = dirname(__FILE__) .'/files'; + $filesDir = constant('TEST_FILESDIR'); $page = new cs_genericPage(false, $filesDir .'/templates/main.shared.tmpl', false); $fs = new cs_fileSystem($filesDir .'/templates'); @@ -302,6 +305,36 @@ + //------------------------------------------------------------------------- + function test_cs_fileSystem() { + $fs = new cs_fileSystem(constant('TEST_FILESDIR')); + + $list = array( + 'slashTest' => array('/sampleConfig.xml', 'sampleConfig.xml'), + 'slashtest2' => array('/templates/content.shared.tmpl', 'templates/content.shared.tmpl'), + 'pathWithDots' => array('templates/.././sampleConfig.xml', '/templates/.././sampleConfig.xml'), + 'multiSlashes' => array('////sampleConfig.xml', '///sampleConfig.xml', '/templates///////content.shared.tmpl/../templates/content.shared.tmpl') + ); + + foreach($list as $testName=>$files) { + foreach($files as $filename) { + $gotException=false; + try { + $data = $fs->ls('/sampleConfig.xml'); + } + catch(exception $e) { + $gotException=true; + } + + $this->assertFalse($gotException, "Failed test '". $testName ."'"); + } + } + + }//end test_cs_fileSystem() + //------------------------------------------------------------------------- + + + }//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-10 17:40:07
|
Revision: 365 http://cs-content.svn.sourceforge.net/cs-content/?rev=365&view=rev Author: crazedsanity Date: 2009-02-10 17:40:03 +0000 (Tue, 10 Feb 2009) Log Message: ----------- Fix issue with incorrectly stripping leading slash of path to main template. /cs_genericPage.class.php: * initialize_locals(): -- use preg_match_all() to determine number of matches; preg_match() will always return 1 if there is one or more matches. 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-09 20:33:21 UTC (rev 364) +++ trunk/1.0/cs_genericPage.class.php 2009-02-10 17:40:03 UTC (rev 365) @@ -63,7 +63,10 @@ //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)) { + + $showMatches=array(); + $numMatches = preg_match_all('/\//', $mainTemplateFile, $showMatches); + if($numMatches == 1 && preg_match('/^/', $mainTemplateFile)) { $mainTemplateFile = preg_replace('/^\//', '', $mainTemplateFile); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-02-09 20:33:28
|
Revision: 364 http://cs-content.svn.sourceforge.net/cs-content/?rev=364&view=rev Author: crazedsanity Date: 2009-02-09 20:33:21 +0000 (Mon, 09 Feb 2009) Log Message: ----------- *** RELEASE 1.0-ALPHA8 *** NOTE:: this includes changes from ALPHA7, which was never committed to releases. CHANGE LOG::: * cs_siteConfig attempts to fix problems with invalid vars * functionality for stripping undefined template vars from text * fix problem with not including all includes (#246) SVN COMMAND::: merge --depth=infinity -r355:HEAD https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/1.0 Modified Paths: -------------- releases/1.0/VERSION releases/1.0/contentSystem.class.php releases/1.0/cs_genericPage.class.php releases/1.0/cs_siteConfig.class.php releases/1.0/tests/testOfCSContent.php Modified: releases/1.0/VERSION =================================================================== --- releases/1.0/VERSION 2009-02-09 20:16:19 UTC (rev 363) +++ releases/1.0/VERSION 2009-02-09 20:33:21 UTC (rev 364) @@ -1,5 +1,5 @@ ## Stores the current version of the cs-content system, and it's source. Please do NOT modify this file. -VERSION: 1.0-ALPHA6 +VERSION: 1.0-ALPHA8 PROJECT: cs-content $HeadURL$ \ No newline at end of file Modified: releases/1.0/contentSystem.class.php =================================================================== --- releases/1.0/contentSystem.class.php 2009-02-09 20:16:19 UTC (rev 363) +++ releases/1.0/contentSystem.class.php 2009-02-09 20:33:21 UTC (rev 364) @@ -262,6 +262,8 @@ * Rips apart the "section" string, setting $this->section and $this->sectionArr. */ private function parse_section() { + + //TODO::: this should be an OPTIONAL THING as to how to handle "/" (i.e. CSCONTENT_HANDLE_ROOTURL='content/index') if($this->section === 0 || is_null($this->section) || !strlen($this->section)) { $this->section = "content/index"; } @@ -650,20 +652,43 @@ $this->load_dir_includes($this->baseDir); //okay, now loop through $this->sectionArr & see if we can include anything else. + $addIndex=false; if(($this->fileSystemObj->cd($this->baseDir)) && is_array($this->sectionArr) && count($this->sectionArr) > 0) { - foreach($this->sectionArr as $mySection) { + + //if the last item in the array is "index", disregard it... + $loopThis = $this->sectionArr; + $lastSection = $this->sectionArr[(count($this->sectionArr) -1)]; + if($lastSection == 'index') { + array_pop($loopThis); + } + + + foreach($loopThis as $mySection) { //Run includes. $this->load_dir_includes($mySection); //attempt to cd() into the next directory, or die if we can't. if(!$this->fileSystemObj->cd($mySection)) { //no dice. Break the loop. + $addIndex = false; break; } + else { + //okay, we made it to the final directory; add the magic "index.inc" file if it exists. + $addIndex = true; + } } } + //include the final shared & index files. + $lsData = $this->fileSystemObj->ls(); + if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { + $this->add_include('shared.inc'); + } + if(isset($lsData['index.inc']) && is_array($lsData['index.inc']) && $addIndex==true) { + $this->add_include('index.inc'); + } }//end load_includes() //------------------------------------------------------------------------ @@ -679,13 +704,13 @@ //attempt to load the shared includes file. if(isset($lsData['shared.inc']) && $lsData['shared.inc']['type'] == 'file') { - $this->includesList[] = $this->fileSystemObj->realcwd .'/shared.inc'; + $this->add_include('shared.inc'); } //attempt to load the section's includes file. $myFile = $section .'.inc'; if(isset($lsData[$myFile]) && $lsData[$myFile]['type'] == 'file') { - $this->includesList[] = $this->fileSystemObj->realcwd .'/'. $myFile; + $this->add_include($myFile); } if(isset($lsData[$section]) && !count($this->sectionArr)) { @@ -850,5 +875,19 @@ //------------------------------------------------------------------------ + + //------------------------------------------------------------------------ + /** + * Method that appends filenames to the list of include scripts. + */ + private final function add_include($file) { + $myFile = $this->fileSystemObj->realcwd .'/'. $file; + if(!array_search($myFile, $this->includesList)) { + $this->includesList[] = $myFile; + } + }//end add_include() + //------------------------------------------------------------------------ + + }//end contentSystem{} ?> Modified: releases/1.0/cs_genericPage.class.php =================================================================== --- releases/1.0/cs_genericPage.class.php 2009-02-09 20:16:19 UTC (rev 363) +++ releases/1.0/cs_genericPage.class.php 2009-02-09 20:33:21 UTC (rev 364) @@ -61,7 +61,13 @@ */ protected function initialize_locals($mainTemplateFile) { + //replace multiple slashes with a single one to avoid confusing other logic... + $mainTemplateFile = preg_replace('/(\/){2,}/', '/', $mainTemplateFile); + if(preg_match('/\//', $mainTemplateFile) == 1 && preg_match('/^/', $mainTemplateFile)) { + $mainTemplateFile = preg_replace('/^\//', '', $mainTemplateFile); + } + if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/' && !preg_match('/^\./', dirname($mainTemplateFile))) { $this->tmplDir = dirname($mainTemplateFile); $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir); @@ -640,32 +646,40 @@ //------------------------------------------------------------------------- - public function strip_undef_template_vars($section='content') { + public function strip_undef_template_vars($templateContents) { $numLoops = 0; - if(isset($this->templateVars[$section])) { - $templateContents = $this->templateVars[$section]; - while(preg_match_all('/\{.\S+?\}/', $templateContents, $tags) && $numLoops < 50) { - $tags = $tags[0]; - - //TODO: figure out why this works when running it twice. - foreach($tags as $key=>$str) { - $str2 = str_replace("{", "", $str); - $str2 = str_replace("}", "", $str2); - if(!$this->templateVars[$str2]) { - //TODO: set an internal pointer or something to use here, so they can see what was missed. - $templateContents = str_replace($str, '', $templateContents); - } + while(preg_match_all('/\{.\S+?\}/', $templateContents, $tags) && $numLoops < 50) { + $tags = $tags[0]; + + //TODO: figure out why this works when running it twice. + foreach($tags as $key=>$str) { + $str2 = str_replace("{", "", $str); + $str2 = str_replace("}", "", $str2); + if(!$this->templateVars[$str2]) { + //TODO: set an internal pointer or something to use here, so they can see what was missed. + $templateContents = str_replace($str, '', $templateContents); } - $this->templateObj->parse("out", "out"); - $numLoops++; } + $numLoops++; } + return($templateContents); + }//end strip_undef_template_vars() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function strip_undef_template_vars_from_section($section='content') { + if(isset($this->templateVars[$section])) { + $this->templateVars[$section] = $this->strip_undef_template_vars($this->templateVars[$section]); + } else { throw new exception(__METHOD__ .": section (". $section .") does not exist"); } - return($templateContents); + + return($this->templateVars[$section]); + }//strip_undef_template_vars_from_section() //------------------------------------------------------------------------- - } }//end cs_genericPage{} ?> Modified: releases/1.0/cs_siteConfig.class.php =================================================================== --- releases/1.0/cs_siteConfig.class.php 2009-02-09 20:16:19 UTC (rev 363) +++ releases/1.0/cs_siteConfig.class.php 2009-02-09 20:33:21 UTC (rev 364) @@ -180,9 +180,18 @@ $itemValue = $itemValue['value']; if(preg_match("/{/", $itemValue)) { $origVal = $itemValue; + + //remove double-slashes (//) + $itemValue = preg_replace('/[\/]{2,}/', '\/', $itemValue); + + //remove leading slash for string replaces (i.e. "{/MAIN/SITE_ROOT}" becomes "{MAIN/SITE_ROOT}") + $itemValue = preg_replace('/{\//', '{', $itemValue); + + //replace special vars. $itemValue = $this->gfObj->mini_parser($itemValue, $specialVars, '{', '}'); + + //replace internal vars. $itemValue = $this->gfObj->mini_parser($itemValue, $parseThis, '{', '}'); - $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue); } if($attribs['CLEANPATH']) { Modified: releases/1.0/tests/testOfCSContent.php =================================================================== --- releases/1.0/tests/testOfCSContent.php 2009-02-09 20:16:19 UTC (rev 363) +++ releases/1.0/tests/testOfCSContent.php 2009-02-09 20:33:21 UTC (rev 364) @@ -293,9 +293,9 @@ $this->assertNotEqual($page->templateVars, $page2->templateVars); $page2 = clone $page; - $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars('content')); - $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars('content')); - $page2->templateVars['content'] = $page2->strip_undef_template_vars('content'); + $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars($page2->templateVars['content'])); + $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars($page2->templateVars['content'])); + $page2->templateVars['content'] = $page2->strip_undef_template_vars($page2->templateVars['content']); $this->assertEqual($page->return_printed_page(1), $page2->return_printed_page(1)); }//end test_genericPage //------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-02-09 20:16:25
|
Revision: 363 http://cs-content.svn.sourceforge.net/cs-content/?rev=363&view=rev Author: crazedsanity Date: 2009-02-09 20:16:19 +0000 (Mon, 09 Feb 2009) Log Message: ----------- *** RELEASE 1.0-ALPHA8 *** CHANGE LOG::: * cs_siteConfig attempts to fix problems with invalid vars Modified Paths: -------------- trunk/1.0/VERSION Modified: trunk/1.0/VERSION =================================================================== --- trunk/1.0/VERSION 2009-02-09 20:13:02 UTC (rev 362) +++ trunk/1.0/VERSION 2009-02-09 20:16:19 UTC (rev 363) @@ -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-ALPHA7 +VERSION: 1.0-ALPHA8 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-09 20:13:06
|
Revision: 362 http://cs-content.svn.sourceforge.net/cs-content/?rev=362&view=rev Author: crazedsanity Date: 2009-02-09 20:13:02 +0000 (Mon, 09 Feb 2009) Log Message: ----------- Automatically strip leading slashes from vars in config. /cs_siteConfig.class.php: * parse_config(): -- replace "{/" with "{" so replacements still work -- change multiple slashes into single slashes immediately instead of after parsing -- added comments about what the code means & why. Modified Paths: -------------- trunk/1.0/cs_siteConfig.class.php Modified: trunk/1.0/cs_siteConfig.class.php =================================================================== --- trunk/1.0/cs_siteConfig.class.php 2009-02-06 20:40:44 UTC (rev 361) +++ trunk/1.0/cs_siteConfig.class.php 2009-02-09 20:13:02 UTC (rev 362) @@ -180,9 +180,18 @@ $itemValue = $itemValue['value']; if(preg_match("/{/", $itemValue)) { $origVal = $itemValue; + + //remove double-slashes (//) + $itemValue = preg_replace('/[\/]{2,}/', '\/', $itemValue); + + //remove leading slash for string replaces (i.e. "{/MAIN/SITE_ROOT}" becomes "{MAIN/SITE_ROOT}") + $itemValue = preg_replace('/{\//', '{', $itemValue); + + //replace special vars. $itemValue = $this->gfObj->mini_parser($itemValue, $specialVars, '{', '}'); + + //replace internal vars. $itemValue = $this->gfObj->mini_parser($itemValue, $parseThis, '{', '}'); - $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue); } if($attribs['CLEANPATH']) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |