-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
BackendPage.php
167 lines (137 loc) · 4.53 KB
/
BackendPage.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
164
165
166
167
<?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;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/**
* Back end page picker.
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class BackendPage extends \Backend
{
/**
* Current Ajax object
* @var Ajax
*/
protected $objAjax;
/**
* 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');
}
/**
* Run the controller and parse the template
*
* @return Response
*/
public function run()
{
/** @var SessionInterface $objSession */
$objSession = \System::getContainer()->get('session');
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_picker');
$objTemplate->main = '';
// Ajax request
if ($_POST && \Environment::get('isAjaxRequest'))
{
$this->objAjax = new \Ajax(\Input::post('action'));
$this->objAjax->executePreActions();
}
$strTable = \Input::get('table');
$strField = \Input::get('field');
// Define the current ID
define('CURRENT_ID', (\Input::get('table') ? $objSession->get('CURRENT_ID') : \Input::get('id')));
$this->loadDataContainer($strTable);
$strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer'];
$objDca = new $strDriver($strTable);
$objDca->field = $strField;
// Set the active record
if ($this->Database->tableExists($strTable))
{
/** @var Model $strModel */
$strModel = \Model::getClassFromTable($strTable);
if (class_exists($strModel))
{
$objModel = $strModel::findByPk(\Input::get('id'));
if ($objModel !== null)
{
$objDca->activeRecord = $objModel;
}
}
}
// AJAX request
if ($_POST && \Environment::get('isAjaxRequest'))
{
$this->objAjax->executePostActions($objDca);
}
$objSession->set('filePickerRef', \Environment::get('request'));
$arrValues = array_filter(explode(',', \Input::get('value')));
// Call the load_callback
if (is_array($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback']))
{
foreach ($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$arrValues = $this->{$callback[0]}->{$callback[1]}($arrValues, $objDca);
}
elseif (is_callable($callback))
{
$arrValues = $callback($arrValues, $objDca);
}
}
}
/** @var PageSelector $strClass */
$strClass = $GLOBALS['BE_FFL']['pageSelector'];
/** @var PageSelector $objPageTree */
$objPageTree = new $strClass($strClass::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, $arrValues, $strField, $strTable, $objDca));
/** @var AttributeBagInterface $objSessionBag */
$objSessionBag = $objSession->getBag('contao_backend');
$objTemplate->main = $objPageTree->generate();
$objTemplate->theme = \Backend::getTheme();
$objTemplate->base = \Environment::get('base');
$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
$objTemplate->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']);
$objTemplate->charset = \Config::get('characterSet');
$objTemplate->addSearch = true;
$objTemplate->search = $GLOBALS['TL_LANG']['MSC']['search'];
$objTemplate->action = ampersand(\Environment::get('request'));
$objTemplate->value = $objSessionBag->get('page_selector_search');
$objTemplate->breadcrumb = $GLOBALS['TL_DCA']['tl_page']['list']['sorting']['breadcrumb'];
if ($this->User->hasAccess('page', 'modules'))
{
$objTemplate->manager = $GLOBALS['TL_LANG']['MSC']['pageManager'];
$objTemplate->managerHref = 'contao/main.php?do=page&popup=1';
}
if (\Input::get('switch') && $this->User->hasAccess('files', 'modules'))
{
$objTemplate->switch = $GLOBALS['TL_LANG']['MSC']['filePicker'];
$objTemplate->switchHref = str_replace('contao/page?', 'contao/file?', ampersand(\Environment::get('request')));
}
return $objTemplate->getResponse();
}
}