Merge branch '2429' into 0.9.x

This commit is contained in:
James Walker 2010-08-02 16:45:23 -04:00
commit 5fa19a0384
2 changed files with 40 additions and 74 deletions

View File

@ -97,24 +97,18 @@ class MagicEnvelope
}
public function toXML($env) {
$dom = new DOMDocument();
$xs = new XMLStringer();
$xs->startXML();
$xs->elementStart('me:env', array('xmlns:me' => MagicEnvelope::NS));
$xs->element('me:data', array('type' => $env['data_type']), $env['data']);
$xs->element('me:encoding', null, $env['encoding']);
$xs->element('me:alg', null, $env['alg']);
$xs->element('me:sig', null, $env['sig']);
$xs->elementEnd('me:env');
$envelope = $dom->createElementNS(MagicEnvelope::NS, 'me:env');
$envelope->setAttribute('xmlns:me', MagicEnvelope::NS);
$data = $dom->createElementNS(MagicEnvelope::NS, 'me:data', $env['data']);
$data->setAttribute('type', $env['data_type']);
$envelope->appendChild($data);
$enc = $dom->createElementNS(MagicEnvelope::NS, 'me:encoding', $env['encoding']);
$envelope->appendChild($enc);
$alg = $dom->createElementNS(MagicEnvelope::NS, 'me:alg', $env['alg']);
$envelope->appendChild($alg);
$sig = $dom->createElementNS(MagicEnvelope::NS, 'me:sig', $env['sig']);
$envelope->appendChild($sig);
$dom->appendChild($envelope);
return $dom->saveXML();
$string = $xs->getString();
common_debug($string);
return $string;
}

View File

@ -106,44 +106,43 @@ class XRD
public function toXML()
{
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$xs = new XMLStringer();
$xrd_dom = $dom->createElementNS(XRD::XRD_NS, 'XRD');
$dom->appendChild($xrd_dom);
$xs->startXML();
$xs->elementStart('XRD', array('xmlns' => XRD::XRD_NS));
if ($this->host) {
$host_dom = $dom->createElement('hm:Host', $this->host);
$xrd_dom->setAttributeNS(XRD::XML_NS, 'xmlns:hm', XRD::HOST_META_NS);
$xrd_dom->appendChild($host_dom);
$xs->element('hm:Host', array('xmlns:hm' => XRD::HOST_META_NS), $this->host);
}
if ($this->expires) {
$expires_dom = $dom->createElement('Expires', $this->expires);
$xrd_dom->appendChild($expires_dom);
$xs->element('Expires', null, $this->expires);
}
if ($this->subject) {
$subject_dom = $dom->createElement('Subject', $this->subject);
$xrd_dom->appendChild($subject_dom);
$xs->element('Subject', null, $this->subject);
}
foreach ($this->alias as $alias) {
$alias_dom = $dom->createElement('Alias', $alias);
$xrd_dom->appendChild($alias_dom);
}
foreach ($this->types as $type) {
$type_dom = $dom->createElement('Type', $type);
$xrd_dom->appendChild($type_dom);
$xs->element('Alias', null, $alias);
}
foreach ($this->links as $link) {
$link_dom = $this->saveLink($dom, $link);
$xrd_dom->appendChild($link_dom);
$titles = array();
if (isset($link['title'])) {
$titles = $link['title'];
unset($link['title']);
}
$xs->elementStart('Link', $link);
foreach ($titles as $title) {
$xs->element('Title', null, $title);
}
$xs->elementEnd('Link');
}
return $dom->saveXML();
$xs->elementEnd('XRD');
return $xs->getString();
}
function parseType($element)
@ -169,32 +168,5 @@ class XRD
return $link;
}
function saveLink($doc, $link)
{
$link_element = $doc->createElement('Link');
if (!empty($link['rel'])) {
$link_element->setAttribute('rel', $link['rel']);
}
if (!empty($link['type'])) {
$link_element->setAttribute('type', $link['type']);
}
if (!empty($link['href'])) {
$link_element->setAttribute('href', $link['href']);
}
if (!empty($link['template'])) {
$link_element->setAttribute('template', $link['template']);
}
if (!empty($link['title']) && is_array($link['title'])) {
foreach($link['title'] as $title) {
$title = $doc->createElement('Title', $title);
$link_element->appendChild($title);
}
}
return $link_element;
}
}