OSDN Git Service

Small update (Added UTF-8 Support)
[idb/iDB.git.git] / inc / misc / functions.php
index e78b82b..6fb13e2 100644 (file)
@@ -8,10 +8,10 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     Revised BSD License for more details.
 
-    Copyright 2004-2007 Cool Dude 2k - http://intdb.sourceforge.net/
-    Copyright 2004-2007 Game Maker 2k - http://upload.idb.s1.jcink.com/
+    Copyright 2004-2009 Cool Dude 2k - http://idb.berlios.de/
+    Copyright 2004-2009 Game Maker 2k - http://intdb.sourceforge.net/
 
-    $FileInfo: functions.php - Last Update: 10/05/2007 SVN 115 - Author: cooldude2k $
+    $FileInfo: functions.php - Last Update: 6/07/2009 SVN 262 - Author: cooldude2k $
 */
 $File3Name = basename($_SERVER['SCRIPT_NAME']);
 if ($File3Name=="functions.php"||$File3Name=="/functions.php") {
@@ -39,12 +39,14 @@ if ($_GET['act']=="phpinfo") { @phpinfo(); exit(); }
 if ($_GET['act']=="PHPCredits") { @phpcredits(); exit(); }
 if ($_GET['act']=="phpcredits") { @phpcredits(); exit(); } 
 */// Connect to mysql database
-function ConnectMysql($sqlhost,$sqluser,$sqlpass,$sqldb) {
+function ConnectMysql($sqlhost,$sqluser,$sqlpass,$sqldb,$retlink=false) {
+if($retlink!==true) { $retlink = false; }
 $StatSQL = @mysql_connect($sqlhost,$sqluser,$sqlpass);
 $StatBase = @mysql_select_db($sqldb);
 if (!$StatSQL) { return false; }
 if (!$StatBase) { return false; }
-return true; }
+if($retlink===true) { return $StatSQL; }
+if($retlink===false) { return true; } }
        $Names['RS'] = "Renee Sabonis";
 define("_renee_", $Names['RS']);
 // Change the title and gzip page
@@ -56,7 +58,7 @@ $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title
 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
 $SessName = @session_name();
 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
-$qstrcode = htmlentities($Settings['qstr']);
+$qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
 if($use_gzip!="on") {
        echo $output; }
@@ -74,7 +76,7 @@ $output = @ob_get_clean();
 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
 $SessName = @session_name();
 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
-$qstrcode = htmlentities($Settings['qstr']);
+$qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
 if($use_gzip!="on") {
        echo $output; }
@@ -84,8 +86,7 @@ if($use_gzip=="on") {
        if($gzip_type=="deflate") {
        $goutput = gzcompress($output); }
        echo $goutput; } }
-$output = @ob_get_clean();
-       $Names['RJ'] = "René Johnson";
+       $Names['RJ'] = "Kazuki Przyborowski";
 define("_rene_", $Names['RJ']);
 // GZip page for faster download
 function gzip_page($use_gzip="off",$gzip_type="gzip") {
@@ -101,6 +102,11 @@ if($use_gzip=="on") {
        $goutput = gzcompress($output); }
        echo $goutput; } }
 $foo="bar"; $$foo="foo";
+if(function_exists('mysql_set_charset')===false) {
+function mysql_set_charset($charset) {
+       mysql_query("SET CHARACTER SET '".$charset."'");
+       mysql_query("SET NAMES '".$charset."'"); 
+       return true; } }
 // SafeSQL Lite Source Code by Cool Dude 2k
 // Make SQL Query's safe
 function query($query_string,$query_vars) {
@@ -118,6 +124,8 @@ $query_val[$query_is] = $query_vars[$query_i];
 ++$query_i; }
    $query_val[0] = $query_string;
    return call_user_func_array("sprintf",$query_val); }
+       $Names['KP'] = "Kazuki Przyborowski";
+define("_kazuki_", $Names['KP']);
 // Kill bad vars for some functions
 function killbadvars($varname) {
 $badphp1 = array('$'); $badphp2 = array(null);
@@ -128,6 +136,28 @@ $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
        return $varname; }
+// Trying to fix this bug. ^_^
+// http://xforce.iss.net/xforce/xfdb/49697
+if(!isset($Settings['DefaultTheme'])) {
+       $Settings['DefaultTheme'] = "iDB"; }
+$BoardTheme = $Settings['DefaultTheme'];
+function chack_themes($theme) {
+global $BoardTheme;
+if(!isset($theme)) { $theme = null; }
+require('settings.php');
+$ckskindir = dirname(realpath("settings.php"))."/".$SettDir['themes'];
+if ($handle = opendir($ckskindir)) { $dirnum = null;
+   while (false !== ($ckfile = readdir($handle))) {
+          if ($dirnum==null) { $dirnum = 0; }
+          if (file_exists($ckskindir.$ckfile."/info.php")) {
+                  if ($ckfile != "." && $ckfile != "..") {
+          include($ckskindir.$ckfile."/info.php");
+       $cktheme[$dirnum] =  $ckfile;
+          ++$dirnum; } } }
+   closedir($handle); asort($cktheme); }
+$theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
+if(!in_array($theme,$cktheme)||strlen($theme)>26) {
+       $theme = $BoardTheme; } return $theme; }
 // Change the text to icons(smileys)
 function text2icons($Text,$sqlt) {
 global $Settings;
@@ -209,6 +239,12 @@ function getnextid($tablepre,$table) {
    $getnextid = mysql_fetch_assoc($getnextidr);
    return $getnextid['Auto_increment'];
    @mysql_free_result($getnextidr); }
+function getnumrows($tablepre,$table) {
+   $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
+   $getnextidr = mysql_query($getnextidq);
+   $getnextid = mysql_fetch_assoc($getnextidr);
+   return $getnextid['Rows'];
+   @mysql_free_result($getnextidr); }
        $Names['K'] = "Katarzyna";
 define("_katarzyna_", $Names['K']);
 // Change Time Stamp to a readable time
@@ -219,7 +255,7 @@ $TCSecond = date("s",$timestamp);
 $TCMonth = date("n",$timestamp);
 $TCDay = date("d",$timestamp);
 $TCYear = date("Y",$timestamp);
-unset($dstake); $dstake = null;
+$dstake = null;
 if(!is_numeric($minoffset)) { $minoffset = "00"; }
 $ts_array = explode(":",$offset);
 if(count($ts_array)!=2) {
@@ -258,7 +294,7 @@ function GMTimeStampS() { return time() - date('Z', time()); }
 function GMTimeGet($format,$offset,$minoffset=null,$dst=null) { 
        return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); }
 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
-unset($dstake); $dstake = null;
+$dstake = null;
 if(!is_numeric($offset)) { $offset = "0"; }
 if(!is_numeric($minoffset)) { $minoffset = "00"; }
 $ts_array = explode(":",$offset);
@@ -358,8 +394,8 @@ function cp($infile,$outfile,$mode="w") {
    fclose($cpfp);
    return true; }
 /* str_ireplace for PHP below ver. 5 updated // 
-//       by René Johnson - Cool Dude 2k      //
-//      and upaded by René Johnson again     */
+//       by Kazuki Przyborowski - Cool Dude 2k      //
+//      and upaded by Kazuki Przyborowski again     */
 if(!function_exists('str_ireplace')) {
 function str_ireplace($search,$replace,$subject) {
 if(!is_array($search)&&is_array($replace)) {
@@ -377,8 +413,13 @@ if(!is_array($search)&&!is_array($replace)) {
 $search = preg_quote($search, "/");
 $subject = preg_replace("/".$search."/i", $replace, $subject); }
 return $subject; } }
+/*   Adds mysql_set_charset to PHP below Ver. 5.2.3 - by: Janez R.      // 
+//   http://us.php.net/manual/en/function.mysql-set-charset.php#77565   */
+if (!function_exists('mysql_set_charset')) {
+  function mysql_set_charset($charset) {
+    return mysql_query("set names $charset"); } }
 /*   Adds httponly to PHP below Ver. 5.2.0   // 
-//       by René Johnson - Cool Dude 2k      */
+//       by Kazuki Przyborowski - Cool Dude 2k      */
 function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,$secure=false,$httponly=false) {
        $mkcookie = null; $expireGMT = null;
        if(!isset($name)) { echo "Error: You need to enter a name for cookie."; return false; }
@@ -394,8 +435,8 @@ function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,
        $mkcookie = $mkcookie."; expires=".$expireGMT;
        if(isset($path)&&$path!=null) { $mkcookie = $mkcookie."; path=".$path; }
        if(isset($domain)&&$domain!=null) { $mkcookie = $mkcookie."; domain=".$domain; }
-       if(isset($secure)&&$secure==true) { $mkcookie = $mkcookie."; secure"; }
-       if(isset($httponly)&&$httponly==true) { $mkcookie = $mkcookie."; HttpOnly"; }
+       if(isset($secure)&&$secure===true) { $mkcookie = $mkcookie."; secure"; }
+       if(isset($httponly)&&$httponly===true) { $mkcookie = $mkcookie."; HttpOnly"; }
 header($mkcookie, false); return true; } }
 $foobar="fubar"; $$foobar="foobar";
 // Debug info