]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OpenID/OpenIDPlugin.php
Move some last OpenID stuff into the OpenID plugin (XRDS)
[quix0rs-gnu-social.git] / plugins / OpenID / OpenIDPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * PHP version 5
6  *
7  * LICENCE: This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * @category  Plugin
21  * @package   StatusNet
22  * @author    Evan Prodromou <evan@status.net>
23  * @author    Craig Andrews <candrews@integralblue.com>
24  * @copyright 2009-2010 StatusNet, Inc.
25  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Plugin for OpenID authentication and identity
36  *
37  * This class enables consumer support for OpenID, the distributed authentication
38  * and identity system.
39  *
40  * Depends on: WebFinger plugin for HostMeta-lookup (user@host format)
41  *
42  * @category Plugin
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
45  * @author   Craig Andrews <candrews@integralblue.com>
46  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
47  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48  * @link     http://status.net/
49  * @link     http://openid.net/
50  */
51 class OpenIDPlugin extends Plugin
52 {
53     // Plugin parameter: set true to disallow non-OpenID logins
54     // If set, overrides the setting in database or $config['site']['openidonly']
55     public $openidOnly = null;
56
57     function initialize()
58     {
59         parent::initialize();
60         if ($this->openidOnly !== null) {
61             global $config;
62             $config['site']['openidonly'] = (bool)$this->openidOnly;
63         }
64     }
65
66     /**
67      * Add OpenID-related paths to the router table
68      *
69      * Hook for RouterInitialized event.
70      *
71      * @param URLMapper $m URL mapper
72      *
73      * @return boolean hook return
74      */
75     public function onStartInitializeRouter(URLMapper $m)
76     {
77         $m->connect('main/openid', array('action' => 'openidlogin'));
78         $m->connect('main/openidtrust', array('action' => 'openidtrust'));
79         $m->connect('settings/openid', array('action' => 'openidsettings'));
80         $m->connect('index.php?action=finishopenidlogin',
81                     array('action' => 'finishopenidlogin'));
82         $m->connect('index.php?action=finishaddopenid',
83                     array('action' => 'finishaddopenid'));
84         $m->connect('main/openidserver', array('action' => 'openidserver'));
85         $m->connect('panel/openid', array('action' => 'openidadminpanel'));
86
87         return true;
88     }
89
90     /**
91      * In OpenID-only mode, disable paths for password stuff
92      *
93      * @param string $path     path to connect
94      * @param array  $defaults path defaults
95      * @param array  $rules    path rules
96      * @param array  $result   unused
97      *
98      * @return boolean hook return
99      */
100     function onStartConnectPath(&$path, &$defaults, &$rules, &$result)
101     {
102         if (common_config('site', 'openidonly')) {
103             // Note that we should not remove the login and register
104             // actions. Lots of auth-related things link to them,
105             // such as when visiting a private site without a session
106             // or revalidating a remembered login for admin work.
107             //
108             // We take those two over with redirects to ourselves
109             // over in onArgsInitialize().
110             static $block = array('main/recoverpassword',
111                                   'settings/password');
112
113             if (in_array($path, $block)) {
114                 return false;
115             }
116         }
117
118         return true;
119     }
120
121     /**
122      * If we've been hit with password-login args, redirect
123      *
124      * @param array $args args (URL, Get, post)
125      *
126      * @return boolean hook return
127      */
128     function onArgsInitialize($args)
129     {
130         if (common_config('site', 'openidonly')) {
131             if (array_key_exists('action', $args)) {
132                 $action = trim($args['action']);
133                 if (in_array($action, array('login', 'register'))) {
134                     common_redirect(common_local_url('openidlogin'));
135                 } else if ($action == 'passwordsettings') {
136                     common_redirect(common_local_url('openidsettings'));
137                 } else if ($action == 'recoverpassword') {
138                     // TRANS: Client exception thrown when an action is not available.
139                     throw new ClientException(_m('Unavailable action.'));
140                 }
141             }
142         }
143         return true;
144     }
145
146     /**
147      * Public XRDS output hook
148      *
149      * Puts the bits of code needed by some OpenID providers to show
150      * we're good citizens.
151      *
152      * @param Action       $action         Action being executed
153      * @param XMLOutputter &$xrdsOutputter Output channel
154      *
155      * @return boolean hook return
156      */
157     function onEndPublicXRDS(Action $action, &$xrdsOutputter)
158     {
159         $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
160                                                   'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
161                                                   'version' => '2.0'));
162         $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
163         //consumer
164         foreach (array('finishopenidlogin', 'finishaddopenid') as $finish) {
165             $xrdsOutputter->showXrdsService(Auth_OpenID_RP_RETURN_TO_URL_TYPE,
166                                             common_local_url($finish));
167         }
168         //provider
169         $xrdsOutputter->showXrdsService('http://specs.openid.net/auth/2.0/server',
170                                         common_local_url('openidserver'),
171                                         null,
172                                         null,
173                                         'http://specs.openid.net/auth/2.0/identifier_select');
174         $xrdsOutputter->elementEnd('XRD');
175     }
176
177     /**
178      * User XRDS output hook
179      *
180      * Puts the bits of code needed to discover OpenID endpoints.
181      *
182      * @param Action       $action         Action being executed
183      * @param XMLOutputter &$xrdsOutputter Output channel
184      *
185      * @return boolean hook return
186      */
187     function onEndUserXRDS(Action $action, &$xrdsOutputter)
188     {
189         $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
190                                                   'xml:id' => 'openid',
191                                                   'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
192                                                   'version' => '2.0'));
193         $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
194
195         //consumer
196         $xrdsOutputter->showXrdsService('http://specs.openid.net/auth/2.0/return_to',
197                                         common_local_url('finishopenidlogin'));
198
199         //provider
200         $xrdsOutputter->showXrdsService('http://specs.openid.net/auth/2.0/signon',
201                                         common_local_url('openidserver'),
202                                         null,
203                                         null,
204                                         common_profile_url($action->user->nickname));
205         $xrdsOutputter->elementEnd('XRD');
206     }
207
208     /**
209      * If we're in OpenID-only mode, hide all the main menu except OpenID login.
210      *
211      * @param Action $action Action being run
212      *
213      * @return boolean hook return
214      */
215     function onStartPrimaryNav($action)
216     {
217         if (common_config('site', 'openidonly') && !common_logged_in()) {
218             // TRANS: Tooltip for main menu option "Login"
219             $tooltip = _m('TOOLTIP', 'Login to the site.');
220             $action->menuItem(common_local_url('openidlogin'),
221                               // TRANS: Main menu option when not logged in to log in
222                               _m('MENU', 'Login'),
223                               $tooltip,
224                               false,
225                               'nav_login');
226             // TRANS: Tooltip for main menu option "Help"
227             $tooltip = _m('TOOLTIP', 'Help me!');
228             $action->menuItem(common_local_url('doc', array('title' => 'help')),
229                               // TRANS: Main menu option for help on the StatusNet site
230                               _m('MENU', 'Help'),
231                               $tooltip,
232                               false,
233                               'nav_help');
234             if (!common_config('site', 'private')) {
235                 // TRANS: Tooltip for main menu option "Search"
236                 $tooltip = _m('TOOLTIP', 'Search for people or text.');
237                 $action->menuItem(common_local_url('peoplesearch'),
238                                   // TRANS: Main menu option when logged in or when the StatusNet instance is not private
239                                   _m('MENU', 'Search'), $tooltip, false, 'nav_search');
240             }
241             Event::handle('EndPrimaryNav', array($action));
242             return false;
243         }
244         return true;
245     }
246
247     /**
248      * Menu for login
249      *
250      * If we're in openidOnly mode, we disable the menu for all other login.
251      *
252      * @param Action $action Action being executed
253      *
254      * @return boolean hook return
255      */
256     function onStartLoginGroupNav($action)
257     {
258         if (common_config('site', 'openidonly')) {
259             $this->showOpenIDLoginTab($action);
260             // Even though we replace this code, we
261             // DON'T run the End* hook, to keep others from
262             // adding tabs. Not nice, but.
263             return false;
264         }
265
266         return true;
267     }
268
269     /**
270      * Menu item for login
271      *
272      * @param Action $action Action being executed
273      *
274      * @return boolean hook return
275      */
276     function onEndLoginGroupNav($action)
277     {
278         $this->showOpenIDLoginTab($action);
279
280         return true;
281     }
282
283     /**
284      * Show menu item for login
285      *
286      * @param Action $action Action being executed
287      *
288      * @return void
289      */
290     function showOpenIDLoginTab($action)
291     {
292         $action_name = $action->trimmed('action');
293
294         $action->menuItem(common_local_url('openidlogin'),
295                           // TRANS: OpenID plugin menu item on site logon page.
296                           _m('MENU', 'OpenID'),
297                           // TRANS: OpenID plugin tooltip for logon menu item.
298                           _m('Login or register with OpenID.'),
299                           $action_name === 'openidlogin');
300     }
301
302     /**
303      * Show menu item for password
304      *
305      * We hide it in openID-only mode
306      *
307      * @param Action $menu    Widget for menu
308      * @param void   &$unused Unused value
309      *
310      * @return void
311      */
312     function onStartAccountSettingsPasswordMenuItem($menu, &$unused) {
313         if (common_config('site', 'openidonly')) {
314             return false;
315         }
316         return true;
317     }
318
319     /**
320      * Menu item for OpenID settings
321      *
322      * @param Action $action Action being executed
323      *
324      * @return boolean hook return
325      */
326     function onEndAccountSettingsNav($action)
327     {
328         $action_name = $action->trimmed('action');
329
330         $action->menuItem(common_local_url('openidsettings'),
331                           // TRANS: OpenID plugin menu item on user settings page.
332                           _m('MENU', 'OpenID'),
333                           // TRANS: OpenID plugin tooltip for user settings menu item.
334                           _m('Add or remove OpenIDs.'),
335                           $action_name === 'openidsettings');
336
337         return true;
338     }
339
340     /**
341      * Autoloader
342      *
343      * Loads our classes if they're requested.
344      *
345      * @param string $cls Class requested
346      *
347      * @return boolean hook return
348      */
349     function onAutoload($cls)
350     {
351         switch ($cls)
352         {
353         case 'Auth_OpenID_TeamsExtension':
354         case 'Auth_OpenID_TeamsRequest':
355         case 'Auth_OpenID_TeamsResponse':
356             require_once dirname(__FILE__) . '/extlib/teams-extension.php';
357             return false;
358         }
359
360         return parent::onAutoload($cls);
361     }
362
363     /**
364      * Sensitive actions
365      *
366      * These actions should use https when SSL support is 'sometimes'
367      *
368      * @param Action  $action Action to form an URL for
369      * @param boolean &$ssl   Whether to mark it for SSL
370      *
371      * @return boolean hook return
372      */
373     function onSensitiveAction($action, &$ssl)
374     {
375         switch ($action)
376         {
377         case 'finishopenidlogin':
378         case 'finishaddopenid':
379             $ssl = true;
380             return false;
381         default:
382             return true;
383         }
384     }
385
386     /**
387      * Login actions
388      *
389      * These actions should be visible even when the site is marked private
390      *
391      * @param Action  $action Action to show
392      * @param boolean &$login Whether it's a login action
393      *
394      * @return boolean hook return
395      */
396     function onLoginAction($action, &$login)
397     {
398         switch ($action)
399         {
400         case 'openidlogin':
401         case 'finishopenidlogin':
402         case 'openidserver':
403             $login = true;
404             return false;
405         default:
406             return true;
407         }
408     }
409
410     /**
411      * We include a <meta> element linking to the webfinger resource page,
412      * for OpenID client-side authentication.
413      *
414      * @param Action $action Action being shown
415      *
416      * @return void
417      */
418     function onEndShowHeadElements(Action $action)
419     {
420         if ($action instanceof ShowstreamAction) {
421             $action->element('link', array('rel' => 'openid2.provider',
422                                            'href' => common_local_url('openidserver')));
423             $action->element('link', array('rel' => 'openid2.local_id',
424                                            'href' => $action->profile->profileurl));
425             $action->element('link', array('rel' => 'openid.server',
426                                            'href' => common_local_url('openidserver')));
427             $action->element('link', array('rel' => 'openid.delegate',
428                                            'href' => $action->profile->profileurl));
429         }
430
431         if ($action instanceof SitestreamAction) {
432             $action->element('meta', array('http-equiv' => 'X-XRDS-Location',
433                                          'content' => common_local_url('publicxrds')));
434         }
435         return true;
436     }
437
438     /**
439      * Redirect to OpenID login if they have an OpenID
440      *
441      * @param Action $action Action being executed
442      * @param User   $user   User doing the action
443      *
444      * @return boolean whether to continue
445      */
446     function onRedirectToLogin($action, $user)
447     {
448         if (common_config('site', 'openid_only') || (!empty($user) && User_openid::hasOpenID($user->id))) {
449             common_redirect(common_local_url('openidlogin'), 303);
450         }
451         return true;
452     }
453
454     /**
455      * Show some extra instructions for using OpenID
456      *
457      * @param Action $action Action being executed
458      *
459      * @return boolean hook value
460      */
461     function onEndShowPageNotice($action)
462     {
463         $name = $action->trimmed('action');
464
465         switch ($name)
466         {
467         case 'register':
468             if (common_logged_in()) {
469                 // TRANS: Page notice for logged in users to try and get them to add an OpenID account to their StatusNet account.
470                 // TRANS: This message contains Markdown links in the form (description)[link].
471                 $instr = _m('(Have an [OpenID](http://openid.net/)? ' .
472                   '[Add an OpenID to your account](%%action.openidsettings%%)!');
473             } else {
474                 // TRANS: Page notice for anonymous users to try and get them to register with an OpenID account.
475                 // TRANS: This message contains Markdown links in the form (description)[link].
476                 $instr = _m('(Have an [OpenID](http://openid.net/)? ' .
477                   'Try our [OpenID registration]'.
478                   '(%%action.openidlogin%%)!)');
479             }
480             break;
481         case 'login':
482             // TRANS: Page notice on the login page to try and get them to log on with an OpenID account.
483             // TRANS: This message contains Markdown links in the form (description)[link].
484             $instr = _m('(Have an [OpenID](http://openid.net/)? ' .
485               'Try our [OpenID login]'.
486               '(%%action.openidlogin%%)!)');
487             break;
488         default:
489             return true;
490         }
491
492         $output = common_markup_to_html($instr);
493         $action->raw($output);
494         return true;
495     }
496
497     /**
498      * Load our document if requested
499      *
500      * @param string &$title  Title to fetch
501      * @param string &$output HTML to output
502      *
503      * @return boolean hook value
504      */
505     function onStartLoadDoc(&$title, &$output)
506     {
507         if ($title == 'openid') {
508             $filename = INSTALLDIR.'/plugins/OpenID/doc-src/openid';
509
510             $c      = file_get_contents($filename);
511             $output = common_markup_to_html($c);
512             return false; // success!
513         }
514
515         return true;
516     }
517
518     /**
519      * Add our document to the global menu
520      *
521      * @param string $title   Title being fetched
522      * @param string &$output HTML being output
523      *
524      * @return boolean hook value
525      */
526     function onEndDocsMenu(&$items) {
527         $items[] = array('doc', 
528                          array('title' => 'openid'),
529                          _m('MENU', 'OpenID'),
530                          _('Logging in with OpenID'),
531                          'nav_doc_openid');
532         return true;
533     }
534
535     /**
536      * Data definitions
537      *
538      * Assure that our data objects are available in the DB
539      *
540      * @return boolean hook value
541      */
542     function onCheckSchema()
543     {
544         $schema = Schema::get();
545         $schema->ensureTable('user_openid', User_openid::schemaDef());
546         $schema->ensureTable('user_openid_trustroot', User_openid_trustroot::schemaDef());
547         $schema->ensureTable('user_openid_prefs', User_openid_prefs::schemaDef());
548
549         /* These are used by JanRain OpenID library */
550
551         $schema->ensureTable('oid_associations',
552                              array(
553                                  'fields' => array(
554                                      'server_url' => array('type' => 'blob', 'not null' => true),
555                                      'handle' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'default' => ''), // character set latin1,
556                                      'secret' => array('type' => 'blob'),
557                                      'issued' => array('type' => 'int'),
558                                      'lifetime' => array('type' => 'int'),
559                                      'assoc_type' => array('type' => 'varchar', 'length' => 64),
560                                  ),
561                                  'primary key' => array(array('server_url', 191), 'handle'),
562                              ));
563         $schema->ensureTable('oid_nonces',
564                              array(
565                                  'fields' => array(
566                                      'server_url' => array('type' => 'varchar', 'length' => 2047),
567                                      'timestamp' => array('type' => 'int'),
568                                      'salt' => array('type' => 'char', 'length' => 40),
569                                  ),
570                                  'unique keys' => array(
571                                      'oid_nonces_server_url_timestamp_salt_key' => array(array('server_url', 191), 'timestamp', 'salt'),
572                                  ),
573                              ));
574
575         return true;
576     }
577
578     /**
579      * Add our tables to be deleted when a user is deleted
580      *
581      * @param User  $user    User being deleted
582      * @param array &$tables Array of table names
583      *
584      * @return boolean hook value
585      */
586     function onUserDeleteRelated($user, &$tables)
587     {
588         $tables[] = 'User_openid';
589         $tables[] = 'User_openid_trustroot';
590         return true;
591     }
592
593     /**
594      * Add an OpenID tab to the admin panel
595      *
596      * @param Widget $nav Admin panel nav
597      *
598      * @return boolean hook value
599      */
600     function onEndAdminPanelNav($nav)
601     {
602         if (AdminPanelAction::canAdmin('openid')) {
603
604             $action_name = $nav->action->trimmed('action');
605
606             $nav->out->menuItem(
607                 common_local_url('openidadminpanel'),
608                 // TRANS: OpenID configuration menu item.
609                 _m('MENU','OpenID'),
610                 // TRANS: Tooltip for OpenID configuration menu item.
611                 _m('OpenID configuration.'),
612                 $action_name == 'openidadminpanel',
613                 'nav_openid_admin_panel'
614             );
615         }
616
617         return true;
618     }
619
620     /**
621      * Add OpenID information to the Account Management Control Document
622      * Event supplied by the Account Manager plugin
623      *
624      * @param array &$amcd Array that expresses the AMCD
625      *
626      * @return boolean hook value
627      */
628
629     function onEndAccountManagementControlDocument(&$amcd)
630     {
631         $amcd['auth-methods']['openid'] = array(
632             'connect' => array(
633                 'method' => 'POST',
634                 'path' => common_local_url('openidlogin'),
635                 'params' => array(
636                     'identity' => 'openid_url'
637                 )
638             )
639         );
640     }
641
642     /**
643      * Add our version information to output
644      *
645      * @param array &$versions Array of version-data arrays
646      *
647      * @return boolean hook value
648      */
649     function onPluginVersion(&$versions)
650     {
651         $versions[] = array('name' => 'OpenID',
652                             'version' => GNUSOCIAL_VERSION,
653                             'author' => 'Evan Prodromou, Craig Andrews',
654                             'homepage' => 'http://status.net/wiki/Plugin:OpenID',
655                             'rawdescription' =>
656                             // TRANS: Plugin description.
657                             _m('Use <a href="http://openid.net/">OpenID</a> to login to the site.'));
658         return true;
659     }
660
661     function onStartOAuthLoginForm($action, &$button)
662     {
663         if (common_config('site', 'openidonly')) {
664             // Cancel the regular password login form, we won't need it.
665             $this->showOAuthLoginForm($action);
666             // TRANS: button label for OAuth authorization page when needing OpenID authentication first.
667             $button = _m('BUTTON', 'Continue');
668             return false;
669         } else {
670             // Leave the regular password login form in place.
671             // We'll add an OpenID link at bottom...?
672             return true;
673         }
674     }
675
676     /**
677      * @fixme merge with common code for main OpenID login form
678      * @param HTMLOutputter $action
679      */
680     protected function showOAuthLoginForm($action)
681     {
682         $action->elementStart('fieldset');
683         // TRANS: OpenID plugin logon form legend.
684         $action->element('legend', null, _m('LEGEND','OpenID login'));
685
686         $action->elementStart('ul', 'form_data');
687         $action->elementStart('li');
688         $provider = common_config('openid', 'trusted_provider');
689         $appendUsername = common_config('openid', 'append_username');
690         if ($provider) {
691             // TRANS: Field label.
692             $action->element('label', array(), _m('OpenID provider'));
693             $action->element('span', array(), $provider);
694             if ($appendUsername) {
695                 $action->element('input', array('id' => 'openid_username',
696                                               'name' => 'openid_username',
697                                               'style' => 'float: none'));
698             }
699             $action->element('p', 'form_guide',
700                            // TRANS: Form guide.
701                            ($appendUsername ? _m('Enter your username.') . ' ' : '') .
702                            // TRANS: Form guide.
703                            _m('You will be sent to the provider\'s site for authentication.'));
704             $action->hidden('openid_url', $provider);
705         } else {
706             // TRANS: OpenID plugin logon form field label.
707             $action->input('openid_url', _m('OpenID URL'),
708                          '',
709                         // TRANS: OpenID plugin logon form field instructions.
710                          _m('Your OpenID URL.'));
711         }
712         $action->elementEnd('li');
713         $action->elementEnd('ul');
714
715         $action->elementEnd('fieldset');
716     }
717
718     /**
719      * Handle a POST user credential check in apioauthauthorization.
720      * If given an OpenID URL, we'll pass us over to the regular things
721      * and then redirect back here on completion.
722      *
723      * @fixme merge with common code for main OpenID login form
724      * @param HTMLOutputter $action
725      */
726     function onStartOAuthLoginCheck($action, &$user)
727     {
728         $provider = common_config('openid', 'trusted_provider');
729         if ($provider) {
730             $openid_url = $provider;
731             if (common_config('openid', 'append_username')) {
732                 $openid_url .= $action->trimmed('openid_username');
733             }
734         } else {
735             $openid_url = $action->trimmed('openid_url');
736         }
737
738         if ($openid_url) {
739             require_once dirname(__FILE__) . '/openid.php';
740             oid_assert_allowed($openid_url);
741
742             $returnto = common_local_url(
743                 'ApiOAuthAuthorize',
744                 array(),
745                 array(
746                     'oauth_token' => $action->arg('oauth_token'),
747                     'mode'        => $action->arg('mode')
748                 )
749             );
750             common_set_returnto($returnto);
751
752             // This will redirect if functional...
753             $result = oid_authenticate($openid_url,
754                                        'finishopenidlogin');
755             if (is_string($result)) { # error message
756                 throw new ServerException($result);
757             } else {
758                 exit(0);
759             }
760         }
761
762         return true;
763     }
764
765     /**
766      * Add link in user's XRD file to allow OpenID login.
767      *
768      * This link in the XRD should let users log in with their
769      * Webfinger identity to services that support it. See
770      * http://webfinger.org/login for an example.
771      *
772      * @param XML_XRD   $xrd    Currently-displaying resource descriptor
773      * @param Profile   $target The profile that it's for
774      *
775      * @return boolean hook value (always true)
776      */
777
778     function onEndWebFingerProfileLinks(XML_XRD $xrd, Profile $target)
779     {
780         $xrd->links[] = new XML_XRD_Element_Link(
781                             'http://specs.openid.net/auth/2.0/provider',
782                             $target->profileurl);
783
784         return true;
785     }
786
787     /**
788      * Add links in the user's profile block to their OpenID URLs.
789      *
790      * @param Profile $profile The profile being shown
791      * @param Array   &$links  Writeable array of arrays (href, text, image).
792      *
793      * @return boolean hook value (true)
794      */
795     
796     function onOtherAccountProfiles($profile, &$links)
797     {
798         $prefs = User_openid_prefs::getKV('user_id', $profile->id);
799
800         if (empty($prefs) || !$prefs->hide_profile_link) {
801
802             $oid = new User_openid();
803
804             $oid->user_id = $profile->id;
805
806             if ($oid->find()) {
807                 while ($oid->fetch()) {
808                     $links[] = array('href' => $oid->display,
809                                      'text' => _('OpenID'),
810                                      'image' => $this->path("icons/openid-16x16.gif"));
811                 }
812             }
813         }
814
815         return true;
816     }
817 }