cs-content-commits Mailing List for CS-Content [Dynamic Content System] (Page 4)
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...> - 2009-08-14 16:37:00
|
Revision: 437 http://cs-content.svn.sourceforge.net/cs-content/?rev=437&view=rev Author: crazedsanity Date: 2009-08-14 16:36:52 +0000 (Fri, 14 Aug 2009) Log Message: ----------- Minor comment & superficial changes, test file (no tests yet) for cs_fileSystem{} Modified Paths: -------------- trunk/1.0/tests/testOfCSGlobalFunctions.php trunk/1.0/tests/testOfCSPHPDB.php Added Paths: ----------- trunk/1.0/tests/testOfCSFileSystem.php Copied: trunk/1.0/tests/testOfCSFileSystem.php (from rev 436, trunk/1.0/tests/testOfCSGlobalFunctions.php) =================================================================== --- trunk/1.0/tests/testOfCSFileSystem.php (rev 0) +++ trunk/1.0/tests/testOfCSFileSystem.php 2009-08-14 16:36:52 UTC (rev 437) @@ -0,0 +1,42 @@ +<?php +/* + * Created on Jan 13, 2009 + * + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + + + +//============================================================================= +class TestOfCSFileSystem extends UnitTestCase { + + //------------------------------------------------------------------------- + function __construct() { + require_once(dirname(__FILE__) .'/../cs_globalFunctions.class.php'); + require_once(dirname(__FILE__) .'/../cs_fileSystem.class.php'); + + $this->gfObj = new cs_globalFunctions; + $this->gfObj->debugPrintOpt=1; + + $filesDir = dirname(__FILE__) ."/files"; + define('TEST_FILESDIR', $filesDir); + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + + + +}//end TestOfCSFileSystem +//============================================================================= +?> Modified: trunk/1.0/tests/testOfCSGlobalFunctions.php =================================================================== --- trunk/1.0/tests/testOfCSGlobalFunctions.php 2009-08-14 16:04:18 UTC (rev 436) +++ trunk/1.0/tests/testOfCSGlobalFunctions.php 2009-08-14 16:36:52 UTC (rev 437) @@ -402,6 +402,6 @@ -}//end TestOfCSContent +}//end TestOfCSGlobalFunctions //============================================================================= ?> Modified: trunk/1.0/tests/testOfCSPHPDB.php =================================================================== --- trunk/1.0/tests/testOfCSPHPDB.php 2009-08-14 16:04:18 UTC (rev 436) +++ trunk/1.0/tests/testOfCSPHPDB.php 2009-08-14 16:36:52 UTC (rev 437) @@ -154,9 +154,5 @@ //------------------------------------------------------------------------- - - - - } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-14 16:04:27
|
Revision: 436 http://cs-content.svn.sourceforge.net/cs-content/?rev=436&view=rev Author: crazedsanity Date: 2009-08-14 16:04:18 +0000 (Fri, 14 Aug 2009) Log Message: ----------- More tests to make sure stuff works as expected (and continues to do so). /tests/testOfCSGlobalFunctions.php: * test_interpret_bool(): -- added a couple of more tests at the end to make sure it interprets the initial boolean(true) correctly. * test_mini_parser() [NEW]: -- puts cs_globalFunctions::mini_parser() through its paces * test_truncate_string() [NEW]: -- puts cs_globalFunctions::truncate_string() through its paces. * test_create_list() [NEW]: -- puts cs_globalFunctions::create_list() through a few paces... -- NOTE::: the tested method is VERY important to other classes, specifically cs_fileSystem{}. Modified Paths: -------------- trunk/1.0/tests/testOfCSGlobalFunctions.php Modified: trunk/1.0/tests/testOfCSGlobalFunctions.php =================================================================== --- trunk/1.0/tests/testOfCSGlobalFunctions.php 2009-08-13 18:57:31 UTC (rev 435) +++ trunk/1.0/tests/testOfCSGlobalFunctions.php 2009-08-14 16:04:18 UTC (rev 436) @@ -238,12 +238,170 @@ //now go through the same thing, but this time tell it to give back a specific value for true and false. $this->assertEqual($gf->interpret_bool(false, array(0=>'FaLSe',1=>"crap")), 'FaLSe'); + $this->assertEqual($gf->interpret_bool(true, array(0=>'FaLSe',1=>"crap")), 'crap'); $this->assertEqual($gf->interpret_bool(false, array(0=>"crap",1=>'FaLSe')), 'crap'); + $this->assertEqual($gf->interpret_bool(true, array(0=>"crap",1=>'FaLSe')), 'FaLSe'); }//end test_interpret_bool() //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + function test_mini_parser() { + + $gf = new cs_globalFunctions; + + //Basic test. + { + $stringToChange = '{{random-{number}-item}} {test}'; + $arrayOfVars = array( + 'number' => 5, + 'random-5-item' => "test", + 'test' => "SUCCESS" + ); + $expectedOutput = 'SUCCESS SUCCESS'; + $actualOutput = $gf->mini_parser($stringToChange, $arrayOfVars, '{', '}'); + $this->assertEqual($expectedOutput, $actualOutput); + } + + //Order of operations test. + { + $stringToChange = '{{random-{number}-item}} {test}'; + $arrayOfVars = array( + 'random-5-item' => "test", + 'number' => 5, + 'test' => "SUCCESS" + ); + $expectedOutput = '{{random-5-item}} SUCCESS'; + $actualOutput = $gf->mini_parser($stringToChange, $arrayOfVars, '{', '}'); + $this->assertEqual($expectedOutput, $actualOutput); + + //if we put that same actualOutput through the ringer again, it comes up with the originally expected output. + $expectedOutput = "SUCCESS SUCCESS"; + $actualOutput = $gf->mini_parser($actualOutput, $arrayOfVars, '{', '}'); + $this->assertEqual($expectedOutput, $actualOutput); + } + + //some testing with the default begin/end strings. + { + $stringToChange = '%%%%random-%%number%%-item%%%% %%test%%'; + $arrayOfVars = array( + 'number' => 5, + 'random-5-item' => "test", + 'test' => "SUCCESS" + ); + $expectedOutput = 'SUCCESS SUCCESS'; + $actualOutput = $gf->mini_parser($stringToChange, $arrayOfVars); + $this->assertEqual($expectedOutput, $actualOutput); + } + + //A stupid test to make sure we can specify different begin/end var identifiers. + + { + $stringToChange = '__BEGIN____BEGIN__random-__BEGIN__number__END__-item__END____END__ __BEGIN__test__END__'; + $arrayOfVars = array( + 'number' => 5, + 'random-5-item' => "test", + 'test' => "SUCCESS" + ); + $expectedOutput = 'SUCCESS SUCCESS'; + $actualOutput = $gf->mini_parser($stringToChange, $arrayOfVars, '__BEGIN__', '__END__'); + $this->assertEqual($expectedOutput, $actualOutput); + } + + }//end test_mini_parser() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function test_truncate_string() { + + $gf = new cs_globalFunctions; + + //basic test. + { + $length = 15; + $string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et mi scelerisque massa consequat adipiscing."; + $looseFinal = "Lorem ipsum dol..."; + $strictFinal= "Lorem ipsum ..."; + + $this->assertEqual($looseFinal, $gf->truncate_string($string, $length)); + $this->assertEqual($looseFinal, $gf->truncate_string($string, $length, '...')); + $this->assertEqual($looseFinal, $gf->truncate_string($string, $length, '...', false)); + $this->assertEqual($looseFinal, $gf->truncate_string($string, $length, '...', 0)); + $this->assertEqual($looseFinal, $gf->truncate_string($string, $length, '...', null)); + + + $this->assertEqual($strictFinal, $gf->truncate_string($string, $length, '...', true)); + $this->assertEqual($strictFinal, $gf->truncate_string($string, $length, '...', 1)); + $this->assertEqual($strictFinal, $gf->truncate_string($string, $length, '...', "Do it")); + + + $this->assertNotEqual($looseFinal, $gf->truncate_string($string, $length, '...', true)); + $this->assertNotEqual($looseFinal, $gf->truncate_string($string, $length, '...', 1)); + $this->assertNotEqual($looseFinal, $gf->truncate_string($string, $length, '...', "Do it")); + } + + //advanced test: give it a final length of *near* the length of the string & see what happens. + { + + $length = 56; + $string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + $string2= "Lorem ipsum dolor sit amet, consectetur adipiscing elit..."; + $string3= "Lorem ipsum dolor sit amet, consectetur adipiscing eli..."; + $string54= "Lorem ipsum dolor sit amet, consectetur adipiscing ..."; + $string55= "Lorem ipsum dolor sit amet, consectetur adipiscing e..."; + $string56= "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + + //make sure the initial string is ACTUALLY 56 characters long. + $this->assertEqual($length, strlen($string)); + + $this->assertEqual($string, $gf->truncate_string($string, 56, '...', false)); + $this->assertEqual($string2, $gf->truncate_string($string, 55, '...', false)); + $this->assertEqual($string3, $gf->truncate_string($string, 54, '...', false)); + + $this->assertEqual($string56, $gf->truncate_string($string, 56, '...', true)); + $this->assertEqual(56, strlen($gf->truncate_string($string, 56, '...', true))); + + $this->assertEqual($string55, $gf->truncate_string($string, 55, '...', true)); + $this->assertEqual(55, strlen($gf->truncate_string($string, 55, '...', true))); + + $this->assertEqual($string54, $gf->truncate_string($string, 54, '...', true)); + $this->assertEqual(54, strlen($gf->truncate_string($string, 54, '...', true))); + } + + }//end truncate_string() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function test_create_list() { + + $gf = new cs_globalFunctions; + + $items = array( + "", "one", "'TWO", "thr'ee", "four", "^five", "six'" + ); + $noSqlRes = "one, 'TWO, thr'ee, four, ^five, six'"; + $sqlRes = "'', 'one', ''TWO', 'thr'ee', 'four', '^five', 'six''"; + + $checkNoSql = null; + $checkSql = null; + foreach($items as $str) { + $checkNoSql = $gf->create_list($checkNoSql, $str, ", ", 0); + $checkSql = $gf->create_list($checkSql, $str, ", ", 1); + } + + $this->assertEqual($checkNoSql, $noSqlRes); + $this->assertEqual($checkSql, $sqlRes); + + }//end test_create_list() + //------------------------------------------------------------------------- + + + }//end TestOfCSContent //============================================================================= ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-13 18:57:39
|
Revision: 435 http://cs-content.svn.sourceforge.net/cs-content/?rev=435&view=rev Author: crazedsanity Date: 2009-08-13 18:57:31 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Fix cs_tabs{} so it doesn't require the page object. /contentSystem.class.php: * initialize_locals(): -- TODO about making the tabs object useable. -- don't pass any arguments to cs_tabs::__construct() /cs_tabs.class.php: * MAIN::: -- remove csPageObj -- add gfObj * __construct(): -- ARG CHANGE: ARG DELETED: #1 (cs_genericPage $csPageObj) -- ARG CHANGE: ARG SHIFTED: #2 ($templateVar="tabs" now #1) -- special check so calling code knows not to try to pass cs_genericPage as the first argument (the old code caused an error about an inability to convert the object to a string). -- create cs_globalFunctions object. * load_tabs_template() [DELETED]: -- no longer needed * display_tabs(): -- ARG CHANGE: NEW ARG: #1 (array $blockRows) -- Need to pass an array of block rows (i.e. using $page->templateRows) so the tabs can be built. -- remove call to non-existent function load_tabs_template() -- fix exception -- returns parsed tabs instead of trying to use cs_genericPage::add_template_var()... Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/cs_tabs.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-08-13 18:40:21 UTC (rev 434) +++ trunk/1.0/contentSystem.class.php 2009-08-13 18:57:31 UTC (rev 435) @@ -180,7 +180,8 @@ //create a tabs object, in case they want to load tabs on the page. - $this->tabs = new cs_tabs($this->templateObj); + //TODO: make the tabs object usable to included code! + $this->tabs = new cs_tabs(); //check versions, make sure they're all the same. $myVersion = $this->get_version(); Modified: trunk/1.0/cs_tabs.class.php =================================================================== --- trunk/1.0/cs_tabs.class.php 2009-08-13 18:40:21 UTC (rev 434) +++ trunk/1.0/cs_tabs.class.php 2009-08-13 18:57:31 UTC (rev 435) @@ -11,8 +11,8 @@ private $tabsArr=array(); private $selectedTab; - private $csPageObj; private $templateVar; + private $gfObj; /** This is the default suffix to use when none is given during the add_tab() call. */ private $defaultSuffix='tab'; @@ -24,19 +24,14 @@ * @param $csPageObj (object) Instance of the class "cs_genericPage". * @param $templateVar (str,optional) What template var to find the tab blockrows in. */ - public function __construct(cs_genericPage $csPageObj, $templateVar="tabs") { + public function __construct($templateVar="tabs") { parent::__construct(false); - if(is_null($csPageObj) || !is_object($csPageObj) || get_class($csPageObj) !== 'cs_genericPage') { - //can't continue without that! - throw new exception("cs_tabs::__construct(): cannot load without cs_genericPage{} object (". get_class($csPageObj) .")"); - } - else { - //set it as a member. - $this->csPageObj = $csPageObj; - } - - if(is_null($templateVar) || strlen($templateVar) < 3) { + if(is_object($templateVar)) { + //trying to pass cs_genericPage{}... tell 'em we don't like that anymore. + throw new exception(__METHOD__ .": got an object (". get_class($templateVar) .") instead of template var name"); + } + elseif(is_string($templateVar) && is_null($templateVar) || strlen($templateVar) < 3) { //no template name? AHH!!! throw new exception("cs_tabs::__construct(): failed to specify proper template file"); } @@ -44,33 +39,14 @@ //set the internal var. $this->templateVar = $templateVar; } + + $this->gfObj = new cs_globalFunctions; }//end __construct() //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- - /** - * Loads & parses the given tabs template. Requires that the given template has "selected_tab" - * and "unselected_tab" block row definitions. - * - * @param (void) - * @return (void) - */ - private function load_tabs_template() { - //now let's parse it for the proper block rows. - $blockRows = $this->csPageObj->rip_all_block_rows($this->templateVar); - - #if(count($blockRows) < 2) { - # //not enough blocks, or they're not properly named. - # throw new exception("cs_tabs::load_tabs_template(): failed to retrieve the required block rows"); - #} - }//end load_tabs_template() - //--------------------------------------------------------------------------------------------- - - - - //--------------------------------------------------------------------------------------------- public function add_tab_array(array $tabs, $useSuffix=null) { $retval = 0; foreach($tabs as $name=>$url) { @@ -120,7 +96,7 @@ /** * Call this to add the parsed tabs into the page. */ - public function display_tabs() { + public function display_tabs(array $blockRows) { if(!strlen($this->selectedTab)) { $keys = array_keys($this->tabsArr); @@ -128,7 +104,6 @@ } if(is_array($this->tabsArr) && count($this->tabsArr)) { - $this->load_tabs_template(); $finalString = ""; //loop through the array. foreach($this->tabsArr as $tabName=>$tabData) { @@ -141,11 +116,13 @@ $blockRowName = 'selected_'. $suffix; } - if(isset($this->csPageObj->templateRows[$blockRowName])) { - $useTabContent = $this->csPageObj->templateRows[$blockRowName]; + if(isset($blockRows[$blockRowName])) { + $useTabContent = $blockRows[$blockRowName]; } else { - throw new exception(__METHOD__ ."(): failed to load block row (". $blockRowName .") for tab (". $tabName .")". $this->csPageObj->gfObj->debug_print($this->csPageObj->templateRows,0)); + throw new exception(__METHOD__ ."(): failed to load block row " . + "(". $blockRowName .") for tab (". $tabName .")". + $this->gfObj->debug_print($blockRows,0)); } $parseThis = array( @@ -153,17 +130,15 @@ 'url' => $url, 'cleanTitle' => preg_replace('/[^a-zA-Z0-9]/', '_', $tabName) ); - $finalString .= $this->csPageObj->mini_parser($useTabContent, $parseThis, '%%', '%%'); + $finalString .= $this->gfObj->mini_parser($useTabContent, $parseThis, '%%', '%%'); } - - //now parse it onto the page. - $this->csPageObj->add_template_var($this->templateVar, $finalString); } else { //something bombed. throw new exception(__METHOD__ ."(): no tabs to add"); } + return($finalString); }//end display_tabs() //--------------------------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-13 18:40:32
|
Revision: 434 http://cs-content.svn.sourceforge.net/cs-content/?rev=434&view=rev Author: crazedsanity Date: 2009-08-13 18:40:21 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Initialize templateRows to avoid certain errors... Modified Paths: -------------- trunk/1.0/cs_genericPage.class.php Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2009-08-13 15:24:06 UTC (rev 433) +++ trunk/1.0/cs_genericPage.class.php 2009-08-13 18:40:21 UTC (rev 434) @@ -13,6 +13,7 @@ class cs_genericPage extends cs_contentAbstract { public $templateObj; //template object to parse the pages public $templateVars = array(); //our copy of the global templateVars + public $templateRows = array(); //array of block rows & their contents. public $mainTemplate; //the default layout of the site public $unhandledVars=array(); public $printOnFinish=true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-13 15:24:21
|
Revision: 433 http://cs-content.svn.sourceforge.net/cs-content/?rev=433&view=rev Author: crazedsanity Date: 2009-08-13 15:24:06 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Remove unused test SQL file (not sure what it was for anymore...) Removed Paths: ------------- trunk/1.0/tests/dbSchema/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-12 15:41:20
|
Revision: 432 http://cs-content.svn.sourceforge.net/cs-content/?rev=432&view=rev Author: crazedsanity Date: 2009-08-12 15:41:12 +0000 (Wed, 12 Aug 2009) Log Message: ----------- Cleanup some PHP errors/warnings. Modified Paths: -------------- trunk/1.0/cs_session.class.php Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2009-08-12 15:40:46 UTC (rev 431) +++ trunk/1.0/cs_session.class.php 2009-08-12 15:41:12 UTC (rev 432) @@ -40,7 +40,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']; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-12 15:40:55
|
Revision: 431 http://cs-content.svn.sourceforge.net/cs-content/?rev=431&view=rev Author: crazedsanity Date: 2009-08-12 15:40:46 +0000 (Wed, 12 Aug 2009) Log Message: ----------- Don't pass session object by reference, since it may be an overloaded object... Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-08-12 15:10:23 UTC (rev 430) +++ trunk/1.0/contentSystem.class.php 2009-08-12 15:40:46 UTC (rev 431) @@ -792,7 +792,7 @@ } if(isset($this->session) && is_object($this->session)) { - $page->session =& $this->session; + $page->session = $this->session; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-12 15:10:30
|
Revision: 430 http://cs-content.svn.sourceforge.net/cs-content/?rev=430&view=rev Author: crazedsanity Date: 2009-08-12 15:10:23 +0000 (Wed, 12 Aug 2009) Log Message: ----------- Fix PHP warnings involving array values & such. Modified Paths: -------------- trunk/1.0/cs_siteConfig.class.php Modified: trunk/1.0/cs_siteConfig.class.php =================================================================== --- trunk/1.0/cs_siteConfig.class.php 2009-08-11 18:53:21 UTC (rev 429) +++ trunk/1.0/cs_siteConfig.class.php 2009-08-12 15:10:23 UTC (rev 430) @@ -178,7 +178,7 @@ unset($secData['type']); - if(is_array($secData['attributes'])) { + if(isset($secData['attributes']) && is_array($secData['attributes'])) { $sectionAttribs = $secData['attributes']; unset($secData['attributes']); @@ -196,10 +196,15 @@ foreach($secData as $itemName=>$itemValue) { $attribs = array(); - if(is_array($itemValue['attributes'])) { + if(isset($itemValue['attributes']) && is_array($itemValue['attributes'])) { $attribs = $itemValue['attributes']; } - $itemValue = $itemValue['value']; + if(isset($itemValue['value'])) { + $itemValue = $itemValue['value']; + } + else { + $itemValue = null; + } if(preg_match("/{/", $itemValue)) { $origVal = $itemValue; @@ -239,7 +244,9 @@ $setVarIndex = $attribs['SETCONSTANTPREFIX'] ."-". $setVarIndex; } } - define($setVarIndex, $itemValue); + if(!defined($setVarIndex)) { + define($setVarIndex, $itemValue); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-11 18:53:28
|
Revision: 429 http://cs-content.svn.sourceforge.net/cs-content/?rev=429&view=rev Author: crazedsanity Date: 2009-08-11 18:53:21 +0000 (Tue, 11 Aug 2009) Log Message: ----------- Remove unnecessary logging. /cs_sessionDB.class.php: * REMOVE DEBUG LOGGING::: -- sessdb_open() -- sessdb_close() -- sessdb_write() Modified Paths: -------------- trunk/1.0/cs_sessionDB.class.php Modified: trunk/1.0/cs_sessionDB.class.php =================================================================== --- trunk/1.0/cs_sessionDB.class.php 2009-08-09 23:58:15 UTC (rev 428) +++ trunk/1.0/cs_sessionDB.class.php 2009-08-11 18:53:21 UTC (rev 429) @@ -152,7 +152,6 @@ * Open the session (doesn't really do anything) */ public function sessdb_open($savePath, $sessionName) { - $this->do_log("Request for new session, savePath=(". $savePath ."), sessionName=(". $sessionName .")", 'debug'); return(true); }//end sessdb_open() //------------------------------------------------------------------------- @@ -164,7 +163,6 @@ * Close the session (call the "gc" method) */ public function sessdb_close() { - $this->do_log("Request for session close", 'debug'); return($this->sessdb_gc(0)); }//end sessdb_close() //------------------------------------------------------------------------- @@ -239,7 +237,6 @@ try { $funcName = 'run_'. $type; $res = $this->db->$funcName($sql, $secondArg); - $this->do_log(__METHOD__ .": action=(". $type ."), result=(". $res .")", 'debug'); } catch(exception $e) { //umm... yeah. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-10 00:50:26
|
Revision: 428 http://cs-content.svn.sourceforge.net/cs-content/?rev=428&view=rev Author: crazedsanity Date: 2009-08-09 23:58:15 +0000 (Sun, 09 Aug 2009) Log Message: ----------- Fix issue caused by last fix. /contentSystem.class.php: * load_includes(): -- remove "/index" from the section if it exists. Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-08-09 23:20:09 UTC (rev 427) +++ trunk/1.0/contentSystem.class.php 2009-08-09 23:58:15 UTC (rev 428) @@ -669,7 +669,11 @@ } //include the final shared & index files. - if($this->incFs->cd('/'. $this->section)) { + $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'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-09 23:20:16
|
Revision: 427 http://cs-content.svn.sourceforge.net/cs-content/?rev=427&view=rev Author: crazedsanity Date: 2009-08-09 23:20:09 +0000 (Sun, 09 Aug 2009) Log Message: ----------- Fix inclusion of "index.inc" script. /contentSystem.class.php: * load_includes(): -- cd() into the full section, instead of using finalSection (which is sometimes blank, apparently). Modified Paths: -------------- trunk/1.0/contentSystem.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-08-09 22:18:34 UTC (rev 426) +++ trunk/1.0/contentSystem.class.php 2009-08-09 23:20:09 UTC (rev 427) @@ -669,7 +669,7 @@ } //include the final shared & index files. - if($this->incFs->cd($this->finalSection)) { + if($this->incFs->cd('/'. $this->section)) { $lsData = $this->incFs->ls(); if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { $this->add_include('shared.inc'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-09 22:18:41
|
Revision: 426 http://cs-content.svn.sourceforge.net/cs-content/?rev=426&view=rev Author: crazedsanity Date: 2009-08-09 22:18:34 +0000 (Sun, 09 Aug 2009) Log Message: ----------- Fix requirements & some errors. /cs_sessionDB.class.php: * MAIN::: -- require the cs_phpDB class file. * do_log(): -- don't create a log file anymore. Modified Paths: -------------- trunk/1.0/cs_sessionDB.class.php Modified: trunk/1.0/cs_sessionDB.class.php =================================================================== --- trunk/1.0/cs_sessionDB.class.php 2009-08-08 21:21:41 UTC (rev 425) +++ trunk/1.0/cs_sessionDB.class.php 2009-08-09 22:18:34 UTC (rev 426) @@ -9,6 +9,7 @@ */ require_once(dirname(__FILE__) .'/cs_session.class.php'); +require_once(dirname(__FILE__) .'/cs_phpDB.class.php'); require_once(constant('LIBDIR') .'/cs-phpxml/cs_arrayToPath.class.php'); require_once(constant('LIBDIR') .'/cs-webdblogger/cs_webdblogger.class.php'); @@ -341,15 +342,6 @@ $this->logger = new cs_webdblogger($newDB, $this->logCategory); } - $fs = new cs_fileSystem(constant('RWDIR')); - $logFile = 'session.log'; - if(!is_array($fs->ls($logFile))) { - $fs->create_file($logFile); - } - $fs->openFile($logFile); - $fs->append_to_file($this->logCategory .": ". $type ." -- ". $message); - - return($this->logger->log_by_class("SID=(". $this->sid .") -- ". $message,$type)); }//end do_log() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-08 21:21:49
|
Revision: 425 http://cs-content.svn.sourceforge.net/cs-content/?rev=425&view=rev Author: crazedsanity Date: 2009-08-08 21:21:41 +0000 (Sat, 08 Aug 2009) Log Message: ----------- Added logging with cs-webdblogger. /cs_sessionDB.class.php: * MAIN::: -- new vars for logger & logCategory * CALL EXCEPTION HANDLER FOR LOGGING ERRORS::: -- sessdb_table_exists() -- load_table() -- is_valid_sid() -- sessdb_read() -- sessdb_write() -- sessdb_gc() * DEBUG LOGGING::: -- sessdb_open() -- sessdb_close() -- sessdb_write() -- sessdb_destroy() (only when one gets destroyed) * sessdb_gc(): -- allow SESSION_MAX_TIME and SESSION_MAX_IDLE constants to define how long sessions will last. -- conditionally excludes the current session -- actually executes the delete statement, along with logging if something was deleted. * do_log() [NEW]: -- does generic logging * exception_handler() [NEW]: -- calls do_log() to log exceptions and optionally throwing them. Modified Paths: -------------- trunk/1.0/cs_sessionDB.class.php Modified: trunk/1.0/cs_sessionDB.class.php =================================================================== --- trunk/1.0/cs_sessionDB.class.php 2009-08-06 20:16:24 UTC (rev 424) +++ trunk/1.0/cs_sessionDB.class.php 2009-08-08 21:21:41 UTC (rev 425) @@ -10,11 +10,16 @@ require_once(dirname(__FILE__) .'/cs_session.class.php'); require_once(constant('LIBDIR') .'/cs-phpxml/cs_arrayToPath.class.php'); +require_once(constant('LIBDIR') .'/cs-webdblogger/cs_webdblogger.class.php'); class cs_sessionDB extends cs_session { protected $db; + protected $logger = null; + + protected $logCategory = "DB Sessions"; + //------------------------------------------------------------------------- /** * The constructor. @@ -82,6 +87,7 @@ $exists = true; } catch(exception $e) { + $this->exception_handler(__METHOD__ .": exception while trying to detect table::: ". $e->getMessage()); $exists = false; } @@ -99,16 +105,15 @@ $this->db->run_update(file_get_contents($filename),true); } catch(exception $e) { - throw new exception(__METHOD__ .": failed to load required table " . - "into your database automatically::: ". $e->getMessage()); + $this->exception_handler(__METHOD__ .": failed to load required table " . + "into your database automatically::: ". $e->getMessage(), true); } } else { - throw new exception(__METHOD__ .": while attempting to load required " . + $this->exception_handler(__METHOD__ .": while attempting to load required " . "table into your database, discovered you have a missing schema " . - "file (". $filename .")"); + "file (". $filename .")", true); } - $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); }//end load_table() //------------------------------------------------------------------------- @@ -127,7 +132,7 @@ $isValid = true; } elseif($numrows > 0 || $numrows < 0) { - throw new exception(__METHOD__ .": invalid numrows returned (". $numrows .")"); + $this->exception_handler(__METHOD__ .": invalid numrows returned (". $numrows .")",true); } } catch(exception $e) { @@ -146,6 +151,7 @@ * Open the session (doesn't really do anything) */ public function sessdb_open($savePath, $sessionName) { + $this->do_log("Request for new session, savePath=(". $savePath ."), sessionName=(". $sessionName .")", 'debug'); return(true); }//end sessdb_open() //------------------------------------------------------------------------- @@ -157,6 +163,7 @@ * Close the session (call the "gc" method) */ public function sessdb_close() { + $this->do_log("Request for session close", 'debug'); return($this->sessdb_gc(0)); }//end sessdb_close() //------------------------------------------------------------------------- @@ -181,6 +188,7 @@ } catch(exception $e) { //no throwing exceptions... + $this->exception_handler(__METHOD__ .": failed to read::: ". $e->getMessage()); } return($retval); }//end sessdb_read() @@ -230,9 +238,11 @@ try { $funcName = 'run_'. $type; $res = $this->db->$funcName($sql, $secondArg); + $this->do_log(__METHOD__ .": action=(". $type ."), result=(". $res .")", 'debug'); } catch(exception $e) { //umm... yeah. + $this->exception_handler(__METHOD__ .": failed to perform action (". $type .")::: ". $e->getMessage()); } return(true); @@ -245,7 +255,11 @@ public function sessdb_destroy($sid) { try { $sql = "DELETE FROM ". $this->tableName ." WHERE session_id='". $sid ."'"; - $this->db->run_update($sql, true); + $numDeleted = $this->db->run_update($sql, true); + + if($numDeleted > 0) { + $this->do_log("Destroyed session_id (". $sid .")", 'deleted'); + } } catch(exception $e) { //do... nothing? @@ -263,31 +277,96 @@ */ public function sessdb_gc($maxLifetime=null) { - $nowTime = date('Y-m-d H:i:s'); - if(is_null($maxLifetime) || !is_numeric($maxLifetime) || $maxLifetime < 0) { + $dateFormat = 'Y-m-d H:i:s'; + $strftimeFormat = '%Y-%m-%d %H:%M:%S'; + $nowTime = date($dateFormat); + $excludeCurrent = true; + if(defined('SESSION_MAX_TIME') || defined('SESSION_MAX_IDLE')) { + $maxFreshness = null; + if(defined('SESSION_MAX_TIME')) { + $date = strtotime('- '. constant('SESSION_MAX_TIME')); + $maxFreshness = "date_created < '". strftime($strftimeFormat, $date) ."'"; + $excludeCurrent=false; + } + if(defined('SESSION_MAX_IDLE')) { + + $date = strtotime('- '. constant('SESSION_MAX_IDLE')); + $addThis = "last_updated < '". strftime($strftimeFormat, $date) ."'"; + $maxFreshness = $this->gfObj->create_list($maxFreshness, $addThis, ' OR '); + } + } + elseif(is_null($maxLifetime) || !is_numeric($maxLifetime) || $maxLifetime <= 0) { //pull it from PHP's ini settings. $maxLifetime = ini_get("session.gc_maxlifetime"); + $interval = $maxLifetime .' seconds'; + + $dt1 = strtotime($nowTime .' - '. $interval); + $maxFreshness = "last_updated < '". date($dateFormat, $dt1) ."'"; } - $interval = $maxLifetime .' seconds'; - $dt1 = strtotime($nowTime .' - '. $interval); - $dt2 = date('Y-m-d H:i:s', $dt1); - try { //destroy old sessions, but don't complain if nothing is deleted. - $sql = "DELETE FROM ". $this->tableName ." WHERE last_updated < ". $dt2; - #$this->db->run_update($sql, true); + $sql = "DELETE FROM ". $this->tableName ." WHERE ". $maxFreshness; + if(strlen($this->sid) && $excludeCurrent === false) { + $sql .= " AND session_id != '". $this->sid ."'"; + } + $numCleaned = $this->db->run_update($sql, true); + + if($numCleaned > 0) { + $this->do_log("cleaned (". $numCleaned .") old sessions, " . + "excludeCurrent=(". $this->gfObj->interpret_bool($excludeCurrent) .")" . + ", maxFreshness=(". $maxFreshness .")", "debug"); + } } catch(exception $e) { - //probably should do something here. + $this->exception_handler(__METHOD__ .": exception while cleaning: ". $e->getMessage()); } return(true); }//end sessdb_gc() //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + protected function do_log($message, $type) { + + //check if the logger object has been created. + if(!is_object($this->logger)) { + $newDB = new cs_phpDB(constant('DBTYPE')); + $newDB->connect($this->db->connectParams, true); + $this->logger = new cs_webdblogger($newDB, $this->logCategory); + } + + $fs = new cs_fileSystem(constant('RWDIR')); + $logFile = 'session.log'; + if(!is_array($fs->ls($logFile))) { + $fs->create_file($logFile); + } + $fs->openFile($logFile); + $fs->append_to_file($this->logCategory .": ". $type ." -- ". $message); + + + return($this->logger->log_by_class("SID=(". $this->sid .") -- ". $message,$type)); + + }//end do_log() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + protected function exception_handler($message, $throwException=false) { + $logId = $this->do_log($message, 'exception in code'); + if($throwException === true) { + //in this class, it is mostly useless to throw exceptions, so by default they're not thrown. + throw new exception($message); + } + return($logId); + }//end exception_handler() + //------------------------------------------------------------------------- }//end cs_session{} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-06 20:16:37
|
Revision: 424 http://cs-content.svn.sourceforge.net/cs-content/?rev=424&view=rev Author: crazedsanity Date: 2009-08-06 20:16:24 +0000 (Thu, 06 Aug 2009) Log Message: ----------- *** RELEASE 1.0-ALPHA10 *** SUMMARY OF CHANGES::: * compatibility changes between pgsql & mysql layers * support in mysql layer for resetting connect * better transaction support in MySQL (with notes on caveats) * ability to change selected database on an open database connection in MySQL * generic methods in cs_phpDB for doing queries, updates, and inserts. * unit tests for database layers & cs_globalFunctions. * ability to ping db connection * cs_siteConfig has special var for its location & support for prefixes. * cs_tabs can use different templates + more vars parsed. * lots of fixes to remove/suppress PHP warnings * database storage of session info by setting constants! * conversion script to push content of session files into database. SVN COMMAND::: merge --depth=infinity -r393: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_globalFunctions.class.php releases/1.0/cs_phpDB.class.php releases/1.0/cs_session.class.php releases/1.0/cs_siteConfig.class.php releases/1.0/cs_tabs.class.php releases/1.0/db_types/cs_phpDB__mysql.class.php releases/1.0/db_types/cs_phpDB__pgsql.class.php releases/1.0/tests/testOfCSContent.php Added Paths: ----------- releases/1.0/cs_sessionDB.class.php releases/1.0/sample_files/bin/ releases/1.0/sample_files/bin/convertSessionFilesToDB.php releases/1.0/schema/ releases/1.0/schema/db_session_schema.mysql.sql releases/1.0/schema/db_session_schema.pgsql.sql releases/1.0/tests/dbSchema/ releases/1.0/tests/dbSchema/cs_content_test.mysql.sql releases/1.0/tests/testOfCSGlobalFunctions.php releases/1.0/tests/testOfCSPHPDB.php Removed Paths: ------------- releases/1.0/sample_files/bin/convertSessionFilesToDB.php releases/1.0/schema/db_session_schema.mysql.sql releases/1.0/schema/db_session_schema.pgsql.sql releases/1.0/tests/dbSchema/cs_content_test.mysql.sql Modified: releases/1.0/VERSION =================================================================== --- releases/1.0/VERSION 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/VERSION 2009-08-06 20:16:24 UTC (rev 424) @@ -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-ALPHA9 +VERSION: 1.0-ALPHA10 PROJECT: cs-content $HeadURL$ \ No newline at end of file Modified: releases/1.0/contentSystem.class.php =================================================================== --- releases/1.0/contentSystem.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/contentSystem.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -134,6 +134,14 @@ * Creates internal objects & prepares for later usage. */ private function initialize_locals() { + + //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); + } + //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(). Modified: releases/1.0/cs_fileSystem.class.php =================================================================== --- releases/1.0/cs_fileSystem.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/cs_fileSystem.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -195,17 +195,18 @@ */ public function get_fileinfo($tFile) { + //TODO: shouldn't require putting the "@" in front of these calls! $retval = array( - "size" => filesize($tFile), + "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) + "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) ); return($retval); Modified: releases/1.0/cs_globalFunctions.class.php =================================================================== --- releases/1.0/cs_globalFunctions.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/cs_globalFunctions.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -54,6 +54,9 @@ $newSetting = 0; } } + elseif(!is_bool($newSetting) && is_bool($this->oldForceSqlQuotes)) { + $newSetting = $this->oldForceSqlQuotes; + } else { throw new exception(__METHOD__ .": invalid new setting (". $newSetting .")"); } @@ -159,7 +162,6 @@ } //make sure $style is valid. - $typesArr = array("insert", "update"); $style = strtolower($style); if(is_array($array)) { @@ -191,14 +193,14 @@ foreach($array as $key=>$value) { @$tmp[0] = $this->create_list($tmp[0], $key); //clean the string, if required. - if($cleanString) { + if(is_null($value)) { + $value = "NULL"; + } + elseif($cleanString) { //make sure it's not full of poo... $value = $this->cleanString($value, "sql"); #$value = "'". $value ."'"; } - if((is_null($value)) OR ($value == "")) { - $value = "NULL"; - } @$tmp[1] = $this->create_list($tmp[1], $value, ",", 1); } @@ -219,10 +221,17 @@ if(($value === "NULL" || $value === NULL) && !$this->forceSqlQuotes) { $sqlQuotes = 0; } - if($cleanString && !preg_match('/^\'/',$value)) { + if($cleanString && !(preg_match('/^\'/',$value) && preg_match('/\'$/', $value))) { //make sure it doesn't have crap in it... $value = $this->cleanString($value, "sql",$sqlQuotes); } + if($value == "'") { + //Fix possible SQL-injection. + $value = "'\''"; + } + elseif(!strlen($value)) { + $value = "''"; + } $retval = $this->create_list($retval, $field . $separator . $value); } break; @@ -274,12 +283,12 @@ } if($cleanString) { //make sure it doesn't have crap in it... - $value = $this->cleanString($value, "sql"); + $value = $this->cleanString($value, "sql", $this->forceSqlQuotes); } - if(!is_numeric($value) && isset($separator)) { + if(isset($separator)) { $value = "'". $value ."'"; } - $retval = $this->create_list($retval, $field . $separator . $value, " $delimiter ", $this->forceSqlQuotes); + $retval = $this->create_list($retval, $field . $separator . $value, " $delimiter "); } } break; @@ -801,8 +810,12 @@ //now figure out the value to return. if(is_numeric($interpretThis)) { + if(preg_match('/\.[0-9]{1,}/', $interpretThis)) { + //if it is a decimal number, remove the dot (i.e. "0.000001" -> "0000001" -> 1) + $interpretThis = str_replace('.', '', $interpretThis); + } settype($interpretThis, 'integer'); - if($interpretThis == '0') { + if($interpretThis == 0) { $index=0; } else { Modified: releases/1.0/cs_phpDB.class.php =================================================================== --- releases/1.0/cs_phpDB.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/cs_phpDB.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -31,6 +31,7 @@ private $dbLayerObj; private $dbType; + public $connectParams = array(); //========================================================================= public function __construct($type='pgsql') { @@ -60,6 +61,10 @@ */ 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 { @@ -69,6 +74,124 @@ }//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-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/cs_session.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -13,12 +13,11 @@ class cs_session extends cs_contentAbstract { - protected $db; - public $uid; - public $sid; - public $sid_check = 1; + protected $uid; + protected $sid; + protected $sid_check = 1; - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * The constructor. * @@ -26,10 +25,10 @@ * this parameter is non-null and non-numeric, the value will be * used as the session name. */ - function __construct($createSession=1) { - parent::__construct(false); + function __construct($createSession=true) { + parent::__construct(true); if($createSession) { - if(!is_null($createSession) && strlen($createSession) && !is_numeric($createSession)) { + if(is_string($createSession) && strlen($createSession) >2) { session_name($createSession); } @@ -49,11 +48,11 @@ $this->sid = session_id(); }//end __construct() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Required method, so passing the object to contentSystem::handle_session() * will work properly. @@ -65,11 +64,11 @@ public function is_authenticated() { return(FALSE); }//end is_authenticated() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Retrieve data for an existing cookie. * @@ -85,11 +84,11 @@ } return($retval); }//end get_cookie() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Create a new cookie. * @@ -116,11 +115,11 @@ return($retval); }//end create_cookie() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Destroy (expire) an existing cookie. * @@ -138,7 +137,20 @@ } return($retval); }//end drop_cookie() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * PHP5 magic method for retrieving the value of internal vars; this allows + * code to find the value of these variables, but not modify them (modifying + * requires the "__set($var,$val)" method). + */ + public function __get($var) { + return($this->$var); + }//end __get() + //------------------------------------------------------------------------- }//end cs_session{} Copied: releases/1.0/cs_sessionDB.class.php (from rev 423, trunk/1.0/cs_sessionDB.class.php) =================================================================== --- releases/1.0/cs_sessionDB.class.php (rev 0) +++ releases/1.0/cs_sessionDB.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -0,0 +1,294 @@ +<?php +/* + * FILE INFORMATION: + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +require_once(dirname(__FILE__) .'/cs_session.class.php'); +require_once(constant('LIBDIR') .'/cs-phpxml/cs_arrayToPath.class.php'); + +class cs_sessionDB extends cs_session { + + protected $db; + + //------------------------------------------------------------------------- + /** + * The constructor. + * + * @param $createSession (mixed,optional) determines if a session will be started or not; if + * this parameter is non-null and non-numeric, the value will be + * used as the session name. + */ + function __construct() { + + + //map some constants to connection parameters. + //NOTE::: all constants should be prefixed... + $constantPrefix = 'SESSION_DB_'; + $params = array('host', 'port', 'dbname', 'user', 'password'); + foreach($params as $name) { + $value = null; + $constantName = $constantPrefix . strtoupper($name); + if(defined($constantName)) { + $value = constant($constantName); + } + $dbParams[$name] = $value; + } + $this->db = new cs_phpDB(constant('DBTYPE')); + $this->db->connect($dbParams); + + $this->tableName = 'cs_session_store_table'; + $this->tablePKey = 'session_store_id'; + $this->sequenceName = 'cs_session_store_table_session_store_id_seq'; + + if(!$this->sessdb_table_exists()) { + $this->load_table(); + } + + //now tell PHP to use this class's methods for saving the session. + session_set_save_handler( + array(&$this, 'sessdb_open'), + array(&$this, 'sessdb_close'), + array(&$this, 'sessdb_read'), + array(&$this, 'sessdb_write'), + array(&$this, 'sessdb_destroy'), + array(&$this, 'sessdb_gc') + ); + + parent::__construct(true); + + //Stop things from going into an audit log... see + //http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711/page3.html + // NOTE::: not sure if this is valid or not... + $this->audit_logging = false; + + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Determines if the appropriate table exists in the database. + */ + public function sessdb_table_exists() { + try { + $test = $this->db->run_query("SELECT * FROM ". $this->tableName . + " ORDER BY ". $this->tablePKey ." LIMIT 1"); + $exists = true; + } + catch(exception $e) { + $exists = false; + } + + return($exists); + }//end sessdb_table_exists() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function load_table() { + $filename = dirname(__FILE__) .'/schema/db_session_schema.'. $this->db->get_dbtype() .'.sql'; + if(file_exists($filename)) { + try { + $this->db->run_update(file_get_contents($filename),true); + } + catch(exception $e) { + throw new exception(__METHOD__ .": failed to load required table " . + "into your database automatically::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": while attempting to load required " . + "table into your database, discovered you have a missing schema " . + "file (". $filename .")"); + } + $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); + }//end load_table() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + protected function is_valid_sid($sid) { + $isValid = false; + if(strlen($sid) == 32) { + try { + $sql = "SELECT * FROM ". $this->tableName ." WHERE session_id='". + $sid ."'"; + $this->db->run_query($sql); + $numrows = $this->db->numRows(); + if($numrows == 1) { + $isValid = true; + } + elseif($numrows > 0 || $numrows < 0) { + throw new exception(__METHOD__ .": invalid numrows returned (". $numrows .")"); + } + } + catch(exception $e) { + //well... do nothing I guess. + } + } + + return($isValid); + }//end is_valid_sid() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Open the session (doesn't really do anything) + */ + public function sessdb_open($savePath, $sessionName) { + return(true); + }//end sessdb_open() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Close the session (call the "gc" method) + */ + public function sessdb_close() { + return($this->sessdb_gc(0)); + }//end sessdb_close() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Read information about the session. If there is no data, it MUST return + * an empty string instead of NULL. + */ + public function sessdb_read($sid) { + $retval = ''; + try { + $sql = "SELECT * FROM ". $this->tableName ." WHERE session_id='". + $sid ."'"; + $data = $this->db->run_query($sql); + + if($this->db->numRows() == 1) { + $retval = $data['session_data']; + } + } + catch(exception $e) { + //no throwing exceptions... + } + return($retval); + }//end sessdb_read() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function sessdb_write($sid, $data) { + $data = array( + 'session_data' => $data, + 'user_id' => null + ); + $cleanString = array( + 'session_data' => 'sql', + 'user_id' => 'numeric' + ); + + + + //pull the uid out of the session... + if(defined('SESSION_DBSAVE_UIDPATH')) { + $a2p = new cs_arrayToPath($_SESSION); + $uidVal = $a2p->get_data(constant('SESSION_DBSAVE_UIDPATH')); + + if(is_string($uidVal) || is_numeric($uidVal)) { + $data['user_id'] = $uidVal; + } + } + + $afterSql = ""; + if($this->is_valid_sid($sid)) { + $type = 'update'; + $sql = "UPDATE ". $this->tableName ." SET "; + $afterSql = "WHERE session_id='". $sid ."'"; + $data['last_updated'] = 'NOW()'; + $secondArg = false; + } + else { + $type = 'insert'; + $sql = "INSERT INTO ". $this->tableName ." "; + $data['session_id'] = $sid; + $secondArg = $this->sequenceName; + } + + $sql .= $this->gfObj->string_from_array($data, $type, null, $cleanString) .' '. $afterSql; + try { + $funcName = 'run_'. $type; + $res = $this->db->$funcName($sql, $secondArg); + } + catch(exception $e) { + //umm... yeah. + } + + return(true); + }//end sessdb_write() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function sessdb_destroy($sid) { + try { + $sql = "DELETE FROM ". $this->tableName ." WHERE session_id='". $sid ."'"; + $this->db->run_update($sql, true); + } + catch(exception $e) { + //do... nothing? + } + return(true); + }//end sessdb_destroy() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Define maximum lifetime (in seconds) to store sessions in the database. + * Anything that is older than that time will be purged (gc='garbage collector'). + */ + public function sessdb_gc($maxLifetime=null) { + + $nowTime = date('Y-m-d H:i:s'); + if(is_null($maxLifetime) || !is_numeric($maxLifetime) || $maxLifetime < 0) { + //pull it from PHP's ini settings. + $maxLifetime = ini_get("session.gc_maxlifetime"); + } + $interval = $maxLifetime .' seconds'; + + $dt1 = strtotime($nowTime .' - '. $interval); + $dt2 = date('Y-m-d H:i:s', $dt1); + + + + try { + //destroy old sessions, but don't complain if nothing is deleted. + $sql = "DELETE FROM ". $this->tableName ." WHERE last_updated < ". $dt2; + #$this->db->run_update($sql, true); + } + catch(exception $e) { + //probably should do something here. + } + + return(true); + + }//end sessdb_gc() + //------------------------------------------------------------------------- + + +}//end cs_session{} +?> \ No newline at end of file Modified: releases/1.0/cs_siteConfig.class.php =================================================================== --- releases/1.0/cs_siteConfig.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/cs_siteConfig.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -42,6 +42,9 @@ /** Directory for the config file. */ private $configDirname; + /** Location of the configuration file itself. */ + private $configFile; + /** Active section of the full site configuration. */ private $activeSection; @@ -84,6 +87,7 @@ if(strlen($configFileLocation) && file_exists($configFileLocation)) { $this->configDirname = dirname($configFileLocation); + $this->configFile = $configFileLocation; $this->fs = new cs_fileSystem($this->configDirname); $this->xmlReader = new cs_phpxmlParser($this->fs->read($configFileLocation)); @@ -212,7 +216,7 @@ $itemValue = $this->gfObj->mini_parser($itemValue, $parseThis, '{', '}'); } - if($attribs['CLEANPATH']) { + if(isset($attribs['CLEANPATH'])) { $itemValue = $this->fs->resolve_path_with_dots($itemValue); } @@ -221,10 +225,20 @@ $data[$section][$itemName]['value'] = $itemValue; $setVarIndex = $this->setVarPrefix . $itemName; - if($attribs['SETGLOBAL']) { + if(isset($attribs['SETGLOBAL'])) { $GLOBALS[$setVarIndex] = $itemValue; } - if($attribs['SETCONSTANT']) { + if(isset($attribs['SETCONSTANT'])) { + if(isset($attribs['SETCONSTANTPREFIX'])) { + //did they give a specific prefix, or just a number/true? + if(strlen($attribs['SETCONSTANTPREFIX']) == 1) { + $setVarIndex = $section ."-". $setVarIndex; + } + else { + //use the prefix they gave. + $setVarIndex = $attribs['SETCONSTANTPREFIX'] ."-". $setVarIndex; + } + } define($setVarIndex, $itemValue); } } @@ -277,7 +291,7 @@ $retval = $data; } else { - throw new exception(__METHOD__ .": invalid section or no data (". $data['type'] .")"); + throw new exception(__METHOD__ .": invalid section (". $section .") or no data (". $data['type'] .")"); } } else { @@ -370,6 +384,8 @@ $specialVars = array( '_DIRNAMEOFFILE_' => $this->configDirname, + '_CONFIGFILE_' => $this->configFile, + '_THISFILE_' => $this->configFile, '_APPURL_' => $appUrl ); return($specialVars); Modified: releases/1.0/cs_tabs.class.php =================================================================== --- releases/1.0/cs_tabs.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/cs_tabs.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -149,8 +149,9 @@ } $parseThis = array( - 'title' => $tabName, - 'url' => $url + 'title' => $tabName, + 'url' => $url, + 'cleanTitle' => preg_replace('/[^a-zA-Z0-9]/', '_', $tabName) ); $finalString .= $this->csPageObj->mini_parser($useTabContent, $parseThis, '%%', '%%'); } Modified: releases/1.0/db_types/cs_phpDB__mysql.class.php =================================================================== --- releases/1.0/db_types/cs_phpDB__mysql.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/db_types/cs_phpDB__mysql.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -129,7 +129,10 @@ $this->isConnected = FALSE; $retval = null; if($this->connectionID != -1) { - $retval = mysqlclose($this->connectionID); + $retval = mysql_close($this->connectionID); + $this->transStatus = null; + $this->inTrans=null; + $this->transactionTree=null; } else { throw new exception(__METHOD__ .": Failed to close connection: connection is invalid"); @@ -152,7 +155,7 @@ $this->set_db_info($dbParams); } - if($this->paramsAreSet === TRUE && $this->isConnected === FALSE) { + if($this->paramsAreSet === TRUE) { //start output buffer for displaying error. ob_start(); @@ -280,7 +283,15 @@ + //========================================================================= + public function ping() { + return(mysql_ping($this->connectionID)); + }//end ping() + //========================================================================= + + + //////////////////// // Cursor movement //////////////////// @@ -632,11 +643,10 @@ * Returns the number of rows in a result (from a SELECT query). */ function numRows() { - if ($this->result == null) { + if ($this->result == null || !is_resource($this->result)) { $retval = 0; } else { - //TODO: implement MySQL version.. $this->numrows = mysql_num_rows($this->result); $retval = $this->numrows; } @@ -667,7 +677,6 @@ $retval = 0; } else { - //TODO: implement MySQL version.. $retval = mysql_num_fields($this->result); } return($retval); @@ -689,9 +698,9 @@ * get last ID of last INSERT statement */ function lastID() { - $retval = mysql_insert_id(); + $retval = mysql_insert_id($this->connectionID); return($retval); - }//end lastOID() + }//end lastID() //========================================================================= @@ -769,6 +778,44 @@ + //========================================================================= + public function select_db($dbName) { + if(mysql_select_db($dbName, $this->connectionID)) { + $this->dbname = $dbName; + } + else { + throw new exception(__METHOD__ .": failed to select db (". $dbName .")"); + } + }//end select_db() + //========================================================================= + + + + //========================================================================= + public function beginTrans() { + $this->exec('BEGIN;SET autocommit=0;'); + return(true); + }//end beginTrans() + //========================================================================= + + + + //========================================================================= + public function commitTrans() { + $this->exec('COMMIT'); + return(true); + }//end commitTrans() + //========================================================================= + + + + //========================================================================= + public function rollbackTrans() { + $this->exec('ROLLBACK'); + return(true); + }//end rollbackTrans() + //========================================================================= + } // end class phpDB ?> Modified: releases/1.0/db_types/cs_phpDB__pgsql.class.php =================================================================== --- releases/1.0/db_types/cs_phpDB__pgsql.class.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/db_types/cs_phpDB__pgsql.class.php 2009-08-06 20:16:24 UTC (rev 424) @@ -305,7 +305,15 @@ + //========================================================================= + public function ping() { + return(pg_ping($this->connectionID)); + }//end ping() + //========================================================================= + + + //////////////////// // Cursor movement //////////////////// @@ -1115,6 +1123,22 @@ + //========================================================================= + public function lastID($sequence) { + + if(strlen($sequence)) { + $retval = $this->get_currval($sequence); + } + else { + throw new exception(__METHOD__ .": no sequence specified (required by ". $this->dbType .")"); + } + + return($retval); + }//end lastID() + //========================================================================= + + + } // end class phpDB ?> Deleted: releases/1.0/sample_files/bin/convertSessionFilesToDB.php =================================================================== --- trunk/1.0/sample_files/bin/convertSessionFilesToDB.php 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/sample_files/bin/convertSessionFilesToDB.php 2009-08-06 20:16:24 UTC (rev 424) @@ -1,156 +0,0 @@ -<?php -/* - * Created on Aug 6, 2009 - * - * SVN INFORMATION::: - * ------------------- - * Last Author::::::::: $Author$ - * Current Revision:::: $Revision$ - * Repository Location: $HeadURL$ - * Last Updated:::::::: $Date$ - */ - -require_once(dirname(__FILE__) .'/../../cs_fileSystem.class.php'); -require_once(dirname(__FILE__) .'/../../cs_siteConfig.class.php'); -require_once(dirname(__FILE__) .'/../../cs_phpDB.class.php'); - -$site = new cs_siteConfig(dirname(__FILE__) .'/../../../../rw/siteConfig.xml', 'website'); -require_once(dirname(__FILE__) .'/../../cs_sessionDB.class.php'); -#error_reporting(E_ALL); -require_once(constant('LIBDIR') .'/cs_debug.php'); - -class convertFiles extends cs_sessionDB { - - //------------------------------------------------------------------------- - public function __construct() { - $this->fs = new cs_fileSystem(constant('RWDIR') .'/tmp'); - parent::__construct(); - $this->gfObj->debugPrintOpt = 1; - }//end __construct() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function do_conversion() { - $files = $this->fs->ls(); - - $this->db->beginTrans(); - - $created = 0; - $skipped = 0; - $total = count($files); - $handled = 0; - - foreach($files as $filename=>$data) { - //get the file's contents... - $fData = $this->fs->read($filename); - - $sid = preg_replace('/^sess_/', '', $filename); - - print "Handling ". $filename ."... "; - - $data['accessed'] = strftime('%Y-%m-%d %H:%M:%S', $data['accessed']); - $data['modified'] = strftime('%Y-%m-%d %H:%M:%S', $data['modified']); - - $bits = explode('|', $fData); - $uid = null; - if(is_array($bits)) { - foreach($bits as $n=>$v) { - $check = unserialize($v); - if(is_array($check) && isset($check['userInfo'])) { - #$this->gfObj->debug_print($check); - $uid = $check['userInfo']['uid']; - #$this->gfObj->debug_print(__METHOD__ .": uid=(". $uid .")"); - break; - } - } - } - $insertData = array( - 'session_id' => $sid, - 'user_id' => $uid, - 'date_created' => $data['modified'], - 'last_updated' => $data['accessed'], - 'session_data' => $fData, - ); - if(!$this->check_sid_exists($sid)) { - $this->do_insert($insertData); - $created++; - } - else { - $skipped++; - } - $handled++; - - print " DONE (". $handled ." / ". $total .") SKIPPED=(". $skipped .") \r"; - - $this->db->commitTrans(); - } - }//end do_conversion() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - private function check_sid_exists($sid) { - $exists = false; - if(strlen($sid) == 32) { - $sql = "SELECT session_id FROM ". $this->tableName ." WHERE " . - "session_id='". $sid ."'"; - try { - $data = $this->db->run_query($sql); - $numrows = $this->db->numRows(); - if($numrows == 1) { - $exists = true; - } - elseif($numrows == 0) { - $exists = false; - } - else { - throw new exception(__METHOD__ .": invalid value of numrows (". $numrows .")"); - } - } - catch(exception $e) { - - } - } - else { - throw new exception(__METHOD__ .": invalid session id (". $sid .")"); - } - - return($exists); - }//end check_sid_exists() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - private function do_insert(array $data) { - $cleanString = array( - 'session_id' => 'sql', - 'user_id' => 'numeric', - 'date_created' => 'sql', - 'last_updated' => 'sql', - 'session_data' => 'sql' - ); - if(!is_numeric($data['user_id'])) { - unset($data['user_id']); - } - $sql = "INSERT INTO ". $this->tableName ." ". - $this->gfObj->string_from_array($data, 'insert', null, $cleanString); - - #$this->gfObj->debug_print($sql); - #$this->gfObj->debug_print($data); - $id = $this->db->run_insert($sql, $this->sequenceName); - - return($id); - }//end do_insert() - //------------------------------------------------------------------------- - -} - - -$obj = new convertFiles; -$obj->do_conversion(); - -?> Copied: releases/1.0/sample_files/bin/convertSessionFilesToDB.php (from rev 423, trunk/1.0/sample_files/bin/convertSessionFilesToDB.php) =================================================================== --- releases/1.0/sample_files/bin/convertSessionFilesToDB.php (rev 0) +++ releases/1.0/sample_files/bin/convertSessionFilesToDB.php 2009-08-06 20:16:24 UTC (rev 424) @@ -0,0 +1,156 @@ +<?php +/* + * Created on Aug 6, 2009 + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + +require_once(dirname(__FILE__) .'/../../cs_fileSystem.class.php'); +require_once(dirname(__FILE__) .'/../../cs_siteConfig.class.php'); +require_once(dirname(__FILE__) .'/../../cs_phpDB.class.php'); + +$site = new cs_siteConfig(dirname(__FILE__) .'/../../../../rw/siteConfig.xml', 'website'); +require_once(dirname(__FILE__) .'/../../cs_sessionDB.class.php'); +#error_reporting(E_ALL); +require_once(constant('LIBDIR') .'/cs_debug.php'); + +class convertFiles extends cs_sessionDB { + + //------------------------------------------------------------------------- + public function __construct() { + $this->fs = new cs_fileSystem(constant('RWDIR') .'/tmp'); + parent::__construct(); + $this->gfObj->debugPrintOpt = 1; + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function do_conversion() { + $files = $this->fs->ls(); + + $this->db->beginTrans(); + + $created = 0; + $skipped = 0; + $total = count($files); + $handled = 0; + + foreach($files as $filename=>$data) { + //get the file's contents... + $fData = $this->fs->read($filename); + + $sid = preg_replace('/^sess_/', '', $filename); + + print "Handling ". $filename ."... "; + + $data['accessed'] = strftime('%Y-%m-%d %H:%M:%S', $data['accessed']); + $data['modified'] = strftime('%Y-%m-%d %H:%M:%S', $data['modified']); + + $bits = explode('|', $fData); + $uid = null; + if(is_array($bits)) { + foreach($bits as $n=>$v) { + $check = unserialize($v); + if(is_array($check) && isset($check['userInfo'])) { + #$this->gfObj->debug_print($check); + $uid = $check['userInfo']['uid']; + #$this->gfObj->debug_print(__METHOD__ .": uid=(". $uid .")"); + break; + } + } + } + $insertData = array( + 'session_id' => $sid, + 'user_id' => $uid, + 'date_created' => $data['modified'], + 'last_updated' => $data['accessed'], + 'session_data' => $fData, + ); + if(!$this->check_sid_exists($sid)) { + $this->do_insert($insertData); + $created++; + } + else { + $skipped++; + } + $handled++; + + print " DONE (". $handled ." / ". $total .") SKIPPED=(". $skipped .") \r"; + + $this->db->commitTrans(); + } + }//end do_conversion() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function check_sid_exists($sid) { + $exists = false; + if(strlen($sid) == 32) { + $sql = "SELECT session_id FROM ". $this->tableName ." WHERE " . + "session_id='". $sid ."'"; + try { + $data = $this->db->run_query($sql); + $numrows = $this->db->numRows(); + if($numrows == 1) { + $exists = true; + } + elseif($numrows == 0) { + $exists = false; + } + else { + throw new exception(__METHOD__ .": invalid value of numrows (". $numrows .")"); + } + } + catch(exception $e) { + + } + } + else { + throw new exception(__METHOD__ .": invalid session id (". $sid .")"); + } + + return($exists); + }//end check_sid_exists() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function do_insert(array $data) { + $cleanString = array( + 'session_id' => 'sql', + 'user_id' => 'numeric', + 'date_created' => 'sql', + 'last_updated' => 'sql', + 'session_data' => 'sql' + ); + if(!is_numeric($data['user_id'])) { + unset($data['user_id']); + } + $sql = "INSERT INTO ". $this->tableName ." ". + $this->gfObj->string_from_array($data, 'insert', null, $cleanString); + + #$this->gfObj->debug_print($sql); + #$this->gfObj->debug_print($data); + $id = $this->db->run_insert($sql, $this->sequenceName); + + return($id); + }//end do_insert() + //------------------------------------------------------------------------- + +} + + +$obj = new convertFiles; +$obj->do_conversion(); + +?> Deleted: releases/1.0/schema/db_session_schema.mysql.sql =================================================================== --- trunk/1.0/schema/db_session_schema.mysql.sql 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/schema/db_session_schema.mysql.sql 2009-08-06 20:16:24 UTC (rev 424) @@ -1,17 +0,0 @@ - - --- --- Store session data in here. --- Idea originally from: http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711 --- - -CREATE TABLE `test`.`sess_tmp` ( - `session_store_id` int NOT NULL AUTO_INCREMENT, - `session_id` varchar(32) NOT NULL, - `user_id` varchar(16) NOT NULL, - `date_created` datetime NOT NULL, - `last_updated` datetime NOT NULL, - `session_data` LONGTEXT NOT NULL, - PRIMARY KEY (`session_store_id`) -) -ENGINE = MyISAM; \ No newline at end of file Copied: releases/1.0/schema/db_session_schema.mysql.sql (from rev 423, trunk/1.0/schema/db_session_schema.mysql.sql) =================================================================== --- releases/1.0/schema/db_session_schema.mysql.sql (rev 0) +++ releases/1.0/schema/db_session_schema.mysql.sql 2009-08-06 20:16:24 UTC (rev 424) @@ -0,0 +1,17 @@ + + +-- +-- Store session data in here. +-- Idea originally from: http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711 +-- + +CREATE TABLE `test`.`sess_tmp` ( + `session_store_id` int NOT NULL AUTO_INCREMENT, + `session_id` varchar(32) NOT NULL, + `user_id` varchar(16) NOT NULL, + `date_created` datetime NOT NULL, + `last_updated` datetime NOT NULL, + `session_data` LONGTEXT NOT NULL, + PRIMARY KEY (`session_store_id`) +) +ENGINE = MyISAM; \ No newline at end of file Deleted: releases/1.0/schema/db_session_schema.pgsql.sql =================================================================== --- trunk/1.0/schema/db_session_schema.pgsql.sql 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/schema/db_session_schema.pgsql.sql 2009-08-06 20:16:24 UTC (rev 424) @@ -1,16 +0,0 @@ - - --- --- Store session data in here. --- Idea originally from: http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711 --- - -CREATE TABLE cs_session_store_table ( - session_store_id serial NOT NULL PRIMARY KEY, - session_id varchar(32) NOT NULL DEFAULT '' UNIQUE, - user_id varchar(16), - date_created timestamp NOT NULL DEFAULT NOW(), - last_updated timestamp NOT NULL DEFAULT NOW(), - session_data text -); - Copied: releases/1.0/schema/db_session_schema.pgsql.sql (from rev 423, trunk/1.0/schema/db_session_schema.pgsql.sql) =================================================================== --- releases/1.0/schema/db_session_schema.pgsql.sql (rev 0) +++ releases/1.0/schema/db_session_schema.pgsql.sql 2009-08-06 20:16:24 UTC (rev 424) @@ -0,0 +1,16 @@ + + +-- +-- Store session data in here. +-- Idea originally from: http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711 +-- + +CREATE TABLE cs_session_store_table ( + session_store_id serial NOT NULL PRIMARY KEY, + session_id varchar(32) NOT NULL DEFAULT '' UNIQUE, + user_id varchar(16), + date_created timestamp NOT NULL DEFAULT NOW(), + last_updated timestamp NOT NULL DEFAULT NOW(), + session_data text +); + Deleted: releases/1.0/tests/dbSchema/cs_content_test.mysql.sql =================================================================== --- trunk/1.0/tests/dbSchema/cs_content_test.mysql.sql 2009-08-06 20:10:49 UTC (rev 423) +++ releases/1.0/tests/dbSchema/cs_content_test.mysql.sql 2009-08-06 20:16:24 UTC (rev 424) @@ -1,2328 +0,0 @@ --- MySQL Administrator dump 1.4 --- --- ------------------------------------------------------ --- Server version 5.0.75-0ubuntu10.2 - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; - -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; - - --- --- Create schema mysql --- - -CREATE DATABASE IF NOT EXISTS mysql; -USE mysql; - --- --- Definition of table `mysql`.`columns_priv` --- - -DROP TABLE IF EXISTS `mysql`.`columns_priv`; -CREATE TABLE `mysql`.`columns_priv` ( - `Host` char(60) collate utf8_bin NOT NULL default '', - `Db` char(64) collate utf8_bin NOT NULL default '', - `User` char(16) collate utf8_bin NOT NULL default '', - `Table_name` char(64) collate utf8_bin NOT NULL default '', - `Column_name` char(64) collate utf8_bin NOT NULL default '', - `Timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, - `Column_priv` set('Select','Insert','Update','References') character set utf8 NOT NULL default '', - PRIMARY KEY (`Host`,`Db`,`User`,`Table_name`,`Column_name`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Column privileges'; - --- --- Dumping data for table `mysql`.`columns_priv` --- - -/*!40000 ALTER TABLE `columns_priv` DISABLE KEYS */; -LOCK TABLES `columns_priv` WRITE; -UNLOCK TABLES; -/*!40000 ALTER TABLE `columns_priv` ENABLE KEYS */; - - --- --- Definition of table `mysql`.`db` --- - -DROP TABLE IF EXISTS `mysql`.`db`; -CREATE TABLE `mysql`.`db` ( - `Host` char(60) collate utf8_bin NOT NULL default '', - `Db` char(64) collate utf8_bin NOT NULL default '', - `User` char(16) collate utf8_bin NOT NULL default '', - `Select_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Insert_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Update_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Delete_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Create_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Drop_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Grant_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `References_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Index_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Alter_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Create_tmp_table_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Lock_tables_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Create_view_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Show_view_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Create_routine_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Alter_routine_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - `Execute_priv` enum('N','Y') character set utf8 NOT NULL default 'N', - PRIMARY KEY (`Host`,`Db`,`User`), - KEY `User` (`User`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Database privileges'; - --- --- Dumping data for table `mysql`.`db` --- - -/*!40000 ALTER TABLE `db` DISABLE KEYS */; -LOCK TABLES `db` WRITE; -INSERT INTO `mysql`.`db` VALUES (0x25,0x74657374,'','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N'), - (0x25,0x746573745C5F25,'','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N'), - (0x25,0x7265736F7572636572657175657374,0x63686174746572,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'), - (0x25,0x6D7973716C,0x63686174746572,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'), - (0x25,0x696E666F726D6174696F6E5F736368656D61,0x63686174746572,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'), - (0x25,0x63686174,0x63686174746572,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'), - (0x31302E25,0x7265736F7572636572657175657374,0x726F6F74,'Y','Y','Y','Y','N','N','N','N','N','N','N','Y','N','N','N','N','N'), - (0x3132372E302E302E31,0x7265736F7572636572657175657374,0x726F6F74,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'), - (0x6C6F63616C686F7374,0x7265736F7572636572657175657374,0x726F6F74,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'), - (0x736B6974746C6573,0x7265736F7572636572657175657374,0x726F6F74,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); -INSERT INTO `mysql`.`db` VALUES (0x25,0x7265736F7572636572657175657374,0x7265736F7572636572657175657374,'Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','N','N','N','N','N'), - (0x3132372E25,0x7265736F7572636572657175657374,0x7265736F7572636572657175657374,'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); -UNLOCK TABLES; -/*!40000 ALTER TABLE `db` ENABLE KEYS */; - - --- --- Definition of table `mysql`.`func` --- - -DROP TABLE IF EXISTS `mysql`.`func`; -CREATE TABLE `mysql`.`func` ( - `name` char(64) collate utf8_bin NOT NULL default '', - `ret` tinyint(1) NOT NULL default '0', - `dl` char(128) collate utf8_bin NOT NULL default '', - `type` enum('function','aggregate') character set utf8 NOT NULL, - PRIMARY KEY (`name`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='User defined functions'; - --- --- Dumping data for table `mysql`.`func` --- - -/*!40000 ALTER TABLE `func` DISABLE KEYS */; -LOCK TABLES `func` WRITE; -UNLOCK TABLES; -/*!40000 ALTER TABLE `func` ENABLE KEYS */; - - --- --- Definition of table `mysql`.`help_category` --- - -DROP TABLE IF EXISTS `mysql`.`help_category`; -CREATE TABLE `mysql`.`help_category` ( - `help_category_id` smallint(5) unsigned NOT NULL, - `name` char(64) NOT NULL, - `parent_category_id` smallint(5) unsigned default NULL, - `url` char(128) NOT NULL, - PRIMARY KEY (`help_category_id`), - UNIQUE KEY `name` (`name`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='help categories'; - --- --- Dumping data for table `mysql`.`help_category` --- - -/*!40000 ALTER TABLE `help_category` DISABLE KEYS */; -LOCK TABLES `help_category` WRITE; -INSERT INTO `mysql`.`help_category` VALUES (1,'Geographic',0,''), - (2,'Polygon properties',31,''), - (3,'WKT',31,''), - (4,'Numeric Functions',35,''), - (5,'MBR',31,''), - (6,'Control flow functions',35,''), - (7,'Transactions',32,''), - (8,'Account Management',32,''), - (9,'Point properties',31,''), - (10,'Encryption Functions',35,''), - (11,'LineString properties',31,''), - (12,'Logical operators',35,''), - (13,'Miscellaneous Functions',35,''), - (14,'Information Functions',35,''), - (15,'Functions and Modifiers for Use with GROUP BY',32,''), - (16,'Comparison operators',35,''), - (17,'Bit Functions',35,''), - (18,'Table Maintenance',32,''), - (19,'Data Types',32,''), - (20,'User-Defined Functions',32,''), - (21,'Compound Statements',32,''), - (22,'Geometry constructors',31,''), - (23,'GeometryCollection properties',1,''), - (24,'Administration',32,''), - (25,'Data Manipulation',32,''), - (26,'Utility',32,''), - (27,'Language Structure',32,''), - (28,'Geometry relations',31,''), - (29,'Date and Time Functions',35,''), - (30,'WKB',31,''); -INSERT INTO `mysql`.`help_category` VALUES (31,'Geographic Features',32,''), - (32,'Contents',0,''), - (33,'Geometry properties',31,''), - (34,'String Functions',35,''), - (35,'Functions',32,''), - (36,'Data Definition',32,''); -UNLOCK TABLES; -/*!40000 ALTER TABLE `help_category` ENABLE KEYS */; - - --- --- Definition of table `mysql`.`help_keyword` --- - -DROP TABLE IF EXISTS `mysql`.`help_keyword`; -CREATE TABLE `mysql`.`help_keyword` ( - `help_keyword_id` int(10) unsigned NOT NULL, - `name` char(64) NOT NULL, - PRIMARY KEY (`help_keyword_id`), - UNIQUE KEY `name` (`name`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='help keywords'; - --- --- Dumping data for table `mysql`.`help_keyword` --- - -/*!40000 ALTER TABLE `help_keyword` DISABLE KEYS */; -LOCK TABLES `help_keyword` WRITE; -INSERT INTO `mysql`.`help_keyword` VALUES (0,'JOIN'), - (1,'REPEAT'), - (2,'SERIALIZABLE'), - (3,'REPLACE'), - (4,'RETURNS'), - (5,'MASTER_SSL_CA'), - (6,'NCHAR'), - (7,'COLUMNS'), - (8,'WORK'), - (9,'DATETIME'), - (10,'MODE'), - (11,'OPEN'), - (12,'INTEGER'), - (13,'ESCAPE'), - (14,'VALUE'), - (15,'SQL_BIG_RESULT'), - (16,'DROP'), - (17,'GEOMETRYCOLLECTIONFROMWKB'), - (18,'EVENTS'), - (19,'MONTH'), - (20,'INFO'), - (21,'PROFILES'), - (22,'DUPLICATE'), - (23,'REPLICATION'), - (24,'UNLOCK'), - (25,'INNODB'), - (26,'YEAR_MONTH'), - (27,'SUBJECT'), - (28,'PREPARE'), - (29,'LOCK'), - (30,'NDB'), - (31,'CHECK'), - (32,'FULL'), - (33,'INT4'), - (34,'BY'), - (35,'NO'), - (36,'MINUTE'), - (37,'DATA'), - (38,'DAY'), - (39,'SHARE'), - (40,'REAL'), - (41,'SEPARATOR'), - (42,'DELETE'), - (43,'ON'), - (44,'CONNECTION'), - (45,'CLOSE'), - (46,'X509'), - (47,'USE'), - (48,'WHERE'), - (49,'PRIVILEGES'), - (50,'SPATIAL'), - (51,'SUPER'), - (52,'SQL_BUFFER_RESULT'), - (53,'IGNORE'), - (54,'QUICK'), - (55,'SIGNED'), - (56,'SECURITY'), - (57,'NDBCLUSTER'), - (58,'POLYGONFROMWKB'), - (59,'FALSE'); -INSERT INTO `mysql`.`help_keyword` VALUES (60,'LEVEL'), - (61,'FORCE'), - (62,'BINARY'), - (63,'TO'), - (64,'CHANGE'), - (65,'HOUR_MINUTE'), - (66,'UPDATE'), - (67,'INTO'), - (68,'FEDERATED'), - (69,'VARYING'), - (70,'HOUR_SECOND'), - (71,'VARIABLE'), - (72,'ROLLBACK'), - (73,'RTREE'), - (74,'PROCEDURE'), - (75,'TIMESTAMP'), - (76,'IMPORT'), - (77,'AGAINST'), - (78,'CHECKSUM'), - (79,'COUNT'), - (80,'LONGBINARY'), - (81,'THEN'), - (82,'INSERT'), - (83,'ENGINES'), - (84,'HANDLER'), - (85,'DAY_SECOND'), - (86,'EXISTS'), - (87,'MUTEX'), - (88,'RELEASE'), - (89,'BOOLEAN'), - (90,'MOD'), - (91,'DEFAULT'), - (92,'TYPE'), - (93,'NO_WRITE_TO_BINLOG'), - (94,'OPTIMIZE'), - (95,'RESET'), - (96,'ITERATE'), - (97,'DO'), - (98,'BIGINT'), - (99,'SET'), - (100,'ISSUER'), - (101,'DATE'), - (102,'STATUS'), - (103,'FULLTEXT'), - (104,'COMMENT'), - (105,'MASTER_CONNECT_RETRY'), - (106,'INNER'), - (107,'STOP'), - (108,'MASTER_LOG_FILE'), - (109,'MRG_MYISAM'), - (110,'PRECISION'), - (111,'REQUIRE'), - (112,'TRAILING'), - (113,'LONG'), - (114,'OPTION'), - (115,'ELSE'), - (116,'DEALLOCATE'); -INSERT INTO `mysql`.`help_keyword` VALUES (117,'IO_THREAD'), - (118,'CASE'), - (119,'CIPHER'), - (120,'CONTINUE'), - (121,'FROM'), - (122,'READ'), - (123,'LEFT'), - (124,'ELSEIF'), - (125,'MINUTE_SECOND'), - (126,'COMPACT'), - (127,'RESTORE'), - (128,'DEC'), - (129,'FOR'), - (130,'WARNINGS'), - (131,'MIN_ROWS'), - (132,'CONDITION'), - (133,'STRING'), - (134,'ENCLOSED'), - (135,'FUNCTION'), - (136,'AGGREGATE'), - (137,'FIELDS'), - (138,'INT3'), - (139,'ARCHIVE'), - (140,'AVG_ROW_LENGTH'), - (141,'ADD'), - (142,'KILL'), - (143,'FLOAT4'), - (144,'VIEW'), - (145,'REPEATABLE'), - (146,'INFILE'), - (147,'ORDER'), - (148,'USING'), - (149,'MIDDLEINT'), - (150,'GRANT'), - (151,'UNSIGNED'), - (152,'DECIMAL'), - (153,'GEOMETRYFROMTEXT'), - (154,'INDEXES'), - (155,'FOREIGN'), - (156,'CACHE'), - (157,'HOSTS'), - (158,'COMMIT'), - (159,'SCHEMAS'), - (160,'LEADING'), - (161,'SNAPSHOT'), - (162,'DECLARE'), - (163,'LOAD'), - (164,'SQL_CACHE'), - (165,'CONVERT'), - (166,'DYNAMIC'), - (167,'COLLATE'), - (168,'POLYGONFROMTEXT'), - (169,'BYTE'), - (170,'GLOBAL'), - (171,'LINESTRINGFROMWKB'); -INSERT INTO `mysql`.`help_keyword` VALUES (172,'BERKELEYDB'), - (173,'WHEN'), - (174,'HAVING'), - (175,'AS'), - (176,'STARTING'), - (177,'RELOAD'), - (178,'AUTOCOMMIT'), - (179,'REVOKE'), - (180,'GRANTS'), - (181,'OUTER'), - (182,'FLOOR'), - (183,'EXPLAIN'), - (184,'WITH'), - (185,'AFTER'), - (186,'STD'), - (187,'CSV'), - (188,'DISABLE'), - (189,'OUTFILE'), - (190,'LOW_PRIORITY'), - (191,'FILE'), - (192,'BDB'), - (193,'SCHEMA'), - (194,'SONAME'), - (195,'POW'), - (196,'MULTIPOINTFROMWKB'), - (197,'INDEX'), - (198,'DUAL'), - (199,'BACKUP'), - (200,'MULTIPOINTFROMTEXT'), - (201,'EXTENDED'), - (202,'MULTILINESTRINGFROMWKB'), - (203,'CROSS'), - (204,'NATIONAL'), - (205,'GROUP'), - (206,'SHA'), - (207,'UNDO'), - (208,'ZEROFILL'), - (209,'CLIENT'), - (210,'MASTER_PASSWORD'), - (211,'RELAY_LOG_FILE'), - (212,'TRUE'), - (213,'CHARACTER'), - (214,'MASTER_USER'), - (215,'TABLE'), - (216,'ENGINE'), - (217,'INSERT_METHOD'), - (218,'CASCADE'), - (219,'RELAY_LOG_POS'), - (220,'SQL_CALC_FOUND_ROWS'), - (221,'UNION'), - (222,'MYISAM'), - (223,'LEAVE'), - (224,'MODIFY'); -INSERT INTO `mysql`.`help_keyword` VALUES (225,'MATCH'), - (226,'MASTER_LOG_POS'), - (227,'DESC'), - (228,'DISTINCTROW'), - (229,'TIME'), - (230,'NUMERIC'), - (231,'EXPANSION'), - (232,'CURSOR'), - (233,'CODE'), - (234,'GEOMETRYCOLLECTIONFROMTEXT'), - (235,'CHAIN'), - (236,'FLUSH'), - (237,'CREATE'), - (238,'DESCRIBE'), - (239,'MAX_UPDATES_PER_HOUR'), - (240,'INT2'), - (241,'PROCESSLIST'), - (242,'LOGS'), - (243,'HEAP'), - (244,'SOUNDS'), - (245,'BETWEEN'), - (246,'REPAIR'), - (247,'MULTILINESTRINGFROMTEXT'), - (248,'PACK_KEYS'), - (249,'FAST'), - (250,'CALL'), - (251,'VALUES'), - (252,'LOOP'), - (253,'VARCHARACTER'), - (254,'BEFORE'), - (255,'TRUNCATE'), - (256,'SHOW'), - (257,'REDUNDANT'), - (258,'ALL'), - (259,'USER_RESOURCES'), - (260,'PARTIAL'), - (261,'BINLOG'), - (262,'END'), - (263,'SECOND'), - (264,'AND'), - (265,'FLOAT8'), - (266,'PREV'), - (267,'HOUR'), - (268,'SELECT'), - (269,'DATABASES'), - (270,'OR'), - (271,'IDENTIFIED'), - (272,'MASTER_SSL_CIPHER'), - (273,'SQL_SLAVE_SKIP_COUNTER'), - (274,'BOTH'), - (275,'BOOL'), - (276,'YEAR'), - (277,'MASTER_PORT'); -INSERT INTO `mysql`.`help_keyword` VALUES (278,'CONCURRENT'), - (279,'HELP'), - (280,'UNIQUE'), - (281,'TRIGGERS'), - (282,'PROCESS'), - (283,'CONSISTENT'), - (284,'MASTER_SSL'), - (285,'DATE_ADD'), - (286,'MAX_CONNECTIONS_PER_HOUR'), - (287,'LIKE'), - (288,'FETCH'), - (289,'IN'), - (290,'COLUMN'), - (291,'DUMPFILE'), - (292,'USAGE'), - (293,'EXECUTE'), - (294,'MEMORY'), - (295,'CEIL'), - (296,'QUERY'), - (297,'MASTER_HOST'), - (298,'LINES'), - (299,'SQL_THREAD'), - (300,'MAX_QUERIES_PER_HOUR'), - (301,'MASTER_SSL_CERT'), - (302,'MULTIPOLYGONFROMWKB'), - (303,'TRANSACTION'), - (304,'DAY_MINUTE'), - (305,'STDDEV'), - (306,'DATE_SUB'), - (307,'GEO... [truncated message content] |
From: <cra...@us...> - 2009-08-06 20:10:56
|
Revision: 423 http://cs-content.svn.sourceforge.net/cs-content/?rev=423&view=rev Author: crazedsanity Date: 2009-08-06 20:10:49 +0000 (Thu, 06 Aug 2009) Log Message: ----------- *** RELEASE 1.0-ALPHA10 *** SUMMARY OF CHANGES::: * compatibility changes between pgsql & mysql layers * support in mysql layer for resetting connect * better transaction support in MySQL (with notes on caveats) * ability to change selected database on an open database connection in MySQL * generic methods in cs_phpDB for doing queries, updates, and inserts. * unit tests for database layers & cs_globalFunctions. * ability to ping db connection * cs_siteConfig has special var for its location & support for prefixes. * cs_tabs can use different templates + more vars parsed. * lots of fixes to remove/suppress PHP warnings * database storage of session info by setting constants! * conversion script to push content of session files into database. Modified Paths: -------------- trunk/1.0/VERSION Modified: trunk/1.0/VERSION =================================================================== --- trunk/1.0/VERSION 2009-08-06 20:08:05 UTC (rev 422) +++ trunk/1.0/VERSION 2009-08-06 20:10:49 UTC (rev 423) @@ -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-ALPHA9 +VERSION: 1.0-ALPHA10 PROJECT: cs-content $HeadURL$ \ 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...> - 2009-08-06 20:08:12
|
Revision: 422 http://cs-content.svn.sourceforge.net/cs-content/?rev=422&view=rev Author: crazedsanity Date: 2009-08-06 20:08:05 +0000 (Thu, 06 Aug 2009) Log Message: ----------- Fix accidental code removal from last commit. /cs_sessionDB.class.php: * load_table(): -- re-added setting for $filename (otherwise it would always fail). Modified Paths: -------------- trunk/1.0/cs_sessionDB.class.php Property Changed: ---------------- trunk/1.0/cs_sessionDB.class.php Modified: trunk/1.0/cs_sessionDB.class.php =================================================================== --- trunk/1.0/cs_sessionDB.class.php 2009-08-06 19:38:47 UTC (rev 421) +++ trunk/1.0/cs_sessionDB.class.php 2009-08-06 20:08:05 UTC (rev 422) @@ -93,7 +93,7 @@ //------------------------------------------------------------------------- private function load_table() { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + $filename = dirname(__FILE__) .'/schema/db_session_schema.'. $this->db->get_dbtype() .'.sql'; if(file_exists($filename)) { try { $this->db->run_update(file_get_contents($filename),true); Property changes on: trunk/1.0/cs_sessionDB.class.php ___________________________________________________________________ Deleted: svn:mergeinfo - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-06 19:38:55
|
Revision: 421 http://cs-content.svn.sourceforge.net/cs-content/?rev=421&view=rev Author: crazedsanity Date: 2009-08-06 19:38:47 +0000 (Thu, 06 Aug 2009) Log Message: ----------- Allow prefixes to be automatically set when defining constants. cs_siteConfig.class.php: * parse_config(): -- add "isset()" for attribute checks to avoid PHP warnings -- when SETCONSTANT is an attribute, check if SETCONSTANTPREFIX is there so either a specific prefix can be set, or the section's name can be used as the prefix (separated by a "-"). -- NOTE::: when using a specific prefix, it is NOT uppercased. Modified Paths: -------------- trunk/1.0/cs_siteConfig.class.php Modified: trunk/1.0/cs_siteConfig.class.php =================================================================== --- trunk/1.0/cs_siteConfig.class.php 2009-08-06 17:05:18 UTC (rev 420) +++ trunk/1.0/cs_siteConfig.class.php 2009-08-06 19:38:47 UTC (rev 421) @@ -216,7 +216,7 @@ $itemValue = $this->gfObj->mini_parser($itemValue, $parseThis, '{', '}'); } - if($attribs['CLEANPATH']) { + if(isset($attribs['CLEANPATH'])) { $itemValue = $this->fs->resolve_path_with_dots($itemValue); } @@ -225,10 +225,20 @@ $data[$section][$itemName]['value'] = $itemValue; $setVarIndex = $this->setVarPrefix . $itemName; - if($attribs['SETGLOBAL']) { + if(isset($attribs['SETGLOBAL'])) { $GLOBALS[$setVarIndex] = $itemValue; } - if($attribs['SETCONSTANT']) { + if(isset($attribs['SETCONSTANT'])) { + if(isset($attribs['SETCONSTANTPREFIX'])) { + //did they give a specific prefix, or just a number/true? + if(strlen($attribs['SETCONSTANTPREFIX']) == 1) { + $setVarIndex = $section ."-". $setVarIndex; + } + else { + //use the prefix they gave. + $setVarIndex = $attribs['SETCONSTANTPREFIX'] ."-". $setVarIndex; + } + } define($setVarIndex, $itemValue); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-06 17:05:27
|
Revision: 420 http://cs-content.svn.sourceforge.net/cs-content/?rev=420&view=rev Author: crazedsanity Date: 2009-08-06 17:05:18 +0000 (Thu, 06 Aug 2009) Log Message: ----------- Script to push existing session data into a database. Added Paths: ----------- trunk/1.0/sample_files/bin/ trunk/1.0/sample_files/bin/convertSessionFilesToDB.php Added: trunk/1.0/sample_files/bin/convertSessionFilesToDB.php =================================================================== --- trunk/1.0/sample_files/bin/convertSessionFilesToDB.php (rev 0) +++ trunk/1.0/sample_files/bin/convertSessionFilesToDB.php 2009-08-06 17:05:18 UTC (rev 420) @@ -0,0 +1,156 @@ +<?php +/* + * Created on Aug 6, 2009 + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + +require_once(dirname(__FILE__) .'/../../cs_fileSystem.class.php'); +require_once(dirname(__FILE__) .'/../../cs_siteConfig.class.php'); +require_once(dirname(__FILE__) .'/../../cs_phpDB.class.php'); + +$site = new cs_siteConfig(dirname(__FILE__) .'/../../../../rw/siteConfig.xml', 'website'); +require_once(dirname(__FILE__) .'/../../cs_sessionDB.class.php'); +#error_reporting(E_ALL); +require_once(constant('LIBDIR') .'/cs_debug.php'); + +class convertFiles extends cs_sessionDB { + + //------------------------------------------------------------------------- + public function __construct() { + $this->fs = new cs_fileSystem(constant('RWDIR') .'/tmp'); + parent::__construct(); + $this->gfObj->debugPrintOpt = 1; + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function do_conversion() { + $files = $this->fs->ls(); + + $this->db->beginTrans(); + + $created = 0; + $skipped = 0; + $total = count($files); + $handled = 0; + + foreach($files as $filename=>$data) { + //get the file's contents... + $fData = $this->fs->read($filename); + + $sid = preg_replace('/^sess_/', '', $filename); + + print "Handling ". $filename ."... "; + + $data['accessed'] = strftime('%Y-%m-%d %H:%M:%S', $data['accessed']); + $data['modified'] = strftime('%Y-%m-%d %H:%M:%S', $data['modified']); + + $bits = explode('|', $fData); + $uid = null; + if(is_array($bits)) { + foreach($bits as $n=>$v) { + $check = unserialize($v); + if(is_array($check) && isset($check['userInfo'])) { + #$this->gfObj->debug_print($check); + $uid = $check['userInfo']['uid']; + #$this->gfObj->debug_print(__METHOD__ .": uid=(". $uid .")"); + break; + } + } + } + $insertData = array( + 'session_id' => $sid, + 'user_id' => $uid, + 'date_created' => $data['modified'], + 'last_updated' => $data['accessed'], + 'session_data' => $fData, + ); + if(!$this->check_sid_exists($sid)) { + $this->do_insert($insertData); + $created++; + } + else { + $skipped++; + } + $handled++; + + print " DONE (". $handled ." / ". $total .") SKIPPED=(". $skipped .") \r"; + + $this->db->commitTrans(); + } + }//end do_conversion() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function check_sid_exists($sid) { + $exists = false; + if(strlen($sid) == 32) { + $sql = "SELECT session_id FROM ". $this->tableName ." WHERE " . + "session_id='". $sid ."'"; + try { + $data = $this->db->run_query($sql); + $numrows = $this->db->numRows(); + if($numrows == 1) { + $exists = true; + } + elseif($numrows == 0) { + $exists = false; + } + else { + throw new exception(__METHOD__ .": invalid value of numrows (". $numrows .")"); + } + } + catch(exception $e) { + + } + } + else { + throw new exception(__METHOD__ .": invalid session id (". $sid .")"); + } + + return($exists); + }//end check_sid_exists() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function do_insert(array $data) { + $cleanString = array( + 'session_id' => 'sql', + 'user_id' => 'numeric', + 'date_created' => 'sql', + 'last_updated' => 'sql', + 'session_data' => 'sql' + ); + if(!is_numeric($data['user_id'])) { + unset($data['user_id']); + } + $sql = "INSERT INTO ". $this->tableName ." ". + $this->gfObj->string_from_array($data, 'insert', null, $cleanString); + + #$this->gfObj->debug_print($sql); + #$this->gfObj->debug_print($data); + $id = $this->db->run_insert($sql, $this->sequenceName); + + return($id); + }//end do_insert() + //------------------------------------------------------------------------- + +} + + +$obj = new convertFiles; +$obj->do_conversion(); + +?> Property changes on: trunk/1.0/sample_files/bin/convertSessionFilesToDB.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-06 14:46:25
|
Revision: 419 http://cs-content.svn.sourceforge.net/cs-content/?rev=419&view=rev Author: crazedsanity Date: 2009-08-06 14:46:17 +0000 (Thu, 06 Aug 2009) Log Message: ----------- MySQL & PostgreSQL schema for database storage of sessions (cs_sessionDB{}). Added Paths: ----------- trunk/1.0/schema/ trunk/1.0/schema/db_session_schema.mysql.sql trunk/1.0/schema/db_session_schema.pgsql.sql Added: trunk/1.0/schema/db_session_schema.mysql.sql =================================================================== --- trunk/1.0/schema/db_session_schema.mysql.sql (rev 0) +++ trunk/1.0/schema/db_session_schema.mysql.sql 2009-08-06 14:46:17 UTC (rev 419) @@ -0,0 +1,17 @@ + + +-- +-- Store session data in here. +-- Idea originally from: http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711 +-- + +CREATE TABLE `test`.`sess_tmp` ( + `session_store_id` int NOT NULL AUTO_INCREMENT, + `session_id` varchar(32) NOT NULL, + `user_id` varchar(16) NOT NULL, + `date_created` datetime NOT NULL, + `last_updated` datetime NOT NULL, + `session_data` LONGTEXT NOT NULL, + PRIMARY KEY (`session_store_id`) +) +ENGINE = MyISAM; \ No newline at end of file Added: trunk/1.0/schema/db_session_schema.pgsql.sql =================================================================== --- trunk/1.0/schema/db_session_schema.pgsql.sql (rev 0) +++ trunk/1.0/schema/db_session_schema.pgsql.sql 2009-08-06 14:46:17 UTC (rev 419) @@ -0,0 +1,16 @@ + + +-- +-- Store session data in here. +-- Idea originally from: http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711 +-- + +CREATE TABLE cs_session_store_table ( + session_store_id serial NOT NULL PRIMARY KEY, + session_id varchar(32) NOT NULL DEFAULT '' UNIQUE, + user_id varchar(16), + date_created timestamp NOT NULL DEFAULT NOW(), + last_updated timestamp NOT NULL DEFAULT NOW(), + session_data text +); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-06 05:09:19
|
Revision: 418 http://cs-content.svn.sourceforge.net/cs-content/?rev=418&view=rev Author: crazedsanity Date: 2009-08-06 05:09:06 +0000 (Thu, 06 Aug 2009) Log Message: ----------- Working support for sessions stored in the database. /contentSystem.class.php: * initialize_locals(): -- start database-based session storage if SESSION_DBSAVE is a properly set constant. /cs_session.class.php: * __construct(): -- ARG CHANGE: DEFAULT VALUE CHANGED: #1 (from 1 to true) -- when passing a boolean true as arg #1, a session was created which was literally named "1" (the bool was interpretted to a string val). /cs_sessionDB.class.php: * REMOVE LOGGER STUFF::: -- sessdb_table_exists() -- load_table() -- is_valid_sid() -- sessdb_open() -- sessdb_close() -- sessdb_read() -- sessdb_destroy() -- sessdb_gc() * __construct(): -- remove logger stuff -- move session_set_save_handler() call to just before the call to the parent's __construct(). * sessdb_write(): -- removed logger stuff -- set array signifying how to clean the fields. -- pass the cleanString var to string_from_array() Modified Paths: -------------- trunk/1.0/contentSystem.class.php trunk/1.0/cs_session.class.php trunk/1.0/cs_sessionDB.class.php Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-08-05 20:28:56 UTC (rev 417) +++ trunk/1.0/contentSystem.class.php 2009-08-06 05:09:06 UTC (rev 418) @@ -134,6 +134,14 @@ * Creates internal objects & prepares for later usage. */ private function initialize_locals() { + + //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); + } + //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(). Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2009-08-05 20:28:56 UTC (rev 417) +++ trunk/1.0/cs_session.class.php 2009-08-06 05:09:06 UTC (rev 418) @@ -25,10 +25,10 @@ * this parameter is non-null and non-numeric, the value will be * used as the session name. */ - function __construct($createSession=1) { + function __construct($createSession=true) { parent::__construct(true); if($createSession) { - if(!is_null($createSession) && strlen($createSession) && !is_numeric($createSession)) { + if(is_string($createSession) && strlen($createSession) >2) { session_name($createSession); } Modified: trunk/1.0/cs_sessionDB.class.php =================================================================== --- trunk/1.0/cs_sessionDB.class.php 2009-08-05 20:28:56 UTC (rev 417) +++ trunk/1.0/cs_sessionDB.class.php 2009-08-06 05:09:06 UTC (rev 418) @@ -26,21 +26,6 @@ function __construct() { - require_once(dirname(__FILE__) .'/cs_fileSystem.class.php'); - $this->logger = new cs_fileSystem(constant('RWDIR')); - $this->logger->create_file('session.log',true); - $this->logger->openFile('session.log'); - - //now tell PHP to use this class's methods for saving the session. - session_set_save_handler( - array(&$this, 'sessdb_open'), - array(&$this, 'sessdb_close'), - array(&$this, 'sessdb_read'), - array(&$this, 'sessdb_write'), - array(&$this, 'sessdb_destroy'), - array(&$this, 'sessdb_gc') - ); - //map some constants to connection parameters. //NOTE::: all constants should be prefixed... $constantPrefix = 'SESSION_DB_'; @@ -64,6 +49,16 @@ $this->load_table(); } + //now tell PHP to use this class's methods for saving the session. + session_set_save_handler( + array(&$this, 'sessdb_open'), + array(&$this, 'sessdb_close'), + array(&$this, 'sessdb_read'), + array(&$this, 'sessdb_write'), + array(&$this, 'sessdb_destroy'), + array(&$this, 'sessdb_gc') + ); + parent::__construct(true); //Stop things from going into an audit log... see @@ -81,7 +76,6 @@ * Determines if the appropriate table exists in the database. */ public function sessdb_table_exists() { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); try { $test = $this->db->run_query("SELECT * FROM ". $this->tableName . " ORDER BY ". $this->tablePKey ." LIMIT 1"); @@ -90,7 +84,6 @@ catch(exception $e) { $exists = false; } - $this->logger->append_to_file(__METHOD__ .": result=(". $exists .")". microtime(true)); return($exists); }//end sessdb_table_exists() @@ -101,7 +94,6 @@ //------------------------------------------------------------------------- private function load_table() { $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); - $filename = dirname(__FILE__) .'/schema/db_session_schema.'. $this->db->get_dbtype() .'.sql'; if(file_exists($filename)) { try { $this->db->run_update(file_get_contents($filename),true); @@ -124,32 +116,24 @@ //------------------------------------------------------------------------- protected function is_valid_sid($sid) { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); $isValid = false; if(strlen($sid) == 32) { - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); try { - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); $sql = "SELECT * FROM ". $this->tableName ." WHERE session_id='". $sid ."'"; $this->db->run_query($sql); - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); $numrows = $this->db->numRows(); - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); if($numrows == 1) { $isValid = true; } elseif($numrows > 0 || $numrows < 0) { throw new exception(__METHOD__ .": invalid numrows returned (". $numrows .")"); } - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ ."), numrows=(". $numrows ."), SQL::: ". $sql ." ". microtime(true)); } catch(exception $e) { - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); //well... do nothing I guess. } } - $this->logger->append_to_file(__METHOD__ .": result=(". $isValid .")". microtime(true)); return($isValid); }//end is_valid_sid() @@ -162,8 +146,6 @@ * Open the session (doesn't really do anything) */ public function sessdb_open($savePath, $sessionName) { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); - $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); return(true); }//end sessdb_open() //------------------------------------------------------------------------- @@ -175,8 +157,6 @@ * Close the session (call the "gc" method) */ public function sessdb_close() { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); - $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); return($this->sessdb_gc(0)); }//end sessdb_close() //------------------------------------------------------------------------- @@ -189,7 +169,6 @@ * an empty string instead of NULL. */ public function sessdb_read($sid) { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); $retval = ''; try { $sql = "SELECT * FROM ". $this->tableName ." WHERE session_id='". @@ -203,7 +182,6 @@ catch(exception $e) { //no throwing exceptions... } - $this->logger->append_to_file(__METHOD__ .": result=(". $retval .")". microtime(true)); return($retval); }//end sessdb_read() //------------------------------------------------------------------------- @@ -212,36 +190,33 @@ //------------------------------------------------------------------------- public function sessdb_write($sid, $data) { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); $data = array( 'session_data' => $data, 'user_id' => null ); + $cleanString = array( + 'session_data' => 'sql', + 'user_id' => 'numeric' + ); - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); //pull the uid out of the session... if(defined('SESSION_DBSAVE_UIDPATH')) { - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); $a2p = new cs_arrayToPath($_SESSION); - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); $uidVal = $a2p->get_data(constant('SESSION_DBSAVE_UIDPATH')); - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); if(is_string($uidVal) || is_numeric($uidVal)) { - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); $data['user_id'] = $uidVal; } - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); } - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); $afterSql = ""; if($this->is_valid_sid($sid)) { $type = 'update'; $sql = "UPDATE ". $this->tableName ." SET "; $afterSql = "WHERE session_id='". $sid ."'"; + $data['last_updated'] = 'NOW()'; $secondArg = false; } else { @@ -250,19 +225,15 @@ $data['session_id'] = $sid; $secondArg = $this->sequenceName; } - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); - $sql .= $this->gfObj->string_from_array($data, $type, null, 'sql') . $afterSql; + $sql .= $this->gfObj->string_from_array($data, $type, null, $cleanString) .' '. $afterSql; try { $funcName = 'run_'. $type; $res = $this->db->$funcName($sql, $secondArg); - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ ."), SQL::: ". $sql ." ". microtime(true)); } catch(exception $e) { //umm... yeah. - $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ ."), EXCEPTION::: ". $e->getMessage() ."\n ". microtime(true)); } - $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); return(true); }//end sessdb_write() @@ -272,7 +243,6 @@ //------------------------------------------------------------------------- public function sessdb_destroy($sid) { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); try { $sql = "DELETE FROM ". $this->tableName ." WHERE session_id='". $sid ."'"; $this->db->run_update($sql, true); @@ -280,7 +250,6 @@ catch(exception $e) { //do... nothing? } - $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); return(true); }//end sessdb_destroy() //------------------------------------------------------------------------- @@ -293,7 +262,6 @@ * Anything that is older than that time will be purged (gc='garbage collector'). */ public function sessdb_gc($maxLifetime=null) { - $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); $nowTime = date('Y-m-d H:i:s'); if(is_null($maxLifetime) || !is_numeric($maxLifetime) || $maxLifetime < 0) { @@ -306,9 +274,7 @@ $dt2 = date('Y-m-d H:i:s', $dt1); - $this->logger->append_to_file(__METHOD__ .": still going, dt2=(". $dt2 .").. ". microtime(true)); - try { //destroy old sessions, but don't complain if nothing is deleted. $sql = "DELETE FROM ". $this->tableName ." WHERE last_updated < ". $dt2; @@ -317,7 +283,6 @@ catch(exception $e) { //probably should do something here. } - $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); return(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-05 20:29:07
|
Revision: 417 http://cs-content.svn.sourceforge.net/cs-content/?rev=417&view=rev Author: crazedsanity Date: 2009-08-05 20:28:56 +0000 (Wed, 05 Aug 2009) Log Message: ----------- Facilitating the database session storage. NOTE::: it sort of works, but currently it continuously creates new records with different session ID's... probably something very small that I'm missing. Modified Paths: -------------- trunk/1.0/cs_session.class.php Added Paths: ----------- trunk/1.0/cs_sessionDB.class.php Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2009-08-05 16:39:27 UTC (rev 416) +++ trunk/1.0/cs_session.class.php 2009-08-05 20:28:56 UTC (rev 417) @@ -13,10 +13,9 @@ class cs_session extends cs_contentAbstract { - protected $db; - public $uid; - public $sid; - public $sid_check = 1; + protected $uid; + protected $sid; + protected $sid_check = 1; //------------------------------------------------------------------------- /** @@ -27,7 +26,7 @@ * used as the session name. */ function __construct($createSession=1) { - parent::__construct(false); + parent::__construct(true); if($createSession) { if(!is_null($createSession) && strlen($createSession) && !is_numeric($createSession)) { session_name($createSession); @@ -139,6 +138,19 @@ return($retval); }//end drop_cookie() //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * PHP5 magic method for retrieving the value of internal vars; this allows + * code to find the value of these variables, but not modify them (modifying + * requires the "__set($var,$val)" method). + */ + public function __get($var) { + return($this->$var); + }//end __get() + //------------------------------------------------------------------------- }//end cs_session{} Copied: trunk/1.0/cs_sessionDB.class.php (from rev 416, trunk/1.0/cs_session.class.php) =================================================================== --- trunk/1.0/cs_sessionDB.class.php (rev 0) +++ trunk/1.0/cs_sessionDB.class.php 2009-08-05 20:28:56 UTC (rev 417) @@ -0,0 +1,329 @@ +<?php +/* + * FILE INFORMATION: + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +require_once(dirname(__FILE__) .'/cs_session.class.php'); +require_once(constant('LIBDIR') .'/cs-phpxml/cs_arrayToPath.class.php'); + +class cs_sessionDB extends cs_session { + + protected $db; + + //------------------------------------------------------------------------- + /** + * The constructor. + * + * @param $createSession (mixed,optional) determines if a session will be started or not; if + * this parameter is non-null and non-numeric, the value will be + * used as the session name. + */ + function __construct() { + + + require_once(dirname(__FILE__) .'/cs_fileSystem.class.php'); + $this->logger = new cs_fileSystem(constant('RWDIR')); + $this->logger->create_file('session.log',true); + $this->logger->openFile('session.log'); + + //now tell PHP to use this class's methods for saving the session. + session_set_save_handler( + array(&$this, 'sessdb_open'), + array(&$this, 'sessdb_close'), + array(&$this, 'sessdb_read'), + array(&$this, 'sessdb_write'), + array(&$this, 'sessdb_destroy'), + array(&$this, 'sessdb_gc') + ); + + //map some constants to connection parameters. + //NOTE::: all constants should be prefixed... + $constantPrefix = 'SESSION_DB_'; + $params = array('host', 'port', 'dbname', 'user', 'password'); + foreach($params as $name) { + $value = null; + $constantName = $constantPrefix . strtoupper($name); + if(defined($constantName)) { + $value = constant($constantName); + } + $dbParams[$name] = $value; + } + $this->db = new cs_phpDB(constant('DBTYPE')); + $this->db->connect($dbParams); + + $this->tableName = 'cs_session_store_table'; + $this->tablePKey = 'session_store_id'; + $this->sequenceName = 'cs_session_store_table_session_store_id_seq'; + + if(!$this->sessdb_table_exists()) { + $this->load_table(); + } + + parent::__construct(true); + + //Stop things from going into an audit log... see + //http://www.developertutorials.com/tutorials/php/saving-php-session-data-database-050711/page3.html + // NOTE::: not sure if this is valid or not... + $this->audit_logging = false; + + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Determines if the appropriate table exists in the database. + */ + public function sessdb_table_exists() { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + try { + $test = $this->db->run_query("SELECT * FROM ". $this->tableName . + " ORDER BY ". $this->tablePKey ." LIMIT 1"); + $exists = true; + } + catch(exception $e) { + $exists = false; + } + $this->logger->append_to_file(__METHOD__ .": result=(". $exists .")". microtime(true)); + + return($exists); + }//end sessdb_table_exists() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function load_table() { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + $filename = dirname(__FILE__) .'/schema/db_session_schema.'. $this->db->get_dbtype() .'.sql'; + if(file_exists($filename)) { + try { + $this->db->run_update(file_get_contents($filename),true); + } + catch(exception $e) { + throw new exception(__METHOD__ .": failed to load required table " . + "into your database automatically::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": while attempting to load required " . + "table into your database, discovered you have a missing schema " . + "file (". $filename .")"); + } + $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); + }//end load_table() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + protected function is_valid_sid($sid) { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + $isValid = false; + if(strlen($sid) == 32) { + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + try { + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + $sql = "SELECT * FROM ". $this->tableName ." WHERE session_id='". + $sid ."'"; + $this->db->run_query($sql); + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + $numrows = $this->db->numRows(); + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + if($numrows == 1) { + $isValid = true; + } + elseif($numrows > 0 || $numrows < 0) { + throw new exception(__METHOD__ .": invalid numrows returned (". $numrows .")"); + } + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ ."), numrows=(". $numrows ."), SQL::: ". $sql ." ". microtime(true)); + } + catch(exception $e) { + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + //well... do nothing I guess. + } + } + $this->logger->append_to_file(__METHOD__ .": result=(". $isValid .")". microtime(true)); + + return($isValid); + }//end is_valid_sid() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Open the session (doesn't really do anything) + */ + public function sessdb_open($savePath, $sessionName) { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); + return(true); + }//end sessdb_open() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Close the session (call the "gc" method) + */ + public function sessdb_close() { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); + return($this->sessdb_gc(0)); + }//end sessdb_close() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Read information about the session. If there is no data, it MUST return + * an empty string instead of NULL. + */ + public function sessdb_read($sid) { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + $retval = ''; + try { + $sql = "SELECT * FROM ". $this->tableName ." WHERE session_id='". + $sid ."'"; + $data = $this->db->run_query($sql); + + if($this->db->numRows() == 1) { + $retval = $data['session_data']; + } + } + catch(exception $e) { + //no throwing exceptions... + } + $this->logger->append_to_file(__METHOD__ .": result=(". $retval .")". microtime(true)); + return($retval); + }//end sessdb_read() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function sessdb_write($sid, $data) { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + $data = array( + 'session_data' => $data, + 'user_id' => null + ); + + + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + + //pull the uid out of the session... + if(defined('SESSION_DBSAVE_UIDPATH')) { + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + $a2p = new cs_arrayToPath($_SESSION); + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + $uidVal = $a2p->get_data(constant('SESSION_DBSAVE_UIDPATH')); + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + + if(is_string($uidVal) || is_numeric($uidVal)) { + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + $data['user_id'] = $uidVal; + } + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + } + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + + $afterSql = ""; + if($this->is_valid_sid($sid)) { + $type = 'update'; + $sql = "UPDATE ". $this->tableName ." SET "; + $afterSql = "WHERE session_id='". $sid ."'"; + $secondArg = false; + } + else { + $type = 'insert'; + $sql = "INSERT INTO ". $this->tableName ." "; + $data['session_id'] = $sid; + $secondArg = $this->sequenceName; + } + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ .") ". microtime(true)); + + $sql .= $this->gfObj->string_from_array($data, $type, null, 'sql') . $afterSql; + try { + $funcName = 'run_'. $type; + $res = $this->db->$funcName($sql, $secondArg); + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ ."), SQL::: ". $sql ." ". microtime(true)); + } + catch(exception $e) { + //umm... yeah. + $this->logger->append_to_file(__METHOD__ .": still going, line=(". __LINE__ ."), EXCEPTION::: ". $e->getMessage() ."\n ". microtime(true)); + } + $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); + + return(true); + }//end sessdb_write() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function sessdb_destroy($sid) { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + try { + $sql = "DELETE FROM ". $this->tableName ." WHERE session_id='". $sid ."'"; + $this->db->run_update($sql, true); + } + catch(exception $e) { + //do... nothing? + } + $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); + return(true); + }//end sessdb_destroy() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + /** + * Define maximum lifetime (in seconds) to store sessions in the database. + * Anything that is older than that time will be purged (gc='garbage collector'). + */ + public function sessdb_gc($maxLifetime=null) { + $this->logger->append_to_file(__METHOD__ .": starting... ". microtime(true)); + + $nowTime = date('Y-m-d H:i:s'); + if(is_null($maxLifetime) || !is_numeric($maxLifetime) || $maxLifetime < 0) { + //pull it from PHP's ini settings. + $maxLifetime = ini_get("session.gc_maxlifetime"); + } + $interval = $maxLifetime .' seconds'; + + $dt1 = strtotime($nowTime .' - '. $interval); + $dt2 = date('Y-m-d H:i:s', $dt1); + + + $this->logger->append_to_file(__METHOD__ .": still going, dt2=(". $dt2 .").. ". microtime(true)); + + + try { + //destroy old sessions, but don't complain if nothing is deleted. + $sql = "DELETE FROM ". $this->tableName ." WHERE last_updated < ". $dt2; + #$this->db->run_update($sql, true); + } + catch(exception $e) { + //probably should do something here. + } + $this->logger->append_to_file(__METHOD__ .": done". microtime(true)); + + return(true); + + }//end sessdb_gc() + //------------------------------------------------------------------------- + + +}//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...> - 2009-08-05 16:39:40
|
Revision: 416 http://cs-content.svn.sourceforge.net/cs-content/?rev=416&view=rev Author: crazedsanity Date: 2009-08-05 16:39:27 +0000 (Wed, 05 Aug 2009) Log Message: ----------- Minor change to separators (no changed code). Modified Paths: -------------- trunk/1.0/cs_session.class.php Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2009-08-05 01:29:10 UTC (rev 415) +++ trunk/1.0/cs_session.class.php 2009-08-05 16:39:27 UTC (rev 416) @@ -18,7 +18,7 @@ public $sid; public $sid_check = 1; - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * The constructor. * @@ -49,11 +49,11 @@ $this->sid = session_id(); }//end __construct() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Required method, so passing the object to contentSystem::handle_session() * will work properly. @@ -65,11 +65,11 @@ public function is_authenticated() { return(FALSE); }//end is_authenticated() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Retrieve data for an existing cookie. * @@ -85,11 +85,11 @@ } return($retval); }//end get_cookie() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Create a new cookie. * @@ -116,11 +116,11 @@ return($retval); }//end create_cookie() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Destroy (expire) an existing cookie. * @@ -138,7 +138,7 @@ } return($retval); }//end drop_cookie() - //--------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------- }//end cs_session{} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-05 01:29:19
|
Revision: 415 http://cs-content.svn.sourceforge.net/cs-content/?rev=415&view=rev Author: crazedsanity Date: 2009-08-05 01:29:10 +0000 (Wed, 05 Aug 2009) Log Message: ----------- TODO about suppressing errors that shouldn't happen. Modified Paths: -------------- trunk/1.0/cs_fileSystem.class.php Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2009-08-04 05:03:17 UTC (rev 414) +++ trunk/1.0/cs_fileSystem.class.php 2009-08-05 01:29:10 UTC (rev 415) @@ -195,6 +195,7 @@ */ public function get_fileinfo($tFile) { + //TODO: shouldn't require putting the "@" in front of these calls! $retval = array( "size" => @filesize($tFile), "type" => @filetype($tFile), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-04 05:03:23
|
Revision: 414 http://cs-content.svn.sourceforge.net/cs-content/?rev=414&view=rev Author: crazedsanity Date: 2009-08-04 05:03:17 +0000 (Tue, 04 Aug 2009) Log Message: ----------- Override some PHP warnings... Modified Paths: -------------- trunk/1.0/cs_fileSystem.class.php Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2009-08-03 17:41:13 UTC (rev 413) +++ trunk/1.0/cs_fileSystem.class.php 2009-08-04 05:03:17 UTC (rev 414) @@ -196,16 +196,16 @@ public function get_fileinfo($tFile) { $retval = array( - "size" => filesize($tFile), + "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) + "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) ); return($retval); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-08-03 17:41:27
|
Revision: 413 http://cs-content.svn.sourceforge.net/cs-content/?rev=413&view=rev Author: crazedsanity Date: 2009-08-03 17:41:13 +0000 (Mon, 03 Aug 2009) Log Message: ----------- Tests strictly for cs_globalFunctions. /cs_globalFunctions.class.php: * string_from_array(): -- removed unused $typesArr -- [update]: + clean only if it does not both start AND end in single quotes + if the entire value is one single quote, delimit it and wrap in single quotes. + empty values get an empty string value ('') -- [select]: + pass forceSqlQuotes to cleanString() + wrap in quotes if there's a separator, regardless of whether or not the value is numeric (the DB should be able to convert a text number into an actual number). * interpret_bool(): -- when a decimal number is passed, drop the decimal so it is handled as a whole number; otherwise, 0.1 is treated as though it were 0 (due to the settype() as integer call). /tests/testOfCSContent.php: * Dropped methods (moved to testOfCSGlobalFunctions.php): -- test_cleanString() -- test_string_from_array() -- test_interpret_bool() /tests/testOfCSGlobalFunctions.php [NEW]: * copied from testOfCSContent.php, with expanded tests. Modified Paths: -------------- trunk/1.0/cs_globalFunctions.class.php trunk/1.0/tests/testOfCSContent.php Added Paths: ----------- trunk/1.0/tests/testOfCSGlobalFunctions.php Modified: trunk/1.0/cs_globalFunctions.class.php =================================================================== --- trunk/1.0/cs_globalFunctions.class.php 2009-07-29 19:03:37 UTC (rev 412) +++ trunk/1.0/cs_globalFunctions.class.php 2009-08-03 17:41:13 UTC (rev 413) @@ -162,7 +162,6 @@ } //make sure $style is valid. - $typesArr = array("insert", "update"); $style = strtolower($style); if(is_array($array)) { @@ -222,10 +221,17 @@ if(($value === "NULL" || $value === NULL) && !$this->forceSqlQuotes) { $sqlQuotes = 0; } - if($cleanString && !preg_match('/^\'/',$value)) { + if($cleanString && !(preg_match('/^\'/',$value) && preg_match('/\'$/', $value))) { //make sure it doesn't have crap in it... $value = $this->cleanString($value, "sql",$sqlQuotes); } + if($value == "'") { + //Fix possible SQL-injection. + $value = "'\''"; + } + elseif(!strlen($value)) { + $value = "''"; + } $retval = $this->create_list($retval, $field . $separator . $value); } break; @@ -277,9 +283,9 @@ } if($cleanString) { //make sure it doesn't have crap in it... - $value = $this->cleanString($value, "sql"); + $value = $this->cleanString($value, "sql", $this->forceSqlQuotes); } - if(!is_numeric($value) && isset($separator)) { + if(isset($separator)) { $value = "'". $value ."'"; } $retval = $this->create_list($retval, $field . $separator . $value, " $delimiter "); @@ -804,8 +810,12 @@ //now figure out the value to return. if(is_numeric($interpretThis)) { + if(preg_match('/\.[0-9]{1,}/', $interpretThis)) { + //if it is a decimal number, remove the dot (i.e. "0.000001" -> "0000001" -> 1) + $interpretThis = str_replace('.', '', $interpretThis); + } settype($interpretThis, 'integer'); - if($interpretThis == '0') { + if($interpretThis == 0) { $index=0; } else { Modified: trunk/1.0/tests/testOfCSContent.php =================================================================== --- trunk/1.0/tests/testOfCSContent.php 2009-07-29 19:03:37 UTC (rev 412) +++ trunk/1.0/tests/testOfCSContent.php 2009-08-03 17:41:13 UTC (rev 413) @@ -33,154 +33,6 @@ //------------------------------------------------------------------------- - public function test_cleanString() { - - $gf = new cs_globalFunctions(); - - $cleanThis = '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS'; - $testSQL = array( - 'none' => $cleanThis, - 'query' => '@_=;34:/JuST THIS', - 'theDefault' => '34JuSTTHIS', - 'alphanumeric' => '34JuSTTHIS', - 'sql' => '~`!@#$^&*()_+-=[]{}|;34:\\\'<>?,.//\".JuST THIS', - 'sql_insert' => '~`!@#$^&*()_+-=[]{}|;34:\\\\\'<>?,.//".JuST THIS', - 'sql92_insert' => '~`!@#$^&*()_+-=[]{}|;34:\'\'<>?,.//".JuST THIS', - 'double_quote' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\.JuST THIS', - 'htmlspecial' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', - 'htmlspecial_q' => '~`!@#$^&*()_+-=[]\{}|;34:\\'\<>?,.//\".JuST THIS', - 'htmlspecial_nq' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', - 'htmlentity' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', - 'htmlentity_plus_brackets' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', - 'double_entity' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\.JuST THIS', - 'meta' => '~`!@#\$\^&\*\(\)_\+-=\[\]\\\\{}|;34:\\\\\'\\\<>\?,\.//\\\\"\.JuST THIS', - 'email' => '@_-34..JuSTTHIS', - 'email_plus_spaces' => '@_-34..JuST THIS', - 'phone_fax' => '()+-34 ', - 'integer' => '34', - 'numeric' => '34', - 'decimal' => '34..', - 'float' => '34..', - 'name' => '\'JuSTTHIS', - 'names' => '\'JuSTTHIS', - 'alpha' => 'JuSTTHIS', - 'bool' => 't', - 'varchar' => '\'@_=;34:/JuST THIS\'', - 'date' => '-34', - 'datetime' => '-34:\'.//.JuST THIS', - 'all' => '34JuSTTHIS' - ); - - foreach($testSQL as $name=>$expected) { - $cleanedData = $gf->cleanString($cleanThis, $name); - - //NOTE::: passing "%" in the message data causes an exception with the simpletest framework. - $this->assertEqual($expected, $cleanedData); - } - - - //test quoting (with a few exceptions). - $testQuotes = $testSQL; - unset($testQuotes['none'], $testQuotes['sql92_insert']); - foreach($testQuotes as $name=>$expected) { - $gf->switch_force_sql_quotes(1); - $cleanedDataPlusQuotes = $gf->cleanString($cleanThis, $name, 1); - $this->assertEqual("'". $expected ."'", $cleanedDataPlusQuotes, "Failed quoting with style=(". $name .")"); - - $gf->switch_force_sql_quotes(0); - $this->assertEqual("'". $expected ."'", $cleanedDataPlusQuotes, "Failed quoting with style=(". $name .")"); - } - - - //TEST NULLS - { - - $this->assertEqual($gf->cleanString("", "numeric",0), ""); - $this->assertEqual($gf->cleanString("", "numeric",1), "''"); - $this->assertEqual($gf->cleanString("", "integer",0), ""); - $this->assertEqual($gf->cleanString("", "integer",1), "''"); - $this->assertEqual($gf->cleanString(null, "numeric",0), "NULL"); - $this->assertEqual($gf->cleanString(null, "numeric",1), "NULL"); - $this->assertEqual($gf->cleanString(null, "integer",0), "NULL"); - $this->assertEqual($gf->cleanString(null, "integer",1), "NULL"); - - $this->assertEqual($gf->cleanString(null, "varchar",0), "NULL"); - $this->assertEqual($gf->cleanString(null, "varchar",1), "'NULL'"); - $this->assertEqual($gf->cleanString("", "varchar",0), "NULL"); - $this->assertEqual($gf->cleanString("", "varchar",1), "'NULL'"); - } - - }//end test_cleanString() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - function test_string_from_array() { - $gf = new cs_globalFunctions; - $gf->switch_force_sql_quotes(0); - - //Test some SQL-Specific stuff. - $testSQL = array( - 'column1' => "'my value ' OR 'x'='x'", - 'column two' => "Stuff" - ); - - //Test INSERT style. - { - $expected = "(column1, column two) VALUES ('my value ' OR 'x'='x','Stuff')"; - $this->assertEqual($gf->string_from_array($testSQL, 'insert'), $expected); - - $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; - $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql'), $expected); - - $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; - $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql_insert'), $expected); - - $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; - $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql92_insert'), $expected); - - //now let's see what happens if we pass an array signifying how it should be cleaned. - $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; - $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql', 'column two'=>'sql')), $expected); - $expected = "(column1, column two) VALUES ('\\\\\'my value \\\\\' OR \\\\\'x\\\\\'=\\\\\'x\\\\\'','Stuff')"; - $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql_insert', 'column two'=>'sql_insert')), $expected); - $expected = "(column1, column two) VALUES ('\'\'my value \'\' OR \'\'x\'\'=\'\'x\'\'','Stuff')"; - $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql92_insert', 'column two'=>'sql92_insert')), $expected); - - } - - }//end test_string_from_array() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - function test_interpret_bool() { - $gf=new cs_globalFunctions; - - $this->assertEqual($gf->interpret_bool('true'), true); - $this->assertEqual($gf->interpret_bool('false'), false); - $this->assertEqual($gf->interpret_bool('0'), false); - $this->assertEqual($gf->interpret_bool('1'), true); - $this->assertEqual($gf->interpret_bool(0), false); - $this->assertEqual($gf->interpret_bool(1), true); - $this->assertEqual($gf->interpret_bool('f'), false); - $this->assertEqual($gf->interpret_bool('t'), true); - $this->assertEqual($gf->interpret_bool("1stuff"), true); - $this->assertEqual($gf->interpret_bool(""), false); - $this->assertEqual($gf->interpret_bool(" true "), true); - $this->assertEqual($gf->interpret_bool(" false "), false); - - //now go through the same thing, but this time tell it to give back a specific value for true and false. - $this->assertEqual($gf->interpret_bool(false, array(0=>'FaLSe',1=>"crap")), 'FaLSe'); - $this->assertEqual($gf->interpret_bool(false, array(0=>"crap",1=>'FaLSe')), 'crap'); - }//end test_interpret_bool() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- public function test_siteConfig() { $configFile = constant('TEST_FILESDIR') .'/sampleConfig.xml'; $varPrefix = preg_replace("/:/", "_", __METHOD__ ."-"); Copied: trunk/1.0/tests/testOfCSGlobalFunctions.php (from rev 412, trunk/1.0/tests/testOfCSContent.php) =================================================================== --- trunk/1.0/tests/testOfCSGlobalFunctions.php (rev 0) +++ trunk/1.0/tests/testOfCSGlobalFunctions.php 2009-08-03 17:41:13 UTC (rev 413) @@ -0,0 +1,249 @@ +<?php +/* + * Created on Jan 13, 2009 + * + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + + + +//============================================================================= +class TestOfCSGlobalFunctions extends UnitTestCase { + + //------------------------------------------------------------------------- + function __construct() { + require_once(dirname(__FILE__) .'/../cs_globalFunctions.class.php'); + require_once(dirname(__FILE__) .'/../cs_siteConfig.class.php'); + + $this->gfObj = new cs_globalFunctions; + $this->gfObj->debugPrintOpt=1; + + $filesDir = dirname(__FILE__) ."/files"; + define('TEST_FILESDIR', $filesDir); + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function test_cleanString() { + + $gf = new cs_globalFunctions(); + + $cleanThis = '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS'; + $testSQL = array( + 'none' => $cleanThis, + 'query' => '@_=;34:/JuST THIS', + 'theDefault' => '34JuSTTHIS', + 'alphanumeric' => '34JuSTTHIS', + 'sql' => '~`!@#$^&*()_+-=[]{}|;34:\\\'<>?,.//\".JuST THIS', + 'sql_insert' => '~`!@#$^&*()_+-=[]{}|;34:\\\\\'<>?,.//".JuST THIS', + 'sql92_insert' => '~`!@#$^&*()_+-=[]{}|;34:\'\'<>?,.//".JuST THIS', + 'double_quote' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\.JuST THIS', + 'htmlspecial' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'htmlspecial_q' => '~`!@#$^&*()_+-=[]\{}|;34:\\'\<>?,.//\".JuST THIS', + 'htmlspecial_nq' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'htmlentity' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'htmlentity_plus_brackets' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'double_entity' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\.JuST THIS', + 'meta' => '~`!@#\$\^&\*\(\)_\+-=\[\]\\\\{}|;34:\\\\\'\\\<>\?,\.//\\\\"\.JuST THIS', + 'email' => '@_-34..JuSTTHIS', + 'email_plus_spaces' => '@_-34..JuST THIS', + 'phone_fax' => '()+-34 ', + 'integer' => '34', + 'numeric' => '34', + 'decimal' => '34..', + 'float' => '34..', + 'name' => '\'JuSTTHIS', + 'names' => '\'JuSTTHIS', + 'alpha' => 'JuSTTHIS', + 'bool' => 't', + 'varchar' => '\'@_=;34:/JuST THIS\'', + 'date' => '-34', + 'datetime' => '-34:\'.//.JuST THIS', + 'all' => '34JuSTTHIS' + ); + + foreach($testSQL as $name=>$expected) { + $cleanedData = $gf->cleanString($cleanThis, $name); + + //NOTE::: passing "%" in the message data causes an exception with the simpletest framework. + $this->assertEqual($expected, $cleanedData); + } + + + //test quoting (with a few exceptions). + $testQuotes = $testSQL; + unset($testQuotes['none'], $testQuotes['sql92_insert']); + foreach($testQuotes as $name=>$expected) { + $gf->switch_force_sql_quotes(1); + $cleanedDataPlusQuotes = $gf->cleanString($cleanThis, $name, 1); + $this->assertEqual("'". $expected ."'", $cleanedDataPlusQuotes, "Failed quoting with style=(". $name .")"); + + $gf->switch_force_sql_quotes(0); + $this->assertEqual("'". $expected ."'", $cleanedDataPlusQuotes, "Failed quoting with style=(". $name .")"); + } + + + //TEST NULLS + { + + $this->assertEqual($gf->cleanString("", "numeric",0), ""); + $this->assertEqual($gf->cleanString("", "numeric",1), "''"); + $this->assertEqual($gf->cleanString("", "integer",0), ""); + $this->assertEqual($gf->cleanString("", "integer",1), "''"); + $this->assertEqual($gf->cleanString(null, "numeric",0), "NULL"); + $this->assertEqual($gf->cleanString(null, "numeric",1), "NULL"); + $this->assertEqual($gf->cleanString(null, "integer",0), "NULL"); + $this->assertEqual($gf->cleanString(null, "integer",1), "NULL"); + + $this->assertEqual($gf->cleanString(null, "varchar",0), "NULL"); + $this->assertEqual($gf->cleanString(null, "varchar",1), "'NULL'"); + $this->assertEqual($gf->cleanString("", "varchar",0), "NULL"); + $this->assertEqual($gf->cleanString("", "varchar",1), "'NULL'"); + } + + }//end test_cleanString() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function test_string_from_array() { + $gf = new cs_globalFunctions; + $gf->switch_force_sql_quotes(0); + + //Test some SQL-Specific stuff. + $testSQL = array( + 'column1' => "'my value ' OR 'x'='x'", + 'column two' => "Stuff" + ); + + //Test INSERT style. + { + $expected = "(column1, column two) VALUES ('my value ' OR 'x'='x','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert'), $expected); + + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql'), $expected); + + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql_insert'), $expected); + + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql92_insert'), $expected); + + //now let's see what happens if we pass an array signifying how it should be cleaned. + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql', 'column two'=>'sql')), $expected); + $expected = "(column1, column two) VALUES ('\\\\\'my value \\\\\' OR \\\\\'x\\\\\'=\\\\\'x\\\\\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql_insert', 'column two'=>'sql_insert')), $expected); + $expected = "(column1, column two) VALUES ('\'\'my value \'\' OR \'\'x\'\'=\'\'x\'\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql92_insert', 'column two'=>'sql92_insert')), $expected); + + } + + //make sure forceSqlQuotes is OFF. + $gf->switch_force_sql_quotes(0); + + //Test the SELECT style. + { + //a basic set of criteria... + $expected = "w='' AND x='y' AND y='0' AND z=''"; + $actual = $gf->string_from_array(array('w'=>'', 'x'=>"y", 'y'=>0,'z'=>NULL), 'select'); + $this->assertEqual($expected, $actual); + + //make sure it distinguishes between text "NULL" and literal NULL. + $expected = "w='' AND x='y' AND y='0' AND z='NULL'"; + $actual = $gf->string_from_array(array('w'=>'', 'x'=>"y", 'y'=>0,'z'=>"NULL"), 'select'); + $this->assertEqual($expected, $actual); + + //make sure it distinguishes between text "NULL" and literal NULL. + $expected = "w='' AND x='y' AND y='0' AND z='NULL'"; + $actual = $gf->string_from_array(array('w'=>'', 'x'=>"y", 'y'=>0,'z'=>"NULL"), 'select', null, 'sql'); + $this->assertEqual($expected, $actual); + + //check with specific cleaning styles. + $expected = "w='' AND x='y' AND y='0' AND z='NULL'"; + $cleanString = array('w'=>"nonexistent", 'x'=>"alpha", 'y'=>"numeric", 'z'=>"sql"); + $actual = $gf->string_from_array(array('w'=>'', 'x'=>"y", 'y'=>0,'z'=>"NULL"), 'select', null, $cleanString); + $this->assertEqual($expected, $actual); + } + + + //Test the UPDATE style. + { + //basic update. + $expected = "w='', x='y', y='0', z=''"; + $actual = $gf->string_from_array(array('w'=>"", 'x'=>"y", 'y'=>0, 'z'=>NULL), 'update', null, 'sql'); + $this->assertEqual($expected, $actual); + + + //basic update, but force SQL quotes... + $gf->switch_force_sql_quotes(1); + $expected = "w='', x='y', y='0', z=''"; + $actual = $gf->string_from_array(array('w'=>"", 'x'=>"y", 'y'=>0, 'z'=>NULL), 'update', null, 'sql'); + $this->assertEqual($expected, $actual); + $gf->switch_force_sql_quotes(0); + + //update with invalid quotes (attempts at SQL injection) + $expected = "w='\' ', x='\'', y='0', z=''"; + $actual = $gf->string_from_array(array('w'=>"' ", 'x'=>"'", 'y'=>0, 'z'=>NULL), 'update', null, 'sql'); + $this->assertEqual($expected, $actual); + } + + + }//end test_string_from_array() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function test_interpret_bool() { + $gf=new cs_globalFunctions; + + $this->assertEqual($gf->interpret_bool('true'), true); + $this->assertEqual($gf->interpret_bool(true), true); + $this->assertEqual($gf->interpret_bool('false'), false); + $this->assertEqual($gf->interpret_bool(false), false); + $this->assertEqual($gf->interpret_bool('0'), false); + $this->assertEqual($gf->interpret_bool('1'), true); + $this->assertEqual($gf->interpret_bool(0), false); + $this->assertEqual($gf->interpret_bool(000000), false); + $this->assertEqual($gf->interpret_bool(1), true); + $this->assertEqual($gf->interpret_bool(0.1), true); + $this->assertEqual($gf->interpret_bool(0.01), true); + $this->assertEqual($gf->interpret_bool(0.001), true); + $this->assertEqual($gf->interpret_bool('f'), false); + $this->assertEqual($gf->interpret_bool('fa'), true); + $this->assertEqual($gf->interpret_bool('fal'), true); + $this->assertEqual($gf->interpret_bool('fals'), true); + $this->assertEqual($gf->interpret_bool('t'), true); + $this->assertEqual($gf->interpret_bool('tr'), true); + $this->assertEqual($gf->interpret_bool('tru'), true); + $this->assertEqual($gf->interpret_bool("1stuff"), true); + $this->assertEqual($gf->interpret_bool(""), false); + $this->assertEqual($gf->interpret_bool(" true "), true); + $this->assertEqual($gf->interpret_bool(" false "), false); + $this->assertEqual($gf->interpret_bool('false-showastrue'), true); + $this->assertEqual($gf->interpret_bool('true-showastrue'), true); + + + //now go through the same thing, but this time tell it to give back a specific value for true and false. + $this->assertEqual($gf->interpret_bool(false, array(0=>'FaLSe',1=>"crap")), 'FaLSe'); + $this->assertEqual($gf->interpret_bool(false, array(0=>"crap",1=>'FaLSe')), 'crap'); + }//end test_interpret_bool() + //------------------------------------------------------------------------- + + + +}//end TestOfCSContent +//============================================================================= +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |