/** * Sets up some basic stuff for the gallery. */ public static function init() { global $db, $user; phpbb_gallery_url::_include('functions_phpbb', 'phpbb', 'includes/gallery/'); phpbb_gallery_plugins::init(phpbb_gallery_url::path()); // Little precaution. $user->data['user_id'] = (int) $user->data['user_id']; self::$user = new phpbb_gallery_user($db, $user->data['user_id']); $user_id = $user->data['user_perm_from'] == 0 ? $user->data['user_id'] : $user->data['user_perm_from']; self::$auth = new phpbb_gallery_auth($user_id); if (phpbb_gallery_config::get('mvc_time') < time()) { // Check the version, do we need to update? phpbb_gallery_config::set('mvc_time', time() + 86400); phpbb_gallery_config::set('mvc_version', phpbb_gallery_modversioncheck::check(true)); } self::$loaded = true; }
/** * Generate personal album for user, when moving image into it */ public static function generate_personal_album($album_name, $user_id, $user_colour, $gallery_user) { global $cache, $db; $album_data = array('album_name' => $album_name, 'parent_id' => 0, 'album_desc_options' => 7, 'album_desc' => '', 'album_parents' => '', 'album_type' => self::TYPE_UPLOAD, 'album_status' => self::STATUS_UNLOCKED, 'album_user_id' => $user_id, 'album_last_username' => '', 'album_last_user_colour' => $user_colour); $db->sql_query('INSERT INTO ' . GALLERY_ALBUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $album_data)); $personal_album_id = $db->sql_nextid(); $gallery_user->update_data(array('personal_album_id' => $personal_album_id)); phpbb_gallery_config::inc('num_pegas', 1); // Update the config for the statistic on the index phpbb_gallery_config::set('newest_pega_user_id', $user_id); phpbb_gallery_config::set('newest_pega_username', $album_name); phpbb_gallery_config::set('newest_pega_user_colour', $user_colour); phpbb_gallery_config::set('newest_pega_album_id', $personal_album_id); $cache->destroy('_albums'); $cache->destroy('sql', GALLERY_ALBUMS_TABLE); return $personal_album_id; }
/** * Edit the data in the tables */ function update_db_data($mode, $sub) { global $cache, $db, $template, $user; global $phpbb_root_path, $phpEx, $table_prefix; include $phpbb_root_path . 'includes/acp/auth.' . $phpEx; $database_step = request_var('step', 0); $this->page_title = $user->lang['STAGE_UPDATE_DB']; $next_update_url = ''; switch (phpbb_gallery_config::get('version')) { case '0.1.2': case '0.1.3': case '0.2.0': case '0.2.1': case '0.2.2': case '0.2.3': case '0.3.0': case '0.3.1': case '0.3.2-RC1': case '0.3.2-RC2': case '0.4.0-RC1': case '0.4.0-RC2': case '0.4.0-RC3': case '0.4.0': case '0.4.1': case '0.5.0': case '0.5.1-dev': case '0.5.1': case '0.5.2-dev': case '0.5.2': case '0.5.3-dev': case '0.5.3': case '0.5.4': case '1.0.0-dev': case '1.0.0-RC1': case '1.0.0-RC2': case '1.0.0': case '1.0.1-dev': case '1.0.1': case '1.0.2-dev': case '1.0.2-RC1': case '1.0.2': case '1.0.3-RC1': case '1.0.3-RC2': case '1.0.3': case '1.0.4': case '1.0.5-RC1': /** * Cheating? */ trigger_error('VERSION_NOT_SUPPORTED', E_USER_ERROR); break; case '1.0.5': $sql = 'SELECT * FROM ' . GALLERY_CONFIG_TABLE; $result = $db->sql_query($sql); $old_config = array(); while ($row = $db->sql_fetchrow($result)) { $old_config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); $others = array('gallery_total_images', 'gallery_viewtopic_icon', 'gallery_viewtopic_images', 'gallery_viewtopic_link'); foreach ($others as $config_name) { if (isset($config[$config_name])) { $old_config[$config_name] = $config[$config_name]; } } $db->sql_freeresult($result); $config_map = config_mapping(); foreach ($config_map as $old_name => $new_name) { if (isset($old_config[$old_name])) { phpbb_gallery_config::set($new_name, $old_config[$old_name]); } } // Add new configs: $default_config = phpbb_gallery_config::get_default(); foreach ($default_config as $name => $value) { if (!phpbb_gallery_config::exists($name)) { phpbb_gallery_config::set($name, $value); } } $next_update_url = append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode={$mode}&sub=update_db&step=4"); break; } $next_update_url = !$next_update_url ? append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode={$mode}&sub=update_db&step=4") : $next_update_url; $template->assign_vars(array('BODY' => $user->lang['UPDATING_DATA'], 'L_SUBMIT' => $user->lang['NEXT_STEP'], 'S_HIDDEN' => '', 'U_ACTION' => $next_update_url)); }
function cleanup() { global $auth, $cache, $db, $template, $user; $delete = isset($_POST['delete']) ? true : false; $submit = isset($_POST['submit']) ? true : false; $missing_sources = request_var('source', array(0)); $missing_entries = request_var('entry', array(''), true); $missing_authors = request_var('author', array(0), true); $missing_comments = request_var('comment', array(0), true); $missing_personals = request_var('personal', array(0), true); $personals_bad = request_var('personal_bad', array(0), true); $s_hidden_fields = build_hidden_fields(array('source' => $missing_sources, 'entry' => $missing_entries, 'author' => $missing_authors, 'comment' => $missing_comments, 'personal' => $missing_personals, 'personal_bad' => $personals_bad)); if ($submit) { if ($missing_authors) { $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' SET image_user_id = ' . ANONYMOUS . ",\n\t\t\t\t\t\timage_user_colour = ''\n\t\t\t\t\tWHERE " . $db->sql_in_set('image_id', $missing_authors); $db->sql_query($sql); } if ($missing_comments) { $sql = 'UPDATE ' . GALLERY_COMMENTS_TABLE . ' SET comment_user_id = ' . ANONYMOUS . ",\n\t\t\t\t\t\tcomment_user_colour = ''\n\t\t\t\t\tWHERE " . $db->sql_in_set('comment_id', $missing_comments); $db->sql_query($sql); } trigger_error($user->lang['CLEAN_CHANGED'] . adm_back_link($this->u_action)); } if (confirm_box(true)) { $message = array(); if ($missing_sources) { $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . ' WHERE ' . $db->sql_in_set('comment_image_id', $missing_sources); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('report_image_id', $missing_sources); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $missing_sources); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $missing_sources); $db->sql_query($sql); phpbb_gallery_image_base::delete_images($missing_sources); $message[] = $user->lang['CLEAN_SOURCES_DONE']; } if ($missing_entries) { foreach ($missing_entries as $missing_image) { @unlink(phpbb_gallery_url::path('upload') . utf8_decode($missing_image)); } $message[] = $user->lang['CLEAN_ENTRIES_DONE']; } if ($missing_authors) { $deleted_images = $filenames = array(); $sql = 'SELECT image_id, image_filename FROM ' . GALLERY_IMAGES_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $missing_authors); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $filenames[(int) $row['image_id']] = $row['image_filename']; $deleted_images[] = $row['image_id']; } $db->sql_freeresult($result); // we have all image_ids in $deleted_images which are deleted // aswell as the album_ids in $deleted_albums // so now drop the comments, ratings, images and albums if ($deleted_images) { $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . ' WHERE ' . $db->sql_in_set('comment_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('report_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); phpbb_gallery_image_base::delete_images($deleted_images, $filenames); } $message[] = $user->lang['CLEAN_AUTHORS_DONE']; } if ($missing_comments) { $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . ' WHERE ' . $db->sql_in_set('comment_id', $missing_comments); $db->sql_query($sql); $message[] = $user->lang['CLEAN_COMMENTS_DONE']; } if ($missing_personals || $personals_bad) { $delete_albums = array_merge($missing_personals, $personals_bad); $deleted_images = $deleted_albums = array(0); $user_image_count = array(); $sql = 'SELECT COUNT(album_user_id) personal_counter FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE parent_id = 0 AND ' . $db->sql_in_set('album_user_id', $delete_albums); $result = $db->sql_query($sql); $remove_personal_counter = $db->sql_fetchfield('personal_counter'); $db->sql_freeresult($result); $sql = 'SELECT album_id FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE ' . $db->sql_in_set('album_user_id', $delete_albums); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $deleted_albums[] = $row['album_id']; } $db->sql_freeresult($result); $sql = 'SELECT image_id, image_filename, image_user_id FROM ' . GALLERY_IMAGES_TABLE . ' WHERE ' . $db->sql_in_set('image_album_id', $deleted_albums); $result = $db->sql_query($sql); $filenames = array(); while ($row = $db->sql_fetchrow($result)) { $deleted_images[] = $row['image_id']; $filenames[(int) $row['image_id']] = $row['image_filename']; if (isset($user_image_count[$row['image_user_id']])) { $user_image_count[$row['image_user_id']]++; } else { $user_image_count[(int) $row['image_user_id']] = 1; } } $db->sql_freeresult($result); if ($deleted_images) { $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . ' WHERE ' . $db->sql_in_set('comment_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('report_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); phpbb_gallery_image_base::delete_images($deleted_images, $filenames); } $sql = 'DELETE FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE ' . $db->sql_in_set('album_id', $deleted_albums); $db->sql_query($sql); phpbb_gallery_config::get('num_pegas', $remove_personal_counter); if (in_array(phpbb_gallery_config::get('newest_pega_album_id'), $deleted_albums)) { // Update the config for the statistic on the index if (phpbb_gallery_config::get('num_pegas') > 0) { $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']); } else { phpbb_gallery_config::set('newest_pega_user_id', 0); phpbb_gallery_config::set('newest_pega_username', ''); phpbb_gallery_config::set('newest_pega_user_colour', ''); phpbb_gallery_config::set('newest_pega_album_id', 0); } } $user_ids = array(); foreach ($user_image_count as $user_id => $images) { $user_ids[] = (int) $user_id; phpbb_gallery_hookup::add_image($user_id, 0 - $images); $uploader = new phpbb_gallery_user($db, $user_id, false); $uploader->update_images(0 - $images); } phpbb_gallery_user_helpers::update_users($user_ids, array('personal_album_id' => 0)); if ($missing_personals) { $message[] = $user->lang['CLEAN_PERSONALS_DONE']; } if ($personals_bad) { $message[] = $user->lang['CLEAN_PERSONALS_BAD_DONE']; } } // Make sure the overall image & comment count is correct... $sql = 'SELECT COUNT(image_id) AS num_images, SUM(image_comments) AS num_comments FROM ' . GALLERY_IMAGES_TABLE . ' WHERE image_status <> ' . phpbb_gallery_image::STATUS_UNAPPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); phpbb_gallery_config::set('num_images', $row['num_images']); phpbb_gallery_config::set('num_comments', $row['num_comments']); $cache->destroy('sql', GALLERY_ALBUMS_TABLE); $cache->destroy('sql', GALLERY_COMMENTS_TABLE); $cache->destroy('sql', GALLERY_FAVORITES_TABLE); $cache->destroy('sql', GALLERY_IMAGES_TABLE); $cache->destroy('sql', GALLERY_RATES_TABLE); $cache->destroy('sql', GALLERY_REPORTS_TABLE); $cache->destroy('sql', GALLERY_WATCH_TABLE); $cache->destroy('_albums'); phpbb_gallery_auth::set_user_permissions('all', ''); trigger_error(implode('<br />', $message) . adm_back_link($this->u_action)); } else { if ($delete || isset($_POST['cancel'])) { if (isset($_POST['cancel'])) { trigger_error($user->lang['CLEAN_GALLERY_ABORT'] . adm_back_link($this->u_action), E_USER_WARNING); } else { $user->lang['CLEAN_GALLERY_CONFIRM'] = $user->lang['CONFIRM_CLEAN']; if ($missing_sources) { $user->lang['CLEAN_GALLERY_CONFIRM'] = $user->lang['CONFIRM_CLEAN_SOURCES'] . '<br />' . $user->lang['CLEAN_GALLERY_CONFIRM']; } if ($missing_entries) { $user->lang['CLEAN_GALLERY_CONFIRM'] = $user->lang['CONFIRM_CLEAN_ENTRIES'] . '<br />' . $user->lang['CLEAN_GALLERY_CONFIRM']; } if ($missing_authors) { $user->lang['CLEAN_GALLERY_CONFIRM'] = $user->lang['CONFIRM_CLEAN_AUTHORS'] . '<br />' . $user->lang['CLEAN_GALLERY_CONFIRM']; } if ($missing_comments) { $user->lang['CLEAN_GALLERY_CONFIRM'] = $user->lang['CONFIRM_CLEAN_COMMENTS'] . '<br />' . $user->lang['CLEAN_GALLERY_CONFIRM']; } if ($personals_bad || $missing_personals) { $sql = 'SELECT album_name, album_user_id FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE ' . $db->sql_in_set('album_user_id', array_merge($missing_personals, $personals_bad)); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (in_array($row['album_user_id'], $personals_bad)) { $personals_bad_names[] = $row['album_name']; } else { $missing_personals_names[] = $row['album_name']; } } $db->sql_freeresult($result); } if ($missing_personals) { $user->lang['CLEAN_GALLERY_CONFIRM'] = sprintf($user->lang['CONFIRM_CLEAN_PERSONALS'], implode(', ', $missing_personals_names)) . '<br />' . $user->lang['CLEAN_GALLERY_CONFIRM']; } if ($personals_bad) { $user->lang['CLEAN_GALLERY_CONFIRM'] = sprintf($user->lang['CONFIRM_CLEAN_PERSONALS_BAD'], implode(', ', $personals_bad_names)) . '<br />' . $user->lang['CLEAN_GALLERY_CONFIRM']; } confirm_box(false, 'CLEAN_GALLERY', $s_hidden_fields); } } } $requested_source = array(); $sql_array = array('SELECT' => 'i.image_id, i.image_name, i.image_filemissing, i.image_filename, i.image_username, u.user_id', 'FROM' => array(GALLERY_IMAGES_TABLE => 'i'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = i.image_user_id'))); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if ($row['image_filemissing']) { $template->assign_block_vars('sourcerow', array('IMAGE_ID' => $row['image_id'], 'IMAGE_NAME' => $row['image_name'])); } if (!$row['user_id']) { $template->assign_block_vars('authorrow', array('IMAGE_ID' => $row['image_id'], 'AUTHOR_NAME' => $row['image_username'])); } $requested_source[] = $row['image_filename']; } $db->sql_freeresult($result); $check_mode = request_var('check_mode', ''); if ($check_mode == 'source') { $source_missing = array(); // Reset the status: a image might have been viewed without file but the file is back $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' SET image_filemissing = 0'; $db->sql_query($sql); $sql = 'SELECT image_id, image_filename, image_filemissing FROM ' . GALLERY_IMAGES_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (!file_exists(phpbb_gallery_url::path('upload') . $row['image_filename'])) { $source_missing[] = $row['image_id']; } } $db->sql_freeresult($result); if ($source_missing) { $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . "\n\t\t\t\t\tSET image_filemissing = 1\n\t\t\t\t\tWHERE " . $db->sql_in_set('image_id', $source_missing); $db->sql_query($sql); } } if ($check_mode == 'entry') { $directory = phpbb_gallery_url::path('upload'); $handle = opendir($directory); while ($file = readdir($handle)) { if (!is_dir($directory . $file) && (substr(strtolower($file), '-4') == '.png' || substr(strtolower($file), '-4') == '.gif' || substr(strtolower($file), '-4') == '.jpg') && !in_array($file, $requested_source)) { if (strpos($file, 'image_not_exist') !== false || strpos($file, 'not_authorised') !== false || strpos($file, 'no_hotlinking') !== false) { continue; } $template->assign_block_vars('entryrow', array('FILE_NAME' => utf8_encode($file))); } } closedir($handle); } $sql_array = array('SELECT' => 'c.comment_id, c.comment_image_id, c.comment_username, u.user_id', 'FROM' => array(GALLERY_COMMENTS_TABLE => 'c'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = c.comment_user_id'))); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (!$row['user_id']) { $template->assign_block_vars('commentrow', array('COMMENT_ID' => $row['comment_id'], 'IMAGE_ID' => $row['comment_image_id'], 'AUTHOR_NAME' => $row['comment_username'])); } } $db->sql_freeresult($result); $sql_array = array('SELECT' => 'a.album_id, a.album_user_id, a.album_name, u.user_id, a.album_images_real', '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'); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $personalrow = $personal_bad_row = array(); while ($row = $db->sql_fetchrow($result)) { $album = array('user_id' => $row['album_user_id'], 'album_id' => $row['album_id'], 'album_name' => $row['album_name'], 'images' => $row['album_images_real']); if (!$row['user_id']) { $personalrow[$row['album_user_id']] = $album; } $personal_bad_row[$row['album_user_id']] = $album; } $db->sql_freeresult($result); $sql = 'SELECT ga.album_user_id, ga.album_images_real FROM ' . GALLERY_ALBUMS_TABLE . ' ga WHERE ga.album_user_id <> ' . phpbb_gallery_album::PUBLIC_ALBUM . ' AND ga.parent_id <> 0'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (isset($personalrow[$row['album_user_id']])) { $personalrow[$row['album_user_id']]['images'] = $personalrow[$row['album_user_id']]['images'] + $row['album_images_real']; } $personal_bad_row[$row['album_user_id']]['images'] = $personal_bad_row[$row['album_user_id']]['images'] + $row['album_images_real']; } $db->sql_freeresult($result); foreach ($personalrow as $key => $row) { $template->assign_block_vars('personalrow', array('USER_ID' => $row['user_id'], 'ALBUM_ID' => $row['album_id'], 'AUTHOR_NAME' => $row['album_name'])); } foreach ($personal_bad_row as $key => $row) { $template->assign_block_vars('personal_bad_row', array('USER_ID' => $row['user_id'], 'ALBUM_ID' => $row['album_id'], 'AUTHOR_NAME' => $row['album_name'], 'IMAGES' => $row['images'])); } $template->assign_vars(array('S_GALLERY_MANAGE_RESTS' => true, 'ACP_GALLERY_TITLE' => $user->lang['ACP_GALLERY_CLEANUP'], 'ACP_GALLERY_TITLE_EXPLAIN' => $user->lang['ACP_GALLERY_CLEANUP_EXPLAIN'], 'CHECK_SOURCE' => $this->u_action . '&check_mode=source', 'CHECK_ENTRY' => $this->u_action . '&check_mode=entry', 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false)); }
function delete_album() { global $cache, $db, $template, $user; $s_hidden_fields = build_hidden_fields(array('album_id' => request_var('album_id', 0))); if (confirm_box(true)) { $album_id = request_var('album_id', 0); $left_id = $right_id = 0; $deleted_images_na = ''; $deleted_albums = array(); // Check for owner $sql = 'SELECT album_id, left_id, right_id, parent_id FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_user_id = ' . $user->data['user_id'] . ' ORDER BY left_id ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $album[] = $row; if ($row['album_id'] == $album_id) { $left_id = $row['left_id']; $right_id = $row['right_id']; $parent_id = $row['parent_id']; } } $db->sql_freeresult($result); for ($i = 0, $end = count($album); $i < $end; $i++) { if ($left_id <= $album[$i]['left_id'] && $album[$i]['left_id'] <= $right_id) { $deleted_albums[] = $album[$i]['album_id']; } } // $deleted_albums is the array of albums we are going to delete. // Now get the images in $deleted_images $sql = 'SELECT image_id, image_filename FROM ' . GALLERY_IMAGES_TABLE . ' WHERE ' . $db->sql_in_set('image_album_id', $deleted_albums) . ' ORDER BY image_id ASC'; $result = $db->sql_query($sql); $deleted_images = $filenames = array(); while ($row = $db->sql_fetchrow($result)) { $deleted_images[] = $row['image_id']; $filenames[(int) $row['image_id']] = $row['image_filename']; } // We have all image_ids in $deleted_images which are deleted. // Aswell as the album_ids in $deleted_albums. // So now drop the comments, ratings, images and albums. if (!empty($deleted_images)) { $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . ' WHERE ' . $db->sql_in_set('comment_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('report_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); phpbb_gallery_image_base::delete_images($deleted_images, $filenames); } $sql = 'DELETE FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE ' . $db->sql_in_set('album_id', $deleted_albums); $db->sql_query($sql); // Make sure the overall image & comment count is correct... $sql = 'SELECT COUNT(image_id) AS num_images, SUM(image_comments) AS num_comments FROM ' . GALLERY_IMAGES_TABLE . ' WHERE image_status <> ' . phpbb_gallery_image::STATUS_UNAPPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); phpbb_gallery_config::set('num_images', $row['num_images']); phpbb_gallery_config::set('num_comments', $row['num_comments']); $num_images = sizeof($deleted_images); if ($num_images) { phpbb_gallery_hookup::add_image($user->data['user_id'], 0 - $num_images); phpbb_gallery::$user->update_images(0 - $num_images); } // Maybe we deleted all, so we have to empty phpbb_gallery::$user->get_data('personal_album_id') if (in_array(phpbb_gallery::$user->get_data('personal_album_id'), $deleted_albums)) { phpbb_gallery::$user->update_data(array('personal_album_id' => 0)); phpbb_gallery_config::dec('num_pegas', 1); if (phpbb_gallery_config::get('newest_pega_album_id') == phpbb_gallery::$user->get_data('personal_album_id')) { // Update the config for the statistic on the index if (phpbb_gallery_config::get('num_pegas') > 0) { $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']); } else { phpbb_gallery_config::set('newest_pega_user_id', 0); phpbb_gallery_config::set('newest_pega_username', ''); phpbb_gallery_config::set('newest_pega_user_colour', ''); phpbb_gallery_config::set('newest_pega_album_id', 0); } } } else { // Solve the left_id right_id problem $delete_id = $right_id - ($left_id - 1); $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\t\tSET left_id = left_id - {$delete_id}\n\t\t\t\t\tWHERE left_id > {$left_id}\n\t\t\t\t\t\tAND album_user_id = " . $user->data['user_id']; $db->sql_query($sql); $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\t\tSET right_id = right_id - {$delete_id}\n\t\t\t\t\tWHERE right_id > {$right_id}\n\t\t\t\t\t\tAND album_user_id = " . $user->data['user_id']; $db->sql_query($sql); } $cache->destroy('sql', GALLERY_ALBUMS_TABLE); $cache->destroy('sql', GALLERY_COMMENTS_TABLE); $cache->destroy('sql', GALLERY_FAVORITES_TABLE); $cache->destroy('sql', GALLERY_IMAGES_TABLE); $cache->destroy('sql', GALLERY_RATES_TABLE); $cache->destroy('sql', GALLERY_REPORTS_TABLE); $cache->destroy('sql', GALLERY_WATCH_TABLE); $cache->destroy('_albums'); phpbb_gallery_auth::set_user_permissions('all', ''); trigger_error($user->lang['DELETED_ALBUMS'] . '<br /><br /> <a href="' . ($parent_id ? phpbb_gallery_url::append_sid('phpbb', 'ucp', 'i=gallery&mode=manage_albums&action=manage&parent_id=' . $parent_id) : append_sid('phpbb', 'ucp', 'i=gallery&mode=manage_albums')) . '">' . $user->lang['BACK_TO_PREV'] . '</a>'); } else { $album_id = request_var('album_id', 0); phpbb_gallery_album::check_user($album_id); confirm_box(false, 'DELETE_ALBUM', $s_hidden_fields); } }
/** * Delete album content: * Deletes all images, comments, rates, image-files, etc. */ public function delete_album_content($album_id) { global $cache, $db; $album_id = (int) $album_id; // Before we remove anything we make sure we are able to adjust the image counts later. ;) $sql = 'SELECT image_user_id FROM ' . GALLERY_IMAGES_TABLE . ' WHERE image_album_id = ' . $album_id . ' AND image_status <> ' . phpbb_gallery_image::STATUS_UNAPPROVED; $result = $db->sql_query($sql); $image_counts = array(); while ($row = $db->sql_fetchrow($result)) { $image_counts[$row['image_user_id']] = !empty($image_counts[$row['image_user_id']]) ? $image_counts[$row['image_user_id']] + 1 : 1; } $db->sql_freeresult($result); $sql = 'SELECT image_id, image_filename, image_album_id FROM ' . GALLERY_IMAGES_TABLE . ' WHERE image_album_id = ' . $album_id; $result = $db->sql_query($sql); $filenames = $deleted_images = array(); while ($row = $db->sql_fetchrow($result)) { $deleted_images[] = $row['image_id']; $filenames[(int) $row['image_id']] = $row['image_filename']; } $db->sql_freeresult($result); if (!empty($deleted_images)) { $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . ' WHERE ' . $db->sql_in_set('comment_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('report_image_id', $deleted_images); $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('image_id', $deleted_images); $db->sql_query($sql); phpbb_gallery_image_base::delete_images($deleted_images, $filenames); } $sql = 'DELETE FROM ' . LOG_TABLE . "\n\t\t\tWHERE album_id = {$album_id}\n\t\t\t\tAND log_type = " . LOG_GALLERY; $db->sql_query($sql); //@todo: merge queries into loop $sql = 'DELETE FROM ' . GALLERY_PERMISSIONS_TABLE . ' WHERE perm_album_id = ' . $album_id; $db->sql_query($sql); $sql = 'DELETE FROM ' . GALLERY_CONTESTS_TABLE . ' WHERE contest_album_id = ' . $album_id; $db->sql_query($sql); $table_ary = array(GALLERY_WATCH_TABLE, GALLERY_MODSCACHE_TABLE); foreach ($table_ary as $table) { $db->sql_query("DELETE FROM {$table} WHERE album_id = {$album_id}"); } // Adjust users image counts if (!empty($image_counts)) { foreach ($image_counts as $image_user_id => $substract) { $sql = 'UPDATE ' . GALLERY_USERS_TABLE . ' SET user_images = 0 WHERE user_id = ' . $image_user_id . ' AND user_images < ' . $substract; $db->sql_query($sql); $sql = 'UPDATE ' . GALLERY_USERS_TABLE . ' SET user_images = user_images - ' . $substract . ' WHERE user_id = ' . $image_user_id . ' AND user_images >= ' . $substract; $db->sql_query($sql); } } // Make sure the overall image & comment count is correct... $sql = 'SELECT COUNT(image_id) AS num_images, SUM(image_comments) AS num_comments FROM ' . GALLERY_IMAGES_TABLE . ' WHERE image_status <> ' . phpbb_gallery_image::STATUS_UNAPPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); phpbb_gallery_config::set('num_images', $row['num_images']); phpbb_gallery_config::set('num_comments', $row['num_comments']); $cache->destroy('sql', GALLERY_ALBUMS_TABLE); $cache->destroy('sql', GALLERY_COMMENTS_TABLE); $cache->destroy('sql', GALLERY_FAVORITES_TABLE); $cache->destroy('sql', GALLERY_IMAGES_TABLE); $cache->destroy('sql', GALLERY_RATES_TABLE); $cache->destroy('sql', GALLERY_REPORTS_TABLE); $cache->destroy('sql', GALLERY_WATCH_TABLE); $cache->destroy('_albums'); return array(); }
/** * Set users default group * * borrowed from phpBB3 * @author: phpBB Group * @function: group_set_user_default */ public static function group_set_user_default($user_id_ary, $sql_ary) { global $db; if (empty($user_id_ary)) { return; } if (isset($sql_ary['user_colour'])) { // Update any cached colour information for these users $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . " SET album_last_user_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "'\n\t\t\t\tWHERE " . $db->sql_in_set('album_last_user_id', $user_id_ary); $db->sql_query($sql); $sql = 'UPDATE ' . GALLERY_COMMENTS_TABLE . " SET comment_user_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "'\n\t\t\t\tWHERE " . $db->sql_in_set('comment_user_id', $user_id_ary); $db->sql_query($sql); $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . " SET image_user_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "'\n\t\t\t\tWHERE " . $db->sql_in_set('image_user_id', $user_id_ary); $db->sql_query($sql); if (in_array(phpbb_gallery_config::get('newest_pega_user_id'), $user_id_ary)) { phpbb_gallery_config::set('newest_pega_user_colour', $sql_ary['user_colour']); } } }
function main($id, $mode) { global $db, $user, $auth, $cache, $template; phpbb_gallery::init(); $user->add_lang(array('mods/gallery_acp', 'mods/gallery')); $submit = isset($_POST['submit']) ? true : false; $form_key = 'acp_time'; add_form_key($form_key); switch ($mode) { case 'main': // Disable some Options if they can not be used if (!function_exists('exif_read_data')) { $this->display_vars['vars']['exif_data']['type'] = 'custom'; $this->display_vars['vars']['exif_data']['explain'] = true; $this->display_vars['vars']['exif_data']['method'] = 'disabled_boolean'; } if (!function_exists('imagerotate')) { $this->display_vars['vars']['allow_rotate_images']['type'] = 'custom'; $this->display_vars['vars']['allow_rotate_images']['explain'] = true; $this->display_vars['vars']['allow_rotate_images']['method'] = 'disabled_boolean'; } break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } phpbb_gallery_config::load(true); $this->new_config = phpbb_gallery_config::get_array(); $cfg_array = isset($_REQUEST['config']) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; $error = array(); // We validate the complete config if whished validate_config_vars($this->display_vars['vars'], $cfg_array, $error); if ($submit && !check_form_key($form_key)) { $error[] = $user->lang['FORM_INVALID']; } // Do not write values if there is an error if (sizeof($error)) { $submit = false; } // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... foreach ($this->display_vars['vars'] as $config_name => $null) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; if ($submit) { // Check for RRC-display-options if (isset($null['method']) && ($null['method'] == 'rrc_display' || $null['method'] == 'rrc_modes')) { // Changing the value, casted by int to not mess up anything $config_value = (int) array_sum(request_var($config_name, array(0))); } // Recalculate the Watermark-position if (isset($null['method']) && $null['method'] == 'watermark_position') { // Changing the value, casted by int to not mess up anything $config_value = request_var('watermark_position_x', 0) + request_var('watermark_position_y', 0); } if ($config_name == 'link_thumbnail') { $update_bbcode = request_var('update_bbcode', ''); // Update the BBCode if ($update_bbcode) { if (!class_exists('acp_bbcodes')) { phpbb_gallery_url::_include('acp/acp_bbcodes', 'phpbb'); } $acp_bbcodes = new acp_bbcodes(); $bbcode_match = '[album]{NUMBER}[/album]'; $bbcode_tpl = $this->bbcode_tpl($config_value); $sql_ary = $acp_bbcodes->build_regexp($bbcode_match, $bbcode_tpl); $sql_ary = array_merge($sql_ary, array('bbcode_match' => $bbcode_match, 'bbcode_tpl' => $bbcode_tpl, 'display_on_posting' => true, 'bbcode_helpline' => 'GALLERY_HELPLINE_ALBUM')); $sql = 'UPDATE ' . BBCODES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE bbcode_tag = '" . $sql_ary['bbcode_tag'] . "'"; $db->sql_query($sql); $cache->destroy('sql', BBCODES_TABLE); } } phpbb_gallery_config::set($config_name, $config_value); } } if ($submit) { $cache->destroy('sql', CONFIG_TABLE); trigger_error($user->lang['GALLERY_CONFIG_UPDATED'] . adm_back_link($this->u_action)); } $this->tpl_name = 'acp_board'; $this->page_title = $this->display_vars['title']; $template->assign_vars(array('L_TITLE' => $user->lang[$this->display_vars['title']], 'L_TITLE_EXPLAIN' => $user->lang[$this->display_vars['title'] . '_EXPLAIN'], 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'U_ACTION' => $this->u_action)); // Output relevant page foreach ($this->display_vars['vars'] as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars)); continue; } $this->new_config[$config_key] = phpbb_gallery_config::get($config_key); $type = explode(':', $vars['type']); $l_explain = ''; if ($vars['explain']) { $l_explain = isset($user->lang[$vars['lang'] . '_EXP']) ? $user->lang[$vars['lang'] . '_EXP'] : ''; } $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { continue; } $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($user->lang[$vars['lang']]) ? $user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content)); unset($this->display_vars['vars'][$config_key]); } }