|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @package Board3 Portal v2.1 |
|
5
|
|
|
* @copyright (c) 2013 Board3 Group ( www.board3.de ) |
|
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace board3\portal\modules; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @package Poll |
|
14
|
|
|
*/ |
|
15
|
|
|
class poll extends module_base |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Allowed columns: Just sum up your options (Exp: left + right = 10) |
|
19
|
|
|
* top 1 |
|
20
|
|
|
* left 2 |
|
21
|
|
|
* center 4 |
|
22
|
|
|
* right 8 |
|
23
|
|
|
* bottom 16 |
|
24
|
|
|
*/ |
|
25
|
|
|
public $columns = 31; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Default modulename |
|
29
|
|
|
*/ |
|
30
|
|
|
public $name = 'PORTAL_POLL'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Default module-image: |
|
34
|
|
|
* file must be in "{T_THEME_PATH}/images/portal/" |
|
35
|
|
|
*/ |
|
36
|
|
|
public $image_src = 'portal_poll.png'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* module-language file |
|
40
|
|
|
* file must be in "language/{$user->lang}/mods/portal/" |
|
41
|
|
|
*/ |
|
42
|
|
|
public $language = 'portal_poll_module'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* custom acp template |
|
46
|
|
|
* file must be in "adm/style/portal/" |
|
47
|
|
|
*/ |
|
48
|
|
|
public $custom_acp_tpl = ''; |
|
49
|
|
|
|
|
50
|
|
|
/** @var \phpbb\auth\auth */ |
|
51
|
|
|
protected $auth; |
|
52
|
|
|
|
|
53
|
|
|
/** @var \phpbb\config\config */ |
|
54
|
|
|
protected $config; |
|
55
|
|
|
|
|
56
|
|
|
/** @var \phpbb\template */ |
|
57
|
|
|
protected $template; |
|
58
|
|
|
|
|
59
|
|
|
/** @var \phpbb\db\driver */ |
|
60
|
|
|
protected $db; |
|
61
|
|
|
|
|
62
|
|
|
/** @var \phpbb\request\request */ |
|
63
|
|
|
protected $request; |
|
64
|
|
|
|
|
65
|
|
|
/** @var string PHP file extension */ |
|
66
|
|
|
protected $php_ext; |
|
67
|
|
|
|
|
68
|
|
|
/** @var string phpBB root path */ |
|
69
|
|
|
protected $phpbb_root_path; |
|
70
|
|
|
|
|
71
|
|
|
/** @var \phpbb\user */ |
|
72
|
|
|
protected $user; |
|
73
|
|
|
|
|
74
|
|
|
/** @var \board3\portal\includes\modules_helper */ |
|
75
|
|
|
protected $modules_helper; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Construct a poll object |
|
79
|
|
|
* |
|
80
|
|
|
* @param \phpbb\auth\auth $auth phpBB auth service |
|
81
|
|
|
* @param \phpbb\config\config $config phpBB config |
|
82
|
|
|
* @param \phpbb\db\driver $db Database driver |
|
83
|
|
|
* @param \phpbb\request\request $request phpBB request |
|
84
|
|
|
* @param \phpbb\template $template phpBB template |
|
85
|
|
|
* @param string $phpEx php file extension |
|
86
|
|
|
* @param string $phpbb_root_path phpBB root path |
|
87
|
|
|
* @param \phpbb\user $user phpBB user object |
|
88
|
|
|
* @param \board3\portal\includes\modules_helper $modules_helper Modules helper |
|
89
|
|
|
*/ |
|
90
|
|
View Code Duplication |
public function __construct($auth, $config, $db, $request, $template, $phpbb_root_path, $phpEx, $user, $modules_helper) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->auth = $auth; |
|
93
|
|
|
$this->config = $config; |
|
94
|
|
|
$this->db = $db; |
|
95
|
|
|
$this->request = $request; |
|
96
|
|
|
$this->template = $template; |
|
97
|
|
|
$this->php_ext = $phpEx; |
|
98
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
|
99
|
|
|
$this->user = $user; |
|
100
|
|
|
$this->modules_helper = $modules_helper; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritdoc} |
|
105
|
|
|
*/ |
|
106
|
|
|
public function get_template_center($module_id) |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->parse_template($module_id); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* {@inheritdoc} |
|
113
|
|
|
*/ |
|
114
|
|
|
public function get_template_side($module_id) |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->parse_template($module_id, 'side'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* {@inheritdoc} |
|
121
|
|
|
*/ |
|
122
|
|
|
public function get_template_acp($module_id) |
|
123
|
|
|
{ |
|
124
|
|
|
return array( |
|
125
|
|
|
'title' => 'ACP_PORTAL_POLLS_SETTINGS', |
|
126
|
|
|
'vars' => array( |
|
127
|
|
|
'legend1' => 'ACP_PORTAL_POLLS_SETTINGS', |
|
128
|
|
|
'board3_poll_topic_id_' . $module_id => array('lang' => 'PORTAL_POLL_TOPIC_ID' , 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')), |
|
129
|
|
|
'board3_poll_exclude_id_' . $module_id => array('lang' => 'PORTAL_POLL_EXCLUDE_ID' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
130
|
|
|
'board3_poll_limit_' . $module_id => array('lang' => 'PORTAL_POLL_LIMIT' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), |
|
131
|
|
|
'board3_poll_allow_vote_' . $module_id => array('lang' => 'PORTAL_POLL_ALLOW_VOTE' , 'validate' => 'ibool', 'type' => 'radio:yes_no', 'explain' => true), |
|
132
|
|
|
'board3_poll_hide_' . $module_id => array('lang' => 'PORTAL_POLL_HIDE' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
133
|
|
|
) |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* {@inheritdoc} |
|
139
|
|
|
*/ |
|
140
|
|
|
public function install($module_id) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->config->set('board3_poll_allow_vote_' . $module_id, 1); |
|
143
|
|
|
$this->config->set('board3_poll_topic_id_' . $module_id, ''); |
|
144
|
|
|
$this->config->set('board3_poll_exclude_id_' . $module_id, 0); |
|
145
|
|
|
$this->config->set('board3_poll_hide_' . $module_id, 0); |
|
146
|
|
|
$this->config->set('board3_poll_limit_' . $module_id, 3); |
|
147
|
|
|
return true; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* {@inheritdoc} |
|
152
|
|
|
*/ |
|
153
|
|
View Code Duplication |
public function uninstall($module_id, $db) |
|
154
|
|
|
{ |
|
155
|
|
|
$del_config = array( |
|
156
|
|
|
'board3_poll_allow_vote_' . $module_id, |
|
157
|
|
|
'board3_poll_topic_id_' . $module_id, |
|
158
|
|
|
'board3_poll_exclude_id_' . $module_id, |
|
159
|
|
|
'board3_poll_hide_' . $module_id, |
|
160
|
|
|
'board3_poll_limit_' . $module_id, |
|
161
|
|
|
); |
|
162
|
|
|
$sql = 'DELETE FROM ' . CONFIG_TABLE . ' |
|
163
|
|
|
WHERE ' . $db->sql_in_set('config_name', $del_config); |
|
164
|
|
|
return $db->sql_query($sql); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Parse template variables for module |
|
169
|
|
|
* |
|
170
|
|
|
* @param int $module_id Module ID |
|
171
|
|
|
* @param string $type Module type (center or side) |
|
172
|
|
|
* |
|
173
|
|
|
* @return string HTML filename |
|
174
|
|
|
*/ |
|
175
|
|
|
protected function parse_template($module_id, $type = '') |
|
176
|
|
|
{ |
|
177
|
|
|
$this->user->add_lang('viewtopic'); |
|
178
|
|
|
|
|
179
|
|
|
// check if we need to include the bbcode class |
|
180
|
|
|
if (!class_exists('bbcode')) |
|
181
|
|
|
{ |
|
182
|
|
|
include($this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$view = $this->request->variable('view', ''); |
|
186
|
|
|
$update = $this->request->variable('update', false); |
|
187
|
|
|
$poll_view = $this->request->variable('polls', ''); |
|
188
|
|
|
|
|
189
|
|
|
$poll_view_ar = (strpos($poll_view, ',') !== false) ? explode(',', $poll_view) : (($poll_view != '') ? array($poll_view) : array()); |
|
190
|
|
|
|
|
191
|
|
|
if ($update && $this->config['board3_poll_allow_vote_' . $module_id]) |
|
192
|
|
|
{ |
|
193
|
|
|
$up_topic_id = $this->request->variable('t', 0); |
|
194
|
|
|
$up_forum_id = $this->request->variable('f', 0); |
|
195
|
|
|
$voted_id = $this->request->variable('vote_id', array('' => 0)); |
|
196
|
|
|
|
|
197
|
|
|
$cur_voted_id = array(); |
|
198
|
|
View Code Duplication |
if ($this->user->data['is_registered']) |
|
199
|
|
|
{ |
|
200
|
|
|
$sql = 'SELECT poll_option_id |
|
201
|
|
|
FROM ' . POLL_VOTES_TABLE . ' |
|
202
|
|
|
WHERE topic_id = ' . (int) $up_topic_id . ' |
|
203
|
|
|
AND vote_user_id = ' . (int) $this->user->data['user_id']; |
|
204
|
|
|
$result = $this->db->sql_query($sql); |
|
205
|
|
|
|
|
206
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
|
207
|
|
|
{ |
|
208
|
|
|
$cur_voted_id[] = $row['poll_option_id']; |
|
209
|
|
|
} |
|
210
|
|
|
$this->db->sql_freeresult($result); |
|
211
|
|
|
} |
|
212
|
|
|
else |
|
213
|
|
|
{ |
|
214
|
|
|
// Cookie based guest tracking ... I don't like this but hum ho |
|
215
|
|
|
// it's oft requested. This relies on "nice" users who don't feel |
|
216
|
|
|
// the need to delete cookies to mess with results. |
|
217
|
|
|
if ($this->request->is_set($this->config['cookie_name'] . '_poll_' . $up_topic_id, \phpbb\request\request_interface::COOKIE)) |
|
218
|
|
|
{ |
|
219
|
|
|
$cur_voted_id = explode(',', $this->request->variable($this->config['cookie_name'] . '_poll_' . $up_topic_id, '', true, \phpbb\request\request_interface::COOKIE)); |
|
220
|
|
|
$cur_voted_id = array_map('intval', $cur_voted_id); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
$sql = 'SELECT t.poll_length, t.poll_start, t.poll_vote_change, t.topic_status, f.forum_status, t.poll_max_options |
|
225
|
|
|
FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f |
|
226
|
|
|
WHERE t.forum_id = f.forum_id |
|
227
|
|
|
AND t.topic_id = " . (int) $up_topic_id . " |
|
228
|
|
|
AND t.forum_id = " . (int) $up_forum_id; |
|
229
|
|
|
$result = $this->db->sql_query_limit($sql, 1); |
|
230
|
|
|
$topic_data = $this->db->sql_fetchrow($result); |
|
231
|
|
|
$this->db->sql_freeresult($result); |
|
232
|
|
|
|
|
233
|
|
|
$s_can_up_vote = (((!sizeof($cur_voted_id) && $this->auth->acl_get('f_vote', $up_forum_id)) || |
|
234
|
|
|
($this->auth->acl_get('f_votechg', $up_forum_id) && $topic_data['poll_vote_change'])) && |
|
235
|
|
|
(($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) && |
|
236
|
|
|
$topic_data['topic_status'] != ITEM_LOCKED && |
|
237
|
|
|
$topic_data['forum_status'] != ITEM_LOCKED) ? true : false; |
|
238
|
|
|
|
|
239
|
|
|
if ($s_can_up_vote) |
|
240
|
|
|
{ |
|
241
|
|
|
$redirect_url = $this->modules_helper->route('board3_portal_controller'); |
|
242
|
|
|
|
|
243
|
|
|
if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id)) |
|
244
|
|
|
{ |
|
245
|
|
|
meta_refresh(5, $redirect_url); |
|
246
|
|
|
if (!sizeof($voted_id)) |
|
247
|
|
|
{ |
|
248
|
|
|
$message = 'NO_VOTE_OPTION'; |
|
249
|
|
|
} |
|
250
|
|
|
else if (sizeof($voted_id) > $topic_data['poll_max_options']) |
|
251
|
|
|
{ |
|
252
|
|
|
$message = 'TOO_MANY_VOTE_OPTIONS'; |
|
253
|
|
|
} |
|
254
|
|
|
else |
|
255
|
|
|
{ |
|
256
|
|
|
$message = 'VOTE_CONVERTED'; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
$message = $this->user->lang[$message] . '<br /><br />' . sprintf($this->user->lang['RETURN_PORTAL'], '<a href="' . $redirect_url . '">', '</a>'); |
|
260
|
|
|
trigger_error($message); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
foreach ($voted_id as $option) |
|
264
|
|
|
{ |
|
265
|
|
|
if (in_array($option, $cur_voted_id)) |
|
266
|
|
|
{ |
|
267
|
|
|
continue; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . ' |
|
271
|
|
|
SET poll_option_total = poll_option_total + 1 |
|
272
|
|
|
WHERE poll_option_id = ' . (int) $option . ' |
|
273
|
|
|
AND topic_id = ' . (int) $up_topic_id; |
|
274
|
|
|
$this->db->sql_query($sql); |
|
275
|
|
|
|
|
276
|
|
|
if ($this->user->data['is_registered']) |
|
277
|
|
|
{ |
|
278
|
|
|
$sql_ary = array( |
|
279
|
|
|
'topic_id' => (int) $up_topic_id, |
|
280
|
|
|
'poll_option_id' => (int) $option, |
|
281
|
|
|
'vote_user_id' => (int) $this->user->data['user_id'], |
|
282
|
|
|
'vote_user_ip' => (string) $this->user->ip, |
|
283
|
|
|
); |
|
284
|
|
|
|
|
285
|
|
|
$sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); |
|
286
|
|
|
$this->db->sql_query($sql); |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
foreach ($cur_voted_id as $option) |
|
291
|
|
|
{ |
|
292
|
|
|
if (!in_array($option, $voted_id)) |
|
293
|
|
|
{ |
|
294
|
|
|
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . ' |
|
295
|
|
|
SET poll_option_total = poll_option_total - 1 |
|
296
|
|
|
WHERE poll_option_id = ' . (int) $option . ' |
|
297
|
|
|
AND topic_id = ' . (int) $up_topic_id; |
|
298
|
|
|
$this->db->sql_query($sql); |
|
299
|
|
|
|
|
300
|
|
|
if ($this->user->data['is_registered']) |
|
301
|
|
|
{ |
|
302
|
|
|
$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . ' |
|
303
|
|
|
WHERE topic_id = ' . (int) $up_topic_id . ' |
|
304
|
|
|
AND poll_option_id = ' . (int) $option . ' |
|
305
|
|
|
AND vote_user_id = ' . (int) $this->user->data['user_id']; |
|
306
|
|
|
$this->db->sql_query($sql); |
|
307
|
|
|
} |
|
308
|
|
|
} |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
if ($this->user->data['user_id'] == ANONYMOUS && !$this->user->data['is_bot']) |
|
312
|
|
|
{ |
|
313
|
|
|
$this->user->set_cookie('poll_' . $up_topic_id, implode(',', $voted_id), time() + 31536000); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
$sql = 'UPDATE ' . TOPICS_TABLE . ' |
|
317
|
|
|
SET poll_last_vote = ' . time() . ' |
|
318
|
|
|
WHERE topic_id = ' . (int) $up_topic_id; |
|
319
|
|
|
//, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now |
|
320
|
|
|
$this->db->sql_query($sql); |
|
321
|
|
|
|
|
322
|
|
|
meta_refresh(5, $redirect_url); |
|
323
|
|
|
trigger_error($this->user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PORTAL'], '<a href="' . $redirect_url . '">', '</a>')); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
$poll_forums = false; |
|
328
|
|
|
|
|
329
|
|
|
// Get readable forums |
|
330
|
|
|
$forum_list = array_unique(array_keys($this->auth->acl_getf('f_read', true))); |
|
331
|
|
|
|
|
332
|
|
|
if ($this->config['board3_poll_topic_id_' . $module_id] !== '') |
|
333
|
|
|
{ |
|
334
|
|
|
$poll_forums_config = explode(',' ,$this->config['board3_poll_topic_id_' . $module_id]); |
|
335
|
|
|
|
|
336
|
|
View Code Duplication |
if ($this->config['board3_poll_exclude_id_' . $module_id]) |
|
337
|
|
|
{ |
|
338
|
|
|
$forum_list = array_unique(array_diff($forum_list, $poll_forums_config)); |
|
339
|
|
|
} |
|
340
|
|
|
else |
|
341
|
|
|
{ |
|
342
|
|
|
$forum_list = array_unique(array_intersect($poll_forums_config, $forum_list)); |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
$where = ''; |
|
347
|
|
|
|
|
348
|
|
View Code Duplication |
if (sizeof($forum_list)) |
|
349
|
|
|
{ |
|
350
|
|
|
$poll_forums = true; |
|
351
|
|
|
$where = 'AND ' . $this->db->sql_in_set('t.forum_id', $forum_list); |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
if ($this->config['board3_poll_hide_' . $module_id]) |
|
355
|
|
|
{ |
|
356
|
|
|
$portal_poll_hide = 'AND (t.poll_start + t.poll_length > ' . time() . ' OR t.poll_length = 0)'; |
|
357
|
|
|
} |
|
358
|
|
|
else |
|
359
|
|
|
{ |
|
360
|
|
|
$portal_poll_hide = ''; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
if ($poll_forums === true) |
|
364
|
|
|
{ |
|
365
|
|
|
|
|
366
|
|
|
$sql = 'SELECT t.poll_title, t.poll_start, t.topic_id, t.topic_first_post_id, t.forum_id, t.poll_length, t.poll_vote_change, t.poll_max_options, t.topic_status, f.forum_status, p.bbcode_bitfield, p.bbcode_uid |
|
367
|
|
|
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . " f |
|
368
|
|
|
WHERE t.forum_id = f.forum_id |
|
369
|
|
|
AND t.topic_visibility = 1 |
|
370
|
|
|
AND t.poll_start > 0 |
|
371
|
|
|
{$where} |
|
372
|
|
|
AND t.topic_moved_id = 0 |
|
373
|
|
|
AND p.post_id = t.topic_first_post_id |
|
374
|
|
|
{$portal_poll_hide} |
|
375
|
|
|
ORDER BY t.poll_start DESC"; |
|
376
|
|
|
$limit = (isset($this->config['board3_poll_limit_' . $module_id])) ? $this->config['board3_poll_limit_' . $module_id] : 3; |
|
377
|
|
|
$result = $this->db->sql_query_limit($sql, $limit); |
|
378
|
|
|
$has_poll = false; |
|
379
|
|
|
|
|
380
|
|
|
if ($result) |
|
381
|
|
|
{ |
|
382
|
|
|
while ($data = $this->db->sql_fetchrow($result)) |
|
383
|
|
|
{ |
|
384
|
|
|
$has_poll = true; |
|
385
|
|
|
$poll_has_options = false; |
|
386
|
|
|
|
|
387
|
|
|
$topic_id = (int) $data['topic_id']; |
|
388
|
|
|
$forum_id = (int) $data['forum_id']; |
|
389
|
|
|
|
|
390
|
|
|
$cur_voted_id = array(); |
|
391
|
|
|
if ($this->config['board3_poll_allow_vote_' . $module_id]) |
|
392
|
|
|
{ |
|
393
|
|
View Code Duplication |
if ($this->user->data['is_registered']) |
|
394
|
|
|
{ |
|
395
|
|
|
$vote_sql = 'SELECT poll_option_id |
|
396
|
|
|
FROM ' . POLL_VOTES_TABLE . ' |
|
397
|
|
|
WHERE topic_id = ' . (int) $topic_id . ' |
|
398
|
|
|
AND vote_user_id = ' . (int) $this->user->data['user_id']; |
|
399
|
|
|
$vote_result = $this->db->sql_query($vote_sql); |
|
400
|
|
|
|
|
401
|
|
|
while ($row = $this->db->sql_fetchrow($vote_result)) |
|
402
|
|
|
{ |
|
403
|
|
|
$cur_voted_id[] = $row['poll_option_id']; |
|
404
|
|
|
} |
|
405
|
|
|
$this->db->sql_freeresult($vote_result); |
|
406
|
|
|
} |
|
407
|
|
|
else |
|
408
|
|
|
{ |
|
409
|
|
|
// Cookie based guest tracking ... I don't like this but hum ho |
|
410
|
|
|
// it's oft requested. This relies on "nice" users who don't feel |
|
411
|
|
|
// the need to delete cookies to mess with results. |
|
412
|
|
|
if ($this->request->is_set($this->config['cookie_name'] . '_poll_' . $topic_id, \phpbb\request\request_interface::COOKIE)) |
|
413
|
|
|
{ |
|
414
|
|
|
$cur_voted_id = explode(',', $this->request->variable($this->config['cookie_name'] . '_poll_' . $topic_id, 0, false, true)); |
|
415
|
|
|
$cur_voted_id = array_map('intval', $cur_voted_id); |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
$s_can_vote = (((!sizeof($cur_voted_id) && $this->auth->acl_get('f_vote', $forum_id)) || |
|
420
|
|
|
($this->auth->acl_get('f_votechg', $forum_id) && $data['poll_vote_change'])) && |
|
421
|
|
|
(($data['poll_length'] != 0 && $data['poll_start'] + $data['poll_length'] > time()) || $data['poll_length'] == 0) && |
|
422
|
|
|
$data['topic_status'] != ITEM_LOCKED && |
|
423
|
|
|
$data['forum_status'] != ITEM_LOCKED) ? true : false; |
|
424
|
|
|
} |
|
425
|
|
|
else |
|
426
|
|
|
{ |
|
427
|
|
|
$s_can_vote = false; |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
|
$s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || ($view == 'viewpoll' && in_array($topic_id, $poll_view_ar))) ? true : false; |
|
431
|
|
|
|
|
432
|
|
|
$poll_sql = 'SELECT po.poll_option_id, po.poll_option_text, po.poll_option_total |
|
433
|
|
|
FROM ' . POLL_OPTIONS_TABLE . ' po |
|
434
|
|
|
WHERE po.topic_id = ' . (int) $topic_id .' |
|
435
|
|
|
ORDER BY po.poll_option_id'; |
|
436
|
|
|
|
|
437
|
|
|
$poll_result = $this->db->sql_query($poll_sql); |
|
438
|
|
|
$poll_total_votes = 0; |
|
439
|
|
|
$poll_data = array(); |
|
440
|
|
|
|
|
441
|
|
|
if ($poll_result) |
|
442
|
|
|
{ |
|
443
|
|
|
while ($polls_data = $this->db->sql_fetchrow($poll_result)) |
|
444
|
|
|
{ |
|
445
|
|
|
$poll_has_options = true; |
|
446
|
|
|
$poll_data[] = $polls_data; |
|
447
|
|
|
$poll_total_votes += $polls_data['poll_option_total']; |
|
448
|
|
|
} |
|
449
|
|
|
} |
|
450
|
|
|
$this->db->sql_freeresult($poll_result); |
|
451
|
|
|
|
|
452
|
|
|
$make_poll_view = array(); |
|
453
|
|
|
|
|
454
|
|
|
if (in_array($topic_id, $poll_view_ar) === false) |
|
455
|
|
|
{ |
|
456
|
|
|
$make_poll_view[] = $topic_id; |
|
457
|
|
|
$make_poll_view = array_merge($poll_view_ar, $make_poll_view); |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
$poll_view_str = urlencode(implode(',', $make_poll_view)); |
|
461
|
|
|
$portalpoll_url= $this->modules_helper->route('board3_portal_controller') . "?polls=$poll_view_str"; |
|
462
|
|
|
$portalvote_url= $this->modules_helper->route('board3_portal_controller') . "?f=$forum_id&t=$topic_id"; |
|
463
|
|
|
$viewtopic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f=$forum_id&t=$topic_id"); |
|
464
|
|
|
$poll_end = $data['poll_length'] + $data['poll_start']; |
|
465
|
|
|
|
|
466
|
|
|
// Parse BBCode title |
|
467
|
|
|
if ($data['bbcode_bitfield']) |
|
468
|
|
|
{ |
|
469
|
|
|
$poll_bbcode = new \bbcode(); |
|
470
|
|
|
} |
|
471
|
|
|
else |
|
472
|
|
|
{ |
|
473
|
|
|
$poll_bbcode = false; |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
$data['poll_title'] = censor_text($data['poll_title']); |
|
477
|
|
|
|
|
478
|
|
|
if ($poll_bbcode !== false) |
|
479
|
|
|
{ |
|
480
|
|
|
$poll_bbcode->bbcode_second_pass($data['poll_title'], $data['bbcode_uid'], $data['bbcode_bitfield']); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
$data['poll_title'] = bbcode_nl2br($data['poll_title']); |
|
484
|
|
|
$data['poll_title'] = smiley_text($data['poll_title']); |
|
485
|
|
|
unset($poll_bbcode); |
|
486
|
|
|
|
|
487
|
|
|
$this->template->assign_block_vars(($type !== '') ? 'poll_' . $type : 'poll', array( |
|
488
|
|
|
'S_POLL_HAS_OPTIONS' => $poll_has_options, |
|
489
|
|
|
'POLL_QUESTION' => $data['poll_title'], |
|
490
|
|
|
'U_POLL_TOPIC' => append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, 't=' . $topic_id . '&f=' . $forum_id), |
|
491
|
|
|
'POLL_LENGTH' => $data['poll_length'], |
|
492
|
|
|
'TOPIC_ID' => $topic_id, |
|
493
|
|
|
'TOTAL_VOTES' => $poll_total_votes, |
|
494
|
|
|
'L_MAX_VOTES' => $this->user->lang('MAX_OPTIONS_SELECT', $data['poll_max_options']), |
|
495
|
|
|
'L_POLL_LENGTH' => ($data['poll_length']) ? sprintf($this->user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $this->user->format_date($poll_end)) : '', |
|
496
|
|
|
'S_CAN_VOTE' => $s_can_vote, |
|
497
|
|
|
'S_DISPLAY_RESULTS' => $s_display_results, |
|
498
|
|
|
'S_IS_MULTI_CHOICE' => ($data['poll_max_options'] > 1) ? true : false, |
|
499
|
|
|
'S_POLL_ACTION' => $portalvote_url, |
|
500
|
|
|
'U_VIEW_RESULTS' => $portalpoll_url . '&view=viewpoll#viewpoll', |
|
501
|
|
|
'U_VIEW_TOPIC' => $viewtopic_url, |
|
502
|
|
|
)); |
|
503
|
|
|
|
|
504
|
|
|
foreach ($poll_data as $pd) |
|
505
|
|
|
{ |
|
506
|
|
|
$option_pct = ($poll_total_votes > 0) ? $pd['poll_option_total'] / $poll_total_votes : 0; |
|
507
|
|
|
$option_pct_txt = sprintf("%.1d%%", round($option_pct * 100)); |
|
508
|
|
|
|
|
509
|
|
|
// Parse BBCode option text |
|
510
|
|
|
if ($data['bbcode_bitfield']) |
|
511
|
|
|
{ |
|
512
|
|
|
$poll_bbcode = new \bbcode(); |
|
513
|
|
|
} |
|
514
|
|
|
else |
|
515
|
|
|
{ |
|
516
|
|
|
$poll_bbcode = false; |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
$pd['poll_option_text'] = censor_text($pd['poll_option_text']); |
|
520
|
|
|
|
|
521
|
|
|
if ($poll_bbcode !== false) |
|
522
|
|
|
{ |
|
523
|
|
|
$poll_bbcode->bbcode_second_pass($pd['poll_option_text'], $data['bbcode_uid'], $data['bbcode_bitfield']); |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
$pd['poll_option_text'] = bbcode_nl2br($pd['poll_option_text']); |
|
527
|
|
|
$pd['poll_option_text'] = smiley_text($pd['poll_option_text']); |
|
528
|
|
|
unset($poll_bbcode); |
|
529
|
|
|
|
|
530
|
|
|
$this->template->assign_block_vars((($type !== '') ? 'poll_' . $type : 'poll') . '.poll_option', array( |
|
531
|
|
|
'POLL_OPTION_ID' => $pd['poll_option_id'], |
|
532
|
|
|
'POLL_OPTION_CAPTION' => $pd['poll_option_text'], |
|
533
|
|
|
'POLL_OPTION_RESULT' => $pd['poll_option_total'], |
|
534
|
|
|
'POLL_OPTION_PERCENT' => $option_pct_txt, |
|
535
|
|
|
'POLL_OPTION_PCT' => round($option_pct * 100), |
|
536
|
|
|
'POLL_OPTION_IMG' => $this->user->img('poll_center', $option_pct_txt, round($option_pct * 35) . 'px'), |
|
537
|
|
|
'POLL_OPTION_VOTED' => (in_array($pd['poll_option_id'], $cur_voted_id)) ? true : false |
|
538
|
|
|
)); |
|
539
|
|
|
} |
|
540
|
|
|
} |
|
541
|
|
|
} |
|
542
|
|
|
$this->db->sql_freeresult($result); |
|
543
|
|
|
|
|
544
|
|
|
$this->template->assign_vars(array( |
|
545
|
|
|
'S_HAS_POLL' => $has_poll, |
|
546
|
|
|
'POLL_LEFT_CAP_IMG' => $this->user->img('poll_left'), |
|
547
|
|
|
'POLL_RIGHT_CAP_IMG' => $this->user->img('poll_right'), |
|
548
|
|
|
)); |
|
549
|
|
|
} |
|
550
|
|
|
return (($type !== '') ? 'poll_' . $type : 'poll_center') . '.html'; |
|
551
|
|
|
} |
|
552
|
|
|
} |
|
553
|
|
|
|