|
|
|
@ -6,23 +6,36 @@ $_ = function() {
|
|
|
|
|
$MAX_LIMIT = 10000;
|
|
|
|
|
$start = arg('*get.start', null, 'valid_mastodon_account_id');
|
|
|
|
|
$limit = arg('i:get.limit', $MAX_LIMIT);
|
|
|
|
|
$local = arg('set:get.local');
|
|
|
|
|
if ($limit > $MAX_LIMIT)
|
|
|
|
|
$limit = $MAX_LIMIT;
|
|
|
|
|
$fields = "id, TRIM(CONCAT(spoiler_text, ' ', text)) AS post, created_at, updated_at";
|
|
|
|
|
|
|
|
|
|
$pg = new PgDatabase();
|
|
|
|
|
if (!$pg->is_ok())
|
|
|
|
|
return apiresult(['error' => 'Unknown database error ocurred'], 500);
|
|
|
|
|
|
|
|
|
|
$fields = "s.id, s.account_id, TRIM(CONCAT(s.spoiler_text, ' ', s.text)) AS post, s.created_at, s.updated_at";
|
|
|
|
|
$sql_all = '
|
|
|
|
|
SELECT '.$fields.', reblog_of_id
|
|
|
|
|
FROM statuses
|
|
|
|
|
WHERE id >= '.$start.'
|
|
|
|
|
FROM statuses AS s
|
|
|
|
|
{innerJoinAccounts}
|
|
|
|
|
WHERE
|
|
|
|
|
{isLocal}
|
|
|
|
|
s.id >= '.$start.'
|
|
|
|
|
ORDER BY id ASC LIMIT '.$limit.'
|
|
|
|
|
';
|
|
|
|
|
$pg = new PgDatabase();
|
|
|
|
|
if (!$pg->is_ok())
|
|
|
|
|
return apiresult(['error' => 'Unknown database error ocurred'], 500);
|
|
|
|
|
if ($local) {
|
|
|
|
|
$sql_all = str_replace('{isLocal}', 'a.domain IS NULL AND', $sql_all);
|
|
|
|
|
$sql_all = str_replace('{innerJoinAccounts}', 'INNER JOIN accounts AS a ON a.id = s.account_id', $sql_all);
|
|
|
|
|
} else {
|
|
|
|
|
$sql_all = str_replace('{isLocal}', '', $sql_all);
|
|
|
|
|
$sql_all = str_replace('{innerJoinAccounts}', '', $sql_all);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$objects = $pg->fetch_all($sql_all);
|
|
|
|
|
foreach ($objects as &$object) {
|
|
|
|
|
if ($object['reblog_of_id'] !== null)
|
|
|
|
|
$object['original'] = $pg->fetch("SELECT $fields FROM statuses WHERE id = {$object['reblog_of_id']} LIMIT 1");
|
|
|
|
|
$object['original'] = $pg->fetch("SELECT $fields FROM statuses AS s WHERE s.id = {$object['reblog_of_id']} LIMIT 1");
|
|
|
|
|
unset($object['reblog_of_id']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|