aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--action.php22
-rw-r--r--engine/lib/api.php104
-rw-r--r--engine/lib/elgglib.php2
-rw-r--r--views/default/api/output.php46
-rw-r--r--views/json/api/output.php19
-rw-r--r--views/json/pageshells/pageshell.php15
-rw-r--r--views/php/api/output.php19
-rw-r--r--views/php/pageshells/pageshell.php15
-rw-r--r--views/xml/api/output.php19
-rw-r--r--views/xml/pageshells/pageshell.php16
10 files changed, 156 insertions, 121 deletions
diff --git a/action.php b/action.php
deleted file mode 100644
index 4e6569242..000000000
--- a/action.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
- /**
- * Elgg action handler
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
-
- /**
- * Load searunner framework
- */
- require_once(dirname(__FILE__) . "/engine/start.php");
-
- $action = get_input("action");
- action($action);
-
-?> \ No newline at end of file
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)
+ ))
);
}
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 6edc41fbd..10a2ebb25 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -777,7 +777,7 @@
* @param array $vars An array that points to the active symbol table at the point that the error occurred
*/
function __elgg_php_error_handler($errno, $errmsg, $filename, $linenum, $vars)
- {
+ {
$error = date("Y-m-d H:i:s (T)") . ": \"" . $errmsg . "\" in file " . $filename . " (line " . $linenum . ")";
switch ($errno) {
diff --git a/views/default/api/output.php b/views/default/api/output.php
new file mode 100644
index 000000000..70246e181
--- /dev/null
+++ b/views/default/api/output.php
@@ -0,0 +1,46 @@
+<?php
+ /**
+ * Elgg API default output
+ * This outputs the api in a human readable way.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ $result = $vars['result'];
+ $export = $result->export();
+
+?>
+<div id="api_result">
+ <table width="100%">
+ <tr><td width="100" valign="top"><b>Status:</b></td> <td>
+ <?php
+ if ($result instanceof SuccessResult)
+ echo "OK";
+ else
+ echo "**** ERROR ({$export->status}) ****";
+ ?>
+ </td></tr>
+
+ <?php if ($export->message!="") { ?>
+ <tr><td width="100" valign="top"><b>Message:</b></td> <td><?php echo $export->message; ?></td></tr>
+ <?php } ?>
+ <?php if ($export->result) { ?>
+ <tr><td width="100" valign="top"><b>Result:</b></td> <td><pre><?php print_r($export->result); ?></pre></td></tr>
+ <?php } ?>
+
+
+ <?php if ($export->pam) { ?>
+ <tr><td width="100" valign="top"><b>PAM:</b></td> <td><pre><?php print_r($export->pam); ?></pre></td></tr>
+ <?php } ?>
+
+ <?php if ($export->runtime_errors) { ?>
+ <tr><td width="100" valign="top"><b>Runtime:</b></td> <td><pre><?php print_r($export->runtime_errors); ?></pre></td></tr>
+ <?php } ?>
+ </table>
+</div> \ No newline at end of file
diff --git a/views/json/api/output.php b/views/json/api/output.php
new file mode 100644
index 000000000..84e0d1ec3
--- /dev/null
+++ b/views/json/api/output.php
@@ -0,0 +1,19 @@
+<?php
+ /**
+ * Elgg JSON output
+ * This outputs the api as JSON
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ $result = $vars['result'];
+ $export = $result->export();
+
+ echo json_encode($export);
+?> \ No newline at end of file
diff --git a/views/json/pageshells/pageshell.php b/views/json/pageshells/pageshell.php
new file mode 100644
index 000000000..5c01e030b
--- /dev/null
+++ b/views/json/pageshells/pageshell.php
@@ -0,0 +1,15 @@
+<?php
+ /**
+ * Elgg JSON output pageshell
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ echo $vars['body'];
+?> \ No newline at end of file
diff --git a/views/php/api/output.php b/views/php/api/output.php
new file mode 100644
index 000000000..6d1edcb05
--- /dev/null
+++ b/views/php/api/output.php
@@ -0,0 +1,19 @@
+<?php
+ /**
+ * Elgg PHP output
+ * This outputs the api as PHP
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ $result = $vars['result'];
+ $export = $result->export();
+
+ echo serialize($export);
+?> \ No newline at end of file
diff --git a/views/php/pageshells/pageshell.php b/views/php/pageshells/pageshell.php
new file mode 100644
index 000000000..30747720f
--- /dev/null
+++ b/views/php/pageshells/pageshell.php
@@ -0,0 +1,15 @@
+<?php
+ /**
+ * Elgg PHP output pageshell
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ echo $vars['body'];
+?> \ No newline at end of file
diff --git a/views/xml/api/output.php b/views/xml/api/output.php
new file mode 100644
index 000000000..aa385c9e3
--- /dev/null
+++ b/views/xml/api/output.php
@@ -0,0 +1,19 @@
+<?php
+ /**
+ * Elgg XML output
+ * This outputs the api as XML
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ $result = $vars['result'];
+ $export = $result->export();
+
+ echo serialise_object_to_xml($export, "elgg");
+?> \ No newline at end of file
diff --git a/views/xml/pageshells/pageshell.php b/views/xml/pageshells/pageshell.php
new file mode 100644
index 000000000..f5c7a4ce0
--- /dev/null
+++ b/views/xml/pageshells/pageshell.php
@@ -0,0 +1,16 @@
+<?php
+ /**
+ * Elgg XML output pageshell
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ header("Content-Type: text/xml");
+ echo $vars['body'];
+?> \ No newline at end of file