Skip to content

Commit 9f98fbb

Browse files
authored
Merge pull request #313 from Leinad4Mind/improve-code
Fix recent-comments pagination + code improvments
2 parents 4c9f6da + 4a84931 commit 9f98fbb

File tree

10 files changed

+110
-101
lines changed

10 files changed

+110
-101
lines changed

acpcleanup/cleanup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function delete_pegas($unwanted_pegas, $obsolete_pegas)
226226
),
227227
),
228228

229-
'WHERE' => 'a.album_user_id <> ' . $this->album->get_public() . ' AND a.parent_id = 0',
229+
'WHERE' => 'a.album_user_id <> ' . (int) $this->album->get_public() . ' AND a.parent_id = 0',
230230
'ORDER_BY' => 'a.album_id DESC',
231231
);
232232
$sql = $this->db->sql_build_query('SELECT', $sql_array);

acpimport/acp/main_module.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function import()
302302

303303
$sql = 'SELECT username, user_colour, user_id
304304
FROM ' . USERS_TABLE . '
305-
WHERE user_id = ' . $user_id;
305+
WHERE user_id = ' . (int) $user_id;
306306
$result = $db->sql_query($sql);
307307
$user_row = $db->sql_fetchrow($result);
308308
$db->sql_freeresult($result);
@@ -339,7 +339,7 @@ function import()
339339
// Where do we put them to?
340340
$sql = 'SELECT album_id, album_name
341341
FROM ' . $table_prefix . 'gallery_albums
342-
WHERE album_id = ' . $album_id;
342+
WHERE album_id = ' . (int) $album_id;
343343
$result = $db->sql_query($sql);
344344
$album_row = $db->sql_fetchrow($result);
345345
$db->sql_freeresult($result);

core/album/display.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function generate_navigation($album_data)
137137
$album_parents = $this->get_parents($album_data);
138138

139139
// Display username for personal albums
140-
if ($album_data['album_user_id'] > \phpbbgallery\core\block::PUBLIC_ALBUM)
140+
if ($album_data['album_user_id'] > (int) \phpbbgallery\core\block::PUBLIC_ALBUM)
141141
{
142142
$sql = 'SELECT user_id, username, user_colour
143143
FROM ' . USERS_TABLE . '
@@ -179,9 +179,9 @@ public function generate_navigation($album_data)
179179
'ALBUM_ID' => $album_data['album_id'],
180180
'ALBUM_NAME' => $album_data['album_name'],
181181
'ALBUM_DESC' => generate_text_for_display($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_bitfield'], $album_data['album_desc_options']),
182-
'ALBUM_CONTEST_START' => ($album_data['album_type'] == \phpbbgallery\core\block::TYPE_CONTEST) ? $this->language->lang('CONTEST_START' . ((($album_data['contest_start']) < time())? 'ED' : 'S'), $this->user->format_date(($album_data['contest_start']), false, true)) : '',
183-
'ALBUM_CONTEST_RATING' => ($album_data['album_type'] == \phpbbgallery\core\block::TYPE_CONTEST) ? $this->language->lang('CONTEST_RATING_START' . ((($album_data['contest_start'] + $album_data['contest_rating']) < time())? 'ED' : 'S'), $this->user->format_date(($album_data['contest_start'] + $album_data['contest_rating']), false, true)) : '',
184-
'ALBUM_CONTEST_END' => ($album_data['album_type'] == \phpbbgallery\core\block::TYPE_CONTEST) ? $this->language->lang('CONTEST_END' . ((($album_data['contest_start'] + $album_data['contest_end']) < time())? 'ED' : 'S'), $this->user->format_date(($album_data['contest_start'] + $album_data['contest_end']), false, true)) : '',
182+
'ALBUM_CONTEST_START' => ($album_data['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) ? $this->language->lang('CONTEST_START' . ((($album_data['contest_start']) < time())? 'ED' : 'S'), $this->user->format_date(($album_data['contest_start']), false, true)) : '',
183+
'ALBUM_CONTEST_RATING' => ($album_data['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) ? $this->language->lang('CONTEST_RATING_START' . ((($album_data['contest_start'] + $album_data['contest_rating']) < time())? 'ED' : 'S'), $this->user->format_date(($album_data['contest_start'] + $album_data['contest_rating']), false, true)) : '',
184+
'ALBUM_CONTEST_END' => ($album_data['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) ? $this->language->lang('CONTEST_END' . ((($album_data['contest_start'] + $album_data['contest_end']) < time())? 'ED' : 'S'), $this->user->format_date(($album_data['contest_start'] + $album_data['contest_end']), false, true)) : '',
185185
'U_VIEW_ALBUM' => $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $album_data['album_id'])),
186186
));
187187

@@ -199,7 +199,8 @@ public function generate_navigation($album_data)
199199
*/
200200
public function get_parents($album_data)
201201
{
202-
$album_parents = array();
202+
$album_parents = [];
203+
203204
if ($album_data['parent_id'] > 0)
204205
{
205206
if ($album_data['album_parents'] == '')
@@ -210,11 +211,12 @@ public function get_parents($album_data)
210211
AND right_id > ' . (int) $album_data['right_id'] . '
211212
AND album_user_id = ' . (int) $album_data['album_user_id'] . '
212213
ORDER BY left_id ASC';
214+
213215
$result = $this->db->sql_query($sql);
214216

215217
while ($row = $this->db->sql_fetchrow($result))
216218
{
217-
$album_parents[$row['album_id']] = array($row['album_name'], (int) $row['album_type']);
219+
$album_parents[$row['album_id']] = [$row['album_name'], (int) $row['album_type']];
218220
}
219221
$this->db->sql_freeresult($result);
220222

@@ -344,8 +346,8 @@ public function display_albums($root_data = '', $display_moderators = true, $ret
344346
{
345347
$mark_read = 'all';
346348
}
347-
$root_data = array('album_id' => \phpbbgallery\core\block::PUBLIC_ALBUM);
348-
$sql_where = 'a.album_user_id = ' . \phpbbgallery\core\block::PUBLIC_ALBUM;
349+
$root_data = array('album_id' => (int) \phpbbgallery\core\block::PUBLIC_ALBUM);
350+
$sql_where = 'a.album_user_id = ' . (int) \phpbbgallery\core\block::PUBLIC_ALBUM;
349351
}
350352
else if ($root_data == 'personal')
351353
{
@@ -354,7 +356,7 @@ public function display_albums($root_data = '', $display_moderators = true, $ret
354356
$mark_read = 'all';
355357
}
356358
$root_data = array('album_id' => 0);
357-
$sql_where = 'a.album_user_id > ' . \phpbbgallery\core\block::PUBLIC_ALBUM;
359+
$sql_where = 'a.album_user_id > ' . (int) \phpbbgallery\core\block::PUBLIC_ALBUM;
358360
$num_pegas = $this->config['phpbb_gallery_num_pegas'];
359361
$first_char = $this->request->variable('first_char', '');
360362
if ($first_char == 'other')
@@ -601,7 +603,7 @@ public function display_albums($root_data = '', $display_moderators = true, $ret
601603
foreach ($album_rows as $row)
602604
{
603605
// Empty category
604-
if (($row['parent_id'] == $root_data['album_id']) && ($row['album_type'] == \phpbbgallery\core\block::TYPE_CAT))
606+
if (($row['parent_id'] == $root_data['album_id']) && ($row['album_type'] == (int) \phpbbgallery\core\block::TYPE_CAT))
605607
{
606608
$this->template->assign_block_vars('albumrow', array(
607609
'S_IS_CAT' => true,
@@ -676,7 +678,7 @@ public function display_albums($root_data = '', $display_moderators = true, $ret
676678
$folder_alt = ($album_unread) ? 'NEW_IMAGES' : 'NO_NEW_IMAGES';
677679
$folder_image = ($album_unread) ? 'forum_unread' : 'forum_read';
678680
}
679-
if ($row['album_status'] == \phpbbgallery\core\block::ALBUM_LOCKED)
681+
if ($row['album_status'] == (int) \phpbbgallery\core\block::ALBUM_LOCKED)
680682
{
681683
$folder_image = ($album_unread) ? 'forum_unread_locked' : 'forum_read_locked';
682684
$folder_alt = 'ALBUM_LOCKED';
@@ -721,12 +723,12 @@ public function display_albums($root_data = '', $display_moderators = true, $ret
721723
$s_subalbums_list = (string) implode(', ', $s_subalbums_list);
722724
$catless = ($row['parent_id'] == $root_data['album_id']) ? true : false;
723725

724-
$s_username_hidden = ($lastimage_album_type == \phpbbgallery\core\block::TYPE_CONTEST) && $lastimage_contest_marked && !$this->gallery_auth->acl_check('m_status', $album_id, $row['album_user_id']) && ($this->user->data['user_id'] != $row['album_last_user_id'] || $row['album_last_user_id'] == ANONYMOUS);
726+
$s_username_hidden = ($lastimage_album_type == (int) \phpbbgallery\core\block::TYPE_CONTEST) && $lastimage_contest_marked && !$this->gallery_auth->acl_check('m_status', $album_id, $row['album_user_id']) && ($this->user->data['user_id'] != $row['album_last_user_id'] || $row['album_last_user_id'] == ANONYMOUS);
725727

726728
$this->template->assign_block_vars('albumrow', array(
727729
'S_IS_CAT' => false,
728730
'S_NO_CAT' => $catless && !$last_catless,
729-
'S_LOCKED_ALBUM' => ($row['album_status'] == \phpbbgallery\core\block::ALBUM_LOCKED) ? true : false,
731+
'S_LOCKED_ALBUM' => ($row['album_status'] == (int) \phpbbgallery\core\block::ALBUM_LOCKED) ? true : false,
730732
'S_UNREAD_ALBUM' => ($album_unread) ? true : false,
731733
'S_LIST_SUBALBUMS' => ($row['display_subalbum_list']) ? true : false,
732734
'S_SUBALBUMS' => (sizeof($subalbums_list)) ? true : false,

core/controller/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function base()
225225
'S_RECENT_COMMENTS' => $this->helper->route('phpbbgallery_core_search_commented'),
226226
'COMMENTS_EXPAND' => $this->gallery_config->get('rrc_gindex_comments') ? true : false,
227227
));
228-
$this->gallery_search->recent_comments($this->gallery_config->get('items_per_page'), 0);
228+
$this->gallery_search->recent_comments($this->gallery_config->get('items_per_page'), 0, false);
229229
}
230230
}
231231
$this->display_legend();

core/controller/moderate.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
*
55
* @package phpBB Gallery Core
6-
* @copyright (c) 2014 nickvergessen
6+
* @copyright (c) 2014 nickvergessen | 2025 Leinad4Mind
77
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
88
*
99
*/
@@ -425,56 +425,51 @@ public function album_overview($album_id, $page)
425425
{
426426
if (confirm_box(true) || $moving_target)
427427
{
428+
$message = '';
428429
switch ($action)
429430
{
430431
case 'approve':
431432
$this->image->approve_images($actions_array, $album_id);
432433
$this->album->update_info($album_id);
433-
434434
$message = $this->language->lang('WAITING_APPROVED_IMAGE', count($actions_array));
435-
$this->url->meta_refresh(3, $back_link);
436-
trigger_error($message);
437435
break;
436+
438437
case 'unapprove':
439438
$this->image->unapprove_images($actions_array, $album_id);
440439
$this->album->update_info($album_id);
441-
442440
$message = $this->language->lang('WAITING_UNAPPROVED_IMAGE', count($actions_array));
443-
$this->url->meta_refresh(3, $back_link);
444-
trigger_error($message);
445441
break;
442+
446443
case 'lock':
447444
$this->image->lock_images($actions_array, $album_id);
448445
$this->album->update_info($album_id);
449-
450446
$message = $this->language->lang('WAITING_LOCKED_IMAGE', count($actions_array));
451-
$this->url->meta_refresh(3, $back_link);
452-
trigger_error($message);
453447
break;
448+
454449
case 'delete':
455450
$this->moderate->delete_images($actions_array);
456451
$this->album->update_info($album_id);
457-
458452
$message = $this->language->lang('DELETED_IMAGES', count($actions_array));
459-
$this->url->meta_refresh(3, $back_link);
460-
trigger_error($message);
461453
break;
454+
462455
case 'move':
463456
$this->image->move_image($actions_array, $moving_target);
464457
$this->album->update_info($album_id);
465458
$this->album->update_info($moving_target);
466-
467459
$message = $this->language->lang('MOVED_IMAGES', count($actions_array));
468-
$this->url->meta_refresh(3, $back_link);
469-
trigger_error($message);
470460
break;
461+
471462
case 'report':
472463
$this->report->close_reports_by_image($actions_array);
473464
$message = $this->language->lang('WAITING_REPORTED_DONE', count($actions_array));
474-
$this->url->meta_refresh(3, $back_link);
475-
trigger_error($message);
476465
break;
477466
}
467+
468+
if (!empty($message))
469+
{
470+
$this->url->meta_refresh(3, $back_link);
471+
trigger_error($message);
472+
}
478473
}
479474
else
480475
{

core/image/image.php

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
*
55
* @package phpBB Gallery Core
6-
* @copyright (c) 2014 nickvergessen
6+
* @copyright (c) 2014 nickvergessen | Leinad4Mind 2025
77
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
88
*
99
*/
@@ -613,50 +613,19 @@ public function get_last_image()
613613

614614
return $row;
615615
}
616-
public function assign_block($image_block_name, $image_data, $display_option = 0, $thumbanil_link = 'image_page', $imagename_link = 'image_page')
616+
public function assign_block($image_block_name, $image_data, $display_option = 0, $thumbnail_link = 'image_page', $imagename_link = 'image_page')
617617
{
618618
// Now let's get display options
619-
$show_ip = $show_ratings = $show_username = $show_views = $show_time = $show_imagename = $show_comments = $show_album = false;
620-
if ($display_option >= self::IMAGE_SHOW_IP)
621-
{
622-
$show_ip = true;
623-
$display_option = $display_option - self::IMAGE_SHOW_IP;
624-
}
625-
if ($display_option >= self::IMAGE_SHOW_RATINGS)
626-
{
627-
$show_ratings = true;
628-
$display_option = $display_option - self::IMAGE_SHOW_RATINGS;
629-
}
630-
if ($display_option >= self::IMAGE_SHOW_USERNAME)
631-
{
632-
$show_username = true;
633-
$display_option = $display_option - self::IMAGE_SHOW_USERNAME;
634-
}
635-
if ($display_option >= self::IMAGE_SHOW_VIEWS)
636-
{
637-
$show_views = true;
638-
$display_option = $display_option - self::IMAGE_SHOW_VIEWS;
639-
}
640-
if ($display_option >= self::IMAGE_SHOW_TIME)
641-
{
642-
$show_time = true;
643-
$display_option = $display_option - self::IMAGE_SHOW_TIME;
644-
}
645-
if ($display_option >= self::IMAGE_SHOW_IMAGENAME)
646-
{
647-
$show_imagename = true;
648-
$display_option = $display_option - self::IMAGE_SHOW_IMAGENAME;
649-
}
650-
if ($display_option >= self::IMAGE_SHOW_COMMENTS)
651-
{
652-
$show_comments = true;
653-
$display_option = $display_option - self::IMAGE_SHOW_COMMENTS;
654-
}
655-
if ($display_option == self::IMAGE_SHOW_ALBUM)
656-
{
657-
$show_album = true;
658-
}
659-
switch ($thumbanil_link)
619+
$show_ip = ($display_option & self::IMAGE_SHOW_IP) !== 0;
620+
$show_ratings = ($display_option & self::IMAGE_SHOW_RATINGS) !== 0;
621+
$show_username = ($display_option & self::IMAGE_SHOW_USERNAME) !== 0;
622+
$show_views = ($display_option & self::IMAGE_SHOW_VIEWS) !== 0;
623+
$show_time = ($display_option & self::IMAGE_SHOW_TIME) !== 0;
624+
$show_imagename = ($display_option & self::IMAGE_SHOW_IMAGENAME) !== 0;
625+
$show_comments = ($display_option & self::IMAGE_SHOW_COMMENTS) !== 0;
626+
$show_album = ($display_option & self::IMAGE_SHOW_ALBUM) !== 0;
627+
628+
switch ($thumbnail_link)
660629
{
661630
case 'image_page':
662631
$action = $this->helper->route('phpbbgallery_core_image', array('image_id' => (int) $image_data['image_id']));

core/log.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ public function delete_logs($mark)
127127
* @param array $additional
128128
* @internal param int $start start count used to build paging
129129
*/
130-
public function build_list($type, $limit = 0, $page = 1, $album = 0, $image = 0, $additional = array())
130+
public function build_list($type, $limit = 0, $page = 1, $album = 0, $image = 0, $additional = [])
131131
{
132132
if ($limit == 0)
133133
{
134134
$limit = $this->gallery_config->get('items_per_page');
135135
}
136-
$this->language->add_lang(array('info_acp_gallery_logs'), 'phpbbgallery/core');
136+
$this->language->add_lang(['info_acp_gallery_logs'], 'phpbbgallery/core');
137137

138138
$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
139139
$sql_array = array(
@@ -147,7 +147,7 @@ public function build_list($type, $limit = 0, $page = 1, $album = 0, $image = 0,
147147
)
148148
)
149149
);
150-
$sql_where = array();
150+
$sql_where = [];
151151
if ($type != 'all')
152152
{
153153
$sql_where[] = "l.log_type = '" . $this->db->sql_escape($type) . "'";
@@ -261,8 +261,7 @@ public function build_list($type, $limit = 0, $page = 1, $album = 0, $image = 0,
261261
'U_LOG_IP' => $var['ip'],
262262
'U_ALBUM_LINK' => $var['album'] != 0 ? $this->helper->route('phpbbgallery_core_album', array('album_id' => $var['album'])) : false,
263263
'U_IMAGE_LINK' => $var['image'] != 0 ? $this->helper->route('phpbbgallery_core_image', array('image_id' => $var['image'])) : false,
264-
//'U_LOG_ACTION' => $description,
265-
'U_LOG_ACTION' => $this->language->lang($var['description'][0], isset($var['description'][1]) ? $var['description'][1] : false, isset($var['description'][2]) ? $var['description'][2] : false, isset($var['description'][3]) ? $var['description'][3] : false),
264+
'U_LOG_ACTION' => isset($var['description']) && is_array($var['description']) ? $this->language->lang($var['description'][0], $var['description'][1] ?? false, $var['description'][2] ?? false, $var['description'][3] ?? false) : '',
266265
'U_TIME' => $this->user->format_date($var['time']),
267266
));
268267
}

0 commit comments

Comments
 (0)