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;
// 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;
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;
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;
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);
}
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Module\Response;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML;
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') {
System::jsonExit($ret);
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
+use Friendica\Core\System;
use Friendica\Core\Theme;
+use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Util\Network;
use Friendica\Util\Strings;
}
if ($_GET["mode"] == "raw") {
- header("Content-type: text/html; charset=utf-8");
-
- echo substr($target->saveHTML(), 6, -8);
-
- exit();
+ System::httpExit(substr($target->saveHTML(), 6, -8), Response::TYPE_HTML);
}
}
* @param string $content Response body. Optional.
* @throws \Exception
*/
- public static function httpExit($val, $message = '', $content = '')
+ public static function httpError($httpCode, $message = '', $content = '')
{
- if ($val >= 400) {
- Logger::debug('Exit with error', ['code' => $val, 'message' => $message, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
+ if ($httpCode >= 400) {
+ Logger::debug('Exit with error', ['code' => $httpCode, 'message' => $message, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
}
- DI::apiResponse()->setStatus($val, $message);
+ DI::apiResponse()->setStatus($httpCode, $message);
DI::apiResponse()->addContent($content);
DI::page()->exit(DI::apiResponse()->generate());
exit();
}
- public static function jsonError($httpCode, $data, $content_type = 'application/json')
+ /**
+ * This function adds the content and a content-teype HTTP header to the output.
+ * After finishing the process is getting killed.
+ *
+ * @param string $content
+ * @param [type] $responce
+ * @param string|null $content_type
+ * @return void
+ */
+ public static function httpExit(string $content, string $responce = Response::TYPE_HTML, ?string $content_type = null) {
+ DI::apiResponse()->setType($responce, $content_type);
+ DI::apiResponse()->addContent($content);
+ DI::page()->exit(DI::apiResponse()->generate());
+ exit();
+ }
+
+ public static function jsonError($httpCode, $content, $content_type = 'application/json')
{
if ($httpCode >= 400) {
Logger::debug('Exit with error', ['code' => $httpCode, 'content_type' => $content_type, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
}
DI::apiResponse()->setStatus($httpCode);
- self::jsonExit($data, $content_type);
+ self::jsonExit($content, $content_type);
}
/**
* and adds an application/json HTTP header to the output.
* After finishing the process is getting killed.
*
- * @param mixed $x The input content
+ * @param mixed $content The input content
* @param string $content_type Type of the input (Default: 'application/json')
* @param integer $options JSON options
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function jsonExit($x, $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) {
+ public static function jsonExit($content, $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::apiResponse()->addContent(json_encode($content, $options));
DI::page()->exit(DI::apiResponse()->generate());
exit();
}
namespace Friendica\Module\DFRN;
use Friendica\BaseModule;
+use Friendica\Core\System;
+use Friendica\Module\Response;
use Friendica\Protocol\OStatus;
/**
{
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);
}
}
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;
$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');
}
}
namespace Friendica\Module;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\DI;
use Friendica\Protocol\Feed as ProtocolFeed;
{
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
$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);
}
}
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]);
}
use DOMDocument;
use DOMElement;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\DI;
use Friendica\Util\XML;
*/
protected function rawContent(array $request = [])
{
- header('Content-type: application/opensearchdescription+xml');
-
$hostname = DI::baseUrl()->getHostname();
$baseUrl = DI::baseUrl()->get();
'template' => "$baseUrl/opensearch",
]);
- echo $xml->saveXML();
-
- exit();
+ System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
}
}
namespace Friendica\Module;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\User;
use Friendica\Network\HTTPException\BadRequestException;
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');
}
}
namespace Friendica\Module;
use Friendica\BaseModule;
+use Friendica\Core\System;
use Friendica\DI;
use Friendica\Util\XML;
{
protected function rawContent(array $request = [])
{
- header('Content-Type: text/xml');
-
$xml = null;
- echo XML::fromArray([
+ $content = XML::fromArray([
'rsd' => [
'@attributes' => [
'version' => '1.0',
],
],
], $xml);
- exit();
+ System::httpExit($content, Response::TYPE_XML);
}
}
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';
$content = Renderer::replaceMacros($tpl, self::getVars($e));
}
- System::httpExit($e->getCode(), $e->getDescription(), $content);
+ System::httpError($e->getCode(), $e->getDescription(), $content);
}
/**
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;
{
$config = DI::config();
- header('Content-type: text/xml');
-
if (!$config->get('system', 'site_pubkey', false)) {
$res = Crypto::newKeypair(1024);
}
$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);
}
}
$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'])) {
$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;
}
}
$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);
{
$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, [
$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);
}
}