aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/api/rest.php113
-rw-r--r--services/export/handler.php218
2 files changed, 161 insertions, 170 deletions
diff --git a/services/api/rest.php b/services/api/rest.php
index 5e99d58b7..dfa6cd3a5 100644
--- a/services/api/rest.php
+++ b/services/api/rest.php
@@ -1,58 +1,59 @@
<?php
- /**
- * Rest endpoint.
- * The API REST endpoint.
- *
- * @package Elgg
- * @subpackage API
- * @author Curverider Ltd <info@elgg.com>
- * @link http://elgg.org/
- */
-
- /**
- * Start the Elgg engine
- */
- require_once("../../engine/start.php");
- global $CONFIG;
-
- // Register the error handler
- error_reporting(E_ALL);
- set_error_handler('__php_api_error_handler');
-
- // Register a default exception handler
- set_exception_handler('__php_api_exception_handler');
-
- // Check to see if the api is available
- if ((isset($CONFIG->disable_api)) && ($CONFIG->disable_api == true))
- throw new SecurityException(elgg_echo('SecurityException:APIAccessDenied'));
-
- // Register some default PAM methods, plugins can add their own
- register_pam_handler('pam_auth_session_or_hmac'); // Command must either be authenticated by a hmac or the user is already logged in
- register_pam_handler('pam_auth_usertoken', 'required'); // Either token present and valid OR method doesn't require one.
- register_pam_handler('pam_auth_anonymous_method'); // Support anonymous functions
-
- // Get parameter variables
- $method = get_input('method');
- $result = null;
-
- // Authenticate session
- if (pam_authenticate())
- {
- // Authenticated somehow, now execute.
- $token = "";
- $params = get_parameters_for_method($method); // Use $CONFIG->input instead of $_REQUEST since this is called by the pagehandler
- if (isset($params['auth_token'])) $token = $params['auth_token'];
-
- $result = execute_method($method, $params, $token);
+/**
+ * Rest endpoint.
+ * The API REST endpoint.
+ *
+ * @package Elgg
+ * @subpackage API
+ * @author Curverider Ltd <info@elgg.com>
+ * @link http://elgg.org/
+ */
+
+/**
+ * Start the Elgg engine
+ */
+require_once("../../engine/start.php");
+global $CONFIG;
+
+// Register the error handler
+error_reporting(E_ALL);
+set_error_handler('__php_api_error_handler');
+
+// Register a default exception handler
+set_exception_handler('__php_api_exception_handler');
+
+// Check to see if the api is available
+if ((isset($CONFIG->disable_api)) && ($CONFIG->disable_api == true)) {
+ throw new SecurityException(elgg_echo('SecurityException:APIAccessDenied'));
+}
+
+// Register some default PAM methods, plugins can add their own
+register_pam_handler('pam_auth_session_or_hmac'); // Command must either be authenticated by a hmac or the user is already logged in
+register_pam_handler('pam_auth_usertoken', 'required'); // Either token present and valid OR method doesn't require one.
+register_pam_handler('pam_auth_anonymous_method'); // Support anonymous functions
+
+// Get parameter variables
+$method = get_input('method');
+$result = null;
+
+// Authenticate session
+if (pam_authenticate()) {
+ // Authenticated somehow, now execute.
+ $token = "";
+ $params = get_parameters_for_method($method); // Use $CONFIG->input instead of $_REQUEST since this is called by the pagehandler
+ if (isset($params['auth_token'])) {
+ $token = $params['auth_token'];
}
- else
- throw new SecurityException(elgg_echo('SecurityException:NoAuthMethods'));
-
- // Finally output
- if (!($result instanceof GenericResult))
- throw new APIException(elgg_echo('APIException:ApiResultUnknown'));
-
- // Output the result
- page_draw($method, elgg_view("api/output", array("result" => $result)));
-
-?> \ No newline at end of file
+
+ $result = execute_method($method, $params, $token);
+} else {
+ throw new SecurityException(elgg_echo('SecurityException:NoAuthMethods'));
+}
+
+// Finally output
+if (!($result instanceof GenericResult)) {
+ throw new APIException(elgg_echo('APIException:ApiResultUnknown'));
+}
+
+// Output the result
+page_draw($method, elgg_view("api/output", array("result" => $result))); \ No newline at end of file
diff --git a/services/export/handler.php b/services/export/handler.php
index d198149da..4c5391ed2 100644
--- a/services/export/handler.php
+++ b/services/export/handler.php
@@ -1,123 +1,113 @@
<?php
- /**
- * Open Document Definition Handler.
- * This file acts as the endpoint for ODD UUID url requests, exporting the requested data as an
- * OpenDD XML file.
- *
- * @package Elgg
- * @subpackage Core
- * @author Curverider Ltd
- * @link http://elgg.org/
- */
-
- require_once("../../engine/start.php");
-
- // Get input values, these will be mapped via modrewrite
- $guid = get_input("guid"); // guid of the entity
-
- // For attributes eg http://example.com/odd/73/attr/owner_uuid/ or http://example.com/odd/73/metadata/86/
- $type = get_input("type"); // attr, metadata, annotation, rekationship
- $id_or_name = get_input("idname"); // Either a number or the key name (if attribute)
-
-
- $body = "";
- $title = "";
-
- // Only export the GUID
- if (
- ($guid!="") &&
- ($type=="") &&
- ($id_or_name=="")
- )
- {
- $entity = get_entity($guid);
-
- if (!$entity)
- throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:GUIDNotFound'), $guid));
-
- $title = "GUID:$guid";
- $body = elgg_view("export/entity", array("entity" => $entity, "uuid" => guid_to_uuid($guid)));
+/**
+ * Open Document Definition Handler.
+ * This file acts as the endpoint for ODD UUID url requests, exporting the requested data as an
+ * OpenDD XML file.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+
+require_once("../../engine/start.php");
+
+// Get input values, these will be mapped via modrewrite
+$guid = get_input("guid"); // guid of the entity
+
+// For attributes eg http://example.com/odd/73/attr/owner_uuid/ or http://example.com/odd/73/metadata/86/
+$type = get_input("type"); // attr, metadata, annotation, rekationship
+$id_or_name = get_input("idname"); // Either a number or the key name (if attribute)
+
+$body = "";
+$title = "";
+
+// Only export the GUID
+if (($guid!="") && ($type=="") && ($id_or_name=="")) {
+ $entity = get_entity($guid);
+
+ if (!$entity) {
+ throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:GUIDNotFound'), $guid));
}
-
- // Export an individual attribute
- else if (
- ($guid!="") &&
- ($type!="") &&
- ($id_or_name!="")
- )
- {
- // Get a uuid
- $entity = get_entity($guid);
- if (!$entity)
- throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:GUIDNotFound'), $guid));
-
- $uuid = guid_to_uuid($entity->getGUID()) . "$type/$id_or_name/";
-
- switch ($type)
- {
- case 'attr' : // TODO: Do this better? - This is a bit of a hack...
- $v = $entity->get($id_or_name);
- if (!$v) throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:IdNotExistForGUID'), $id_or_name, $guid));
-
- $m = new ElggMetadata();
-
- $m->value = $v;
- $m->name = $id_or_name;
- $m->entity_guid = $guid;
- $m->time_created = $entity->time_created;
- $m->time_updated = $entity->time_updated;
- $m->owner_guid = $entity->owner_guid;
- $m->id = $id_or_name;
- $m->type = "attr";
+
+ $title = "GUID:$guid";
+ $body = elgg_view("export/entity", array("entity" => $entity, "uuid" => guid_to_uuid($guid)));
+}
+
+// Export an individual attribute
+else if (($guid!="") && ($type!="") && ($id_or_name!="")) {
+ // Get a uuid
+ $entity = get_entity($guid);
+ if (!$entity) {
+ throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:GUIDNotFound'), $guid));
+ }
+
+ $uuid = guid_to_uuid($entity->getGUID()) . "$type/$id_or_name/";
+
+ switch ($type) {
+ case 'attr' : // TODO: Do this better? - This is a bit of a hack...
+ $v = $entity->get($id_or_name);
+ if (!$v) {
+ throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:IdNotExistForGUID'), $id_or_name, $guid));
+ }
+
+ $m = new ElggMetadata();
+
+ $m->value = $v;
+ $m->name = $id_or_name;
+ $m->entity_guid = $guid;
+ $m->time_created = $entity->time_created;
+ $m->time_updated = $entity->time_updated;
+ $m->owner_guid = $entity->owner_guid;
+ $m->id = $id_or_name;
+ $m->type = "attr";
break;
- case 'metadata' :
- $m = get_metadata($id_or_name);
+ case 'metadata' :
+ $m = get_metadata($id_or_name);
break;
- case 'annotation' :
- $m = get_annotation($id_or_name);
- break;
- case 'relationship' :
- $r = get_relationship($id_or_name);
+ case 'annotation' :
+ $m = get_annotation($id_or_name);
break;
- case 'volatile' :
- $m = trigger_plugin_hook('volatile', 'metadata', array('guid' => $guid, 'varname' => $id_or_name));
+ case 'relationship' :
+ $r = get_relationship($id_or_name);
break;
-
- default :
- throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:CanNotExportType'), $type));
- }
-
- // Render metadata or relationship
- if ((!$m) && (!$r))
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:NoDataFound'));
-
- // Exporting metadata?
- if ($m)
- {
- if ($m->entity_guid!=$entity->guid)
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:DoesNotBelong'));
-
- $title = "$type:$id_or_name";
- $body = elgg_view("export/metadata", array("metadata" => $m, "uuid" => $uuid));
+ case 'volatile' :
+ $m = trigger_plugin_hook('volatile', 'metadata', array('guid' => $guid, 'varname' => $id_or_name));
+ break;
+
+ default :
+ throw new InvalidParameterException(sprintf(elgg_echo('InvalidParameterException:CanNotExportType'), $type));
+ }
+
+ // Render metadata or relationship
+ if ((!$m) && (!$r)) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:NoDataFound'));
+ }
+
+ // Exporting metadata?
+ if ($m) {
+ if ($m->entity_guid!=$entity->guid) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:DoesNotBelong'));
}
-
- // Exporting relationship
- if ($r)
- {
- if (
- ($r->guid_one!=$entity->guid) &&
- ($r->guid_two!=$entity->guid)
- )
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:DoesNotBelongOrRefer'));
-
- $title = "$type:$id_or_name";
- $body = elgg_view("export/relationship", array("relationship" => $r, "uuid" => $uuid));
+
+ $title = "$type:$id_or_name";
+ $body = elgg_view("export/metadata", array("metadata" => $m, "uuid" => $uuid));
+ }
+
+ // Exporting relationship
+ if ($r) {
+ if (($r->guid_one!=$entity->guid) && ($r->guid_two!=$entity->guid)) {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:DoesNotBelongOrRefer'));
}
+
+ $title = "$type:$id_or_name";
+ $body = elgg_view("export/relationship", array("relationship" => $r, "uuid" => $uuid));
}
-
- // Something went wrong
- else
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:MissingParameter'));
-
- page_draw($title, elgg_view_layout('one_column',elgg_view_title($title) . $body));
-?> \ No newline at end of file
+}
+
+// Something went wrong
+else {
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:MissingParameter'));
+}
+
+page_draw($title, elgg_view_layout('one_column',elgg_view_title($title) . $body)); \ No newline at end of file