From: Andrew Dolgov Date: Fri, 15 Mar 2013 10:15:06 +0000 (+0400) Subject: db: use builtin classloader, lowercase class files X-Git-Tag: 1.7.3~2 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=57b8469e674ef082c30b7d1de40d5d53d50b251b;p=tt-rss.git db: use builtin classloader, lowercase class files --- diff --git a/classes/Db/Abstract.php b/classes/Db/Abstract.php deleted file mode 100644 index d84701fd..00000000 --- a/classes/Db/Abstract.php +++ /dev/null @@ -1,56 +0,0 @@ -dbconn; - } - - public function init() { } - - public function escape_string($s, $strip_tags = true) { } - - public function query($query, $die_on_error = true) { } - - public function fetch_assoc($result) { } - - public function num_rows($result) { } - - public function fetch_result($result, $row, $param) { } - - public function unescape_string($str) - { - $tmp = str_replace("\\\"", "\"", $str); - $tmp = str_replace("\\'", "'", $tmp); - return $tmp; - } - - public function close() { } - - public function affected_rows($result) { } - - public function last_error() { } - - public function quote($str) - { - return("'$str'"); - } - -} \ No newline at end of file diff --git a/classes/Db/Interface.php b/classes/Db/Interface.php deleted file mode 100644 index c5bfad56..00000000 --- a/classes/Db/Interface.php +++ /dev/null @@ -1,18 +0,0 @@ -dbconn = $link; - return $link; - } else { - die("Unable to connect to database (as $user to $host, database $db): " . mysql_error()); - } - } - - public function init() - { - db_query($this->dbconn, "SET time_zone = '+0:0'"); - - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { - db_query($this->dbconn, "SET NAMES " . MYSQL_CHARSET); - } - } - - public function escape_string($s, $strip_tags = true) - { - if ($strip_tags) $s = strip_tags($s); - return mysql_real_escape_string($s); - } - - public function query($query, $die_on_error = true) - { - $result = mysql_query($query, $this->dbconn); - if (!$result) { - $query = htmlspecialchars($query); - if ($die_on_error) { - die("Query $query failed: " . ($this->dbconn ? mysql_error($this->dbconn) : "No connection")); - } - } - return $result; - } - - public function fetch_assoc($result) { - return mysql_fetch_assoc($result); - } - - public function num_rows($result) { - return mysql_num_rows($result); - } - - public function fetch_result($result, $row, $param) { - // I hate incoherent naming of PHP functions - return mysql_result($result, $row, $param); - } - - public function close() { - return mysql_close($this->dbconn); - } - - public function affected_rows($result) { - return mysql_affected_rows($this->dbconn); - } - - public function last_error() { - return mysql_error($this->dbconn); - } -} diff --git a/classes/Db/Pgsql.php b/classes/Db/Pgsql.php deleted file mode 100644 index 39ed181d..00000000 --- a/classes/Db/Pgsql.php +++ /dev/null @@ -1,80 +0,0 @@ -dbconn = $link; - return $link; - } - - public function init() - { - pg_query($this->dbconn, "set client_encoding = 'UTF-8'"); - pg_set_client_encoding("UNICODE"); - pg_query($this->dbconn, "set datestyle = 'ISO, european'"); - pg_query($this->dbconn, "set TIME ZONE 0"); - } - - public function escape_string($s, $strip_tags = true) - { - if ($strip_tags) $s = strip_tags($s); - return pg_escape_string($s); - } - - public function query($query, $die_on_error = true) - { - $result = pg_query($this->dbconn, $query); - if (!$result) { - $query = htmlspecialchars($query); // just in case - if ($die_on_error) { - die("Query $query failed [$result]: " . ($this->dbconn ? pg_last_error($this->dbconn) : "No connection")); - } - } - return $result; - } - - public function fetch_assoc($result) { - return pg_fetch_assoc($result); - } - - public function num_rows($result) { - return pg_num_rows($result); - } - - public function fetch_result($result, $row, $param) { - return pg_fetch_result($result, $row, $param); - } - - public function close() { - return pg_close($this->dbconn); - } - - public function affected_rows($result) { - return pg_affected_rows($result); - } - - public function last_error() { - return pg_last_error($this->dbconn); - } -} diff --git a/classes/db/abstract.php b/classes/db/abstract.php new file mode 100644 index 00000000..d84701fd --- /dev/null +++ b/classes/db/abstract.php @@ -0,0 +1,56 @@ +dbconn; + } + + public function init() { } + + public function escape_string($s, $strip_tags = true) { } + + public function query($query, $die_on_error = true) { } + + public function fetch_assoc($result) { } + + public function num_rows($result) { } + + public function fetch_result($result, $row, $param) { } + + public function unescape_string($str) + { + $tmp = str_replace("\\\"", "\"", $str); + $tmp = str_replace("\\'", "'", $tmp); + return $tmp; + } + + public function close() { } + + public function affected_rows($result) { } + + public function last_error() { } + + public function quote($str) + { + return("'$str'"); + } + +} \ No newline at end of file diff --git a/classes/db/interface.php b/classes/db/interface.php new file mode 100644 index 00000000..c5bfad56 --- /dev/null +++ b/classes/db/interface.php @@ -0,0 +1,18 @@ +dbconn = $link; + return $link; + } else { + die("Unable to connect to database (as $user to $host, database $db): " . mysql_error()); + } + } + + public function init() + { + db_query($this->dbconn, "SET time_zone = '+0:0'"); + + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { + db_query($this->dbconn, "SET NAMES " . MYSQL_CHARSET); + } + } + + public function escape_string($s, $strip_tags = true) + { + if ($strip_tags) $s = strip_tags($s); + return mysql_real_escape_string($s); + } + + public function query($query, $die_on_error = true) + { + $result = mysql_query($query, $this->dbconn); + if (!$result) { + $query = htmlspecialchars($query); + if ($die_on_error) { + die("Query $query failed: " . ($this->dbconn ? mysql_error($this->dbconn) : "No connection")); + } + } + return $result; + } + + public function fetch_assoc($result) { + return mysql_fetch_assoc($result); + } + + public function num_rows($result) { + return mysql_num_rows($result); + } + + public function fetch_result($result, $row, $param) { + // I hate incoherent naming of PHP functions + return mysql_result($result, $row, $param); + } + + public function close() { + return mysql_close($this->dbconn); + } + + public function affected_rows($result) { + return mysql_affected_rows($this->dbconn); + } + + public function last_error() { + return mysql_error($this->dbconn); + } +} diff --git a/classes/db/pgsql.php b/classes/db/pgsql.php new file mode 100644 index 00000000..39ed181d --- /dev/null +++ b/classes/db/pgsql.php @@ -0,0 +1,80 @@ +dbconn = $link; + return $link; + } + + public function init() + { + pg_query($this->dbconn, "set client_encoding = 'UTF-8'"); + pg_set_client_encoding("UNICODE"); + pg_query($this->dbconn, "set datestyle = 'ISO, european'"); + pg_query($this->dbconn, "set TIME ZONE 0"); + } + + public function escape_string($s, $strip_tags = true) + { + if ($strip_tags) $s = strip_tags($s); + return pg_escape_string($s); + } + + public function query($query, $die_on_error = true) + { + $result = pg_query($this->dbconn, $query); + if (!$result) { + $query = htmlspecialchars($query); // just in case + if ($die_on_error) { + die("Query $query failed [$result]: " . ($this->dbconn ? pg_last_error($this->dbconn) : "No connection")); + } + } + return $result; + } + + public function fetch_assoc($result) { + return pg_fetch_assoc($result); + } + + public function num_rows($result) { + return pg_num_rows($result); + } + + public function fetch_result($result, $row, $param) { + return pg_fetch_result($result, $row, $param); + } + + public function close() { + return pg_close($this->dbconn); + } + + public function affected_rows($result) { + return pg_affected_rows($result); + } + + public function last_error() { + return pg_last_error($this->dbconn); + } +} diff --git a/include/classloader.php b/include/classloader.php new file mode 100644 index 00000000..4b8b3738 --- /dev/null +++ b/include/classloader.php @@ -0,0 +1,15 @@ + diff --git a/include/db.php b/include/db.php index 28718fb0..020fd08a 100644 --- a/include/db.php +++ b/include/db.php @@ -1,13 +1,9 @@ quote($str); } -?> \ No newline at end of file +?> diff --git a/include/functions.php b/include/functions.php index 4dc286eb..caea2576 100644 --- a/include/functions.php +++ b/include/functions.php @@ -5,19 +5,7 @@ $fetch_last_error = false; $pluginhost = false; - function __autoload($class) { - $class_file1 = str_replace("_", "/", basename($class)); // PSR-0 - $class_file2 = str_replace("_", "/", strtolower(basename($class))); - - $file1 = dirname(__FILE__)."/../classes/$class_file1.php"; - $file2 = dirname(__FILE__)."/../classes/$class_file2.php"; - - if (file_exists($file1)) { - require $file1; - } elseif (file_exists($file2)) { - require $file2; - } - } + require_once "classloader.php"; mb_internal_encoding("UTF-8"); date_default_timezone_set('UTC'); @@ -3903,4 +3891,4 @@ return in_array($interface, class_implements($class)); } -?> \ No newline at end of file +?>