forked from GithubBackups/tinyib
Tweak JSON changes
This commit is contained in:
parent
d6841c02aa
commit
4223e82c66
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
TinyIB <https://gitlab.com/tslocum/tinyib>
|
TinyIB
|
||||||
|
https://gitlab.com/tslocum/tinyib
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
@ -79,9 +80,6 @@ foreach ($writedirs as $dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$includes = array("inc/defines.php", "inc/functions.php", "inc/html.php");
|
$includes = array("inc/defines.php", "inc/functions.php", "inc/html.php");
|
||||||
if (TINYIB_JSON) {
|
|
||||||
$includes[] = 'inc/json.php';
|
|
||||||
}
|
|
||||||
if (in_array(TINYIB_DBMODE, array('flatfile', 'mysql', 'mysqli', 'sqlite', 'sqlite3', 'pdo'))) {
|
if (in_array(TINYIB_DBMODE, array('flatfile', 'mysql', 'mysqli', 'sqlite', 'sqlite3', 'pdo'))) {
|
||||||
$includes[] = 'inc/database_' . TINYIB_DBMODE . '.php';
|
$includes[] = 'inc/database_' . TINYIB_DBMODE . '.php';
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,7 +3,7 @@ if (!defined('TINYIB_BOARD')) {
|
|||||||
die('');
|
die('');
|
||||||
}
|
}
|
||||||
|
|
||||||
# Post Structure
|
// Post Structure
|
||||||
define('POSTS_FILE', '.posts');
|
define('POSTS_FILE', '.posts');
|
||||||
define('POST_ID', 0);
|
define('POST_ID', 0);
|
||||||
define('POST_PARENT', 1);
|
define('POST_PARENT', 1);
|
||||||
@ -30,7 +30,7 @@ define('POST_THUMB_HEIGHT', 21);
|
|||||||
define('POST_STICKIED', 22);
|
define('POST_STICKIED', 22);
|
||||||
define('POST_LOCKED', 23);
|
define('POST_LOCKED', 23);
|
||||||
|
|
||||||
# Ban Structure
|
// Ban Structure
|
||||||
define('BANS_FILE', '.bans');
|
define('BANS_FILE', '.bans');
|
||||||
define('BAN_ID', 0);
|
define('BAN_ID', 0);
|
||||||
define('BAN_IP', 1);
|
define('BAN_IP', 1);
|
||||||
@ -42,7 +42,7 @@ require_once 'flatfile/flatfile.php';
|
|||||||
$db = new Flatfile();
|
$db = new Flatfile();
|
||||||
$db->datadir = 'inc/flatfile/';
|
$db->datadir = 'inc/flatfile/';
|
||||||
|
|
||||||
# Post Functions
|
// Post Functions
|
||||||
function uniquePosts() {
|
function uniquePosts() {
|
||||||
return 0; // Unsupported by this database option
|
return 0; // Unsupported by this database option
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ function lastPostByIP() {
|
|||||||
return convertPostsToSQLStyle($rows, true);
|
return convertPostsToSQLStyle($rows, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ban Functions
|
// Ban Functions
|
||||||
function banByID($id) {
|
function banByID($id) {
|
||||||
return convertBansToSQLStyle($GLOBALS['db']->selectWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON), 1), true);
|
return convertBansToSQLStyle($GLOBALS['db']->selectWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON), 1), true);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ if (mysql_num_rows(mysql_query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE
|
|||||||
mysql_query("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
mysql_query("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
||||||
}
|
}
|
||||||
|
|
||||||
# Post Functions
|
// Post Functions
|
||||||
function uniquePosts() {
|
function uniquePosts() {
|
||||||
$row = mysql_fetch_row(mysql_query("SELECT COUNT(DISTINCT(`ip`)) FROM " . TINYIB_DBPOSTS));
|
$row = mysql_fetch_row(mysql_query("SELECT COUNT(DISTINCT(`ip`)) FROM " . TINYIB_DBPOSTS));
|
||||||
return $row[0];
|
return $row[0];
|
||||||
@ -177,7 +177,7 @@ function lastPostByIP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ban Functions
|
// Ban Functions
|
||||||
function banByID($id) {
|
function banByID($id) {
|
||||||
$result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
|
$result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
@ -35,7 +35,7 @@ if (mysqli_num_rows(mysqli_query($link, "SHOW COLUMNS FROM `" . TINYIB_DBPOSTS .
|
|||||||
mysqli_query($link,"ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
mysqli_query($link,"ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
||||||
}
|
}
|
||||||
|
|
||||||
# Post Functions
|
// Post Functions
|
||||||
function uniquePosts() {
|
function uniquePosts() {
|
||||||
global $link;
|
global $link;
|
||||||
$row = mysqli_fetch_row(mysqli_query($link, "SELECT COUNT(DISTINCT(`ip`)) FROM " . TINYIB_DBPOSTS));
|
$row = mysqli_fetch_row(mysqli_query($link, "SELECT COUNT(DISTINCT(`ip`)) FROM " . TINYIB_DBPOSTS));
|
||||||
@ -194,7 +194,7 @@ function lastPostByIP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ban Functions
|
// Ban Functions
|
||||||
function banByID($id) {
|
function banByID($id) {
|
||||||
global $link;
|
global $link;
|
||||||
$result = mysqli_query($link, "SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `id` = '" . mysqli_real_escape_string($link, $id) . "' LIMIT 1");
|
$result = mysqli_query($link, "SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `id` = '" . mysqli_real_escape_string($link, $id) . "' LIMIT 1");
|
||||||
|
@ -78,7 +78,7 @@ if (!$stickied_exists) {
|
|||||||
$dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
$dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
||||||
}
|
}
|
||||||
|
|
||||||
# Utility
|
// Utility
|
||||||
function pdoQuery($sql, $params = false) {
|
function pdoQuery($sql, $params = false) {
|
||||||
global $dbh;
|
global $dbh;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ function pdoQuery($sql, $params = false) {
|
|||||||
return $statement;
|
return $statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Post Functions
|
// Post Functions
|
||||||
function uniquePosts() {
|
function uniquePosts() {
|
||||||
$result = pdoQuery("SELECT COUNT(DISTINCT(ip)) FROM " . TINYIB_DBPOSTS);
|
$result = pdoQuery("SELECT COUNT(DISTINCT(ip)) FROM " . TINYIB_DBPOSTS);
|
||||||
return (int)$result->fetchColumn();
|
return (int)$result->fetchColumn();
|
||||||
@ -218,12 +218,13 @@ function deletePostByID($id) {
|
|||||||
function trimThreads() {
|
function trimThreads() {
|
||||||
$limit = (int)TINYIB_MAXTHREADS;
|
$limit = (int)TINYIB_MAXTHREADS;
|
||||||
if ($limit > 0) {
|
if ($limit > 0) {
|
||||||
$results = pdoQuery("SELECT id FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated = 1 ORDER BY stickied DESC, bumped DESC LIMIT 100 OFFSET " . $limit
|
$results = pdoQuery("SELECT id FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated = 1 ORDER BY stickied DESC, bumped DESC LIMIT 100 OFFSET " . $limit);
|
||||||
);
|
/*
|
||||||
# old mysql, sqlite3: SELECT id FROM $table ORDER BY bumped LIMIT $limit,100
|
old mysql, sqlite3: SELECT id FROM $table ORDER BY bumped LIMIT $limit,100
|
||||||
# mysql, postgresql, sqlite3: SELECT id FROM $table ORDER BY bumped LIMIT 100 OFFSET $limit
|
mysql, postgresql, sqlite3: SELECT id FROM $table ORDER BY bumped LIMIT 100 OFFSET $limit
|
||||||
# oracle: SELECT id FROM ( SELECT id, rownum FROM $table ORDER BY bumped) WHERE rownum >= $limit
|
oracle: SELECT id FROM ( SELECT id, rownum FROM $table ORDER BY bumped) WHERE rownum >= $limit
|
||||||
# MSSQL: WITH ts AS (SELECT ROWNUMBER() OVER (ORDER BY bumped) AS 'rownum', * FROM $table) SELECT id FROM ts WHERE rownum >= $limit
|
MSSQL: WITH ts AS (SELECT ROWNUMBER() OVER (ORDER BY bumped) AS 'rownum', * FROM $table) SELECT id FROM ts WHERE rownum >= $limit
|
||||||
|
*/
|
||||||
foreach ($results as $post) {
|
foreach ($results as $post) {
|
||||||
deletePostByID($post['id']);
|
deletePostByID($post['id']);
|
||||||
}
|
}
|
||||||
@ -235,7 +236,7 @@ function lastPostByIP() {
|
|||||||
return $result->fetch(PDO::FETCH_ASSOC);
|
return $result->fetch(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ban Functions
|
// Ban Functions
|
||||||
function banByID($id) {
|
function banByID($id) {
|
||||||
$result = pdoQuery("SELECT * FROM " . TINYIB_DBBANS . " WHERE id = ?", array($id));
|
$result = pdoQuery("SELECT * FROM " . TINYIB_DBBANS . " WHERE id = ?", array($id));
|
||||||
return $result->fetch(PDO::FETCH_ASSOC);
|
return $result->fetch(PDO::FETCH_ASSOC);
|
||||||
|
@ -59,7 +59,7 @@ sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN stickied INTEGE
|
|||||||
// Add locked column if it isn't present
|
// Add locked column if it isn't present
|
||||||
sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN locked INTEGER NOT NULL DEFAULT '0'");
|
sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN locked INTEGER NOT NULL DEFAULT '0'");
|
||||||
|
|
||||||
# Post Functions
|
// Post Functions
|
||||||
function uniquePosts() {
|
function uniquePosts() {
|
||||||
return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(ip) FROM (SELECT DISTINCT ip FROM " . TINYIB_DBPOSTS . ")"));
|
return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(ip) FROM (SELECT DISTINCT ip FROM " . TINYIB_DBPOSTS . ")"));
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ function lastPostByIP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ban Functions
|
// Ban Functions
|
||||||
function banByID($id) {
|
function banByID($id) {
|
||||||
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBBANS . " WHERE id = '" . sqlite_escape_string($id) . "' LIMIT 1"), SQLITE_ASSOC);
|
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBBANS . " WHERE id = '" . sqlite_escape_string($id) . "' LIMIT 1"), SQLITE_ASSOC);
|
||||||
foreach ($result as $ban) {
|
foreach ($result as $ban) {
|
||||||
|
@ -60,7 +60,7 @@ if (!$result->fetchArray()) {
|
|||||||
// Add locked column if it isn't present
|
// Add locked column if it isn't present
|
||||||
@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN locked INTEGER NOT NULL DEFAULT '0'");
|
@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN locked INTEGER NOT NULL DEFAULT '0'");
|
||||||
|
|
||||||
# Post Functions
|
// Post Functions
|
||||||
function uniquePosts() {
|
function uniquePosts() {
|
||||||
global $db;
|
global $db;
|
||||||
return $db->querySingle("SELECT COUNT(ip) FROM (SELECT DISTINCT ip FROM " . TINYIB_DBPOSTS . ")");
|
return $db->querySingle("SELECT COUNT(ip) FROM (SELECT DISTINCT ip FROM " . TINYIB_DBPOSTS . ")");
|
||||||
@ -199,7 +199,7 @@ function lastPostByIP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ban Functions
|
// Ban Functions
|
||||||
function banByID($id) {
|
function banByID($id) {
|
||||||
global $db;
|
global $db;
|
||||||
$result = $db->query("SELECT * FROM " . TINYIB_DBBANS . " WHERE id = '" . $db->escapeString($id) . "' LIMIT 1");
|
$result = $db->query("SELECT * FROM " . TINYIB_DBBANS . " WHERE id = '" . $db->escapeString($id) . "' LIMIT 1");
|
||||||
|
70
inc/html.php
70
inc/html.php
@ -623,10 +623,6 @@ function rebuildIndexes() {
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
$htmlposts = '';
|
$htmlposts = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TINYIB_JSON) {
|
|
||||||
writePage("res/" . $thread['id'] . '.json', buildThreadNoJSON($thread['id']));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($page == 0 || $htmlposts != '') {
|
if ($page == 0 || $htmlposts != '') {
|
||||||
@ -639,12 +635,14 @@ function rebuildIndexes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TINYIB_JSON) {
|
if (TINYIB_JSON) {
|
||||||
writePage('threads.json', buildThreadsJSON());
|
writePage('threads.json', buildIndexJSON());
|
||||||
writePage('catalog.json', buildCatalogJSON());
|
writePage('catalog.json', buildCatalogJSON());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildThread($id) {
|
function rebuildThread($id) {
|
||||||
|
$id = intval($id);
|
||||||
|
|
||||||
$htmlposts = "";
|
$htmlposts = "";
|
||||||
$posts = postsInThreadByID($id);
|
$posts = postsInThreadByID($id);
|
||||||
foreach ($posts as $post) {
|
foreach ($posts as $post) {
|
||||||
@ -654,6 +652,10 @@ function rebuildThread($id) {
|
|||||||
$htmlposts .= "\n<hr>";
|
$htmlposts .= "\n<hr>";
|
||||||
|
|
||||||
writePage('res/' . $id . '.html', fixLinksInRes(buildPage($htmlposts, $id)));
|
writePage('res/' . $id . '.html', fixLinksInRes(buildPage($htmlposts, $id)));
|
||||||
|
|
||||||
|
if (TINYIB_JSON) {
|
||||||
|
writePage('res/' . $id . '.json', buildSingleThreadJSON($id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminBar() {
|
function adminBar() {
|
||||||
@ -943,3 +945,61 @@ EOF;
|
|||||||
function manageInfo($text) {
|
function manageInfo($text) {
|
||||||
return '<div class="manageinfo">' . $text . '</div>';
|
return '<div class="manageinfo">' . $text . '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function encodeJSON($array) {
|
||||||
|
if (version_compare(phpversion(), '5.4.0', '>')) {
|
||||||
|
return json_encode($array, JSON_PRETTY_PRINT);
|
||||||
|
}
|
||||||
|
return json_encode($array);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildSinglePostJSON($post) {
|
||||||
|
$name = $post['name'];
|
||||||
|
if ($name == '') {
|
||||||
|
$name = 'Anonymous';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = array('id' => $post['id'], 'parent' => $post['parent'], 'timestamp' => $post['timestamp'], 'bumped' => $post['bumped'], 'name' => $name, 'tripcode' => $post['tripcode'], 'subject' => $post['subject'], 'message' => $post['message'], 'file' => $post['file'], 'file_hex' => $post['file_hex'], 'file_original' => $post['file_original'], 'file_size' => $post['file_size'], 'file_size_formated' => $post['file_size_formatted'], 'image_width' => $post['image_width'], 'image_height' => $post['image_height'], 'thumb' => $post['thumb'], 'thumb_width' => $post['thumb_width'], 'thumb_height' => $post['thumb_height']);
|
||||||
|
|
||||||
|
if($post['parent'] == TINYIB_NEWTHREAD) {
|
||||||
|
$replies = count(postsInThreadByID($post['id'])) - 1;
|
||||||
|
$images = imagesInThreadByID($post['id']);
|
||||||
|
|
||||||
|
$output = array_merge($output, array('stickied' => $post['stickied'], 'locked' => $post['locked'], 'replies' => $replies, 'images' => $images));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildIndexJSON() {
|
||||||
|
$output = array('threads' => array());
|
||||||
|
|
||||||
|
$threads = allThreads();
|
||||||
|
foreach ($threads as $thread) {
|
||||||
|
array_push($output['threads'], array('id' => $thread['id'], 'subject' => $thread['subject'], 'bumped' => $thread['bumped']));
|
||||||
|
}
|
||||||
|
|
||||||
|
return encodeJSON($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildCatalogJSON() {
|
||||||
|
$output = array('threads' => array());
|
||||||
|
|
||||||
|
$threads = allThreads();
|
||||||
|
foreach ($threads as $post) {
|
||||||
|
array_push($output['threads'], buildSinglePostJSON($post));
|
||||||
|
}
|
||||||
|
|
||||||
|
return encodeJSON($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildSingleThreadJSON($id) {
|
||||||
|
$output = array('posts' => array());
|
||||||
|
|
||||||
|
$posts = postsInThreadByID($id);
|
||||||
|
foreach ($posts as $post) {
|
||||||
|
array_push($output['posts'], buildSinglePostJSON($post));
|
||||||
|
}
|
||||||
|
|
||||||
|
return encodeJSON($output);
|
||||||
|
}
|
76
inc/json.php
76
inc/json.php
@ -1,76 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
function buildThreadsJSON() {
|
|
||||||
$output['threads'] = array();
|
|
||||||
|
|
||||||
$threads = allThreads();
|
|
||||||
//$pages may be useful later, dismiss it for now
|
|
||||||
//$pages = ceil(count($threads) / TINYIB_THREADSPERPAGE) - 1;
|
|
||||||
|
|
||||||
foreach ($threads as $thread) {
|
|
||||||
array_push($output['threads'], array('id' => $thread['id'], 'subject' => $thread['subject'], 'bumped' => $thread['bumped']));
|
|
||||||
}
|
|
||||||
|
|
||||||
$threads_json[] = $output;
|
|
||||||
if (version_compare(phpversion(), '5.4.0', '>')) {
|
|
||||||
return json_encode($threads_json, JSON_PRETTY_PRINT);
|
|
||||||
} else {
|
|
||||||
return json_encode($threads_json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildCatalogJSON() {
|
|
||||||
$output['threads'] = array();
|
|
||||||
|
|
||||||
$threads = allThreads();
|
|
||||||
|
|
||||||
foreach ($threads as $thread) {
|
|
||||||
$replies = postsInThreadByID($thread['id']);
|
|
||||||
$images = imagesInThreadByID($thread['id']);
|
|
||||||
|
|
||||||
if($thread['name'] == '') {
|
|
||||||
array_push($output['threads'], array('id' => $thread['id'], 'parent' => $thread['parent'], 'timestamp' => $thread['timestamp'], 'bumped' => $thread['bumped'], 'name' => 'Anonymous', 'tripcode' => $thread['tripcode'], 'subject' => $thread['subject'], 'message' => $thread['message'], 'file' => $thread['file'], 'file_hex' => $thread['file_hex'], 'file_original' => $thread['file_original'], 'file_size' => $thread['file_size'], 'file_size_formated' => $thread['file_size_formatted'], 'image_width' => $thread['image_width'], 'image_height' => $thread['image_height'], 'thumb' => $thread['thumb'], 'thumb_width' => $thread['thumb_width'], 'thumb_height' => $thread['thumb_height'], 'stickied' => $thread['stickied'], 'moderated' => $thread['moderated'], 'locked' => $thread['locked'], 'replies' => count($replies) - 1, 'images' => $images));
|
|
||||||
} else {
|
|
||||||
array_push($output['threads'], array('id' => $thread['id'], 'parent' => $thread['parent'], 'timestamp' => $thread['timestamp'], 'bumped' => $thread['bumped'], 'name' => $thread['name'], 'tripcode' => $thread['tripcode'], 'subject' => $thread['subject'], 'message' => $thread['message'], 'file' => $thread['file'], 'file_hex' => $thread['file_hex'], 'file_original' => $thread['file_original'], 'file_size' => $thread['file_size'], 'file_size_formated' => $thread['file_size_formatted'], 'image_width' => $thread['image_width'], 'image_height' => $thread['image_height'], 'thumb' => $thread['thumb'], 'thumb_width' => $thread['thumb_width'], 'thumb_height' => $thread['thumb_height'], 'stickied' => $thread['stickied'], 'moderated' => $thread['moderated'], 'locked' => $thread['locked'], 'replies' => count($replies) - 1, 'images' => $images));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$threads_json[] = $output;
|
|
||||||
if (version_compare(phpversion(), '5.4.0', '>')) {
|
|
||||||
return json_encode($threads_json, JSON_PRETTY_PRINT);
|
|
||||||
} else {
|
|
||||||
return json_encode($threads_json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildThreadNoJSON($id) {
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
$threads = allThreads();
|
|
||||||
|
|
||||||
foreach ($threads as $thread) {
|
|
||||||
$replies = postsInThreadByID($id);
|
|
||||||
if($thread['parent'] == 0 && $thread['id'] == $id) {
|
|
||||||
if($thread['name'] == '') {
|
|
||||||
$output = array('posts' => [array('id' => $thread['id'], 'parent' => $thread['parent'], 'timestamp' => $thread['timestamp'], 'bumped' => $thread['bumped'], 'name' => 'Anonymous', 'tripcode' => $thread['tripcode'], 'subject' => $thread['subject'], 'message' => $thread['message'], 'file' => $thread['file'], 'file_hex' => $thread['file_hex'], 'file_original' => $thread['file_original'], 'file_size' => $thread['file_size'], 'file_size_formated' => $thread['file_size_formatted'], 'image_width' => $thread['image_width'], 'image_height' => $thread['image_height'], 'thumb' => $thread['thumb'], 'thumb_width' => $thread['thumb_width'], 'thumb_height' => $thread['thumb_height'], 'stickied' => $thread['stickied'], 'moderated' => $thread['moderated'], 'locked' => $thread['locked'])]);
|
|
||||||
} else {
|
|
||||||
$output = array('posts' => [array('id' => $thread['id'], 'parent' => $thread['parent'], 'timestamp' => $thread['timestamp'], 'bumped' => $thread['bumped'], 'name' => $thread['name'], 'tripcode' => $thread['tripcode'], 'subject' => $thread['subject'], 'message' => $thread['message'], 'file' => $thread['file'], 'file_hex' => $thread['file_hex'], 'file_original' => $thread['file_original'], 'file_size' => $thread['file_size'], 'file_size_formated' => $thread['file_size_formatted'], 'image_width' => $thread['image_width'], 'image_height' => $thread['image_height'], 'thumb' => $thread['thumb'], 'thumb_width' => $thread['thumb_width'], 'thumb_height' => $thread['thumb_height'], 'stickied' => $thread['stickied'], 'moderated' => $thread['moderated'], 'locked' => $thread['locked'])]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($replies as $reply) {
|
|
||||||
if($reply['parent'] == $id) {
|
|
||||||
if($thread['name'] == '') {
|
|
||||||
array_push($output['posts'], array('id' => $reply['id'], 'parent' => $reply['parent'], 'timestamp' => $reply['timestamp'], 'bumped' => $reply['bumped'], 'name' => 'Anonymous', 'tripcode' => $reply['tripcode'], 'subject' => $reply['subject'], 'message' => $reply['message'], 'file' => $reply['file'], 'file_hex' => $reply['file_hex'], 'file_original' => $reply['file_original'], 'file_size' => $reply['file_size'], 'file_size_formated' => $reply['file_size_formatted'], 'image_width' => $reply['image_width'], 'image_height' => $reply['image_height'], 'thumb' => $reply['thumb'], 'thumb_width' => $reply['thumb_width'], 'thumb_height' => $reply['thumb_height'], 'moderated' => $reply['moderated']));
|
|
||||||
} else {
|
|
||||||
array_push($output['posts'], array('id' => $reply['id'], 'parent' => $reply['parent'], 'timestamp' => $reply['timestamp'], 'bumped' => $reply['bumped'], 'name' => $reply['name'], 'tripcode' => $reply['tripcode'], 'subject' => $reply['subject'], 'message' => $reply['message'], 'file' => $reply['file'], 'file_hex' => $reply['file_hex'], 'file_original' => $reply['file_original'], 'file_size' => $reply['file_size'], 'file_size_formated' => $reply['file_size_formatted'], 'image_width' => $reply['image_width'], 'image_height' => $reply['image_height'], 'thumb' => $reply['thumb'], 'thumb_width' => $reply['thumb_width'], 'thumb_height' => $reply['thumb_height'], 'moderated' => $reply['moderated']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version_compare(phpversion(), '5.4.0', '>')) {
|
|
||||||
return json_encode($output, JSON_PRETTY_PRINT);
|
|
||||||
} else {
|
|
||||||
return json_encode($output);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
# TinyIB
|
/*
|
||||||
#
|
TinyIB
|
||||||
# https://gitlab.com/tslocum/tinyib
|
https://gitlab.com/tslocum/tinyib
|
||||||
#
|
|
||||||
# Contact the author via trevor@rocketnine.space if you need support.
|
Support:
|
||||||
# See README for instructions on configuring, moderating and upgrading your board.
|
https://gitlab.com/tslocum/tinyib/issues
|
||||||
#
|
|
||||||
# Set TINYIB_DBMODE to a MySQL-related mode if it's available. By default it's set to flatfile, which can be very slow.
|
See README for instructions on configuring, moderating and upgrading your board.
|
||||||
|
|
||||||
|
Set TINYIB_DBMODE to a MySQL-related mode if it's available. By default it's set to flatfile, which can be very slow.
|
||||||
|
*/
|
||||||
|
|
||||||
// Administrator/moderator credentials
|
// Administrator/moderator credentials
|
||||||
define('TINYIB_ADMINPASS', ''); // Administrators have full access to the board
|
define('TINYIB_ADMINPASS', ''); // Administrators have full access to the board
|
||||||
@ -28,7 +31,7 @@ define('TINYIB_TRUNCATE', 15); // Messages are truncated to this many lin
|
|||||||
define('TINYIB_WORDBREAK', 80); // Words longer than this many characters will be broken apart [0 to disable]
|
define('TINYIB_WORDBREAK', 80); // Words longer than this many characters will be broken apart [0 to disable]
|
||||||
define('TINYIB_TIMEZONE', 'UTC'); // See https://secure.php.net/manual/en/timezones.php - e.g. America/Los_Angeles
|
define('TINYIB_TIMEZONE', 'UTC'); // See https://secure.php.net/manual/en/timezones.php - e.g. America/Los_Angeles
|
||||||
define('TINYIB_CATALOG', true); // Generate catalog page
|
define('TINYIB_CATALOG', true); // Generate catalog page
|
||||||
define('TINYIB_JSON', true); // Write JSON files (threads.json, catalog.json, etc.)
|
define('TINYIB_JSON', true); // Generate JSON files
|
||||||
$tinyib_hidefieldsop = array(); // Fields to hide when creating a new thread - e.g. array('name', 'email', 'subject', 'message', 'file', 'embed', 'password')
|
$tinyib_hidefieldsop = array(); // Fields to hide when creating a new thread - e.g. array('name', 'email', 'subject', 'message', 'file', 'embed', 'password')
|
||||||
$tinyib_hidefields = array(); // Fields to hide when replying
|
$tinyib_hidefields = array(); // Fields to hide when replying
|
||||||
|
|
||||||
@ -44,11 +47,11 @@ $tinyib_uploads = array('image/jpeg' => array('jpg'),
|
|||||||
'image/pjpeg' => array('jpg'),
|
'image/pjpeg' => array('jpg'),
|
||||||
'image/png' => array('png'),
|
'image/png' => array('png'),
|
||||||
'image/gif' => array('gif'));
|
'image/gif' => array('gif'));
|
||||||
# 'application/x-shockwave-flash' => array('swf', 'swf_thumbnail.png');
|
// 'application/x-shockwave-flash' => array('swf', 'swf_thumbnail.png');
|
||||||
# 'video/webm' => array('webm'); // Video uploads require mediainfo and ffmpegthumbnailer (see README for instructions)
|
// 'video/webm' => array('webm'); // Video uploads require mediainfo and ffmpegthumbnailer (see README for instructions)
|
||||||
# 'audio/webm' => array('webm');
|
// 'audio/webm' => array('webm');
|
||||||
# 'video/mp4' => array('mp4');
|
// 'video/mp4' => array('mp4');
|
||||||
# 'audio/mp4' => array('mp4');
|
// 'audio/mp4' => array('mp4');
|
||||||
|
|
||||||
// oEmbed APIs
|
// oEmbed APIs
|
||||||
// Empty array to disable
|
// Empty array to disable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user