Add JSON interface to Recents Posts functionality, e.g. mod_recent_posts
This commit is contained in:
parent
6c06045c03
commit
454acf0566
@ -1678,7 +1678,7 @@ function mod_delete($board, $post) {
|
||||
}
|
||||
if ($time !== ''){
|
||||
$dt = new DateTime("@$time");
|
||||
$autotag = "";
|
||||
$autotag = "";
|
||||
$autotag .= $name . " " . $subject . " " . $dt->format('Y-m-d H:i:s') . " No.". $post . "\r\n";
|
||||
$autotag .= "/${board}/" . " " . $filehash . " " . $filename ."\r\n";
|
||||
$autotag .= $body . "\r\n";
|
||||
@ -2452,7 +2452,7 @@ function mod_report_dismiss($id, $all = false) {
|
||||
header('Location: ?/reports', true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_recent_posts($lim) {
|
||||
function mod_recent_posts($lim,$json = false) {
|
||||
global $config, $mod, $pdo;
|
||||
|
||||
if (!hasPermission($config['mod']['recent']))
|
||||
@ -2485,6 +2485,10 @@ function mod_recent_posts($lim) {
|
||||
$query->bindValue(':last_time', $last_time);
|
||||
$query->execute() or error(db_error($query));
|
||||
$posts = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($config['api']['enabled']) {
|
||||
$apithreads = array();
|
||||
}
|
||||
|
||||
foreach ($posts as &$post) {
|
||||
openBoard($post['board']);
|
||||
@ -2492,20 +2496,39 @@ function mod_recent_posts($lim) {
|
||||
// Still need to fix this:
|
||||
$po = new Thread($post, '?/', $mod, false);
|
||||
$post['built'] = $po->build(true);
|
||||
if ($config['api']['enabled']) {
|
||||
$apithreads[] = $po;
|
||||
}
|
||||
|
||||
} else {
|
||||
$po = new Post($post, '?/', $mod);
|
||||
$post['built'] = $po->build(true);
|
||||
if ($config['api']['enabled']) {
|
||||
$pot = new Thread($post, '?/', $mod, false);
|
||||
$pot->add($po);
|
||||
$apithreads[] = $pot;
|
||||
}
|
||||
}
|
||||
$last_time = $post['time'];
|
||||
}
|
||||
|
||||
echo mod_page(_('Recent posts'), 'mod/recent_posts.html', array(
|
||||
'posts' => $posts,
|
||||
'limit' => $limit,
|
||||
'last_time' => $last_time
|
||||
)
|
||||
);
|
||||
|
||||
if ($config['api']['enabled']) {
|
||||
require_once __DIR__. '/../../inc/api.php';
|
||||
$api = new Api();
|
||||
$jsonFilename = 'mod/' . 'recent.json';
|
||||
$jsondata = json_encode($api->translatePage($apithreads));
|
||||
}
|
||||
|
||||
if ($json){
|
||||
echo $jsondata;
|
||||
}
|
||||
else {
|
||||
echo mod_page(_('Recent posts'), 'mod/recent_posts.html', array(
|
||||
'posts' => $posts,
|
||||
'limit' => $limit,
|
||||
'last_time' => $last_time
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function mod_config($board_config = false) {
|
||||
|
1
mod.php
1
mod.php
@ -73,6 +73,7 @@ $pages = array(
|
||||
'/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals
|
||||
|
||||
'/recent/(\d+)' => 'recent_posts', // view recent posts
|
||||
'/recent/(\d+)/(json)?' => 'recent_posts', // view recent posts JSON
|
||||
|
||||
'/search' => 'search_redirect', // search
|
||||
'/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
|
||||
|
Loading…
Reference in New Issue
Block a user