aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/atom.php170
-rw-r--r--engine/lib/export.php5
-rw-r--r--engine/lib/opendd.php95
-rw-r--r--views/atom/export/entity.php17
-rw-r--r--views/atom/export/metadata.php21
-rw-r--r--views/atom/export/relationship.php21
-rw-r--r--views/atom/pageshells/pageshell.php16
7 files changed, 330 insertions, 15 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
diff --git a/engine/lib/export.php b/engine/lib/export.php
index e389613e8..815fc5819 100644
--- a/engine/lib/export.php
+++ b/engine/lib/export.php
@@ -161,9 +161,10 @@
*
* @see ElggEntity for an example of its usage.
* @param int $guid The GUID.
+ * @param ODDWrapperFactory $wrapper Optional wrapper permitting the export process to embed ODD in other document formats.
* @return xml
*/
- function export($guid)
+ function export($guid, ODDWrapperFactory $wrapper = null)
{
$guid = (int)$guid;
@@ -178,7 +179,7 @@
$odd = new ODDDocument($to_be_serialised);
- return "$odd";
+ return ODD_Export($odd, $wrapper);
}
/**
diff --git a/engine/lib/opendd.php b/engine/lib/opendd.php
index 2c87f3265..96c18bbea 100644
--- a/engine/lib/opendd.php
+++ b/engine/lib/opendd.php
@@ -6,7 +6,7 @@
* @subpackage Core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Marcus Povey
- * @version 0.2
+ * @version 0.3
* @copyright Curverider Ltd 2008
* @link http://elgg.org/
*/
@@ -32,6 +32,11 @@
*/
private $elements;
+ /**
+ * Optional wrapper factory.
+ */
+ private $wrapperfactory;
+
public function __construct(array $elements = NULL)
{
if ($elements)
@@ -57,23 +62,38 @@
public function getElements() { return $this->elements; }
/**
+ * Set an optional wrapper factory to optionally embed the ODD document in another format.
+ */
+ public function setWrapperFactory(ODDWrapperFactory $factory) { $this->wrapperfactory = $factory; }
+
+ /**
* Magic function to generate valid ODD XML for this item.
*/
public function __toString()
{
$xml = "";
- // Output begin tag
- $generated = date("r");
- $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";
-
- // Get XML for elements
- foreach ($this->elements as $element)
- $xml .= "$element";
-
- // Output end tag
- $xml .= "</odd>\n";
-
+ if ($this->wrapperfactory)
+ {
+ // A wrapper has been provided
+ $wrapper = $this->wrapperfactory->getElementWrapper($this); // Get the wrapper for this element
+
+ $xml = $wrapper->wrap($this); // Wrap this element (and subelements)
+ }
+ else
+ {
+ // Output begin tag
+ $generated = date("r");
+ $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";
+
+ // Get XML for elements
+ foreach ($this->elements as $element)
+ $xml .= "$element";
+
+ // Output end tag
+ $xml .= "</odd>\n";
+ }
+
return $xml;
}
@@ -157,6 +177,7 @@
{
$this->attributes['published'] = date("r", $time);
}
+
/**
* For serialisation, implement to return a string name of the tag eg "header" or "metadata".
* @return string
@@ -182,6 +203,7 @@
return "<{$tag} $attr" . $end . "\n";
}
+
}
/**
@@ -248,6 +270,46 @@
}
/**
+ * A wrapper factory is used to construct the appropriate wrappers that permit ODD documents to be embedded
+ * as a payload in other formats.
+ */
+ abstract class ODDWrapperFactory
+ {
+ abstract function getElementWrapper($element);
+ }
+
+ /**
+ * Element wrapper superclass.
+ */
+ abstract class ODDWrapper
+ {
+ /**
+ * Wrap an element and return the encoded string.
+ */
+ abstract function wrap($element);
+ }
+
+ /**
+ * Document wrapper superclass
+ */
+ abstract class ODDDocumentWrapper extends ODDWrapper { }
+
+ /**
+ * Entity wrapper superclass
+ */
+ abstract class ODDEntityWrapper extends ODDWrapper { }
+
+ /**
+ * Metadata wrapper superclass
+ */
+ abstract class ODDMetaDataWrapper extends ODDWrapper { }
+
+ /**
+ * Relationship wrapper superclass.
+ */
+ abstract class ODDRelationshipWrapper extends ODDWrapper { }
+
+ /**
* Attempt to construct an ODD object out of a XmlElement or sub-elements.
*
* @param XmlElement $element The element(s)
@@ -309,10 +371,17 @@
* Export an ODD Document.
*
* @param ODDDocument $document The Document.
+ * @param ODDWrapperFactory $wrapper Optional wrapper permitting the export process to embed ODD in other document formats.
*/
- function ODD_Export(ODDDocument $document)
+ function ODD_Export(ODDDocument $document, ODDWrapperFactory $wrapper = null)
{
+ if ($wrapper)
+ $document->setWrapperFactory($wrapper);
+
return "$document";
}
+
+
+ // input - how? root element handler?
?> \ No newline at end of file
diff --git a/views/atom/export/entity.php b/views/atom/export/entity.php
new file mode 100644
index 000000000..c89a73fc4
--- /dev/null
+++ b/views/atom/export/entity.php
@@ -0,0 +1,17 @@
+<?php
+ /**
+ * Elgg Entity export.
+ * Displays an entity as ODD over Atom
+ *
+ * @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, new ODDAtomWrapperFactory());
+?> \ No newline at end of file
diff --git a/views/atom/export/metadata.php b/views/atom/export/metadata.php
new file mode 100644
index 000000000..2c943cd4d
--- /dev/null
+++ b/views/atom/export/metadata.php
@@ -0,0 +1,21 @@
+<?php
+ /**
+ * Elgg metadata export.
+ * Displays a metadata item using ODD over Atom
+ *
+ * @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'];
+
+ $odd = new ODDDocument();
+ $odd->addElement($m->export());
+ $odd->setWrapperFactory(new ODDAtomWrapperFactory());
+
+ echo $odd;
+?> \ No newline at end of file
diff --git a/views/atom/export/relationship.php b/views/atom/export/relationship.php
new file mode 100644
index 000000000..d0ad62385
--- /dev/null
+++ b/views/atom/export/relationship.php
@@ -0,0 +1,21 @@
+<?php
+ /**
+ * Elgg relationship export.
+ * Displays a relationship using ODD over Atom
+ *
+ * @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());
+ $odd->setWrapperFactory(new ODDAtomWrapperFactory());
+
+ echo $odd;
+?> \ No newline at end of file
diff --git a/views/atom/pageshells/pageshell.php b/views/atom/pageshells/pageshell.php
new file mode 100644
index 000000000..f5c7a4ce0
--- /dev/null
+++ b/views/atom/pageshells/pageshell.php
@@ -0,0 +1,16 @@
+<?php
+ /**
+ * Elgg XML output pageshell
+ *
+ * @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