From: <tr...@us...> - 2011-10-15 23:19:01
|
Revision: 7891 http://xoops.svn.sourceforge.net/xoops/?rev=7891&view=rev Author: trabis Date: 2011-10-15 23:18:53 +0000 (Sat, 15 Oct 2011) Log Message: ----------- Refactoring class/database Modified Paths: -------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/admin.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.image.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.recaptcha.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.text.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/image.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/text.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/mysqldatabase.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/sqlutility.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoopsload.php Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/admin.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/admin.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/admin.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -20,8 +20,8 @@ /** * Admin Authentication */ -if ($xoopsUser) { - if (!$xoopsUser->isAdmin(-1)) { +if ($GLOBALS['xoopsUser']) { + if (!$GLOBALS['xoopsUser']->isAdmin(-1)) { redirect_header('index.php', 2, _AD_NORIGHT); exit(); } @@ -35,7 +35,7 @@ /** * Error warning messages */ -if (!isset($xoopsConfig['admin_warnings_enable']) || $xoopsConfig['admin_warnings_enable']) { +if (!isset($GLOBALS['xoopsConfig']['admin_warnings_enable']) || $GLOBALS['xoopsConfig']['admin_warnings_enable']) { if (is_dir(XOOPS_ROOT_PATH . '/install/')) { xoops_error(sprintf(_AD_WARNINGINSTALL, XOOPS_ROOT_PATH . '/install/')); echo '<br />'; @@ -84,9 +84,6 @@ $items = array(); if (!$items = XoopsCache::read($rssfile)) { - require_once $GLOBALS['xoops']->path('class/snoopy.php'); - include_once $GLOBALS['xoops']->path('class/xml/rss/xmlrss2parser.php'); - $snoopy = new Snoopy(); $cnt = 0; foreach ($rssurl as $url) { Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.image.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.image.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.image.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -14,7 +14,7 @@ * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package class - * @subpackage CAPTCHA + * @subpackage captcha * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -12,7 +12,7 @@ * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package class - * @subpackage CAPTCHA + * @subpackage captcha * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.recaptcha.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.recaptcha.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.recaptcha.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -12,7 +12,7 @@ * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package class - * @subpackage CAPTCHA + * @subpackage captcha * @since 2.5.2 * @author trabis <lus...@gm...> * @version $Id: config.recaptcha.php 7695 2011-09-22 23:03:33Z trabis $ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.text.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.text.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/config.text.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -12,7 +12,7 @@ * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package class - * @subpackage CAPTCHA + * @subpackage captcha * @since 2.5.2 * @author trabis <lus...@gm...> * @version $Id: config.text.php 7695 2011-09-22 23:03:33Z trabis $ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/image.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/image.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/image.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -14,7 +14,7 @@ * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package class - * @subpackage CAPTCHA + * @subpackage captcha * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -12,7 +12,7 @@ * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package class - * @subpackage CAPTCHA + * @subpackage captcha * @since 2.5.2 * @author trabis <lus...@gm...> * @version $Id: recaptcha.php 7695 2011-09-22 23:03:33Z trabis $ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/text.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/text.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/text.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -12,7 +12,7 @@ * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package class - * @subpackage CAPTCHA + * @subpackage captcha * @since 2.3.0 * @author Taiwen Jiang <ph...@us...> * @version $Id$ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -11,7 +11,7 @@ * * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage database * @since 1.0.0 * @author Kazumi Ono <on...@xo...> @@ -21,15 +21,6 @@ defined('XOOPS_ROOT_PATH') or die('Restricted access'); /** - * make sure this is only included once! - */ -if (defined('XOOPS_C_DATABASE_INCLUDED')) { - return; -} - -define('XOOPS_C_DATABASE_INCLUDED', 1); - -/** * Abstract base class for Database access classes * * @abstract @@ -37,47 +28,34 @@ * @package kernel * @subpackage database */ -class XoopsDatabase +abstract class XoopsDatabase { /** * Prefix for tables in the database * * @var string */ - var $prefix = ''; + public $prefix = ''; - /** - * reference to a {@link XoopsLogger} object - * - * @see XoopsLogger - * @var object XoopsLogger - */ - var $logger; + /** + * @var XoopsLogger + */ + public $logger; /** * If statements that modify the database are selected * * @var boolean */ - var $allowWebChanges = false; + public $allowWebChanges = false; /** - * constructor - * - * will always fail, because this is an abstract class! - */ - public function __construct() - { - // exit('Cannot instantiate this class directly'); - } - - /** * assign a {@link XoopsLogger} object to the database * * @see XoopsLogger - * @param object $logger reference to a {@link XoopsLogger} object + * @param XoopsLogger $logger reference to a {@link XoopsLogger} object */ - function setLogger($logger) + public function setLogger(XoopsLogger $logger) { $this->logger = $logger; } @@ -87,7 +65,7 @@ * * @param string $value table prefix */ - function setPrefix($value) + public function setPrefix($value) { $this->prefix = $value; } @@ -100,7 +78,7 @@ * @param string $tablename tablename * @return string prefixed tablename, just prefix if tablename is empty */ - function prefix($tablename = '') + public function prefix($tablename = '') { if ($tablename != '') { return $this->prefix . '_' . $tablename; @@ -110,120 +88,91 @@ } /** - * @param $selectdb * @abstract + * @param bool $selectdb + * @return void */ - function connect($selectdb) - { - } + abstract function connect($selectdb = true); /** * @param $sequence * @abstract */ - function genId($sequence) - { - } + abstract function genId($sequence); /** * @param $result * @abstract */ - function fetchRow($result) - { - } + abstract function fetchRow($result); /** * @param $result * @return array * @abstract */ - function fetchArray($result) - { - } + abstract function fetchArray($result); /** * @param $result * @abstract */ - function fetchBoth($result) - { - } + abstract function fetchBoth($result); /** * @param $result * @abstract */ - function fetchObject($result) - { - } + abstract function fetchObject($result); /** * @abstract */ - function getInsertId() - { - } + abstract function getInsertId(); /** * @param $result * @abstract */ - function getRowsNum($result) - { - } + abstract function getRowsNum($result); /** * @abstract */ - function getAffectedRows() - { - } + abstract function getAffectedRows(); /** * @abstract */ - function close() - { - } + abstract function close(); /** * @param $result * @abstract */ - function freeRecordSet($result) - { - } + abstract function freeRecordSet($result); /** * @abstract */ - function error() - { - } + abstract function error(); /** * @abstract */ - function errno() - { - } + abstract function errno(); /** * @param $str * @abstract */ - function quoteString($str) - { - } + abstract function quoteString($str); /** * @param $string * @abstract */ - function quote($string) - { - } + abstract function quote($string); /** * @param $sql @@ -231,9 +180,7 @@ * @param int $start * @abstract */ - function queryF($sql, $limit = 0, $start = 0) - { - } + abstract function queryF($sql, $limit = 0, $start = 0); /** * @param $sql @@ -241,57 +188,33 @@ * @param int $start * @abstract */ - function query($sql, $limit = 0, $start = 0) - { - } + abstract function query($sql, $limit = 0, $start = 0); /** * @param $file * @abstract */ - function queryFromFile($file) - { - } + abstract function queryFromFile($file); /** * @param $result * @param $offset * @abstract */ - function getFieldName($result, $offset) - { - } + abstract function getFieldName($result, $offset); /** * @param $result * @param $offset * @abstract */ - function getFieldType($result, $offset) - { - } + abstract function getFieldType($result, $offset); /** * @param $result * @abstract */ - function getFieldsNum($result) - { - } + abstract function getFieldsNum($result); } -/** - * Only for backward compatibility - * - * @deprecated - */ -class Database -{ - function getInstance() - { - $inst = XoopsDatabaseFactory::getDatabaseConnection(); - return $inst; - } -} - ?> \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -11,10 +11,11 @@ * * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage database * @version $Id$ */ + defined('XOOPS_ROOT_PATH') or die('Restricted access'); /** @@ -52,7 +53,7 @@ $xoopsPreload = XoopsPreload::getInstance(); $xoopsPreload->triggerEvent('core.class.database.databasefactory.connection', array(&$class)); - + /* @var $instance XoopsDatabase */ $instance = new $class(); $instance->setLogger(XoopsLogger::getInstance()); $instance->setPrefix(XOOPS_DB_PREFIX); @@ -71,10 +72,10 @@ * only being used within the installer. * * @static - * @staticvar object The only instance of database class - * @return object Reference to the only instance of database class + * @staticvar XoopsDatabase The only instance of database class + * @return XoopsDatabase Reference to the only instance of database class */ - function getDatabase() + static function getDatabase() { static $database; if (!isset($database)) { Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/mysqldatabase.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/mysqldatabase.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/mysqldatabase.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -11,34 +11,22 @@ * * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage database * @since 1.0.0 * @author Kazumi Ono <on...@xo...> * @version $Id$ */ + defined('XOOPS_ROOT_PATH') or die('Restricted access'); /** - * - * @package kernel - * @subpackage database - * @author Kazumi Ono <on...@xo...> - * @copyright copyright (c) 2000-2003 XOOPS.org - */ - -/** - * base class - */ -include_once XOOPS_ROOT_PATH . '/class/database/database.php'; -// xoops_load( 'xoopsdatabase' ); -/** * connection to a mysql database * * @abstract * @author Kazumi Ono <on...@xo...> * @copyright copyright (c) 2000-2003 XOOPS.org - * @package kernel + * @package class * @subpackage database */ class XoopsMySQLDatabase extends XoopsDatabase @@ -48,7 +36,7 @@ * * @var resource */ - var $conn; + private $conn; /** * connect to the database @@ -56,7 +44,7 @@ * @param bool $selectdb select the database now? * @return bool successful? */ - function connect($selectdb = true) + public function connect($selectdb = true) { static $db_charset_set; @@ -100,7 +88,7 @@ * @param string $sequence name of the sequence from which to get the next ID * @return int always 0, because mysql has support for autoincrement */ - function genId($sequence) + public function genId($sequence) { return 0; // will use auto_increment } @@ -111,7 +99,7 @@ * @param resource $result * @return array */ - function fetchRow($result) + public function fetchRow($result) { return @mysql_fetch_row($result); } @@ -119,9 +107,10 @@ /** * Fetch a result row as an associative array * + * @param resource $result * @return array */ - function fetchArray($result) + public function fetchArray($result) { return @mysql_fetch_assoc($result); } @@ -129,9 +118,10 @@ /** * Fetch a result row as an associative array * + * @param resource $result * @return array */ - function fetchBoth($result) + public function fetchBoth($result) { return @mysql_fetch_array($result, MYSQL_BOTH); } @@ -139,10 +129,10 @@ /** * XoopsMySQLDatabase::fetchObjected() * - * @param mixed $result - * @return + * @param resource $result + * @return object|stdClass */ - function fetchObject($result) + public function fetchObject($result) { return @mysql_fetch_object($result); } @@ -152,7 +142,7 @@ * * @return int */ - function getInsertId() + public function getInsertId() { return mysql_insert_id($this->conn); } @@ -160,10 +150,10 @@ /** * Get number of rows in result * - * @param resource $ query result + * @param resource $result * @return int */ - function getRowsNum($result) + public function getRowsNum($result) { return @mysql_num_rows($result); } @@ -173,15 +163,17 @@ * * @return int */ - function getAffectedRows() + public function getAffectedRows() { return mysql_affected_rows($this->conn); } /** * Close MySQL connection + * + * @return void */ - function close() + public function close() { mysql_close($this->conn); } @@ -189,10 +181,10 @@ /** * will free all memory associated with the result identifier result. * - * @param resource $ query result + * @param resource $result query result * @return bool TRUE on success or FALSE on failure. */ - function freeRecordSet($result) + public function freeRecordSet($result) { return mysql_free_result($result); } @@ -202,7 +194,7 @@ * * @return bool Returns the error text from the last MySQL function, or '' (the empty string) if no error occurred. */ - function error() + public function error() { return @mysql_error(); } @@ -212,7 +204,7 @@ * * @return int Returns the error number from the last MySQL function, or 0 (zero) if no error occurred. */ - function errno() + public function errno() { return @mysql_errno(); } @@ -223,15 +215,18 @@ * @param string $str unescaped string text * @return string escaped string text with single quotes around */ - function quoteString($str) + public function quoteString($str) { return $this->quote($str); } /** * Quotes a string for use in a query. + * + * @param $string + * @return string */ - function quote($string) + public function quote($string) { return "'" . str_replace("\\\"", '"', str_replace("\\"", '"', mysql_real_escape_string($string, $this->conn))) . "'"; } @@ -245,7 +240,7 @@ * @return resource query result or FALSE if successful * or TRUE if successful and no result */ - function queryF($sql, $limit = 0, $start = 0) + public function queryF($sql, $limit = 0, $start = 0) { if (!empty($limit)) { if (empty($start)) { @@ -277,7 +272,7 @@ * @param int $start offset of first record to return * @abstract */ - function query($sql, $limit = 0, $start = 0) + public function query($sql, $limit = 0, $start = 0) { } @@ -287,10 +282,9 @@ * @param string $file file path to an SQL dump file * @return bool FALSE if failed reading SQL file or TRUE if the file has been read and queries executed */ - function queryFromFile($file) + public function queryFromFile($file) { if (false !== ($fp = fopen($file, 'r'))) { - include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_queries = trim(fread($fp, filesize($file))); SqlUtility::splitMySqlFile($pieces, $sql_queries); foreach ($pieces as $query) { @@ -310,10 +304,10 @@ * Get field name * * @param resource $result query result - * @param int $ numerical field index + * @param int $offset numerical field index * @return string */ - function getFieldName($result, $offset) + public function getFieldName($result, $offset) { return mysql_field_name($result, $offset); } @@ -325,7 +319,7 @@ * @param int $offset numerical field index * @return string */ - function getFieldType($result, $offset) + public function getFieldType($result, $offset) { return mysql_field_type($result, $offset); } @@ -336,7 +330,7 @@ * @param resource $result query result * @return int */ - function getFieldsNum($result) + public function getFieldsNum($result) { return mysql_num_fields($result); } @@ -361,7 +355,7 @@ * @return resource query result or FALSE if successful * or TRUE if successful and no result */ - function query($sql, $limit = 0, $start = 0) + public function query($sql, $limit = 0, $start = 0) { return $this->queryF($sql, $limit, $start); } @@ -390,14 +384,13 @@ * @param int $start offset of first record to return * @return resource query result or FALSE if unsuccessful */ - function query($sql, $limit = 0, $start = 0) + public function query($sql, $limit = 0, $start = 0) { $sql = ltrim($sql); if (!$this->allowWebChanges && strtolower(substr($sql, 0, 6)) != 'select') { trigger_error('Database updates are not allowed during processing of a GET request', E_USER_WARNING); return false; } - return $this->queryF($sql, $limit, $start); } } Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/sqlutility.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/sqlutility.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/sqlutility.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -11,7 +11,7 @@ * * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package kernel + * @package class * @subpackage database * @author Kazumi Ono <on...@xo...> * @version $Id$ @@ -26,20 +26,21 @@ * @package kernel * @subpackage database */ -class SqlUtility { +class SqlUtility +{ /** - * Function from phpMyAdmin (http://phpwizard.net/projects/phpMyAdmin/) - * - * Removes comment and splits large sql files into individual queries - * - * Last revision: September 23, 2001 - gandon - * - * @param array $ the splitted sql commands - * @param string $ the sql commands - * @return boolean always true - * @access public - */ - function splitMySqlFile(&$ret, $sql) + * Function from phpMyAdmin (http://phpwizard.net/projects/phpMyAdmin/) + * + * Removes comment and splits large sql files into individual queries + * + * Last revision: September 23, 2001 - gandon + * + * @param array $ret the splitted sql commands + * @param string $sql the sql commands + * @return bool always true + * @access public + */ + static function splitMySqlFile(&$ret, $sql) { $sql = trim($sql); $sql_len = strlen($sql); @@ -52,87 +53,91 @@ // We are in a string, check for not escaped end of // strings except for backquotes that can't be escaped if ($in_string) { - for (;;) { + for (; ;) { $i = strpos($sql, $string_start, $i); // No end of string found -> add the current // substring to the returned array if (!$i) { $ret[] = $sql; return true; - } - // Backquotes or no backslashes before - // quotes: it's indeed the end of the - // string -> exit the loop - else if ($string_start == '`' || $sql[$i-1] != '\\') { - $string_start = ''; - $in_string = false; - break; - } - // one or more Backslashes before the presumed - // end of string... + } // Backquotes or no backslashes before + // quotes: it's indeed the end of the + // string -> exit the loop else { - // first checks for escaped backslashes - $j = 2; - $escaped_backslash = false; - while ($i - $j > 0 && $sql[$i - $j] == '\\') { - $escaped_backslash = !$escaped_backslash; - $j++; - } - // ... if escaped backslashes: it's really the - // end of the string -> exit the loop - if ($escaped_backslash) { + if ($string_start == '`' || $sql[$i - 1] != '\\') { $string_start = ''; $in_string = false; break; - } - // ... else loop + } // one or more Backslashes before the presumed + // end of string... else { - $i++; + // first checks for escaped backslashes + $j = 2; + $escaped_backslash = false; + while ($i - $j > 0 && $sql[$i - $j] == '\\') { + $escaped_backslash = !$escaped_backslash; + $j++; + } + // ... if escaped backslashes: it's really the + // end of the string -> exit the loop + if ($escaped_backslash) { + $string_start = ''; + $in_string = false; + break; + } // ... else loop + else { + $i++; + } } } // end if...elseif...else } // end for } // end if (in string) - // We are not in a string, first check for delimiter... - else if ($char == ';') { - // if delimiter found, add the parsed part to the returned array - $ret[] = substr($sql, 0, $i); - $sql = ltrim(substr($sql, min($i + 1, $sql_len))); - $sql_len = strlen($sql); - if ($sql_len) { - $i = -1; - } else { - // The submited statement(s) end(s) here - return true; + // We are not in a string, first check for delimiter... + else { + if ($char == ';') { + // if delimiter found, add the parsed part to the returned array + $ret[] = substr($sql, 0, $i); + $sql = ltrim(substr($sql, min($i + 1, $sql_len))); + $sql_len = strlen($sql); + if ($sql_len) { + $i = -1; + } else { + // The submited statement(s) end(s) here + return true; + } + } // end else if (is delimiter) + // ... then check for start of a string,... + else { + if (($char == '"') || ($char == '\'') || ($char == '`')) { + $in_string = true; + $string_start = $char; + } // end else if (is start of string) + // for start of a comment (and remove this comment if found)... + else { + if ($char == '#' || ($char == ' ' && $i > 1 && $sql[$i - 2] . $sql[$i - 1] == '--')) { + // starting position of the comment depends on the comment type + $start_of_comment = (($sql[$i] == '#') ? $i : $i - 2); + // if no "\n" exits in the remaining string, checks for "\r" + // (Mac eol style) + $end_of_comment = (strpos(' ' . $sql, "\012", $i + 2)) ? strpos(' ' . $sql, "\012", $i + 2) + : strpos(' ' . $sql, "\015", $i + 2); + if (!$end_of_comment) { + // no eol found after '#', add the parsed part to the returned + // array and exit + // RMV fix for comments at end of file + //$last = trim(substr($sql, 0, $i-1)); + //if (!empty($last)) { + // $ret[] = $last; + //} + return true; + } else { + $sql = substr($sql, 0, $start_of_comment) . ltrim(substr($sql, $end_of_comment)); + $sql_len = strlen($sql); + $i--; + } // end if...else + } + } } - } // end else if (is delimiter) - // ... then check for start of a string,... - else if (($char == '"') || ($char == '\'') || ($char == '`')) { - $in_string = true; - $string_start = $char; - } // end else if (is start of string) - // for start of a comment (and remove this comment if found)... - else if ($char == '#' || ($char == ' ' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '--')) { - // starting position of the comment depends on the comment type - $start_of_comment = (($sql[$i] == '#') ? $i : $i-2); - // if no "\n" exits in the remaining string, checks for "\r" - // (Mac eol style) - $end_of_comment = (strpos(' ' . $sql, "\012", $i + 2)) - ? strpos(' ' . $sql, "\012", $i + 2) - : strpos(' ' . $sql, "\015", $i + 2); - if (!$end_of_comment) { - // no eol found after '#', add the parsed part to the returned - // array and exit - // RMV fix for comments at end of file - //$last = trim(substr($sql, 0, $i-1)); - //if (!empty($last)) { - // $ret[] = $last; - //} - return true; - } else { - $sql = substr($sql, 0, $start_of_comment) . ltrim(substr($sql, $end_of_comment)); - $sql_len = strlen($sql); - $i--; - } // end if...else } // end else if (is comment) } // end for // add any rest to the returned array @@ -143,13 +148,13 @@ } /** - * add a prefix.'_' to all tablenames in a query - * - * @param string $query valid SQL query string - * @param string $prefix prefix to add to all table names - * @return mixed FALSE on failure - */ - function prefixQuery($query, $prefix) + * add a prefix.'_' to all tablenames in a query + * + * @param string $query valid SQL query string + * @param string $prefix prefix to add to all table names + * @return mixed FALSE on failure + */ + static function prefixQuery($query, $prefix) { $pattern = "/^(INSERT[\s]+INTO|CREATE[\s]+TABLE|ALTER[\s]+TABLE|UPDATE)(\s)+([`]?)([^`\s]+)\\3(\s)+/siU"; $pattern2 = "/^(DROP TABLE)(\s)+([`]?)([^`\s]+)\\3(\s)?$/siU"; Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoopsload.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoopsload.php 2011-10-15 19:16:16 UTC (rev 7890) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoopsload.php 2011-10-15 23:18:53 UTC (rev 7891) @@ -166,6 +166,7 @@ 'mytextsanitizerextension' => XOOPS_ROOT_PATH . '/class/module.textsanitizer.php', 'smarty' => XOOPS_ROOT_PATH . '/class/smarty/Smarty.class.php', 'snoopy' => XOOPS_ROOT_PATH . '/class/snoopy.php', + 'sqlutility' => XOOPS_ROOT_PATH . '/class/database/sqlutility.php', 'tar' => XOOPS_ROOT_PATH . '/class/class.tar.php', 'xoopsauth' => XOOPS_ROOT_PATH . '/class/auth/auth.php', 'xoopsauthfactory' => XOOPS_ROOT_PATH . '/class/auth/auth_ldap.php', @@ -176,6 +177,7 @@ 'xoopscalendar' => XOOPS_ROOT_PATH . '/class/calendar/xoopscalendar.php', 'xoopscaptcha' => XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php', 'xoopscommentrenderer' => XOOPS_ROOT_PATH . '/class/commentrenderer.php', + 'xoopsdatabase' => XOOPS_ROOT_PATH . '/class/database/database.php', 'xoopsdownloader' => XOOPS_ROOT_PATH . '/class/downloader.php', 'xoopslists' => XOOPS_ROOT_PATH . '/class/xoopslists.php', 'xoopslocal' => XOOPS_ROOT_PATH . '/include/xoopslocal.php', @@ -231,6 +233,7 @@ 'xoopsthemeform' => XOOPS_ROOT_PATH . '/class/xoopsform/themeform.php', 'xoopsuserutility' => XOOPS_ROOT_PATH . '/class/userutility.php', 'xoopsutility' => XOOPS_ROOT_PATH . '/class/utility/xoopsutility.php', + 'xoopsxmlrss2parser' => XOOPS_ROOT_PATH . 'class/xml/rss/xmlrss2parser.php', 'xoopszipdownloader' => XOOPS_ROOT_PATH . '/class/zipdownloader.php', 'xos_opal_adminthemefactory' => XOOPS_ROOT_PATH . '/class/theme.php', 'xos_logos_pagebuilder' => XOOPS_ROOT_PATH . '/class/theme_blocks.php', This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |