1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package phpBB Gallery Core |
5
|
|
|
* @copyright (c) 2014 Luifer |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace phpbbgallery\core; |
11
|
|
|
|
12
|
|
|
class search |
13
|
|
|
{ |
14
|
|
|
/* @var \phpbb\db\driver\driver */ |
|
|
|
|
15
|
|
|
protected $db; |
16
|
|
|
|
17
|
|
|
/* @var \phpbb\request\request */ |
|
|
|
|
18
|
|
|
protected $request; |
19
|
|
|
|
20
|
|
|
/* @var \phpbb\template\template */ |
|
|
|
|
21
|
|
|
protected $template; |
22
|
|
|
|
23
|
|
|
/* @var \phpbb\user */ |
|
|
|
|
24
|
|
|
protected $user; |
25
|
|
|
|
26
|
|
|
/* @var \phpbb\language\language */ |
|
|
|
|
27
|
|
|
protected $language; |
28
|
|
|
|
29
|
|
|
/* @var \phpbb\controller\helper */ |
|
|
|
|
30
|
|
|
protected $helper; |
31
|
|
|
|
32
|
|
|
/* @var \phpbbgallery\core\config */ |
33
|
|
|
protected $gallery_config; |
34
|
|
|
|
35
|
|
|
/* @var \phpbbgallery\core\auth\auth */ |
36
|
|
|
protected $gallery_auth; |
37
|
|
|
|
38
|
|
|
/* @var \phpbbgallery\core\album\album */ |
39
|
|
|
protected $album; |
40
|
|
|
|
41
|
|
|
/* @var \phpbbgallery\core\image\image */ |
42
|
|
|
protected $image; |
43
|
|
|
|
44
|
|
|
/* @var \phpbb\pagination */ |
|
|
|
|
45
|
|
|
protected $pagination; |
46
|
|
|
|
47
|
|
|
/* @var \phpbb\user_loader */ |
|
|
|
|
48
|
|
|
protected $user_loader; |
49
|
|
|
|
50
|
|
|
/* @var string */ |
51
|
|
|
protected $images_table; |
52
|
|
|
|
53
|
|
|
/* @var string */ |
54
|
|
|
protected $albums_table; |
55
|
|
|
|
56
|
|
|
/* @var string */ |
57
|
|
|
protected $comments_table; |
58
|
|
|
|
59
|
|
|
/* @var \phpbbgallery\core\album\display */ |
60
|
|
|
protected $display; |
61
|
|
|
|
62
|
|
|
/* @var string */ |
63
|
|
|
protected $root_path; |
64
|
|
|
|
65
|
|
|
/* @var string */ |
66
|
|
|
protected $php_ext; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Constructor |
70
|
|
|
* |
71
|
|
|
* @param \phpbb\db\driver\driver|\phpbb\db\driver\driver_interface $db Database object |
72
|
|
|
* @param \phpbb\template\template $template Template object |
73
|
|
|
* @param \phpbb\user $user User object |
74
|
|
|
* @param \phpbb\language\language $language |
75
|
|
|
* @param \phpbb\controller\helper $helper Controller helper object |
76
|
|
|
* @param config $gallery_config |
77
|
|
|
* @param auth\auth $gallery_auth |
78
|
|
|
* @param album\album $album |
79
|
|
|
* @param image\image $image |
80
|
|
|
* @param \phpbb\pagination $pagination |
81
|
|
|
* @param \phpbb\user_loader $user_loader |
82
|
|
|
* @param $images_table |
83
|
|
|
* @param $albums_table |
84
|
|
|
* @param $comments_table |
85
|
|
|
* @internal param \phpbb\auth\auth $auth Auth object |
86
|
|
|
* @internal param \phpbb\config\config $config Config object |
87
|
|
|
* @internal param \phpbb\request\request $request Request object |
88
|
|
|
* @internal param album\display $display Albums display object |
89
|
|
|
* @internal param string $root_path Root path |
90
|
|
|
* @internal param string $php_ext php file extension |
91
|
|
|
*/ |
92
|
90 |
|
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, |
|
|
|
|
93
|
|
|
\phpbb\language\language $language, \phpbb\controller\helper $helper, \phpbbgallery\core\config $gallery_config, |
94
|
|
|
\phpbbgallery\core\auth\auth $gallery_auth, \phpbbgallery\core\album\album $album, \phpbbgallery\core\image\image $image, |
95
|
|
|
\phpbb\pagination $pagination, \phpbb\user_loader $user_loader, |
96
|
|
|
$images_table, $albums_table, $comments_table) |
97
|
|
|
{ |
98
|
90 |
|
$this->db = $db; |
99
|
90 |
|
$this->template = $template; |
100
|
90 |
|
$this->user = $user; |
101
|
90 |
|
$this->language = $language; |
102
|
90 |
|
$this->helper = $helper; |
103
|
90 |
|
$this->gallery_config = $gallery_config; |
104
|
90 |
|
$this->gallery_auth = $gallery_auth; |
105
|
90 |
|
$this->album = $album; |
106
|
90 |
|
$this->image = $image; |
107
|
90 |
|
$this->pagination = $pagination; |
108
|
90 |
|
$this->user_loader = $user_loader; |
109
|
90 |
|
$this->images_table = $images_table; |
110
|
90 |
|
$this->albums_table = $albums_table; |
111
|
90 |
|
$this->comments_table = $comments_table; |
112
|
90 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Generate random images and populate template |
116
|
|
|
* @param (int) $limit how many images to generate_link |
117
|
|
|
* @param int $user |
118
|
|
|
* @param string $fields |
119
|
|
|
* @param bool $block_name |
120
|
|
|
* @param bool $u_block |
121
|
|
|
*/ |
122
|
33 |
|
public function random($limit, $user = 0, $fields = 'rrc_gindex_display', $block_name = false, $u_block = false) |
123
|
|
|
{ |
124
|
|
|
// We will do small escape for not devising by 0 |
125
|
33 |
|
if ($limit == 0) |
126
|
|
|
{ |
127
|
|
|
return; |
128
|
|
|
} |
129
|
33 |
|
if ($limit < -1) |
130
|
|
|
{ |
131
|
|
|
$limit = -1; |
132
|
|
|
} |
133
|
|
|
// Define some vars |
134
|
33 |
|
$images_per_page = $limit; |
135
|
|
|
|
136
|
33 |
|
$this->gallery_auth->load_user_permissions($this->user->data['user_id']); |
137
|
|
|
|
138
|
33 |
|
switch ($this->db->get_sql_layer()) |
139
|
|
|
{ |
140
|
33 |
|
case 'postgres': |
141
|
33 |
|
case 'sqlite3': |
142
|
|
|
$sql_order = 'RANDOM()'; |
143
|
|
|
break; |
144
|
|
|
|
145
|
33 |
|
case 'mssql': |
146
|
33 |
|
case 'mssql_odbc': |
147
|
|
|
$sql_order = 'NEWID()'; |
148
|
|
|
break; |
149
|
|
|
|
150
|
|
|
default: |
151
|
33 |
|
$sql_order = 'RAND()'; |
152
|
33 |
|
break; |
153
|
|
|
} |
154
|
33 |
|
$sql_limit = $images_per_page; |
155
|
|
|
$sql = 'SELECT image_id |
156
|
33 |
|
FROM ' . $this->images_table . ' |
157
|
33 |
|
WHERE image_status <> ' . \phpbbgallery\core\block::STATUS_ORPHAN; |
158
|
33 |
|
if ($user > 0) |
159
|
|
|
{ |
160
|
30 |
|
$sql .= ' and image_user_id = ' . (int) $user; |
161
|
|
|
} |
162
|
33 |
|
$exclude_albums = array(); |
163
|
33 |
|
if (!$this->gallery_config->get('rrc_gindex_pegas')) |
164
|
|
|
{ |
165
|
|
|
$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0'; |
166
|
|
|
$result = $this->db->sql_query($sql_no_user); |
167
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
168
|
|
|
{ |
169
|
|
|
$exclude_albums[] = (int) $row['album_id']; |
170
|
|
|
} |
171
|
|
|
$this->db->sql_freeresult($result); |
172
|
|
|
} |
173
|
33 |
|
$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra()); |
174
|
33 |
|
$sql .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND image_status <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED . ') |
|
|
|
|
175
|
33 |
|
OR (' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('a_list'), $exclude_albums), false, true) . ' AND image_status <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED . ') |
176
|
33 |
|
OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ') |
177
|
33 |
|
ORDER BY ' . $sql_order; |
178
|
|
|
|
179
|
33 |
|
if (!$sql_limit) |
180
|
|
|
{ |
181
|
|
|
$result = $this->db->sql_query($sql); |
182
|
|
|
} |
183
|
|
|
else |
184
|
|
|
{ |
185
|
33 |
|
$result = $this->db->sql_query_limit($sql, $sql_limit); |
186
|
|
|
} |
187
|
33 |
|
$id_ary = array(); |
188
|
33 |
|
while ($row = $this->db->sql_fetchrow($result)) |
189
|
|
|
{ |
190
|
33 |
|
$id_ary[] = $row['image_id']; |
191
|
|
|
} |
192
|
33 |
|
$this->db->sql_freeresult($result); |
193
|
|
|
|
194
|
33 |
|
$total_match_count = sizeof($id_ary); |
195
|
|
|
|
196
|
33 |
|
$l_search_matches = $this->language->lang('FOUND_SEARCH_MATCHES', $total_match_count); |
|
|
|
|
197
|
|
|
|
198
|
33 |
|
$this->template->assign_block_vars('imageblock', array( |
199
|
33 |
|
'BLOCK_NAME' => $block_name ? $block_name : $this->language->lang('RANDOM_IMAGES'), |
200
|
33 |
|
'U_BLOCK' => $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_random'), |
201
|
|
|
)); |
202
|
|
|
|
203
|
|
|
// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options. |
204
|
33 |
|
if (!sizeof($id_ary)) |
205
|
|
|
{ |
206
|
|
|
$this->template->assign_block_vars('imageblock', array( |
207
|
|
|
'ERROR' => $this->language->lang('NO_SEARCH_RESULTS_RANDOM'), |
208
|
|
|
)); |
209
|
|
|
return; |
210
|
|
|
} |
211
|
|
|
|
212
|
33 |
|
$id_ary = array_map('intval', $id_ary); |
213
|
|
|
|
214
|
33 |
|
$sql_where = $this->db->sql_in_set('i.image_id', $id_ary); |
215
|
|
|
|
216
|
|
|
$sql_array = array( |
217
|
33 |
|
'SELECT' => 'i.*, a.album_name, a.album_status, a.album_user_id, album_id', |
218
|
33 |
|
'FROM' => array($this->images_table => 'i'), |
219
|
|
|
|
220
|
|
|
'LEFT_JOIN' => array( |
221
|
|
|
array( |
222
|
33 |
|
'FROM' => array($this->albums_table => 'a'), |
223
|
33 |
|
'ON' => 'a.album_id = i.image_album_id', |
224
|
|
|
), |
225
|
|
|
), |
226
|
|
|
|
227
|
33 |
|
'WHERE' => 'i.image_status <> ' . \phpbbgallery\core\block::STATUS_ORPHAN . ' AND ' . $sql_where, |
228
|
33 |
|
'WHERE' => 'i.image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' AND ' . $sql_where, |
229
|
33 |
|
'GROUP_BY' => 'i.image_id, a.album_name, a.album_status, a.album_user_id, a.album_id', |
230
|
33 |
|
'ORDER_BY' => $sql_order, |
231
|
|
|
); |
232
|
33 |
|
$sql = $this->db->sql_build_query('SELECT', $sql_array); |
233
|
33 |
|
$result = $this->db->sql_query($sql); |
234
|
33 |
|
$rowset = array(); |
|
|
|
|
235
|
|
|
|
236
|
33 |
|
$show_options = $this->gallery_config->get($fields); |
237
|
33 |
|
$thumbnail_link = $this->gallery_config->get('link_thumbnail'); |
238
|
33 |
|
$imagename_link = $this->gallery_config->get('link_image_name'); |
239
|
|
|
|
240
|
33 |
|
while ($row = $this->db->sql_fetchrow($result)) |
241
|
|
|
{ |
242
|
33 |
|
$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link); |
243
|
|
|
} |
244
|
|
|
|
245
|
33 |
|
$this->db->sql_freeresult($result); |
246
|
33 |
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Get all recent images the user has access to |
250
|
|
|
* return (int) $images_count |
251
|
|
|
*/ |
252
|
2 |
|
public function recent_count() |
253
|
|
|
{ |
254
|
2 |
|
$this->gallery_auth->load_user_permissions($this->user->data['user_id']); |
255
|
|
|
|
256
|
2 |
|
$exclude_albums = []; |
257
|
|
|
|
258
|
2 |
|
if (!$this->gallery_config->get('rrc_gindex_pegas')) |
259
|
|
|
{ |
260
|
|
|
$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0'; |
261
|
|
|
$result = $this->db->sql_query($sql_no_user); |
262
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
263
|
|
|
{ |
264
|
|
|
$exclude_albums[] = (int) $row['album_id']; |
265
|
|
|
} |
266
|
|
|
$this->db->sql_freeresult($result); |
267
|
|
|
} |
268
|
|
|
|
269
|
2 |
|
$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra()); |
270
|
|
|
|
271
|
|
|
// Get allowed album ids for view and mod permissions excluding excluded albums |
272
|
2 |
|
$view_album_ids = array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums); |
|
|
|
|
273
|
2 |
|
$mod_album_ids = array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums); |
274
|
|
|
|
275
|
2 |
|
if (empty($view_album_ids) && empty($mod_album_ids)) |
276
|
|
|
{ |
277
|
|
|
return 0; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
$sql = 'SELECT COUNT(image_id) AS count |
281
|
2 |
|
FROM ' . $this->images_table . ' |
282
|
2 |
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN; |
283
|
|
|
|
284
|
2 |
|
$conditions = []; |
285
|
|
|
|
286
|
2 |
|
if (!empty($view_album_ids)) |
287
|
|
|
{ |
288
|
2 |
|
$conditions[] = '(' . $this->db->sql_in_set('image_album_id', $view_album_ids) . ' |
289
|
2 |
|
AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ')'; |
290
|
|
|
} |
291
|
|
|
|
292
|
2 |
|
if (!empty($mod_album_ids)) |
293
|
|
|
{ |
294
|
|
|
$conditions[] = $this->db->sql_in_set('image_album_id', $mod_album_ids); |
295
|
|
|
} |
296
|
|
|
|
297
|
2 |
|
if (!empty($conditions)) |
298
|
|
|
{ |
299
|
2 |
|
$sql .= ' AND (' . implode(' OR ', $conditions) . ')'; |
300
|
|
|
} |
301
|
|
|
|
302
|
2 |
|
$result = $this->db->sql_query($sql); |
303
|
2 |
|
$row = $this->db->sql_fetchrow($result); |
304
|
2 |
|
$this->db->sql_freeresult($result); |
305
|
|
|
|
306
|
2 |
|
return (int) $row['count']; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
|
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* recent comments |
313
|
|
|
* @param (int) $limit How many images to query |
314
|
|
|
* @param int $start |
315
|
|
|
*/ |
316
|
7 |
|
public function recent_comments($limit, $start = 0, $pagination = true) |
317
|
|
|
{ |
318
|
7 |
|
$this->gallery_auth->load_user_permissions($this->user->data['user_id']); |
319
|
7 |
|
$sql_limit = $limit; |
320
|
7 |
|
$exclude_albums = array(); |
321
|
7 |
|
if (!$this->gallery_config->get('rrc_gindex_pegas')) |
322
|
|
|
{ |
323
|
|
|
$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0'; |
324
|
|
|
$result = $this->db->sql_query($sql_no_user); |
325
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
326
|
|
|
{ |
327
|
|
|
$exclude_albums[] = (int) $row['album_id']; |
328
|
|
|
} |
329
|
|
|
$this->db->sql_freeresult($result); |
330
|
|
|
} |
331
|
7 |
|
$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra()); |
332
|
|
|
$sql_array = array( |
333
|
|
|
'FROM' => array( |
334
|
7 |
|
$this->images_table => 'i', |
335
|
7 |
|
$this->comments_table => 'c', |
336
|
|
|
), |
337
|
7 |
|
'WHERE' => 'i.image_id = c.comment_image_id and ' . $this->db->sql_in_set('image_album_id', $this->gallery_auth->acl_album_ids('c_read'), false, true), |
338
|
7 |
|
'GROUP_BY' => 'c.comment_id, c.comment_time, i.image_id', |
339
|
7 |
|
'ORDER_BY' => 'comment_time DESC' |
340
|
|
|
); |
341
|
7 |
|
$sql_array['WHERE'] .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ') |
|
|
|
|
342
|
7 |
|
OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')'; |
343
|
|
|
|
344
|
7 |
|
$sql_array['SELECT'] = 'COUNT(c.comment_id) as count'; |
345
|
7 |
|
$sql = $this->db->sql_build_query('SELECT', $sql_array); |
346
|
7 |
|
$result = $this->db->sql_query($sql); |
347
|
7 |
|
$row = $this->db->sql_fetchrow($result); |
348
|
7 |
|
$this->db->sql_freeresult($result); |
349
|
7 |
|
$count = 0; |
350
|
7 |
|
if ($row) |
351
|
|
|
{ |
352
|
7 |
|
$count = $row['count']; |
353
|
|
|
} |
354
|
7 |
|
$sql_array['SELECT'] = '*'; |
355
|
7 |
|
$sql = $this->db->sql_build_query('SELECT', $sql_array); |
356
|
7 |
|
$result = $this->db->sql_query_limit($sql, $sql_limit, $start); |
357
|
7 |
|
$rowset = array(); |
358
|
|
|
|
359
|
7 |
|
$users_array = array(); |
360
|
7 |
|
while ($row = $this->db->sql_fetchrow($result)) |
361
|
|
|
{ |
362
|
6 |
|
$rowset[] = $row; |
363
|
6 |
|
$users_array[$row['comment_user_id']] = array(''); |
364
|
6 |
|
$users_array[$row['image_user_id']] = array(''); |
365
|
|
|
} |
366
|
7 |
|
$this->db->sql_freeresult($result); |
367
|
7 |
|
if (empty($rowset)) |
368
|
|
|
{ |
369
|
1 |
|
$this->template->assign_vars(array( |
370
|
1 |
|
'ERROR' => $this->language->lang('NO_SEARCH_RESULTS_RECENT_COMMENTS'), |
371
|
|
|
)); |
372
|
1 |
|
return; |
373
|
|
|
} |
374
|
|
|
|
375
|
6 |
|
$this->user_loader->load_users(array_keys($users_array)); |
376
|
6 |
|
foreach ($rowset as $var) |
377
|
|
|
{ |
378
|
|
|
|
379
|
6 |
|
$album_tmp = $this->album->get_info($var['image_album_id']); |
380
|
6 |
|
$this->template->assign_block_vars('commentrow', array( |
381
|
6 |
|
'COMMENT_ID' => (int) $var['comment_id'], |
382
|
6 |
|
'U_DELETE' => ($this->gallery_auth->acl_check('m_comments', $album_tmp['album_id'], $album_tmp['album_user_id']) || ($this->gallery_auth->acl_check('c_delete', $album_tmp['album_id'], $album_tmp['album_user_id']) && ($var['comment_user_id'] == $this->user->data['user_id']) && $this->user->data['is_registered'])) ? $this->helper->route('phpbbgallery_core_comment_delete', array('image_id' => $var['comment_image_id'], 'comment_id' => $var['comment_id'])) : false, |
383
|
6 |
|
'U_EDIT' => $this->gallery_auth->acl_check('c_edit', $album_tmp['album_id'], $album_tmp['album_user_id'])? $this->helper->route('phpbbgallery_core_comment_edit', array('image_id' => $var['comment_image_id'], 'comment_id' => $var['comment_id'])) : false, |
384
|
6 |
|
'U_QUOTE' => ($this->gallery_auth->acl_check('c_post', $album_tmp['album_id'], $album_tmp['album_user_id'])) ? $this->helper->route('phpbbgallery_core_comment_add', array('image_id' => $var['comment_image_id'], 'comment_id' => $var['comment_id'])) : false, |
385
|
6 |
|
'U_COMMENT' => $this->helper->route('phpbbgallery_core_image', array('image_id' => $var['comment_image_id'])) . '#comment_' . $var['comment_id'], |
386
|
6 |
|
'POST_AUTHOR_FULL' => (string) $this->user_loader->get_username($var['comment_user_id'], 'full'), |
387
|
6 |
|
'TIME' => $this->user->format_date($var['comment_time']), |
388
|
6 |
|
'TEXT' => generate_text_for_display($var['comment'], $var['comment_uid'], $var['comment_bitfield'], 7), |
|
|
|
|
389
|
6 |
|
'UC_IMAGE_NAME' => '<a href="' . $this->helper->route('phpbbgallery_core_image', array('image_id' => $var['comment_image_id'])) . '">' . $var['image_name'] . '</a>', |
390
|
|
|
// 'UC_THUMBNAIL' => $this->helper->route('phpbbgallery_core_image_file_mini', array('image_id' => $var['image_id'])), |
391
|
6 |
|
'UC_THUMBNAIL' => $this->image->generate_link('thumbnail', $this->gallery_config->get('link_thumbnail'), $var['comment_image_id'], $var['image_name'], $var['image_album_id']), |
392
|
6 |
|
'IMAGE_AUTHOR' => $this->user_loader->get_username((int) $var['image_user_id'], 'full'), |
393
|
6 |
|
'IMAGE_TIME' => $this->user->format_date($var['image_time']), |
394
|
|
|
)); |
395
|
|
|
} |
396
|
6 |
|
$this->template->assign_vars(array( |
397
|
6 |
|
'SEARCH_MATCHES' => $this->language->lang('TOTAL_COMMENTS_SPRINTF', $count), |
398
|
6 |
|
'SEARCH_TITLE' => $this->language->lang('RECENT_COMMENTS'), |
399
|
|
|
)); |
400
|
6 |
|
if ($pagination) |
401
|
|
|
{ |
402
|
6 |
|
$this->pagination->generate_template_pagination(array( |
403
|
|
|
'routes' => array( |
404
|
6 |
|
'phpbbgallery_core_search_commented', |
405
|
|
|
'phpbbgallery_core_search_commented_page',), |
406
|
6 |
|
'params' => array()), 'pagination', 'page', $count, $limit, $start |
407
|
|
|
); |
408
|
|
|
} |
409
|
6 |
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Generate recent images and populate template |
413
|
|
|
* @param (int) $limit How many images to query |
414
|
|
|
* @param int $start |
415
|
|
|
* @param int $user |
416
|
|
|
* @param string $fields |
417
|
|
|
* @param bool $block_name |
418
|
|
|
* @param bool $u_block |
419
|
|
|
*/ |
420
|
34 |
|
public function recent($limit, $start = 0, $user = 0, $fields = 'rrc_gindex_display', $block_name = false, $u_block = false) |
421
|
|
|
{ |
422
|
|
|
// We will do small escape for not devising by 0 |
423
|
34 |
|
if ($limit == 0) |
424
|
|
|
{ |
425
|
|
|
return; |
426
|
|
|
} |
427
|
34 |
|
if ($limit < -1) |
428
|
|
|
{ |
429
|
|
|
$limit = -1; |
430
|
|
|
} |
431
|
34 |
|
$pagination = true; |
432
|
34 |
|
if ($start == -1) |
433
|
|
|
{ |
434
|
1 |
|
$start = 0; |
435
|
1 |
|
$pagination = false; |
436
|
|
|
} |
437
|
34 |
|
$this->gallery_auth->load_user_permissions($this->user->data['user_id']); |
438
|
34 |
|
$sql_order = ''; |
439
|
34 |
|
switch ($this->gallery_config->get('default_sort_key')) |
440
|
|
|
{ |
441
|
34 |
|
case 't': |
442
|
34 |
|
$sql_order = 'image_time'; |
443
|
34 |
|
break; |
444
|
|
|
case 'n': |
445
|
|
|
$sql_order = 'image_name_clean'; |
446
|
|
|
break; |
447
|
|
|
case 'vc': |
448
|
|
|
$sql_order = 'image_view_count'; |
449
|
|
|
break; |
450
|
|
|
case 'u': |
451
|
|
|
$sql_order = 'image_username_clean'; |
452
|
|
|
break; |
453
|
|
|
case 'ra': |
454
|
|
|
$sql_order = 'image_rate_avg'; |
455
|
|
|
break; |
456
|
|
|
case 'r': |
457
|
|
|
$sql_order = 'image_rates'; |
458
|
|
|
break; |
459
|
|
|
case 'c': |
460
|
|
|
$sql_order = 'image_comments'; |
461
|
|
|
break; |
462
|
|
|
case 'lc': |
463
|
|
|
$sql_order = 'image_last_comment'; |
464
|
|
|
break; |
465
|
|
|
} |
466
|
34 |
|
$sql_order = $sql_order . ($this->gallery_config->get('default_sort_dir') == 'd' ? ' DESC' : ' ASC'); |
467
|
34 |
|
$sql_limit = $limit; |
468
|
34 |
|
$exclude_albums = array(); |
469
|
34 |
|
if (!$this->gallery_config->get('rrc_gindex_pegas')) |
470
|
|
|
{ |
471
|
|
|
$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0'; |
472
|
|
|
$result = $this->db->sql_query($sql_no_user); |
473
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
474
|
|
|
{ |
475
|
|
|
$exclude_albums[] = (int) $row['album_id']; |
476
|
|
|
} |
477
|
|
|
$this->db->sql_freeresult($result); |
478
|
|
|
} |
479
|
34 |
|
$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra()); |
480
|
|
|
$sql_ary = array( |
481
|
|
|
'FROM' => array( |
482
|
34 |
|
$this->images_table => 'i' |
483
|
|
|
), |
484
|
|
|
'WHERE' => 'image_status <> ' . \phpbbgallery\core\block::STATUS_ORPHAN |
485
|
|
|
); |
486
|
34 |
|
if ($user > 0) |
487
|
|
|
{ |
488
|
30 |
|
$sql_ary['WHERE'] .= ' and image_user_id = ' . (int) $user; |
489
|
|
|
} |
490
|
34 |
|
$sql_ary['WHERE'] .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND image_status <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED . ') |
|
|
|
|
491
|
34 |
|
OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')'; |
492
|
|
|
|
493
|
34 |
|
$sql_ary['SELECT'] = 'COUNT(image_id) as count'; |
494
|
34 |
|
$sql = $this->db->sql_build_query('SELECT', $sql_ary); |
495
|
34 |
|
$result = $this->db->sql_query($sql); |
496
|
34 |
|
$row = $this->db->sql_fetchrow($result); |
497
|
34 |
|
$this->db->sql_freeresult($result); |
498
|
34 |
|
$count = $row['count']; |
499
|
|
|
|
500
|
34 |
|
$sql_ary['SELECT'] = 'image_id'; |
501
|
34 |
|
$sql_ary['ORDER_BY'] = $sql_order; |
502
|
34 |
|
$sql = $this->db->sql_build_query('SELECT', $sql_ary); |
503
|
34 |
|
$result = $this->db->sql_query_limit($sql, $sql_limit, $start); |
504
|
34 |
|
$id_ary = array(); |
505
|
34 |
|
while ($row = $this->db->sql_fetchrow($result)) |
506
|
|
|
{ |
507
|
34 |
|
$id_ary[] = $row['image_id']; |
508
|
|
|
} |
509
|
|
|
|
510
|
34 |
|
$this->db->sql_freeresult($result); |
511
|
|
|
|
512
|
34 |
|
$total_match_count = sizeof($id_ary); |
513
|
|
|
|
514
|
34 |
|
$l_search_matches = $this->language->lang('FOUND_SEARCH_MATCHES', $total_match_count); |
|
|
|
|
515
|
|
|
|
516
|
34 |
|
if ($user > 0) |
517
|
|
|
{ |
518
|
30 |
|
$this->template->assign_block_vars('imageblock', array( |
519
|
30 |
|
'BLOCK_NAME' => $block_name ? $block_name : '' , |
520
|
30 |
|
'U_BLOCK' => $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_egosearch'), |
521
|
|
|
)); |
522
|
|
|
} |
523
|
|
|
else |
524
|
|
|
{ |
525
|
4 |
|
$this->template->assign_block_vars('imageblock', array( |
526
|
4 |
|
'BLOCK_NAME' => $block_name ? $block_name : $this->language->lang('RECENT_IMAGES'), |
527
|
4 |
|
'U_BLOCK' => $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_recent'), |
528
|
|
|
)); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options. |
532
|
34 |
|
if (!sizeof($id_ary)) |
533
|
|
|
{ |
534
|
|
|
$this->template->assign_block_vars('imageblock', array( |
535
|
|
|
'ERROR' => $this->language->lang('NO_SEARCH_RESULTS_RECENT') |
536
|
|
|
)); |
537
|
|
|
return; |
538
|
|
|
} |
539
|
|
|
|
540
|
34 |
|
$id_ary = array_map('intval', $id_ary); |
541
|
|
|
|
542
|
34 |
|
$sql_where = $this->db->sql_in_set('i.image_id', $id_ary); |
543
|
|
|
|
544
|
|
|
$sql_array = array( |
545
|
34 |
|
'SELECT' => 'i.*, a.album_name, a.album_status, a.album_user_id, a.album_id', |
546
|
34 |
|
'FROM' => array($this->images_table => 'i'), |
547
|
|
|
|
548
|
|
|
'LEFT_JOIN' => array( |
549
|
|
|
array( |
550
|
34 |
|
'FROM' => array($this->albums_table => 'a'), |
551
|
34 |
|
'ON' => 'a.album_id = i.image_album_id', |
552
|
|
|
), |
553
|
|
|
), |
554
|
|
|
|
555
|
34 |
|
'WHERE' => 'i.image_status <> ' . \phpbbgallery\core\block::STATUS_ORPHAN . ' AND ' . $sql_where, |
556
|
34 |
|
'WHERE' => 'i.image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' AND ' . $sql_where, |
557
|
34 |
|
'ORDER_BY' => $sql_order, |
558
|
|
|
); |
559
|
34 |
|
$sql = $this->db->sql_build_query('SELECT', $sql_array); |
560
|
34 |
|
$result = $this->db->sql_query($sql); |
561
|
|
|
|
562
|
34 |
|
$show_options = $this->gallery_config->get($fields); |
563
|
34 |
|
$thumbnail_link = $this->gallery_config->get('link_thumbnail'); |
564
|
34 |
|
$imagename_link = $this->gallery_config->get('link_image_name'); |
565
|
|
|
|
566
|
34 |
|
while ($row = $this->db->sql_fetchrow($result)) |
567
|
|
|
{ |
568
|
34 |
|
$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link); |
569
|
|
|
} |
570
|
34 |
|
$this->db->sql_freeresult($result); |
571
|
|
|
|
572
|
34 |
|
if ($user > 0) |
573
|
|
|
{ |
574
|
30 |
|
$this->template->assign_vars(array( |
575
|
30 |
|
'SEARCH_MATCHES' => $this->language->lang('TOTAL_IMAGES_SPRINTF', $count), |
576
|
30 |
|
'SEARCH_TITLE' => $this->language->lang('SEARCH_USER_IMAGES_OF', $this->user->data['username']), |
577
|
|
|
)); |
578
|
30 |
|
$this->pagination->generate_template_pagination(array( |
579
|
|
|
'routes' => array( |
580
|
30 |
|
'phpbbgallery_core_search_egosearch', |
581
|
|
|
'phpbbgallery_core_search_egosearch_page',), |
582
|
30 |
|
'params' => array()), 'pagination', 'page', $count, $limit, $start |
583
|
|
|
); |
584
|
|
|
} |
585
|
|
|
else |
586
|
|
|
{ |
587
|
4 |
|
$this->template->assign_vars(array( |
588
|
4 |
|
'TOTAL_IMAGES' => $this->language->lang('VIEW_ALBUM_IMAGES', $count), |
589
|
|
|
)); |
590
|
4 |
|
if ($pagination) |
591
|
|
|
{ |
592
|
3 |
|
$this->pagination->generate_template_pagination(array( |
593
|
|
|
'routes' => array( |
594
|
3 |
|
'phpbbgallery_core_search_recent', |
595
|
|
|
'phpbbgallery_core_search_recent_page',), |
596
|
3 |
|
'params' => array()), 'pagination', 'page', $count, $limit, $start |
597
|
|
|
); |
598
|
|
|
} |
599
|
|
|
} |
600
|
34 |
|
} |
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* Get top rated image |
604
|
|
|
* @param $limit |
605
|
|
|
* @param int $start |
606
|
|
|
*/ |
607
|
|
|
public function rating($limit, $start = 0) |
608
|
|
|
{ |
609
|
|
|
$this->gallery_auth->load_user_permissions($this->user->data['user_id']); |
610
|
|
|
$sql_array = array(); |
611
|
|
|
$sql_array['FROM'] = array( |
612
|
|
|
$this->images_table => 'i' |
613
|
|
|
); |
614
|
|
|
$sql_array['WHERE'] = $this->db->sql_in_set('image_album_id', $this->gallery_auth->acl_album_ids('i_view'), false, true) . ' and image_rate_avg <> 0'; |
615
|
|
|
$sql_array['SELECT'] = 'COUNT(image_id) as count'; |
616
|
|
|
$sql = $this->db->sql_build_query('SELECT', $sql_array); |
617
|
|
|
$result = $this->db->sql_query($sql); |
618
|
|
|
$row = $this->db->sql_fetchrow($result); |
619
|
|
|
$this->db->sql_freeresult($result); |
620
|
|
|
$count = $row['count']; |
621
|
|
|
$sql_array['SELECT'] = '* , a.album_name, a.album_status, a.album_user_id, a.album_id'; |
622
|
|
|
$sql_array['LEFT_JOIN'] = array( |
623
|
|
|
array( |
624
|
|
|
'FROM' => array($this->albums_table => 'a'), |
625
|
|
|
'ON' => 'a.album_id = i.image_album_id', |
626
|
|
|
) |
627
|
|
|
); |
628
|
|
|
$sql_array['ORDER_BY'] = 'image_rate_avg DESC, image_rates DESC'; |
629
|
|
|
$sql = $this->db->sql_build_query('SELECT', $sql_array); |
630
|
|
|
$result = $this->db->sql_query_limit($sql, $limit, $start); |
631
|
|
|
$rowset = array(); |
632
|
|
|
|
633
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
634
|
|
|
{ |
635
|
|
|
$rowset[] = $row; |
636
|
|
|
$users_array[$row['image_user_id']] = array(''); |
637
|
|
|
} |
638
|
|
|
$this->db->sql_freeresult($result); |
639
|
|
|
if (empty($rowset)) |
640
|
|
|
{ |
641
|
|
|
$this->template->assign_var('S_NO_SEARCH', true); |
642
|
|
|
trigger_error('NO_SEARCH'); |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
$this->template->assign_block_vars('imageblock', array( |
646
|
|
|
'BLOCK_NAME' => $this->language->lang('SEARCH_TOPRATED'), |
647
|
|
|
'U_BLOCK' => $this->helper->route('phpbbgallery_core_search_toprated'), |
648
|
|
|
)); |
649
|
|
|
$this->user_loader->load_users(array_keys($users_array)); |
|
|
|
|
650
|
|
|
// Now let's get display options |
651
|
|
|
$show_options = $this->gallery_config->get('rrc_gindex_display'); |
652
|
|
|
$thumbnail_link = $this->gallery_config->get('link_thumbnail'); |
653
|
|
|
$imagename_link = $this->gallery_config->get('link_image_name'); |
654
|
|
|
foreach ($rowset as $row) |
655
|
|
|
{ |
656
|
|
|
$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
$this->template->assign_vars(array( |
660
|
|
|
'SEARCH_MATCHES' => $this->language->lang('TOTAL_IMAGES_SPRINTF', $count), |
661
|
|
|
'SEARCH_TITLE' => $this->language->lang('SEARCH_TOPRATED'), |
662
|
|
|
)); |
663
|
|
|
$this->pagination->generate_template_pagination(array( |
664
|
|
|
'routes' => array( |
665
|
|
|
'phpbbgallery_core_search_toprated', |
666
|
|
|
'phpbbgallery_core_search_toprated_page',), |
667
|
|
|
'params' => array()), 'pagination', 'page', $count, $limit, $start |
668
|
|
|
); |
669
|
|
|
} |
670
|
|
|
} |
671
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths