function moved

This commit is contained in:
Michael 2021-11-21 09:55:42 +00:00
parent bfddf14b6b
commit 0e5f876680
2 changed files with 39 additions and 35 deletions

View File

@ -3,12 +3,14 @@
namespace Friendica\Module\Api; namespace Friendica\Module\Api;
use Friendica\App\Arguments; use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Module\BaseApi;
use Friendica\Util\Arrays; use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPInputData; use Friendica\Util\HTTPInputData;
use Friendica\Util\XML; use Friendica\Util\XML;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Friendica\Factory\Api\Twitter\User as TwitterUser;
/** /**
* This class is used to format and return API responses * This class is used to format and return API responses
@ -27,11 +29,13 @@ class ApiResponse
* @param Arguments $args * @param Arguments $args
* @param LoggerInterface $logger * @param LoggerInterface $logger
*/ */
public function __construct(L10n $l10n, Arguments $args, LoggerInterface $logger) public function __construct(L10n $l10n, Arguments $args, LoggerInterface $logger, BaseURL $baseurl, TwitterUser $twitteruser)
{ {
$this->l10n = $l10n; $this->l10n = $l10n;
$this->args = $args; $this->args = $args;
$this->logger = $logger; $this->logger = $logger;
$this->baseurl = $baseurl;
$this->twitterUser = $twitteruser;
} }
/** /**
@ -103,6 +107,35 @@ class ApiResponse
return XML::fromArray($data3, $xml, false, $namespaces); return XML::fromArray($data3, $xml, false, $namespaces);
} }
/**
* Set values for RSS template
*
* @param array $arr Array to be passed to template
* @param int $cid Contact ID of template
* @return array
*/
private function addRSSValues(array $arr, int $cid)
{
if (empty($cid)) {
return $arr;
}
$user_info = $this->twitterUser->createFromContactId($cid)->toArray();
$arr['$user'] = $user_info;
$arr['$rss'] = [
'alternate' => $user_info['url'],
'self' => $this->baseurl . '/' . $this->args->getQueryString(),
'base' => $this->baseurl,
'updated' => DateTimeFormat::utc(null, DateTimeFormat::API),
'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'language' => $user_info['lang'],
'logo' => $this->baseurl . '/images/friendica-32.png',
];
return $arr;
}
/** /**
* Formats the data according to the data type * Formats the data according to the data type
* *
@ -117,7 +150,7 @@ class ApiResponse
{ {
switch ($type) { switch ($type) {
case 'rss': case 'rss':
$data = BaseApi::addRSSValues($data, $cid); $data = $this->addRSSValues($data, $cid);
case 'atom': case 'atom':
case 'xml': case 'xml':
return $this->createXML($data, $root_element); return $this->createXML($data, $root_element);

View File

@ -314,33 +314,4 @@ class BaseApi extends BaseModule
return $cid; return $cid;
} }
/**
* Set values for RSS template
*
* @param array $arr Array to be passed to template
* @param int $cid Contact ID of template
* @return array
*/
public static function addRSSValues(array $arr, int $cid)
{
if (empty($cid)) {
return $arr;
}
$user_info = DI::twitterUser()->createFromContactId($cid)->toArray();
$arr['$user'] = $user_info;
$arr['$rss'] = [
'alternate' => $user_info['url'],
'self' => DI::baseUrl() . '/' . DI::args()->getQueryString(),
'base' => DI::baseUrl(),
'updated' => DateTimeFormat::utc(null, DateTimeFormat::API),
'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'language' => $user_info['lang'],
'logo' => DI::baseUrl() . '/images/friendica-32.png',
];
return $arr;
}
} }