OSDN Git Service

MARGE:masterブランチのマージ(マージできない分について、データベースハンドラーを書き換え)
[nucleus-jp/nucleus-next.git] / nucleus / libs / globalfunctions.php
index 6cf9616..4db7221 100644 (file)
@@ -2,7 +2,7 @@
 \r
 /*\r
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
- * Copyright (C) 2002-2012 The Nucleus Group\r
+ * Copyright (C) 2002-2009 The Nucleus Group\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
@@ -12,8 +12,8 @@
  */\r
 /**\r
  * @license http://nucleuscms.org/license.txt GNU General Public License\r
- * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
- * @version $Id: globalfunctions.php 1727 2012-04-07 02:54:22Z sakamocchi $\r
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group\r
+ * @version $Id: globalfunctions.php 1825 2012-05-04 16:56:35Z sakamocchi $\r
  */\r
 \r
 /* needed if we include globalfunctions from install.php */\r
@@ -22,14 +22,28 @@ global $nucleus, $CONF, $DIR_LIBS, $DIR_LOCALES, $manager, $member;
 $nucleus['version'] = 'v4.00 SVN';\r
 $nucleus['codename'] = '';\r
 \r
+/*\r
+ * make sure there's no unnecessary escaping:\r
+ * set_magic_quotes_runtime(0);\r
+ */\r
+if ( version_compare(PHP_VERSION, '5.3.0', '<') )\r
+{\r
+       ini_set('magic_quotes_runtime', '0');\r
+}\r
+\r
 /* check and die if someone is trying to override internal globals (when register_globals turn on) */\r
 checkVars(array('nucleus', 'CONF', 'DIR_LIBS', 'MYSQL_HOST', 'MYSQL_USER', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', 'DIR_LOCALES', 'DIR_PLUGINS', 'HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_ENV_VARS', 'HTTP_SESSION_VARS', 'HTTP_POST_FILES', 'HTTP_SERVER_VARS', 'GLOBALS', 'argv', 'argc', '_GET', '_POST', '_COOKIE', '_ENV', '_SESSION', '_SERVER', '_FILES'));\r
 \r
-/* debug mode */\r
 if ( !isset($CONF) )\r
 {\r
        $CONF = array();\r
 }\r
+\r
+/* debug mode */\r
+if ( array_key_exists('debug', $CONF) && $CONF['debug'] )\r
+{\r
+       $CONF = array();\r
+}\r
 if ( array_key_exists('debug', $CONF) && $CONF['debug'] )\r
 {\r
        /* report all errors! */\r
@@ -42,63 +56,23 @@ else
 }\r
 \r
 /*\r
- * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.\r
- */\r
-if ( !isset($DIR_LOCALES) )\r
-{\r
-       $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';\r
-}\r
-global $DIR_LANG;\r
-if ( !isset($DIR_LANG) )\r
-{\r
-       $DIR_LANG = $DIR_LOCALES;\r
-}\r
-\r
-/*\r
- * load and initialize i18n class\r
- */\r
-if (!class_exists('i18n', FALSE))\r
-{\r
-       include($DIR_LIBS . 'i18n.php');\r
-}\r
-if ( !i18n::init('UTF-8', $DIR_LOCALES) )\r
-{\r
-       exit('Fail to initialize i18n class.');\r
-}\r
-/*\r
- * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.\r
- */\r
-define('_CHARSET', i18n::get_current_charset());\r
-\r
-/*\r
- * Indicates when Nucleus should display startup errors. Set to 1 if you want\r
- * the error enabled (default), false otherwise\r
- *\r
  * alertOnHeadersSent\r
  *  Displays an error when visiting a public Nucleus page and headers have\r
  *  been sent out to early. This usually indicates an error in either a\r
  *  configuration file or a translation file, and could cause Nucleus to\r
  *  malfunction\r
- * alertOnSecurityRisk\r
- * Displays an error only when visiting the admin area, and when one or\r
- *  more of the installation files (install.php, install.sql, upgrades/\r
- *  directory) are still on the server.\r
  */\r
 if ( !array_key_exists('alertOnHeadersSent', $CONF) || $CONF['alertOnHeadersSent'] !== 0 )\r
 {\r
        $CONF['alertOnHeadersSent'] = 1;\r
 }\r
-$CONF['alertOnSecurityRisk'] = 1;\r
 /*\r
- * NOTE: this should be removed when releasing 4.0\r
-$CONF['ItemURL']           = $CONF['Self'];\r
-$CONF['ArchiveURL']          = $CONF['Self'];\r
-$CONF['ArchiveListURL']      = $CONF['Self'];\r
-$CONF['MemberURL']           = $CONF['Self'];\r
-$CONF['SearchURL']           = $CONF['Self'];\r
-$CONF['BlogURL']             = $CONF['Self'];\r
-$CONF['CategoryURL']         = $CONF['Self'];\r
-*/\r
+ * alertOnSecurityRisk\r
+ * Displays an error only when visiting the admin area, and when one or\r
+ *  more of the installation files (install.php, install.sql, upgrades/\r
+ *  directory) are still on the server.\r
+ */\r
+$CONF['alertOnSecurityRisk'] = 1;\r
 \r
 /*\r
  * Set these to 1 to allow viewing of future items or draft items\r
@@ -115,60 +89,80 @@ if ( getNucleusPatchLevel() > 0 )
 }\r
 \r
 /* Avoid notices */\r
-if ( !isset($CONF['installscript']) )\r
+if ( !array_key_exists('installscript', $CONF) || empty($CONF['installscript']) )\r
 {\r
        $CONF['installscript'] = 0;\r
 }\r
-\r
-/* we will use postVar, getVar, ... methods instead of $_GET, $_POST ...*/\r
-if ( $CONF['installscript'] != 1 )\r
+if ( !array_key_exists('UsingAdminArea', $CONF) )\r
 {\r
-       /* vars were already included in install.php */\r
-       include_once($DIR_LIBS . 'vars4.1.0.php');\r
+       $CONF['UsingAdminArea'] = 0;\r
 }\r
 \r
-/* sanitize option */\r
-$bLoggingSanitizedResult=0;\r
-$bSanitizeAndContinue=0;\r
+if ( !headers_sent() )\r
+{\r
+       header('Generator: Nucleus CMS ' . $nucleus['version']);\r
+}\r
 \r
-$orgRequestURI = serverVar('REQUEST_URI');\r
-sanitizeParams();\r
 \r
-/* get all variables that can come from the request and put them in the global scope */\r
-$blogid       = requestVar('blogid');\r
-$itemid       = intRequestVar('itemid');\r
-$catid        = intRequestVar('catid');\r
-$skinid       = requestVar('skinid');\r
-$memberid     = requestVar('memberid');\r
-$archivelist  = requestVar('archivelist');\r
-$imagepopup   = requestVar('imagepopup');\r
-$archive      = requestVar('archive');\r
-$query        = requestVar('query');\r
-$highlight    = requestVar('highlight');\r
-$amount       = requestVar('amount');\r
-$action       = requestVar('action');\r
-$nextaction   = requestVar('nextaction');\r
-$maxresults   = requestVar('maxresults');\r
-$startpos     = intRequestVar('startpos');\r
-$errormessage = '';\r
-$error        = '';\r
-$special      = requestVar('special');\r
-$virtualpath  = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));\r
+/* TODO: This is for compatibility since 4.0, should be obsoleted at future release. */\r
+if ( !isset($DIR_LOCALES) )\r
+{\r
+       $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';\r
+}\r
+global $DIR_LANG;\r
+if ( !isset($DIR_LANG) )\r
+{\r
+       $DIR_LANG = $DIR_LOCALES;\r
+}\r
 \r
-if ( !headers_sent() )\r
+/* load and initialize i18n class */\r
+if (!class_exists('i18n', FALSE))\r
 {\r
-       header('Generator: Nucleus CMS ' . $nucleus['version']);\r
+       include($DIR_LIBS . 'i18n.php');\r
 }\r
+if ( !i18n::init('UTF-8', $DIR_LOCALES) )\r
+{\r
+       exit('Fail to initialize i18n class.');\r
+}\r
+\r
+/* TODO: This is just for compatibility since 4.0, should be obsoleted at future release. */\r
+define('_CHARSET', i18n::get_current_charset());\r
+\r
 \r
 /*\r
  * NOTE: Since 4.0 release, Entity class becomes to be important class\r
  *  with some wrapper functions for htmlspechalchars/htmlentity PHP's built-in function\r
-*/\r
+ */\r
 include($DIR_LIBS . 'ENTITY.php');\r
 \r
+/* we will use postVar, getVar, ... methods instead of $_GET, $_POST ... */\r
+if ( $CONF['installscript'] != 1 )\r
+{\r
+       /* vars were already included in install.php */\r
+       include_once($DIR_LIBS . 'vars4.1.0.php');\r
+       \r
+       /* added for 4.0 DB::* wrapper and compatibility sql_* */\r
+       include_once($DIR_LIBS . 'sql/sql.php');\r
+}\r
+\r
 /* include core classes that are needed for login & plugin handling */\r
-include_once($DIR_LIBS . 'mysql.php');\r
-/* added for 3.5 sql_* wrapper */\r
+include($DIR_LIBS . 'MEMBER.php');\r
+include($DIR_LIBS . 'ACTIONLOG.php');\r
+include($DIR_LIBS . 'MANAGER.php');\r
+include($DIR_LIBS . 'PLUGIN.php');\r
+\r
+$manager =& MANAGER::instance();\r
+\r
+/* only needed when updating logs */\r
+if ( $CONF['UsingAdminArea'] )\r
+{\r
+       /* XML-RPC client classes */\r
+       include($DIR_LIBS . 'xmlrpc.inc.php');\r
+       include($DIR_LIBS . 'ADMIN.php');\r
+}\r
+\r
+\r
+/* connect to database */\r
 global $MYSQL_HANDLER;\r
 if ( !isset($MYSQL_HANDLER) )\r
 {\r
@@ -178,50 +172,61 @@ if ( $MYSQL_HANDLER[0] == '' )
 {\r
        $MYSQL_HANDLER[0] = 'mysql';\r
 }\r
-include_once($DIR_LIBS . 'sql/'.$MYSQL_HANDLER[0].'.php');\r
-/* end new for 3.5 sql_* wrapper */\r
-include($DIR_LIBS . 'MEMBER.php');\r
-include($DIR_LIBS . 'ACTIONLOG.php');\r
-include($DIR_LIBS . 'MANAGER.php');\r
-include($DIR_LIBS . 'PLUGIN.php');\r
+DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);\r
 \r
-$manager =& Manager::instance();\r
 \r
-/*\r
- * make sure there's no unnecessary escaping:\r
- * set_magic_quotes_runtime(0);\r
- */\r
-if ( version_compare(PHP_VERSION, '5.3.0', '<') )\r
+/* force locale or charset */\r
+$locale = '';\r
+$charset = i18n::get_current_charset();\r
+\r
+$data = array(\r
+       'locale'        => &$locale,\r
+       'charset'       => &$charset\r
+);\r
+$manager->notify('ForceLocale', $data);\r
+\r
+if ( $data['locale'] !== '' )\r
 {\r
-       ini_set('magic_quotes_runtime', '0');\r
+       i18n::set_forced_locale($data['locale']);\r
 }\r
-\r
-/* Avoid notices */\r
-if ( !array_key_exists('UsingAdminArea', $CONF) )\r
+if ( $data['charset'] !== '' )\r
 {\r
-       $CONF['UsingAdminArea'] = 0;\r
+       i18n::set_forced_charset($data['charset']);\r
 }\r
+unset($locale);\r
+unset($charset);\r
 \r
-/* only needed when updating logs */\r
-if ( $CONF['UsingAdminArea'] )\r
+\r
+/* convert forced charset to current charset */\r
+if ( i18n::get_forced_charset() != i18n::get_current_charset() )\r
 {\r
-       /* XML-RPC client classes */\r
-       include($DIR_LIBS . 'xmlrpc.inc.php');\r
-       include_once($DIR_LIBS . 'ADMIN.php');\r
+       $_POST          = i18n::convert_array($_POST, i18n::get_forced_charset());\r
+       $_GET           = i18n::convert_array($_GET, i18n::get_forced_charset());\r
+       $_REQUEST       = i18n::convert_array($_REQUEST, i18n::get_forced_charset());\r
+       $_COOKIE        = i18n::convert_array($_COOKIE, i18n::get_forced_charset());\r
+       $_FILES         = i18n::convert_array($_FILES, i18n::get_forced_charset());\r
+       \r
+       if ( session_id() !== '' )\r
+       {\r
+               $_SESSION = i18n::convert_array($_SESSION, i18n::get_forced_charset());\r
+       }\r
 }\r
 \r
-/* connect to database */\r
-sql_connect();\r
-$SQLCount = 0;\r
+\r
+/* sanitize option */\r
+$bLoggingSanitizedResult = 0;\r
+$bSanitizeAndContinue = 0;\r
+$orgRequestURI = serverVar('REQUEST_URI');\r
+sanitizeParams();\r
 \r
 /* logs sanitized result if need */\r
-if ( $orgRequestURI!==serverVar('REQUEST_URI') )\r
+if ( $orgRequestURI !== serverVar('REQUEST_URI') )\r
 {\r
        $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";\r
        $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');\r
        if ( $bLoggingSanitizedResult )\r
        {\r
-       addToLog(WARNING, $msg);\r
+               addToLog(WARNING, $msg);\r
        }\r
        if ( !$bSanitizeAndContinue )\r
        {\r
@@ -229,25 +234,31 @@ if ( $orgRequestURI!==serverVar('REQUEST_URI') )
        }\r
 }\r
 \r
-/* makes sure database connection gets closed on script termination */\r
-register_shutdown_function('sql_disconnect');\r
+/* get all variables that can come from the request and put them in the global scope */\r
+$blogid                = requestVar('blogid');\r
+$itemid                = intRequestVar('itemid');\r
+$catid         = intRequestVar('catid');\r
+$skinid                = requestVar('skinid');\r
+$memberid      = requestVar('memberid');\r
+$archivelist = requestVar('archivelist');\r
+$imagepopup    = requestVar('imagepopup');\r
+$archive       = requestVar('archive');\r
+$query         = requestVar('query');\r
+$highlight     = requestVar('highlight');\r
+$amount                = requestVar('amount');\r
+$action                = requestVar('action');\r
+$nextaction    = requestVar('nextaction');\r
+$maxresults    = requestVar('maxresults');\r
+$startpos      = intRequestVar('startpos');\r
+$errormessage = '';\r
+$error         = '';\r
+$special       = requestVar('special');\r
+$virtualpath = ((getVar('virtualpath') != NULL) ? getVar('virtualpath') : serverVar('PATH_INFO'));\r
+\r
 \r
 /* read config */\r
 getConfig();\r
 \r
-/*\r
- * FIXME: This is for backward compatibility, should be obsoleted near future.\r
- */\r
-if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])\r
-  && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )\r
-{\r
-       $CONF['Locale'] = 'en_Latn_US';\r
-}\r
-if ( !array_key_exists('Language', $CONF) )\r
-{\r
-       $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);\r
-}\r
-$locale = $CONF['Locale'];\r
 \r
 /* Properly set $CONF['Self'] and others if it's not set...\r
  * usually when we are access from admin menu\r
@@ -262,13 +273,13 @@ if ( !array_key_exists('Self', $CONF) )
        }\r
 }\r
 \r
-$CONF['ItemURL'] = $CONF['Self'];\r
-$CONF['ArchiveURL'] = $CONF['Self'];\r
-$CONF['ArchiveListURL'] = $CONF['Self'];\r
-$CONF['MemberURL'] = $CONF['Self'];\r
-$CONF['SearchURL'] = $CONF['Self'];\r
-$CONF['BlogURL'] = $CONF['Self'];\r
-$CONF['CategoryURL'] = $CONF['Self'];\r
+$CONF['ItemURL']               = $CONF['Self'];\r
+$CONF['ArchiveURL']            = $CONF['Self'];\r
+$CONF['ArchiveListURL']        = $CONF['Self'];\r
+$CONF['MemberURL']             = $CONF['Self'];\r
+$CONF['SearchURL']             = $CONF['Self'];\r
+$CONF['BlogURL']               = $CONF['Self'];\r
+$CONF['CategoryURL']   = $CONF['Self'];\r
 \r
 /*\r
  *switch URLMode back to normal when $CONF['Self'] ends in .php\r
@@ -307,14 +318,39 @@ else
        $member->cookielogin();\r
 }\r
 \r
+\r
+/* TODO: This is for backward compatibility, should be obsoleted near future. */\r
+if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])\r
+  && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )\r
+{\r
+       $CONF['Locale'] = 'en_Latn_US';\r
+}\r
+if ( !array_key_exists('Language', $CONF) )\r
+{\r
+       $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);\r
+}\r
+$locale = $CONF['Locale'];\r
+\r
+\r
 /* NOTE: include translation file and set locale */\r
-if ( $member->isLoggedIn() && $member->getLocale())\r
+if ( $member->isLoggedIn() )\r
 {\r
-       $locale = $member->getLocale();\r
+       if ( $member->getLocale() )\r
+       {\r
+               $locale = $member->getLocale();\r
+       }\r
+}\r
+else\r
+{\r
+       if ( i18n::get_forced_locale() !== '' )\r
+       {\r
+               $locale = i18n::get_forced_locale();\r
+       }\r
 }\r
 include_translation($locale);\r
 i18n::set_current_locale($locale);\r
 \r
+\r
 /* login completed */\r
 $manager->notify('PostAuthentication', array('loggedIn' => $member->isLoggedIn() ) );\r
 \r
@@ -511,20 +547,38 @@ if ( $CONF['URLMode'] == 'pathinfo' )
  * the values of something like catid or itemid\r
  * New in 3.60\r
  */\r
-$manager->notify(\r
-       'PostParseURL',\r
-       array(\r
-               /* e.g. item, blog, ... */\r
-               'type' => basename(serverVar('SCRIPT_NAME') ),\r
-               'info' => $virtualpath\r
-       )\r
+$data = array(\r
+       'type' => basename(serverVar('SCRIPT_NAME')),\r
+       'info' => $virtualpath\r
 );\r
+$manager->notify('PostParseURL', $data);\r
 \r
 /*\r
  * NOTE: Here is the end of initialization\r
  */\r
 \r
-       /**\r
+/**\r
+ * Errors before the database connection has been made\r
+ * \r
+ * @param      string  $msg    message to notify\r
+ * @param      string  $title  page title\r
+ * @return     void\r
+ */\r
+function startUpError($msg, $title)\r
+{\r
+       header('Content-Type: text/xml; charset=' . i18n::get_current_charset());\r
+       echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";\r
+       echo "<head>\n";\r
+       echo '<title>'. Entity::hsc($title) . "</title></head>\n";\r
+       echo "<body>\n";\r
+       echo '<h1>' . Entity::hsc($title) . "</h1>\n";\r
+       echo $msg;\r
+       echo "</body>\n";\r
+       echo "</html>\n";\r
+       exit;\r
+}\r
+\r
+/**\r
         * This function includes or requires the specified library file\r
         * @param string $file\r
         * @param bool $once use the _once() version\r
@@ -735,51 +789,72 @@ $manager->notify(
        }\r
 \r
 \r
-       /**\r
-        * TODO: This function should be changed to send_content_type() per the Coding Guidelines. Ensure this change is compatible with rest of core.\r
-        *\r
-        * This function sends the Content-Type header if headers have not already been sent\r
-        * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.\r
-        * @param string $content_type\r
-        * @param string $page_type\r
-        * @param string $charset Deprecated. This has no meaning.\r
-        */\r
-       function sendContentType($content_type, $page_type = '', $charset = _CHARSET)\r
+/**\r
+ * sendContentType()\r
+ * This function sends the Content-Type header if headers have not already been sent\r
+ * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.\r
+ * \r
+ * if content type is application/xhtml+xml, only send it to browsers\r
+ * that can handle it (IE6 cannot). Otherwise, send text/html\r
+ *\r
+ * v2.5:\r
+ * For admin area pages, keep sending text/html (unless it's a debug version)\r
+ * application/xhtml+xml still causes too much problems with the javascript implementations\r
+ *\r
+ * v3.3:\r
+ * ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,\r
+ * application/xhtml+xml seems to be working, so we're going to use it if we can.\r
+ * \r
+ * @param      string  $content_type   MIME media type registered to IANA, http://www.iana.org/assignments/media-types/index.html\r
+ * @param      string  $page_type              \r
+ * @param      string  $charset                Deprecated. This has no meaning.\r
+ * @return     void\r
+ * \r
+ */\r
+function sendContentType($content_type, $page_type = '', $charset = '')\r
+{\r
+       global $manager, $CONF;\r
+       \r
+       if ( headers_sent() )\r
        {\r
-               global $manager, $CONF;\r
-               \r
-               if ( !headers_sent() )\r
-               {\r
-                       // if content type is application/xhtml+xml, only send it to browsers\r
-                       // that can handle it (IE6 cannot). Otherwise, send text/html\r
-\r
-                       // v2.5: For admin area pages, keep sending text/html (unless it's a debug version)\r
-                       //       application/xhtml+xml still causes too much problems with the javascript implementations\r
-\r
-                       // v3.3: ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,\r
-                       //       application/xhtml+xml seems to be working, so we're going to use it if we can.\r
-\r
-                       if ( ($content_type == 'application/xhtml+xml')\r
-                               && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )\r
-                       {\r
-                               $content_type = 'text/html';\r
-                       } // end if\r
-\r
-                       $manager->notify(\r
-                               'PreSendContentType',\r
-                               array(\r
-                                       'contentType' => &$content_type,\r
-                                       'charset' => i18n::get_current_charset(),\r
-                                       'pageType' => $page_type\r
-                               )\r
-                       );\r
-\r
-                       // strip strange characters\r
-                       $content_type = preg_replace('|[^a-z0-9-+./]|i', '', $content_type);\r
-                       header('Content-Type: ' . $content_type . '; charset=' . i18n::get_current_charset());\r
-               } // end if\r
-\r
+               return;\r
        }\r
+       \r
+       /* NOTE: MIME Media Type */\r
+       if ( ($content_type == 'application/xhtml+xml')\r
+               && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )\r
+       {\r
+               $content_type = 'text/html';\r
+       }\r
+       \r
+       /* NOTE: generate event */\r
+       $data = array(\r
+               'pageType'              =>  $page_type,\r
+               'contentType'   => &$content_type\r
+       );\r
+       $manager->notify('PreSendContentType', $data);\r
+       \r
+       /* NOTE: confirm MIME Media Type */\r
+       $content_type = preg_replace('#[^a-zA-Z0-9-+./]#', '', $content_type);\r
+       \r
+       /* NOTE: confirm character set */\r
+       $charset = i18n::get_current_charset();\r
+       if ( i18n::get_forced_charset() !== '' )\r
+       {\r
+               $charset = i18n::get_forced_charset();\r
+       }\r
+       \r
+       /* NOTE: send HTTP 1.1 header */\r
+       header("Content-Type: {$content_type}; charset={$charset}");\r
+       \r
+       /* NOTE: set handler for translating character set */\r
+       if ( $charset != i18n::get_current_charset() )\r
+       {\r
+               ob_start(array('i18n', 'convert_handler'));\r
+       }\r
+       \r
+       return;\r
+}\r
 \r
 \r
        /**\r
@@ -828,7 +903,8 @@ $manager->notify(
         */\r
        function getBlogIDFromName($name)\r
        {\r
-               return quickQuery('SELECT bnumber AS result FROM ' . sql_table('blog') . ' WHERE bshortname = "' . sql_real_escape_string($name) . '"');\r
+               $query = sprintf('SELECT bnumber AS result FROM %s WHERE bshortname=%s', sql_table('blog'), DB::quoteValue($name));\r
+               return DB::getValue($query);\r
        }\r
 \r
 \r
@@ -839,7 +915,8 @@ $manager->notify(
         */\r
        function getBlogNameFromID($id)\r
        {\r
-               return quickQuery('SELECT bname AS result FROM ' . sql_table('blog') . ' WHERE bnumber = ' . intval($id));\r
+               $query = sprintf('SELECT bname AS result FROM %s WHERE bnumber=%d', sql_table('blog'), intval($id));\r
+               return DB::getValue($query);\r
        }\r
 \r
 \r
@@ -850,7 +927,8 @@ $manager->notify(
         */\r
        function getBlogIDFromItemID($item_id)\r
        {\r
-               return quickQuery('SELECT iblog AS result FROM ' . sql_table('item') . ' WHERE inumber = ' . intval($item_id));\r
+               $query = sprintf('SELECT iblog AS result FROM %s WHERE inumber=%d', sql_table('item'), intval($item_id));\r
+               return DB::getValue($query);\r
        }\r
 \r
 \r
@@ -861,7 +939,8 @@ $manager->notify(
         */\r
        function getBlogIDFromCommentID($comment_id)\r
        {\r
-               return quickQuery('SELECT cblog AS result FROM ' . sql_table('comment') . ' WHERE cnumber = ' . intval($comment_id));\r
+               $query = sprintf('SELECT cblog AS result FROM %s WHERE cnumber=%d', sql_table('comment'), intval($comment_id));\r
+               return DB::getValue($query);\r
        }\r
 \r
 \r
@@ -872,7 +951,8 @@ $manager->notify(
         */\r
        function getBlogIDFromCatID($category_id)\r
        {\r
-               return quickQuery('SELECT cblog AS result FROM ' . sql_table('category') . ' WHERE catid = ' . intval($category_id));\r
+               $query = sprintf('SELECT cblog AS result FROM %s WHERE catid=%d', sql_table('category'), intval($category_id));\r
+               return DB::getValue($query);\r
        }\r
 \r
 \r
@@ -883,26 +963,25 @@ $manager->notify(
         */\r
        function getCatIDFromName($name)\r
        {\r
-               return quickQuery('SELECT catid AS result FROM ' . sql_table('category') . ' WHERE cname = "' . sql_real_escape_string($name) . '"');\r
+               $query = sprintf('SELECT catid AS result FROM %s WHERE cname=%s', sql_table('category'), DB::quoteValue($name));\r
+               return DB::getValue($query);\r
        }\r
 \r
 \r
        /**\r
         * This function performs a quick SQL query\r
+        * @deprecated\r
         * @param string $query\r
         * @return object\r
         */\r
        function quickQuery($query)\r
        {\r
-               $res = sql_query($query);\r
-               $obj = sql_fetch_object($res);\r
-               return (is_object($obj)) ? $obj->result : FALSE;\r
+               $row = DB::getRow($query);\r
+               return $row['result'];\r
        }\r
-\r
 function getPluginNameFromPid($pid) {\r
-    $res = sql_query('SELECT pfile FROM ' . sql_table('plugin') . ' WHERE pid=' . intval($pid) );\r
-    $obj = sql_fetch_object($res);\r
-    return $obj->pfile;\r
+    $query = sprintf('SELECT pfile FROM %s WHERE pid=%d', sql_table('plugin'), intval($pid));\r
+    return DB::getValue($query);\r
 //    return isset($obj->pfile) ? $obj->pfile : false;\r
 }\r
 \r
@@ -972,69 +1051,64 @@ function selector()
                \r
                // 1. get timestamp, blogid and catid for item\r
                $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d';\r
-               $query = sprintf($query, sql_table('item'), (integer) $itemid);\r
-               $res = sql_query($query);\r
-               $obj = sql_fetch_object($res);\r
+               $query = sprintf($query, sql_table('item'), intval($itemid));\r
+               $row = DB::getRow($query);\r
                \r
                // if a different blog id has been set through the request or selectBlog(),\r
                // deny access\r
                \r
-               if ( $blogid && (intval($blogid) != $obj->iblog) )\r
+               if ( $blogid && (intval($blogid) != $row['iblog']) )\r
                {\r
                        doError(_ERROR_NOSUCHITEM);\r
                }\r
                \r
                // if a category has been selected which doesn't match the item, ignore the\r
                // category. #85\r
-               if ( ($catid != 0) && ($catid != $obj->icat) )\r
+               if ( ($catid != 0) && ($catid != $row['icat']) )\r
                {\r
                        $catid = 0;\r
                }\r
                \r
-               $blogid = $obj->iblog;\r
-               $timestamp = strtotime($obj->itime);\r
+               $blogid = $row['iblog'];\r
+               $timestamp = strtotime($row['itime']);\r
                \r
                $b =& $manager->getBlog($blogid);\r
                \r
                if ( !$b->isValidCategory($catid) )\r
                {\r
-                       $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";\r
-                       $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid);\r
+                       $query = "SELECT inumber, ititle FROM %s WHERE itime<%s AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";\r
+                       $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), intval($blogid));\r
                }\r
                else\r
                {\r
-                       $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime DESC LIMIT 1";\r
-                       $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid, $catid);\r
+                       $query = "SELECT inumber, ititle FROM %s WHERE itime<%s AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime DESC LIMIT 1";\r
+                       $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), intval($blogid), intval($catid));\r
                }\r
+               $row = DB::getRow($query);\r
                \r
-               $res = sql_query($query);\r
-               $obj = sql_fetch_object($res);\r
-               \r
-               if ( $obj )\r
+               if ( $row )\r
                {\r
-                       $itemidprev = $obj->inumber;\r
-                       $itemtitleprev = $obj->ititle;\r
+                       $itemidprev = $row['inumber'];\r
+                       $itemtitleprev = $row['ititle'];\r
                }\r
                \r
                // get next itemid and title\r
                if ( !$b->isValidCategory($catid) )\r
                {\r
-                       $query = "SELECT inumber, ititle FROM %s WHERE itime>'%s' AND itime<='%s' AND idraft=0 AND iblog=%d ORDER BY itime ASC LIMIT 1";\r
-                       $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid);\r
+                       $query = "SELECT inumber, ititle FROM %s WHERE itime>%s AND itime<=%s AND idraft=0 AND iblog=%d ORDER BY itime ASC LIMIT 1";\r
+                       $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), DB::formatDateTime($b->getCorrectTime()), intval($blogid));\r
                }\r
                else\r
                {\r
-                       $query = "SELECT inumber, ititle FROM %s WHERE itime>'%s' AND itime<='%s' AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime ASC LIMIT 1";\r
-                       $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid, $catid);\r
+                       $query = "SELECT inumber, ititle FROM %s WHERE itime>%s AND itime<=%s AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime ASC LIMIT 1";\r
+                       $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), DB::formatDateTime($b->getCorrectTime()), intval($blogid), intval($catid));\r
                }\r
-               $res = sql_query($query);\r
+               $row = DB::getRow($query);\r
                \r
-               $obj = sql_fetch_object($res);\r
-               \r
-               if ( $obj )\r
+               if ( $row )\r
                {\r
-                       $itemidnext = $obj->inumber;\r
-                       $itemtitlenext = $obj->ititle;\r
+                       $itemidnext = $row['inumber'];\r
+                       $itemtitlenext = $row['ititle'];\r
                }\r
        }\r
        elseif ( $archive )\r
@@ -1046,10 +1120,10 @@ function selector()
                global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;\r
                \r
                // sql queries for the timestamp of the first and the last published item\r
-               $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime ASC";\r
-               $first_timestamp=quickQuery ($query);\r
-               $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime DESC";\r
-               $last_timestamp=quickQuery ($query);\r
+               $query = sprintf('SELECT UNIX_TIMESTAMP(itime) as result FROM %s WHERE idraft=0 ORDER BY itime ASC', sql_table('item'));\r
+               $first_timestamp = DB::getValue($query);\r
+               $query = sprintf('SELECT UNIX_TIMESTAMP(itime) as result FROM %s WHERE idraft=0 ORDER BY itime DESC', sql_table('item'));\r
+               $last_timestamp = DB::getValue($query);\r
                \r
                sscanf($archive, '%d-%d-%d', $y, $m, $d);\r
                \r
@@ -1309,11 +1383,12 @@ function doError($msg, $skin = '')
 function getConfig() {\r
     global $CONF;\r
 \r
-    $query = 'SELECT * FROM ' . sql_table('config');\r
-    $res = sql_query($query);\r
+    $query = sprintf('SELECT * FROM %s', sql_table('config'));\r
+    $res = DB::getResult($query);\r
 \r
-    while ($obj = sql_fetch_object($res) ) {\r
-        $CONF[$obj->name] = $obj->value;\r
+    foreach ( $res as $row )\r
+    {\r
+       $CONF[$row['name']] = $row['value'];\r
     }\r
 }\r
 \r
@@ -1408,7 +1483,7 @@ function selectItem($id) {
 function parseFile($filename, $includeMode = 'normal', $includePrefix = '')\r
 {\r
        global $skinid;\r
-\r
+       \r
        if ( !$skinid || !existsID($skinid) )\r
        {\r
                $skin = new Skin($CONF['BaseSkin']);\r
@@ -1416,16 +1491,16 @@ function parseFile($filename, $includeMode = 'normal', $includePrefix = '')
        else\r
        {\r
                $skin = new Skin($skinid);\r
-    }\r
-\r
+       }\r
+       \r
        $oldIncludeMode = Parser::getProperty('IncludeMode');\r
        $oldIncludePrefix = Parser::getProperty('IncludePrefix');\r
-\r
+       \r
        $skin->parse('fileparse', $filename);\r
-\r
+       \r
        Parser::setProperty('IncludeMode', $oldIncludeMode);\r
        Parser::setProperty('IncludePrefix', $oldIncludePrefix);\r
-\r
+       \r
        return;\r
 }\r
 \r
@@ -1583,52 +1658,42 @@ function checkVars($aVars) {
 \r
 \r
 /**\r
+ * sanitizeParams()\r
  * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.\r
- * to avoid XSS\r
+ * to avoid XSS.\r
+ * \r
+ * @param      void\r
+ * @return     void\r
  */\r
 function sanitizeParams()\r
 {\r
-    global $HTTP_SERVER_VARS;\r
-\r
-    $array = array();\r
-    $str = '';\r
-    $frontParam = '';\r
-\r
-    // REQUEST_URI of $HTTP_SERVER_VARS\r
-    $str =& $HTTP_SERVER_VARS["REQUEST_URI"];\r
-    serverStringToArray($str, $array, $frontParam);\r
-    sanitizeArray($array);\r
-    arrayToServerString($array, $frontParam, $str);\r
-\r
-    // QUERY_STRING of $HTTP_SERVER_VARS\r
-    $str =& $HTTP_SERVER_VARS["QUERY_STRING"];\r
-    serverStringToArray($str, $array, $frontParam);\r
-    sanitizeArray($array);\r
-    arrayToServerString($array, $frontParam, $str);\r
-\r
-    if (phpversion() >= '4.1.0') {\r
-        // REQUEST_URI of $_SERVER\r
-        $str =& $_SERVER["REQUEST_URI"];\r
-        serverStringToArray($str, $array, $frontParam);\r
-        sanitizeArray($array);\r
-        arrayToServerString($array, $frontParam, $str);\r
-\r
-        // QUERY_STRING of $_SERVER\r
-        $str =& $_SERVER["QUERY_STRING"];\r
-        serverStringToArray($str, $array, $frontParam);\r
-        sanitizeArray($array);\r
-        arrayToServerString($array, $frontParam, $str);\r
-    }\r
-\r
-    // $_GET\r
-    convArrayForSanitizing($_GET, $array);\r
-    sanitizeArray($array);\r
-    revertArrayForSanitizing($array, $_GET);\r
-\r
-    // $_REQUEST (only GET param)\r
-    convArrayForSanitizing($_REQUEST, $array);\r
-    sanitizeArray($array);\r
-    revertArrayForSanitizing($array, $_REQUEST);\r
+       $array = array();\r
+       $str = '';\r
+       $frontParam = '';\r
+       \r
+       // REQUEST_URI of $_SERVER\r
+       $str =& $_SERVER["REQUEST_URI"];\r
+       serverStringToArray($str, $array, $frontParam);\r
+       sanitizeArray($array);\r
+       arrayToServerString($array, $frontParam, $str);\r
+       \r
+       // QUERY_STRING of $_SERVER\r
+       $str =& $_SERVER["QUERY_STRING"];\r
+       serverStringToArray($str, $array, $frontParam);\r
+       sanitizeArray($array);\r
+       arrayToServerString($array, $frontParam, $str);\r
+       \r
+       // $_GET\r
+       convArrayForSanitizing($_GET, $array);\r
+       sanitizeArray($array);\r
+       revertArrayForSanitizing($array, $_GET);\r
+       \r
+       // $_REQUEST (only GET param)\r
+       convArrayForSanitizing($_REQUEST, $array);\r
+       sanitizeArray($array);\r
+       revertArrayForSanitizing($array, $_REQUEST);\r
+       \r
+       return;\r
 }\r
 \r
 /**\r
@@ -1686,16 +1751,16 @@ function ticketForPlugin()
        \r
        // Solve the plugin name.\r
        $plugins = array();\r
-       $query = 'SELECT pfile FROM '.sql_table('plugin');\r
-       $res = sql_query($query);\r
+       $query = sprintf('SELECT pfile FROM %s', sql_table('plugin'));\r
+       $res = DB::getResult($query);\r
        \r
-       while($row = sql_fetch_row($res) )\r
+       foreach ( $res as $row )\r
        {\r
-               $name = i18n::substr($row[0], 3);\r
+               $name = i18n::substr($row['pfile'], 3);\r
                $plugins[strtolower($name)] = $name;\r
        }\r
        \r
-       sql_free_result($res);\r
+       $res->closeCursor();\r
        \r
        if (array_key_exists($path, $plugins))\r
        {\r
@@ -1829,55 +1894,85 @@ function _addInputTags(&$keys,$prefix=''){
  * Convert the server string such as $_SERVER['REQUEST_URI']\r
  * to arry like arry['blogid']=1 and array['page']=2 etc.\r
  * \r
- * @param      string  $str            string\r
- * @param      string  $array          \r
- * @param      string  $frontParam     \r
+ * @param      string   $uri                           string\r
+ * @param      string  &$query_elements        elements of query according to application/x-www-form-urlencoded\r
+ * @param      string  &$hier_part                     hierarchical part includes path\r
+ * \r
+ * NOTE:\r
+ * RFC 3986: Uniform Resource Identifiers (URI): Generic Syntax\r
+ * 3.  Syntax Components\r
+ * http://www.ietf.org/rfc/rfc3986.txt\r
+ * \r
+ * Hypertext Markup Language - 2.0\r
+ * 8.2.1. The form-urlencoded Media Type\r
+ * http://tools.ietf.org/html/rfc1866#section-8.2.1\r
+ * \r
+ * $_SERVER > Language Reference > Predefined Variables > PHP Manual\r
+ * http://www.php.net/manual/en/reserved.variables.server.php\r
  */\r
-function serverStringToArray($str, &$array, &$frontParam)\r
+function serverStringToArray($uri, &$query_elements, &$hier_part)\r
 {\r
        // init param\r
-       $array = array();\r
-       $frontParam = "";\r
+       $query_elements = array();\r
+       $hier_part = "";\r
        \r
-       // split front param, e.g. /index.php, and others, e.g. blogid=1&page=2\r
-       if ( i18n::strpos($str, "?") > 0 )\r
+       // split hierarchical part, e.g. /index.php, query and fragment, e.g. blogid=1&page=2#section1\r
+       if ( i18n::strpos($uri, "?") > 0 )\r
        {\r
-               list($frontParam, $args) = preg_split("#\?#", $str, 2);\r
+               list($hier_part, $query_and_fragment) = preg_split("#\?#", $uri, 2);\r
        }\r
        else\r
        {\r
-               $args = $str;\r
-               $frontParam = "";\r
+               $query_and_fragment = $uri;\r
+               $hier_part = '';\r
        }\r
        \r
-       // If there is no args like blogid=1&page=2, return\r
-       if ( i18n::strpos($str, "=") == FALSE && !i18n::strlen($frontParam) )\r
+       // If there is no query like blogid=1&page=2, return\r
+       if ( i18n::strpos($uri, "=") == FALSE && !i18n::strlen($hier_part) )\r
        {\r
-               $frontParam = $str;\r
+               $hier_part = $uri;\r
                return;\r
        }\r
        \r
-       $array = preg_split("#&#", $args);\r
+       $query_elements = preg_split("#&#", $query_and_fragment);\r
        return;\r
 }\r
 \r
 /**\r
+ * arrayToServerString()\r
  * Convert array like array['blogid'] to server string\r
  * such as $_SERVER['REQUEST_URI']\r
+ * \r
+ * @param      array    $query_elements        elements of query according to application/x-www-form-urlencoded\r
+ * @param      string   $hier_part                     hier-part defined in RFC3986\r
+ * @param      string  &$uri                           return value\r
+ * @return     void\r
+ * \r
+ * NOTE:\r
+ * RFC 3986: Uniform Resource Identifiers (URI): Generic Syntax\r
+ * 3.  Syntax Components\r
+ * http://www.ietf.org/rfc/rfc3986.txt\r
+ * \r
+ * Hypertext Markup Language - 2.0\r
+ * 8.2.1. The form-urlencoded Media Type\r
+ * http://tools.ietf.org/html/rfc1866#section-8.2.1\r
+ * \r
+ * $_SERVER > Language Reference > Predefined Variables > PHP Manual\r
+ * http://www.php.net/manual/en/reserved.variables.server.php\r
  */\r
-function arrayToServerString($array, $frontParam, &$str)\r
+function arrayToServerString($query_elements, $hier_part, &$uri)\r
 {\r
-       if ( i18n::strpos($str, "?") !== FALSE )\r
+       if ( i18n::strpos($uri, "?") !== FALSE )\r
        {\r
-               $str = $frontParam . "?";\r
+               $uri = $hier_part . "?";\r
        }\r
        else\r
        {\r
-               $str = $frontParam;\r
+               $uri = $hier_part;\r
        }\r
-       if ( count($array) )\r
+       if ( count($query_elements) > 0 )\r
        {\r
-               $str .= implode("&", $array);\r
+               $uri .= implode("&", $query_elements);\r
        }\r
        return;\r
 }\r
@@ -1889,7 +1984,7 @@ function arrayToServerString($array, $frontParam, &$str)
  * - check key if it inclues " (double quote),  remove from array\r
  * - check value if it includes \ (escape sequece), remove remaining string\r
  * \r
- * @param      array   &$array \r
+ * @param      array   &$array elements of query according to application/x-www-form-urlencoded\r
  * @return     void\r
  */\r
 function sanitizeArray(&$array)\r
@@ -1911,6 +2006,7 @@ function sanitizeArray(&$array)
                {\r
                        $val = stripslashes($val);\r
                }\r
+               \r
                // note that we must use addslashes here because this function is called before the db connection is made\r
                // and sql_real_escape_string needs a db connection\r
                $val = addslashes($val);\r
@@ -1919,7 +2015,7 @@ function sanitizeArray(&$array)
                if ( !in_array($key, $excludeListForSanitization) )\r
                {\r
                        // check value\r
-                       if ( i18n::strpos($val, '\\') )\r
+                       if ( i18n::strpos($val, '\\') > 0 )\r
                        {\r
                                list($val, $tmp) = preg_split('#\\\\#', $val);\r
                        }\r
@@ -1928,7 +2024,7 @@ function sanitizeArray(&$array)
                        $val = strtr($val, "\0\r\n<>'\"", "       ");\r
                        \r
                        // check key\r
-                       if ( preg_match('#\"#', $key) )\r
+                       if ( preg_match('#\"#', $key) > 0 )\r
                        {\r
                                unset($array[$k]);\r
                                continue;\r
@@ -1942,27 +2038,45 @@ function sanitizeArray(&$array)
 }\r
 \r
 /**\r
+ * convArrayForSanitizing()\r
  * Convert array for sanitizeArray function\r
+ * \r
+ * @param      string  $src    array to be sanitized\r
+ * @param      array   &$array array to be temporarily stored\r
+ * @return     void\r
  */\r
 function convArrayForSanitizing($src, &$array)\r
 {\r
-    $array = array();\r
-    foreach ($src as $key => $val) {\r
-        if (key_exists($key, $_GET)) {\r
-            array_push($array, sprintf("%s=%s", $key, $val));\r
-        }\r
-    }\r
+       $array = array();\r
+       foreach ( $src as $key => $val )\r
+       {\r
+               if ( !key_exists($key, $_GET) )\r
+               {\r
+                       continue;\r
+               }\r
+               $array[] = sprintf("%s=%s", $key, $val);\r
+               continue;\r
+       }\r
+       return;\r
 }\r
 \r
 /**\r
+ * revertArrayForSanitizing()\r
  * Revert array after sanitizeArray function\r
+ * \r
+ * @param      array   $array  element of query according to application/x-www-form-urlencoded\r
+ * @param      array   &$dst   combination of key and value\r
+ * @return     void\r
  */\r
 function revertArrayForSanitizing($array, &$dst)\r
 {\r
-    foreach ($array as $v) {\r
-        list($key, $val) = preg_split("/=/", $v, 2);\r
-        $dst[$key] = $val;\r
-    }\r
+       foreach ( $array as $v )\r
+       {\r
+               list($key, $val) = preg_split("#=#", $v, 2);\r
+               $dst[$key] = $val;\r
+               continue;\r
+       }\r
+       return;\r
 }\r
 \r
 /**\r
@@ -2035,10 +2149,9 @@ function ifset(&$var) {
  * @return number of subscriber(s)\r
  */\r
 function numberOfEventSubscriber($event) {\r
-    $query = 'SELECT COUNT(*) as count FROM ' . sql_table('plugin_event') . ' WHERE event=\'' . $event . '\'';\r
-    $res = sql_query($query);\r
-    $obj = sql_fetch_object($res);\r
-    return $obj->count;\r
+    $query = sprintf('SELECT COUNT(*) as count FROM %s WHERE event=%s', sql_table('plugin_event'), DB::quoteValue($event));\r
+    $res = DB::getValue($query);\r
+    return $res;\r
 }\r
 \r
 /**\r
@@ -2152,10 +2265,13 @@ function formatDate($format, $timestamp, $default_format, &$blog)
        }\r
        return i18n::formatted_datetime($format, $timestamp, $offset, $default_format);\r
 }\r
-/* NOTE: use i18n::formatted_datetime() directly instead of this */\r
+/**\r
+ * NOTE: use DB::formatDateTime() directly instead of this\r
+ * @deprecated\r
+ */\r
 function mysqldate($timestamp)\r
 {\r
-       return '"' . i18n::formatted_datetime('mysql', $timestamp) . '"';\r
+       return DB::formatDateTime($timestamp);\r
  }\r
 /**\r
  * Centralisation of the functions that generate links\r