]> git.mxchange.org Git - friendica.git/commitdiff
function moved
authorMichael <heluecht@pirati.ca>
Sun, 21 Nov 2021 09:55:42 +0000 (09:55 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 21 Nov 2021 09:55:42 +0000 (09:55 +0000)
src/Module/Api/ApiResponse.php
src/Module/BaseApi.php

index 8d48126596e5071388306506d03d24c6e64295fa..b2d17f7fb20106728db0864df7bcde5e7dfee1a5 100644 (file)
@@ -3,12 +3,14 @@
 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
@@ -27,11 +29,13 @@ class ApiResponse
         * @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;
        }
 
        /**
@@ -103,6 +107,35 @@ class ApiResponse
                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
         *
@@ -117,7 +150,7 @@ class ApiResponse
        {
                switch ($type) {
                        case 'rss':
-                               $data = BaseApi::addRSSValues($data, $cid);
+                               $data = $this->addRSSValues($data, $cid);
                        case 'atom':
                        case 'xml':
                                return $this->createXML($data, $root_element);
index c097a5826937b4125d51d836052f279b8330f22b..eaefdd0bdf917b94f6f2e1b4e90aaa7b90418470 100644 (file)
@@ -314,33 +314,4 @@ class BaseApi extends BaseModule
 
                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;
-       }
 }