From 0e6609ba525892ee16aab648ea583944a51e2f56 Mon Sep 17 00:00:00 2001 From: icewing Date: Fri, 16 May 2008 11:41:39 +0000 Subject: Marcus Povey * Refactored export to services/export for future expansion of other rest style endpoints git-svn-id: https://code.elgg.org/elgg/trunk@648 36083f99-b078-4883-b0ff-0f9b5a30f544 --- export/handler.php | 108 -------------------------------------------- htaccess_dist | 12 ++--- services/export/handler.php | 108 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 114 deletions(-) delete mode 100644 export/handler.php create mode 100644 services/export/handler.php diff --git a/export/handler.php b/export/handler.php deleted file mode 100644 index 2c8643a73..000000000 --- a/export/handler.php +++ /dev/null @@ -1,108 +0,0 @@ - - * @copyright Curverider Ltd 2008 - * @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 - $id_or_name = get_input("idname"); // Either a number or the key name (if attribute) - - - - // Only export the GUID - if ( - ($guid!="") && - ($type=="") && - ($id_or_name=="") - ) - { - page_draw("GUID:$guid", elgg_view("export/entity", array("entity" => get_entity($guid), "uuid" => guid_to_uuid($guid)))); - } - - // Export an individual attribute - else if ( - ($guid!="") && - ($type!="") && - ($id_or_name!="") - ) - { - // Get a uuid - $entity = get_entity($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("Sorry, '$id_or_name' does not exist for guid:$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); - break; - case 'annotation' : - $m = get_annotation($id_or_name); - break; - case 'relationship' : - $r = get_relationship($id_or_name); - break; - - default : - throw new InvalidParameterException("Sorry, I don't know how to export '$type'"); - } - - // Render metadata or relationship - if ((!$m) && (!$r)) - throw new InvalidParameterException("Could not find any data."); - - // Exporting metadata? - if ($m) - { - if ($m->entity_guid!=$entity->guid) - throw new InvalidParameterException("Does not belong to entity."); - - page_draw("$type:$id_or_name", 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("Does not belong to entity or refer to entity."); - - page_draw("$type:$id_or_name", elgg_view("export/relationship", array("relationship" => $r, "uuid" => $uuid))); - } - } - - // Something went wrong - else - throw new InvalidParameterException("Missing parmeter, you need to provide a GUID "); - -?> \ No newline at end of file diff --git a/htaccess_dist b/htaccess_dist index 2e711e82c..10bfb1d5e 100644 --- a/htaccess_dist +++ b/htaccess_dist @@ -10,12 +10,12 @@ RewriteEngine on RewriteRule ^action\/([A-Za-z\_\-\/]+)$ action_handler.php?action=$1 RewriteRule ^actions\/([A-Za-z\_\-\/]+)$ action_handler.php?action=$1 -RewriteRule ^odd\/([0-9]+)\/$ export/handler.php?view=odd&guid=$1 -RewriteRule ^odd\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z]+)\/$ export/handler.php?view=odd&guid=$1&type=$2&idname=$3 -RewriteRule ^php\/([0-9]+)\/$ export/handler.php?view=php&guid=$1 -RewriteRule ^php\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z]+)\/$ export/handler.php?view=php&guid=$1&type=$2&idname=$3 -RewriteRule ^json\/([0-9]+)\/$ export/handler.php?view=json&guid=$1 -RewriteRule ^json\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z]+)\/$ export/handler.php?view=json&guid=$1&type=$2&idname=$3 +RewriteRule ^odd\/([0-9]+)\/$ services/export/handler.php?view=odd&guid=$1 +RewriteRule ^odd\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z]+)\/$ services/export/handler.php?view=odd&guid=$1&type=$2&idname=$3 +RewriteRule ^php\/([0-9]+)\/$ services/export/handler.php?view=php&guid=$1 +RewriteRule ^php\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z]+)\/$ services/export/handler.php?view=php&guid=$1&type=$2&idname=$3 +RewriteRule ^json\/([0-9]+)\/$ services/export/handler.php?view=json&guid=$1 +RewriteRule ^json\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z]+)\/$ services/export/handler.php?view=json&guid=$1&type=$2&idname=$3 RewriteRule ^\_css\/css\.css$ _css/css.php diff --git a/services/export/handler.php b/services/export/handler.php new file mode 100644 index 000000000..2c8643a73 --- /dev/null +++ b/services/export/handler.php @@ -0,0 +1,108 @@ + + * @copyright Curverider Ltd 2008 + * @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 + $id_or_name = get_input("idname"); // Either a number or the key name (if attribute) + + + + // Only export the GUID + if ( + ($guid!="") && + ($type=="") && + ($id_or_name=="") + ) + { + page_draw("GUID:$guid", elgg_view("export/entity", array("entity" => get_entity($guid), "uuid" => guid_to_uuid($guid)))); + } + + // Export an individual attribute + else if ( + ($guid!="") && + ($type!="") && + ($id_or_name!="") + ) + { + // Get a uuid + $entity = get_entity($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("Sorry, '$id_or_name' does not exist for guid:$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); + break; + case 'annotation' : + $m = get_annotation($id_or_name); + break; + case 'relationship' : + $r = get_relationship($id_or_name); + break; + + default : + throw new InvalidParameterException("Sorry, I don't know how to export '$type'"); + } + + // Render metadata or relationship + if ((!$m) && (!$r)) + throw new InvalidParameterException("Could not find any data."); + + // Exporting metadata? + if ($m) + { + if ($m->entity_guid!=$entity->guid) + throw new InvalidParameterException("Does not belong to entity."); + + page_draw("$type:$id_or_name", 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("Does not belong to entity or refer to entity."); + + page_draw("$type:$id_or_name", elgg_view("export/relationship", array("relationship" => $r, "uuid" => $uuid))); + } + } + + // Something went wrong + else + throw new InvalidParameterException("Missing parmeter, you need to provide a GUID "); + +?> \ No newline at end of file -- cgit v1.2.3