One True Image Info Editor

git-svn-id: file:///home/shish/svn/shimmie2/trunk@616 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-11-14 10:11:56 +00:00
parent 078043b9bf
commit 614f11d910
8 changed files with 138 additions and 92 deletions

View file

@ -51,14 +51,15 @@ class NumericScore extends Extension {
}
}
if(is_a($event, 'DisplayingImageEvent')) {
if(is_a($event, 'ImageInfoBoxBuildingEvent')) {
global $user;
global $config;
if(!$user->is_anonymous() || $config->get_bool("numeric_score_anon")) {
$this->theme->display_voter($event->page, $event->image->id, $event->image->numeric_score);
$event->add_part($this->theme->get_voter_html($event->image));
}
}
if(is_a($event, 'ImageDeletionEvent')) {
global $database;
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));

View file

@ -1,15 +1,16 @@
<?php
class NumericScoreTheme extends Themelet {
public function display_voter($page, $image_id, $score) {
$i_image_id = int_escape($image_id);
$i_score = int_escape($score);
public function get_voter_html($image) {
$i_image_id = int_escape($image->id);
$i_score = int_escape($image->numeric_score);
$html = "
<table style='width: 400px;'>
<tr>
<td>Current score is $i_score</td>
<td>
<!--
<form action='".make_link("numeric_score/vote")."' method='POST'>
<input type='hidden' name='image_id' value='$i_image_id' />
<input type='hidden' name='score' value='1'>
@ -21,12 +22,12 @@ class NumericScoreTheme extends Themelet {
<input type='hidden' name='image_id' value='$i_image_id' />
<input type='hidden' name='score' value='-1'>
<input type='submit' value='Vote Down' />
</form>
</form>-->
</td>
</tr>
</table>
";
$page->add_block(new Block(null, $html, "main", 7));
return $html;
}
}

View file

@ -30,35 +30,30 @@ class TextScore extends Extension {
}
$config->set_default_bool("text_score_anon", true);
}
if(is_a($event, 'PageRequestEvent') && $event->page_name == "text_score" &&
$event->get_arg(0) == "vote" &&
isset($_POST['score']) && isset($_POST['image_id'])) {
$i_score = int_escape($_POST['score']);
$i_image_id = int_escape($_POST['image_id']);
if($i_score >= -2 || $i_score <= 2) {
send_event(new TextScoreSetEvent($i_image_id, $event->user, $i_score));
if(is_a($event, 'ImageInfoBoxBuildingEvent')) {
global $user;
global $config;
if(!$user->is_anonymous() || $config->get_bool("text_score_anon")) {
$event->add_part($this->theme->get_scorer_html($event->image));
}
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$i_image_id"));
}
if(is_a($event, 'ImageInfoSetEvent')) {
global $user;
$i_score = int_escape($_POST['text_score__score']);
if($i_score >= -2 || $i_score <= 2) {
send_event(new TextScoreSetEvent($event->image_id, $user, $i_score));
}
}
if(is_a($event, 'TextScoreSetEvent')) {
if(!$event->user->is_anonymous() || $config->get_bool("text_score_anon")) {
$this->add_vote($event->image_id, $event->user->id, $event->score);
}
}
if(is_a($event, 'DisplayingImageEvent')) {
global $user;
global $config;
if(!$user->is_anonymous() || $config->get_bool("text_score_anon")) {
$this->theme->display_scorer($event->page, $event->image->id, $event->image->text_score);
}
}
if(is_a($event, 'ImageDeletionEvent')) {
global $database;
$database->execute("DELETE FROM text_score_votes WHERE image_id=?", array($event->image->id));

View file

@ -1,23 +1,21 @@
<?php
class TextScoreTheme extends Themelet {
public function display_scorer($page, $image_id, $score) {
$i_image_id = int_escape($image_id);
public function get_scorer_html($image) {
$i_image_id = int_escape($image->id);
$s_score = $this->score_to_name($score);
$s_score = $this->score_to_name($image->text_score);
$html = "
Current score is \"$s_score\"
<br><form action='".make_link("text_score/vote")."' method='POST'>
<input type='hidden' name='image_id' value='$i_image_id' />
<input type='radio' name='score' value='-2' id='-2'><label for='-2'>Delete</label>
<input type='radio' name='score' value='-1' id='-1'><label for='-1'>Bad</label>
<input type='radio' name='score' value='0' id='0' ><label for='0' >Ok</label>
<input type='radio' name='score' value='1' id='1' ><label for='1' >Good</label>
<input type='radio' name='score' value='2' id='2' ><label for='2' >Favourite</label>
<input type='submit' value='Vote' />
</form>
<br/>
<input type='hidden' name='image_id' value='$i_image_id' />
<input type='radio' name='text_score__score' value='-2' id='-2'><label for='-2'>Delete</label>
<input type='radio' name='text_score__score' value='-1' id='-1'><label for='-1'>Bad</label>
<input type='radio' name='text_score__score' value='0' id='0' ><label for='0' >Ok</label>
<input type='radio' name='text_score__score' value='1' id='1' ><label for='1' >Good</label>
<input type='radio' name='text_score__score' value='2' id='2' ><label for='2' >Favourite</label>
";
$page->add_block(new Block(null, $html, "main", 7));
return $html;
}
public function score_to_name($score) {

View file

@ -8,23 +8,7 @@ class TagEdit extends Extension {
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "tag_edit")) {
global $page;
if($event->get_arg(0) == "set") {
if($this->can_tag()) {
global $database;
$i_image_id = int_escape($_POST['image_id']);
$query = $_POST['query'];
send_event(new TagSetEvent($i_image_id, $_POST['tags']));
if($this->can_source()) {
send_event(new SourceSetEvent($i_image_id, $_POST['source']));
}
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$i_image_id", $query));
}
else {
$this->theme->display_error($event->page, "Error", "Anonymous tag editing is disabled");
}
}
else if($event->get_arg(0) == "replace") {
if($event->get_arg(0) == "replace") {
global $user;
if($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) {
$search = $_POST['search'];
@ -43,6 +27,19 @@ class TagEdit extends Extension {
}
}
if(is_a($event, 'ImageInfoSetEvent')) {
if($this->can_tag()) {
global $database;
send_event(new TagSetEvent($event->image_id, $_POST['tag_edit__tags']));
if($this->can_source()) {
send_event(new SourceSetEvent($event->image_id, $_POST['tag_edit__source']));
}
}
else {
$this->theme->display_error($event->page, "Error", "Anonymous tag editing is disabled");
}
}
if(is_a($event, 'TagSetEvent')) {
global $database;
$database->set_tags($event->image_id, $event->tags);
@ -67,6 +64,11 @@ class TagEdit extends Extension {
$this->mass_tag_edit($event->oldtag, $event->newtag);
}
if(is_a($event, 'ImageInfoBoxBuildingEvent')) {
global $user;
$event->add_part($this->theme->get_editor_html($event->image, $user), 40);
}
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Tag Editing");
$sb->add_bool_option("tag_edit_anon", "Allow anonymous tag editing: ");

View file

@ -17,5 +17,30 @@ class TagEditTheme extends Themelet {
";
$page->add_block(new Block("Mass Tag Edit", $html));
}
public function get_editor_html($image, $user) {
$html = "";
global $config;
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
$h_tags = html_escape($image->get_tag_list());
$i_image_id = int_escape($image->id);
$source_edit = "";
if($config->get_bool("source_edit_anon") || !$user->is_anonymous()) {
$source_edit = "<tr><td>Source</td><td><input type='text' name='tag_edit__source' value='$h_source'></td></tr>";
}
$html .= "
<table style='width: 500px;'>
<tr><td width='50px'>Tags</td><td width='300px'><input type='text' name='tag_edit__tags' value='$h_tags'></td></tr>
$source_edit
</table>
";
}
return $html;
}
}
?>

View file

@ -1,5 +1,29 @@
<?php
class ImageInfoBoxBuildingEvent extends Event {
var $parts = array();
var $image;
var $user;
public function ImageInfoBoxBuildingEvent($image, $user) {
$this->image = $image;
$this->user = $user;
}
public function add_part($html, $position=50) {
while(isset($this->parts[$position])) $position++;
$this->parts[$position] = $html;
}
}
class ImageInfoSetEvent extends Event {
var $image_id;
public function ImageInfoSetEvent($image_id) {
$this->image_id = int_escape($image_id);
}
}
class ViewImage extends Extension {
var $theme;
@ -20,8 +44,21 @@ class ViewImage extends Extension {
}
}
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "post") && ($event->get_arg(0) == "set")) {
$image_id = int_escape($_POST['image_id']);
send_event(new ImageInfoSetEvent($image_id));
$query = $_POST['query'];
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$image_id", $query));
}
if(is_a($event, 'DisplayingImageEvent')) {
$this->theme->display_page($event->page, $event->get_image());
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $event->user);
send_event($iibbe);
ksort($iibbe->parts);
$this->theme->display_page($event->page, $event->get_image(), $iibbe->parts);
}
}
}

View file

@ -4,12 +4,13 @@ class ViewTheme extends Themelet {
/*
* Build a page showing $image and some info about it
*/
public function display_page($page, $image) {
public function display_page($page, $image, $editor_parts) {
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
$page->set_heading(html_escape($image->get_tag_list()));
$page->add_block(new Block("Navigation", $this->build_navigation($image->id), "left", 0));
$page->add_block(new Block("Image", $this->build_image_view($image), "main", 0));
$page->add_block(new Block(null, $this->build_info($image), "main", 10));
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 10));
$page->add_block(new Block(null, $this->build_pin($image->id), "main", 11));
}
@ -60,7 +61,7 @@ class ViewTheme extends Themelet {
return "<img id='main_image' src='$ilink'>";
}
protected function build_info($image) {
protected function build_info($image, $editor_parts) {
global $user;
$owner = $image->get_owner();
$h_owner = html_escape($owner->name);
@ -70,6 +71,7 @@ class ViewTheme extends Themelet {
$html = "";
$html .= "<p>Uploaded by <a href='".make_link("user/$h_owner")."'>$h_owner</a>";
if($user->is_admin()) {
$html .= " ($h_ip)";
}
@ -81,41 +83,26 @@ class ViewTheme extends Themelet {
$html .= " (<a href='http://$h_source'>source</a>)";
}
}
$html .= " (<a href=\"javascript: toggle('imgdata')\">edit info</a>)";
global $config;
global $user;
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
$html .= " (<a href=\"javascript: toggle('imgdata')\">edit</a>)";
if(isset($_GET['search'])) {$h_query = "search=".url_escape($_GET['search']);}
else {$h_query = "";}
if(isset($_GET['search'])) {$h_query = "search=".url_escape($_GET['search']);}
else {$h_query = "";}
$h_tags = html_escape($image->get_tag_list());
$i_image_id = int_escape($image->id);
$source_edit = "";
if($config->get_bool("source_edit_anon") || !$user->is_anonymous()) {
$source_edit = "<tr><td>Source</td><td><input type='text' name='source' value='$h_source'></td></tr>";
}
$html .= "
<div id='imgdata'><form action='".make_link("tag_edit/set")."' method='POST'>
<input type='hidden' name='image_id' value='$i_image_id'>
<input type='hidden' name='query' value='$h_query'>
<table style='width: 500px;'>
<tr><td width='50px'>Tags</td><td width='300px'><input type='text' name='tags' value='$h_tags'></td></tr>
$source_edit
<tr><td>&nbsp;</td><td><input type='submit' value='Set'></td></tr>
</table>
</form>
</div>
";
$html .= "
<div id='imgdata'>
<form action='".make_link("post/set")."' method='POST'>
<input type='hidden' name='image_id' value='{$image->id}'>
<input type='hidden' name='query' value='$h_query'>
";
foreach($editor_parts as $part) {
$html .= $part;
}
$html .= "<p>".$this->build_pin($image->id);
$html .= "
<input type='submit' value='Set'>
</div>
</form>
";
return $html;
}
}