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