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 +++++++++ 1 file changed, 9 insertions(+) (limited to 'inc/config.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 -- 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/config.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 b01a402d23a1e7dd94ef2b9980a055c07d332f9d Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 21 Aug 2013 22:41:42 +1000 Subject: 4chan-compatible api: better config.php comments --- inc/config.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 750782bc..b6c510a7 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1291,14 +1291,14 @@ * ============= */ - // Whether or not to use the API, disabled by default. + // Whether or not to enable the 4chan-compatible API, disabled by default. See + // https://github.com/4chan/4chan-API for API specification. $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'); + // Extra fields in to be shown in the array that are not in the 4chan-API. You can get these by taking a + // look at the schema for posts_ tables. The array should be formatted as $db_column => $translated_name. + // Example: Adding the pre-markup post body to the API as "com_nomarkup". + // $config['api']['extra_fields'] = array('body_nomarkup' => 'com_nomarkup'); /* * ==================== -- cgit v1.3 From c31e374a71a5109b136327b89b51a34f9bf8809f Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Wed, 28 Aug 2013 20:09:30 +1000 Subject: Allow Unix sockets for database connection --- inc/config.php | 8 +++++--- inc/database.php | 12 ++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index b6c510a7..5d572010 100644 --- a/inc/config.php +++ b/inc/config.php @@ -77,16 +77,18 @@ // Database driver (http://www.php.net/manual/en/pdo.drivers.php) // Only MySQL is supported by Tinyboard at the moment, sorry. $config['db']['type'] = 'mysql'; - // Hostname or IP address + // Hostname, IP address or Unix socket (prefixed with ":") $config['db']['server'] = 'localhost'; + // Example: Unix socket + // $config['db']['server'] = ':/tmp/mysql.sock'; // Login $config['db']['user'] = ''; $config['db']['password'] = ''; // Tinyboard database $config['db']['database'] = ''; - // Table prefix + // Table prefix (optional) $config['db']['prefix'] = ''; - // Use a persistent connection (experimental) + // Use a persistent connection (experimental; benefits unknown) $config['db']['persistent'] = false; // Anything more to add to the DSN string (eg. port=xxx;foo=bar) $config['db']['dsn'] = ''; diff --git a/inc/database.php b/inc/database.php index 24959d0c..8daa20b4 100644 --- a/inc/database.php +++ b/inc/database.php @@ -43,9 +43,17 @@ class PreparedQueryDebug { function sql_open() { global $pdo, $config; - if ($pdo) return true; + if ($pdo) + return true; - $dsn = $config['db']['type'] . ':host=' . $config['db']['server'] . ';dbname=' . $config['db']['database']; + if (isset($config['db']['server'][0]) && $config['db']['server'][0] == ':') + $unix_socket = substr($config['db']['server'], 1); + else + $unix_socket = false; + + $dsn = $config['db']['type'] . ':' . + ($unix_socket ? 'unix_socket=' . $unix_socket : 'host=' . $config['db']['server']) . + ';dbname=' . $config['db']['database']; if (!empty($config['db']['dsn'])) $dsn .= ';' . $config['db']['dsn']; try { -- cgit v1.3