52716845155f82520477f39df0302a1e8824f21d
[platal.git] / modules / openid / openid.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 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 General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once "Auth/OpenID/Discover.php";
23
24 function init_openid_server()
25 {
26 // Initialize a filesystem-based store
27 $store_location = dirname(__FILE__) . '/../../spool/openid/store';
28 require_once "Auth/OpenID/FileStore.php";
29 $store = new Auth_OpenID_FileStore($store_location);
30
31 // Create an OpenId server
32 require_once 'Auth/OpenID/Server.php';
33 return new Auth_OpenID_Server($store, get_openid_url());
34 }
35
36 function get_openid_url()
37 {
38 global $globals;
39 return $globals->baseurl . '/openid';
40 }
41
42 function get_user($x) {
43 if (is_null($x)) {
44 return null;
45 }
46 $user = User::getSilent($x);
47 return $user ? $user : null;
48
49 }
50
51 function get_user_openid_url($user)
52 {
53 if (is_null($user)) {
54 return null;
55 }
56 global $globals;
57 return $globals->baseurl . '/openid/' . $user->hruid;
58 }
59
60 function get_user_xrds_url($user)
61 {
62 if (is_null($user)) {
63 return null;
64 }
65 global $globals;
66 return $globals->baseurl . '/openid/user_xrds/' . $user->hruid;
67 }
68
69 function get_sreg_data($user)
70 {
71 if (is_null($user)) {
72 return null;
73 }
74 return array('fullname' => $user->fullName(),
75 'nickname' => $user->displayName(),
76 'dob' => null,
77 'email' => $user->bestEmail(),
78 'gender' => $user->isFemale() ? 'F' : 'M',
79 'postcode' => null,
80 'country' => null,
81 'language' => null,
82 'timezone' => null);
83 }
84
85
86 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
87 ?>