[Cs-content-commits] SF.net SVN: cs-content:[325] trunk/0.10
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-01-26 02:20:14
|
Revision: 325 http://cs-content.svn.sourceforge.net/cs-content/?rev=325&view=rev Author: crazedsanity Date: 2009-01-26 01:33:48 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Reverse merge (HEAD:311) to match /releases/0.10 Modified Paths: -------------- trunk/0.10/cs_globalFunctions.php trunk/0.10/db_types/cs_phpDB__pgsql.class.php Removed Paths: ------------- trunk/0.10/cs_siteConfig.class.php trunk/0.10/tests/ Modified: trunk/0.10/cs_globalFunctions.php =================================================================== --- trunk/0.10/cs_globalFunctions.php 2009-01-26 01:29:21 UTC (rev 324) +++ trunk/0.10/cs_globalFunctions.php 2009-01-26 01:33:48 UTC (rev 325) @@ -17,17 +17,10 @@ public function __construct() { //These checks have been implemented for pseudo backwards-compatibility // (internal vars won't change if GLOBAL vars changed). - if(defined('DEBUGREMOVEHR')) { - $this->debugRemoveHr = constant('DEBUGREMOVEHR'); - } - elseif(isset($GLOBALS['DEBUGREMOVEHR'])) { + if(isset($GLOBALS['DEBUGREMOVEHR'])) { $this->debugRemoveHr = $GLOBALS['DEBUGREMOVEHR']; } - - if(defined('DEBUGPRINTOPT')) { - $this->debugPrintOpt = constant('DEBUGPRINTOPT'); - } - elseif(isset($GLOBALS['DEBUGPRINTOPT'])) { + if(isset($GLOBALS['DEBUGPRINTOPT'])) { $this->debugPrintOpt = $GLOBALS['DEBUGPRINTOPT']; } $this->set_version_file_location(dirname(__FILE__) . '/VERSION'); @@ -62,13 +55,15 @@ $this->oldForceSqlQuotes = $this->forceSqlQuotes; $this->forceSqlQuotes = $newSetting; $retval = true; + $this->debug_print(__METHOD__ .": swapped (OLD=". $this->oldForceSqlQuotes .", CUR=". $this->forceSqlQuotes .")"); } else { $retval = false; + $this->debug_print(__METHOD__ .": no swap (OLD=". $this->oldForceSqlQuotes .", CUR=". $this->forceSqlQuotes .")"); } return($retval); - }//end switch_force_sql_quotes() + }//end force_sql_quotes() //========================================================================= @@ -380,7 +375,6 @@ */ $evilChars = array("\$", "%", "~", "*",">", "<", "-", "{", "}", "[", "]", ")", "(", "&", "#", "?", ".", "\,","\/","\\","\"","\|","!","^","+","`","\n","\r"); $cleanThis = preg_replace("/\|/","",$cleanThis); - $cleanThis = preg_replace("/\'/", "", $cleanThis); $cleanThis = str_replace($evilChars,"", $cleanThis); $cleanThis = stripslashes(addslashes($cleanThis)); break; @@ -519,7 +513,7 @@ case "name": case "names": - //allows only things in the "alpha" case and single quotes. + //removes everything in the "alpha" case, but allows "'". $cleanThis = preg_replace("/[^a-zA-Z']/", "", $cleanThis); break; @@ -531,7 +525,7 @@ case "bool": case "boolean": //makes it either T or F (gotta lower the string & only check the first char to ensure accurate results). - $cleanThis = $this->interpret_bool($cleanThis, array('f', 't')); + $cleanThis = interpret_bool($cleanThis, array('f', 't')); break; case "varchar": @@ -777,67 +771,6 @@ return($retval); }//end array_as_option_list() //########################################################################## - - - - //########################################################################## - public function interpret_bool($interpretThis, array $trueFalseMapper=null) { - $interpretThis = preg_replace('/ /', '', $interpretThis); - if(is_array($trueFalseMapper)) { - if(count($trueFalseMapper) == 2 && isset($trueFalseMapper[0]) && isset($trueFalseMapper[1])) { - $realVals = $trueFalseMapper; - } - else { - throw new exception(__METHOD__ .": invalid true/false map"); - } - } - else { - //set an array that defines what "0" and "1" return. - $realVals = array( - 0 => false, - 1 => true - ); - } - - //now figure out the value to return. - if(is_numeric($interpretThis)) { - settype($interpretThis, 'integer'); - if($interpretThis == '0') { - $index=0; - } - else { - $index=1; - } - } - elseif(is_bool($interpretThis)) { - if($interpretThis == true) { - $index=1; - } - else { - $index=0; - } - } - elseif(preg_match('/^true$/i', $interpretThis) || preg_match('/^false$/', $interpretThis) || preg_match("/^[tf]$/", $interpretThis)) { - if(preg_match('/^true$/i', $interpretThis) || preg_match('/^t$/', $interpretThis)) { - $index=1; - } - else { - $index=0; - } - } - else { - //straight-up PHP if/else evaluation. - if($interpretThis) { - $index=1; - } - else { - $index=0; - } - } - - return($realVals[$index]); - }//end interpret_bool() - //########################################################################## }//end cs_globalFunctions{} Deleted: trunk/0.10/cs_siteConfig.class.php =================================================================== --- trunk/0.10/cs_siteConfig.class.php 2009-01-26 01:29:21 UTC (rev 324) +++ trunk/0.10/cs_siteConfig.class.php 2009-01-26 01:33:48 UTC (rev 325) @@ -1,307 +0,0 @@ -<?php - -/* - * A class for handling configuration of database-driven web applications. - * - * NOTICE::: this class requires that cs-phpxml and cs-arraytopath are both available - * at the same directory level as cs-content; all projects are SourceForge.net projects, - * using their unix names ("cs-phpxml" and "cs-arrayToPath"). The cs-phpxml project - * requires cs-arrayToPath for parsing XML paths. - * - * SVN INFORMATION::: - * SVN Signature:::::::: $Id$ - * Last Committted Date: $Date$ - * Last Committed Path:: $HeadURL$ - * - */ - -require_once(dirname(__FILE__) .'/cs_globalFunctions.php'); -require_once(dirname(__FILE__) .'/cs_fileSystemClass.php'); -require_once(dirname(__FILE__). '/../cs-phpxml/cs_phpxmlParser.class.php'); -require_once(dirname(__FILE__) .'/../cs-phpxml/cs_phpxmlBuilder.class.php'); - -class cs_siteConfig { - - /** XMLParser{} object, for reading XML config file. */ - private $xmlReader; - - /** cs_fileSystemClass{} object, for writing/updating XML config file - * (only available if file is writable) - */ - private $xmlWriter; - - /** XMLBuilder{} object, for updating XML. */ - private $xmlBuilder; - - /** cs_fileSystemClass{} object, for handling generic file operations (i.e. reading) */ - private $fs; - - /** boolean flag indicating if the given config file is readOnly (false=read/write) */ - private $readOnly; - - /** Directory for the config file. */ - private $configDirname; - - /** Active section of the full site configuration. */ - private $activeSection; - - /** The FULL configuration file, instead of just the active section. */ - private $fullConfig=array(); - - /** cs_arrayToPath{} object. */ - private $a2p; - - /** Prefix to add to every index in GLOBALS and CONSTANTS. */ - private $setVarPrefix; - - /** Sections available within the config */ - private $configSections=array(); - - /** Boolean flag to determine if the object has been properly initialized or not. */ - private $isInitialized=false; - - - //------------------------------------------------------------------------- - /** - * Constructor. - * - * @param $configFileLocation (str) URI for config file. - * @param $section (str,optional) set active section (default=MAIN) - * @param $setVarPrefix (str,optional) prefix to add to all global & constant names. - * - * @return NULL (PASS) object successfully created - * @return exception (FAIL) failed to create object (see exception message) - */ - public function __construct($configFileLocation, $section='MAIN', $setVarPrefix=null) { - - $section = strtoupper($section); - $this->setVarPrefix=$setVarPrefix; - - $this->gf = new cs_globalFunctions; - $this->gf->debugPrintOpt=1; - - if(strlen($configFileLocation) && file_exists($configFileLocation)) { - - $this->configDirname = dirname($configFileLocation); - $this->fs = new cs_fileSystemClass($this->configDirname); - - $this->xmlReader = new cs_phpxmlParser($this->fs->read($configFileLocation)); - - if($this->fs->is_writable($configFileLocation)) { - $this->readOnly = false; - $this->xmlWriter = new cs_fileSystemClass($this->configDirname); - - } - else { - $this->readOnly = true; - } - } - else { - throw new exception(__METHOD__ .": invalid configuration file (". $configFileLocation .")"); - } - - if(strlen($section)) { - try { - $this->parse_config(); - $this->set_active_section($section); - $this->config = $this->get_section($section); - } - catch(exception $e) { - throw new exception(__METHOD__ .": invalid section (". $section ."), DETAILS::: ". $e->getMessage()); - } - } - else { - throw new exception(__METHOD__ .": no section given (". $section .")"); - } - - }//end __construct() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Sets the active section. - * - * @param $section (str) section to be set as active. - * - * @return VOID (PASS) section was set successfully. - * @return exception (FAIL) problem encountred setting section. - */ - public function set_active_section($section) { - if($this->isInitialized === true) { - $section = strtoupper($section); - if(in_array($section, $this->configSections)) { - $this->activeSection = $section; - } - else { - throw new exception(__METHOD__ .": invalid section (". $section .")"); - } - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - }//end set_active_section($section) - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Parse the configuration file. Handles replacing {VARIABLES} in values, - * sets items as global or as constants, and creates array indicating the - * available sections from the config file. - * - * @param VOID (void) no arguments accepted. - * - * @return NULL (PASS) successfully parsed configuration - * @return exception (FAIL) exception indicates problem encountered. - */ - private function parse_config() { - if(is_object($this->xmlReader)) { - $data = $this->xmlReader->get_path($this->xmlReader->get_root_element()); - - $specialVars = array( - '_DIRNAMEOFFILE_' => $this->configDirname - ); - $parseThis = array(); - - - $this->configSections = array(); - - foreach($data as $section=>$secData) { - //only handle UPPERCASE index names; lowercase indexes are special entries (i.e. "type" or "attributes" - if($section == strtoupper($section)) { - $this->configSections[] = $section; - foreach($secData as $itemName=>$itemValue) { - $attribs = array(); - if(is_array($itemValue['attributes'])) { - $attribs = $itemValue['attributes']; - } - $itemValue = $itemValue['value']; - if(preg_match("/{/", $itemValue)) { - $origVal = $itemValue; - $itemValue = $this->gf->mini_parser($itemValue, $specialVars, '{', '}'); - $itemValue = $this->gf->mini_parser($itemValue, $parseThis, '{', '}'); - $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue); - } - - if($attribs['CLEANPATH']) { - $itemValue = $this->fs->resolve_path_with_dots($itemValue); - } - - $parseThis[$itemName] = $itemValue; - $parseThis[$section ."/". $itemName] = $itemValue; - $data[$section][$itemName]['value'] = $itemValue; - - $setVarIndex = $this->setVarPrefix . $itemName; - if($attribs['SETGLOBAL']) { - $GLOBALS[$setVarIndex] = $itemValue; - } - if($attribs['SETCONSTANT']) { - define($setVarIndex, $itemValue); - } - } - } - } - $this->a2p = new cs_arrayToPath($data); - $this->isInitialized=true; - } - else { - throw new exception(__METHOD__ .": xmlReader not created, object probably not initialized"); - } - }//end parse_config() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Retrieve all data about the given section. - * - * @param $section (str) section to retrieve. - * - * @return array (PASS) array contains section data. - * @return exception (FAIL) exception indicates problem. - */ - public function get_section($section) { - if($this->isInitialized === true) { - $data = $this->a2p->get_data($section); - - if(is_array($data) && count($data) && $data['type'] == 'open') { - unset($data['type']); - $retval = $data; - } - else { - throw new exception(__METHOD__ .": invalid section or no data (". $data['type'] .")"); - } - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - - return($retval); - }//end get_section() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Retrieves value from the active section, or from another (other sections - * specified like "SECTION/INDEX"). - * - * @param $index (str) index name of value to retrieve. - * - * @return mixed (PASS) returns value of given index. - * - * NOTE::: this will return NULL if the given index or section/index does - * not exist. - */ - public function get_value($index) { - if($this->isInitialized === true) { - if(preg_match("/\//", $index)) { - //section NOT given, assume they're looking for something in the active section. - $index = $this->activeSection ."/". $index; - } - $retval = $this->a2p->get_data($index .'/value'); - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - return($retval); - }//end get_value() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Retrieves list of valid configuration sections, as defined by - * parse_config(). - * - * @param VOID (void) no parameters accepted. - * - * @return array (PASS) array holds list of valid sections. - * @return exception (FAIL) exception gives error. - */ - public function get_valid_sections() { - if($this->isInitialized === true) { - if(is_array($this->configSections) && count($this->configSections)) { - $retval = $this->configSections; - } - else { - throw new exception(__METHOD__ .": no sections defined, probably invalid configuration"); - } - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - - return($retval); - }//end get_valid_sections() - //------------------------------------------------------------------------- - -}//end cs_siteConfig - -?> Modified: trunk/0.10/db_types/cs_phpDB__pgsql.class.php =================================================================== --- trunk/0.10/db_types/cs_phpDB__pgsql.class.php 2009-01-26 01:29:21 UTC (rev 324) +++ trunk/0.10/db_types/cs_phpDB__pgsql.class.php 2009-01-26 01:33:48 UTC (rev 325) @@ -136,7 +136,7 @@ $requiredCount = 0; foreach($required as $index) { - if(isset($params[$index]) || $index == 'password') { + if(isset($params[$index])) { $this->$index = $params[$index]; $requiredCount++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |