-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathext.php
236 lines (210 loc) · 6.87 KB
/
ext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
namespace gn36\hookup;
class ext extends \phpbb\extension\base
{
/**
* An array of all defined notification types so they can be properly enabled/disabled
* @var array
*/
protected $notification_types = array(
'gn36.hookup.notification.type.base',
'gn36.hookup.notification.type.active_date_reset',
'gn36.hookup.notification.type.active_date_set',
'gn36.hookup.notification.type.date_added',
'gn36.hookup.notification.type.date_added_rotation',
'gn36.hookup.notification.type.invited',
'gn36.hookup.notification.type.user_added',
);
/**
* List extra dependencies of this extensions not added to composer.json (e.g. because composer doesn't know them)
* @return multitype:string
*/
protected function extra_dependencies()
{
return array();
}
/**
* Split Version info up into known parts
* @param unknown $string
* @return array|boolean|NULL
*/
protected function split_version_info($string)
{
$pattern = '#(\^|~|>=|>|gt(?:;=?)?|ge|==?|eq|!=|<>|ne|<=|<|le|lt(?:;=?)?(?:gt;)?)([0-9._*-PLAHBETRCDV]+?)(?:$|,)#is';
$matches = null;
preg_match_all($pattern, $string, $matches);
if (!$matches)
{
return false;
}
$ret = array();
$ret['version'] = $matches[2];
$ret['operator'] = $matches[1];
$ret['operator'] = str_replace(array('gt;', 'lt;'), array('>', '<'), $ret['operator']);
return $ret;
}
/**
* @see \phpbb\extension\base::is_enableable()
*/
function is_enableable()
{
$config = $this->container->get('config');
$mgr = $this->container->get('ext.manager');
$template = $this->container->get('template');
$meta_mgr = $mgr->create_extension_metadata_manager($this->extension_name, $template);
$meta = $meta_mgr->get_metadata();
if (isset($meta['require']))
{
$require = $meta['require'];
}
else
{
$require = array();
}
if (isset($meta['extra']['soft_require']))
{
$require = array_merge($require, $meta['extra']['soft_require']);
}
$require = array_merge($require, $this->extra_dependencies());
/** @var $user \phpbb\user */
$user = $this->container->get('user');
$user->add_lang_ext($this->extension_name, 'install');
$dep_files_to_search = array();
foreach ($require as $key => $value)
{
$info = $this->split_version_info($value);
foreach ($info['version'] as $vkey => $version)
{
switch (strtolower($key))
{
case 'php':
if (!phpbb_version_compare(PHP_VERSION, $version, $info['operator'][$vkey]))
{
trigger_error($user->lang('WRONG_PHP_VERSION') . adm_back_link(append_sid('index.' . $this->container->getParameter('core.php_ext'), 'i=acp_extensions&mode=main')), E_USER_WARNING);
return false;
}
break;
case 'phpbb':
case 'phpbb/phpbb':
if (!phpbb_version_compare($config['version'], $version, $info['operator'][$vkey]))
{
trigger_error($user->lang('WRONG_PHPBB_VERSION') . adm_back_link(append_sid('index.' . $this->container->getParameter('core.php_ext'), 'i=acp_extensions&mode=main')), E_USER_WARNING);
return false;
}
break;
case 'gn36/phpbb-oo-posting-api':
$dep_files_to_search[$key] = __DIR__ . '/vendor/gn36/phpbb-oo-posting-api/src/Gn36/OoPostingApi/post.php';
break;
case 'eonasdan/bootstrap-datetimepicker':
$dep_files_to_search[$key] = __DIR__ . '/vendor/eonasdan/bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js';
$dep_files_to_search[$key] = __DIR__ . '/vendor/moment/moment/min/moment.min.js';
break;
case 'components/bootstrap':
$dep_files_to_search[$key] = __DIR__ . '/vendor/components/bootstrap/css/bootstrap.min.css';
break;
case 'fortawesome/font-awesome':
$dep_files_to_search[$key] = __DIR__ . '/vendor/fortawesome/font-awesome/fonts/fontawesome-webfont.eot';
break;
case 'composer/package-versions-deprecated':
case 'ocramius/proxy-manager':
// Fallback case for correct error message
$dep_files_to_search[$key] = __DIR__ . '/vendor/' . $key . '/composer.json';
break;
default:
// First check if this is a dependency in the vendor dir that we missed above
if (file_exists(__DIR__ . '/vendor/' . $key . '/composer.json'))
{
// Assume installed for simplicity
break;
}
// Apparently not a vendor dir. This should be an extension as a requirement
if (!$mgr->is_enabled($key))
{
trigger_error($user->lang('MISSING_EXTENSION', $key) . adm_back_link(append_sid('index.' . $this->container->getParameter('core.php_ext'), 'i=acp_extensions&mode=main')), E_USER_WARNING);
return false;
}
$ext_meta_mgr = $mgr->create_extension_metadata_manager($key, $template);
$ext_meta = $ext_meta_mgr->get_metadata();
$ext_version = $ext_meta['version'];
if (!phpbb_version_compare($ext_version, $version, $info['operator'][$vkey]))
{
trigger_error($user->lang('WRONG_EXTENSION_VERSION', $key) . adm_back_link(append_sid('index.' . $this->container->getParameter('core.php_ext'), 'i=acp_extensions&mode=main')), E_USER_WARNING);
return false;
}
break;
}
}
}
// Now check the files to search for:
foreach ($dep_files_to_search as $key => $file)
{
if (!file_exists($file))
{
trigger_error($user->lang('MISSING_DEPENDENCIES', $key) . adm_back_link(append_sid('index.' . $this->container->getParameter('core.php_ext'), 'i=acp_extensions&mode=main')), E_USER_WARNING);
return false;
}
}
// Apparently passed all checks
return true;
}
/**
* @see \phpbb\extension\base::enable_step()
*/
public function enable_step($old_state)
{
switch ($old_state)
{
case '':
$phpbb_notifications = $this->container->get('notification_manager');
foreach ($this->notification_types as $notification_type)
{
$phpbb_notifications->enable_notifications($notification_type);
}
return 'notifications';
break;
default:
return parent::enable_step($old_state);
break;
}
}
/**
* @see \phpbb\extension\base::disable_step()
*/
public function disable_step($old_state)
{
switch ($old_state)
{
case '':
$phpbb_notifications = $this->container->get('notification_manager');
foreach ($this->notification_types as $notification_type)
{
$phpbb_notifications->disable_notifications($notification_type);
}
return 'notifications';
break;
default:
return parent::disable_step($old_state);
break;
}
}
/**
* @see \phpbb\extension\base::purge_step()
*/
public function purge_step($old_state)
{
switch ($old_state)
{
case '':
$phpbb_notifications = $this->container->get('notification_manager');
foreach ($this->notification_types as $notification_type)
{
$phpbb_notifications->purge_notifications($notification_type);
}
return 'notifications';
break;
default:
return parent::purge_step($old_state);
break;
}
}
}