|
@@ -6,9 +6,12 @@ use Dever;
|
|
|
|
|
|
class Handle
|
|
|
{
|
|
|
- public function get($url)
|
|
|
+ public function get($type, $url, $param)
|
|
|
{
|
|
|
- $where['key'] = md5($url);
|
|
|
+ $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);
|
|
|
|
|
@@ -16,19 +19,28 @@ class Handle
|
|
|
$id = $info['id'];
|
|
|
} else {
|
|
|
$where['url'] = $url;
|
|
|
+ $where['param'] = $param;
|
|
|
$id = Dever::db('short/info')->insert($where);
|
|
|
}
|
|
|
|
|
|
- return Dever::idtostr($id);
|
|
|
+ return $type['host'] . Dever::uid($id);
|
|
|
}
|
|
|
|
|
|
public function show($str)
|
|
|
{
|
|
|
- $id = Dever::strtoid($str);
|
|
|
+ $id = Dever::uid($str, 'decode');
|
|
|
if ($id && $id > 0) {
|
|
|
$info = Dever::db('short/info')->one($id);
|
|
|
if ($info && $info['url']) {
|
|
|
- Dever::location($info['url']);
|
|
|
+ $param = json_decode($info['param'], true);
|
|
|
+ foreach ($param as $k => $v) {
|
|
|
+ if (strstr($v, '|')) {
|
|
|
+ $temp = explode('|', $v);
|
|
|
+ $v = Dever::load($temp[1], $temp[0]);
|
|
|
+ $param[$k] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Dever::location($info['url'] . '?' . http_build_query($param));
|
|
|
}
|
|
|
}
|
|
|
|