⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.php

📁 这个版本只是修正了一些BUG
💻 PHP
字号:
<?php
/*******************************************************
	function.php - 基本支持函数库

	Version  : 1.0.0
	Author   : Tracemouse (tracemouse@msn.com)
	Copyright:
	Writed   : 2003/08/08
	Modified : 2004/03/18
********************************************************/

function dhtmlspecialchars($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = dhtmlspecialchars($val);
		}
	} else {
		//$string = str_replace("&lt;", "&amp;lt;", $string);
		//$string = str_replace("&gt;", "&amp;gt;", $string);
		$string = str_replace('"', '&quot;', $string);
		$string = str_replace('<', '&lt;', $string);
		$string = str_replace('>', '&gt;', $string);
	}
	return $string;
}

function daddslashes($string, $force = 0) {
	if(!$GLOBALS['magic_quotes_gpc'] || $force) {
		if(is_array($string)) {
			foreach($string as $key => $val) {
				$string[$key] = daddslashes($val, $force);
			}
		} else {
			$string = addslashes($string);
		}
	}
	return $string;
}

function debuginfo() {
 global $db, $starttime, $gzipcompress;
	$mtime = explode(' ', microtime());
	$totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
	echo 'Page Generation: '.$totaltime.' seconds, SQL Generation: '.$db->querynum.' queries'.
	($gzipcompress ? ', Gzip enabled' : NULL);

}

function site_exit($message = '') {
	global $db;
 	$db->close();
    echo $message;
    exit;
   //	exit($message);
}

function checkpass($user,$pass)
{
	global $db,$table_members,$table_groups,$isadmin,$login_user;
 	$query = $db->query("select password,status,credits from $table_members where username = '$user'");
 	//$pass=md5($pass);
 	if ($dbq_rec=$db->fetch_array($query))
 	{
  		if ($pass != $dbq_rec['password'])
   		{
   			unset($dbq_rec);unset($query);
    			return 1;
    		}
   		else
   		{
   			$login_user[username]=$user;
   			$login_user[password]=$pass;
   			$credits=$login_user[credits]=$dbq_rec[credits];
   			$login_user[status]=$dbq_rec[status];
   			if($dbq_rec['status']=='Admin')  $isadmin = 1;
   			if($dbq_rec['status'] != 'Member')
   			{
   				$sqlstr="select * from $table_groups where status = '$dbq_rec[status]'";
   				$query=$db->query($sqlstr);
   				$dbq_rec=$db->fetch_array($query);
   				$login_user[avatar]=$dbq_rec[grouptitle];
   				$login_user[maxpm]=$dbq_rec[maxpm];
   				$login_user[agio]=$dbq_rec[agio];
   			}
   			else
   			{
   				$sqlstr="select * from $table_groups where status = 'Member' and creditslower <= $credits and creditshigher > $credits ";
   				$query=$db->query($sqlstr);
   				if($dbq_rec=$db->fetch_array($query))
   				{
   					$login_user[avatar]=$dbq_rec[grouptitle];
   					$login_user[maxpm]=$dbq_rec[maxpm];
   					$login_user[agio]=$dbq_rec[agio];
   				}
   				else
   				{
   					$login_user[avatar]='Member';
   					$login_user[maxpm]=50;
   					$login_user[agio]=10;
   				}
   			}
   			unset($dbq_rec);unset($query);
   			return  0;
   		}
  	}
 	else
 	{
 		unset($dbq_rec);unset($query);
  		return 2;
 	}
 }
 
 function checkallow($user,$allow)
{
	global $db,$table_members,$isadmin,$table_groups;
	$sqlstr="select status,credits from $table_members where username='$user'";
	$query=$db->query($sqlstr,1);
	if($dbq_rec=$db->fetch_array($query))
	{
		//$groupid=$dbq_rec[groupid];
		$status=$dbq_rec[status];
		$credits=$dbq_rec[credits];
		if($status == 'Member')
		{
			$sqlstr="select  $allow from $table_groups where status='Member' and creditslower <= $credits and creditshigher > $credits";  
		}
		else
		{
			$sqlstr="select $allow from $table_groups where status = '$status'";
		}
		$query=$db->query($sqlstr,1);
		if($dbq_rec=$db->fetch_array($query))
		{
			return $dbq_rec[$allow];
		}
		else
		{
			return 0;
		}	
	}
	else
	{
		return 0;
	}
}

function getdatewin($month,$day,$year)
{
 	$total=11;
 	$week=5;
 	$today=getdate();
 	if (!$month) $month=$today[mon];
 	if (!$day) $day=$today[mday];
 	if (!$year) $year=$today[year];

 	//计算到所求日期阳历的总天数-自1900年12月21日始
 	#先算年的和
 	for ($y=1901;$y<$year;$y++)
 	{
 		$total+=365;
	 	if ($y%4==0) $total ++;
 	}
 	//再加当年的几个月
 	switch ($month)
 	{
  		case 12:$total+=30;
  		case 11:$total+=31;
  		case 10:$total+=30;
  		case 9:$total+=31;
  		case 8:$total+=31;
  		case 7:$total+=30;
  		case 6:$total+=31;
  		case 5:$total+=30;
  		case 4:$total+=31;
  		case 3:$total+=28;
  		case 2:$total+=31;
 	}
	//如果当年是闰年还要加一天
 	if ($year%4==0 and $month>2){
 		$total++;
 	}
	//算出当月1日星期几
 	$week=($total+$week)%7;
 	$tr='';
 	$d='';
 	for($i=1;$i<10;$i++)
 	{
  		$tr.='<tr>';
  		for ($j=1;$j<8;$j++)
  		{
   			if($i ==1)
   			{
   	 			if ($week == $j) {unset($d);$d=1;}
    				elseif ($week < $j) $d=$d+1;
    				else $d='';
    				$bgcolor=($day==$d)?'class=header':"bgcolor='".ALTBG1."'";
    				$tr.="<td height=22 ".$bgcolor." align=center>$d</td>";
    				continue;
   			}
   			$d=$d+1;
   			if (!checkdate($month,$d,$year))
   			{
    				unset($d);
    				$d='';
    				$end_flag=1;
    				$tr.="<td height=22 align=center>$d</td>";
    				break;
   			}
   			$bgcolor=($day==$d)?'class=header':"bgcolor='".ALTBG1."'";
   			$tr.="<td height=22 ".$bgcolor." align=center>$d</td>";
  		}
  		$tr.='</tr>';
  		if ($end_flag) break;
 	}
	return $tr;
}


function language($langfile='',$langdir='')
{
	global $LANGDIR;
	$langdir=($langdir=='')?$LANGDIR:$langdir;
	return $langdir.'/'.$langfile.'.lang.php';
}


function setconst($styleid=1)
{
	global $db,$table_stylevars,$IMGDIR;
	$query = $db->query("SELECT * FROM $table_stylevars WHERE styleid=$styleid");
	while($dbq_rec = $db->fetch_array($query))
	{
 		$constvar=strtoupper($dbq_rec['variable']);
 		if (($dbq_rec['variable'] == 'bgcolor')||($dbq_rec['variable'] == 'headercolor')||($dbq_rec['variable'] == 'catcolor')||($dbq_rec['variable']=='catbgcolor'))
 		{
  			if(strstr($dbq_rec['substitute'],'.'))
  			{
 	 			$constval="background-image:url(\"".$IMGDIR.'/'.$dbq_rec['substitute']."\")";
  				define($constvar,$constval);
  			}
  			else
  			{
  				$constval="background-color:".$dbq_rec['substitute']."";
  				define($constvar,$constval);
  			}
 		}
 		else
 		{
 			define($constvar,$dbq_rec['substitute']);
 		}
	}
}

function viewbanner($bid=1,$width=0,$height=0)
{
	global $db,$table_banners;
	$query=$db->query("SELECT * FROM $table_banners WHERE bid=$bid");
	$str='';
	if($dbq_rec=$db->fetch_array($query))
	{
  		if($dbq_rec['type']=='img')
  		{
        		$width=($width==0)?" ":"width='".$width."'";
			$height=($height==0)?" ":"height='".$height."'";
           	 	$str.="<a target=_blanket href='".$dbq_rec['siteurl']."'>";
    			$str.="<img border=0 src='".$dbq_rec['fileurl']."' alt='".$dbq_rec['subject']."' ";
    			$str.=$width." ".$height."></a>";
  		}
  		else
  		{
            		$str.="<object codebase='http://download.macromedia.com/pub/shockwave/cabs/Flash/swFlash.cab#3,0,0,0' width='".$width."' height='".$height."'>";
            		$str.="<param  name='SRC' value='".$dbq_rec['fileurl']."'>";
            		$str.="<embed src='".$dbq_rec['fileurl']."' quality=high ";
            		$str.="pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'";
            		$str.=" type='application/x-shockwave-flash' width='".$width."' height='".$height."'>";
            		$str.="</embed></object>";
  		}
	}
    	unset($query);unset($dbq_rec);
    	//showmessage($str);
	return $str;
}

// changed by tracemouse in 2004.3.18.
/*
function faq($faq_path,$filename)
{
	global $site_root;
	$tmpdir='./tempdata/faq';
	$faqfile=$faq_path.'/'.$filename;
	$objfile=$tmpdir.'/'.$filename.'.htm';
	if (!file_exists($objfile))
	{
  		require_once $site_root.'./include/faq.php';
  		parse_faq($faq_path,$filename);
	}
	else
	{
  		if(@filemtime($faqfile) > @filemtime($objfile))
  		{
   			require_once $site_root.'./include/faq.php';
   			parse_faq($faq_path,$filename);
  		}
	}
	return $objfile;
}
*/

function random($length) {
	$hash = '';
	$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
	$max = strlen($chars) - 1;
	mt_srand((double)microtime() * 1000000);
	for($i = 0; $i < $length; $i++) {
		$hash .= $chars[mt_rand(0, $max)];
	}
	return $hash;
}

function sendmail($to, $subject, $message, $from = '') 
{
    	extract($GLOBALS, EXTR_SKIP);
	require $shop_root.'./include/email.php';
}

//检查EMAIL地址的合法性
function checkEmail($inAddress)
{
	return (ereg("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+",$inAddress));
	//return (ereg( "^[^@ ]+@([a-zA-Z0-9-]+.)+([a-zA-Z0-9-]
	//{2}|net|com|gov|mil|org|edu|int|com.cn|net.cn)$",$inAddress));
}

function autosubmit($tourl,$passval)
{
    	echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><title></title></head>";
    	echo "<body>";
	echo "<script LANGUAGE='JavaScript'>";
	echo "setTimeout('document.passform.submit();', 1000);";
	echo "</script>";
	echo "<FORM METHOD=POST ACTION='$tourl' NAME='passform'>";
    	echo "<input type='text' value='$passval' name='passval'>";
    	echo "</FORM></body></html>";

}

//include './include/multi.php';
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -