[Cs-content-commits] SF.net SVN: cs-content:[313] trunk/0.10/cs_globalFunctions.php
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-01-14 02:43:53
|
Revision: 313 http://cs-content.svn.sourceforge.net/cs-content/?rev=313&view=rev Author: crazedsanity Date: 2009-01-14 02:43:38 +0000 (Wed, 14 Jan 2009) Log Message: ----------- Fix cleanString() and some minor tweaks & comment updates. /cs_globalFunctions.php: * switch_force_sql_quotes(): -- remove some debug_print statements -- fix ending comment so it indicates the actual name of the method * cleanString(): -- fixed "query" case so it strips single quotes. -- fixed comment in "name/names" case -- fixed "bool/boolean" case to use internal interpret_bool() method * interpret_bool() [NEW]: -- interprets data as boolean, and can specify return values for true or false -- NOTE: this has always been required for the "bool/boolean" cleaning style from cleanString(), but no tests were performed to ensure that it actually worked (until now, though they're not included yet). Modified Paths: -------------- trunk/0.10/cs_globalFunctions.php Modified: trunk/0.10/cs_globalFunctions.php =================================================================== --- trunk/0.10/cs_globalFunctions.php 2009-01-08 18:48:49 UTC (rev 312) +++ trunk/0.10/cs_globalFunctions.php 2009-01-14 02:43:38 UTC (rev 313) @@ -62,15 +62,13 @@ $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 force_sql_quotes() + }//end switch_force_sql_quotes() //========================================================================= @@ -382,6 +380,7 @@ */ $evilChars = array("\$", "%", "~", "*",">", "<", "-", "{", "}", "[", "]", ")", "(", "&", "#", "?", ".", "\,","\/","\\","\"","\|","!","^","+","`","\n","\r"); $cleanThis = preg_replace("/\|/","",$cleanThis); + $cleanThis = preg_replace("/\'/", "", $cleanThis); $cleanThis = str_replace($evilChars,"", $cleanThis); $cleanThis = stripslashes(addslashes($cleanThis)); break; @@ -520,7 +519,7 @@ case "name": case "names": - //removes everything in the "alpha" case, but allows "'". + //allows only things in the "alpha" case and single quotes. $cleanThis = preg_replace("/[^a-zA-Z']/", "", $cleanThis); break; @@ -532,7 +531,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 = interpret_bool($cleanThis, array('f', 't')); + $cleanThis = $this->interpret_bool($cleanThis, array('f', 't')); break; case "varchar": @@ -778,6 +777,67 @@ 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{} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |