MoveElementController.php 12.8 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Controller\ContentElement;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
20
21
use TYPO3\CMS\Backend\Module\AbstractModule;
use TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap;
use TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap;
Nicole Cordes's avatar
Nicole Cordes committed
22
use TYPO3\CMS\Backend\Utility\BackendUtility;
23
use TYPO3\CMS\Core\Imaging\Icon;
Nicole Cordes's avatar
Nicole Cordes committed
24
25
use TYPO3\CMS\Core\Utility\GeneralUtility;

26
27
28
/**
 * Script Class for rendering the move-element wizard display
 */
29
class MoveElementController extends AbstractModule
30
31
32
33
34
{
    /**
     * @var int
     */
    public $sys_language = 0;
35

36
37
38
39
    /**
     * @var int
     */
    public $page_id;
40

41
42
43
44
    /**
     * @var string
     */
    public $table;
45

46
47
48
49
    /**
     * @var string
     */
    public $R_URI;
50

51
52
53
54
    /**
     * @var int
     */
    public $input_moveUid;
55

56
57
58
59
    /**
     * @var int
     */
    public $moveUid;
60

61
62
63
64
    /**
     * @var int
     */
    public $makeCopy;
65

66
67
68
69
70
71
    /**
     * Pages-select clause
     *
     * @var string
     */
    public $perms_clause;
72

73
74
75
76
77
78
    /**
     * Content for module accumulated here.
     *
     * @var string
     */
    public $content;
79

80
81
82
83
84
    /**
     * Constructor
     */
    public function __construct()
    {
85
        parent::__construct();
86
87
88
89
        $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
        $GLOBALS['SOBE'] = $this;
        $this->init();
    }
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    /**
     * Constructor, initializing internal variables.
     *
     * @return void
     */
    public function init()
    {
        // Setting internal vars:
        $this->sys_language = (int)GeneralUtility::_GP('sys_language');
        $this->page_id = (int)GeneralUtility::_GP('uid');
        $this->table = GeneralUtility::_GP('table');
        $this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
        $this->input_moveUid = GeneralUtility::_GP('moveUid');
        $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
        $this->makeCopy = GeneralUtility::_GP('makeCopy');
        // Select-pages where clause for read-access:
        $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
108
        $this->content = '<h1>' . $this->getLanguageService()->getLL('movingElement') . '</h1>';
109
    }
110

111
112
113
114
115
116
117
118
119
120
121
    /**
     * Injects the request object for the current request or subrequest
     * As this controller goes only through the main() method, it is rather simple for now
     *
     * @param ServerRequestInterface $request the current request
     * @param ResponseInterface $response
     * @return ResponseInterface the response with the content
     */
    public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
    {
        $this->main();
122

123
124
        $this->moduleTemplate->setContent($this->content);
        $response->getBody()->write($this->moduleTemplate->renderContent());
125
126
        return $response;
    }
127

128
129
130
131
132
133
134
135
136
137
    /**
     * Creating the module output.
     *
     * @return void
     */
    public function main()
    {
        $lang = $this->getLanguageService();
        if ($this->page_id) {
            $backendUser = $this->getBackendUser();
138
            $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
139
140
141
            // Get record for element:
            $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
            // Headerline: Icon, record title:
142
            $headerLine = '<span ' . BackendUtility::getRecordToolTip($elRow, $this->table) . '>' . $this->moduleTemplate->getIconFactory()->getIconForRecord($this->table, $elRow, Icon::SIZE_SMALL)->render() . '</span>';
143
144
145
            $headerLine .= BackendUtility::getRecordTitle($this->table, $elRow, true);
            // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
            $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(array('makeCopy' => !$this->makeCopy))) . ';';
146
            $headerLine .= '<div><input type="hidden" name="makeCopy" value="0" />' . '<input type="checkbox" name="makeCopy" id="makeCopy" value="1"' . ($this->makeCopy ? ' checked="checked"' : '') . ' onclick="' . htmlspecialchars($onClick) . '" /> <label for="makeCopy" class="t3-label-valign-top">' . $lang->getLL('makeCopy', 1) . '</label></div>';
147
            // Add the header-content to the module content:
148
            $this->content .= '<div>' . $headerLine . '</div>';
149
150
151
152
153
154
155
156
            // Reset variable to pick up the module content in:
            $code = '';
            // IF the table is "pages":
            if ((string)$this->table == 'pages') {
                // Get page record (if accessible):
                $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
                if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
                    // Initialize the position map:
157
                    $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
158
159
160
161
162
163
                    $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
                    // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
                    if ($pageInfo['pid']) {
                        $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
                        if (is_array($pidPageInfo)) {
                            if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
164
                                $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('uid' => (int)$pageInfo['pid'], 'moveUid' => $this->moveUid))) . '">' . $this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '</a><br />';
165
                            } else {
166
                                $code .= $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '<br />';
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
                            }
                        }
                    }
                    // Create the position tree:
                    $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
                }
            }
            // IF the table is "tt_content":
            if ((string)$this->table == 'tt_content') {
                // First, get the record:
                $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
                // ?
                if (!$this->input_moveUid) {
                    $this->page_id = $tt_content_rec['pid'];
                }
                // Checking if the parent page is readable:
                $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
                if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
                    // Initialize the position map:
186
                    $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
187
188
189
                    $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
                    $posMap->cur_sys_language = $this->sys_language;
                    // Headerline for the parent page: Icon, record title:
190
                    $headerLine = '<span ' . BackendUtility::getRecordToolTip($pageInfo, 'pages') . '>'
191
192
193
194
195
                        . $this->moduleTemplate->getIconFactory()->getIconForRecord(
                            'pages',
                            $pageInfo,
                            Icon::SIZE_SMALL
                        )->render() . '</span>';
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
                    $headerLine .= BackendUtility::getRecordTitle('pages', $pageInfo, true);
                    // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
                    // SHARED page-TSconfig settings.
                    // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
                    $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
                    $colPosIds = array();
                    foreach ($colPosArray as $colPos) {
                        $colPosIds[] = $colPos[1];
                    }
                    // Removing duplicates, if any
                    $colPosList = implode(',', array_unique($colPosIds));
                    // Adding parent page-header and the content element columns from position-map:
                    $code = $headerLine . '<br />';
                    $code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
                    // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
                    $code .= '<br /><br />';
                    if ($pageInfo['pid']) {
                        $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
                        if (is_array($pidPageInfo)) {
                            if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
                                $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array(
                                    'uid' => (int)$pageInfo['pid'],
                                    'moveUid' => $this->moveUid
219
                                ))) . '">' . $this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '</a><br />';
220
                            } else {
221
                                $code .= $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '<br />';
222
223
224
225
226
227
228
229
                            }
                        }
                    }
                    // Create the position tree (for pages):
                    $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
                }
            }
            // Add the $code content as a new section to the module:
230
231
            $this->content .= '<h2>' . $lang->getLL('selectPositionOfElement') . '</h2>';
            $this->content .= '<div>' . $code . '</div>';
232
233
        }
        // Setting up the buttons and markers for docheader
234
        $this->getButtons();
235
        // Build the <body> for the module
236
        $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
237
    }
238

239
240
241
242
243
    /**
     * Create the panel of buttons for submitting the form or otherwise perform operations.
     */
    protected function getButtons()
    {
244
        $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
245
246
        if ($this->page_id) {
            if ((string)$this->table == 'pages') {
247
248
249
250
                $cshButton = $buttonBar->makeHelpButton()
                    ->setModuleName('xMOD_csh_corebe')
                    ->setFieldName('move_el_pages');
                $buttonBar->addButton($cshButton);
251
            } elseif ((string)$this->table == 'tt_content') {
252
253
254
255
                $cshButton = $buttonBar->makeHelpButton()
                    ->setModuleName('xMOD_csh_corebe')
                    ->setFieldName('move_el_cs');
                $buttonBar->addButton($cshButton);
256
            }
257

258
            if ($this->R_URI) {
259
260
                $backButton = $buttonBar->makeLinkButton()
                    ->setHref($this->R_URI)
261
                    ->setTitle($this->getLanguageService()->getLL('goBack'))
262
263
264
265
266
                    ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
                        'actions-view-go-back',
                        Icon::SIZE_SMALL
                    ));
                $buttonBar->addButton($backButton);
267
268
269
            }
        }
    }
270

271
272
273
274
275
276
277
278
279
    /**
     * Returns LanguageService
     *
     * @return \TYPO3\CMS\Lang\LanguageService
     */
    protected function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }
280

281
282
283
284
285
286
287
288
289
    /**
     * Returns the current BE user.
     *
     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
     */
    protected function getBackendUser()
    {
        return $GLOBALS['BE_USER'];
    }
290
}