/startZine/src/main/core/function/global.func.php
PHP | 2753 lines | 2277 code | 179 blank | 297 comment | 191 complexity | f8d6a76af62f652deea627aaaa9c15ef MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- // +----------------------------------------------------------------------
- // | ?????????? (Build on ThinkPHP)
- // +----------------------------------------------------------------------
- // | Copyright (c) 2011 http://fanwe.com All rights reserved.
- // +----------------------------------------------------------------------
-
- /**
- * global.func
- *
- * ????
- *
- * @package function
- * @author awfigq <awfigq@qq.com>
- */
- function getPhpSelf()
- {
- $php_self = '';
- $script_name = basename($_SERVER['SCRIPT_FILENAME']);
- if(basename($_SERVER['SCRIPT_NAME']) === $script_name)
- $php_self = $_SERVER['SCRIPT_NAME'];
- else if(basename($_SERVER['PHP_SELF']) === $script_name)
- $php_self = $_SERVER['PHP_SELF'];
- else if(isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $script_name)
- $php_self = $_SERVER['ORIG_SCRIPT_NAME'];
- else if(($pos = strpos($_SERVER['PHP_SELF'],'/'.$script_name)) !== false)
- $php_self = substr($_SERVER['SCRIPT_NAME'],0,$pos).'/'.$script_name;
- else if(isset($_SERVER['DOCUMENT_ROOT']) && strpos($_SERVER['SCRIPT_FILENAME'],$_SERVER['DOCUMENT_ROOT']) === 0)
- $php_self = str_replace('\\','/',str_replace($_SERVER['DOCUMENT_ROOT'],'',$_SERVER['SCRIPT_FILENAME']));
- else
- return false;
- return $php_self;
- }
-
- /**
- * ????????
- * @param string $file_name ????
- * @param string $folder ????(????)
- * @return string
- */
- function fimport($file_name, $folder = '')
- {
- global $_FANWE;
- static $sufix = array(
- 'module'=>'.module',
- 'service'=>'.service',
- 'class'=>'.class',
- 'function' => '.func',
- 'include' => '.inc',
- 'language' => '.lang',
- 'cache' => '.cache',
- 'dynamic'=>'.dynamic',
- );
-
- $file_name = strtolower($file_name);
- $file_path = FANWE_ROOT.'./core';
- if(strstr($file_name, '/'))
- {
- list($pre, $name) = explode('/', $file_name);
-
- $insert = '';
- if($pre == 'language')
- $insert = $_FANWE['config']['default_lang'].'/';
-
- return "{$file_path}/{$pre}/".$insert.(empty($folder) ? "" : $folder . "/")."{$name}".$sufix[$pre].".php";
- }
- else
- {
- return "{$file_path}/".(empty($folder) ? "" : $folder . "/")."{$file_name}.php";
- }
- }
-
- /**
- * ?????????
- * @param string $module ??
- * @return object
- */
- function FM($module)
- {
- static $modules = array();
- if($modules[$module] === NULL)
- {
- require fimport("module/".strtolower($module));
- $m = ucfirst($module)."Module";
- $modules[$module] = new $m();
- unset($m);
- }
- return $modules[$module];
- }
-
- /**
- * ?????
- * @param string $service ??
- * @return object
- */
- function FS($service)
- {
- static $services = array();
- if($services[$service] === NULL)
- {
- require_once fimport("service/".strtolower($service));
- $s = ucfirst($service)."Service";
- $services[$service] = new $s();
- unset($s);
- }
-
- return $services[$service];
- }
-
- /**
- * ??????
- * @param string $type ??
- * @param array $args ??
- * @return string
- */
- function FU($type,$args,$is_full = false)
- {
- global $_FANWE;
- static $is_rewrite = NULL,$site_url = NULL,$url_lists = array(),$url_flists = array();
-
- if ($is_rewrite === NULL)
- $is_rewrite = intval($_FANWE['setting']['url_model']);
-
- if ($site_url === NULL)
- $site_url = $_FANWE['site_root'];
-
- $depr = '/';
-
- $url = $site_url;
- if($is_full)
- {
- $url = $_FANWE['site_url'];
- $site_url = $_FANWE['site_url'];
- }
-
- $apps = explode('/',$type);
- $module = $apps[0];
- $action = isset($apps[1]) ? $apps[1] : 'index';
- $type = $module.'/'.$action;
-
- $url_key = $type.'_'.md5(http_build_query($args));
- if($is_full)
- {
- if(isset($url_flists[$url_key]))
- return $url_flists[$url_key];
- }
- else
- {
- if(isset($url_lists[$url_key]))
- return $url_lists[$url_key];
- }
-
- $query = '';
- if($is_rewrite == 0)
- {
- $query = http_build_query($args);
- if(!empty($query))
- $query = '&'.$query;
- }
-
- if($is_rewrite == 0)
- {
- $url .= $module.'.php?action='.$action.$query;
- }
- else
- {
- $params = array();
- switch($type)
- {
- case 'club/index':
- case 'ask/index':
- case 'event/index':
- case 'index/index':
- case 'share/index': //lvjiyun add
- case 'invite/index':
- $search = array('/index');
- $replace = array('');
- break;
-
- case 'link/index':
- $module = "links";
- $search = array('/index');
- $replace = array('');
- break;
-
- case 'daren/index':
- $params = array('page' => 0);
- $search = array('/index','page/');
- $replace = array('','');
- break;
-
- case 'daren/all':
- $params = array('page' => 0);
- $search = array('page/');
- $replace = array('');
- break;
-
- case 'club/forum':
- $params = array('fid' => 0,'sort' => '','page' => 0);
- $search = array('forum/','fid/','sort/','page/');
- $replace = array('','','','');
- break;
-
- case 'club/best':
- $params = array('fid' => 0,'sort' => '','page' => 0);
- $search = array('fid/','sort/','page/');
- $replace = array('','','');
- break;
-
- case "club/newtopic":
- $search = array('fid/');
- $replace = array('');
- break;
-
- case "club/detail":
- $params = array('tid' => 0,'page' => 0);
- $search = array('tid/','page/');
- $replace = array('','');
- break;
-
- case 'ask/forum':
- $params = array('aid' => 0,'type' => '','page' => 0);
- $search = array('forum/','aid/','type/','page/');
- $replace = array('','','','');
- break;
-
- case "ask/newtopic":
- $search = array('aid/');
- $replace = array('');
- break;
-
- case "ask/detail":
- $params = array('tid' => 0,'page' => 0);
- $search = array('tid/','page/');
- $replace = array('','');
- break;
-
- case 'book/cate':
- case 'book/shopping':
- case 'book/search':
- $params = array('cate' => '','sid' => 0,'sort'=>'','tag' => '','page' => 0);
- $search = array('cate/','sid/','sort/','tag/','page/');
- $replace = array('','s','','','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'book/dapei':
- case 'book/look':
- $params = array('sid' => 0,'sort'=>'','tag' => '','page' => 0);
- $search = array('sid/','sort/','tag/','page/');
- $replace = array('s','','','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'style/index':
- $params = array('sort'=>'','tag' => '','page' => 0);
- $search = array('/index','sort/','tag/','page/');
- $replace = array('','','','');
- $url = str_replace($search,$replace,$url);
- break;
- case 'event/detail':
- $params = array('detail'=>'','id'=>'','page' => 0);
- $search = array('/detail','/id','/page');
- $replace = array('','','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'event/list':
- $params = array('type'=>'','order'=>'','page' => 0);
- $search = array('/type','/order','/page');
- $replace = array('','','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'adv/show':
- $params = array('id'=>'');
- $search = array('/show','id/');
- $replace = array('','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'second/index':
- $params = array('sid'=>0,'cid' => 0,'page' => 0);
- $search = array('/index','sid/','cid/','page/');
- $replace = array('','s','c','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'album/index':
- $params = array('sort'=>'','page' => 0);
- $search = array('/index','sort/','page/');
- $replace = array('','','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'album/category':
- $params = array('cid'=>0,'sort'=>'','page' => 0);
- $search = array('/category', 'cid/','sort/','page/');
- $replace = array('','c','','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'album/show':
- $args['aid'] = $args['id'];
- unset($args['id']);
- $params = array('aid'=>0,'sid'=>0,'type' => 0,'page' => 0);
- $search = array('/show','aid/','sid/','type/','page/');
- $replace = array('','','s','t','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'album/edit':
- $params = array('id'=>0);
- $search = array('id/');
- $replace = array('');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'shop/index':
- $params = array('cid' => 0,'page' => 0);
- $search = array('/index','cid/','page/');
- $replace = array('','c','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'shop/show':
- $params = array('id' => 0,'page' => 0);
- $search = array('id/','page/');
- $replace = array('s','');
- $url = str_replace($search,$replace,$url);
- break;
-
- case 'exchange/index':
- $params = array('page' => 0);
- $search = array('/index','page/');
- $replace = array('','');
- $url = str_replace($search,$replace,$url);
- break;
- }
-
- if(!empty($params))
- $args = array_merge($params, $args);
-
- foreach($args as $var=>$val)
- {
- if($var == 'page' && $val == '0')
- $val = '';
-
- if($val != '')
- $query .= $depr.$var.$depr.$val;
- }
-
- $url .= $module.$depr.$action.$query;
- if(!empty($search))
- $url = str_replace($search,$replace,$url);
-
- switch($module)
- {
- case 'index':
- if((isset($args['hot']) && $args['hot'] != '') || (isset($args['sy']) && $args['sy'] != ''))
- {
- if(isset($args['hot']) && $args['hot'] != '')
- {
- $url = $site_url.'hot'.$depr.$args['hot'];
- }
-
- if(isset($args['sy']) && $args['sy'] != '')
- {
- $url = $site_url.'sy'.$depr.$args['sy'];
- }
-
- }
- else
- $url = $site_url;
- break;
-
- //lvjiyun add
- case 'share':
- if(isset($args['sort']) && $args['sort'] != '')
- {
- if($args['sort'] == 'all')
- {
- $url = $site_url.$module.$depr.'all';
- }
- else
- {
- $url = $site_url.$module.$depr.'popular';
- }
-
- if(isset($args['hot']) && $args['hot'] != '')
- {
- $url = $url.$depr.$args['hot'];
- }
- }
- else if(isset($args['hot']) && $args['hot'] != '')
- {
- $url = $site_url.$module.$depr.'popular'.$depr.$args['hot'];
- }
- else
- $url = $site_url.$module;
- break;
-
- case 'u':
- if(!isset($args['uid']))
- $args['uid'] = $_FANWE['uid'];
-
- if($action == 'all')
- $url = $site_url.$module.$depr.$action;
- elseif($action == 'msgview')
- {
- }
- else
- {
- if($action == 'index')
- {
- if($args['uid'] == $_FANWE['uid'])
- $url = $site_url.'me';
- else
- $url = $site_url.$module.$depr.$args['uid'];
- }
- else
- $url = $site_url.$module.$depr.$args['uid'].$depr.$action;
-
- if($action == 'album')
- {
- if(isset($args['type']) && $args['type'] != '')
- {
- $url.= $depr.'t'.$args['type'];
- }
- }
- elseif($action == 'exchange')
- {
- if(isset($args['status']) && $args['status'] != '')
- $url.= $depr.'s'.$args['status'];
- }
- else
- {
- if(isset($args['type']) && $args['type'] != '')
- $url.= $depr.$args['type'];
-
- if(isset($args['sort']) && $args['sort'] != '')
- $url.= $depr.$args['sort'];
- }
-
- if(isset($args['page']) && $args['page'] != '0')
- $url.= $depr.$args['page'];
- }
- break;
-
- case 'note':
- if($action == 'index')
- $url = $site_url.$module.$depr.$args['sid'];
- else
- $url = $site_url.$module.$depr.$args['sid'].$depr.$action.$depr.$args['id'];
-
- if(isset($args['page']) && $args['page'] != '0')
- $url.= $depr.$args['page'];
- break;
- }
- }
-
- if($type == 'tgo/index')
- $url = $site_url.'tgo.php?url='.base64_encode($args['url']);
-
- if($is_full)
- $url_flists[$url_key] = $url;
- else
- $url_lists[$url_key] = $url;
- return $url;
- }
-
- /**
- * ????????
- * @param array $keys ???
- * @return void
- */
- function getRewriteArgs($keys)
- {
- global $_FANWE;
- $args = trim($_FANWE['request']['args']);
- foreach($keys as $key)
- {
- preg_match("/$key-(.+?)(?:$|-)/is",$args,$value);
- if(count($value) > 1)
- {
- $_FANWE['request'][$key] = $value[1];
- if($key == 'page')
- $_FANWE['page'] = $value[1];
- }
- }
- unset($_FANWE['request']['args']);
- }
-
- /**
- * ????
- * @param string $type ????
- * @param array $args ??
- * @param int $total_count ??
- * @param int $page ???
- * @param int $page_size ????
- * @param string $url ?????
- * @param int $offset ???
- * @return array
- */
- function buildPage($type,$args,$total_count,$page = 1,$page_size = 0,$url='',$offset = 5)
- {
- global $_FANWE;
-
- $pager['total_count'] = intval($total_count);
- $pager['page'] = $page;
- $pager['page_size'] = ($page_size == 0) ? ($_FANWE['setting']['page_listrows'] > 0 ? $_FANWE['setting']['page_listrows'] : 20) : $page_size;
- /* page ?? */
- $pager['page_count'] = ($pager['total_count'] > 0) ? ceil($pager['total_count'] / $pager['page_size']) : 1;
-
- /* ???? */
- if ($pager['page'] > $pager['page_count'])
- $pager['page'] = $pager['page_count'];
-
- $pager['limit'] = ($pager['page'] - 1) * $pager['page_size'] . "," . $pager['page_size'];
-
- $page_prev = ($pager['page'] > 1) ? $pager['page'] - 1 : 1;
- $page_next = ($pager['page'] < $pager['page_count']) ? $pager['page'] + 1 : $pager['page_count'];
- $pager['prev_page'] = $page_prev;
- $pager['next_page'] = $page_next;
-
- if (!empty($url))
- {
- $pager['page_first'] = $url . 1;
- $pager['page_prev'] = $url . $page_prev;
- $pager['page_next'] = $url . $page_next;
- $pager['page_last'] = $url . $pager['page_count'];
- }
- else
- {
- $args['page'] = '_page_';
- if(!empty($type))
- $page_url = FU($type,$args);
- else
- $page_url = 'javascript:;';
-
- $pager['page_first'] = str_replace('_page_',1,$page_url);
- $pager['page_prev'] = str_replace('_page_',$page_prev,$page_url);
- $pager['page_next'] = str_replace('_page_',$page_next,$page_url);
- $pager['page_last'] = str_replace('_page_',$pager['page_count'],$page_url);
- }
-
- $pager['page_nums'] = array();
-
- if($pager['page_count'] <= $offset * 2)
- {
- for ($i=1; $i <= $pager['page_count']; $i++)
- {
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
- }
- else
- {
- if($pager['page'] - $offset < 2)
- {
- $temp = $offset * 2;
-
- for ($i=1; $i<=$temp; $i++)
- {
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
-
- $pager['page_nums'][] = array('name'=>'...');
- $pager['page_nums'][] = array('name' => $pager['page_count'],'url' => empty($url) ? str_replace('_page_',$pager['page_count'],$page_url) : $url . $pager['page_count']);
- }
- else
- {
- $pager['page_nums'][] = array('name' => 1,'url' => empty($url) ? str_replace('_page_',1,$page_url) : $url . 1);
- $pager['page_nums'][] = array('name'=>'...');
- $start = $pager['page'] - $offset + 1;
- $end = $pager['page'] + $offset - 1;
-
- if($pager['page_count'] - $end > 1)
- {
- for ($i=$start;$i<=$end;$i++)
- {
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
-
- $pager['page_nums'][] = array('name'=>'...');
- $pager['page_nums'][] = array('name' => $pager['page_count'],'url' => empty($url) ? str_replace('_page_',$pager['page_count'],$page_url) : $url . $pager['page_count']);
- }
- else
- {
- $start = $pager['page_count'] - $offset * 2 + 1;
- $end = $pager['page_count'];
- for ($i=$start;$i<=$end;$i++)
- {
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
- }
- }
- }
-
- return $pager;
- }
-
- /**
- * ????
- * @param int $total_count ??
- * @param int $page ???
- * @param int $page_size ????
- * @return array
- */
- function buildPageMini($total_count,$page = 1,$page_size = 0)
- {
- $pager['total_count'] = intval($total_count);
- $pager['page'] = $page;
- $pager['page_size'] = ($page_size == 0) ? ($_FANWE['setting']['page_listrows'] > 0 ? $_FANWE['setting']['page_listrows'] : 20) : $page_size;
- /* page ?? */
- $pager['page_count'] = ($pager['total_count'] > 0) ? ceil($pager['total_count'] / $pager['page_size']) : 1;
-
- /* ???? */
- if ($pager['page'] > $pager['page_count'])
- $pager['page'] = $pager['page_count'];
-
- $pager['limit'] = ($pager['page'] - 1) * $pager['page_size'] . "," . $pager['page_size'];
-
- $page_prev = ($pager['page'] > 1) ? $pager['page'] - 1 : 1;
- $page_next = ($pager['page'] < $pager['page_count']) ? $pager['page'] + 1 : $pager['page_count'];
- $pager['prev_page'] = $page_prev;
- $pager['next_page'] = $page_next;
- return $pager;
- }
-
- /**
- * ????????IP?????,time_span???????? ?
- *
- * @param string $ip_str IP??
- * @param string $module ????? *
- * @param integer $time_span ??
- * @param integer $id ?????
- *
- * @return boolean
- */
- function checkIpOperation($module,$time_span = 0,$id = 0)
- {
- global $_FANWE;
- @session_start();
- $key = $_FANWE['client_ip'].'_'.$_FANWE['uid'].'_check_'.$module.($id > 0 ? '_'.$id : '');
-
- if(!isset($_SESSION[$key]))
- {
- $_SESSION[$key] = TIME_UTC;
- return true;
- }
- else
- {
- $time = (int)$_SESSION[$key];
- if(TIME_UTC - $time < $time_span)
- {
- return false;
- }
- else
- {
- $_SESSION[$key] = TIME_UTC;
- return true;
- }
- }
- }
-
- /**
- * ???????
- * @param string $string ???????
- * @param int $length ????
- * @param string $dot ?????????
- * @return array
- */
- function cutStr($string, $length, $dot = '...')
- {
- if(getStrLen($string) <= $length)
- return $string;
-
- $pre = '{%';
- $end = '%}';
- $string = str_replace(array('&', '"', '<', '>'), array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), $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($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), array('&', '"', '<', '>'), $strcut);
-
- return $strcut.$dot;
- }
-
- /**
- * ???????
- * @param string $str ?????????
- * @return int
- */
- function getStrLen($str)
- {
- $length = strlen(preg_replace('/[\x00-\x7F]/', '', $str));
-
- if ($length)
- {
- return strlen($str) - $length + intval($length / 3) * 2;
- }
- else
- {
- return strlen($str);
- }
- }
-
- /**
- * ?????
- * @param string $val ??????????
- * @return int
- */
- function getBytes($val)
- {
- $val = trim($val);
- $last = strtolower($val{strlen($val)-1});
- switch($last)
- {
- case 'g': $val *= 1024;
- case 'm': $val *= 1024;
- case 'k': $val *= 1024;
- }
-
- return $val;
- }
-
- /**
- * ????
- * @param string $message ????
- * @param bool $show ????
- * @param bool $save ????
- * @param bool $halt ????
- * @return void
- */
- function systemError($message, $show = true, $save = true, $halt = true)
- {
- require_once fimport('class/error');
- FanweError::systemError($message, $show, $save, $halt);
- }
-
- /**
- * ??????
- * @param string $title ??
- * @param string $message ????
- * @param string $jump_url ????
- * @param int $wait ????
- * @return void
- */
- function showSuccess($title, $message,$jump_url,$wait = 3)
- {
- global $_FANWE;
- include template('page/success');
- display();
- exit;
- }
-
- /**
- * ??????
- * @param string $title ??
- * @param string $message ????
- * @param string $jump_url ????
- * @param int $wait ????
- * @param bool $is_close ????????
- * @return void
- */
- function showError($title, $message,$jump_url,$wait = 3,$is_close = false)
- {
- global $_FANWE;
-
- if($is_close)
- include template('page/close');
- else
- include template('page/error');
-
- display();
- exit;
- }
-
- /**
- * ?????????
- * @param string $string
- * @param string $find
- * @return bool
- */
- function strExists($string, $find)
- {
- return !(strpos($string, $find) === FALSE);
- }
-
- /**
- * ???????????
- * @param string $userAgent ????
- * @return bool
- */
- function checkRobot($userAgent = '')
- {
- static $kwSpiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
- static $kwBrowsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
-
- $userAgent = empty($userAgent) ? $_SERVER['HTTP_USER_AGENT'] : $userAgent;
-
- if(!strExists($userAgent, 'http://') && preg_match("/($kwBrowsers)/i", $userAgent))
- return false;
- elseif(preg_match("/($kwSpiders)/i", $userAgent))
- return true;
- else
- return false;
- }
-
- /**
- * ??????????
- * @param string $url ??
- * @return bool
- */
- function parseUrl($url)
- {
- $parse_url = parse_url($url);
- return (!empty($parse_url['scheme']) && !empty($parse_url['host']));
- }
-
-
- /**
- * ?????IP
- * @return string
- */
- function getFClientIp()
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP']))
- {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- }
- elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches))
- {
- foreach ($matches[0] AS $xip)
- {
- if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip))
- {
- $ip = $xip;
- break;
- }
- }
- }
- return $ip;
- }
-
- /**
- * ????
- * @return string
- */
- function fAddslashes($string)
- {
- if(is_array($string))
- {
- foreach($string as $key => $val)
- {
- unset($string[$key]);
- $string[addslashes($key)] = fAddslashes($val);
- }
- }
- else
- {
- $string = addslashes($string);
- }
-
- return $string;
- }
-
- /**
- * ????
- * @return string
- */
- function fStripslashes($string)
- {
- if(is_array($string))
- {
- foreach($string as $key => $val)
- {
- unset($string[$key]);
- $string[stripslashes($key)] = fStripslashes($val);
- }
- }
- else
- {
- $string = stripslashes($string);
- }
-
- return $string;
- }
-
- /**
- * ?????
- * @param int $length ?????
- * @param int $numeric ???????
- * @return string
- */
- function random($length, $numeric = 0)
- {
- $seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
- $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
- $hash = '';
- $max = strlen($seed) - 1;
- for($i = 0; $i < $length; $i++)
- {
- $hash .= $seed{mt_rand(0, $max)};
- }
- return $hash;
- }
-
- /**
- * ??cookie
- * @param string $var ??
- * @param string $value ?
- * @param int $life ????
- * @param bool $prefix ??????
- * @param bool $http_only
- * @return void
- */
- function fSetCookie($var, $value = '', $life = 0, $prefix = true, $http_only = false)
- {
- global $_FANWE;
- $config = $_FANWE['config']['cookie'];
- $_FANWE['cookie'][$var] = $value;
- $var = ($prefix ? $config['cookie_pre'] : '').$var;
- $_COOKIE[$var] = $value;
-
- if($value == '' || $life < 0)
- {
- $value = '';
- $life = -1;
- }
-
- $life = $life > 0 ? TIME_UTC + $life : ($life < 0 ? TIME_UTC - 31536000 : 0);
- $path = $http_only && PHP_VERSION < '5.2.0' ? $config['cookie_path'].'; HttpOnly' : $config['cookie_path'];
-
- $secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
- if(PHP_VERSION < '5.2.0')
- {
- setcookie($var, $value, $life, $path, $config['cookie_domain'], $secure);
- }
- else
- {
- setcookie($var, $value, $life, $path, $config['cookie_domain'], $secure, $http_only);
- }
- }
-
- /**
- * ??session
- * @param bool $force ????
- * @return bool
- */
- function updateSession($force = false) {
-
- global $_FANWE;
- static $updated = false;
-
- if(!$updated)
- {
- $fanwe = & FanweService::instance();
- foreach($fanwe->session->var as $k => $v)
- {
- if(isset($_FANWE['user'][$k]) && $k != 'last_activity')
- $fanwe->session->set($k, $_FANWE['user'][$k]);
- }
-
- $fanwe->session->update();
-
- $updated = true;
- }
-
- return $updated;
- }
-
- /**
- * ??cookie
- * @param string $key ??
- * @return bool
- */
- function getCookie($key)
- {
- global $_FANWE;
- return isset($_FANWE['cookie'][$key]) ? $_FANWE['cookie'][$key] : '';
- }
-
- /**
- * ???????
- * @param string $specialadd ????
- * @return string
- */
- function formHash($specialadd = '')
- {
- global $_FANWE;
- return substr(md5(substr(TIME_UTC, 0, -7).$_FANWE['user_name'].$_FANWE['uid'].$_FANWE['authkey'].$specialadd), 8, 8);
- }
-
- /**
- * ??????
- * @param string $string ??????
- * @param string $operation ????(DECODE:??,ENCODE:??)
- * @param string $key ??
- * @param int $expiry ????
- * @return string
- */
- function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
- {
- global $_FANWE;
- $ckey_length = 4;
- $key = md5($key != '' ? $key : $_FANWE['authkey']);
- $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));
- }
-
- }
-
- /**
- * ??????
- * @param string $file ????
- * @param string $var ?
- * @param string $default ???
- * @return mixed
- */
- function lang($file, $var = NULL, $default = NULL)
- {
- global $_FANWE;
-
- $key = $file."_lang";
-
- if(!isset($_FANWE['lang'][$key]))
- {
- include fimport("language/$file");
- $_FANWE['lang'][$key] = $lang;
- }
-
- $return = $var !== NULL ? (isset($_FANWE['lang'][$key][$var]) ? $_FANWE['lang'][$key][$var] : NULL) : $_FANWE['lang'][$key];
-
- $return = $return === NULL ? ($default !== NULL ? $default : $var) : $return;
-
- return $return;
- }
-
- /**
- * ??IP??????????IP
- * @param string $ip ip
- * @param string $access_list ip??
- * @return bool
- */
- function ipAccess($ip, $access_list)
- {
- return preg_match("/^(".str_replace(array("\r\n", ' '), array('|', ''), preg_quote($access_list, '/')).")/", $ip);
- }
-
- /**
- * ??IP??????
- * @param string $ip ip
- * @return bool
- */
- function ipBanned($ip)
- {
- global $_FANWE;
-
- if($_FANWE['setting']['ip_access'] && !ipAccess($ip, $_FANWE['setting']['ip_access']))
- {
- return true;
- }
-
- FanweService::instance()->cache->loadCache('ipbanned');
-
- if(empty($_FANWE['cache']['ipbanned']))
- return false;
- else
- {
- if($_FANWE['cache']['ipbanned']['expiration'] < TIME_UTC)
- {
- FanweService::instance()->cache->updateCache('ipbanned');
- }
-
- return preg_match("/^(".$_FANWE['cache']['ipbanned']['regexp'].")$/", $ip);
- }
- }
-
- /**
- * ????cache????
- * @param string $file ????
- * @param array $args ??
- * @param int $is_dynamic ???????(???????????????)
- * @param string $dir ????
- * @return string
- */
- function getTplCache($file, $args, $is_dynamic = 0,$dir = '')
- {
- global $_FANWE;
- $tpl_dir = './tpl/'.$_FANWE['setting']['site_tmpl'];
- $tpl_file = $tpl_dir.'/'.$file.'.htm';
-
- if(!empty($dir))
- $dir .= '/';
-
- switch($is_dynamic)
- {
- case 1:
- $dir = 'dynamic/'.$dir;
- break;
-
- case 2:
- $dir = 'page/'.$dir;
- break;
-
- default:
- $dir = 'static/'.$dir;
- break;
- }
- return PUBLIC_ROOT.'./data/tpl/caches/'.$dir.str_replace('/', '_', $file).'/'.md5($tpl_file.implode(',',$args)).".htm";
- }
-
- /**
- * ??????????
- * @param string $main_tpl
- * @param string $sub_tpl
- * @param int $time_compare
- * @param string $cache_file
- * @param string $tpl_dir
- * @param string $file
- * @return bool
- */
- function checkTplRefresh($main_tpl, $sub_tpl, $time_compare, $cache_file, $tpl_dir, $file)
- {
- global $_FANWE;
- static $tpl_refresh = NULL;
- if($tpl_refresh === NULL)
- {
- $tpl_refresh = $_FANWE['config']['output']['tpl_refresh'];
- }
-
- if(empty($time_compare) || $tpl_refresh == 1 || ($tpl_refresh > 1 && !(TIMESTAMP % $tpl_refresh)))
- {
- if(empty($time_compare) || @filemtime(FANWE_ROOT.$sub_tpl) > $time_compare)
- {
- require_once fimport('class/template');
- $template = new Template();
- $template->parseTemplate($main_tpl, $tpl_dir, $file, $cache_file);
- return TRUE;
- }
- }
- return FALSE;
- }
-
- /**
- * ????
- * @param string $file
- * @param string $tpl_dir
- * @param bool $get_tpl_file
- * @return string
- */
- function template($file, $tpl_dir = '', $get_tpl_file = 0)
- {
- global $_FANWE;
-
- $tpl_dir = $tpl_dir ? $tpl_dir : './tpl/'.$_FANWE['setting']['site_tmpl'];
- $tpl_file = $tpl_dir.'/'.$file.'.htm';
- $cache_file = './data/tpl/compiled/'.str_replace('/', '_', $file).'.tpl.php';
-
- if($get_tpl_file)
- return $tpl_file;
-
- checkTplRefresh($tpl_file, $tpl_file, @filemtime(PUBLIC_ROOT.$cache_file), $cache_file, $tpl_dir, $file);
- return PUBLIC_ROOT.$cache_file;
- }
-
- /**
- * ?????????
- * @param string $file
- * @param array $args
- * @param string $tpl_dir
- * @return string
- */
- function tplFetch($file,&$args = array(), $tpl_dir = '',$cache_file = '')
- {
- global $_FANWE;
-
- if(!empty($args))
- {
- foreach($args as $key=>$val)
- {
- $$key = &$args[$key];
- }
- }
-
- ob_start();
- if(!empty($cache_file) && file_exists($cache_file))
- include $cache_file;
- else
- include template($file,$tpl_dir);
- $content = ob_get_contents();
- ob_end_clean();
-
- express($content);
- if(!empty($cache_file) && !file_exists($cache_file) && diskfreespace(PUBLIC_ROOT.'./data/tpl/caches') > 1000000)
- {
- if(makeDir(preg_replace("/^(.*)\/.*?\.htm$/is", "\\1", $cache_file)))
- writeFile($cache_file,$content);
- }
-
- require_once fimport('dynamic/common');
- $module_dynamic = '';
- if(defined('MODULE_NAME') && MODULE_NAME != '')
- $module_dynamic = fimport('dynamic/'.MODULE_NAME);
-
- if(!empty($module_dynamic) && file_exists($module_dynamic))
- require_once $module_dynamic;
-
- $content = preg_replace('/<!--dynamic\s+(.+?)(?:|\sargs=(.*?))-->/ies', "\\1('\\2');", $content);
-
- //???????
- formatUserFollowTags($content);
- contentParse($content);
-
- return $content;
- }
-
- /**
- * ????????????????
- * @param string $string
- * @param string $cache_key
- * @param array $args
- * @return string
- */
- function tplString($string,$cache_key,&$args = array())
- {
- global $_FANWE;
-
- if(!empty($args))
- {
- foreach($args as $key=>$val)
- {
- $$key = &$args[$key];
- }
- }
-
- if(empty($cache_key))
- $cache_key = md5($string);
-
- $cache_file = PUBLIC_ROOT.'./data/tpl/caches/'.$cache_key.'.htm';
-
- if(!file_exists($cache_file))
- {
- if(makeDir(preg_replace("/^(.*)\/.*?\.htm$/is", "\\1", $cache_file)))
- {
- require_once fimport('class/template');
- $template = new Template();
- $string = $template->parseString($string);
- writeFile($cache_file,$string);
- }
- }
-
- ob_start();
- include $cache_file;
- $content = ob_get_contents();
- ob_end_clean();
-
- require_once fimport('dynamic/common');
- $module_dynamic = '';
- if(defined('MODULE_NAME') && MODULE_NAME != '')
- $module_dynamic = fimport('dynamic/'.MODULE_NAME);
-
- if(!empty($module_dynamic) && file_exists($module_dynamic))
- require_once $module_dynamic;
-
- $content = preg_replace('/<!--dynamic\s+(.+?)(?:|\sargs=(.*?))-->/ies', "\\1('\\2');", $content);
- //???????
- express($content);
- formatUserFollowTags($content);
- contentParse($content);
- return $content;
- }
-
- /**
- * ????
- * @param string $cache_file ????
- * @param bool $is_session ????session
- * @param bool $is_return ????????
- * @return mixed
- */
- function display($cache_file,$is_session = true,$is_return = false)
- {
- global $_FANWE;
- $content = NULL;
- if(!empty($cache_file) && !file_exists($cache_file) && diskfreespace(PUBLIC_ROOT.'./data/tpl/caches') > 1000000)
- {
- if(makeDir(preg_replace("/^(.*)\/.*?\.htm$/is", "\\1", $cache_file)))
- {
- $css_script_php = '';
- if(isset($_FANWE['page_parses']))
- $css_script_php = "<?php\n".'$_FANWE[\'CACHE_CSS_SCRIPT_PHP\']'." = ".var_export($_FANWE['page_parses'], true).";\n?>";
-
- $content = ob_get_contents();
- express($content);
- writeFile($cache_file,$css_script_php.$content);
- }
- }
-
- require_once fimport('dynamic/common');
- $module_dynamic = '';
- if(defined('MODULE_NAME') && MODULE_NAME != '')
- $module_dynamic = fimport('dynamic/'.MODULE_NAME);
-
- if(!empty($module_dynamic) && file_exists($module_dynamic))
- require_once $module_dynamic;
-
- if($content === NULL)
- {
- $content = ob_get_contents();
- express($content);
- }
- ob_end_clean();
- $content = preg_replace('/<!--dynamic\s+(.+?)(?:|\sargs=(.*?))-->/ies', "\\1('\\2');", $content);
-
- if(isset($_FANWE['CACHE_CSS_SCRIPT_PHP']))
- {
- if(isset($_FANWE['CACHE_CSS_SCRIPT_PHP']['css']))
- {
- foreach($_FANWE['CACHE_CSS_SCRIPT_PHP']['css'] as $url)
- {
- cssParse($url);
- }
- }
-
- if(isset($_FANWE['CACHE_CSS_SCRIPT_PHP']['script']))
- {
- foreach($_FANWE['CACHE_CSS_SCRIPT_PHP']['script'] as $url)
- {
- scriptParse($url);
- }
- }
- }
-
- //???????
- formatUserFollowTags($content);
- contentParse($content);
-
- if($is_session)
- updateSession();
-
- if($is_return)
- return $content;
-
- $_FANWE['gzip_compress'] ? ob_start('ob_gzhandler') : ob_start();
-
- echo $content;
- }
-
- function contentParse(&$content)
- {
- global $_FANWE;
-
- $patterns = array (
- "/\.\/public\/js\//i",
- "/\.\/public\/upload\//i",
- "/\.\/public\//i",
- //"/\.\/tpl\/(.*?)\/css\//i",
- //"/\.\/tpl\/(.*?)\/js\//i",
- //"/\.\/tpl\/(.*?)\/images\//i",
- "/\.\/tpl\/css\//i",
- "/\.\/tpl\/images\//i",
- "/\.\/tpl\/js\//i",
- "/\.\/tpl\/(.*?)\//i",
- );
-
- $image_url = !empty($_FANWE['config']['cdn']['image']) ? $_FANWE['config']['cdn']['image'] : $_FANWE['site_root'];
- $css_url = !empty($_FANWE['config']['cdn']['css']) ? $_FANWE['config']['cdn']['css'] : $_FANWE['site_root'];
- $js_url = !empty($_FANWE['config']['cdn']['js']) ? $_FANWE['config']['cdn']['js'] : $_FANWE['site_root'];
-
- $replace = array (
- $js_url.'public/js/',
- $image_url.'public/upload/',
- $_FANWE['site_root'].'public/',
- //$css_url.'tpl/\\1/css/',
- //$js_url.'tpl/\\1/js/',
- //$image_url.'tpl/\\1/images/',
- $_FANWE['site_root'].'public/data/tpl/css/',
- $_FANWE['site_root'].'tpl/'.TMPL.'/images/',
- $_FANWE['site_root'].'tpl/'.TMPL.'/js/',
- $_FANWE['site_root'].'tpl/\\1/',
- );
-
- $content = preg_replace($patterns,$replace, $content);
- }
-
- function clearExpress($content)
- {
- return preg_replace("/\[[^\]]+\]/i",'',$content);
- }
-
- function express(&$content)
- {
- global $_FANWE;
-
- $express = getCache('emotion_express_cache'); //??????hash
- if(!$express)
- {
- $express_rs = FDB::fetchAll("select `emotion`,concat('./public/expression/',`type`,'/',`filename`) as fname from ".FDB::table('expression'));
- foreach($express_rs as $k=>$row)
- {
- $express[0][] = $row['emotion'];
- $express[1][] = "<img src='".$row['fname']."' title='".preg_replace("/[\[\]]/",'',$row['emotion'])."' />";
- }
- setCache('emotion_express_cache',$express);
- }
-
- preg_match("/(<html.*?>.*?<\/head>)/s",$content,$data);
- $head_html = $data[1];
- $content = str_replace($head_html,'<!--TAG_HEADER-->',$content);
-
- preg_match_all("/(<textarea.*?>.*?<\/textarea>)/s",$content,$data);
- $textareas = $data[1];
- if(count($textareas) > 0)
- {
- foreach($textareas as $key => $textarea)
- {
- $content = str_replace($textarea,'<!--TAG_TEXTAREA_'.$key.'-->',$content);
- }
- }
-
- preg_match_all("/@([^\f\n\r\t\v@<> ]{2,20}?)(?:\:| )/",$content,$users);
- if(!empty($users[1]))
- {
- $patterns = array();
- $replace = array();
- $users = array_unique($users[1]);
- $arr = array();
- foreach($users as $user)
- {
- if(!empty($user))
- {
- $arr[] = addslashes($user);
- }
- }
-
- $res = FDB::query('SELECT uid,user_name
- FROM '.FDB::table('user').'
- WHERE user_name '.FDB::createIN($arr));
- while($data = FDB::fetch($res))
- {
- $patterns[] = '/@'.preg_quote($data['user_name']).'(\:| )/';
- $replace[] = '<a class="u_name GUID" uid="'.$data['uid'].'" href="'.FU('u/index',array('uid'=>$data['uid'])).'">@'.$data['user_name']."</a>\$1";
- }
-
- $content = preg_replace($patterns,$replace,$content);
- }
-
- preg_match_all("/#([^\f\n\r\t\v]{1,80}?)#/",$content,$events);
- if(!empty($events[1]))
- {
- $patterns = array();
- $replace = array();
- $events = array_unique($events[1]);
- $arr = array();
- foreach($events as $event)
- {
- if(!empty($event))
- {
- $arr[] = addslashes($event);
- }
- }
-
- $res = FDB::query('SELECT id,title
- FROM '.FDB::table('event').'
- WHERE title '.FDB::createIN($arr));
- while($data = FDB::fetch($res))
- {
- $patterns[] = '#'.$data['title'].'#';
- $replace[] = '<a href="'.FU("event/detail",array("id"=>$data['id'])).'" target="_blank">#'.$data['title'].'#</a>';
- }
-
- $content = str_replace($patterns,$replace,$content);
- }
-
- if(count($_FANWE['tpl_user_formats']) > 0)
- {
- $patterns = array();
- $replace = array();
-
- $user_ids = array_keys($_FANWE['tpl_user_formats']);
- $user_ids = implode(',',$user_ids);
- $res = FDB::query("SELECT uid,user_name,reg_time,credits,is_daren,is_buyer,follows,fans,collects,
- favs,threads,photos,goods,ask,ask_posts,ask_best_posts,shares,forums,forum_posts,
- seconds,albums,referrals FROM ".FDB::table('user').'
- INNER JOIN '.FDB::table('user_count').' AS uc USING(uid)
- WHERE uid IN ('.$user_ids.')');
- while($user = FDB::fetch($res))
- {
- $uid = $user['uid'];
- $user['url'] = FU('u/index',array('uid'=>$uid));
- foreach($_FANWE['tpl_user_formats'][$uid] as $tuf_key => $tuf_val)
- {
- $patterns[] = "<!--USER_".$uid."_".$tuf_key."-->";
- $replace[] = getUserFormatHtml($user,$tuf_val);
- }
- unset($_FANWE['tpl_user_formats'][$uid]);
- }
- $content = str_replace($patterns,$replace,$content);
- }
-
- $content = str_replace($express[0],$express[1],$content);
- $content = str_replace('<!--TAG_HEADER-->',$head_html,$content);
-
- if(count($textareas) > 0)
- {
- foreach($textareas as $key => $textarea)
- {
- $content = str_replace('<!--TAG_TEXTAREA_'.$key.'-->',$textarea,$content);
- }
- }
- return $content;
- }
-
- //???????
- function setTplUserFormat($uid,$type,$is_mark,$img_type,$img_size,$link_class,$img_class,$tpl)
- {
- global $_FANWE;
- $key = md5($type.'_'.$is_mark.'_'.$img_type.'_'.$img_size.'_'.$link_class.'_'.$img_class.'_'.$tpl);
- $_FANWE['tpl_user_formats'][$uid][$key] = array(
- 'type' => $type,
- 'is_mark'=>$is_mark,
- 'img_type' => $img_type,
- 'img_size' => $img_size,
- 'link_class' => $link_class,
- 'img_class' => $img_class,
- 'tpl' => $tpl
- );
- return "<!--USER_".$uid."_".$key."-->";
- }
-
- //???????html
- function getUserFormatHtml($user,$format)
- {
- global $_FANWE;
- static $templates = array(),$daren_name = NULL;
- $html = '';
- if(!empty($format['tpl']))
- {
- if(!isset($templates[$format['tpl']]))
- $templates[$format['tpl']] = template($format['tpl']);
-
- if($templates[$format['tpl']])
- {
- ob_start();
- include $templates[$format['tpl']];
- $html = ob_get_contents();
- ob_end_clean();
- }
- }
- else
- {
- $uid = $user['uid'];
- $user_name = htmlspecialchars($user['user_name']);
- if($format['type'] == 0)
- $html = '<a class="GUID '.$format['link_class'].'" uid="'.$uid.'" title="'.$user_name.'" href="'.$user['url'].'" target="_blank">'.$user_name.'</a>';
- else
- {
- $width = '';
- if($format['img_size'] > 0)
- $width = 'width="'.$format['img_size'].'" ';
-
- $is_lazyload = FALSE;
- $img_class = $format['img_class'];
- if(!empty($img_class))
- $is_lazyload = strpos($img_class,'lazyload');
-
- $link_class = '';
- if(!empty($format['link_class']))
- $link_class = 'class="'.$format['link_class'].'" ';
-
- if($is_lazyload === FALSE)
- $html = '<a '.$link_class.'title="'.$user_name.'" href="'.$user['url'].'" target="_blank"><img class="GUID '.$img_class.'" uid="'.$uid.'" src="'.avatar($uid,$format['img_type'],1).'" '.$width.' alt="'.$user_name.'"/></a>';
- else
- $html = '<a '.$link_class.'title="'.$user_name.'" href="'.$user['url'].'" target="_blank"><img class="GUID '.$img_class.'" uid="'.$uid.'" original="'.avatar($uid,$format['img_type'],1).'" src="./tpl/images/lazyload.gif" '.$width.' alt="'.$user_name.'"/></a>';
- }
-
- if($format['is_mark'] == 1)
- {
- if($user['is_daren'] == 1)
- {
- if($daren_name === NULL)
- $daren_name = sprintf(lang('user','daren_alt'),$_FANWE['setting']['site_name']);
- $html .= '<a href="'.FU('daren/apply').'" class="v" target="_blank"><img title="'.$daren_name.'" src="./tpl/images/daren_icon.png" class="v"></a>';
- }
- elseif($user['is_buyer'] == 1)
- $html .= '<a href="'.FU('settings/buyerverifier').'" class="v" target="_blank"><img title="'.lang('user','buyer_alt').'" src="./tpl/images/buyer_icon.png" class="v"></a>';
- }
- }
- return $html;
- }
-
- function formatUserFollowTags(&$content)
- {
- global $_FANWE;
-
- preg_match_all("/<!--getfollow\s(\d+?)\s(.+?)-->/",$content,$follows);
- if(!empty($follows[1]))
- {
- $patterns = array();
- $replace = array();
- $user_ids = array();
-
- foreach($follows[1] as $key => $uid)
- {
- $tpl = $follows[2][$key];
- if($_FANWE['uid'] == $uid)
- {
- if(!isset($user_ids[$uid][$tpl]))
- {
- $patterns[] = "<!--getfollow ".$uid." ".$tpl."-->";
- $replace[] = getUserFollowFormatHtml($uid,-1,$tpl);
- $user_ids[$uid][$tpl] = -1;
- }
- }
- else
- {
- $user_ids[$uid]['is_follow'] = 0;
- $user_ids[$uid]['tpls'][$tpl] = 0;
- }
- }
- unset($user_ids[$_FANWE['uid']]);
-
- if($_FANWE['uid'] > 0)
- {
- $follow_ids = array_keys($user_ids);
- if(count($follow_ids) > 0)
- {
- $res = FDB::query("SELECT uid FROM ".FDB::table('user_follow').'
- WHERE f_uid = '.$_FANWE['uid'].' AND uid IN ('.implode(',',$follow_ids).')');
- while($item = FDB::fetch($res))
- {
- $user_ids[$item['uid']]['is_follow'] = 1;
- }
- }
- }
-
- foreach($user_ids as $uid => $user)
- {
- $is_follow = $user['is_follow'];
- foreach($user['tpls'] as $tpl => $temp)
- {
- $patterns[] = "<!--getfollow ".$uid." ".$tpl."-->";
- $replace[] = getUserFollowFormatHtml($uid,$is_follow,$tpl);
- }
- }
-
- $content = str_replace($patterns,$replace,$content);
- }
- }
-
- //?????????html
- function getUserFollowFormatHtml($uid,$is_follow,$tpl)
- {
- static $templates = array();
- $html = '';
-
- if(!isset($templates[$tpl]))
- $templates[$tpl] = template($tpl);
-
- if($templates[$tpl])
- {
- ob_start();
- include $templates[$tpl];
- $html = ob_get_contents();
- ob_end_clean();
- }
-
- return $html;
- }
-
- /**
- * ??????
- * @param string $file ??????
- * @param int $is_dynamic ???????
- * @param string $dir ????
- * @return void
- */
- function clearTplCache($file,$is_dynamic = 0,$dir='')
- {
- if(!empty($dir))
- $dir .= '/';
- $dir = ($is_dynamic == 1 ? 'dynamic/' : 'static/').$dir;
- clearDir(PUBLIC_ROOT.'./data/tpl/caches/'.$dir.str_replace('/', '_', $file));
- }
-
- /**
- * ????????????
- * @param string $cache_file ??????
- * @param int $time_out ????(?)
- * @return bool ?????? true
- */
- function getCacheIsUpdate($cache_file,$time_out)
- {
- if (!file_exists($cache_file))
- return true;
-
- $mtime = filemtime($cache_file);
-
- if(TIMESTAMP - $mtime > $time_out)
- {
- removeFile($cache_file);
- return true;
- }
- else
- return false;
- }
-
- /**
- * ??json??
- * @param mixed $result ??????
- * @return void
- */
- function outputJson($result,$is_die = true)
- {
- static $json = NULL;
- if($json === NULL)
- {
- require fimport('class/json');
- $json = new Json();
- }
-
- if($is_die)
- die($json->encode($result));
- else
- return $json->encode($result);
- }
-
- /**
- * ??json??
- * @param mixed $result
- * @return string
- */
- function getJson($result)
- {
- static $json = NULL;
- if($json === NULL)
- {
- require fimport('class/json');
- $json = new Json();
- }
- return $json->encode($result);
- }
-
- /**
- * ??????????
- * @param string $dir ????
- * @return void
- */
- function clearDir($dir,$is_del_dir = false)
- {
- if(!file_exists($dir))
- return;
-
- $directory = dir($dir);
-
- while($entry = $directory->read())
- {
- if($entry != '.' && $entry != '..')
- {
- $filename = $dir.'/'.$entry;
- if(is_dir($filename))
- clearDir($filename,$is_del_dir);
-
- if(is_file($filename))
- removeFile($filename);
- }
- }
-
- $directory->close();
- if($is_del_dir)
- @rmdir($dir);
- }
-
- /**
- * ?????????????????????????
- *
- * @access public
- * @param string folder ??????????????????URL
- *
- * @return bool
- */
- function makeDir($folder)
- {
- $reval = false;
- if (!file_exists($folder))
- {
- $folder = str_replace(FANWE_ROOT,'',$folder);
- /* ??????????????? */
- @umask(0);
- /* ?????????? */
- preg_match_all('/([^\/]*)\/?/i', $folder, $atmp);
- /* ????????/????????? */
- $base = FANWE_ROOT.(($atmp[0][0] == '/') ? '/' : '');
-
- /* ??????????? */
- foreach ($atmp[1] AS $val)
- {
- if ('' != $val)
- {
- $base .= $val;
- if ('..' == $val || '.' == $val)
- {
- /* ?????.??..????/??????? */
- $base .= '/';
- continue;
- }
- }
- else
- {
- continue;
- }
- $base .= '/';
-
- if (!file_exists($base))
- {
- /* ?????????????????? */
- if (@mkdir(rtrim($base, '/'), 0777))
- {
- @chmod($base, 0777);
- $reval = true;
- }
- }
- }
- }
- else
- {
- /* ??????????????????? */
- $reval = is_dir($folder);
- }
-
- clearstatcache();
- return $reval;
- }
-
- /**
- * utf8?????GBK???
- * @param string $str ???????
- * @return void
- */
- function utf8ToGB($str)
- {
- static $chinese = NULL;
- if($chinese === NULL)
- {
- require_once fimport('class/chinese');
- $chinese = new Chinese('UTF-8','GBK');
- }
- return $chinese->convert($str);
- }
-
- /**
- * GBK????utf8????
- * @param string $str ???????
- * @return void
- */
- function gbToUTF8($str)
- {
- static $chinese = NULL;
- if($chinese === NULL)
- {
- require_once fimport('class/chinese');
- $chinese = new Chinese('GBK','UTF-8');
- }
- return $chinese->convert($str);
- }
-
- /**
- * utf8???Unicode??
- * @param string $char ???????
- * @return void
- */
- function utf8ToUnicode($char)
- {
- switch(strlen($char))
- {
- case 1:
- return ord($char);
- case 2:
- $n = (ord($char[0]) & 0x3f) << 6;
- $n += ord($char[1]) & 0x3f;
- return $n;
- case 3:
- $n = (ord($char[0]) & 0x1f) << 12;
- $n += (ord($char[1]) & 0x3f) << 6;
- $n += ord($char[2]) & 0x3f;
- return $n;
- case 4:
- $n = (ord($char[0]) & 0x0f) << 18;
- $n += (ord($char[1]) & 0x3f) << 12;
- $n += (ord($char[2]) & 0x3f) << 6;
- $n += ord($char[3]) & 0x3f;
- return $n;
- }
- }
-
- /**
- * utf8??????unicode???
- * @param string $str ???????
- * @param string $pre
- * @return string
- */
- function segmentToUnicode($str,$pre = '')
- {
- $arr = array();
- $str_len = mb_strlen($str,'UTF-8');
- for($i = 0;$i < $str_len;$i++)
- {
- $s = mb_substr($str,$i,1,'UTF-8');
- if($s != ' ' && $s != '?')
- {
- $arr[] = $pre.'ux'.utf8ToUnicode($s);
- }
- }
-
- $arr = array_unique($arr);
-
- return implode(' ',$arr);
- }
-
- /**
- * ????????unicode???
- * @param array $tags ??????
- * @param string $pre
- * @return string
- */
- function tagToUnicode($tags,$pre = '')
- {
- $tags = array_unique($tags);
-
- $arr = array();
- foreach($tags as $tag)
- {
- $tmp = '';
- $str_len = mb_strlen($tag,'UTF-8');
- for($i = 0;$i < $str_len;$i++)
- {
- $s = mb_substr($tag,$i,1,'UTF-8');
- if($s != ' ' && $s != '?')
- {
- $tmp.= 'ux'.utf8ToUnicode($s);
- }
- }
-
- if($tmp != '')
- $arr[] = $pre.$tmp;
- }
-
- $arr = array_unique($arr);
- return implode(' ',$arr);
- }
-
- /**
- * ????
- * @param string $str ?????????
- * @return string
- */
- function clearSymbol($str)
- {
- static $symbols …
Large files files are truncated, but you can click here to view the full file