Move image uploader info into the image info editor, make it editable

This commit is contained in:
Shish 2012-02-09 17:03:39 +00:00
parent 7ced04d0d0
commit fbbdc898b0
6 changed files with 137 additions and 74 deletions

View file

@ -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
*/

View file

@ -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,
),
);

View file

@ -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) {

View file

@ -24,19 +24,71 @@ class TagEditTheme extends Themelet {
return "
<tr>
<td width='50px'>Tags</td>
<td width='300px'><input type='text' name='tag_edit__tags' value='$h_tags' class='autocomplete_tags' id='tag_editor'></td>
<td width='300px'>
<span class='view'>$h_tags</span>
<input class='edit' type='text' name='tag_edit__tags' value='$h_tags' class='autocomplete_tags' id='tag_editor'>
</td>
</tr>
";
}
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 "
<tr>
<td>User</td>
<td>
<span class='view'><a href='".make_link("user/$h_owner")."'>$h_owner</a>$ip, $h_date</span>
<input class='edit' type='text' name='tag_edit__owner' value='$h_owner'>
</td>
<td width='80px' rowspan='4'>$h_av</td>
</tr>
";
}
public function get_source_editor_html(Image $image) {
$h_source = html_escape($image->get_source());
return "<tr><td>Source</td><td><input type='text' name='tag_edit__source' value='$h_source'></td></tr>";
$f_source = $this->format_source($image->get_source());
return "
<tr>
<td>Source</td>
<td>
<span class='view' style='overflow: hidden; white-space: nowrap;'>$f_source</span>
<input class='edit' type='text' name='tag_edit__source' value='$h_source'>
</td>
</tr>
";
}
private function format_source($source) {
if(!empty($source)) {
$h_source = html_escape($source);
if(startsWith($source, "http://") || startsWith($source, "https://")) {
return "<a href='$h_source'>$h_source</a>";
}
else {
return "<a href='http://$h_source'>$h_source</a>";
}
}
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 "<tr><td>Locked</td><td><input type='checkbox' name='tag_edit__locked'$h_locked></td></tr>";
return "
<tr>
<td>Locked</td>
<td>
<span class='view'>$b_locked</span>
<input class='edit' type='checkbox' name='tag_edit__locked'$h_locked>
</td>
</tr>
";
}
}
?>

View file

@ -52,7 +52,7 @@ class ViewImageTheme extends Themelet {
$h_search = "
<p><form action='".make_link()."' method='GET'>
<input type='hidden' name='q' value='/post/list'>
<input placeholder='Search' id='search_input' name='search' type='text'>
<input placeholder='Search' name='search' type='text'>
<input type='submit' value='Find' style='display: none;'>
</form>
";
@ -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 = "<table style='width: 700px;'><tr><td>";
$html .= "Uploaded by:";
//$html .= "<br>".$owner->get_avatar_html();
$html .= "<br><a href='".make_link("user/$h_owner")."'>$h_owner</a>";
if($user->can("view_ip")) {
$html .= " ($h_ip)";
}
$html .= "<br><small>$h_date";
$html .= $this->format_source($image->source);
$html .= "</small>";
$html .= "</td><td>";
$html .= $this->build_image_editor($image, $editor_parts);
$html .= "</td></tr></table>";
return $html;
}
private function format_source($source) {
if(!is_null($source)) {
$h_source = html_escape($source);
if(startsWith($source, "http://") || startsWith($source, "https://")) {
return " (<a href='$h_source'>source</a>)";
}
else {
return " (<a href='http://$h_source'>source</a>)";
}
}
return "";
}
protected function build_image_editor(Image $image, $editor_parts) {
if(count($editor_parts) == 0) return ($image->is_locked() ? "<br>[Image Locked]" : "");
$html = make_form(make_link("post/set"))."
<input type='hidden' name='image_id' value='{$image->id}'>
<table style='width: 500px;'>
<table style='width: 500px;' class='image_info'>
";
foreach($editor_parts as $part) {
$html .= $part;
}
if(!$image->is_locked() || $user->can("lock_image")) {
$html .= "
<tr><td colspan='4'>
<input class='view' type='button' value='Edit' onclick='$(\".view\").hide(); $(\".edit\").show();'>
<input class='edit' type='submit' value='Set'>
</td></tr>
";
}
$html .= "
<tr><td colspan='2'><input type='submit' value='Set'></td></tr>
</table>
</form>
<script>
$(function() {
$('.edit').hide();
});
</script>
";
return $html;
}

View file

@ -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;
}