|
1
|
|
|
<?php |
|
2
|
|
|
//------------------------------------------------------------------------- |
|
3
|
|
|
// OVIDENTIA http://www.ovidentia.org |
|
4
|
|
|
// Ovidentia is free software; you can redistribute it and/or modify |
|
5
|
|
|
// it under the terms of the GNU General Public License as published by |
|
6
|
|
|
// the Free Software Foundation; either version 2, or (at your option) |
|
7
|
|
|
// any later version. |
|
8
|
|
|
// |
|
9
|
|
|
// This program is distributed in the hope that it will be useful, but |
|
10
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
12
|
|
|
// See the GNU General Public License for more details. |
|
13
|
|
|
// |
|
14
|
|
|
// You should have received a copy of the GNU General Public License |
|
15
|
|
|
// along with this program; if not, write to the Free Software |
|
16
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
17
|
|
|
// USA. |
|
18
|
|
|
//------------------------------------------------------------------------- |
|
19
|
|
|
/** |
|
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
|
21
|
|
|
* @copyright Copyright (c) 2010 by CANTICO ({@link http://www.cantico.fr}) |
|
22
|
|
|
*/ |
|
23
|
|
|
require_once dirname(__FILE__).'/functions.php'; |
|
24
|
|
|
|
|
25
|
|
|
function LibCaldav_upgrade($version_base, $version_ini) |
|
26
|
|
|
{ |
|
27
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; |
|
28
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/functionalityincl.php'; |
|
29
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/eventincl.php"; |
|
30
|
|
|
|
|
31
|
|
|
if (!@bab_functionality::includefile('CalendarBackend')) { |
|
|
|
|
|
|
32
|
|
|
return false; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$addonName = 'LibCaldav'; |
|
36
|
|
|
$addonInfo = bab_getAddonInfosInstance($addonName); |
|
37
|
|
|
|
|
38
|
|
|
$addonPhpPath = $addonInfo->getPhpPath(); |
|
39
|
|
|
|
|
40
|
|
|
$functionalities = new bab_functionalities(); |
|
41
|
|
|
$functionalities->registerClass('Func_CalendarBackend_Caldav', $addonPhpPath . 'caldav.class.php'); |
|
42
|
|
|
|
|
43
|
|
|
$addonInfo->removeAllEventListeners(); |
|
44
|
|
|
$addonInfo->addEventListener('bab_eventBeforePeriodsCreated', 'caldav_onBeforePeriodsCreated', 'eventperiod.php'); |
|
45
|
|
|
$addonInfo->addEventListener('bab_eventBeforePeriodsCreated', 'caldav_onBeforePeriodsCreated', 'eventperiod.php'); |
|
46
|
|
|
$addonInfo->addEventListener('bab_eventCollectCalendarsBeforeDisplay', 'caldav_onCollectCalendarsBeforeDisplay', 'eventperiod.php'); |
|
47
|
|
|
$addonInfo->addEventListener('bab_eventPageRefreshed', 'LibCaldav_onPageRefreshed', 'init.php'); |
|
48
|
|
|
$addonInfo->addEventListener('bab_eventUserCreated', 'LibCaldav_onUserCreated', 'init.php'); |
|
49
|
|
|
|
|
50
|
|
|
$tables = new bab_synchronizeSql(); |
|
51
|
|
|
$tables->fromSqlFile(dirname(__FILE__).'/tables.sql'); |
|
52
|
|
|
|
|
53
|
|
|
$registry = bab_getRegistryInstance(); |
|
54
|
|
|
$registry->changeDirectory('/LibCaldav/'); |
|
55
|
|
|
|
|
56
|
|
|
if ($serverUrl = $registry->getValue('defaultServerUrl')) |
|
57
|
|
|
{ |
|
58
|
|
|
// move default server from registry to server table |
|
59
|
|
|
|
|
60
|
|
|
$userCalendarPath = $registry->getValue('defaultUserCalendarPath'); |
|
61
|
|
|
|
|
62
|
|
|
$url = parse_url($serverUrl); |
|
63
|
|
|
if (isset($url['host'])) |
|
64
|
|
|
{ |
|
65
|
|
|
$host = $url['host']; |
|
66
|
|
|
} else { |
|
67
|
|
|
$host = 'Serveur'; |
|
68
|
|
|
} |
|
69
|
|
|
$useuniqueid = 'false'; |
|
70
|
|
|
global $babDB; |
|
71
|
|
|
$babDB->db_query('INSERT INTO libcaldav_servers (name, server_url, user_calendar_path, use_unique_id) |
|
72
|
|
|
VALUES ('.$babDB->quote($host).', '.$babDB->quote($serverUrl).', '.$babDB->quote($userCalendarPath).', '.$babDB->quote($useuniqueid).')'); |
|
73
|
|
|
|
|
74
|
|
|
$id_server = (int) $babDB->db_insert_id(); |
|
75
|
|
|
|
|
76
|
|
|
$registry->removeKey('defaultUserCalendarPath'); |
|
77
|
|
|
$registry->removeKey('defaultServerUrl'); |
|
78
|
|
|
|
|
79
|
|
|
// browse users |
|
80
|
|
|
|
|
81
|
|
|
$registry->changeDirectory('/LibCaldav/Users/'); |
|
82
|
|
|
$keys = array(); |
|
83
|
|
|
while ($id_user = $registry->fetchChildDir()) |
|
84
|
|
|
{ |
|
85
|
|
|
$keys[] = $id_user; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
foreach($keys as $dirkey) |
|
89
|
|
|
{ |
|
90
|
|
|
$registry->changeDirectory("/LibCaldav/Users/$dirkey"); |
|
91
|
|
|
$registry->setKeyValue('server', $id_server); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return true; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$GLOBALS['LibCaldav_AdminSectionMenus'] = array( |
|
99
|
|
|
'CalDAV configuration' => $GLOBALS['babAddonUrl'].'configuration' |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
function LibCaldav_getAdminSectionMenus(&$url, &$text) |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
global $LibCaldav_AdminSectionMenus; |
|
105
|
|
|
if (list($text, $url) = each($LibCaldav_AdminSectionMenus)) |
|
106
|
|
|
{ |
|
107
|
|
|
$text = caldav_translate($text); |
|
108
|
|
|
return true; |
|
109
|
|
|
} |
|
110
|
|
|
reset($LibCaldav_AdminSectionMenus); |
|
111
|
|
|
return false; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
function LibCaldav_onDeleteAddon() |
|
118
|
|
|
{ |
|
119
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/functionalityincl.php'; |
|
120
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/eventincl.php"; |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
bab_removeEventListener('bab_eventBeforePeriodsCreated' ,'caldav_onBeforePeriodsCreated' ,'addons/LibCaldav/eventperiod.php'); |
|
124
|
|
|
bab_removeEventListener('bab_eventCollectCalendarsBeforeDisplay','caldav_onCollectCalendarsBeforeDisplay' ,'addons/LibCaldav/eventperiod.php'); |
|
125
|
|
|
bab_removeEventListener('bab_eventPageRefreshed', 'LibCaldav_onPageRefreshed', 'addons/LibCaldav/init.php'); |
|
126
|
|
|
bab_removeEventListener('bab_eventUserCreated', 'LibCaldav_onUserCreated', 'addons/LibCaldav/init.php'); |
|
127
|
|
|
|
|
128
|
|
|
$functionalities = new bab_functionalities(); |
|
129
|
|
|
$functionalities->unregister('CalendarBackend/Caldav'); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
function LibCaldav_onPageRefreshed(bab_eventPageRefreshed $event) |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
// afficher les stats de connexion a caldav |
|
138
|
|
|
|
|
139
|
|
|
/* |
|
140
|
|
|
if (!isset($_SESSION['LibCaldav']['stats'])) |
|
141
|
|
|
{ |
|
142
|
|
|
return; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if (isset($_SESSION['LibCaldav']['stats']['pending'])) { |
|
146
|
|
|
$_SESSION['LibCaldav']['stats'][date('H:i:s')] = array_values($_SESSION['LibCaldav']['stats']['pending']); |
|
147
|
|
|
unset($_SESSION['LibCaldav']['stats']['pending']); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
// get only the last 10 queries |
|
151
|
|
|
if (count($_SESSION['LibCaldav']['stats']) > 10) |
|
152
|
|
|
{ |
|
153
|
|
|
$_SESSION['LibCaldav']['stats'] = array_slice($_SESSION['LibCaldav']['stats'], -10, 10, true); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
bab_debug($_SESSION['LibCaldav']['stats'], DBG_TRACE, 'Caldav statistics'); |
|
158
|
|
|
*/ |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
function LibCaldav_onUserCreated(bab_eventUserCreated $event) |
|
164
|
|
|
{ |
|
165
|
|
|
$registry = bab_getRegistryInstance(); |
|
166
|
|
|
$registry->changeDirectory('/LibCaldav/'); |
|
167
|
|
|
|
|
168
|
|
|
if ($registry->getValue('default_backend')) |
|
169
|
|
|
{ |
|
170
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/calapi.php'; |
|
171
|
|
|
|
|
172
|
|
|
/* @var $caldav Func_CalendarBackend_Caldav */ |
|
173
|
|
|
$caldav = bab_functionality::get('CalendarBackend/Caldav'); |
|
174
|
|
|
|
|
175
|
|
|
bab_setPersonnalCalendarBackend($event->id_user, $caldav); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
} |
|
180
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: