[Openfirst-cvscommit] base/includes .cvsignore,NONE,1.1.2.2 compatibility.php,NONE,1.3.2.2 functions
Brought to you by:
xtimg
Update of /cvsroot/openfirst/base/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20526/includes Modified Files: Tag: REL1_1_BRANCH auth.php dbase.php Added Files: Tag: REL1_1_BRANCH .cvsignore compatibility.php functions.php globals.php sitesettings.tpl Log Message: Updated globals.php, auth.php, and partly dbase.php. Added functions.php and compatibility.php in the process Updated install system. --- NEW FILE: sitesettings.tpl --- <?php /* * openFIRST base configuration file * This file has been automatically generated by first.php. * it contains the basic configuration options required to * operate the OpenFIRST web portal software. Note, that * most configuration options are now stored in the MySQL * database, in the ofirst_config table. */ $dbasetype = %DBTYPE%; $encryption = %ENCRYPT%; $title = %TITLE%; $version = %VER%; $sqlserver = %DBSERVER%; $sqluser = %DBUSER%; $sqlpassword = %DBPASS%; $sqldatabase = %DBNAME%; $pass_save_disabled = %COOKIE%; $regenabled = %REG%; $server = %SERVER%; $basepath = %BASEPATH%; $fbasepath = %FBASEPATH%; $home = %HOME%; $ogStylePath = "$BasePath/style"; $ogFStylePath = "$fBasePath/style"; $header = %HEADER%; $footer = %FOOTER%; $mailnotify = %MASTERMAIL%; $mailfrom = %BOTMAIL%; ?> --- NEW FILE: functions.php --- <?php /* * openFIRST.base - includes/functions.php * * Copyright (C) 2003, * openFIRST Project * Original Author: Jamie Bliss <ja...@op...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ // Purpose: Provide global functions to openFIRST /** Replaces standard vars in config text. * Currently includes $BasePath, $fBasePath, * $StylePath, $fStylePath, $ModPath, and $fModPath. */ function ofReplaceVariables($text, $ModuleDir = false) { if ($ModuleDir === false) { global $CurrentModule; if (is_object($CurrentModule)) $ModuleDir == $CurrentModule->getDir(); } global $BasePath, $fBasePath, $StylePath, $fStylePath; $find = array('$BasePath', '$fBasePath', '$StylePath', '$fStylePath', '$ModPath', '$fModPath', '$DirName' ); $replace = array($BasePath, $fBasePath, $StylePath, $fStylePath, "$BasePath/$ModuleDir", "$fBasePath/$ModuleDir", "$ModuleDir" ); return str_ireplace($find, $replace, $text); } /** Formats the size of computer data. * Uses the units: KB, MB, GB, etc. * Uses 1024 definition (1 KB = 1024 B) */ function ofFormatSize($size) { $base = 1024; $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'XB', false, 'VB' ); $units = array_reverse($units, true); reset($units); while (list($pow, $unit) = each($units)) { if ($unit === false) continue; if ($size >= pow($base, $pow)) { $unitsize = $size/pow($base, $pow); $unitsize = rtrim($unitsize, '0'); if (substr($unitsize, -1) == '.') $unitsize = substr($unitsize, 0, -1); return number_format($unitsize, 2, '.', '').' '.$unit; } } } /** Strip line comment. * Given a string and an array of commentors (in PHP, it would be array('#', '//')), * remove all end-of-line comments. * Now handles multiple lines */ function ofStripLineComment($commentors, $text) { $rtn = array(); $lines = explode(array("\r\n","\n","\r"), $text); foreach($lines as $line) { $parts = explode($commentors, $line, 2); $rtn[] = $parts[0]; } return implode(PHP_EOL, $rtn); } /** Converts input to boolean * returns true on: yes, y, true, 1 * returns false on: no, n, false, 0 * returns nothing if neither (return;). * if a value is in both $moretrue and $morefalse, it is treated as true * case-insensitive */ function ofConvert2Bool($text, $moretrue=array(), $morefalse=array()) { $yesvals = $moretrue; $yesvals[] = 'yes'; $yesvals[] = 'y'; $yesvals[] = 'true'; $yesvals[] = '1'; $novals = $morefalse; $novals[] = 'no'; $novals[] = 'n'; $novals[] = 'false'; $novals[] = '0'; foreach ($yesvals as $val) { if (strcasecmp($text, $val) == 0) return true; } foreach ($novals as $val) { if (strcasecmp($text, $val) == 0) return false; } return; } ?> --- NEW FILE: compatibility.php --- <?php /* * openFIRST.base - includes/compatibility.php * * Copyright (C) 2003, * openFIRST Project * Original Author: Jamie Bliss <ja...@op...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ // Purpose: Provides functions and constants not available in certain // versions of PHP. Also die if there are common functions not // available. // We use glob enough that we should either write a substitute or just refuse to work if(!function_exists('glob')) { die('You really should upgrade PHP, seeing as you don\'t even have <a href="http://www.php.net/manual/en/function.glob.php"><code>glob()</code></a>.'); } if (!defined('PATH_SEPARATOR')) { switch ($ostype) { case osWINDOWS: define('PATH_SEPARATOR', ';'); break; case osUNIX: default: define('PATH_SEPARATOR', ':'); break; } } if (!function_exists('set_include_path')) { function set_include_path($new_include_path) { $old = get_include_path(); ini_set('include_path', $new_include_path); return $old; } } if (!function_exists('get_include_path')) { function get_include_path() { return ini_get('include_path'); } } if (!function_exists('restore_include_path')) { function restore_include_path() { ini_restore('include_path'); } } ?> --- NEW FILE: globals.php --- <?php /* * openFIRST.base - includes/globals.php * * Copyright (C) 2003, * openFIRST Project * Original Author: Tim Ginn <tim...@po...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ // Purpose: Initialize the openFIRST system. $configdir = dirname(__FILE__); if( !defined('OPENFIRST_NO_INSTALLATION') && !file_exists( "$configdir/sitesettings.php" ) ) { $path = "#"; if(file_exists("../config/first.php")) { $path = "../config/first.php"; } elseif(file_exists("config/first.php")) { $path = "config/first.php"; } elseif(file_exists("../../config/first.php")) { $path = "../../config/first.php"; } $path = htmlentities($path); die( "You'll have to <a href=\"$path\">set openFIRST up</a> first!" ); } if (defined('OPENFIRST_NO_INSTALLATION')) { if(is_readable("style/headers.php")) { $Header = "style/headers.php"; } else { $Header = "../style/headers.php"; } } define('osUNIX', 'unix'); define('osWINDOWS', 'windows'); #Add more operating systems here if (substr(PHP_OS, 0, 3) == 'WIN') { $osType = osWINDOWS; } else { $osType = osUNIX; } #Because of the differences between versions, this may be needed. $usingPHP5 = version_compare(PHP_VERSION, '5.0.0', '>='); require_once('compatibility.php'); if (!defined('OPENFIRST_NO_INSTALLATION')) require_once('dbase.php'); set_include_path( get_include_path().PATH_SEPARATOR."$configdir/".PATH_SEPARATOR."."); unset($configdir); require_once('functions.php'); if (!defined('OPENFIRST_NO_INSTALLATION')) require_once('auth.php'); /*if (!defined('OPENFIRST_INSTALLATION_SCRIPT')) { require_once('Module.php'); require_once('slug.php'); require_once('edit.php'); require_once('settings.php'); } require_once('skin.php');*/ $sqlTablePrefix = 'ofirst_'; if (!defined('OPENFIRST_INSTALLATION_SCRIPT')) require_once('sitesettings.php'); if (!defined('OPENFIRST_NO_INSTALLATION')) { /* $ogDB = new DataBase($DBaseType, $sqlServer, $sqlUser, $sqlPassword); $ogDB->selectDB($sqlDatabase);*/ $sqlconnection = ofirst_dbconnect("$sqlserver","$sqluser","$sqlpassword"); ofirst_select_db($sqldatabase); } if (!defined('OPENFIRST_INSTALLATION_SCRIPT')) InitUser(); // Determine what module the user is viewing if (!defined('OPENFIRST_NO_INSTALLATION')) { $curmodule = str_replace($basepath, '', $_SERVER['SCRIPT_NAME']); $curmodule = substr($curmodule, 1, strpos($curmodule, '/', 2) - 1); } if (!defined('OPENFIRST_NO_INSTALLATION')) { // Include the functions using glob(); foreach (glob("$fbasepath/includes/functions/*.php") as $filename) { include_once($filename); } } $headers = ""; ofirst_select_db($sqldatabase, $sqlconnection); $incl = ofirst_dbquery("SELECT * FROM ofirst_config"); // If there is no error then run the module add feature if(ofirst_dberrno() == 0) { // Begin to loop through modules from the databaes while($module = ofirst_dbfetch_object($incl)) { // Check if the value is try, if it is then run an include if( (bool) $module->active == true) { // Check if there are includes that need to be included if(! $module->includes == ""){ // If the list is not empty then explode the value and put it into inclist $inclist = explode(",",$module->includes); // This is to remove an error that you have if you don't check if there are more then 2 if(count($inclist) >= 2){ // Loop through the inclist and add them according to their paths foreach($inclist As $inc){ include("$fbasepath/$module->modulename/$inc"); } } else { // If there is only 1 include available then use this line to include it instead include("$fbasepath/$module->modulename/$module->includes"); } } // If the module has requested to be shown on the menu then add it if( (bool) $module->showonmenu == true) { // If it is the current module then color the item if ($currentmodule == $module->modulename){ $headers .= " » <font color='red'><u><a class='menu' href='$basepath/$module->modulename'>".ucwords($module->modulename)."</a></u></font> |"; // Declare important variables so that headers can pick them up and preview them $adminnav = str_replace("\$basepath", $basepath, $module->adminnavigation) . " <a href='http://bugzilla.openfirst.org'>Report Bug</a>"; $subnav = str_replace("\$basepath", $basepath, $module->modulenavigation); } else { $headers .= " » <a class='menu' href='$basepath/$module->modulename'>".ucwords($module->modulename)."</a> |"; } } } } } session_write_close(); ?> Index: auth.php =================================================================== RCS file: /cvsroot/openfirst/base/includes/auth.php,v retrieving revision 1.5.2.3 retrieving revision 1.5.2.4 diff -C2 -d -r1.5.2.3 -r1.5.2.4 *** auth.php 24 Aug 2005 22:23:58 -0000 1.5.2.3 --- auth.php 25 Aug 2005 00:16:31 -0000 1.5.2.4 *************** *** 27,31 **** --- 27,38 ---- */ // Purpose: Deal with authorization of users. + /** + * @TODO Change $user to $ogUser + * @TODO Create User class + * @TODO Generalize sessioning & authentication and move into classes. + */ + require_once('dbase.php'); + if(isset($encryption) == false) { $encryption = "crypt"; } *************** *** 33,43 **** // syntax: cryptpassword(password, encryption-type, salt); ! function cryptpassword ($password, $encryption = "md5", $salt="") { // Encrypt passwords using whatever algorithm is preferred. ! if ($encryption == "crc32") { return(crc32($password)); ! } elseif ($encryption == "sha1") { return(sha1($password)); ! } elseif ($encryption == "crypt") { return(crypt($password, $salt)); } else { --- 40,53 ---- // syntax: cryptpassword(password, encryption-type, salt); ! function cryptpassword ($password, $enctype = false, $salt="") { ! global $encryption; ! if ($enctype === false) $enctype = $encryption; ! // Encrypt passwords using whatever algorithm is preferred. ! if ($enctype == "crc32") { return(crc32($password)); ! } else if ($enctype == "sha1") { return(sha1($password)); ! } else if ($enctype == "crypt") { return(crypt($password, $salt)); } else { *************** *** 48,51 **** --- 58,62 ---- function logout(){ if(isset($GLOBALS["user"]->user)) { + #FIXME: Bad SQL Handling $q = ofirst_dbquery("UPDATE ofirst_members SET authcode = NULL WHERE user='".$GLOBALS["user"]->user."';"); } *************** *** 86,103 **** } // Determine if the user has already logged in with this session. If // they have, set variables indicating this. If they have not, make a // note of this so that components requiring them to log in are disabled. ! if((isset($_SESSION['authcode']))||(isset($_COOKIE["openFIRSTlogin"])&&!isset($pass_save_disabled))) { ! if(isset($_SESSION['authcode'])){ $authcode = $_SESSION['authcode']; ! }elseif(isset($_COOKIE["openFIRSTlogin"])&&$_COOKIE["openFIRSTlogin"]!=0){ $authcode = $_COOKIE["openFIRSTlogin"]; ! $_SESSION['authcode']=$authcode; //renew cookie ! setcookie("openFIRSTlogin",$authcode,time()+2592000,"/"); } else { ! $authcode=0; } $query = ofirst_dbquery("SELECT * FROM ofirst_members WHERE authcode='$authcode';"); if(ofirst_dberrno() == 0 && ofirst_dbnum_rows($query) == 1 && $authcode!=0 ) { --- 97,122 ---- } + function InitUser() { + global $pass_save_disabled, $encryption, $user; // Determine if the user has already logged in with this session. If // they have, set variables indicating this. If they have not, make a // note of this so that components requiring them to log in are disabled. ! ! if ( (isset($_SESSION['authcode'])) || ! (isset($_COOKIE["openFIRSTlogin"]) && !$pass_save_disabled) ! ) { ! ! if (isset($_SESSION['authcode'])) { $authcode = $_SESSION['authcode']; ! } else if (isset($_COOKIE["openFIRSTlogin"]) && $_COOKIE["openFIRSTlogin"] != 0) { $authcode = $_COOKIE["openFIRSTlogin"]; ! $_SESSION['authcode'] = $authcode; //renew cookie ! setcookie("openFIRSTlogin", $authcode, time()+2592000, "/"); } else { ! $authcode = 0; } + + #FIXME: Bad SQL handling $query = ofirst_dbquery("SELECT * FROM ofirst_members WHERE authcode='$authcode';"); if(ofirst_dberrno() == 0 && ofirst_dbnum_rows($query) == 1 && $authcode!=0 ) { *************** *** 110,113 **** --- 129,133 ---- } if(isset($_POST["login"])){ + #FIXME: Bad SQL handling $query = ofirst_dbquery("SELECT * FROM ofirst_members WHERE user='" . $_POST["login"] . "';"); if(ofirst_dberrno() == 0) { *************** *** 128,131 **** --- 148,152 ---- } elseif( isset($_POST["login"]) && isset($_POST["password"]) ) { + #FIXME: Bad SQL handling $query = ofirst_dbquery("SELECT * FROM ofirst_members WHERE user='" . $_POST["login"] . "';"); if(ofirst_dberrno() == 0) { *************** *** 148,212 **** } } else { ! echo "Passwords don't match"; unset($user); } } ! } else echo "DB Error: ".ofirst_dberror(); ! } ! ! ! if(ofirst_dberrno() != 0) { ! // There was an error, check if it's because they didn't create the ! // members table. ! if(ofirst_dberrno() == 1146) { ! echo("<p>Members table does not exist, therefore I am creating it.</p>"); ! $query = ofirst_dbquery("CREATE TABLE ofirst_members ( ! UNIQUE(user), ! user CHAR(128), ! firstname TINYTEXT, ! lastname TINYTEXT, ! lastseen TINYTEXT, ! ip TINYTEXT, ! password TEXT, ! authcode TEXT, ! membertype TINYTEXT, ! division TINYTEXT, ! year INTEGER, ! email TEXT, ! icq INTEGER, ! aim TINYTEXT, ! msn TINYTEXT, ! yim TINYTEXT, ! description TEXT, ! signature TINYTEXT, ! dateregistered TINYTEXT, ! picturelocation TINYTEXT, ! team INTEGER, ! skills TEXT ! );"); ! if(ofirst_dberrno() == 0) { ! // Insert a default user 'administrator' and set them to have ! // administrative access and some password. ! ! $query = ofirst_dbquery("INSERT INTO ofirst_members (user, ! membertype, password) VALUES('admin', 'administrator', '" . ! cryptpassword("openfirst", $encryption) ."');"); ! echo("<p>Members table has been created. Please login as <b>admin</b> using the password <b>openfirst</b> to set configuration options.</p>"); ! showlogin(); ! die(); ! } else { ! die(ofirst_dberror()); ! } } } if(isset($user->user)){ $query = "UPDATE ofirst_members SET lastseen='" . date("h:i:s M d, Y") . "' WHERE user='$user->user';"; ! $q = ofirst_dbquery($query); ! unset($q); } ! ! /* This is here for legacy reasons, so as to make previous versions ! * of certain modules function with the newer base modules. ! */ ! function membersmenu() { return(0); } ! ?> --- 169,187 ---- } } else { ! # invalid password! unset($user); } } ! } else { ! # invalid user! ! unset($user); } } + if(isset($user->user)){ + #FIXME: Bad SQL handling $query = "UPDATE ofirst_members SET lastseen='" . date("h:i:s M d, Y") . "' WHERE user='$user->user';"; ! ofirst_dbquery($query); } ! } ! ?> \ No newline at end of file Index: dbase.php =================================================================== RCS file: /cvsroot/openfirst/base/includes/dbase.php,v retrieving revision 1.7.2.3 retrieving revision 1.7.2.4 diff -C2 -d -r1.7.2.3 -r1.7.2.4 *** dbase.php 24 Aug 2005 22:23:58 -0000 1.7.2.3 --- dbase.php 25 Aug 2005 00:16:31 -0000 1.7.2.4 *************** *** 227,229 **** --- 227,451 ---- exit(0); } + + function ofirst_dbfree_result($resource) { + global $DBaseType; + if($DBaseType == "mysql") { + if(function_exists("mysql_free_result") == false) { + die("MySQL support is not available in your version of PHP. To use the openFIRST Web Portal Software, please either enable MySQL support, or choose another database type."); + } + if (!is_resource($resource)) return false; + return mysql_free_result($resource); + } elseif($DBaseType == "mssql") { + if(function_exists("mssql_free_result") == false) { + die("Microsoft SQL support is not available in your version of PHP. To use the openFIRST Web Portal Software, please either enable Microsoft SQL support, or choose another database type."); + } + if (!is_resource($resource)) return false; + return mssql_free_result($resource); + } elseif($DBaseType == "odbc") { + if(function_exists("odbc_free_result") == false) { + die("ODBC support is not available in your version of PHP. To use the openFIRST Web Portal Software, please either enable ODBC support, or choose another database type."); + } + if (!is_resource($resource)) return false; + return odbc_free_result($resource); + } + exit(0); + } + function ofirst_dbname_version() { + global $DBaseType; + if($DBaseType == "mysql") { + $v = ofirst_dbfetch_object(ofirst_dbquery("SELECT VERSION() AS mysql_version")); + return "MySQL $v->mysql_version"; + } elseif($DBaseType == "mssql") { + $v = ofirst_dbquery("SELECT @@VERSION"); + return "Microsoft SQL Server $v <br><strong>Warning:</strong> unconfirmed"; + } elseif($DBaseType == "odbc") { + return "ODBC"; + } else { + return "Unknown DB type"; + } + } + + function ofirst_dbsize() { + global $DBaseType, $sqlDatabase; + if($DBaseType == "mysql") { + $dbsize = 0; + $dq = ofirst_dbquery("SHOW TABLE STATUS FROM $sqlDatabase"); + while($d = ofirst_dbfetch_object($dq)) { + $dbsize += $d->Data_length + $d->Index_length; + } + return (int) (($dbsize + 0.5) / 1024 * 10) / 10 . " KB"; + } elseif($DBaseType == "mssql") { + $s = ofirst_dbfetch_object(ofirst_dbquery("SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize FROM sysfiles")); + return (int) (( $s->dbsize + 0.5) / 1024 * 10) / 10 . " KB"; + } else { + return "Size not supported"; + } + } + + # Check if there the connection is valid + function ofirst_dbcheck($linkidentifier = "") { + #TODO: Write me! + global $DBaseType; + if($DBaseType == "mysql") { + } elseif($DBaseType == "mssql") { + } elseif($DBaseType == "odbc") { + } + exit(0); + } + + function ofirst_dbcreate($sqlserver, $sqluser, $sqlpassword, $sqldatabase) { + trigger_error('Depreciated function called: ofirst_dbcreate()', E_USER_NOTICE); + /* Create database if it does not already exist */ + ofirst_dbconnect("$sqlserver","$sqluser","$sqlpassword"); + + ofirst_dbquery("CREATE DATABASE IF NOT EXISTS $sqldatabase;"); + if (ofirst_dberror() != 0) return false; + + ofirst_select_db($sqldatabase); + + ofirst_dbquery("CREATE TABLE `ofirst_config` ( + `modulename` varchar(25) NOT NULL default '', + `label` VARCHAR(25), + `version` VARCHAR(10) NOT NULL default 'CVS', + `showonmenu` TINYINT( 1 ) NOT NULL DEFAULT '0', + `active` TINYINT( 1 ) NOT NULL DEFAULT '0', + `adminnavigation` text, + `modulenavigation` text, + `includes` text, + PRIMARY KEY (`modulename`), + UNIQUE (`modulename`) + )"); + if (ofirst_dberror() != 0) return false; + + /* copied from auth.php */ + ofirst_dbquery("CREATE TABLE ofirst_members ( + UNIQUE(user), + user CHAR(128), + firstname TINYTEXT, + lastname TINYTEXT, + lastseen TINYTEXT, + ip TINYTEXT, + password TEXT, + authcode TEXT, + membertype TINYTEXT, + division TINYTEXT, + year INTEGER, + email TEXT, + icq INTEGER, + aim TINYTEXT, + msn TINYTEXT, + yim TINYTEXT, + description TEXT, + signature TINYTEXT, + dateregistered TINYTEXT, + picturelocation TINYTEXT, + team INTEGER, + skills TEXT + );"); + if (ofirst_dberror() != 0) return false; + + if (ofirst_dberrno() == 0) { + // Insert a default user 'administrator' and set them to have + // administrative access and some password. + + ofirst_dbquery("INSERT INTO ofirst_members (user, + membertype, password) VALUES('admin', 'administrator', '" . + cryptpassword("openfirst") ."');"); + if (ofirst_dberror() != 0) return false; + } + /* End copy */ + return true; + } + + function ofirst_dbexec_file($filename, $linkidentifier = "") { + if (file_exists($filename) && is_readable($filename)) { + $sf = fopen($filename, "r"); + $query = ""; + while($line = fgets($sf)) { + if(substr($line, 0, 2) != "--" && substr($line, 0, 1) != "#" && strlen($line) > 0) { + $q = ofirst_dbquery(trim($line)); + } + } + fclose($sf); + return true; + } else { + return false; + } + } + + function ofirst_dbescape($text) { + global $DBaseType; + if($DBaseType == "mysql") { + return mysql_real_escape_string($text); + # MS SQL and ODBC don't have specific escaping functions. + } else { + # Lets just assume there isn't an escaping function + return addslashes($text); + } + exit(0); + } + + /** SQL escaping and quoting. + * These functions escape various kinds of literals. + * If an array is passed, it is assumed to be a list + * of things to be passed and is merged. + */ + + #Used for quoting field and DB names + function ofirst_dbquote_name($name, $delimiter = ',') { + if (is_array($name)) { + $value = ''; + foreach ($name as $text) { + $value .= ofirst_dbquote_name($text).$delimiter; + } + $value = substr($value, 0, -strlen($delimiter)); + return $value; + } else { + return '`'.ofirst_dbescape($name).'`'; + } + } + + #Used for quoting table names. Includes table prefix. + function ofirst_dbquote_table($name, $delimiter = ',') { + global $sqlTablePrefix; + if (is_array($name)) { + $value = ''; + foreach ($name as $text) { + $value .= ofirst_dbquote_table($text).$delimiter; + } + $value = substr($value, 0, -strlen($delimiter)); + return $value; + } else { + return ofirst_dbquote_name("$sqlTablePrefix$name"); + } + } + + #Used for quoting data + function ofirst_dbquote_data($data, $delimiter = ',') { + if (is_array($data)) { + $value = ''; + foreach ($data as $text) { + $value .= ofirst_dbquote_data($text).$delimiter; + } + $value = substr($value, 0, -strlen($delimiter)); + return $value; + } else { + return "'".ofirst_dbescape($data)."'"; + } + } + + #Used to quote field-data pairs in the form of `field`='data' + #passed like: + # array( 'field' => 'data' ) + function ofirst_dbquote_fd_pairs($pairs, $delimiter = ',') { + $value = ''; + foreach ($pairs as $field => $data) { + $value .= ofirst_dbquote_name($field); + $value .= '='; + $value .= ofirst_dbquote_data($data); + $value .= $delimiter; + } + $value = substr($value, 0, -strlen($delimiter)); + return $value; + } ?> --- NEW FILE: .cvsignore --- sitesettings.php |