gnu-social/plugins/LRDD/extlib/XML/XRD/Serializer/JSON.php
Mikael Nordfeldth a0e107f17f Implemented WebFinger and replaced our XRD with PEAR XML_XRD
New plugins:
* LRDD
    LRDD implements client-side RFC6415 and RFC7033 resource descriptor
    discovery procedures. I.e. LRDD, host-meta and WebFinger stuff.

    OStatus and OpenID now depend on the LRDD plugin (XML_XRD).

* WebFinger
    This plugin implements the server-side of RFC6415 and RFC7033. Note:
    WebFinger technically doesn't handle XRD, but we serve both that and
    JRD (JSON Resource Descriptor), depending on Accept header and one
    ugly hack to check for old StatusNet installations.

    WebFinger depends on LRDD.

We might make this even prettier by using Net_WebFinger, but it is not
currently RFC7033 compliant (no /.well-known/webfinger resource GETs).

Disabling the WebFinger plugin would effectively render your site non-
federated (which might be desired on a private site).

Disabling the LRDD plugin would make your site unable to do modern web
URI lookups (making life just a little bit harder).
2013-09-30 22:04:52 +02:00

95 lines
2.5 KiB
PHP

<?php
/**
* Part of XML_XRD
*
* PHP version 5
*
* @category XML
* @package XML_XRD
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @link http://pear.php.net/package/XML_XRD
*/
/**
* Generate JSON from a XML_XRD object (for JRD files).
*
* @category XML
* @package XML_XRD
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @version Release: @package_version@
* @link http://pear.php.net/package/XML_XRD
* @link http://tools.ietf.org/html/rfc6415#appendix-A
*/
class XML_XRD_Serializer_JSON
{
protected $xrd;
/**
* Create new instance
*
* @param XML_XRD $xrd XRD instance to convert to JSON
*/
public function __construct(XML_XRD $xrd)
{
$this->xrd = $xrd;
}
/**
* Generate JSON.
*
* @return string JSON code
*/
public function __toString()
{
$o = new stdClass();
if ($this->xrd->expires !== null) {
$o->expires = gmdate('Y-m-d\TH:i:s\Z', $this->xrd->expires);
}
if ($this->xrd->subject !== null) {
$o->subject = $this->xrd->subject;
}
foreach ($this->xrd->aliases as $alias) {
$o->aliases[] = $alias;
}
foreach ($this->xrd->properties as $property) {
$o->properties[$property->type] = $property->value;
}
$o->links = array();
foreach ($this->xrd->links as $link) {
$lid = count($o->links);
$o->links[$lid] = new stdClass();
if ($link->rel) {
$o->links[$lid]->rel = $link->rel;
}
if ($link->type) {
$o->links[$lid]->type = $link->type;
}
if ($link->href) {
$o->links[$lid]->href = $link->href;
}
if ($link->template !== null && $link->href === null) {
$o->links[$lid]->template = $link->template;
}
foreach ($link->titles as $lang => $value) {
if ($lang == null) {
$lang = 'default';
}
$o->links[$lid]->titles[$lang] = $value;
}
foreach ($link->properties as $property) {
$o->links[$lid]->properties[$property->type] = $property->value;
}
}
if (count($o->links) == 0) {
unset($o->links);
}
return json_encode($o);
}
}
?>