mirror of
https://github.com/Circlepuller/Tinyboard.git
synced 2025-01-17 21:39:27 +01:00
Custom fields in API, read config.php for info. Non-4chan compatible fields removed.
This commit is contained in:
parent
a29a9324ea
commit
3e9f4f101a
67
inc/api.php
67
inc/api.php
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2013 Tinyboard Development Group
|
* Copyright (c) 2010-2013 Tinyboard Development Group
|
||||||
*/
|
*/
|
||||||
@ -8,42 +7,38 @@
|
|||||||
* Class for generating json API compatible with 4chan API
|
* Class for generating json API compatible with 4chan API
|
||||||
*/
|
*/
|
||||||
class Api {
|
class Api {
|
||||||
|
function __construct($config){
|
||||||
|
/**
|
||||||
|
* Translation from local fields to fields in 4chan-style API
|
||||||
|
*/
|
||||||
|
$this->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',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){
|
||||||
* Translation from local fields to fields in 4chan-style API
|
$this->postFields = array_merge($this->postFields, $config['api']['extra_fields']);
|
||||||
*/
|
}
|
||||||
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' => '',
|
|
||||||
);
|
|
||||||
|
|
||||||
static $ints = array(
|
private static $ints = array(
|
||||||
'no' => 1,
|
'no' => 1,
|
||||||
'resto' => 1,
|
'resto' => 1,
|
||||||
'time' => 1,
|
'time' => 1,
|
||||||
@ -60,7 +55,7 @@ class Api {
|
|||||||
|
|
||||||
private function translatePost($post) {
|
private function translatePost($post) {
|
||||||
$apiPost = array();
|
$apiPost = array();
|
||||||
foreach (self::$postFields as $local => $translated) {
|
foreach ($this->postFields as $local => $translated) {
|
||||||
if (!isset($post->$local))
|
if (!isset($post->$local))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1351,6 +1351,12 @@
|
|||||||
// Whether or not to use the API, disabled by default.
|
// Whether or not to use the API, disabled by default.
|
||||||
$config['api']['enabled'] = false;
|
$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
|
* Other/uncategorized
|
||||||
|
@ -1300,7 +1300,7 @@ function buildIndex() {
|
|||||||
$antibot = create_antibot($board['uri']);
|
$antibot = create_antibot($board['uri']);
|
||||||
|
|
||||||
if ($config['api']['enabled']) {
|
if ($config['api']['enabled']) {
|
||||||
$api = new Api();
|
$api = new Api($config);
|
||||||
$catalog = array();
|
$catalog = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1772,7 +1772,7 @@ function buildThread($id, $return = false, $mod = false) {
|
|||||||
|
|
||||||
// json api
|
// json api
|
||||||
if ($config['api']['enabled']) {
|
if ($config['api']['enabled']) {
|
||||||
$api = new Api();
|
$api = new Api($config);
|
||||||
$json = json_encode($api->translateThread($thread));
|
$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);
|
file_write($jsonFilename, $json);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user