1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Advanced BBCode Box |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2020 Matt Friedman |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace vse\abbc3\acp; |
12
|
|
|
|
13
|
|
|
class abbc3_module |
14
|
|
|
{ |
15
|
|
|
/** @var \phpbb\cache\driver\driver_interface */ |
|
|
|
|
16
|
|
|
protected $cache; |
17
|
|
|
|
18
|
|
|
/** @var \phpbb\config\config */ |
|
|
|
|
19
|
|
|
protected $config; |
20
|
|
|
|
21
|
|
|
/** @var \phpbb\config\db_text */ |
|
|
|
|
22
|
|
|
protected $config_text; |
23
|
|
|
|
24
|
|
|
/** @var \Symfony\Component\DependencyInjection\ContainerInterface */ |
|
|
|
|
25
|
|
|
protected $container; |
26
|
|
|
|
27
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
|
|
|
|
28
|
|
|
protected $db; |
29
|
|
|
|
30
|
|
|
/** @var \phpbb\extension\manager */ |
|
|
|
|
31
|
|
|
protected $ext_manager; |
32
|
|
|
|
33
|
|
|
/** @var \phpbb\language\language */ |
|
|
|
|
34
|
|
|
protected $language; |
35
|
|
|
|
36
|
|
|
/** @var \phpbb\request\request */ |
|
|
|
|
37
|
|
|
protected $request; |
38
|
|
|
|
39
|
|
|
/** @var \phpbb\template\template */ |
|
|
|
|
40
|
|
|
protected $template; |
41
|
|
|
|
42
|
|
|
/** @var string */ |
43
|
|
|
public $page_title; |
44
|
|
|
|
45
|
|
|
/** @var string */ |
46
|
|
|
public $tpl_name; |
47
|
|
|
|
48
|
|
|
/** @var string */ |
49
|
|
|
public $u_action; |
50
|
|
|
|
51
|
|
|
/** @var array */ |
52
|
|
|
protected $errors = []; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Constructor |
56
|
|
|
* |
57
|
|
|
* @throws \Exception |
58
|
|
|
*/ |
59
|
|
|
public function __construct() |
60
|
|
|
{ |
61
|
|
|
global $phpbb_container; |
62
|
|
|
|
63
|
|
|
$this->container = $phpbb_container; |
64
|
|
|
$this->cache = $this->container->get('cache'); |
65
|
|
|
$this->config = $this->container->get('config'); |
66
|
|
|
$this->config_text = $this->container->get('config_text'); |
67
|
|
|
$this->db = $this->container->get('dbal.conn'); |
68
|
|
|
$this->ext_manager = $this->container->get('ext.manager'); |
69
|
|
|
$this->language = $this->container->get('language'); |
70
|
|
|
$this->request = $this->container->get('request'); |
71
|
|
|
$this->template = $this->container->get('template'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Main ACP module |
76
|
|
|
*/ |
77
|
|
|
public function main() |
78
|
|
|
{ |
79
|
|
|
$this->language->add_lang('abbc3', 'vse/abbc3'); |
80
|
|
|
|
81
|
|
|
$this->tpl_name = 'acp_abbc3_settings'; |
82
|
|
|
$this->page_title = $this->language->lang('ACP_ABBC3_SETTINGS'); |
83
|
|
|
|
84
|
|
|
$form_key = 'vse/abbc3'; |
85
|
|
|
add_form_key($form_key); |
|
|
|
|
86
|
|
|
|
87
|
|
|
if ($this->request->is_set_post('submit')) |
88
|
|
|
{ |
89
|
|
|
if (!check_form_key($form_key)) |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
trigger_error('FORM_INVALID', E_USER_WARNING); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->save_settings(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->display_settings(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Add settings template vars to the form |
102
|
|
|
*/ |
103
|
|
|
protected function display_settings() |
104
|
|
|
{ |
105
|
|
|
$this->template->assign_vars([ |
106
|
|
|
'S_ABBC3_PIPES' => $this->config['abbc3_pipes'], |
107
|
|
|
'S_ABBC3_BBCODE_BAR' => $this->config['abbc3_bbcode_bar'], |
108
|
|
|
'S_ABBC3_QR_BBCODES' => $this->config['abbc3_qr_bbcodes'], |
109
|
|
|
'S_ABBC3_AUTO_VIDEO' => $this->config['abbc3_auto_video'], |
110
|
|
|
'S_ABBC3_ICONS_TYPE' => build_select(['png' => 'PNG', 'svg' => 'SVG'], $this->config['abbc3_icons_type']), |
|
|
|
|
111
|
|
|
'S_ABBC3_GOOGLE_FONTS' => $this->show_google_fonts(), |
112
|
|
|
'S_ABBC3_MEDIA_EMBED' => (int) $this->ext_manager->is_enabled('phpbb/mediaembed'), |
113
|
|
|
'U_ACTION' => $this->u_action, |
114
|
|
|
]); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Save settings data to the database |
119
|
|
|
*/ |
120
|
|
|
protected function save_settings() |
121
|
|
|
{ |
122
|
|
|
$this->config->set('abbc3_bbcode_bar', $this->request->variable('abbc3_bbcode_bar', 0)); |
123
|
|
|
$this->config->set('abbc3_qr_bbcodes', $this->request->variable('abbc3_qr_bbcodes', 0)); |
124
|
|
|
$this->config->set('abbc3_auto_video', $this->request->variable('abbc3_auto_video', 0)); |
125
|
|
|
$this->config->set('abbc3_icons_type', $this->request->variable('abbc3_icons_type', 'png')); |
126
|
|
|
$this->save_pipes(); |
127
|
|
|
$this->save_google_fonts(); |
128
|
|
|
|
129
|
|
|
$this->cache->destroy($this->container->getParameter('text_formatter.cache.parser.key')); |
130
|
|
|
$this->cache->destroy($this->container->getParameter('text_formatter.cache.renderer.key')); |
131
|
|
|
|
132
|
|
|
if ($this->errors) |
|
|
|
|
133
|
|
|
{ |
134
|
|
|
trigger_error(implode('<br>', $this->errors) . adm_back_link($this->u_action), E_USER_WARNING); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
trigger_error($this->language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Save the Pipes Table setting. |
142
|
|
|
* - Set the config |
143
|
|
|
* - Show or hide the Pipes BBCode button |
144
|
|
|
* - Purge BBCode caches. |
145
|
|
|
*/ |
146
|
|
|
protected function save_pipes() |
147
|
|
|
{ |
148
|
|
|
$enable_pipes = $this->request->variable('abbc3_pipes', 0); |
149
|
|
|
|
150
|
|
|
$this->config->set('abbc3_pipes', $enable_pipes); |
151
|
|
|
|
152
|
|
|
$sql = 'UPDATE ' . BBCODES_TABLE . ' |
|
|
|
|
153
|
|
|
SET display_on_posting = ' . (int) $enable_pipes . " |
154
|
|
|
WHERE bbcode_tag = 'pipes'"; |
155
|
|
|
$this->db->sql_query($sql); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get the Google font setting data and format it for the form. |
160
|
|
|
* |
161
|
|
|
* @return string |
162
|
|
|
*/ |
163
|
|
|
protected function show_google_fonts() |
164
|
|
|
{ |
165
|
|
|
$fonts = json_decode($this->config_text->get('abbc3_google_fonts'), true); |
166
|
|
|
return $fonts ? implode("\n", $fonts) : ''; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Save the Google fonts setting. |
171
|
|
|
* - If field has data, explode it to an array and save as JSON data. |
172
|
|
|
* - If field is empty, store just an empty string. |
173
|
|
|
*/ |
174
|
|
|
protected function save_google_fonts() |
175
|
|
|
{ |
176
|
|
|
$fonts = $this->request->variable('abbc3_google_fonts', ''); |
177
|
|
|
$fonts = explode("\n", $fonts); |
178
|
|
|
$this->validate_google_fonts($fonts); |
179
|
|
|
$this->config_text->set('abbc3_google_fonts', json_encode($fonts)); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Validate Google Font exists. |
184
|
|
|
* |
185
|
|
|
* @param array $fonts |
186
|
|
|
* @return void |
187
|
|
|
*/ |
188
|
|
|
protected function validate_google_fonts(&$fonts) |
189
|
|
|
{ |
190
|
|
|
foreach ($fonts as $key => $font) |
191
|
|
|
{ |
192
|
|
|
if (empty($font) || $this->valid_url('https://fonts.googleapis.com/css?family=' . urlencode($font))) |
193
|
|
|
{ |
194
|
|
|
continue; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$this->errors[] = $this->language->lang('ABBC3_INVALID_FONT', $font); |
198
|
|
|
unset($fonts[$key]); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Check for valid URL headers |
204
|
|
|
* |
205
|
|
|
* @param string $url |
206
|
|
|
* @return bool Return true if URL is valid, false if not. Return true if unable to check URL. |
207
|
|
|
*/ |
208
|
|
|
private function valid_url($url) |
209
|
|
|
{ |
210
|
|
|
$file_headers = @get_headers($url); |
211
|
|
|
return !$file_headers || $file_headers[0] === 'HTTP/1.1 200 OK'; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths