Elgg  Version 1.9
export_handler.php
Go to the documentation of this file.
1 <?php
9 require_once(dirname(dirname(__FILE__)) . "/start.php");
10 
11 
12 // Get input values, these will be mapped via modrewrite
13 $guid = get_input("guid"); // guid of the entity
14 
15 // For attributes eg http://example.com/odd/73/attr/owner_uuid/
16 // or http://example.com/odd/73/metadata/86/
17 $type = get_input("type"); // attr, metadata, annotation, relationship
18 $id_or_name = get_input("idname"); // Either a number or the key name (if attribute)
19 
20 $body = "";
21 $title = "";
22 
23 // Only export the GUID
24 if (($guid != "") && ($type == "") && ($id_or_name == "")) {
26 
27  if (!$entity) {
28  $query = "GUID:" . $guid . " could not be found, or you can not access it.";
29  throw new InvalidParameterException($query);
30  }
31 
32  $title = "GUID:$guid";
33  $body = elgg_view("export/entity", array("entity" => $entity, "uuid" => guid_to_uuid($guid)));
34 
35  // Export an individual attribute
36 } else if (($guid != "") && ($type != "") && ($id_or_name != "")) {
37  // Get a uuid
39  if (!$entity) {
40  $msg = "GUID:" . $guid . " could not be found, or you can not access it.";
41  throw new InvalidParameterException($msg);
42  }
43 
44  $uuid = guid_to_uuid($entity->getGUID()) . "$type/$id_or_name/";
45 
46  switch ($type) {
47  case 'attr' : // @todo: Do this better? - This is a bit of a hack...
48  $v = $entity->get($id_or_name);
49  if (!$v) {
50  $msg = "Sorry, '" . $id_or_name . "' does not exist for guid:" . $guid;
51  throw new InvalidParameterException($msg);
52  }
53 
54  $m = new ElggMetadata();
55 
56  $m->value = $v;
57  $m->name = $id_or_name;
58  $m->entity_guid = $guid;
59  $m->time_created = $entity->time_created;
60  $m->time_updated = $entity->time_updated;
61  $m->owner_guid = $entity->owner_guid;
62  $m->id = $id_or_name;
63  $m->type = "attr";
64  break;
65  case 'metadata' :
67  break;
68  case 'annotation' :
70  break;
71  case 'relationship' :
73  break;
74  case 'volatile' :
75  $m = elgg_trigger_plugin_hook('volatile', 'metadata', array(
76  'guid' => $guid,
77  'varname' => $id_or_name,
78  ));
79  break;
80 
81  default :
82  $msg = "Sorry, I don't know how to export '" . $type . "'";
83  throw new InvalidParameterException($msg);
84  }
85 
86  // Render metadata or relationship
87  if ((!$m) && (!$r)) {
88  throw new InvalidParameterException("Could not find any data.");
89  }
90 
91  // Exporting metadata?
92  if ($m) {
93  if ($m->entity_guid != $entity->guid) {
94  throw new InvalidParameterException("Does not belong to entity.");
95  }
96 
97  $title = "$type:$id_or_name";
98  $body = elgg_view("export/metadata", array("metadata" => $m, "uuid" => $uuid));
99  }
100 
101  // Exporting relationship
102  if ($r) {
103  if (($r->guid_one != $entity->guid) && ($r->guid_two != $entity->guid)) {
104  throw new InvalidParameterException("Does not belong to entity or refer to entity.");
105  }
106 
107  $title = "$type:$id_or_name";
108  $body = elgg_view("export/relationship", array("relationship" => $r, "uuid" => $uuid));
109  }
110 
111  // Something went wrong
112 } else {
113  throw new InvalidParameterException("Missing parameter, you need to provide a GUID.");
114 }
115 
116 $body = elgg_view_layout('one_sidebar', array(
117  'title' => $title,
118  'content' => $body
119 ));
$r
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
get_relationship($id)
Get a relationship by its ID.
$m
Definition: metadata.php:11
elgg_get_metadata_from_id($id)
Get a specific metadata object by its id.
Definition: metadata.php:35
$title
elgg_get_annotation_from_id($id)
Get a specific annotation by its id.
Definition: annotations.php:36
elgg echo
Translates a string.
Definition: languages.js:43
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
Definition: views.php:617
guid_to_uuid($guid)
Generate a UUID from a given GUID.
$id_or_name
elgg_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.
Definition: views.php:437
$entity
Definition: delete.php:10
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604