PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/move_el.php

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