[CS-Project-svn_notify] SF.net SVN: cs-project: [794] releases/1.0
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-02-07 02:19:28
|
Revision: 794 http://cs-project.svn.sourceforge.net/cs-project/?rev=794&view=rev Author: crazedsanity Date: 2008-02-06 18:19:25 -0800 (Wed, 06 Feb 2008) Log Message: ----------- *** RELEASE 1.0.12 *** SUMMARY OF CHANGES::: * update to cs-content v0.10.8 * update to cs-phpxml v0.5.5 * minor template & include changes for updated version of cs-content. SVN COMMAND::: merge -r789:HEAD https://cs-project.svn.sourceforge.net/svnroot/cs-project/trunk/1.0 Modified Paths: -------------- releases/1.0/VERSION releases/1.0/includes/login.inc releases/1.0/lib/cs-arrayToPath/VERSION releases/1.0/lib/cs-arrayToPath/arrayToPathClass.php releases/1.0/lib/cs-content/VERSION releases/1.0/lib/cs-content/contentSystemClass.php releases/1.0/lib/cs-content/cs_bbCodeParser.class.php releases/1.0/lib/cs-content/cs_fileSystemClass.php releases/1.0/lib/cs-content/cs_genericPageClass.php releases/1.0/lib/cs-content/cs_globalFunctions.php releases/1.0/lib/cs-content/cs_phpDB.php releases/1.0/lib/cs-content/cs_sessionClass.php releases/1.0/lib/cs-content/cs_versionAbstract.class.php releases/1.0/lib/cs-content/documentation/basics.pdf releases/1.0/lib/cs-phpxml/VERSION releases/1.0/lib/cs-phpxml/xmlAbstract.class.php releases/1.0/lib/cs-phpxml/xmlBuilderClass.php releases/1.0/lib/cs-phpxml/xmlCreatorClass.php releases/1.0/lib/cs-phpxml/xmlParserClass.php releases/1.0/lib/globalFunctions.php releases/1.0/lib/includes.php releases/1.0/lib/projectClass.php releases/1.0/lib/sessionCacheClass.php releases/1.0/lib/session_class.php releases/1.0/lib/site_config.php Added Paths: ----------- releases/1.0/lib/cs-content/db_types/ releases/1.0/lib/cs-content/db_types/cs_phpDB__pgsql.class.php releases/1.0/lib/cs-content/documentation/source/why_templating.odt releases/1.0/lib/cs-content/documentation/why_templating.pdf releases/1.0/templates/content/notes/create.content.tmpl releases/1.0/templates/content/notes/view.content.tmpl releases/1.0/templates/login.content.tmpl releases/1.0/templates/system/404.shared.tmpl Removed Paths: ------------- releases/1.0/lib/cs-content/db_types/cs_phpDB__pgsql.class.php releases/1.0/templates/content/notes/index.shared.tmpl releases/1.0/templates/login.tmpl Modified: releases/1.0/VERSION =================================================================== --- releases/1.0/VERSION 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/VERSION 2008-02-07 02:19:25 UTC (rev 794) @@ -1,4 +1,4 @@ $Id$ -VERSION: 1.0.11 +VERSION: 1.0.12 $HeadURL$ Modified: releases/1.0/includes/login.inc =================================================================== --- releases/1.0/includes/login.inc 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/includes/login.inc 2008-02-07 02:19:25 UTC (rev 794) @@ -55,7 +55,7 @@ if($_GET['destination']) { $_SESSION['loginDestination'] = urlencode($_GET['destination']); } -//show the default page. -$page->change_content(html_file_to_string("login.tmpl")); +$page->add_template_var('cs-project_version', VERSION_STRING); + ?> \ No newline at end of file Modified: releases/1.0/lib/cs-arrayToPath/VERSION =================================================================== --- releases/1.0/lib/cs-arrayToPath/VERSION 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-arrayToPath/VERSION 2008-02-07 02:19:25 UTC (rev 794) @@ -2,4 +2,4 @@ VERSION: 0.2.2 PROJECT: cs-arrayToPath -$HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2.2/VERSION $ \ No newline at end of file +$HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2/VERSION $ \ No newline at end of file Modified: releases/1.0/lib/cs-arrayToPath/arrayToPathClass.php =================================================================== --- releases/1.0/lib/cs-arrayToPath/arrayToPathClass.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-arrayToPath/arrayToPathClass.php 2008-02-07 02:19:25 UTC (rev 794) @@ -6,7 +6,7 @@ * ------------------- * Last Author::::::::: $Author: crazedsanity $ * Current Revision:::: $Revision: 17 $ - * Repository Location: $HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2.2/arrayToPathClass.php $ + * Repository Location: $HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2/arrayToPathClass.php $ * Last Updated:::::::: $Date: 2007-09-12 14:24:46 -0500 (Wed, 12 Sep 2007) $ * * Modified: releases/1.0/lib/cs-content/VERSION =================================================================== --- releases/1.0/lib/cs-content/VERSION 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/VERSION 2008-02-07 02:19:25 UTC (rev 794) @@ -1,5 +1,5 @@ ## Stores the current version of the cs-content system, and it's source. Please do NOT modify this file. -VERSION: 0.9.1 +VERSION: 0.10.8 PROJECT: cs-content -$HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/VERSION $ \ No newline at end of file +$HeadURL:https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/VERSION $ \ No newline at end of file Modified: releases/1.0/lib/cs-content/contentSystemClass.php =================================================================== --- releases/1.0/lib/cs-content/contentSystemClass.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/contentSystemClass.php 2008-02-07 02:19:25 UTC (rev 794) @@ -1,10 +1,10 @@ -<? +<?php /* * FILE INFORMATION: - * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/contentSystemClass.php $ - * $Id: contentSystemClass.php 165 2007-09-21 16:00:30Z crazedsanity $ - * $LastChangedDate: 2007-09-21 11:00:30 -0500 (Fri, 21 Sep 2007) $ - * $LastChangedRevision: 165 $ + * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/contentSystemClass.php $ + * $Id: contentSystemClass.php 252 2008-01-31 21:57:49Z crazedsanity $ + * $LastChangedDate: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ + * $LastChangedRevision: 252 $ * $LastChangedBy: crazedsanity $ * * HOW THE SYSTEM WORKS::: @@ -90,12 +90,15 @@ ); protected $templateList = array(); protected $includesList = array(); - protected $templateObj = NULL; + public $templateObj = NULL; protected $gfObj = NULL; protected $tabs = NULL; protected $finalSection; + private $isValid=FALSE; + private $reason=NULL; + //------------------------------------------------------------------------ /** * The CONSTRUCTOR. Duh. @@ -201,13 +204,16 @@ * if they're not, this will cause them to be redirected to another URL * (generally, so they can login). */ - public function force_authentication($redirectToUrl, $appendDestination=TRUE) { + public function force_authentication($redirectToUrl, $destinationArg='loginDestination') { if(is_object($this->session) && method_exists($this->session, 'is_authenticated')) { if(strlen($redirectToUrl)) { $cleanedRedirect = $this->clean_url($redirectToUrl); if($this->section != $cleanedRedirect) { if(!$this->session->is_authenticated()) { //run the redirect. + if(strlen($destinationArg)) { + $redirectToUrl .= '?'. $destinationArg .'='. urlencode($_SERVER['REQUEST_URI']); + } $this->gfObj->conditional_header($redirectToUrl, TRUE); } } @@ -254,8 +260,7 @@ * Rips apart the "section" string, setting $this->section and $this->sectionArr. */ private function parse_section() { - // - if($this->section === 0) { + if($this->section === 0 || is_null($this->section) || !strlen($this->section)) { $this->section = "content/index"; } $myArr = split('/', $this->section); @@ -283,8 +288,10 @@ //make sure we've still got something valid to work with. if(!strlen($section)) { + //TODO: remove the extra return statement (should only be one at the bottom of the method). return(0); - } else { + } + else { //check the string to make sure it doesn't begin or end with a "/" if($section[0] == '/') { $section = substr($section, 1, strlen($section)); @@ -356,8 +363,9 @@ //now cd() all the way back. $this->fileSystemObj->cd('/'); - } else { - //couldn't find the templates directory... ick. + } + else { + //couldn't find the templates directory, and no includes... it's dead. $this->die_gracefully(__METHOD__ .": unable to find the templates directory, or non-valid page [". $this->validate_page() ."]"); } }//end prepare() @@ -396,14 +404,17 @@ } $lsDir = $this->fileSystemObj->ls($indexFilename); + $lsDirVals = array_values($lsDir); $lsFile = $this->fileSystemObj->ls("$finalSection.content.tmpl"); - if(is_array(array_values($lsDir))) { - //it's the dir. + + if(is_array(array_values($lsFile)) && is_array($lsFile[$finalSection .".content.tmpl"])) { + //it's the file ("{finalSection}.content.tmpl", like "mySection.content.tmpl") + $myIndex = $finalSection .".content.tmpl"; + } + elseif(is_array(array_values($lsDir)) && (is_array($lsDir[$indexFilename]))) { $myIndex = $indexFilename; - } elseif(is_array(array_values($lsFile))) { - //it's the file (no dir, or dir w/o index) - $myIndex = $finalSection.content.tmpl; - } else { + } + else { //nothin' doin'. $myIndex = NULL; } @@ -417,21 +428,35 @@ if(isset($myIndex)) { $valid = TRUE; $this->fileSystemObj->cd('/templates'); - } else { - $this->reason = __METHOD__ .": couldn't find page template for (". $this->section .", final=[$finalSection])..."; } - } else { - //just the base template. Make sure it's good. + else { + $this->reason = __METHOD__ .": couldn't find page template for ". $this->section; + } + } + else { + //if the baseDir is "help", this would try to use "/help/index.content.tmpl" $myFile = $this->baseDir .'/index.content.tmpl'; - $lsData = $this->fileSystemObj->ls($myFile); - if(isset($lsData[$myFile]) && $lsData[$myFile]['type'] == 'file') { + $sectionLsData = $this->fileSystemObj->ls($myFile); + + //if the baseDir is "help", this would try to use "/help.content.tmpl" + $sectionFile = $this->baseDir .'.content.tmpl'; + $lsData = $this->fileSystemObj->ls(); + + if(isset($lsData[$sectionFile]) && is_array($lsData[$sectionFile])) { + $valid = TRUE; + $this->finalSection = $this->baseDir; + } + elseif(isset($sectionLsData[$myFile]) && $sectionLsData[$myFile]['type'] == 'file') { //we're good. $valid = TRUE; $this->finalSection = $this->baseDir; - } else { + } + else { $this->reason = __METHOD__ .": couldn't find base template."; } } + $this->isValid = $valid; + return($valid); }//end validate_page() //------------------------------------------------------------------------ @@ -483,6 +508,10 @@ $this->templateList[$mySection] = $myTmpl; } } + if(isset($tmplList[$this->baseDir]['content'])) { + //load template for the main page (if $this->baseDir == "help", this would load "/help.content.tmpl" as content) + $this->templateList['content'] = $tmplList[$this->baseDir]['content']; + } } }//end load_page_templates() //------------------------------------------------------------------------ @@ -550,6 +579,7 @@ if(($myType == 'file') && !in_array($index, $this->ignoredList[$myType])) { $filename = $this->gfObj->create_list($this->fileSystemObj->cwd, $index, '/'); $filename = preg_replace('/^\/templates/', '', $filename); + $filename = preg_replace('/^\/\//', '/', $filename); //call another method to rip the filename apart properly, then arrange things as needed. $pieces = $this->parse_filename($index); $myPriIndex = $pieces[$primaryIndex]; @@ -684,9 +714,8 @@ } else { //TODO: make it *actually* die gracefully... the way it works now looks more like puke than grace. - $this->gfObj->debug_print(__METHOD__ .": something broke. \nDETAILS::: $details" . + throw new exception(__METHOD__ .": Couldn't find 404 template, plus additional error... \nDETAILS::: $details" . "\nREASON::: ". $this->reason); - exit; } }//end die_gracefully() //------------------------------------------------------------------------ @@ -735,15 +764,41 @@ //now include the includes scripts, if there are any. if(is_array($this->includesList) && count($this->includesList)) { - foreach($this->includesList as $myInternalIndex=>$myInternalScriptName) { - $this->myLastInclude = $myInternalScriptName; - include_once($this->myLastInclude); + try { + foreach($this->includesList as $myInternalIndex=>$myInternalScriptName) { + $this->myLastInclude = $myInternalScriptName; + include_once($this->myLastInclude); + } } + catch(exception $e) { + $myRoot = preg_replace('/\//', '\\\/', $this->fileSystemObj->root); + $displayableInclude = preg_replace('/^'. $myRoot .'/', '', $this->myLastInclude); + $this->templateObj->set_message_wrapper(array( + 'title' => "Fatal Error", + 'message' => __METHOD__ .": A fatal error occurred while processing <b>". + $displayableInclude ."</b>:<BR>\n<b>ERROR</b>: ". $e->getMessage(), + 'type' => "fatal" + )); + + //try to pass the error on to the user's exception handler, if there is one. + if(function_exists('exception_handler')) { + exception_handler($e); + } + } unset($myInternalIndex); unset($myInternalScriptName); } - $page->print_page(); + if(is_bool($this->templateObj->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) { + $this->isValid = $this->templateObj->allow_invalid_urls(); + } + + if($this->isValid === TRUE) { + $page->print_page(); + } + else { + $this->die_gracefully($this->reason); + } }//end finish() //------------------------------------------------------------------------ @@ -753,8 +808,7 @@ /** * Method for accessing the protected $this->sectionArr array. */ - public function get_sectionArr() - { + public function get_sectionArr() { //give 'em what they want. return($this->sectionArr); }//end get_sectionArr() @@ -766,8 +820,7 @@ /** * Method for accessing the protected member $this->finalSection. */ - public function get_finalSection() - { + public function get_finalSection() { //give 'em what they want. return($this->finalSection); }//end get_finalSection() @@ -779,8 +832,7 @@ /** * Method for accessing "baseDir", only referenced as the base section. */ - public function get_baseSection() - { + public function get_baseSection() { return($this->baseDir); }//end get_baseSection() //------------------------------------------------------------------------ Modified: releases/1.0/lib/cs-content/cs_bbCodeParser.class.php =================================================================== --- releases/1.0/lib/cs-content/cs_bbCodeParser.class.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/cs_bbCodeParser.class.php 2008-02-07 02:19:25 UTC (rev 794) @@ -5,11 +5,11 @@ * * SVN INFORMATION::: * ------------------ - * SVN Signature::::::: $Id: cs_bbCodeParser.class.php 173 2007-10-02 14:36:50Z crazedsanity $ + * SVN Signature::::::: $Id: cs_bbCodeParser.class.php 179 2007-10-04 22:31:43Z crazedsanity $ * Last Author::::::::: $Author: crazedsanity $ - * Current Revision:::: $Revision: 173 $ - * Repository Location: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/cs_bbCodeParser.class.php $ - * Last Updated:::::::: $Date: 2007-10-02 09:36:50 -0500 (Tue, 02 Oct 2007) $ + * Current Revision:::: $Revision: 179 $ + * Repository Location: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_bbCodeParser.class.php $ + * Last Updated:::::::: $Date: 2007-10-04 17:31:43 -0500 (Thu, 04 Oct 2007) $ * * * Originally from a snippet (just the function) on PHPFreaks.com: http://www.phpfreaks.com/quickcode/BBCode/712.php Modified: releases/1.0/lib/cs-content/cs_fileSystemClass.php =================================================================== --- releases/1.0/lib/cs-content/cs_fileSystemClass.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/cs_fileSystemClass.php 2008-02-07 02:19:25 UTC (rev 794) @@ -1,12 +1,12 @@ -<? +<?php /* * FILE INFORMATION: - * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/cs_fileSystemClass.php $ - * $Id: cs_fileSystemClass.php 170 2007-09-25 22:54:19Z crazedsanity $ - * $LastChangedDate: 2007-09-25 17:54:19 -0500 (Tue, 25 Sep 2007) $ + * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_fileSystemClass.php $ + * $Id: cs_fileSystemClass.php 252 2008-01-31 21:57:49Z crazedsanity $ + * $LastChangedDate: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ * $LastChangedBy: crazedsanity $ - * $LastChangedRevision: 170 $ + * $LastChangedRevision: 252 $ */ require_once(dirname(__FILE__) ."/cs_globalFunctions.php"); @@ -253,6 +253,7 @@ * can enlighten me, I'd be glad to give them credit. */ private function translate_perms($in_Perms) { + $sP = ""; $sP .= (($in_Perms & 0x0100) ? 'r' : '-') . (($in_Perms & 0x0080) ? 'w' : '-') . (($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) : @@ -307,11 +308,11 @@ $this->closeFile(); } else { - throw new exception(__METHOD__ .": unable to open specified file"); + throw new exception(__METHOD__ .": unable to open specified file (". $filename .")"); } } else { - throw new exception(__METHOD__ .": file is not writable"); + throw new exception(__METHOD__ .": Cannot truncate, file (". $filename .") is not writable"); } } return($retval); Modified: releases/1.0/lib/cs-content/cs_genericPageClass.php =================================================================== --- releases/1.0/lib/cs-content/cs_genericPageClass.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/cs_genericPageClass.php 2008-02-07 02:19:25 UTC (rev 794) @@ -1,11 +1,11 @@ <?php /* * FILE INFORMATION: - * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/cs_genericPageClass.php $ - * $Id: cs_genericPageClass.php 172 2007-10-01 16:24:17Z crazedsanity $ - * $LastChangedDate: 2007-10-01 11:24:17 -0500 (Mon, 01 Oct 2007) $ + * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_genericPageClass.php $ + * $Id: cs_genericPageClass.php 252 2008-01-31 21:57:49Z crazedsanity $ + * $LastChangedDate: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ * $LastChangedBy: crazedsanity $ - * $LastChangedRevision: 172 $ + * $LastChangedRevision: 252 $ */ require_once(dirname(__FILE__) ."/template.inc"); require_once(dirname(__FILE__) ."/cs_versionAbstract.class.php"); @@ -22,6 +22,8 @@ private $showEditableLink = FALSE; + private $allowInvalidUrls=NULL; + //--------------------------------------------------------------------------------------------- /** * The constructor. @@ -65,7 +67,7 @@ $this->add_template_var($key, $value); } } - if(is_array($GLOBALS['templateFiles'])) { + if(isset($GLOBALS['templateFiles']) && is_array($GLOBALS['templateFiles'])) { foreach($GLOBALS['templateFiles'] as $key => $value) { $this->templateFiles[$key] = $value; } @@ -257,7 +259,7 @@ if($stripUndefVars) { $numLoops = 0; - while(preg_match_all('/\{.*?\}/', $this->templateObj->varvals[out], $tags) && $numLoops < 50) { + while(preg_match_all('/\{.\S+?\}/', $this->templateObj->varvals['out'], $tags) && $numLoops < 50) { $tags = $tags[0]; //TODO: figure out why this works when running it twice. @@ -286,8 +288,9 @@ */ public function process_set_message() { //if there's not a message set, skip. - $errorBox = $this->file_to_string("system/message_box.tmpl"); - if(is_array($_SESSION['message'])) { + $errorBox = ""; + if(isset($_SESSION['message']) && is_array($_SESSION['message'])) { + $errorBox = $this->file_to_string("system/message_box.tmpl"); //let's make sure the "type" value is *lowercase*. $_SESSION['message']['type'] = strtolower($_SESSION['message']['type']); @@ -307,6 +310,7 @@ // they'll never get past this point). unset($_SESSION['message']); } + return($errorBox); }//end of process_set_message() //--------------------------------------------------------------------------------------------- @@ -595,6 +599,17 @@ return($retval); }//end set_all_block_rows() //--------------------------------------------------------------------------------------------- + + + + //--------------------------------------------------------------------------------------------- + public function allow_invalid_urls($newSetting=NULL) { + if(!is_null($newSetting) && is_bool($newSetting)) { + $this->allowInvalidUrls = $newSetting; + } + return($this->allowInvalidUrls); + }//end allow_invalid_urls() + //--------------------------------------------------------------------------------------------- }//end cs_genericPage{} ?> Modified: releases/1.0/lib/cs-content/cs_globalFunctions.php =================================================================== --- releases/1.0/lib/cs-content/cs_globalFunctions.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/cs_globalFunctions.php 2008-02-07 02:19:25 UTC (rev 794) @@ -82,9 +82,10 @@ */ public function string_from_array($array,$style=NULL,$separator=NULL, $cleanString=NULL, $removeEmptyVals=FALSE) { + $retval = NULL; //precheck... if it's not an array, kill it. if(!is_array($array)) { - return(0); + return(NULL); } //make sure $style is valid. @@ -167,7 +168,7 @@ $value = $this->cleanString($value, "sql"); $value = "'". $value ."'"; } - $retval = $this->create_list($retval, $field . $separator . $value, " "); + $retval = $this->create_list($retval, $value, ", "); } if($style == "order" && !preg_match('/order by/', strtolower($retval))) { $retval = "ORDER BY ". $retval; @@ -271,7 +272,7 @@ } else { //not an array. - $retval = 0; + $retval = NULL; } return($retval); @@ -639,6 +640,49 @@ }//end truncate_string() //--------------------------------------------------------------------------------------------- + + + + //########################################################################## + public function array_as_option_list(array $data, $checkedValue=NULL, $type="select", $useTemplateString=NULL, array $repArr=NULL) { + $typeArr = array ( + "select" => "selected", + "radio" => "checked", + "checkbox" => "checked" + ); + + $myType = $typeArr[$type]; + if(is_null($useTemplateString)) { + // + $useTemplateString = "\t\t<option value='%%value%%'%%selectedString%%>%%display%%</option>"; + } + + $retval = ""; + foreach($data as $value=>$display) { + //see if it's the value that's been selected. + $selectedString = ""; + if($value == $checkedValue || $display == $checkedValue) { + //yep, it's selected. + $selectedString = " ". $myType; + } + + //create the string. + $myRepArr = array( + 'value' => $value, + 'display' => $display, + 'selectedString' => $selectedString + ); + if(is_array($repArr) && is_array($repArr[$value])) { + //merge the arrays. + $myRepArr = array_merge($repArr[$value], $myRepArr); + } + $addThis = $this->mini_parser($useTemplateString, $myRepArr, "%%", "%%"); + $retval = $this->create_list($retval, $addThis, "\n"); + } + + return($retval); + }//end array_as_option_list() + //########################################################################## }//end cs_globalFunctions{} Modified: releases/1.0/lib/cs-content/cs_phpDB.php =================================================================== --- releases/1.0/lib/cs-content/cs_phpDB.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/cs_phpDB.php 2008-02-07 02:19:25 UTC (rev 794) @@ -4,9 +4,9 @@ * A class for generic PostgreSQL database access. * * SVN INFORMATION::: - * SVN Signature:::::::: $Id: cs_phpDB.php 154 2007-09-12 18:43:16Z crazedsanity $ - * Last Committted Date: $Date: 2007-09-12 13:43:16 -0500 (Wed, 12 Sep 2007) $ - * Last Committed Path:: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/cs_phpDB.php $ + * SVN Signature:::::::: $Id: cs_phpDB.php 252 2008-01-31 21:57:49Z crazedsanity $ + * Last Committted Date: $Date: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ + * Last Committed Path:: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_phpDB.php $ * */ @@ -24,1062 +24,59 @@ // /////////////////////// +//TODO: option to not use layered transactions +//TODO: rollbackTrans() in layered transaction causes abort when final layer is committed/aborted +//TODO: stop sending queries to backend when transction is bad/aborted. +//TODO: commit/abort specific layer requests (i.e. if there's 8 layers & the first is named "x", calling commitTrans("x") will cause the whole transaction to commit & all layers to be destroyed. + require_once(dirname(__FILE__) ."/cs_versionAbstract.class.php"); class cs_phpDB extends cs_versionAbstract { - - /** Internal result set pointer. */ - protected $result = NULL; - /** Internal error code. */ - protected $errorCode = 0; + private $dbLayerObj; + private $dbType; - /** Status of the current transaction. */ - protected $transStatus = NULL; - - /** Whether there is a transaction in progress or not. */ - protected $inTrans = FALSE; - - /** Holds the last query performed. */ - protected $lastQuery = NULL; - - /** List of queries that have been run */ - protected $queryList=array(); - - /** How many seconds to wait for a query before cancelling it. */ - protected $timeOutSeconds = NULL; - - /** Internal check to determine if a connection has been established. */ - protected $isConnected=FALSE; - - /** Internal check to determine if the parameters have been set. */ - protected $paramsAreSet=FALSE; - - /** Resource handle. */ - protected $connectionID = -1; - - /** Hostname or IP to connect to */ - protected $host; - - /** Port to connect to (default for Postgres is 5432) */ - protected $port; - - /** Name of the database */ - protected $dbname; - - /** Username to connect to the database */ - protected $user; - - /** password to connect to the database */ - protected $password; - - /** Row counter for looping through records */ - protected $row = -1; - - /** cs_globalFunctions object, for string stuff. */ - protected $gfObj; - - /** Internal check to ensure the object has been properly created. */ - protected $isInitialized=FALSE; - - /** List of prepared statements, indexed off the name, with the sub-array being fieldname=>dataType. */ - protected $preparedStatements = array(); - - /** Set to TRUE to save all queries into an array. */ - protected $useQueryList=FALSE; - - //////////////////////////////////////////// - // Core primary connection/database function - //////////////////////////////////////////// - - //========================================================================= - public function __construct() { - $this->gfObj = new cs_globalFunctions; - $this->gfObj->debugRemoveHr=0; - $this->gfObj->debugPrintOpt=0; + public function __construct($type='pgsql') { - $this->isInitialized = TRUE; - }//end __construct() - //========================================================================= - - - - //========================================================================= - /** - * Make sure the object is sane. - */ - final protected function sanity_check() { - if($this->isInitialized !== TRUE) { - throw new exception(__METHOD__ .": not properly initialized"); - } - }//end sanity_check() - //========================================================================= - - - - //========================================================================= - /** - * Set appropriate parameters for database connection - */ - public function set_db_info(array $params){ - $this->sanity_check(); - $required = array('host', 'port', 'dbname', 'user', 'password'); - - $requiredCount = 0; - foreach($params as $index=>$value) { - if(property_exists($this, $index) && in_array($index, $required)) { - $this->$index = $value; - $requiredCount++; - } - else { - throw new exception(__METHOD__. ": property (". $index .") does " . - "not exist or isn't allowed"); - } - } - - if($requiredCount == count($required)) { - $this->paramsAreSet = TRUE; - } - else { - throw new exception(__METHOD__ .": required count (". $requiredCount - .") does not match required number of fields (". count($required) .")"); - } - }//end set_db_info() - //========================================================================= - - - - //========================================================================= - /** - * Wrapper for close() - */ - function disconnect() { - //Disconnect from $database - return($this->close()); - }//end disconnect() - //========================================================================= - - - - //========================================================================= - /** - * Standard method to close connection. - */ - function close() { - $this->isConnected = FALSE; - $retval = null; - if($this->connectionID != -1) { - $retval = pg_close($this->connectionID); - } - else { - throw new exception(__METHOD__ .": Failed to close connection: connection is invalid"); - } - - return($retval); - }//end close() - //========================================================================= - - - - //========================================================================= - /** - * Connect to the database - */ - function connect(array $dbParams=NULL, $forceNewConnection=FALSE){ - $this->sanity_check(); - $retval = NULL; - if(is_array($dbParams)) { - $this->set_db_info($dbParams); - } - - if($this->paramsAreSet === TRUE && $this->isConnected === FALSE) { + if(strlen($type)) { - $myConnArr = array( - 'host' => $this->host, - 'port' => $this->port, - 'dbname' => $this->dbname, - 'user' => $this->user, - 'password' => $this->password - ); + require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php'); + $className = __CLASS__ .'__'. $type; + $this->dbLayerObj = new $className; + $this->dbType = $type; - //make it into a string separated by spaces, don't clean anything, remove null elements - $connStr = $this->gfObj->string_from_array($myConnArr, 'url', " "); + $this->gfObj = new cs_globalFunctions; - //start output buffer for displaying error. - ob_start(); - if($forceNewConnection) { - $connID = pg_connect($connStr, PGSQL_CONNECT_FORCE_NEW); + if(defined('DEBUGPRINTOPT')) { + $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; } - else { - $connID =pg_connect($connStr); - } - $connectError = ob_get_contents(); - ob_end_clean(); - if(is_resource($connID)) { - $this->errorCode=0; - $this->connectionID = $connID; - $this->isConnected = TRUE; - $retval = $this->connectionID; - } - else { - throw new exception(__METHOD__ .": FATAL ERROR: ". $connectError); - } + $this->isInitialized = TRUE; } else { - throw new exception(__METHOD__ .": paramsAreSet=(". $this->paramsAreSet ."), isConnected=(". $this->isConnected .")"); + throw new exception(__METHOD__ .": failed to give a type (". $type .")"); } - - return($retval); - }//end connect() + }//end __construct() //========================================================================= //========================================================================= - function get_hostname() { - $this->sanity_check(); - return($this->host); - }//end get_hostname() - //========================================================================= - - - - //========================================================================= - /** - * Run sql queries - * - * TODO: re-implement query logging (setting debug, logfilename, etc). - */ - function exec($query) { - $this->lastQuery = $query; - if($this->useQueryList) { - $this->queryList[] = $query; - } - $returnVal = false; - - if(($this->get_transaction_status() != -1) && ($this->connectionID != -1)) { - $this->result = @pg_query($this->connectionID, $query); - - if($this->result !== false) { - if (eregi("^[[:space:]]*select", $query)) { - //If we didn't have an error and we are a select statement, move the pointer to first result - $numRows = $this->numRows(); - if($numRows > 0) { - $this->move_first(); - } - $returnVal = $numRows; - - } - else { - //We got something other than an update. Use numAffected - $returnVal = $this->numAffected(); - } - } - } - return($returnVal); - }//end exec() - //========================================================================= - - - - //========================================================================= /** - * Returns any error caused by the last executed query. - * - * @return NULL OK: no error - * @return (string) FAIL: contains error returned from the query. + * Magic method to call methods within the database abstraction layer ($this->dbLayerObj). */ - function errorMsg($setMessage=NULL,$logError=NULL) { - $this->sanity_check(); - if ($this->connectionID < 0) { - switch ($this->errorCode) { - //############################################### - case -1: - $retVal = "FATAL ERROR - CONNECTION ERROR: RESOURCE NOT FOUND"; - break; - //############################################### - - //############################################### - case -2: - $retVal = "FATAL ERROR - CLASS ERROR: FUNCTION CALLED WITHOUT PARAMETERS"; - break; - //############################################### - - //############################################### - case -3: - $retVal = "Query exceeded maximum timeout (". $this->timeoutSeconds .")"; - break; - //############################################### - - //############################################### - default: - $retVal = null; - //############################################### - } - } else { - $retVal = pg_last_error($this->connectionID); + public function __call($methodName, $args) { + if(method_exists($this->dbLayerObj, $methodName)) { + $retval = call_user_func_array(array($this->dbLayerObj, $methodName), $args); } - - return($retVal); - }//end errorMsg() - //========================================================================= - - - - - //////////////////// - // Cursor movement - //////////////////// - - - - - //========================================================================= - /** - * move pointer to first row of result set - */ - function move_first() { - $this->sanity_check(); - if($this->result == NULL) { - $retval = FALSE; - } else { - $this->set_row(0); - $retval = TRUE; + throw new exception(__METHOD__ .': unsupported method ('. $methodName .') for database of type ('. $this->dbType .')'); } - return($retval); - }//end move_first() + }//end __call() //========================================================================= - - - //========================================================================= - /** - * move pointer to last row of result set - */ - function move_last() { - $this->sanity_check(); - if($this->result == NULL) { - $retval = FALSE; - } - else { - $this->set_row($this->numRows()-1); - $retval = TRUE; - } - - return($retval); - }//end move_list() - //========================================================================= - - - - //========================================================================= - /** - * point to the next row, return false if no next row - */ - function move_next() { - $this->sanity_check(); - // If more rows, then advance row pointer - if($this->row < $this->numRows()-1) { - $this->set_row($this->row +1); - $retval = TRUE; - } - else { - $retval = FALSE; - } - - return($retval); - }//end move_next() - //========================================================================= - - - - //========================================================================= - /** - * point to the previous row, return false if no previous row - */ - function move_previous() { - // If not first row, then advance row pointer - if ($this->row > 0) { - $this->set_row($this->row -1); - return true; - } - else return false; - }//end move_previous() - //========================================================================= - - - - //========================================================================= - // point to the next row, return false if no next row - function next_row() { - // If more rows, then advance row pointer - if ($this->row < $this->numRows()-1) { - $this->set_row($this->row +1); - return true; - } - else return false; - }//end next_row() - //========================================================================= - - - - //========================================================================= - // can be used to set a pointer to a perticular row - function set_row($row){ - if(is_numeric($row)) { - $this->row = $row; - } - else { - throw new exception(__METHOD__ .": invalid data for row (". $row .")"); - } - return($this->row); - }//end set_row(); - //========================================================================= - - - - - /////////////////////// - // Result set related - /////////////////////// - - - - //========================================================================= - /** - * Return the current row as an object. - */ - function fobject() { - $this->sanity_check(); - if($this->result == NULL || $this->row == -1) { - $retval = NULL; - } - else { - $retval = pg_fetch_object($this->result, $this->row); - } - - return($retval); - } - //========================================================================= - - - - //========================================================================= - /** - * Fetch the current row as an array containing fieldnames AND numeric indexes. - */ - function farray(){ - if($this->result == NULL || $this->row == -1) { - $retval = NULL; - } - else { - $retval = pg_fetch_array($this->result,$this->row); - } - - return($retval); - }//end farray() - //========================================================================= - - - - //========================================================================= - /** - * Another way to retrieve a single row (useful for loops). - */ - function frow(){ - $this->sanity_check(); - if($this->numRows() <= 0) { - $retval = NULL; - } - else { - if($this->result == null || $this->row == -1) { - $retval = NULL; - } - else { - $retval = pg_fetch_row($this->result, $this->row); - } - } - - return($retval); - }//end frow() - //========================================================================= - - - - //========================================================================= - /** - * Similar to farray(), except all indexes are non-numeric, and the entire - * result set is retrieved: if only one row is available, no numeric index - * is set, unless $numbered is TRUE. - * - * TODO: clean this up! - */ - function farray_fieldnames($index=NULL, $numbered=NULL,$unsetIndex=1) { - $this->sanity_check(); - $retval = NULL; - - //before we get too far, let's make sure there's something there. - if($this->numRows() <= 0) { - $retval = 0; - } - else { - //keep any errors/warnings from printing to the screen by using OUTPUT BUFFERS. - ob_start(); - - $x = 0; - do { - $temp = $this->farray(); - foreach($temp as $key=>$value) { - //remove the numbered indexes. - if(is_string($key)) { - $tArr[$key] = $value; - } - } - $newArr[$x] = $tArr; - $x++; - } - while($this->next_row()); - - if($index) { - foreach($newArr as $row=>$contents) { //For each of the returned sets of information - foreach($contents as $fieldname=>$value) { //And now for each of the items in that set - if($fieldname == $index) { - //The index for the new array will be this fieldname's value - $arrayKey = $value; - } - - $tempContent[$fieldname] = $value; - //don't include the "index" field in the subarray; that always seems to end badly. - if ($unsetIndex) { - unset($tempContent[$index]); - } - } - - if (!isset($tempArr[$arrayKey])) { - //Make sure we didn't already set this in the array. If so, then we don't have a unique variable to use for the array index. - $tempArr[$arrayKey] = $tempContent; - } - else { - //TODO: bigtime cleaning... should only return at the bottom of the method. - $retval = 0; - break; - } - $arrayKey = NULL; //Blank this out after using it, just in case we don't find one in the next iteration - } - - if (count($tempArr) != count($newArr)) { - $details = "farray_fieldnames(): Array counts don't match.<BR>\n" - ."FUNCTION ARGUMENTS: index=[$index], numbered=[$numbered], unsetIndex=[$unsetIndex]<BR>\n" - ."LAST QUERY: ". $this->lastQuery; - throw new exception(__METHOD__ .": $details"); - } - $newArr = $tempArr; - } - //this is where, if there's only one row (and the planets align just the way - // I like them to), there's no row w/ a sub-array... This is only done - // if $index is NOT set... - if(($this->numRows() == 1) AND (!$index) AND (!$numbered)) { - $newArr = $newArr[0]; - } - $retval = $newArr; - ob_end_clean(); - } - return($retval); - }//end farray_fieldnames() - //========================================================================= - - - - //========================================================================= - /** - * Uses farray_fieldnames() to retrieve the entire result set, but the final - * array is contains name=>value pairs. - */ - function farray_nvp($name, $value) { - if((!$name) OR (!$value)) { - $retval = 0; - } - else { - $tArr = $this->farray_fieldnames(NULL,1); - if(!is_array($tArr)) { - $retval = 0; - } - else { - //loop through it & grab the proper info. - $retval = array(); - foreach($tArr as $row=>$array) { - $tKey = $array[$name]; - $tVal = $array[$value]; - $retval[$tKey] = $tVal; - } - } - } - - //return the new array. - return($retval); - }//end farray_nvp() - //========================================================================= - - - - //========================================================================= - /** - * Similar to farray_fieldnames(), but only returns the NUMERIC indexes - */ - function farray_numbered() { - do { - $temp = $this->frow(); - $retArr[] = $temp[0]; - } - while($this->next_row()); - - return($retArr); - }//end farray_numbered() - //========================================================================= - - - - //========================================================================= - /** - * Returns the number of tuples affected by an insert/delete/update query. - * NOTE: select queries must use numRows() - */ - function numAffected() { - if($this->result == null) { - $retval = 0; - } else { - $this->affectedRows = pg_affected_rows($this->result); - $retval = $this->affectedRows; - } - - return($retval); - }//end numAffected() - //========================================================================= - - - - //========================================================================= - /** - * Returns the number of rows in a result (from a SELECT query). - */ - function numRows() { - if ($this->result == null) { - $retval = 0; - } - else { - $this->numrows = pg_num_rows($this->result); - $retval = $this->numrows; - } - - return($retval); - }//end numRows() - //========================================================================= - - - - //========================================================================= - /** - * wrapper for numAffected() - */ - function affectedRows(){ - return($this->numAffected()); - }//end affectedRows() - //========================================================================= - - - - //========================================================================= - /** - * Returns the current row number. - */ - function currRow(){ - return($this->row); - }//end currRow() - //========================================================================= - - - - //========================================================================= - /** - * Get the number of fields in a result. - */ - // get the number of fields in a result - function num_fields() { - if($this->result == null) { - $retval = 0; - } - else { - $retval = pg_num_fields($this->result); - } - return($retval); - }//end num_fields() - //========================================================================= - - - - //========================================================================= - function column_count() { - return($this->numFields()); - }//end column_count() - //========================================================================= - - - - //========================================================================= - /** - * get last OID (object identifier) of last INSERT statement - */ - function lastOID($doItForMe=0, $field=NULL) { - if($this->result == NULL) { - $retval = NULL; - } - else { - $tOid = pg_last_oid($this->result); - $retval = $tOid; - - if(($doItForMe) AND (eregi("^insert", $this->last_query))) { - //attempt to parse the insert statement, then select - // all fields (unless $field is set) from it. - $t = split(" into ", strtolower($this->last_query)); - $t = split(" ", $t[1]); - $t = split("\(", $t[0]); - $table = $t[0]; - - //now we have the table. - if(!$field) { - $field = "*"; - } - $query = "SELECT $field FROM $table WHERE OID=$tOid"; - $this->exec($query); - $dberror = $this->errorMsg(1,1,1,"lastOID(): "); - - if(!$dberror) { - $res = $this->farray(); - if(is_string($field)) { - $retval = $res[0]; - } - } - } - } - return($retval); - }//end lastOID() - //========================================================================= - - - - //========================================================================= - /** - * get result field name of the given field number. - */ - // get result field name - function fieldname($fieldnum) { - if($this->result == NULL) { - $retval =NULL; - } - else { - $retval = pg_field_name($this->result, $fieldnum); - } - - return($retval); - }//end fieldname() - //========================================================================= - - - - - //////////////////////// - // Transaction related - //////////////////////// - - - - - //========================================================================= - /** - * Start a transaction. - */ - function beginTrans() { - $this->inTrans = TRUE; - return($this->exec("BEGIN")); - }//end beginTrans() - //========================================================================= - - - - //========================================================================= - /** - * Commit a transaction. - */ - function commitTrans() { - $retval = $this->get_transaction_status(); - if($retval > 1) { - $retval = 1; - } - $this->exec("COMMIT"); - $this->get_transaction_status(); - return($retval); - }//end commitTrans() - //========================================================================= - - - - //========================================================================= - // returns true/false - function rollbackTrans() { - $retval = $this->exec("ABORT"); - $this->get_transaction_status(); - return($retval); - }//end rollbackTrans() - //========================================================================= - - - - //////////////////////// - // SQL String Related - //////////////////////// - - - - //========================================================================= - /** - * Gets rid of evil characters that might lead ot SQL injection attacks. - */ - function querySafe($string) { - return($this->gfObj->cleanString($string,"query")); - }//end querySafe() - //========================================================================= - - - - //========================================================================= - /** - * Make it SQL safe. - */ - function sqlSafe($string) { - return($this->gfObj->cleanString($string,"sql")); - }//end sqlSafe() - //========================================================================= - - - - //========================================================================= - /** - * Gives textual explanation of the current status of our database - * connection. - * - * @param $goodOrBad (bool,optional) return good/bad status. - * - * @return (-1) (FAIL) connection is broken - * @return (0) (FAIL) error was encountered (transient error) - * @return (1) (PASS) useable - * @return (2) (PASS) useable, but not just yet (working - * on something) - */ - function get_transaction_status($goodOrBad=TRUE) { - $myStatus = pg_transaction_status($this->connectionID); - $text = 'unknown'; - switch($myStatus) { - case PGSQL_TRANSACTION_IDLE: { - //No query in progress: it's idle. - $goodOrBadValue = 1; - $text = 'idle'; - $this->inTrans = FALSE; - } - break; - - - case PGSQL_TRANSACTION_ACTIVE: { - //there's a command in progress. - $goodOrBadValue = 2; - $text = 'processing'; - } - break; - - - case PGSQL_TRANSACTION_INTRANS: { - //connection idle within a valid transaction block. - $goodOrBadValue = 1; - $text = 'valid transaction'; - $this->inTrans = TRUE; - } - break; - - - case PGSQL_TRANSACTION_INERROR: { - //connection idle within a broken transaction. - $goodOrBadValue = 0; - $text = 'failed transaction'; - $this->inTrans = TRUE; - } - break; - - - case PGSQL_TRANSACTION_UNKNOWN: - default: { - //the connection is bad. - $goodOrBadValue = -1; - $text = 'bad connection'; - } - break; - } - - //do they want text or the good/bad number? - $retval = $text; - $this->transactionStatus = $goodOrBadValue; - if($goodOrBad) { - //they want the number. - $retval = $goodOrBadValue; - } - - return($retval); - }//end valid_transaction() - //========================================================================= - - - - //========================================================================= - public function is_connected() { - $retval = FALSE; - if(is_resource($this->connectionID) && $this->isConnected === TRUE) { - $retval = TRUE; - } - - return($retval); - }//end is_connected() - //========================================================================= - - - - //========================================================================= - /** - * Create a prepared statement. - */ - public function create_prepared_statement($planName,array $fieldToType, $statement) { - $retval = FALSE; - //store the mappings. - $this->preparedStatements[$planName] = $fieldToType; - - //TODO: check that the string in "$statement" has the same number of "${n}" as are in "$fieldToType". - - $dataTypeString = ""; - foreach($fieldToType as $field => $type) { - $dataTypeString = $this->gfObj->create_list($dataTypeString, $type, ", "); - } - - $sql = "PREPARE ". $planName ."(". $dataTypeString .") AS ". $statement; - - $myNumrows = $this->exec($sql); - $myDberror = $this->errorMsg(); - - if(!strlen($myDberror)) { - $retval = TRUE; - } - else { - throw new exception(__METHOD__ .": failed to create prepared statement '". $planName ."'... dberror::: ". $myDberror ."\n\nSQL::: ". $sql); - } - - return($retval); - }//end create_prepared_statement() - //========================================================================= - - - - //========================================================================= - /** - * Run a statement prepared by this object. - * - * NOTE: determination of rows affected (numAffected) vs. rows returned (numRows) - * must be done by the user via the referenced methods. - */ - public function run_prepared_statement($name, array $data) { - $retval = FALSE; - if(is_array($this->preparedStatements[$name]) && count($data) == count($this->preparedStatements[$name])) { - $this->result = pg_execute($this->connectionID, $name, $data); - $dberror = $this->errorMsg(); - - if(!strlen($dberror)) { - $retval = TRUE; - } - } - else { - throw new exception(__METHOD__ .": invalid statement name (". $name ."), or incorrect number of elements"); - } - - return($retval); - }//end run_prepared_statement() - //========================================================================= - - - - //========================================================================= - /** - * Starts a copy command. - * - * TODO: implement safeguards so they can only put a line until the copy is ended. - */ - public function start_copy($tableName, array $fields) { - $retval = FALSE; - $copyStmt = "COPY ". $tableName ." (". $this->gfObj->string_from_array($fields, NULL, ", ") . ") FROM stdin;"; - $this->exec($copyStmt); - if(!strlen($this->errorMsg())) { - //TODO: set something here so that NOTHING ELSE can be done except put_line() and end_copy(). - $this->copyInProgress = TRUE; - $retval = TRUE; - } - else { - $this->end_copy(); - $retval = FALSE; - } - - return($retval); - }//end start_copy() - //========================================================================= - - - - //========================================================================= - /** - * Used to send a line to the COPY in progress (only if it was initiated by - * the internal start_copy() method). - * - * NOTE: the "end-of-copy" line, '\.', should NEVER be sent here. - */ - public function put_line($line) { - $retval = FALSE; - if($this->copyInProgress === TRUE) { - $myLine = trim($line); - $myLine .= "\n"; - - $retval = pg_put_line($this->connectionID, $myLine); - } - else { - throw new exception(__METHOD__ .": cannot send line if no copy is in progress"); - } - - return($retval); - }//end put_line() - //========================================================================= - - - - //========================================================================= - public function end_copy() { - if($this->copyInProgress === TRUE) { - //send the end-of-copy line... - $this->put_line("\\.\n"); - } - - $retval = pg_end_copy($this->connectionID); - - return($retval); - }//end end_copy() - //========================================================================= - - } // end class phpDB ?> Modified: releases/1.0/lib/cs-content/cs_sessionClass.php =================================================================== --- releases/1.0/lib/cs-content/cs_sessionClass.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/cs_sessionClass.php 2008-02-07 02:19:25 UTC (rev 794) @@ -1,11 +1,11 @@ <?php /* * FILE INFORMATION: - * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/cs_sessionClass.php $ - * $Id: cs_sessionClass.php 161 2007-09-19 02:49:28Z crazedsanity $ - * $LastChangedDate: 2007-09-18 21:49:28 -0500 (Tue, 18 Sep 2007) $ + * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_sessionClass.php $ + * $Id: cs_sessionClass.php 221 2007-11-21 17:39:01Z crazedsanity $ + * $LastChangedDate: 2007-11-21 11:39:01 -0600 (Wed, 21 Nov 2007) $ * $LastChangedBy: crazedsanity $ - * $LastChangedRevision: 161 $ + * $LastChangedRevision: 221 $ */ require_once(dirname(__FILE__) ."/cs_versionAbstract.class.php"); @@ -18,6 +18,11 @@ public $sid_check = 1; //--------------------------------------------------------------------------------------------- + /** + * The constructor. + * + * @param $createSession (boolean,optional) determines if a session will be started or not. + */ function __construct($createSession=1) { if($createSession) { //now actually create the session. @@ -41,10 +46,91 @@ //--------------------------------------------------------------------------------------------- + /** + * Required method, so passing the object to contentSystem::handle_session() + * will work properly. + * + * @param (none) + * + * @return FALSE FAIL: user is not authenticated (hard-coded this way). + */ public function is_authenticated() { return(FALSE); }//end is_authenticated() //--------------------------------------------------------------------------------------------- + + + + //--------------------------------------------------------------------------------------------- + /** + * Retrieve data for an existing cookie. + * + * @param $name (string) Name of cookie to retrieve value for. + * + * @return NULL FAIL (?): cookie doesn't exist or has NULL value. + * @return (string) PASS: value of cookie. + */ + public function get_cookie($name) { + $retval = NULL; + if(isset($_COOKIE) && $_COOKIE[$name]) { + $retval = $_COOKIE[$name]; + } + return($retval); + }//end get_cookie() + //--------------------------------------------------------------------------------------------- + + + + //--------------------------------------------------------------------------------------------- + /** + * Create a new cookie. + * + * @param $name (string) Name of cookie + * @param $value (string) value of cookie + * @param $expiration (string/number) unix timestamp or value for strtotime(). + */ + public function create_cookie($name, $value, $expiration=NULL) { + + $expTime = NULL; + if(!is_null($expiration)) { + if(is_numeric($expiration)) { + $expTime = $expiration; + } + elseif(preg_match('/ /', $expiration)) { + $expTime = strtotime($expiration); + } + else { + throw new exception(__METHOD__ .": invalid timestamp given (". $expiration .")"); + } + } + + $retval = setcookie($name, $value, $expTime, '/'); + return($retval); + + }//end create_cookie() + //--------------------------------------------------------------------------------------------- + + + + //--------------------------------------------------------------------------------------------- + /** + * Destroy (expire) an existing cookie. + * + * @param $name (string) Name of cookie to destroy + * + * @return FALSE FAIL: no cookie by that name. + * @return TRUE PASS: cookie destroyed. + */ + public function drop_cookie($name) { + $retval = FALSE; + if(isset($_COOKIE[$name])) { + setcookie($name, $_COOKIE[$name], time() -10000, '/'); + unset($_COOKIE[$name]); + $retval = TRUE; + } + return($retval); + }//end drop_cookie() + //--------------------------------------------------------------------------------------------- }//end cs_session{} Modified: releases/1.0/lib/cs-content/cs_versionAbstract.class.php =================================================================== --- releases/1.0/lib/cs-content/cs_versionAbstract.class.php 2008-02-07 02:17:02 UTC (rev 793) +++ releases/1.0/lib/cs-content/cs_versionAbstract.class.php 2008-02-07 02:19:25 UTC (rev 794) @@ -5,9 +5,9 @@ * SVN INFORMATION::: * ------------------- * Last Author::::::::: $Author: crazedsanity $ - * Current Revision:::: $Revision: 155 $ - * Repository Location: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.9.0/cs_versionAbstract.class.php $ - * Last Updated:::::::: $Date: 2007-09-12 14:28:20 -0500 (Wed, 12 Sep 2007) $ + * Current Revision:::: $Revision: 221 $ + * Repository Location: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_versionAbstract.clas... [truncated message content] |