12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193 |
- <?php
- class Dever extends Dever\Config\Load
- {
- static private $register = array
- (
- 'path' => array('File\\Path','create'),
- 'page' => array('Page\\Main','getPage'),
- 'total' => array('Page\\Main','getTotal'),
- 'html' => array('Page\\Main','getHtml'),
- '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'),
- 'pageInfo' => array('Http\\Output','page'),
- 'load' => array('Routing\\Load','get'),
- 'object' => array('Routing\\Load','object'),
- 'setStep' => array('Routing\\Step','set'),
- 'getStep' => array('Routing\\Step','get'),
- 'config' => array('Config\\Load','get'),
- 'project' => array('Config\\Project','load'),
- 'debug' => array('Debug\\Process','wait'),
- 'view' => array('Template\\View','get'),
- 'render' => array('Template\\View','html'),
-
- 'token' => array('Security\\Api','get'),
- 'login' => array('Security\\Api','login'),
- 'rule' => array('Security\\String','rule'),
- 'idtostr' => array('Security\\String','idtostr'),
- 'strtoid' => array('Security\\String','strtoid'),
- 'tcp' => array('Server\\Swoole','getInstance'),
- );
-
- static public $markdown;
- static public $save;
- /**
- * 设置循环里每行不同的值
- * @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;
- }
- }
- /**
- * 除了最后一条
- * @param string $value
- * @param string $index
- * @param string $total
- *
- * @return array
- */
- static public function other($value, $index, $total)
- {
- if($index != $total)
- {
- return $value;
- }
- }
- /**
- * 对多维数组进行排序
- * @param string $array
- * @param string $field
- * @param string $desc
- *
- * @return array
- */
- private function sort(&$array, $field, $desc = false)
- {
- $fieldArr = array();
- foreach ($array as $k => $v)
- {
- $fieldArr[$k] = $v[$field];
- }
- $sort = $desc == false ? SORT_ASC : SORT_DESC;
- array_multisort($fieldArr, $sort, $array);
- }
- /**
- * 生成html a标记 以后统一修改
- * @param string $name
- * @param string $link
- * @param string $target
- *
- * @return array
- */
- private function a($name, $link, $target = '_self')
- {
- return '<a href="'.Dever::url($link).'" target="'.$target.'">'.$name.'</a>';
- }
- /**
- * 生成html img标记 以后统一修改
- * @param string $link
- * @param string $target
- *
- * @return array
- */
- private function img($link, $target = '_self')
- {
- return Dever::a('<img src="'.$link.'" />', $link, $target);
- }
- /**
- * 获取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 $data
- * @param string $class
- *
- * @return array
- */
- static public function table($data, $class = '', $num = 1)
- {
- if($class)
- {
- $style = 'class='.$class.'';
- }
- else
- {
- $style = 'border=1 width=100% height=100%';
- }
-
- $html = '<table '.$style.'>';
-
- foreach($data as $k => $v)
- {
- if(is_array($v) && $num == 2)
- {
- $tbody = array($k);
- foreach($v as $j)
- {
- array_push($tbody, $j);
- }
- $html .= self::tbody($tbody);
- }
- else
- {
- if(is_array($v))
- {
- $v = self::table($v, $class);
- //$v = var_export($v, true);
- }
- if(is_numeric($k))
- {
- $html .= self::tbody(array($v));
- }
- else
- {
- $html .= self::tbody(array($k, $v));
- }
- }
- }
-
- $html .= '</table>';
- return $html;
- }
-
- /**
- * 生成tbody
- * @param string $data
- * @param string $class
- *
- * @return array
- */
- static public function tbody($data)
- {
- $html = '<tr>';
- foreach($data as $k => $v)
- {
- if($k == 0)
- {
- $html .= '<td style=width:30%;line-height:1.75;font-weight:bold>'.$v.'</td>';
- }
- elseif($k == 1)
- {
- $html .= '<td style=width:30%;word-break:break-all;word-wrap:break-word;>'.$v.'</td>';
- }
- else
- {
- $html .= '<td style=word-break:break-all;word-wrap:break-word;>'.$v.'</td>';
- }
- }
-
- $html .= '</tr>';
-
- return $html;
- }
- /**
- * 判断是否包含
- * @param string $value
- * @param string $source
- *
- * @return array
- */
- static public function in($value, $index)
- {
- $key = $value . '_' . $index;
- if(isset(self::$global['in'][$key]))
- {
- return self::$global['in'][$key];
- }
- if(is_array($index))
- {
- $index = implode(',', $index);
- }
- $index .= ',';
- if(strpos($value, ','))
- {
- $temp = explode(',', $value);
- foreach($temp as $k => $v)
- {
- $state = self::in($v, $index);
- if($state == true)
- {
- break;
- }
- }
- return self::$global['in'][$key] = $state;
- }
- else
- {
- if(strpos($index, $value . ',') !== false)
- {
- return self::$global['in'][$key] = true;
- }
- return self::$global['in'][$key] = false;
- }
- }
-
- /**
- * pic
- * @param string $file
- * @param string $name
- *
- * @return array
- */
- static public function pic($file, $name = false)
- {
- if(strpos($file, ',') !== false)
- {
- $temp = explode(',', $file);
- $file = array();
- foreach($temp as $k => $v)
- {
- $file[$k] = self::pic($v, $name);
- }
- return implode(',', $file);
- }
- if($name && strpos($file, '_') !== false)
- {
- $temp = explode('_', $file);
- $file = $temp[0] . '_' . $name;
- }
- # 替换host
- if($file && strpos($file, 'http://') === false)
- {
- $host = Dever::$global['host']['image'];
- if(is_array(Dever::$global['host']['image']))
- {
- $index = array_rand(Dever::$global['host']['image']);
- $host = Dever::$global['host']['image'][$index];
- }
- $file = $host . $file;
- }
- return $file;
- }
- /**
- * 获取链接
- * @param string $url
- * @param array $param
- *
- * @return string
- */
- static public function link($url, $param = array(), $project = 'main')
- {
- if($param)
- {
- $send = array();
- foreach($param as $k => $v)
- {
- if(is_string($k) && $v)
- {
- $send[] = $k.'=' . $v;
- }
- elseif($v && $value = Dever::input($v))
- {
- $send[] = $v.'=' . $value;
- }
- }
- if($send)
- {
- $url .= '?' . implode('&', $send);
- }
- }
- return Dever::url($url, $project);
- }
- /**
- * str_explode
- * @param string $value
- * @param string $index
- *
- * @return array
- */
- static function str_explode($value, $num = 2)
- {
- $len = strlen($value);
- $result = array();
- for($i = 0; $i < $len; $i=$i+$num)
- {
- $result[$i/$num] = substr($value, $i, $num);
- }
- return $result;
- }
-
- /**
- * 获取_param
- * @param string $value
- * @param string $index
- *
- * @return array
- */
- static public function param($name)
- {
- if(isset(Dever::$global['base']['_param']))
- {
- if(isset(Dever::$global['base']['_param']['add_' . $name]))
- {
- return Dever::$global['base']['_param']['add_' . $name];
- }
-
- if(isset(Dever::$global['base']['_param']['set_' . $name]))
- {
- return Dever::$global['base']['_param']['set_' . $name];
- }
- }
- return false;
- }
- /**
- * 获取ip
- *
- * @return string
- */
- static public function ip()
- {
- $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'];
- }
- /**
- * kill
- *
- * @return string
- */
- static public function kill($commend)
- {
- $shell = "ps -ef | grep ".$commend." | grep -v grep | awk '{print $2}' | xargs kill -9";
- self::run($shell, '');
- }
- /**
- * 运维程序
- *
- * @return string
- */
- static public function daemon($interface, $project = false, $file = 'index.php', $state = false)
- {
- if(strpos($interface, 'http://') !== false)
- {
- return self::run('curl "' . $interface . '"');
- }
- $project = $project ? $project : DEVER_APP_NAME;
- $path = self::load('manage/project.setup', $project);
- if(strpos($path, 'http://') !== false)
- {
- //self::curl($path . $interface);
- return self::run('curl "' . $path . $interface . '"');
- }
- else
- {
- # ?和&无法解析
- $interface = str_replace(array('?', '&'), array('__', '^'), $interface);
- return self::run('php ' . $path . $file . ' -send ' . $interface, $state);
- }
- }
-
- /**
- * shell
- *
- * @return string
- */
- static public function run($shell, $state = false, $method = 'system')
- {
- if($state === false)
- {
- $state = ' > /dev/null &';
- }
- $method($shell . $state, $result);
-
- return $result;
- }
- /**
- * process
- *
- * @return string
- */
- static public function process($commend, $count = false)
- {
- $shell = "ps -ef | grep ".$commend." | grep -v grep";
- if($count)
- {
- $shell .= ' | grep "master" | wc -l';
- }
- $result = self::run($shell, '', 'system');
- if($result != 1)
- {
- return $result;
- }
- return false;
- }
- static public function mdate($num, $type = 1)
- {
- $num = time() - $num;
-
- if($num <= 0)
- {
- if($type == 2)
- {
- return '1秒前';
- }
- else
- {
- return '1S';
- }
- }
- $config = array
- (
- array(31536000, 'Y', '年'),
- array(2592000, 'T', '个月'),
- array(604800, 'W', '星期'),
- array(86400, 'D', '天'),
- array(3600, 'H', '小时'),
- array(60, 'M', '分钟'),
- array(1, 'S', '秒')
- );
- if($type == 2)
- {
- foreach($config as $k => $v)
- {
- $value = intval($num/$v[0]);
-
- if($value != 0)
- {
- return $value . $v[2] . '前';
- }
- }
-
- return '';
- }
- else
- {
- $result = '';
-
- foreach($config as $k => $v)
- {
- if($num > $v[0])
- {
- $value = intval($num/$v[0]);
- $num = $num - $v[0]*$value;
- $result .= $value . $v[1] . ' ';
- }
- }
-
- return $result;
- }
- }
- /**
- * 加入到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 = Dever::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'];
- Dever::load('manage/cron-update', $update);
- }
- }
- else
- {
- $update = array();
- $update['add_name'] = $name;
- $update['add_ldate'] = $ldate;
- $update['add_interface'] = $interface;
- $update['add_time'] = $time;
- $update['add_project'] = $project;
- Dever::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;
- }
- /**
- * strlen
- * @param string $string
- *
- * @return array
- */
- static public function strlen($string)
- {
- preg_match_all("/./us", $string, $match);
-
- return count($match[0]);
- }
- /**
- * 执行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];
- }
- }
- /**
- * 注册dever类库里的常用类,方便使用
- * @param string $name
- * @param array $param
- *
- * @return mixed
- */
- static public function __callStatic($name, $param = array())
- {
- if(isset(self::$register[$name]))
- {
- $class = 'Dever\\' . self::$register[$name][0];
- $method = self::$register[$name][1];
- return call_user_func_array(array($class, $method), $param);
- }
- }
-
- static public function curl($url, $param = false, $type = '', $ip = '', $refer = '')
- {
- //初始化
- $ch = curl_init();
- //设置选项,包括URL
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- if($ip)
- {
- $headers['CLIENT-IP'] = $ip;
- $headers['X-FORWARDED-FOR'] = $ip;
- $headerArr = array();
- foreach($headers as $n => $v)
- {
- $headerArr[] = $n .':' . $v;
- }
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
- }
- if($refer)
- {
- curl_setopt($ch, CURLOPT_REFERER, $refer);
- }
- if($ip || $refer)
- {
- curl_setopt($ch, CURLOPT_HEADER, 1);
- }
- else
- {
- 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_numeric($v)) return $v;
- 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;
- }
-
- static function proxy($method = false, $param = false)
- {
- if($method)
- {
- if(isset(Dever::$global['host']['proxy']) && Dever::$global['host']['proxy'])
- {
- $method = urlencode($method);
- return Dever::url(Dever::$global['host']['proxy'] . 'proxy_method=' . $method . '&' . $param);
- }
- return Dever::url($method . '?' . $param);
- }
- $data = Dever::input();
-
- foreach($data as $k => $v)
- {
- Dever::setInput($k, $v);
- }
-
- return Dever::load(urldecode($data['proxy_method']), array('CHECK' => true));
- }
-
- static public function script()
- {
- $script = 'var config={};config.host="'.Dever::url('').'";config.type="'.Dever\Routing\Uri::$type.'";config.current="'.Dever::url().'";config.upload="'.Dever::$global['host']['upload'].'";config.assets="'.Dever::$global['host']['core'].'";';
- if(isset(Dever::$global['host']['proxy']))
- {
- $script .= 'config.proxy="'.Dever::$global['host']['proxy'].'";';
- }
- if(isset(Dever::$global['host']['manage']))
- {
- $script .= 'config.manage_assets="'.Dever::$global['host']['manage'].'";';
- }
- if(isset(Dever::$global['host']['workspace']))
- {
- $script .= 'config.workspace="'.Dever::$global['host']['workspace'].'";';
- }
- if(isset(Dever::$global['base']['layout']))
- {
- $script .= 'config.layout = "'.Dever::$global['base']['layout'].'";$(document).ready(function()
- {
- $(document).pjax("a", "'.Dever::$global['base']['layout'].'");
- $(document).on("submit", "#form1", function (event) {event.preventDefault();$.pjax.submit(event, "'.Dever::$global['base']['layout'].'", {"push": true, "replace": false, timeout:6000, "scrollTo": 0, maxCacheLength: 0});});
- $(document).on("pjax:start", function()
- {
- NProgress.start();
- });
- $(document).on("pjax:end", function()
- {
- NProgress.done();
- });
- });';
- }
- return $script;
- }
- /**
- * 获取文件后缀
- * @param string $file
- *
- * @return string
- */
- static public function ext($file)
- {
- return pathinfo($file, PATHINFO_EXTENSION);
- }
-
- /**
- * markdown解析
- * @param string $value
- *
- * @return string
- */
- static public function markdown($value)
- {
- self::$markdown = self::$markdown ? self::$markdown : new \Parsedown();
-
- # 一个回车就换行
- self::$markdown->setBreaksEnabled(true);
-
- # 过滤掉所有特殊代码
- return self::$markdown->text($value);
- }
-
- /**
- * setup 安装引导程序
- * @param string $value
- *
- * @return string
- */
- static public function setup()
- {
- $host = DEVER_APP_HOST;
-
- $path = DEVER_APP_PATH . '../';
-
- $dir = scandir($path);
-
- foreach($dir as $k => $v)
- {
- if($v != '.' && $v != '..' && is_dir($path . $v))
- {
- $url = str_replace(array('www', 'main'), $v, $host);
-
- Dever::curl($url);
- echo $url . ' 安装成功!<br />' . "\r\n";
- }
- }
-
- return '感谢您使用Dever!';
- }
- /**
- * cache 缓存功能
- * @param string $key
- * @param array $data
- * @param int $expire
- * @param string $type
- *
- * @return mixed
- */
- static public function cache($key = false, $data = false, $expire = 0, $type = 'data')
- {
- $cache = self::$global['cache'];
- if(empty($cache[$type]))
- {
- return;
- }
- //$handle =& \Dever\Cache\Handle::getInstance($type, $cache[$type]);
- $handle = \Dever\Cache\Handle::getInstance($type, $cache[$type]);
- if(is_string($data) && $data == 'delete')
- {
- return $handle->delete($key);
- }
- elseif($data)
- {
- return $handle->set($key, $data, $expire);
- }
- return $handle->get($key);
- }
- /**
- * dyna 动态解析功能
- * @param string $key
- * @param array $data
- *
- * @return mixed
- */
- static public function odyna($key = false, $data = array())
- {
- return (object)self::dyna($key, $data);
- }
- /**
- * dyna 动态解析功能
- * @param string $key
- * @param array $data
- *
- * @return mixed
- */
- static public function dyna($key = false, $data = array())
- {
- if(isset(self::$global['dyna_data'][$key]))
- {
- return self::$global['dyna_data'][$key];
- }
- $config = self::get('dyna');
- if(empty($config[$key]))
- {
- return $key;
- }
- if(!$data)
- {
- return $config[$key];
- }
- if(is_array($config[$key]))
- {
- foreach($config[$key] as $k => $v)
- {
- $v = '$value = "'.$v.'";';
- eval($v);
- if(isset($value))
- {
- $config[$key][$k] = $value;
- }
- }
- }
- else
- {
- $v = '$value = "'.$config[$key].'";';
- eval($v);
- if(isset($value))
- {
- $config[$key] = $value;
- }
- }
- self::$global['dyna_data'][$key] = $config[$key];
-
- return $config[$key];
- }
- /**
- * submit 处理重复提交功能 此处暂时有问题
- * @param string $type
- * @param int $value
- *
- * @return mixed
- */
- static public function submit($type = 'update', $value = 1)
- {
- if(empty(self::$save))
- {
- self::$save = new \Dever\Session\Save(DEVER_APP_NAME, 'cookie');
- }
-
- if($type == 'check')
- {
- $submit = self::$save->get('submit');
- if($submit == 2)
- {
- Dever::abert('请不要重复提交');
- }
- }
- if($value)
- {
- self::$save->add('submit', $value);
- }
- }
- }
|