[TASK] Fix CGL violations against InlineControlStructure
[Packages/TYPO3.CMS.git] / typo3 / move_el.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Move element wizard:
29 * Moving pages or content elements (tt_content) around in the system via a page tree navigation.
30 *
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 * XHTML compatible.
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36
37 $BACK_PATH = '';
38 require('init.php');
39 require('template.php');
40
41 // Include local language labels:
42 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
43
44 /**
45 * Local extension of the page tree class
46 *
47 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
48 * @package TYPO3
49 * @subpackage core
50 */
51 class localPageTree extends t3lib_pageTree {
52
53 /**
54 * Inserting uid-information in title-text for an icon
55 *
56 * @param string $icon Icon image
57 * @param array $row Item row
58 * @return string Wrapping icon image.
59 */
60 function wrapIcon($icon, $row) {
61 return $this->addTagAttributes($icon, ' title="id='.htmlspecialchars($row['uid']).'"');
62 }
63 }
64
65 /**
66 * Extension of position map for pages
67 *
68 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
69 * @package TYPO3
70 * @subpackage core
71 */
72 class ext_posMap_pages extends t3lib_positionMap {
73 var $l_insertNewPageHere = 'movePageToHere';
74
75 /**
76 * Creates the onclick event for the insert-icons.
77 *
78 * @param integer $pid The pid.
79 * @param integer $newPagePID New page id.
80 * @return string Onclick attribute content
81 */
82 function onClickEvent($pid, $newPagePID) {
83 return 'window.location.href=\'tce_db.php?cmd[pages][' . $GLOBALS['SOBE']->moveUid . '][' . $this->moveOrCopy . ']=' . $pid .
84 '&redirect=' . rawurlencode($this->R_URI) .
85 '&prErr=1&uPT=1&vC=' . $GLOBALS['BE_USER']->veriCode() .
86 t3lib_BEfunc::getUrlToken('tceAction') .
87 '\';return false;';
88 }
89
90 /**
91 * Wrapping page title.
92 *
93 * @param string $str Page title.
94 * @param array $rec Page record (?)
95 * @return string Wrapped title.
96 */
97 function linkPageTitle($str, $rec) {
98 $url = t3lib_div::linkThisScript(array('uid' => intval($rec['uid']), 'moveUid' => $GLOBALS['SOBE']->moveUid));
99 return '<a href="'.htmlspecialchars($url).'">'.$str.'</a>';
100 }
101
102 /**
103 * Wrap $t_code in bold IF the $dat uid matches $id
104 *
105 * @param string $t_code Title string
106 * @param array $dat Infomation array with record array inside.
107 * @param integer $id The current id.
108 * @return string The title string.
109 */
110 function boldTitle($t_code, $dat, $id) {
111 return parent::boldTitle($t_code, $dat, $GLOBALS['SOBE']->moveUid);
112 }
113 }
114
115 /**
116 * Extension of position map for content elements
117 *
118 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
119 * @package TYPO3
120 * @subpackage core
121 */
122 class ext_posMap_tt_content extends t3lib_positionMap {
123 var $dontPrintPageInsertIcons = 1;
124
125 /**
126 * Wrapping page title.
127 *
128 * @param string $str Page title.
129 * @param array $rec Page record (?)
130 * @return string Wrapped title.
131 */
132 function linkPageTitle($str, $rec) {
133 $url = t3lib_div::linkThisScript(array('uid'=>intval($rec['uid']), 'moveUid'=>$GLOBALS['SOBE']->moveUid));
134 return '<a href="'.htmlspecialchars($url).'">'.$str.'</a>';
135 }
136
137 /**
138 * Wrapping the title of the record.
139 *
140 * @param string $str The title value.
141 * @param array $row The record row.
142 * @return string Wrapped title string.
143 */
144 function wrapRecordTitle($str, $row) {
145 if ($GLOBALS['SOBE']->moveUid==$row['uid']) {
146 $str = '<strong>'.$str.'</strong>';
147 }
148 return parent::wrapRecordTitle($str, $row);
149 }
150 }
151
152 /**
153 * Script Class for rendering the move-element wizard display
154 *
155 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
156 * @package TYPO3
157 * @subpackage core
158 */
159 class SC_move_el {
160
161 // Internal, static (eg. from GPvars):
162 var $sys_language = 0;
163 var $page_id;
164 var $table;
165 var $R_URI;
166 var $input_moveUid;
167 var $moveUid;
168 var $makeCopy;
169
170 /**
171 * Document template object
172 *
173 * @var mediumDoc
174 */
175 var $doc;
176 // Pages-select clause
177 var $perms_clause;
178
179 // Internal, dynamic:
180 // Content for module accumulated here.
181 var $content;
182
183 /**
184 * Constructor, initializing internal variables.
185 *
186 * @return void
187 */
188 function init() {
189
190 // Setting internal vars:
191 $this->sys_language = intval(t3lib_div::_GP('sys_language'));
192 $this->page_id = intval(t3lib_div::_GP('uid'));
193 $this->table = t3lib_div::_GP('table');
194 $this->R_URI = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
195 $this->input_moveUid = t3lib_div::_GP('moveUid');
196 $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
197 $this->makeCopy = t3lib_div::_GP('makeCopy');
198
199 // Select-pages where clause for read-access:
200 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
201
202 // Starting the document template object:
203 $this->doc = t3lib_div::makeInstance('template');
204 $this->doc->backPath = $GLOBALS['BACK_PATH'];
205 $this->doc->setModuleTemplate('templates/move_el.html');
206 $this->doc->JScode = '';
207
208 // Starting document content (header):
209 $this->content = '';
210 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('movingElement'));
211 }
212
213 /**
214 * Creating the module output.
215 *
216 * @return void
217 */
218 function main() {
219 if ($this->page_id) {
220
221 // Get record for element:
222 $elRow = t3lib_BEfunc::getRecordWSOL($this->table, $this->moveUid);
223
224 // Headerline: Icon, record title:
225 $hline = t3lib_iconWorks::getSpriteIconForRecord($this->table, $elRow, array('id' => 'c-recIcon', 'title' => htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($elRow, $this->table))));
226 $hline .= t3lib_BEfunc::getRecordTitle($this->table, $elRow, TRUE);
227
228 // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
229 $hline .= $this->doc->spacer(5);
230 $onClick = 'window.location.href=\''.t3lib_div::linkThisScript(array('makeCopy'=>!$this->makeCopy)).'\';';
231 $hline .= $this->doc->spacer(5);
232 $hline .= '<input type="hidden" name="makeCopy" value="0" />' .
233 '<input type="checkbox" name="makeCopy" id="makeCopy" value="1"' .
234 ($this->makeCopy ? ' checked="checked"' : '') .
235 ' onclick="' . htmlspecialchars($onClick) . '" /> <label for="makeCopy" class="t3-label-valign-top">' .
236 $GLOBALS['LANG']->getLL('makeCopy', 1) . '</label>';
237
238 // Add the header-content to the module content:
239 $this->content .= $this->doc->section('', $hline, FALSE, TRUE);
240 $this->content .= $this->doc->spacer(20);
241
242 // Reset variable to pick up the module content in:
243 $code = '';
244
245 // IF the table is "pages":
246 if ((string)$this->table=='pages') {
247 // Get page record (if accessible):
248 $pageinfo = t3lib_BEfunc::readPageAccess($this->page_id, $this->perms_clause);
249 if (is_array($pageinfo) && $GLOBALS['BE_USER']->isInWebMount($pageinfo['pid'], $this->perms_clause)) {
250
251 // Initialize the position map:
252 $posMap = t3lib_div::makeInstance('ext_posMap_pages');
253 $posMap->moveOrCopy = $this->makeCopy?'copy':'move';
254
255 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
256 if ($pageinfo['pid']) {
257 $pidPageInfo = t3lib_BEfunc::readPageAccess($pageinfo['pid'], $this->perms_clause);
258 if (is_array($pidPageInfo)) {
259 if ($GLOBALS['BE_USER']->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
260 $code .= '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('uid'=>intval($pageinfo['pid']), 'moveUid'=>$this->moveUid))).'">'.
261 t3lib_iconWorks::getSpriteIcon('actions-view-go-up') .
262 t3lib_BEfunc::getRecordTitle('pages', $pidPageInfo, TRUE).
263 '</a><br />';
264 } else {
265 $code .= t3lib_iconWorks::getSpriteIconForRecord('pages', $pidPageInfo) .
266 t3lib_BEfunc::getRecordTitle('pages', $pidPageInfo, TRUE).
267 '<br />';
268 }
269 }
270 }
271
272 // Create the position tree:
273 $code .= $posMap->positionTree($this->page_id, $pageinfo, $this->perms_clause, $this->R_URI);
274 }
275 }
276
277 // IF the table is "tt_content":
278 if ((string)$this->table == 'tt_content') {
279
280 // First, get the record:
281 $tt_content_rec = t3lib_BEfunc::getRecord('tt_content', $this->moveUid);
282
283 // ?
284 if (!$this->input_moveUid) {
285 $this->page_id = $tt_content_rec['pid'];
286 }
287
288 // Checking if the parent page is readable:
289 $pageinfo = t3lib_BEfunc::readPageAccess($this->page_id, $this->perms_clause);
290 if (is_array($pageinfo) && $GLOBALS['BE_USER']->isInWebMount($pageinfo['pid'], $this->perms_clause)) {
291
292 // Initialize the position map:
293 $posMap = t3lib_div::makeInstance('ext_posMap_tt_content');
294 $posMap->moveOrCopy = $this->makeCopy?'copy':'move';
295 $posMap->cur_sys_language = $this->sys_language;
296
297 // Headerline for the parent page: Icon, record title:
298 $hline = t3lib_iconWorks::getSpriteIconForRecord('pages', $pageinfo, array('title' => htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($pageinfo, 'pages'))));
299 $hline .= t3lib_BEfunc::getRecordTitle('pages', $pageinfo, TRUE);
300
301 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
302 // SHARED page-TSconfig settings.
303 $modTSconfig_SHARED = t3lib_BEfunc::getModTSconfig($this->page_id, 'mod.SHARED');
304 $colPosArray = t3lib_div::callUserFunction('EXT:cms/classes/class.tx_cms_backendlayout.php:tx_cms_BackendLayout->getColPosListItemsParsed', $this->page_id, $this);
305 foreach ($colPosArray as $colPos) {
306 $colPosList .= $colPosList != '' ? ',' . $colPos[1] : $colPos[1];
307 }
308 // Removing duplicates, if any
309 $colPosList = implode(',', array_unique(t3lib_div::intExplode(',', $colPosList)));
310
311 // Adding parent page-header and the content element columns from position-map:
312 $code = $hline . '<br />';
313 $code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
314
315 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
316 $code .= '<br />';
317 $code .= '<br />';
318 if ($pageinfo['pid']) {
319 $pidPageInfo = t3lib_BEfunc::readPageAccess($pageinfo['pid'], $this->perms_clause);
320 if (is_array($pidPageInfo)) {
321 if ($GLOBALS['BE_USER']->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
322 $code .= '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
323 'uid' => intval($pageinfo['pid']),
324 'moveUid' => $this->moveUid)
325 )) . '">'
326 . t3lib_iconWorks::getSpriteIcon('actions-view-go-up')
327 . t3lib_BEfunc::getRecordTitle('pages', $pidPageInfo, TRUE)
328 . '</a><br />';
329 } else {
330 $code.= t3lib_iconWorks::getSpriteIconForRecord('pages', $pidPageInfo)
331 . t3lib_BEfunc::getRecordTitle('pages', $pidPageInfo, TRUE)
332 . '<br />';
333 }
334 }
335 }
336
337 // Create the position tree (for pages):
338 $code .= $posMap->positionTree($this->page_id, $pageinfo, $this->perms_clause, $this->R_URI);
339 }
340 }
341
342 // Add the $code content as a new section to the module:
343 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('selectPositionOfElement'), $code, FALSE, TRUE);
344 }
345
346 // Setting up the buttons and markers for docheader
347 $docHeaderButtons = $this->getButtons();
348 $markers['CSH'] = $docHeaderButtons['csh'];
349 $markers['CONTENT'] = $this->content;
350
351 // Build the <body> for the module
352 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('movingElement'));
353 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
354 $this->content .= $this->doc->endPage();
355 $this->content = $this->doc->insertStylesAndJS($this->content);
356 }
357
358 /**
359 * Print out the accumulated content:
360 *
361 * @return void
362 */
363 function printContent() {
364 echo $this->content;
365 }
366
367 /**
368 * Create the panel of buttons for submitting the form or otherwise perform operations.
369 *
370 * @return array All available buttons as an assoc. array
371 */
372 protected function getButtons() {
373 $buttons = array(
374 'csh' => '',
375 'back' => ''
376 );
377
378 if ($this->page_id) {
379 if ((string)$this->table == 'pages') {
380 // CSH
381 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'move_el_pages', $GLOBALS['BACK_PATH'], '', TRUE);
382 } elseif((string)$this->table == 'tt_content') {
383 // CSH
384 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'move_el_cs', $GLOBALS['BACK_PATH'], '', TRUE);
385 }
386
387 if ($this->R_URI) {
388 // Back
389 $buttons['back'] ='<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->getLL('goBack', TRUE) .'">' .
390 t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
391 '</a>';
392 }
393 }
394
395 return $buttons;
396 }
397 }
398
399 // Make instance:
400 $SOBE = t3lib_div::makeInstance('SC_move_el');
401 $SOBE->init();
402 $SOBE->main();
403 $SOBE->printContent();
404
405 ?>