aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/api.php
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-25 11:40:46 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-25 11:40:46 +0000
commit347b09527e5d812cd1ed67d6faa4ce0cba259b09 (patch)
tree32b636ea8502bcf4a5abbbbb7f3e819084a63131 /engine/lib/api.php
parent0c1b67ac3cf61daac65c15f43306ecc4d027fbdd (diff)
downloadelgg-347b09527e5d812cd1ed67d6faa4ce0cba259b09.tar.gz
elgg-347b09527e5d812cd1ed67d6faa4ce0cba259b09.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* git-svn-id: https://code.elgg.org/elgg/trunk@526 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/api.php')
-rw-r--r--engine/lib/api.php104
1 files changed, 6 insertions, 98 deletions
diff --git a/engine/lib/api.php b/engine/lib/api.php
index 14e875a77..6ce5bd29c 100644
--- a/engine/lib/api.php
+++ b/engine/lib/api.php
@@ -20,7 +20,7 @@
* @package Elgg
* @subpackage Core
*/
- abstract class GenericResult implements Exportable
+ abstract class GenericResult
{
/**
* The status of the result.
@@ -85,7 +85,7 @@
*/
public function export()
{
- global $ERRORS, $CONFIG, $PAM_HANDLER_MSG;
+ global $ERRORS, $CONFIG, $_PAM_HANDLERS_MSG;
$result = new stdClass;
@@ -680,97 +680,6 @@
return false;
}
- // Output functions ///////////////////////////////////////////////////////////////////////
-
- $API_OUTPUT_FUNCTIONS = array();
-
- /**
- * Register an API output handler.
- * This function is used by the system and the plugins to register an output encoding method for
- * returning API results.
- *
- * @param string $form The format string, eg 'xml' or 'php'
- * @param string $function The function, which must be in the format function_name(stdClass $result) and return a string.
- * @return bool
- */
- function register_api_outputhandler($form, $function)
- {
- global $API_OUTPUT_FUNCTIONS;
-
- if ( ($form!="") && ($function!=""))
- {
- $API_OUTPUT_FUNCTIONS[$form] = $function;
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Output the result, with the given fault.
- *
- * @param GenericResult $result Result object.
- * @param string $format The format
- * @return string
- */
- function output_result(GenericResult $result, $format)
- {
- global $API_OUTPUT_FUNCTIONS;
-
- if (
- (array_key_exists($format, $API_OUTPUT_FUNCTIONS)) &&
- (is_callable($API_OUTPUT_FUNCTIONS[$format]))
- )
- return $API_OUTPUT_FUNCTIONS[$format]($result->export());
-
- // We got here, so no output format was found. Output an error
- $result = print_r($result->export(), true);
-
- return <<< END
-<html>
-<head><title>Something went wrong...</title></head>
-<body>
- <h1>API Output Error</h1>
- <p>Something went badly wrong while outputting the result of your request in '$format' format. The result and any errors are displayed in
- raw text below.</p>
- <pre>
-$result
-</pre>
-</body>
-</html>
-END;
- }
-
-
- function xml_result_handler(stdClass $result)
- {
- header("Content-Type: text/xml");
- return serialise_object_to_xml($result, "elgg");
- }
-
- function php_result_handler(stdClass $result)
- {
- return serialize($result);
- }
-
- function json_result_handler(stdClass $result)
- {
- return json_encode($result);
- }
-
- function csv_result_handler(stdClass $result)
- {
- throw new NotImplementedException("CSV View currently not implemented");
- }
-
- // Register some format handlers
- register_api_outputhandler('xml', 'xml_result_handler');
- register_api_outputhandler('php', 'php_result_handler');
- register_api_outputhandler('json', 'json_result_handler');
- register_api_outputhandler('csv', 'csv_result_handler');
-
-
// Error handler functions ////////////////////////////////////////////////////////////////
/** Define a global array of errors */
@@ -825,13 +734,12 @@ END;
error_log("*** FATAL EXCEPTION (API) *** : " . $exception);
- echo output_result(
- ErrorResult::getInstance(
+ page_draw($exception->getMessage(), elgg_view("api/output",
+ array('result' => ErrorResult::getInstance(
$exception->getMessage(),
$exception->getCode() == 0 ? ErrorResult::$RESULT_FAIL : $exception->getCode(),
- $exception),
-
- get_input('format','php') // Attempt to get the requested format if passed.
+ $exception)
+ ))
);
}