global.php

来自「全新且完善的强大网上商店系统」· PHP 代码 · 共 255 行

PHP
255
字号
<?php

/*
  [SOOBIC!] includes/global.php 

	Version: 1.5
	Author: Soolan (soolan@qq.com)
	Copyright: soolan (www.soobic.com)
	Last Modified: 2005/4/1 10:00

*/


if(!defined('IN_SOOBIC')) {
    exit('Access Denied');
}

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

function soobic_exit($message = '') {
	global $db;
	soobic_output();
	$db->close();
	exit($message);
}

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 url_rewriter($url, $tag = '') {
	global $osCsid;
	$tag = stripslashes($tag);
	if(!$tag || (!preg_match("/^(http:\/\/|mailto:|#|javascript)/i", $url) && !strpos($url, 'sid='))) {
		$pos = strpos($url, '#');
		if($pos) {
			$urlret = substr($url, $pos);
			$url = substr($url, 0, $pos);
		}
		$url .= strpos($url, '?') ? '&' : '?';
		$url .= "osCsid=$osCsid$urlret";
	}
	return $tag.$url;
}
function soobic_output() {
	  tep_session_close();
		global $ext_zlib_loaded,$ini_zlib_output_compression;
    if ( (GZIP_COMPRESSION == 'true') && ($ext_zlib_loaded == true) && ($ini_zlib_output_compression < 1) ) {
        if ( (PHP_VERSION < '4.0.4') && (PHP_VERSION >= '4') ) {
            tep_gzip_output(GZIP_LEVEL);
        }
    }
}

function clearcookies() {
	global $timestamp, $cookiepath, $cookiedomain, $soolan_user, $soolan_pw, $status;
	setcookie('_soolan_user', '', $timestamp - 86400 * 365, $cookiepath, $cookiedomain);
	setcookie('_soolan_pw', '', $timestamp - 86400 * 365, $cookiepath, $cookiedomain);
	$soolan_user = $soolan_pw = '';
	$status = 'Guest';
}

function image($imageinfo, $basedir = "", $remark = "") {
	if($basedir) {
		$basedir .= "/";
	}
	if(strstr($imageinfo, ",")) {
		$flash = explode(",", $imageinfo);
		return "<embed src=\"$basedir".trim($flash[0])."\" width=\"".trim($flash[1])."\" height=\"".trim($flash[2])."\" type=\"application/x-shockwave-flash\" $remark></embed>";
	} else {
		return "<img src=\"$basedir$imageinfo\" $remark border=\"0\">";
	}
}

function template($file, $tpldir = '') {
	global $soolan_root;

	$tpldir = $tpldir ? $tpldir : TPLDIR;
  
  $filename= file_exists($soolan_root.'./templates/'.$tpldir.'/'.$file.'.html')? $soolan_root.'./templates/'.$tpldir.'/'.$file.'.html' : $soolan_root.'./templates/default/'.$file.'.html' ;
  
	return $filename;
}

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 debuginfo() {
	if($GLOBALS['debug']) {
		global $db, $starttime, $gzipcompress;
		$mtime = explode(' ', microtime());
		$totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
		echo '<br>Processed in '.$totaltime.' second(s), '.$db->querynum.' queries'.
			(GZIP_COMPRESSION ? ', Gzip enabled' : NULL);
	}
}

function multi($num, $perpage, $curr_page, $mpurl) {
	$multipage = '';
	if($num > $perpage) {
		$page = 10;
		$offset = 2;

		$pages = ceil($num / $perpage);
		$from = $curr_page - $offset;
		$to = $curr_page + $page - $offset - 1;
		if($page > $pages) {
			$from = 1;
			$to = $pages;
		} else {
			if($from < 1) {
				$to = $curr_page + 1 - $from;
				$from = 1;
				if(($to - $from) < $page && ($to - $from) < $pages) {
					$to = $page;
				}
			} elseif($to > $pages) {
				$from = $curr_page - $pages + $to;
				$to = $pages;
				if(($to - $from) < $page && ($to - $from) < $pages) {
					$from = $pages - $page + 1;
				}
			}
		}
		$multipage .= "<a href=\"$mpurl&page=1\">&lt;&lt;</a> &nbsp;";
		for($i = $from; $i <= $to; $i++) {
			if($i != $curr_page) {
				$multipage .= "<a href=\"$mpurl&page=$i\">[$i]</a>&nbsp;";
			} else {
				$multipage .= '<u><b>['.$i.']</b></u>&nbsp;';
			}
		}
		$multipage .= $pages > $page ? " ... <a href=\"$mpurl&page=$pages\"> [$pages] &gt;&gt;</a>" : " <a href=\"$mpurl&page=$pages\">&gt;&gt;</a>";
	}
	return $multipage;
}

function wordscut($string, $length) {
	if(strlen($string) > $length) {
		for($i = 0; $i < $length - 3; $i++) {
			if(ord($string[$i]) > 127) {
				$wordscut .= $string[$i].$string[$i + 1];
				$i++;
			} else {
				$wordscut .= $string[$i];
			}
		}
		return $wordscut.' ...';
	}
	return $string;
}

// 输入内容安全转换
function safe_input($d) {
  $d = str_replace("\n",'<br>',$d);
  $d = str_replace(" ",'&nbsp;',$d);
  return $d;
}
// 输出内容安全转换
function safe_output($d) {
  $d = str_replace('<br>',"\n",$d);
  $d = str_replace('&nbsp;'," ",$d);
  return $d;
}

function tep_db_perform($table, $data, $action = 'insert', $parameters = '') {
    global $db;
		reset($data);
    if ($action == 'insert') {
      $query = 'insert into ' . $table . ' (';
      while (list($columns, ) = each($data)) {
        $query .= $columns . ', ';
      }
      $query = substr($query, 0, -2) . ') values (';
      reset($data);
      while (list(, $value) = each($data)) {
        switch ((string)$value) {
          case 'now()':
            $query .= 'now(), ';
            break;
          case 'null':
            $query .= 'null, ';
            break;
          default:
            $query .= '\'' . ($value) . '\', ';
            break;
        }
      }
      $query = substr($query, 0, -2) . ')';
    } elseif ($action == 'update') {
      $query = 'update ' . $table . ' set ';
      while (list($columns, $value) = each($data)) {
        switch ((string)$value) {
          case 'now()':
            $query .= $columns . ' = now(), ';
            break;
          case 'null':
            $query .= $columns .= ' = null, ';
            break;
          default:
            $query .= $columns . ' = \'' . ($value) . '\', ';
            break;
        }
      }
      $query = substr($query, 0, -2) . ' where ' . $parameters;
    }
    return $db->query($query);
}

function tep_db_prepare_input($string) {
    if (is_string($string)) {
      return trim(tep_sanitize_string(stripslashes($string)));
    } elseif (is_array($string)) {
      reset($string);
      while (list($key, $value) = each($string)) {
        $string[$key] = tep_db_prepare_input($value);
      }
      return $string;
    } else {
      return $string;
    }
}


?>

⌨️ 快捷键说明

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