-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
BackendConfirm.php
163 lines (139 loc) · 4.04 KB
/
BackendConfirm.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
<?php
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
namespace Contao;
use Contao\CoreBundle\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
/**
* Confirm an invalid token URL.
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class BackendConfirm extends Backend
{
/**
* Initialize the controller
*
* 1. Import the user
* 2. Call the parent constructor
* 3. Authenticate the user
* 4. Load the language files
* DO NOT CHANGE THIS ORDER!
*/
public function __construct()
{
$this->import(BackendUser::class, 'User');
parent::__construct();
if (!System::getContainer()->get('security.authorization_checker')->isGranted('ROLE_USER'))
{
throw new AccessDeniedException('Access denied');
}
System::loadLanguageFile('default');
System::loadLanguageFile('modules');
}
/**
* Run the controller
*
* @return Response
*/
public function run()
{
/** @var Session $objSession */
$objSession = System::getContainer()->get('session');
// Redirect to the back end home page
if (Input::post('FORM_SUBMIT') == 'invalid_token_url')
{
list($strUrl) = explode('?', $objSession->get('INVALID_TOKEN_URL'));
$this->redirect($strUrl);
}
$objTemplate = new BackendTemplate('be_confirm');
// Prepare the URL
$url = preg_replace('/(\?|&)rt=[^&]*/', '', $objSession->get('INVALID_TOKEN_URL'));
$objTemplate->href = ampersand($url . ((strpos($url, '?') !== false) ? '&rt=' : '?rt=') . REQUEST_TOKEN);
$vars = array();
list(, $request) = explode('?', $url, 2);
// Extract the arguments
foreach (explode('&', $request) as $arg)
{
list($key, $value) = explode('=', $arg, 2);
$vars[$key] = $value;
}
$arrInfo = array();
// Provide more information about the link (see #4007)
foreach ($vars as $k=>$v)
{
switch ($k)
{
default:
$arrInfo[$k] = $v;
break;
case 'do':
$arrInfo['do'] = $GLOBALS['TL_LANG']['MOD'][$v][0];
break;
case 'id':
$arrInfo['id'] = 'ID ' . $v;
break;
}
}
// Use the first table if none is given
if (!isset($arrInfo['table']))
{
foreach ($GLOBALS['BE_MOD'] as $category=>$modules)
{
if (isset($GLOBALS['BE_MOD'][$category][$vars['do']]))
{
$arrInfo['table'] = $GLOBALS['BE_MOD'][$category][$vars['do']]['tables'][0];
break;
}
}
}
System::loadLanguageFile($arrInfo['table']);
// Override the action label
if (isset($arrInfo['clipboard']))
{
$arrInfo['act'] = $GLOBALS['TL_LANG']['MSC']['clearClipboard'];
}
elseif (isset($arrInfo['mode']) && !isset($arrInfo['act']))
{
if ($arrInfo['mode'] == 'create')
{
$arrInfo['act'] = $GLOBALS['TL_LANG'][$arrInfo['table']]['new'][0];
}
elseif ($arrInfo['mode'] == 'cut' || $arrInfo['mode'] == 'copy')
{
$arrInfo['act'] = $GLOBALS['TL_LANG'][$arrInfo['table']][$arrInfo['mode']][0];
}
}
else
{
$arrInfo['act'] = $GLOBALS['TL_LANG'][$arrInfo['table']][$arrInfo['act']][0];
}
unset($arrInfo['pid']);
unset($arrInfo['clipboard']);
unset($arrInfo['ref']);
unset($arrInfo['mode']);
// Template variables
$objTemplate->confirm = true;
$objTemplate->link = StringUtil::specialchars($url);
$objTemplate->info = $arrInfo;
$objTemplate->labels = $GLOBALS['TL_LANG']['CONFIRM'];
$objTemplate->explain = $GLOBALS['TL_LANG']['MSC']['invalidTokenUrl'];
$objTemplate->cancel = $GLOBALS['TL_LANG']['MSC']['cancelBT'];
$objTemplate->continue = $GLOBALS['TL_LANG']['MSC']['continue'];
$objTemplate->theme = Backend::getTheme();
$objTemplate->base = Environment::get('base');
$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
$objTemplate->h1 = $GLOBALS['TL_LANG']['MSC']['invalidToken'];
$objTemplate->title = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['invalidToken']);
$objTemplate->host = Backend::getDecodedHostname();
$objTemplate->charset = Config::get('characterSet');
return $objTemplate->getResponse();
}
}
class_alias(BackendConfirm::class, 'BackendConfirm');