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
|
|
|
namespace ernadoo\phpbbdirectory\controller; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
use \ernadoo\phpbbdirectory\core\helper; |
16
|
|
|
|
17
|
|
|
class links extends helper |
18
|
|
|
{ |
19
|
|
|
private $link_user_id; |
20
|
|
|
private $site_name; |
21
|
|
|
private $url; |
22
|
|
|
private $description; |
23
|
|
|
private $guest_email; |
24
|
|
|
private $rss; |
25
|
|
|
private $banner; |
26
|
|
|
private $back; |
27
|
|
|
private $flag; |
28
|
|
|
|
29
|
|
|
private $captcha; |
30
|
|
|
private $s_hidden_fields = array(); |
31
|
|
|
|
32
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
33
|
|
|
protected $db; |
34
|
|
|
|
35
|
|
|
/** @var \phpbb\config\config */ |
36
|
|
|
protected $config; |
37
|
|
|
|
38
|
|
|
/** @var \phpbb\language\language */ |
39
|
|
|
protected $language; |
40
|
|
|
|
41
|
|
|
/** @var \phpbb\template\template */ |
42
|
|
|
protected $template; |
43
|
|
|
|
44
|
|
|
/** @var \phpbb\user */ |
45
|
|
|
protected $user; |
46
|
|
|
|
47
|
|
|
/** @var \phpbb\controller\helper */ |
48
|
|
|
protected $helper; |
49
|
|
|
|
50
|
|
|
/** @var \phpbb\request\request */ |
51
|
|
|
protected $request; |
52
|
|
|
|
53
|
|
|
/** @var \phpbb\auth\auth */ |
54
|
|
|
protected $auth; |
55
|
|
|
|
56
|
|
|
/** @var \phpbb\captcha\factory */ |
57
|
|
|
protected $captcha_factory; |
58
|
|
|
|
59
|
|
|
/** @var \ernadoo\phpbbdirectory\core\categorie */ |
60
|
|
|
protected $categorie; |
61
|
|
|
|
62
|
|
|
/** @var \ernadoo\phpbbdirectory\core\link */ |
63
|
|
|
protected $link; |
64
|
|
|
|
65
|
|
|
/** @var string phpBB root path */ |
66
|
|
|
protected $root_path; |
67
|
|
|
|
68
|
|
|
/** @var string phpEx */ |
69
|
|
|
protected $php_ext; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Constructor |
73
|
|
|
* |
74
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database object |
75
|
|
|
* @param \phpbb\config\config $config Config object |
76
|
|
|
* @param \phpbb\language\language $language Language object |
77
|
|
|
* @param \phpbb\template\template $template Template object |
78
|
|
|
* @param \phpbb\user $user User object |
79
|
|
|
* @param \phpbb\controller\helper $helper Controller helper object |
80
|
|
|
* @param \phpbb\request\request $request Request object |
81
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
82
|
|
|
* @param \phpbb\captcha\factory $captcha_factory Captcha object |
83
|
|
|
* @param \ernadoo\phpbbdirectory\core\categorie $categorie PhpBB Directory extension categorie object |
84
|
|
|
* @param \ernadoo\phpbbdirectory\core\link $link PhpBB Directory extension link object |
85
|
|
|
* @param string $root_path phpBB root path |
86
|
|
|
* @param string $php_ext phpEx |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\captcha\factory $captcha_factory, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link, $root_path, $php_ext) |
89
|
|
|
{ |
90
|
|
|
$this->db = $db; |
91
|
|
|
$this->config = $config; |
92
|
|
|
$this->language = $language; |
93
|
|
|
$this->template = $template; |
94
|
|
|
$this->user = $user; |
95
|
|
|
$this->helper = $helper; |
96
|
|
|
$this->request = $request; |
97
|
|
|
$this->auth = $auth; |
98
|
|
|
$this->captcha_factory = $captcha_factory; |
99
|
|
|
$this->categorie = $categorie; |
100
|
|
|
$this->link = $link; |
101
|
|
|
$this->root_path = $root_path; |
102
|
|
|
$this->php_ext = $php_ext; |
103
|
|
|
|
104
|
|
|
$language->add_lang('directory', 'ernadoo/phpbbdirectory'); |
105
|
|
|
|
106
|
|
|
$template->assign_vars(array( |
107
|
|
|
'S_PHPBB_DIRECTORY' => true, |
108
|
|
|
)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Delete a link |
113
|
|
|
* |
114
|
|
|
* @param int $cat_id The category ID |
115
|
|
|
* @param int $link_id The link ID |
116
|
|
|
* @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object |
117
|
|
|
*/ |
118
|
|
|
public function delete_link($cat_id, $link_id) |
119
|
|
|
{ |
120
|
|
|
if ($this->request->is_set_post('cancel')) |
121
|
|
|
{ |
122
|
|
|
$redirect = $this->helper->route('ernadoo_phpbbdirectory_dynamic_route_' . $cat_id); |
123
|
|
|
redirect($redirect); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$sql = 'SELECT link_user_id |
127
|
|
|
FROM ' . $this->links_table . ' |
128
|
|
|
WHERE link_id = ' . (int) $link_id; |
129
|
|
|
$result = $this->db->sql_query($sql); |
130
|
|
|
$link_data = $this->db->sql_fetchrow($result); |
131
|
|
|
|
132
|
|
|
if (empty($link_data)) |
133
|
|
|
{ |
134
|
|
|
throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || ($this->user->data['user_id'] == $link_data['link_user_id'] && $this->auth->acl_get('u_delete_dir'))); |
138
|
|
|
|
139
|
|
|
if (!$delete_allowed) |
140
|
|
|
{ |
141
|
|
|
throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if (confirm_box(true)) |
145
|
|
|
{ |
146
|
|
|
$this->link->del($cat_id, $link_id); |
147
|
|
|
|
148
|
|
|
$meta_info = $this->helper->route('ernadoo_phpbbdirectory_dynamic_route_' . $cat_id); |
149
|
|
|
meta_refresh(3, $meta_info); |
150
|
|
|
$message = $this->language->lang('DIR_DELETE_OK') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_DIR', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_base_controller') . '">', '</a>') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_dynamic_route_' . $cat_id) . '">', '</a>'); |
151
|
|
|
return $this->helper->message($message); |
152
|
|
|
} |
153
|
|
|
else |
154
|
|
|
{ |
155
|
|
|
confirm_box(false, 'DIR_DELETE_SITE'); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Edit a link |
161
|
|
|
* |
162
|
|
|
* @param int $cat_id The category ID |
163
|
|
|
* @param int $link_id The link ID |
164
|
|
|
* @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object |
165
|
|
|
* @throws \phpbb\exception\http_exception |
166
|
|
|
*/ |
167
|
|
|
public function edit_link($cat_id, $link_id) |
168
|
|
|
{ |
169
|
|
|
$sql = 'SELECT link_id, link_uid, link_user_id, link_flags, link_bitfield, link_cat, link_url, link_description, link_guest_email, link_name, link_rss, link_back, link_banner, link_flag, link_cat, link_time |
170
|
|
|
FROM ' . $this->links_table . ' |
171
|
|
|
WHERE link_id = ' . (int) $link_id; |
172
|
|
|
$result = $this->db->sql_query($sql); |
173
|
|
|
$link_data = $this->db->sql_fetchrow($result); |
174
|
|
|
$this->link_user_id = (int) $link_data['link_user_id']; |
175
|
|
|
|
176
|
|
|
if (empty($link_data['link_id'])) |
177
|
|
|
{ |
178
|
|
|
throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS'); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
$edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || ($this->user->data['user_id'] == (int) $link_data['link_user_id'] && $this->auth->acl_get('u_edit_dir')))); |
182
|
|
|
|
183
|
|
|
if (!$edit_allowed) |
184
|
|
|
{ |
185
|
|
|
throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH'); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$cat_id = $this->request->variable('id', $cat_id); |
189
|
|
|
$submit = $this->request->is_set_post('submit') ? true : false; |
190
|
|
|
$refresh = $this->request->is_set_post('refresh_vc') ? true : false; |
191
|
|
|
$title = $this->language->lang('DIR_EDIT_SITE'); |
192
|
|
|
|
193
|
|
|
$this->template->assign_block_vars('dir_navlinks', array( |
194
|
|
|
'BREADCRUMB_NAME' => $title, |
195
|
|
|
'U_BREADCRUMB' => $this->helper->route('ernadoo_phpbbdirectory_edit_controller', array('cat_id' => (int) $cat_id, 'link_id' => $link_id)) |
196
|
|
|
)); |
197
|
|
|
|
198
|
|
|
$this->categorie->get($cat_id); |
199
|
|
|
|
200
|
|
|
// If form is done |
201
|
|
|
if ($submit || $refresh) |
202
|
|
|
{ |
203
|
|
|
if (false != ($result = $this->_data_processing($cat_id, $link_id, 'edit'))) |
204
|
|
|
{ |
205
|
|
|
return $result; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
else |
209
|
|
|
{ |
210
|
|
|
$this->s_hidden_fields = array( |
211
|
|
|
'old_cat_id' => $link_data['link_cat'], |
212
|
|
|
'old_banner' => $link_data['link_banner'], |
213
|
|
|
); |
214
|
|
|
|
215
|
|
|
$site_description = generate_text_for_edit($link_data['link_description'], $link_data['link_uid'], $link_data['link_flags']); |
216
|
|
|
$link_data['link_banner'] = (preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $link_data['link_banner'])) ? $link_data['link_banner'] : ''; |
217
|
|
|
|
218
|
|
|
$this->url = $link_data['link_url']; |
219
|
|
|
$this->site_name = $link_data['link_name']; |
220
|
|
|
$this->description = $site_description['text']; |
221
|
|
|
$this->guest_email = $link_data['link_guest_email']; |
222
|
|
|
$this->rss = $link_data['link_rss']; |
223
|
|
|
$this->banner = $link_data['link_banner']; |
224
|
|
|
$this->back = $link_data['link_back']; |
225
|
|
|
$this->flag = $link_data['link_flag']; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$this->_populate_form($cat_id, 'edit', $title); |
229
|
|
|
|
230
|
|
|
return $this->helper->render('add_site.html', $title); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Display add form |
235
|
|
|
* |
236
|
|
|
* @param int $cat_id The category ID |
237
|
|
|
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object |
238
|
|
|
* @throws \phpbb\exception\http_exception |
239
|
|
|
*/ |
240
|
|
|
public function new_link($cat_id) |
241
|
|
|
{ |
242
|
|
|
if (!$this->auth->acl_get('u_submit_dir')) |
243
|
|
|
{ |
244
|
|
|
throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH'); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
$cat_id = $this->request->variable('id', $cat_id); |
248
|
|
|
$submit = $this->request->is_set_post('submit') ? true : false; |
249
|
|
|
$refresh = $this->request->is_set_post('refresh_vc') ? true : false; |
250
|
|
|
$title = $this->language->lang('DIR_NEW_SITE'); |
251
|
|
|
|
252
|
|
|
$this->template->assign_block_vars('dir_navlinks', array( |
253
|
|
|
'BREADCRUMB_NAME' => $title, |
254
|
|
|
'U_BREADCRUMB' => $this->helper->route('ernadoo_phpbbdirectory_new_controller', array('cat_id' => (int) $cat_id)) |
255
|
|
|
)); |
256
|
|
|
|
257
|
|
|
$this->categorie->get($cat_id); |
258
|
|
|
|
259
|
|
|
// The CAPTCHA kicks in here. We can't help that the information gets lost on language change. |
260
|
|
View Code Duplication |
if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) |
261
|
|
|
{ |
262
|
|
|
$this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']); |
263
|
|
|
$this->captcha->init(CONFIRM_POST); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
// If form is done |
267
|
|
|
if ($submit || $refresh) |
268
|
|
|
{ |
269
|
|
|
if (false != ($result = $this->_data_processing($cat_id))) |
270
|
|
|
{ |
271
|
|
|
return $result; |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
$this->_populate_form($cat_id, 'new', $title); |
276
|
|
|
|
277
|
|
|
return $this->helper->render('add_site.html', $title); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* View link controller |
282
|
|
|
* |
283
|
|
|
* @param int $link_id The link ID |
284
|
|
|
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object |
285
|
|
|
*/ |
286
|
|
|
public function view_link($link_id) |
287
|
|
|
{ |
288
|
|
|
return $this->link->view($link_id); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Vote for a link |
293
|
|
|
* |
294
|
|
|
* @param int $cat_id The category ID |
295
|
|
|
* @param int $link_id The link ID |
296
|
|
|
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object |
297
|
|
|
*/ |
298
|
|
|
public function vote_link($cat_id, $link_id) |
299
|
|
|
{ |
300
|
|
|
$this->categorie->get($cat_id); |
301
|
|
|
|
302
|
|
|
if (!$this->auth->acl_get('u_vote_dir') || !$this->categorie->data['cat_allow_votes']) |
303
|
|
|
{ |
304
|
|
|
throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH'); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
$data = array( |
308
|
|
|
'vote_link_id' => (int) $link_id, |
309
|
|
|
'vote_user_id' => (int) $this->user->data['user_id'], |
310
|
|
|
); |
311
|
|
|
|
312
|
|
|
// We check if user had already vot for this website. |
313
|
|
|
$sql = 'SELECT vote_link_id |
314
|
|
|
FROM ' . $this->votes_table . ' |
315
|
|
|
WHERE ' . $this->db->sql_build_array('SELECT', $data); |
316
|
|
|
$result = $this->db->sql_query($sql); |
317
|
|
|
$data = $this->db->sql_fetchrow($result); |
318
|
|
|
|
319
|
|
|
if (!empty($data['vote_link_id'])) |
320
|
|
|
{ |
321
|
|
|
throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_VOTE'); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
$this->link->add_vote($link_id, $this->request->variable('vote', 0)); |
325
|
|
|
|
326
|
|
|
$meta_info = $this->helper->route('ernadoo_phpbbdirectory_dynamic_route_' . $cat_id); |
327
|
|
|
meta_refresh(3, $meta_info); |
328
|
|
|
$message = $this->language->lang('DIR_VOTE_OK') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $meta_info . '">', '</a>'); |
329
|
|
|
return $this->helper->message($message); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Routine |
334
|
|
|
* |
335
|
|
|
* @param int $cat_id The category ID |
336
|
|
|
* @param int $link_id The link ID |
337
|
|
|
* @param string $mode add|edit |
338
|
|
|
* @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object |
339
|
|
|
* @throws \phpbb\exception\http_exception |
340
|
|
|
*/ |
341
|
|
|
private function _data_processing($cat_id, $link_id = 0, $mode = 'new') |
342
|
|
|
{ |
343
|
|
|
if (($mode == 'edit' && !$this->auth->acl_get('m_edit_dir') && !$this->auth->acl_get('u_edit_dir')) || ($mode == 'new' && !$this->auth->acl_get('u_submit_dir'))) |
344
|
|
|
{ |
345
|
|
|
throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH'); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
if (!check_form_key('dir_form')) |
349
|
|
|
{ |
350
|
|
|
return $this->helper->message('FORM_INVALID'); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
$this->url = $this->request->variable('url', ''); |
354
|
|
|
$this->site_name = $this->request->variable('site_name', '', true); |
355
|
|
|
$this->description = $this->request->variable('description', '', true); |
356
|
|
|
$this->guest_email = $this->request->variable('guest_email', ''); |
357
|
|
|
$this->rss = $this->request->variable('rss', ''); |
358
|
|
|
$this->banner = $this->request->variable('banner', ''); |
359
|
|
|
$this->back = $this->request->variable('back', ''); |
360
|
|
|
$this->flag = $this->request->variable('flag', ''); |
361
|
|
|
|
362
|
|
|
if (!function_exists('validate_data')) |
363
|
|
|
{ |
364
|
|
|
include($this->root_path . 'includes/functions_user.' . $this->php_ext); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
// We define variables to check |
368
|
|
|
$data = array( |
369
|
|
|
'email' => $this->guest_email, |
370
|
|
|
'site_name' => $this->site_name, |
371
|
|
|
'website' => $this->url, |
372
|
|
|
'description' => $this->description, |
373
|
|
|
'rss' => $this->rss, |
374
|
|
|
'banner' => $this->banner, |
375
|
|
|
'back' => $this->back, |
376
|
|
|
'cat' => (int) $cat_id, |
377
|
|
|
); |
378
|
|
|
|
379
|
|
|
// We define verification type for each variable |
380
|
|
|
$data2 = array( |
381
|
|
|
'email' => array( |
382
|
|
|
array('string', $this->user->data['is_registered'], 6, 60), |
383
|
|
|
array('user_email', '')), |
384
|
|
|
'site_name' => array( |
385
|
|
|
array('string', false, 1, 100)), |
386
|
|
|
'website' => array( |
387
|
|
|
array('string', false, 12, 255), |
388
|
|
|
array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')), |
389
|
|
|
'description' => array( |
390
|
|
|
array('string', !$this->categorie->data['cat_must_describe'], 1, $this->config['dir_length_describe'])), |
391
|
|
|
'rss' => array( |
392
|
|
|
array('string', true, 12, 255), |
393
|
|
|
array('match', empty($this->rss), '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')), |
394
|
|
|
'banner' => array( |
395
|
|
|
array('string', true, 5, 255)), |
396
|
|
|
'back' => array( |
397
|
|
|
array('string', !$this->categorie->data['cat_link_back'], 12, 255), |
398
|
|
|
array(array($this->link, 'link_back'), true)), |
399
|
|
|
'cat' => array( |
400
|
|
|
array('num', '', 1)) |
401
|
|
|
); |
402
|
|
|
|
403
|
|
|
$this->language->add_lang('ucp'); |
404
|
|
|
$error = validate_data($data, $data2); |
405
|
|
|
$error = array_map(array($this->language, 'lang'), $error); |
406
|
|
|
|
407
|
|
|
// We check that url have good format |
408
|
|
|
if (preg_match('/^(http|https):\/\//si', $this->url) && $this->config['dir_activ_checkurl'] && !$this->link->checkurl($this->url)) |
409
|
|
|
{ |
410
|
|
|
$error[] = $this->language->lang('DIR_ERROR_CHECK_URL'); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
View Code Duplication |
if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) |
414
|
|
|
{ |
415
|
|
|
$vc_response = $this->captcha->validate($data); |
416
|
|
|
if ($vc_response !== false) |
417
|
|
|
{ |
418
|
|
|
$error[] = $vc_response; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) |
422
|
|
|
{ |
423
|
|
|
$error[] = $this->language->lang('TOO_MANY_ADDS'); |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
if (!$error) |
428
|
|
|
{ |
429
|
|
|
/** |
430
|
|
|
* No errrors, we execute heavy tasks wich need a valid url |
431
|
|
|
*/ |
432
|
|
|
|
433
|
|
|
// Banner |
434
|
|
|
$this->link->banner_process($this->banner, $error); |
435
|
|
|
|
436
|
|
|
// Thumb ;) |
437
|
|
|
$thumb = $this->link->thumb_process($this->url); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
// Still no errors?? So let's go! |
441
|
|
|
if (!$error) |
442
|
|
|
{ |
443
|
|
|
$this->banner = (!$this->banner && !$this->request->is_set_post('delete_banner')) ? $this->request->variable('old_banner', '') : $this->banner; |
444
|
|
|
$this->url = $this->link->clean_url($this->url); |
445
|
|
|
|
446
|
|
|
$data_edit = array( |
447
|
|
|
'link_user_id' => $this->link_user_id, |
448
|
|
|
'link_guest_email' => $this->guest_email, |
449
|
|
|
'link_name' => $this->site_name, |
450
|
|
|
'link_url' => $this->url, |
451
|
|
|
'link_description' => $this->description, |
452
|
|
|
'link_cat' => (int) $cat_id, |
453
|
|
|
'link_rss' => $this->rss, |
454
|
|
|
'link_banner' => $this->banner, |
455
|
|
|
'link_back' => $this->back, |
456
|
|
|
'link_uid' => '', |
457
|
|
|
'link_flags' => 7, |
458
|
|
|
'link_flag' => $this->flag, |
459
|
|
|
'link_bitfield' => '', |
460
|
|
|
'link_thumb' => $thumb, |
461
|
|
|
); |
462
|
|
|
|
463
|
|
|
if ($this->description) |
464
|
|
|
{ |
465
|
|
|
generate_text_for_storage($data_edit['link_description'], $data_edit['link_uid'], $data_edit['link_bitfield'], $data_edit['link_flags'], (bool) $this->config['allow_bbcode'], (bool) $this->config['allow_post_links'], (bool) $this->config['allow_smilies'], (bool) $this->config['allow_bbcode'], ($this->config['allow_bbcode'] && $this->config['allow_post_flash']), true, (bool) $this->config['allow_post_links']); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
$need_approval = ($this->categorie->need_approval() && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_')) ? true : false; |
469
|
|
|
|
470
|
|
|
if ($mode == 'edit') |
471
|
|
|
{ |
472
|
|
|
$data_edit['link_cat_old'] = $this->request->variable('old_cat_id', 0); |
473
|
|
|
$this->link->edit($data_edit, $link_id, $need_approval); |
474
|
|
|
} |
475
|
|
|
else |
476
|
|
|
{ |
477
|
|
|
$data_add = array( |
478
|
|
|
'link_time' => time(), |
479
|
|
|
'link_view' => 0, |
480
|
|
|
'link_active' => $need_approval ? false : true, |
481
|
|
|
'link_user_id' => $this->user->data['user_id'], |
482
|
|
|
); |
483
|
|
|
|
484
|
|
|
$data_add = array_merge($data_edit, $data_add); |
485
|
|
|
|
486
|
|
|
$this->link->add($data_add, $need_approval); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
$meta_info = $this->helper->route('ernadoo_phpbbdirectory_dynamic_route_' . $cat_id); |
490
|
|
|
meta_refresh(3, $meta_info); |
491
|
|
|
$message = ($need_approval) ? $this->language->lang('DIR_'.strtoupper($mode).'_SITE_ACTIVE') : $this->language->lang('DIR_'.strtoupper($mode).'_SITE_OK'); |
492
|
|
|
$message = $message . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_DIR', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_base_controller') . '">', '</a>') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_dynamic_route_' . $cat_id) . '">', '</a>'); |
493
|
|
|
return $this->helper->message($message); |
494
|
|
|
} |
495
|
|
|
else |
496
|
|
|
{ |
497
|
|
|
if ($mode == 'edit') |
498
|
|
|
{ |
499
|
|
|
$this->s_hidden_fields = array( |
500
|
|
|
'old_cat_id' => $this->request->variable('old_cat_id', 0), |
501
|
|
|
'old_banner' => $this->request->variable('old_banner', '') |
502
|
|
|
); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
$this->template->assign_vars(array( |
506
|
|
|
'ERROR' => (isset($error)) ? implode('<br />', $error) : '' |
507
|
|
|
)); |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Display a banner |
513
|
|
|
* |
514
|
|
|
* @param string $banner_img Path to banner file |
515
|
|
|
* @return Response object |
516
|
|
|
*/ |
517
|
|
|
public function return_banner($banner_img) |
518
|
|
|
{ |
519
|
|
|
if (!function_exists('file_gc')) |
520
|
|
|
{ |
521
|
|
|
include($this->root_path . 'includes/functions_download.' . $this->php_ext); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
$file_path = $this->root_path . $this->get_banner_path($banner_img); |
525
|
|
|
|
526
|
|
|
if ((@file_exists($file_path) && @is_readable($file_path))) |
527
|
|
|
{ |
528
|
|
|
$response = new BinaryFileResponse($file_path); |
529
|
|
|
$response->setContentDisposition('inline', $banner_img); |
530
|
|
|
|
531
|
|
|
// Without fileinfo extension, Symfony is unable to guess the mime type |
532
|
|
|
if (!extension_loaded('fileinfo')) |
533
|
|
|
{ |
534
|
|
|
$imagesize = new \FastImageSize\FastImageSize(); |
535
|
|
|
$image_data = $imagesize->getImageSize($file_path); |
536
|
|
|
$response->headers->set('Content-Type', image_type_to_mime_type($image_data['type'])); |
537
|
|
|
} |
538
|
|
|
} |
539
|
|
|
else |
540
|
|
|
{ |
541
|
|
|
$response = new Response(); |
542
|
|
|
$response->setStatusCode(404); |
543
|
|
|
} |
544
|
|
|
file_gc(false); |
545
|
|
|
|
546
|
|
|
return $response; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* Populate form when an error occurred |
551
|
|
|
* |
552
|
|
|
* @param int $cat_id The category ID |
553
|
|
|
* @param string $mode add|edit |
554
|
|
|
* @param string $title Page title (depends of $mode) |
555
|
|
|
* @return null |
556
|
|
|
*/ |
557
|
|
|
private function _populate_form($cat_id, $mode, $title) |
558
|
|
|
{ |
559
|
|
|
global $phpbb_extension_manager; |
560
|
|
|
|
561
|
|
View Code Duplication |
if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode == 'new') |
562
|
|
|
{ |
563
|
|
|
$this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields()); |
564
|
|
|
|
565
|
|
|
$this->language->add_lang('ucp'); |
566
|
|
|
|
567
|
|
|
$this->template->assign_vars(array( |
568
|
|
|
'CAPTCHA_TEMPLATE' => $this->captcha->get_template(), |
569
|
|
|
)); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
$this->language->add_lang('posting'); |
573
|
|
|
|
574
|
|
|
if (!function_exists('display_custom_bbcodes')) |
575
|
|
|
{ |
576
|
|
|
include($this->root_path . 'includes/functions_display.' . $this->php_ext); |
577
|
|
|
} |
578
|
|
|
display_custom_bbcodes(); |
579
|
|
|
add_form_key('dir_form'); |
580
|
|
|
|
581
|
|
|
$ext_path = $phpbb_extension_manager->get_extension_path('ernadoo/phpbbdirectory', false); |
582
|
|
|
$flag_path = $ext_path.'images/flags/'; |
583
|
|
|
|
584
|
|
|
$s_guest = (!$this->user->data['is_registered'] || !empty($this->guest_email)); |
585
|
|
|
$s_rss = $this->config['dir_activ_rss']; |
586
|
|
|
$s_banner = $this->config['dir_activ_banner']; |
587
|
|
|
$s_back = $this->categorie->data['cat_link_back']; |
588
|
|
|
$s_flag = $this->config['dir_activ_flag']; |
589
|
|
|
|
590
|
|
|
$this->template->assign_vars(array( |
591
|
|
|
'BBCODE_STATUS' => ($this->config['allow_bbcode']) ? $this->language->lang('BBCODE_IS_ON', '<a href="' . append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode') . '">', '</a>') : $this->language->lang('BBCODE_IS_OFF', '<a href="' . append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode') . '">', '</a>'), |
592
|
|
|
'IMG_STATUS' => ($this->config['allow_bbcode']) ? $this->language->lang('IMAGES_ARE_ON') : $this->language->lang('IMAGES_ARE_OFF'), |
593
|
|
|
'SMILIES_STATUS' => ($this->config['allow_smilies']) ? $this->language->lang('SMILIES_ARE_ON') : $this->language->lang('SMILIES_ARE_OFF'), |
594
|
|
|
'URL_STATUS' => ($this->config['allow_post_links']) ? $this->language->lang('URL_IS_ON') : $this->language->lang('URL_IS_OFF'), |
595
|
|
|
'FLASH_STATUS' => ($this->config['allow_bbcode'] && $this->config['allow_post_flash']) ? $this->language->lang('FLASH_IS_ON') : $this->language->lang('FLASH_IS_OFF'), |
596
|
|
|
|
597
|
|
|
'L_TITLE' => $title, |
598
|
|
|
'L_DIR_DESCRIPTION_EXP' => $this->language->lang('DIR_DESCRIPTION_EXP', $this->config['dir_length_describe']), |
599
|
|
|
'L_DIR_SUBMIT_TYPE' => $this->categorie->dir_submit_type($this->categorie->need_approval()), |
600
|
|
|
'L_DIR_SITE_BANN_EXP' => $this->language->lang('DIR_SITE_BANN_EXP', $this->config['dir_banner_width'], $this->config['dir_banner_height']), |
601
|
|
|
|
602
|
|
|
'S_GUEST' => $s_guest ? true : false, |
603
|
|
|
'S_RSS' => $s_rss ? true : false, |
604
|
|
|
'S_BANNER' => $s_banner ? true : false, |
605
|
|
|
'S_BACK' => $s_back ? true : false, |
606
|
|
|
'S_FLAG' => $s_flag ? true : false, |
607
|
|
|
'S_BBCODE_ALLOWED' => (bool) $this->config['allow_bbcode'], |
608
|
|
|
'S_BBCODE_IMG' => (bool) $this->config['allow_bbcode'], |
609
|
|
|
'S_BBCODE_FLASH' => ($this->config['allow_bbcode'] && $this->config['allow_post_flash']) ? true : false, |
610
|
|
|
'S_BBCODE_QUOTE' => true, |
611
|
|
|
'S_LINKS_ALLOWED' => (bool) $this->config['allow_post_links'], |
612
|
|
|
|
613
|
|
|
'DIR_FLAG_PATH' => $flag_path, |
614
|
|
|
'DIR_FLAG_IMAGE' => $this->flag ? $this->get_img_path('flags', $this->flag) : '', |
615
|
|
|
|
616
|
|
|
'EDIT_MODE' => ($mode == 'edit') ? true : false, |
617
|
|
|
|
618
|
|
|
'SITE_NAME' => isset($this->site_name) ? $this->site_name : '', |
619
|
|
|
'SITE_URL' => isset($this->url) ? $this->url : '', |
620
|
|
|
'DESCRIPTION' => isset($this->description) ? $this->description : '', |
621
|
|
|
'GUEST_EMAIL' => isset($this->guest_email) ? $this->guest_email : '', |
622
|
|
|
'RSS' => isset($this->rss) ? $this->rss : '', |
623
|
|
|
'BANNER' => isset($this->banner) ? $this->banner : '', |
624
|
|
|
'BACK' => isset($this->back) ? $this->back : '', |
625
|
|
|
'S_POST_ACTION' => '', |
626
|
|
|
'S_CATLIST' => $this->categorie->make_cat_select($cat_id), |
627
|
|
|
'S_LIST_FLAG' => $this->link->get_dir_flag_list($flag_path, $this->flag), |
628
|
|
|
'S_DESC_STAR' => (@$this->categorie->data['cat_must_describe']) ? '*' : '', |
629
|
|
|
'S_ROOT' => $cat_id, |
630
|
|
|
'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields), |
631
|
|
|
)); |
632
|
|
|
} |
633
|
|
|
} |
634
|
|
|
|