aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-28 13:59:15 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-28 13:59:15 +0000
commita604a1d45db88e59f47beccc35ce4bdf30b6b746 (patch)
treeb1c9c49f0888e3f06a8ec18e4409172431bbd4ba
parentcda80c696522c713d4e802f5aaa5c91b82f05353 (diff)
downloadelgg-a604a1d45db88e59f47beccc35ce4bdf30b6b746.tar.gz
elgg-a604a1d45db88e59f47beccc35ce4bdf30b6b746.tar.bz2
Fixes #2681 moves export handler into handler directory - current installs need to have .htaccess updated
git-svn-id: http://code.elgg.org/elgg/trunk@7461 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/handlers/export_handler.php116
-rw-r--r--htaccess_dist6
2 files changed, 119 insertions, 3 deletions
diff --git a/engine/handlers/export_handler.php b/engine/handlers/export_handler.php
new file mode 100644
index 000000000..eb931fdd8
--- /dev/null
+++ b/engine/handlers/export_handler.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Export handler.
+ *
+ * @package Elgg.Core
+ * @subpackage Export
+ */
+
+require_once(dirname(dirname(__FILE__)) . "/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) {
+ $query = elgg_echo('InvalidParameterException:GUIDNotFound', array($guid));
+ throw new InvalidParameterException($query);
+ }
+
+ $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) {
+ $msg = elgg_echo('InvalidParameterException:GUIDNotFound', array($guid));
+ throw new InvalidParameterException($msg);
+ }
+
+ $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) {
+ $msg = elgg_echo('InvalidParameterException:IdNotExistForGUID', array($id_or_name, $guid));
+ throw new InvalidParameterException($msg);
+ }
+
+ $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;
+ case 'volatile' :
+ $m = elgg_trigger_plugin_hook('volatile', 'metadata',
+ array('guid' => $guid, 'varname' => $id_or_name));
+ break;
+
+ default :
+ $msg = elgg_echo('InvalidParameterException:CanNotExportType', array($type));
+ throw new InvalidParameterException($msg);
+ }
+
+ // 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));
+ }
+
+ // 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'));
+}
+
+$content = elgg_view_title($title) . $body;
+$body = elgg_view_layout('one_column_with_sidebar', array('content' => $content));
+echo elgg_view_page($title, $body); \ No newline at end of file
diff --git a/htaccess_dist b/htaccess_dist
index 679dd71d8..dcc829fba 100644
--- a/htaccess_dist
+++ b/htaccess_dist
@@ -101,9 +101,9 @@ RewriteRule ^action\/([A-Za-z0-9\_\-\/]+)$ engine/handlers/action_handler.php?ac
RewriteRule ^services\/api\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/service_handler.php?handler=$1&request=$2&%{QUERY_STRING}
-RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)$ services/export/handler.php?view=$1&guid=$2
-RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/$ services/export/handler.php?view=$1&guid=$2
-RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$ services/export/handler.php?view=$1&guid=$2&type=$3&idname=$4
+RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)$ engine/handlers/export_handler.php?view=$1&guid=$2
+RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/$ engine/handlers/export_handler.php?view=$1&guid=$2
+RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$ engine/handlers/export_handler.php?view=$1&guid=$2&type=$3&idname=$4
RewriteRule ^\_css\/css\.css$ _css/css.php