@@ -28,6 +28,10 @@ |
||
28 | 28 | $function = new \Twig_SimpleFunction('I','I'); |
29 | 29 | $this->twig->addFunction($function); |
30 | 30 | } |
31 | + |
|
32 | + /** |
|
33 | + * @param string $name |
|
34 | + */ |
|
31 | 35 | protected function assign($name, $value = '') |
32 | 36 | { |
33 | 37 | if (is_array($name)) { |
@@ -4,44 +4,44 @@ discard block |
||
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 | - protected function assign($name, $value = '') |
|
31 | + protected function assign($name, $value='') |
|
32 | 32 | { |
33 | 33 | if (is_array($name)) { |
34 | - $this->tVar = array_merge($this->tVar, $name); |
|
34 | + $this->tVar=array_merge($this->tVar, $name); |
|
35 | 35 | } else { |
36 | - $this->tVar[$name] = $value; |
|
36 | + $this->tVar[$name]=$value; |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - protected function show($tmpPath = '') |
|
40 | + protected function show($tmpPath='') |
|
41 | 41 | { |
42 | 42 | if ($tmpPath == '') { |
43 | 43 | if (defined("CONTROLLER_NAME") && defined("ACTION_NAME")) { |
44 | - $tmpPath = CONTROLLER_NAME . '/' . ACTION_NAME; |
|
44 | + $tmpPath=CONTROLLER_NAME.'/'.ACTION_NAME; |
|
45 | 45 | } else { |
46 | 46 | show_json($this->tVar); |
47 | 47 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | header('Content-Type:text/html; charset=utf-8'); |
50 | 50 | header('Cache-control: private'); // 页面缓存控制 |
51 | 51 | header('X-Powered-By:ViviAnAuthSystem'); |
52 | - $this->assign('title',$this->title); |
|
53 | - echo $this->twig->render($tmpPath . '.' . TempExt, $this->tVar); |
|
52 | + $this->assign('title', $this->title); |
|
53 | + echo $this->twig->render($tmpPath.'.'.TempExt, $this->tVar); |
|
54 | 54 | die(); |
55 | 55 | } |
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -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 | //数据类型检测 |
@@ -6,46 +6,46 @@ discard block |
||
6 | 6 | * @param boolean $adv 是否进行高级模式获取(有可能被伪装) |
7 | 7 | * @return mixed |
8 | 8 | */ |
9 | -function get_client_ip($type = 0, $adv = true) |
|
9 | +function get_client_ip($type=0, $adv=true) |
|
10 | 10 | { |
11 | - $type = $type ? 1 : 0; |
|
12 | - static $ip = null; |
|
11 | + $type=$type ? 1 : 0; |
|
12 | + static $ip=null; |
|
13 | 13 | if (null !== $ip) { |
14 | 14 | return $ip[$type]; |
15 | 15 | } |
16 | 16 | if ($adv) { |
17 | 17 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
18 | - $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
19 | - $pos = array_search('unknown', $arr); |
|
18 | + $arr=explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
19 | + $pos=array_search('unknown', $arr); |
|
20 | 20 | if (false !== $pos) { |
21 | 21 | unset($arr[$pos]); |
22 | 22 | } |
23 | - $ip = trim($arr[0]); |
|
23 | + $ip=trim($arr[0]); |
|
24 | 24 | } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { |
25 | - $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
25 | + $ip=$_SERVER['HTTP_CLIENT_IP']; |
|
26 | 26 | } elseif (isset($_SERVER['REMOTE_ADDR'])) { |
27 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
27 | + $ip=$_SERVER['REMOTE_ADDR']; |
|
28 | 28 | } |
29 | 29 | } elseif (isset($_SERVER['REMOTE_ADDR'])) { |
30 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
30 | + $ip=$_SERVER['REMOTE_ADDR']; |
|
31 | 31 | } |
32 | 32 | // IP地址合法验证 |
33 | - $long = sprintf("%u", ip2long($ip)); |
|
34 | - $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); |
|
33 | + $long=sprintf("%u", ip2long($ip)); |
|
34 | + $ip=$long ? array($ip, $long) : array('0.0.0.0', 0); |
|
35 | 35 | return $ip[$type]; |
36 | 36 | } |
37 | 37 | //2为直接输出数组 |
38 | -function show_json($arr,$type=2) |
|
38 | +function show_json($arr, $type=2) |
|
39 | 39 | { |
40 | - if(isset($arr['status']) && $type==2){ |
|
40 | + if (isset($arr['status']) && $type == 2) { |
|
41 | 41 | $ret=$arr; |
42 | 42 | } |
43 | - else{ |
|
44 | - $ret['status'] = $type; |
|
45 | - $ret['data'] = $arr; |
|
43 | + else { |
|
44 | + $ret['status']=$type; |
|
45 | + $ret['data']=$arr; |
|
46 | 46 | } |
47 | 47 | |
48 | - $obj = json_encode($ret); |
|
48 | + $obj=json_encode($ret); |
|
49 | 49 | header('Content-Type: application/json'); |
50 | 50 | echo $obj; |
51 | 51 | exit(); |
@@ -53,16 +53,16 @@ discard block |
||
53 | 53 | |
54 | 54 | function success($arr) |
55 | 55 | { |
56 | - show_json($arr,1); |
|
56 | + show_json($arr, 1); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function error($arr) |
60 | 60 | { |
61 | 61 | /* $db=\MysqliDb::getInstance(); |
62 | 62 | $db->_transaction_status_check();*/ |
63 | - show_json($arr,0); |
|
63 | + show_json($arr, 0); |
|
64 | 64 | } |
65 | -function not_found($str='page not found,that is all we know!'){ |
|
65 | +function not_found($str='page not found,that is all we know!') { |
|
66 | 66 | header('HTTP/1.1 404 Not Found'); |
67 | 67 | header("status: 404 Not Found"); |
68 | 68 | exit($str); |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | function data_auth_sign($data) { |
84 | 84 | //数据类型检测 |
85 | 85 | |
86 | - if(!is_array($data)){ |
|
86 | + if (!is_array($data)) { |
|
87 | 87 | |
88 | - $data = (array)$data; |
|
88 | + $data=(array) $data; |
|
89 | 89 | } |
90 | 90 | ksort($data); //排序 |
91 | - $code = http_build_query($data); //url编码并生成query字符串 |
|
92 | - $sign = sha1($code); //生成签名 |
|
91 | + $code=http_build_query($data); //url编码并生成query字符串 |
|
92 | + $sign=sha1($code); //生成签名 |
|
93 | 93 | return $sign; |
94 | 94 | } |
95 | 95 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param mixed $value session值 |
99 | 99 | * @return mixed |
100 | 100 | */ |
101 | -function session($name = '', $value = '') { |
|
101 | +function session($name='', $value='') { |
|
102 | 102 | if (is_array($name)) { |
103 | 103 | |
104 | 104 | if (isset($name['id'])) { |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | session_start(); |
151 | 151 | } elseif ('[destroy]' == $name) { |
152 | 152 | // 销毁session |
153 | - $_SESSION = array(); |
|
153 | + $_SESSION=array(); |
|
154 | 154 | session_unset(); |
155 | 155 | session_destroy(); |
156 | 156 | } elseif ('[regenerate]' == $name) { |
157 | 157 | // 重新生成id |
158 | 158 | session_regenerate_id(); |
159 | 159 | } |
160 | - }else { |
|
160 | + } else { |
|
161 | 161 | if (strpos($name, '.')) { |
162 | - list($name1, $name2) = explode('.', $name); |
|
162 | + list($name1, $name2)=explode('.', $name); |
|
163 | 163 | return isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; |
164 | 164 | } else { |
165 | 165 | return isset($_SESSION[$name]) ? $_SESSION[$name] : null; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } elseif (is_null($value)) { |
169 | 169 | // 删除session |
170 | 170 | if (strpos($name, '.')) { |
171 | - list($name1, $name2) = explode('.', $name); |
|
171 | + list($name1, $name2)=explode('.', $name); |
|
172 | 172 | unset($_SESSION[$name1][$name2]); |
173 | 173 | } else { |
174 | 174 | unset($_SESSION[$name]); |
@@ -176,30 +176,30 @@ discard block |
||
176 | 176 | } else { |
177 | 177 | // 设置session |
178 | 178 | if (strpos($name, '.')) { |
179 | - list($name1, $name2) = explode('.', $name); |
|
180 | - $_SESSION[$name1][$name2] = $value; |
|
179 | + list($name1, $name2)=explode('.', $name); |
|
180 | + $_SESSION[$name1][$name2]=$value; |
|
181 | 181 | } else { |
182 | - $_SESSION[$name] = $value; |
|
182 | + $_SESSION[$name]=$value; |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | return null; |
186 | 186 | } |
187 | 187 | |
188 | 188 | |
189 | -function admin_is_login(){ |
|
190 | - $user = session('admin_user_auth'); |
|
189 | +function admin_is_login() { |
|
190 | + $user=session('admin_user_auth'); |
|
191 | 191 | if (empty($user)) { |
192 | 192 | return 0; |
193 | 193 | } else { |
194 | 194 | $auth_sign=session('admin_user_auth_sign'); |
195 | - if(data_auth_sign($user)!=$auth_sign){ |
|
195 | + if (data_auth_sign($user) != $auth_sign) { |
|
196 | 196 | return 0; |
197 | 197 | } |
198 | 198 | return $user['uid']; |
199 | 199 | } |
200 | 200 | } |
201 | -function json($str){ |
|
202 | - $obj = json_encode($str,JSON_UNESCAPED_UNICODE); |
|
201 | +function json($str) { |
|
202 | + $obj=json_encode($str, JSON_UNESCAPED_UNICODE); |
|
203 | 203 | header('Content-Type: application/json'); |
204 | 204 | echo $obj; |
205 | 205 | } |
@@ -211,17 +211,17 @@ discard block |
||
211 | 211 | * @param integer $flags htmlspecialchars flags |
212 | 212 | * @return void|string |
213 | 213 | */ |
214 | -function dump($var, $echo = true, $label = null, $flags = ENT_SUBSTITUTE) |
|
214 | +function dump($var, $echo=true, $label=null, $flags=ENT_SUBSTITUTE) |
|
215 | 215 | { |
216 | - $label = (null === $label) ? '' : rtrim($label) . ':'; |
|
216 | + $label=(null === $label) ? '' : rtrim($label).':'; |
|
217 | 217 | ob_start(); |
218 | 218 | var_dump($var); |
219 | - $output = ob_get_clean(); |
|
220 | - $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); |
|
219 | + $output=ob_get_clean(); |
|
220 | + $output=preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); |
|
221 | 221 | if (!extension_loaded('xdebug')) { |
222 | - $output = htmlspecialchars($output, $flags); |
|
222 | + $output=htmlspecialchars($output, $flags); |
|
223 | 223 | } |
224 | - $output = '<pre>' . $label . $output . '</pre>'; |
|
224 | + $output='<pre>'.$label.$output.'</pre>'; |
|
225 | 225 | if ($echo) { |
226 | 226 | echo($output); |
227 | 227 | return; |
@@ -245,95 +245,95 @@ discard block |
||
245 | 245 | * @param mixed $datas 要获取的额外数据源 |
246 | 246 | * @return mixed |
247 | 247 | */ |
248 | -function I($name, $default = '', $filter = null, $datas = null) |
|
248 | +function I($name, $default='', $filter=null, $datas=null) |
|
249 | 249 | { |
250 | - static $_PUT = null; |
|
250 | + static $_PUT=null; |
|
251 | 251 | if (strpos($name, '/')) { |
252 | 252 | // 指定修饰符 |
253 | - list($name, $type) = explode('/', $name, 2); |
|
254 | - } else{ |
|
253 | + list($name, $type)=explode('/', $name, 2); |
|
254 | + } else { |
|
255 | 255 | // 默认强制转换为字符串 |
256 | - $type = 's'; |
|
256 | + $type='s'; |
|
257 | 257 | } |
258 | 258 | if (strpos($name, '.')) { |
259 | 259 | // 指定参数来源 |
260 | - list($method, $name) = explode('.', $name, 2); |
|
260 | + list($method, $name)=explode('.', $name, 2); |
|
261 | 261 | } else { |
262 | 262 | // 默认为自动判断 |
263 | - $method = 'param'; |
|
263 | + $method='param'; |
|
264 | 264 | } |
265 | 265 | switch (strtolower($method)) { |
266 | 266 | case 'get': |
267 | - $input = &$_GET; |
|
267 | + $input=&$_GET; |
|
268 | 268 | break; |
269 | 269 | case 'post': |
270 | - $input = &$_POST; |
|
270 | + $input=&$_POST; |
|
271 | 271 | break; |
272 | 272 | case 'put': |
273 | 273 | if (is_null($_PUT)) { |
274 | 274 | parse_str(file_get_contents('php://input'), $_PUT); |
275 | 275 | } |
276 | - $input = $_PUT; |
|
276 | + $input=$_PUT; |
|
277 | 277 | break; |
278 | 278 | case 'param': |
279 | 279 | switch ($_SERVER['REQUEST_METHOD']) { |
280 | 280 | case 'POST': |
281 | - $input = $_POST; |
|
281 | + $input=$_POST; |
|
282 | 282 | break; |
283 | 283 | case 'PUT': |
284 | 284 | if (is_null($_PUT)) { |
285 | 285 | parse_str(file_get_contents('php://input'), $_PUT); |
286 | 286 | } |
287 | - $input = $_PUT; |
|
287 | + $input=$_PUT; |
|
288 | 288 | break; |
289 | 289 | default: |
290 | - $input = $_GET; |
|
290 | + $input=$_GET; |
|
291 | 291 | } |
292 | 292 | break; |
293 | 293 | case 'path': |
294 | - $input = array(); |
|
294 | + $input=array(); |
|
295 | 295 | if (!empty($_SERVER['PATH_INFO'])) { |
296 | - $depr = C('URL_PATHINFO_DEPR'); |
|
297 | - $input = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); |
|
296 | + $depr=C('URL_PATHINFO_DEPR'); |
|
297 | + $input=explode($depr, trim($_SERVER['PATH_INFO'], $depr)); |
|
298 | 298 | } |
299 | 299 | break; |
300 | 300 | case 'request': |
301 | - $input = &$_REQUEST; |
|
301 | + $input=&$_REQUEST; |
|
302 | 302 | break; |
303 | 303 | case 'session': |
304 | - $input = &$_SESSION; |
|
304 | + $input=&$_SESSION; |
|
305 | 305 | break; |
306 | 306 | case 'cookie': |
307 | - $input = &$_COOKIE; |
|
307 | + $input=&$_COOKIE; |
|
308 | 308 | break; |
309 | 309 | case 'server': |
310 | - $input = &$_SERVER; |
|
310 | + $input=&$_SERVER; |
|
311 | 311 | break; |
312 | 312 | case 'globals': |
313 | - $input = &$GLOBALS; |
|
313 | + $input=&$GLOBALS; |
|
314 | 314 | break; |
315 | 315 | case 'data': |
316 | - $input = &$datas; |
|
316 | + $input=&$datas; |
|
317 | 317 | break; |
318 | 318 | default: |
319 | 319 | return null; |
320 | 320 | } |
321 | 321 | if ('' == $name) { |
322 | 322 | // 获取全部变量 |
323 | - $data = $input; |
|
324 | - $filters = isset($filter) ? $filter : 'htmlspecialchars'; |
|
323 | + $data=$input; |
|
324 | + $filters=isset($filter) ? $filter : 'htmlspecialchars'; |
|
325 | 325 | if ($filters) { |
326 | 326 | if (is_string($filters)) { |
327 | - $filters = explode(',', $filters); |
|
327 | + $filters=explode(',', $filters); |
|
328 | 328 | } |
329 | 329 | foreach ($filters as $filter) { |
330 | - $data = array_map_recursive($filter, $data); // 参数过滤 |
|
330 | + $data=array_map_recursive($filter, $data); // 参数过滤 |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | } elseif (isset($input[$name])) { |
334 | 334 | // 取值操作 |
335 | - $data = $input[$name]; |
|
336 | - $filters = isset($filter) ? $filter : 'htmlspecialchars'; |
|
335 | + $data=$input[$name]; |
|
336 | + $filters=isset($filter) ? $filter : 'htmlspecialchars'; |
|
337 | 337 | if ($filters) { |
338 | 338 | if (is_string($filters)) { |
339 | 339 | if (0 === strpos($filters, '/')) { |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | return isset($default) ? $default : null; |
343 | 343 | } |
344 | 344 | } else { |
345 | - $filters = explode(',', $filters); |
|
345 | + $filters=explode(',', $filters); |
|
346 | 346 | } |
347 | 347 | } elseif (is_int($filters)) { |
348 | - $filters = array($filters); |
|
348 | + $filters=array($filters); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | if (is_array($filters)) { |
352 | 352 | foreach ($filters as $filter) { |
353 | - $filter = trim($filter); |
|
353 | + $filter=trim($filter); |
|
354 | 354 | if (function_exists($filter)) { |
355 | - $data = is_array($data) ? array_map_recursive($filter, $data) : $filter($data); // 参数过滤 |
|
355 | + $data=is_array($data) ? array_map_recursive($filter, $data) : $filter($data); // 参数过滤 |
|
356 | 356 | } else { |
357 | - $data = filter_var($data, is_int($filter) ? $filter : filter_id($filter)); |
|
357 | + $data=filter_var($data, is_int($filter) ? $filter : filter_id($filter)); |
|
358 | 358 | if (false === $data) { |
359 | 359 | return isset($default) ? $default : null; |
360 | 360 | } |
@@ -365,34 +365,34 @@ discard block |
||
365 | 365 | if (!empty($type)) { |
366 | 366 | switch (strtolower($type)) { |
367 | 367 | case 'a': // 数组 |
368 | - $data = (array) $data; |
|
368 | + $data=(array) $data; |
|
369 | 369 | break; |
370 | 370 | case 'd': // 数字 |
371 | - $data = (int) $data; |
|
371 | + $data=(int) $data; |
|
372 | 372 | break; |
373 | 373 | case 'f': // 浮点 |
374 | - $data = (float) $data; |
|
374 | + $data=(float) $data; |
|
375 | 375 | break; |
376 | 376 | case 'b': // 布尔 |
377 | - $data = (boolean) $data; |
|
377 | + $data=(boolean) $data; |
|
378 | 378 | break; |
379 | 379 | case 's':// 字符串 |
380 | 380 | default: |
381 | - $data = (string) $data; |
|
381 | + $data=(string) $data; |
|
382 | 382 | } |
383 | 383 | } |
384 | 384 | } else { |
385 | 385 | // 变量默认值 |
386 | - $data = isset($default) ? $default : null; |
|
386 | + $data=isset($default) ? $default : null; |
|
387 | 387 | } |
388 | 388 | is_array($data) && array_walk_recursive($data, 'think_filter'); |
389 | 389 | return $data; |
390 | 390 | } |
391 | 391 | function array_map_recursive($filter, $data) |
392 | 392 | { |
393 | - $result = array(); |
|
393 | + $result=array(); |
|
394 | 394 | foreach ($data as $key => $val) { |
395 | - $result[$key] = is_array($val) |
|
395 | + $result[$key]=is_array($val) |
|
396 | 396 | ? array_map_recursive($filter, $val) |
397 | 397 | : call_user_func($filter, $val); |
398 | 398 | } |
@@ -404,18 +404,18 @@ discard block |
||
404 | 404 | |
405 | 405 | // 过滤查询特殊字符 |
406 | 406 | if (preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) { |
407 | - $value .= ' '; |
|
407 | + $value.=' '; |
|
408 | 408 | } |
409 | 409 | } |
410 | -function config($name=null,$value=null,$default=null){ |
|
410 | +function config($name=null, $value=null, $default=null) { |
|
411 | 411 | $config=\puck\conf::load(); |
412 | - if ($name===null){ |
|
412 | + if ($name === null) { |
|
413 | 413 | return $config->all(); |
414 | 414 | } |
415 | - if ($value===null){ |
|
416 | - return $config->get($name,$default); |
|
415 | + if ($value === null) { |
|
416 | + return $config->get($name, $default); |
|
417 | 417 | } |
418 | - $config->set($name,$value); |
|
418 | + $config->set($name, $value); |
|
419 | 419 | } |
420 | 420 | /** |
421 | 421 | * 字符串命名风格转换 |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | * @param integer $type 转换类型 |
425 | 425 | * @return string |
426 | 426 | */ |
427 | -function parse_name($name, $type = 0) { |
|
427 | +function parse_name($name, $type=0) { |
|
428 | 428 | if ($type) { |
429 | - return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {return strtoupper($match[1]);}, $name)); |
|
429 | + return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function($match) {return strtoupper($match[1]); }, $name)); |
|
430 | 430 | } else { |
431 | 431 | return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); |
432 | 432 | } |
@@ -39,8 +39,7 @@ discard block |
||
39 | 39 | { |
40 | 40 | if(isset($arr['status']) && $type==2){ |
41 | 41 | $ret=$arr; |
42 | - } |
|
43 | - else{ |
|
42 | + } else{ |
|
44 | 43 | $ret['status'] = $type; |
45 | 44 | $ret['data'] = $arr; |
46 | 45 | } |
@@ -157,7 +156,7 @@ discard block |
||
157 | 156 | // 重新生成id |
158 | 157 | session_regenerate_id(); |
159 | 158 | } |
160 | - }else { |
|
159 | + } else { |
|
161 | 160 | if (strpos($name, '.')) { |
162 | 161 | list($name1, $name2) = explode('.', $name); |
163 | 162 | return isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; |
@@ -62,6 +62,10 @@ |
||
62 | 62 | self::param(); |
63 | 63 | self::exec($class,ACTION_NAME); |
64 | 64 | } |
65 | + |
|
66 | + /** |
|
67 | + * @param string $function |
|
68 | + */ |
|
65 | 69 | static public function exec($class,$function){ |
66 | 70 | $method = new \ReflectionMethod($class, $function); |
67 | 71 | if ($method->isPublic() && !$method->isStatic()) { |
@@ -6,48 +6,48 @@ discard block |
||
6 | 6 | |
7 | 7 | class DispatchHelper |
8 | 8 | { |
9 | - static public function init(){ |
|
9 | + static public function init() { |
|
10 | 10 | define('NOW_TIME', $_SERVER['REQUEST_TIME']); |
11 | 11 | define('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']); |
12 | 12 | define('IS_GET', REQUEST_METHOD == 'GET' ? true : false); |
13 | 13 | define('IS_POST', REQUEST_METHOD == 'POST' ? true : false); |
14 | 14 | define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false); |
15 | 15 | define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false); |
16 | - define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ) ? true : false); |
|
16 | + define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) ? true : false); |
|
17 | 17 | define('__SELF__', strip_tags($_SERVER['REQUEST_URI'])); |
18 | 18 | } |
19 | - static public function dispatch($path='',$app='\\admin') { |
|
19 | + static public function dispatch($path='', $app='\\admin') { |
|
20 | 20 | self::init(); |
21 | - if($path==''){ |
|
21 | + if ($path == '') { |
|
22 | 22 | $path=array(); |
23 | - }else{ |
|
24 | - $path=str_replace('-','_',$path); |
|
25 | - $path = explode('/',$path); |
|
23 | + } else { |
|
24 | + $path=str_replace('-', '_', $path); |
|
25 | + $path=explode('/', $path); |
|
26 | 26 | } |
27 | 27 | |
28 | - if(count($path)==0){ |
|
29 | - array_push($path,'home'); |
|
30 | - array_push($path,'index'); |
|
28 | + if (count($path) == 0) { |
|
29 | + array_push($path, 'home'); |
|
30 | + array_push($path, 'index'); |
|
31 | 31 | } |
32 | - elseif (count($path)==1){ |
|
33 | - array_push($path,'index'); |
|
32 | + elseif (count($path) == 1) { |
|
33 | + array_push($path, 'index'); |
|
34 | 34 | } |
35 | - if(!empty($path)){ |
|
35 | + if (!empty($path)) { |
|
36 | 36 | $tmpAction=array_pop($path); |
37 | 37 | $tmpAction=preg_replace('/\.(html|aspx|do|php|htm|h5|api)$/i', '', $tmpAction); |
38 | - $tmpAction=parse_name($tmpAction,1); |
|
38 | + $tmpAction=parse_name($tmpAction, 1); |
|
39 | 39 | $var['a']=$tmpAction; |
40 | 40 | } |
41 | - define('ACTION_NAME',$var['a']); |
|
41 | + define('ACTION_NAME', $var['a']); |
|
42 | 42 | if (!preg_match('/^[A-Za-z](\w)*$/', ACTION_NAME)) { |
43 | 43 | die("error action"); |
44 | 44 | } |
45 | - if(!empty($path)){ |
|
45 | + if (!empty($path)) { |
|
46 | 46 | $tmpController=array_pop($path); |
47 | - $tmpController=parse_name($tmpController,1); |
|
47 | + $tmpController=parse_name($tmpController, 1); |
|
48 | 48 | $var['c']=$tmpController; |
49 | 49 | } |
50 | - define('CONTROLLER_NAME',$var['c']); |
|
50 | + define('CONTROLLER_NAME', $var['c']); |
|
51 | 51 | if (!preg_match('/^[A-Za-z](\/|\w)*$/', CONTROLLER_NAME)) { |
52 | 52 | die("error controller"); |
53 | 53 | } |
@@ -55,20 +55,20 @@ discard block |
||
55 | 55 | if (!class_exists($class)) { |
56 | 56 | not_found('this controller is can not work now!'); |
57 | 57 | } |
58 | - $class= new $class(); |
|
59 | - if (!method_exists($class,ACTION_NAME)) { |
|
58 | + $class=new $class(); |
|
59 | + if (!method_exists($class, ACTION_NAME)) { |
|
60 | 60 | not_found(); |
61 | 61 | } |
62 | 62 | self::param(); |
63 | - self::exec($class,ACTION_NAME); |
|
63 | + self::exec($class, ACTION_NAME); |
|
64 | 64 | } |
65 | - static public function exec($class,$function){ |
|
66 | - $method = new \ReflectionMethod($class, $function); |
|
65 | + static public function exec($class, $function) { |
|
66 | + $method=new \ReflectionMethod($class, $function); |
|
67 | 67 | if ($method->isPublic() && !$method->isStatic()) { |
68 | - $refClass = new \ReflectionClass($class); |
|
68 | + $refClass=new \ReflectionClass($class); |
|
69 | 69 | //前置方法 |
70 | - if ($refClass->hasMethod('_before_' . $function)) { |
|
71 | - $before = $refClass->getMethod('_before_' . $function); |
|
70 | + if ($refClass->hasMethod('_before_'.$function)) { |
|
71 | + $before=$refClass->getMethod('_before_'.$function); |
|
72 | 72 | if ($before->isPublic()) { |
73 | 73 | $before->invoke($class); |
74 | 74 | } |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | //方法本身 |
77 | 77 | $response=$method->invoke($class); |
78 | 78 | //后置方法 |
79 | - if ($refClass->hasMethod('_after_' . $function)) { |
|
80 | - $after = $refClass->getMethod('_after_' . $function); |
|
79 | + if ($refClass->hasMethod('_after_'.$function)) { |
|
80 | + $after=$refClass->getMethod('_after_'.$function); |
|
81 | 81 | if ($after->isPublic()) { |
82 | 82 | $after->invoke($class); |
83 | 83 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | self::render($response); |
86 | 86 | } |
87 | 87 | } |
88 | - static public function param(){ |
|
88 | + static public function param() { |
|
89 | 89 | $vars=array(); |
90 | - parse_str(parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY),$vars); |
|
90 | + parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $vars); |
|
91 | 91 | $_GET=$vars; |
92 | 92 | } |
93 | - static public function render($res){ |
|
93 | + static public function render($res) { |
|
94 | 94 | $response=$res; |
95 | - if(is_array($res)){ |
|
95 | + if (is_array($res)) { |
|
96 | 96 | $response=json($res); |
97 | 97 | } |
98 | 98 | echo $response; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | self::init(); |
21 | 21 | if($path==''){ |
22 | 22 | $path=array(); |
23 | - }else{ |
|
23 | + } else{ |
|
24 | 24 | $path=str_replace('-','_',$path); |
25 | 25 | $path = explode('/',$path); |
26 | 26 | } |
@@ -28,8 +28,7 @@ discard block |
||
28 | 28 | if(count($path)==0){ |
29 | 29 | array_push($path,'home'); |
30 | 30 | array_push($path,'index'); |
31 | - } |
|
32 | - elseif (count($path)==1){ |
|
31 | + } elseif (count($path)==1){ |
|
33 | 32 | array_push($path,'index'); |
34 | 33 | } |
35 | 34 | if(!empty($path)){ |
@@ -46,8 +46,8 @@ |
||
46 | 46 | * |
47 | 47 | * pass values when class is istantiated |
48 | 48 | * |
49 | - * @param numeric $_perPage sets the number of iteems per page |
|
50 | - * @param numeric $_instance sets the instance for the GET parameter |
|
49 | + * @param numeric $perPage sets the number of iteems per page |
|
50 | + * @param numeric $instance sets the instance for the GET parameter |
|
51 | 51 | */ |
52 | 52 | public function __construct($perPage,$instance){ |
53 | 53 | $this->_instance = $instance; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | namespace puck\helpers; |
5 | 5 | |
6 | -class PageHelper{ |
|
6 | +class PageHelper { |
|
7 | 7 | /** |
8 | 8 | * set the number of items per page. |
9 | 9 | * |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @var numeric |
39 | 39 | */ |
40 | - private $_totalRows = 0; |
|
40 | + private $_totalRows=0; |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @param numeric $_perPage sets the number of iteems per page |
50 | 50 | * @param numeric $_instance sets the instance for the GET parameter |
51 | 51 | */ |
52 | - public function __construct($perPage,$instance){ |
|
53 | - $this->_instance = $instance; |
|
54 | - $this->_perPage = $perPage; |
|
52 | + public function __construct($perPage, $instance) { |
|
53 | + $this->_instance=$instance; |
|
54 | + $this->_perPage=$perPage; |
|
55 | 55 | $this->set_instance(); |
56 | 56 | } |
57 | 57 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * creates the starting point for limiting the dataset |
62 | 62 | * @return numeric |
63 | 63 | */ |
64 | - public function get_start(){ |
|
64 | + public function get_start() { |
|
65 | 65 | return ($this->_page * $this->_perPage) - $this->_perPage; |
66 | 66 | } |
67 | 67 | |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @var numeric |
74 | 74 | */ |
75 | - private function set_instance(){ |
|
76 | - $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); |
|
77 | - $this->_page = ($this->_page == 0 ? 1 : $this->_page); |
|
75 | + private function set_instance() { |
|
76 | + $this->_page=(int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); |
|
77 | + $this->_page=($this->_page == 0 ? 1 : $this->_page); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @var numeric |
86 | 86 | */ |
87 | - public function set_total($_totalRows){ |
|
88 | - $this->_totalRows = $_totalRows; |
|
87 | + public function set_total($_totalRows) { |
|
88 | + $this->_totalRows=$_totalRows; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string |
97 | 97 | */ |
98 | - public function get_limit(){ |
|
98 | + public function get_limit() { |
|
99 | 99 | return "LIMIT ".$this->get_start().",$this->_perPage"; |
100 | 100 | } |
101 | 101 | |
102 | 102 | |
103 | - private function getParam(){ |
|
103 | + private function getParam() { |
|
104 | 104 | $vars=$_GET; |
105 | - if(isset($vars[$this->_instance])){ |
|
105 | + if (isset($vars[$this->_instance])) { |
|
106 | 106 | unset($vars[$this->_instance]); |
107 | 107 | } |
108 | 108 | $str=http_build_query($vars); |
109 | - $str ='&'.$str; |
|
109 | + $str='&'.$str; |
|
110 | 110 | return $str; |
111 | 111 | } |
112 | 112 | |
@@ -119,86 +119,86 @@ discard block |
||
119 | 119 | * @var sting $ext optionally pass in extra parameters to the GET |
120 | 120 | * @return string returns the html menu |
121 | 121 | */ |
122 | - public function page_links($path='?',$ext=null) |
|
122 | + public function page_links($path='?', $ext=null) |
|
123 | 123 | { |
124 | - $adjacents = "2"; |
|
125 | - $prev = $this->_page - 1; |
|
126 | - $next = $this->_page + 1; |
|
127 | - $lastpage = ceil($this->_totalRows/$this->_perPage); |
|
128 | - $lpm1 = $lastpage - 1; |
|
129 | - $pagination = ""; |
|
130 | - if($lastpage > 1) |
|
124 | + $adjacents="2"; |
|
125 | + $prev=$this->_page - 1; |
|
126 | + $next=$this->_page + 1; |
|
127 | + $lastpage=ceil($this->_totalRows / $this->_perPage); |
|
128 | + $lpm1=$lastpage - 1; |
|
129 | + $pagination=""; |
|
130 | + if ($lastpage > 1) |
|
131 | 131 | { |
132 | - if($ext==null){ |
|
132 | + if ($ext == null) { |
|
133 | 133 | $ext=$this->getParam(); |
134 | 134 | } |
135 | - $pagination .= "<ul class='pager'>"; |
|
135 | + $pagination.="<ul class='pager'>"; |
|
136 | 136 | if ($this->_page > 1) |
137 | - $pagination.= "<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
137 | + $pagination.="<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
138 | 138 | else |
139 | - $pagination.= "<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
139 | + $pagination.="<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
140 | 140 | |
141 | 141 | if ($lastpage < 7 + ($adjacents * 2)) |
142 | 142 | { |
143 | - for ($counter = 1; $counter <= $lastpage; $counter++) |
|
143 | + for ($counter=1; $counter <= $lastpage; $counter++) |
|
144 | 144 | { |
145 | 145 | if ($counter == $this->_page) |
146 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
146 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
147 | 147 | else |
148 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
148 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
149 | 149 | } |
150 | 150 | } |
151 | - elseif($lastpage > 5 + ($adjacents * 2)) |
|
151 | + elseif ($lastpage > 5 + ($adjacents * 2)) |
|
152 | 152 | { |
153 | - if($this->_page < 1 + ($adjacents * 2)) |
|
153 | + if ($this->_page < 1 + ($adjacents * 2)) |
|
154 | 154 | { |
155 | - for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) |
|
155 | + for ($counter=1; $counter < 4 + ($adjacents * 2); $counter++) |
|
156 | 156 | { |
157 | 157 | if ($counter == $this->_page) |
158 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
158 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
159 | 159 | else |
160 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
160 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
161 | 161 | } |
162 | - $pagination.= "..."; |
|
163 | - $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
164 | - $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
162 | + $pagination.="..."; |
|
163 | + $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
164 | + $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
165 | 165 | } |
166 | - elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
166 | + elseif ($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
167 | 167 | { |
168 | - $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
169 | - $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
170 | - $pagination.= "..."; |
|
171 | - for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
|
168 | + $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
169 | + $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
170 | + $pagination.="..."; |
|
171 | + for ($counter=$this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
|
172 | 172 | { |
173 | 173 | if ($counter == $this->_page) |
174 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
174 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
175 | 175 | else |
176 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
176 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
177 | 177 | } |
178 | - $pagination.= ".."; |
|
179 | - $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
180 | - $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
178 | + $pagination.=".."; |
|
179 | + $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
180 | + $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
181 | 181 | } |
182 | 182 | else |
183 | 183 | { |
184 | - $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
185 | - $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
186 | - $pagination.= ".."; |
|
187 | - for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
|
184 | + $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
185 | + $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
186 | + $pagination.=".."; |
|
187 | + for ($counter=$lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
|
188 | 188 | { |
189 | 189 | if ($counter == $this->_page) |
190 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
190 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
191 | 191 | else |
192 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
192 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | if ($this->_page < $counter - 1) |
198 | - $pagination.= "<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
198 | + $pagination.="<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
199 | 199 | else |
200 | - $pagination.= "<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
201 | - $pagination.= "</ul>\n"; |
|
200 | + $pagination.="<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
201 | + $pagination.="</ul>\n"; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 |
@@ -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 |
@@ -17,57 +17,57 @@ |
||
17 | 17 | protected $limitCount=null; |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - if(!$this->dbConn){ |
|
20 | + if (!$this->dbConn) { |
|
21 | 21 | $this->dbConn='main'; |
22 | 22 | } |
23 | - $this->db = mysql::getDb($this->dbConn); |
|
23 | + $this->db=mysql::getDb($this->dbConn); |
|
24 | 24 | } |
25 | - public function __call($method,$arg){ |
|
25 | + public function __call($method, $arg) { |
|
26 | 26 | $ret=$this; |
27 | - if(method_exists ($this->db, $method)){ |
|
28 | - $ret=call_user_func_array(array($this->db,$method),$arg); |
|
27 | + if (method_exists($this->db, $method)) { |
|
28 | + $ret=call_user_func_array(array($this->db, $method), $arg); |
|
29 | 29 | } |
30 | - return $ret==$this->db? $this: $ret; |
|
30 | + return $ret == $this->db ? $this : $ret; |
|
31 | 31 | } |
32 | - public function __get($name){ |
|
33 | - if(property_exists($this->db, $name)){ |
|
32 | + public function __get($name) { |
|
33 | + if (property_exists($this->db, $name)) { |
|
34 | 34 | return $this->db->$name; |
35 | 35 | } |
36 | - throw new MemberAccessException('model Property ' . $name . ' not exists'); |
|
36 | + throw new MemberAccessException('model Property '.$name.' not exists'); |
|
37 | 37 | } |
38 | - public function limit($limit){ |
|
38 | + public function limit($limit) { |
|
39 | 39 | $this->limitCount=$limit; |
40 | 40 | return $this; |
41 | 41 | } |
42 | - public function find(){ |
|
43 | - return $this->db->getOne($this->table,$this->field); |
|
42 | + public function find() { |
|
43 | + return $this->db->getOne($this->table, $this->field); |
|
44 | 44 | } |
45 | - public function select(){ |
|
46 | - return $this->db->get($this->table,$this->limitCount?$this->limitCount:null,$this->field); |
|
45 | + public function select() { |
|
46 | + return $this->db->get($this->table, $this->limitCount ? $this->limitCount : null, $this->field); |
|
47 | 47 | } |
48 | - public function count(){ |
|
48 | + public function count() { |
|
49 | 49 | return $this->db->count; |
50 | 50 | } |
51 | - public function table($table){ |
|
51 | + public function table($table) { |
|
52 | 52 | $this->table=$table; |
53 | 53 | return $this; |
54 | 54 | } |
55 | - public function add($data){ |
|
56 | - return $this->db->insert($this->table,$data); |
|
55 | + public function add($data) { |
|
56 | + return $this->db->insert($this->table, $data); |
|
57 | 57 | } |
58 | - public function update($data){ |
|
59 | - return $this->db->update($this->table,$data); |
|
58 | + public function update($data) { |
|
59 | + return $this->db->update($this->table, $data); |
|
60 | 60 | } |
61 | - public function field($field){ |
|
61 | + public function field($field) { |
|
62 | 62 | $this->field=$field; |
63 | 63 | return $this; |
64 | 64 | } |
65 | - public function delete(){ |
|
65 | + public function delete() { |
|
66 | 66 | return $this->db->delete($this->table); |
67 | 67 | } |
68 | - public function page($page,$pageLimit='10'){ |
|
68 | + public function page($page, $pageLimit='10') { |
|
69 | 69 | $this->db->pageLimit=$pageLimit; |
70 | - $info= $this->db->paginate($this->table,$page); |
|
70 | + $info=$this->db->paginate($this->table, $page); |
|
71 | 71 | return $info; |
72 | 72 | } |
73 | 73 | } |
74 | 74 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | namespace puck\helpers; |
10 | 10 | |
11 | 11 | use Overtrue\Pinyin\Pinyin; |
12 | -class PinYinHelper extends Pinyin{ |
|
12 | +class PinYinHelper extends Pinyin { |
|
13 | 13 | |
14 | 14 | public function noun($str) { |
15 | 15 | $pinyinArr=$this->convert($str); |
@@ -17,6 +17,6 @@ discard block |
||
17 | 17 | //首字母转大写 |
18 | 18 | $pinyin[0]=strtoupper($pinyin[0]); |
19 | 19 | } |
20 | - return implode('',$pinyinArr); |
|
20 | + return implode('', $pinyinArr); |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -9,11 +9,11 @@ |
||
9 | 9 | namespace puck; |
10 | 10 | |
11 | 11 | |
12 | -class mysql extends \MysqliDb{ |
|
12 | +class mysql extends \MysqliDb { |
|
13 | 13 | |
14 | - static public function getDb($db){ |
|
14 | + static public function getDb($db) { |
|
15 | 15 | static $dbList; |
16 | - if(!isset($dbList[$db])){ |
|
16 | + if (!isset($dbList[$db])) { |
|
17 | 17 | $dbList[$db]=new \MysqliDb(config('db.'.$db)); |
18 | 18 | } |
19 | 19 | return $dbList[$db]; |
@@ -2,13 +2,13 @@ |
||
2 | 2 | @ini_set('date.timezone', 'Asia/Shanghai'); |
3 | 3 | @header('content-type:text/html;charset=utf-8'); |
4 | 4 | |
5 | -define('EXPORT_PATH',__DIR__); |
|
5 | +define('EXPORT_PATH', __DIR__); |
|
6 | 6 | |
7 | -if(DEBUG){ |
|
7 | +if (DEBUG) { |
|
8 | 8 | error_reporting(E_ALL); |
9 | 9 | @ini_set('display_errors', 'On'); |
10 | 10 | @ob_start(); |
11 | - $whoops = new \Whoops\Run; |
|
11 | + $whoops=new \Whoops\Run; |
|
12 | 12 | $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); |
13 | 13 | $whoops->register(); |
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -11,8 +11,8 @@ |
||
11 | 11 | |
12 | 12 | class conf { |
13 | 13 | static $config=false; |
14 | - static public function load(){ |
|
15 | - if(!self::$config){ |
|
14 | + static public function load() { |
|
15 | + if (!self::$config) { |
|
16 | 16 | self::$config=Config::load(BASE_PATH.'/app/conf'); |
17 | 17 | } |
18 | 18 | return self::$config; |