Beispiel #1
0
 /**
  * Create a auth-object for a given user
  *
  * @param	int		$user_id	User you want the permissions from.
  * @param	int		$album_id	Only get the permissions for a given album_id. Should save some memory. // Not yet implemented.
  */
 public function phpbb_gallery_auth($user_id, $album_id = false)
 {
     self::$_permissions = array_merge(self::$_permission_i, self::$_permission_c, self::$_permission_m, self::$_permission_misc);
     self::$_permissions_flipped = array_flip(array_merge(self::$_permissions, array('m_')));
     self::$_permissions_flipped['i_count'] = 'i_count';
     self::$_permissions_flipped['a_count'] = 'a_count';
     global $user;
     if ($user_id == $user->data['user_id'] && !empty($user->gallery['user_permissions'])) {
         $this->unserialize_auth_data($user->gallery['user_permissions']);
         return;
     } else {
         if ($user_id != $user->data['user_id']) {
             $permissions_user = phpbb_gallery_user::get_settings($user_id);
             if (!empty($permissions_user['user_permissions'])) {
                 $this->unserialize_auth_data($permissions_user['user_permissions']);
                 return;
             }
         }
     }
     $this->query_auth_data($user_id);
 }
Beispiel #2
0
    public function edit($image_id)
    {
        //we cheat a little but we will make good later
        global $phpbb_root_path, $phpEx;
        $image_data = $this->image->get_image_data($image_id);
        $album_id = $image_data['image_album_id'];
        $album_data = $this->album->get_info($album_id);
        $this->user->add_lang_ext('phpbbgallery/core', array('gallery'));
        $this->display->generate_navigation($album_data);
        add_form_key('gallery');
        $submit = $this->request->variable('submit', false);
        $image_backlink = append_sid('./gallery/image/' . $image_id);
        $album_backlink = append_sid('./gallery/album/' . $image_data['image_album_id']);
        $disp_image_data = $image_data;
        $owner_id = $image_data['image_user_id'];
        $album_loginlink = './ucp.php?mode=login';
        $this->gallery_auth->load_user_premissions($this->user->data['user_id']);
        if (!$this->gallery_auth->acl_check('i_edit', $album_id, $owner_id) || $image_data['image_status'] == \phpbbgallery\core\image\image::STATUS_ORPHAN) {
            if (!$this->gallery_auth->acl_check('m_edit', $album_id, $owner_id)) {
                $this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD');
            }
        }
        if ($submit) {
            if (!check_form_key('gallery')) {
                trigger_error('FORM_INVALID');
            }
            $image_desc = $this->request->variable('message', array(''), true);
            $image_desc = $image_desc[0];
            $image_name = $this->request->variable('image_name', array(''), true);
            $image_name = $image_name[0];
            if (strlen($image_desc) > $this->gallery_config->get('description_length')) {
                trigger_error($this->user->lang('DESC_TOO_LONG'));
            }
            // Create message parser instance
            include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
            $message_parser = new \parse_message();
            $message_parser->message = utf8_normalize_nfc($image_desc);
            if ($message_parser->message) {
                $message_parser->parse(true, true, true, true, false, true, true, true);
            }
            $sql_ary = array('image_name' => $image_name, 'image_name_clean' => utf8_clean_string($image_name), 'image_desc' => $message_parser->message, 'image_desc_uid' => $message_parser->bbcode_uid, 'image_desc_bitfield' => $message_parser->bbcode_bitfield, 'image_allow_comments' => $this->request->variable('allow_comments', 0));
            $errors = array();
            if (empty($sql_ary['image_name_clean'])) {
                $errors[] = $user->lang['MISSING_IMAGE_NAME'];
            }
            if (!$this->gallery_config->get('allow_comments') || !$this->gallery_config->get('comment_user_control')) {
                unset($sql_ary['image_allow_comments']);
            }
            $change_image_count = false;
            if ($this->gallery_auth->acl_check('m_edit', $album_id, $album_data['album_user_id'])) {
                $user_data = $this->image->get_new_author_info($this->request->variable('change_author', '', true));
                if ($user_data) {
                    $sql_ary = array_merge($sql_ary, array('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']));
                    if ($image_data['image_status'] != $this->image->get_status_unaproved()) {
                        $change_image_count = true;
                    }
                } else {
                    if ($this->request->variable('change_author', '', true)) {
                        $errors[] = $user->lang['INVALID_USERNAME'];
                    }
                }
            }
            $move_to_personal = $this->request->variable('move_to_personal', 0);
            if ($move_to_personal) {
                $personal_album_id = 0;
                if ($user->data['user_id'] != $image_data['image_user_id']) {
                    $image_user = new \phpbbgallery\core\user($db, $image_data['image_user_id']);
                    $personal_album_id = $image_user->get_data('personal_album_id');
                    // The User has no personal album, moderators can created that without the need of permissions
                    if (!$personal_album_id) {
                        $personal_album_id = $this->album->generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], $image_user);
                    }
                } else {
                    $personal_album_id = $this->user->get_data('personal_album_id');
                    if (!$personal_album_id && $this->gallery_auth->acl_check('i_upload', $this->gallery_auth->get_own_album())) {
                        $personal_album_id = $this->album->generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], phpbb_gallery::$user);
                    }
                }
                if ($personal_album_id) {
                    $sql_ary['image_album_id'] = $personal_album_id;
                }
            }
            $rotate = $this->request->variable('rotate', array(0));
            $rotate = isset($rotate[0]) ? $rotate[0] : 0;
            if ($this->gallery_config->get('allow_rotate') && $rotate > 0 && $rotate % 90 == 0) {
                $image_tools = new \phpbbgallery\core\file\file();
                $image_tools->set_image_options($this->gallery_config->get('max_filesize'), $this->gallery_config->get('max_height'), $this->gallery_config->get('max_width'));
                $image_tools->set_image_data($this->url->path('upload') . $image_data['image_filename']);
                // Rotate the image
                $image_tools->rotate_image($rotate, $this->gallery_config->get('allow_rotate'));
                if ($image_tools->rotated) {
                    $image_tools->write_image($image_tools->image_source, $this->gallery_config->get('jpg_quality'), true);
                }
                @unlink($this->url->path('thumbnail') . $image_data['image_filename']);
                @unlink($this->url->path('medium') . $image_data['image_filename']);
            }
            $error = implode('<br />', $errors);
            if (!$error) {
                $sql = 'UPDATE ' . $this->table_images . '
					SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE image_id = ' . $image_id;
                $this->db->sql_query($sql);
                $this->album->update_info($album_data['album_id']);
                if ($move_to_personal && $personal_album_id) {
                    $this->album->update_info($personal_album_id);
                }
                if ($change_image_count) {
                    $new_user = new phpbb_gallery_user($db, $user_data['user_id'], false);
                    $new_user->update_images(1);
                    $old_user = new phpbb_gallery_user($db, $image_data['image_user_id'], false);
                    $old_user->update_images(-1);
                }
                if ($this->user->data['user_id'] != $image_data['image_user_id']) {
                    $this->gallery_log->add_log('moderator', 'edit', $image_data['image_album_id'], $image_id, array('LOG_GALLERY_EDITED', $image_name));
                }
                $message = $this->user->lang['IMAGES_UPDATED_SUCCESSFULLY'];
                $message .= '<br /><br />' . sprintf($this->user->lang['CLICK_RETURN_IMAGE'], '<a href="' . $image_backlink . '">', '</a>');
                $message .= '<br /><br />' . sprintf($this->user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>');
                $this->url->meta_refresh(3, $image_backlink);
                trigger_error($message);
            }
            $disp_image_data = array_merge($disp_image_data, $sql_ary);
        }
        if (!class_exists('bbcode')) {
            include $this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext;
        }
        include_once $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext;
        $message_parser = new \parse_message();
        $message_parser->message = $disp_image_data['image_desc'];
        $message_parser->decode_message($disp_image_data['image_desc_uid']);
        $page_title = $disp_image_data['image_name'];
        $this->template->assign_block_vars('image', array('U_IMAGE' => $this->image->generate_link('thumbnail', 'plugin', $image_id, $image_data['image_name'], $album_id), 'IMAGE_NAME' => $disp_image_data['image_name'], 'IMAGE_DESC' => $message_parser->message));
        $this->template->assign_vars(array('L_DESCRIPTION_LENGTH' => $this->user->lang('DESCRIPTION_LENGTH', $this->gallery_config->get('description_length')), 'S_EDIT' => true, 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_image_edit', array('image_id' => $image_id)), 'ERROR' => isset($error) ? $error : '', 'U_VIEW_IMAGE' => $this->helper->route('phpbbgallery_image', array('image_id' => $image_id)), 'IMAGE_NAME' => $image_data['image_name'], 'S_CHANGE_AUTHOR' => $this->gallery_auth->acl_check('m_edit', $album_id, $album_data['album_user_id']), 'U_FIND_USERNAME' => $this->url->append_sid('phpbb', 'memberlist', 'mode=searchuser&amp;form=postform&amp;field=change_author&amp;select_single=true'), 'S_COMMENTS_ENABLED' => $this->gallery_config->get('allow_comments') && $this->gallery_config->get('comment_user_control'), 'S_ALLOW_COMMENTS' => $image_data['image_allow_comments'], 'NUM_IMAGES' => 1, 'S_ALLOW_ROTATE' => $this->gallery_config->get('allow_rotate') && function_exists('imagerotate'), 'S_MOVE_MODERATOR' => $this->user->data['user_id'] != $image_data['image_user_id'] ? true : false));
        return $this->helper->render('gallery/posting_body.html', $page_title);
    }
 /**
  * @dataProvider user_delete_data
  */
 public function test_user_delete($user_id, $exists_before_delete)
 {
     $db = $this->new_dbal();
     $user = new phpbb_gallery_user($db, $user_id);
     $this->assertEquals($exists_before_delete, $user->entry_exists);
     $user->delete();
     unset($user);
     $user = new phpbb_gallery_user($db, $user_id);
     $this->assertEquals(false, $user->entry_exists);
 }
    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 . '&amp;check_mode=source', 'CHECK_ENTRY' => $this->u_action . '&amp;check_mode=entry', 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false));
    }
Beispiel #5
0
 $image_desc = request_var('message', '', true);
 $image_name = request_var('image_name', '', true);
 if (empty($image_name)) {
     trigger_error('MISSING_IMAGE_NAME');
 }
 $message_parser = new parse_message();
 $message_parser->message = utf8_normalize_nfc($image_desc);
 if ($message_parser->message) {
     $message_parser->parse(true, true, true, true, false, true, true, true);
 }
 $sql_ary = array('image_name' => $image_name, 'image_name_clean' => utf8_clean_string($image_name), 'image_desc' => $message_parser->message, 'image_desc_uid' => $message_parser->bbcode_uid, 'image_desc_bitfield' => $message_parser->bbcode_bitfield);
 $move_to_personal = request_var('move_to_personal', 0);
 if ($move_to_personal) {
     $personal_album_id = 0;
     if ($user->data['user_id'] != $image_data['image_user_id']) {
         $image_user = new phpbb_gallery_user($db, $image_data['image_user_id']);
         $personal_album_id = $image_user->get_data('personal_album_id');
         // The User has no personal album, moderators can created that without the need of permissions
         if (!$personal_album_id) {
             $personal_album_id = phpbb_gallery_album::generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], $image_user);
         }
     } else {
         $personal_album_id = phpbb_gallery::$user->get_data('personal_album_id');
         if (!$personal_album_id && phpbb_gallery::$auth->acl_check('i_upload', phpbb_gallery_auth::OWN_ALBUM)) {
             $personal_album_id = phpbb_gallery_album::generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], phpbb_gallery::$user);
         }
     }
     if ($personal_album_id) {
         $sql_ary['image_album_id'] = $personal_album_id;
     }
 } else {