]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/WebFinger/WebFingerPlugin.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / WebFinger / WebFingerPlugin.php
index 24200a6f36dbd9d486f0e3b2ecfa90f5bf0e66c2..1edc3d8971351790ac70f9fc22418800814a6237 100644 (file)
@@ -31,7 +31,18 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 class WebFingerPlugin extends Plugin
 {
-    public function onRouterInitialized($m)
+    const OAUTH_ACCESS_TOKEN_REL    = 'http://apinamespace.org/oauth/access_token';
+    const OAUTH_REQUEST_TOKEN_REL   = 'http://apinamespace.org/oauth/request_token';
+    const OAUTH_AUTHORIZE_REL       = 'http://apinamespace.org/oauth/authorize';
+
+    public $http_alias = false;
+
+    public function initialize()
+    {
+        common_config_set('webfinger', 'http_alias', $this->http_alias);
+    }
+
+    public function onRouterInitialized(URLMapper $m)
     {
         $m->connect('.well-known/host-meta', array('action' => 'hostmeta'));
         $m->connect('.well-known/host-meta.:format',
@@ -58,6 +69,18 @@ class WebFingerPlugin extends Plugin
         return true;
     }
 
+    public function onStartGetProfileAcctUri(Profile $profile, &$acct)
+    {
+        $wfr = new WebFingerResource_Profile($profile);
+        try {
+            $acct = $wfr->reconstructAcct();
+        } catch (Exception $e) {
+            return true;
+        }
+
+        return false;
+    }
+
     public function onEndGetWebFingerResource($resource, WebFingerResource &$target=null, array $args=array())
     {
         $profile = null;
@@ -108,27 +131,32 @@ class WebFingerPlugin extends Plugin
                             $type,
                             true);    // isTemplate
         }
+
+        // OAuth connections
+        $links[] = new XML_XRD_Element_link(self::OAUTH_ACCESS_TOKEN_REL,  common_local_url('ApiOAuthAccessToken'));
+        $links[] = new XML_XRD_Element_link(self::OAUTH_REQUEST_TOKEN_REL, common_local_url('ApiOAuthRequestToken'));
+        $links[] = new XML_XRD_Element_link(self::OAUTH_AUTHORIZE_REL,     common_local_url('ApiOAuthAuthorize'));
     }
 
     /**
      * Add a link header for LRDD Discovery
      */
-    public function onStartShowHTML($action)
+    public function onStartShowHTML(Action $action)
     {
         if ($action instanceof ShowstreamAction) {
-            $acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
+            $acct = 'acct:'. $action->getTarget()->getNickname() .'@'. common_config('site', 'server');
             $url = common_local_url('webfinger') . '?resource='.$acct;
 
             foreach (array(Discovery::JRD_MIMETYPE, Discovery::XRD_MIMETYPE) as $type) {
-                header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="'.$type.'"');
+                header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="'.$type.'"', false);
             }
         }
     }
 
-    public function onPluginVersion(&$versions)
+    public function onPluginVersion(array &$versions)
     {
         $versions[] = array('name' => 'WebFinger',
-                            'version' => STATUSNET_VERSION,
+                            'version' => GNUSOCIAL_VERSION,
                             'author' => 'Mikael Nordfeldth',
                             'homepage' => 'http://www.gnu.org/software/social/',
                             // TRANS: Plugin description.