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