1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-12 01:50:48 +01:00

Removed board.id. Use the board URI/name at the key instead.

This commit is contained in:
Michael Save 2012-04-12 23:23:47 +10:00
parent c39c54c2c2
commit 95709e7588
8 changed files with 117 additions and 98 deletions

View File

@ -100,7 +100,7 @@ class Filter {
if($all_boards)
$query->bindValue(':board', null, PDO::PARAM_NULL);
else
$query->bindValue(':board', $board['id']);
$query->bindValue(':board', $board['uri']);
$query->execute() or error(db_error($query));

View File

@ -276,10 +276,10 @@ function setupBoard($array) {
global $board, $config;
$board = array(
'id' => $array['id'],
'uri' => $array['uri'],
'name' => $array['title'],
'title' => $array['subtitle']);
'uri' => $array['uri'],
'name' => $array['title'],
'title' => $array['subtitle']
);
$board['dir'] = sprintf($config['board_path'], $board['uri']);
$board['url'] = sprintf($config['board_abbreviation'], $board['uri']);
@ -287,13 +287,16 @@ function setupBoard($array) {
loadConfig();
if(!file_exists($board['dir']))
mkdir($board['dir'], 0777) or error("Couldn't create " . $board['dir'] . ". Check permissions.", true);
@mkdir($board['dir'], 0777) or error("Couldn't create " . $board['dir'] . ". Check permissions.", true);
if(!file_exists($board['dir'] . $config['dir']['img']))
@mkdir($board['dir'] . $config['dir']['img'], 0777) or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
@mkdir($board['dir'] . $config['dir']['img'], 0777)
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
if(!file_exists($board['dir'] . $config['dir']['thumb']))
@mkdir($board['dir'] . $config['dir']['thumb'], 0777) or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
@mkdir($board['dir'] . $config['dir']['thumb'], 0777)
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
if(!file_exists($board['dir'] . $config['dir']['res']))
@mkdir($board['dir'] . $config['dir']['res'], 0777) or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
@mkdir($board['dir'] . $config['dir']['res'], 0777)
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
}
function openBoard($uri) {
@ -567,12 +570,12 @@ function checkBan($board = 0) {
if(event('check-ban', $board))
return true;
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri`, `bans`.`id` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1");
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board);
$query->execute() or error(db_error($query));
if($query->rowCount() < 1 && $config['ban_range']) {
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri`, `bans`.`id` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board);
$query->execute() or error(db_error($query));
@ -580,7 +583,7 @@ function checkBan($board = 0) {
if($query->rowCount() < 1 && $config['ban_cidr'] && !isIPv6()) {
// my most insane SQL query yet
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri`, `bans`.`id` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board)
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board)
AND (
`ip` REGEXP '^(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+\)\/(\[0-9]+)$'
AND

View File

@ -96,7 +96,7 @@ function modLog($action, $_board=null) {
if(isset($_board))
$query->bindValue(':board', $_board);
elseif(isset($board))
$query->bindValue(':board', $board['id']);
$query->bindValue(':board', $board['uri']);
else
$query->bindValue(':board', null, PDO::PARAM_NULL);
$query->execute() or error(db_error($query));
@ -125,7 +125,7 @@ function ulBoards() {
$b['title'] .
(isset($b['subtitle']) ? '<span class="unimportant"> — ' . $b['subtitle'] . '</span>' : '') .
($mod['type'] >= $config['mod']['manageboards'] ?
' <a href="?/board/' . $b['uri'] . '" class="unimportant">[manage]</a>' : '') .
' <a href="?/' . $b['uri'] . '/edit" class="unimportant">[manage]</a>' : '') .
'</li>';
}
@ -139,10 +139,10 @@ function form_newBan($ip=null, $reason='', $continue=false, $delete=false, $boar
global $config, $mod;
$boards = listBoards();
$__boards = '<li><input type="radio" checked="checked" name="board_id" id="board_*" value="-1"/> <label style="display:inline" for="board_*"><em>' . _('all boards') . '</em></label></li>';
$__boards = '<li><input type="radio" checked="checked" name="board" id="board_*" value=""/> <label style="display:inline" for="board_*"><em>' . _('all boards') . '</em></label></li>';
foreach($boards as &$_board) {
$__boards .= '<li>' .
'<input type="radio" name="board_id" id="board_' . $_board['uri'] . '" value="' . $_board['id'] . '">' .
'<input type="radio" name="board" id="board_' . $_board['uri'] . '" value="' . $_board['uri'] . '">' .
'<label style="display:inline" for="board_' . $_board['uri'] . '"> ' .
($_board['uri'] == '*' ?
'<em>"*"</em>'

View File

@ -1,7 +1,7 @@
<?php
// Installation/upgrade file
define('VERSION', 'v0.9.6-dev-2');
define('VERSION', 'v0.9.6-dev-3');
require 'inc/functions.php';
@ -184,7 +184,30 @@ if(file_exists($config['has_installed'])) {
`passed` smallint(6) NOT NULL,
PRIMARY KEY (`hash`),
KEY `board` (`board`,`thread`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error());
case 'v0.9.6-dev-2':
query("ALTER TABLE `boards`
DROP `id`,
CHANGE `uri` `uri` VARCHAR( 120 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL") or error(db_error());
query("ALTER TABLE `bans` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
query("ALTER TABLE `reports` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
query("ALTER TABLE `modlogs` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
foreach($boards as $board) {
$query = prepare("UPDATE `bans` SET `board` = :newboard WHERE `board` = :oldboard");
$query->bindValue(':newboard', $board['uri']);
$query->bindValue(':oldboard', $board['id']);
$query->execute() or error(db_error($query));
$query = prepare("UPDATE `modlogs` SET `board` = :newboard WHERE `board` = :oldboard");
$query->bindValue(':newboard', $board['uri']);
$query->bindValue(':oldboard', $board['id']);
$query->execute() or error(db_error($query));
$query = prepare("UPDATE `reports` SET `board` = :newboard WHERE `board` = :oldboard");
$query->bindValue(':newboard', $board['uri']);
$query->bindValue(':oldboard', $board['id']);
$query->execute() or error(db_error($query));
}
case false:
// Update version number
file_write($config['has_installed'], VERSION);

View File

@ -3,9 +3,9 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 09, 2011 at 04:03 AM
-- Server version: 5.1.58
-- PHP Version: 5.3.6
-- Generation Time: Apr 12, 2012 at 11:22 PM
-- Server version: 5.1.61
-- PHP Version: 5.3.3-7+squeeze8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
@ -22,6 +22,23 @@ SET time_zone = "+00:00";
-- --------------------------------------------------------
--
-- Table structure for table `antispam`
--
CREATE TABLE IF NOT EXISTS `antispam` (
`board` varchar(255) NOT NULL,
`thread` int(11) DEFAULT NULL,
`hash` bigint(20) NOT NULL,
`created` int(11) NOT NULL,
`expires` int(11) DEFAULT NULL,
`passed` smallint(6) NOT NULL,
PRIMARY KEY (`hash`),
KEY `board` (`board`,`thread`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `bans`
--
@ -33,10 +50,10 @@ CREATE TABLE IF NOT EXISTS `bans` (
`set` int(11) NOT NULL,
`expires` int(11) DEFAULT NULL,
`reason` text,
`board` smallint(6) DEFAULT NULL,
`board` varchar(120) DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
@ -45,20 +62,33 @@ CREATE TABLE IF NOT EXISTS `bans` (
--
CREATE TABLE IF NOT EXISTS `boards` (
`id` smallint(6) NOT NULL AUTO_INCREMENT,
`uri` varchar(50) NOT NULL,
`title` TINYTEXT NOT NULL,
`subtitle` TINYTEXT DEFAULT NULL,
PRIMARY KEY (`uri`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
`uri` varchar(120) NOT NULL,
`title` tinytext NOT NULL,
`subtitle` tinytext,
PRIMARY KEY (`uri`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `boards`
--
INSERT INTO `boards` (`id`, `uri`, `title`, `subtitle`) VALUES
(1, 'b', 'Beta', 'In development.');
INSERT INTO `boards` (`uri`, `title`, `subtitle`) VALUES
('b', 'Beta', 'In development.');
-- --------------------------------------------------------
--
-- Table structure for table `cites`
--
CREATE TABLE IF NOT EXISTS `cites` (
`board` varchar(8) NOT NULL,
`post` int(11) NOT NULL,
`target_board` varchar(8) NOT NULL,
`target` int(11) NOT NULL,
KEY `target` (`target_board`,`target`),
KEY `post` (`board`,`post`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@ -85,7 +115,7 @@ CREATE TABLE IF NOT EXISTS `ip_notes` (
CREATE TABLE IF NOT EXISTS `modlogs` (
`mod` int(11) NOT NULL,
`ip` varchar(45) NOT NULL,
`board` int(11) DEFAULT NULL,
`board` varchar(120) DEFAULT NULL,
`time` int(11) NOT NULL,
`text` text NOT NULL,
KEY `time` (`time`)
@ -183,7 +213,7 @@ CREATE TABLE IF NOT EXISTS `reports` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time` int(11) NOT NULL,
`ip` varchar(45) NOT NULL,
`board` smallint(6) NOT NULL,
`board` varchar(120) DEFAULT NULL,
`post` int(11) NOT NULL,
`reason` text NOT NULL,
PRIMARY KEY (`id`)
@ -213,39 +243,6 @@ CREATE TABLE IF NOT EXISTS `theme_settings` (
KEY `theme` (`theme`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `cites`
--
CREATE TABLE IF NOT EXISTS `cites` (
`board` varchar(8) NOT NULL,
`post` int(11) NOT NULL,
`target_board` varchar(8) NOT NULL,
`target` int(11) NOT NULL,
KEY `target` (`target_board`,`target`),
KEY `post` (`board`,`post`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `antispam`
--
CREATE TABLE IF NOT EXISTS `antispam` (
`board` varchar(255) NOT NULL,
`thread` int(11) DEFAULT NULL,
`hash` bigint(20) NOT NULL,
`created` int(11) NOT NULL,
`expires` int(11) DEFAULT NULL,
`passed` smallint(6) NOT NULL,
PRIMARY KEY (`hash`),
KEY `board` (`board`,`thread`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

52
mod.php
View File

@ -1541,20 +1541,21 @@ if(!$mod) {
$body = '';
$reports = 0;
$query = prepare("SELECT `reports`.*, `boards`.`uri` FROM `reports` INNER JOIN `boards` ON `board` = `boards`.`id` ORDER BY `time` DESC LIMIT :limit");
$query = prepare("SELECT * FROM `reports` ORDER BY `time` DESC LIMIT :limit");
$query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
while($report = $query->fetch()) {
$p_query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `id` = :id", $report['uri']));
$p_query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `id` = :id", $report['board']));
$p_query->bindValue(':id', $report['post'], PDO::PARAM_INT);
$p_query->execute() or error(db_error($query));
$p_query->execute() or error(db_error($p_query));
if(!$post = $p_query->fetch()) {
// Invalid report (post has since been deleted)
$p_query = prepare("DELETE FROM `reports` WHERE `post` = :id");
$p_query = prepare("DELETE FROM `reports` WHERE `post` = :id AND `board` = :board");
$p_query->bindValue(':id', $report['post'], PDO::PARAM_INT);
$p_query->execute() or error(db_error($query));
$p_query->bindValue(':board', $report['board']);
$p_query->execute() or error(db_error($p_query));
continue;
}
@ -1646,7 +1647,7 @@ if(!$mod) {
// Redirect
header('Location: ?/reports', true, $config['redirect_http']);
} elseif(preg_match('/^\/board\/(\w+)(\/delete)?$/', $query, $matches)) {
} elseif(preg_match('/^\/(\w+)\/edit(\/delete)?$/', $query, $matches)) {
if(!hasPermission($config['mod']['manageboards'])) error($config['error']['noaccess']);
if(!openBoard($matches[1]))
@ -1666,12 +1667,12 @@ if(!$mod) {
// Clear reports
$query = prepare("DELETE FROM `reports` WHERE `board` = :id");
$query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->bindValue(':id', $board['uri'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
// Delete from table
$query = prepare("DELETE FROM `boards` WHERE `id` = :id");
$query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query = prepare("DELETE FROM `boards` WHERE `uri` = :uri");
$query->bindValue(':uri', $board['uri'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
if($config['cache']['enabled']) {
@ -1711,7 +1712,7 @@ if(!$mod) {
header('Location: ?/', true, $config['redirect_http']);
} else {
if(isset($_POST['title']) && isset($_POST['subtitle'])) {
$query = prepare("UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `id` = :id");
$query = prepare("UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri");
$query->bindValue(':title', utf8tohtml($_POST['title'], true));
if(!empty($_POST['subtitle']))
@ -1719,7 +1720,7 @@ if(!$mod) {
else
$query->bindValue(':subtitle', null, PDO::PARAM_NULL);
$query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->bindValue(':id', $board['uri'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
if($config['cache']['enabled']) {
@ -1761,7 +1762,7 @@ if(!$mod) {
// Delete button
(hasPermission($config['mod']['deleteboard']) ?
'<p style="text-align:center"><a href="?/board/' . $board['uri'] . '/delete">Delete board</a></p>'
'<p style="text-align:center"><a href="?/' . $board['uri'] . '/edit/delete">Delete board</a></p>'
:'') .
'</fieldset>';
@ -1786,12 +1787,12 @@ if(!$mod) {
}
}
if(hasPermission($config['mod']['view_banexpired'])) {
$query = prepare("SELECT `bans`.*, `username`, `uri` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY (`expires` IS NOT NULL AND `expires` < :time), `set` DESC");
$query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY (`expires` IS NOT NULL AND `expires` < :time), `set` DESC");
$query->bindValue(':time', time(), PDO::PARAM_INT);
$query->execute() or error(db_error($query));
} else {
// Filter out expired bans
$query = prepare("SELECT `bans`.*, `username`, `uri` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC");
$query = prepare("SELECT `bans`.*, `username` FROM `bans` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC");
$query->bindValue(':time', time(), PDO::PARAM_INT);
$query->execute() or error(db_error($query));
}
@ -1829,8 +1830,8 @@ if(!$mod) {
'<td style="white-space: nowrap">' .
(isset($ban['uri']) ?
sprintf($config['board_abbreviation'], $ban['uri'])
(isset($ban['board']) ?
sprintf($config['board_abbreviation'], $ban['board'])
:
'<em>' . _('all boards') . '</em>'
) . '</td>' .
@ -2152,7 +2153,7 @@ if(!$mod) {
error(sprintf($config['error']['boardexists'], sprintf($config['board_abbreviation'], $b['uri'])));
}
$query = prepare("INSERT INTO `boards` VALUES (NULL, :uri, :title, :subtitle)");
$query = prepare("INSERT INTO `boards` VALUES (:uri, :title, :subtitle)");
$query->bindValue(':uri', $b['uri']);
$query->bindValue(':title', $b['title']);
if(!empty($b['subtitle'])) {
@ -2179,7 +2180,7 @@ if(!$mod) {
rebuildThemes('boards');
header('Location: ?/board/' . $b['uri'], true, $config['redirect_http']);
header('Location: ?/' . $b['uri'] . '/' . $config['file_index'], true, $config['redirect_http']);
} else {
$body .= form_newBoard();
@ -2536,8 +2537,7 @@ if(!$mod) {
if(isset($_POST['new_ban'])) {
if( !isset($_POST['ip']) ||
!isset($_POST['reason']) ||
!isset($_POST['length']) ||
!isset($_POST['board_id'])
!isset($_POST['length'])
) error($config['error']['missedafield']);
// Check required fields
@ -2600,10 +2600,10 @@ if(!$mod) {
$query->bindValue(':reason', null, PDO::PARAM_NULL);
}
if($_POST['board_id'] < 0) {
if($_POST['board'] == '') {
$query->bindValue(':board', null, PDO::PARAM_NULL);
} else {
$query->bindValue(':board', (int)$_POST['board_id'], PDO::PARAM_INT);
$query->bindValue(':board', $_POST['board'], PDO::PARAM_INT);
}
// Record the action
@ -3036,7 +3036,7 @@ if(!$mod) {
}
if(hasPermission($config['mod']['view_ban'])) {
$query = prepare("SELECT `bans`.*, `username`, `uri` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
$query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
@ -3060,11 +3060,7 @@ if(!$mod) {
// Board
'<tr><th>Board</th><td>' .
(isset($ban['board']) ?
(isset($ban['uri']) ?
sprintf($config['board_abbreviation'], $ban['uri'])
:
'<em>deleted?</em>'
)
sprintf($config['board_abbreviation'], $ban['board'])
:
'<em>' . _('all boards') . '</em>'
) .

View File

@ -126,7 +126,7 @@ if(isset($_POST['delete'])) {
$query = prepare("INSERT INTO `reports` VALUES (NULL, :time, :ip, :board, :post, :reason)");
$query->bindValue(':time', time(), PDO::PARAM_INT);
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
$query->bindValue(':board', $board['id'], PDO::PARAM_INT);
$query->bindValue(':board', $board['uri'], PDO::PARAM_INT);
$query->bindValue(':post', $id, PDO::PARAM_INT);
$query->bindValue(':reason', $reason, PDO::PARAM_STR);
$query->execute() or error(db_error($query));

View File

@ -4,8 +4,8 @@
<h2>{% trans %}You are banned! ;_;{% endtrans %}</h2>
<p>
{% trans %}You have been banned from{% endtrans %}
{% if ban.uri %}
<strong>{{ config.board_abbreviation|sprintf(ban.uri) }}</strong>
{% if ban.board %}
<strong>{{ config.board_abbreviation|sprintf(ban.board) }}</strong>
{% else %}
{% trans %}all boards{% endtrans %}
{% endif %}