From 638589d254bdd3f2f6cd639ff47a6ca4fe03631d Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 6 Apr 2011 19:18:36 +1000 Subject: Wordfilters --- inc/functions.php | 87 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 23 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index ed8908cf..f54352e9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -906,7 +906,19 @@ $ipoc = explode('.', $ip); 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) { global $board, $config; @@ -938,43 +950,72 @@ } // Cites - if(isset($board) && preg_match_all('/(^|\s)>>([0-9]+?)(\s|$)/', $body, $cites)) { - $previousPosition = 0; - $temp = ''; + if(isset($board) && preg_match_all('/(^|\s)>>(\d+?)(\s|$)/', $body, $cites)) { + if(count($cites[0]) > $config['max_cites']) { + error($config['error']['toomanycites']); + } sql_open(); for($index=0;$indexbindValue(':id', $cite); $query->execute() or error(db_error($query)); if($post = $query->fetch()) { - $replacement = '>>' . $cite . ''; - } else { - $replacement = ">>{$cite}"; + $replacement = '' . + '>>' . $cite . + ''; + $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)>>>\/(\w+?)\/(\d+)?(\s|$)/', $body, $cites)) { + if(count($cites[0]) > $config['max_cites']) { + error($config['error']['toomanycross']); + } + sql_open(); + for($index=0;$indexbindValue(':id', $cite); + $query->execute() or error(db_error($query)); + + if($post = $query->fetch()) { + $replacement = '' . + '>>>/' . $_board . '/' . $cite . + ''; + $body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[4][$index], $body); + } + } else { + $replacement = '' . + '>>>/' . $_board . '/' . + ''; + $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. - $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]); + //var_dump($cite); + // exit; - $temp .= substr($body, $previousPosition, $position-$previousPosition) . $cites[1][$index] . $replacement . $cites[3][$index]; - $previousPosition = $position+strlen($cites[0][$index]); + // Restore main board settings + openBoard($tmp_board); } - - // The rest - $temp .= substr($body, $previousPosition); - - $body = $temp; } + $body = str_replace("\r", '', $body); -- cgit v1.3