]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/WebFinger/WebFingerPlugin.php
GNU social is with a minor s.
[quix0rs-gnu-social.git] / plugins / WebFinger / WebFingerPlugin.php
1 <?php
2 /*
3  * GNU Social - a federating social network
4  * Copyright (C) 2013, Free Software Foundation, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * Implements WebFinger for GNU Social, as well as support for the
22  * '.well-known/host-meta' resource.
23  *
24  * Depends on: LRDD plugin
25  *
26  * @package GNUsocial
27  * @author  Mikael Nordfeldth <mmn@hethane.se>
28  */
29
30 if (!defined('GNUSOCIAL')) { exit(1); }
31
32 class WebFingerPlugin extends Plugin
33 {
34     public function onRouterInitialized($m)
35     {
36         $m->connect('.well-known/host-meta', array('action' => 'hostmeta'));
37         $m->connect('.well-known/host-meta.:format',
38                         array('action' => 'hostmeta',
39                               'format' => '(xml|json)'));
40         // the resource GET parameter can be anywhere, so don't mention it here
41         $m->connect('.well-known/webfinger', array('action' => 'webfinger'));
42         $m->connect('.well-known/webfinger.:format',
43                         array('action' => 'webfinger',
44                               'format' => '(xml|json)'));
45         $m->connect('main/ownerxrd', array('action' => 'ownerxrd'));
46         return true;
47     }
48
49     public function onLoginAction($action, &$login)
50     {
51         switch ($action) {
52         case 'hostmeta':
53         case 'webfinger':
54             $login = true;
55             return false;
56         }
57         
58         return true;
59     }
60
61     public function onStartHostMetaLinks(array &$links)
62     {
63         foreach (Discovery::supportedMimeTypes() as $type) {
64             $links[] = new XML_XRD_Element_Link(Discovery::LRDD_REL,
65                             common_local_url('webfinger') . '?resource={uri}',
66                             $type,
67                             true);    // isTemplate
68         }
69     }
70
71     /**
72      * Add a link header for LRDD Discovery
73      */
74     public function onStartShowHTML($action)
75     {
76         if ($action instanceof ShowstreamAction) {
77             $acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
78             $url = common_local_url('webfinger') . '?resource='.$acct;
79
80             foreach (array(Discovery::JRD_MIMETYPE, Discovery::XRD_MIMETYPE) as $type) {
81                 header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="'.$type.'"');
82             }
83         }
84     }
85
86     public function onPluginVersion(&$versions)
87     {
88         $versions[] = array('name' => 'WebFinger',
89                             'version' => STATUSNET_VERSION,
90                             'author' => 'Mikael Nordfeldth',
91                             'homepage' => 'http://www.gnu.org/software/social/',
92                             // TRANS: Plugin description.
93                             'rawdescription' => _m('Adds WebFinger lookup to GNU Social'));
94
95         return true;
96     }
97 }