table_common_smiley.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_common_smiley.php 28700 2012-03-08 06:23:29Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_smiley extends discuz_table
  12. {
  13. private $allowtype = array('smiley','stamp','stamplist');
  14. public function __construct() {
  15. $this->_table = 'common_smiley';
  16. $this->_pk = 'id';
  17. parent::__construct();
  18. }
  19. public function fetch_all_by_type($type) {
  20. $type = $this->checktype($type);
  21. if(empty($type)) {
  22. return array();
  23. }
  24. $typesql = is_array($type) ? 'type IN(%n)' : 'type=%s';
  25. return DB::fetch_all("SELECT * FROM %t WHERE $typesql ORDER BY displayorder", array($this->_table, $type), $this->_pk);
  26. }
  27. public function fetch_all_by_typeid_type($typeid, $type, $start = 0, $limit = 0) {
  28. return DB::fetch_all('SELECT * FROM %t WHERE typeid=%d AND type=%s ORDER BY displayorder '.DB::limit($start, $limit), array($this->_table, $typeid, $type), $this->_pk);
  29. }
  30. public function fetch_all_by_type_code_typeid($type, $typeid) {
  31. return DB::fetch_all("SELECT * FROM %t WHERE type=%s AND code<>'' AND typeid=%d ORDER BY displayorder ", array($this->_table, $type, $typeid), $this->_pk);
  32. }
  33. public function fetch_all_cache() {
  34. return DB::fetch_all("SELECT s.id, s.code, s.url, t.typeid FROM %t s INNER JOIN %t t ON t.typeid=s.typeid WHERE s.type='smiley' AND s.code<>'' AND t.available='1' ORDER BY LENGTH(s.code) DESC", array($this->_table, 'forum_imagetype'));
  35. }
  36. public function fetch_by_id_type($id, $type) {
  37. return DB::fetch_first('SELECT * FROM %t WHERE id=%d AND type=%s', array($this->_table, $id, $type), $this->_pk);
  38. }
  39. public function update_by_type($type, $data) {
  40. if(!empty($data) && is_array($data) && in_array($type, $this->allowtype)) {
  41. return DB::update($this->_table, $data, DB::field('type', $type));
  42. }
  43. return 0;
  44. }
  45. public function update_by_id_type($id, $type, $data) {
  46. $id = dintval($id, true);
  47. if(!empty($data) && is_array($data) && $id && in_array($type, $this->allowtype)) {
  48. return DB::update($this->_table, $data, DB::field('id', $id).' AND '.DB::field('type', $type));
  49. }
  50. return 0;
  51. }
  52. public function update_code_by_typeid($typeid) {
  53. $typeid = dintval($typeid, true);
  54. if(empty($typeid)) {
  55. return 0;
  56. }
  57. $typeidsql = is_array($typeid) ? 'typeid IN(%n)' : 'typeid=%d';
  58. return DB::query("UPDATE %t SET code=CONCAT('{:', typeid, '_', id, ':}') WHERE $typeidsql", array($this->_table, $typeid));
  59. }
  60. public function update_code_by_id($ids) {
  61. $ids = dintval($ids, true);
  62. if(empty($ids)) {
  63. return 0;
  64. }
  65. $idssql = is_array($ids) ? 'id IN(%n)' : 'id=%d';
  66. return DB::query("UPDATE %t SET code=CONCAT('{:', typeid, '_', id, ':}') WHERE $idssql", array($this->_table, $ids));
  67. }
  68. public function count_by_type($type) {
  69. $type = $this->checktype($type);
  70. if(empty($type)) {
  71. return 0;
  72. }
  73. return DB::result_first('SELECT COUNT(*) FROM %t WHERE type IN(%n)', array($this->_table, $type));
  74. }
  75. public function count_by_typeid($typeid) {
  76. return DB::result_first('SELECT COUNT(*) FROM %t WHERE typeid=%d', array($this->_table, $typeid));
  77. }
  78. public function count_by_type_typeid($type, $typeid) {
  79. $typeid = dintval($typeid, true);
  80. if(!empty($typeid) && in_array($type, $this->allowtype)) {
  81. return DB::result_first('SELECT COUNT(*) FROM %t WHERE type=%s AND typeid IN(%n)', array($this->_table, $type, $typeid));
  82. }
  83. return 0;
  84. }
  85. public function count_by_type_code_typeid($type, $typeid) {
  86. return DB::result_first("SELECT COUNT(*) FROM %t WHERE type=%s AND code<>'' AND typeid=%d", array($this->_table, $type, $typeid));
  87. }
  88. private function checktype($type) {
  89. if(is_array($type)) {
  90. foreach($type as $key => $val) {
  91. if(!in_array($val, $this->allowtype)) {
  92. unset($type[$key]);
  93. }
  94. }
  95. } else {
  96. $type = in_array($type, $this->allowtype) ? $type : '';
  97. }
  98. return $type;
  99. }
  100. }
  101. ?>