From 0cb54b15dc097cc27d6ba6dd2645e856bfda6df5 Mon Sep 17 00:00:00 2001 From: K Date: Tue, 2 Jul 2013 19:52:29 +0200 Subject: Add support for 4chan-compatible json API. Conflicts: inc/functions.php --- inc/functions.php | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index d5348f0d..cedf5534 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -13,6 +13,7 @@ require_once 'inc/display.php'; require_once 'inc/template.php'; require_once 'inc/database.php'; require_once 'inc/events.php'; +require_once 'inc/api.php'; require_once 'inc/lib/gettext/gettext.inc'; // the user is not currently logged in as a moderator @@ -1047,6 +1048,9 @@ function index($page, $mod=false) { if ($query->rowCount() < 1 && $page > 1) return false; + + $threads = array(); + while ($th = $query->fetch(PDO::FETCH_ASSOC)) { $thread = new Thread($th, $mod ? '?/' : $config['root'], $mod); @@ -1087,7 +1091,8 @@ function index($page, $mod=false) { $thread->omitted = $omitted['post_count'] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']); $thread->omitted_images = $omitted['image_count'] - $num_images; } - + + $threads[] = $thread; $body .= $thread->build(true); } @@ -1096,7 +1101,8 @@ function index($page, $mod=false) { 'body' => $body, 'post_url' => $config['post_url'], 'config' => $config, - 'boardlist' => createBoardlist($mod) + 'boardlist' => createBoardlist($mod), + 'threads' => $threads ); } @@ -1289,10 +1295,14 @@ function buildIndex() { if (!$config['try_smarter']) $antibot = create_antibot($board['uri']); + $api = new Api(); + $catalog = array(); + for ($page = 1; $page <= $config['max_pages']; $page++) { $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); - if ($config['try_smarter'] && isset($build_pages) && count($build_pages) && !in_array($page, $build_pages) && is_file($filename)) + if ($config['try_smarter'] && isset($build_pages) && count($build_pages) + && !in_array($page, $build_pages) && is_file($filename)) continue; $content = index($page); if (!$content) @@ -1309,13 +1319,30 @@ function buildIndex() { $content['antibot'] = $antibot; file_write($filename, Element('index.html', $content)); + + // json api + $threads = $content['threads']; + $json = json_encode($api->translatePage($threads)); + $jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0 + file_write($jsonFilename, $json); + + $catalog[$page-1] = $threads; } + if ($page < $config['max_pages']) { for (;$page<=$config['max_pages'];$page++) { $filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page)); file_unlink($filename); + + $jsonFilename = $board['dir'] . ($page-1) . ".json"; + file_unlink($jsonFilename); } } + + // json api catalog + $json = json_encode($api->translateCatalog($catalog)); + $jsonFilename = $board['dir'] . "catalog.json"; + file_write($jsonFilename, $json); } function buildJavascript() { @@ -1735,6 +1762,12 @@ function buildThread($id, $return = false, $mod = false) { return $body; file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); + + // json api + $api = new Api(); + $json = json_encode($api->translateThread($thread)); + $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; + file_write($jsonFilename, $json); } function rrmdir($dir) { -- cgit v1.3 From 01e906b1d37858168d4e8b2b7faa114fd4b9f63e Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 16:53:05 +0000 Subject: Make it possible to disable API, disable it by default Conflicts: inc/functions.php --- inc/config.php | 9 ++++ inc/functions.php | 129 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 123 insertions(+), 15 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index ae45a746..886d7183 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1285,6 +1285,15 @@ // return 'Sorry, you cannot post that!'; // }); +/* + * ============= + * API settings + * ============= + */ + + // Whether or not to use the API, disabled by default. + $config['api']['enabled'] = false; + /* * ==================== * Other/uncategorized diff --git a/inc/functions.php b/inc/functions.php index cedf5534..98cf9d77 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1295,9 +1295,11 @@ function buildIndex() { if (!$config['try_smarter']) $antibot = create_antibot($board['uri']); - $api = new Api(); - $catalog = array(); - + if ($config['api']['enabled']) { + $api = new Api(); + $catalog = array(); + } + for ($page = 1; $page <= $config['max_pages']; $page++) { $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); @@ -1321,12 +1323,14 @@ function buildIndex() { file_write($filename, Element('index.html', $content)); // json api - $threads = $content['threads']; - $json = json_encode($api->translatePage($threads)); - $jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0 - file_write($jsonFilename, $json); + if ($config['api']['enabled']) { + $threads = $content['threads']; + $json = json_encode($api->translatePage($threads)); + $jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0 + file_write($jsonFilename, $json); - $catalog[$page-1] = $threads; + $catalog[$page-1] = $threads; + } } if ($page < $config['max_pages']) { @@ -1340,9 +1344,11 @@ function buildIndex() { } // json api catalog - $json = json_encode($api->translateCatalog($catalog)); - $jsonFilename = $board['dir'] . "catalog.json"; - file_write($jsonFilename, $json); + if ($config['api']['enabled']) { + $json = json_encode($api->translateCatalog($catalog)); + $jsonFilename = $board['dir'] . "catalog.json"; + file_write($jsonFilename, $json); + } } function buildJavascript() { @@ -1764,10 +1770,103 @@ function buildThread($id, $return = false, $mod = false) { file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); // json api - $api = new Api(); - $json = json_encode($api->translateThread($thread)); - $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; - file_write($jsonFilename, $json); + if ($config['api']['enabled']) { + $api = new Api(); + $json = json_encode($api->translateThread($thread)); + $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; + file_write($jsonFilename, $json); + } + + if ($return) { + return $body; + } else { + $noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id); + if ($hasnoko50 || file_exists($noko50fn)) { + buildThread50($id, $return, $mod, $thread); + } + + file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); + } +} + +function buildThread50($id, $return = false, $mod = false, $thread = null) { + global $board, $config, $build_pages; + $id = round($id); + + if (event('build-thread', $id)) + return; + + if (!$thread) { + $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id` DESC LIMIT :limit", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->bindValue(':limit', $config['noko50_count']+1, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $num_images = 0; + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + if (!isset($thread)) { + $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); + } else { + if ($post['file']) + $num_images++; + + $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); + } + } + + // Check if any posts were found + if (!isset($thread)) + error($config['error']['nonexistant']); + + + if ($query->rowCount() == $config['noko50_count']+1) { + $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri'])); + $count->bindValue(':thread', $id, PDO::PARAM_INT); + $count->execute() or error(db_error($count)); + + $c = $count->fetch(); + $thread->omitted = $c['num'] - $config['noko50_count']; + + $c = $count->fetch(); + $thread->omitted_images = $c['num'] - $num_images; + } + + $thread->posts = array_reverse($thread->posts); + } else { + $allPosts = $thread->posts; + + $thread->posts = array_slice($allPosts, -$config['noko50_count']); + $thread->omitted += count($allPosts) - count($thread->posts); + foreach ($allPosts as $index => $post) { + if ($index == count($allPosts)-count($thread->posts)) + break; + if ($post->file) + $thread->omitted_images++; + } + } + + $hasnoko50 = $thread->postCount() >= $config['noko50_min']; + + $body = Element('thread.html', array( + 'board' => $board, + 'thread' => $thread, + 'body' => $thread->build(false, true), + 'config' => $config, + 'id' => $id, + 'mod' => $mod, + 'hasnoko50' => $hasnoko50, + 'isnoko50' => true, + 'antibot' => $mod ? false : create_antibot($board['uri'], $id), + 'boardlist' => createBoardlist($mod), + 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) + )); + + if ($return) { + return $body; + } else { + file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body); + } +>>>>>>> a29a932... Make it possible to disable API, disable it by default } function rrmdir($dir) { -- cgit v1.3 From ecda099dfb73f9e967a33ce96e45dc7ba1217bf6 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 18:17:05 +0000 Subject: Custom fields in API, read config.php for info. Non-4chan compatible fields removed. --- inc/api.php | 67 +++++++++++++++++++++++++------------------------------ inc/config.php | 6 +++++ inc/functions.php | 4 ++-- 3 files changed, 39 insertions(+), 38 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/api.php b/inc/api.php index 5592d8af..2bf6b7b8 100644 --- a/inc/api.php +++ b/inc/api.php @@ -1,5 +1,4 @@ postFields = array( + 'id' => 'no', + 'thread' => 'resto', + 'subject' => 'sub', + 'body' => 'com', + 'email' => 'email', + 'name' => 'name', + 'trip' => 'trip', + 'capcode' => 'capcode', + 'time' => 'time', + 'thumbx' => 'tn_w', + 'thumby' => 'tn_h', + 'filex' => 'w', + 'filey' => 'h', + 'filesize' => 'fsize', + 'filename' => 'filename', + 'omitted' => 'omitted_posts', + 'omitted_images' => 'omitted_images', + 'sticky' => 'sticky', + 'locked' => 'locked', + ); - /** - * Translation from local fields to fields in 4chan-style API - */ - public static $postFields = array( - 'id' => 'no', - 'thread' => 'resto', - 'subject' => 'sub', - 'email' => 'email', - 'name' => 'name', - 'trip' => 'trip', - 'capcode' => 'capcode', - 'body' => 'com', - 'time' => 'time', - 'thumb' => 'thumb', // non-compatible field - 'thumbx' => 'tn_w', - 'thumby' => 'tn_h', - 'file' => 'file', // non-compatible field - 'filex' => 'w', - 'filey' => 'h', - 'filesize' => 'fsize', - //'filename' => 'filename', - 'omitted' => 'omitted_posts', - 'omitted_images' => 'omitted_images', - //'posts' => 'replies', - //'ip' => '', - 'sticky' => 'sticky', - 'locked' => 'locked', - //'bumplocked' => '', - //'embed' => '', - //'root' => '', - //'mod' => '', - //'hr' => '', - ); + if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){ + $this->postFields = array_merge($this->postFields, $config['api']['extra_fields']); + } + } - static $ints = array( + private static $ints = array( 'no' => 1, 'resto' => 1, 'time' => 1, @@ -60,7 +55,7 @@ class Api { private function translatePost($post) { $apiPost = array(); - foreach (self::$postFields as $local => $translated) { + foreach ($this->postFields as $local => $translated) { if (!isset($post->$local)) continue; diff --git a/inc/config.php b/inc/config.php index 886d7183..750782bc 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1294,6 +1294,12 @@ // Whether or not to use the API, disabled by default. $config['api']['enabled'] = false; + // Extra fields in to be shown in the array that are not 4chan API compatible. + // You canget these by taking a look at the schema for posts_ tables. The array should be formatted as $db_name => $translated_name. + // For example: + + // $config['api']['extra_fields'] = array('body_nomarkup'=>'com_nomarkup'); + /* * ==================== * Other/uncategorized diff --git a/inc/functions.php b/inc/functions.php index 98cf9d77..aa92d0ef 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1296,7 +1296,7 @@ function buildIndex() { $antibot = create_antibot($board['uri']); if ($config['api']['enabled']) { - $api = new Api(); + $api = new Api($config); $catalog = array(); } @@ -1771,7 +1771,7 @@ function buildThread($id, $return = false, $mod = false) { // json api if ($config['api']['enabled']) { - $api = new Api(); + $api = new Api($config); $json = json_encode($api->translateThread($thread)); $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; file_write($jsonFilename, $json); -- cgit v1.3 From ed142a5e5d47b4e41ebb35ec51d50eba98a3d44b Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 21:35:16 +0000 Subject: ;_; --- inc/api.php | 3 ++- inc/functions.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/api.php b/inc/api.php index 5e4cc88a..9cad8ba0 100644 --- a/inc/api.php +++ b/inc/api.php @@ -8,7 +8,8 @@ * Class for generating json API compatible with 4chan API */ class Api { - function __construct($config){ + function __construct(){ + global $config; /** * Translation from local fields to fields in 4chan-style API */ diff --git a/inc/functions.php b/inc/functions.php index aa92d0ef..98cf9d77 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1296,7 +1296,7 @@ function buildIndex() { $antibot = create_antibot($board['uri']); if ($config['api']['enabled']) { - $api = new Api($config); + $api = new Api(); $catalog = array(); } @@ -1771,7 +1771,7 @@ function buildThread($id, $return = false, $mod = false) { // json api if ($config['api']['enabled']) { - $api = new Api($config); + $api = new Api(); $json = json_encode($api->translateThread($thread)); $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; file_write($jsonFilename, $json); -- cgit v1.3 From cbfafeea3636e222feb73cf42c24fec16bff71bd Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 21 Aug 2013 22:36:48 +1000 Subject: merge fail --- inc/functions.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 98cf9d77..76865882 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1866,7 +1866,6 @@ function buildThread50($id, $return = false, $mod = false, $thread = null) { } else { file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body); } ->>>>>>> a29a932... Make it possible to disable API, disable it by default } function rrmdir($dir) { -- cgit v1.3 From a83715dcb0c6f9bdb82f037b385f09870638963c Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 21 Aug 2013 22:43:35 +1000 Subject: single quotation marks please --- inc/functions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 76865882..c34adbcc 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1326,7 +1326,7 @@ function buildIndex() { if ($config['api']['enabled']) { $threads = $content['threads']; $json = json_encode($api->translatePage($threads)); - $jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0 + $jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0 file_write($jsonFilename, $json); $catalog[$page-1] = $threads; @@ -1338,7 +1338,7 @@ function buildIndex() { $filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page)); file_unlink($filename); - $jsonFilename = $board['dir'] . ($page-1) . ".json"; + $jsonFilename = $board['dir'] . ($page - 1) . '.json'; file_unlink($jsonFilename); } } @@ -1346,7 +1346,7 @@ function buildIndex() { // json api catalog if ($config['api']['enabled']) { $json = json_encode($api->translateCatalog($catalog)); - $jsonFilename = $board['dir'] . "catalog.json"; + $jsonFilename = $board['dir'] . 'catalog.json'; file_write($jsonFilename, $json); } } @@ -1773,7 +1773,7 @@ function buildThread($id, $return = false, $mod = false) { if ($config['api']['enabled']) { $api = new Api(); $json = json_encode($api->translateThread($thread)); - $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; + $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; file_write($jsonFilename, $json); } -- cgit v1.3 From 11fa73e4d11777ce6cc808c278d5c8ca2175b392 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 21 Aug 2013 22:44:23 +1000 Subject: automatically initialize $config['api'] --- inc/functions.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index c34adbcc..9ea6aa9a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -35,6 +35,7 @@ function loadConfig() { $arrays = array( 'db', + 'api', 'cache', 'cookies', 'error', -- cgit v1.3 From d92b13876216064317ed28efa60a5a525a40a646 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 21 Aug 2013 22:53:48 +1000 Subject: Accidentally merged noko50 stuff --- inc/functions.php | 86 +------------------------------------------------------ 1 file changed, 1 insertion(+), 85 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 9ea6aa9a..afebd5d8 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1781,95 +1781,11 @@ function buildThread($id, $return = false, $mod = false) { if ($return) { return $body; } else { - $noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id); - if ($hasnoko50 || file_exists($noko50fn)) { - buildThread50($id, $return, $mod, $thread); - } - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); } } -function buildThread50($id, $return = false, $mod = false, $thread = null) { - global $board, $config, $build_pages; - $id = round($id); - - if (event('build-thread', $id)) - return; - - if (!$thread) { - $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id` DESC LIMIT :limit", $board['uri'])); - $query->bindValue(':id', $id, PDO::PARAM_INT); - $query->bindValue(':limit', $config['noko50_count']+1, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); - - $num_images = 0; - while ($post = $query->fetch(PDO::FETCH_ASSOC)) { - if (!isset($thread)) { - $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); - } else { - if ($post['file']) - $num_images++; - - $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); - } - } - - // Check if any posts were found - if (!isset($thread)) - error($config['error']['nonexistant']); - - - if ($query->rowCount() == $config['noko50_count']+1) { - $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri'])); - $count->bindValue(':thread', $id, PDO::PARAM_INT); - $count->execute() or error(db_error($count)); - - $c = $count->fetch(); - $thread->omitted = $c['num'] - $config['noko50_count']; - - $c = $count->fetch(); - $thread->omitted_images = $c['num'] - $num_images; - } - - $thread->posts = array_reverse($thread->posts); - } else { - $allPosts = $thread->posts; - - $thread->posts = array_slice($allPosts, -$config['noko50_count']); - $thread->omitted += count($allPosts) - count($thread->posts); - foreach ($allPosts as $index => $post) { - if ($index == count($allPosts)-count($thread->posts)) - break; - if ($post->file) - $thread->omitted_images++; - } - } - - $hasnoko50 = $thread->postCount() >= $config['noko50_min']; - - $body = Element('thread.html', array( - 'board' => $board, - 'thread' => $thread, - 'body' => $thread->build(false, true), - 'config' => $config, - 'id' => $id, - 'mod' => $mod, - 'hasnoko50' => $hasnoko50, - 'isnoko50' => true, - 'antibot' => $mod ? false : create_antibot($board['uri'], $id), - 'boardlist' => createBoardlist($mod), - 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) - )); - - if ($return) { - return $body; - } else { - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body); - } -} - - function rrmdir($dir) { +function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { -- cgit v1.3 From a7ac3339def8d07d825d64f33e8ca69c21dd2743 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 28 Aug 2013 17:00:41 +1000 Subject: DNS(): Cache NXDOMAIN --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index afebd5d8..6ce0b29e 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1940,7 +1940,7 @@ function DNS($host) { global $config; if ($config['cache']['enabled'] && ($ip_addr = cache::get('dns_' . $host))) { - return $ip_addr; + return $ip_addr != '?' ? $ip_addr : false; } if (!$config['dns_system']) { @@ -1956,7 +1956,7 @@ function DNS($host) { } if ($config['cache']['enabled']) - cache::set('dns_' . $host, $ip_addr, 3600); + cache::set('dns_' . $host, $ip_addr !== false ? $ip_addr : '?', 3600); return $ip_addr; } -- cgit v1.3 From 7a4e481333c3ab39ea63c2d961a7c05016b12460 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 28 Aug 2013 22:30:56 +1000 Subject: Huge bugfix: Old tracked cites where not being purged correctly. Recommend query: "TRUNCATE TABLE `cites`;" to start over --- inc/functions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 6ce0b29e..e2289ef1 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -997,9 +997,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { 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 = prepare("DELETE FROM ``cites`` WHERE (`target_board` = :board AND `target` = (" . implode(' OR `target` = ', $ids) . ")) OR (`board` = :board AND (`post` = " . implode(' OR `post` = ', $ids) . "))"); $query->bindValue(':board', $board['uri']); - $query->bindValue(':id', $id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); if (isset($rebuild) && $rebuild_after) { -- cgit v1.3