Thread: [Cs-content-commits] SF.net SVN: cs-content:[341] trunk/1.0/cs_genericPage.class.php
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-01-30 20:40:30
|
Revision: 341 http://cs-content.svn.sourceforge.net/cs-content/?rev=341&view=rev Author: crazedsanity Date: 2009-01-30 20:40:25 +0000 (Fri, 30 Jan 2009) Log Message: ----------- Fix parsing of block rows (#230). /cs_genericPage.class.php: * get_block_row_defs(): -- fix regex for begin and end statements so the entire definition can be put onto a single line. Modified Paths: -------------- trunk/1.0/cs_genericPage.class.php Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2009-01-30 14:32:17 UTC (rev 340) +++ trunk/1.0/cs_genericPage.class.php 2009-01-30 20:40:25 UTC (rev 341) @@ -530,14 +530,14 @@ if(strlen($templateContents) >= 31) { //looks good to me. Run the regex... $flags = PREG_PATTERN_ORDER; - $reg = "/<!-- BEGIN (.+) -->/"; + $reg = "/<!-- BEGIN (\S{1,}) -->/"; preg_match_all($reg, $templateContents, $beginArr, $flags); $beginArr = $beginArr[1]; - $endReg = "/<!-- END (.+) -->/"; + $endReg = "/<!-- END (\S{1,}) -->/"; preg_match_all($endReg, $templateContents, $endArr, $flags); $endArr = $endArr[1]; - + //create a part of the array that shows any orphaned "BEGIN" statements (no matching "END" // statement), and orphaned "END" statements (no matching "BEGIN" statements) // NOTE::: by doing this, should easily be able to tell if the block rows were defined @@ -577,6 +577,7 @@ $rowDefs = $this->get_block_row_defs($templateVar); $useTheseBlockRows = $rowDefs['ordered']; + $retval = array(); if(is_array($useTheseBlockRows)) { foreach($useTheseBlockRows as $blockRowName) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-02-04 16:55:02
|
Revision: 353 http://cs-content.svn.sourceforge.net/cs-content/?rev=353&view=rev Author: crazedsanity Date: 2009-02-04 16:54:59 +0000 (Wed, 04 Feb 2009) Log Message: ----------- Fix minor logic problem missed in last commit. /cs_genericPage.class.php: * initialize_locals(): -- sanity checking of dirname for mainTemplateFile before using it -- set siteRoot AND tmplDir no matter how they're derived. Modified Paths: -------------- trunk/1.0/cs_genericPage.class.php Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2009-02-04 16:42:52 UTC (rev 352) +++ trunk/1.0/cs_genericPage.class.php 2009-02-04 16:54:59 UTC (rev 353) @@ -62,14 +62,15 @@ protected function initialize_locals($mainTemplateFile) { - if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/') { + if(strlen(dirname($mainTemplateFile)) && dirname($mainTemplateFile) !== '/' && !preg_match('/^\./', dirname($mainTemplateFile))) { $this->tmplDir = dirname($mainTemplateFile); + $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir); } else { //NOTE: this **requires** that the global variable "SITE_ROOT" is already set. $this->siteRoot = preg_replace('/\/public_html/', '', $_SERVER['DOCUMENT_ROOT']); + $this->tmplDir = $this->siteRoot .'/templates'; } - $this->siteRoot = preg_replace('/\/templates$/', '', $this->tmplDir); $this->libDir = $this->siteRoot .'/lib'; //if there have been some global template vars (or files) set, read 'em in here. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-02-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-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-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-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-08-13 18:40:32
|
Revision: 434 http://cs-content.svn.sourceforge.net/cs-content/?rev=434&view=rev Author: crazedsanity Date: 2009-08-13 18:40:21 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Initialize templateRows to avoid certain errors... 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-08-13 15:24:06 UTC (rev 433) +++ trunk/1.0/cs_genericPage.class.php 2009-08-13 18:40:21 UTC (rev 434) @@ -13,6 +13,7 @@ class cs_genericPage extends cs_contentAbstract { public $templateObj; //template object to parse the pages public $templateVars = array(); //our copy of the global templateVars + public $templateRows = array(); //array of block rows & their contents. public $mainTemplate; //the default layout of the site public $unhandledVars=array(); public $printOnFinish=true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-18 20:36:07
|
Revision: 444 http://cs-content.svn.sourceforge.net/cs-content/?rev=444&view=rev Author: crazedsanity Date: 2009-08-18 20:35:56 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Minor modifications after more unit testing. /cs_genericPage.class.php: * print_page(): -- reset internal "unhandledVars" array so it doesn't get updated erroneously. * strip_undef_template_vars(): -- ARG CHANGE: NEW ARG: #2 (array &$unhandled=null) -- this will eventually be called from print_page(), as the only difference was that print_page() stores unhandledVars. -- if the second argument is an array, it updates that with the list of unhandled vars. * strip_undef_template_vars_from_section(): -- added a comment to explain code that otherwise looks a bit like it would continuously call itself... 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-08-18 20:31:49 UTC (rev 443) +++ trunk/1.0/cs_genericPage.class.php 2009-08-18 20:35:56 UTC (rev 444) @@ -268,6 +268,7 @@ * @return (str) Final, parsed page. */ public function print_page($stripUndefVars=1) { + $this->unhandledVars = array(); //Show any available messages. $this->process_set_message(); @@ -630,7 +631,7 @@ //------------------------------------------------------------------------- - public function strip_undef_template_vars($templateContents) { + public function strip_undef_template_vars($templateContents, array &$unhandled=null) { $numLoops = 0; while(preg_match_all('/\{.\S+?\}/', $templateContents, $tags) && $numLoops < 50) { $tags = $tags[0]; @@ -641,6 +642,9 @@ $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. + if(is_array($unhandled)) { + $unhandled[$str2]++; + } $templateContents = str_replace($str, '', $templateContents); } } @@ -655,6 +659,7 @@ //------------------------------------------------------------------------- public function strip_undef_template_vars_from_section($section='content') { if(isset($this->templateVars[$section])) { + //rip out undefined vars from the contents of the given section. $this->templateVars[$section] = $this->strip_undef_template_vars($this->templateVars[$section]); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-18 20:43:20
|
Revision: 446 http://cs-content.svn.sourceforge.net/cs-content/?rev=446&view=rev Author: crazedsanity Date: 2009-08-18 20:43:12 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Removed code duplication for stripped undefined template vars. /cs_genericPage.class.php: * print_page(): -- call strip_undef_template_vars() instead of doing EXACTLY what it does already (the code for the called method was copied directly from print_page() at one point, I'm guessing this part was simply forgotten). 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-08-18 20:36:41 UTC (rev 445) +++ trunk/1.0/cs_genericPage.class.php 2009-08-18 20:43:12 UTC (rev 446) @@ -280,28 +280,10 @@ $this->templateObj->parse("out","main"); //parse the sub-files into the main page if($stripUndefVars) { - $numLoops = 0; - while(preg_match_all('/\{.\S+?\}/', $this->templateObj->varvals['out'], $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(!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']); - if(isset($this->unhandledVars[$str2])) { - $this->unhandledVars[$str2]++; - } - else { - $this->unhandledVars[$str2] = 1; - } - } - } - $this->templateObj->parse("out", "out"); - $numLoops++; - } + $this->templateObj->varvals['out'] = $this->strip_undef_template_vars( + $this->templateObj->varvals['out'], + $this->unhandledVars + ); } $this->templateObj->pparse("out","out"); //parse the main page This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-24 16:53:00
|
Revision: 454 http://cs-content.svn.sourceforge.net/cs-content/?rev=454&view=rev Author: crazedsanity Date: 2009-08-24 16:52:54 +0000 (Mon, 24 Aug 2009) Log Message: ----------- Fix for PHP warnings. /cs_genericPage.class.php: * strip_undef_template_vars(): -- use isset() when checking if the given $str2 value exists in the templateVars array. -- initialize indexes in the $unhandled array as 0 if they're not set before incrementing them. 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-08-20 20:34:59 UTC (rev 453) +++ trunk/1.0/cs_genericPage.class.php 2009-08-24 16:52:54 UTC (rev 454) @@ -621,9 +621,12 @@ foreach($tags as $key=>$str) { $str2 = str_replace("{", "", $str); $str2 = str_replace("}", "", $str2); - if(!$this->templateVars[$str2]) { + if(!isset($this->templateVars[$str2])) { //TODO: set an internal pointer or something to use here, so they can see what was missed. if(is_array($unhandled)) { + if(!isset($unhandled[$str2])) { + $unhandled[$str2]=0; + } $unhandled[$str2]++; } $templateContents = str_replace($str, '', $templateContents); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-10-30 02:40:35
|
Revision: 469 http://cs-content.svn.sourceforge.net/cs-content/?rev=469&view=rev Author: crazedsanity Date: 2009-10-30 02:40:26 +0000 (Fri, 30 Oct 2009) Log Message: ----------- Fix PHP notices/warnings. 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-10-23 14:58:22 UTC (rev 468) +++ trunk/1.0/cs_genericPage.class.php 2009-10-30 02:40:26 UTC (rev 469) @@ -86,7 +86,7 @@ } //if there have been some global template vars (or files) set, read 'em in here. - if(is_array($GLOBALS['templateVars']) && count($GLOBALS['templateVars'])) { + if(isset($GLOBALS['templateVars']) && is_array($GLOBALS['templateVars']) && count($GLOBALS['templateVars'])) { foreach($GLOBALS['templateVars'] as $key=>$value) { $this->add_template_var($key, $value); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |