cs-content-commits Mailing List for CS-Content [Dynamic Content System] (Page 2)
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...> - 2011-01-19 03:40:03
|
Revision: 487 http://cs-content.svn.sourceforge.net/cs-content/?rev=487&view=rev Author: crazedsanity Date: 2011-01-19 03:39:57 +0000 (Wed, 19 Jan 2011) Log Message: ----------- Performance enhancements for __autoload(). NOTE::: both changes (__autoload() and cs_fileSystem::ls()) are optional; sites/apps that don't want to use them will continue to function as normal. /__autoload.php: * __autoload(): -- fixed indentation. -- test for class hints before trying to find files manually. -- stop searching if _autoload_hints_parser() returns true. * _autoload_hints_parser() [NEW]: -- function for finding and parsing a class hints file. * _autoload_directory_checker(): -- call to cs_fileSystem::ls() send args to avoid unncessary parsing. /contentSystem.class.php: * ARGUMENTS CHANGE TO cs_fileSystem::ls()::: -- arrange_directory_contents() -- load_includes() -- load_dir_includes() /cs_fileSystem.class.php: * ls(): -- ARG CHANGE: ARG RENAMED: #2 ($extendedInfo=true, WAS $args=NULL) -- extra call to self passes $extendedInfo argument -- call to get_fileinfo() passes $extendedInfo argument * get_fileinfo(): -- optionally adds file information to the returned array (still gets type, is_readable, and is_writable). /bin/generateHints.bash [NEW]: * create hints file with some standard Linux command-line utilities. Modified Paths: -------------- trunk/1.0/__autoload.php trunk/1.0/contentSystem.class.php trunk/1.0/cs_fileSystem.class.php Added Paths: ----------- trunk/1.0/bin/ trunk/1.0/bin/generateHints.bash Modified: trunk/1.0/__autoload.php =================================================================== --- trunk/1.0/__autoload.php 2011-01-16 00:18:29 UTC (rev 486) +++ trunk/1.0/__autoload.php 2011-01-19 03:39:57 UTC (rev 487) @@ -21,18 +21,17 @@ function __autoload($class) { - $tried = array(); + $tried = array(); + + $fsRoot = dirname(__FILE__) .'/../../'; + if(defined('LIBDIR')) { + $fsRoot = constant('LIBDIR'); + } + $fs = new cs_fileSystem($fsRoot); + $fs->cd('lib'); + if(!_autoload_hints_parser($class, $fs)) { + $lsData = $fs->ls(null,false); - $fsRoot = dirname(__FILE__) .'/../../'; - if(defined('LIBDIR')) { - $fsRoot = constant('LIBDIR'); - } - $fs = new cs_fileSystem($fsRoot); - - //try going into a "lib" directory. - $fs->cd('lib'); - $lsData = $fs->ls(); - //attempt to find it here... $tryThis = array(); if(preg_match('/[aA]bstract/', $class)) { @@ -44,22 +43,47 @@ $tryThis[] = $class .'Class.php'; $tryThis[] = $class .'.php'; - _autoload_directory_checker($fs, $class, $tryThis); - if(!class_exists($class)) { - $gf = new cs_globalFunctions; - $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class ."), realcwd=(". $fs->realcwd .")",1); - $gf->debug_print($tried,1); - $gf->debug_print($tryThis,1); - if(function_exists('cs_debug_backtrace')) { - cs_debug_backtrace(1); + _autoload_directory_checker($fs, $class, $tryThis); + if(!class_exists($class)) { + $gf = new cs_globalFunctions; + $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class ."), realcwd=(". $fs->realcwd .")",1); + $gf->debug_print($tried,1); + $gf->debug_print($tryThis,1); + if(function_exists('cs_debug_backtrace')) { + cs_debug_backtrace(1); + } + exit; } - exit; } }//end __autoload() +function _autoload_hints_parser($class, $fs) { + $foundClass=false; + if(defined('AUTOLOAD_HINTS') && file_exists(constant('AUTOLOAD_HINTS'))) { + $data = $fs->read(constant('AUTOLOAD_HINTS'),true); + $myHints = array(); + foreach($data as $s) { + $bits = explode('|', rtrim($s)); + if(count($bits) == 2) { + $myHints[$bits[1]] = $bits[0]; + } + } + #print "<pre>"; + #print_r($myHints); + $tryFile = constant('LIBDIR') .'/'. $myHints[$class]; + if(isset($myHints[$class]) && file_exists($tryFile)) { + require_once($tryFile); + if(class_exists($class)) { + $foundClass=true; + } + } + } + return($foundClass); +}//end _autoload_hints_parser() + function _autoload_directory_checker($fs, $class, $lookForFiles) { - $lsData = $fs->ls(); + $lsData = $fs->ls(null,false); $dirNames = array(); $curDirectory = $fs->realcwd; Added: trunk/1.0/bin/generateHints.bash =================================================================== --- trunk/1.0/bin/generateHints.bash (rev 0) +++ trunk/1.0/bin/generateHints.bash 2011-01-19 03:39:57 UTC (rev 487) @@ -0,0 +1,2 @@ +#!/bin/bash +grep "^class " * -R --exclude=*.svn* --exclude=*.tmp| grep ".php" | cut --delimiter=" " --fields 1,2 | sed "s/class //" | sed "s/:/\|/"> class.hints Property changes on: trunk/1.0/bin/generateHints.bash ___________________________________________________________________ Added: svn:executable + * Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2011-01-16 00:18:29 UTC (rev 486) +++ trunk/1.0/contentSystem.class.php 2011-01-19 03:39:57 UTC (rev 487) @@ -572,7 +572,7 @@ * name, or vice-versa. */ private function arrange_directory_contents($primaryIndex='section', $secondaryIndex='name') { - $directoryInfo = $this->tmplFs->ls(); + $directoryInfo = $this->tmplFs->ls(null,false); $arrangedArr = array(); if(is_array($directoryInfo)) { foreach($directoryInfo as $index=>$data) { @@ -678,7 +678,7 @@ $mySection = preg_replace('/\/index$/','', $mySection); } if($this->incFs->cd('/'. $mySection)) { - $lsData = $this->incFs->ls(); + $lsData = $this->incFs->ls(null,false); if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { $this->add_include('shared.inc'); } @@ -700,7 +700,7 @@ * solely by load_includes(). */ private function load_dir_includes($section) { - $lsData = $this->incFs->ls(); + $lsData = $this->incFs->ls(null,false); $addThese = array(); Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2011-01-16 00:18:29 UTC (rev 486) +++ trunk/1.0/cs_fileSystem.class.php 2011-01-19 03:39:57 UTC (rev 487) @@ -134,7 +134,7 @@ /** * Just like the linux version of the 'ls' command. */ - public function ls($filename=NULL, $args=NULL) { + public function ls($filename=NULL, $extendedInfo=true) { clearstatcache(); $retval = null; @@ -146,13 +146,13 @@ $tFile=$this->filename2absolute($filename); if(file_exists($tFile)) { //it's there... get info about it. - $info = $this->get_fileinfo($tFile); + $info = $this->get_fileinfo($tFile, $extendedInfo); if($info['type'] == 'dir') { $oldCwd = $this->cwd; $oldRealCwd = $this->realcwd; $this->cd($filename); - $retval = $this->ls(); + $retval = $this->ls(null, $extendedInfo); $this->cwd = $oldCwd; $this->realcwd = $oldRealCwd; @@ -189,23 +189,25 @@ /** * Grabs an array of information for a given file. */ - public function get_fileinfo($tFile) { + public function get_fileinfo($tFile,$extendedInfo=true) { //TODO: shouldn't require putting the "@" in front of these calls! $retval = array( - "size" => @filesize($tFile), "type" => @filetype($tFile), - "accessed" => @fileatime($tFile), - "modified" => @filemtime($tFile), - "owner" => @$this->my_getuser_group(fileowner($tFile), 'uid'), - "uid" => @fileowner($tFile), - "group" => @$this->my_getuser_group(filegroup($tFile), 'gid'), - "gid" => @filegroup($tFile), - "perms" => @$this->translate_perms(fileperms($tFile)), - "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4), "is_readable" => is_readable($tFile), "is_writable" => is_writable($tFile) ); + if($extendedInfo) { + $retval["size"] = @filesize($tFile); + $retval["accessed"] = @fileatime($tFile); + $retval["modified"] = @filemtime($tFile); + $retval["owner"] = @$this->my_getuser_group(fileowner($tFile), 'uid'); + $retval["uid"] = @fileowner($tFile); + $retval["group"] = @$this->my_getuser_group(filegroup($tFile), 'gid'); + $retval["gid"] = @filegroup($tFile); + $retval["perms"] = @$this->translate_perms(fileperms($tFile)); + $retval["perms_num"]= @substr(sprintf('%o', fileperms($tFile)), -4); + } return($retval); }//end get_fileinfo() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-16 00:18:35
|
Revision: 486 http://cs-content.svn.sourceforge.net/cs-content/?rev=486&view=rev Author: crazedsanity Date: 2011-01-16 00:18:29 +0000 (Sun, 16 Jan 2011) Log Message: ----------- Fix warning about undefined constant. Modified Paths: -------------- trunk/1.0/cs_session.class.php Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2011-01-06 01:16:49 UTC (rev 485) +++ trunk/1.0/cs_session.class.php 2011-01-16 00:18:29 UTC (rev 486) @@ -31,7 +31,7 @@ $sessName = $createSession; session_name($createSession); } - elseif(constant('SESSION_NAME') && isset($_COOKIE) && isset($_COOKIE[constant('SESSION_NAME')])) { + elseif(defined('SESSION_NAME') && constant('SESSION_NAME') && isset($_COOKIE) && isset($_COOKIE[constant('SESSION_NAME')])) { $sessName = constant('SESSION_NAME'); session_name(constant('SESSION_NAME')); $sessionId = $_COOKIE[constant('SESSION_NAME')]; @@ -163,4 +163,4 @@ }//end cs_session{} -?> \ No newline at end of file +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-06 01:16:55
|
Revision: 485 http://cs-content.svn.sourceforge.net/cs-content/?rev=485&view=rev Author: crazedsanity Date: 2011-01-06 01:16:49 +0000 (Thu, 06 Jan 2011) Log Message: ----------- Create session ID from cookie, if available. /cs_session.class.php: * __construct(): -- set defaults for $sessName & $sessionId. -- use session name from $_COOKIE, with the constant 'SESSION_NAME'. Modified Paths: -------------- trunk/1.0/cs_session.class.php Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2010-09-01 14:03:03 UTC (rev 484) +++ trunk/1.0/cs_session.class.php 2011-01-06 01:16:49 UTC (rev 485) @@ -24,14 +24,26 @@ */ function __construct($createSession=true) { parent::__construct(true); + $sessName = null; + $sessionId = null; if($createSession) { if(is_string($createSession) && strlen($createSession) >2) { + $sessName = $createSession; session_name($createSession); } + elseif(constant('SESSION_NAME') && isset($_COOKIE) && isset($_COOKIE[constant('SESSION_NAME')])) { + $sessName = constant('SESSION_NAME'); + session_name(constant('SESSION_NAME')); + $sessionId = $_COOKIE[constant('SESSION_NAME')]; + session_id($sessionId); + } //now actually create the session. @session_start(); } + if(is_null($sessName)) { + $sessName = session_name(); + } //check if there's a uid in the session already. //TODO: need a setting somewhere that says what the name of this var should be, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-09-01 14:03:09
|
Revision: 484 http://cs-content.svn.sourceforge.net/cs-content/?rev=484&view=rev Author: crazedsanity Date: 2010-09-01 14:03:03 +0000 (Wed, 01 Sep 2010) Log Message: ----------- Minor feature addition + exception on invalid data. /cs_globalFunctions.class.php: * debug_print(): -- ARG CHANGE: NEW ARG: #4 ($usePreTags=true) -- don't wrap the output with "<pre></pre>" if $usePreTags is false; set default value as true to keep normal behaviour if not specified. * mini_parser(): -- throw an exception if no array was passed. Modified Paths: -------------- trunk/1.0/cs_globalFunctions.class.php Modified: trunk/1.0/cs_globalFunctions.class.php =================================================================== --- trunk/1.0/cs_globalFunctions.class.php 2010-08-12 15:10:22 UTC (rev 483) +++ trunk/1.0/cs_globalFunctions.class.php 2010-09-01 14:03:03 UTC (rev 484) @@ -617,7 +617,7 @@ * * @return (string) printed data. */ - public function debug_print($input=NULL, $printItForMe=NULL, $removeHR=NULL) { + public function debug_print($input=NULL, $printItForMe=NULL, $removeHR=NULL, $usePreTags=true) { if(!is_numeric($removeHR)) { $removeHR = $this->debugRemoveHr; } @@ -630,9 +630,11 @@ print_r($input); $output = ob_get_contents(); ob_end_clean(); - - $output = "<pre>$output</pre>"; + if($usePreTags === true) { + $output = "<pre>$output</pre>"; + } + if(!isset($_SERVER['SERVER_PROTOCOL']) || !$_SERVER['SERVER_PROTOCOL']) { $output = strip_tags($output); $hrString = "\n***************************************************************\n"; @@ -690,12 +692,18 @@ $b="{"; $e="}"; } - - foreach($repArr as $key=>$value) { - //run the replacements. - $key = "$b" . $key . "$e"; - $template = str_replace("$key", $value, $template); + + if(is_array($repArr)) { + foreach($repArr as $key=>$value) { + //run the replacements. + $key = "$b" . $key . "$e"; + $template = str_replace("$key", $value, $template); + } } + else { + cs_debug_backtrace(1); + throw new exception(__METHOD__ .": no replacement array passed, or array was empty"); + } return($template); }//end mini_parser() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-08-12 15:10:29
|
Revision: 483 http://cs-content.svn.sourceforge.net/cs-content/?rev=483&view=rev Author: crazedsanity Date: 2010-08-12 15:10:22 +0000 (Thu, 12 Aug 2010) Log Message: ----------- Minor CLI-based fix. /contentSystem.class.php: * die_gracefully(): -- don't check SERVER_PROTOCOL right away. -- only set header if SERVER_PROTOCOL is found. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2010-08-12 15:06:07 UTC (rev 482) +++ trunk/1.0/contentSystem.class.php 2010-08-12 15:10:22 UTC (rev 483) @@ -740,8 +740,10 @@ * Called when something is broken. */ private function die_gracefully($details=NULL) { - if(isset($_SERVER['SERVER_PROTOCOL']) && $this->templateObj->template_file_exists('system/404.shared.tmpl')) { - header('HTTP/1.0 404 Not Found'); + if($this->templateObj->template_file_exists('system/404.shared.tmpl')) { + if(isset($_SERVER['SERVER_PROTOCOL'])) { + header('HTTP/1.0 404 Not Found'); + } //Simple "Page Not Found" error... show 'em. $this->templateObj->add_template_var('main', $this->templateObj->file_to_string('system/404.shared.tmpl')); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-08-12 15:06:13
|
Revision: 482 http://cs-content.svn.sourceforge.net/cs-content/?rev=482&view=rev Author: crazedsanity Date: 2010-08-12 15:06:07 +0000 (Thu, 12 Aug 2010) Log Message: ----------- Fixes to allow cs-content be used for command-line things. NOTE::: if an error occurs, it still parses an HTML template. It would probably be better to have a class that extends cs_genericPage, overriding some of the methods to be more CLI-friendly. /contentSystem.class.php: * __construct(): -- ARG CHANGE: NEW ARG: #2 ($section=null) -- only set section to REQUEST_URI if the passed $section is null /cs_genericPage.class.php: * print_page(): -- added a bit of debug info if something goes wrong. 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 2010-07-28 00:49:16 UTC (rev 481) +++ trunk/1.0/contentSystem.class.php 2010-08-12 15:06:07 UTC (rev 482) @@ -99,7 +99,7 @@ /** * The CONSTRUCTOR. Duh. */ - public function __construct($siteRoot=null) { + public function __construct($siteRoot=null, $section=null) { parent::__construct(); //setup the section stuff... @@ -109,8 +109,12 @@ //figure out the section & subsection stuff. $requestUri = preg_replace('/\/$/', '', $_SERVER['REQUEST_URI']); $this->fullSectionArr = explode('/', $requestUri); //TODO: will this cope with an APPURL being set? - $this->section = $this->clean_url($_SERVER['REQUEST_URI']); + if(is_null($section)) { + $section = @$_SERVER['REQUEST_URI']; + } + $this->section = $this->clean_url($section); + $this->initialize_locals($siteRoot); }//end __construct() //------------------------------------------------------------------------ Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2010-07-28 00:49:16 UTC (rev 481) +++ trunk/1.0/cs_genericPage.class.php 2010-08-12 15:06:07 UTC (rev 482) @@ -277,7 +277,7 @@ if(!strlen($out)) { $this->gfObj->debug_print($out); $this->gfObj->debug_print($this->mainTemplate); - $this->gfObj->debug_print("MANUAL FILE CONTENTS::: ". htmlentities(file_get_contents($this->tmplDir .'/'. $this->mainTemplate))); + $this->gfObj->debug_print("MANUAL FILE CONTENTS::: ". htmlentities(file_get_contents($this->mainTemplate))); exit(__METHOD__ .": mainTemplate (". $this->mainTemplate .") was empty...?"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-07-28 00:49:23
|
Revision: 481 http://cs-content.svn.sourceforge.net/cs-content/?rev=481&view=rev Author: crazedsanity Date: 2010-07-28 00:49:16 +0000 (Wed, 28 Jul 2010) Log Message: ----------- Fix cleaning for numeric values. /cs_globalFunctions.class.php: * string_from_array(): -- fix SQL quoting for int/integer/numeric/number/decimal/float values when an array of values is passed. -- add "-" to the list of excluded characters -- add "number" and "int" as synonyms for integer/numeric /tests/testOfCSGlobalFunctions.php: * test_cleanString(): -- integer/numeric both return negative numbers (the "-" isn't cleaned) Modified Paths: -------------- trunk/1.0/cs_globalFunctions.class.php trunk/1.0/tests/testOfCSGlobalFunctions.php Added Paths: ----------- trunk/1.0/useForCLI.patch Modified: trunk/1.0/cs_globalFunctions.class.php =================================================================== --- trunk/1.0/cs_globalFunctions.class.php 2010-07-12 23:37:31 UTC (rev 480) +++ trunk/1.0/cs_globalFunctions.class.php 2010-07-28 00:49:16 UTC (rev 481) @@ -176,7 +176,12 @@ } else { //now format it properly. - $array[$myIndex] = $this->cleanString($array[$myIndex], $myCleanStringArg); + $myUseSqlQuotes = null; + if(in_array($myCleanStringArg, array('int', 'integer', 'numeric', 'number', 'decimal', 'float'))) { + $myUseSqlQuotes = false; + } + $array[$myIndex] = $this->cleanString($array[$myIndex], $myCleanStringArg, $myUseSqlQuotes); + unset($myUseSqlQuotes); } } } @@ -507,15 +512,17 @@ $cleanThis = preg_replace("/[^0-9-+() ]/","",$cleanThis); break; + case "int": case "integer": case "numeric": + case "number": //Remove everything that's not numeric. if(is_null($cleanThis)) { $cleanThis = "NULL"; $sqlQuotes = 0; } else { - $cleanThis = preg_replace("/[^0-9]/","",$cleanThis); + $cleanThis = preg_replace("/[^0-9\-]/","",$cleanThis); } break; Modified: trunk/1.0/tests/testOfCSGlobalFunctions.php =================================================================== --- trunk/1.0/tests/testOfCSGlobalFunctions.php 2010-07-12 23:37:31 UTC (rev 480) +++ trunk/1.0/tests/testOfCSGlobalFunctions.php 2010-07-28 00:49:16 UTC (rev 481) @@ -54,8 +54,8 @@ 'email' => '@_-34..JuSTTHIS', 'email_plus_spaces' => '@_-34..JuST THIS', 'phone_fax' => '()+-34 ', - 'integer' => '34', - 'numeric' => '34', + 'integer' => '-34', + 'numeric' => '-34', 'decimal' => '34..', 'float' => '34..', 'name' => '\'JuSTTHIS', @@ -72,7 +72,7 @@ $cleanedData = $gf->cleanString($cleanThis, $name); //NOTE::: passing "%" in the message data causes an exception with the simpletest framework. - $this->assertEqual($expected, $cleanedData); + $this->assertEqual($expected, $cleanedData, "Cleaning test '". $name ."' FAILED... expected=(". $expected ."), got (". $cleanedData ."), "); } Added: trunk/1.0/useForCLI.patch =================================================================== --- trunk/1.0/useForCLI.patch (rev 0) +++ trunk/1.0/useForCLI.patch 2010-07-28 00:49:16 UTC (rev 481) @@ -0,0 +1,53 @@ +Index: code/lib/cs-content/cs_genericPage.class.php +=================================================================== +--- code/lib/cs-content/cs_genericPage.class.php (revision 480) ++++ code/lib/cs-content/cs_genericPage.class.php (working copy) +@@ -277,7 +277,7 @@ + if(!strlen($out)) { + $this->gfObj->debug_print($out); + $this->gfObj->debug_print($this->mainTemplate); +- $this->gfObj->debug_print("MANUAL FILE CONTENTS::: ". htmlentities(file_get_contents($this->tmplDir .'/'. $this->mainTemplate))); ++ $this->gfObj->debug_print("MANUAL FILE CONTENTS::: ". htmlentities(file_get_contents($this->mainTemplate))); + exit(__METHOD__ .": mainTemplate (". $this->mainTemplate .") was empty...?"); + } + +Index: code/lib/cs-content/contentSystem.class.php +=================================================================== +--- code/lib/cs-content/contentSystem.class.php (revision 480) ++++ code/lib/cs-content/contentSystem.class.php (working copy) +@@ -99,7 +99,7 @@ + /** + * The CONSTRUCTOR. Duh. + */ +- public function __construct($siteRoot=null) { ++ public function __construct($siteRoot=null, $section=null) { + parent::__construct(); + + //setup the section stuff... +@@ -109,8 +109,12 @@ + //figure out the section & subsection stuff. + $requestUri = preg_replace('/\/$/', '', $_SERVER['REQUEST_URI']); + $this->fullSectionArr = explode('/', $requestUri); //TODO: will this cope with an APPURL being set? +- $this->section = $this->clean_url($_SERVER['REQUEST_URI']); + ++ if(is_null($section)) { ++ $section = @$_SERVER['REQUEST_URI']; ++ } ++ $this->section = $this->clean_url($section); ++ + $this->initialize_locals($siteRoot); + }//end __construct() + //------------------------------------------------------------------------ +@@ -736,8 +740,10 @@ + * Called when something is broken. + */ + private function die_gracefully($details=NULL) { +- if(isset($_SERVER['SERVER_PROTOCOL']) && $this->templateObj->template_file_exists('system/404.shared.tmpl')) { +- header('HTTP/1.0 404 Not Found'); ++ if($this->templateObj->template_file_exists('system/404.shared.tmpl')) { ++ if(isset($_SERVER['SERVER_PROTOCOL'])) { ++ header('HTTP/1.0 404 Not Found'); ++ } + //Simple "Page Not Found" error... show 'em. + $this->templateObj->add_template_var('main', $this->templateObj->file_to_string('system/404.shared.tmpl')); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-07-12 23:37:37
|
Revision: 480 http://cs-content.svn.sourceforge.net/cs-content/?rev=480&view=rev Author: crazedsanity Date: 2010-07-12 23:37:31 +0000 (Mon, 12 Jul 2010) Log Message: ----------- Stop debug printing the "ls" data on failure. Modified Paths: -------------- trunk/1.0/__autoload.php Modified: trunk/1.0/__autoload.php =================================================================== --- trunk/1.0/__autoload.php 2010-07-09 16:41:44 UTC (rev 479) +++ trunk/1.0/__autoload.php 2010-07-12 23:37:31 UTC (rev 480) @@ -53,7 +53,6 @@ if(function_exists('cs_debug_backtrace')) { cs_debug_backtrace(1); } - $gf->debug_print($lsData,1); exit; } }//end __autoload() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-07-09 16:41:50
|
Revision: 479 http://cs-content.svn.sourceforge.net/cs-content/?rev=479&view=rev Author: crazedsanity Date: 2010-07-09 16:41:44 +0000 (Fri, 09 Jul 2010) Log Message: ----------- Provide a backtrace when a class can't be found (only if cs_debug_backtrace() is available). Modified Paths: -------------- trunk/1.0/__autoload.php Modified: trunk/1.0/__autoload.php =================================================================== --- trunk/1.0/__autoload.php 2010-07-08 17:44:25 UTC (rev 478) +++ trunk/1.0/__autoload.php 2010-07-09 16:41:44 UTC (rev 479) @@ -50,6 +50,9 @@ $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class ."), realcwd=(". $fs->realcwd .")",1); $gf->debug_print($tried,1); $gf->debug_print($tryThis,1); + if(function_exists('cs_debug_backtrace')) { + cs_debug_backtrace(1); + } $gf->debug_print($lsData,1); exit; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-07-08 17:44:31
|
Revision: 478 http://cs-content.svn.sourceforge.net/cs-content/?rev=478&view=rev Author: crazedsanity Date: 2010-07-08 17:44:25 +0000 (Thu, 08 Jul 2010) Log Message: ----------- Fix __autoload() to be more thorough. NOTE::: in some cases, this class could be very slow, depending on disk speed, caching, etc. The "clearstatcache()" call in cs_fileSystem::ls() may add to this slowing effect... consider removal or only optionally running it. /__autoload.php: * __autoload(): -- call _autoload_directory_checker()--a new recursive fuction--to look at all files & sub-folders until the class is found or there's no more stuff to look at. * _autoload_directory_checker() [NEW]: -- function that recursively calls itself, digging into sub-folders until it finds the class or runs out of files. /cs_fileSystem.class.php: * ls(): -- set return value var ($retval) as null initially to avoid PHP warnings/notices. -- removed some unnecessary commented-out debugging stuff. Modified Paths: -------------- trunk/1.0/__autoload.php trunk/1.0/cs_fileSystem.class.php Modified: trunk/1.0/__autoload.php =================================================================== --- trunk/1.0/__autoload.php 2010-07-07 15:05:57 UTC (rev 477) +++ trunk/1.0/__autoload.php 2010-07-08 17:44:25 UTC (rev 478) @@ -39,53 +39,60 @@ $myClass = preg_replace('/[aA]bstract/', '', $class); $tryThis[] = $class .'.abstract.class.php'; $tryThis[] = $myClass .'.abstract.class.php'; - $tryThis[] = 'abstract/'. $myClass .'.abstract.class.php'; } $tryThis[] = $class .'.class.php'; $tryThis[] = $class .'Class.php'; $tryThis[] = $class .'.php'; - $found=false; - foreach($tryThis as $filename) { - if(isset($lsData[$filename])) { - $tried[] = $fs->realcwd .'/'. $filename; - require_once($fs->realcwd .'/'. $filename); - if(class_exists($class)) { - $found=true; - break; - } + _autoload_directory_checker($fs, $class, $tryThis); + if(!class_exists($class)) { + $gf = new cs_globalFunctions; + $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class ."), realcwd=(". $fs->realcwd .")",1); + $gf->debug_print($tried,1); + $gf->debug_print($tryThis,1); + $gf->debug_print($lsData,1); + exit; + } +}//end __autoload() + + +function _autoload_directory_checker($fs, $class, $lookForFiles) { + $lsData = $fs->ls(); + $dirNames = array(); + $curDirectory = $fs->realcwd; + + $found = false; + + if(is_array($lsData)) { + foreach($lsData as $objectName => $objectData) { + if($objectData['type'] == 'dir') { + $dirNames[] = $objectName; } - } - - if(!$found) { - //try going into sub-directories to pull the files. - foreach($lsData as $i=>$d) { - if($d['type'] == 'dir') { - $subLs = $fs->ls($i); - foreach($tryThis as $filename) { - $fileLocation = $fs->realcwd .'/'. $i .'/'. $filename; - if(file_exists($fileLocation)) { - $tried[] = $fileLocation; - require_once($fileLocation); - if(class_exists($class)) { - $found=true; - break; - } - } + elseif($objectData['type'] == 'file') { + if(in_array($objectName, $lookForFiles)) { + require_once($fs->realcwd .'/'. $objectName); + if(class_exists($class)) { + $found = true; + break; } } - if($found) { - break; - } } } + } - if(!$found) { - $gf = new cs_globalFunctions; - $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class .")",1); - $gf->debug_print($tried,1); - $gf->debug_print($tryThis,1); - exit; + if(!$found && is_array($dirNames) && count($dirNames)) { + foreach($dirNames as $dir) { + $fs->cd($dir); + $found = _autoload_directory_checker($fs, $class, $lookForFiles); + $fs->cdup(); + + if($found === true) { + break; + } + } } -}//end __autoload() + + return($found); +} + ?> Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2010-07-07 15:05:57 UTC (rev 477) +++ trunk/1.0/cs_fileSystem.class.php 2010-07-08 17:44:25 UTC (rev 478) @@ -137,6 +137,7 @@ public function ls($filename=NULL, $args=NULL) { clearstatcache(); + $retval = null; //open the directory for reading. $this->dh = opendir($this->realcwd); clearstatcache(); @@ -175,13 +176,10 @@ debug_print("FILE: $tFile || TYPE: $tType || is_file(): ". is_file($tFile) ."is_dir(): ". is_dir($tFile)); exit; } - #debug_print("FILE: $file || $dir". $file); unset($tType); } } } - #debug_print($retval); - #debug_print(readdir($this->dh)); return($retval); }//end ls() //======================================================================================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-07-07 15:06:03
|
Revision: 477 http://cs-content.svn.sourceforge.net/cs-content/?rev=477&view=rev Author: crazedsanity Date: 2010-07-07 15:05:57 +0000 (Wed, 07 Jul 2010) Log Message: ----------- Fix warnings & deprecated function usages. /contentSystem.class.php: * __construct(): -- replace ereg_replace() with preg_replace() -- use explode() instead of split(). * parse_section(): -- use explode() instead of split() * clean_url(): -- use preg_match() instead of ereg() -- use explode() instead of split() /cs_session.class.php: * get_cookie(): -- use isset() on $_COOKIE **and* $_COOKIE[$name] (avoids PHP notices/warnings. Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/cs_session.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2010-05-26 17:47:04 UTC (rev 476) +++ trunk/1.0/contentSystem.class.php 2010-07-07 15:05:57 UTC (rev 477) @@ -104,11 +104,11 @@ //setup the section stuff... $repArr = array($_SERVER['SCRIPT_NAME'], "/"); - $_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']); + $_SERVER['REQUEST_URI'] = preg_replace('/^\//', "", $_SERVER['REQUEST_URI']); //figure out the section & subsection stuff. $requestUri = preg_replace('/\/$/', '', $_SERVER['REQUEST_URI']); - $this->fullSectionArr = split('/', $requestUri); //TODO: will this cope with an APPURL being set? + $this->fullSectionArr = explode('/', $requestUri); //TODO: will this cope with an APPURL being set? $this->section = $this->clean_url($_SERVER['REQUEST_URI']); $this->initialize_locals($siteRoot); @@ -298,7 +298,7 @@ if(($this->section === 0 || is_null($this->section) || !strlen($this->section)) && defined('DEFAULT_SECTION')) { $this->section = preg_replace('/^\//', '', constant('DEFAULT_SECTION')); } - $myArr = split('/', $this->section); + $myArr = explode('/', $this->section); //if we've got something in the array, keep going. if(is_array($myArr) && count($myArr) > 0) { @@ -357,13 +357,13 @@ $section = $section[0]; } - if(ereg("\.", $section)) { + if(preg_match("/\./", $section)) { //disregard file extensions, but keep everything else... // i.e. "index.php/yermom.html" becomes "index/yermom" - $tArr = split('/', $section); + $tArr = explode('/', $section); $tSection = null; foreach($tArr as $tSecName) { - $temp = split("\.", $tSecName); + $temp = explode(".", $tSecName); if(strlen($temp[0]) > 1) { $tSecName = $temp[0]; } Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2010-05-26 17:47:04 UTC (rev 476) +++ trunk/1.0/cs_session.class.php 2010-07-07 15:05:57 UTC (rev 477) @@ -76,7 +76,7 @@ */ public function get_cookie($name) { $retval = NULL; - if(isset($_COOKIE) && $_COOKIE[$name]) { + if(isset($_COOKIE) && isset($_COOKIE[$name])) { $retval = $_COOKIE[$name]; } return($retval); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-05-26 17:47:11
|
Revision: 476 http://cs-content.svn.sourceforge.net/cs-content/?rev=476&view=rev Author: crazedsanity Date: 2010-05-26 17:47:04 +0000 (Wed, 26 May 2010) Log Message: ----------- Minor change to quash PHP warnings. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2010-05-18 15:49:47 UTC (rev 475) +++ trunk/1.0/contentSystem.class.php 2010-05-26 17:47:04 UTC (rev 476) @@ -361,6 +361,7 @@ //disregard file extensions, but keep everything else... // i.e. "index.php/yermom.html" becomes "index/yermom" $tArr = split('/', $section); + $tSection = null; foreach($tArr as $tSecName) { $temp = split("\.", $tSecName); if(strlen($temp[0]) > 1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-05-18 15:49:54
|
Revision: 475 http://cs-content.svn.sourceforge.net/cs-content/?rev=475&view=rev Author: crazedsanity Date: 2010-05-18 15:49:47 +0000 (Tue, 18 May 2010) Log Message: ----------- *** RELEASE 1.0.0-RC1 *** SUMMARY OF CHANGES: * remove/suppress multiple PHP warnings. * add "is_readable" and "is_writable" to cs_fileSystem::get_fileinfo(). * fix issue with trailing "/" on DOCUMENT_ROOT. * changes for unit testing. * add $fullSectionArr as a local variable available to includes scripts. * fix output when called from CLI. SVN COMMAND::: svn merge -r463: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_fileSystem.class.php releases/1.0/cs_genericPage.class.php releases/1.0/cs_session.class.php releases/1.0/tests/files/templates/system/message_box.tmpl releases/1.0/tests/testOfCSContent.php Added Paths: ----------- releases/1.0/tests/files/includes/ releases/1.0/tests/files/includes/shared.inc Removed Paths: ------------- releases/1.0/tests/files/includes/shared.inc Property Changed: ---------------- releases/1.0/ Property changes on: releases/1.0 ___________________________________________________________________ Added: svn:mergeinfo + /trunk/1.0:464-474 Modified: releases/1.0/VERSION =================================================================== --- releases/1.0/VERSION 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/VERSION 2010-05-18 15:49:47 UTC (rev 475) @@ -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-BETA1 +VERSION: 1.0-RC1 PROJECT: cs-content -$HeadURL$ \ No newline at end of file +$HeadURL$ Modified: releases/1.0/contentSystem.class.php =================================================================== --- releases/1.0/contentSystem.class.php 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/contentSystem.class.php 2010-05-18 15:49:47 UTC (rev 475) @@ -69,6 +69,7 @@ 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 $fullsectionArr = array(); protected $tmplFs = NULL; //Object used to access the TEMPLATES filesystem @@ -106,6 +107,8 @@ $_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']); //figure out the section & subsection stuff. + $requestUri = preg_replace('/\/$/', '', $_SERVER['REQUEST_URI']); + $this->fullSectionArr = split('/', $requestUri); //TODO: will this cope with an APPURL being set? $this->section = $this->clean_url($_SERVER['REQUEST_URI']); $this->initialize_locals($siteRoot); @@ -129,7 +132,8 @@ //build the templating engine: this may cause an immediate redirect, if they need to be logged-in. //TODO: find a way to define this on a per-page basis. Possibly have templateObj->check_login() // run during the "finish" stage... probably using GenericPage{}->check_login(). - $root = preg_replace('/\/public_html$/', '', $_SERVER['DOCUMENT_ROOT']); + $root = preg_replace('/\/$/', '', $_SERVER['DOCUMENT_ROOT']); + $root = preg_replace('/\/public_html$/', '', $root); $root = preg_replace('/\/html/', '', $root); if(!is_null($siteRoot) && is_dir($siteRoot)) { @@ -149,7 +153,7 @@ 'curMonth' => date("m"), 'timezone' => date("T"), 'DOMAIN' => $_SERVER['SERVER_NAME'], - 'PHP_SELF' => $_SERVER['SCRIPT_NAME'], + //'PHP_SELF' => $_SERVER['SCRIPT_NAME'], // --> set in finish(). 'REQUEST_URI' => $_SERVER['REQUEST_URI'], 'FULL_URL' => $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], 'error_msg' => "" @@ -546,7 +550,7 @@ //pull a list of the files. $dirContents = $this->arrange_directory_contents(); - if(count($dirContents['shared'])) { + if(isset($dirContents['shared']) && count($dirContents['shared'])) { foreach($dirContents['shared'] as $section => $template) { $this->add_template($section, $template); @@ -574,8 +578,8 @@ $filename = preg_replace('/^\/\//', '/', $filename); //call another method to rip the filename apart properly, then arrange things as needed. $pieces = $this->parse_filename($index); - $myPriIndex = $pieces[$primaryIndex]; - $mySecIndex = $pieces[$secondaryIndex]; + $myPriIndex = @$pieces[$primaryIndex]; + $mySecIndex = @$pieces[$secondaryIndex]; if(strlen($myPriIndex) && strlen($mySecIndex)) { //only load if it's got BOTH parts of the filename. $arrangedArr[$myPriIndex][$mySecIndex] = $filename; @@ -731,8 +735,8 @@ * Called when something is broken. */ private function die_gracefully($details=NULL) { - header('HTTP/1.0 404 Not Found'); - if($this->templateObj->template_file_exists('system/404.shared.tmpl')) { + if(isset($_SERVER['SERVER_PROTOCOL']) && $this->templateObj->template_file_exists('system/404.shared.tmpl')) { + header('HTTP/1.0 404 Not Found'); //Simple "Page Not Found" error... show 'em. $this->templateObj->add_template_var('main', $this->templateObj->file_to_string('system/404.shared.tmpl')); @@ -748,7 +752,6 @@ exit; } else { - //TODO: make it *actually* die gracefully... the way it works now looks more like puke than grace. throw new exception(__METHOD__ .": Couldn't find 404 template, plus additional error... \nDETAILS::: $details" . "\nREASON::: ". $this->reason); } @@ -771,6 +774,7 @@ foreach($badUrlVars as $badVarName) { unset($_GET[$badVarName], $_POST[$badVarName]); } + unset($badUrlVars, $badVarName); if(is_array($this->injectVars) && count($this->injectVars)) { $definedVars = get_defined_vars(); @@ -783,6 +787,7 @@ } } } + unset($definedVars, $myVarName, $myVarVal); if(isset($this->session) && is_object($this->session)) { $this->templateObj->session = $this->session; @@ -797,8 +802,10 @@ //make the "final section" available to scripts. $finalSection = $this->finalSection; $sectionArr = $this->sectionArr; + $fullSectionArr = $this->fullSectionArr; array_unshift($sectionArr, $this->baseDir); $finalURL = $this->gfObj->string_from_array($sectionArr, NULL, '/'); + $this->templateObj->add_template_var('PHP_SELF', '/'. $this->gfObj->string_from_array($sectionArr, NULL, '/')); $page = $this->templateObj; @@ -808,6 +815,7 @@ try { foreach($this->includesList as $myInternalIndex=>$myInternalScriptName) { $this->myLastInclude = $myInternalScriptName; + unset($myInternalScriptName, $myInternalIndex); include_once($this->myLastInclude); } @@ -815,6 +823,7 @@ if(is_array($this->afterIncludesList)) { foreach($this->afterIncludesList as $myInternalIndex=>$myInternalScriptName) { $this->myLastInclude = $myInternalScriptName; + unset($myInternalScriptName, $myInternalIndex); include_once($this->myLastInclude); } } Modified: releases/1.0/cs_fileSystem.class.php =================================================================== --- releases/1.0/cs_fileSystem.class.php 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/cs_fileSystem.class.php 2010-05-18 15:49:47 UTC (rev 475) @@ -204,7 +204,9 @@ "group" => @$this->my_getuser_group(filegroup($tFile), 'gid'), "gid" => @filegroup($tFile), "perms" => @$this->translate_perms(fileperms($tFile)), - "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4) + "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4), + "is_readable" => is_readable($tFile), + "is_writable" => is_writable($tFile) ); return($retval); Modified: releases/1.0/cs_genericPage.class.php =================================================================== --- releases/1.0/cs_genericPage.class.php 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/cs_genericPage.class.php 2010-05-18 15:49:47 UTC (rev 475) @@ -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); } @@ -680,7 +680,7 @@ * Magic PHP method for retrieving the values of private/protected vars. */ public function __get($var) { - return($this->$var); + return(@$this->$var); }//end __get() //------------------------------------------------------------------------- Modified: releases/1.0/cs_session.class.php =================================================================== --- releases/1.0/cs_session.class.php 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/cs_session.class.php 2010-05-18 15:49:47 UTC (rev 475) @@ -30,7 +30,7 @@ } //now actually create the session. - session_start(); + @session_start(); } //check if there's a uid in the session already. Deleted: releases/1.0/tests/files/includes/shared.inc =================================================================== --- trunk/1.0/tests/files/includes/shared.inc 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/tests/files/includes/shared.inc 2010-05-18 15:49:47 UTC (rev 475) @@ -1,40 +0,0 @@ -<?php -/* - * Created on Oct 21, 2009 - * - * SVN INFORMATION::: - * ------------------- - * Last Author::::::::: $Author$ - * Current Revision:::: $Revision$ - * Repository Location: $HeadURL$ - * Last Updated:::::::: $Date$ - */ - - -$page->gfObj->debugPrintOpt=1; -$page->allow_invalid_urls(true); -$page->printOnFinish=false; - -if(isset($testObj) && is_object($testObj) && get_class($testObj) == 'TestOfCSContent') { - - //start unit tests!!! - - $testObj->assertTrue(is_array($sectionArr)); - $testObj->assertTrue(is_array($fullSectionArr)); - if(!$testObj->assertEqual(count($sectionArr), count($fullSectionArr))) { - $testObj->assertEqual(false, true, $page->gfObj->debug_print($fullSectionArr)); - } - - foreach(get_defined_vars() as $n=>$v) { - $acceptableVars = array('testObj', 'page', 'sectionArr', 'fullSectionArr', 'finalURL', 'finalSection', 'this'); - $testObj->assertTrue(in_array($n, $acceptableVars), "local var '". $n ."' not allowed as a local var"); - unset($acceptableVars); - } - -} -else { - throw new exception(__FILE__ .": failed to locate unit test object (testObj) while running include script unit tests"); -} - - -?> Copied: releases/1.0/tests/files/includes/shared.inc (from rev 474, trunk/1.0/tests/files/includes/shared.inc) =================================================================== --- releases/1.0/tests/files/includes/shared.inc (rev 0) +++ releases/1.0/tests/files/includes/shared.inc 2010-05-18 15:49:47 UTC (rev 475) @@ -0,0 +1,40 @@ +<?php +/* + * Created on Oct 21, 2009 + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + + +$page->gfObj->debugPrintOpt=1; +$page->allow_invalid_urls(true); +$page->printOnFinish=false; + +if(isset($testObj) && is_object($testObj) && get_class($testObj) == 'TestOfCSContent') { + + //start unit tests!!! + + $testObj->assertTrue(is_array($sectionArr)); + $testObj->assertTrue(is_array($fullSectionArr)); + if(!$testObj->assertEqual(count($sectionArr), count($fullSectionArr))) { + $testObj->assertEqual(false, true, $page->gfObj->debug_print($fullSectionArr)); + } + + foreach(get_defined_vars() as $n=>$v) { + $acceptableVars = array('testObj', 'page', 'sectionArr', 'fullSectionArr', 'finalURL', 'finalSection', 'this'); + $testObj->assertTrue(in_array($n, $acceptableVars), "local var '". $n ."' not allowed as a local var"); + unset($acceptableVars); + } + +} +else { + throw new exception(__FILE__ .": failed to locate unit test object (testObj) while running include script unit tests"); +} + + +?> Modified: releases/1.0/tests/files/templates/system/message_box.tmpl =================================================================== --- releases/1.0/tests/files/templates/system/message_box.tmpl 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/tests/files/templates/system/message_box.tmpl 2010-05-18 15:49:47 UTC (rev 475) @@ -11,7 +11,7 @@ <table class="{messageType}" width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td valign="top"> - <p style="border-style: solid; border-width: 0px 0px 2px 0px" class="title1">{title}</p> + <p style="border-style: solid; border-width: 0px 0px 2px 0px" class="title1">TEST -- {title}</p> <p style="margin: 5px 0px 5px 0px">{message}</p> {redirect} </td> </tr> Modified: releases/1.0/tests/testOfCSContent.php =================================================================== --- releases/1.0/tests/testOfCSContent.php 2010-05-18 13:29:42 UTC (rev 474) +++ releases/1.0/tests/testOfCSContent.php 2010-05-18 15:49:47 UTC (rev 475) @@ -24,7 +24,9 @@ $this->gfObj->debugPrintOpt=1; $filesDir = dirname(__FILE__) ."/files"; - define('TEST_FILESDIR', $filesDir); + if(!defined('TEST_FILESDIR')) { + define('TEST_FILESDIR', $filesDir); + } }//end __construct() //------------------------------------------------------------------------- @@ -68,7 +70,7 @@ foreach($sc->get_valid_sections() as $section) { $sectionData = $sc->get_section($section); foreach($sectionData as $name=>$value) { - if(is_array($value['attributes'])) { + if(isset($value['attributes']) && is_array($value['attributes'])) { if(isset($value['attributes']['SETGLOBAL'])) { $setAsGlobals[$name] = $value['value']; } @@ -247,6 +249,17 @@ + //------------------------------------------------------------------------- + public function test_contentSystem () { + + $content = new contentSystem(dirname(__FILE__) .'/files'); + $content->inject_var('testObj', $this); + $content->finish(); + }//end test_contentSystem() + //------------------------------------------------------------------------- + + + }//end TestOfCSContent //============================================================================= ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-05-18 13:29:48
|
Revision: 474 http://cs-content.svn.sourceforge.net/cs-content/?rev=474&view=rev Author: crazedsanity Date: 2010-05-18 13:29:42 +0000 (Tue, 18 May 2010) Log Message: ----------- Minor change to remove a PHP warning. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2010-05-14 17:14:14 UTC (rev 473) +++ trunk/1.0/contentSystem.class.php 2010-05-18 13:29:42 UTC (rev 474) @@ -550,7 +550,7 @@ //pull a list of the files. $dirContents = $this->arrange_directory_contents(); - if(count($dirContents['shared'])) { + if(isset($dirContents['shared']) && count($dirContents['shared'])) { foreach($dirContents['shared'] as $section => $template) { $this->add_template($section, $template); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-05-14 17:14:22
|
Revision: 473 http://cs-content.svn.sourceforge.net/cs-content/?rev=473&view=rev Author: crazedsanity Date: 2010-05-14 17:14:14 +0000 (Fri, 14 May 2010) Log Message: ----------- Suppress some PHP warnings. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2010-04-14 22:54:33 UTC (rev 472) +++ trunk/1.0/contentSystem.class.php 2010-05-14 17:14:14 UTC (rev 473) @@ -578,8 +578,8 @@ $filename = preg_replace('/^\/\//', '/', $filename); //call another method to rip the filename apart properly, then arrange things as needed. $pieces = $this->parse_filename($index); - $myPriIndex = $pieces[$primaryIndex]; - $mySecIndex = $pieces[$secondaryIndex]; + $myPriIndex = @$pieces[$primaryIndex]; + $mySecIndex = @$pieces[$secondaryIndex]; if(strlen($myPriIndex) && strlen($mySecIndex)) { //only load if it's got BOTH parts of the filename. $arrangedArr[$myPriIndex][$mySecIndex] = $filename; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-04-14 22:54:39
|
Revision: 472 http://cs-content.svn.sourceforge.net/cs-content/?rev=472&view=rev Author: crazedsanity Date: 2010-04-14 22:54:33 +0000 (Wed, 14 Apr 2010) Log Message: ----------- Add "is_readable" and "is_writable" indexes to get_fileinfo(). Modified Paths: -------------- trunk/1.0/cs_fileSystem.class.php Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2010-03-01 14:44:04 UTC (rev 471) +++ trunk/1.0/cs_fileSystem.class.php 2010-04-14 22:54:33 UTC (rev 472) @@ -204,7 +204,9 @@ "group" => @$this->my_getuser_group(filegroup($tFile), 'gid'), "gid" => @filegroup($tFile), "perms" => @$this->translate_perms(fileperms($tFile)), - "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4) + "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4), + "is_readable" => is_readable($tFile), + "is_writable" => is_writable($tFile) ); return($retval); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2010-03-01 14:44:11
|
Revision: 471 http://cs-content.svn.sourceforge.net/cs-content/?rev=471&view=rev Author: crazedsanity Date: 2010-03-01 14:44:04 +0000 (Mon, 01 Mar 2010) Log Message: ----------- Fix issue #318 /contentSystem.class.php: * initialize_locals(): -- strip trailing "/" from DOCUMENT_ROOT (issue #318) Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-11-11 01:06:10 UTC (rev 470) +++ trunk/1.0/contentSystem.class.php 2010-03-01 14:44:04 UTC (rev 471) @@ -132,7 +132,8 @@ //build the templating engine: this may cause an immediate redirect, if they need to be logged-in. //TODO: find a way to define this on a per-page basis. Possibly have templateObj->check_login() // run during the "finish" stage... probably using GenericPage{}->check_login(). - $root = preg_replace('/\/public_html$/', '', $_SERVER['DOCUMENT_ROOT']); + $root = preg_replace('/\/$/', '', $_SERVER['DOCUMENT_ROOT']); + $root = preg_replace('/\/public_html$/', '', $root); $root = preg_replace('/\/html/', '', $root); if(!is_null($siteRoot) && is_dir($siteRoot)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-11-11 01:06:26
|
Revision: 470 http://cs-content.svn.sourceforge.net/cs-content/?rev=470&view=rev Author: crazedsanity Date: 2009-11-11 01:06:10 +0000 (Wed, 11 Nov 2009) Log Message: ----------- Minor fixes for PHP warnings/notices. /cs_genericPage.class.php: * __get(): -- suppress notices/warnings about retrieving properties that don't exist. /cs_session.class.php: * __construct(): -- suppress notices/warnings if the session is already active. /tests/testOfCSContent.php: * __construct(): -- only define TEST_FILESDIR if it isn't already defined to avoid warnings/notices. Modified Paths: -------------- trunk/1.0/cs_genericPage.class.php trunk/1.0/cs_session.class.php trunk/1.0/tests/testOfCSContent.php Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2009-10-30 02:40:26 UTC (rev 469) +++ trunk/1.0/cs_genericPage.class.php 2009-11-11 01:06:10 UTC (rev 470) @@ -680,7 +680,7 @@ * Magic PHP method for retrieving the values of private/protected vars. */ public function __get($var) { - return($this->$var); + return(@$this->$var); }//end __get() //------------------------------------------------------------------------- Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2009-10-30 02:40:26 UTC (rev 469) +++ trunk/1.0/cs_session.class.php 2009-11-11 01:06:10 UTC (rev 470) @@ -30,7 +30,7 @@ } //now actually create the session. - session_start(); + @session_start(); } //check if there's a uid in the session already. Modified: trunk/1.0/tests/testOfCSContent.php =================================================================== --- trunk/1.0/tests/testOfCSContent.php 2009-10-30 02:40:26 UTC (rev 469) +++ trunk/1.0/tests/testOfCSContent.php 2009-11-11 01:06:10 UTC (rev 470) @@ -24,7 +24,9 @@ $this->gfObj->debugPrintOpt=1; $filesDir = dirname(__FILE__) ."/files"; - define('TEST_FILESDIR', $filesDir); + if(!defined('TEST_FILESDIR')) { + define('TEST_FILESDIR', $filesDir); + } }//end __construct() //------------------------------------------------------------------------- @@ -68,7 +70,7 @@ foreach($sc->get_valid_sections() as $section) { $sectionData = $sc->get_section($section); foreach($sectionData as $name=>$value) { - if(is_array($value['attributes'])) { + if(isset($value['attributes']) && is_array($value['attributes'])) { if(isset($value['attributes']['SETGLOBAL'])) { $setAsGlobals[$name] = $value['value']; } 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. |
From: <cra...@us...> - 2009-10-23 14:58:31
|
Revision: 468 http://cs-content.svn.sourceforge.net/cs-content/?rev=468&view=rev Author: crazedsanity Date: 2009-10-23 14:58:22 +0000 (Fri, 23 Oct 2009) Log Message: ----------- Set "PHP_SELF" template var as expected (previously, it was only a partial). NOTE::: see issue #306 for more details. /contentSystem.class.php: * initialize_locals(): -- commented-out "PHP_SELF" template var, with note that it is now set in finish(). * finish(): -- set PHP_SELF template var to be the URL form of $sectionArr. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-10-21 16:30:53 UTC (rev 467) +++ trunk/1.0/contentSystem.class.php 2009-10-23 14:58:22 UTC (rev 468) @@ -152,7 +152,7 @@ 'curMonth' => date("m"), 'timezone' => date("T"), 'DOMAIN' => $_SERVER['SERVER_NAME'], - 'PHP_SELF' => $_SERVER['SCRIPT_NAME'], + //'PHP_SELF' => $_SERVER['SCRIPT_NAME'], // --> set in finish(). 'REQUEST_URI' => $_SERVER['REQUEST_URI'], 'FULL_URL' => $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], 'error_msg' => "" @@ -804,6 +804,7 @@ $fullSectionArr = $this->fullSectionArr; array_unshift($sectionArr, $this->baseDir); $finalURL = $this->gfObj->string_from_array($sectionArr, NULL, '/'); + $this->templateObj->add_template_var('PHP_SELF', '/'. $this->gfObj->string_from_array($sectionArr, NULL, '/')); $page = $this->templateObj; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-10-21 16:31:01
|
Revision: 467 http://cs-content.svn.sourceforge.net/cs-content/?rev=467&view=rev Author: crazedsanity Date: 2009-10-21 16:30:53 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Minor updates for unit testing. Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/tests/testOfCSContent.php Added Paths: ----------- trunk/1.0/tests/files/includes/ trunk/1.0/tests/files/includes/shared.inc Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-10-21 16:30:18 UTC (rev 466) +++ trunk/1.0/contentSystem.class.php 2009-10-21 16:30:53 UTC (rev 467) @@ -107,7 +107,8 @@ $_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']); //figure out the section & subsection stuff. - $this->fullSectionArr = split('/', $_SERVER['REQUEST_URI']); //TODO: will this cope with an APPURL being set? + $requestUri = preg_replace('/\/$/', '', $_SERVER['REQUEST_URI']); + $this->fullSectionArr = split('/', $requestUri); //TODO: will this cope with an APPURL being set? $this->section = $this->clean_url($_SERVER['REQUEST_URI']); $this->initialize_locals($siteRoot); @@ -772,6 +773,7 @@ foreach($badUrlVars as $badVarName) { unset($_GET[$badVarName], $_POST[$badVarName]); } + unset($badUrlVars, $badVarName); if(is_array($this->injectVars) && count($this->injectVars)) { $definedVars = get_defined_vars(); @@ -784,6 +786,7 @@ } } } + unset($definedVars, $myVarName, $myVarVal); if(isset($this->session) && is_object($this->session)) { $this->templateObj->session = $this->session; @@ -810,6 +813,7 @@ try { foreach($this->includesList as $myInternalIndex=>$myInternalScriptName) { $this->myLastInclude = $myInternalScriptName; + unset($myInternalScriptName, $myInternalIndex); include_once($this->myLastInclude); } @@ -817,6 +821,7 @@ if(is_array($this->afterIncludesList)) { foreach($this->afterIncludesList as $myInternalIndex=>$myInternalScriptName) { $this->myLastInclude = $myInternalScriptName; + unset($myInternalScriptName, $myInternalIndex); include_once($this->myLastInclude); } } Added: trunk/1.0/tests/files/includes/shared.inc =================================================================== --- trunk/1.0/tests/files/includes/shared.inc (rev 0) +++ trunk/1.0/tests/files/includes/shared.inc 2009-10-21 16:30:53 UTC (rev 467) @@ -0,0 +1,40 @@ +<?php +/* + * Created on Oct 21, 2009 + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + + +$page->gfObj->debugPrintOpt=1; +$page->allow_invalid_urls(true); +$page->printOnFinish=false; + +if(isset($testObj) && is_object($testObj) && get_class($testObj) == 'TestOfCSContent') { + + //start unit tests!!! + + $testObj->assertTrue(is_array($sectionArr)); + $testObj->assertTrue(is_array($fullSectionArr)); + if(!$testObj->assertEqual(count($sectionArr), count($fullSectionArr))) { + $testObj->assertEqual(false, true, $page->gfObj->debug_print($fullSectionArr)); + } + + foreach(get_defined_vars() as $n=>$v) { + $acceptableVars = array('testObj', 'page', 'sectionArr', 'fullSectionArr', 'finalURL', 'finalSection', 'this'); + $testObj->assertTrue(in_array($n, $acceptableVars), "local var '". $n ."' not allowed as a local var"); + unset($acceptableVars); + } + +} +else { + throw new exception(__FILE__ .": failed to locate unit test object (testObj) while running include script unit tests"); +} + + +?> Property changes on: trunk/1.0/tests/files/includes/shared.inc ___________________________________________________________________ Added: svn:keywords + Author Revision HeadURL Date Modified: trunk/1.0/tests/testOfCSContent.php =================================================================== --- trunk/1.0/tests/testOfCSContent.php 2009-10-21 16:30:18 UTC (rev 466) +++ trunk/1.0/tests/testOfCSContent.php 2009-10-21 16:30:53 UTC (rev 467) @@ -247,6 +247,17 @@ + //------------------------------------------------------------------------- + public function test_contentSystem () { + + $content = new contentSystem(dirname(__FILE__) .'/files'); + $content->inject_var('testObj', $this); + $content->finish(); + }//end test_contentSystem() + //------------------------------------------------------------------------- + + + }//end TestOfCSContent //============================================================================= ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-10-21 16:30:27
|
Revision: 466 http://cs-content.svn.sourceforge.net/cs-content/?rev=466&view=rev Author: crazedsanity Date: 2009-10-21 16:30:18 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Minor change so I know what template is loading on error. Modified Paths: -------------- trunk/1.0/tests/files/templates/system/message_box.tmpl Modified: trunk/1.0/tests/files/templates/system/message_box.tmpl =================================================================== --- trunk/1.0/tests/files/templates/system/message_box.tmpl 2009-10-20 23:32:57 UTC (rev 465) +++ trunk/1.0/tests/files/templates/system/message_box.tmpl 2009-10-21 16:30:18 UTC (rev 466) @@ -11,7 +11,7 @@ <table class="{messageType}" width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td valign="top"> - <p style="border-style: solid; border-width: 0px 0px 2px 0px" class="title1">{title}</p> + <p style="border-style: solid; border-width: 0px 0px 2px 0px" class="title1">TEST -- {title}</p> <p style="margin: 5px 0px 5px 0px">{message}</p> {redirect} </td> </tr> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-10-20 23:33:11
|
Revision: 465 http://cs-content.svn.sourceforge.net/cs-content/?rev=465&view=rev Author: crazedsanity Date: 2009-10-20 23:32:57 +0000 (Tue, 20 Oct 2009) Log Message: ----------- Add fullSectionArr to show the URL with file extensions, etc. /contentSystem.class.php: * MAIN::: -- new (protected) var $fullSectionArr=array() * __construct(): -- build internal fullSectionArr just like sectionArr, but prior to any cleaning. May be different than sectionArr if APPURL is set. * finish(): -- create $fullSectionArr as a local variable for include scripts. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-09-23 14:46:10 UTC (rev 464) +++ trunk/1.0/contentSystem.class.php 2009-10-20 23:32:57 UTC (rev 465) @@ -69,6 +69,7 @@ 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 $fullsectionArr = array(); protected $tmplFs = NULL; //Object used to access the TEMPLATES filesystem @@ -106,6 +107,7 @@ $_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']); //figure out the section & subsection stuff. + $this->fullSectionArr = split('/', $_SERVER['REQUEST_URI']); //TODO: will this cope with an APPURL being set? $this->section = $this->clean_url($_SERVER['REQUEST_URI']); $this->initialize_locals($siteRoot); @@ -796,6 +798,7 @@ //make the "final section" available to scripts. $finalSection = $this->finalSection; $sectionArr = $this->sectionArr; + $fullSectionArr = $this->fullSectionArr; array_unshift($sectionArr, $this->baseDir); $finalURL = $this->gfObj->string_from_array($sectionArr, NULL, '/'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-09-23 14:46:27
|
Revision: 464 http://cs-content.svn.sourceforge.net/cs-content/?rev=464&view=rev Author: crazedsanity Date: 2009-09-23 14:46:10 +0000 (Wed, 23 Sep 2009) Log Message: ----------- Die gracefully on CLI too... /contentSystem.class.php: * die_gracefully(): -- only spit out HTML if it is NOT on the command line interface (CLI) -- remove TODO that was already done. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-09-21 14:38:05 UTC (rev 463) +++ trunk/1.0/contentSystem.class.php 2009-09-23 14:46:10 UTC (rev 464) @@ -731,8 +731,8 @@ * Called when something is broken. */ private function die_gracefully($details=NULL) { - header('HTTP/1.0 404 Not Found'); - if($this->templateObj->template_file_exists('system/404.shared.tmpl')) { + if(isset($_SERVER['SERVER_PROTOCOL']) && $this->templateObj->template_file_exists('system/404.shared.tmpl')) { + header('HTTP/1.0 404 Not Found'); //Simple "Page Not Found" error... show 'em. $this->templateObj->add_template_var('main', $this->templateObj->file_to_string('system/404.shared.tmpl')); @@ -748,7 +748,6 @@ exit; } else { - //TODO: make it *actually* die gracefully... the way it works now looks more like puke than grace. throw new exception(__METHOD__ .": Couldn't find 404 template, plus additional error... \nDETAILS::: $details" . "\nREASON::: ". $this->reason); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-09-21 14:38:17
|
Revision: 463 http://cs-content.svn.sourceforge.net/cs-content/?rev=463&view=rev Author: crazedsanity Date: 2009-09-21 14:38:05 +0000 (Mon, 21 Sep 2009) Log Message: ----------- *** RELEASE 1.0.0-BETA1 *** SUMMARY OF CHANGES::: * support for database session storage (cs_sessionDB from cs-webapplibs) * fix inclusion of index.inc script * clean up PHP warnings involving arrays * initialize internal vars to fix errors * more unit testing * add template vars immediately instead of at finish() for unit testing * pass siteRoot to contentSystem{}. * cs_versionAbstract now included here (cs-versionparse project defunct) * add many commonly-used template vars. * moved extra libraries into cs-webapplibs::: -- cs_phpDB -- cs_bbCodeParser -- cs_sessionDB -- cs_siteConfig -- cs_tabs * add script with __autoload() for loading classes on-the-fly. * removed dependency on PHPLib's "Template" class (#237) * fix parsing of template vars within nested block rows (#301) * root path for contentSystem set automatically. SVN COMMAND::: merge --depth=infinity -r423:HEAD https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/1.0 Modified Paths: -------------- releases/1.0/VERSION releases/1.0/abstract/cs_content.abstract.class.php releases/1.0/contentSystem.class.php releases/1.0/cs_fileSystem.class.php releases/1.0/cs_genericPage.class.php releases/1.0/cs_globalFunctions.class.php releases/1.0/cs_session.class.php releases/1.0/sample_files/public_html/content releases/1.0/tests/files/gptest_all-together.txt releases/1.0/tests/files/templates/content.shared.tmpl releases/1.0/tests/files/templates/footer.shared.tmpl releases/1.0/tests/files/templates/infobar.shared.tmpl releases/1.0/tests/files/templates/main.shared.tmpl releases/1.0/tests/files/templates/menubar.shared.tmpl releases/1.0/tests/files/templates/title.shared.tmpl releases/1.0/tests/testOfCSContent.php releases/1.0/tests/testOfCSGlobalFunctions.php Added Paths: ----------- releases/1.0/__autoload.php releases/1.0/abstract/cs_version.abstract.class.php releases/1.0/tests/files/gptest_blockrows.txt releases/1.0/tests/files/gptest_blockrows2.txt releases/1.0/tests/files/templates/system/ releases/1.0/tests/files/templates/system/404.shared.tmpl releases/1.0/tests/files/templates/system/message_box.tmpl releases/1.0/tests/files/version1 releases/1.0/tests/files/version2 releases/1.0/tests/files/version3 releases/1.0/tests/testOfCSFileSystem.php releases/1.0/tests/testOfCSVersionAbstract.php Removed Paths: ------------- releases/1.0/abstract/cs_phpDB.abstract.class.php releases/1.0/cs_bbCodeParser.class.php releases/1.0/cs_phpDB.class.php releases/1.0/cs_sessionDB.class.php releases/1.0/cs_siteConfig.class.php releases/1.0/cs_tabs.class.php releases/1.0/db_types/ releases/1.0/required/ releases/1.0/sample_files/bin/ releases/1.0/schema/ releases/1.0/tests/dbSchema/ releases/1.0/tests/files/templates/system/404.shared.tmpl releases/1.0/tests/files/templates/system/message_box.tmpl releases/1.0/tests/testOfCSPHPDB.php Modified: releases/1.0/VERSION =================================================================== --- releases/1.0/VERSION 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/VERSION 2009-09-21 14:38:05 UTC (rev 463) @@ -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-ALPHA10 +VERSION: 1.0-BETA1 PROJECT: cs-content $HeadURL$ \ No newline at end of file Copied: releases/1.0/__autoload.php (from rev 462, trunk/1.0/__autoload.php) =================================================================== --- releases/1.0/__autoload.php (rev 0) +++ releases/1.0/__autoload.php 2009-09-21 14:38:05 UTC (rev 463) @@ -0,0 +1,91 @@ +<?php +/* + * Created on Aug 28, 2009 + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + +//these libraries are **REQUIRED** to make __autoload() function without chicken-or-the-egg issues. +require_once(dirname(__FILE__) .'/abstract/cs_version.abstract.class.php'); +require_once(dirname(__FILE__) .'/abstract/cs_content.abstract.class.php'); +require_once(dirname(__FILE__) .'/cs_fileSystem.class.php'); +require_once(dirname(__FILE__) .'/cs_globalFunctions.class.php'); + + + + +function __autoload($class) { + + $tried = array(); + + $fsRoot = dirname(__FILE__) .'/../../'; + if(defined('LIBDIR')) { + $fsRoot = constant('LIBDIR'); + } + $fs = new cs_fileSystem($fsRoot); + + //try going into a "lib" directory. + $fs->cd('lib'); + $lsData = $fs->ls(); + + //attempt to find it here... + $tryThis = array(); + if(preg_match('/[aA]bstract/', $class)) { + $myClass = preg_replace('/[aA]bstract/', '', $class); + $tryThis[] = $class .'.abstract.class.php'; + $tryThis[] = $myClass .'.abstract.class.php'; + $tryThis[] = 'abstract/'. $myClass .'.abstract.class.php'; + } + $tryThis[] = $class .'.class.php'; + $tryThis[] = $class .'Class.php'; + $tryThis[] = $class .'.php'; + + $found=false; + foreach($tryThis as $filename) { + if(isset($lsData[$filename])) { + $tried[] = $fs->realcwd .'/'. $filename; + require_once($fs->realcwd .'/'. $filename); + if(class_exists($class)) { + $found=true; + break; + } + } + } + + if(!$found) { + //try going into sub-directories to pull the files. + foreach($lsData as $i=>$d) { + if($d['type'] == 'dir') { + $subLs = $fs->ls($i); + foreach($tryThis as $filename) { + $fileLocation = $fs->realcwd .'/'. $i .'/'. $filename; + if(file_exists($fileLocation)) { + $tried[] = $fileLocation; + require_once($fileLocation); + if(class_exists($class)) { + $found=true; + break; + } + } + } + } + if($found) { + break; + } + } + } + + if(!$found) { + $gf = new cs_globalFunctions; + $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class .")",1); + $gf->debug_print($tried,1); + $gf->debug_print($tryThis,1); + exit; + } +}//end __autoload() +?> Modified: releases/1.0/abstract/cs_content.abstract.class.php =================================================================== --- releases/1.0/abstract/cs_content.abstract.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/abstract/cs_content.abstract.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -11,7 +11,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) ."/../../cs-versionparse/cs_version.abstract.class.php"); abstract class cs_contentAbstract extends cs_versionAbstract { @@ -24,7 +23,6 @@ if($makeGfObj === true) { //make a cs_globalFunctions{} object. - require_once(dirname(__FILE__) ."/../cs_globalFunctions.class.php"); $this->gfObj = new cs_globalFunctions(); } }//end __construct() Deleted: releases/1.0/abstract/cs_phpDB.abstract.class.php =================================================================== --- releases/1.0/abstract/cs_phpDB.abstract.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/abstract/cs_phpDB.abstract.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -1,166 +0,0 @@ -<?php -/* - * Created on Jan 29, 2009 - * - * FILE INFORMATION: - * - * $HeadURL$ - * $Id$ - * $LastChangedDate$ - * $LastChangedBy$ - * $LastChangedRevision$ - */ - -abstract class cs_phpDBAbstract { - - /** Internal result set pointer. */ - protected $result = NULL; - - /** Internal error code. */ - protected $errorCode = 0; - - /** Status of the current transaction. */ - protected $transStatus = NULL; - - /** Whether there is a transaction in progress or not. */ - protected $inTrans = FALSE; - - /** Holds the last query performed. */ - protected $lastQuery = NULL; - - /** List of queries that have been run */ - protected $queryList=array(); - - /** How many seconds to wait for a query before cancelling it. */ - protected $timeOutSeconds = NULL; - - /** Internal check to determine if a connection has been established. */ - protected $isConnected=FALSE; - - /** Internal check to determine if the parameters have been set. */ - protected $paramsAreSet=FALSE; - - /** Resource handle. */ - protected $connectionID = -1; - - /** Hostname or IP to connect to */ - protected $host; - - /** Port to connect to (default for Postgres is 5432) */ - protected $port; - - /** Name of the database */ - protected $dbname; - - /** Username to connect to the database */ - protected $user; - - /** password to connect to the database */ - protected $password; - - /** Row counter for looping through records */ - protected $row = -1; - - /** cs_globalFunctions object, for string stuff. */ - protected $gfObj; - - /** Internal check to ensure the object has been properly created. */ - protected $isInitialized=FALSE; - - /** List of prepared statements, indexed off the name, with the sub-array being fieldname=>dataType. */ - protected $preparedStatements = array(); - - /** Set to TRUE to save all queries into an array. */ - protected $useQueryList=FALSE; - - /** array that essentially remembers how many times beginTrans() was called. */ - protected $transactionTree = NULL; - - - - //Define some abstract methods so they MUST be provided in order for things to work. - abstract public function set_db_info(array $params); - abstract public function close(); - abstract public function connect(array $dbParams=NULL, $forceNewConnection=FALSE); - abstract public function exec($query); - abstract public function errorMsg($setMessage=null, $logError=null); - abstract public function fobject(); - abstract public function farray(); - abstract public function farray_fieldnames($index=null, $numbered=null,$unsetIndex=1); - abstract public function farray_nvp($name, $value); - abstract public function farray_numbered(); - abstract public function numAffected(); - abstract public function numRows(); - abstract public function is_connected(); - - - //========================================================================= - public function __construct() { - $this->gfObj = new cs_globalFunctions; - $this->isInitialized = true; - }//end __construct() - //========================================================================= - - - - //========================================================================= - /** - * Make sure the object is sane. - */ - final protected function sanity_check() { - if($this->isInitialized !== TRUE) { - throw new exception(__METHOD__ .": not properly initialized"); - } - }//end sanity_check() - //========================================================================= - - - - //========================================================================= - /** - * Disconnect from the database (calls internal "close()" method). - */ - public function disconnect() { - return($this->close()); - }//end disconnect() - //========================================================================= - - - - //========================================================================= - public function affectedRows() { - return($this->numAffected()); - }//end affectedRows() - //========================================================================= - - - - //========================================================================= - public function currRow() { - return($this->row); - }//end currRow() - //========================================================================= - - - - //========================================================================= - public function querySafe($string) { - return($this->gfObj->cleanString($string,"query")); - }//end querySafe() - //========================================================================= - - - - //========================================================================= - /** - * Make it SQL safe. - */ - public function sqlSafe($string) { - return($this->gfObj->cleanString($string,"sql")); - }//end sqlSafe() - //========================================================================= - - - -} -?> \ No newline at end of file Copied: releases/1.0/abstract/cs_version.abstract.class.php (from rev 462, trunk/1.0/abstract/cs_version.abstract.class.php) =================================================================== --- releases/1.0/abstract/cs_version.abstract.class.php (rev 0) +++ releases/1.0/abstract/cs_version.abstract.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -0,0 +1,398 @@ +<?php +/* + * Created on January 01, 2009 by Dan Falconer + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + +abstract class cs_versionAbstract { + + public $isTest = FALSE; + + + + private $versionFileLocation=null; + private $fullVersionString; + private $suffixList = array( + 'ALPHA', //very unstable + 'BETA', //kinda unstable, but probably useable + 'RC' //all known bugs fixed, searching for unknown ones + ); + + + + abstract public function __construct(); + + + + //========================================================================= + /** + * Retrieve our version string from the VERSION file. + */ + final public function get_version($asArray=false) { + $retval = NULL; + + $this->auto_set_version_file(); + + if(file_exists($this->versionFileLocation)) { + $myMatches = array(); + $findIt = preg_match('/VERSION: (.+)/', file_get_contents($this->versionFileLocation), $matches); + + if($findIt == 1 && count($matches) == 2) { + $fullVersionString = $matches[1]; + $versionInfo = $this->parse_version_string($fullVersionString); + $this->fullVersionString = $this->build_full_version_string($versionInfo); + + + if($asArray) { + $retval = $versionInfo; + $retval['version_string'] = $this->fullVersionString; + } + else { + $retval = $this->build_full_version_string($versionInfo); + } + } + else { + throw new exception(__METHOD__ .": failed to retrieve version string in file " . + "(". $this->versionFileLocation .")"); + } + } + else { + throw new exception(__METHOD__ .": failed to retrieve version information, file " . + "(". $this->versionFileLocation .") does not exist or was not set"); + } + + return($retval); + }//end get_version() + //========================================================================= + + + + //========================================================================= + public function __get($var) { + return($this->$var); + }//end __get() + //========================================================================= + + + + //========================================================================= + final public function get_project() { + $retval = NULL; + $this->auto_set_version_file(); + if(file_exists($this->versionFileLocation)) { + $myMatches = array(); + $findIt = preg_match('/PROJECT: (.+)/', file_get_contents($this->versionFileLocation), $matches); + + if($findIt == 1 && count($matches) == 2 && strlen($matches[1])) { + $retval = $matches[1]; + } + else { + throw new exception(__METHOD__ .": failed to retrieve project string"); + } + } + else { + throw new exception(__METHOD__ .": failed to retrieve project information"); + } + + return($retval); + }//end get_project() + //========================================================================= + + + + //========================================================================= + public function set_version_file_location($location) { + if(file_exists($location)) { + $this->versionFileLocation = $location; + } + else { + throw new exception(__METHOD__ .": invalid location of VERSION file (". $location .")"); + } + }//end set_version_file_location() + //========================================================================= + + + + //========================================================================= + protected function auto_set_version_file() { + if(!strlen($this->versionFileLocation)) { + $bt = debug_backtrace(); + foreach($bt as $callNum=>$data) { + if(strlen($data['class'])) { + if($data['class'] != __CLASS__) { + $dir = dirname($data['file']); + if(preg_match('/tests$/', $dir)) { + $dir = preg_replace('/\/tests$/', '', $dir); + } + elseif(preg_match('/test$/', $dir)) { + $dir = preg_replace('/\/test$/', '', $dir); + } + break; + } + } + else { + throw new exception(__METHOD__ .": failed to locate the calling class in backtrace"); + } + } + + if(file_exists($dir .'/VERSION')) { + $this->set_version_file_location($dir .'/VERSION'); + } + else { + throw new exception(__METHOD__ .": failed to automatically set version file (tried ". $dir ."/VERSION)"); + } + } + }//end auto_set_version_file() + //========================================================================= + + + + //========================================================================= + /** + * + * TODO: add logic to split apart the suffix (i.e. "-ALPHA5" broken into "ALPHA" and "5"). + */ + public function parse_version_string($version) { + if(is_string($version) && strlen($version) && preg_match('/\./', $version)) { + $version = preg_replace('/ /', '', $version); + + $pieces = explode('.', $version); + $retval = array( + 'version_major' => $pieces[0], + 'version_minor' => $pieces[1] + ); + if(isset($pieces[2]) && strlen($pieces[2])) { + $retval['version_maintenance'] = $pieces[2]; + } + else { + $retval['version_maintenance'] = 0; + } + + if(preg_match('/-/', $retval['version_maintenance'])) { + $bits = explode('-', $retval['version_maintenance']); + $retval['version_maintenance'] = $bits[0]; + $suffix = $bits[1]; + } + elseif(preg_match('/-/', $retval['version_minor'])) { + $bits = explode('-', $retval['version_minor']); + $retval['version_minor'] = $bits[0]; + $suffix = $bits[1]; + } + else { + $suffix = ""; + } + $retval['version_suffix'] = $suffix; + } + else { + throw new exception(__METHOD__ .": invalid version string passed (". $version .")"); + } + + return($retval); + }//end parse_version_string() + //========================================================================= + + + + //========================================================================= + public function build_full_version_string(array $versionInfo) { + $requiredIndexes = array( + 'version_major', 'version_minor', 'version_maintenance', 'version_suffix' + ); + + $missing=""; + $count=0; + foreach($requiredIndexes as $indexName) { + if(isset($versionInfo[$indexName])) { + $count++; + } + else { + if(strlen($missing)) { + $missing .= ", ". $indexName; + } + else { + $missing = $indexName; + } + } + } + + if($count == count($requiredIndexes) && !strlen($missing)) { + $suffix = $versionInfo['version_suffix']; + unset($versionInfo['version_suffix']); + + $retval = ""; + foreach($versionInfo as $name=>$value) { + if(strlen($retval)) { + $retval .= ".". $value; + } + else { + $retval = $value; + } + } + if(strlen($suffix)) { + $retval .= "-". $suffix; + } + } + else { + throw new exception(__METHOD__ .": missing indexes in given array (". $missing .")"); + } + + return($retval); + + }//end build_full_version_string() + //========================================================================= + + + + //========================================================================= + public function is_higher_version($version, $checkIfHigher) { + $retval = FALSE; + $this->gfObj = new cs_globalFunctions; + if(!is_string($version) || !is_string($checkIfHigher)) { + throw new exception(__METHOD__ .": no valid version strings, version=(". $version ."), checkIfHigher=(". $checkIfHigher .")"); + } + elseif($version == $checkIfHigher) { + $retval = FALSE; + } + else { + $curVersionArr = $this->parse_version_string($version); + $checkVersionArr = $this->parse_version_string($checkIfHigher); + + unset($curVersionArr['version_string'], $checkVersionArr['version_string']); + + + $curVersionSuffix = $curVersionArr['version_suffix']; + $checkVersionSuffix = $checkVersionArr['version_suffix']; + + + unset($curVersionArr['version_suffix']); + + foreach($curVersionArr as $index=>$versionNumber) { + $checkThis = $checkVersionArr[$index]; + + if(is_numeric($checkThis) && is_numeric($versionNumber)) { + //set them as integers. + settype($versionNumber, 'int'); + settype($checkThis, 'int'); + + if($checkThis > $versionNumber) { + $retval = TRUE; + break; + } + elseif($checkThis == $versionNumber) { + //they're equal... + } + else { + //TODO: should there maybe be an option to throw an exception (freak out) here? + } + } + else { + throw new exception(__METHOD__ .": ". $index ." is not numeric in one of the strings " . + "(versionNumber=". $versionNumber .", checkThis=". $checkThis .")"); + } + } + + //now deal with those damnable suffixes, but only if the versions are so far identical: if + // the "$checkIfHigher" is actually higher, don't bother (i.e. suffixes don't matter when + // we already know there's a major, minor, or maintenance version that's also higher. + if($retval === FALSE) { + //EXAMPLE: $version="1.0.0-BETA3", $checkIfHigher="1.1.0" + // Moving from a non-suffixed version to a suffixed version isn't supported, but the inverse is: + // i.e. (1.0.0-BETA3 to 1.0.0) is okay, but (1.0.0 to 1.0.0-BETA3) is NOT. + // Also: (1.0.0-BETA3 to 1.0.0-BETA4) is okay, but (1.0.0-BETA4 to 1.0.0-BETA3) is NOT. + if(strlen($curVersionSuffix) && strlen($checkVersionSuffix) && $curVersionSuffix == $checkVersionSuffix) { + //matching suffixes. + } + elseif(strlen($curVersionSuffix) || strlen($checkVersionSuffix)) { + //we know the suffixes are there and DO match. + if(strlen($curVersionSuffix) && strlen($checkVersionSuffix)) { + //okay, here's where we do some crazy things... + $curVersionData = $this->parse_suffix($curVersionSuffix); + $checkVersionData = $this->parse_suffix($checkVersionSuffix); + + if($curVersionData['type'] == $checkVersionData['type']) { + //got the same suffix type (like "BETA"), check the number. + if($checkVersionData['number'] > $curVersionData['number']) { + //new version's suffix number higher than current... + $retval = TRUE; + } + elseif($checkVersionData['number'] == $curVersionData['number']) { + //new version's suffix number is EQUAL TO current... + $retval = FALSE; + } + else { + //new version's suffix number is LESS THAN current... + $retval = FALSE; + } + } + else { + //not the same suffix... see if the new one is higher. + $suffixValues = array_flip($this->suffixList); + if($suffixValues[$checkVersionData['type']] > $suffixValues[$curVersionData['type']]) { + $retval = TRUE; + } + else { + //current suffix type is higher... + } + } + + } + elseif(strlen($curVersionSuffix) && !strlen($checkVersionSuffix)) { + //i.e. "1.0.0-BETA1" to "1.0.0" --->>> OKAY! + $retval = TRUE; + } + elseif(!strlen($curVersionSuffix) && strlen($checkVersionSuffix)) { + //i.e. "1.0.0" to "1.0.0-BETA1" --->>> NOT ACCEPTABLE! + } + } + else { + //no suffix to care about + } + } + } + + return($retval); + + }//end is_higher_version() + //========================================================================= + + + + //========================================================================= + protected function parse_suffix($suffix) { + $retval = NULL; + if(strlen($suffix)) { + //determine what kind it is. + foreach($this->suffixList as $type) { + if(preg_match('/^'. $type .'/', $suffix)) { + $checkThis = preg_replace('/^'. $type .'/', '', $suffix); + if(strlen($checkThis) && is_numeric($checkThis)) { + //oooh... it's something like "BETA3" + $retval = array( + 'type' => $type, + 'number' => $checkThis + ); + } + else { + throw new exception(__METHOD__ .": invalid suffix (". $suffix .")"); + } + break; + } + } + } + else { + throw new exception(__METHOD__ .": invalid suffix (". $suffix .")"); + } + + return($retval); + }//end parse_suffix() + //========================================================================= + + +} +?> \ No newline at end of file Modified: releases/1.0/contentSystem.class.php =================================================================== --- releases/1.0/contentSystem.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/contentSystem.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -63,11 +63,6 @@ * |--> /includes/content/members/test.inc */ -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"); -require_once(dirname(__FILE__) ."/cs_genericPage.class.php"); -require_once(dirname(__FILE__) ."/cs_tabs.class.php"); class contentSystem extends cs_contentAbstract { @@ -103,27 +98,17 @@ /** * The CONSTRUCTOR. Duh. */ - public function __construct($testOnly=FALSE) { + public function __construct($siteRoot=null) { parent::__construct(); - if($testOnly === 'unit_test') { - //It's just a test, don't do anything we might regret later. - $this->isTest = TRUE; - } - 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']); - - //figure out the section & subsection stuff. - $this->section = $this->clean_url($_SERVER['REQUEST_URI']); - - $this->initialize_locals(); - } + + //setup the section stuff... + $repArr = array($_SERVER['SCRIPT_NAME'], "/"); + $_SERVER['REQUEST_URI'] = ereg_replace('^/', "", $_SERVER['REQUEST_URI']); + + //figure out the section & subsection stuff. + $this->section = $this->clean_url($_SERVER['REQUEST_URI']); + + $this->initialize_locals($siteRoot); }//end __construct() //------------------------------------------------------------------------ @@ -133,11 +118,10 @@ /** * Creates internal objects & prepares for later usage. */ - private function initialize_locals() { + private function initialize_locals($siteRoot=null) { //create a session that gets stored in a database if they so desire... if(defined('SESSION_DBSAVE')) { - require_once(dirname(__FILE__) .'/cs_sessionDB.class.php'); $obj = new cs_sessionDB(); $this->handle_session($obj); } @@ -145,13 +129,36 @@ //build the templating engine: this may cause an immediate redirect, if they need to be logged-in. //TODO: find a way to define this on a per-page basis. Possibly have templateObj->check_login() // run during the "finish" stage... probably using GenericPage{}->check_login(). - $this->templateObj = new cs_genericPage(FALSE, "main.shared.tmpl"); + $root = preg_replace('/\/public_html$/', '', $_SERVER['DOCUMENT_ROOT']); + $root = preg_replace('/\/html/', '', $root); + if(!is_null($siteRoot) && is_dir($siteRoot)) { + $root = $siteRoot; + } + elseif(defined('SITE_ROOT') && is_dir(constant('SITE_ROOT'))) { + $root = constant('SITE_ROOT'); + } + $this->templateObj = new cs_genericPage(FALSE, $root ."/templates/main.shared.tmpl"); + //setup some default template vars. - $this->templateObj->add_template_var('date', date('m-d-Y')); - $this->templateObj->add_template_var('time', date('H:i:s')); - $this->templateObj->add_template_var('curYear', date('Y')); + $defaultVars = array( + 'date' => date('m-d-Y'), + 'time' => date('H:i:s'), + 'curYear' => date('Y'), + 'curDate' => date("F j, Y"), + 'curMonth' => date("m"), + 'timezone' => date("T"), + 'DOMAIN' => $_SERVER['SERVER_NAME'], + 'PHP_SELF' => $_SERVER['SCRIPT_NAME'], + 'REQUEST_URI' => $_SERVER['REQUEST_URI'], + 'FULL_URL' => $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], + 'error_msg' => "" + ); + foreach($defaultVars as $k=>$v) { + $this->templateObj->add_template_var($k, $v); + } + $myUrl = '/'; if(strlen($this->section) && $this->section !== 0) { $myUrl = '/'. $this->section; @@ -164,24 +171,15 @@ } //create a fileSystem object for templates. - $tmplBaseDir = constant('SITE_ROOT') .'/templates'; - if(defined('TMPLDIR')) { - $tmplBaseDir = constant('TMPLDIR'); - } + $tmplBaseDir = $root .'/templates'; $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'); - } + $incBaseDir = $root .'/includes'; $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); - //check versions, make sure they're all the same. $myVersion = $this->get_version(); if($this->templateObj->get_version() !== $myVersion) { @@ -193,9 +191,6 @@ if($this->gfObj->get_version() !== $myVersion) { throw new exception(__METHOD__ .": ". get_class($this->gfObj) ." has mismatched version (". $this->gfObj->get_version() ." does not equal ". $myVersion .")"); } - if($this->tabs->get_version() !== $myVersion) { - throw new exception(__METHOD__ .": ". get_class($this->tabs) ." has mismatched version (". $this->tabs->get_version() ." does not equal ". $myVersion .")"); - } //split apart the section so we can do stuff with it later. $this->parse_section(); @@ -669,7 +664,11 @@ } //include the final shared & index files. - if($this->incFs->cd($this->finalSection)) { + $mySection = $this->section; + if(preg_match('/\/index$/', $mySection)) { + $mySection = preg_replace('/\/index$/','', $mySection); + } + if($this->incFs->cd('/'. $mySection)) { $lsData = $this->incFs->ls(); if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { $this->add_include('shared.inc'); @@ -773,8 +772,6 @@ unset($_GET[$badVarName], $_POST[$badVarName]); } - $page =& $this->templateObj; - if(is_array($this->injectVars) && count($this->injectVars)) { $definedVars = get_defined_vars(); foreach($this->injectVars as $myVarName=>$myVarVal) { @@ -788,29 +785,24 @@ } if(isset($this->session) && is_object($this->session)) { - $page->session =& $this->session; + $this->templateObj->session = $this->session; } //if we loaded an index, but there is no "content", then move 'em around so we have content. - if(isset($this->templateList['index']) && !isset($this->templateList['content'])) { - $this->add_template('content', $this->templateList['index']); - unset($this->templateList['index']); + if(isset($this->templateObj->templateFiles['index']) && !isset($this->templateObj->templateFiles['content'])) { + $this->add_template('content', $this->templateObj->templateFiles['index']); } - foreach($this->templateList as $mySection => $myTmpl) { - $myTmpl = preg_replace("/\/\//", "/", $myTmpl); - $page->add_template_file($mySection, $myTmpl); - } - unset($mySection); - unset($myTmpl); - //make the "final section" available to scripts. $finalSection = $this->finalSection; $sectionArr = $this->sectionArr; array_unshift($sectionArr, $this->baseDir); $finalURL = $this->gfObj->string_from_array($sectionArr, NULL, '/'); + + $page = $this->templateObj; + //now include the includes scripts, if there are any. if(is_array($this->includesList) && count($this->includesList)) { try { @@ -830,7 +822,7 @@ catch(exception $e) { $myRoot = preg_replace('/\//', '\\\/', $this->incFs->root); $displayableInclude = preg_replace('/^'. $myRoot .'/', '', $this->myLastInclude); - $this->templateObj->set_message_wrapper(array( + $page->set_message_wrapper(array( 'title' => "Fatal Error", 'message' => __METHOD__ .": A fatal error occurred while processing <b>". $displayableInclude ."</b>:<BR>\n<b>ERROR</b>: ". $e->getMessage(), @@ -846,12 +838,12 @@ unset($myInternalScriptName); } - if(is_bool($this->templateObj->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) { - $this->isValid = $this->templateObj->allow_invalid_urls(); + if(is_bool($page->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) { + $this->isValid = $page->allow_invalid_urls(); } if($this->isValid === TRUE) { - if($this->templateObj->printOnFinish === true) { + if($page->printOnFinish === true) { $page->print_page(); } } @@ -929,7 +921,8 @@ //------------------------------------------------------------------------ private final function add_template($var, $file) { - $this->templateList[$var] = $file; + $file = preg_replace("/\/\//", "/", $file); + $this->templateObj->add_template_file($var, $file); }//end add_template() //------------------------------------------------------------------------ Deleted: releases/1.0/cs_bbCodeParser.class.php =================================================================== --- releases/1.0/cs_bbCodeParser.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/cs_bbCodeParser.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -1,165 +0,0 @@ -<?php -/** - * Created on 2007-09-26 - * - * - * SVN INFORMATION::: - * ------------------ - * SVN Signature::::::: $Id$ - * Last Author::::::::: $Author$ - * Current Revision:::: $Revision$ - * Repository Location: $HeadURL$ - * Last Updated:::::::: $Date$ - * - * - * Originally from a snippet (just the function) on PHPFreaks.com: http://www.phpfreaks.com/quickcode/BBCode/712.php - * The original code had parse errors, so it had to be fixed... While it was posted as just a basic function, - * the code within (such as the reference to "$this->bbCodeData" indicated it was from a class... so it has - * been converted. - */ - -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); - -class cs_bbCodeParser extends cs_contentAbstract { - - /** Array containing all the codes & how to parse them. */ - private $bbCodeData = NULL; - - //========================================================================= - /** - * Setup internal structures. - */ - function __construct() { - parent::__construct(false); - # Which BBCode is accepted here - $this->bbCodeData = array( - 'bold' => array( - 'start' => array('[b]', '\[b\](.*)', '<b>\\1'), - 'end' => array('[/b]', '\[\/b\]', '</b>'), - ), - - 'underline' => array( - 'start' => array('[u]', '\[u\](.*)', '<u>\\1'), - 'end' => array('[/u]', '\[\/u\]', '</u>'), - ), - - 'italic' => array( - 'start' => array('[i]', '\[i\](.*)', '<i>\\1'), - 'end' => array('[/i]', '\[\/i\]', '</i>'), - ), - - 'image' => array( - 'start' => array('[img]', '\[img\](http:\/\/|https:\/\/|ftp:\/\/|\/)(.*)(.jpg|.jpeg|.bmp|.gif|.png)', '<img src=\'\\1\\2\\3\' />'), - 'end' => array('[/img]', '\[\/img\]', ''), - ), - - # [url]http://x.com[/url] - 'url1' => array( - 'start' => array('[url]', '\[url\](http:\/\/|https:\/\/|ftp:\/\/)(.*)', '<a target="_blank" href=\'\\1\\2\'>\\1\\2'), - 'end' => array('[/url]', '\[\/url\]', '</a>'), - ), - - # [url=http://x.com]stuff[/url] - 'url2' => array( - 'start' => array('[url]', '\[url=(http:\/\/|https:\/\/|ftp:\/\/)(.*)\](.*)', '<a target="_blank" href=\'\\1\\2\'>\\3'), - 'end' => array('[/url]', '\[\/url\]', '</a>'), - ), - - 'code' => array( - 'start' => array('[code]', '\[code\](.*)', '<br /><br /><b>CODE</b>:<div class="code">\\1'), - 'end' => array('[/code]', '\[\/code\]', '</div><br />'), - ), - ); - }//end __construct() - //========================================================================= - - - - //========================================================================= - /** - * Ensure the object is initialized properly, throw exception if not. - */ - private function isInitialized() { - if(!is_array($this->bbCodeData) || !count($this->bbCodeData)) { - throw new exception(__METHOD__ .": BBCode array not initialized"); - } - }//end isInitialized() - //========================================================================= - - - - //========================================================================= - /** - * Parse BBCode from the given string & return it with formatting. - */ - function parseString($data, $newlines2BR=FALSE) { - if(is_string($data) && strlen($data) > 10) { - $this->isInitialized(); - $data = str_replace("\n", '||newline||', $data); - - foreach( $this->bbCodeData as $k => $v ) { - if(isset($this->bbCodeData[$k]['special'])) { - $myMatches = array(); - $regex = '/'. $this->bbCodeData[$k]['start'][1] . $this->bbCodeData[$k]['end'][1] .'/'; - $x = preg_match_all($regex .'U', $data, $myMatches); - - if(count($myMatches[1])) { - $funcName = $v['special']; - $myArgs = $myMatches[1]; - $myArgs = array_unique($myArgs); - - foreach($myArgs as $index=>$value) { - $showThis = $this->$funcName($value); - $replaceThis = str_replace(array('[', ']'), array('\\[', '\\]'), $myMatches[0][$index]); - $data = preg_replace('/'. $replaceThis .'/U', $showThis, $data); - } - } - } - else { - $data = preg_replace("/".$this->bbCodeData[$k]['start'][1].$this->bbCodeData[$k]['end'][1]."/U", $this->bbCodeData[$k]['start'][2].$this->bbCodeData[$k]['end'][2], $data); - } - } - - $replaceNewlineStr = "\n"; - if($newlines2BR) { - $replaceNewlineStr = "<br />\n"; - } - $data = str_replace('||newline||', $replaceNewlineStr, $data); - - } - return $data; - }//end parseString() - //========================================================================= - - - - //========================================================================= - /** - * Enables extending classes to register a bbCode with special parsing. - * - * NOTE: right now, this will only handle syntax like "[{bbCodeString}={arg}]". - */ - protected function register_code_with_callback($bbCodeString, $method) { - - if(method_exists($this, $method)) { - $this->bbCodeData[$bbCodeString] = array( - 'special' => $method, - 'start' => array( - '['. $bbCodeString .']', - '\['. $bbCodeString .'=(.*)' - ), - 'end' => array( - '', - '\]' - ) - ); - } - else { - throw new exception(__METHOD__ .": method (". $method .") doesn't exist"); - } - - }//end register_code_with_callback() - //========================================================================= - -} -?> Modified: releases/1.0/cs_fileSystem.class.php =================================================================== --- releases/1.0/cs_fileSystem.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/cs_fileSystem.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -9,8 +9,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); - class cs_fileSystem extends cs_contentAbstract { public $root; //actual root directory. @@ -363,7 +361,7 @@ //something bad happened. $retval = 0; } - } + } else { throw new exception(__METHOD__ .": file is unreadable (". $filename .")"); } @@ -885,6 +883,8 @@ if($this->is_readable($filename)) { if($this->check_chroot($destination)) { //do the move. + $filename = $this->filename2absolute($filename); + $destination = $this->filename2absolute($destination); $retval = rename($filename, $destination); } else { Modified: releases/1.0/cs_genericPage.class.php =================================================================== --- releases/1.0/cs_genericPage.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/cs_genericPage.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -7,13 +7,12 @@ * $LastChangedBy$ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) ."/required/template.inc"); -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); class cs_genericPage extends cs_contentAbstract { - public $templateObj; //template object to parse the pages - public $templateVars = array(); //our copy of the global templateVars - public $mainTemplate; //the default layout of the site + public $templateVars = array(); //our copy of the global templateVars + public $templateFiles = array(); //our list of template files... + public $templateRows = array(); //array of block rows & their contents. + public $mainTemplate; //the default layout of the site public $unhandledVars=array(); public $printOnFinish=true; @@ -22,17 +21,13 @@ private $siteRoot; private $allowRedirect; - private $showEditableLink = FALSE; - private $allowInvalidUrls=NULL; //--------------------------------------------------------------------------------------------- /** * The constructor. */ - public function __construct($restrictedAccess=TRUE, $mainTemplateFile=NULL, $allowRedirect=TRUE) { - //handle some configuration. - $this->allowRedirect = $allowRedirect; + public function __construct($restrictedAccess=TRUE, $mainTemplateFile=NULL) { //initialize stuff from our parent... parent::__construct(); @@ -46,11 +41,6 @@ if(!defined('CS-CONTENT_SESSION_NAME')) { define("CS-CONTENT_SESSION_NAME", ini_get('session.name')); } - - //TODO: if the end page doesn't want to allow the "edit" links, will this still work? - if(defined("CS_CONTENT_MODIFIABLE") && constant("CS_CONTENT_MODIFIABLE") === TRUE) { - $this->showEditableLink = TRUE; - } }//end __construct() //--------------------------------------------------------------------------------------------- @@ -71,16 +61,30 @@ $mainTemplateFile = preg_replace('/^\//', '', $mainTemplateFile); } - - if(defined('SITE_ROOT')) { + if(isset($mainTemplateFile) && strlen($mainTemplateFile) && is_dir(dirname($mainTemplateFile)) && dirname($mainTemplateFile) != '.') { + $this->siteRoot = dirname($mainTemplateFile); + if(preg_match('/\//', $this->siteRoot) && preg_match('/templates/', $this->siteRoot)) { + $this->siteRoot .= "/.."; + } + } + elseif(defined('SITE_ROOT') && is_dir(constant('SITE_ROOT'))) { $this->siteRoot = constant('SITE_ROOT'); } + elseif(is_dir($_SERVER['DOCUMENT_ROOT'] .'/templates')) { + $this->siteRoot = $_SERVER['DOCUMENT_ROOT'] .'/templates'; + } else { - throw new exception(__METHOD__ .": required constant 'SITE_ROOT' not set"); + throw new exception(__METHOD__ .": cannot locate siteRoot from main template file (". $mainTemplateFile .")"); } + $fs = new cs_fileSystem(dirname(__FILE__)); + $this->siteRoot = $fs->resolve_path_with_dots($this->siteRoot); $this->tmplDir = $this->siteRoot .'/templates'; $this->libDir = $this->siteRoot .'/lib'; + if(!is_dir($this->tmplDir)) { + throw new exception(__METHOD__ .": invalid templates folder (". $this->tmplDir ."), siteRoot=(". $this->siteRoot .")"); + } + //if there have been some global template vars (or files) set, read 'em in here. if(is_array($GLOBALS['templateVars']) && count($GLOBALS['templateVars'])) { foreach($GLOBALS['templateVars'] as $key=>$value) { @@ -93,9 +97,6 @@ } } unset($GLOBALS['templateVars'], $GLOBALS['templateFiles']); - - //build a new instance of the template library (from PHPLib) - $this->templateObj=new Template($this->tmplDir,"keep"); //initialize a new template parser if(!preg_match('/^\//', $mainTemplateFile)) { $mainTemplateFile = $this->tmplDir ."/". $mainTemplateFile; @@ -175,13 +176,8 @@ * TODO: check if $fileName exists before blindly trying to parse it. */ public function add_template_file($handleName, $fileName){ - if($this->showEditableLink) { - $prefix = '[<a href="#NULL_page='. $fileName .'"><font color="red"><b>Edit "'. $handleName .'"</b></font></a>]<BR>'; - $this->add_template_var($handleName, $prefix .$this->file_to_string($fileName)); - } - else { - $this->add_template_var($handleName, $this->file_to_string($fileName)); - } + $this->templateFiles[$handleName] = $fileName; + $this->add_template_var($handleName, $this->file_to_string($fileName)); }//end add_template_file() //--------------------------------------------------------------------------------------------- @@ -267,42 +263,37 @@ * @return (str) Final, parsed page. */ public function print_page($stripUndefVars=1) { + $this->unhandledVars = array(); //Show any available messages. $this->process_set_message(); - //Load the default page layout. - $this->templateObj->set_file("main", $this->mainTemplate); - - //load the placeholder names and thier values - $this->templateObj->set_var($this->templateVars); - $this->templateObj->parse("out","main"); //parse the sub-files into the main page + if(isset($this->templateVars['main'])) { + //this is done to simulate old behaviour (the "main" templateVar could overwrite the entire main template). + $out = $this->templateVars['main']; + } + else { + $out = $this->file_to_string($this->mainTemplate); + } + if(!strlen($out)) { + $this->gfObj->debug_print($out); + $this->gfObj->debug_print($this->mainTemplate); + $this->gfObj->debug_print("MANUAL FILE CONTENTS::: ". htmlentities(file_get_contents($this->tmplDir .'/'. $this->mainTemplate))); + exit(__METHOD__ .": mainTemplate (". $this->mainTemplate .") was empty...?"); + } + $numLoops = 0; + $tags = array(); + while(preg_match_all('/\{.\S+?\}/', $out, $tags) && $numLoops < 10) { + $out = $this->gfObj->mini_parser($out, $this->templateVars, '{', '}'); + $numLoops++; + } + 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++; - } + $out = $this->strip_undef_template_vars($out, $this->unhandledVars); } - $this->templateObj->pparse("out","out"); //parse the main page + print($out); + }//end of print_page() //--------------------------------------------------------------------------------------------- @@ -348,9 +339,20 @@ * content & returns it. */ public function file_to_string($templateFileName) { + + if(preg_match('/templates/', $templateFileName)) { + $bits = explode('templates', $templateFileName); + if(count($bits) == 2) { + $templateFileName = $bits[1]; + } + else { + throw new exception(__METHOD__ .": full path to template file given but could not break the path into bits::: ". $templateFileName); + } + } $templateFileName = preg_replace('/\/\//', '\/', $templateFileName); - if($this->template_file_exists($templateFileName)) { - $retval = file_get_contents($this->tmplDir .'/'. $templateFileName); + $fullPathToFile = $this->template_file_exists($templateFileName); + if($fullPathToFile !== false && strlen($fullPathToFile)) { + $retval = file_get_contents($fullPathToFile); } else { $this->set_message_wrapper(array( "title" => 'Template File Error', @@ -369,7 +371,7 @@ * Checks to see if the given filename exists within the template directory. */ public function template_file_exists($file) { - $retval = 0; + $retval = false; //If the string doesn't start with a /, add one if (strncmp("/",$file,1)) { //strncmp returns 0 if they match, so we're putting a / on if they don't @@ -488,35 +490,8 @@ /** * Performs redirection, provided it is allowed. */ - function conditional_header($url, $exitAfter=TRUE) { - if($this->allowRedirect) { - //checks to see if headers were sent; if yes: use a meta redirect. - // if no: send header("location") info... - if(headers_sent()) { - //headers sent. Use the meta redirect. - print " - <HTML> - <HEAD> - <TITLE>Redirect Page</TITLE> - <META HTTP-EQUIV='refresh' content='0; URL=$url'> - </HEAD> - <a href=\"$url\"></a> - </HTML> - "; - } - else { - header("location:$url"); - } - - if($exitAfter) { - //redirecting without exitting is bad, m'kay? - exit; - } - } - else { - //TODO: should an exception be thrown, or maybe exit here anyway? - throw new exception(__METHOD__ .": auto redirects not allowed...?"); - } + function conditional_header($url, $exitAfter=TRUE,$isPermRedir=FALSE) { + $this->gfObj->conditional_header($url, $exitAfter, $isPermRedir); }//end conditional_header() //--------------------------------------------------------------------------------------------- @@ -656,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]; @@ -665,8 +640,14 @@ 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); } } @@ -681,6 +662,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 { @@ -690,6 +672,31 @@ return($this->templateVars[$section]); }//strip_undef_template_vars_from_section() //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Magic PHP method for retrieving the values of private/protected vars. + */ + public function __get($var) { + return($this->$var); + }//end __get() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Magic PHP method for changing the values of private/protected vars (or + * creating new ones). + */ + public function __set($var, $val) { + + //TODO: set some restrictions on internal vars... + $this->$var = $val; + }//end __set() + //------------------------------------------------------------------------- }//end cs_genericPage{} ?> Modified: releases/1.0/cs_globalFunctions.class.php =================================================================== --- releases/1.0/cs_globalFunctions.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/cs_globalFunctions.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -1,6 +1,5 @@ <?php -require_once(dirname(__FILE__) ."/../cs-versionparse/cs_version.abstract.class.php"); class cs_globalFunctions extends cs_versionAbstract { Deleted: releases/1.0/cs_phpDB.class.php =================================================================== --- releases/1.0/cs_phpDB.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/cs_phpDB.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -1,197 +0,0 @@ -<?php - -/* - * A class for generic PostgreSQL database access. - * - * SVN INFORMATION::: - * SVN Signature:::::::: $Id$ - * Last Committted Date: $Date$ - * Last Committed Path:: $HeadURL$ - * - */ - -/////////////////////// -// ORIGINATION INFO: -// Author: Trevin Chow (with contributions from Lee Pang, wle...@ho...) -// Email: t1...@ma... -// Date: February 21, 2000 -// Last Updated: August 14, 2001 -// -// Description: -// Abstracts both the php function calls and the server information to POSTGRES -// databases. Utilizes class variables to maintain connection information such -// as number of rows, result id of last operation, etc. -// -/////////////////////// - -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); -require_once(dirname(__FILE__) ."/abstract/cs_phpDB.abstract.class.php"); - -class cs_phpDB extends cs_contentAbstract { - - private $dbLayerObj; - private $dbType; - public $connectParams = array(); - - //========================================================================= - public function __construct($type='pgsql') { - - if(strlen($type)) { - - require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php'); - $className = __CLASS__ .'__'. $type; - $this->dbLayerObj = new $className; - $this->dbType = $type; - - parent::__construct(); - - $this->isInitialized = TRUE; - } - else { - throw new exception(__METHOD__ .": failed to give a type (". $type .")"); - } - }//end __construct() - //========================================================================= - - - - //========================================================================= - /** - * Magic method to call methods within the database abstraction layer ($this->dbLayerObj). - */ - public function __call($methodName, $args) { - if(method_exists($this->dbLayerObj, $methodName)) { - if($methodName == 'connect' && is_array($args[0])) { - //capture the connection parameters. - $this->connectParams = $args[0]; - } - $retval = call_user_func_array(array($this->dbLayerObj, $methodName), $args); - } - else { - throw new exception(__METHOD__ .': unsupported method ('. $methodName .') for database of type ('. $this->dbType .')'); - } - return($retval); - }//end __call() - //========================================================================= - - - - //========================================================================= - public function get_dbtype() { - return($this->dbType); - }//end get_dbtype() - //========================================================================= - - - - //========================================================================= - /** - * Performs queries which require results. Passing $indexField returns a - * complex array indexed from that field; passing $valueField will change - * it to a name=>value formatted array. - * - * NOTE:: when using an index field, be sure it is guaranteed to be unique, - * i.e. it is a primary key! If duplicates are found, the database class - * will throw an exception! - */ - public function run_query($sql, $indexField=null, $valueField=null) { - - $retval = array(); - - //length must be 19 as that's about the shortest valid SQL: "select * from table" - if(strlen($sql) >= 19) { - $this->exec($sql); - - $numRows = $this->numRows(); - $dbError = $this->errorMsg(); - if($numRows > 0 && !strlen($dbError)) { - if(strlen($indexField) && (is_null($valueField) || !strlen($valueField))) { - //return a complex array based on a given field. - $retval = $this->farray_fieldnames($indexField, null, 0); - } - elseif(strlen($indexField) && strlen($valueField)) { - //return an array as name=>value pairs. - $retval = $this->farray_nvp($indexField, $valueField); - } - else { - $retval = $this->farray_fieldnames(); - } - } - elseif($numRows == 0 && !strlen($dbError)) { - $retval = false; - } - else { - throw new exception(__METHOD__ .": no rows (". $numRows .") or dbError::: ". $dbError ."<BR>\nSQL::: ". $sql); - } - } - else { - throw new exception(__METHOD__ .": invalid length SQL (". $sql .")"); - } - - return($retval); - }//end run_query() - //========================================================================= - - - - //========================================================================= - /** - * Handles performing the insert statement & returning the last inserted ID. - */ - public function run_insert($sql, $sequence='null') { - - $this->exec($sql); - - if($this->numAffected() == 1 && !strlen($this->errorMsg())) { - //retrieve the ID just created. - $retval = $this->lastID($sequence); - } - else { - //something broke... - throw new exception(__METHOD__ .": failed to insert, rows=(". $this->numRows .")... " - ."ERROR::: ". $this->errorMsg() ."\n -- SQL:::: ". $sql); - } - - return($retval); - }//end run_insert() - //========================================================================= - - - - //========================================================================= - /** - * Performs the update & returns how many rows were affected. - */ - public function run_update($sql, $zeroIsOk=false) { - $this->exec($sql); - - $dberror = $this->errorMsg(); - $numAffected = $this->numAffected(); - - if(strlen($dberror)) { - throw new exception(__METHOD__ .": error while running update::: ". $dberror ." -- SQL::: ". $sql); - } - elseif($numAffected==0 && $zeroIsOk == false) { - throw new exception(__METHOD__ .": no rows updated (". $numAffected ."), SQL::: ". $sql); - } - - return($numAffected); - }//end run_update() - //========================================================================= - - - - //========================================================================= - public function reconnect() { - if(is_array($this->connectParams) && count($this->connectParams)) { - $this->dbLayerObj->connect($this->connectParams, true); - } - else { - throw new exception(__METHOD__ .": no connection parameters stored"); - } - }//end reconnect() - //========================================================================= - -} // end class phpDB - -?> Modified: releases/1.0/cs_session.class.php =================================================================== --- releases/1.0/cs_session.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/cs_session.class.php 2009-09-21 14:38:05 UTC (rev 463) @@ -8,9 +8,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); -require_once(dirname(__FILE__) ."/../cs-versionparse/cs_version.abstract.class.php"); - class cs_session extends cs_contentAbstract { protected $uid; @@ -40,7 +37,7 @@ //TODO: need a setting somewhere that says what the name of this var should be, // instead of always forcing "uid". $this->uid = 0; - if($_SESSION['uid']) { + if(isset($_SESSION['uid']) && $_SESSION['uid']) { $this->uid = $_SESSION['uid']; } Deleted: releases/1.0/cs_sessionDB.class.php =================================================================== --- releases/1.0/cs_sessionDB.class.php 2009-09-21 14:34:39 UTC (rev 462) +++ releases/1.0/cs_sessionDB.class.php 2009-09-21 14... [truncated message content] |