Handle.php 701 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Short\Lib;
  3. use Dever;
  4. class Handle
  5. {
  6. public function get($url)
  7. {
  8. $where['key'] = md5($url);
  9. $info = Dever::db('short/info')->one($where);
  10. if ($info) {
  11. $id = $info['id'];
  12. } else {
  13. $where['url'] = $url;
  14. $id = Dever::db('short/info')->insert($where);
  15. }
  16. return Dever::idtostr($id);
  17. }
  18. public function show($str)
  19. {
  20. $id = Dever::strtoid($str);
  21. if ($id && $id > 0) {
  22. $info = Dever::db('short/info')->one($id);
  23. if ($info && $info['url']) {
  24. Dever::location($info['url']);
  25. }
  26. }
  27. return 'error';
  28. }
  29. }