]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/magicenvelope.php
Break out MagicEnvelope->toXML() functionality to allow for plugin flexibility
[quix0rs-gnu-social.git] / plugins / OStatus / lib / magicenvelope.php
index 533cd7d201560c3e00cea17b748f3d35dcaed822..2c54e3679b2e5605ce87584f091f231d5f6999e0 100644 (file)
@@ -205,18 +205,25 @@ class MagicEnvelope
      *
      * @return string representation of XML document
      */
-    public function toXML() {
-        $xs = new XMLStringer();
-        $xs->startXML();
-        $xs->elementStart('me:env', array('xmlns:me' => self::NS));
-        $xs->element('me:data', array('type' => $this->data_type), $this->data);
-        $xs->element('me:encoding', null, $this->encoding);
-        $xs->element('me:alg', null, $this->alg);
-        $xs->element('me:sig', null, $this->getSignature());
-        $xs->elementEnd('me:env');
-
-        $string =  $xs->getString();
-        return $string;
+    public function toXML($flavour=null) {
+        $xml = null;
+        if (Event::handle('MagicEnvelopeToXML', array($this, $flavour, &$xml))) {
+            // fall back to our default, normal Magic Envelope XML.
+            $xs = new XMLStringer();
+            $xs->startXML();
+            $xs->elementStart('me:env', array('xmlns:me' => self::NS));
+            $xs->element('me:data', array('type' => $this->data_type), $this->data);
+            $xs->element('me:encoding', null, $this->encoding);
+            $xs->element('me:alg', null, $this->alg);
+            $xs->element('me:sig', null, $this->getSignature());
+            $xs->elementEnd('me:env');
+
+            $xml = $xs->getString();
+        }
+        if (is_null($xml)) {
+            throw new ServerException('No Magic Envelope XML string was created.');
+        }
+        return $xml;
     }
 
     /*
@@ -265,6 +272,21 @@ class MagicEnvelope
         return $this->sig;
     }
 
+    public function getSignatureAlgorithm()
+    {
+        return $this->alg;
+    }
+
+    public function getDataType()
+    {
+        return $this->data_type;
+    }
+
+    public function getEncoding()
+    {
+        return $this->encoding;
+    }
+
     /**
      * Find the author URI referenced in the payload Atom entry.
      *