[TASK] Remove trailing newlines from EOF
[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 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 96: class localPageTree extends t3lib_pageTree
42 * 105: function wrapIcon($icon,$row)
43 *
44 *
45 * 127: class ext_posMap_pages extends t3lib_positionMap
46 * 137: function onClickEvent($pid,$newPagePID)
47 * 148: function linkPageTitle($str,$rec)
48 * 161: function boldTitle($t_code,$dat,$id)
49 *
50 *
51 * 184: class ext_posMap_tt_content extends t3lib_positionMap
52 * 194: function linkPageTitle($str,$rec)
53 * 206: function wrapRecordTitle($str,$row)
54 *
55 *
56 * 227: class SC_move_el
57 * 250: function init()
58 * 284: function main()
59 * 416: function printContent()
60 *
61 * TOTAL FUNCTIONS: 9
62 * (This index is automatically created/updated by the extension "extdeveval")
63 *
64 */
65
66
67 $BACK_PATH='';
68 require('init.php');
69 require('template.php');
70
71 // Include local language labels:
72 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
73
74
75
76
77
78
79
80
81
82
83 /**
84 * Local extension of the page tree class
85 *
86 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
87 * @package TYPO3
88 * @subpackage core
89 */
90 class localPageTree extends t3lib_pageTree {
91
92 /**
93 * Inserting uid-information in title-text for an icon
94 *
95 * @param string Icon image
96 * @param array Item row
97 * @return string Wrapping icon image.
98 */
99 function wrapIcon($icon,$row) {
100 return $this->addTagAttributes($icon,' title="id='.htmlspecialchars($row['uid']).'"');
101 }
102 }
103
104
105
106
107
108
109
110
111
112
113
114 /**
115 * Extension of position map for pages
116 *
117 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
118 * @package TYPO3
119 * @subpackage core
120 */
121 class ext_posMap_pages extends t3lib_positionMap {
122 var $l_insertNewPageHere = 'movePageToHere';
123
124 /**
125 * Creates the onclick event for the insert-icons.
126 *
127 * @param integer The pid.
128 * @param integer New page id.
129 * @return string Onclick attribute content
130 */
131 function onClickEvent($pid,$newPagePID) {
132 return 'window.location.href=\'tce_db.php?cmd[pages][' . $GLOBALS['SOBE']->moveUid . '][' . $this->moveOrCopy . ']=' . $pid .
133 '&redirect=' . rawurlencode($this->R_URI) .
134 '&prErr=1&uPT=1&vC=' . $GLOBALS['BE_USER']->veriCode() .
135 t3lib_BEfunc::getUrlToken('tceAction') .
136 '\';return false;';
137 }
138
139 /**
140 * Wrapping page title.
141 *
142 * @param string Page title.
143 * @param array Page record (?)
144 * @return string Wrapped title.
145 */
146 function linkPageTitle($str,$rec) {
147 $url = t3lib_div::linkThisScript(array('uid'=>intval($rec['uid']),'moveUid'=>$GLOBALS['SOBE']->moveUid));
148 return '<a href="'.htmlspecialchars($url).'">'.$str.'</a>';
149 }
150
151 /**
152 * Wrap $t_code in bold IF the $dat uid matches $id
153 *
154 * @param string Title string
155 * @param array Infomation array with record array inside.
156 * @param integer The current id.
157 * @return string The title string.
158 */
159 function boldTitle($t_code,$dat,$id) {
160 return parent::boldTitle($t_code,$dat,$GLOBALS['SOBE']->moveUid);
161 }
162 }
163
164
165
166
167
168
169
170
171
172
173
174
175 /**
176 * Extension of position map for content elements
177 *
178 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
179 * @package TYPO3
180 * @subpackage core
181 */
182 class ext_posMap_tt_content extends t3lib_positionMap {
183 var $dontPrintPageInsertIcons = 1;
184
185 /**
186 * Wrapping page title.
187 *
188 * @param string Page title.
189 * @param array Page record (?)
190 * @return string Wrapped title.
191 */
192 function linkPageTitle($str,$rec) {
193 $url = t3lib_div::linkThisScript(array('uid'=>intval($rec['uid']),'moveUid'=>$GLOBALS['SOBE']->moveUid));
194 return '<a href="'.htmlspecialchars($url).'">'.$str.'</a>';
195 }
196
197 /**
198 * Wrapping the title of the record.
199 *
200 * @param string The title value.
201 * @param array The record row.
202 * @return string Wrapped title string.
203 */
204 function wrapRecordTitle($str,$row) {
205 if ($GLOBALS['SOBE']->moveUid==$row['uid']) $str = '<strong>'.$str.'</strong>';
206 return parent::wrapRecordTitle($str,$row);
207 }
208 }
209
210
211
212
213
214
215
216
217
218 /**
219 * Script Class for rendering the move-element wizard display
220 *
221 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
222 * @package TYPO3
223 * @subpackage core
224 */
225 class SC_move_el {
226
227 // Internal, static (eg. from GPvars):
228 var $sys_language=0;
229 var $page_id;
230 var $table;
231 var $R_URI;
232 var $input_moveUid;
233 var $moveUid;
234 var $makeCopy;
235
236 /**
237 * Document template object
238 *
239 * @var mediumDoc
240 */
241 var $doc;
242 var $perms_clause; // Pages-select clause
243
244 // Internal, dynamic:
245 var $content; // Content for module accumulated here.
246
247
248 /**
249 * Constructor, initializing internal variables.
250 *
251 * @return void
252 */
253 function init() {
254
255 // Setting internal vars:
256 $this->sys_language = intval(t3lib_div::_GP('sys_language'));
257 $this->page_id=intval(t3lib_div::_GP('uid'));
258 $this->table=t3lib_div::_GP('table');
259 $this->R_URI=t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
260 $this->input_moveUid = t3lib_div::_GP('moveUid');
261 $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
262 $this->makeCopy = t3lib_div::_GP('makeCopy');
263
264 // Select-pages where clause for read-access:
265 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
266
267 // Starting the document template object:
268 $this->doc = t3lib_div::makeInstance('template');
269 $this->doc->backPath = $GLOBALS['BACK_PATH'];
270 $this->doc->setModuleTemplate('templates/move_el.html');
271 $this->doc->JScode='';
272
273 // Starting document content (header):
274 $this->content='';
275 $this->content.=$this->doc->header($GLOBALS['LANG']->getLL('movingElement'));
276 $this->content.=$this->doc->spacer(5);
277 }
278
279 /**
280 * Creating the module output.
281 *
282 * @return void
283 */
284 function main() {
285 if ($this->page_id) {
286
287 // Get record for element:
288 $elRow = t3lib_BEfunc::getRecordWSOL($this->table,$this->moveUid);
289
290 // Headerline: Icon, record title:
291 $hline = t3lib_iconWorks::getSpriteIconForRecord($this->table, $elRow, array('id' => "c-recIcon", 'title' => htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($elRow,$this->table))));
292 $hline.= t3lib_BEfunc::getRecordTitle($this->table,$elRow,TRUE);
293
294 // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
295 $onClick = 'window.location.href=\''.t3lib_div::linkThisScript(array('makeCopy'=>!$this->makeCopy)).'\';';
296 $hline.= '<br /><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">'.
297 $GLOBALS['LANG']->getLL('makeCopy', 1) . '</label>';
298
299 // Add the header-content to the module content:
300 $this->content.=$this->doc->section($GLOBALS['LANG']->getLL('moveElement') . ':', $hline, 0, 1);
301 $this->content.=$this->doc->spacer(20);
302
303 // Reset variable to pick up the module content in:
304 $code='';
305
306 // IF the table is "pages":
307 if ((string)$this->table=='pages') {
308 // Get page record (if accessible):
309 $pageinfo = t3lib_BEfunc::readPageAccess($this->page_id,$this->perms_clause);
310 if (is_array($pageinfo) && $GLOBALS['BE_USER']->isInWebMount($pageinfo['pid'],$this->perms_clause)) {
311
312 // Initialize the position map:
313 $posMap = t3lib_div::makeInstance('ext_posMap_pages');
314 $posMap->moveOrCopy = $this->makeCopy?'copy':'move';
315
316 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
317 if ($pageinfo['pid']) {
318 $pidPageInfo = t3lib_BEfunc::readPageAccess($pageinfo['pid'],$this->perms_clause);
319 if (is_array($pidPageInfo)) {
320 if ($GLOBALS['BE_USER']->isInWebMount($pidPageInfo['pid'],$this->perms_clause)) {
321 $code.= '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('uid'=>intval($pageinfo['pid']),'moveUid'=>$this->moveUid))).'">'.
322 t3lib_iconWorks::getSpriteIcon('actions-view-go-up') .
323 t3lib_BEfunc::getRecordTitle('pages',$pidPageInfo,TRUE).
324 '</a><br />';
325 } else {
326 $code.= t3lib_iconWorks::getSpriteIconForRecord('pages', $pidPageInfo) .
327 t3lib_BEfunc::getRecordTitle('pages',$pidPageInfo,TRUE).
328 '<br />';
329 }
330 }
331 }
332
333 // Create the position tree:
334 $code.= $posMap->positionTree($this->page_id,$pageinfo,$this->perms_clause,$this->R_URI);
335 }
336 }
337
338 // IF the table is "tt_content":
339 if ((string)$this->table=='tt_content') {
340
341 // First, get the record:
342 $tt_content_rec = t3lib_BEfunc::getRecord('tt_content',$this->moveUid);
343
344 // ?
345 if (!$this->input_moveUid) $this->page_id = $tt_content_rec['pid'];
346
347 // Checking if the parent page is readable:
348 $pageinfo = t3lib_BEfunc::readPageAccess($this->page_id,$this->perms_clause);
349 if (is_array($pageinfo) && $GLOBALS['BE_USER']->isInWebMount($pageinfo['pid'],$this->perms_clause)) {
350
351 // Initialize the position map:
352 $posMap = t3lib_div::makeInstance('ext_posMap_tt_content');
353 $posMap->moveOrCopy = $this->makeCopy?'copy':'move';
354 $posMap->cur_sys_language = $this->sys_language;
355
356 // Headerline for the parent page: Icon, record title:
357 $hline = t3lib_iconWorks::getSpriteIconForRecord('pages', $pageinfo, array('title' => htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($pageinfo, 'pages'))));
358 $hline .= t3lib_BEfunc::getRecordTitle('pages', $pageinfo, TRUE);
359
360 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
361 $modTSconfig_SHARED = t3lib_BEfunc::getModTSconfig($this->page_id,'mod.SHARED'); // SHARED page-TSconfig settings.
362 $colPosArray = t3lib_div::callUserFunction('EXT:cms/classes/class.tx_cms_backendlayout.php:tx_cms_BackendLayout->getColPosListItemsParsed', $this->page_id, $this);
363 foreach ($colPosArray as $colPos) {
364 $colPosList .= $colPosList != '' ? ',' . $colPos[1] : $colPos[1];
365 }
366 $colPosList = implode(',', array_unique(t3lib_div::intExplode(',', $colPosList))); // Removing duplicates, if any
367
368 // Adding parent page-header and the content element columns from position-map:
369 $code = $hline . '<br />';
370 $code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
371
372 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
373 $code .= '<br />';
374 $code .= '<br />';
375 if ($pageinfo['pid']) {
376 $pidPageInfo = t3lib_BEfunc::readPageAccess($pageinfo['pid'], $this->perms_clause);
377 if (is_array($pidPageInfo)) {
378 if ($GLOBALS['BE_USER']->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
379 $code .= '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
380 'uid' => intval($pageinfo['pid']),
381 'moveUid' => $this->moveUid)
382 )) . '">'
383 . t3lib_iconWorks::getSpriteIcon('actions-view-go-up')
384 . t3lib_BEfunc::getRecordTitle('pages', $pidPageInfo, TRUE)
385 . '</a><br />';
386 } else {
387 $code.= t3lib_iconWorks::getSpriteIconForRecord('pages', $pidPageInfo)
388 . t3lib_BEfunc::getRecordTitle('pages', $pidPageInfo, TRUE)
389 . '<br />';
390 }
391 }
392 }
393
394 // Create the position tree (for pages):
395 $code.= $posMap->positionTree($this->page_id, $pageinfo, $this->perms_clause, $this->R_URI);
396 }
397 }
398
399 // Add the $code content as a new section to the module:
400 $this->content.=$this->doc->section($GLOBALS['LANG']->getLL('selectPositionOfElement') . ':', $code, 0, 1);
401 }
402
403 // Setting up the buttons and markers for docheader
404 $docHeaderButtons = $this->getButtons();
405 $markers['CSH'] = $docHeaderButtons['csh'];
406 $markers['CONTENT'] = $this->content;
407
408 // Build the <body> for the module
409 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('movingElement'));
410 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
411 $this->content.= $this->doc->endPage();
412 $this->content = $this->doc->insertStylesAndJS($this->content);
413 }
414
415 /**
416 * Print out the accumulated content:
417 *
418 * @return void
419 */
420 function printContent() {
421 echo $this->content;
422 }
423
424 /**
425 * Create the panel of buttons for submitting the form or otherwise perform operations.
426 *
427 * @return array all available buttons as an assoc. array
428 */
429 protected function getButtons() {
430 $buttons = array(
431 'csh' => '',
432 'back' => ''
433 );
434
435 if ($this->page_id) {
436 if ((string)$this->table == 'pages') {
437 // CSH
438 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'move_el_pages', $GLOBALS['BACK_PATH'], '', TRUE);
439 } elseif((string)$this->table == 'tt_content') {
440 // CSH
441 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'move_el_cs', $GLOBALS['BACK_PATH'], '', TRUE);
442 }
443
444 if ($this->R_URI) {
445 // Back
446 $buttons['back'] ='<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->getLL('goBack', TRUE) .'">' .
447 t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
448 '</a>';
449 }
450 }
451
452 return $buttons;
453 }
454 }
455
456
457 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/move_el.php'])) {
458 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/move_el.php']);
459 }
460
461
462
463 // Make instance:
464 $SOBE = t3lib_div::makeInstance('SC_move_el');
465 $SOBE->init();
466 $SOBE->main();
467 $SOBE->printContent();
468
469 ?>