OSDN Git Service

For private server which has no condition for default time zone, refering to the...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / globalfunctions.php
index 2b7aa02..1e51478 100755 (executable)
@@ -2,7 +2,7 @@
 \r
 /*\r
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
- * Copyright (C) 2002-2009 The Nucleus Group\r
+ * Copyright (C) 2002-2011 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,7 +12,7 @@
  */\r
 /**\r
  * @license http://nucleuscms.org/license.txt GNU General Public License\r
- * @copyright Copyright (C) 2002-2009 The Nucleus Group\r
+ * @copyright Copyright (C) 2002-2011 The Nucleus Group\r
  * @version $Id$\r
  * $NucleusJP: globalfunctions.php,v 1.23.2.7 2008/02/05 08:30:08 kimitake Exp $\r
  */\r
 // needed if we include globalfunctions from install.php\r
 global $nucleus, $CONF, $DIR_LIBS, $DIR_LANG, $manager, $member;\r
 \r
-$nucleus['version'] = 'v3.40RC';\r
+$nucleus['version'] = 'v3.62_Beta-jp';\r
 $nucleus['codename'] = '';\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_LANG', '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
 $CONF['debug'] = 0;\r
 if ($CONF['debug']) {\r
-       error_reporting(E_ALL); // report all errors!\r
+       error_reporting(E_ALL); // report all errors!\r
 } else {\r
+       ini_set('display_errors','0');\r
        error_reporting(E_ERROR | E_WARNING | E_PARSE);\r
 }\r
 \r
 /*\r
+ * Set default time zone\r
+ * By Japanese Packaging Team, Jan.27, 2011\r
+ * For private server which has no condition for default time zone\r
+ */\r
+\r
+if (function_exists('date_default_timezone_get')) {\r
+       if (FALSE == ($timezone = @date_default_timezone_get()) {\r
+               $timezone = 'UTC';\r
+       }\r
+}\r
+if (function_exists('date_default_timezone_set')) {\r
+        @date_default_timezone_set($timezone);\r
+}\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
@@ -46,21 +63,31 @@ if ($CONF['debug']) {
                more of the installation files (install.php, install.sql, upgrades/\r
                directory) are still on the server.\r
 */\r
+\r
 $CONF['alertOnHeadersSent']  = 1;\r
 $CONF['alertOnSecurityRisk'] = 1;\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
 // switch URLMode back to normal when $CONF['Self'] ends in .php\r
 // this avoids urls like index.php/item/13/index.php/item/15\r
 if (!isset($CONF['URLMode']) || (($CONF['URLMode'] == 'pathinfo') && (substr($CONF['Self'], strlen($CONF['Self']) - 4) == '.php'))) {\r
        $CONF['URLMode'] = 'normal';\r
-}\r
+}*/\r
+\r
+/*\r
+       Set these to 1 to allow viewing of future items or draft items\r
+       Should really never do this, but can be useful for some plugins that might need to\r
+       Could cause some other issues if you use future posts otr drafts\r
+       So use with care\r
+*/\r
+$CONF['allowDrafts'] = 0;\r
+$CONF['allowFuture'] = 0;\r
 \r
 if (getNucleusPatchLevel() > 0) {\r
        $nucleus['version'] .= '/' . getNucleusPatchLevel();\r
@@ -88,23 +115,24 @@ $orgRequestURI = serverVar('REQUEST_URI');
 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
+$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
+$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
+$startpos       = intRequestVar('startpos');\r
 $errormessage = '';\r
-$error        = '';\r
+$error         = '';\r
+$special         = requestVar('special');\r
 $virtualpath  = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));\r
 \r
 if (!headers_sent() ) {\r
@@ -112,7 +140,15 @@ if (!headers_sent() ) {
 }\r
 \r
 // include core classes that are needed for login & plugin handling\r
-include($DIR_LIBS . 'mysql.php');\r
+include_once($DIR_LIBS . 'mysql.php');\r
+// added for 3.5 sql_* wrapper\r
+global $MYSQL_HANDLER;\r
+if (!isset($MYSQL_HANDLER))\r
+       $MYSQL_HANDLER = array('mysql','');\r
+if ($MYSQL_HANDLER[0] == '')\r
+       $MYSQL_HANDLER[0] = 'mysql';\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
@@ -121,7 +157,10 @@ include($DIR_LIBS . 'PLUGIN.php');
 $manager =& MANAGER::instance();\r
 \r
 // make sure there's no unnecessary escaping:\r
-set_magic_quotes_runtime(0);\r
+//set_magic_quotes_runtime(0);\r
+if (version_compare(PHP_VERSION, '5.3.0', '<')) {\r
+       ini_set('magic_quotes_runtime', '0');\r
+}\r
 \r
 // Avoid notices\r
 if (!isset($CONF['UsingAdminArea'])) {\r
@@ -130,7 +169,7 @@ if (!isset($CONF['UsingAdminArea'])) {
 \r
 // only needed when updating logs\r
 if ($CONF['UsingAdminArea']) {\r
-       include($DIR_LIBS . 'xmlrpc.inc.php');  // XML-RPC client classes\r
+       include($DIR_LIBS . 'xmlrpc.inc.php');  // XML-RPC client classes\r
        include_once($DIR_LIBS . 'ADMIN.php');\r
 }\r
 \r
@@ -142,12 +181,12 @@ $SQLCount = 0;
 if ($orgRequestURI!==serverVar('REQUEST_URI')) {\r
        $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";\r
        $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');\r
-    if ($bLoggingSanitizedResult) {\r
-        addToLog(WARNING, $msg);\r
-    }\r
-    if (!$bSanitizeAndContinue) {\r
-        die("");\r
-    }\r
+       if ($bLoggingSanitizedResult) {\r
+               addToLog(WARNING, $msg);\r
+       }\r
+       if (!$bSanitizeAndContinue) {\r
+               die("");\r
+       }\r
 }\r
 \r
 // makes sure database connection gets closed on script termination\r
@@ -164,13 +203,27 @@ if (!isset($CONF['Self'])) {
                $CONF['Self'] = substr($CONF['Self'], 0, strlen($CONF['Self']) -1);\r
        }\r
 \r
-       $CONF['ItemURL']        = $CONF['Self'];\r
-       $CONF['ArchiveURL']     = $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
+       $CONF['MemberURL']        = $CONF['Self'];\r
+       $CONF['SearchURL']        = $CONF['Self'];\r
+       $CONF['BlogURL']                = $CONF['Self'];\r
+       $CONF['CategoryURL']    = $CONF['Self'];*/\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
+\r
+// switch URLMode back to normal when $CONF['Self'] ends in .php\r
+// this avoids urls like index.php/item/13/index.php/item/15\r
+if (!isset($CONF['URLMode']) || (($CONF['URLMode'] == 'pathinfo') && (substr($CONF['Self'], strlen($CONF['Self']) - 4) == '.php'))) {\r
+       $CONF['URLMode'] = 'normal';\r
 }\r
 \r
 // automatically use simpler toolbar for mozilla\r
@@ -205,7 +258,7 @@ if ($action == 'login') {
        // Form Authentication\r
        $login = postVar('login');\r
        $pw = postVar('password');\r
-       $shared = intPostVar('shared'); // shared computer or not\r
+       $shared = intPostVar('shared'); // shared computer or not\r
 \r
        $pw=substr($pw,0,40); // avoid md5 collision by using a long key\r
 \r
@@ -225,13 +278,20 @@ if ($action == 'login') {
                        $action = $nextaction;\r
                }\r
 \r
-               $manager->notify('LoginSuccess', array('member' => &$member) );\r
+               $manager->notify('LoginSuccess', array('member' => &$member, 'username' => $login) );\r
                $errormessage = '';\r
                ACTIONLOG::add(INFO, "Login successful for $login (sharedpc=$shared)");\r
        } else {\r
                // errormessage for [%errordiv%]\r
-               $errormessage = 'Login failed for ' . $login;\r
-\r
+               $trimlogin = trim($login);\r
+               if (empty($trimlogin))\r
+               {\r
+                       $errormessage = "Please enter a username.";\r
+               }\r
+               else \r
+               {\r
+                       $errormessage = 'Login failed for ' . $login;\r
+               } \r
                $manager->notify('LoginFailed', array('username' => $login) );\r
                ACTIONLOG::add(INFO, $errormessage);\r
        }\r
@@ -242,7 +302,7 @@ Backed out for now: See http://forum.nucleuscms.org/viewtopic.php?t=3684 for det
 } elseif (serverVar('PHP_AUTH_USER') && serverVar('PHP_AUTH_PW')) {\r
        // HTTP Authentication\r
        $login  = serverVar('PHP_AUTH_USER');\r
-       $pw     = serverVar('PHP_AUTH_PW');\r
+       $pw      = serverVar('PHP_AUTH_PW');\r
 \r
        if ($member->login($login, $pw) ) {\r
                $manager->notify('LoginSuccess',array('member' => &$member));\r
@@ -317,16 +377,58 @@ if (!headers_sent() ) {
 \r
 // read language file, only after user has been initialized\r
 $language = getLanguageName();\r
-include($DIR_LANG . ereg_replace( '[\\|/]', '', $language) . '.php');\r
+\r
+# replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0\r
+# original ereg_replace: ereg_replace( '[\\|/]', '', $language) . '.php')\r
+# important note that '\' must be matched with '\\\\' in preg* expressions\r
+include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');\r
 \r
 // check if valid charset\r
 if (!encoding_check(false, false, _CHARSET)) {\r
-       foreach(array($_REQUEST, $_SERVER) as $input) {\r
+       foreach(array($_GET, $_POST) as $input) {\r
                array_walk($input, 'encoding_check');\r
        }\r
 }\r
 \r
 /*\r
+ * for preventing I/O strings from auto-detecting the charactor encodings by MySQL\r
+ * since 3.62_beta-jp\r
+ * Jan.20, 2011 by kotorisan and cacher\r
+ * refering to their conversation below,\r
+ * http://japan.nucleuscms.org/bb/viewtopic.php?p=26581\r
+ * \r
+ * NOTE:       shift_jis is only supported for output. Using shift_jis in DB is prohibited.\r
+ * NOTE:       iso-8859-x,windows-125x if _CHARSET is unset.\r
+ */\r
+if (in_array('mysql',$MYSQL_HANDLER)) {\r
+       switch(strtolower(_CHARSET)){\r
+               case 'utf-8':\r
+                       $charset = 'utf8';\r
+                       break;\r
+               case 'euc-jp':\r
+                       $charset = 'ujis';\r
+                       break;\r
+               case 'gb2312':\r
+                       $charset = 'gb2312';\r
+                       break;\r
+               case 'shift_jis':\r
+                       $charset = 'sjis';\r
+                       break;\r
+               default:\r
+                       $resource = sql_query("show variables LIKE 'character_set_database'");\r
+                       $fetchDat = sql_fetch_assoc($resource);\r
+                       $charset  = $fetchDat['Value'];\r
+                       break;\r
+       }\r
+       $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info($MYSQL_CONN))));\r
+       if ($mySqlVer >= '5.0.7' && function_exists('mysql_set_charset')) {\r
+               mysql_set_charset($charset);\r
+       } elseif ($mySqlVer >= '4.1.0') {\r
+               sql_query("SET CHARACTER SET " . $charset);\r
+       }\r
+}\r
+\r
+/*\r
        Backed out for now: See http://forum.nucleuscms.org/viewtopic.php?t=3684 for details\r
 \r
 // To remove after v2.5 is released and language files have been updated.\r
@@ -334,47 +436,49 @@ if (!encoding_check(false, false, _CHARSET)) {
 // without having weird _SETTINGS_EXTAUTH string showing up in the admin area.\r
 if (!defined('_MEMBERS_BYPASS'))\r
 {\r
-       define('_SETTINGS_EXTAUTH',                     'Enable External Authentication');\r
-       define('_WARNING_EXTAUTH',                      'Warning: Enable only if needed.');\r
-       define('_MEMBERS_BYPASS',                       'Use External Authentication');\r
+       define('_SETTINGS_EXTAUTH',              'Enable External Authentication');\r
+       define('_WARNING_EXTAUTH',                'Warning: Enable only if needed.');\r
+       define('_MEMBERS_BYPASS',                  'Use External Authentication');\r
 }\r
 \r
 */\r
 \r
 // make sure the archivetype skinvar keeps working when _ARCHIVETYPE_XXX not defined\r
-if (!defined('_ARCHIVETYPE_MONTH') ) {\r
+if (!defined('_ARCHIVETYPE_MONTH') )\r
+{\r
        define('_ARCHIVETYPE_DAY', 'day');\r
        define('_ARCHIVETYPE_MONTH', 'month');\r
+       define('_ARCHIVETYPE_YEAR', 'year');\r
 }\r
 \r
 // decode path_info\r
 if ($CONF['URLMode'] == 'pathinfo') {\r
        // initialize keywords if this hasn't been done before\r
-       if ($CONF['ItemKey'] == '') {\r
+       if (!isset($CONF['ItemKey']) || $CONF['ItemKey'] == '') {\r
                $CONF['ItemKey'] = 'item';\r
        }\r
 \r
-       if ($CONF['ArchiveKey'] == '') {\r
+       if (!isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '') {\r
                $CONF['ArchiveKey'] = 'archive';\r
        }\r
 \r
-       if ($CONF['ArchivesKey'] == '') {\r
+       if (!isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '') {\r
                $CONF['ArchivesKey'] = 'archives';\r
        }\r
 \r
-       if ($CONF['MemberKey'] == '') {\r
+       if (!isset($CONF['MemberKey']) || $CONF['MemberKey'] == '') {\r
                $CONF['MemberKey'] = 'member';\r
        }\r
 \r
-       if ($CONF['BlogKey'] == '') {\r
+       if (!isset($CONF['BlogKey']) || $CONF['BlogKey'] == '') {\r
                $CONF['BlogKey'] = 'blog';\r
        }\r
 \r
-       if ($CONF['CategoryKey'] == '') {\r
+       if (!isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '') {\r
                $CONF['CategoryKey'] = 'category';\r
        }\r
 \r
-       if ($CONF['SpecialskinKey'] == '') {\r
+       if (!isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '') {\r
                $CONF['SpecialskinKey'] = 'special';\r
        }\r
 \r
@@ -447,13 +551,13 @@ if ($CONF['URLMode'] == 'pathinfo') {
                                        }\r
                                        break;\r
 \r
-                case $CONF['SpecialskinKey']:\r
-                    $i++;\r
+                               case $CONF['SpecialskinKey']:\r
+                                       $i++;\r
 \r
                                        if ($i < sizeof($data) ) {\r
-                       $_REQUEST['special'] = $data[$i];\r
-                    }\r
-                    break;\r
+                                               $special = $data[$i];\r
+                                       }\r
+                                       break;\r
 \r
                                default:\r
                                        // skip...\r
@@ -461,6 +565,37 @@ if ($CONF['URLMode'] == 'pathinfo') {
                }\r
        }\r
 }\r
+/*     PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run.\r
+       It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking\r
+       global variables to clean up (scrub out catid or add catid) or to set someother global variable based on\r
+       the values of something like catid or itemid\r
+       New in 3.60\r
+*/\r
+$manager->notify(\r
+       'PostParseURL',\r
+       array(\r
+               'type' => basename(serverVar('SCRIPT_NAME') ), // e.g. item, blog, ...\r
+               'info' => $virtualpath\r
+       )\r
+);\r
+\r
+function include_libs($file,$once=true,$require=true){\r
+       global $DIR_LIBS;\r
+       if (!is_dir($DIR_LIBS)) exit;\r
+       if ($once && $require) require_once($DIR_LIBS.$file);\r
+       elseif ($once && !$require) include_once($DIR_LIBS.$file);\r
+       elseif ($require) require($DIR_LIBS.$file);\r
+       else include($DIR_LIBS.$file);\r
+}\r
+\r
+function include_plugins($file,$once=true,$require=true){\r
+       global $DIR_PLUGINS;\r
+       if (!is_dir($DIR_PLUGINS)) exit;\r
+       if ($once && $require) require_once($DIR_PLUGINS.$file);\r
+       elseif ($once && !$require) include_once($DIR_PLUGINS.$file);\r
+       elseif ($require) require($DIR_PLUGINS.$file);\r
+       else include($DIR_PLUGINS.$file);\r
+}\r
 \r
 function intPostVar($name) {\r
        return intval(postVar($name) );\r
@@ -482,7 +617,7 @@ function intCookieVar($name) {
   * returns the currently used version (100 = 1.00, 101 = 1.01, etc...)\r
   */\r
 function getNucleusVersion() {\r
-       return 340;\r
+       return 362;\r
 }\r
 \r
 /**\r
@@ -495,8 +630,28 @@ function getNucleusPatchLevel() {
 }\r
 \r
 /**\r
+ * returns the latest version available for download from nucleuscms.org \r
+ * or false if unable to attain data\r
+ * format will be major.minor/patachlevel\r
+ * e.g. 3.41 or 3.41/02\r
+ */\r
+function getLatestVersion() {\r
+       if (!function_exists('curl_init')) return false;\r
+       $crl = curl_init();\r
+       $timeout = 5;\r
+       curl_setopt ($crl, CURLOPT_URL,'http://nucleuscms.org/version_check.php');\r
+       curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);\r
+       curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);\r
+       $ret = curl_exec($crl);\r
+       curl_close($crl);\r
+       return $ret;\r
+\r
+}\r
+\r
+/**\r
   * Connects to mysql server\r
   */\r
+/* moved to $DIR_LIBS/sql/*.php handler files\r
 function sql_connect() {\r
        global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_CONN;\r
 \r
@@ -504,7 +659,7 @@ function sql_connect() {
        mysql_select_db($MYSQL_DATABASE) or startUpError('<p>Could not select database: ' . mysql_error() . '</p>', 'Connect Error');\r
 \r
        return $MYSQL_CONN;\r
-}\r
+}*/\r
 \r
 /**\r
  * returns a prefixed nucleus table name\r
@@ -527,18 +682,18 @@ function sendContentType($contenttype, $pagetype = '', $charset = _CHARSET) {
                // 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
+               //         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
+               //         application/xhtml+xml seems to be working, so we're going to use it if we can.\r
                //\r
                // Note: reverted the following function in JP version\r
                //\r
        /*\r
-               // v3.3 code\r
+               // v3.3 code\r
                if (\r
                                ($contenttype == 'application/xhtml+xml')\r
-                       &&      (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') )\r
+                       &&  (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') )\r
                        ) {\r
                        $contenttype = 'text/html';\r
                }\r
@@ -546,7 +701,7 @@ function sendContentType($contenttype, $pagetype = '', $charset = _CHARSET) {
                // v3.2x code\r
                if (\r
                                ($contenttype == 'application/xhtml+xml')\r
-                       &&      (($CONF['UsingAdminArea'] && !$CONF['debug']) || !stristr(serverVar('HTTP_ACCEPT'),'application/xhtml+xml'))\r
+                       &&  (($CONF['UsingAdminArea'] && !$CONF['debug']) || !stristr(serverVar('HTTP_ACCEPT'),'application/xhtml+xml'))\r
                        )\r
                {\r
                        $contenttype = 'text/html';\r
@@ -573,7 +728,7 @@ function sendContentType($contenttype, $pagetype = '', $charset = _CHARSET) {
 \r
                // check if valid charset\r
                if (!encoding_check(false,false,$charset)) {\r
-                       foreach(array($_REQUEST, $_SERVER) as $input) {\r
+                       foreach(array($_GET, $_POST) as $input) {\r
                                array_walk($input, 'encoding_check');\r
                        }\r
                }\r
@@ -581,8 +736,9 @@ function sendContentType($contenttype, $pagetype = '', $charset = _CHARSET) {
 }\r
 \r
 /**\r
- * Errors before the database connection has been made\r
+ * Errors before the database connection has been made - moved to\r
  */\r
+/* moved to $DIR_LIBS/sql/*.php handler files\r
 function startUpError($msg, $title) {\r
        if (!defined('_CHARSET')) define('_CHARSET', 'iso-8859-1');\r
        header('Content-Type: text/html; charset=' . _CHARSET);\r
@@ -595,76 +751,84 @@ function startUpError($msg, $title) {
                        <?php echo $msg?>\r
                </body>\r
        </html>\r
-       <?php   exit;\r
-}\r
+       <?php   exit;\r
+}*/\r
 \r
 /**\r
   * disconnects from SQL server\r
   */\r
+/* moved to $DIR_LIBS/sql/*.php handler files\r
 function sql_disconnect() {\r
        @mysql_close();\r
-}\r
+}*/\r
 \r
 /**\r
   * executes an SQL query\r
   */\r
+/* moved to $DIR_LIBS/sql/*.php handler files\r
 function sql_query($query) {\r
        global $SQLCount;\r
        $SQLCount++;\r
        $res = mysql_query($query) or print("mySQL error with query $query: " . mysql_error() . '<p />');\r
        return $res;\r
-}\r
-\r
+}*/\r
 \r
 /**\r
  * Highlights a specific query in a given HTML text (not within HTML tags) and returns it\r
- *\r
- * @param $text\r
- *             text to be highlighted\r
- * @param $expression\r
- *             regular expression to be matched (can be an array of expressions as well)\r
- * @param $highlight\r
- *             highlight to be used (use \\0 to indicate the matched expression)\r
- *\r
- */\r
+ * @param string $text text to be highlighted\r
+ * @param string $expression regular expression to be matched (can be an array of expressions as well)\r
+ * @param string $highlight highlight to be used (use \\0 to indicate the matched expression)\r
+ * @return string\r
+ **/\r
 function highlight($text, $expression, $highlight) {\r
-       if (!$highlight || !$expression) {\r
+       if (!$highlight || !$expression)\r
+       {\r
                return $text;\r
        }\r
-\r
-       if (is_array($expression) && (count($expression) == 0) ) {\r
+       \r
+       if (is_array($expression) && (count($expression) == 0) )\r
+       {\r
                return $text;\r
        }\r
-\r
+       \r
        // add a tag in front (is needed for preg_match_all to work correct)\r
        $text = '<!--h-->' . $text;\r
-\r
+       \r
        // split the HTML up so we have HTML tags\r
        // $matches[0][i] = HTML + text\r
        // $matches[1][i] = HTML\r
        // $matches[2][i] = text\r
        preg_match_all('/(<[^>]+>)([^<>]*)/', $text, $matches);\r
-\r
+       \r
        // throw it all together again while applying the highlight to the text pieces\r
        $result = '';\r
-       for ($i = 0; $i < sizeof($matches[2]); $i++) {\r
-               if ($i != 0) {\r
+       $count_matches = count($matches[2]);\r
+       for ($i = 0; $i < $count_matches; $i++) {\r
+               if ($i != 0)\r
+               {\r
                        $result .= $matches[1][$i];\r
                }\r
-\r
-               if (is_array($expression) ) {\r
-                       foreach ($expression as $regex) {\r
-                               if ($regex) {\r
-                                       $matches[2][$i] = @eregi_replace($regex, $highlight, $matches[2][$i]);\r
+               \r
+               if (is_array($expression) )\r
+               {\r
+                       foreach ($expression as $regex)\r
+                       {\r
+                               if ($regex)\r
+                               {\r
+                                       //$matches[2][$i] = @eregi_replace($regex, $highlight, $matches[2][$i]);\r
+                                       $matches[2][$i] = @preg_replace("#".$regex."#i", $highlight, $matches[2][$i]);\r
                                }\r
                        }\r
-\r
+                       \r
                        $result .= $matches[2][$i];\r
-               } else {\r
-                       $result .= @eregi_replace($expression, $highlight, $matches[2][$i]);\r
+               }\r
+               else\r
+               {\r
+                       //$result .= @eregi_replace($expression, $highlight, $matches[2][$i]);\r
+                       $result .= @preg_replace("#".$expression."#i", $highlight, $matches[2][$i]);\r
                }\r
        }\r
-\r
+       \r
        return $result;\r
 }\r
 \r
@@ -677,7 +841,7 @@ function parseHighlight($query) {
        // get rid of quotes\r
        $query = preg_replace('/\'|"/', '', $query);\r
 \r
-       if (!query) {\r
+       if (!$query) {\r
                return array();\r
        }\r
 \r
@@ -686,9 +850,9 @@ function parseHighlight($query) {
        for ($i = 0; $i < count($aHighlight); $i++) {\r
                $aHighlight[$i] = trim($aHighlight[$i]);\r
 \r
-               if (strlen($aHighlight[$i]) < 3) {\r
-                       unset($aHighlight[$i]);\r
-               }\r
+//             if (strlen($aHighlight[$i]) < 3) {\r
+//                     unset($aHighlight[$i]);\r
+//             }\r
        }\r
 \r
        if (count($aHighlight) == 1) {\r
@@ -702,17 +866,17 @@ function parseHighlight($query) {
   * Checks if email address is valid\r
   */\r
 function isValidMailAddress($address) {\r
-       if (preg_match('/^[a-zA-Z+0-9\._-]+@[a-zA-Z0-9\._-]+\.[A-Za-z]{2,5}$/', $address)) {\r
+       // enhancement made in 3.6x based on code by Quandary.\r
+       if (preg_match('/^(?!\\.)(?:\\.?[-a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~]+)+@(?!\\.)(?:\\.?(?!-)[-a-zA-Z0-9]+(?<!-)){2,}$/', $address)) {\r
                return 1;\r
        } else {\r
                return 0;\r
        }\r
 }\r
 \r
-\r
 // some helper functions\r
 function getBlogIDFromName($name) {\r
-       return quickQuery('SELECT bnumber as result FROM ' . sql_table('blog') . ' WHERE bshortname="' . addslashes($name) . '"');\r
+       return quickQuery('SELECT bnumber as result FROM ' . sql_table('blog') . ' WHERE bshortname="' . sql_real_escape_string($name) . '"');\r
 }\r
 \r
 function getBlogNameFromID($id) {\r
@@ -732,25 +896,25 @@ function getBlogIDFromCatID($catid) {
 }\r
 \r
 function getCatIDFromName($name) {\r
-       return quickQuery('SELECT catid as result FROM ' . sql_table('category') . ' WHERE cname="' . addslashes($name) . '"');\r
+       return quickQuery('SELECT catid as result FROM ' . sql_table('category') . ' WHERE cname="' . sql_real_escape_string($name) . '"');\r
 }\r
 \r
 function quickQuery($q) {\r
        $res = sql_query($q);\r
-       $obj = mysql_fetch_object($res);\r
+       $obj = sql_fetch_object($res);\r
        return $obj->result;\r
 }\r
 \r
 function getPluginNameFromPid($pid) {\r
        $res = sql_query('SELECT pfile FROM ' . sql_table('plugin') . ' WHERE pid=' . intval($pid) );\r
-       $obj = mysql_fetch_object($res);\r
+       $obj = sql_fetch_object($res);\r
        return $obj->pfile;\r
 }\r
 \r
 function selector() {\r
        global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;\r
        global $archive, $skinid, $blog, $memberinfo, $CONF, $member;\r
-       global $imagepopup, $catid;\r
+       global $imagepopup, $catid, $special;\r
        global $manager;\r
 \r
        $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');\r
@@ -773,14 +937,14 @@ function selector() {
                // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+)\r
                if (function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') ) {\r
                        headers_sent($hsFile, $hsLine);\r
-                       $extraInfo = ' in <code>' . $hsFile . '</code> line <code>' . $hsLine . '</code>';\r
+                       $extraInfo = sprintf(_GFUNCTIONS_HEADERSALREADYSENT_FILE,$hsFile,$hsLine);\r
                } else {\r
                        $extraInfo = '';\r
                }\r
 \r
                startUpError(\r
-                       '<p>The page headers have already been sent out' . $extraInfo . '. This could cause Nucleus not to work in the expected way.</p><p>Usually, this is caused by spaces or newlines at the end of the <code>config.php</code> file, at the end of the language file or at the end of a plugin file. Please check this and try again.</p><p>If you don\'t want to see this error message again, without solving the problem, set <code>$CONF[\'alertOnHeadersSent\']</code> in <code>globalfunctions.php</code> to <code>0</code></p>',\r
-                       'Page headers already sent'\r
+                       sprintf(_GFUNCTIONS_HEADERSALREADYSENT_TXT,$extraInfo),\r
+                       _GFUNCTIONS_HEADERSALREADYSENT_TITLE\r
                );\r
                exit;\r
        }\r
@@ -796,7 +960,7 @@ function selector() {
                // itemid given -> only show that item\r
                $type = 'item';\r
 \r
-               if (!$manager->existsItem($itemid,0,0) ) {\r
+               if (!$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts']))) {\r
                        doError(_ERROR_NOSUCHITEM);\r
                }\r
 \r
@@ -805,13 +969,11 @@ function selector() {
                // 1. get timestamp, blogid and catid for item\r
                $query = 'SELECT itime, iblog, icat FROM ' . sql_table('item') . ' WHERE inumber=' . intval($itemid);\r
                $res = sql_query($query);\r
-               $obj = mysql_fetch_object($res);\r
+               $obj = sql_fetch_object($res);\r
 \r
                // if a different blog id has been set through the request or selectBlog(),\r
                // deny access\r
-//             if ($blogid && (intval($blogid) != $obj->iblog) ) {\r
-//                     doError(_ERROR_NOSUCHITEM);\r
-//             }\r
+               \r
                if ($blogid && (intval($blogid) != $obj->iblog) ) {\r
                        if (!headers_sent()) {\r
                                $b =& $manager->getBlog($obj->iblog);\r
@@ -839,13 +1001,15 @@ function selector() {
 \r
                if ($b->isValidCategory($catid) ) {\r
                        $catextra = ' and icat=' . $catid;\r
+               } else {\r
+                       $catextra = '';\r
                }\r
 \r
                // get previous itemid and title\r
                $query = 'SELECT inumber, ititle FROM ' . sql_table('item') . ' WHERE itime<' . mysqldate($timestamp) . ' and idraft=0 and iblog=' . $blogid . $catextra . ' ORDER BY itime DESC LIMIT 1';\r
                $res = sql_query($query);\r
 \r
-               $obj = mysql_fetch_object($res);\r
+               $obj = sql_fetch_object($res);\r
 \r
                if ($obj) {\r
                        $itemidprev = $obj->inumber;\r
@@ -856,7 +1020,7 @@ function selector() {
                $query = 'SELECT inumber, ititle FROM ' . sql_table('item') . ' WHERE itime>' . mysqldate($timestamp) . ' and itime <= ' . mysqldate($b->getCorrectTime()) . ' and idraft=0 and iblog=' . $blogid . $catextra . ' ORDER BY itime ASC LIMIT 1';\r
                $res = sql_query($query);\r
 \r
-               $obj = mysql_fetch_object($res);\r
+               $obj = sql_fetch_object($res);\r
 \r
                if ($obj) {\r
                        $itemidnext = $obj->inumber;\r
@@ -869,7 +1033,7 @@ function selector() {
 \r
                // get next and prev month links ...\r
                global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;\r
-               \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 AND iblog=".(int)($blogid ? $blogid : $CONF['DefaultBlog'])." ORDER BY itime ASC";\r
                $first_timestamp=quickQuery ($query);\r
@@ -881,18 +1045,18 @@ function selector() {
                if ($d != 0) {\r
                        $archivetype = _ARCHIVETYPE_DAY;\r
                        $t = mktime(0, 0, 0, $m, $d, $y);\r
-                       // one day has 24 * 60 * 60 = 86400 seconds                     \r
+                       // one day has 24 * 60 * 60 = 86400 seconds\r
                        $archiveprev = strftime('%Y-%m-%d', $t - 86400 );\r
-                       // check for published items                    \r
+                       // check for published items\r
                        if ($t > $first_timestamp) {\r
                                $archiveprevexists = true;\r
                        }\r
                        else {\r
                                $archiveprevexists = false;\r
                        }\r
-                       \r
+\r
                        // one day later\r
-                       $t += 86400; \r
+                       $t += 86400;\r
                        $archivenext = strftime('%Y-%m-%d', $t);\r
                        if ($t < $last_timestamp) {\r
                                $archivenextexists = true;\r
@@ -900,7 +1064,28 @@ function selector() {
                        else {\r
                                $archivenextexists = false;\r
                        }\r
-                       \r
+\r
+               } elseif ($m == 0) {\r
+                       $archivetype = _ARCHIVETYPE_YEAR;\r
+                       $t = mktime(0, 0, 0, 12, 31, $y - 1);\r
+                       // one day before is in the previous year\r
+                       $archiveprev = strftime('%Y', $t);\r
+                       if ($t > $first_timestamp) {\r
+                               $archiveprevexists = true;\r
+                       }\r
+                       else {\r
+                               $archiveprevexists = false;\r
+                       }\r
+\r
+                       // timestamp for the next year\r
+                       $t = mktime(0, 0, 0, 1, 1, $y + 1);\r
+                       $archivenext = strftime('%Y', $t);\r
+                       if ($t < $last_timestamp) {\r
+                               $archivenextexists = true;\r
+                       }\r
+                       else {\r
+                               $archivenextexists = false;\r
+                       }\r
                } else {\r
                        $archivetype = _ARCHIVETYPE_MONTH;\r
                        $t = mktime(0, 0, 0, $m, 1, $y);\r
@@ -912,8 +1097,8 @@ function selector() {
                        else {\r
                                $archiveprevexists = false;\r
                        }\r
-                       \r
-                       // timestamp for the next month                 \r
+\r
+                       // timestamp for the next month\r
                        $t = mktime(0, 0, 0, $m+1, 1, $y);\r
                        $archivenext = strftime('%Y-%m', $t);\r
                        if ($t < $last_timestamp) {\r
@@ -944,8 +1129,26 @@ function selector() {
                if(preg_match("/^(\xA1{2}|\xe3\x80{2}|\x20)+$/", $query)){\r
                                        $type = 'index';\r
                }\r
-               $order = (_CHARSET == 'EUC-JP') ? 'EUC-JP, UTF-8,' : 'UTF-8, EUC-JP,';\r
-               $query = mb_convert_encoding($query, _CHARSET, $order . ' JIS, SJIS, ASCII');\r
+//             $order = (_CHARSET == 'EUC-JP') ? 'EUC-JP, UTF-8,' : 'UTF-8, EUC-JP,';\r
+//             $query = mb_convert_encoding($query, _CHARSET, $order . ' JIS, SJIS, ASCII');\r
+               switch(strtolower(_CHARSET)){\r
+                       case 'utf-8':\r
+                               $order = 'ASCII, UTF-8, EUC-JP, JIS, SJIS, EUC-CN, ISO-8859-1';\r
+                               break;\r
+                       case 'gb2312':\r
+                               $order = 'ASCII, EUC-CN, EUC-JP, UTF-8, JIS, SJIS, ISO-8859-1';\r
+                               break;\r
+                       case 'shift_jis':\r
+                               // Note that shift_jis is only supported for output.\r
+                               // Using shift_jis in DB is prohibited.\r
+                               $order = 'ASCII, SJIS, EUC-JP, UTF-8, JIS, EUC-CN, ISO-8859-1';\r
+                               break;\r
+                       default:\r
+                               // euc-jp,iso-8859-x,windows-125x\r
+                               $order = 'ASCII, EUC-JP, UTF-8, JIS, SJIS, EUC-CN, ISO-8859-1';\r
+                               break;\r
+               }\r
+               $query = mb_convert_encoding($query, _CHARSET, $order);\r
                if (is_numeric($blogid)) {\r
                        $blogid = intVal($blogid);\r
                } else {\r
@@ -977,13 +1180,18 @@ function selector() {
                $type = 'index';\r
        }\r
 \r
+       // any type of skin with catid\r
+       if ($catid && !$blogid) {\r
+               $blogid = getBlogIDFromCatID($catid);\r
+       }\r
+\r
        // decide which blog should be displayed\r
        if (!$blogid) {\r
                $blogid = $CONF['DefaultBlog'];\r
        }\r
 \r
        $b =& $manager->getBlog($blogid);\r
-       $blog = $b;     // references can't be placed in global variables?\r
+       $blog = $b; // references can't be placed in global variables?\r
 \r
        if (!$blog->isValid) {\r
                doError(_ERROR_NOSUCHBLOG);\r
@@ -991,7 +1199,12 @@ function selector() {
 \r
        // set catid if necessary\r
        if ($catid) {\r
-               $blog->setSelectedCategory($catid);\r
+               // check if the category is valid\r
+               if (!$blog->isValidCategory($catid)) {\r
+                       doError(_ERROR_NOSUCHCATEGORY);\r
+               } else {\r
+                       $blog->setSelectedCategory($catid);\r
+               }\r
        }\r
 \r
        // decide which skin should be used\r
@@ -1003,7 +1216,7 @@ function selector() {
                $skinid = $blog->getDefaultSkin();\r
        }\r
 \r
-       $special = requestVar('special');\r
+       //$special = requestVar('special'); //get at top of file as global\r
        if (!empty($special) && isValidShortName($special)) {\r
                $type = strtolower($special);\r
        }\r
@@ -1013,7 +1226,11 @@ function selector() {
        if (!$skin->isValid) {\r
                doError(_ERROR_NOSUCHSKIN);\r
        }\r
-\r
+       \r
+       // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude\r
+       global $skinpart;\r
+       $skinpart = $type;\r
+       \r
        // parse the skin\r
        $skin->parse($type);\r
 \r
@@ -1044,6 +1261,7 @@ function doError($msg, $skin = '') {
 \r
        }\r
 \r
+       $skinid = $skin->id;\r
        $errormessage = $msg;\r
        $skin->parse('error');\r
        exit;\r
@@ -1055,18 +1273,22 @@ function getConfig() {
        $query = 'SELECT * FROM ' . sql_table('config');\r
        $res = sql_query($query);\r
 \r
-       while ($obj = mysql_fetch_object($res) ) {\r
+       while ($obj = sql_fetch_object($res) ) {\r
                $CONF[$obj->name] = $obj->value;\r
        }\r
 }\r
 \r
 // some checks for names of blogs, categories, templates, members, ...\r
 function isValidShortName($name) {\r
-       return eregi('^[a-z0-9]+$', $name);\r
+       # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+       # original eregi: eregi('^[a-z0-9]+$', $name)\r
+       return preg_match('#^[a-z0-9]+$#i', $name);\r
 }\r
 \r
 function isValidDisplayName($name) {\r
-       return eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name);\r
+       # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+       # original eregi: eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name)\r
+       return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name);\r
 }\r
 \r
 function isValidCategoryName($name) {\r
@@ -1074,11 +1296,15 @@ function isValidCategoryName($name) {
 }\r
 \r
 function isValidTemplateName($name) {\r
-       return eregi('^[a-z0-9/]+$', $name);\r
+       # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+       # original eregi: eregi('^[a-z0-9/]+$', $name)\r
+       return preg_match('#^[a-z0-9/]+$#i', $name);\r
 }\r
 \r
 function isValidSkinName($name) {\r
-       return eregi('^[a-z0-9/]+$', $name);\r
+       # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+       # original eregi: eregi('^[a-z0-9/]+$', $name);\r
+       return preg_match('#^[a-z0-9/]+$#i', $name);\r
 }\r
 \r
 // add and remove linebreaks\r
@@ -1100,8 +1326,11 @@ function shorten($text, $maxlength, $toadd) {
        $text  = strtr($text, $trans);\r
 \r
        // 2. the actual shortening\r
-       if (strlen($text) > $maxlength)\r
-               $text = mb_strimwidth($text, 0, $maxlength, $toadd, _CHARSET);\r
+       if (strlen($text) > $maxlength) {\r
+//             $text = substr($text, 0, $maxlength - strlen($toadd) ) . $toadd;\r
+               $text = mb_strimwidth($text, 0, $maxlength, $toadd, _CHARSET); // for Japanese\r
+       }\r
+\r
        return $text;\r
 }\r
 \r
@@ -1118,7 +1347,9 @@ function mysqldate($timestamp) {
   */\r
 function selectBlog($shortname) {\r
        global $blogid, $archivelist;\r
-       $blogid = getBlogIDFromName($shortname);\r
+       if (!$blogid) {\r
+               $blogid = getBlogIDFromName($shortname);\r
+       }\r
 \r
        // also force archivelist variable, if it is set\r
        if ($archivelist) {\r
@@ -1128,7 +1359,9 @@ function selectBlog($shortname) {
 \r
 function selectSkin($skinname) {\r
        global $skinid;\r
-       $skinid = SKIN::getIdFromName($skinname);\r
+       if (!$skinid) {\r
+               $skinid = SKIN::getIdFromName($skinname);\r
+       }\r
 }\r
 \r
 /**\r
@@ -1137,22 +1370,33 @@ function selectSkin($skinname) {
  */\r
 function selectCategory($cat) {\r
        global $catid;\r
-       if (is_numeric($cat) ) {\r
-               $catid = intval($cat);\r
-       } else {\r
-               $catid = getCatIDFromName($cat);\r
+       if (!$catid) {\r
+               if (is_numeric($cat) ) {\r
+                       $catid = intval($cat);\r
+               } else {\r
+                       $catid = getCatIDFromName($cat);\r
+               }\r
        }\r
 }\r
 \r
 function selectItem($id) {\r
        global $itemid;\r
-       $itemid = intval($id);\r
+       if (!$itemid) {\r
+               $itemid = intval($id);\r
+       }\r
 }\r
 \r
 // force the use of a language file (warning: can cause warnings)\r
 function selectLanguage($language) {\r
+\r
        global $DIR_LANG;\r
-       include($DIR_LANG . ereg_replace( '[\\|/]', '', $language) . '.php');\r
+\r
+       # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0\r
+       # original ereg_replace: preg_replace( '@\\|/@', '', $language) . '.php')\r
+       # important note that '\' must be matched with '\\\\' in preg* expressions\r
+\r
+       include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');\r
+\r
 }\r
 \r
 function parseFile($filename, $includeMode = 'normal', $includePrefix = '') {\r
@@ -1165,7 +1409,7 @@ function parseFile($filename, $includeMode = 'normal', $includePrefix = '') {
        PARSER::setProperty('IncludePrefix', $includePrefix);\r
 \r
        if (!file_exists($filename) ) {\r
-               doError('A file is missing');\r
+               doError(_GFUNCTIONS_PARSEFILE_FILEMISSING);\r
        }\r
 \r
        $fsize = filesize($filename);\r
@@ -1201,11 +1445,13 @@ function help($id) {
 }\r
 \r
 function helpHtml($id) {\r
-       return helplink($id) . '<img src="documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" /></a>';\r
+       global $CONF;\r
+       return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" title="' . _HELP_TT . '" /></a>';\r
 }\r
 \r
 function helplink($id) {\r
-       return '<a href="documentation/help.html#'. $id . '" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return help(this.href);">';\r
+       global $CONF;\r
+       return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return help(this.href);">';\r
 }\r
 \r
 function getMailFooter() {\r
@@ -1270,16 +1516,33 @@ function includephp($filename) {
 }\r
 \r
 /**\r
-  * Checks if a certain language/plugin exists\r
-  */\r
+ * Checks if a certain language exists\r
+ * @param string $lang\r
+ * @return bool\r
+ **/\r
 function checkLanguage($lang) {\r
-       global $DIR_LANG ;\r
-       return file_exists($DIR_LANG . ereg_replace( '[\\|/]', '', $lang) . '.php');\r
+       global $DIR_LANG;\r
+       # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0\r
+       # original ereg_replace: ereg_replace( '[\\|/]', '', $lang) . '.php')\r
+       # important note that '\' must be matched with '\\\\' in preg* expressions\r
+       return file_exists($DIR_LANG . preg_replace('#[\\\\|/]#', '', $lang) . '.php');\r
 }\r
 \r
+/**\r
+ * Checks if a certain plugin exists\r
+ * @param string $plug\r
+ * @return bool\r
+ **/\r
 function checkPlugin($plug) {\r
+\r
        global $DIR_PLUGINS;\r
-       return file_exists($DIR_PLUGINS . ereg_replace( '[\\|/]', '', $plug) . '.php');\r
+\r
+       # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0\r
+       # original ereg_replace: ereg_replace( '[\\|/]', '', $plug) . '.php')\r
+       # important note that '\' must be matched with '\\\\' in preg* expressions\r
+\r
+       return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $plug) . '.php');\r
+\r
 }\r
 \r
 /**\r
@@ -1394,17 +1657,17 @@ function createLink($type, $params) {
 }\r
 \r
 function createBlogLink($url, $params) {\r
-    global $CONF;\r
-    if ($CONF['URLMode'] == 'normal') {\r
-        if (strpos($url, '?') === FALSE && is_array($params)) {\r
-            $fParam = reset($params);\r
-            $fKey   = key($params);\r
-            array_shift($params);\r
-            $url .= '?' . $fKey . '=' . $fParam;\r
-        }\r
-    } elseif ($CONF['URLMode'] == 'pathinfo' && substr($url, -1) == '/') {\r
-        $url = substr($url, 0, -1);\r
-    }\r
+       global $CONF;\r
+       if ($CONF['URLMode'] == 'normal') {\r
+               if (strpos($url, '?') === FALSE && is_array($params)) {\r
+                       $fParam = reset($params);\r
+                       $fKey   = key($params);\r
+                       array_shift($params);\r
+                       $url .= '?' . $fKey . '=' . $fParam;\r
+               }\r
+       } elseif ($CONF['URLMode'] == 'pathinfo' && substr($url, -1) == '/') {\r
+               $url = substr($url, 0, -1);\r
+       }\r
        return addLinkParams($url, $params);\r
 }\r
 \r
@@ -1413,7 +1676,7 @@ function addLinkParams($link, $params) {
 \r
        if (is_array($params) ) {\r
 \r
-               if ($CONF['URLMode'] == 'pathinfo')     {\r
+               if ($CONF['URLMode'] == 'pathinfo') {\r
 \r
                        foreach ($params as $param => $value) {\r
                                $link .= '/' . $param . '/' . urlencode($value);\r
@@ -1624,119 +1887,153 @@ function checkVars($aVars) {
 }\r
 \r
 \r
-/** \r
+/**\r
  * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.\r
- * to avoid XSS \r
+ * to avoid XSS\r
  */\r
 function sanitizeParams()\r
 {\r
        global $HTTP_SERVER_VARS;\r
-       \r
+\r
        $array = array();\r
        $str = '';\r
        $frontParam = '';\r
-       \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
+\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
+\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
+\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
+\r
        // $_GET\r
        convArrayForSanitizing($_GET, $array);\r
        sanitizeArray($array);\r
        revertArrayForSanitizing($array, $_GET);\r
-       \r
+\r
        // $_REQUEST (only GET param)\r
        convArrayForSanitizing($_REQUEST, $array);\r
        sanitizeArray($array);\r
        revertArrayForSanitizing($array, $_REQUEST);\r
 }\r
 \r
-/** \r
+/**\r
  * Check ticket when not checked in plugin's admin page\r
  * to avoid CSRF.\r
  * Also avoid the access to plugin/index.php by guest user.\r
  */\r
 function ticketForPlugin(){\r
        global $CONF,$DIR_PLUGINS,$member,$ticketforplugin;\r
-       \r
+\r
        /* initialize */\r
        $ticketforplugin=array();\r
-       $ticketforplugin['ticket']=false;\r
+       $ticketforplugin['ticket'] = FALSE;\r
        \r
        /* Check if using plugin's php file. */\r
-       if ($p_translated=serverVar('PATH_TRANSLATED')) {\r
-               if (!file_exists($p_translated)) $p_translated='';\r
+       if ($p_translated = serverVar('PATH_TRANSLATED') )\r
+       {\r
+               if (!file_exists($p_translated) )\r
+               {\r
+                       $p_translated = '';\r
+               }\r
        }\r
-       if (!$p_translated) {\r
-               $p_translated=serverVar('SCRIPT_FILENAME');\r
-               if (!file_exists($p_translated)) {\r
+       \r
+       if (!$p_translated)\r
+       {\r
+               $p_translated = serverVar('SCRIPT_FILENAME');\r
+               if (!file_exists($p_translated) )\r
+               {\r
                        header("HTTP/1.0 404 Not Found");\r
                        exit('');\r
                }\r
        }\r
+       \r
        $p_translated=str_replace('\\','/',$p_translated);\r
        $d_plugins=str_replace('\\','/',$DIR_PLUGINS);\r
-       if (strpos($p_translated,$d_plugins)!==0) return;// This isn't plugin php file.\r
+       \r
+       if (strpos($p_translated, $d_plugins) !== 0)\r
+       {\r
+               return;// This isn't plugin php file.\r
+       }\r
        \r
        /* Solve the plugin php file or admin directory */\r
        $phppath=substr($p_translated,strlen($d_plugins));\r
-       $phppath=preg_replace('!^/!','',$phppath);// Remove the first "/" if exists.\r
-       $path=preg_replace('/^NP_(.*)\.php$/','$1',$phppath); // Remove the first "NP_" and the last ".php" if exists.\r
-       $path=preg_replace('!^([^/]*)/(.*)$!','$1',$path); // Remove the "/" and beyond.\r
-       \r
+       $phppath=preg_replace('#^/#','',$phppath);// Remove the first "/" if exists.\r
+       $path=preg_replace('#^NP_(.*)\.php$#','$1',$phppath); // Remove the first "NP_" and the last ".php" if exists.\r
+       $path=preg_replace('#^([^/]*)/(.*)$#','$1',$path); // Remove the "/" and beyond.\r
+\r
        /* Solve the plugin name. */\r
        $plugins=array();\r
-       $query='SELECT pfile FROM '.sql_table('plugin');\r
+       $query='SELECT `pfile` FROM '.sql_table('plugin');\r
        $res=sql_query($query);\r
-       while($row=mysql_fetch_row($res)) {\r
+       while($row=sql_fetch_row($res))\r
+       {\r
                $name=substr($row[0],3);\r
                $plugins[strtolower($name)]=$name;\r
        }\r
-       mysql_free_result($res);\r
-       if ($plugins[$path]) $plugin_name=$plugins[$path];\r
-       else if (in_array($path,$plugins)) $plugin_name=$path;\r
-       else {\r
+       sql_free_result($res);\r
+       \r
+       if ($plugins[$path])\r
+       {\r
+               $plugin_name = $plugins[$path];\r
+       }\r
+       else if (in_array($path, $plugins))\r
+       {\r
+               $plugin_name = $path;\r
+       }\r
+       else\r
+       {\r
                header("HTTP/1.0 404 Not Found");\r
                exit('');\r
        }\r
        \r
        /* Return if not index.php */\r
-       if ( $phppath!=strtolower($plugin_name).'/'\r
-               && $phppath!=strtolower($plugin_name).'/index.php' ) return;\r
-       \r
+       if ( ($phppath != strtolower($plugin_name) . '/') && ($phppath != strtolower($plugin_name) . '/index.php') )\r
+       {\r
+               return;\r
+       }\r
+\r
        /* Exit if not logged in. */\r
-       if ( !$member->isLoggedIn() ) exit("You aren't logged in.");\r
-       \r
+       if ( !$member->isLoggedIn() )\r
+       {\r
+               exit(_GFUNCTIONS_YOU_AERNT_LOGGEDIN);\r
+       }\r
+\r
        global $manager,$DIR_LIBS,$DIR_LANG,$HTTP_GET_VARS,$HTTP_POST_VARS;\r
-       \r
+\r
        /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */\r
-       if (!($p_translated=serverVar('PATH_TRANSLATED'))) $p_translated=serverVar('SCRIPT_FILENAME');\r
-       if ($file=@file($p_translated)) {\r
+       if (!($p_translated=serverVar('PATH_TRANSLATED')))\r
+       {\r
+               $p_translated=serverVar('SCRIPT_FILENAME');\r
+       }\r
+       if ($file=@file($p_translated))\r
+       {\r
                $prevline='';\r
-               foreach($file as $line) {\r
-                       if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i',$prevline.$line)) return;\r
+               foreach($file as $line)\r
+               {\r
+                       if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i',$prevline.$line))\r
+                       {\r
+                               return;\r
+                       }\r
                        $prevline=$line;\r
                }\r
        }\r
@@ -1744,15 +2041,22 @@ function ticketForPlugin(){
        /* Show a form if not valid ticket */\r
        if ( ( strstr(serverVar('REQUEST_URI'),'?') || serverVar('QUERY_STRING')\r
                        || strtoupper(serverVar('REQUEST_METHOD'))=='POST' )\r
-                               && (!$manager->checkTicket()) ){\r
-\r
-               if (!class_exists('PluginAdmin')) {\r
+                               && (!$manager->checkTicket()) )\r
+       {\r
+               if (!class_exists('PluginAdmin'))\r
+               {\r
                        $language = getLanguageName();\r
-                       include($DIR_LANG . ereg_replace( '[\\|/]', '', $language) . '.php');\r
+                       \r
+                       # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0\r
+                       # original ereg_replace: ereg_replace( '[\\|/]', '', $language) . '.php')\r
+                       # important note that '\' must be matched with '\\\\' in preg* expressions\r
+                       include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');\r
                        include($DIR_LIBS . 'PLUGINADMIN.php');\r
                }\r
-               if (!(function_exists('mb_strimwidth') || extension_loaded('mbstring'))) {\r
-                       if (file_exists($DIR_LIBS.'mb_emulator/mb-emulator.php')) {\r
+               if (!(function_exists('mb_strimwidth') || extension_loaded('mbstring')))\r
+               {\r
+                       if (file_exists($DIR_LIBS.'mb_emulator/mb-emulator.php'))\r
+                       {\r
                                global $mbemu_internals;\r
                                include_once($DIR_LIBS.'mb_emulator/mb-emulator.php');\r
                        }\r
@@ -1760,22 +2064,31 @@ function ticketForPlugin(){
                $oPluginAdmin = new PluginAdmin($plugin_name);\r
                $oPluginAdmin->start();\r
                echo '<p>' . _ERROR_BADTICKET . "</p>\n";\r
-               \r
+\r
                /* Show the form to confirm action */\r
                // PHP 4.0.x support\r
                $get=  (isset($_GET))  ? $_GET  : $HTTP_GET_VARS;\r
                $post= (isset($_POST)) ? $_POST : $HTTP_POST_VARS;\r
                // Resolve URI and QUERY_STRING\r
-               if ($uri=serverVar('REQUEST_URI')) {\r
+               if ($uri=serverVar('REQUEST_URI'))\r
+               {\r
                        list($uri,$qstring)=explode('?',$uri);\r
-               } else {\r
-                       if ( !($uri=serverVar('PHP_SELF')) ) $uri=serverVar('SCRIPT_NAME');\r
+               }\r
+               else\r
+               {\r
+                       if ( !($uri=serverVar('PHP_SELF')) )\r
+                       {\r
+                               $uri=serverVar('SCRIPT_NAME');\r
+                       }\r
                        $qstring=serverVar('QUERY_STRING');\r
                }\r
-               if ($qstring) $qstring='?'.$qstring;\r
-               echo '<p>'._SETTINGS_UPDATE.' : '._QMENU_PLUGINS.' <span style="color:red;">'.\r
-                       htmlspecialchars($plugin_name)."</span> ?</p>\n";\r
-               switch(strtoupper(serverVar('REQUEST_METHOD'))){\r
+               if ($qstring)\r
+               {\r
+                       $qstring='?'.$qstring;\r
+               }\r
+               echo '<p>'._SETTINGS_UPDATE.' : '._QMENU_PLUGINS.' <span style="color:red;">'.htmlspecialchars($plugin_name)."</span> ?</p>\n";\r
+               switch(strtoupper(serverVar('REQUEST_METHOD')))\r
+               {\r
                case 'POST':\r
                        echo '<form method="POST" action="'.htmlspecialchars($uri.$qstring).'">';\r
                        $manager->addTicketHidden();\r
@@ -1791,11 +2104,11 @@ function ticketForPlugin(){
                echo '<input type="submit" value="'._YES.'" />&nbsp;&nbsp;&nbsp;&nbsp;';\r
                echo '<input type="button" value="'._NO.'" onclick="history.back(); return false;" />';\r
                echo "</form>\n";\r
-               \r
+\r
                $oPluginAdmin->end();\r
                exit;\r
        }\r
-       \r
+\r
        /* Create new ticket */\r
        $ticket=$manager->addTicketToUrl('');\r
        $ticketforplugin['ticket']=substr($ticket,strpos($ticket,'ticket=')+7);\r
@@ -1813,7 +2126,7 @@ function _addInputTags(&$keys,$prefix=''){
        }\r
 }\r
 \r
-/** \r
+/**\r
  * Convert the server string such as $_SERVER['REQUEST_URI']\r
  * to arry like arry['blogid']=1 and array['page']=2 etc.\r
  */\r
@@ -1831,7 +2144,7 @@ function serverStringToArray($str, &$array, &$frontParam)
                $args = $str;\r
                $frontParam = "";\r
        }\r
-       \r
+\r
        // If there is no args like blogid=1&page=2, return\r
        if (!strstr($str, "=") && !strlen($frontParam)) {\r
                $frontParam = $str;\r
@@ -1841,7 +2154,7 @@ function serverStringToArray($str, &$array, &$frontParam)
        $array = explode("&", $args);\r
 }\r
 \r
-/** \r
+/**\r
  * Convert array like array['blogid'] to server string\r
  * such as $_SERVER['REQUEST_URI']\r
  */\r
@@ -1857,14 +2170,14 @@ function arrayToServerString($array, $frontParam, &$str)
        }\r
 }\r
 \r
-/** \r
+/**\r
  * Sanitize array parameters.\r
  * This function checks both key and value.\r
  * - check key if it inclues " (double quote),  remove from array\r
  * - check value if it includes \ (escape sequece), remove remaining string\r
  */\r
 function sanitizeArray(&$array)\r
-{      \r
+{\r
        $excludeListForSanitization = array('query');\r
 //     $excludeListForSanitization = array();\r
 \r
@@ -1881,23 +2194,27 @@ function sanitizeArray(&$array)
                if (get_magic_quotes_gpc()) {\r
                        $val = stripslashes($val);\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
-               \r
+\r
                // if $key is included in exclude list, skip this param\r
                if (!in_array($key, $excludeListForSanitization)) {\r
-                               \r
+\r
                        // check value\r
-                       @list($val, $tmp) = explode('\\', $val);\r
-                       \r
+                       if (strpos($val, '\\')) {\r
+                               list($val, $tmp) = explode('\\', $val);\r
+                       }\r
+\r
                        // remove control code etc.\r
-                       $val = strtr($val, "\0\r\n<>'\"", "       ");\r
-                               \r
+                       $val = strtr($val, "\0\r\n<>'\"", "        ");\r
+\r
                        // check key\r
                        if (preg_match('/\"/i', $key)) {\r
                                unset($array[$k]);\r
                                continue;\r
                        }\r
-                               \r
+\r
                        // set sanitized info\r
                        $array[$k] = sprintf("%s=%s", $key, $val);\r
                }\r
@@ -1966,7 +2283,7 @@ function stringToAttribute ($string) {
        $string = entity::named_to_numeric($string);\r
        $string = entity::normalize_numeric($string);\r
 \r
-       if (_CHARSET == 'UTF-8') {\r
+       if (strtoupper(_CHARSET) == 'UTF-8') {\r
                $string = entity::numeric_to_utf8($string);\r
        }\r
 \r
@@ -1985,7 +2302,7 @@ function stringToXML ($string) {
        $string = entity::named_to_numeric($string);\r
        $string = entity::normalize_numeric($string);\r
 \r
-       if (_CHARSET == 'UTF-8') {\r
+       if (strtoupper(_CHARSET) == 'UTF-8') {\r
                $string = entity::numeric_to_utf8($string);\r
        }\r
 \r
@@ -2033,16 +2350,17 @@ function _links_list() {
  * @todo document this\r
  */\r
 function encode_desc(&$data)\r
-    {   //_$to_entities = get_html_translation_table(HTML_ENTITIES);\r
-        $to_entities = get_html_translation_table(HTML_SPECIALCHARS);\r
-        $from_entities = array_flip($to_entities);\r
-        $data = str_replace('<br />', '\n', $data); //hack\r
-        $data = strtr($data,$from_entities);\r
-        $data = strtr($data,$to_entities);\r
-        $data = str_replace('\n', '<br />', $data); //hack\r
-        return $data;\r
-    }\r
\r
+{\r
+//     _$to_entities = get_html_translation_table(HTML_ENTITIES);\r
+       $to_entities = get_html_translation_table(HTML_SPECIALCHARS); // for Japanese\r
+       $from_entities = array_flip($to_entities);\r
+       $data = str_replace('<br />', '\n', $data); //hack\r
+       $data = strtr($data,$from_entities);\r
+       $data = strtr($data,$to_entities);\r
+       $data = str_replace('\n', '<br />', $data); //hack\r
+       return $data;\r
+}\r
+\r
 /**\r
  * Returns the Javascript code for a bookmarklet that works on most modern browsers\r
  *\r
@@ -2055,7 +2373,7 @@ function getBookmarklet($blogid) {
        $document = 'document';\r
        $bookmarkletline = "javascript:Q='';x=".$document.";y=window;if(x.selection){Q=x.selection.createRange().text;}else if(y.getSelection){Q=y.getSelection();}else if(x.getSelection){Q=x.getSelection();}wingm=window.open('";\r
        $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";\r
-       $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');wingm.focus();";\r
+       $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+encodeURIComponent(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','toolbar=no,scrollbars=no,width=600,height=550,left=10,top=10,status=no,resizable=yes');wingm.focus();";\r
 \r
        return $bookmarkletline;\r
 }\r
@@ -2084,8 +2402,45 @@ function ifset(&$var) {
 function numberOfEventSubscriber($event) {\r
        $query = 'SELECT COUNT(*) as count FROM ' . sql_table('plugin_event') . ' WHERE event=\'' . $event . '\'';\r
        $res = sql_query($query);\r
-       $obj = mysql_fetch_object($res);\r
+       $obj = sql_fetch_object($res);\r
        return $obj->count;\r
 }\r
 \r
+/**\r
+ * sets $special global variable for use in index.php before selector()\r
+ *\r
+ * @param String id\r
+ * @return nothing\r
+ */\r
+function selectSpecialSkinType($id) {\r
+       global $special;\r
+       $special = strtolower($id);\r
+}\r
+\r
+/**\r
+ * cleans filename of uploaded file for writing to file system\r
+ *\r
+ * @param String str\r
+ * @return String cleaned filename ready for use\r
+ */\r
+function cleanFileName($str) {\r
+       $cleaner = array();\r
+       $cleaner[] = array('expression'=>"/[àáäãâª]/",'replace'=>"a");\r
+       $cleaner[] = array('expression'=>"/[èéêë]/",'replace'=>"e");\r
+       $cleaner[] = array('expression'=>"/[ìíîï]/",'replace'=>"i");\r
+       $cleaner[] = array('expression'=>"/[òóõôö]/",'replace'=>"o");\r
+       $cleaner[] = array('expression'=>"/[ùúûü]/",'replace'=>"u");\r
+       $cleaner[] = array('expression'=>"/[ñ]/",'replace'=>"n");\r
+       $cleaner[] = array('expression'=>"/[ç]/",'replace'=>"c");\r
+       \r
+       $str = strtolower($str);\r
+       $ext_point = strrpos($str,".");\r
+       if ($ext_point===false) return false;\r
+       $ext = substr($str,$ext_point,strlen($str));\r
+       $str = substr($str,0,$ext_point);\r
+       \r
+       //foreach( $cleaner as $cv ) $str = preg_replace($cv["expression"],$cv["replace"],$str);\r
+       \r
+       return preg_replace("/[^a-z0-9-]/","_",$str).$ext;\r
+}\r
 ?>
\ No newline at end of file