b7dfd18057a72394df938b8d9a2a0f975ddb8cf4
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / app / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (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 * Import / Export module
29 *
30 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
31 */
32 /**
33 * [CLASS/FUNCTION INDEX of SCRIPT]
34 *
35 *
36 *
37 * 136: class localPageTree extends t3lib_browseTree
38 * 143: function localPageTree()
39 * 154: function wrapTitle($title,$v)
40 * 167: function PM_ATagWrap($icon,$cmd,$bMark='')
41 * 178: function wrapIcon($icon,$row)
42 * 187: function permsC()
43 * 197: function ext_tree($pid)
44 *
45 *
46 * 278: class SC_mod_tools_log_index extends t3lib_SCbase
47 * 287: function main()
48 * 339: function printContent()
49 *
50 * SECTION: EXPORT FUNCTIONS
51 * 367: function exportData($inData)
52 * 641: function addRecordsForPid($k, $tables, $maxNumber)
53 * 667: function exec_listQueryPid($table,$pid,$limit)
54 * 695: function makeConfigurationForm($inData, &$row)
55 * 859: function makeAdvancedOptionsForm($inData, &$row)
56 * 906: function makeSaveForm($inData, &$row)
57 *
58 * SECTION: IMPORT FUNCTIONS
59 * 1036: function importData($inData)
60 *
61 * SECTION: Preset functions
62 * 1314: function processPresets(&$inData)
63 * 1411: function getPreset($uid)
64 *
65 * SECTION: Helper functions
66 * 1437: function userTempFolder()
67 * 1453: function userSaveFolder()
68 * 1477: function checkUploadOfThumbnail(&$inData)
69 * 1512: function renderSelectBox($prefix,$value,$optValues)
70 * 1535: function tableSelector($prefix,$value,$excludeList='')
71 * 1570: function extensionSelector($prefix,$value)
72 *
73 * TOTAL FUNCTIONS: 23
74 * (This index is automatically created/updated by the extension "extdeveval")
75 *
76 */
77 /**
78 * IMPORTING DATA:
79 *
80 * Incoming array has syntax:
81 * GETvar 'id' = import page id (must be readable)
82 *
83 * file = (pointing to filename relative to PATH_site)
84 *
85 *
86 *
87 * [all relation fields are clear, but not files]
88 * - page-tree is written first
89 * - then remaining pages (to the root of import)
90 * - then all other records are written either to related included pages or if not found to import-root (should be a sysFolder in most cases)
91 * - then all internal relations are set and non-existing relations removed, relations to static tables preserved.
92 *
93 * EXPORTING DATA:
94 *
95 * Incoming array has syntax:
96 *
97 * file[] = file
98 * dir[] = dir
99 * list[] = table:pid
100 * record[] = table:uid
101 *
102 * pagetree[id] = (single id)
103 * pagetree[levels]=1,2,3, -1 = currently unpacked tree, -2 = only tables on page
104 * pagetree[tables][]=table/_ALL
105 *
106 * external_ref[tables][]=table/_ALL
107 */
108
109
110 unset($MCONF);
111 require ('conf.php');
112 require ($BACK_PATH.'init.php');
113 require ($BACK_PATH.'template.php');
114 $LANG->includeLLFile('EXT:impexp/app/locallang.php');
115 require_once (PATH_t3lib.'class.t3lib_scbase.php');
116 require_once (t3lib_extMgm::extPath('impexp').'class.tx_impexp.php');
117 require_once (PATH_t3lib.'class.t3lib_browsetree.php');
118 require_once (PATH_t3lib.'class.t3lib_pagetree.php');
119
120 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
121 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
122
123 t3lib_extMgm::isLoaded('impexp',1);
124
125
126
127
128
129 /**
130 * Extension of the page tree class. Used to get the tree of pages to export.
131 *
132 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
133 * @package TYPO3
134 * @subpackage tx_impexp
135 */
136 class localPageTree extends t3lib_browseTree {
137
138 /**
139 * Initialization
140 *
141 * @return void
142 */
143 function localPageTree() {
144 $this->init();
145 }
146
147 /**
148 * Wrapping title from page tree.
149 *
150 * @param string Title to wrap
151 * @param mixed (See parent class)
152 * @return string Wrapped title
153 */
154 function wrapTitle($title,$v) {
155 $title = (!strcmp(trim($title),'')) ? '<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>' : htmlspecialchars($title);
156 return $title;
157 }
158
159 /**
160 * Wrapping Plus/Minus icon
161 *
162 * @param string Icon HTML
163 * @param mixed (See parent class)
164 * @param mixed (See parent class)
165 * @return string Icon HTML
166 */
167 function PM_ATagWrap($icon,$cmd,$bMark='') {
168 return $icon;
169 }
170
171 /**
172 * Wrapping Icon
173 *
174 * @param string Icon HTML
175 * @param array Record row (page)
176 * @return string Icon HTML
177 */
178 function wrapIcon($icon,$row) {
179 return $icon;
180 }
181
182 /**
183 * Select permissions
184 *
185 * @return string SQL where clause
186 */
187 function permsC() {
188 return $this->BE_USER->getPagePermsClause(1);
189 }
190
191 /**
192 * Tree rendering
193 *
194 * @param integer PID value
195 * @return array Array of tree elements
196 */
197 function ext_tree($pid) {
198
199 // Initialize:
200 $this->init(' AND '.$this->permsC());
201
202 // Get stored tree structure:
203 $this->stored = unserialize($this->BE_USER->uc['browseTrees']['browsePages']);
204
205 // PM action:
206 $PM = t3lib_div::intExplode('_',t3lib_div::_GP('PM'));
207
208 // traverse mounts:
209 $titleLen = intval($this->BE_USER->uc['titleLen']);
210 $treeArr = array();
211
212 $idx = 0;
213
214 // Set first:
215 $this->bank = $idx;
216 $isOpen = $this->stored[$idx][$pid] || $this->expandFirst;
217
218 $curIds = $this->ids; // save ids
219 $this->reset();
220 $this->ids = $curIds;
221
222 // Set PM icon:
223 $cmd = $this->bank.'_'.($isOpen?'0_':'1_').$pid;
224 $icon = '<img src="'.$this->backPath.'t3lib/gfx/ol/'.($isOpen?'minus':'plus').'only.gif" width="18" height="16" align="top" border="0" alt="" />';
225 $firstHtml = $this->PM_ATagWrap($icon,$cmd);
226
227 if ($pid>0) {
228 $rootRec = t3lib_befunc::getRecord('pages',$pid);
229 $firstHtml.= $this->wrapIcon('<img src="'.$this->backPath.t3lib_iconWorks::getIcon('pages',$rootRec).'" width="18" height="16" align="top" alt="" />',$rootRec);
230 } else {
231 $rootRec = array(
232 'title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
233 'uid' => 0
234 );
235 $firstHtml.= $this->wrapIcon('<img src="'.$this->backPath.'gfx/i/_icon_website.gif" width="18" height="16" align="top" alt="" />',$rootRec);
236 }
237 $this->tree[] = array('HTML'=>$firstHtml, 'row'=>$rootRec);
238 if ($isOpen) {
239 // Set depth:
240 $depthD = '<img src="'.$this->backPath.'t3lib/gfx/ol/blank.gif" width="18" height="16" align="top" alt="" />';
241 if ($this->addSelfId) $this->ids[] = $pid;
242 $this->getTree($pid,999,$depthD);
243
244 $idH = array();
245 $idH[$pid]['uid'] = $pid;
246 if (count($this->buffer_idH)) $idH[$pid]['subrow'] = $this->buffer_idH;
247 $this->buffer_idH = $idH;
248
249 }
250
251 // Add tree:
252 $treeArr = array_merge($treeArr,$this->tree);
253
254 return $treeArr;
255 }
256 }
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271 /**
272 * Main script class for the Import / Export facility
273 *
274 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
275 * @package TYPO3
276 * @subpackage tx_impexp
277 */
278 class SC_mod_tools_log_index extends t3lib_SCbase {
279
280 var $pageinfo; // array containing the current page.
281
282 /**
283 * Main module function
284 *
285 * @return void
286 */
287 function main() {
288 global $BE_USER,$LANG,$BACK_PATH;
289
290 // Start document template object:
291 $this->doc = t3lib_div::makeInstance('mediumDoc');
292 $this->doc->backPath = $BACK_PATH;
293 $this->doc->docType = 'xhtml_trans';
294
295 // JavaScript
296 $this->doc->JScode = $this->doc->wrapScriptTags('
297 script_ended = 0;
298 function jumpToUrl(URL) { //
299 document.location = URL;
300 }
301 ');
302
303 // Set up JS for dynamic tab menu
304 $this->doc->JScode .= $this->doc->getDynTabMenuJScode();
305
306 $this->doc->postCode = $this->doc->wrapScriptTags('
307 script_ended = 1;
308 if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
309 ');
310 $this->doc->form = '<form action="index.php" method="post" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'"><input type="hidden" name="id" value="'.$this->id.'" />';
311
312 $this->content.= $this->doc->startPage($LANG->getLL('title'));
313 $this->content.= $this->doc->header($LANG->getLL('title'));
314 $this->content.= $this->doc->spacer(5);
315
316 // Input data grabbed:
317 $inData = t3lib_div::_GP('tx_impexp');
318
319 $this->checkUpload();
320
321 switch((string)$inData['action']) {
322 case 'export':
323
324 // Finally: If upload went well, set the new file as the thumbnail in the $inData array:
325 if (is_object($this->fileProcessor) && $this->fileProcessor->internalUploadMap[1]) {
326 $inData['meta']['thumbnail'] = md5($this->fileProcessor->internalUploadMap[1]);
327 }
328
329 // Call export interface
330 $this->exportData($inData);
331 break;
332 case 'import':
333
334 // Call import interface:
335 $this->importData($inData);
336 break;
337 }
338
339 if ($BE_USER->mayMakeShortcut()) {
340 $this->content.=$this->doc->spacer(20).$this->doc->section('',$this->doc->makeShortcutIcon('tx_impexp','',$this->MCONF['name']));
341 }
342 }
343
344 /**
345 * Print the content
346 *
347 * @return void
348 */
349 function printContent() {
350
351 $this->content.= $this->doc->spacer(20);
352 $this->content.= $this->doc->endPage();
353 echo $this->content;
354 }
355
356
357
358
359
360
361
362
363
364
365 /**************************
366 *
367 * EXPORT FUNCTIONS
368 *
369 **************************/
370
371 /**
372 * Export part of module
373 *
374 * @param array Content of POST VAR tx_impexp[]..
375 * @return void Setting content in $this->content
376 */
377 function exportData($inData) {
378 global $TCA, $LANG;
379
380 // BUILDING EXPORT DATA:
381
382 // Processing of InData array values:
383 $inData['pagetree']['maxNumber'] = t3lib_div::intInRange($inData['pagetree']['maxNumber'],1,10000,100);
384 $inData['listCfg']['maxNumber'] = t3lib_div::intInRange($inData['listCfg']['maxNumber'],1,10000,100);
385 $inData['maxFileSize'] = t3lib_div::intInRange($inData['maxFileSize'],1,10000,1000);
386 $inData['filename'] = trim(ereg_replace('[^[:alnum:]./_-]*','',ereg_replace('\.(t3d|xml)$','',$inData['filename'])));
387 if (strlen($inData['filename'])) {
388 $inData['filename'].= $inData['filetype']=='xml' ? '.xml' : '.t3d';
389 }
390
391 // Set exclude fields in export object:
392 if (!is_array($inData['exclude'])) {
393 $inData['exclude'] = array();
394 }
395
396
397 // Saving/Loading/Deleting presets:
398 $this->processPresets($inData);
399
400 // Create export object and configure it:
401 $this->export = t3lib_div::makeInstance('tx_impexp');
402 $this->export->init(0,'export');
403 $this->export->setCharset($LANG->charSet);
404
405 $this->export->maxFileSize = $inData['maxFileSize']*1024;
406 $this->export->excludeMap = (array)$inData['exclude'];
407 $this->export->softrefCfg = (array)$inData['softrefCfg'];
408 $this->export->extensionDependencies = (array)$inData['extension_dep'];
409 $this->export->showStaticRelations = $inData['showStaticRelations'];
410
411 $this->export->includeHTMLfileResources = $inData['includeHTMLfileResources'];
412 #debug($inData);
413 // Static tables:
414 if (is_array($inData['external_static']['tables'])) {
415 $this->export->relStaticTables = $inData['external_static']['tables'];
416 }
417
418 // Configure which tables external relations are included for:
419 if (is_array($inData['external_ref']['tables'])) {
420 $this->export->relOnlyTables = $inData['external_ref']['tables'];
421 }
422 $this->export->setHeaderBasics();
423
424 // Meta data setting:
425 $this->export->setMetaData(
426 $inData['meta']['title'],
427 $inData['meta']['description'],
428 $inData['meta']['notes'],
429 $GLOBALS['BE_USER']->user['username'],
430 $GLOBALS['BE_USER']->user['realName'],
431 $GLOBALS['BE_USER']->user['email']
432 );
433 if ($inData['meta']['thumbnail']) {
434 $tempDir = $this->userTempFolder();
435 if ($tempDir) {
436 $thumbnails = t3lib_div::getFilesInDir($tempDir,'png,gif,jpg',1);
437 $theThumb = $thumbnails[$inData['meta']['thumbnail']];
438 if ($theThumb) {
439 $this->export->addThumbnail($theThumb);
440 }
441 }
442 }
443
444
445 // Configure which records to export
446 if (is_array($inData['record'])) {
447 foreach($inData['record'] as $ref) {
448 $rParts = explode(':',$ref);
449 $this->export->export_addRecord($rParts[0],t3lib_BEfunc::getRecord($rParts[0],$rParts[1]));
450 }
451 }
452
453 // Configure which tables to export
454 if (is_array($inData['list'])) {
455 foreach($inData['list'] as $ref) {
456 $rParts = explode(':',$ref);
457 if ($GLOBALS['BE_USER']->check('tables_select',$rParts[0])) {
458 $res = $this->exec_listQueryPid($rParts[0],$rParts[1],t3lib_div::intInRange($inData['listCfg']['maxNumber'],1));
459 while($subTrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
460 $this->export->export_addRecord($rParts[0],$subTrow);
461 }
462 }
463 }
464 }
465
466 // Pagetree
467 if (isset($inData['pagetree']['id'])) {
468 if ($inData['pagetree']['levels']==-1) { // Based on click-expandable tree
469 $pagetree = t3lib_div::makeInstance('localPageTree');
470 $tree = $pagetree->ext_tree($inData['pagetree']['id']);
471 $this->treeHTML = $pagetree->printTree($tree);
472
473 $idH = $pagetree->buffer_idH;
474 # debug($pagetree->buffer_idH);
475 } elseif ($inData['pagetree']['levels']==-2) { // Only tables on page
476 $this->addRecordsForPid($inData['pagetree']['id'],$inData['pagetree']['tables'],$inData['pagetree']['maxNumber']);
477 } else { // Based on depth
478 // Drawing tree:
479 // If the ID is zero, export root
480 if (!$inData['pagetree']['id'] && $GLOBALS['BE_USER']->isAdmin()) {
481 $sPage = array(
482 'uid' => 0,
483 'title' => 'ROOT'
484 );
485 } else {
486 $sPage = t3lib_BEfunc::getRecord('pages',$inData['pagetree']['id'],'*',' AND '.$this->perms_clause);
487 }
488 if (is_array($sPage)) {
489 $pid = $inData['pagetree']['id'];
490 $tree = t3lib_div::makeInstance('t3lib_pageTree');
491 $tree->init('AND '.$this->perms_clause);
492
493 $HTML = '<img src="'.$GLOBALS['BACK_PATH'].t3lib_iconWorks::getIcon('pages',$sPage).'" width="18" height="16" align="top" alt="" />';
494 $tree->tree[] = Array('row'=>$sPage,'HTML'=>$HTML);
495 $tree->buffer_idH = array();
496 if ($inData['pagetree']['levels']>0) {
497 $tree->getTree($pid,$inData['pagetree']['levels'],'');
498 }
499
500 $idH = array();
501 $idH[$pid]['uid'] = $pid;
502 if (count($tree->buffer_idH)) {
503 $idH[$pid]['subrow'] = $tree->buffer_idH;
504 }
505
506
507 $pagetree = t3lib_div::makeInstance('localPageTree');
508 $this->treeHTML = $pagetree->printTree($tree->tree);
509
510 #debug($idH);
511 }
512 }
513 // In any case we should have a multi-level array, $idH, with the page structure here (and the HTML-code loaded into memory for nice display...)
514 if (is_array($idH)) {
515 $flatList = $this->export->setPageTree($idH); // Sets the pagetree and gets a 1-dim array in return with the pages (in correct submission order BTW...)
516 reset($flatList);
517 while(list($k)=each($flatList)) {
518 $this->export->export_addRecord('pages',t3lib_BEfunc::getRecord('pages',$k));
519 $this->addRecordsForPid($k,$inData['pagetree']['tables'],$inData['pagetree']['maxNumber']);
520 }
521 }
522 }
523
524 // After adding ALL records we set relations:
525 # debug($this->export->relOnlyTables);
526 # if (count($this->export->relOnlyTables)) {
527 for($a=0;$a<10;$a++) {
528 $addR = $this->export->export_addDBRelations($a);
529 if (!count($addR)) break;
530 }
531 # }
532
533 // Finally files are added:
534 $this->export->export_addFilesFromRelations(); // MUST be after the DBrelations are set so that files from ALL added records are included!
535 #debug($this->export->dat['header']);
536 // If the download button is clicked, return file
537 if ($inData['download_export'] || $inData['save_export']) {
538 switch((string)$inData['filetype']) {
539 case 'xml':
540 $out = $this->export->compileMemoryToFileContent('xml');
541 $fExt = '.xml';
542 break;
543 case 't3d':
544 $this->export->dontCompress = 1;
545 default:
546 $out = $this->export->compileMemoryToFileContent();
547 $fExt = ($this->export->doOutputCompress()?'-z':'').'.t3d';
548 break;
549 }
550
551 // Filename:
552 $dlFile = $inData['filename'] ? $inData['filename'] : 'T3D_'.substr(ereg_replace('[^[:alnum:]_]','-',$inData['download_export_name']),0,20).'_'.date('d-m-H-i-s').$fExt;
553
554 // Export for download:
555 if ($inData['download_export']) {
556 $mimeType = 'application/octet-stream';
557 Header('Content-Type: '.$mimeType);
558 Header('Content-Disposition: attachment; filename='.basename($dlFile));
559 echo $out;
560 exit;
561 }
562
563 // Export by saving:
564 if ($inData['save_export']) {
565 $savePath = $this->userSaveFolder();
566 $fullName = $savePath.$dlFile;
567
568 if (t3lib_div::isAllowedAbsPath($savePath) && @is_dir(dirname($fullName)) && t3lib_div::isAllowedAbsPath($fullName)) {
569 t3lib_div::writeFile($fullName, $out);
570 $this->content.= $this->doc->section('SAVED FILE','Saved in "'.substr($savePath.$dlFile,strlen(PATH_site)).'", bytes '.t3lib_div::formatSize(strlen($out)),0,1);
571 } else {
572 $this->content.= $this->doc->section('Problems saving file','Bad path: "'.$fullName.'"',0,1,2);
573 }
574 }
575 }
576
577
578 // OUTPUT to BROWSER:
579 // Now, if we didn't make download file, show configuration form based on export:
580 $menuItems = array();
581
582 // Export configuration
583 $row = array();
584 $this->makeConfigurationForm($inData, $row);
585 $menuItems[] = array(
586 'label' => $LANG->getLL('tableselec_configuration','1'),
587 'content' => '
588 <table border="0" cellpadding="1" cellspacing="1">
589 '.implode('
590 ',$row).'
591 </table>
592 '
593 );
594
595 // File options
596 $row = array();
597 $this->makeSaveForm($inData, $row);
598 $menuItems[] = array(
599 'label' => 'File & Preset',
600 'content' => '
601 <table border="0" cellpadding="1" cellspacing="1">
602 '.implode('
603 ',$row).'
604 </table>
605 '
606 );
607
608 // File options
609 $row = array();
610 $this->makeAdvancedOptionsForm($inData, $row);
611 $menuItems[] = array(
612 'label' => 'Advanced Options',
613 'content' => '
614 <table border="0" cellpadding="1" cellspacing="1">
615 '.implode('
616 ',$row).'
617 </table>
618 '
619 );
620
621 // Generate overview:
622 $overViewContent = $this->export->displayContentOverview();
623
624 // Print errors that might be:
625 $errors = $this->export->printErrorLog();
626 $menuItems[] = array(
627 'label' => 'Messages',
628 'content' => $errors,
629 'stateIcon' => $errors ? 2 : 0
630 );
631
632 // Add hidden fields and create tabs:
633 $content = $this->doc->getDynTabMenu($menuItems,'tx_impexp_export',-1);
634 $content.= '<input type="hidden" name="tx_impexp[action]" value="export" />';
635 $this->content.= $this->doc->section('',$content,0,1);
636
637 // Output Overview:
638 $this->content.= $this->doc->section('Structure to be exported:',$overViewContent,0,1);
639
640 }
641
642 /**
643 * Adds records to the export object for a specific page id.
644 *
645 * @param integer Page id for which to select records to add
646 * @param array Array of table names to select from
647 * @param integer Max amount of records to select
648 * @return void
649 */
650 function addRecordsForPid($k, $tables, $maxNumber) {
651 global $TCA;
652
653 if (is_array($tables)) {
654 reset($TCA);
655 while(list($table)=each($TCA)) {
656 if ($table!='pages' && (in_array($table,$tables) || in_array('_ALL',$tables))) {
657 if ($GLOBALS['BE_USER']->check('tables_select',$table) && !$TCA[$table]['ctrl']['is_static']) {
658 $res = $this->exec_listQueryPid($table,$k,t3lib_div::intInRange($maxNumber,1));
659 while($subTrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
660 $this->export->export_addRecord($table,$subTrow);
661 }
662 }
663 }
664 }
665 }
666 }
667
668 /**
669 * Selects records from table / pid
670 *
671 * @param string Table to select from
672 * @param integer Page ID to select from
673 * @param integer Max number of records to select
674 * @return pointer SQL resource pointer
675 */
676 function exec_listQueryPid($table,$pid,$limit) {
677 global $TCA;
678 $orderBy = $TCA[$table]['ctrl']['sortby'] ? 'ORDER BY '.$TCA[$table]['ctrl']['sortby'] : $TCA[$table]['ctrl']['default_sortby'];
679 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
680 '*',
681 $table,
682 'pid='.intval($pid).
683 t3lib_BEfunc::deleteClause($table),
684 '',
685 $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
686 $limit
687 );
688
689 // Warning about hitting limit:
690 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) == $limit) {
691 $this->content.= $this->doc->section('Max number limit!','An SQL query returned exactly the amount of records specified by the limit value ('.$limit.') - that could indicate an incomplete selection of records! Make sure this is on purpose.',0,1, 2);
692 }
693
694 return $res;
695 }
696
697 /**
698 * Create configuration form
699 *
700 * @param array Form configurat data
701 * @param array Table row accumulation variable. This is filled with table rows.
702 * @return void Sets content in $this->content
703 */
704 function makeConfigurationForm($inData, &$row) {
705
706 $nameSuggestion = '';
707
708 // Page tree export options:
709 if (isset($inData['pagetree']['id'])) {
710
711 $nameSuggestion.= 'tree_PID'.$inData['pagetree']['id'].'_L'.$inData['pagetree']['levels'];
712
713 $row[] = '
714 <tr class="tableheader bgColor5">
715 <td colspan="2">Export pagetree configuration:</td>
716 </tr>';
717
718 $row[] = '
719 <tr class="bgColor4">
720 <td><strong>Page ID:</strong></td>
721 <td>'.htmlspecialchars($inData['pagetree']['id']).
722 '<input type="hidden" value="'.htmlspecialchars($inData['pagetree']['id']).'" name="tx_impexp[pagetree][id]" /></td>
723 </tr>';
724
725 $row[] = '
726 <tr class="bgColor4">
727 <td><strong>Tree:</strong></td>
728 <td>'.($this->treeHTML ? $this->treeHTML : 'No tree exported - only tables on the page.').'</td>
729 </tr>';
730
731 $opt = array(
732 '-2' => 'Tables on this page',
733 '-1' => 'Expanded tree',
734 '0' => 'Only this page',
735 '1' => '1 level',
736 '2' => '2 levels',
737 '3' => '3 levels',
738 '4' => '4 levels',
739 '999' => 'Infinite'
740 );
741 $row[] = '
742 <tr class="bgColor4">
743 <td><strong>Levels:</strong></td>
744 <td>'.$this->renderSelectBox('tx_impexp[pagetree][levels]',$inData['pagetree']['levels'],$opt).'</td>
745 </tr>';
746
747 $row[] = '
748 <tr class="bgColor4">
749 <td><strong>Include tables:</strong></td>
750 <td>'.$this->tableSelector('tx_impexp[pagetree][tables]',$inData['pagetree']['tables'],'pages').'<br/>
751 Max number of records:<br/>
752 <input type="text" name="tx_impexp[pagetree][maxNumber]" value="'.htmlspecialchars($inData['pagetree']['maxNumber']).'"'.$this->doc->formWidth(10).' /><br/>
753 </td>
754 </tr>';
755 }
756
757 // Single record export:
758 if (is_array($inData['record'])) {
759 $row[] = '
760 <tr class="tableheader bgColor5">
761 <td colspan="2">Export single record:</td>
762 </tr>';
763 foreach($inData['record'] as $ref) {
764 $rParts = explode(':', $ref);
765 $tName = $rParts[0];
766 $rUid = $rParts[1];
767 $nameSuggestion.= $tName.'_'.$rUid;
768 $rec = t3lib_BEfunc::getRecord($tName,$rUid);
769
770 $row[] = '
771 <tr class="bgColor4">
772 <td><strong>Record:</strong></td>
773 <td>'.t3lib_iconworks::getIconImage($tName,$rec,$GLOBALS['BACK_PATH'],' align="top"').
774 t3lib_BEfunc::getRecordTitle($tName,$rec,1).
775 '<input type="hidden" name="tx_impexp[record][]" value="'.htmlspecialchars($tName.':'.$rUid).'" /></td>
776 </tr>';
777 }
778 }
779
780 // Single tables/pids:
781 if (is_array($inData['list'])) {
782 $row[] = '
783 <tr class="tableheader bgColor5">
784 <td colspan="2">Export tables from pages:</td>
785 </tr>';
786
787 foreach($inData['list'] as $ref) {
788 $rParts = explode(':', $ref);
789 $tName = $rParts[0];
790
791 if ($GLOBALS['BE_USER']->check('tables_select',$tName)) {
792 $rec = t3lib_BEfunc::getRecord('pages', $rParts[1]);
793 $row[] = '
794 <tr class="bgColor4">
795 <td><strong>Table/Pids:</strong></td>
796 <td>Table "'.$tName.'" from '.t3lib_iconworks::getIconImage('pages',$rec,$GLOBALS['BACK_PATH'],' align="top"').
797 t3lib_BEfunc::getRecordTitle('pages',$rec,1).
798 '<input type="hidden" name="tx_impexp[list][]" value="'.htmlspecialchars($ref).'" /></td>
799 </tr>';
800 }
801 }
802 $row[] = '
803 <tr class="bgColor4">
804 <td>Max number of records:</td>
805 <td>
806 <input type="text" name="tx_impexp[listCfg][maxNumber]" value="'.htmlspecialchars($inData['listCfg']['maxNumber']).'"'.$this->doc->formWidth(10).' /><br/>
807 </td>
808 </tr>';
809 }
810
811
812 $row[] = '
813 <tr class="tableheader bgColor5">
814 <td colspan="2">Relations and Exclusions:</td>
815 </tr>';
816
817 // Add relation selector:
818 $row[] = '
819 <tr class="bgColor4">
820 <td><strong>Include relations to tables:</strong></td>
821 <td>'.$this->tableSelector('tx_impexp[external_ref][tables]',$inData['external_ref']['tables']).'</td>
822 </tr>';
823
824 // Add static relation selector:
825 $row[] = '
826 <tr class="bgColor4">
827 <td><strong>Use static relations for tables:</strong></td>
828 <td>'.$this->tableSelector('tx_impexp[external_static][tables]',$inData['external_static']['tables']).'<br/>
829 Show static relations: <input type="checkbox" name="tx_impexp[showStaticRelations]" value="1"'.($inData['showStaticRelations'] ? ' checked="checked"' : '').' />
830 </td>
831 </tr>';
832
833 // Exclude:
834 $excludeHiddenFields = '';
835 if (is_array($inData['exclude'])) {
836 foreach($inData['exclude'] as $key => $value) {
837 $excludeHiddenFields.= '<input type="hidden" name="tx_impexp[exclude]['.$key.']" value="1" />';
838 }
839 }
840 $row[] = '
841 <tr class="bgColor4">
842 <td><strong>Exclude elements:</strong></td>
843 <td>'.$excludeHiddenFields.'
844 '.(count($inData['exclude']) ? '<em>'.implode(', ',array_keys($inData['exclude'])).'</em><hr/>Clear all exclusions: <input type="checkbox" name="tx_impexp[exclude]" value="1" />' : 'No excluded elements yet. Exclude by setting checkboxes below in the element display.').'
845 </td>
846 </tr>';
847
848
849 // Add buttons:
850 $row[] = '
851 <tr class="bgColor4">
852 <td>&nbsp;</td>
853 <td>
854 <input type="submit" value="Update" />
855 <input type="hidden" name="tx_impexp[download_export_name]" value="'.substr($nameSuggestion,0,30).'" />
856 </td>
857 </tr>';
858
859 }
860
861 /**
862 * Create advanced options form
863 *
864 * @param array Form configurat data
865 * @param array Table row accumulation variable. This is filled with table rows.
866 * @return void Sets content in $this->content
867 */
868 function makeAdvancedOptionsForm($inData, &$row) {
869
870 // Soft references
871 $row[] = '
872 <tr class="tableheader bgColor5">
873 <td colspan="2">Soft References:</td>
874 </tr>';
875 $row[] = '
876 <tr class="bgColor4">
877 <td><strong>Include HTML file resources:</strong></td>
878 <td><input type="checkbox" name="tx_impexp[includeHTMLfileResources]" value="1"'.($inData['includeHTMLfileResources'] ? ' checked="checked"' : '').' /></td>
879 </tr>';
880
881
882 // Extensions
883 $row[] = '
884 <tr class="tableheader bgColor5">
885 <td colspan="2">Extension dependencies:</td>
886 </tr>';
887 $row[] = '
888 <tr class="bgColor4">
889 <td><strong>Select extensions that the exported content depends on:</strong></td>
890 <td>'.$this->extensionSelector('tx_impexp[extension_dep]',$inData['extension_dep']).'</td>
891 </tr>';
892
893
894
895 // Add buttons:
896 $row[] = '
897 <tr class="bgColor4">
898 <td>&nbsp;</td>
899 <td>
900 <input type="submit" value="Update" />
901 <input type="hidden" name="tx_impexp[download_export_name]" value="'.substr($nameSuggestion,0,30).'" />
902 </td>
903 </tr>';
904
905
906 }
907
908 /**
909 * Create configuration form
910 *
911 * @param array Form configurat data
912 * @param array Table row accumulation variable. This is filled with table rows.
913 * @return void Sets content in $this->content
914 */
915 function makeSaveForm($inData, &$row) {
916
917 // Presets:
918 $row[] = '
919 <tr class="tableheader bgColor5">
920 <td colspan="2">Presets:</td>
921 </tr>';
922
923 $opt = array('');
924 $presets = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
925 '*',
926 'tx_impexp_presets',
927 '(public>0 || user_uid='.intval($GLOBALS['BE_USER']->user['uid']).')'.
928 ($inData['pagetree']['id'] ? ' AND item_uid='.intval($inData['pagetree']['id']) : '')
929
930 );
931 if (is_array($presets)) {
932 foreach($presets as $presetCfg) {
933 $opt[$presetCfg['uid']] = $presetCfg['title'].' ['.$presetCfg['uid'].']'.
934 ($presetCfg['public'] ? ' [Public]' : '').
935 ($presetCfg['user_uid']===$GLOBALS['BE_USER']->user['uid'] ? ' [Own]' : '');
936 }
937 }
938
939 $row[] = '
940 <tr class="bgColor4">
941 <td><strong>Presets:</strong></td>
942 <td>
943 Select preset:<br/>
944 '.$this->renderSelectBox('preset[select]','',$opt).'
945 <br/>
946 <input type="submit" value="Load" name="preset[load]" />
947 <input type="submit" value="Save" name="preset[save]" />
948 <input type="submit" value="Delete" name="preset[delete]" />
949 <input type="submit" value="Merge" name="preset[merge]" />
950 <br/>
951 Title of new preset:
952 <input type="text" name="tx_impexp[preset][title]" value="'.htmlspecialchars($inData['preset']['title']).'"'.$this->doc->formWidth(30).' /><br/>
953 Public:
954 <input type="checkbox" name="tx_impexp[preset][public]" value="1"'.($inData['preset']['public'] ? ' checked="checked"' : '').' /><br/>
955 </td>
956 </tr>';
957
958 // Output options:
959 $row[] = '
960 <tr class="tableheader bgColor5">
961 <td colspan="2">Output options:</td>
962 </tr>';
963
964 // Meta data:
965 $tempDir = $this->userTempFolder();
966 if ($tempDir) {
967 $thumbnails = t3lib_div::getFilesInDir($tempDir,'png,gif,jpg');
968 array_unshift($thumbnails,'');
969 } else $thumbnails = FALSE;
970 $row[] = '
971 <tr class="bgColor4">
972 <td><strong>Meta data:</strong></td>
973 <td>
974 Title: <br/>
975 <input type="text" name="tx_impexp[meta][title]" value="'.htmlspecialchars($inData['meta']['title']).'"'.$this->doc->formWidth(30).' /><br/>
976 Description: <br/>
977 <input type="text" name="tx_impexp[meta][description]" value="'.htmlspecialchars($inData['meta']['description']).'"'.$this->doc->formWidth(30).' /><br/>
978 Notes: <br/>
979 <textarea name="tx_impexp[meta][notes]"'.$this->doc->formWidth(30,1).'>'.t3lib_div::formatForTextarea($inData['meta']['notes']).'</textarea><br/>
980 '.(is_array($thumbnails) ? '
981 Thumbnail:<br/>
982 '.$this->renderSelectBox('tx_impexp[meta][thumbnail]',$inData['meta']['thumbnail'],$thumbnails).'<br/>
983 '.($inData['meta']['thumbnail'] ? '<img src="'.$this->doc->backPath.'../'.substr($tempDir,strlen(PATH_site)).$thumbnails[$inData['meta']['thumbnail']].'" vspace="5" style="border: solid black 1px;" alt="" /><br/>' : '').'
984 Upload thumbnail:<br/>
985 <input type="file" name="upload_1" '.$this->doc->formWidth(30).' size="30" /><br/>
986 <input type="hidden" name="file[upload][1][target]" value="'.htmlspecialchars($tempDir).'" />
987 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
988 ' : '').'
989 </td>
990 </tr>';
991
992 // Add file options:
993 $savePath = $this->userSaveFolder();
994 $opt = array();
995 if ($this->export->compress) {
996 $opt['t3d_compressed'] = 'T3D file / compressed';
997 }
998 $opt['t3d'] = 'T3D file';
999 $opt['xml'] = 'XML';
1000 $row[] = '
1001 <tr class="bgColor4">
1002 <td><strong>File format:</strong></td>
1003 <td>'.$this->renderSelectBox('tx_impexp[filetype]',$inData['filetype'],$opt).'<br/>
1004 Max size of files to include (kb):<br/>
1005 <input type="text" name="tx_impexp[maxFileSize]" value="'.htmlspecialchars($inData['maxFileSize']).'"'.$this->doc->formWidth(10).' /><br/>
1006 '.($savePath ? 'Filename (saved in "'.substr($savePath,strlen(PATH_site)).'"):<br/>
1007 <input type="text" name="tx_impexp[filename]" value="'.htmlspecialchars($inData['filename']).'"'.$this->doc->formWidth(30).' /><br/>' : '').'
1008 </td>
1009 </tr>';
1010
1011
1012 // Add buttons:
1013 $row[] = '
1014 <tr class="bgColor4">
1015 <td>&nbsp;</td>
1016 <td><input type="submit" value="Update" /> - <input type="submit" value="Download export" name="tx_impexp[download_export]" />'.
1017 ($savePath ? ' - <input type="submit" value="Save to filename" name="tx_impexp[save_export]" />' : '').'</td>
1018 </tr>';
1019 }
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033 /**************************
1034 *
1035 * IMPORT FUNCTIONS
1036 *
1037 **************************/
1038
1039 /**
1040 * Import part of module
1041 *
1042 * @param array Content of POST VAR tx_impexp[]..
1043 * @return void Setting content in $this->content
1044 */
1045 function importData($inData) {
1046 global $TCA,$LANG,$BE_USER;
1047
1048 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
1049 $access = is_array($this->pageinfo) ? 1 : 0;
1050
1051 if (($this->id && $access) || ($BE_USER->user['admin'] && !$this->id)) {
1052 if ($BE_USER->user['admin'] && !$this->id) {
1053 $this->pageinfo=array('title' => '[root-level]','uid'=>0,'pid'=>0);
1054 }
1055
1056 $headerSection = $this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path').': '.t3lib_div::fixed_lgd_cs($this->pageinfo['_thePath'],-50);
1057 $this->content.= $this->doc->section('',$headerSection);
1058
1059 if ($inData['new_import']) {
1060 unset($inData['import_mode']);
1061 }
1062
1063 $import = t3lib_div::makeInstance('tx_impexp');
1064 $import->init(0,'import');
1065 $import->update = $inData['do_update'];
1066 $import->import_mode = $inData['import_mode'];
1067 $import->enableLogging = $inData['enableLogging'];
1068 $import->global_ignore_pid = $inData['global_ignore_pid'];
1069 $import->showDiff = $inData['showDiff'];
1070 $import->allowPHPScripts = $inData['allowPHPScripts'];
1071 $import->softrefInputValues = $inData['softrefInputValues'];
1072
1073
1074 // OUTPUT creation:
1075 $menuItems = array();
1076
1077
1078 // Make input selector:
1079 $path = 'fileadmin/'; // must have trailing slash.
1080 $filesInDir = t3lib_div::getFilesInDir(PATH_site.$path,'t3d,xml',1,1);
1081 if (is_dir(PATH_site.$path.'export/')) {
1082 $filesInDir = array_merge($filesInDir, t3lib_div::getFilesInDir(PATH_site.$path.'export/','t3d,xml',1,1));
1083 }
1084 $tempFolder = $this->userTempFolder();
1085 if ($tempFolder) {
1086 $temp_filesInDir = t3lib_div::getFilesInDir($tempFolder,'t3d,xml',1,1);
1087 $filesInDir = array_merge($filesInDir, $temp_filesInDir);
1088 }
1089
1090 // Configuration
1091 $row = array();
1092 $opt = array('');
1093 foreach($filesInDir as $file) {
1094 $opt[$file] = substr($file,strlen(PATH_site));
1095 }
1096
1097 $row[] = '<tr class="bgColor5">
1098 <td colspan="2"><strong>Select file to import:</strong></td>
1099 </tr>';
1100
1101 $row[] = '<tr class="bgColor4">
1102 <td><strong>File:</strong></td>
1103 <td>'.
1104 $this->renderSelectBox('tx_impexp[file]',$inData['file'],$opt).'<br />(From path: '.$path.')'.
1105 (!$import->compress ? '<br /><span class="typo3-red">NOTE: No decompressor available for compressed files!</span>':'').
1106 '</td>
1107 </tr>';
1108
1109 $row[] = '<tr class="bgColor5">
1110 <td colspan="2"><strong>Import Options:</strong></td>
1111 </tr>';
1112
1113 $row[] = '<tr class="bgColor4">
1114 <td><strong>Update:</strong></td>
1115 <td>
1116 <input type="checkbox" name="tx_impexp[do_update]" value="1"'.($inData['do_update'] ? ' checked="checked"' : '').' />
1117 Update records<br/>
1118 <em>(This option requires that the structure you import already exists on this server and only needs to be updated with new content!)</em>'.
1119 ($inData['do_update'] ?
1120 ' <hr/>
1121 <input type="checkbox" name="tx_impexp[global_ignore_pid]" value="1"'.($inData['global_ignore_pid'] ? ' checked="checked"' : '').' />
1122 Ignore PID differences globally<br/>
1123 <em>(If you set this option, the position of updated elements will not be updated to match the structure of the input file.)</em>
1124
1125 ' : ''
1126 ).'</td>
1127 </tr>';
1128
1129 $row[] = '<tr class="bgColor4">
1130 <td><strong>Options:</strong></td>
1131 <td>
1132 <input type="checkbox" name="tx_impexp[showDiff]" value="1"'.($inData['showDiff'] ? ' checked="checked"' : '').' />
1133 Show differences in records<br/>
1134 <em>(Green values are from the import file, red values from the current database record and black values are similar in both versions.)</em>
1135 <br/><br/>
1136
1137 '.($GLOBALS['BE_USER']->isAdmin() ? '
1138 <input type="checkbox" name="tx_impexp[allowPHPScripts]" value="1"'.($inData['allowPHPScripts'] ? ' checked="checked"' : '').' />
1139 Allow to write banned file extensions (eg. PHP scripts), if any<br/>' : '').'
1140 </td>
1141 </tr>';
1142
1143 $row[] = '<tr class="bgColor4">
1144 <td><strong>Action:</strong></td>
1145 <td>'.
1146 (!$inData['import_file'] ? '<input type="submit" value="Preview" />'.($inData['file'] ? ' - <input type="submit" value="'.($inData['do_update']?'Update':'Import').'" name="tx_impexp[import_file]" onclick="return confirm(\'Are you sure?\');" />':''):'<input type="submit" name="tx_impexp[new_import]" value="New import" />').'
1147 <input type="hidden" name="tx_impexp[action]" value="import" /></td>
1148 </tr>';
1149
1150 $row[] = '<tr class="bgColor4">
1151 <td><strong>Enable logging:</strong></td>
1152 <td>
1153 <input type="checkbox" name="tx_impexp[enableLogging]" value="1"'.($inData['enableLogging'] ? ' checked="checked"' : '').' />
1154 Write individual DB actions during import to the log<br/>
1155 <em>(This is disabled by default since there may be hundred of entries generated.)</em>
1156 </td>
1157 </tr>';
1158
1159 $menuItems[] = array(
1160 'label' => 'Import',
1161 'content' => '
1162 <table border="0" cellpadding="1" cellspacing="1">
1163 '.implode('
1164 ',$row).'
1165 </table>
1166 '
1167 );
1168
1169 // Upload file:
1170 $tempFolder = $this->userTempFolder();
1171 if ($tempFolder) {
1172 $row = array();
1173
1174 $row[] = '<tr class="bgColor5">
1175 <td colspan="2"><strong>Upload file from local computer:</strong></td>
1176 </tr>';
1177
1178 $row[] = '<tr class="bgColor4">
1179 <td>Browse:</td>
1180 <td>
1181
1182 <input type="file" name="upload_1"'.$this->doc->formWidth(35).' size="40" />
1183 <input type="hidden" name="file[upload][1][target]" value="'.htmlspecialchars($tempFolder).'" />
1184 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
1185
1186 <input type="submit" name="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />
1187 <input type="checkbox" name="overwriteExistingFiles" value="1" checked="checked" /> '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:overwriteExistingFiles',1).'
1188 </td>
1189 </tr>';
1190
1191 $menuItems[] = array(
1192 'label' => 'Upload',
1193 'content' => '
1194 <table border="0" cellpadding="1" cellspacing="1">
1195 '.implode('
1196 ',$row).'
1197 </table>
1198 '
1199 );
1200 }
1201
1202
1203 // Perform import or preview depending:
1204 $overviewContent = '';
1205 $inFile = t3lib_div::getFileAbsFileName($inData['file']);
1206 if ($inFile && @is_file($inFile)) {
1207 $row = array();
1208 if ($import->loadFile($inFile,1)) {
1209
1210 if ($inData['import_file']) {
1211 $import->importData($this->id);
1212 t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
1213 }
1214
1215 $import->display_import_pid_record = $this->pageinfo;
1216 $overviewContent = $import->displayContentOverview();
1217 }
1218
1219 // Meta data output:
1220 $row[] = '<tr class="bgColor5">
1221 <td colspan="2"><strong>Meta data:</strong></td>
1222 </tr>';
1223
1224 $opt = array('');
1225 foreach($filesInDir as $file) {
1226 $opt[$file] = substr($file,strlen(PATH_site));
1227 }
1228
1229 $row[] = '<tr class="bgColor4">
1230 <td><strong>Title:</strong></td>
1231 <td>'.nl2br(htmlspecialchars($import->dat['header']['meta']['title'])).'</td>
1232 </tr>';
1233
1234 $row[] = '<tr class="bgColor4">
1235 <td><strong>Description:</strong></td>
1236 <td>'.nl2br(htmlspecialchars($import->dat['header']['meta']['description'])).'</td>
1237 </tr>';
1238
1239 $row[] = '<tr class="bgColor4">
1240 <td><strong>Notes:</strong></td>
1241 <td>'.nl2br(htmlspecialchars($import->dat['header']['meta']['notes'])).'</td>
1242 </tr>';
1243
1244 $row[] = '<tr class="bgColor4">
1245 <td><strong>Packager:</strong></td>
1246 <td>'.nl2br(htmlspecialchars($import->dat['header']['meta']['packager_name'].' ('.$import->dat['header']['meta']['packager_username'].')')).'<br/>
1247 Email: '.$import->dat['header']['meta']['packager_email'].'</td>
1248 </tr>';
1249
1250 // Thumbnail icon:
1251 if (is_array($import->dat['header']['thumbnail'])) {
1252 $pI = pathinfo($import->dat['header']['thumbnail']['filename']);
1253 if (t3lib_div::inList('gif,jpg,png,jpeg',strtolower($pI['extension']))) {
1254
1255 // Construct filename and write it:
1256 $fileName = PATH_site.
1257 'typo3temp/importthumb.'.$pI['extension'];
1258 t3lib_div::writeFile($fileName, $import->dat['header']['thumbnail']['content']);
1259
1260 // Check that the image really is an image and not a malicious PHP script...
1261 if (getimagesize($fileName)) {
1262 // Create icon tag:
1263 $iconTag = '<img src="'.$this->doc->backPath.'../'.substr($fileName,strlen(PATH_site)).'" '.$import->dat['header']['thumbnail']['imgInfo'][3].' vspace="5" style="border: solid black 1px;" alt="" />';
1264
1265 $row[] = '<tr class="bgColor4">
1266 <td><strong>Icon:</strong></td>
1267 <td>'.$iconTag.'</td>
1268 </tr>';
1269 } else {
1270 t3lib_div::unlink_tempfile($fileName);
1271 }
1272 }
1273 }
1274
1275 $menuItems[] = array(
1276 'label' => 'Meta data',
1277 'content' => '
1278 <table border="0" cellpadding="1" cellspacing="1">
1279 '.implode('
1280 ',$row).'
1281 </table>
1282 '
1283 );
1284 }
1285
1286
1287 // Output tabs:
1288 $content = $this->doc->getDynTabMenu($menuItems,'tx_impexp_import',-1);
1289 $this->content.= $this->doc->section('',$content,0,1);
1290
1291
1292 // Print overview:
1293 if ($overviewContent) {
1294 $this->content.= $this->doc->section($inData['import_file'] ? 'Structure has been imported:' : 'Structure to be imported:', $overviewContent, 0, 1);
1295 }
1296 $errors = $import->printErrorLog();
1297 if ($errors) {
1298 $this->content.= $this->doc->section('Messages:', $errors, 0, 1);
1299 }
1300 }
1301 }
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315 /****************************
1316 *
1317 * Preset functions
1318 *
1319 ****************************/
1320
1321 /**
1322 * Manipulate presets
1323 *
1324 * @param array In data array, passed by reference!
1325 * @return void
1326 */
1327 function processPresets(&$inData) {
1328
1329 $presetData = t3lib_div::_GP('preset');
1330 $err = FALSE;
1331
1332 // Save preset
1333 if (isset($presetData['save'])) {
1334 $preset = $this->getPreset($presetData['select']);
1335 if (is_array($preset)) { // Update existing
1336 if ($GLOBALS['BE_USER']->isAdmin() || $preset['user_uid'] === $GLOBALS['BE_USER']->user['uid']) {
1337 $fields_values = array(
1338 'public' => $inData['preset']['public'],
1339 'title' => $inData['preset']['title'],
1340 'item_uid' => $inData['pagetree']['id'],
1341 'preset_data' => serialize($inData)
1342 );
1343 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_impexp_presets','uid='.intval($preset['uid']),$fields_values);
1344 $msg = 'Preset #'.$preset['uid'].' saved!';
1345 } else {
1346 $msg = 'ERROR: The preset was not saved because you were not the owner of it!';
1347 $err = TRUE;
1348 }
1349 } else { // Insert new:
1350 $fields_values = array(
1351 'user_uid' => $GLOBALS['BE_USER']->user['uid'],
1352 'public' => $inData['preset']['public'],
1353 'title' => $inData['preset']['title'],
1354 'item_uid' => $inData['pagetree']['id'],
1355 'preset_data' => serialize($inData)
1356 );
1357 $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_impexp_presets',$fields_values);
1358 $msg = 'New preset "'.$inData['preset']['title'].'" is created';
1359 }
1360 }
1361
1362 // Delete preset:
1363 if (isset($presetData['delete'])) {
1364 $preset = $this->getPreset($presetData['select']);
1365 if (is_array($preset)) { // Update existing
1366 if ($GLOBALS['BE_USER']->isAdmin() || $preset['user_uid'] === $GLOBALS['BE_USER']->user['uid']) {
1367 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_impexp_presets','uid='.intval($preset['uid']));
1368 $msg = 'Preset #'.$preset['uid'].' deleted!';
1369 } else {
1370 $msg = 'ERROR: You were not the owner of the preset so you could not delete it.';
1371 $err = TRUE;
1372 }
1373 } else {
1374 $msg = 'ERROR: No preset selected for deletion.';
1375 $err = TRUE;
1376 }
1377 }
1378
1379 // Load preset
1380 if (isset($presetData['load']) || isset($presetData['merge'])) {
1381 $preset = $this->getPreset($presetData['select']);
1382 if (is_array($preset)) { // Update existing
1383 $inData_temp = unserialize($preset['preset_data']);
1384 if (is_array($inData_temp)) {
1385 if (isset($presetData['merge'])) {
1386 // Merge records in:
1387 if (is_array($inData_temp['record'])) {
1388 $inData_temp['record'] = array_merge($inData_temp['record'], $inData['record']);
1389 } else $inData_temp['record'] = $inData['record'];
1390 // Merge lists in:
1391 if (is_array($inData_temp['list'])) {
1392 $inData_temp['list'] = array_merge($inData_temp['list'], $inData['list']);
1393 } else $inData_temp['list'] = $inData['list'];
1394 $inData_temp['listCfg'] = $inData['listCfg'];
1395
1396 // Swap:
1397 $inData = $inData_temp;
1398 } else {
1399 $msg = 'Preset #'.$preset['uid'].' loaded!';
1400 $inData = $inData_temp;
1401 }
1402 } else {
1403 $msg = 'ERROR: No configuratio data found in preset record!';
1404 $err = TRUE;
1405 }
1406 } else {
1407 $msg = 'ERROR: No preset selected for loading.';
1408 $err = TRUE;
1409 }
1410 }
1411
1412 // Show message:
1413 if (strlen($msg)) {
1414 $this->content.= $this->doc->section('Presets',$msg,0,1,$err ? 3 : 1);
1415 }
1416 }
1417
1418 /**
1419 * Get single preset record
1420 *
1421 * @param integer Preset record
1422 * @return array Preset record, if any (otherwise false)
1423 */
1424 function getPreset($uid) {
1425 list($preset) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*','tx_impexp_presets','uid='.intval($uid));
1426 return $preset;
1427 }
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439 /****************************
1440 *
1441 * Helper functions
1442 *
1443 ****************************/
1444
1445 /**
1446 * Returns first temporary folder of the user account (from $FILEMOUNTS)
1447 *
1448 * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank.
1449 */
1450 function userTempFolder() {
1451 global $FILEMOUNTS;
1452
1453 foreach($FILEMOUNTS as $filePathInfo) {
1454 $tempFolder = $filePathInfo['path'].'_temp_/';
1455 if (@is_dir($tempFolder)) {
1456 return $tempFolder;
1457 }
1458 }
1459 }
1460
1461 /**
1462 * Returns folder where user can save export files.
1463 *
1464 * @return string Absolute path to folder where export files can be saved.
1465 */
1466 function userSaveFolder() {
1467 global $FILEMOUNTS;
1468
1469 reset($FILEMOUNTS);
1470 $filePathInfo = current($FILEMOUNTS);
1471
1472 if (is_array($filePathInfo)) {
1473 $tempFolder = $filePathInfo['path'].'export/';
1474 if (!@is_dir($tempFolder)) {
1475 $tempFolder = $filePathInfo['path'];
1476 if (!@is_dir($tempFolder)) {
1477 return FALSE;
1478 }
1479 }
1480 return $tempFolder;
1481 }
1482 }
1483
1484 /**
1485 * Check if a file has been uploaded
1486 *
1487 * @return void
1488 */
1489 function checkUpload() {
1490 global $FILEMOUNTS,$TYPO3_CONF_VARS,$BE_USER;
1491
1492 $file = t3lib_div::_GP('file');
1493
1494 // Initializing:
1495 $this->fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
1496 $this->fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
1497 $this->fileProcessor->init_actionPerms($BE_USER->user['fileoper_perms']);
1498 $this->fileProcessor->dontCheckForUnique = t3lib_div::_GP('overwriteExistingFiles') ? 1 : 0;
1499
1500 // Checking referer / executing:
1501 $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
1502 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
1503 if ($httpHost!=$refInfo['host'] && $this->vC!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
1504 $this->fileProcessor->writeLog(0,2,1,'Referer host "%s" and server host "%s" did not match!',array($refInfo['host'],$httpHost));
1505 } else {
1506 $this->fileProcessor->start($file);
1507 $this->fileProcessor->processData();
1508 }
1509 }
1510
1511 /**
1512 * Makes a selector-box from optValues
1513 *
1514 * @param string Form element name
1515 * @param string Current value
1516 * @param array Options to display (key/value pairs)
1517 * @return string HTML select element
1518 */
1519 function renderSelectBox($prefix,$value,$optValues) {
1520 $opt = array();
1521 $isSelFlag = 0;
1522 reset($optValues);
1523 while(list($k,$v) = each($optValues)) {
1524 $sel = (!strcmp($k,$value) ? ' selected="selected"' : '');
1525 if ($sel) $isSelFlag++;
1526 $opt[] = '<option value="'.htmlspecialchars($k).'"'.$sel.'>'.htmlspecialchars($v).'</option>';
1527 }
1528 if (!$isSelFlag && strcmp('',$value)) {
1529 $opt[] = '<option value="'.htmlspecialchars($value).'" selected="selected">'.htmlspecialchars("['".$value."']").'</option>';
1530 }
1531 return '<select name="'.$prefix.'">'.implode('',$opt).'</select>';
1532 }
1533
1534 /**
1535 * Returns a selector-box with TCA tables
1536 *
1537 * @param string Form element name prefix
1538 * @param array The current values selected
1539 * @param string Table names (and the string "_ALL") to exclude. Comma list
1540 * @return string HTML select element
1541 */
1542 function tableSelector($prefix,$value,$excludeList='') {
1543 global $TCA;
1544 reset($TCA);
1545 $optValues = array();
1546
1547 if (!t3lib_div::inList($excludeList,'_ALL')) {
1548 $optValues['_ALL'] = '[ALL tables]';
1549 }
1550
1551 while(list($table) = each($TCA)) {
1552 if ($GLOBALS['BE_USER']->check('tables_select',$table) && !t3lib_div::inList($excludeList,$table)) {
1553 $optValues[$table] = $table;
1554 }
1555 }
1556
1557 // make box:
1558 $opt = array();
1559 $opt[] = '<option value=""></option>';
1560 reset($optValues);
1561 while(list($k,$v)=each($optValues)) {
1562 if (is_array($value)) {
1563 $sel = in_array($k,$value)?' selected="selected"':'';
1564 }
1565 $opt[] = '<option value="'.htmlspecialchars($k).'"'.$sel.'>'.htmlspecialchars($v).'</option>';
1566 }
1567 return '<select name="'.$prefix.'[]" multiple="multiple" size="'.t3lib_div::intInRange(count($opt),5,10).'">'.implode('',$opt).'</select>';
1568 }
1569
1570 /**
1571 * Returns a selector-box with loaded extension keys
1572 *
1573 * @param string Form element name prefix
1574 * @param array The current values selected
1575 * @return string HTML select element
1576 */
1577 function extensionSelector($prefix,$value) {
1578 global $TYPO3_LOADED_EXT;
1579
1580 $extTrav = array_keys($TYPO3_LOADED_EXT);
1581
1582 // make box:
1583 $opt = array();
1584 $opt[] = '<option value=""></option>';
1585 foreach($extTrav as $v) {
1586 if (is_array($value)) {
1587 $sel = in_array($v,$value)?' selected="selected"':'';
1588 }
1589 $opt[] = '<option value="'.htmlspecialchars($v).'"'.$sel.'>'.htmlspecialchars($v).'</option>';
1590 }
1591 return '<select name="'.$prefix.'[]" multiple="multiple" size="'.t3lib_div::intInRange(count($opt),5,10).'">'.implode('',$opt).'</select>';
1592 }
1593 }
1594
1595 // Include extension?
1596 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/impexp/app/index.php']) {
1597 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/impexp/app/index.php']);
1598 }
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611 // Make instance:
1612 $SOBE = t3lib_div::makeInstance('SC_mod_tools_log_index');
1613 $SOBE->init();
1614 $SOBE->main();
1615 $SOBE->printContent();
1616 ?>