a bunch of fixes

This commit is contained in:
Shish 2009-01-22 05:42:44 -08:00
parent bda38bff6c
commit d98962a30e
12 changed files with 28 additions and 40 deletions

View File

@ -82,11 +82,11 @@ class EventLog implements Extension {
$this->add_to_log($user, 'Image Deletion', "Deleted image {$event->image->id} (tags: {$event->image->get_tag_list()})"); $this->add_to_log($user, 'Image Deletion', "Deleted image {$event->image->id} (tags: {$event->image->get_tag_list()})");
} }
if($event instanceof SourceSetEvent) { if($event instanceof SourceSetEvent) {
$this->add_to_log($user, 'Source Set', "Source for image #{$event->image_id} set to '{$event->source}'"); $this->add_to_log($user, 'Source Set', "Source for image #{$event->image->id} set to '{$event->source}'");
} }
if($event instanceof TagSetEvent) { if($event instanceof TagSetEvent) {
$tags = implode($event->tags, ", "); $tags = implode($event->tags, ", ");
$this->add_to_log($user, 'Tags Set', "Tags for image #{$event->image_id} set to '$tags'"); $this->add_to_log($user, 'Tags Set', "Tags for image #{$event->image->id} set to '$tags'");
} }
} }

View File

@ -53,15 +53,6 @@ class NumericScore implements Extension {
} }
} }
if($event instanceof ImageInfoSetEvent) {
global $user;
$char = $_POST['numeric_score'];
$score = 0;
if($char == "u") $score = 1;
else if($char == "d") $score = -1;
if($score != 0) send_event(new NumericScoreSetEvent($event->image_id, $user, $score));
}
if($event instanceof NumericScoreSetEvent) { if($event instanceof NumericScoreSetEvent) {
$this->add_vote($event->image_id, $event->user->id, $event->score); $this->add_vote($event->image_id, $event->user->id, $event->score);
} }

View File

@ -47,7 +47,7 @@ class Ratings implements Extension {
if($event instanceof ImageInfoSetEvent) { if($event instanceof ImageInfoSetEvent) {
global $user; global $user;
if($user->is_admin()) { if($user->is_admin()) {
send_event(new RatingSetEvent($event->image_id, $user, $_POST['rating'])); send_event(new RatingSetEvent($event->image->id, $user, $_POST['rating']));
} }
} }

View File

@ -85,10 +85,8 @@ class ReportImage implements Extension {
} }
if($event instanceof DisplayingImageEvent) { if($event instanceof DisplayingImageEvent) {
global $user; if($event->context->config->get_bool('report_image_anon') || !$event->context->user->is_anonymous()) {
global $config; $this->theme->display_image_banner($event->page, $event->image);
if($config->get_bool('report_image_anon') || !$user->is_anonymous()) {
$this->theme->display_image_banner($event->page, $event->image->id);
} }
} }

View File

@ -74,7 +74,7 @@ class ReportImageTheme extends Themelet {
public function display_image_banner(Page $page, Image $image) { public function display_image_banner(Page $page, Image $image) {
global $config; global $config;
$i_image = int_escape($image); $i_image = int_escape($image->id);
$html = " $html = "
<form action='".make_link("image_report/add")."' method='POST'> <form action='".make_link("image_report/add")."' method='POST'>
<input type='hidden' name='image_id' value='$i_image'> <input type='hidden' name='image_id' value='$i_image'>

View File

@ -57,7 +57,7 @@ class Tag_History implements Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
if(($event instanceof TagSetEvent)) { if(($event instanceof TagSetEvent)) {
$this->add_tag_history($event->image_id, $event->tags); $this->add_tag_history($event->image->id, $event->tags);
} }
} }
@ -76,7 +76,7 @@ class Tag_History implements Extension {
date_set DATETIME NOT NULL, date_set DATETIME NOT NULL,
INDEX(image_id), INDEX(image_id),
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES images(id) ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
"); ");
$config->set_int("ext_tag_history_version", 3); $config->set_int("ext_tag_history_version", 3);
} }

View File

@ -48,7 +48,7 @@ class TextScore implements Extension {
$i_score = int_escape($_POST['text_score__score']); $i_score = int_escape($_POST['text_score__score']);
if($i_score >= -2 || $i_score <= 2) { if($i_score >= -2 || $i_score <= 2) {
send_event(new TextScoreSetEvent($event->image_id, $user, $i_score)); send_event(new TextScoreSetEvent($event->image->id, $user, $i_score));
} }
} }

View File

@ -173,7 +173,7 @@ class Image {
return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext')); return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext'));
} }
else { else {
return $this->parse_link_template('image/$id.$ext'); return $this->parse_link_template(make_link('image/$id.$ext'));
} }
} }
@ -190,7 +190,7 @@ class Image {
return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg')); return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg'));
} }
else { else {
return $this->parse_link_template('image/$id.jpg'); return $this->parse_link_template(make_link('image/$id.jpg'));
} }
} }

View File

@ -193,6 +193,7 @@ class TagList implements Extension {
$h_tag = html_escape($row['tag']); $h_tag = html_escape($row['tag']);
$link = $this->tag_link($row['tag']); $link = $this->tag_link($row['tag']);
$image = Image::by_random($config, $database, array($row['tag'])); $image = Image::by_random($config, $database, array($row['tag']));
if(is_null($image)) continue; // one of the popular tags has no images
$thumb = $image->get_thumb_link(); $thumb = $image->get_thumb_link();
$html .= "<td><a href='$link'><img src='$thumb'><br>$h_tag</a></td>\n"; $html .= "<td><a href='$link'><img src='$thumb'><br>$h_tag</a></td>\n";
if($n%3==2) $html .= "</tr>"; if($n%3==2) $html .= "</tr>";

View File

@ -33,7 +33,7 @@ class UserPageTheme extends Themelet {
$html .= " $html .= "
<form action='".make_link("user_admin/create")."' method='POST'> <form action='".make_link("user_admin/create")."' method='POST'>
<table style='width: 300px;' border='1'> <table style='width: 300px;'>
<tr><td>Name</td><td><input type='text' name='name'></td></tr> <tr><td>Name</td><td><input type='text' name='name'></td></tr>
<tr><td>Password</td><td><input type='password' name='pass1'></td></tr> <tr><td>Password</td><td><input type='password' name='pass1'></td></tr>
<tr><td>Repeat Password</td><td><input type='password' name='pass2'></td></tr> <tr><td>Repeat Password</td><td><input type='password' name='pass2'></td></tr>
@ -61,7 +61,7 @@ class UserPageTheme extends Themelet {
global $config; global $config;
$html = " $html = "
<form action='".make_link("user_admin/login")."' method='POST'> <form action='".make_link("user_admin/login")."' method='POST'>
<table border='1' summary='Login Form'> <table summary='Login Form'>
<tr><td width='70'>Name</td><td width='70'><input type='text' name='user'></td></tr> <tr><td width='70'>Name</td><td width='70'><input type='text' name='user'></td></tr>
<tr><td>Password</td><td><input type='password' name='pass'></td></tr> <tr><td>Password</td><td><input type='password' name='pass'></td></tr>
<tr><td colspan='2'><input type='submit' name='gobu' value='Log In'></td></tr> <tr><td colspan='2'><input type='submit' name='gobu' value='Log In'></td></tr>
@ -148,8 +148,8 @@ class UserPageTheme extends Themelet {
<form action='".make_link("user_admin/change_pass")."' method='POST'> <form action='".make_link("user_admin/change_pass")."' method='POST'>
<input type='hidden' name='name' value='{$duser->name}'> <input type='hidden' name='name' value='{$duser->name}'>
<input type='hidden' name='id' value='{$duser->id}'> <input type='hidden' name='id' value='{$duser->id}'>
<table style='width: 300px;' border='1'> <table style='width: 300px;'>
<tr><td colspan='2'>Change Password</td></tr> <tr><th colspan='2'>Change Password</th></tr>
<tr><td>Password</td><td><input type='password' name='pass1'></td></tr> <tr><td>Password</td><td><input type='password' name='pass1'></td></tr>
<tr><td>Repeat Password</td><td><input type='password' name='pass2'></td></tr> <tr><td>Repeat Password</td><td><input type='password' name='pass2'></td></tr>
<tr><td colspan='2'><input type='Submit' value='Change Password'></td></tr> <tr><td colspan='2'><input type='Submit' value='Change Password'></td></tr>

View File

@ -9,11 +9,12 @@
* which only appears when an image actually exists. * which only appears when an image actually exists.
*/ */
class DisplayingImageEvent extends Event { class DisplayingImageEvent extends Event {
var $image, $page; var $image, $page, $context;
public function DisplayingImageEvent($image, $page) { public function __construct(RequestContext $context, Image $image) {
parent::__construct($context);
$this->image = $image; $this->image = $image;
$this->page = $page; $this->page = $context->page;
} }
public function get_image() { public function get_image() {
@ -74,7 +75,7 @@ class ViewImage implements Extension {
$image = Image::by_id($config, $database, $image_id); $image = Image::by_id($config, $database, $image_id);
if(!is_null($image)) { if(!is_null($image)) {
send_event(new DisplayingImageEvent($image, $event->page)); send_event(new DisplayingImageEvent($event->context, $image));
$iabbe = new ImageAdminBlockBuildingEvent($image, $event->user); $iabbe = new ImageAdminBlockBuildingEvent($image, $event->user);
send_event($iabbe); send_event($iabbe);
ksort($iabbe->parts); ksort($iabbe->parts);

View File

@ -154,7 +154,7 @@ function create_tables($dsn) { // {{{
$db->execute($engine->create_table_sql("aliases", " $db->execute($engine->create_table_sql("aliases", "
oldtag VARCHAR(128) NOT NULL PRIMARY KEY, oldtag VARCHAR(128) NOT NULL PRIMARY KEY,
newtag VARCHAR(128) NOT NULL, newtag VARCHAR(128) NOT NULL,
UNIQUE(oldtag, newtag) INDEX(newtag)
")); "));
$db->execute($engine->create_table_sql("config", " $db->execute($engine->create_table_sql("config", "
name VARCHAR(128) NOT NULL PRIMARY KEY, name VARCHAR(128) NOT NULL PRIMARY KEY,
@ -162,12 +162,11 @@ function create_tables($dsn) { // {{{
")); "));
$db->execute($engine->create_table_sql("users", " $db->execute($engine->create_table_sql("users", "
id SCORE_AIPK, id SCORE_AIPK,
name VARCHAR(32) NOT NULL, name VARCHAR(32) UNIQUE NOT NULL,
pass CHAR(32), pass CHAR(32),
joindate DATETIME NOT NULL DEFAULT SCORE_NOW, joindate DATETIME NOT NULL DEFAULT SCORE_NOW,
admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
email VARCHAR(128), email VARCHAR(128)
INDEX(name)
")); "));
$db->execute($engine->create_table_sql("images", " $db->execute($engine->create_table_sql("images", "
id SCORE_AIPK, id SCORE_AIPK,
@ -175,30 +174,28 @@ function create_tables($dsn) { // {{{
owner_ip SCORE_INET NOT NULL, owner_ip SCORE_INET NOT NULL,
filename VARCHAR(64) NOT NULL, filename VARCHAR(64) NOT NULL,
filesize INTEGER NOT NULL, filesize INTEGER NOT NULL,
hash CHAR(32) NOT NULL, hash CHAR(32) UNIQUE NOT NULL,
ext CHAR(4) NOT NULL, ext CHAR(4) NOT NULL,
source VARCHAR(255), source VARCHAR(255),
width INTEGER NOT NULL, width INTEGER NOT NULL,
height INTEGER NOT NULL, height INTEGER NOT NULL,
posted TIMESTAMP NOT NULL DEFAULT SCORE_NOW, posted TIMESTAMP NOT NULL DEFAULT SCORE_NOW,
INDEX(owner_id), INDEX(owner_id),
INDEX(hash),
INDEX(width), INDEX(width),
INDEX(height), INDEX(height),
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
")); "));
$db->execute($engine->create_table_sql("tags", " $db->execute($engine->create_table_sql("tags", "
id SCORE_AIPK, id SCORE_AIPK,
tag VARCHAR(64) NOT NULL, tag VARCHAR(64) UNIQUE NOT NULL,
count INTEGER NOT NULL DEFAULT 0, count INTEGER NOT NULL DEFAULT 0
UNIQUE(tag)
")); "));
$db->execute($engine->create_table_sql("image_tags", " $db->execute($engine->create_table_sql("image_tags", "
image_id INTEGER NOT NULL, image_id INTEGER NOT NULL,
tag_id INTEGER NOT NULL, tag_id INTEGER NOT NULL,
INDEX(image_id), INDEX(image_id),
INDEX(tag_id), INDEX(tag_id),
INDEX(image_id, tag_id), UNIQUE(image_id, tag_id),
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
")); "));