table_common_block.php
4.37 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
112
113
114
115
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_common_block.php 29175 2012-03-28 04:02:34Z zhangguosheng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_common_block extends discuz_table
{
public $cache_ttl;
public $allowmem;
public function __construct() {
$this->_table = 'common_block';
$this->_pk = 'bid';
parent::__construct();
$this->_allowmem = null;
$this->cache_ttl = $this->_cache_ttl = getglobal('setting/memory/diyblock');
$this->allowmem = $this->_cache_ttl !== null && memory('check');
}
public function fetch($bid) {
if(($block = parent::fetch(dintval($bid)))) {
$block['param'] = $block['param'] ? dunserialize($block['param']) : array();
}
return $block;
}
public function count_by_admincpwhere($wheresql) {
$wheresql = $wheresql ? ' WHERE '.(string)$wheresql : '';
return DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).' b LEFT JOIN '.DB::table('common_template_block').' tb ON tb.bid=b.bid'.$wheresql);
}
public function fetch_all_by_admincpwhere($wheresql, $ordersql, $start, $limit) {
$wheresql = $wheresql ? ' WHERE '.(string)$wheresql : '';
return DB::fetch_all('SELECT b.*, tb.targettplname FROM '.DB::table($this->_table).' b LEFT JOIN '.DB::table('common_template_block').' tb ON tb.bid=b.bid'.$wheresql.' '.(string)$ordersql.DB::limit($start, $limit), null, $this->_pk ? $this->_pk : '');
}
public function update_by_styleid($styleid, $data) {
return ($styleid = dintval($styleid, true)) && !empty($data) && is_array($data) ? DB::update($this->_table, $data, DB::field('styleid', $styleid)) : false;
}
public function fetch_by_styleid($styleid) {
return ($styleid = dintval($styleid, true)) ? DB::fetch_first('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('styleid', $styleid).' LIMIT 1') : array();
}
public function fetch_all_bid_by_blocktype($blocktype, $limit = 1000) {
$data = array();
if ($blocktype !== null && ($data = DB::fetch_all('SELECT bid FROM '.DB::table($this->_table).' WHERE '.DB::field('blocktype', $blocktype).' ORDER BY bid DESC'.DB::limit($limit), null, $this->_pk))) {
$data = array_keys($data);
}
return $data;
}
public function update_dateline_to_expired($bids, $timestamp) {
return ($bids = dintval($bids, true)) && ($timestamp = dintval($timestamp)) ? DB::query('UPDATE '.DB::table($this->_table).' SET `dateline`='.$timestamp.'-cachetime WHERE bid IN ('.dimplode($bids).') AND cachetime>0') : false;
}
public function fetch_all_recommended_block($id, $idtype, $wherearr = array(), $leftjoin = '', $fields = '') {
$data = array();
if(($id = dintval($id)) && $idtype) {
$where = $wherearr ? ' AND '.implode(' AND ', $wherearr) : '';
$data = DB::fetch_all("SELECT bi.dataid,bi.uid,bi.username,bi.dateline,bi.isverified,bi.verifiedtime,b.bid,b.blockclass,b.name,b.script$fields FROM ".DB::table('common_block').' b
LEFT JOIN '.DB::table('common_block_item_data')." bi ON b.bid=bi.bid $leftjoin WHERE bi.id='$id' AND bi.idtype='$idtype'$where ORDER BY b.bid DESC", null, 'bid');
}
return $data;
}
public function count_by_where($wheresql, $leftjoin = '') {
return DB::result_first("SELECT COUNT(*) FROM ".DB::table($this->_table).' b'." $leftjoin $wheresql");
}
public function fetch_all_by_where($wheresql, $start = 0, $limit = 0, $leftjoin = '', $fields = '') {
return DB::fetch_all("SELECT b.bid,b.blockclass,b.name,b.script,b.param$fields FROM ".DB::table($this->_table).' b'." $leftjoin $wheresql ORDER BY b.bid DESC ".DB::limit($start, $limit));
}
public function update($val, $data, $unbuffered = false, $low_priority = false) {
if(($val = dintval($val, true)) && $data && is_array($data)) {
$ret = parent::update($val, $data, $unbuffered, $low_priority);
$this->clear_cache($val);
return $ret;
}
return false;
}
public function delete($val, $unbuffered = false) {
if(($val = dintval($val, true))) {
$ret = parent::delete($val, $unbuffered);
$this->clear_cache($val);
return $ret;
}
return false;
}
public function clear_cache($bids) {
if($this->allowmem) {
memory('rm', $bids,'blockcache_');
memory('rm', $bids, 'blockcache_htm_');
memory('rm', $bids, 'blockcache_js_');
}
}
}
?>