diff options
author | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-20 11:38:25 +0000 |
---|---|---|
committer | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-20 11:38:25 +0000 |
commit | 9caa09ee888d7884e22cc46089e6e0fb6579732c (patch) | |
tree | 6ee22ea1104a337fce3a64d0b519073a4ffbabbd /engine/lib/atom.php | |
parent | 6258b38d2e274df93333ce36696bcbf49fb8ea2e (diff) | |
download | elgg-9caa09ee888d7884e22cc46089e6e0fb6579732c.tar.gz elgg-9caa09ee888d7884e22cc46089e6e0fb6579732c.tar.bz2 |
Marcus Povey <marcus@dushka.co.uk>
* Committed abortive Atom wrapper... we need to support different import/export
git-svn-id: https://code.elgg.org/elgg/trunk@657 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/atom.php')
-rw-r--r-- | engine/lib/atom.php | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/engine/lib/atom.php b/engine/lib/atom.php new file mode 100644 index 000000000..684ae0946 --- /dev/null +++ b/engine/lib/atom.php @@ -0,0 +1,170 @@ +<?php + /** + * OpenDD over Atom PHP Library. + * Provides Atom wrappers for + * + * @package Elgg + * @subpackage Core + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Marcus Povey + * @version 0.1 + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + include_once("opendd.php"); + + /** + * A Wrapper Factory which Constructs a wrapper appropriate for drawing + * ODD elements as Atom. + */ + class ODDAtomWrapperFactory extends ODDWrapperFactory + { + function getElementWrapper($element) + { + if ($element instanceof ODDDocument) + return new ODDAtomDocumentWrapper(); + + if ($element instanceof ODDEntity) + return new ODDAtomEntityWrapper(); + + if ($element instanceof ODDMetaData) + return new ODDAtomMetaDataWrapper(); + + if ($element instanceof ODDRelationship) + return new ODDAtomRelationshipWrapper(); + + throw new DataFormatException("Element could not be wrapped."); + } + } + + /** + * Atom document wrapper + */ + class ODDAtomDocumentWrapper extends ODDDocumentWrapper + { + function wrap($element) + { + global $CONFIG; + + $wrapped = ""; + + // Sanity check + if (!($element instanceof ODDDocument)) + throw new DataFormatException("Element being wrapped is not an ODDDocument"); + + // Create a factory + $factory = new ODDAtomWrapperFactory(); + + // Head + $wrapped .= "<feed>\n"; + $wrapped .= "<id>".urlencode(current_page_url())."</id>\n"; + $wrapped .= "<updated>".date(DATE_ATOM)."</updated>\n"; + $wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n"; + $wrapped .= "<title>OpenDD-over-Atom feed</title>\n"; + + // Itterate + foreach ($element as $e) + { + $wrapper = $factory->getElementWrapper($e); + $wrapped .= $wrapper->wrap($e); + } + + // Tail + $wrapped .= "</feed>\n"; + + return $wrapped; + } + } + + /** + * Atom entity wrapper + */ + class ODDAtomEntityWrapper extends ODDEntityWrapper + { + function wrap($element) + { + $wrapped = ""; + + // Sanity check + if (!($element instanceof ODDEntity)) + throw new DataFormatException("Element being wrapped is not an ODDEntity"); + + $wrapped .= "<entry>\n"; + + $wrapped .= "<id>".$element->getAttribute('uuid')."?view=atom"."</id>\n"; + $wrapped .= "<published>".date(DATE_ATOM)."</published>\n"; + $wrapped .= "<title>Entity</title>\n"; + $wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n"; + + $wrapped .= "<content type=\"text/xml\">\n"; + $wrapped .= "$element\n"; + $wrapped .= "</content>\n"; + + $wrapped .= "</entry>\n"; + + return $wrapped; + } + + } + + /** + * Atom metadata wrapper + */ + class ODDAtomMetaDataWrapper extends ODDMetaDataWrapper + { + function wrap($element) + { + $wrapped = ""; + + // Sanity check + if (!($element instanceof ODDMetaData)) + throw new DataFormatException("Element being wrapped is not an ODDMetaData"); + + $wrapped .= "<entry>\n"; + + $wrapped .= "<id>".$element->getAttribute('uuid')."?view=atom"."</id>\n"; + $wrapped .= "<published>".date(DATE_ATOM)."</published>\n"; + $wrapped .= "<title>Entity</title>\n"; + $wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n"; + + $wrapped .= "<content type=\"text/xml\">\n"; + $wrapped .= "$element\n"; + $wrapped .= "</content>\n"; + + $wrapped .= "</entry>\n"; + + return $wrapped; + } + } + + /** + * Atom Relationship wrapper. + */ + class ODDAtomRelationshipWrapper extends ODDRelationshipWrapper + { + function wrap($element) + { + $wrapped = ""; + + // Sanity check + if (!($element instanceof ODDRelationship)) + throw new DataFormatException("Element being wrapped is not an ODDRelationship"); + + $wrapped .= "<entry>\n"; + + $wrapped .= "<id></id>\n"; + $wrapped .= "<published>".date(DATE_ATOM)."</published>\n"; + $wrapped .= "<title>Entity</title>\n"; + $wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n"; + + $wrapped .= "<content type=\"text/xml\">\n"; + $wrapped .= "$element\n"; + $wrapped .= "</content>\n"; + + $wrapped .= "</entry>\n"; + + return $wrapped; + } + } +?>
\ No newline at end of file |