From ecda099dfb73f9e967a33ce96e45dc7ba1217bf6 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Tue, 20 Aug 2013 18:17:05 +0000 Subject: [PATCH] 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 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);