From fd398f82ed7c055840930e8511684d99b7695b79 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Mon, 19 Aug 2013 13:20:10 +0000 Subject: [PATCH 1/9] Fix reply moving --- inc/mod/pages.php | 5 ++++- templates/mod/move_reply.html | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 templates/mod/move_reply.html diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 35713c27..6a9f07c7 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1059,10 +1059,13 @@ function mod_move_reply($originBoard, $postID) { } } + // build index buildIndex(); + // build new thread + buildThread($newID); // trigger themes - rebuildThemes($post['op'] ? 'post-thread' : 'post'); + rebuildThemes('post'); // mod log modLog("Moved post #${postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#${newID})", $originBoard); diff --git a/templates/mod/move_reply.html b/templates/mod/move_reply.html new file mode 100644 index 00000000..bf7c2f75 --- /dev/null +++ b/templates/mod/move_reply.html @@ -0,0 +1,41 @@ +
+ + + + + + + + + + + + + + +
+ {% trans 'Post ID' %} + + >>>{{ config.board_abbreviation|sprintf(board) }}{{ post }} +
{% trans 'Target board' %} +
    + {% for targetboard in boards %} +
  • + + +
  • + {% endfor %} +
+
+
{% trans 'Target thread' %} +

If you do not want to make the post into a new thread, please specify the thread you want to move the reply to:

+ +
+ + +
+ From a29a9324eaec81938869ceb66cb99b2deebb84b1 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 16:53:05 +0000 Subject: [PATCH 2/9] Make it possible to disable API, disable it by default --- inc/config.php | 9 +++++++++ inc/functions.php | 36 ++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/inc/config.php b/inc/config.php index ae3ce0c0..f7226614 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1342,6 +1342,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 a75ebb8a..a8dd1dda 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1299,8 +1299,10 @@ 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)); @@ -1324,12 +1326,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']) { for (;$page<=$config['max_pages'];$page++) { @@ -1342,9 +1346,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() { @@ -1765,10 +1771,12 @@ function buildThread($id, $return = false, $mod = false) { $build_pages[] = thread_find_page($id); // 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; From 3e9f4f101ab07ed69d202577821d9c3b0fb414f7 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 18:17:05 +0000 Subject: [PATCH 3/9] 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(-) 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 f7226614..956851f2 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1351,6 +1351,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 a8dd1dda..15007505 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1300,7 +1300,7 @@ function buildIndex() { $antibot = create_antibot($board['uri']); if ($config['api']['enabled']) { - $api = new Api(); + $api = new Api($config); $catalog = array(); } @@ -1772,7 +1772,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); From cc5173f4309c72fc8d0f52f70576302dbb998b1e Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 18:52:12 +0000 Subject: [PATCH 4/9] Country flags in API if they are enabled --- inc/api.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/inc/api.php b/inc/api.php index 2bf6b7b8..69a58a0c 100644 --- a/inc/api.php +++ b/inc/api.php @@ -3,6 +3,7 @@ * Copyright (c) 2010-2013 Tinyboard Development Group */ + /** * Class for generating json API compatible with 4chan API */ @@ -11,6 +12,8 @@ class Api { /** * Translation from local fields to fields in 4chan-style API */ + $this->config = $config; + $this->postFields = array( 'id' => 'no', 'thread' => 'resto', @@ -64,6 +67,7 @@ class Api { if ($val !== null && $val !== '') { $apiPost[$translated] = $toInt ? (int) $val : $val; } + } if (isset($post->filename)) { @@ -72,6 +76,18 @@ class Api { $apiPost['ext'] = substr($post->filename, $dotPos); } + // Handle country field + if (isset($post->body_nomarkup) && $this->config['country_flags']) { + $modifiers = extract_modifiers($post->body_nomarkup); + if (isset($modifiers['flag']) && isset($modifiers['flag alt'])) { + $country = mb_convert_case($modifiers['flag'], MB_CASE_UPPER); + if ($country) { + $apiPost['country'] = $country; + $apiPost['country_name'] = $modifiers['flag alt']; + } + } + } + return $apiPost; } From 8c081a4ab5eeccd2e0988c69a870eb0aac6b06e0 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 18:59:20 +0000 Subject: [PATCH 5/9] Oops, forgot to check if enabled at one point --- inc/functions.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 15007505..ae178a73 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1339,9 +1339,11 @@ function buildIndex() { 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); + + if ($config['api']['enabled']) { + $jsonFilename = $board['dir'] . ($page-1) . ".json"; + file_unlink($jsonFilename); + } } } From 8794fe0149c46038acde37d859bcfb0acdf6c1cd Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 19:53:11 +0000 Subject: [PATCH 6/9] Delete JSON when thread deleted --- inc/functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/functions.php b/inc/functions.php index ae178a73..02e2a932 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -959,6 +959,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { // Delete thread HTML page file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id'])); file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $post['id'])); + file_unlink($board['dir'] . $config['dir']['res'] . sprintf('%d.json', $post['id'])); $antispam_query = prepare('DELETE FROM ``antispam`` WHERE `board` = :board AND `thread` = :thread'); $antispam_query->bindValue(':board', $board['uri']); From 31aad827add4abfe6ece70a916967b9e09ec2511 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 21:31:46 +0000 Subject: [PATCH 7/9] Make file/thumb dimensons actually work (thanks sti) --- inc/api.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/api.php b/inc/api.php index 69a58a0c..5e4cc88a 100644 --- a/inc/api.php +++ b/inc/api.php @@ -24,10 +24,10 @@ class Api { 'trip' => 'trip', 'capcode' => 'capcode', 'time' => 'time', - 'thumbx' => 'tn_w', - 'thumby' => 'tn_h', - 'filex' => 'w', - 'filey' => 'h', + 'thumbheight' => 'tn_w', + 'thumbwidth' => 'tn_h', + 'fileheight' => 'w', + 'filewidth' => 'h', 'filesize' => 'fsize', 'filename' => 'filename', 'omitted' => 'omitted_posts', From c61760317976483bd0a4202f238703afd5e228d4 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 21:35:16 +0000 Subject: [PATCH 8/9] ;_; --- inc/api.php | 3 ++- inc/functions.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) 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 02e2a932..8de88ecf 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1301,7 +1301,7 @@ function buildIndex() { $antibot = create_antibot($board['uri']); if ($config['api']['enabled']) { - $api = new Api($config); + $api = new Api(); $catalog = array(); } @@ -1775,7 +1775,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); From 07bf8914e688486e0c9e879ed25cfa866f3efb59 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 22:11:32 +0000 Subject: [PATCH 9/9] Only add country to JSON if flag fits country code regex --- inc/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/api.php b/inc/api.php index 9cad8ba0..a8331590 100644 --- a/inc/api.php +++ b/inc/api.php @@ -80,8 +80,8 @@ class Api { // Handle country field if (isset($post->body_nomarkup) && $this->config['country_flags']) { $modifiers = extract_modifiers($post->body_nomarkup); - if (isset($modifiers['flag']) && isset($modifiers['flag alt'])) { - $country = mb_convert_case($modifiers['flag'], MB_CASE_UPPER); + if (isset($modifiers['flag']) && isset($modifiers['flag alt']) && preg_match('/^[a-z]{2}$/', $modifiers['flag'])) { + $country = strtoupper($modifiers['flag']); if ($country) { $apiPost['country'] = $country; $apiPost['country_name'] = $modifiers['flag alt'];