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