[Cs-content-commits] SF.net SVN: cs-content:[463] releases/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
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] |