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

@ -22,6 +22,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\System;
/**
* Static definition for the Firefox Account Manager
@ -78,7 +79,6 @@ class AccountManagementControlDocument extends BaseModule
],
];
echo json_encode($output);
exit();
System::jsonExit($output);
}
}

View file

@ -0,0 +1,51 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Module\ActivityPub;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
/**
* ActivityPub featured posts
*/
class Featured extends BaseModule
{
protected function rawContent(array $request = [])
{
if (empty($this->parameters['nickname'])) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
$owner = User::getOwnerDataByNick($this->parameters['nickname']);
if (empty($owner)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
$page = $request['page'] ?? null;
$featured = ActivityPub\Transmitter::getFeatured($owner, $page);
System::jsonExit($featured, 'application/activity+json');
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module\ActivityPub;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
@ -48,8 +49,6 @@ class Followers extends BaseModule
$followers = ActivityPub\Transmitter::getContacts($owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers', $page, (string)HTTPSignature::getSigner('', $_SERVER));
header('Content-Type: application/activity+json');
echo json_encode($followers);
exit();
System::jsonExit($followers, 'application/activity+json');
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module\ActivityPub;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
@ -46,8 +47,6 @@ class Following extends BaseModule
$following = ActivityPub\Transmitter::getContacts($owner, [Contact::SHARING, Contact::FRIEND], 'following', $page);
header('Content-Type: application/activity+json');
echo json_encode($following);
exit();
System::jsonExit($following, 'application/activity+json');
}
}

View file

@ -50,7 +50,7 @@ class Inbox extends BaseModule
$filename = 'failed-activitypub';
}
$tempfile = tempnam(System::getTempPath(), $filename);
file_put_contents($tempfile, json_encode(['parameters' => $this->parameters, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
file_put_contents($tempfile, json_encode(['parameters' => $this->parameters, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
Logger::notice('Incoming message stored', ['file' => $tempfile]);
}

View file

@ -31,7 +31,6 @@ use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
use Friendica\Security\PermissionSet\Repository\PermissionSet;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Network;
use Friendica\Util\Strings;
@ -130,6 +129,7 @@ class Objects extends BaseModule
// Relaxed CORS header for public items
header('Access-Control-Allow-Origin: *');
System::jsonExit($data, 'application/activity+json');
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module\ActivityPub;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
@ -46,8 +47,7 @@ class Outbox extends BaseModule
$requester = HTTPSignature::getSigner('', $_SERVER);
$outbox = ActivityPub\Transmitter::getOutbox($owner, $page, $requester);
header('Content-Type: application/activity+json');
echo json_encode($outbox);
exit();
System::jsonExit($outbox, 'application/activity+json');
}
}

View file

@ -22,6 +22,8 @@
namespace Friendica\Module\DFRN;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Module\Response;
use Friendica\Protocol\OStatus;
/**
@ -31,9 +33,7 @@ class Poll extends BaseModule
{
protected function rawContent(array $request = [])
{
header("Content-type: application/atom+xml");
$last_update = $_GET['last_update'] ?? '';
echo OStatus::feed($this->parameters['nickname'], $last_update, 10);
exit();
$last_update = $request['last_update'] ?? '';
System::httpExit(OStatus::feed($this->parameters['nickname'], $last_update, 10), Response::TYPE_ATOM);
}
}

View file

@ -28,6 +28,7 @@ use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Diaspora;
use Friendica\Util\Strings;
@ -84,9 +85,6 @@ class Fetch extends BaseModule
$xml = Diaspora::buildPostXml($status["type"], $status["message"]);
// Send the envelope
header("Content-Type: application/magic-envelope+xml; charset=utf-8");
echo Diaspora::buildMagicEnvelope($xml, $user);
exit();
System::httpExit(Diaspora::buildMagicEnvelope($xml, $user), Response::TYPE_XML, 'application/magic-envelope+xml');
}
}

View file

@ -21,6 +21,7 @@
namespace Friendica\Module\Events;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Event;
@ -94,9 +95,7 @@ class Json extends \Friendica\BaseModule
$events = self::map($events);
}
header('Content-Type: application/json');
echo json_encode($events);
exit();
System::jsonExit($events);
}
private static function map(array $events): array

View file

@ -22,6 +22,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Protocol\Feed as ProtocolFeed;
@ -43,10 +44,8 @@ class Feed extends BaseModule
{
protected function content(array $request = []): string
{
$a = DI::app();
$last_update = $_GET['last_update'] ?? '';
$nocache = !empty($_GET['nocache']) && local_user();
$last_update = $request['last_update'] ?? '';
$nocache = !empty($request['nocache']) && local_user();
$type = null;
// @TODO: Replace with parameter from router
@ -67,8 +66,6 @@ class Feed extends BaseModule
$type = 'posts';
}
header("Content-type: application/atom+xml; charset=utf-8");
echo ProtocolFeed::atom($this->parameters['nickname'], $last_update, 10, $type, $nocache, true);
exit();
System::httpExit(ProtocolFeed::atom($this->parameters['nickname'], $last_update, 10, $type, $nocache, true), Response::TYPE_ATOM);
}
}

View file

@ -182,8 +182,6 @@ class Friendica extends BaseModule
'no_scrape_url' => DI::baseUrl()->get() . '/noscrape',
];
header('Content-type: application/json; charset=utf-8');
echo json_encode($data);
exit();
System::jsonExit($data);
}
}

View file

@ -291,9 +291,7 @@ class Ping extends BaseModule
if (isset($_GET['callback'])) {
// JSONP support
header("Content-type: application/javascript");
echo $_GET['callback'] . '(' . json_encode(['result' => $data]) . ')';
exit;
System::httpExit($_GET['callback'] . '(' . json_encode(['result' => $data]) . ')', Response::TYPE_BLANK, 'application/javascript');
} else {
System::jsonExit(['result' => $data]);
}

View file

@ -24,6 +24,7 @@ namespace Friendica\Module;
use DOMDocument;
use DOMElement;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Util\XML;
@ -38,8 +39,6 @@ class OpenSearch extends BaseModule
*/
protected function rawContent(array $request = [])
{
header('Content-type: application/opensearchdescription+xml');
$hostname = DI::baseUrl()->getHostname();
$baseUrl = DI::baseUrl()->get();
@ -85,8 +84,6 @@ class OpenSearch extends BaseModule
'template' => "$baseUrl/opensearch",
]);
echo $xml->saveXML();
exit();
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
}
}

View file

@ -88,8 +88,7 @@ class ParseUrl extends BaseModule
if ($format == 'json') {
System::jsonExit($arr['text']);
} else {
echo $arr['text'];
exit();
System::httpExit($arr['text']);
}
}
@ -122,8 +121,7 @@ class ParseUrl extends BaseModule
System::jsonExit($ret);
} else {
echo BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? '');
exit();
System::httpExit(BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? ''));
}
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\User;
use Friendica\Network\HTTPException\BadRequestException;
@ -48,9 +49,7 @@ class PublicRSAKey extends BaseModule
Crypto::pemToMe($user['spubkey'], $modulus, $exponent);
header('Content-type: application/magic-public-key');
echo 'RSA' . '.' . Strings::base64UrlEncode($modulus, true) . '.' . Strings::base64UrlEncode($exponent, true);
exit();
$content = 'RSA' . '.' . Strings::base64UrlEncode($modulus, true) . '.' . Strings::base64UrlEncode($exponent, true);
System::httpExit($content, Response::TYPE_BLANK, 'application/magic-public-key');
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Util\XML;
@ -33,10 +34,8 @@ class ReallySimpleDiscovery extends BaseModule
{
protected function rawContent(array $request = [])
{
header('Content-Type: text/xml');
$xml = null;
echo XML::fromArray([
$content = XML::fromArray([
'rsd' => [
'@attributes' => [
'version' => '1.0',
@ -69,6 +68,6 @@ class ReallySimpleDiscovery extends BaseModule
],
],
], $xml);
exit();
System::httpExit($content, Response::TYPE_XML);
}
}

View file

@ -97,7 +97,7 @@ class Response implements ICanCreateResponses
switch ($type) {
case static::TYPE_HTML:
$content_type = $content_type ?? 'text/html';
$content_type = $content_type ?? 'text/html; charset=utf-8';
break;
case static::TYPE_JSON:
$content_type = $content_type ?? 'application/json';

View file

@ -27,6 +27,7 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Search;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -61,8 +62,7 @@ class Acl extends BaseModule
$o = self::regularContactSearch($type);
}
echo json_encode($o);
exit;
System::jsonExit($o);
}
private static function globalContactSearch()

View file

@ -74,7 +74,7 @@ class HTTPException
$content = Renderer::replaceMacros($tpl, self::getVars($e));
}
System::httpExit($e->getCode(), $e->getDescription(), $content);
System::httpError($e->getCode(), $e->getDescription(), $content);
}
/**

View file

@ -26,6 +26,7 @@ use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -78,9 +79,7 @@ class Statistics extends BaseModule
'services' => $services,
], $services);
header("Content-Type: application/json");
echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$this->logger->debug("statistics.", ['statistics' => $statistics]);
exit();
System::jsonExit($statistics);
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Core\Theme;
/**
@ -40,7 +41,7 @@ class ThemeDetails extends BaseModule
$version = $info['version'] ?? '';
$credits = $info['credits'] ?? '';
echo json_encode([
System::jsonExit([
'img' => Theme::getScreenshot($theme),
'desc' => $description,
'version' => $version,

View file

@ -23,7 +23,9 @@ namespace Friendica\Module\WellKnown;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Module\Response;
use Friendica\Protocol\Salmon;
use Friendica\Util\Crypto;
@ -37,8 +39,6 @@ class HostMeta extends BaseModule
{
$config = DI::config();
header('Content-type: text/xml');
if (!$config->get('system', 'site_pubkey', false)) {
$res = Crypto::newKeypair(1024);
@ -47,13 +47,13 @@ class HostMeta extends BaseModule
}
$tpl = Renderer::getMarkupTemplate('xrd_host.tpl');
echo Renderer::replaceMacros($tpl, [
$content = Renderer::replaceMacros($tpl, [
'$zhost' => DI::baseUrl()->getHostname(),
'$zroot' => DI::baseUrl()->get(),
'$domain' => DI::baseUrl()->get(),
'$bigkey' => Salmon::salmonKey($config->get('system', 'site_pubkey'))
]);
exit();
System::httpExit($content, Response::TYPE_XML, 'application/xrd+xml');
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module\WellKnown;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\DI;
/**
@ -51,8 +52,6 @@ class NodeInfo extends BaseModule
]
];
header('Content-type: application/json; charset=utf-8');
echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
System::jsonExit($nodeinfo);
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica\Module\WellKnown;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Search;
use Friendica\Protocol\Relay;
@ -76,8 +77,6 @@ class XSocialRelay extends BaseModule
$relay['protocols']['diaspora'] = ['receive' => DI::baseUrl()->get() . '/receive/public'];
}
header('Content-type: application/json; charset=utf-8');
echo json_encode($relay, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
System::jsonExit($relay);
}
}

View file

@ -46,9 +46,9 @@ class Xrd extends BaseModule
$uri = urldecode(trim($_GET['uri']));
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/jrd+json') !== false) {
$mode = 'json';
$mode = Response::TYPE_JSON;
} else {
$mode = 'xml';
$mode = Response::TYPE_XML;
}
} else {
if (empty($_GET['resource'])) {
@ -57,9 +57,9 @@ class Xrd extends BaseModule
$uri = urldecode(trim($_GET['resource']));
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/xrd+xml') !== false) {
$mode = 'xml';
$mode = Response::TYPE_XML;
} else {
$mode = 'json';
$mode = Response::TYPE_JSON;
}
}
@ -101,7 +101,7 @@ class Xrd extends BaseModule
$avatar = ['type' => 'image/jpeg'];
}
if ($mode == 'xml') {
if ($mode == Response::TYPE_JSON) {
self::printXML($alias, DI::baseUrl()->get(), $user, $owner, $avatar);
} else {
self::printJSON($alias, DI::baseUrl()->get(), $owner, $avatar);
@ -238,9 +238,6 @@ class Xrd extends BaseModule
{
$salmon_key = Salmon::salmonKey($owner['spubkey']);
header('Access-Control-Allow-Origin: *');
header('Content-type: text/xml');
$tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
$o = Renderer::replaceMacros($tpl, [
@ -263,7 +260,8 @@ class Xrd extends BaseModule
$arr = ['user' => $user, 'xml' => $o];
Hook::callAll('personal_xrd', $arr);
echo $arr['xml'];
exit();
header('Access-Control-Allow-Origin: *');
System::httpExit($arr['xml'], Response::TYPE_XML, 'application/xrd+xml');
}
}