]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OpenID/OpenIDPlugin.php
5d600159bf9c3c6908907da2c56663604edc6191
[quix0rs-gnu-social.git] / plugins / OpenID / OpenIDPlugin.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
22  * @author    Evan Prodromou <evan@controlyourself.ca>
23  * @copyright 2009 Control Yourself, Inc.
24  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25  * @link      http://laconi.ca/
26  */
27
28 if (!defined('LACONICA')) {
29     exit(1);
30 }
31
32 /**
33  * Plugin for OpenID authentication and identity
34  *
35  * This class enables consumer support for OpenID, the distributed authentication
36  * and identity system.
37  *
38  * @category Plugin
39  * @package  Laconica
40  * @author   Evan Prodromou <evan@controlyourself.ca>
41  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42  * @link     http://laconi.ca/
43  * @link     http://openid.net/
44  */
45
46 class OpenIDPlugin extends Plugin
47 {
48     /**
49      * Initializer for the plugin.
50      */
51
52     function __construct()
53     {
54         parent::__construct();
55     }
56
57     /**
58      * Add OpenID-related paths to the router table
59      *
60      * Hook for RouterInitialized event.
61      *
62      * @return boolean hook return
63      */
64
65     function onRouterInitialized(&$m)
66     {
67         $m->connect('main/openid', array('action' => 'openidlogin'));
68         $m->connect('settings/openid', array('action' => 'openidsettings'));
69         $m->connect(':nickname/xrds',
70                     array('action' => 'xrds'),
71                     array('nickname' => '[a-zA-Z0-9]{1,64}'));
72         $m->connect('xrds', array('action' => 'publicxrds'));
73         $m->connect('index.php?action=finishopenidlogin', array('action' => 'finishopenidlogin'));
74         $m->connect('index.php?action=finishaddopenid', array('action' => 'finishaddopenid'));
75
76         return true;
77     }
78
79     function onEndLoginGroupNav(&$action)
80     {
81         $action_name = $action->trimmed('action');
82
83         $action->menuItem(common_local_url('openidlogin'),
84                           _('OpenID'),
85                           _('Login or register with OpenID'),
86                           $action_name === 'openidlogin');
87
88         return true;
89     }
90
91     function onEndAccountSettingsNav(&$action)
92     {
93         $action_name = $action->trimmed('action');
94
95         $action->menuItem(common_local_url('openidsettings'),
96                           _('OpenID'),
97                           _('Add or remove OpenIDs'),
98                           $action_name === 'openidsettings');
99
100         return true;
101     }
102
103     function onAutoload($cls)
104     {
105         switch ($cls)
106         {
107          case 'OpenidloginAction':
108          case 'FinishopenidloginAction':
109          case 'FinishaddopenidAction':
110          case 'XrdsAction':
111          case 'PublicxrdsAction':
112          case 'OpenidsettingsAction':
113             require_once(INSTALLDIR.'/plugins/OpenID/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
114             return false;
115          case 'User_openid':
116             require_once(INSTALLDIR.'/plugins/OpenID/User_openid.php');
117             return false;
118          default:
119             return true;
120         }
121     }
122 }