コード例 #1
0
    function import()
    {
        global $db, $template, $user;
        $import_schema = request_var('import_schema', '');
        $images = request_var('images', array(''), true);
        $submit = isset($_POST['submit']) ? true : (empty($images) ? false : true);
        if ($import_schema) {
            if (phpbb_gallery_url::_file_exists($import_schema, 'import', '')) {
                include phpbb_gallery_url::_return_file($import_schema, 'import', '');
                // Replace the md5 with the ' again and remove the space at the end to prevent \' troubles
                $user_data['username'] = utf8_substr(str_replace("{{$import_schema}}", "'", $user_data['username']), 0, -1);
                $image_name = utf8_substr(str_replace("{{$import_schema}}", "'", $image_name), 0, -1);
            } else {
                global $phpEx;
                trigger_error(sprintf($user->lang['MISSING_IMPORT_SCHEMA'], $import_schema . '.' . $phpEx), E_USER_WARNING);
            }
            $images_loop = 0;
            foreach ($images as $image_src) {
                /**
                 * Import the images
                 */
                $image_src = str_replace("{{$import_schema}}", "'", $image_src);
                $image_src_full = phpbb_gallery_url::path('import') . utf8_decode($image_src);
                if (file_exists($image_src_full)) {
                    $filetype = getimagesize($image_src_full);
                    $filetype_ext = '';
                    switch ($filetype['mime']) {
                        case 'image/jpeg':
                        case 'image/jpg':
                        case 'image/pjpeg':
                            $filetype_ext = '.jpg';
                            $read_function = 'imagecreatefromjpeg';
                            if (substr(strtolower($image_src), -4) != '.jpg' && substr(strtolower($image_src), -5) != '.jpeg') {
                                trigger_error(sprintf($user->lang['FILETYPE_MIMETYPE_MISMATCH'], $image_src, $filetype['mime']), E_USER_WARNING);
                            }
                            break;
                        case 'image/png':
                        case 'image/x-png':
                            $filetype_ext = '.png';
                            $read_function = 'imagecreatefrompng';
                            if (substr(strtolower($image_src), -4) != '.png') {
                                trigger_error(sprintf($user->lang['FILETYPE_MIMETYPE_MISMATCH'], $image_src, $filetype['mime']), E_USER_WARNING);
                            }
                            break;
                        case 'image/gif':
                        case 'image/giff':
                            $filetype_ext = '.gif';
                            $read_function = 'imagecreatefromgif';
                            if (substr(strtolower($image_src), -4) != '.gif') {
                                trigger_error(sprintf($user->lang['FILETYPE_MIMETYPE_MISMATCH'], $image_src, $filetype['mime']), E_USER_WARNING);
                            }
                            break;
                        default:
                            trigger_error('NOT_ALLOWED_FILE_TYPE');
                            break;
                    }
                    $image_filename = md5(unique_id()) . $filetype_ext;
                    if (!@move_uploaded_file($image_src_full, phpbb_gallery_url::path('upload') . $image_filename)) {
                        if (!@copy($image_src_full, phpbb_gallery_url::path('upload') . $image_filename)) {
                            $user->add_lang('posting');
                            trigger_error(sprintf($user->lang['GENERAL_UPLOAD_ERROR'], phpbb_gallery_url::path('upload') . $image_filename), E_USER_WARNING);
                        }
                    }
                    @chmod(phpbb_gallery_url::path('upload') . $image_filename, 0777);
                    // The source image is imported, so we delete it.
                    @unlink($image_src_full);
                    $sql_ary = array('image_filename' => $image_filename, 'image_thumbnail' => '', 'image_desc' => '', 'image_desc_uid' => '', 'image_desc_bitfield' => '', 'image_user_id' => $user_data['user_id'], 'image_username' => $user_data['username'], 'image_username_clean' => utf8_clean_string($user_data['username']), 'image_user_colour' => $user_data['user_colour'], 'image_user_ip' => $user->ip, 'image_time' => $start_time + $done_images, 'image_album_id' => $album_id, 'image_status' => phpbb_gallery_image::STATUS_APPROVED, 'image_exif_data' => '');
                    $image_tools = new phpbb_gallery_image_tools();
                    $image_tools->set_image_options(phpbb_gallery_config::get('max_filesize'), phpbb_gallery_config::get('max_height'), phpbb_gallery_config::get('max_width'));
                    $image_tools->set_image_data(phpbb_gallery_url::path('upload') . $image_filename);
                    // Read exif data from file
                    $image_tools->read_exif_data();
                    $sql_ary['image_exif_data'] = $image_tools->exif_data_serialized;
                    $sql_ary['image_has_exif'] = $image_tools->exif_data_exist;
                    if ($filetype[0] > phpbb_gallery_config::get('max_width') || $filetype[1] > phpbb_gallery_config::get('max_height')) {
                        /**
                         * Resize overside images
                         */
                        if (phpbb_gallery_config::get('allow_resize')) {
                            $image_tools->resize_image(phpbb_gallery_config::get('max_width'), phpbb_gallery_config::get('max_height'));
                            if ($image_tools->resized) {
                                $image_tools->write_image(phpbb_gallery_url::path('upload') . $image_filename, phpbb_gallery_config::get('jpg_quality'), true);
                            }
                        }
                    }
                    if (!$image_tools->exif_data_force_db && $sql_ary['image_has_exif'] == phpbb_gallery_constants::EXIF_DBSAVED) {
                        // Image was not resized, so we can pull the Exif from the image to save db-memory.
                        $sql_ary['image_has_exif'] = phpbb_gallery_constants::EXIF_AVAILABLE;
                        $sql_ary['image_exif_data'] = '';
                    }
                    // Try to get real filesize from temporary folder (not always working) ;)
                    $sql_ary['filesize_upload'] = @filesize(phpbb_gallery_url::path('upload') . $image_filename) ? @filesize(phpbb_gallery_url::path('upload') . $image_filename) : 0;
                    if ($filename || $image_name == '') {
                        $sql_ary['image_name'] = str_replace("_", " ", utf8_substr($image_src, 0, -4));
                    } else {
                        $sql_ary['image_name'] = str_replace('{NUM}', $num_offset + $done_images, $image_name);
                    }
                    $sql_ary['image_name_clean'] = utf8_clean_string($sql_ary['image_name']);
                    // Put the images into the database
                    $db->sql_query('INSERT INTO ' . GALLERY_IMAGES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                    $done_images++;
                }
                // Remove the image from the list
                unset($images[$images_loop]);
                $images_loop++;
                if ($images_loop == 10) {
                    // We made 10 images, so we end for this turn
                    break;
                }
            }
            if ($images_loop) {
                $image_user = new phpbb_gallery_user($db, $user_data['user_id'], false);
                $image_user->update_images($images_loop);
                phpbb_gallery_config::inc('num_images', $images_loop);
                $todo_images = $todo_images - $images_loop;
            }
            phpbb_gallery_album::update_info($album_id);
            if (!$todo_images) {
                unlink(phpbb_gallery_url::_return_file($import_schema, 'import', ''));
                trigger_error(sprintf($user->lang['IMPORT_FINISHED'], $done_images) . adm_back_link($this->u_action));
            } else {
                // Write the new list
                $this->create_import_schema($import_schema, $album_id, $user_data, $start_time, $num_offset, $done_images, $todo_images, $image_name, $filename, $images);
                // Redirect
                $forward_url = $this->u_action . "&import_schema={$import_schema}";
                meta_refresh(1, $forward_url);
                trigger_error(sprintf($user->lang['IMPORT_DEBUG_MES'], $done_images, $todo_images));
            }
        } else {
            if ($submit) {
                if (!check_form_key('acp_gallery')) {
                    trigger_error('FORM_INVALID', E_USER_WARNING);
                }
                if (!$images) {
                    trigger_error('NO_FILE_SELECTED', E_USER_WARNING);
                }
                // Who is the uploader?
                $username = request_var('username', '', true);
                $user_id = 0;
                if ($username) {
                    if (!function_exists('user_get_id_name')) {
                        phpbb_gallery_url::_include('functions_user', 'phpbb');
                    }
                    user_get_id_name($user_id, $username);
                }
                if (is_array($user_id)) {
                    $user_id = $user_id[0];
                }
                if (!$user_id) {
                    $user_id = $user->data['user_id'];
                }
                $sql = 'SELECT username, user_colour, user_id
				FROM ' . USERS_TABLE . '
				WHERE user_id = ' . $user_id;
                $result = $db->sql_query($sql);
                $user_row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$user_row) {
                    trigger_error('HACKING_ATTEMPT', E_USER_WARNING);
                }
                // Where do we put them to?
                $album_id = request_var('album_id', 0);
                $sql = 'SELECT album_id, album_name
				FROM ' . GALLERY_ALBUMS_TABLE . '
				WHERE album_id = ' . $album_id;
                $result = $db->sql_query($sql);
                $album_row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$album_row) {
                    trigger_error('HACKING_ATTEMPT', E_USER_WARNING);
                }
                $start_time = time();
                $import_schema = md5($start_time);
                $filename = request_var('filename', '') == 'filename' ? true : false;
                $image_name = request_var('image_name', '', true);
                $num_offset = request_var('image_num', 0);
                $this->create_import_schema($import_schema, $album_row['album_id'], $user_row, $start_time, $num_offset, 0, sizeof($images), $image_name, $filename, $images);
                $forward_url = $this->u_action . "&import_schema={$import_schema}";
                meta_refresh(2, $forward_url);
                trigger_error('IMPORT_SCHEMA_CREATED');
            }
        }
        $handle = opendir(phpbb_gallery_url::path('import'));
        $files = array();
        while ($file = readdir($handle)) {
            if (!is_dir(phpbb_gallery_url::path('import') . $file) && (substr(strtolower($file), -4) == '.png' && phpbb_gallery_config::get('allow_png') || substr(strtolower($file), -4) == '.gif' && phpbb_gallery_config::get('allow_gif') || substr(strtolower($file), -4) == '.jpg' && phpbb_gallery_config::get('allow_jpg') || substr(strtolower($file), -5) == '.jpeg' && phpbb_gallery_config::get('allow_jpg'))) {
                $files[utf8_strtolower($file)] = $file;
            }
        }
        closedir($handle);
        // Sort the files by name again
        ksort($files);
        foreach ($files as $file) {
            $template->assign_block_vars('imagerow', array('FILE_NAME' => utf8_encode($file)));
        }
        $template->assign_vars(array('S_IMPORT_IMAGES' => true, 'ACP_GALLERY_TITLE' => $user->lang['ACP_IMPORT_ALBUMS'], 'ACP_GALLERY_TITLE_EXPLAIN' => $user->lang['ACP_IMPORT_ALBUMS_EXPLAIN'], 'L_IMPORT_DIR_EMPTY' => sprintf($user->lang['IMPORT_DIR_EMPTY'], phpbb_gallery_url::path('import')), 'S_ALBUM_IMPORT_ACTION' => $this->u_action, 'S_SELECT_IMPORT' => phpbb_gallery_album::get_albumbox(false, 'album_id', false, false, false, phpbb_gallery_album::PUBLIC_ALBUM, phpbb_gallery_album::TYPE_UPLOAD), 'U_FIND_USERNAME' => phpbb_gallery_url::append_sid('phpbb', 'memberlist', 'mode=searchuser&form=acp_gallery&field=username&select_single=true')));
    }
コード例 #2
0
    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 . '&amp;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 . '&amp;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 . '&amp;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 . '&amp;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 . '&amp;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 . '&amp;parent_id=' . $this->parent_id, 'U_EDIT_ACTION' => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action={$action}&amp;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 . '&amp;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 . "&amp;parent_id={$parent_id}&amp;action=delete&amp;a=" . $album_id, 'U_BACK' => $this->u_action . '&amp;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 .= ' -&gt; ' . $row['album_name'];
                } else {
                    $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;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 . "&amp;parent_id={$this->parent_id}&amp;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 . '&amp;parent_id=' . $row['album_id'], 'U_MOVE_UP' => $url . '&amp;action=move_up', 'U_MOVE_DOWN' => $url . '&amp;action=move_down', 'U_EDIT' => $url . '&amp;action=edit', 'U_DELETE' => $url . '&amp;action=delete', 'U_SYNC' => $url . '&amp;action=sync'));
            } while ($row = $db->sql_fetchrow($result));
        } else {
            if ($this->parent_id) {
                $row = get_album_info($this->parent_id);
                $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;a=' . $row['album_id'];
                $template->assign_vars(array('S_NO_ALBUMS' => true, 'U_EDIT' => $url . '&amp;action=edit', 'U_DELETE' => $url . '&amp;action=delete', 'U_SYNC' => $url . '&amp;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 . '&amp;parent_id=' . $this->parent_id, 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar', 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar')));
    }
コード例 #3
0
ファイル: mcp.php プロジェクト: phpbbgallery/phpbb-gallery
                }
                $db->sql_freeresult($result);
                $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
					SET image_reported = ' . phpbb_gallery_constants::REPORT_UNREPORT . '
					WHERE ' . $db->sql_in_set('image_reported', $image_id_ary);
                $db->sql_query($sql);
                $success = true;
            } else {
                confirm_box(false, 'REPORT' . $multiple . '_A_DELETE2', $s_hidden_fields);
            }
            break;
    }
    if (isset($success)) {
        phpbb_gallery_album::update_info($album_id);
        if ($moving_target) {
            phpbb_gallery_album::update_info($moving_target);
        }
        redirect($redirect == 'redirect' ? phpbb_gallery_url::append_sid('album', "album_id={$album_id}") : phpbb_gallery_url::append_sid('mcp', "mode={$mode}&amp;album_id={$album_id}"));
    }
}
// end if ($action && $image_id_ary)
switch ($mode) {
    case 'album':
        phpbb_gallery_mcp::album($mode, $album_id, $album_data);
        break;
    case 'report_open':
    case 'report_closed':
        phpbb_gallery_mcp::report($mode, $album_id, $album_data);
        break;
    case 'queue_unapproved':
    case 'queue_approved':
コード例 #4
0
    /**
     * Move album content from one to another album
     *
     * borrowed from phpBB3
     * @author: phpBB Group
     * @function: move_forum_content
     */
    public function move_album_content($from_id, $to_id, $sync = true)
    {
        global $cache, $db;
        $sql = 'UPDATE ' . LOG_TABLE . "\n\t\t\tSET album_id = {$to_id}\n\t\t\tWHERE album_id = {$from_id}\n\t\t\t\tAND log_type = " . LOG_GALLERY;
        $db->sql_query($sql);
        // Reset contest-information for safety.
        $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
			SET image_album_id = ' . $to_id . ',
				image_contest_rank = 0,
				image_contest_end = 0,
				image_contest = ' . phpbb_gallery_image::NO_CONTEST . '
			WHERE image_album_id = ' . $from_id;
        $db->sql_query($sql);
        $sql = 'UPDATE ' . GALLERY_REPORTS_TABLE . "\n\t\t\tSET report_album_id = {$to_id}\n\t\t\tWHERE report_album_id = {$from_id}";
        $db->sql_query($sql);
        //@todo: merge queries into loop
        $sql = 'DELETE FROM ' . GALLERY_CONTESTS_TABLE . '
			WHERE contest_album_id = ' . $from_id;
        $db->sql_query($sql);
        $sql = 'DELETE FROM ' . GALLERY_PERMISSIONS_TABLE . '
			WHERE perm_album_id = ' . $from_id;
        $db->sql_query($sql);
        $table_ary = array(GALLERY_WATCH_TABLE, GALLERY_MODSCACHE_TABLE);
        foreach ($table_ary as $table) {
            $sql = "DELETE FROM {$table}\n\t\t\t\tWHERE album_id = {$from_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');
        if ($sync) {
            // Resync counters
            phpbb_gallery_album::update_info($from_id);
            phpbb_gallery_album::update_info($to_id);
        }
        return array();
    }
コード例 #5
0
                                }
                                // Rotate the image
                                $image_tools->rotate_image($rotate, phpbb_gallery_config::get('allow_resize'));
                                if ($image_tools->rotated) {
                                    $image_tools->write_image($image_tools->image_source, phpbb_gallery_config::get('jpg_quality'), true);
                                }
                                @unlink(phpbb_gallery_url::path('cache') . $image_data['image_filename']);
                                @unlink(phpbb_gallery_url::path('medium') . $image_data['image_filename']);
                            }
                            $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' 
						SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
						WHERE image_id = ' . $image_id;
                            $db->sql_query($sql);
                            if ($move_to_personal && $personal_album_id) {
                                phpbb_gallery_album::update_info($album_data['album_id']);
                                phpbb_gallery_album::update_info($personal_album_id);
                            }
                            if ($user->data['user_id'] != $image_data['image_user_id']) {
                                add_log('gallery', $image_data['image_album_id'], $image_id, 'LOG_GALLERY_EDITED', $image_name);
                            }
                        }
                        $message_parser = new parse_message();
                        $message_parser->message = $image_data['image_desc'];
                        $message_parser->decode_message($image_data['image_desc_uid']);
                        $template->assign_vars(array('IMAGE_NAME' => $image_data['image_name'], 'MESSAGE' => $message_parser->message, 'L_DESCRIPTION_LENGTH' => sprintf($user->lang['DESCRIPTION_LENGTH'], phpbb_gallery_config::get('description_length')), 'U_IMAGE' => $image_id ? phpbb_gallery_url::append_sid('image', "album_id={$album_id}&amp;image_id={$image_id}") : '', 'U_VIEW_IMAGE' => $image_id ? phpbb_gallery_url::append_sid('image_page', "album_id={$album_id}&amp;image_id={$image_id}") : '', 'IMAGE_RSZ_WIDTH' => phpbb_gallery_config::get('medium_width'), 'IMAGE_RSZ_HEIGHT' => phpbb_gallery_config::get('medium_height'), 'S_IMAGE' => true, 'S_EDIT' => true, 'S_ALLOW_ROTATE' => phpbb_gallery_config::get('allow_rotate') && function_exists('imagerotate'), 'S_MOVE_PERSONAL' => phpbb_gallery::$auth->acl_check('i_upload', phpbb_gallery_auth::OWN_ALBUM) || phpbb_gallery::$user->get_data('personal_album_id') || $user->data['user_id'] != $image_data['image_user_id'] ? true : false, 'S_MOVE_MODERATOR' => $user->data['user_id'] != $image_data['image_user_id'] ? true : false, 'S_ALBUM_ACTION' => phpbb_gallery_url::append_sid('posting', "mode=image&amp;submode=edit&amp;album_id={$album_id}&amp;image_id={$image_id}")));
                        $message = $user->lang['IMAGES_UPDATED_SUCCESSFULLY'] . '<br />';
                        $page_title = $user->lang['EDIT_IMAGE'];
                    }
                    break;
                case 'report':
                    if ($submode == 'report') {