diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 878cfb96..fad0ad73 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -236,6 +236,17 @@ class Image { return User::by_id($this->owner_id); } + /** + * Set the image's owner + */ + public function set_owner(User $owner) { + global $database; + if($owner->id != $this->owner_id) { + $database->execute("UPDATE images SET owner_id=:owner_id WHERE id=:id", array("owner_id"=>$owner->id, "id"=>$this->id)); + log_info("core-image", "Owner for Image #{$this->id} set to: ".$owner->username); + } + } + /** * Get this image's tags as an array */ diff --git a/core/user.class.php b/core/user.class.php index 843d6c9d..aa9073d1 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -110,8 +110,9 @@ class User { "replace_image" => False, "manage_extension_list" => False, "manage_alias_list" => False, - "edit_tag" => $config->get_bool("tag_edit_anon"), - "edit_source" => $config->get_bool("source_edit_anon"), + "edit_image_tag" => $config->get_bool("tag_edit_anon"), + "edit_image_source" => $config->get_bool("source_edit_anon"), + "edit_image_owner" => False, "mass_tag_edit" => False, ), "user" => array( @@ -125,11 +126,13 @@ class User { "delete_user" => False, "delete_image" => False, "delete_comment" => False, + "change_image_owner" => False, "replace_image" => False, "manage_extension_list" => False, "manage_alias_list" => False, - "edit_tag" => True, - "edit_source" => True, + "edit_image_tag" => True, + "edit_image_source" => True, + "edit_image_owner" => False, "mass_tag_edit" => False, ), "admin" => array( @@ -146,8 +149,9 @@ class User { "replace_image" => True, "manage_extension_list" => True, "manage_alias_list" => True, - "edit_tag" => True, - "edit_source" => True, + "edit_image_tag" => True, + "edit_image_source" => True, + "edit_image_owner" => True, "mass_tag_edit" => True, ), ); diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index bdae3ec0..8e485f19 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -5,6 +5,23 @@ * Description: Allow images to have tags assigned to them */ +/* + * OwnerSetEvent: + * $image_id + * $source + * + */ +class OwnerSetEvent extends Event { + var $image; + var $owner; + + public function OwnerSetEvent(Image $image, User $owner) { + $this->image = $image; + $this->owner = $owner; + } +} + + /* * SourceSetEvent: * $image_id @@ -73,14 +90,15 @@ class TagEdit extends Extension { public function onImageInfoSet(ImageInfoSetEvent $event) { global $user, $page; + if($user->can("edit_image_owner")) { + $owner = User::by_name($_POST['tag_edit__owner']); + send_event(new OwnerSetEvent($event->image, $owner)); + } if($this->can_tag($event->image)) { send_event(new TagSetEvent($event->image, $_POST['tag_edit__tags'])); - if($this->can_source($event->image)) { - send_event(new SourceSetEvent($event->image, $_POST['tag_edit__source'])); - } } - else { - $this->theme->display_error($page, "Error", "Anonymous tag editing is disabled"); + if($this->can_source($event->image)) { + send_event(new SourceSetEvent($event->image, $_POST['tag_edit__source'])); } if($user->can("lock_image")) { $locked = isset($_POST['tag_edit__locked']) && $_POST['tag_edit__locked']=="on"; @@ -88,16 +106,23 @@ class TagEdit extends Extension { } } + public function onOwnerSet(OwnerSetEvent $event) { + global $user; + if($user->can("edit_image_owner") || !$event->image->is_locked()) { + $event->image->set_owner($event->owner); + } + } + public function onTagSet(TagSetEvent $event) { global $user; - if($user->can("edit_tag") || !$event->image->is_locked()) { + if($user->can("edit_image_tag") || !$event->image->is_locked()) { $event->image->set_tags($event->tags); } } public function onSourceSet(SourceSetEvent $event) { global $user; - if($user->can("edit_tag") || !$event->image->is_locked()) { + if($user->can("edit_image_source") || !$event->image->is_locked()) { $event->image->set_source($event->source); } } @@ -124,15 +149,10 @@ class TagEdit extends Extension { public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { global $user; - if($this->can_tag($event->image)) { - $event->add_part($this->theme->get_tag_editor_html($event->image), 40); - } - if($this->can_source($event->image)) { - $event->add_part($this->theme->get_source_editor_html($event->image), 41); - } - if($user->can("lock_image")) { - $event->add_part($this->theme->get_lock_editor_html($event->image), 42); - } + $event->add_part($this->theme->get_user_editor_html($event->image), 39); + $event->add_part($this->theme->get_tag_editor_html($event->image), 40); + $event->add_part($this->theme->get_source_editor_html($event->image), 41); + $event->add_part($this->theme->get_lock_editor_html($event->image), 42); } public function onSetupBuilding(SetupBuildingEvent $event) { @@ -145,18 +165,12 @@ class TagEdit extends Extension { private function can_tag(Image $image) { global $config, $user; - return ( - ($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) && - ($user->can("edit_tag") || !$image->is_locked()) - ); + return ($user->can("edit_image_tag") || !$image->is_locked()); } private function can_source(Image $image) { global $config, $user; - return ( - ($config->get_bool("source_edit_anon") || !$user->is_anonymous()) && - ($user->can("edit_source") || !$image->is_locked()) - ); + return ($user->can("edit_image_source") || !$image->is_locked()); } private function mass_tag_edit($search, $replace) { diff --git a/ext/tag_edit/theme.php b/ext/tag_edit/theme.php index 9d0ced81..edabd32f 100644 --- a/ext/tag_edit/theme.php +++ b/ext/tag_edit/theme.php @@ -24,19 +24,71 @@ class TagEditTheme extends Themelet { return " Tags - + + $h_tags + + + + "; + } + + public function get_user_editor_html(Image $image) { + global $user; + $h_owner = html_escape($image->get_owner()->name); + $h_av = $image->get_owner()->get_avatar_html(); + $h_date = autodate($image->posted); + $ip = $user->can("view_ip") ? " ({$image->owner_ip})" : ""; + return " + + User + + $h_owner$ip, $h_date + + + $h_av "; } public function get_source_editor_html(Image $image) { $h_source = html_escape($image->get_source()); - return "Source"; + $f_source = $this->format_source($image->get_source()); + return " + + Source + + $f_source + + + + "; + } + + private function format_source($source) { + if(!empty($source)) { + $h_source = html_escape($source); + if(startsWith($source, "http://") || startsWith($source, "https://")) { + return "$h_source"; + } + else { + return "$h_source"; + } + } + return "Unknown"; } public function get_lock_editor_html(Image $image) { + $b_locked = $image->is_locked() ? "Yes (Only admins may edit these details)" : "No"; $h_locked = $image->is_locked() ? " checked" : ""; - return "Locked"; + return " + + Locked + + $b_locked + + + + "; } } ?> diff --git a/ext/view/theme.php b/ext/view/theme.php index fc91f712..4cd80d2a 100644 --- a/ext/view/theme.php +++ b/ext/view/theme.php @@ -52,7 +52,7 @@ class ViewImageTheme extends Themelet { $h_search = "

- +
"; @@ -62,58 +62,32 @@ class ViewImageTheme extends Themelet { protected function build_info(Image $image, $editor_parts) { global $user; - $owner = $image->get_owner(); - $h_owner = html_escape($owner->name); - $h_ip = html_escape($image->owner_ip); - $i_owner_id = int_escape($owner->id); - $h_date = autodate($image->posted); - $html = "
"; - $html .= "Uploaded by:"; - //$html .= "
".$owner->get_avatar_html(); - $html .= "
$h_owner"; - - if($user->can("view_ip")) { - $html .= " ($h_ip)"; - } - $html .= "
$h_date"; - $html .= $this->format_source($image->source); - $html .= ""; - - $html .= "
"; - $html .= $this->build_image_editor($image, $editor_parts); - $html .= "
"; - - return $html; - } - - private function format_source($source) { - if(!is_null($source)) { - $h_source = html_escape($source); - if(startsWith($source, "http://") || startsWith($source, "https://")) { - return " (source)"; - } - else { - return " (source)"; - } - } - return ""; - } - - protected function build_image_editor(Image $image, $editor_parts) { if(count($editor_parts) == 0) return ($image->is_locked() ? "
[Image Locked]" : ""); $html = make_form(make_link("post/set"))." - +
"; foreach($editor_parts as $part) { $html .= $part; } + if(!$image->is_locked() || $user->can("lock_image")) { + $html .= " + + "; + } $html .= " -
+ + +
+ "; return $html; } diff --git a/themes/default/style.css b/themes/default/style.css index 7aa10387..370a9dc8 100644 --- a/themes/default/style.css +++ b/themes/default/style.css @@ -50,6 +50,7 @@ CODE { font-size: 0.8em; } #body SELECT {width: 150px;} +TD>INPUT[type="button"] {width: 100%;} TD>INPUT[type="submit"] {width: 100%;} TD>INPUT[type="text"] {width: 100%;} TD>INPUT[type="password"] {width: 100%;} @@ -233,3 +234,10 @@ UL { margin: auto; } +.image_info TD { + text-align: left; +} +.image_info TD:first-child { + text-align: right; + padding-right: 4px; +}