changes to 2.2, and remove broken text score
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.2@784 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
64db094721
commit
d3ceb8ef97
@ -28,48 +28,32 @@ class NumericScore extends Extension {
|
||||
if($config->get_int("ext_numeric_score_version", 0) < 1) {
|
||||
$this->install();
|
||||
}
|
||||
$config->set_default_bool("numeric_score_anon", true);
|
||||
}
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && $event->page_name == "numeric_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 >= -1 || $i_score <= 1) {
|
||||
send_event(new NumericScoreSetEvent($i_image_id, $event->user, $i_score));
|
||||
}
|
||||
|
||||
$event->page->set_mode("redirect");
|
||||
$event->page->set_redirect(make_link("post/view/$i_image_id"));
|
||||
}
|
||||
|
||||
if(is_a($event, 'NumericScoreSetEvent')) {
|
||||
if(!$event->user->is_anonymous() || $config->get_bool("numeric_score_anon")) {
|
||||
$this->add_vote($event->image_id, $event->user->id, $event->score);
|
||||
}
|
||||
}
|
||||
|
||||
if(is_a($event, 'ImageInfoBoxBuildingEvent')) {
|
||||
global $user;
|
||||
global $config;
|
||||
if(!$user->is_anonymous() || $config->get_bool("numeric_score_anon")) {
|
||||
if(!$user->is_anonymous()) {
|
||||
$event->add_part($this->theme->get_voter_html($event->image));
|
||||
}
|
||||
}
|
||||
|
||||
if(is_a($event, 'ImageInfoSetEvent')) {
|
||||
global $user;
|
||||
$char = $_POST['numeric_score'];
|
||||
if($char == "u") $score = 1;
|
||||
else if($char == "d") $score = -1;
|
||||
send_event(new NumericScoreSetEvent($event->image_id, $user, $score));
|
||||
}
|
||||
|
||||
if(is_a($event, 'NumericScoreSetEvent')) {
|
||||
$this->add_vote($event->image_id, $event->user->id, $event->score);
|
||||
}
|
||||
|
||||
if(is_a($event, 'ImageDeletionEvent')) {
|
||||
global $database;
|
||||
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));
|
||||
}
|
||||
|
||||
if(is_a($event, 'SetupBuildingEvent')) {
|
||||
$sb = new SetupBlock("Numeric Score");
|
||||
$sb->add_bool_option("numeric_score_anon", "Allow anonymous votes: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
if(is_a($event, 'ParseLinkTemplateEvent')) {
|
||||
$event->replace('$score', $event->image->numeric_score);
|
||||
|
@ -6,26 +6,14 @@ class NumericScoreTheme extends Themelet {
|
||||
$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'>
|
||||
<input type='submit' value='Vote Up' />
|
||||
</form>
|
||||
</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'>
|
||||
<input type='submit' value='Vote Down' />
|
||||
</form>-->
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<tr>
|
||||
<td>Score ($i_score)</td>
|
||||
<td>
|
||||
<input type='radio' name='numeric_score' value='u' id='u'><label for='u'>Up</label>
|
||||
<input type='radio' name='numeric_score' value='n' id='n' checked><label for='n'>Keep</label>
|
||||
<input type='radio' name='numeric_score' value='d' id='d'><label for='d'>Down</label>
|
||||
</td>
|
||||
</tr>
|
||||
";
|
||||
return $html;
|
||||
}
|
||||
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Name: Image Scores (Text)
|
||||
* Author: Shish <webmaster@shishnet.org>
|
||||
* Link: http://trac.shishnet.org/shimmie2/
|
||||
* License: GPLv2
|
||||
* Description: Allow users to score images
|
||||
*/
|
||||
|
||||
class TextScoreSetEvent extends Event {
|
||||
var $image_id, $user, $score;
|
||||
|
||||
public function TextScoreSetEvent($image_id, $user, $score) {
|
||||
$this->image_id = $image_id;
|
||||
$this->user = $user;
|
||||
$this->score = $score;
|
||||
}
|
||||
}
|
||||
|
||||
class TextScore extends Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event($event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object("text_score", "TextScoreTheme");
|
||||
|
||||
if(is_a($event, 'InitExtEvent')) {
|
||||
global $config;
|
||||
if($config->get_int("ext_text_score_version", 0) < 1) {
|
||||
$this->install();
|
||||
}
|
||||
$config->set_default_bool("text_score_anon", true);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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, 'ImageDeletionEvent')) {
|
||||
global $database;
|
||||
$database->execute("DELETE FROM text_score_votes WHERE image_id=?", array($event->image->id));
|
||||
}
|
||||
|
||||
if(is_a($event, 'SetupBuildingEvent')) {
|
||||
$sb = new SetupBlock("Text Score");
|
||||
$sb->add_bool_option("text_score_anon", "Allow anonymous votes: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
if(is_a($event, 'ParseLinkTemplateEvent')) {
|
||||
$event->replace('$text_score', $this->theme->score_to_name($event->image->text_score));
|
||||
}
|
||||
}
|
||||
|
||||
private function install() {
|
||||
global $database;
|
||||
global $config;
|
||||
|
||||
if($config->get_int("ext_text_score_version") < 1) {
|
||||
$database->Execute("ALTER TABLE images ADD COLUMN text_score INTEGER NOT NULL DEFAULT 0");
|
||||
$database->Execute("CREATE INDEX images__text_score ON images(text_score)");
|
||||
$database->Execute("
|
||||
CREATE TABLE text_score_votes (
|
||||
image_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
score INTEGER NOT NULL,
|
||||
UNIQUE(image_id, user_id),
|
||||
INDEX(image_id)
|
||||
)
|
||||
");
|
||||
$config->set_int("ext_text_score_version", 1);
|
||||
}
|
||||
}
|
||||
|
||||
private function add_vote($image_id, $user_id, $score) {
|
||||
global $database;
|
||||
// TODO: update if already voted
|
||||
$database->Execute(
|
||||
"REPLACE INTO text_score_votes(image_id, user_id, score) VALUES(?, ?, ?)",
|
||||
array($image_id, $user_id, $score));
|
||||
$database->Execute(
|
||||
"UPDATE images SET text_score=(SELECT AVG(score) FROM text_score_votes WHERE image_id=?) WHERE id=?",
|
||||
array($image_id, $image_id));
|
||||
}
|
||||
}
|
||||
add_event_listener(new TextScore());
|
||||
?>
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
class TextScoreTheme extends Themelet {
|
||||
public function get_scorer_html($image) {
|
||||
$i_image_id = int_escape($image->id);
|
||||
|
||||
$s_score = $this->score_to_name($image->text_score);
|
||||
$html = "
|
||||
Current score is \"$s_score\"
|
||||
<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>
|
||||
";
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function score_to_name($score) {
|
||||
$words = array();
|
||||
$words[-2] = "Delete";
|
||||
$words[-1] = "Bad";
|
||||
$words[ 0] = "Ok";
|
||||
$words[ 1] = "Good";
|
||||
$words[ 2] = "Favourite";
|
||||
$s_score = $words[$score];
|
||||
return $s_score;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -34,10 +34,8 @@ class TagEditTheme extends Themelet {
|
||||
}
|
||||
|
||||
$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>
|
||||
";
|
||||
}
|
||||
|
||||
|
@ -93,12 +93,14 @@ class ViewTheme extends Themelet {
|
||||
<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'>
|
||||
<table style='width: 500px;'>
|
||||
";
|
||||
foreach($editor_parts as $part) {
|
||||
$html .= $part;
|
||||
}
|
||||
$html .= "
|
||||
<br><input type='submit' value='Set'>
|
||||
<tr><td colspan='2'><input type='submit' value='Set'></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
<br>
|
||||
</div>
|
||||
|
@ -43,7 +43,9 @@ TD {
|
||||
background: #DDD;
|
||||
}
|
||||
#body SELECT {width: 150px;}
|
||||
TD>INPUT {width: 100%;}
|
||||
TD>INPUT[type="submit"] {width: 100%;}
|
||||
TD>INPUT[type="text"] {width: 100%;}
|
||||
TD>INPUT[type="password"] {width: 100%;}
|
||||
TD>SELECT {width: 100%;}
|
||||
|
||||
#footer {
|
||||
|
Loading…
x
Reference in New Issue
Block a user