]> git.mxchange.org Git - friendica.git/commitdiff
Using the "extension" parameter
authorMichael <heluecht@pirati.ca>
Tue, 9 Nov 2021 19:40:39 +0000 (19:40 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 9 Nov 2021 19:40:39 +0000 (19:40 +0000)
src/Module/Api/Friendica/Events/Index.php
src/Module/Api/Friendica/GNUSocial/Version.php
src/Module/Api/Friendica/Help/Test.php
src/Module/Api/Friendica/Profile/Show.php
src/Module/BaseApi.php

index ec8cc077aebbedd7321fd84a8e54ecc8099cea9a..b0ca78ac9e38d02b5ba409b696aa85d2299d49a0 100644 (file)
@@ -70,6 +70,6 @@ class Index extends BaseApi
                        ];
                }
 
-               self::exit('events', ['events' => $items]);
+               self::exit('events', ['events' => $items], $parameters['extension'] ?? null);
        }
 }
index 83949de7b793215674650cae2d0c4317e751dbd6..121b5717976ae959ba461e8a19dcff0514d9d404 100644 (file)
@@ -30,6 +30,6 @@ class Version extends BaseApi
 {
        public static function rawContent(array $parameters = [])
        {
-               self::exit('version', ['version' => '0.9.7']);
+               self::exit('version', ['version' => '0.9.7'], $parameters['extension'] ?? null);
        }
 }
index 394c5e4830ac91f89e335ada11db3543938347ae..244e9f2e572083db8ba0da009968dd5d13239279 100644 (file)
@@ -30,12 +30,12 @@ class Test extends BaseApi
 {
        public static function rawContent(array $parameters = [])
        {
-               if (self::$format == 'xml') {
+               if (!empty($parameters['extension']) && ($parameters['extension'] == 'xml')) {
                        $ok = 'true';
                } else {
                        $ok = 'ok';
                }
 
-               self::exit('ok', ['ok' => $ok]);
+               self::exit('ok', ['ok' => $ok], $parameters['extension'] ?? null);
        }
 }
index 67dcfdb6e75a9996f8c164c007ab49f70fd97f40..18671e0dd5478dac5e8c8aaa77cbf2abd1380100 100644 (file)
@@ -50,7 +50,7 @@ class Show extends BaseApi
                $profile = self::formatProfile($profile, $profileFields);
 
                $profiles = [];
-               if (self::$format == 'xml') {
+               if (!empty($parameters['extension']) && ($parameters['extension'] == 'xml')) {
                        $profiles['0:profile'] = $profile;
                } else {
                        $profiles[] = $profile;
@@ -66,7 +66,7 @@ class Show extends BaseApi
                        'profiles' => $profiles
                ];
 
-               self::exit('friendica_profiles', ['$result' => $result]);
+               self::exit('friendica_profiles', ['$result' => $result], $parameters['extension'] ?? null);
        }
 
        /**
index 75ee9ca29a7a756028b4ab43df69c4a93adfd329..a7a0688ef43adb79b0e40828f539c93293d70a7d 100644 (file)
@@ -43,11 +43,6 @@ class BaseApi extends BaseModule
        const SCOPE_FOLLOW = 'follow';
        const SCOPE_PUSH   = 'push';
 
-       /**
-        * @var string json|xml|rss|atom
-        */
-       protected static $format = 'json';
-
        /**
         * @var array
         */
@@ -60,17 +55,6 @@ class BaseApi extends BaseModule
 
        public static function init(array $parameters = [])
        {
-               $arguments = DI::args();
-
-               if (substr($arguments->getCommand(), -4) === '.xml') {
-                       self::$format = 'xml';
-               }
-               if (substr($arguments->getCommand(), -4) === '.rss') {
-                       self::$format = 'rss';
-               }
-               if (substr($arguments->getCommand(), -4) === '.atom') {
-                       self::$format = 'atom';
-               }
        }
 
        public static function delete(array $parameters = [])
@@ -351,14 +335,17 @@ class BaseApi extends BaseModule
         * Outputs formatted data according to the data type and then exits the execution.
         *
         * @param string $root_element
-        * @param array $data An array with a single element containing the returned result
+        * @param array  $data         An array with a single element containing the returned result
+        * @param string $format       Output format (xml, json, rss, atom)
         * @return false|string
         */
-       protected static function exit(string $root_element, array $data)
+       protected static function exit(string $root_element, array $data, string $format = null)
        {
-               $return = self::formatData($root_element, self::$format, $data);
+               $format = $format ?? 'json';
+
+               $return = self::formatData($root_element, $format, $data);
 
-               switch (self::$format) {
+               switch ($format) {
                        case 'xml':
                                header('Content-Type: text/xml');
                                break;