block_topic.php
5.18 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: block_topic.php 31470 2012-08-31 03:29:50Z zhangguosheng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class block_topic extends discuz_block {
var $setting = array();
function block_topic() {
$this->setting = array(
'topicids' => array(
'title' => 'topiclist_topicids',
'type' => 'text',
'value' => ''
),
'uids' => array(
'title' => 'topiclist_uids',
'type' => 'text',
'value' => ''
),
'picrequired' => array(
'title' => 'topiclist_picrequired',
'type' => 'radio',
'default' => '0'
),
'orderby' => array(
'title' => 'topiclist_orderby',
'type' => 'mradio',
'value' => array(
array('dateline', 'topiclist_orderby_dateline'),
array('viewnum', 'topiclist_orderby_viewnum')
),
'default' => 'dateline'
),
'titlelength' => array(
'title' => 'topiclist_titlelength',
'type' => 'text',
'default' => 40
),
'summarylength' => array(
'summary' => 'topiclist_summarylength',
'type' => 'text',
'default' => 80
),
'startrow' => array(
'title' => 'topiclist_startrow',
'type' => 'text',
'default' => 0
),
);
}
function name() {
return lang('blockclass', 'blockclass_topic_script_topic');
}
function blockclass() {
return array('topic', lang('blockclass', 'blockclass_portal_topic'));
}
function fields() {
return array(
'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
'url' => array('name' => lang('blockclass', 'blockclass_topic_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
'title' => array('name' => lang('blockclass', 'blockclass_topic_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
'pic' => array('name' => lang('blockclass', 'blockclass_topic_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
'summary' => array('name' => lang('blockclass', 'blockclass_topic_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
'uid' => array('name' => lang('blockclass', 'blockclass_topic_field_uid'), 'formtype' => 'text', 'datatype' => 'int'),
'username' => array('name' => lang('blockclass', 'blockclass_topic_field_username'), 'formtype' => 'text', 'datatype' => 'string'),
'dateline' => array('name' => lang('blockclass', 'blockclass_topic_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
'viewnum' => array('name' => lang('blockclass', 'blockclass_topic_field_viewnum'), 'formtype' => 'text', 'datatype' => 'int'),
);
}
function getsetting() {
global $_G;
$settings = $this->setting;
return $settings;
}
function getdata($style, $parameter) {
global $_G;
$parameter = $this->cookparameter($parameter);
$topicids = !empty($parameter['topicids']) ? explode(',',$parameter['topicids']) : array();
$uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
$startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
$items = isset($parameter['items']) ? intval($parameter['items']) : 10;
$titlelength = $parameter['titlelength'] ? intval($parameter['titlelength']) : 40;
$summarylength = $parameter['summarylength'] ? intval($parameter['summarylength']) : 80;
$orderby = isset($parameter['orderby']) && in_array($parameter['orderby'],array('dateline', 'viewnum')) ? $parameter['orderby'] : 'dateline';
$picrequired = !empty($parameter['picrequired']) ? 1 : 0;
$bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
$datalist = $list = array();
$wherearr = array();
if($topicids) {
$wherearr[] = 'topicid IN ('.dimplode($topicids).')';
}
if($bannedids) {
$wherearr[] = 'topicid NOT IN ('.dimplode($bannedids).')';
}
if($uids) {
$wherearr[] = 'uid IN ('.dimplode($uids).')';
}
if($picrequired) {
$wherearr[] = "cover != ''";
}
$wherearr[] = "closed = '0'";
require_once libfile('function/portal');
foreach(C::t('portal_topic')->fetch_all_by_search_where($wherearr, "ORDER BY $orderby DESC", $startrow, $items) as $data) {
if(empty($data['cover'])) {
$data['cover'] = STATICURL.'image/common/nophoto.gif';
$data['picflag'] = '0';
}
$list[] = array(
'id' => $data['topicid'],
'idtype' => 'topicid',
'title' => cutstr($data['title'], $titlelength, ''),
'url' => !empty($_G['setting']['makehtml']['flag']) && !empty($_G['setting']['makehtml']['topichtmldir']) && !$data['htmlmade'] ? fetch_topic_url($data) : 'portal.php?mod=topic&topic='.$data['name'],
'pic' => $data['cover'] ? $data['cover'] : '',
'picflag' => $data['picflag'] ? $data['picflag'] : '',
'summary' => $data['summary'] ? cutstr($data['summary'], $summarylength, '') : '',
'fields' => array(
'fulltitle' => $data['title'],
'uid'=>$data['uid'],
'username'=>$data['username'],
'dateline'=>$data['dateline'],
'viewnum'=>$data['viewnum'],
)
);
}
return array('html' => '', 'data' => $list);
}
}
?>