1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* phpBB Directory extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2014 ErnadoO <http://www.phpbb-services.com> |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
// this file is not really needed, when empty it can be omitted |
12
|
|
|
// however you can override the default methods and add custom |
13
|
|
|
// installation logic |
14
|
|
|
|
15
|
|
|
namespace ernadoo\phpbbdirectory; |
16
|
|
|
|
17
|
|
|
class ext extends \phpbb\extension\base |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Enable extension if requirements are met |
21
|
|
|
* |
22
|
|
|
* @return bool |
23
|
|
|
* @aceess public |
24
|
|
|
*/ |
25
|
|
|
public function is_enableable() |
26
|
|
|
{ |
27
|
|
|
$config = $this->container->get('config'); |
28
|
|
|
|
29
|
|
|
// Check phpbb version |
30
|
|
|
if (!version_compare($config['version'], '3.1.3', '>=')) |
31
|
|
|
{ |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// Check for getimagesize |
36
|
|
|
if (!@function_exists('getimagesize')) |
37
|
|
|
{ |
38
|
|
|
return false; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Check for url_fopen |
42
|
|
|
return (bool) @ini_get('allow_url_fopen'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Single enable step that installs any included migrations |
47
|
|
|
* |
48
|
|
|
* @param mixed $old_state State returned by previous call of this method |
49
|
|
|
* @return mixed Returns false after last step, otherwise temporary state |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function enable_step($old_state) |
52
|
|
|
{ |
53
|
|
|
switch ($old_state) |
54
|
|
|
{ |
55
|
|
|
case '': // Empty means nothing has run yet |
56
|
|
|
|
57
|
|
|
// Enable notifications |
58
|
|
|
return $this->notification_handler('enable', array( |
59
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website', |
60
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_approved', |
61
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved', |
62
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', |
63
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue', |
64
|
|
|
)); |
65
|
|
|
|
66
|
|
|
break; |
67
|
|
|
|
68
|
|
|
default: |
69
|
|
|
|
70
|
|
|
// Run parent enable step method |
71
|
|
|
return parent::enable_step($old_state); |
72
|
|
|
|
73
|
|
|
break; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Single disable step that does nothing |
79
|
|
|
* |
80
|
|
|
* @param mixed $old_state State returned by previous call of this method |
81
|
|
|
* @return mixed Returns false after last step, otherwise temporary state |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function disable_step($old_state) |
84
|
|
|
{ |
85
|
|
|
switch ($old_state) |
86
|
|
|
{ |
87
|
|
|
case '': // Empty means nothing has run yet |
88
|
|
|
|
89
|
|
|
// Disable notifications |
90
|
|
|
return $this->notification_handler('disable', array( |
91
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website', |
92
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_approved', |
93
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved', |
94
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', |
95
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue', |
96
|
|
|
)); |
97
|
|
|
|
98
|
|
|
break; |
99
|
|
|
|
100
|
|
|
default: |
101
|
|
|
|
102
|
|
|
// Run parent disable step method |
103
|
|
|
return parent::disable_step($old_state); |
104
|
|
|
|
105
|
|
|
break; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Single purge step that reverts any included and installed migrations |
111
|
|
|
* |
112
|
|
|
* @param mixed $old_state State returned by previous call of this method |
113
|
|
|
* @return mixed Returns false after last step, otherwise temporary state |
114
|
|
|
*/ |
115
|
|
View Code Duplication |
public function purge_step($old_state) |
116
|
|
|
{ |
117
|
|
|
switch ($old_state) |
118
|
|
|
{ |
119
|
|
|
case '': // Empty means nothing has run yet |
120
|
|
|
|
121
|
|
|
// Purge notifications |
122
|
|
|
return $this->notification_handler('purge', array( |
123
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website', |
124
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_approved', |
125
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved', |
126
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', |
127
|
|
|
'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue', |
128
|
|
|
)); |
129
|
|
|
|
130
|
|
|
break; |
131
|
|
|
|
132
|
|
|
default: |
133
|
|
|
|
134
|
|
|
// Run parent purge step method |
135
|
|
|
return parent::purge_step($old_state); |
136
|
|
|
|
137
|
|
|
break; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Notification handler to call notification enable/disable/purge steps |
143
|
|
|
* |
144
|
|
|
* @author VSEphpbb (Matt Friedman) |
145
|
|
|
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> |
146
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
147
|
|
|
* @param string $step The step (enable, disable, purge) |
148
|
|
|
* @param array $notification_types The notification type names |
149
|
|
|
* @return string Return notifications as temporary state |
150
|
|
|
* @access protected |
151
|
|
|
*/ |
152
|
|
|
protected function notification_handler($step, $notification_types) |
153
|
|
|
{ |
154
|
|
|
$phpbb_notifications = $this->container->get('notification_manager'); |
155
|
|
|
|
156
|
|
|
foreach ($notification_types as $notification_type) |
157
|
|
|
{ |
158
|
|
|
call_user_func(array($phpbb_notifications, $step . '_notifications'), $notification_type); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
return 'notifications'; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|