@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | /** |
96 | 96 | * session管理函数 |
97 | - * @param string|array $name session名称 如果为数组则表示进行session设置 |
|
97 | + * @param string $name session名称 如果为数组则表示进行session设置 |
|
98 | 98 | * @param mixed $value session值 |
99 | 99 | * @return mixed |
100 | 100 | */ |
@@ -407,6 +407,11 @@ discard block |
||
407 | 407 | $value .= ' '; |
408 | 408 | } |
409 | 409 | } |
410 | +/** |
|
411 | + * @param string $name |
|
412 | + * |
|
413 | + * @return string|null |
|
414 | + */ |
|
410 | 415 | function config($name=null,$value=null,$default=null){ |
411 | 416 | $config=\puck\Conf::load(); |
412 | 417 | if ($name===null){ |
@@ -70,15 +70,10 @@ |
||
70 | 70 | |
71 | 71 | |
72 | 72 | /** |
73 | - |
|
74 | 73 | * 数据签名认证 |
75 | - |
|
76 | 74 | * @param array $data 被认证的数据 |
77 | - |
|
78 | 75 | * @return string 签名 |
79 | - |
|
80 | 76 | * @author 麦当苗儿 <[email protected]> |
81 | - |
|
82 | 77 | */ |
83 | 78 | function data_auth_sign($data) { |
84 | 79 | //数据类型检测 |
@@ -35,18 +35,18 @@ discard block |
||
35 | 35 | return $ip[$type]; |
36 | 36 | } |
37 | 37 | //2为直接输出数组 |
38 | -function show_json(array $arr,$type=2) |
|
38 | +function show_json(array $arr, $type=2) |
|
39 | 39 | { |
40 | 40 | |
41 | - if(isset($arr['status']) && $type==2){ |
|
41 | + if (isset($arr['status']) && $type == 2) { |
|
42 | 42 | $ret=$arr; |
43 | 43 | } |
44 | - else{ |
|
45 | - $ret['status'] = $type; |
|
46 | - $ret['data'] = $arr; |
|
44 | + else { |
|
45 | + $ret['status']=$type; |
|
46 | + $ret['data']=$arr; |
|
47 | 47 | } |
48 | 48 | |
49 | - $obj = json_encode($ret); |
|
49 | + $obj=json_encode($ret); |
|
50 | 50 | header('Content-Type: application/json'); |
51 | 51 | echo $obj; |
52 | 52 | exit(); |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | |
55 | 55 | function success($arr) |
56 | 56 | { |
57 | - show_json($arr,1); |
|
57 | + show_json($arr, 1); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function error($arr) |
61 | 61 | { |
62 | - show_json($arr,0); |
|
62 | + show_json($arr, 0); |
|
63 | 63 | } |
64 | -function not_found($str='page not found,that is all we know!'){ |
|
64 | +function not_found($str='page not found,that is all we know!') { |
|
65 | 65 | header('HTTP/1.1 404 Not Found'); |
66 | 66 | header("status: 404 Not Found"); |
67 | 67 | exit($str); |
@@ -82,13 +82,13 @@ discard block |
||
82 | 82 | function data_auth_sign($data) { |
83 | 83 | //数据类型检测 |
84 | 84 | |
85 | - if(!is_array($data)){ |
|
85 | + if (!is_array($data)) { |
|
86 | 86 | |
87 | - $data = (array)$data; |
|
87 | + $data=(array) $data; |
|
88 | 88 | } |
89 | 89 | ksort($data); //排序 |
90 | - $code = http_build_query($data); //url编码并生成query字符串 |
|
91 | - $sign = sha1($code); //生成签名 |
|
90 | + $code=http_build_query($data); //url编码并生成query字符串 |
|
91 | + $sign=sha1($code); //生成签名 |
|
92 | 92 | return $sign; |
93 | 93 | } |
94 | 94 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param mixed $value session值 |
98 | 98 | * @return mixed |
99 | 99 | */ |
100 | -function session($name = '', $value = '') { |
|
100 | +function session($name='', $value='') { |
|
101 | 101 | if (is_array($name)) { |
102 | 102 | |
103 | 103 | if (isset($name['id'])) { |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | session_start(); |
150 | 150 | } elseif ('[destroy]' == $name) { |
151 | 151 | // 销毁session |
152 | - $_SESSION = array(); |
|
152 | + $_SESSION=array(); |
|
153 | 153 | session_unset(); |
154 | 154 | session_destroy(); |
155 | 155 | } elseif ('[regenerate]' == $name) { |
156 | 156 | // 重新生成id |
157 | 157 | session_regenerate_id(); |
158 | 158 | } |
159 | - }else { |
|
159 | + } else { |
|
160 | 160 | if (strpos($name, '.')) { |
161 | - list($name1, $name2) = explode('.', $name); |
|
161 | + list($name1, $name2)=explode('.', $name); |
|
162 | 162 | return isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; |
163 | 163 | } else { |
164 | 164 | return isset($_SESSION[$name]) ? $_SESSION[$name] : null; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | } elseif (is_null($value)) { |
168 | 168 | // 删除session |
169 | 169 | if (strpos($name, '.')) { |
170 | - list($name1, $name2) = explode('.', $name); |
|
170 | + list($name1, $name2)=explode('.', $name); |
|
171 | 171 | unset($_SESSION[$name1][$name2]); |
172 | 172 | } else { |
173 | 173 | unset($_SESSION[$name]); |
@@ -175,30 +175,30 @@ discard block |
||
175 | 175 | } else { |
176 | 176 | // 设置session |
177 | 177 | if (strpos($name, '.')) { |
178 | - list($name1, $name2) = explode('.', $name); |
|
179 | - $_SESSION[$name1][$name2] = $value; |
|
178 | + list($name1, $name2)=explode('.', $name); |
|
179 | + $_SESSION[$name1][$name2]=$value; |
|
180 | 180 | } else { |
181 | - $_SESSION[$name] = $value; |
|
181 | + $_SESSION[$name]=$value; |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | return null; |
185 | 185 | } |
186 | 186 | |
187 | 187 | |
188 | -function admin_is_login(){ |
|
189 | - $user = session('admin_user_auth'); |
|
188 | +function admin_is_login() { |
|
189 | + $user=session('admin_user_auth'); |
|
190 | 190 | if (empty($user)) { |
191 | 191 | return 0; |
192 | 192 | } else { |
193 | 193 | $auth_sign=session('admin_user_auth_sign'); |
194 | - if(data_auth_sign($user)!=$auth_sign){ |
|
194 | + if (data_auth_sign($user) != $auth_sign) { |
|
195 | 195 | return 0; |
196 | 196 | } |
197 | 197 | return $user['uid']; |
198 | 198 | } |
199 | 199 | } |
200 | -function json($str){ |
|
201 | - $obj = json_encode($str,JSON_UNESCAPED_UNICODE); |
|
200 | +function json($str) { |
|
201 | + $obj=json_encode($str, JSON_UNESCAPED_UNICODE); |
|
202 | 202 | header('Content-Type: application/json'); |
203 | 203 | echo $obj; |
204 | 204 | } |
@@ -210,20 +210,20 @@ discard block |
||
210 | 210 | * @param integer $flags htmlspecialchars flags |
211 | 211 | * @return void|string |
212 | 212 | */ |
213 | -function dump($var, $echo = true, $label = null, $flags = ENT_SUBSTITUTE) |
|
213 | +function dump($var, $echo=true, $label=null, $flags=ENT_SUBSTITUTE) |
|
214 | 214 | { |
215 | - $label = (null === $label) ? '' : rtrim($label) . ':'; |
|
215 | + $label=(null === $label) ? '' : rtrim($label).':'; |
|
216 | 216 | ob_start(); |
217 | 217 | var_dump($var); |
218 | - $output = ob_get_clean(); |
|
219 | - $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); |
|
218 | + $output=ob_get_clean(); |
|
219 | + $output=preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); |
|
220 | 220 | if (IS_CLI) { |
221 | - $output = PHP_EOL . $label . $output . PHP_EOL; |
|
221 | + $output=PHP_EOL.$label.$output.PHP_EOL; |
|
222 | 222 | } else { |
223 | 223 | if (!extension_loaded('xdebug')) { |
224 | - $output = htmlspecialchars($output, $flags); |
|
224 | + $output=htmlspecialchars($output, $flags); |
|
225 | 225 | } |
226 | - $output = '<pre>' . $label . $output . '</pre>'; |
|
226 | + $output='<pre>'.$label.$output.'</pre>'; |
|
227 | 227 | } |
228 | 228 | if ($echo) { |
229 | 229 | echo($output); |
@@ -248,99 +248,99 @@ discard block |
||
248 | 248 | * @param mixed $datas 要获取的额外数据源 |
249 | 249 | * @return mixed |
250 | 250 | */ |
251 | -function I($name, $default = '', $filter = null, $datas = null) |
|
251 | +function I($name, $default='', $filter=null, $datas=null) |
|
252 | 252 | { |
253 | - static $_PUT = null; |
|
253 | + static $_PUT=null; |
|
254 | 254 | if (strpos($name, '/')) { |
255 | 255 | // 指定修饰符 |
256 | - list($name, $type) = explode('/', $name, 2); |
|
257 | - } else{ |
|
256 | + list($name, $type)=explode('/', $name, 2); |
|
257 | + } else { |
|
258 | 258 | // 默认强制转换为字符串 |
259 | - $type = 's'; |
|
259 | + $type='s'; |
|
260 | 260 | } |
261 | 261 | if (strpos($name, '.')) { |
262 | 262 | // 指定参数来源 |
263 | - list($method, $name) = explode('.', $name, 2); |
|
263 | + list($method, $name)=explode('.', $name, 2); |
|
264 | 264 | } else { |
265 | 265 | // 默认为自动判断 |
266 | - $method = 'param'; |
|
266 | + $method='param'; |
|
267 | 267 | } |
268 | 268 | switch (strtolower($method)) { |
269 | 269 | case 'get': |
270 | - $input = &$_GET; |
|
270 | + $input=&$_GET; |
|
271 | 271 | break; |
272 | 272 | case 'post': |
273 | - $input = &$_POST; |
|
273 | + $input=&$_POST; |
|
274 | 274 | break; |
275 | 275 | case 'put': |
276 | 276 | if (is_null($_PUT)) { |
277 | 277 | parse_str(file_get_contents('php://input'), $_PUT); |
278 | 278 | } |
279 | - $input = $_PUT; |
|
279 | + $input=$_PUT; |
|
280 | 280 | break; |
281 | 281 | case 'param': |
282 | 282 | switch ($_SERVER['REQUEST_METHOD']) { |
283 | 283 | case 'POST': |
284 | - $input = $_POST; |
|
284 | + $input=$_POST; |
|
285 | 285 | break; |
286 | 286 | case 'PUT': |
287 | 287 | if (is_null($_PUT)) { |
288 | 288 | parse_str(file_get_contents('php://input'), $_PUT); |
289 | 289 | } |
290 | - $input = $_PUT; |
|
290 | + $input=$_PUT; |
|
291 | 291 | break; |
292 | 292 | default: |
293 | - $input = $_GET; |
|
293 | + $input=$_GET; |
|
294 | 294 | } |
295 | 295 | break; |
296 | 296 | case 'path': |
297 | - $input = array(); |
|
297 | + $input=array(); |
|
298 | 298 | if (!empty($_SERVER['PATH_INFO'])) { |
299 | - $depr = C('URL_PATHINFO_DEPR'); |
|
300 | - $input = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); |
|
299 | + $depr=C('URL_PATHINFO_DEPR'); |
|
300 | + $input=explode($depr, trim($_SERVER['PATH_INFO'], $depr)); |
|
301 | 301 | } |
302 | 302 | break; |
303 | 303 | case 'request': |
304 | - $input = &$_REQUEST; |
|
304 | + $input=&$_REQUEST; |
|
305 | 305 | break; |
306 | 306 | case 'session': |
307 | - $input = &$_SESSION; |
|
307 | + $input=&$_SESSION; |
|
308 | 308 | break; |
309 | 309 | case 'cookie': |
310 | - $input = &$_COOKIE; |
|
310 | + $input=&$_COOKIE; |
|
311 | 311 | break; |
312 | 312 | case 'server': |
313 | - $input = &$_SERVER; |
|
313 | + $input=&$_SERVER; |
|
314 | 314 | break; |
315 | 315 | case 'globals': |
316 | - $input = &$GLOBALS; |
|
316 | + $input=&$GLOBALS; |
|
317 | 317 | break; |
318 | 318 | case 'data': |
319 | - $input = &$datas; |
|
319 | + $input=&$datas; |
|
320 | 320 | break; |
321 | 321 | default: |
322 | 322 | return null; |
323 | 323 | } |
324 | 324 | if ('' == $name) { |
325 | 325 | // 获取全部变量 |
326 | - $data = $input; |
|
327 | - $filters = isset($filter) ? $filter : 'htmlspecialchars'; |
|
326 | + $data=$input; |
|
327 | + $filters=isset($filter) ? $filter : 'htmlspecialchars'; |
|
328 | 328 | if ($filters) { |
329 | 329 | if (is_string($filters)) { |
330 | - $filters = explode(',', $filters); |
|
330 | + $filters=explode(',', $filters); |
|
331 | 331 | } |
332 | - else if (is_array($filters)){ |
|
332 | + else if (is_array($filters)) { |
|
333 | 333 | foreach ($filters as $filter) { |
334 | - $data = array_map_recursive($filter, $data); // 参数过滤 |
|
334 | + $data=array_map_recursive($filter, $data); // 参数过滤 |
|
335 | 335 | } |
336 | - }else{ |
|
336 | + } else { |
|
337 | 337 | throw new \RuntimeException('$filters must be an array or string.'); |
338 | 338 | } |
339 | 339 | } |
340 | 340 | } elseif (isset($input[$name])) { |
341 | 341 | // 取值操作 |
342 | - $data = $input[$name]; |
|
343 | - $filters = isset($filter) ? $filter : 'htmlspecialchars'; |
|
342 | + $data=$input[$name]; |
|
343 | + $filters=isset($filter) ? $filter : 'htmlspecialchars'; |
|
344 | 344 | if ($filters) { |
345 | 345 | if (is_string($filters)) { |
346 | 346 | if (0 === strpos($filters, '/')) { |
@@ -349,19 +349,19 @@ discard block |
||
349 | 349 | return isset($default) ? $default : null; |
350 | 350 | } |
351 | 351 | } else { |
352 | - $filters = explode(',', $filters); |
|
352 | + $filters=explode(',', $filters); |
|
353 | 353 | } |
354 | 354 | } elseif (is_int($filters)) { |
355 | - $filters = array($filters); |
|
355 | + $filters=array($filters); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | if (is_array($filters)) { |
359 | 359 | foreach ($filters as $filter) { |
360 | - $filter = trim($filter); |
|
360 | + $filter=trim($filter); |
|
361 | 361 | if (function_exists($filter)) { |
362 | - $data = is_array($data) ? array_map_recursive($filter, $data) : $filter($data); // 参数过滤 |
|
362 | + $data=is_array($data) ? array_map_recursive($filter, $data) : $filter($data); // 参数过滤 |
|
363 | 363 | } else { |
364 | - $data = filter_var($data, is_int($filter) ? $filter : filter_id($filter)); |
|
364 | + $data=filter_var($data, is_int($filter) ? $filter : filter_id($filter)); |
|
365 | 365 | if (false === $data) { |
366 | 366 | return isset($default) ? $default : null; |
367 | 367 | } |
@@ -372,34 +372,34 @@ discard block |
||
372 | 372 | if (!empty($type)) { |
373 | 373 | switch (strtolower($type)) { |
374 | 374 | case 'a': // 数组 |
375 | - $data = (array) $data; |
|
375 | + $data=(array) $data; |
|
376 | 376 | break; |
377 | 377 | case 'd': // 数字 |
378 | - $data = (int) $data; |
|
378 | + $data=(int) $data; |
|
379 | 379 | break; |
380 | 380 | case 'f': // 浮点 |
381 | - $data = (float) $data; |
|
381 | + $data=(float) $data; |
|
382 | 382 | break; |
383 | 383 | case 'b': // 布尔 |
384 | - $data = (boolean) $data; |
|
384 | + $data=(boolean) $data; |
|
385 | 385 | break; |
386 | 386 | case 's':// 字符串 |
387 | 387 | default: |
388 | - $data = (string) $data; |
|
388 | + $data=(string) $data; |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | } else { |
392 | 392 | // 变量默认值 |
393 | - $data = isset($default) ? $default : null; |
|
393 | + $data=isset($default) ? $default : null; |
|
394 | 394 | } |
395 | 395 | is_array($data) && array_walk_recursive($data, 'think_filter'); |
396 | 396 | return $data; |
397 | 397 | } |
398 | 398 | function array_map_recursive($filter, $data) |
399 | 399 | { |
400 | - $result = array(); |
|
400 | + $result=array(); |
|
401 | 401 | foreach ($data as $key => $val) { |
402 | - $result[$key] = is_array($val) |
|
402 | + $result[$key]=is_array($val) |
|
403 | 403 | ? array_map_recursive($filter, $val) |
404 | 404 | : call_user_func($filter, $val); |
405 | 405 | } |
@@ -411,18 +411,18 @@ discard block |
||
411 | 411 | |
412 | 412 | // 过滤查询特殊字符 |
413 | 413 | if (preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) { |
414 | - $value .= ' '; |
|
414 | + $value.=' '; |
|
415 | 415 | } |
416 | 416 | } |
417 | -function config($name=null,$value=null,$default=null){ |
|
417 | +function config($name=null, $value=null, $default=null) { |
|
418 | 418 | $config=\puck\Conf::load(); |
419 | - if ($name===null){ |
|
419 | + if ($name === null) { |
|
420 | 420 | return $config->all(); |
421 | 421 | } |
422 | - if ($value===null){ |
|
423 | - return $config->get($name,$default); |
|
422 | + if ($value === null) { |
|
423 | + return $config->get($name, $default); |
|
424 | 424 | } |
425 | - $config->set($name,$value); |
|
425 | + $config->set($name, $value); |
|
426 | 426 | } |
427 | 427 | /** |
428 | 428 | * 字符串命名风格转换 |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | * @param integer $type 转换类型 |
432 | 432 | * @return string |
433 | 433 | */ |
434 | -function parse_name($name, $type = 0) { |
|
434 | +function parse_name($name, $type=0) { |
|
435 | 435 | if ($type) { |
436 | - return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {return strtoupper($match[1]);}, $name)); |
|
436 | + return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function($match) {return strtoupper($match[1]); }, $name)); |
|
437 | 437 | } else { |
438 | 438 | return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); |
439 | 439 | } |
@@ -40,8 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | if(isset($arr['status']) && $type==2){ |
42 | 42 | $ret=$arr; |
43 | - } |
|
44 | - else{ |
|
43 | + } else{ |
|
45 | 44 | $ret['status'] = $type; |
46 | 45 | $ret['data'] = $arr; |
47 | 46 | } |
@@ -156,7 +155,7 @@ discard block |
||
156 | 155 | // 重新生成id |
157 | 156 | session_regenerate_id(); |
158 | 157 | } |
159 | - }else { |
|
158 | + } else { |
|
160 | 159 | if (strpos($name, '.')) { |
161 | 160 | list($name1, $name2) = explode('.', $name); |
162 | 161 | return isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; |
@@ -328,12 +327,11 @@ discard block |
||
328 | 327 | if ($filters) { |
329 | 328 | if (is_string($filters)) { |
330 | 329 | $filters = explode(',', $filters); |
331 | - } |
|
332 | - else if (is_array($filters)){ |
|
330 | + } else if (is_array($filters)){ |
|
333 | 331 | foreach ($filters as $filter) { |
334 | 332 | $data = array_map_recursive($filter, $data); // 参数过滤 |
335 | 333 | } |
336 | - }else{ |
|
334 | + } else{ |
|
337 | 335 | throw new \RuntimeException('$filters must be an array or string.'); |
338 | 336 | } |
339 | 337 | } |
@@ -139,6 +139,10 @@ |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | //随机重复一个字符 |
142 | + |
|
143 | + /** |
|
144 | + * @param string $str |
|
145 | + */ |
|
142 | 146 | function setRepeat($str) { |
143 | 147 | $len = iconv_strlen( $str, 'UTF-8' ); |
144 | 148 | $action = 0; |
@@ -1,195 +1,195 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace puck\helpers; |
3 | 3 | class Chaos { |
4 | - public $GbToBigArray; |
|
5 | - public $_pinyin; |
|
6 | - public $string; |
|
7 | - public $url=''; |
|
8 | - public $msg=''; |
|
9 | - public $action; |
|
10 | - private $prefix; |
|
4 | + public $GbToBigArray; |
|
5 | + public $_pinyin; |
|
6 | + public $string; |
|
7 | + public $url=''; |
|
8 | + public $msg=''; |
|
9 | + public $action; |
|
10 | + private $prefix; |
|
11 | 11 | |
12 | 12 | function __construct() { |
13 | - $this->_pinyin=new PinYin(); |
|
14 | - } |
|
13 | + $this->_pinyin=new PinYin(); |
|
14 | + } |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * @param array $prefix |
18 | 18 | */ |
19 | 19 | public function addPrefix(array $prefix) { |
20 | 20 | $this->prefix=$prefix[array_rand($prefix)]; |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | 23 | public function clearPrefix() { |
24 | 24 | $this->prefix=''; |
25 | - } |
|
25 | + } |
|
26 | 26 | public function get($str) { |
27 | 27 | $this->cutting($str); |
28 | 28 | $this->convert(); |
29 | 29 | $this->clearPrefix(); |
30 | 30 | return $this->msg; |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - //分离URL |
|
34 | - private function cutting($str){ |
|
33 | + //分离URL |
|
34 | + private function cutting($str){ |
|
35 | 35 | |
36 | - if(preg_match("@(http://[^\\s]+)@i", $str, $result)) { |
|
37 | - $this->url = $result[1]; |
|
38 | - $this->msg = $str = str_replace($this->url, '%%%%', $str); |
|
39 | - } else { |
|
40 | - $this->msg = $str; |
|
41 | - } |
|
42 | - } |
|
36 | + if(preg_match("@(http://[^\\s]+)@i", $str, $result)) { |
|
37 | + $this->url = $result[1]; |
|
38 | + $this->msg = $str = str_replace($this->url, '%%%%', $str); |
|
39 | + } else { |
|
40 | + $this->msg = $str; |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - private function convert( $method = 'msg' ){ |
|
47 | - if( $method == 'msg' || $method == 'all') { |
|
48 | - $this->msg = $this->setPinyin($this->msg); |
|
49 | - $this->msg = $this->setRepeat($this->msg); |
|
50 | - //$this->msg = $this->GbToBig($this->msg); |
|
51 | - $this->msg = $this->setBlankness($this->msg); |
|
46 | + private function convert( $method = 'msg' ){ |
|
47 | + if( $method == 'msg' || $method == 'all') { |
|
48 | + $this->msg = $this->setPinyin($this->msg); |
|
49 | + $this->msg = $this->setRepeat($this->msg); |
|
50 | + //$this->msg = $this->GbToBig($this->msg); |
|
51 | + $this->msg = $this->setBlankness($this->msg); |
|
52 | 52 | |
53 | - } |
|
54 | - if( $method == 'url' || $method == 'all') { |
|
55 | - $this->url = $this->setChacha($this->url); |
|
56 | - } |
|
57 | - $this->msg=$this->prefix.str_replace( '%%%%', $this->url, $this->msg); |
|
58 | - } |
|
53 | + } |
|
54 | + if( $method == 'url' || $method == 'all') { |
|
55 | + $this->url = $this->setChacha($this->url); |
|
56 | + } |
|
57 | + $this->msg=$this->prefix.str_replace( '%%%%', $this->url, $this->msg); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param string $url |
|
62 | - */ |
|
63 | - function setChacha($url ){ |
|
64 | - $url = strtolower($url); |
|
65 | - $arr = array( |
|
66 | - 'a' => array('a','A','a','A','Α','А','α'), |
|
67 | - 'b' => array('b','B','b','B','Β','В','Ь'), |
|
68 | - 'c' => array('c','C','c','C','С','с'), |
|
69 | - 'd' => array('d','D','d','D'), |
|
70 | - 'e' => array('e','E','e','E','Ε','Е','е'), |
|
71 | - 'f' => array('f','F','f','F'), |
|
72 | - 'g' => array('g','G','g','G'), |
|
73 | - 'h' => array('h','H','h','H','Η','Н','н'), |
|
74 | - 'i' => array('i','I','i','I','Ι','Ⅰ'), |
|
75 | - 'j' => array('j','J','j','J'), |
|
76 | - 'k' => array('k','K','k','K','Κ','κ','к','К'), |
|
77 | - 'l' => array('l','L','l','L','︱','︳','|'), |
|
78 | - 'm' => array('m','M','m','M','Μ','М','м'), |
|
79 | - 'n' => array('n','N','n','N','Ν','∩'), |
|
80 | - 'o' => array('o','O','o','O','Ο','О'), |
|
81 | - 'p' => array('p','P','p','P','Ρ','Р','р'), |
|
82 | - 'q' => array('q','Q','q','Q'), |
|
83 | - 'r' => array('r','R','r','R'), |
|
84 | - 's' => array('s','S','s','S'), |
|
85 | - 't' => array('t','T','t','T','Τ','Т','ㄒ'), |
|
86 | - 'u' => array('u','U','u','U','∪'), |
|
87 | - 'v' => array('v','V','v','V','∨','ν'), |
|
88 | - 'w' => array('w','W','w','W'), |
|
89 | - 'x' => array('x','X','x','X','Χ','χ','Х','х','Ⅹ','×'), |
|
90 | - 'y' => array('y','Y','y','Y','У'), |
|
91 | - 'z' => array('z','Z','z','Z','Ζ'), |
|
60 | + /** |
|
61 | + * @param string $url |
|
62 | + */ |
|
63 | + function setChacha($url ){ |
|
64 | + $url = strtolower($url); |
|
65 | + $arr = array( |
|
66 | + 'a' => array('a','A','a','A','Α','А','α'), |
|
67 | + 'b' => array('b','B','b','B','Β','В','Ь'), |
|
68 | + 'c' => array('c','C','c','C','С','с'), |
|
69 | + 'd' => array('d','D','d','D'), |
|
70 | + 'e' => array('e','E','e','E','Ε','Е','е'), |
|
71 | + 'f' => array('f','F','f','F'), |
|
72 | + 'g' => array('g','G','g','G'), |
|
73 | + 'h' => array('h','H','h','H','Η','Н','н'), |
|
74 | + 'i' => array('i','I','i','I','Ι','Ⅰ'), |
|
75 | + 'j' => array('j','J','j','J'), |
|
76 | + 'k' => array('k','K','k','K','Κ','κ','к','К'), |
|
77 | + 'l' => array('l','L','l','L','︱','︳','|'), |
|
78 | + 'm' => array('m','M','m','M','Μ','М','м'), |
|
79 | + 'n' => array('n','N','n','N','Ν','∩'), |
|
80 | + 'o' => array('o','O','o','O','Ο','О'), |
|
81 | + 'p' => array('p','P','p','P','Ρ','Р','р'), |
|
82 | + 'q' => array('q','Q','q','Q'), |
|
83 | + 'r' => array('r','R','r','R'), |
|
84 | + 's' => array('s','S','s','S'), |
|
85 | + 't' => array('t','T','t','T','Τ','Т','ㄒ'), |
|
86 | + 'u' => array('u','U','u','U','∪'), |
|
87 | + 'v' => array('v','V','v','V','∨','ν'), |
|
88 | + 'w' => array('w','W','w','W'), |
|
89 | + 'x' => array('x','X','x','X','Χ','χ','Х','х','Ⅹ','×'), |
|
90 | + 'y' => array('y','Y','y','Y','У'), |
|
91 | + 'z' => array('z','Z','z','Z','Ζ'), |
|
92 | 92 | |
93 | - '1' => array('1','1'), |
|
94 | - '2' => array('2','2'), |
|
95 | - '3' => array('3','3'), |
|
96 | - '4' => array('4','4'), |
|
97 | - '5' => array('5','5'), |
|
98 | - '6' => array('6','6'), |
|
99 | - '7' => array('7','7'), |
|
100 | - '8' => array('8','8'), |
|
101 | - '9' => array('9','9'), |
|
102 | - '0' => array('0','0'), |
|
93 | + '1' => array('1','1'), |
|
94 | + '2' => array('2','2'), |
|
95 | + '3' => array('3','3'), |
|
96 | + '4' => array('4','4'), |
|
97 | + '5' => array('5','5'), |
|
98 | + '6' => array('6','6'), |
|
99 | + '7' => array('7','7'), |
|
100 | + '8' => array('8','8'), |
|
101 | + '9' => array('9','9'), |
|
102 | + '0' => array('0','0'), |
|
103 | 103 | |
104 | - ':' => array(':',':','∶'), |
|
105 | - '/' => array('/','/'), |
|
106 | - '.' => array('。','·','.','、','﹒',',','丶') |
|
104 | + ':' => array(':',':','∶'), |
|
105 | + '/' => array('/','/'), |
|
106 | + '.' => array('。','·','.','、','﹒',',','丶') |
|
107 | 107 | |
108 | - ); |
|
109 | - $len = strlen( $url ); |
|
110 | - $temp = "\n\n"; |
|
111 | - for( $i=0; $i<$len; $i++){ |
|
112 | - $t_str = substr( $url, $i, 1 ); |
|
113 | - $sj = mt_rand( 0, count($arr[$t_str])-1 ); |
|
114 | - $temp .= $arr[$t_str][$sj]; |
|
115 | - } |
|
116 | - return $temp; |
|
117 | - } |
|
108 | + ); |
|
109 | + $len = strlen( $url ); |
|
110 | + $temp = "\n\n"; |
|
111 | + for( $i=0; $i<$len; $i++){ |
|
112 | + $t_str = substr( $url, $i, 1 ); |
|
113 | + $sj = mt_rand( 0, count($arr[$t_str])-1 ); |
|
114 | + $temp .= $arr[$t_str][$sj]; |
|
115 | + } |
|
116 | + return $temp; |
|
117 | + } |
|
118 | 118 | |
119 | - //随机把一个字符转为拼音 |
|
119 | + //随机把一个字符转为拼音 |
|
120 | 120 | |
121 | - /** |
|
122 | - * @param string $str |
|
123 | - */ |
|
124 | - function setPinyin($str) { |
|
125 | - $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1); |
|
126 | - $t_str = iconv_substr( $str, $py, 1, 'UTF-8'); |
|
127 | - if(mt_rand(0,10) > 5) { |
|
128 | - $pinyin = " "; |
|
129 | - } |
|
130 | - $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE); |
|
121 | + /** |
|
122 | + * @param string $str |
|
123 | + */ |
|
124 | + function setPinyin($str) { |
|
125 | + $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1); |
|
126 | + $t_str = iconv_substr( $str, $py, 1, 'UTF-8'); |
|
127 | + if(mt_rand(0,10) > 5) { |
|
128 | + $pinyin = " "; |
|
129 | + } |
|
130 | + $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE); |
|
131 | 131 | $pinyin=implode(" ",$pinyin); |
132 | - if(mt_rand(0,10) > 5) { |
|
133 | - $pinyin .= " "; |
|
134 | - } |
|
135 | - if($t_str != "%"){ |
|
136 | - $str = preg_replace("'$t_str'", $pinyin, $str, 1); |
|
137 | - } |
|
138 | - return $str; |
|
139 | - } |
|
132 | + if(mt_rand(0,10) > 5) { |
|
133 | + $pinyin .= " "; |
|
134 | + } |
|
135 | + if($t_str != "%"){ |
|
136 | + $str = preg_replace("'$t_str'", $pinyin, $str, 1); |
|
137 | + } |
|
138 | + return $str; |
|
139 | + } |
|
140 | 140 | |
141 | - //随机重复一个字符 |
|
142 | - function setRepeat($str) { |
|
143 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
144 | - $action = 0; |
|
145 | - $temp = ''; |
|
146 | - for( $i=0; $i<$len; $i++ ){ |
|
147 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
148 | - if( mt_rand( 1, 50 ) > 48 && $action == 0) { |
|
149 | - if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
150 | - $temp .= $t_str; |
|
151 | - $action = 1; |
|
152 | - } |
|
153 | - } |
|
154 | - $temp .= $t_str; |
|
155 | - } |
|
156 | - return $temp; |
|
157 | - } |
|
141 | + //随机重复一个字符 |
|
142 | + function setRepeat($str) { |
|
143 | + $len = iconv_strlen( $str, 'UTF-8' ); |
|
144 | + $action = 0; |
|
145 | + $temp = ''; |
|
146 | + for( $i=0; $i<$len; $i++ ){ |
|
147 | + $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
148 | + if( mt_rand( 1, 50 ) > 48 && $action == 0) { |
|
149 | + if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
150 | + $temp .= $t_str; |
|
151 | + $action = 1; |
|
152 | + } |
|
153 | + } |
|
154 | + $temp .= $t_str; |
|
155 | + } |
|
156 | + return $temp; |
|
157 | + } |
|
158 | 158 | |
159 | - //随机插入不影响阅读的字符 |
|
159 | + //随机插入不影响阅读的字符 |
|
160 | 160 | |
161 | - /** |
|
162 | - * @param string $str |
|
163 | - */ |
|
164 | - function setBlankness($str) { |
|
165 | - $blankness = array(" ", ' ', '҉','̅̅','̲','̲̲','̅','̲̲̅̅'); |
|
166 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
167 | - $temp = ''; |
|
168 | - for( $i=0; $i<$len; $i++ ){ |
|
169 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
170 | - if( mt_rand( 1, 50 ) > 48 ) { |
|
171 | - if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
172 | - $temp .= $blankness[mt_rand(0, 7)]; |
|
173 | - } |
|
174 | - } |
|
175 | - $temp .= $t_str; |
|
176 | - } |
|
177 | - return $temp; |
|
178 | - } |
|
161 | + /** |
|
162 | + * @param string $str |
|
163 | + */ |
|
164 | + function setBlankness($str) { |
|
165 | + $blankness = array(" ", ' ', '҉','̅̅','̲','̲̲','̅','̲̲̅̅'); |
|
166 | + $len = iconv_strlen( $str, 'UTF-8' ); |
|
167 | + $temp = ''; |
|
168 | + for( $i=0; $i<$len; $i++ ){ |
|
169 | + $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
170 | + if( mt_rand( 1, 50 ) > 48 ) { |
|
171 | + if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
172 | + $temp .= $blankness[mt_rand(0, 7)]; |
|
173 | + } |
|
174 | + } |
|
175 | + $temp .= $t_str; |
|
176 | + } |
|
177 | + return $temp; |
|
178 | + } |
|
179 | 179 | |
180 | - //随机进行繁体中文转换 |
|
181 | - function GbToBig( $str ){ |
|
182 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
183 | - $temp = ''; |
|
184 | - for( $i=0; $i<$len; $i++ ){ |
|
185 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
186 | - if( mt_rand( 1, 50 ) > 48 ) { |
|
187 | - $t_str = strtr( $t_str, $this->GbToBigArray ); |
|
188 | - } |
|
189 | - $temp .= $t_str; |
|
190 | - } |
|
191 | - return $temp; |
|
192 | - } |
|
180 | + //随机进行繁体中文转换 |
|
181 | + function GbToBig( $str ){ |
|
182 | + $len = iconv_strlen( $str, 'UTF-8' ); |
|
183 | + $temp = ''; |
|
184 | + for( $i=0; $i<$len; $i++ ){ |
|
185 | + $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
186 | + if( mt_rand( 1, 50 ) > 48 ) { |
|
187 | + $t_str = strtr( $t_str, $this->GbToBigArray ); |
|
188 | + } |
|
189 | + $temp .= $t_str; |
|
190 | + } |
|
191 | + return $temp; |
|
192 | + } |
|
193 | 193 | } |
194 | 194 | |
195 | 195 |
@@ -31,87 +31,87 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | //分离URL |
34 | - private function cutting($str){ |
|
34 | + private function cutting($str) { |
|
35 | 35 | |
36 | - if(preg_match("@(http://[^\\s]+)@i", $str, $result)) { |
|
37 | - $this->url = $result[1]; |
|
38 | - $this->msg = $str = str_replace($this->url, '%%%%', $str); |
|
36 | + if (preg_match("@(http://[^\\s]+)@i", $str, $result)) { |
|
37 | + $this->url=$result[1]; |
|
38 | + $this->msg=$str=str_replace($this->url, '%%%%', $str); |
|
39 | 39 | } else { |
40 | - $this->msg = $str; |
|
40 | + $this->msg=$str; |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - private function convert( $method = 'msg' ){ |
|
47 | - if( $method == 'msg' || $method == 'all') { |
|
48 | - $this->msg = $this->setPinyin($this->msg); |
|
49 | - $this->msg = $this->setRepeat($this->msg); |
|
46 | + private function convert($method='msg') { |
|
47 | + if ($method == 'msg' || $method == 'all') { |
|
48 | + $this->msg=$this->setPinyin($this->msg); |
|
49 | + $this->msg=$this->setRepeat($this->msg); |
|
50 | 50 | //$this->msg = $this->GbToBig($this->msg); |
51 | - $this->msg = $this->setBlankness($this->msg); |
|
51 | + $this->msg=$this->setBlankness($this->msg); |
|
52 | 52 | |
53 | 53 | } |
54 | - if( $method == 'url' || $method == 'all') { |
|
55 | - $this->url = $this->setChacha($this->url); |
|
54 | + if ($method == 'url' || $method == 'all') { |
|
55 | + $this->url=$this->setChacha($this->url); |
|
56 | 56 | } |
57 | - $this->msg=$this->prefix.str_replace( '%%%%', $this->url, $this->msg); |
|
57 | + $this->msg=$this->prefix.str_replace('%%%%', $this->url, $this->msg); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @param string $url |
62 | 62 | */ |
63 | - function setChacha($url ){ |
|
64 | - $url = strtolower($url); |
|
65 | - $arr = array( |
|
66 | - 'a' => array('a','A','a','A','Α','А','α'), |
|
67 | - 'b' => array('b','B','b','B','Β','В','Ь'), |
|
68 | - 'c' => array('c','C','c','C','С','с'), |
|
69 | - 'd' => array('d','D','d','D'), |
|
70 | - 'e' => array('e','E','e','E','Ε','Е','е'), |
|
71 | - 'f' => array('f','F','f','F'), |
|
72 | - 'g' => array('g','G','g','G'), |
|
73 | - 'h' => array('h','H','h','H','Η','Н','н'), |
|
74 | - 'i' => array('i','I','i','I','Ι','Ⅰ'), |
|
75 | - 'j' => array('j','J','j','J'), |
|
76 | - 'k' => array('k','K','k','K','Κ','κ','к','К'), |
|
77 | - 'l' => array('l','L','l','L','︱','︳','|'), |
|
78 | - 'm' => array('m','M','m','M','Μ','М','м'), |
|
79 | - 'n' => array('n','N','n','N','Ν','∩'), |
|
80 | - 'o' => array('o','O','o','O','Ο','О'), |
|
81 | - 'p' => array('p','P','p','P','Ρ','Р','р'), |
|
82 | - 'q' => array('q','Q','q','Q'), |
|
83 | - 'r' => array('r','R','r','R'), |
|
84 | - 's' => array('s','S','s','S'), |
|
85 | - 't' => array('t','T','t','T','Τ','Т','ㄒ'), |
|
86 | - 'u' => array('u','U','u','U','∪'), |
|
87 | - 'v' => array('v','V','v','V','∨','ν'), |
|
88 | - 'w' => array('w','W','w','W'), |
|
89 | - 'x' => array('x','X','x','X','Χ','χ','Х','х','Ⅹ','×'), |
|
90 | - 'y' => array('y','Y','y','Y','У'), |
|
91 | - 'z' => array('z','Z','z','Z','Ζ'), |
|
63 | + function setChacha($url) { |
|
64 | + $url=strtolower($url); |
|
65 | + $arr=array( |
|
66 | + 'a' => array('a', 'A', 'a', 'A', 'Α', 'А', 'α'), |
|
67 | + 'b' => array('b', 'B', 'b', 'B', 'Β', 'В', 'Ь'), |
|
68 | + 'c' => array('c', 'C', 'c', 'C', 'С', 'с'), |
|
69 | + 'd' => array('d', 'D', 'd', 'D'), |
|
70 | + 'e' => array('e', 'E', 'e', 'E', 'Ε', 'Е', 'е'), |
|
71 | + 'f' => array('f', 'F', 'f', 'F'), |
|
72 | + 'g' => array('g', 'G', 'g', 'G'), |
|
73 | + 'h' => array('h', 'H', 'h', 'H', 'Η', 'Н', 'н'), |
|
74 | + 'i' => array('i', 'I', 'i', 'I', 'Ι', 'Ⅰ'), |
|
75 | + 'j' => array('j', 'J', 'j', 'J'), |
|
76 | + 'k' => array('k', 'K', 'k', 'K', 'Κ', 'κ', 'к', 'К'), |
|
77 | + 'l' => array('l', 'L', 'l', 'L', '︱', '︳', '|'), |
|
78 | + 'm' => array('m', 'M', 'm', 'M', 'Μ', 'М', 'м'), |
|
79 | + 'n' => array('n', 'N', 'n', 'N', 'Ν', '∩'), |
|
80 | + 'o' => array('o', 'O', 'o', 'O', 'Ο', 'О'), |
|
81 | + 'p' => array('p', 'P', 'p', 'P', 'Ρ', 'Р', 'р'), |
|
82 | + 'q' => array('q', 'Q', 'q', 'Q'), |
|
83 | + 'r' => array('r', 'R', 'r', 'R'), |
|
84 | + 's' => array('s', 'S', 's', 'S'), |
|
85 | + 't' => array('t', 'T', 't', 'T', 'Τ', 'Т', 'ㄒ'), |
|
86 | + 'u' => array('u', 'U', 'u', 'U', '∪'), |
|
87 | + 'v' => array('v', 'V', 'v', 'V', '∨', 'ν'), |
|
88 | + 'w' => array('w', 'W', 'w', 'W'), |
|
89 | + 'x' => array('x', 'X', 'x', 'X', 'Χ', 'χ', 'Х', 'х', 'Ⅹ', '×'), |
|
90 | + 'y' => array('y', 'Y', 'y', 'Y', 'У'), |
|
91 | + 'z' => array('z', 'Z', 'z', 'Z', 'Ζ'), |
|
92 | 92 | |
93 | - '1' => array('1','1'), |
|
94 | - '2' => array('2','2'), |
|
95 | - '3' => array('3','3'), |
|
96 | - '4' => array('4','4'), |
|
97 | - '5' => array('5','5'), |
|
98 | - '6' => array('6','6'), |
|
99 | - '7' => array('7','7'), |
|
100 | - '8' => array('8','8'), |
|
101 | - '9' => array('9','9'), |
|
102 | - '0' => array('0','0'), |
|
93 | + '1' => array('1', '1'), |
|
94 | + '2' => array('2', '2'), |
|
95 | + '3' => array('3', '3'), |
|
96 | + '4' => array('4', '4'), |
|
97 | + '5' => array('5', '5'), |
|
98 | + '6' => array('6', '6'), |
|
99 | + '7' => array('7', '7'), |
|
100 | + '8' => array('8', '8'), |
|
101 | + '9' => array('9', '9'), |
|
102 | + '0' => array('0', '0'), |
|
103 | 103 | |
104 | - ':' => array(':',':','∶'), |
|
105 | - '/' => array('/','/'), |
|
106 | - '.' => array('。','·','.','、','﹒',',','丶') |
|
104 | + ':' => array(':', ':', '∶'), |
|
105 | + '/' => array('/', '/'), |
|
106 | + '.' => array('。', '·', '.', '、', '﹒', ',', '丶') |
|
107 | 107 | |
108 | 108 | ); |
109 | - $len = strlen( $url ); |
|
110 | - $temp = "\n\n"; |
|
111 | - for( $i=0; $i<$len; $i++){ |
|
112 | - $t_str = substr( $url, $i, 1 ); |
|
113 | - $sj = mt_rand( 0, count($arr[$t_str])-1 ); |
|
114 | - $temp .= $arr[$t_str][$sj]; |
|
109 | + $len=strlen($url); |
|
110 | + $temp="\n\n"; |
|
111 | + for ($i=0; $i < $len; $i++) { |
|
112 | + $t_str=substr($url, $i, 1); |
|
113 | + $sj=mt_rand(0, count($arr[$t_str]) - 1); |
|
114 | + $temp.=$arr[$t_str][$sj]; |
|
115 | 115 | } |
116 | 116 | return $temp; |
117 | 117 | } |
@@ -122,36 +122,36 @@ discard block |
||
122 | 122 | * @param string $str |
123 | 123 | */ |
124 | 124 | function setPinyin($str) { |
125 | - $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1); |
|
126 | - $t_str = iconv_substr( $str, $py, 1, 'UTF-8'); |
|
127 | - if(mt_rand(0,10) > 5) { |
|
128 | - $pinyin = " "; |
|
125 | + $py=mt_rand(0, iconv_strlen($str, 'UTF-8') - 1); |
|
126 | + $t_str=iconv_substr($str, $py, 1, 'UTF-8'); |
|
127 | + if (mt_rand(0, 10) > 5) { |
|
128 | + $pinyin=" "; |
|
129 | 129 | } |
130 | - $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE); |
|
131 | - $pinyin=implode(" ",$pinyin); |
|
132 | - if(mt_rand(0,10) > 5) { |
|
133 | - $pinyin .= " "; |
|
130 | + $pinyin=$this->_pinyin->convert($t_str, PINYIN_UNICODE); |
|
131 | + $pinyin=implode(" ", $pinyin); |
|
132 | + if (mt_rand(0, 10) > 5) { |
|
133 | + $pinyin.=" "; |
|
134 | 134 | } |
135 | - if($t_str != "%"){ |
|
136 | - $str = preg_replace("'$t_str'", $pinyin, $str, 1); |
|
135 | + if ($t_str != "%") { |
|
136 | + $str=preg_replace("'$t_str'", $pinyin, $str, 1); |
|
137 | 137 | } |
138 | 138 | return $str; |
139 | 139 | } |
140 | 140 | |
141 | 141 | //随机重复一个字符 |
142 | 142 | function setRepeat($str) { |
143 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
144 | - $action = 0; |
|
145 | - $temp = ''; |
|
146 | - for( $i=0; $i<$len; $i++ ){ |
|
147 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
148 | - if( mt_rand( 1, 50 ) > 48 && $action == 0) { |
|
149 | - if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
150 | - $temp .= $t_str; |
|
151 | - $action = 1; |
|
143 | + $len=iconv_strlen($str, 'UTF-8'); |
|
144 | + $action=0; |
|
145 | + $temp=''; |
|
146 | + for ($i=0; $i < $len; $i++) { |
|
147 | + $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
148 | + if (mt_rand(1, 50) > 48 && $action == 0) { |
|
149 | + if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
150 | + $temp.=$t_str; |
|
151 | + $action=1; |
|
152 | 152 | } |
153 | 153 | } |
154 | - $temp .= $t_str; |
|
154 | + $temp.=$t_str; |
|
155 | 155 | } |
156 | 156 | return $temp; |
157 | 157 | } |
@@ -162,31 +162,31 @@ discard block |
||
162 | 162 | * @param string $str |
163 | 163 | */ |
164 | 164 | function setBlankness($str) { |
165 | - $blankness = array(" ", ' ', '҉','̅̅','̲','̲̲','̅','̲̲̅̅'); |
|
166 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
167 | - $temp = ''; |
|
168 | - for( $i=0; $i<$len; $i++ ){ |
|
169 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
170 | - if( mt_rand( 1, 50 ) > 48 ) { |
|
171 | - if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
172 | - $temp .= $blankness[mt_rand(0, 7)]; |
|
165 | + $blankness=array(" ", ' ', '҉', '̅̅', '̲', '̲̲', '̅', '̲̲̅̅'); |
|
166 | + $len=iconv_strlen($str, 'UTF-8'); |
|
167 | + $temp=''; |
|
168 | + for ($i=0; $i < $len; $i++) { |
|
169 | + $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
170 | + if (mt_rand(1, 50) > 48) { |
|
171 | + if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
172 | + $temp.=$blankness[mt_rand(0, 7)]; |
|
173 | 173 | } |
174 | 174 | } |
175 | - $temp .= $t_str; |
|
175 | + $temp.=$t_str; |
|
176 | 176 | } |
177 | 177 | return $temp; |
178 | 178 | } |
179 | 179 | |
180 | 180 | //随机进行繁体中文转换 |
181 | - function GbToBig( $str ){ |
|
182 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
183 | - $temp = ''; |
|
184 | - for( $i=0; $i<$len; $i++ ){ |
|
185 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
186 | - if( mt_rand( 1, 50 ) > 48 ) { |
|
187 | - $t_str = strtr( $t_str, $this->GbToBigArray ); |
|
181 | + function GbToBig($str) { |
|
182 | + $len=iconv_strlen($str, 'UTF-8'); |
|
183 | + $temp=''; |
|
184 | + for ($i=0; $i < $len; $i++) { |
|
185 | + $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
186 | + if (mt_rand(1, 50) > 48) { |
|
187 | + $t_str=strtr($t_str, $this->GbToBigArray); |
|
188 | 188 | } |
189 | - $temp .= $t_str; |
|
189 | + $temp.=$t_str; |
|
190 | 190 | } |
191 | 191 | return $temp; |
192 | 192 | } |
@@ -15,64 +15,64 @@ |
||
15 | 15 | protected $limitCount=null; |
16 | 16 | public function __construct() |
17 | 17 | { |
18 | - if(!$this->dbConn){ |
|
18 | + if (!$this->dbConn) { |
|
19 | 19 | $this->dbConn='main'; |
20 | 20 | } |
21 | - $this->db = Mysql::getDb($this->dbConn); |
|
21 | + $this->db=Mysql::getDb($this->dbConn); |
|
22 | 22 | } |
23 | - public function __call($method,$arg){ |
|
23 | + public function __call($method, $arg) { |
|
24 | 24 | $ret=$this; |
25 | - if(method_exists ($this->db, $method)){ |
|
26 | - $ret=call_user_func_array(array($this->db,$method),$arg); |
|
25 | + if (method_exists($this->db, $method)) { |
|
26 | + $ret=call_user_func_array(array($this->db, $method), $arg); |
|
27 | 27 | } |
28 | - return $ret==$this->db? $this: $ret; |
|
28 | + return $ret == $this->db ? $this : $ret; |
|
29 | 29 | } |
30 | - public function __get($name){ |
|
31 | - if(property_exists($this->db, $name)){ |
|
30 | + public function __get($name) { |
|
31 | + if (property_exists($this->db, $name)) { |
|
32 | 32 | return $this->db->$name; |
33 | 33 | } |
34 | - throw new MemberAccessException('model Property ' . $name . ' not exists'); |
|
34 | + throw new MemberAccessException('model Property '.$name.' not exists'); |
|
35 | 35 | } |
36 | - public function limit($limit){ |
|
36 | + public function limit($limit) { |
|
37 | 37 | $this->limitCount=$limit; |
38 | 38 | return $this; |
39 | 39 | } |
40 | - public function find(){ |
|
41 | - return $this->db->getOne($this->table,$this->field); |
|
40 | + public function find() { |
|
41 | + return $this->db->getOne($this->table, $this->field); |
|
42 | 42 | } |
43 | - public function select(){ |
|
44 | - return $this->db->get($this->table,$this->limitCount?$this->limitCount:null,$this->field); |
|
43 | + public function select() { |
|
44 | + return $this->db->get($this->table, $this->limitCount ? $this->limitCount : null, $this->field); |
|
45 | 45 | } |
46 | - public function count(){ |
|
46 | + public function count() { |
|
47 | 47 | return $this->field("count(*) as count")->find()['count']; |
48 | 48 | } |
49 | - public function table($table){ |
|
49 | + public function table($table) { |
|
50 | 50 | $this->table=$table; |
51 | 51 | return $this; |
52 | 52 | } |
53 | - public function add($data){ |
|
54 | - return $this->db->insert($this->table,$data); |
|
53 | + public function add($data) { |
|
54 | + return $this->db->insert($this->table, $data); |
|
55 | 55 | } |
56 | - public function replace($data){ |
|
57 | - return $this->db->replace($this->table,$data); |
|
56 | + public function replace($data) { |
|
57 | + return $this->db->replace($this->table, $data); |
|
58 | 58 | } |
59 | - public function update($data){ |
|
60 | - return $this->db->update($this->table,$data); |
|
59 | + public function update($data) { |
|
60 | + return $this->db->update($this->table, $data); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @param string $field |
65 | 65 | */ |
66 | - public function field($field){ |
|
66 | + public function field($field) { |
|
67 | 67 | $this->field=$field; |
68 | 68 | return $this; |
69 | 69 | } |
70 | - public function delete(){ |
|
70 | + public function delete() { |
|
71 | 71 | return $this->db->delete($this->table); |
72 | 72 | } |
73 | - public function page($page,$pageLimit='10'){ |
|
73 | + public function page($page, $pageLimit='10') { |
|
74 | 74 | $this->db->pageLimit=$pageLimit; |
75 | - $info= $this->db->paginate($this->table,$page,$this->field); |
|
75 | + $info=$this->db->paginate($this->table, $page, $this->field); |
|
76 | 76 | return $info; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | \ No newline at end of file |
@@ -4,48 +4,48 @@ |
||
4 | 4 | class Controller |
5 | 5 | { |
6 | 6 | |
7 | - protected $viewPath = ''; |
|
7 | + protected $viewPath=''; |
|
8 | 8 | private $twig; |
9 | - private $tVar = array(); |
|
9 | + private $tVar=array(); |
|
10 | 10 | protected $title=''; |
11 | 11 | public function __construct() |
12 | 12 | { |
13 | - $loader = new \Twig_Loader_Filesystem(BASE_PATH . $this->viewPath); |
|
14 | - $twig = new \Twig_Environment($loader, array( |
|
13 | + $loader=new \Twig_Loader_Filesystem(BASE_PATH.$this->viewPath); |
|
14 | + $twig=new \Twig_Environment($loader, array( |
|
15 | 15 | 'debug' => DEBUG, |
16 | - 'cache' => BASE_PATH . '/cache', |
|
16 | + 'cache' => BASE_PATH.'/cache', |
|
17 | 17 | )); |
18 | - $this->twig = $twig; |
|
18 | + $this->twig=$twig; |
|
19 | 19 | $this->initTwigFilter(); |
20 | 20 | $this->initTwigFunction(); |
21 | - $this->db = \MysqliDb::getInstance(); |
|
21 | + $this->db=\MysqliDb::getInstance(); |
|
22 | 22 | } |
23 | - private function initTwigFilter(){ |
|
24 | - $filter = new \Twig_SimpleFilter('long2ip', 'long2ip'); |
|
23 | + private function initTwigFilter() { |
|
24 | + $filter=new \Twig_SimpleFilter('long2ip', 'long2ip'); |
|
25 | 25 | $this->twig->addFilter($filter); |
26 | 26 | } |
27 | - private function initTwigFunction(){ |
|
28 | - $function = new \Twig_SimpleFunction('I','I'); |
|
27 | + private function initTwigFunction() { |
|
28 | + $function=new \Twig_SimpleFunction('I', 'I'); |
|
29 | 29 | $this->twig->addFunction($function); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @param string $name |
34 | 34 | */ |
35 | - protected function assign($name, $value = '') |
|
35 | + protected function assign($name, $value='') |
|
36 | 36 | { |
37 | 37 | if (is_array($name)) { |
38 | - $this->tVar = array_merge($this->tVar, $name); |
|
38 | + $this->tVar=array_merge($this->tVar, $name); |
|
39 | 39 | } else { |
40 | - $this->tVar[$name] = $value; |
|
40 | + $this->tVar[$name]=$value; |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - protected function show($tmpPath = '') |
|
44 | + protected function show($tmpPath='') |
|
45 | 45 | { |
46 | 46 | if ($tmpPath == '') { |
47 | 47 | if (defined("CONTROLLER_NAME") && defined("ACTION_NAME")) { |
48 | - $tmpPath = parse_name(CONTROLLER_NAME) . '/' . parse_name(ACTION_NAME); |
|
48 | + $tmpPath=parse_name(CONTROLLER_NAME).'/'.parse_name(ACTION_NAME); |
|
49 | 49 | } else { |
50 | 50 | show_json($this->tVar); |
51 | 51 | } |
@@ -54,84 +54,84 @@ |
||
54 | 54 | * @param integer $past |
55 | 55 | * @param integer $now |
56 | 56 | */ |
57 | - public function inStamp($past, $now = null) { |
|
58 | - if($now==null){ |
|
57 | + public function inStamp($past, $now=null) { |
|
58 | + if ($now == null) { |
|
59 | 59 | $now=time(); |
60 | 60 | } |
61 | 61 | // creates the "time ago" string. This always starts with an "about..." |
62 | - $timeAgo = ""; |
|
62 | + $timeAgo=""; |
|
63 | 63 | |
64 | 64 | // finds the time difference |
65 | - $timeDifference = $now - $past; |
|
65 | + $timeDifference=$now - $past; |
|
66 | 66 | // rule 0 |
67 | 67 | // $past is null or empty or '' |
68 | - if ($past==0) { |
|
69 | - $timeAgo = $this->translate('never'); |
|
68 | + if ($past == 0) { |
|
69 | + $timeAgo=$this->translate('never'); |
|
70 | 70 | } |
71 | 71 | // rule 1 |
72 | 72 | // less than 29secs |
73 | 73 | else if ($this->isLessThan29Seconds($timeDifference)) { |
74 | - $timeAgo = $this->translate('lessThanAMinute'); |
|
74 | + $timeAgo=$this->translate('lessThanAMinute'); |
|
75 | 75 | } |
76 | 76 | // rule 2 |
77 | 77 | // more than 29secs and less than 1min29secss |
78 | 78 | else if ($this->isLessThan1Min29Seconds($timeDifference)) { |
79 | - $timeAgo = $this->translate('oneMinute'); |
|
79 | + $timeAgo=$this->translate('oneMinute'); |
|
80 | 80 | } |
81 | 81 | // rule 3 |
82 | 82 | // between 1min30secs and 44mins29secs |
83 | 83 | else if ($this->isLessThan44Min29Secs($timeDifference)) { |
84 | - $minutes = round($timeDifference / $this->secondsPerMinute); |
|
85 | - $timeAgo = $this->translate('lessThanOneHour', $minutes); |
|
84 | + $minutes=round($timeDifference / $this->secondsPerMinute); |
|
85 | + $timeAgo=$this->translate('lessThanOneHour', $minutes); |
|
86 | 86 | } |
87 | 87 | // rule 4 |
88 | 88 | // between 44mins30secs and 1hour29mins59secs |
89 | 89 | else if ($this->isLessThan1Hour29Mins59Seconds($timeDifference)) { |
90 | - $timeAgo = $this->translate('aboutOneHour'); |
|
90 | + $timeAgo=$this->translate('aboutOneHour'); |
|
91 | 91 | } |
92 | 92 | // rule 5 |
93 | 93 | // between 1hour29mins59secs and 23hours59mins29secs |
94 | 94 | else if ($this->isLessThan23Hours59Mins29Seconds($timeDifference)) { |
95 | - $hours = round($timeDifference / $this->secondsPerHour); |
|
96 | - $timeAgo = $this->translate('hours', $hours); |
|
95 | + $hours=round($timeDifference / $this->secondsPerHour); |
|
96 | + $timeAgo=$this->translate('hours', $hours); |
|
97 | 97 | } |
98 | 98 | // rule 6 |
99 | 99 | // between 23hours59mins30secs and 47hours59mins29secs |
100 | 100 | else if ($this->isLessThan47Hours59Mins29Seconds($timeDifference)) { |
101 | - $timeAgo = $this->translate('aboutOneDay'); |
|
101 | + $timeAgo=$this->translate('aboutOneDay'); |
|
102 | 102 | } |
103 | 103 | // rule 7 |
104 | 104 | // between 47hours59mins30secs and 29days23hours59mins29secs |
105 | 105 | else if ($this->isLessThan29Days23Hours59Mins29Seconds($timeDifference)) { |
106 | - $days = round($timeDifference / $this->secondsPerDay); |
|
107 | - $timeAgo = $this->translate('days', $days); |
|
106 | + $days=round($timeDifference / $this->secondsPerDay); |
|
107 | + $timeAgo=$this->translate('days', $days); |
|
108 | 108 | } |
109 | 109 | // rule 8 |
110 | 110 | // between 29days23hours59mins30secs and 59days23hours59mins29secs |
111 | 111 | else if ($this->isLessThan59Days23Hours59Mins29Secs($timeDifference)) { |
112 | - $timeAgo = $this->translate('aboutOneMonth'); |
|
112 | + $timeAgo=$this->translate('aboutOneMonth'); |
|
113 | 113 | } |
114 | 114 | // rule 9 |
115 | 115 | // between 59days23hours59mins30secs and 1year (minus 1sec) |
116 | 116 | else if ($this->isLessThan1Year($timeDifference)) { |
117 | - $months = round($timeDifference / $this->secondsPerMonth); |
|
117 | + $months=round($timeDifference / $this->secondsPerMonth); |
|
118 | 118 | // if months is 1, then set it to 2, because we are "past" 1 month |
119 | 119 | if ($months == 1) { |
120 | - $months = 2; |
|
120 | + $months=2; |
|
121 | 121 | } |
122 | 122 | |
123 | - $timeAgo = $this->translate('months', $months); |
|
123 | + $timeAgo=$this->translate('months', $months); |
|
124 | 124 | } |
125 | 125 | // rule 10 |
126 | 126 | // between 1year and 2years (minus 1sec) |
127 | 127 | else if ($this->isLessThan2Years($timeDifference)) { |
128 | - $timeAgo = $this->translate('aboutOneYear'); |
|
128 | + $timeAgo=$this->translate('aboutOneYear'); |
|
129 | 129 | } |
130 | 130 | // rule 11 |
131 | 131 | // 2years or more |
132 | 132 | else { |
133 | - $years = floor($timeDifference / $this->secondsPerYear); |
|
134 | - $timeAgo = $this->translate('years', $years); |
|
133 | + $years=floor($timeDifference / $this->secondsPerYear); |
|
134 | + $timeAgo=$this->translate('years', $years); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | return $timeAgo; |
@@ -133,71 +133,74 @@ |
||
133 | 133 | $ext=$this->getParam(); |
134 | 134 | } |
135 | 135 | $pagination.="<ul class='pager'>"; |
136 | - if ($this->_page > 1) |
|
137 | - $pagination.="<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
138 | - else |
|
139 | - $pagination.="<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
136 | + if ($this->_page > 1) { |
|
137 | + $pagination.="<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
138 | + } else { |
|
139 | + $pagination.="<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
140 | + } |
|
140 | 141 | |
141 | 142 | if ($lastpage < 7 + ($adjacents * 2)) |
142 | 143 | { |
143 | 144 | for ($counter=1; $counter <= $lastpage; $counter++) |
144 | 145 | { |
145 | - if ($counter == $this->_page) |
|
146 | - $pagination.="<li class='current'><span>$counter</span></li>"; |
|
147 | - else |
|
148 | - $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
146 | + if ($counter == $this->_page) { |
|
147 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
148 | + } else { |
|
149 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
150 | + } |
|
149 | 151 | } |
150 | - } |
|
151 | - elseif ($lastpage > 5 + ($adjacents * 2)) |
|
152 | + } elseif ($lastpage > 5 + ($adjacents * 2)) |
|
152 | 153 | { |
153 | 154 | if ($this->_page < 1 + ($adjacents * 2)) |
154 | 155 | { |
155 | 156 | for ($counter=1; $counter < 4 + ($adjacents * 2); $counter++) |
156 | 157 | { |
157 | - if ($counter == $this->_page) |
|
158 | - $pagination.="<li class='current'><span>$counter</span></li>"; |
|
159 | - else |
|
160 | - $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
158 | + if ($counter == $this->_page) { |
|
159 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
160 | + } else { |
|
161 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
162 | + } |
|
161 | 163 | } |
162 | 164 | $pagination.="..."; |
163 | 165 | $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
164 | 166 | $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
165 | - } |
|
166 | - elseif ($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
167 | + } elseif ($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
167 | 168 | { |
168 | 169 | $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
169 | 170 | $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
170 | 171 | $pagination.="..."; |
171 | 172 | for ($counter=$this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
172 | 173 | { |
173 | - if ($counter == $this->_page) |
|
174 | - $pagination.="<li class='current'><span>$counter</span></li>"; |
|
175 | - else |
|
176 | - $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
174 | + if ($counter == $this->_page) { |
|
175 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
176 | + } else { |
|
177 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
178 | + } |
|
177 | 179 | } |
178 | 180 | $pagination.=".."; |
179 | 181 | $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
180 | 182 | $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
181 | - } |
|
182 | - else |
|
183 | + } else |
|
183 | 184 | { |
184 | 185 | $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
185 | 186 | $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
186 | 187 | $pagination.=".."; |
187 | 188 | for ($counter=$lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
188 | 189 | { |
189 | - if ($counter == $this->_page) |
|
190 | - $pagination.="<li class='current'><span>$counter</span></li>"; |
|
191 | - else |
|
192 | - $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
190 | + if ($counter == $this->_page) { |
|
191 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
192 | + } else { |
|
193 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
194 | + } |
|
193 | 195 | } |
194 | 196 | } |
195 | 197 | } |
196 | 198 | |
197 | - if ($this->_page < $counter - 1) |
|
198 | - $pagination.="<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
199 | - else |
|
200 | - $pagination.="<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
199 | + if ($this->_page < $counter - 1) { |
|
200 | + $pagination.="<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
201 | + } else { |
|
202 | + $pagination.="<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
203 | + } |
|
201 | 204 | $pagination.="</ul>\n"; |
202 | 205 | } |
203 | 206 |
@@ -6,49 +6,49 @@ discard block |
||
6 | 6 | |
7 | 7 | class Dispatch |
8 | 8 | { |
9 | - static public function init(){ |
|
10 | - if(!IS_CLI){ |
|
9 | + static public function init() { |
|
10 | + if (!IS_CLI) { |
|
11 | 11 | define('NOW_TIME', $_SERVER['REQUEST_TIME']); |
12 | 12 | define('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']); |
13 | 13 | define('IS_GET', REQUEST_METHOD == 'GET' ? true : false); |
14 | 14 | define('IS_POST', REQUEST_METHOD == 'POST' ? true : false); |
15 | 15 | define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false); |
16 | 16 | define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false); |
17 | - define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ) ? true : false); |
|
17 | + define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) ? true : false); |
|
18 | 18 | define('__SELF__', strip_tags($_SERVER['REQUEST_URI'])); |
19 | 19 | } |
20 | 20 | } |
21 | - static public function dispatch($path='',$app='\\admin') { |
|
21 | + static public function dispatch($path='', $app='\\admin') { |
|
22 | 22 | self::init(); |
23 | - if($path==''){ |
|
23 | + if ($path == '') { |
|
24 | 24 | $path=array(); |
25 | - } else{ |
|
26 | - $path=str_replace('-','_',$path); |
|
27 | - $path = explode('/',$path); |
|
25 | + } else { |
|
26 | + $path=str_replace('-', '_', $path); |
|
27 | + $path=explode('/', $path); |
|
28 | 28 | } |
29 | 29 | |
30 | - if(count($path)==0){ |
|
31 | - array_push($path,'home'); |
|
32 | - array_push($path,'index'); |
|
33 | - } elseif (count($path)==1){ |
|
34 | - array_push($path,'index'); |
|
30 | + if (count($path) == 0) { |
|
31 | + array_push($path, 'home'); |
|
32 | + array_push($path, 'index'); |
|
33 | + } elseif (count($path) == 1) { |
|
34 | + array_push($path, 'index'); |
|
35 | 35 | } |
36 | - if(!empty($path)){ |
|
36 | + if (!empty($path)) { |
|
37 | 37 | $tmpAction=array_pop($path); |
38 | 38 | $tmpAction=preg_replace('/\.(html|aspx|do|php|htm|h5|api)$/i', '', $tmpAction); |
39 | - $tmpAction=parse_name($tmpAction,1); |
|
39 | + $tmpAction=parse_name($tmpAction, 1); |
|
40 | 40 | $var['a']=$tmpAction; |
41 | 41 | } |
42 | - define('ACTION_NAME',$var['a']); |
|
42 | + define('ACTION_NAME', $var['a']); |
|
43 | 43 | if (!preg_match('/^[A-Za-z](\w)*$/', ACTION_NAME)) { |
44 | 44 | die("error action"); |
45 | 45 | } |
46 | - if(!empty($path)){ |
|
46 | + if (!empty($path)) { |
|
47 | 47 | $tmpController=array_pop($path); |
48 | - $tmpController=parse_name($tmpController,1); |
|
48 | + $tmpController=parse_name($tmpController, 1); |
|
49 | 49 | $var['c']=$tmpController; |
50 | 50 | } |
51 | - define('CONTROLLER_NAME',$var['c']); |
|
51 | + define('CONTROLLER_NAME', $var['c']); |
|
52 | 52 | if (!preg_match('/^[A-Za-z](\/|\w)*$/', CONTROLLER_NAME)) { |
53 | 53 | die("error controller"); |
54 | 54 | } |
@@ -56,24 +56,24 @@ discard block |
||
56 | 56 | if (!class_exists($class)) { |
57 | 57 | not_found('this controller is can not work now!'); |
58 | 58 | } |
59 | - $class= new $class(); |
|
60 | - if (!method_exists($class,ACTION_NAME)) { |
|
59 | + $class=new $class(); |
|
60 | + if (!method_exists($class, ACTION_NAME)) { |
|
61 | 61 | not_found(); |
62 | 62 | } |
63 | 63 | self::param(); |
64 | - self::exec($class,ACTION_NAME); |
|
64 | + self::exec($class, ACTION_NAME); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @param string $function |
69 | 69 | */ |
70 | - static public function exec($class,$function){ |
|
71 | - $method = new \ReflectionMethod($class, $function); |
|
70 | + static public function exec($class, $function) { |
|
71 | + $method=new \ReflectionMethod($class, $function); |
|
72 | 72 | if ($method->isPublic() && !$method->isStatic()) { |
73 | - $refClass = new \ReflectionClass($class); |
|
73 | + $refClass=new \ReflectionClass($class); |
|
74 | 74 | //前置方法 |
75 | - if ($refClass->hasMethod('_before_' . $function)) { |
|
76 | - $before = $refClass->getMethod('_before_' . $function); |
|
75 | + if ($refClass->hasMethod('_before_'.$function)) { |
|
76 | + $before=$refClass->getMethod('_before_'.$function); |
|
77 | 77 | if ($before->isPublic()) { |
78 | 78 | $before->invoke($class); |
79 | 79 | } |