This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
/
BackendPage.php
139 lines (116 loc) · 3.65 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
<?php
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Core
* @link https://contao.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL
*/
/**
* Run in a custom namespace, so the class can be replaced
*/
namespace Contao;
/**
* Class BackendPage
*
* Back end page picker.
* @copyright Leo Feyer 2005-2014
* @author Leo Feyer <https://contao.org>
* @package Core
*/
class BackendPage extends \Backend
{
/**
* Current Ajax object
* @var object
*/
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();
$this->User->authenticate();
\System::loadLanguageFile('default');
}
/**
* Run the controller and parse the template
*/
public function run()
{
$this->Template = new \BackendTemplate('be_picker');
$this->Template->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') ? $this->Session->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
$strModel = \Model::getClassFromTable($strTable);
$objModel = $strModel::findByPk(\Input::get('id'));
if ($objModel !== null)
{
$objDca->activeRecord = $objModel;
}
// AJAX request
if ($_POST && \Environment::get('isAjaxRequest'))
{
$this->objAjax->executePostActions($objDca);
}
$this->Session->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);
}
}
}
// Prepare the widget
$class = $GLOBALS['BE_FFL']['pageSelector'];
$objPageTree = new $class($class::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, $arrValues, $strField, $strTable, $objDca));
$this->Template->main = $objPageTree->generate();
$this->Template->theme = \Backend::getTheme();
$this->Template->base = \Environment::get('base');
$this->Template->language = $GLOBALS['TL_LANGUAGE'];
$this->Template->title = specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']);
$this->Template->charset = \Config::get('characterSet');
$this->Template->addSearch = true;
$this->Template->search = $GLOBALS['TL_LANG']['MSC']['search'];
$this->Template->action = ampersand(\Environment::get('request'));
$this->Template->value = $this->Session->get('page_selector_search');
$this->Template->manager = $GLOBALS['TL_LANG']['MSC']['pageManager'];
$this->Template->managerHref = 'contao/main.php?do=page&popup=1';
$this->Template->breadcrumb = $GLOBALS['TL_DCA']['tl_page']['list']['sorting']['breadcrumb'];
\Config::set('debugMode', false);
$this->Template->output();
}
}