|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Advertisement management. An extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2018 phpBB Limited <https://www.phpbb.com> |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace phpbb\ads\controller; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Visual demo controller |
|
15
|
|
|
*/ |
|
16
|
|
|
class visual_demo_controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var \phpbb\auth\auth */ |
|
19
|
|
|
protected $auth; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \phpbb\config\config */ |
|
22
|
|
|
protected $config; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \phpbb\request\request */ |
|
25
|
|
|
protected $request; |
|
26
|
|
|
|
|
27
|
|
|
/** @var \phpbb\user */ |
|
28
|
|
|
protected $user; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
protected $root_path; |
|
32
|
|
|
|
|
33
|
|
|
/** @var string */ |
|
34
|
|
|
protected $php_ext; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructor |
|
38
|
|
|
* |
|
39
|
|
|
* @param \phpbb\auth\auth $auth |
|
40
|
|
|
* @param \phpbb\config\config $config |
|
41
|
|
|
* @param \phpbb\request\request $request |
|
42
|
|
|
* @param \phpbb\user $user |
|
43
|
|
|
* @param string $root_path |
|
44
|
|
|
* @param string $php_ext |
|
45
|
|
|
*/ |
|
46
|
6 |
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\request\request $request, \phpbb\user $user, $root_path, $php_ext) |
|
47
|
|
|
{ |
|
48
|
6 |
|
$this->auth = $auth; |
|
49
|
6 |
|
$this->config = $config; |
|
50
|
6 |
|
$this->request = $request; |
|
51
|
6 |
|
$this->user = $user; |
|
52
|
6 |
|
$this->root_path = $root_path; |
|
53
|
6 |
|
$this->php_ext = $php_ext; |
|
54
|
6 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Visual demo handler |
|
58
|
|
|
* |
|
59
|
|
|
* When called by an admin, add or remove the visual demo cookie |
|
60
|
|
|
* and direct them to an appropriate forum page to view. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $action enable|disable |
|
63
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse |
|
64
|
|
|
* @throws \phpbb\exception\http_exception An http exception |
|
65
|
|
|
*/ |
|
66
|
6 |
|
public function handle($action) |
|
67
|
|
|
{ |
|
68
|
|
|
// Protect against unauthorised access |
|
69
|
6 |
|
if (!$this->auth->acl_get('a_')) |
|
70
|
|
|
{ |
|
71
|
2 |
|
throw new \phpbb\exception\http_exception(403, 'NO_AUTH_OPERATION'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
4 |
|
if ($action === 'disable') |
|
75
|
|
|
{ |
|
76
|
|
|
// Destroy our cookie and redirect user to previous page viewed. |
|
77
|
2 |
|
$this->user->set_cookie('phpbb_ads_visual_demo', '', 1); |
|
78
|
2 |
|
$redirect = $this->request->variable('redirect', $this->user->data['session_page']); |
|
79
|
|
|
} |
|
80
|
|
|
else |
|
81
|
|
|
{ |
|
82
|
|
|
// Create our cookie and send user to the index page. |
|
83
|
2 |
|
$this->user->set_cookie('phpbb_ads_visual_demo', time(), 0); |
|
84
|
2 |
|
$redirect = "{$this->root_path}index.{$this->php_ext}"; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Send a JSON response if an AJAX request was used |
|
88
|
4 |
|
if ($this->request->is_ajax()) |
|
89
|
|
|
{ |
|
90
|
2 |
|
return new \Symfony\Component\HttpFoundation\JsonResponse(array( |
|
91
|
2 |
|
'success' => true, |
|
92
|
|
|
)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
// Redirect user to a page |
|
96
|
2 |
|
$redirect = reapply_sid($redirect); |
|
97
|
2 |
|
redirect($redirect); |
|
98
|
|
|
|
|
99
|
|
|
// We shouldn't get here, but throw an http exception just in case |
|
100
|
|
|
throw new \phpbb\exception\http_exception(500, 'GENERAL_ERROR'); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|