diff options
-rw-r--r-- | odd/handler.php | 95 | ||||
-rw-r--r-- | views/default/export/entity.php | 95 | ||||
-rw-r--r-- | views/default/export/metadata.php | 23 | ||||
-rw-r--r-- | views/default/export/relationship.php | 25 | ||||
-rw-r--r-- | views/odd/export/entity.php | 16 | ||||
-rw-r--r-- | views/odd/export/metadata.php | 21 | ||||
-rw-r--r-- | views/odd/export/relationship.php | 20 | ||||
-rw-r--r-- | views/odd/pageshells/pageshell.php | 16 |
8 files changed, 270 insertions, 41 deletions
diff --git a/odd/handler.php b/odd/handler.php index 187addb13..2c8643a73 100644 --- a/odd/handler.php +++ b/odd/handler.php @@ -21,75 +21,88 @@ $type = get_input("type"); // attr, metadata, annotation $id_or_name = get_input("idname"); // Either a number or the key name (if attribute) - $owner = page_owner(); // Obvious - + + + // Only export the GUID if ( ($guid!="") && ($type=="") && ($id_or_name=="") ) { - // Only export the GUID, easy. - $export = export($guid); - - header("Content-Type: text/xml"); - echo $export; + 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!="") ) { - // Outputting an individual attribute - - - $odd = ""; + // Get a uuid $entity = get_entity($guid); - $uuid = guid_to_uuid($entity->getGUID()); + $uuid = guid_to_uuid($entity->getGUID()) . "$type/$id_or_name/"; - if (!$entity) throw new InvalidParameterException("Could not find an entity matching query."); - switch ($type) { - case 'attr' : // TODO: Do this better - $odd = new ODDMetaData($uuid . "attr/$id_or_name/", $uuid, $id_or_name, $entity->get($id_or_name)); + 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' : + case 'metadata' : $m = get_metadata($id_or_name); - if (!$m) - throw new InvalidParameterException("Could not find specified item of metadata"); - - if ($m->entity_guid!=$entity->guid) - throw new InvalidParameterException("Does not belong to entity."); - - $odd = new ODDMetaData($uuid . "metadata/$id_or_name/", $uuid, $id_or_name, $m->value); break; - case 'annotation' : $m = get_annotation($id_or_name); - if (!$m) - throw new InvalidParameterException("Could not find specified annotation"); - - if ($m->entity_guid!=$entity->guid) - throw new InvalidParameterException("Does not belong to entity."); - - $odd = new ODDMetaData($uuid . "annotation/$id_or_name/", $uuid, $id_or_name, $m->value); + break; + case 'relationship' : + $r = get_relationship($id_or_name); break; - + default : throw new InvalidParameterException("Sorry, I don't know how to export '$type'"); - } - // echo it - header("Content-Type: text/xml"); - echo "<odd>\n"; - echo new ODDHeader(); - echo "$odd"; - echo "</odd>\n"; + // 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/views/default/export/entity.php b/views/default/export/entity.php new file mode 100644 index 000000000..1ddde4b78 --- /dev/null +++ b/views/default/export/entity.php @@ -0,0 +1,95 @@ +<?php + /** + * Elgg Entity export. + * Displays an entity using the current view. + * + * @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/ + */ + + $entity = $vars['entity']; + if (!$entity) throw new InvalidParameterException("No entity found, it either doesn't exist or you don't have access to it."); + + $metadata = get_metadata_for_entity($entity->guid); + $annotations = get_annotations($entity->guid); + $relationships = get_entity_relationships($entity->guid); + +?> +<div> + <?php + foreach ($entity as $k => $v) + { +?> + <div> + <table> + <tr> + <td><b><?php echo $k; ?></b></td> + <td><?php echo $v; ?></td> + </tr> + </table> + </div> +<?php + } + ?> +</div> +<div id="metadata"> +<h2>Metadata</h2> + <?php + foreach ($metadata as $m) + { +?> + <div> + <table> + <tr> + <td><b><?php echo $m->name; ?></b></td> + <td><?php echo $m->value; ?></td> + </tr> + </table> + </div> +<?php + } + ?> + +</div> + +<div id="annotations"> +<h2>Annotations</h2> + <?php + foreach ($annotations as $a) + { +?> + <div> + <table> + <tr> + <td><b><?php echo $a->name; ?></b></td> + <td><?php echo $a->value; ?></td> + </tr> + </table> + </div> +<?php + } + ?> +</div> + +<div id="relationship"> +<h2>Relationships</h2> + <?php + foreach ($relationships as $r) + { +?> + <div> + <table> + <tr> + <td><b><?php echo $r->relationship; ?></b></td> + <td><?php echo $r->guid_two; ?></td> + </tr> + </table> + </div> +<?php + } + ?> +</div>
\ No newline at end of file diff --git a/views/default/export/metadata.php b/views/default/export/metadata.php new file mode 100644 index 000000000..303c42e54 --- /dev/null +++ b/views/default/export/metadata.php @@ -0,0 +1,23 @@ +<?php + /** + * Elgg metadata export. + * Displays a metadata item using the current view. + * + * @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/ + */ + + $m = $vars['metadata']; +?> +<div> + <table> + <tr> + <td><b><?php echo $m->name; ?></b></td> + <td><?php echo $m->value; ?></td> + </tr> + </table> +</div>
\ No newline at end of file diff --git a/views/default/export/relationship.php b/views/default/export/relationship.php new file mode 100644 index 000000000..8819a356a --- /dev/null +++ b/views/default/export/relationship.php @@ -0,0 +1,25 @@ +<?php + /** + * Elgg relationship export. + * Displays a relationship using the current view. + * + * @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/ + */ + + $r = $vars['relationship']; + +?> +<div> + <table> + <tr> + <td><?php echo $r->guid_one; ?></td> + <td><b><?php echo $r->relationship; ?></b></td> + <td><?php echo $r->guid_two; ?></td> + </tr> + </table> +</div>
\ No newline at end of file diff --git a/views/odd/export/entity.php b/views/odd/export/entity.php new file mode 100644 index 000000000..d6efd413c --- /dev/null +++ b/views/odd/export/entity.php @@ -0,0 +1,16 @@ +<?php + /** + * Elgg Entity export. + * Displays an entity as ODD + * + * @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/ + */ + + $entity = $vars['entity']; + echo export($entity->guid); +?>
\ No newline at end of file diff --git a/views/odd/export/metadata.php b/views/odd/export/metadata.php new file mode 100644 index 000000000..dff62086a --- /dev/null +++ b/views/odd/export/metadata.php @@ -0,0 +1,21 @@ +<?php + /** + * Elgg metadata export. + * Displays a metadata item using the current view. + * + * @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/ + */ + + $m = $vars['metadata']; + $uuid = $vars['uuid']; + + $odd = new ODDDocument(); + $odd->addElement($m->export()); + + echo $odd; +?>
\ No newline at end of file diff --git a/views/odd/export/relationship.php b/views/odd/export/relationship.php new file mode 100644 index 000000000..85387a273 --- /dev/null +++ b/views/odd/export/relationship.php @@ -0,0 +1,20 @@ +<?php + /** + * Elgg relationship export. + * Displays a relationship using ODD. + * + * @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/ + */ + + $r = $vars['relationship']; + + $odd = new ODDDocument(); + $odd->addElement($r->export()); + + echo $odd; +?>
\ No newline at end of file diff --git a/views/odd/pageshells/pageshell.php b/views/odd/pageshells/pageshell.php new file mode 100644 index 000000000..93b3e3185 --- /dev/null +++ b/views/odd/pageshells/pageshell.php @@ -0,0 +1,16 @@ +<?php + /** + * Elgg XML output pageshell for ODD + * + * @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 |