summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2017-03-02 11:40:27 +0900
committerBenjamin Southall <applemansigloo@gmail.com>2017-03-02 11:40:27 +0900
commit454acf056694d374498be7e9d961b36de62a5ce1 (patch)
treeacfd8ec58964015a97d29b5e0fa82a87e0488f02 /inc
parent6c06045c0329a9a2c0462b0db1df5ec72dc41493 (diff)
Add JSON interface to Recents Posts functionality, e.g. mod_recent_posts
Diffstat (limited to 'inc')
-rw-r--r--inc/mod/pages.php43
1 files changed, 33 insertions, 10 deletions
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index a1401042..57edbe6a 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -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) {