table_baidusubmit_sitemap.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. if (!defined('IN_DISCUZ')) {
  3. exit('Access Denied');
  4. }
  5. class table_baidusubmit_sitemap extends discuz_table
  6. {
  7. public function __construct()
  8. {
  9. $this->_table = 'baidusubmit_sitemap';
  10. parent::__construct();
  11. }
  12. public function add($url, $type, $start, $end)
  13. {
  14. $create_time = time();
  15. return DB::query('INSERT INTO %t(url, type, create_time,start,end) values(%s, %d, %d, %d, %d)', array($this->_table, $url, $type, $create_time, $start, $end));
  16. }
  17. public function get_max_end($type)
  18. {
  19. return DB::result_first('SELECT MAX(end) FROM %t WHERE type = %d', array($this->_table, $type));
  20. }
  21. public function get_sitemap_count($type)
  22. {
  23. return DB::result_first('SELECT COUNT(*) FROM %t WHERE type = %d', array($this->_table, $type));
  24. }
  25. public function get_sitemap_list($type, $offset = 0, $limit = 0)
  26. {
  27. if ($offset >= 0 && $limit > 0) {
  28. return DB::fetch_all('SELECT * FROM %t WHERE type=%d LIMIT %d, %d', array($this->_table, $type, $offset, $limit));
  29. }
  30. return DB::fetch_all('SELECT * FROM %t WHERE type=%d', array($this->_table, $type));
  31. }
  32. public function delete_history($time, $type = 2)
  33. {
  34. return DB::query('DELETE FROM %t WHERE type=%d and end<=%d', array($this->_table, $type, $time));
  35. }
  36. public function get_by_start($type, $start, $end = 0)
  37. {
  38. $sql = 'SELECT * FROM %t WHERE type=%d AND start=%d';
  39. $params = array($this->_table, $type, $start);
  40. if ($end > 0) {
  41. $sql .= ' AND end=%d';
  42. $params[] = $end;
  43. }
  44. return DB::fetch_first($sql, $params);
  45. }
  46. public function update_by_sid($sid, array $values)
  47. {
  48. $sql = 'UPDATE %t SET ';
  49. $params = array($this->_table);
  50. foreach ($values as $key => $val) {
  51. $sql .= ('url' === $key) ? "$key = %s," : "$key = %d,";
  52. $params[] = $val;
  53. }
  54. $params[] = $sid;
  55. DB::query(rtrim($sql, ', ') . ' WHERE sid=%d', $params);
  56. }
  57. public function deleteByType($type)
  58. {
  59. return DB::query('DELETE FROM %t WHERE type=%d', array($this->_table, $type));
  60. }
  61. }