namespace Friendica\Module\Api;
use Friendica\App\Arguments;
+use Friendica\App\BaseURL;
use Friendica\Core\L10n;
-use Friendica\Module\BaseApi;
use Friendica\Util\Arrays;
+use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPInputData;
use Friendica\Util\XML;
use Psr\Log\LoggerInterface;
+use Friendica\Factory\Api\Twitter\User as TwitterUser;
/**
* This class is used to format and return API responses
* @param Arguments $args
* @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->args = $args;
- $this->logger = $logger;
+ $this->l10n = $l10n;
+ $this->args = $args;
+ $this->logger = $logger;
+ $this->baseurl = $baseurl;
+ $this->twitterUser = $twitteruser;
}
/**
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
*
{
switch ($type) {
case 'rss':
- $data = BaseApi::addRSSValues($data, $cid);
+ $data = $this->addRSSValues($data, $cid);
case 'atom':
case 'xml':
return $this->createXML($data, $root_element);
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;
- }
}