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;
$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')
*/
use Friendica\App;
+use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
if (!strlen($search)) {
$output = ['total' => 0, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
- echo json_encode($output);
- exit();
+ System::jsonExit($output);
}
$total = 0;
$output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
- echo json_encode($output);
-
- exit();
+ System::jsonExit($output);
}
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\Util\DateTimeFormat;
-use Friendica\Util\Strings;
use Friendica\Util\XML;
function poco_init(App $a) {
exit();
}
if ($format === 'json') {
- header('Content-type: application/json');
- echo json_encode($ret);
- exit();
+ System::jsonExit($ret);
} else {
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
}
use Friendica\App;
use Friendica\Core\Session;
+use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Attach;
$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;
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();
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();
}
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();
}
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;
}
}
if ($r_json) {
- echo json_encode(['ok' => true, 'id' => $newid]);
- exit();
+ System::jsonExit(['ok' => true, 'id' => $newid]);
}
$lf = "\n";
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;
$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;
}
}
} else {
if ($r_json) {
- echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
- exit();
+ System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
}
return;
}
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();
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();
}
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();
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();
}
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();
}
}
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;
}
$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;
}
$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;
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";
* @param integer $options JSON options
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function jsonExit($x, $content_type = 'application/json', int $options = 0) {
+ public static function jsonExit($x, $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) {
DI::apiResponse()->setType(Response::TYPE_JSON, $content_type);
DI::apiResponse()->addContent(json_encode($x, $options));
DI::page()->exit(DI::apiResponse()->generate());
namespace Friendica\Module;
use Friendica\BaseModule;
+use Friendica\Core\System;
/**
* Static definition for the Firefox Account Manager
],
];
- echo json_encode($output);
- exit();
+ System::jsonExit($output);
}
}
$page = $request['page'] ?? null;
- $outbox = ActivityPub\Transmitter::getFeatured($owner, $page);
- System::jsonExit($outbox, 'application/activity+json');
+ $featured = ActivityPub\Transmitter::getFeatured($owner, $page);
+
+ System::jsonExit($featured, 'application/activity+json');
}
}
namespace Friendica\Module\ActivityPub;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
$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');
}
}
namespace Friendica\Module\ActivityPub;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
$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');
}
}
$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]);
}
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;
// Relaxed CORS header for public items
header('Access-Control-Allow-Origin: *');
+
System::jsonExit($data, 'application/activity+json');
}
}
namespace Friendica\Module\ActivityPub;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
$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');
}
}
namespace Friendica\Module\Events;
+use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Event;
$events = self::map($events);
}
- header('Content-Type: application/json');
- echo json_encode($events);
- exit();
+ System::jsonExit($events);
}
private static function map(array $events): array
'no_scrape_url' => DI::baseUrl()->get() . '/noscrape',
];
- header('Content-type: application/json; charset=utf-8');
- echo json_encode($data);
- exit();
+ System::jsonExit($data);
}
}
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;
$o = self::regularContactSearch($type);
}
- echo json_encode($o);
- exit;
+ System::jsonExit($o);
}
private static function globalContactSearch()
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;
'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);
}
}
namespace Friendica\Module;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\Core\Theme;
/**
$version = $info['version'] ?? '';
$credits = $info['credits'] ?? '';
- echo json_encode([
+ System::jsonExit([
'img' => Theme::getScreenshot($theme),
'desc' => $description,
'version' => $version,
namespace Friendica\Module\WellKnown;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\DI;
/**
]
];
- header('Content-type: application/json; charset=utf-8');
- echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
- exit;
+ System::jsonExit($nodeinfo);
}
}
namespace Friendica\Module\WellKnown;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Search;
use Friendica\Protocol\Relay;
$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);
}
}
}
$tempfile = tempnam(System::getTempPath(), $file);
- file_put_contents($tempfile, json_encode(['activity' => $activity, 'body' => $body, 'uid' => $uid, 'trust_source' => $trust_source, 'push' => $push, 'signer' => $signer, 'object_data' => $object_data], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
+ file_put_contents($tempfile, json_encode(['activity' => $activity, 'body' => $body, 'uid' => $uid, 'trust_source' => $trust_source, 'push' => $push, 'signer' => $signer, 'object_data' => $object_data], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
Logger::notice('Unknown activity stored', ['type' => $type, 'object_type' => $object_data['object_type'], $object_data['object_object_type'] ?? '', 'file' => $tempfile]);
}