Merge pull request #11402 from annando/featured-endpoint

We now offer an endpoint for featured posts
This commit is contained in:
Hypolite Petovan 2022-04-11 11:17:56 -04:00 committed by GitHub
commit 3842f02b02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 265 additions and 173 deletions

View file

@ -28,12 +28,14 @@ use Friendica\Content\Nav;
use Friendica\Content\Widget;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Event;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
@ -216,8 +218,7 @@ function cal_content(App $a)
$events = Event::prepareListForTemplate($r);
if (!empty(DI::args()->getArgv()[2]) && (DI::args()->getArgv()[2] === 'json')) {
echo json_encode($events);
exit();
System::jsonExit($events);
}
// links: array('href', 'text', 'extra css classes', 'title')
@ -253,8 +254,7 @@ function cal_content(App $a)
]);
if (!empty($_GET['id'])) {
echo $o;
exit();
System::httpExit($o);
}
return $o;
@ -289,10 +289,8 @@ function cal_content(App $a)
// If nothing went wrong we can echo the export content
if ($evexport["success"]) {
header('Content-type: text/calendar');
header('content-disposition: attachment; filename="' . DI::l10n()->t('calendar') . '-' . $nick . '.' . $evexport["extension"] . '"');
echo $evexport["content"];
exit();
System::httpExit($evexport["content"], Response::TYPE_BLANK, 'text/calendar');
}
return;

View file

@ -25,6 +25,7 @@ use Friendica\Content\Widget;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -32,6 +33,7 @@ use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Module\ActivityPub\Objects;
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\DFRN;
@ -342,7 +344,6 @@ function displayShowFeed(int $uri_id, int $uid, bool $conversation)
if ($xml == '') {
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('The feed for this item is unavailable.'));
}
header("Content-type: application/atom+xml");
echo $xml;
exit();
System::httpExit($xml, Response::TYPE_ATOM);
}

View file

@ -27,6 +27,7 @@ use Friendica\Core\ACL;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
@ -122,8 +123,7 @@ function events_post(App $a)
if (strcmp($finish, $start) < 0 && !$nofinish) {
notice(DI::l10n()->t('Event can not end before it has started.'));
if (intval($_REQUEST['preview'])) {
echo DI::l10n()->t('Event can not end before it has started.');
exit();
System::httpExit(DI::l10n()->t('Event can not end before it has started.'));
}
DI::baseUrl()->redirect($onerror_path);
}
@ -131,8 +131,7 @@ function events_post(App $a)
if (!$summary || ($start === DBA::NULL_DATETIME)) {
notice(DI::l10n()->t('Event title and start time are required.'));
if (intval($_REQUEST['preview'])) {
echo DI::l10n()->t('Event title and start time are required.');
exit();
System::httpExit(DI::l10n()->t('Event title and start time are required.'));
}
DI::baseUrl()->redirect($onerror_path);
}
@ -192,9 +191,7 @@ function events_post(App $a)
$datarray['id'] = $event_id;
if (intval($_REQUEST['preview'])) {
$html = Event::getHTML($datarray);
echo $html;
exit();
System::httpExit(Event::getHTML($datarray));
}
$event_id = Event::store($datarray);
@ -391,8 +388,7 @@ function events_content(App $a)
]);
if (!empty($_GET['id'])) {
echo $o;
exit();
System::httpExit($o);
}
return $o;

View file

@ -24,6 +24,7 @@
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Photo;
@ -153,7 +154,6 @@ function fbrowser_content(App $a)
if (!empty($_GET['mode'])) {
return $o;
} else {
echo $o;
exit();
System::httpExit($o);
}
}

View file

@ -20,6 +20,7 @@
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
@ -37,8 +38,7 @@ function msearch_post(App $a)
if (!strlen($search)) {
$output = ['total' => 0, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
echo json_encode($output);
exit();
System::jsonExit($output);
}
$total = 0;
@ -60,7 +60,5 @@ function msearch_post(App $a)
$output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
echo json_encode($output);
exit();
System::jsonExit($output);
}

View file

@ -21,7 +21,9 @@
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Module\Response;
use Friendica\Module\Security\Login;
function oexchange_init(App $a) {
@ -30,8 +32,7 @@ function oexchange_init(App $a) {
$tpl = Renderer::getMarkupTemplate('oexchange_xrd.tpl');
$o = Renderer::replaceMacros($tpl, ['$base' => DI::baseUrl()]);
echo $o;
exit();
System::httpExit($o, Response::TYPE_XML, 'application/xrd+xml');
}
}

View file

@ -25,10 +25,11 @@ use Friendica\Content\Text\BBCode;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Response;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
use Friendica\Util\XML;
function poco_init(App $a) {
@ -229,14 +230,10 @@ function poco_init(App $a) {
Logger::info("End of poco");
if ($format === 'xml') {
header('Content-type: text/xml');
echo Renderer::replaceMacros(Renderer::getMarkupTemplate('poco_xml.tpl'), XML::arrayEscape(['$response' => $ret]));
exit();
System::httpExit(Renderer::replaceMacros(Renderer::getMarkupTemplate('poco_xml.tpl'), XML::arrayEscape(['$response' => $ret])), Response::TYPE_XML);
}
if ($format === 'json') {
header('Content-type: application/json');
echo json_encode($ret);
exit();
System::jsonExit($ret);
} else {
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
}

View file

@ -21,6 +21,7 @@
use Friendica\App;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Attach;
@ -36,15 +37,13 @@ function wall_attach_post(App $a) {
$owner = User::getOwnerDataByNick($nick);
if (!DBA::isResult($owner)) {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
exit();
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
return;
}
} else {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
exit();
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
return;
@ -65,8 +64,7 @@ function wall_attach_post(App $a) {
if (!$can_post) {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Permission denied.')]);
exit();
System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]);
}
notice(DI::l10n()->t('Permission denied.') . EOL );
exit();
@ -74,7 +72,7 @@ function wall_attach_post(App $a) {
if (empty($_FILES['userfile'])) {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
exit();
}
@ -93,23 +91,23 @@ function wall_attach_post(App $a) {
if ($filesize <= 0) {
$msg = DI::l10n()->t('Sorry, maybe your upload is bigger than the PHP configuration allows') . EOL .(DI::l10n()->t('Or - did you try to upload an empty file?'));
@unlink($src);
if ($r_json) {
echo json_encode(['error' => $msg]);
System::jsonExit(['error' => $msg]);
} else {
notice($msg);
}
@unlink($src);
exit();
}
if ($maxfilesize && $filesize > $maxfilesize) {
$msg = DI::l10n()->t('File exceeds size limit of %s', Strings::formatBytes($maxfilesize));
@unlink($src);
if ($r_json) {
echo json_encode(['error' => $msg]);
System::jsonExit(['error' => $msg]);
} else {
echo $msg . EOL;
}
@unlink($src);
exit();
}
@ -120,7 +118,7 @@ function wall_attach_post(App $a) {
if ($newid === false) {
$msg = DI::l10n()->t('File upload failed.');
if ($r_json) {
echo json_encode(['error' => $msg]);
System::jsonExit(['error' => $msg]);
} else {
echo $msg . EOL;
}
@ -128,8 +126,7 @@ function wall_attach_post(App $a) {
}
if ($r_json) {
echo json_encode(['ok' => true, 'id' => $newid]);
exit();
System::jsonExit(['ok' => true, 'id' => $newid]);
}
$lf = "\n";

View file

@ -28,6 +28,7 @@
use Friendica\App;
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Photo;
@ -50,8 +51,7 @@ function wall_upload_post(App $a, $desktopmode = true)
$user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $nick, 'blocked' => false]);
if (!DBA::isResult($user)) {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
exit();
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
return;
}
@ -60,8 +60,7 @@ function wall_upload_post(App $a, $desktopmode = true)
}
} else {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
exit();
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
return;
}
@ -87,8 +86,7 @@ function wall_upload_post(App $a, $desktopmode = true)
if (!$can_post) {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Permission denied.')]);
exit();
System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]);
}
notice(DI::l10n()->t('Permission denied.'));
exit();
@ -96,7 +94,7 @@ function wall_upload_post(App $a, $desktopmode = true)
if (empty($_FILES['userfile']) && empty($_FILES['media'])) {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
exit();
}
@ -147,8 +145,7 @@ function wall_upload_post(App $a, $desktopmode = true)
if ($src == "") {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
exit();
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
notice(DI::l10n()->t('Invalid request.'));
exit();
@ -164,12 +161,12 @@ function wall_upload_post(App $a, $desktopmode = true)
if (!$Image->isValid()) {
$msg = DI::l10n()->t('Unable to process image.');
@unlink($src);
if ($r_json) {
echo json_encode(['error' => $msg]);
System::jsonExit(['error' => $msg]);
} else {
echo $msg. EOL;
}
@unlink($src);
exit();
}
@ -202,12 +199,12 @@ function wall_upload_post(App $a, $desktopmode = true)
if ($filesize > $maximagesize) {
Logger::notice('Image size is too big', ['size' => $filesize, 'max' => $maximagesize]);
$msg = DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize));
@unlink($src);
if ($r_json) {
echo json_encode(['error' => $msg]);
System::jsonExit(['error' => $msg]);
} else {
echo $msg. EOL;
}
@unlink($src);
exit();
}
}
@ -228,7 +225,7 @@ function wall_upload_post(App $a, $desktopmode = true)
if (!$r) {
$msg = DI::l10n()->t('Image upload failed.');
if ($r_json) {
echo json_encode(['error' => $msg]);
System::jsonExit(['error' => $msg]);
} else {
echo $msg. EOL;
}
@ -255,8 +252,7 @@ function wall_upload_post(App $a, $desktopmode = true)
$photo = Photo::selectFirst(['id', 'datasize', 'width', 'height', 'type'], ['resource-id' => $resource_id], ['order' => ['width']]);
if (!$photo) {
if ($r_json) {
echo json_encode(['error' => '']);
exit();
System::jsonExit(['error' => '']);
}
return false;
}
@ -272,8 +268,7 @@ function wall_upload_post(App $a, $desktopmode = true)
$picture["preview"] = DI::baseUrl() . "/photo/{$resource_id}-{$smallest}." . $Image->getExt();
if ($r_json) {
echo json_encode(['picture' => $picture]);
exit();
System::jsonExit(['picture' => $picture]);
}
Logger::info("upload done");
return $picture;
@ -282,8 +277,7 @@ function wall_upload_post(App $a, $desktopmode = true)
Logger::info("upload done");
if ($r_json) {
echo json_encode(['ok' => true]);
exit();
System::jsonExit(['ok' => true]);
}
echo "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id . '][img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n";