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&form=postform&field=change_author&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); }