* - Check the request and get image_data * - Check the permissions and approval * - Main work here... * - Exif-Data * - Rating * - Posting comment * - Listing comment * */ /** * Check the request and get image_data */ $image_id = request_var('image_id', 0); $image_data = phpbb_gallery_image::get_info($image_id); $album_id = $image_data['image_album_id']; $album_data = phpbb_gallery_album::get_info($album_id); $user_id = $image_data['image_user_id']; if (!file_exists(phpbb_gallery_url::path('upload') . $image_data['image_filename'])) { $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' SET image_filemissing = 1 WHERE image_id = ' . $image_id; $db->sql_query($sql); } /** * Check the permissions and approval */ if (!phpbb_gallery::$auth->acl_check('i_view', $album_id, $album_data['album_user_id'])) { if (!$user->data['is_registered']) { login_box(phpbb_gallery_url::append_sid('relative', 'image_page', "album_id={$album_id}&image_id={$image_id}"), $user->lang['LOGIN_INFO']); } else { trigger_error('NOT_AUTHORISED');
function overview() { global $auth, $config, $db, $template, $user; $action = request_var('action', ''); $id = request_var('i', ''); $mode = 'overview'; if (!confirm_box(true)) { $confirm = false; $album_id = 0; switch ($action) { case 'images': $confirm = true; $confirm_lang = 'RESYNC_IMAGECOUNTS_CONFIRM'; break; case 'personals': $confirm = true; $confirm_lang = 'CONFIRM_OPERATION'; break; case 'stats': $confirm = true; $confirm_lang = 'CONFIRM_OPERATION'; break; case 'last_images': $confirm = true; $confirm_lang = 'CONFIRM_OPERATION'; break; case 'reset_rating': $album_id = request_var('reset_album_id', 0); $album_data = phpbb_gallery_album::get_info($album_id); $confirm = true; $confirm_lang = sprintf($user->lang['RESET_RATING_CONFIRM'], $album_data['album_name']); break; case 'purge_cache': $confirm = true; $confirm_lang = 'GALLERY_PURGE_CACHE_EXPLAIN'; break; } if ($confirm) { confirm_box(false, $album_id ? $confirm_lang : $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'reset_album_id' => $album_id))); } } else { switch ($action) { case 'images': if (!$auth->acl_get('a_board')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $total_images = $total_comments = 0; phpbb_gallery_user_helpers::update_users('all', array('user_images' => 0)); $sql = 'SELECT COUNT(image_id) num_images, image_user_id user_id, SUM(image_comments) AS num_comments FROM ' . GALLERY_IMAGES_TABLE . ' WHERE image_status <> ' . phpbb_gallery_image::STATUS_UNAPPROVED . ' GROUP BY image_user_id'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $total_images += $row['num_images']; $total_comments += $row['num_comments']; $image_user = new phpbb_gallery_user($db, $row['user_id'], false); $image_user->update_data(array('user_images' => $row['num_images'])); } $db->sql_freeresult($result); phpbb_gallery_config::set('num_images', $total_images); phpbb_gallery_config::set('num_comments', $total_comments); trigger_error($user->lang['RESYNCED_IMAGECOUNTS'] . adm_back_link($this->u_action)); break; case 'personals': if (!$auth->acl_get('a_board')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } phpbb_gallery_user_helpers::update_users('all', array('personal_album_id' => 0)); $sql = 'SELECT album_id, album_user_id FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_user_id <> ' . phpbb_gallery_album::PUBLIC_ALBUM . ' AND parent_id = 0 GROUP BY album_user_id'; $result = $db->sql_query($sql); $number_of_personals = 0; while ($row = $db->sql_fetchrow($result)) { $image_user = new phpbb_gallery_user($db, $row['album_user_id'], false); $image_user->update_data(array('personal_album_id' => $row['album_id'])); $number_of_personals++; } $db->sql_freeresult($result); phpbb_gallery_config::set('num_pegas', $number_of_personals); // Update the config for the statistic on the index $sql_array = array('SELECT' => 'a.album_id, u.user_id, u.username, u.user_colour', 'FROM' => array(GALLERY_ALBUMS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = a.album_user_id')), 'WHERE' => 'a.album_user_id <> ' . phpbb_gallery_album::PUBLIC_ALBUM . ' AND a.parent_id = 0', 'ORDER_BY' => 'a.album_id DESC'); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query_limit($sql, 1); $newest_pgallery = $db->sql_fetchrow($result); $db->sql_freeresult($result); phpbb_gallery_config::set('newest_pega_user_id', $newest_pgallery['user_id']); phpbb_gallery_config::set('newest_pega_username', $newest_pgallery['username']); phpbb_gallery_config::set('newest_pega_user_colour', $newest_pgallery['user_colour']); phpbb_gallery_config::set('newest_pega_album_id', $newest_pgallery['album_id']); trigger_error($user->lang['RESYNCED_PERSONALS'] . adm_back_link($this->u_action)); break; case 'stats': if (!$auth->acl_get('a_board')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } // Hopefully this won't take to long! >> I think we must make it batchwise $sql = 'SELECT image_id, image_filename, image_thumbnail FROM ' . GALLERY_IMAGES_TABLE . ' WHERE filesize_upload = 0'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $sql_ary = array('filesize_upload' => @filesize(phpbb_gallery_url::path('upload') . $row['image_filename']), 'filesize_medium' => @filesize(phpbb_gallery_url::path('medium') . $row['image_thumbnail']), 'filesize_cache' => @filesize(phpbb_gallery_url::path('cache') . $row['image_thumbnail'])); $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE ' . $db->sql_in_set('image_id', $row['image_id']); $db->sql_query($sql); } $db->sql_freeresult($result); redirect($this->u_action); break; case 'last_images': $sql = 'SELECT album_id FROM ' . GALLERY_ALBUMS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { // 5 sql's per album, but you don't run this daily ;) phpbb_gallery_album::update_info($row['album_id']); } $db->sql_freeresult($result); trigger_error($user->lang['RESYNCED_LAST_IMAGES'] . adm_back_link($this->u_action)); break; case 'reset_rating': $album_id = request_var('reset_album_id', 0); $image_ids = array(); $sql = 'SELECT image_id FROM ' . GALLERY_IMAGES_TABLE . ' WHERE image_album_id = ' . $album_id; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $image_ids[] = $row['image_id']; } $db->sql_freeresult($result); phpbb_gallery_image_rating::delete_ratings($image_ids, true); trigger_error($user->lang['RESET_RATING_COMPLETED'] . adm_back_link($this->u_action)); break; case 'purge_cache': if ($user->data['user_type'] != USER_FOUNDER) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $cache_dir = @opendir(phpbb_gallery_url::path('cache')); while ($cache_file = @readdir($cache_dir)) { if (preg_match('/(\\.gif$|\\.png$|\\.jpg|\\.jpeg)$/is', $cache_file)) { @unlink(phpbb_gallery_url::path('cache') . $cache_file); } } @closedir($cache_dir); $medium_dir = @opendir(phpbb_gallery_url::path('medium')); while ($medium_file = @readdir($medium_dir)) { if (preg_match('/(\\.gif$|\\.png$|\\.jpg|\\.jpeg)$/is', $medium_file)) { @unlink(phpbb_gallery_url::path('medium') . $medium_file); } } @closedir($medium_dir); $sql_ary = array('filesize_medium' => 0, 'filesize_cache' => 0); $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary); $db->sql_query($sql); trigger_error($user->lang['PURGED_CACHE'] . adm_back_link($this->u_action)); break; } } phpbb_gallery_modversioncheck::check(); $boarddays = (time() - $config['board_startdate']) / 86400; $images_per_day = sprintf('%.2f', phpbb_gallery_config::get('num_images') / $boarddays); $sql = 'SELECT COUNT(album_user_id) num_albums FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_user_id = 0'; $result = $db->sql_query($sql); $num_albums = (int) $db->sql_fetchfield('num_albums'); $db->sql_freeresult($result); $sql = 'SELECT SUM(filesize_upload) as stat, SUM(filesize_medium) as stat_medium, SUM(filesize_cache) as stat_cache FROM ' . GALLERY_IMAGES_TABLE; $result = $db->sql_query($sql); $dir_sizes = $db->sql_fetchrow($result); $db->sql_freeresult($result); $template->assign_vars(array('S_GALLERY_OVERVIEW' => true, 'ACP_GALLERY_TITLE' => $user->lang['ACP_GALLERY_OVERVIEW'], 'ACP_GALLERY_TITLE_EXPLAIN' => $user->lang['ACP_GALLERY_OVERVIEW_EXPLAIN'], 'TOTAL_IMAGES' => phpbb_gallery_config::get('num_images'), 'IMAGES_PER_DAY' => $images_per_day, 'TOTAL_ALBUMS' => $num_albums, 'TOTAL_PERSONALS' => phpbb_gallery_config::get('num_pegas'), 'GUPLOAD_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat']), 'MEDIUM_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat_medium']), 'CACHE_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat_cache']), 'GALLERY_VERSION' => phpbb_gallery_config::get('version'), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false)); }
function main($id, $mode) { global $cache, $db, $user, $auth, $template; phpbb_gallery::init(); $manage_albums = new phpbb_gallery_album_manage(request_var('user_id', 0), request_var('parent_id', 0), $this->u_action); $user->add_lang(array('mods/gallery_acp', 'mods/gallery')); $this->tpl_name = 'gallery_albums'; $this->page_title = 'ACP_GALLERY_MANAGE_ALBUMS'; $form_key = 'acp_gallery_albums'; add_form_key($form_key); $action = request_var('action', ''); $update = isset($_POST['update']) ? true : false; $album_id = request_var('a', 0); $this->parent_id = request_var('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_var('action_subalbums', ''); $subalbums_to_id = request_var('subalbums_to_id', 0); $action_images = request_var('action_images', ''); $images_to_id = request_var('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', GALLERY_ALBUMS_TABLE); 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_var('album_parent_id', $this->parent_id), 'album_type' => request_var('album_type', phpbb_gallery_album::TYPE_UPLOAD), 'type_action' => request_var('type_action', ''), 'album_status' => request_var('album_status', phpbb_gallery_album::STATUS_OPEN), 'album_parents' => '', 'album_name' => utf8_normalize_nfc(request_var('album_name', '', true)), 'album_desc' => utf8_normalize_nfc(request_var('album_desc', '', true)), 'album_desc_uid' => '', 'album_desc_options' => 7, 'album_desc_bitfield' => '', 'album_image' => request_var('album_image', ''), 'album_watermark' => request_var('album_watermark', false), 'album_sort_key' => request_var('album_sort_key', ''), 'album_sort_dir' => request_var('album_sort_dir', ''), 'display_subalbum_list' => request_var('display_subalbum_list', false), 'display_on_index' => request_var('display_on_index', false), 'display_in_rrc' => request_var('display_in_rrc', false)); // Categories are not able to be locked... if ($album_data['album_type'] == phpbb_gallery_album::TYPE_CAT) { $album_data['album_status'] = phpbb_gallery_album::STATUS_OPEN; } // Contests need contest_data, freaky... :-O $contest_data = array('contest_start' => request_var('contest_start', ''), 'contest_rating' => request_var('contest_rating', ''), 'contest_end' => request_var('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_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false)); } $errors = $manage_albums->update_album_data($album_data, $contest_data); if (!sizeof($errors)) { $album_perm_from = request_var('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 ' . GALLERY_PERMISSIONS_TABLE . ' WHERE perm_album_id = ' . $album_data['album_id']; $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_MODSCACHE_TABLE . ' WHERE album_id = ' . $album_data['album_id']; $db->sql_query($sql); } $sql = 'SELECT * FROM ' . GALLERY_PERMISSIONS_TABLE . ' WHERE perm_album_id = ' . $album_perm_from; $result = $db->sql_query($sql); 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 ' . GALLERY_MODSCACHE_TABLE . ' 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(GALLERY_PERMISSIONS_TABLE, $perm_data); $db->sql_multi_insert(GALLERY_MODSCACHE_TABLE, $modscache_ary); } $cache->destroy('sql', GALLERY_ALBUMS_TABLE); $cache->destroy('sql', GALLERY_MODSCACHE_TABLE); $cache->destroy('sql', GALLERY_PERMISSIONS_TABLE); $cache->destroy('_albums'); phpbb_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_gallery_url::append_sid('admin', 'index', 'i=gallery_permissions' . $acl_url) . '">', '</a>'); // Redirect directly to permission settings screen if ($action == 'add' && !$album_perm_from) { meta_refresh(5, phpbb_gallery_url::append_sid('admin', 'index', 'i=gallery_permissions' . $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 ' . GALLERY_ALBUMS_TABLE . "\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) { add_log('admin', 'LOG_ALBUM_' . strtoupper($action), $row['album_name'], $move_album_name); $cache->destroy('sql', GALLERY_ALBUMS_TABLE); } 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 ' . GALLERY_ALBUMS_TABLE . "\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_gallery_album::update_info($album_id); add_log('admin', '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_gallery_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_gallery_album::TYPE_CONTEST) { $contest_data = $this->get_contest_info('album', $album_id); } 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_gallery_album::get_branch(phpbb_gallery_album::PUBLIC_ALBUM, $album_id, 'children') as $row) { $exclude_albums[] = $row['album_id']; } $parents_list = phpbb_gallery_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_gallery_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_gallery_album::TYPE_UPLOAD, 'album_status' => phpbb_gallery_album::STATUS_OPEN, 'album_name' => utf8_normalize_nfc(request_var('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); // 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_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('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_gallery_album::TYPE_CAT => 'CAT', phpbb_gallery_album::TYPE_UPLOAD => 'UPLOAD', phpbb_gallery_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['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_gallery_album::STATUS_OPEN . '"' . ($album_data['album_status'] == phpbb_gallery_album::STATUS_OPEN ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . phpbb_gallery_album::STATUS_LOCKED . '"' . ($album_data['album_status'] == phpbb_gallery_album::STATUS_LOCKED ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>'; $sql = 'SELECT album_id FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_type = ' . phpbb_gallery_album::TYPE_UPLOAD . ' AND album_user_id = ' . phpbb_gallery_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_gallery_album::TYPE_UPLOAD, phpbb_gallery_album::TYPE_CONTEST))) { $subalbums_id = array(); $subalbums = phpbb_gallery_album::get_branch(phpbb_gallery_album::PUBLIC_ALBUM, $album_id, 'children'); foreach ($subalbums as $row) { $subalbums_id[] = $row['album_id']; } $albums_list = phpbb_gallery_album::get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id); if ($uploadable_album_exists) { $template->assign_vars(array('S_MOVE_ALBUM_OPTIONS' => phpbb_gallery_album::get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id, phpbb_gallery_album::PUBLIC_ALBUM, phpbb_gallery_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)); } elseif ($uploadable_album_exists) { $template->assign_vars(array('S_MOVE_ALBUM_OPTIONS' => phpbb_gallery_album::get_albumbox(true, '', $album_data['parent_id'], false, $album_id, 0, phpbb_gallery_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_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_gallery_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_gallery_album::TYPE_UPLOAD ? true : false, 'S_ALBUM_ORIG_CAT' => isset($old_album_type) && $old_album_type == phpbb_gallery_album::TYPE_CAT ? true : false, 'S_ALBUM_ORIG_CONTEST' => isset($old_album_type) && $old_album_type == phpbb_gallery_album::TYPE_CONTEST ? true : false, 'S_ALBUM_UPLOAD' => $album_data['album_type'] == phpbb_gallery_album::TYPE_UPLOAD ? true : false, 'S_ALBUM_CAT' => $album_data['album_type'] == phpbb_gallery_album::TYPE_CAT ? true : false, 'S_ALBUM_CONTEST' => $album_data['album_type'] == phpbb_gallery_album::TYPE_CONTEST ? true : false, 'ALBUM_UPLOAD' => phpbb_gallery_album::TYPE_UPLOAD, 'ALBUM_CAT' => phpbb_gallery_album::TYPE_CAT, 'ALBUM_CONTEST' => phpbb_gallery_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, 'S_CONTEST_START' => $user->format_date($contest_data['contest_start'], 'Y-m-d H:i'), 'CONTEST_RATING' => $user->format_date($contest_data['contest_start'] + $contest_data['contest_rating'], 'Y-m-d H:i'), 'CONTEST_END' => $user->format_date($contest_data['contest_start'] + $contest_data['contest_end'], 'Y-m-d H:i'))); 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_gallery_album::get_info($album_id); $subalbums_id = array(); $subalbums = phpbb_gallery_album::get_branch(phpbb_gallery_album::PUBLIC_ALBUM, $album_id, 'children'); foreach ($subalbums as $row) { $subalbums_id[] = $row['album_id']; } $albums_list = phpbb_gallery_album::get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id); $sql = 'SELECT album_id FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_type = ' . phpbb_gallery_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_gallery_album::PUBLIC_ALBUM; $result = $db->sql_query_limit($sql, 1); if ($db->sql_fetchrow($result)) { $template->assign_vars(array('S_MOVE_ALBUM_OPTIONS' => phpbb_gallery_album::get_albumbox(true, '', $album_data['parent_id'], false, $subalbums_id, phpbb_gallery_album::PUBLIC_ALBUM, phpbb_gallery_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_gallery_album::TYPE_UPLOAD, phpbb_gallery_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_gallery_album::get_branch(phpbb_gallery_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_gallery_album::get_albumbox(true, '', $this->parent_id, false, false); if ($action == 'sync' || $action == 'sync_album') { $template->assign_var('S_RESYNCED', true); } $sql = 'SELECT * FROM ' . GALLERY_ALBUMS_TABLE . "\n\t\t\tWHERE parent_id = {$this->parent_id}\n\t\t\t\tAND album_user_id = " . phpbb_gallery_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_gallery_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_gallery_url::path('phpbb') . $row['album_image'] . '" alt="" />' : '', 'ALBUM_IMAGE_SRC' => $row['album_image'] ? phpbb_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_gallery_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 = get_album_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'))); }
function move_album() { global $cache, $db, $user; $album_id = request_var('album_id', 0); phpbb_gallery_album::check_user($album_id); $move = request_var('move', '', true); $moving = phpbb_gallery_album::get_info($album_id); $sql = 'SELECT album_id, left_id, right_id FROM ' . GALLERY_ALBUMS_TABLE . "\n\t\t\tWHERE parent_id = {$moving['parent_id']}\n\t\t\t\tAND album_user_id = {$user->data['user_id']}\n\t\t\t\tAND " . ($move == 'move_up' ? "right_id < {$moving['right_id']} ORDER BY right_id DESC" : "left_id > {$moving['left_id']} ORDER BY left_id ASC"); $result = $db->sql_query_limit($sql, 1); $target = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!sizeof($target)) { // The album is already on top or bottom return false; } if ($move == 'move_up') { $left_id = $target['left_id']; $right_id = $moving['right_id']; $diff_up = $moving['left_id'] - $target['left_id']; $diff_down = $moving['right_id'] + 1 - $moving['left_id']; $move_up_left = $moving['left_id']; $move_up_right = $moving['right_id']; } else { $left_id = $moving['left_id']; $right_id = $target['right_id']; $diff_up = $moving['right_id'] + 1 - $moving['left_id']; $diff_down = $target['right_id'] - $moving['right_id']; $move_up_left = $moving['right_id'] + 1; $move_up_right = $target['right_id']; } // Now do the dirty job $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\tSET left_id = left_id + CASE\n\t\t\t\tWHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}\n\t\t\t\tELSE {$diff_down}\n\t\t\tEND,\n\t\t\tright_id = right_id + CASE\n\t\t\t\tWHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}\n\t\t\t\tELSE {$diff_down}\n\t\t\tEND,\n\t\t\talbum_parents = ''\n\t\t\tWHERE\n\t\t\t\tleft_id BETWEEN {$left_id} AND {$right_id}\n\t\t\t\tAND right_id BETWEEN {$left_id} AND {$right_id}\n\t\t\t\tAND album_user_id = {$user->data['user_id']}"; $db->sql_query($sql); $cache->destroy('sql', GALLERY_ALBUMS_TABLE); $cache->destroy('_albums'); phpbb_gallery_url::redirect('phpbb', 'ucp', 'i=gallery&mode=manage_albums&action=manage&parent_id=' . $moving['parent_id']); }
/** * Remove complete album * * borrowed from phpBB3 * @author: phpBB Group * @function: delete_forum */ public function delete_album($album_id, $action_images = 'delete', $action_subalbums = 'delete', $images_to_id = 0, $subalbums_to_id = 0) { global $db, $user, $cache; $album_data = phpbb_gallery_album::get_info($album_id); $errors = array(); $log_action_images = $log_action_albums = $images_to_name = $subalbums_to_name = ''; $album_ids = array($album_id); if ($action_images == 'delete') { $log_action_images = 'IMAGES'; $errors = array_merge($errors, $this->delete_album_content($album_id)); } else { if ($action_images == 'move') { if (!$images_to_id) { $errors[] = $user->lang['NO_DESTINATION_ALBUM']; } else { $log_action_images = 'MOVE_IMAGES'; $sql = 'SELECT album_name FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_id = ' . $images_to_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { $errors[] = $user->lang['NO_ALBUM']; } else { $images_to_name = $row['album_name']; $errors = array_merge($errors, $this->move_album_content($album_id, $images_to_id)); } } } } if (sizeof($errors)) { return $errors; } if ($action_subalbums == 'delete') { $log_action_albums = 'ALBUMS'; $rows = phpbb_gallery_album::get_branch($this->user_id, $album_id, 'children', 'descending', false); foreach ($rows as $row) { $album_ids[] = $row['album_id']; $errors = array_merge($errors, $this->delete_album_content($row['album_id'])); } if (sizeof($errors)) { return $errors; } $diff = sizeof($album_ids) * 2; $sql = 'DELETE FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE ' . $db->sql_in_set('album_id', $album_ids); $db->sql_query($sql); } else { if ($action_subalbums == 'move') { if (!$subalbums_to_id) { $errors[] = $user->lang['NO_DESTINATION_ALBUM']; } else { $log_action_albums = 'MOVE_ALBUMS'; $sql = 'SELECT album_name FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_id = ' . $subalbums_to_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { $errors[] = $user->lang['NO_ALBUM']; } else { $subalbums_to_name = $row['album_name']; $sql = 'SELECT album_id FROM ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\t\t\tWHERE parent_id = {$album_id}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $this->move_album($row['album_id'], $subalbums_to_id); } $db->sql_freeresult($result); // Grab new album data for correct tree updating later $album_data = phpbb_gallery_album::get_info($album_id); $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\t\t\tSET parent_id = {$subalbums_to_id}\n\t\t\t\t\t\tWHERE parent_id = {$album_id}\n\t\t\t\t\t\t\tAND album_user_id = " . $this->user_id; $db->sql_query($sql); $diff = 2; $sql = 'DELETE FROM ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\t\t\tWHERE album_id = {$album_id}"; $db->sql_query($sql); } } if (sizeof($errors)) { return $errors; } } else { $diff = 2; $sql = 'DELETE FROM ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\tWHERE album_id = {$album_id}"; $db->sql_query($sql); } } // Resync tree $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\tSET right_id = right_id - {$diff}\n\t\t\tWHERE left_id < {$album_data['right_id']} AND right_id > {$album_data['right_id']}\n\t\t\t\tAND album_user_id = " . $this->user_id; $db->sql_query($sql); $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\t\tWHERE left_id > {$album_data['right_id']}\n\t\t\t\tAND album_user_id = " . $this->user_id; $db->sql_query($sql); $log_action = implode('_', array($log_action_images, $log_action_albums)); /** * Log what we did */ switch ($log_action) { case 'MOVE_IMAGES_MOVE_ALBUMS': add_log('admin', 'LOG_ALBUM_DEL_MOVE_IMAGES_MOVE_ALBUMS', $images_to_name, $subalbums_to_name, $album_data['album_name']); break; case 'MOVE_IMAGES_ALBUMS': add_log('admin', 'LOG_ALBUM_DEL_MOVE_IMAGES_ALBUMS', $images_to_name, $album_data['album_name']); break; case 'IMAGES_MOVE_ALBUMS': add_log('admin', 'LOG_ALBUM_DEL_IMAGES_MOVE_ALBUMS', $subalbums_to_name, $album_data['album_name']); break; case '_MOVE_ALBUMS': add_log('admin', 'LOG_ALBUM_DEL_MOVE_ALBUMS', $subalbums_to_name, $album_data['album_name']); break; case 'MOVE_IMAGES_': add_log('admin', 'LOG_ALBUM_DEL_MOVE_IMAGES', $images_to_name, $album_data['album_name']); break; case 'IMAGES_ALBUMS': add_log('admin', 'LOG_ALBUM_DEL_IMAGES_ALBUMS', $album_data['album_name']); break; case '_ALBUMS': add_log('admin', 'LOG_ALBUM_DEL_ALBUMS', $album_data['album_name']); break; case 'IMAGES_': add_log('admin', 'LOG_ALBUM_DEL_IMAGES', $album_data['album_name']); break; default: add_log('admin', 'LOG_ALBUM_DEL_ALBUM', $album_data['album_name']); break; } phpbb_gallery_auth::set_user_permissions('all', ''); return $errors; }
page_footer(); } phpbb_gallery_album::generate_nav($album_data); $template->assign_block_vars('navlinks', array('FORUM_NAME' => $user->lang['MCP'], 'U_VIEW_FORUM' => phpbb_gallery_url::append_sid('mcp', 'album_id=' . $album_data['album_id']))); $template->assign_vars(array('S_ALLOWED_MOVE' => phpbb_gallery::$auth->acl_check('m_move', $album_id, $album_data['album_user_id']) ? true : false, 'S_ALLOWED_STATUS' => phpbb_gallery::$auth->acl_check('m_status', $album_id, $album_data['album_user_id']) ? true : false, 'S_ALLOWED_DELETE' => phpbb_gallery::$auth->acl_check('m_delete', $album_id, $album_data['album_user_id']) ? true : false, 'S_ALLOWED_REPORT' => phpbb_gallery::$auth->acl_check('m_report', $album_id, $album_data['album_user_id']) ? true : false, 'EDIT_IMG' => $user->img('icon_post_edit', 'EDIT_IMAGE'), 'DELETE_IMG' => $user->img('icon_post_delete', 'DELETE_IMAGE'), 'ALBUM_NAME' => $album_data['album_name'], 'ALBUM_IMAGES' => $album_data['album_images'] . ' ' . ($album_data['album_images'] == 1 ? $user->lang['IMAGE'] : $user->lang['IMAGES']), 'U_VIEW_ALBUM' => phpbb_gallery_url::append_sid('album', 'album_id=' . $album_id), 'U_MOD_ALBUM' => phpbb_gallery_url::append_sid('mcp', 'mode=album&album_id=' . $album_id))); if ($action && $image_id_ary) { $s_hidden_fields = build_hidden_fields(array('mode' => $mode, 'album_id' => $album_id, 'image_id_ary' => $image_id_ary, 'action' => $action, 'redirect' => $redirect)); $multiple = ''; if (isset($image_id_ary[1])) { // We add an S to the lang string (IMAGE), when we have more than one image, so we get IMAGES $multiple = 'S'; } switch ($action) { case 'images_move': if ($moving_target) { $target_data = phpbb_gallery_album::get_info($moving_target); if ($target_data['contest_id'] && time() < $target_data['contest_start'] + $target_data['contest_end']) { $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' SET image_album_id = ' . $moving_target . ', image_contest = ' . phpbb_gallery_image::IN_CONTEST . ' WHERE ' . $db->sql_in_set('image_id', $image_id_ary); $db->sql_query($sql); } else { $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' SET image_album_id = ' . $moving_target . ', image_contest = ' . phpbb_gallery_image::NO_CONTEST . ' WHERE ' . $db->sql_in_set('image_id', $image_id_ary); $db->sql_query($sql); } $sql = 'UPDATE ' . GALLERY_REPORTS_TABLE . ' SET report_album_id = ' . $moving_target . '