Using the "extension" parameter
This commit is contained in:
parent
b4fc1da045
commit
a6db8df92d
5 changed files with 13 additions and 26 deletions
|
@ -70,6 +70,6 @@ class Index extends BaseApi
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
self::exit('events', ['events' => $items]);
|
self::exit('events', ['events' => $items], $parameters['extension'] ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,6 @@ class Version extends BaseApi
|
||||||
{
|
{
|
||||||
public static function rawContent(array $parameters = [])
|
public static function rawContent(array $parameters = [])
|
||||||
{
|
{
|
||||||
self::exit('version', ['version' => '0.9.7']);
|
self::exit('version', ['version' => '0.9.7'], $parameters['extension'] ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,12 @@ class Test extends BaseApi
|
||||||
{
|
{
|
||||||
public static function rawContent(array $parameters = [])
|
public static function rawContent(array $parameters = [])
|
||||||
{
|
{
|
||||||
if (self::$format == 'xml') {
|
if (!empty($parameters['extension']) && ($parameters['extension'] == 'xml')) {
|
||||||
$ok = 'true';
|
$ok = 'true';
|
||||||
} else {
|
} else {
|
||||||
$ok = 'ok';
|
$ok = 'ok';
|
||||||
}
|
}
|
||||||
|
|
||||||
self::exit('ok', ['ok' => $ok]);
|
self::exit('ok', ['ok' => $ok], $parameters['extension'] ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Show extends BaseApi
|
||||||
$profile = self::formatProfile($profile, $profileFields);
|
$profile = self::formatProfile($profile, $profileFields);
|
||||||
|
|
||||||
$profiles = [];
|
$profiles = [];
|
||||||
if (self::$format == 'xml') {
|
if (!empty($parameters['extension']) && ($parameters['extension'] == 'xml')) {
|
||||||
$profiles['0:profile'] = $profile;
|
$profiles['0:profile'] = $profile;
|
||||||
} else {
|
} else {
|
||||||
$profiles[] = $profile;
|
$profiles[] = $profile;
|
||||||
|
@ -66,7 +66,7 @@ class Show extends BaseApi
|
||||||
'profiles' => $profiles
|
'profiles' => $profiles
|
||||||
];
|
];
|
||||||
|
|
||||||
self::exit('friendica_profiles', ['$result' => $result]);
|
self::exit('friendica_profiles', ['$result' => $result], $parameters['extension'] ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,11 +43,6 @@ class BaseApi extends BaseModule
|
||||||
const SCOPE_FOLLOW = 'follow';
|
const SCOPE_FOLLOW = 'follow';
|
||||||
const SCOPE_PUSH = 'push';
|
const SCOPE_PUSH = 'push';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string json|xml|rss|atom
|
|
||||||
*/
|
|
||||||
protected static $format = 'json';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -60,17 +55,6 @@ class BaseApi extends BaseModule
|
||||||
|
|
||||||
public static function init(array $parameters = [])
|
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 = [])
|
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.
|
* Outputs formatted data according to the data type and then exits the execution.
|
||||||
*
|
*
|
||||||
* @param string $root_element
|
* @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
|
* @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';
|
||||||
|
|
||||||
switch (self::$format) {
|
$return = self::formatData($root_element, $format, $data);
|
||||||
|
|
||||||
|
switch ($format) {
|
||||||
case 'xml':
|
case 'xml':
|
||||||
header('Content-Type: text/xml');
|
header('Content-Type: text/xml');
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue