Browse Source

Wordfilters

pull/40/head
Savetheinternet 13 years ago
parent
commit
638589d254
  1. 11
      inc/config.php
  2. 87
      inc/functions.php
  3. 2
      post.php

11
inc/config.php

@ -20,7 +20,8 @@
'dir' => Array(), 'dir' => Array(),
'mod' => Array(), 'mod' => Array(),
'spam' => Array(), 'spam' => Array(),
'flood_filters' => Array() 'flood_filters' => Array(),
'wordfilters' => Array()
); );
// Database stuff // Database stuff
@ -447,6 +448,14 @@
// 'message' => 'Your post has been rejected on the suspicion of a flood attack on this board (too many new threads); post a reply instead.' // 'message' => 'Your post has been rejected on the suspicion of a flood attack on this board (too many new threads); post a reply instead.'
//); //);
// Wordfilters are used to automatically replace certain words/phrases with something else.
// For a normal string replacement:
// $config['wordfilters'][] = Array('cat', 'dog');
// Advanced raplcement (regular expressions):
// $config['wordfilters'][] = Array('/cat/', 'dog', true); // 'true' means it's a regular expression
// A small file in the main directory indicating that the script has been ran and the board(s) have been generated. // A small file in the main directory indicating that the script has been ran and the board(s) have been generated.
// This keeps the script from querying the database and causing strain when not needed. // This keeps the script from querying the database and causing strain when not needed.
$config['has_installed'] = '.installed'; $config['has_installed'] = '.installed';

87
inc/functions.php

@ -906,7 +906,19 @@
$ipoc = explode('.', $ip); $ipoc = explode('.', $ip);
return $ipoc[3] . '.' . $ipoc[2] . '.' . $ipoc[1] . '.' . $ipoc[0]; return $ipoc[3] . '.' . $ipoc[2] . '.' . $ipoc[1] . '.' . $ipoc[0];
} }
function wordfilters(&$body) {
global $config;
foreach($config['wordfilters'] as $filter) {
if(isset($filter[2]) && $filter[2]) {
$body = preg_replace($filter[0], $filter[1], $body);
} else {
$body = str_replace($filter[0], $filter[1], $body);
}
}
}
function markup(&$body) { function markup(&$body) {
global $board, $config; global $board, $config;
@ -938,43 +950,72 @@
} }
// Cites // Cites
if(isset($board) && preg_match_all('/(^|\s)>>([0-9]+?)(\s|$)/', $body, $cites)) { if(isset($board) && preg_match_all('/(^|\s)>>(\d+?)(\s|$)/', $body, $cites)) {
$previousPosition = 0; if(count($cites[0]) > $config['max_cites']) {
$temp = ''; error($config['error']['toomanycites']);
}
sql_open(); sql_open();
for($index=0;$index<count($cites[0]);$index++) { for($index=0;$index<count($cites[0]);$index++) {
$cite = $cites[2][$index]; $cite = $cites[2][$index];
$whitespace = Array(
strlen($cites[1][$index]),
strlen($cites[3][$index]),
);
$query = prepare(sprintf("SELECT `thread`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri'])); $query = prepare(sprintf("SELECT `thread`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri']));
$query->bindValue(':id', $cite); $query->bindValue(':id', $cite);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($post = $query->fetch()) { if($post = $query->fetch()) {
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' . $config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">&gt;&gt;' . $cite . '</a>'; $replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
} else { $config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' .
$replacement = "&gt;&gt;{$cite}"; '&gt;&gt;' . $cite .
'</a>';
$body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[3][$index], $body);
} }
}
// Find the position of the cite }
$position = strpos($body, $cites[0][$index]);
// Cross-board linking
if(preg_match_all('/(^|\s)&gt;&gt;&gt;\/(\w+?)\/(\d+)?(\s|$)/', $body, $cites)) {
if(count($cites[0]) > $config['max_cites']) {
error($config['error']['toomanycross']);
}
sql_open();
for($index=0;$index<count($cites[0]);$index++) {
$_board = $cites[2][$index];
$cite = @$cites[3][$index];
// Temporarily store board information because it will be overwritten
$tmp_board = $board['uri'];
// Check if the board exists, and load settings
if(openBoard($_board)) {
if($cite) {
$query = prepare(sprintf("SELECT `thread`,`id` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri']));
$query->bindValue(':id', $cite);
$query->execute() or error(db_error($query));
if($post = $query->fetch()) {
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' .
'&gt;&gt;&gt;/' . $_board . '/' . $cite .
'</a>';
$body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[4][$index], $body);
}
} else {
$replacement = '<a href="' .
$config['root'] . $board['dir'] . $config['file_index'] . '">' .
'&gt;&gt;&gt;/' . $_board . '/' .
'</a>';
$body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[4][$index], $body);
}
var_dump($post);
}
// Replace the found string with "xxxx[...]". (allows duplicate tags). Keeps whitespace. //var_dump($cite);
$body = substr_replace($body, str_repeat('x', strlen($cites[0][$index]) - $whitespace[0] - $whitespace[1]), $position + $whitespace[0], strlen($cites[0][$index]) - $whitespace[0] - $whitespace[1]); // exit;
$temp .= substr($body, $previousPosition, $position-$previousPosition) . $cites[1][$index] . $replacement . $cites[3][$index]; // Restore main board settings
$previousPosition = $position+strlen($cites[0][$index]); openBoard($tmp_board);
} }
// The rest
$temp .= substr($body, $previousPosition);
$body = $temp;
} }
$body = str_replace("\r", '', $body); $body = str_replace("\r", '', $body);

2
post.php

@ -294,6 +294,8 @@
if($post['mod_tag']) if($post['mod_tag'])
$post['trip'] .= ' <a class="nametag">## ' . $post['mod_tag'] . '</a>'; $post['trip'] .= ' <a class="nametag">## ' . $post['mod_tag'] . '</a>';
wordfilters($post['body']);
$post['body_nomarkup'] = $post['body']; $post['body_nomarkup'] = $post['body'];
if(!($mod && $post['raw'])) if(!($mod && $post['raw']))

Loading…
Cancel
Save