MoveElementController.php 9.93 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

Nicole Cordes's avatar
Nicole Cordes committed
17
18
19
20
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\Utility\IconUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

21
22
23
24
25
26
27
28
29
/**
 * Script Class for rendering the move-element wizard display
 *
 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
 */
class MoveElementController {

	// Internal, static (eg. from GPvars):
	/**
30
	 * @var int
31
32
33
34
	 */
	public $sys_language = 0;

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

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

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

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

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

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

	/**
	 * Document template object
	 *
67
	 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
68
69
70
71
72
	 */
	public $doc;

	// Pages-select clause
	/**
73
	 * @var string
74
75
76
77
78
79
	 */
	public $perms_clause;

	// Internal, dynamic:
	// Content for module accumulated here.
	/**
80
	 * @var string
81
82
83
	 */
	public $content;

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

93
94
95
96
97
98
99
	/**
	 * Constructor, initializing internal variables.
	 *
	 * @return void
	 */
	public function init() {
		// Setting internal vars:
100
101
		$this->sys_language = (int)GeneralUtility::_GP('sys_language');
		$this->page_id = (int)GeneralUtility::_GP('uid');
Nicole Cordes's avatar
Nicole Cordes committed
102
103
104
		$this->table = GeneralUtility::_GP('table');
		$this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
		$this->input_moveUid = GeneralUtility::_GP('moveUid');
105
		$this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
Nicole Cordes's avatar
Nicole Cordes committed
106
		$this->makeCopy = GeneralUtility::_GP('makeCopy');
107
108
109
		// Select-pages where clause for read-access:
		$this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
		// Starting the document template object:
Nicole Cordes's avatar
Nicole Cordes committed
110
		$this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
111
		$this->doc->backPath = $GLOBALS['BACK_PATH'];
112
		$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/move_el.html');
113
114
115
116
117
118
119
120
121
122
123
124
125
126
		$this->doc->JScode = '';
		// Starting document content (header):
		$this->content = '';
		$this->content .= $this->doc->header($GLOBALS['LANG']->getLL('movingElement'));
	}

	/**
	 * Creating the module output.
	 *
	 * @return void
	 */
	public function main() {
		if ($this->page_id) {
			// Get record for element:
Nicole Cordes's avatar
Nicole Cordes committed
127
			$elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
128
			// Headerline: Icon, record title:
Nicole Cordes's avatar
Nicole Cordes committed
129
130
			$hline = IconUtility::getSpriteIconForRecord($this->table, $elRow, array('id' => 'c-recIcon', 'title' => htmlspecialchars(BackendUtility::getRecordIconAltText($elRow, $this->table))));
			$hline .= BackendUtility::getRecordTitle($this->table, $elRow, TRUE);
131
132
			// Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
			$hline .= $this->doc->spacer(5);
Nicole Cordes's avatar
Nicole Cordes committed
133
			$onClick = 'window.location.href=\'' . GeneralUtility::linkThisScript(array('makeCopy' => !$this->makeCopy)) . '\';';
134
			$hline .= $this->doc->spacer(5);
135
			$hline .= '<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">' . $GLOBALS['LANG']->getLL('makeCopy', 1) . '</label>';
136
137
138
139
140
141
142
143
			// Add the header-content to the module content:
			$this->content .= $this->doc->section('', $hline, FALSE, TRUE);
			$this->content .= $this->doc->spacer(20);
			// 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):
Nicole Cordes's avatar
Nicole Cordes committed
144
				$pageinfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
145
146
				if (is_array($pageinfo) && $GLOBALS['BE_USER']->isInWebMount($pageinfo['pid'], $this->perms_clause)) {
					// Initialize the position map:
Nicole Cordes's avatar
Nicole Cordes committed
147
					$posMap = GeneralUtility::makeInstance('ext_posMap_pages');
148
149
150
					$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']) {
Nicole Cordes's avatar
Nicole Cordes committed
151
						$pidPageInfo = BackendUtility::readPageAccess($pageinfo['pid'], $this->perms_clause);
152
153
						if (is_array($pidPageInfo)) {
							if ($GLOBALS['BE_USER']->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
154
								$code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('uid' => (int)$pageinfo['pid'], 'moveUid' => $this->moveUid))) . '">' . IconUtility::getSpriteIcon('actions-view-go-up') . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '</a><br />';
155
							} else {
Nicole Cordes's avatar
Nicole Cordes committed
156
								$code .= IconUtility::getSpriteIconForRecord('pages', $pidPageInfo) . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
157
158
159
160
161
162
163
164
165
166
							}
						}
					}
					// 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:
Nicole Cordes's avatar
Nicole Cordes committed
167
				$tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
168
169
170
171
172
				// ?
				if (!$this->input_moveUid) {
					$this->page_id = $tt_content_rec['pid'];
				}
				// Checking if the parent page is readable:
Nicole Cordes's avatar
Nicole Cordes committed
173
				$pageinfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
174
175
				if (is_array($pageinfo) && $GLOBALS['BE_USER']->isInWebMount($pageinfo['pid'], $this->perms_clause)) {
					// Initialize the position map:
Nicole Cordes's avatar
Nicole Cordes committed
176
					$posMap = GeneralUtility::makeInstance('ext_posMap_tt_content');
177
178
179
					$posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
					$posMap->cur_sys_language = $this->sys_language;
					// Headerline for the parent page: Icon, record title:
Nicole Cordes's avatar
Nicole Cordes committed
180
181
					$hline = IconUtility::getSpriteIconForRecord('pages', $pageinfo, array('title' => htmlspecialchars(BackendUtility::getRecordIconAltText($pageinfo, 'pages'))));
					$hline .= BackendUtility::getRecordTitle('pages', $pageinfo, TRUE);
182
183
					// Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
					// SHARED page-TSconfig settings.
Nicole Cordes's avatar
Nicole Cordes committed
184
185
					$modTSconfig_SHARED = BackendUtility::getModTSconfig($this->page_id, 'mod.SHARED');
					$colPosArray = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getColPosListItemsParsed', $this->page_id, $this);
186
					$colPosIds = array();
187
					foreach ($colPosArray as $colPos) {
188
						$colPosIds[] = $colPos[1];
189
190
					}
					// Removing duplicates, if any
191
					$colPosList = implode(',', array_unique($colPosIds));
192
193
194
195
					// Adding parent page-header and the content element columns from position-map:
					$code = $hline . '<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).
Nicole Cordes's avatar
Nicole Cordes committed
196
					$code .= '<br /><br />';
197
					if ($pageinfo['pid']) {
Nicole Cordes's avatar
Nicole Cordes committed
198
						$pidPageInfo = BackendUtility::readPageAccess($pageinfo['pid'], $this->perms_clause);
199
200
						if (is_array($pidPageInfo)) {
							if ($GLOBALS['BE_USER']->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
Nicole Cordes's avatar
Nicole Cordes committed
201
								$code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array(
202
									'uid' => (int)$pageinfo['pid'],
203
									'moveUid' => $this->moveUid
Nicole Cordes's avatar
Nicole Cordes committed
204
								))) . '">' . IconUtility::getSpriteIcon('actions-view-go-up') . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '</a><br />';
205
							} else {
Nicole Cordes's avatar
Nicole Cordes committed
206
								$code .= IconUtility::getSpriteIconForRecord('pages', $pidPageInfo) . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
							}
						}
					}
					// 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:
			$this->content .= $this->doc->section($GLOBALS['LANG']->getLL('selectPositionOfElement'), $code, FALSE, TRUE);
		}
		// Setting up the buttons and markers for docheader
		$docHeaderButtons = $this->getButtons();
		$markers['CSH'] = $docHeaderButtons['csh'];
		$markers['CONTENT'] = $this->content;
		// Build the <body> for the module
		$this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('movingElement'));
		$this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
		$this->content .= $this->doc->endPage();
		$this->content = $this->doc->insertStylesAndJS($this->content);
	}

	/**
	 * Print out the accumulated content:
	 *
	 * @return void
	 */
	public function printContent() {
		echo $this->content;
	}

	/**
	 * Create the panel of buttons for submitting the form or otherwise perform operations.
	 *
	 * @return array All available buttons as an assoc. array
	 */
	protected function getButtons() {
		$buttons = array(
			'csh' => '',
			'back' => ''
		);
		if ($this->page_id) {
			if ((string) $this->table == 'pages') {
Nicole Cordes's avatar
Nicole Cordes committed
249
				$buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_pages', $GLOBALS['BACK_PATH'], '', TRUE);
250
			} elseif ((string) $this->table == 'tt_content') {
Nicole Cordes's avatar
Nicole Cordes committed
251
				$buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_cs', $GLOBALS['BACK_PATH'], '', TRUE);
252
253
			}
			if ($this->R_URI) {
Nicole Cordes's avatar
Nicole Cordes committed
254
				$buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->getLL('goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
255
256
257
258
259
260
			}
		}
		return $buttons;
	}

}