remove use of sql date types (different databases have wildly different support for them; storing integer times is easier...)
git-svn-id: file:///home/shish/svn/shimmie2/trunk@856 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
d5b21bf8f2
commit
62f6354368
2 changed files with 20 additions and 10 deletions
|
@ -37,7 +37,7 @@ class IPBan extends Extension {
|
||||||
|
|
||||||
if(is_a($event, 'InitExtEvent')) {
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
global $config;
|
global $config;
|
||||||
if($config->get_int("ext_ipban_version") < 3) {
|
if($config->get_int("ext_ipban_version") < 4) {
|
||||||
$this->install();
|
$this->install();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,12 +102,12 @@ class IPBan extends Extension {
|
||||||
id {$database->engine->auto_increment},
|
id {$database->engine->auto_increment},
|
||||||
banner_id INTEGER NOT NULL,
|
banner_id INTEGER NOT NULL,
|
||||||
ip CHAR(15) NOT NULL,
|
ip CHAR(15) NOT NULL,
|
||||||
end DATETIME NOT NULL,
|
end INTEGER,
|
||||||
reason TEXT NOT NULL,
|
reason TEXT NOT NULL,
|
||||||
INDEX (end)
|
INDEX (end)
|
||||||
) {$database->engine->create_table_extras};
|
) {$database->engine->create_table_extras};
|
||||||
");
|
");
|
||||||
$config->set_int("ext_ipban_version", 3);
|
$config->set_int("ext_ipban_version", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===
|
// ===
|
||||||
|
@ -136,6 +136,15 @@ class IPBan extends Extension {
|
||||||
$database->execute("CREATE INDEX bans__end ON bans(end)");
|
$database->execute("CREATE INDEX bans__end ON bans(end)");
|
||||||
$config->set_int("ext_ipban_version", 3);
|
$config->set_int("ext_ipban_version", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($config->get_int("ext_ipban_version") == 3) {
|
||||||
|
$database->execute("ALTER TABLE bans CHANGE end old_end DATE NOT NULL");
|
||||||
|
$database->execute("ALTER TABLE bans ADD COLUMN end INTEGER");
|
||||||
|
$database->execute("UPDATE bans SET end = UNIX_TIMESTAMP(old_end)");
|
||||||
|
$database->execute("ALTER TABLE bans DROP COLUMN old_end");
|
||||||
|
$database->execute("CREATE INDEX bans__end ON bans(end)");
|
||||||
|
$config->set_int("ext_ipban_version", 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
// deal with banned person {{{
|
// deal with banned person {{{
|
||||||
|
@ -172,7 +181,7 @@ class IPBan extends Extension {
|
||||||
|
|
||||||
private function get_active_bans() {
|
private function get_active_bans() {
|
||||||
global $database;
|
global $database;
|
||||||
$bans = $database->get_all("SELECT * FROM bans WHERE (end > now() OR isnull(end))");
|
$bans = $database->get_all("SELECT * FROM bans WHERE (end > ? OR isnull(end))", array(time()));
|
||||||
if($bans) {return $bans;}
|
if($bans) {return $bans;}
|
||||||
else {return array();}
|
else {return array();}
|
||||||
}
|
}
|
||||||
|
@ -182,13 +191,13 @@ class IPBan extends Extension {
|
||||||
$parts = array();
|
$parts = array();
|
||||||
if(preg_match("/^(\d+) (day|week|month)s?$/i", $end, $parts)) {
|
if(preg_match("/^(\d+) (day|week|month)s?$/i", $end, $parts)) {
|
||||||
$sql = "INSERT INTO bans (ip, reason, end, banner_id)
|
$sql = "INSERT INTO bans (ip, reason, end, banner_id)
|
||||||
VALUES (?, ?, now() + interval {$parts[1]} {$parts[2]}, ?)";
|
VALUES (?, ?, ?, ?)";
|
||||||
$database->Execute($sql, array($ip, $reason, $user->id));
|
$database->Execute($sql, array($ip, $reason, strtotime("+{$parts[1]} {$parts[2]}"), $user->id));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql = "INSERT INTO bans (ip, reason, end, banner_id)
|
$sql = "INSERT INTO bans (ip, reason, banner_id)
|
||||||
VALUES (?, ?, ?, ?)";
|
VALUES (?, ?, ?)";
|
||||||
$database->Execute($sql, array($ip, $reason, $end, $user->id));
|
$database->Execute($sql, array($ip, $reason, $user->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,12 @@ class IPBanTheme extends Themelet {
|
||||||
public function display_bans($page, $bans) {
|
public function display_bans($page, $bans) {
|
||||||
$h_bans = "";
|
$h_bans = "";
|
||||||
foreach($bans as $ban) {
|
foreach($bans as $ban) {
|
||||||
|
$end_human = date('Y-m-d', $ban['end']);
|
||||||
$h_bans .= "
|
$h_bans .= "
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$ban['ip']}</td>
|
<td>{$ban['ip']}</td>
|
||||||
<td>{$ban['reason']}</td>
|
<td>{$ban['reason']}</td>
|
||||||
<td>{$ban['end']}</td>
|
<td>{$end_human}</td>
|
||||||
<td>
|
<td>
|
||||||
<form action='".make_link("ip_ban/remove")."' method='POST'>
|
<form action='".make_link("ip_ban/remove")."' method='POST'>
|
||||||
<input type='hidden' name='id' value='{$ban['id']}'>
|
<input type='hidden' name='id' value='{$ban['id']}'>
|
||||||
|
|
Reference in a new issue