12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace Short\Lib;
- use Dever;
- class Handle
- {
- public function showUrl($id)
- {
- $info = Dever::db('short/info')->one($id);
- $type = Dever::db('short/type')->one($info['type']);
- return $type['host'] . Dever::uid($id);
- }
- public function get($type, $url, $param, $host = '')
- {
- $param = json_encode($param);
- $where['type'] = $type;
- $type = Dever::db('short/type')->one($type);
- $where['key'] = md5($url . '?' . $param);
- $info = Dever::db('short/info')->one($where);
- if ($info) {
- $id = $info['id'];
- } else {
- $where['url'] = $url;
- $where['param'] = $param;
- $id = Dever::db('short/info')->insert($where);
- }
- if ($host) {
- $type['host'] = $host;
- }
- return $type['host'] . Dever::uid($id);
- }
- public function show($str)
- {
- $id = Dever::uid($str, 'decode');
- if ($id && $id > 0) {
- $info = Dever::db('short/info')->one($id);
- if ($info && $info['url']) {
- if ($info['param']) {
- $param = Dever::json_decode($info['param']);
- if ($param) {
- foreach ($param as $k => $v) {
- if (strstr($v, '|')) {
- $temp = explode('|', $v);
- $v = Dever::load($temp[1], $temp[0]);
- $param[$k] = $v;
- }
- }
- if (strstr($info['url'], '?')) {
- $info['url'] .= '&' . http_build_query($param);
- } else {
- $info['url'] .= '?' . http_build_query($param);
- }
- }
- }
-
- Dever::location($info['url']);
- }
- }
- return 'error';
- }
- }
|