- /**
- * Get user info array.
- *
- * @param int|string $contact_id Contact ID or URL
- * @return array|bool
- * @throws HTTPException\BadRequestException
- * @throws HTTPException\InternalServerErrorException
- * @throws HTTPException\UnauthorizedException
- * @throws \ImagickException
- */
- protected static function getUser($contact_id = null)
- {
- return api_get_user($contact_id);
- }
-
- /**
- * 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 string $format Output format (xml, json, rss, atom)
- * @return false|string
- */
- protected static function exit(string $root_element, array $data, string $format = null)
- {
- $format = $format ?? 'json';
-
- $return = self::formatData($root_element, $format, $data);
-
- switch ($format) {
- case 'xml':
- header('Content-Type: text/xml');
- break;
- case 'json':
- header('Content-Type: application/json');
- if (!empty($return)) {
- $json = json_encode(end($return));
- if (!empty($_GET['callback'])) {
- $json = $_GET['callback'] . '(' . $json . ')';
- }
- $return = $json;
- }
- break;
- case 'rss':
- header('Content-Type: application/rss+xml');
- $return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
- break;
- case 'atom':
- header('Content-Type: application/atom+xml');
- $return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
- break;
- }
-
- echo $return;
- exit;
- }
-
- /**
- * Formats the data according to the data type
- *
- * @param string $root_element Name of the root element
- * @param string $type Return type (atom, rss, xml, json)
- * @param array $data JSON style array
- *
- * @return array|string (string|array) XML data or JSON data
- */
- public static function formatData($root_element, string $type, array $data)