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

📄 global.func.php

📁 中观在线zol的后台管理代码
💻 PHP
字号:
<?php
/**
 * 公用封装函数 版本 V1.0.0
 * 版权所有:中关村在线 技术部
 * 最后修改时间:2008-8-29
 */

/**
 * 更新日志
 *
 * @param $parm 操作类型
 * @param $content 内容
 * @param $url 源地址
 * @param $type 类型
 */
function addlog($parm,$content,$url,$type){
	global $timestamp,$cms_user,$onlineip,$db_power;
	if($GLOBALS['lang'][$parm]){
		$content = $GLOBALS['lang'][$parm].":".$content;
	}
	$content = addslashes($content);
	$sql_str = "insert into log_op(id,username,content,url,optime,realip,type) 
				values('','$cms_user','$content','$url','$timestamp','$onlineip','$type')";
	$db_power -> query($sql_str);
}

/**
 * 截取中文字符...
 *
 * @param $str 要截取的字符
 * @param $strlen 中文长度
 */
function cnsubstr($str,$strlen=10) {
    if(empty($str)||!is_numeric($strlen)){
        return false;
    }
    if(strlen($str)<=$strlen){
        return $str;
    }
    
    $last_word_needed=substr($str,$strlen-1,1);
    if(!ord($last_word_needed)>128){
        $needed_sub_sentence=substr($str,0,$strlen);
        return $needed_sub_sentence;
    }else{
        for($i=0;$i<$strlen;$i++){ 
            if(ord($str[$i])>128){
                $i++; 
            }
        }
        $needed_sub_sentence=substr($str,0,$i);
        return $needed_sub_sentence;
    }
}

/**
 * 操作信息提示...
 *
 * @param $msg 操作信息
 * @param $dump 跳转地址
 * @param $type 类型
 */
function cpmsg($msg,$dump="",$type=1,$tips=0){
	global $turn_tips,$action,$language;
	if(!$tips) $tips=$turn_tips;
	
	if($language[$msg]){
		$cpmsg = $language[$msg];
	}else{
		$cpmsg = $msg;
	}
	if($tips){
		$alert_msg = "alert('$cpmsg');";
	}
	if(!$dump){
		echo "<script language='javascript'>{$alert_msg}history.go(-1);</script>";
	} else {
		if($type==1){
			$turn_url = "admincp.php?action=$dump";
		}else{
			$turn_url = $dump."?error_msg=".$cpmsg;
		}
		echo "<script language='javascript'>{$alert_msg}location.href='$turn_url';</script>";
	}
}

/**
 * 过滤掉回车...
 */
function cut_br($content,$replace=''){
	while(ereg(chr(10),$content))	{
		$tmp1=substr($content,0,(strpos($content,chr(10))-1)).$replace;
		$tmp2=substr($content,(strpos($content,chr(10))+1));
		$content=$tmp1.$tmp2;
	}
	if(strlen($content) > 40) $content = str_replace(' ','',$content);
	return $content;
}

/**
 * 调试信息
 */
function debuginfo(){
	if($GLOBALS['debug']) {
		global $run_starttime, $debuginfo;
		$mtime = explode(' ', microtime());
		$debuginfo = array('time' => number_format(($mtime[1] + $mtime[0] - $run_starttime), 6));
		return TRUE;
	} else {
		return FALSE;
	}
}

/**
 * 包含缓存文件
 *
 * @param $file 包含的文件名称
 */
function get_cache($file) {
	$cachefile = SYSTEM_ROOT.'./cachedata/'.$file.'.cache.php';
	if(!@file_exists($cachefile)) {			
		update_cache($file);
	}
	return $cachefile;
}

/**
 * 包含插件配置文件
 * @param $file 包含的文件名称
 */
function get_plug_config($file) {
	$configfile = SYSTEM_ROOT.'./include/plug/'.$file.'.inc.php';
	if(!@file_exists($configfile)) {			
		return false;
	}
	return $configfile;
}

/**
 * 通过透明代理服务器获得真实IP
 */
function get_real_ip(){
 $ip=false;
 if(!empty($_SERVER["HTTP_CLIENT_IP"])){
  $ip = $_SERVER["HTTP_CLIENT_IP"];
 }
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
  if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
  for ($i = 0; $i < count($ips); $i++) {
	  echo $ips[$i].'<br>';
   if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
    $ip = $ips[$i];
    break;
   }
  }
 }
 return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}

/**
 * 获取语言包...
 *
 * @param $file 语言包文件
 */
function language($file) {
	$languagepack = ADMIN_ROOT.'/templates/language/'.$file.'.lang.php';
	if(file_exists($languagepack)) {
		return $languagepack;
	} else {
		return FALSE;
	}
}

/**
 * 通用分页函数
 *
 * @param $num 总记录数
 * @param $perpage 每页显示条数
 * @param $curpage 当前页数
 * @param $mpurl 程序地址
 * @param $page 最多显示的页数
 * @param $a_class 链接样式
 * @return unknown
 */
function multi_page($num,$perpage,$curpage,$mpurl,$page=10,$a_class="a_hei14"){
	global $lang;
	$multipage = '';
	$offset = 2;
	$mpurl .= strpos($mpurl, '?') ? '&amp;' : '?';
	if($num > $perpage) {
		$realpages = @ceil($num / $perpage);
		$pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;
		
		//判断开始到结束的页面
		if($page > $pages) {
			$from = 1;
			$to = $pages;
		} else {
			$from = $curpage - $offset;
			$to = $from + $page - 1;
			if($from < 1) {
				$to = $curpage + 1 - $from;
				$from = 1;
				if($to - $from < $page) {
					$to = $page;
				}
			} elseif($to > $pages) {
				$from = $pages - $page + 1;
				$to = $pages;
			}
		}
	
		$multipage .= '<a href="'.$mpurl.'" '.$a_class.'>first</a>';
		if(1 < $curpage)
			$multipage .= '<a href="'.$mpurl.'page='.($curpage-1).'" '.$a_class.'><<</a>';
			
		for($i = $from; $i <= $to; $i++) {
			$multipage .= ($i == $curpage) ? '<a href="'.$mpurl.'page='.$i.'" '.$a_class.'><font color=red>['.$i.']</font></a>':'<a href="'.$mpurl.'page='.$i.'" '.$a_class.'>['.$i.']</a>';
		}
		
		if($realpages > $curpage)
			$multipage .= '<a href="'.$mpurl.'page='.($curpage+1).'" '.$a_class.'>>></a>';
	}
	return $multipage;
}

/**
 * 显示下拉框
 *
 * @param $typename 类型名称
 * @param $select 当前值
 * @param $val_arr 数据值,为空时调settings
 */
function show_select($typename,$select=0,$val_arr=""){
	global $settings;
	if(!is_array($val_arr))
		$val_arr = $settings;
	$selstr = "";
	if($val_arr[$typename]) {
		$selstr .= "<select name='$typename'>";
		$selstr .= "<option value='0'>==请选择==</option>";
		foreach($val_arr[$typename] as $key=>$val){
			$selstr .= "<option value='$key'";
			if($key == $select) $selstr .= " selected";
			$selstr .= ">".$val."</option>";
		}
		$selstr .= "</select>";
	}else{
		$selstr .= "!no value";
	}
	return $selstr;
}

/**
 * 包含模板
 *
 * @param $file 文件名称
 * @param $dir 模板所在相对目录
 */
function template($file,$dir='') {
	$tplrefresh = 1;	#模板是否更新或更新时间

	$tplfile = ADMIN_ROOT.'/templates/'.$dir.$file.'.htm';
	$objfile = ADMIN_ROOT.'/cachedata/templates/'.$dir.$file.'.tpl.php';
//	if($tplrefresh == 1 || ($tplrefresh > 1 && substr($GLOBALS['timestamp'], -1) > $tplrefresh)) {
//		if(@filemtime($tplfile) > @filemtime($objfile)) {			
			require_once ADMIN_ROOT.'/include/template.func.php';
			parse_template($file,$dir);
//		}
//	}
	return $objfile;
}

/**
 * 将内容生成到文件中
 *
 * @param $file_url 文件地址
 * @param $content 内容
 */
function write_file($file_url,$content){
	if(($static_fp = fopen($file_url, "w"))==false){
		echo "File[".$file_url."] open failure!";
		return false;
	}

	fputs($static_fp, $content);
	$ret = fclose($static_fp);
	exec("chmod 0777 ".$file_url);
	return $ret;
}

/**
 * 显示下拉菜单
 *
 * @param $arr 选项数组
 * @param $lab_name 菜单标签
 * @param $value 选中值
 * @param $intr_str 0值提醒
 * @param $other 其它操作
 */
function show_select_list($arr,$lab_name,$value=0,$intr_str='',$other='') {	
	$return_str = '<select name="'.$lab_name.'" id="'.$lab_name.'" '.$other.'>'."\n";
	if ($intr_str) {
		$return_str.= '<option value="0">'.$intr_str.'</option>'."\n";
	}
	if (is_array($arr)) {
		foreach ($arr as $id=>$val) {
			$return_str.= '<option value="'.$id.'"';
			if($value == $id) $return_str.= ' selected';
			$return_str.= '>'.$val.'</option>'."\n";
		}
	}
	$return_str.= '</select>'."\n";	
	return $return_str;
}


/**
 * 得到忽略大小写的字符串首先出现位置
 *
 * @param $str_haystack 原值
 * @param $str_needle 查找的值
 * @param $start_pos 起始位置
 */
function strppos($str_haystack,$str_needle,$start_pos){
    $str_haystack=strtolower($str_haystack);
    $str_needle=strtolower($str_needle);
    return(strpos($str_haystack,$str_needle,$start_pos));
}
?>

⌨️ 快捷键说明

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