array('File\\Path','create'),
'page' => array('Page\\Main','getPage'),
'total' => array('Page\\Main','getTotal'),
'url' => array('Http\\Url','get'),
'location' => array('Http\\Url','location'),
'input' => array('Http\\Input','get'),
'preInput' => array('Http\\Input','prefix'),
'setInput' => array('Http\\Input','set'),
'abert' => array('Http\\Output','abert'),
'out' => array('Http\\Output','result'),
'export' => array('Http\\Output','export'),
'load' => array('Routing\\Load','get'),
'object' => array('Routing\\Load','object'),
'config' => array('Config\\Load','get'),
'project' => array('Config\\Project','load'),
'debug' => array('Debug\\Process','wait'),
);
/**
* 设置循环里每行不同的值
* @param string $value
* @param string $index
*
* @return array
*/
static public function lace($value, $index, $key = 2, $num = 0)
{
$value = explode(',', $value);
if(!isset($value[1]))
{
$value[1] = '';
}
if($index > 0 && $index%$key == $num)
{
return $value[0];
}
else
{
return $value[1];
}
}
/**
* 设置循环里最新一条数据的值
* @param string $value
* @param string $index
*
* @return array
*/
static public function first($value, $index)
{
if($index == 0)
{
return $value;
}
}
/**
* 设置循环里最后一条数据的值
* @param string $value
* @param string $index
* @param string $total
*
* @return array
*/
static public function last($value, $index, $total)
{
if($index == $total)
{
return $value;
}
}
/**
* 获取assets的文件网络路径
* @param string $value
* @param string $type
*
* @return array
*/
static public function assets($value, $type = 'css')
{
return parent::$global['host'][$type] . $value;
}
/**
* 生成table
* @param string $thead
* @param string $tbody
* @param string $class
*
* @return array
*
static public function table($thead, $tbody, $class = '')
{
$result = '
';
foreach($thead as $k => $v)
{
$result .= '' . $v . ' | ';
}
$result .= '
';
foreach($tbody as $k => $v)
{
$result .= '' . $k . ' | ' . $v . ' |
';
}
$result .= '
';
return $result;
}
/**
* 生成table
* @param string $data
* @param string $class
*
* @return array
*/
static public function table($data, $class = '')
{
if($class)
{
$style = 'class='.$class.'';
}
else
{
$style = 'border=1 width=100% height=100%';
}
$html = '';
foreach($data as $k => $v)
{
if(is_array($v))
{
$v = self::table($v, $class);
//$v = var_export($v, true);
}
$html .= ''.$k.' | '.$v.' |
';
}
$html .= '
';
return $html;
}
/**
* 获取pic
* @param string $value
* @param string $index
*
* @return array
*/
static public function pic($pic, $name)
{
if(strpos($pic, '_t') !== false)
{
$temp = explode('_', $pic);
$pic = $temp[0] . '_' . $name . '.jpg';
}
return $pic;
}
/**
* 获取_param
* @param string $value
* @param string $index
*
* @return array
*/
static public function param($name)
{
if(isset(Maze::$global['base']['_param']))
{
if(isset(Maze::$global['base']['_param']['add_' . $name]))
{
return Maze::$global['base']['_param']['add_' . $name];
}
if(isset(Maze::$global['base']['_param']['set_' . $name]))
{
return Maze::$global['base']['_param']['set_' . $name];
}
}
return false;
}
/**
* 获取ip
*
* @return string
*/
static public function ip()
{
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown'))
{
$ip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown'))
{
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown'))
{
$ip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown'))
{
$ip = $_SERVER['REMOTE_ADDR'];
}
return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
}
/**
* 获取ua
*
* @return string
*/
static public function ua()
{
return $_SERVER['HTTP_USER_AGENT'];
}
/**
* 运维程序
*
* @return string
*/
static public function daemon($interface, $project = false)
{
$project = $project ? $project : MAZE_PROJECT_NAME;
$path = self::load('manage/project.path', $project);
if(strpos($path, 'http://'))
{
//self::curl($path . $interface);
system('curl ' . $path . $interface . ' > /dev/null &');
}
else
{
# ?和&无法解析
$interface = str_replace(array('?', '&'), array('__', '^'), $interface);
system('php ' . $path . 'index.php -send ' . $interface . ' > /dev/null &');
}
}
/**
* 加入到cron中
*
* @return string
*/
static public function cron($name, $ldate, $interface, $time = 0, $project = false, $update = true)
{
if($ldate > 0)
{
$ldate = date('Y-m-d H:i:s', $ldate);
}
$info = Maze::load('manage/cron-getOne', array('where_project' => $project, 'where_interface' => $interface));
if($info)
{
if($update)
{
$update = array();
$update['set_name'] = $name;
$update['set_ldate'] = $ldate;
$update['set_interface'] = $interface;
$update['set_time'] = $time;
$update['set_project'] = $project;
$update['set_state'] = 1;
$update['where_id'] = $info['id'];
Maze::load('manage/cron-update', $update);
}
}
else
{
$update['add_name'] = $name;
$update['add_ldate'] = $ldate;
$update['add_interface'] = $interface;
$update['add_time'] = $time;
$update['add_project'] = $project;
Maze::load('manage/cron-insert', $update);
}
}
/**
* 字符串截取
* @param string $string
* @param string $length
* @param string $etc
*
* @return array
*/
static public function cut($string, $length = 80, $etc = '...')
{
$result = '';
$string = html_entity_decode(trim(strip_tags($string)), ENT_QUOTES, 'utf-8');
for($i = 0, $j = 0; $i < strlen($string); $i++)
{
if($j >= $length)
{
for($x = 0, $y = 0; $x < strlen($etc); $x++)
{
if($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0'))
{
$x += $number - 1;
$y++;
}
else
{
$y += 0.5;
}
}
$length -= $y;
break;
}
if($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0'))
{
$i += $number - 1;
$j++;
}
else
{
$j += 0.5;
}
}
for($i = 0; (($i < strlen($string)) && ($length > 0)); $i++)
{
if($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0'))
{
if($length < 1.0)
{
break;
}
$result .= substr($string, $i, $number);
$length -= 1.0;
$i += $number - 1;
}
else
{
$result .= substr($string, $i, 1);
$length -= 0.5;
}
}
$result = htmlentities($result, ENT_QUOTES, 'utf-8');
if($i < strlen($string))
{
$result .= $etc;
}
return $result;
}
/**
* 执行hack的值
* @param string $value
* @param string $index
* @param string $total
*
* @return array
*/
static public function hack($key)
{
if(isset(parent::$global['hack'][$key]))
{
return parent::$global['hack'][$key];
}
}
/**
* 注册maze类库里的常用类,方便使用
* @param string $name
* @param array $param
*
* @return mixed
*/
static public function __callStatic($name, $param = array())
{
if(isset(self::$register[$name]))
{
$class = 'Maze\\' . self::$register[$name][0];
$method = self::$register[$name][1];
if(isset($param[2]))
{
return $class::$method($param[0], $param[1], $param[2]);
}
elseif(isset($param[1]))
{
return $class::$method($param[0], $param[1]);
}
elseif(isset($param[0]))
{
return $class::$method($param[0]);
}
else
{
return $class::$method();
}
}
}
static public function curl($url, $param = false, $type = '')
{
//初始化
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
if($param)
{
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
if($type == 'json')
{
# 中文不用unicode编码
$string = str_replace("\\/", "/", json_encode($param));
$search = "#\\\u([0-9a-f]+)#ie";
if(strpos(strtoupper(PHP_OS), 'WIN') === false)
{
$replace = "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))";//LINUX
}
else
{
$replace = "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))";//WINDOWS
}
$param = preg_replace($search, $replace, $string);
//$param = json_encode($param, JSON_UNESCAPED_UNICODE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($param))
);
}
//print_r($param);die;
// post的变量
@curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
}
//执行并获取HTML文档内容
$output = curl_exec($ch);
//释放curl句柄
curl_close($ch);
//打印获得的数据
return $output;
}
static public function weixin()
{
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false)
{
return true;
}
return false;
}
static public function mobile()
{
$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
$mobile_browser = '0';
if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
{
$mobile_browser++;
}
if((isset($_SERVER['HTTP_ACCEPT'])) && (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))
{
$mobile_browser++;
}
if(isset($_SERVER['HTTP_X_WAP_PROFILE']))
{
$mobile_browser++;
}
if(isset($_SERVER['HTTP_PROFILE']))
{
$mobile_browser++;
}
$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda','xda-'
);
if(in_array($mobile_ua, $mobile_agents))
{
$mobile_browser++;
}
if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
{
$mobile_browser++;
}
// Pre-final check to reset everything if the user is on Windows
if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
{
$mobile_browser=0;
}
// But WP7 is also Windows, with a slightly different characteristic
if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
{
$mobile_browser++;
}
if($mobile_browser>0)
{
return true;
}
else
{
return false;
}
}
static public function maketime($v)
{
if(!$v) return '';
if(is_array($v))
{
$v = $v[1];
}
if(strstr($v, ' '))
{
$t = explode(' ', $v);
$v = $t[0];
$s = explode(':', $t[1]);
}
else
{
$s = array(0,0,0);
}
if(strstr($v, '-'))
{
$t = explode('-', $v);
}
elseif(strstr($v, '/'))
{
$u = explode('/', $v);
$t[0] = $u[2];
$t[1] = $u[0];
$t[2] = $u[1];
}
if(!isset($t))
{
$t = array(0,0,0);
}
$v = mktime($s[0], $s[1], $s[2], $t[1], $t[2], $t[0]);
return $v;
}
/**
* 生成随机码
*/
static function code($num = 4)
{
$codes = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$code="";
for($i=1;$i<=$num;$i++)
{
$code.=$codes{rand(0,61)};
}
return $code;
}
}