aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/opendd.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/opendd.php')
-rw-r--r--engine/lib/opendd.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/engine/lib/opendd.php b/engine/lib/opendd.php
new file mode 100644
index 000000000..f00ea6aab
--- /dev/null
+++ b/engine/lib/opendd.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * OpenDD PHP Library.
+ *
+ * @package Elgg.Core
+ * @subpackage ODD
+ * @version 0.4
+ */
+
+/**
+ * Attempt to construct an ODD object out of a XmlElement or sub-elements.
+ *
+ * @param XmlElement $element The element(s)
+ *
+ * @return mixed An ODD object if the element can be handled, or false.
+ * @access private
+ */
+function ODD_factory (XmlElement $element) {
+ $name = $element->name;
+ $odd = false;
+
+ switch ($name) {
+ case 'entity' :
+ $odd = new ODDEntity("", "", "");
+ break;
+ case 'metadata' :
+ $odd = new ODDMetaData("", "", "", "");
+ break;
+ case 'relationship' :
+ $odd = new ODDRelationship("", "", "");
+ break;
+ }
+
+ // Now populate values
+ if ($odd) {
+ // Attributes
+ foreach ($element->attributes as $k => $v) {
+ $odd->setAttribute($k, $v);
+ }
+
+ // Body
+ $body = $element->content;
+ $a = stripos($body, "<![CDATA");
+ $b = strripos($body, "]]>");
+ if (($body) && ($a !== false) && ($b !== false)) {
+ $body = substr($body, $a + 8, $b - ($a + 8));
+ }
+
+ $odd->setBody($body);
+ }
+
+ return $odd;
+}
+
+/**
+ * Import an ODD document.
+ *
+ * @param string $xml The XML ODD.
+ *
+ * @return ODDDocument
+ * @access private
+ */
+function ODD_Import($xml) {
+ // Parse XML to an array
+ $elements = xml_to_object($xml);
+
+ // Sanity check 1, was this actually XML?
+ if ((!$elements) || (!$elements->children)) {
+ return false;
+ }
+
+ // Create ODDDocument
+ $document = new ODDDocument();
+
+ // Itterate through array of elements and construct ODD document
+ $cnt = 0;
+
+ foreach ($elements->children as $child) {
+ $odd = ODD_factory($child);
+
+ if ($odd) {
+ $document->addElement($odd);
+ $cnt++;
+ }
+ }
+
+ // Check that we actually found something
+ if ($cnt == 0) {
+ return false;
+ }
+
+ return $document;
+}
+
+/**
+ * Export an ODD Document.
+ *
+ * @param ODDDocument $document The Document.
+ *
+ * @return string
+ * @access private
+ */
+function ODD_Export(ODDDocument $document) {
+ return "$document";
+}