summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/config.php4
-rw-r--r--inc/functions.php65
-rw-r--r--install.php9
-rw-r--r--install.sql16
-rw-r--r--post.php11
-rw-r--r--templates/posts.sql1
6 files changed, 98 insertions, 8 deletions
diff --git a/inc/config.php b/inc/config.php
index 78a056d9..b619644d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -274,6 +274,10 @@
// Maximum number of cross-board links/cites per post
$config['max_cross'] = $config['max_cites'];
+ // Track post citations (>>XX). Rebuilds posts after a cited post is deleted, removing broken links.
+ // A little more database load.
+ $config['track_cites'] = true;
+
// Maximum filename length (will be truncated)
$config['max_filename_len'] = 255;
// Maximum filename length to display (the rest can be viewed upon mouseover)
diff --git a/inc/functions.php b/inc/functions.php
index 67a9a347..3ebd319b 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -564,7 +564,7 @@
function post($post, $OP) {
global $pdo, $board;
- $query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky, :locked, 0, :embed)", $board['uri']));
+ $query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky, :locked, 0, :embed)", $board['uri']));
// Basic stuff
if(!empty($post['subject'])) {
@@ -587,6 +587,7 @@
$query->bindValue(':name', $post['name']);
$query->bindValue(':body', $post['body']);
+ $query->bindValue(':body_nomarkup', $post['body_nomarkup']);
$query->bindValue(':time', isset($post['time']) ? $post['time'] : time(), PDO::PARAM_INT);
$query->bindValue(':password', $post['password']);
$query->bindValue(':ip', isset($post['ip']) ? $post['ip'] : $_SERVER['REMOTE_ADDR']);
@@ -697,6 +698,30 @@
buildThread($post['thread']);
}
+ // rebuild post (markup)
+ function rebuildPost($id) {
+ global $board;
+
+ $query = prepare(sprintf("SELECT `body_nomarkup` FROM `posts_%s` WHERE `id` = :id", $board['uri']));
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ if(!$post = $query->fetch())
+ return false;
+
+ if(!$post['body_nomarkup'])
+ return false;
+
+ markup($body = &$post['body_nomarkup']);
+
+ $query = prepare(sprintf("UPDATE `posts_%s` SET `body` = :body WHERE `id` = :id", $board['uri']));
+ $query->bindValue(':body', $body);
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ return true;
+ }
+
// Delete a post (reply or thread)
function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
global $board, $config;
@@ -735,6 +760,28 @@
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
+ $query = prepare("SELECT `board`, `post` FROM `cites` WHERE `target_board` = :board AND `target` = :id");
+ $query->bindValue(':board', $board['uri']);
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+ while($cite = $query->fetch()) {
+ var_dump($cite);
+ if($board['uri'] != $cite['board']) {
+ if(!isset($tmp_board))
+ $tmp_board = $board['uri'];
+ openBoard($cite['board']);
+ }
+ rebuildPost($cite['post']);
+ }
+
+ if(isset($tmp_board))
+ openBoard($tmp_board);
+
+ $query = prepare("DELETE FROM `cites` WHERE (`target_board` = :board AND `target` = :id) OR (`board` = :board AND `post` = :id)");
+ $query->bindValue(':board', $board['uri']);
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
if(isset($rebuild) && $rebuild_after) {
buildThread($rebuild);
}
@@ -1225,7 +1272,7 @@
return $body . "\n";
}
- function markup(&$body) {
+ function markup(&$body, $track_cites = false) {
global $board, $config;
$body = utf8tohtml($body);
@@ -1257,9 +1304,11 @@
// replace tabs with 8 spaces
$body = str_replace("\t", ' ', $body);
-
+
+ $tracked_cites = Array();
+
// Cites
- if(isset($board) && preg_match_all('/(^|\s)>>(\d+?)([\s,.?]|$)/', $body, $cites)) {
+ if(isset($board) && preg_match_all('/(^|\s)>>(\d+?)([\s,.?]|$)/', $body, $cites)) {
if(count($cites[0]) > $config['max_cites']) {
error($config['error']['toomanycites']);
}
@@ -1276,6 +1325,9 @@
'>>' . $cite .
'</a>';
$body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[3][$index], $body);
+
+ if($track_cites && $config['track_cites'])
+ $tracked_cites[] = Array($board['uri'], $post['id']);
}
}
}
@@ -1306,6 +1358,9 @@
'&gt;&gt;&gt;/' . $_board . '/' . $cite .
'</a>';
$body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[4][$index], $body);
+
+ if($track_cites && $config['track_cites'])
+ $tracked_cites[] = Array($board['uri'], $post['id']);
}
} else {
$replacement = '<a href="' .
@@ -1330,6 +1385,8 @@
$body = preg_replace('/\s+$/', '', $body);
$body = preg_replace("/\n/", '<br/>', $body);
+
+ return $tracked_cites;
}
function utf8tohtml($utf8) {
diff --git a/install.php b/install.php
index f68f1575..50c80301 100644
--- a/install.php
+++ b/install.php
@@ -1,6 +1,6 @@
<?php
// Installation/upgrade file
- define('VERSION', 'v0.9.5-dev-1');
+ define('VERSION', 'v0.9.5-dev-2');
require 'inc/functions.php';
require 'inc/display.php';
@@ -159,8 +159,11 @@
CHANGE `email` `email` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,
CHANGE `name` `name` VARCHAR( 35 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL", $board['uri'])) or error(db_error());
}
-
-
+ case 'v0.9.5-dev-1':
+ foreach($boards as &$board) {
+ query(sprintf("ALTER TABLE `posts_%s` ADD `body_nomarkup` TEXT NULL AFTER `body`", $board['uri'])) or error(db_error());
+ }
+ query("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;") or error(db_error());
case false:
// Update version number
file_write($config['has_installed'], VERSION);
diff --git a/install.sql b/install.sql
index 1d032114..de6cc0c8 100644
--- a/install.sql
+++ b/install.sql
@@ -188,6 +188,7 @@ CREATE TABLE IF NOT EXISTS `posts_b` (
`trip` varchar(15) DEFAULT NULL,
`capcode` varchar(50) DEFAULT NULL,
`body` text NOT NULL,
+ `body_nomarkup` text DEFAULT NULL,
`time` int(11) NOT NULL,
`bump` int(11) DEFAULT NULL,
`thumb` varchar(50) DEFAULT NULL,
@@ -251,6 +252,21 @@ 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;
+
/*!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 */;
diff --git a/post.php b/post.php
index 40d7aeb2..7bc6192b 100644
--- a/post.php
+++ b/post.php
@@ -334,7 +334,7 @@
$post['body_nomarkup'] = $post['body'];
if(!($mod && isset($post['raw']) && $post['raw']))
- markup($post['body']);
+ $post['tracked_cites'] = markup($post['body'], true);
// Check for a flood
if(!($mod && $mod['type'] >= $config['mod']['flood']) && checkFlood($post)) {
@@ -557,6 +557,15 @@
$id = post($post, $OP);
+ foreach($post['tracked_cites'] as $cite) {
+ $query = prepare('INSERT INTO `cites` VALUES (:board, :post, :target_board, :target)');
+ $query->bindValue(':board', $board['uri']);
+ $query->bindValue(':post', $id, PDO::PARAM_INT);
+ $query->bindValue(':target_board',$cite[0]);
+ $query->bindValue(':target', $cite[1], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+ }
+
buildThread(($OP?$id:$post['thread']));
if(!$OP && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || numPosts($post['thread']) < $config['reply_limit'])) {
diff --git a/templates/posts.sql b/templates/posts.sql
index 59df4705..ef8d403e 100644
--- a/templates/posts.sql
+++ b/templates/posts.sql
@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS `posts_{{ board }}` (
`trip` varchar(15) DEFAULT NULL,
`capcode` varchar(50) DEFAULT NULL,
`body` text NOT NULL,
+ `body_nomarkup` text DEFAULT NULL,
`time` int(11) NOT NULL,
`bump` int(11) DEFAULT NULL,
`thumb` varchar(50) DEFAULT NULL,