2021-07-10 19:18:17 +01:00
|
|
|
<?php
|
2021-09-02 08:55:14 -04:00
|
|
|
|
|
|
|
use PonePaste\Models\Paste;
|
|
|
|
|
2021-08-17 13:09:08 -04:00
|
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
|
|
|
|
|
|
define('IN_PONEPASTE', 1);
|
|
|
|
require_once('../includes/common.php');
|
|
|
|
require_once('../includes/NonRetardedSSP.class.php');
|
|
|
|
|
2021-09-02 08:55:14 -04:00
|
|
|
function transformPaste(Paste $paste) {
|
|
|
|
$titleHtml = '<a href="/' . urlencode($paste->id) . '">' . pp_html_escape($paste->title) . '</a>';
|
|
|
|
$authorHtml = '<a href="/user/' . urlencode($paste->user->username) . '">' . pp_html_escape($paste->user->username) . '</a>';
|
|
|
|
$tagsHtml = '';//tagsToHtml($row[3]);
|
2021-08-17 13:09:08 -04:00
|
|
|
|
|
|
|
return [
|
|
|
|
$titleHtml,
|
|
|
|
$authorHtml,
|
|
|
|
$tagsHtml
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-09-02 08:55:14 -04:00
|
|
|
$pastes = Paste::with([
|
|
|
|
'user' => function($query) {
|
|
|
|
$query->select('users.id', 'username');
|
|
|
|
},
|
|
|
|
'tags' => function($query) {
|
|
|
|
$query->select('tags.id', 'name', 'slug');
|
|
|
|
}
|
|
|
|
])->select(['id', 'user_id', 'title']);
|
|
|
|
|
2021-08-17 13:09:08 -04:00
|
|
|
$data = NonRetardedSSP::run(
|
2021-09-02 08:55:14 -04:00
|
|
|
$conn, $_GET, $pastes
|
2021-07-10 19:18:17 +01:00
|
|
|
);
|
|
|
|
|
2021-09-02 08:55:14 -04:00
|
|
|
$data['data'] = $data['data']->map('transformPaste');
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-08-17 13:09:08 -04:00
|
|
|
echo json_encode($data);
|