]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/xrds.php
Fix reversed poll & poll response object types in ActivityStreams output
[quix0rs-gnu-social.git] / actions / xrds.php
index def10e4cf7bd90d8af6b6263eec7af093dfb1fbe..818cd1032c1c0516e9005dc424cca7433af281d5 100644 (file)
@@ -1,7 +1,6 @@
 <?php
-
 /**
- * XRDS for OpenID
+ * XRDS for OpenMicroBlogging
  *
  * PHP version 5
  *
@@ -34,9 +33,12 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
 }
 
 require_once INSTALLDIR.'/lib/omb.php';
+require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
+require_once INSTALLDIR.'/extlib/libomb/xrds_mapper.php';
+require_once INSTALLDIR.'/lib/xrdsoutputter.php';
 
 /**
- * XRDS for OpenID
+ * XRDS for OpenMicroBlogging
  *
  * @category Action
  * @package  StatusNet
@@ -47,127 +49,91 @@ require_once INSTALLDIR.'/lib/omb.php';
  */
 class XrdsAction extends Action
 {
+    var $user;
+
     /**
      * Is read only?
      *
      * @return boolean true
      */
-    function isReadOnly($args)
+    function isReadOnly()
     {
         return true;
     }
 
-    /**
-     * Class handler.
-     *
-     * @param array $args query arguments
-     *
-     * @return void
-     */
-    function handle($args)
+    function prepare($args)
     {
-        parent::handle($args);
+        parent::prepare($args);
         $nickname = $this->trimmed('nickname');
-        $user     = User::staticGet('nickname', $nickname);
-        if (!$user) {
+        $this->user     = User::staticGet('nickname', $nickname);
+        if (!$this->user) {
+            // TRANS: Client error displayed providing a non-existing nickname.
             $this->clientError(_('No such user.'));
             return;
         }
-        $this->showXrds($user);
+        return true;
     }
 
     /**
-     * Show XRDS for a user.
+     * Class handler.
      *
-     * @param class $user XRDS for this user.
+     * @param array $args query arguments
      *
      * @return void
      */
-    function showXrds($user)
+    function handle($args)
     {
-        header('Content-Type: application/xrds+xml');
-        $this->startXML();
-        $this->elementStart('XRDS', array('xmlns' => 'xri://$xrds'));
+        parent::handle($args);
+        $xrdsOutputter = new XRDSOutputter();
+        $xrdsOutputter->startXRDS();
 
-        $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+        Event::handle('StartUserXRDS', array($this,&$xrdsOutputter));
+
+        //oauth
+        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
                                           'xml:id' => 'oauth',
                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
                                           'version' => '2.0'));
-        $this->element('Type', null, 'xri://$xrds*simple');
-        $this->showService(OAUTH_ENDPOINT_REQUEST,
+        $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
+        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_REQUEST,
                             common_local_url('requesttoken'),
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
-                            array(OAUTH_HMAC_SHA1),
-                            $user->uri);
-        $this->showService(OAUTH_ENDPOINT_AUTHORIZE,
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1),
+                            null,
+                            $this->user->uri);
+        $xrdsOutputter->showXrdsService( OAUTH_ENDPOINT_AUTHORIZE,
                             common_local_url('userauthorization'),
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
-                            array(OAUTH_HMAC_SHA1));
-        $this->showService(OAUTH_ENDPOINT_ACCESS,
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
+        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_ACCESS,
                             common_local_url('accesstoken'),
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
-                            array(OAUTH_HMAC_SHA1));
-        $this->showService(OAUTH_ENDPOINT_RESOURCE,
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
+        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_RESOURCE,
                             null,
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
-                            array(OAUTH_HMAC_SHA1));
-        $this->elementEnd('XRD');
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
+        $xrdsOutputter->elementEnd('XRD');
 
-        // XXX: decide whether to include user's ID/nickname in postNotice URL
-        $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+        //omb
+        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
                                           'xml:id' => 'omb',
                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
                                           'version' => '2.0'));
-        $this->element('Type', null, 'xri://$xrds*simple');
-        $this->showService(OMB_ENDPOINT_POSTNOTICE,
+        $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
+        $xrdsOutputter->showXrdsService(OMB_ENDPOINT_POSTNOTICE,
                             common_local_url('postnotice'));
-        $this->showService(OMB_ENDPOINT_UPDATEPROFILE,
+        $xrdsOutputter->showXrdsService(OMB_ENDPOINT_UPDATEPROFILE,
                             common_local_url('updateprofile'));
-        $this->elementEnd('XRD');
-        $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+        $xrdsOutputter->elementEnd('XRD');
+
+        Event::handle('EndUserXRDS', array($this,&$xrdsOutputter));
+
+        //misc
+        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
                                           'version' => '2.0'));
-        $this->element('Type', null, 'xri://$xrds*simple');
-        $this->showService(OAUTH_DISCOVERY,
+        $xrdsOutputter->showXrdsService(OAUTH_DISCOVERY,
                             '#oauth');
-        $this->showService(OMB_NAMESPACE,
+        $xrdsOutputter->showXrdsService(OMB_VERSION,
                             '#omb');
-        $this->elementEnd('XRD');
-        $this->elementEnd('XRDS');
-        $this->endXML();
-    }
+        $xrdsOutputter->elementEnd('XRD');
 
-    /**
-     * Show service.
-     *
-     * @param string $type    XRDS type
-     * @param string $uri     URI
-     * @param array  $params  type parameters, null by default
-     * @param array  $sigs    type signatures, null by default
-     * @param string $localId local ID, null by default
-     *
-     * @return void
-     */
-    function showService($type, $uri, $params=null, $sigs=null, $localId=null)
-    {
-        $this->elementStart('Service');
-        if ($uri) {
-            $this->element('URI', null, $uri);
-        }
-        $this->element('Type', null, $type);
-        if ($params) {
-            foreach ($params as $param) {
-                $this->element('Type', null, $param);
-            }
-        }
-        if ($sigs) {
-            foreach ($sigs as $sig) {
-                $this->element('Type', null, $sig);
-            }
-        }
-        if ($localId) {
-            $this->element('LocalID', null, $localId);
-        }
-        $this->elementEnd('Service');
+        $xrdsOutputter->endXRDS();
     }
 }
-