1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace Short\Lib;
- use Dever;
- class Handle
- {
- public function showUrl_api($id)
- {
- $info = Dever::db('short/info')->one($id);
- $type = Dever::db('short/type')->one($info['type_id']);
- $host = Dever::db('short/host')->one($info['host_id']);
- return $host['name'] . Dever::encode($id);
- }
- public function get($host_id, $url, $param, $host = '')
- {
- $param = json_encode($param);
- $where['host_id'] = $host_id;
- $host = Dever::db('short/host')->one($host_id);
- $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) {
- $host['name'] = $host;
- }
- return $host['name'] . Dever::uid($id);
- }
- public function show($str)
- {
- $id = Dever::decode($str);
- 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';
- }
- }
|