mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-24 15:40:12 +01:00
Merge branch 'master' of https://github.com/ctrlcctrlv/Tinyboard
This commit is contained in:
commit
f909fd190a
52
inc/api.php
52
inc/api.php
@ -1,49 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2013 Tinyboard Development Group
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class for generating json API compatible with 4chan API
|
||||
*/
|
||||
class Api {
|
||||
|
||||
function __construct(){
|
||||
global $config;
|
||||
/**
|
||||
* Translation from local fields to fields in 4chan-style API
|
||||
*/
|
||||
public static $postFields = array(
|
||||
$this->config = $config;
|
||||
|
||||
$this->postFields = array(
|
||||
'id' => 'no',
|
||||
'thread' => 'resto',
|
||||
'subject' => 'sub',
|
||||
'body' => 'com',
|
||||
'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',
|
||||
'thumbheight' => 'tn_w',
|
||||
'thumbwidth' => 'tn_h',
|
||||
'fileheight' => 'w',
|
||||
'filewidth' => 'h',
|
||||
'filesize' => 'fsize',
|
||||
//'filename' => 'filename',
|
||||
'filename' => 'filename',
|
||||
'omitted' => 'omitted_posts',
|
||||
'omitted_images' => 'omitted_images',
|
||||
//'posts' => 'replies',
|
||||
//'ip' => '',
|
||||
'sticky' => 'sticky',
|
||||
'locked' => 'locked',
|
||||
//'bumplocked' => '',
|
||||
//'embed' => '',
|
||||
//'root' => '',
|
||||
//'mod' => '',
|
||||
//'hr' => '',
|
||||
);
|
||||
|
||||
static $ints = array(
|
||||
if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){
|
||||
$this->postFields = array_merge($this->postFields, $config['api']['extra_fields']);
|
||||
}
|
||||
}
|
||||
|
||||
private static $ints = array(
|
||||
'no' => 1,
|
||||
'resto' => 1,
|
||||
'time' => 1,
|
||||
@ -60,7 +59,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;
|
||||
|
||||
@ -69,6 +68,7 @@ class Api {
|
||||
if ($val !== null && $val !== '') {
|
||||
$apiPost[$translated] = $toInt ? (int) $val : $val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isset($post->filename)) {
|
||||
@ -77,6 +77,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']) && preg_match('/^[a-z]{2}$/', $modifiers['flag'])) {
|
||||
$country = strtoupper($modifiers['flag']);
|
||||
if ($country) {
|
||||
$apiPost['country'] = $country;
|
||||
$apiPost['country_name'] = $modifiers['flag alt'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $apiPost;
|
||||
}
|
||||
|
||||
|
@ -1342,6 +1342,21 @@
|
||||
// return 'Sorry, you cannot post that!';
|
||||
// });
|
||||
|
||||
/*
|
||||
* =============
|
||||
* API settings
|
||||
* =============
|
||||
*/
|
||||
|
||||
// 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
|
||||
|
@ -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']);
|
||||
@ -1299,8 +1300,10 @@ function buildIndex() {
|
||||
if (!$config['try_smarter'])
|
||||
$antibot = create_antibot($board['uri']);
|
||||
|
||||
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,6 +1327,7 @@ function buildIndex() {
|
||||
file_write($filename, Element('index.html', $content));
|
||||
|
||||
// json api
|
||||
if ($config['api']['enabled']) {
|
||||
$threads = $content['threads'];
|
||||
$json = json_encode($api->translatePage($threads));
|
||||
$jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0
|
||||
@ -1331,20 +1335,25 @@ function buildIndex() {
|
||||
|
||||
$catalog[$page-1] = $threads;
|
||||
}
|
||||
}
|
||||
if ($page < $config['max_pages']) {
|
||||
for (;$page<=$config['max_pages'];$page++) {
|
||||
$filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page));
|
||||
file_unlink($filename);
|
||||
|
||||
if ($config['api']['enabled']) {
|
||||
$jsonFilename = $board['dir'] . ($page-1) . ".json";
|
||||
file_unlink($jsonFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// json api catalog
|
||||
if ($config['api']['enabled']) {
|
||||
$json = json_encode($api->translateCatalog($catalog));
|
||||
$jsonFilename = $board['dir'] . "catalog.json";
|
||||
file_write($jsonFilename, $json);
|
||||
}
|
||||
}
|
||||
|
||||
function buildJavascript() {
|
||||
@ -1765,10 +1774,12 @@ function buildThread($id, $return = false, $mod = false) {
|
||||
$build_pages[] = thread_find_page($id);
|
||||
|
||||
// json api
|
||||
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;
|
||||
|
@ -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);
|
||||
|
||||
|
41
templates/mod/move_reply.html
Normal file
41
templates/mod/move_reply.html
Normal file
@ -0,0 +1,41 @@
|
||||
<form action="?/{{ board }}/move_reply/{{ post }}" method="post">
|
||||
<input type="hidden" name="token" value="{{ token }}">
|
||||
<table>
|
||||
<tr>
|
||||
<th>
|
||||
{% trans 'Post ID' %}
|
||||
</th>
|
||||
<td>
|
||||
>>>{{ config.board_abbreviation|sprintf(board) }}{{ post }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans 'Target board' %}</th>
|
||||
<td>
|
||||
<ul style="list-style:none;padding:0">
|
||||
{% for targetboard in boards %}
|
||||
<li>
|
||||
<input type="radio" name="board" value="{{ targetboard.uri }}" id="ban-board-{{ targetboard.uri }}" {% if boards|count == 2 %}checked{% endif %}>
|
||||
<label style="display:inline" for="ban-board-{{ targetboard.uri }}">
|
||||
{{ config.board_abbreviation|sprintf(targetboard.uri) }} - {{ targetboard.title|e }}
|
||||
</label>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans 'Target thread' %}</th>
|
||||
<td>
|
||||
<p>If you do not want to make the post into a new thread, please specify the thread you want to move the reply to:</p>
|
||||
<input type="text" name="target_thread"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<ul style="padding:0;text-align:center;list-style:none">
|
||||
<li><input type="submit" value="{% trans 'Move reply' %}"></li>
|
||||
</ul>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user