-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
BackendHelp.php
159 lines (136 loc) · 3.53 KB
/
BackendHelp.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
<?php
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2017 Leo Feyer
*
* @license LGPL-3.0+
*/
namespace Contao;
use Contao\CoreBundle\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Response;
/**
* Back end help wizard.
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class BackendHelp 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', '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 and parse the template
*
* @return Response
*/
public function run()
{
$table = \Input::get('table');
$field = \Input::get('field');
\System::loadLanguageFile($table);
$this->loadDataContainer($table);
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_help');
$objTemplate->rows = array();
$objTemplate->explanation = '';
$arrData = $GLOBALS['TL_DCA'][$table]['fields'][$field];
// Add the reference
if (!empty($arrData['reference']))
{
$rows = array();
if (is_array($arrData['options']))
{
$options = $arrData['options'];
}
elseif (is_array($arrData['options_callback']))
{
$this->import($arrData['options_callback'][0]);
$options = $this->{$arrData['options_callback'][0]}->{$arrData['options_callback'][1]}(new \DC_Table($table));
}
elseif (is_callable($arrData['options_callback']))
{
$options = $arrData['options_callback']();
}
else
{
$options = array_keys($arrData['reference']);
}
// Unset the predefined image sizes
unset($options['image_sizes']);
foreach ($options as $key=>$option)
{
if (is_array($option))
{
if (is_array($arrData['reference'][$key]))
{
$rows[] = array('headspan', $arrData['reference'][$key][0]);
}
else
{
$rows[] = array('headspan', $arrData['reference'][$key]);
}
foreach ($option as $opt)
{
$rows[] = $arrData['reference'][$opt];
}
}
else
{
if (isset($arrData['reference'][$key]))
{
$rows[] = $arrData['reference'][$key];
}
elseif (is_array($arrData['reference'][$option]))
{
$rows[] = $arrData['reference'][$option];
}
else
{
$rows[] = array('headspan', $arrData['reference'][$option]);
}
}
}
$objTemplate->rows = $rows;
}
// Add an explanation
if (isset($arrData['explanation']))
{
\System::loadLanguageFile('explain');
$key = $arrData['explanation'];
if (!is_array($GLOBALS['TL_LANG']['XPL'][$key]))
{
$objTemplate->explanation = trim($GLOBALS['TL_LANG']['XPL'][$key]);
}
else
{
$objTemplate->rows = $GLOBALS['TL_LANG']['XPL'][$key];
}
}
$objTemplate->theme = \Backend::getTheme();
$objTemplate->base = \Environment::get('base');
$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
$objTemplate->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['helpWizardTitle']);
$objTemplate->charset = \Config::get('characterSet');
$objTemplate->headline = $arrData['label'][0] ?: $field;
$objTemplate->helpWizard = $GLOBALS['TL_LANG']['MSC']['helpWizard'];
return $objTemplate->getResponse();
}
}