function main($id, $mode) { global $auth, $cache, $config, $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_ext_gallery, $request; global $phpbb_dispatcher, $table_prefix, $table_name, $phpbb_container, $request, $moderators_table, $permissions_table, $roles_table, $users_table; $helper = $phpbb_container->get('controller.helper'); $pagination = $phpbb_container->get('pagination'); // Let us define some helpers; $albums_table = $table_prefix . 'gallery_albums'; $contests_table = $table_prefix . 'gallery_contests'; $tracking_table = $table_prefix . 'gallery_albums_tracking'; // Init ext gallery $phpbb_ext_gallery = new \phpbbgallery\core\core($auth, $cache, $config, $db, $template, $user, $phpEx, $phpbb_root_path); $phpbb_ext_gallery->init(); $user->add_lang_ext('phpbbgallery/core', array('gallery_acp', 'gallery')); // Init auth //$gallery_cache = new \phpbbgallery\core\cache($cache, $db); //$gallery_user = new \phpbbgallery\core\user($db, $phpbb_dispatcher, $table_name); $gallery_user = $phpbb_container->get('phpbbgallery.core.user'); //$phpbb_ext_gallery_core_auth = new \phpbbgallery\core\auth\auth($gallery_cache, $db, $gallery_user, $permissions_table, $roles_table, $users_table); $phpbb_ext_gallery_core_auth = $phpbb_container->get('phpbbgallery.core.auth'); // Init manage albums $manage_albums = new \phpbbgallery\core\album\manage($request->variable('user_id', 0), $request->variable('parent_id', 0), $this->u_action); // Init album $phpbb_ext_gallery_core_album = $phpbb_container->get('phpbbgallery.core.album'); $phpbb_ext_gallery_core_album_display = $phpbb_container->get('phpbbgallery.core.album.display'); // Init contest $phpbb_gallery_contest = new \phpbbgallery\core\contest(); $this->tpl_name = 'gallery_albums'; $this->page_title = 'ACP_GALLERY_MANAGE_ALBUMS'; $form_key = 'acp_gallery_albums'; add_form_key($form_key); $action = $request->variable('action', ''); $update = isset($_POST['update']) ? true : false; $album_id = $request->variable('a', 0); $this->parent_id = $request->variable('parent_id', 0); $album_data = $errors = array(); if ($update && !check_form_key($form_key)) { $update = false; $errors[] = $user->lang['FORM_INVALID']; } // Major routines if ($update) { switch ($action) { case 'delete': $action_subalbums = $request->variable('action_subalbums', ''); $subalbums_to_id = $request->variable('subalbums_to_id', 0); $action_images = $request->variable('action_images', ''); $images_to_id = $request->variable('images_to_id', 0); $errors = $manage_albums->delete_album($album_id, $action_images, $action_subalbums, $images_to_id, $subalbums_to_id); if (sizeof($errors)) { break; } $cache->destroy('sql', $table_prefix . 'gallery_albums'); trigger_error($user->lang['ALBUM_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); break; case 'edit': $album_data = array('album_id' => $album_id); // No break; here // No break; here case 'add': $album_data += array('parent_id' => $request->variable('album_parent_id', $this->parent_id), 'album_type' => $request->variable('album_type', $phpbb_ext_gallery_core_album::TYPE_UPLOAD), 'type_action' => $request->variable('type_action', ''), 'album_status' => $request->variable('album_status', $phpbb_ext_gallery_core_album::STATUS_OPEN), 'album_parents' => '', 'album_name' => utf8_normalize_nfc($request->variable('album_name', '', true)), 'album_desc' => utf8_normalize_nfc($request->variable('album_desc', '', true)), 'album_desc_uid' => '', 'album_desc_options' => 7, 'album_desc_bitfield' => '', 'album_image' => $request->variable('album_image', ''), 'album_watermark' => $request->variable('album_watermark', false), 'album_sort_key' => $request->variable('album_sort_key', ''), 'album_sort_dir' => $request->variable('album_sort_dir', ''), 'display_subalbum_list' => $request->variable('display_subalbum_list', false), 'display_on_index' => $request->variable('display_on_index', false), 'display_in_rrc' => $request->variable('display_in_rrc', false)); /** * Event to send requested data * @event phpbbgallery.core.acp.albums.request_data * @var string action Action we are taking * @var int album_id Album we are doing it to * @var array album_data Album data for the album * @since 1.2.0 */ $vars = array('action', 'album_id', 'album_data'); extract($phpbb_dispatcher->trigger_event('phpbbgallery.core.acp.albums.request_data', compact($vars))); // Categories are not able to be locked... if ($album_data['album_type'] == $phpbb_ext_gallery_core_album::TYPE_CAT) { $album_data['album_status'] = $phpbb_ext_gallery_core_album::STATUS_OPEN; } // Contests need contest_data, freaky... :-O $contest_data = array('contest_start' => $request->variable('contest_start', ''), 'contest_rating' => $request->variable('contest_rating', ''), 'contest_end' => $request->variable('contest_end', '')); // Get data for album description if specified if ($album_data['album_desc']) { generate_text_for_storage($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_bitfield'], $album_data['album_desc_options'], $request->variable('desc_parse_bbcode', false), $request->variable('desc_parse_urls', false), $request->variable('desc_parse_smilies', false)); } $errors = $manage_albums->update_album_data($album_data, $contest_data); if (!sizeof($errors)) { $album_perm_from = $request->variable('album_perm_from', 0); // Copy permissions? You do not need permissions for that in the gallery if ($album_perm_from && $album_perm_from != $album_data['album_id']) { // If we edit a album delete current permissions first if ($action == 'edit') { $sql = 'DELETE FROM ' . $table_prefix . 'gallery_permissions WHERE perm_album_id = ' . $album_data['album_id']; $db->sql_query($sql); $sql = 'DELETE FROM ' . $table_prefix . 'gallery_modscache WHERE album_id = ' . $album_data['album_id']; $db->sql_query($sql); } $sql = 'SELECT * FROM ' . $table_prefix . 'gallery_permissions WHERE perm_album_id = ' . $album_perm_from; $result = $db->sql_query($sql); $perm_data = array(); while ($row = $db->sql_fetchrow($result)) { $perm_data[] = array('perm_role_id' => $row['perm_role_id'], 'perm_album_id' => $album_data['album_id'], 'perm_user_id' => $row['perm_user_id'], 'perm_group_id' => $row['perm_group_id'], 'perm_system' => $row['perm_system']); } $db->sql_freeresult($result); $modscache_ary = array(); $sql = 'SELECT * FROM ' . $table_prefix . 'gallery_modscache WHERE album_id = ' . $album_perm_from; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $modscache_ary[] = array('album_id' => $album_data['album_id'], 'user_id' => $row['user_id'], 'username' => $row['username'], 'group_id' => $row['group_id'], 'group_name' => $row['group_name'], 'display_on_index' => $row['display_on_index']); } $db->sql_freeresult($result); $db->sql_multi_insert($table_prefix . 'gallery_permissions', $perm_data); $db->sql_multi_insert($table_prefix . 'gallery_modscache', $modscache_ary); } $cache->destroy('sql', $table_prefix . 'gallery_albums'); $cache->destroy('sql', $table_prefix . 'gallery_modscache'); $cache->destroy('sql', $table_prefix . 'gallery_permissions'); $cache->destroy('_albums'); $phpbb_ext_gallery->auth->set_user_permissions('all', ''); $acl_url = '&mode=manage&action=v_mask&album_id[]=' . $album_data['album_id']; $message = $action == 'add' ? $user->lang['ALBUM_CREATED'] : $user->lang['ALBUM_UPDATED']; $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . $phpbb_ext_gallery->url->append_sid('admin', 'index', 'i=-phpbbgallery-core-acp-permissions_module' . $acl_url) . '">', '</a>'); // Redirect directly to permission settings screen if ($action == 'add' && !$album_perm_from) { meta_refresh(5, $phpbb_ext_gallery->url->append_sid('admin', 'index', 'i=-phpbbgallery-core-acp-permissions_module' . $acl_url)); } trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); } break; } } switch ($action) { case 'move_up': case 'move_down': if (!$album_id) { trigger_error($user->lang['NO_ALBUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $sql = 'SELECT * FROM ' . $table_prefix . "gallery_albums\n\t\t\t\t\tWHERE album_id = {$album_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error($user->lang['NO_ALBUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $move_album_name = $manage_albums->move_album_by($row, $action, 1); if ($move_album_name !== false) { $log = $phpbb_container->get('phpbbgallery.core.log'); $log->add_log('admin', 'move', $row['album_id'], 0, array('LOG_ALBUM_' . strtoupper($action), $row['album_name'], $move_album_name)); $cache->destroy('sql', $table_prefix . 'gallery_albums'); } break; case 'sync': case 'sync_album': if (!$album_id) { trigger_error($user->lang['NO_ALBUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $sql = 'SELECT album_name, album_type FROM ' . $table_prefix . "gallery_albums\n\t\t\t\t\tWHERE album_id = {$album_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error($user->lang['NO_ALBUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $phpbb_ext_gallery_core_album->update_info($album_id); $log = $phpbb_container->get('phpbbgallery.core.log'); $log->add_log('admin', 'resync', $album_id, 0, array('LOG_ALBUM_SYNC', $row['album_name'])); $template->assign_var('L_ALBUM_RESYNCED', sprintf($user->lang['ALBUM_RESYNCED'], $row['album_name'])); break; case 'add': case 'edit': // Show form to create/modify a album if ($action == 'edit') { $this->page_title = 'EDIT_ALBUM'; $row = $phpbb_ext_gallery_core_album->get_info($album_id); $old_album_type = $row['album_type']; if (!$update) { $album_data = $row; } else { $album_data['left_id'] = $row['left_id']; $album_data['right_id'] = $row['right_id']; } if ($row['album_type'] == $phpbb_ext_gallery_core_album::TYPE_CONTEST) { $contest_data = $phpbb_gallery_contest->get_contest($album_id, 'album'); } else { // Default values, 3 days later rate and 7 for the end of the contest $contest_data = array('contest_start' => time(), 'contest_rating' => 3 * 86400, 'contest_end' => 7 * 86400); } // Make sure no direct child albums are able to be selected as parents. $exclude_albums = array(); foreach ($phpbb_ext_gallery_core_album_display->get_branch($phpbb_ext_gallery_core_album::PUBLIC_ALBUM, $album_id, 'children') as $row) { $exclude_albums[] = $row['album_id']; } $parents_list = $phpbb_ext_gallery_core_album->get_albumbox(true, '', $album_data['parent_id'], false, $exclude_albums); /* $album_data['album_password_confirm'] = $album_data['album_password']; */ } else { $this->page_title = 'CREATE_ALBUM'; $album_id = $this->parent_id; $parents_list = $phpbb_ext_gallery_core_album->get_albumbox(true, '', $this->parent_id); // Fill album data with default values if (!$update) { $album_data = array('parent_id' => $this->parent_id, 'album_type' => $phpbb_ext_gallery_core_album::TYPE_UPLOAD, 'album_status' => $phpbb_ext_gallery_core_album::STATUS_OPEN, 'album_name' => utf8_normalize_nfc($request->variable('album_name', '', true)), 'album_desc' => '', 'album_image' => '', 'album_watermark' => true, 'album_sort_key' => '', 'album_sort_dir' => '', 'display_subalbum_list' => true, 'display_on_index' => true, 'display_in_rrc' => true); /** * Event to send default data * * @event phpbbgallery.core.acp.albums.default_data * @var action action Action taken * @var array album_data Album data array * @since 1.2.0 */ $vars = array('action', 'album_data'); extract($phpbb_dispatcher->trigger_event('phpbbgallery.core.acp.albums.default_data', compact($vars))); // Default values, 3 days later rate and 7 for the end of the contest $contest_data = array('contest_start' => time(), 'contest_rating' => 3 * 86400, 'contest_end' => 7 * 86400); } } $album_desc_data = array('text' => $album_data['album_desc'], 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); // Parse desciption if specified if ($album_data['album_desc']) { if (!isset($album_data['album_desc_uid'])) { // Before we are able to display the preview and plane text, we need to parse our request_var()'d value... $album_data['album_desc_uid'] = ''; $album_data['album_desc_bitfield'] = ''; $album_data['album_desc_options'] = 0; generate_text_for_storage($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_bitfield'], $album_data['album_desc_options'], $request->variable('desc_allow_bbcode', false), $request->variable('desc_allow_urls', false), $request->variable('desc_allow_smilies', false)); } // decode... $album_desc_data = generate_text_for_edit($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_options']); } $album_type_options = ''; $album_type_ary = array($phpbb_ext_gallery_core_album::TYPE_CAT => 'CAT', $phpbb_ext_gallery_core_album::TYPE_UPLOAD => 'UPLOAD'); //, $phpbb_ext_gallery_core_album::TYPE_CONTEST => 'CONTEST'); foreach ($album_type_ary as $value => $lang) { $album_type_options .= '<option value="' . $value . '"' . ($value == $album_data['album_type'] ? ' selected="selected"' : '') . '>' . $user->lang['ALBUM_TYPE_' . $lang] . '</option>'; } $album_sort_key_options = ''; $album_sort_key_options .= '<option' . (!in_array($album_data['album_sort_key'], array('t', 'n', 'vc', 'u', 'ra', 'r', 'c', 'lc')) ? ' selected="selected"' : '') . " value=''>" . $user->lang['SORT_DEFAULT'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 't' ? ' selected="selected"' : '') . " value='t'>" . $user->lang['TIME'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 'n' ? ' selected="selected"' : '') . " value='n'>" . $user->lang['IMAGE_NAME'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 'vc' ? ' selected="selected"' : '') . " value='vc'>" . $user->lang['GALLERY_VIEWS'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 'u' ? ' selected="selected"' : '') . " value='u'>" . $user->lang['USERNAME'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 'ra' ? ' selected="selected"' : '') . " value='ra'>" . $user->lang['RATING'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 'r' ? ' selected="selected"' : '') . " value='r'>" . $user->lang['RATES_COUNT'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 'c' ? ' selected="selected"' : '') . " value='c'>" . $user->lang['COMMENTS'] . '</option>'; $album_sort_key_options .= '<option' . ($album_data['album_sort_key'] == 'lc' ? ' selected="selected"' : '') . " value='lc'>" . $user->lang['NEW_COMMENT'] . '</option>'; $album_sort_dir_options = ''; $album_sort_dir_options .= '<option' . ($album_data['album_sort_dir'] != 'd' && $album_data['album_sort_dir'] != 'a' ? ' selected="selected"' : '') . " value=''>" . $user->lang['SORT_DEFAULT'] . '</option>'; $album_sort_dir_options .= '<option' . ($album_data['album_sort_dir'] == 'd' ? ' selected="selected"' : '') . " value='d'>" . $user->lang['SORT_DESCENDING'] . '</option>'; $album_sort_dir_options .= '<option' . ($album_data['album_sort_dir'] == 'a' ? ' selected="selected"' : '') . " value='a'>" . $user->lang['SORT_ASCENDING'] . '</option>'; $statuslist = '<option value="' . $phpbb_ext_gallery_core_album::STATUS_OPEN . '"' . ($album_data['album_status'] == $phpbb_ext_gallery_core_album::STATUS_OPEN ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . $phpbb_ext_gallery_core_album::STATUS_LOCKED . '"' . ($album_data['album_status'] == $phpbb_ext_gallery_core_album::STATUS_LOCKED ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>'; $sql = 'SELECT album_id FROM ' . $table_prefix . 'gallery_albums WHERE album_type = ' . $phpbb_ext_gallery_core_album::TYPE_UPLOAD . ' AND album_user_id = ' . $phpbb_ext_gallery_core_album::PUBLIC_ALBUM . "\n\t\t\t\t\t\tAND album_id <> {$album_id}"; $result = $db->sql_query_limit($sql, 1); $uploadable_album_exists = false; if ($db->sql_fetchrow($result)) { $uploadable_album_exists = true; } $db->sql_freeresult($result); // Subalbum move options if ($action == 'edit' && in_array($album_data['album_type'], array($phpbb_ext_gallery_core_album::TYPE_UPLOAD, $phpbb_ext_gallery_core_album::TYPE_CONTEST))) { $subalbums_id = array(); $subalbums = $phpbb_ext_gallery_core_album_display->get_branch($phpbb_ext_gallery_core_album::PUBLIC_ALBUM, $album_id, 'children'); foreach ($subalbums as $row) { $subalbums_id[] = $row['album_id']; } $albums_list = $phpbb_ext_gallery_core_album->get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id); if ($uploadable_album_exists) { $template->assign_vars(array('S_MOVE_ALBUM_OPTIONS' => $phpbb_ext_gallery_core_album->get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id, $phpbb_ext_gallery_core_album::PUBLIC_ALBUM, $phpbb_ext_gallery_core_album::TYPE_UPLOAD))); } $template->assign_vars(array('S_HAS_SUBALBUMS' => $album_data['right_id'] - $album_data['left_id'] > 1 ? true : false, 'S_ALBUMS_LIST' => $albums_list)); } else { if ($uploadable_album_exists) { $template->assign_vars(array('S_MOVE_ALBUM_OPTIONS' => $phpbb_ext_gallery_core_album->get_albumbox(true, '', $album_data['parent_id'], false, $album_id, 0, $phpbb_ext_gallery_core_album::TYPE_UPLOAD))); } } /* if (strlen($album_data['album_password']) == 32) { $errors[] = $user->lang['ALBUM_PASSWORD_OLD']; } */ $template->assign_vars(array('S_EDIT_ALBUM' => true, 'S_ERROR' => sizeof($errors) ? true : false, 'S_PARENT_ID' => $this->parent_id, 'S_ALBUM_PARENT_ID' => $album_data['parent_id'], 'S_ADD_ACTION' => $action == 'add' ? true : false, 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id, 'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action={$action}&a={$album_id}", 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'], 'L_TITLE' => $user->lang[$this->page_title], 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'ALBUM_NAME' => $album_data['album_name'], 'ALBUM_IMAGE' => $album_data['album_image'], 'ALBUM_IMAGE_SRC' => $album_data['album_image'] ? $phpbb_ext_gallery->url->path('phpbb') . $album_data['album_image'] : '', 'ALBUM_DESC' => $album_desc_data['text'], 'S_DESC_BBCODE_CHECKED' => $album_desc_data['allow_bbcode'] ? true : false, 'S_DESC_SMILIES_CHECKED' => $album_desc_data['allow_smilies'] ? true : false, 'S_DESC_URLS_CHECKED' => $album_desc_data['allow_urls'] ? true : false, 'S_ALBUM_TYPE_OPTIONS' => $album_type_options, 'S_STATUS_OPTIONS' => $statuslist, 'S_PARENT_OPTIONS' => $parents_list, 'S_ALBUM_OPTIONS' => $phpbb_ext_gallery_core_album->get_albumbox(true, '', $action == 'add' ? $album_data['parent_id'] : false, false, $action == 'edit' ? $album_data['album_id'] : false), 'S_ALBUM_ORIG_UPLOAD' => isset($old_album_type) && $old_album_type == $phpbb_ext_gallery_core_album::TYPE_UPLOAD ? true : false, 'S_ALBUM_ORIG_CAT' => isset($old_album_type) && $old_album_type == $phpbb_ext_gallery_core_album::TYPE_CAT ? true : false, 'S_ALBUM_ORIG_CONTEST' => isset($old_album_type) && $old_album_type == $phpbb_ext_gallery_core_album::TYPE_CONTEST ? true : false, 'S_ALBUM_UPLOAD' => $album_data['album_type'] == $phpbb_ext_gallery_core_album::TYPE_UPLOAD ? true : false, 'S_ALBUM_CAT' => $album_data['album_type'] == $phpbb_ext_gallery_core_album::TYPE_CAT ? true : false, 'S_ALBUM_CONTEST' => $album_data['album_type'] == $phpbb_ext_gallery_core_album::TYPE_CONTEST ? true : false, 'ALBUM_UPLOAD' => $phpbb_ext_gallery_core_album::TYPE_UPLOAD, 'ALBUM_CAT' => $phpbb_ext_gallery_core_album::TYPE_CAT, 'ALBUM_CONTEST' => $phpbb_ext_gallery_core_album::TYPE_CONTEST, 'S_CAN_COPY_PERMISSIONS' => true, 'S_ALBUM_WATERMARK' => $album_data['album_watermark'] ? true : false, 'ALBUM_SORT_KEY_OPTIONS' => $album_sort_key_options, 'ALBUM_SORT_DIR_OPTIONS' => $album_sort_dir_options, 'S_DISPLAY_SUBALBUM_LIST' => $album_data['display_subalbum_list'] ? true : false, 'S_DISPLAY_ON_INDEX' => $album_data['display_on_index'] ? true : false, 'S_DISPLAY_IN_RRC' => $album_data['display_in_rrc'] ? true : false)); /** * Event after assigning data to templete * * @event phpbbgallery.core.acp.albums.send_to_template * @var action action Action taken * @var array album_data Album data array * @since 1.2.0 */ $vars = array('action', 'album_data'); extract($phpbb_dispatcher->trigger_event('phpbbgallery.core.acp.albums.send_to_template', compact($vars))); return; break; case 'delete': if (!$album_id) { trigger_error($user->lang['NO_ALBUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $album_data = $phpbb_ext_gallery_core_album->get_info($album_id); $subalbums_id = array(); $subalbums = $phpbb_ext_gallery_core_album_display->get_branch($phpbb_ext_gallery_core_album::PUBLIC_ALBUM, $album_id, 'children'); foreach ($subalbums as $row) { $subalbums_id[] = $row['album_id']; } $albums_list = $phpbb_ext_gallery_core_album->get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id); $sql = 'SELECT album_id FROM ' . $table_prefix . 'gallery_albums WHERE album_type = ' . $phpbb_ext_gallery_core_album::TYPE_UPLOAD . "\n\t\t\t\t\t\tAND album_id <> {$album_id}\n\t\t\t\t\t\tAND album_user_id = " . $phpbb_ext_gallery_core_album::PUBLIC_ALBUM; $result = $db->sql_query_limit($sql, 1); if ($db->sql_fetchrow($result)) { $template->assign_vars(array('S_MOVE_ALBUM_OPTIONS' => $phpbb_ext_gallery_core_album->get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id, $phpbb_ext_gallery_core_album::PUBLIC_ALBUM, $phpbb_ext_gallery_core_album::TYPE_UPLOAD))); } $db->sql_freeresult($result); $parent_id = $this->parent_id == $album_id ? 0 : $this->parent_id; $template->assign_vars(array('S_DELETE_ALBUM' => true, 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&a=" . $album_id, 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id, 'ALBUM_NAME' => $album_data['album_name'], 'S_ALBUM_POST' => in_array($album_data['album_type'], array($phpbb_ext_gallery_core_album::TYPE_UPLOAD, $phpbb_ext_gallery_core_album::TYPE_CONTEST)) ? true : false, 'S_HAS_SUBALBUMS' => $album_data['right_id'] - $album_data['left_id'] > 1 ? true : false, 'S_ALBUMS_LIST' => $albums_list, 'S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '')); return; break; } // Default management page if (!$this->parent_id) { $navigation = $user->lang['GALLERY_INDEX']; } else { $navigation = '<a href="' . $this->u_action . '">' . $user->lang['GALLERY_INDEX'] . '</a>'; $albums_nav = $phpbb_ext_gallery_core_album_display->get_branch($phpbb_ext_gallery_core_album::PUBLIC_ALBUM, $this->parent_id, 'parents', 'descending'); foreach ($albums_nav as $row) { if ($row['album_id'] == $this->parent_id) { $navigation .= ' -> ' . $row['album_name']; } else { $navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['album_id'] . '">' . $row['album_name'] . '</a>'; } } } // Jumpbox $album_box = $phpbb_ext_gallery_core_album->get_albumbox(true, '', $this->parent_id, false, false); if ($action == 'sync' || $action == 'sync_album') { $template->assign_var('S_RESYNCED', true); } $sql = 'SELECT * FROM ' . $table_prefix . "gallery_albums\n\t\t\tWHERE parent_id = {$this->parent_id}\n\t\t\t\tAND album_user_id = " . $phpbb_ext_gallery_core_album::PUBLIC_ALBUM . ' ORDER BY left_id'; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { do { $album_type = $row['album_type']; if ($row['album_status'] == $phpbb_ext_gallery_core_album::STATUS_LOCKED) { $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />'; } else { $folder_image = $row['left_id'] + 1 != $row['right_id'] ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['SUBALBUM'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />'; } $url = $this->u_action . "&parent_id={$this->parent_id}&a={$row['album_id']}"; $template->assign_block_vars('albums', array('FOLDER_IMAGE' => $folder_image, 'ALBUM_IMAGE' => $row['album_image'] ? '<img src="' . $phpbb_ext_gallery->url->path('phpbb') . $row['album_image'] . '" alt="" />' : '', 'ALBUM_IMAGE_SRC' => $row['album_image'] ? $phpbb_ext_gallery->url->path('phpbb') . $row['album_image'] : '', 'ALBUM_NAME' => $row['album_name'], 'ALBUM_DESCRIPTION' => generate_text_for_display($row['album_desc'], $row['album_desc_uid'], $row['album_desc_bitfield'], $row['album_desc_options']), 'ALBUM_IMAGES' => $row['album_images'], 'S_ALBUM_POST' => $album_type != $phpbb_ext_gallery_core_album::TYPE_CAT ? true : false, 'U_ALBUM' => $this->u_action . '&parent_id=' . $row['album_id'], 'U_MOVE_UP' => $url . '&action=move_up', 'U_MOVE_DOWN' => $url . '&action=move_down', 'U_EDIT' => $url . '&action=edit', 'U_DELETE' => $url . '&action=delete', 'U_SYNC' => $url . '&action=sync')); } while ($row = $db->sql_fetchrow($result)); } else { if ($this->parent_id) { $row = $phpbb_ext_gallery_core_album->get_info($this->parent_id); $url = $this->u_action . '&parent_id=' . $this->parent_id . '&a=' . $row['album_id']; $template->assign_vars(array('S_NO_ALBUMS' => true, 'U_EDIT' => $url . '&action=edit', 'U_DELETE' => $url . '&action=delete', 'U_SYNC' => $url . '&action=sync')); } } $db->sql_freeresult($result); $template->assign_vars(array('ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'NAVIGATION' => $navigation, 'ALBUM_BOX' => $album_box, 'U_SEL_ACTION' => $this->u_action, 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id, 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar', 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'))); }
/** * Delete an image completly. * * @param array $images Array with the image_id(s) * @param array $filenames Array with filenames for the image_ids. If a filename is missing it's queried from the database. * Format: $image_id => $filename * @param bool $skip_files If set to true, we won't try to delete the source files. */ public function delete_images($images, $filenames = array(), $resync_albums = true, $skip_files = false) { global $phpbb_container, $table_prefix, $phpbb_dispatcher, $db; $image_tools = $phpbb_container->get('phpbbgallery.core.file.tool'); $album = $phpbb_container->get('phpbbgallery.core.album'); $phpbb_gallery_image_rating = new \phpbbgallery\core\rating($images); $phpbb_gallery_comment = $phpbb_container->get('phpbbgallery.core.comment'); $phpbb_gallery_notification = new \phpbbgallery\core\notification(); $phpbb_gallery_report = $phpbb_container->get('phpbbgallery.core.report'); $phpbb_gallery_contest = new \phpbbgallery\core\contest(); if (empty($images)) { return; } if (!$skip_files) { // Delete the files from the disc... $need_filenames = array(); foreach ($images as $image) { if (!isset($filenames[$image])) { $need_filenames[] = $image; } } $filenames = array_merge($filenames, self::get_filenames($need_filenames)); $image_tools->delete($filenames); } // Delete the ratings... $phpbb_gallery_image_rating->delete_ratings($images); $phpbb_gallery_comment->delete_images($images); $phpbb_gallery_notification->delete_images($images); $phpbb_gallery_report->delete_images($images); /** * Event delete images * * @event phpbbgallery.core.image.delete_images * @var array images array of the image ids we are deleting * @var array filenames array of the image filenames * @since 1.2.0 */ $vars = array('images', 'filenames'); extract($phpbb_dispatcher->trigger_event('phpbbgallery.core.image.delete_images', compact($vars))); $sql = 'SELECT image_album_id, image_contest_rank FROM ' . $table_prefix . 'gallery_images WHERE ' . $db->sql_in_set('image_id', $images) . ' GROUP BY image_album_id, image_contest_rank'; $result = $db->sql_query($sql); $resync_album_ids = $resync_contests = array(); while ($row = $db->sql_fetchrow($result)) { if ($row['image_contest_rank']) { $resync_contests[] = (int) $row['image_album_id']; } $resync_album_ids[] = (int) $row['image_album_id']; } $db->sql_freeresult($result); $resync_contests = array_unique($resync_contests); $resync_album_ids = array_unique($resync_album_ids); $sql = 'DELETE FROM ' . $table_prefix . 'gallery_images WHERE ' . $db->sql_in_set('image_id', $images); $db->sql_query($sql); // The images need to be deleted, before we grab the new winners. $phpbb_gallery_contest->resync_albums($resync_contests); if ($resync_albums) { foreach ($resync_album_ids as $album_id) { $album->update_info($album_id); } } return true; }