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