diff --git a/api/index.php b/api/index.php index 53b78b010df0351d88c90e69513bb84e27999b9d..823b9527e90319645c98d58e387420b906c514d9 100644 --- a/api/index.php +++ b/api/index.php @@ -54,7 +54,7 @@ @session_start(); } - if (!init_connection($link)) return; + if (!init_plugins($link)) return; $method = strtolower($_REQUEST["op"]); diff --git a/backend.php b/backend.php index 6ee0e081f549eca4c6c3ac2cc676ac66066253e7..40e40aeb323dc8b9ae4cc9c05d23079a9f3254f5 100644 --- a/backend.php +++ b/backend.php @@ -49,7 +49,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; header("Content-Type: text/json; charset=utf-8"); diff --git a/classes/db.php b/classes/db.php index 403cbc93aba3ca452d103a8c5f9eb91a01fa8199..71fc01ae1b6ea5b4701a81200e3f94d2a1b4ba47 100644 --- a/classes/db.php +++ b/classes/db.php @@ -16,6 +16,7 @@ class Db implements IDb { } $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); + $this->adapter->init(); } private function __clone() { @@ -33,6 +34,10 @@ class Db implements IDb { return("'$str'"); } + function init() { + // + } + function connect($host, $user, $pass, $db, $port) { //return $this->adapter->connect($host, $user, $pass, $db, $port); } diff --git a/classes/db/mysql.php b/classes/db/mysql.php index 512ea38943907d8b643c0294bacfab8b69437e1d..fa97dcff16d9af59d931abf5cfb270c21afc556d 100644 --- a/classes/db/mysql.php +++ b/classes/db/mysql.php @@ -55,5 +55,15 @@ class Db_Mysql implements IDb { return mysql_affected_rows($this->link); } + function init() { + $this->query("SET time_zone = '+0:0'"); + + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { + $this->query("SET NAMES " . MYSQL_CHARSET); + } + + return true; + } + } ?> diff --git a/classes/db/pgsql.php b/classes/db/pgsql.php index 87c2abefddd896d6f1be1d4f83046f6f72c1b0f8..c9ec338876dd2e150a2e6b5ca2e18c679d9b6a50 100644 --- a/classes/db/pgsql.php +++ b/classes/db/pgsql.php @@ -69,5 +69,13 @@ class Db_Pgsql implements IDb { return pg_last_error($this->link); } + function init() { + $this->query("set client_encoding = 'UTF-8'"); + pg_set_client_encoding("UNICODE"); + $this->query("set datestyle = 'ISO, european'"); + $this->query("set TIME ZONE 0"); + + return true; + } } ?> diff --git a/classes/idb.php b/classes/idb.php index 16f760bf6ade60d0d4bc41e4c4b67eb7111a8b1c..1ca6925b41ad23b748ce5737963b3fc0a4d3ff37 100644 --- a/classes/idb.php +++ b/classes/idb.php @@ -1,6 +1,7 @@ <?php interface IDb { function connect($host, $user, $pass, $db, $port); + function init(); function escape_string($s, $strip_tags = true); function query($query, $die_on_error = true); function fetch_assoc($result); diff --git a/include/functions.php b/include/functions.php index 43138a1f9af9c968c8bbb1e4d5f756e6c6117f24..0a686e71e6342e9226617ebede1a202df67244d0 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3371,41 +3371,13 @@ return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0; } - function init_connection_only($link) { - if ($link) { - if (DB_TYPE == "pgsql") { - pg_query($link, "set client_encoding = 'UTF-8'"); - pg_set_client_encoding("UNICODE"); - pg_query($link, "set datestyle = 'ISO, european'"); - pg_query($link, "set TIME ZONE 0"); - } else { - db_query($link, "SET time_zone = '+0:0'"); - - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { - db_query($link, "SET NAMES " . MYSQL_CHARSET); - } - } - - return true; - } - - return false; - } - - function init_connection($link) { - if ($link) { - init_connection_only($link); - - global $pluginhost; + function init_plugins($link) { + global $pluginhost; - $pluginhost = new PluginHost($link); - $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL); + $pluginhost = new PluginHost($link); + $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL); - return true; - } else { - print "Unable to connect to database:" . db_last_error(); - return false; - } + return true; } function format_tags_string($tags, $id) { diff --git a/index.php b/index.php index 066b25fa5b1d77bac0afc1ff566de3e482becde6..c21b46809f7d5a776501adaa1ba183300115b9fc 100644 --- a/index.php +++ b/index.php @@ -31,7 +31,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; global $pluginhost; diff --git a/opml.php b/opml.php index b8c9fb6c5c483dd6d9ebc52bb89f444252f85399..ad866fbd5b2e9b20de2652b04978dbbd3dfa5ac7 100644 --- a/opml.php +++ b/opml.php @@ -11,7 +11,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; $op = $_REQUEST['op']; diff --git a/plugins/mobile/article.php b/plugins/mobile/article.php index f6aed994fa6068bf04def2b82c1d8b0a623d3269..c73c0fca50bd82d3a40d70dbbdf1724125f41e40 100644 --- a/plugins/mobile/article.php +++ b/plugins/mobile/article.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/backend.php b/plugins/mobile/backend.php index a88e02a92e41f6e89b0c5340f2ea9cca225c7e02..dc657ed40ec89043ce488b03af9bcd576828165d 100644 --- a/plugins/mobile/backend.php +++ b/plugins/mobile/backend.php @@ -23,7 +23,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); if (!$_SESSION["uid"]) return; diff --git a/plugins/mobile/cat.php b/plugins/mobile/cat.php index 7b5cf43f9db02ab69db66a3515f6e286b47e5bed..acd7f6f341be81a1b4f5d6aac856a15a4fde7ed6 100644 --- a/plugins/mobile/cat.php +++ b/plugins/mobile/cat.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/feed.php b/plugins/mobile/feed.php index 6eae741ace2cb885a14da2127e079c687684a9c6..22590f195e7283735d850832fa4906a5d88ee857 100644 --- a/plugins/mobile/feed.php +++ b/plugins/mobile/feed.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/home.php b/plugins/mobile/home.php index 03fccb3e2fc838bd5eab521633615f66378b1e28..f0ebf6a111cfb5ab756ed692bcc0127cd2dafee0 100644 --- a/plugins/mobile/home.php +++ b/plugins/mobile/home.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/index.php b/plugins/mobile/index.php index 3feec75313bae790147c7e5653b853c9a9844218..3fd496d0464cea26ac8d973646037f2ca029a830 100644 --- a/plugins/mobile/index.php +++ b/plugins/mobile/index.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); ?> diff --git a/plugins/mobile/prefs.php b/plugins/mobile/prefs.php index 3231962541132f1b4bd52e85f4ee0c3b1e206206..e6d4a7b40d7eac2542d3e9a8e42d41c373ade525 100644 --- a/plugins/mobile/prefs.php +++ b/plugins/mobile/prefs.php @@ -20,7 +20,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); ?> diff --git a/prefs.php b/prefs.php index e3b62da70bb46eadfc39999ac73d28100f45b8de..046d5eb76aabee33aa3cfa1ab4ab8b7382b0b860 100644 --- a/prefs.php +++ b/prefs.php @@ -21,7 +21,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; login_sequence($link); diff --git a/public.php b/public.php index 8477f95fc8399f1f4959ed635b3c27e750b67e92..1a50538fb7dd8cdbd321927716b6979bfa65d3b2 100644 --- a/public.php +++ b/public.php @@ -30,7 +30,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) { ob_start("ob_gzhandler"); diff --git a/register.php b/register.php index 53627d9128d6a711defcbdb643af4a91cfe1bd3e..9aec6dde7f1c001289739a7674a514ff0fc61a58 100644 --- a/register.php +++ b/register.php @@ -19,7 +19,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; if ($_REQUEST["format"] == "feed") { header("Content-Type: text/xml"); diff --git a/update.php b/update.php index 1c43cdb94c2233be9aaf3c426e117590498b33bf..ffe54cc7cdac8d44592e77541f08af05b23984a3 100755 --- a/update.php +++ b/update.php @@ -21,7 +21,7 @@ // Create a database connection. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); $longopts = array("feeds", "feedbrowser", diff --git a/update_daemon2.php b/update_daemon2.php index 77d05be66159b2556aaebbfed6ec493d044eb3f8..e8a56eec92a5396368fda7adbebc53aa2b01b563 100755 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -177,7 +177,7 @@ // It is unnecessary to start the fork loop if database is not ok. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) die("Can't initialize db connection.\n"); + if (!init_plugins($link)) die("Can't initialize db connection.\n"); $schema_version = get_schema_version($link); @@ -203,7 +203,7 @@ /* Check if schema version changed */ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) die("Can't initialize db connection.\n"); + if (!init_plugins($link)) die("Can't initialize db connection.\n"); $test_schema_version = get_schema_version($link); db_close($link); @@ -255,7 +255,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; // We disable stamp file, since it is of no use in a multiprocess update. // not really, tho for the time being -fox