📄 class.tx_impexp.php
字号:
// Remove the absolute reference to the file so it doesn't expose absolute paths from source server: unset($this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['file'][$key][$subKey]['ID_absFile']); } } } // DB oriented soft references in flex form fields: if (is_array($vR['flexFormRels']['softrefs'])) { foreach($vR['flexFormRels']['softrefs'] as $key => $subList) { foreach($subList['keys'] as $spKey => $elements) { foreach($elements as $subKey => $el) { if ($el['subst']['type'] === 'file' && $this->includeSoftref($el['subst']['tokenID'])) { // Create abs path and ID for file: $ID_absFile = t3lib_div::getFileAbsFileName(PATH_site.$el['subst']['relFileName']); $ID = md5($ID_absFile); if ($ID_absFile) { if (!$this->dat['files'][$ID]) { $fI = array( 'filename' => basename($ID_absFile), 'ID_absFile' => $ID_absFile, 'ID' => $ID, 'relFileName' => $el['subst']['relFileName'] ); $this->export_addFile($fI, '_SOFTREF_'); } $this->dat['records'][$k]['rels'][$fieldname]['flexFormRels']['softrefs'][$key]['keys'][$spKey][$subKey]['file_ID'] = $ID; } } } } } } } // In any case, if there are soft refs: if (is_array($vR['softrefs']['keys'])) { foreach($vR['softrefs']['keys'] as $spKey => $elements) { foreach($elements as $subKey => $el) { if ($el['subst']['type'] === 'file' && $this->includeSoftref($el['subst']['tokenID'])) { // Create abs path and ID for file: $ID_absFile = t3lib_div::getFileAbsFileName(PATH_site.$el['subst']['relFileName']); $ID = md5($ID_absFile); if ($ID_absFile) { if (!$this->dat['files'][$ID]) { $fI = array( 'filename' => basename($ID_absFile), 'ID_absFile' => $ID_absFile, 'ID' => $ID, 'relFileName' => $el['subst']['relFileName'] ); $this->export_addFile($fI, '_SOFTREF_'); } $this->dat['records'][$k]['rels'][$fieldname]['softrefs']['keys'][$spKey][$subKey]['file_ID'] = $ID; } } } } } } } } } else $this->error('There were no records available.'); } /** * Adds a files content to the export memory * * @param array File information with three keys: "filename" = filename without path, "ID_absFile" = absolute filepath to the file (including the filename), "ID" = md5 hash of "ID_absFile". "relFileName" is optional for files attached to records, but mandatory for soft referenced files (since the relFileName determines where such a file should be stored!) * @param string If the file is related to a record, this is the id on the form [table]:[id]. Information purposes only. * @param string If the file is related to a record, this is the field name it was related to. Information purposes only. * @return void */ function export_addFile($fI, $recordRef='', $fieldname='') { if (@is_file($fI['ID_absFile'])) { if (filesize($fI['ID_absFile']) < $this->maxFileSize) { $fileRec = array(); $fileRec['filesize'] = filesize($fI['ID_absFile']); $fileRec['filename'] = basename($fI['ID_absFile']); $fileRec['filemtime'] = filemtime($fI['ID_absFile']); if ($recordRef) { $fileRec['record_ref'] = $recordRef.'/'.$fieldname; } if ($fI['relFileName']) { $fileRec['relFileName'] = $fI['relFileName']; } // Setting this data in the header $this->dat['header']['files'][$fI['ID']] = $fileRec; // ... and for the recordlisting, why not let us know WHICH relations there was... if ($recordRef && $recordRef!=='_SOFTREF_') { $refParts = explode(':',$recordRef,2); if (!is_array($this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'])) { $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'] = array(); } $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'][] = $fI['ID']; } // ... and finally add the heavy stuff: $fileRec['content'] = t3lib_div::getUrl($fI['ID_absFile']); $fileRec['content_md5'] = md5($fileRec['content']); $this->dat['files'][$fI['ID']] = $fileRec; // For soft references, do further processing: if ($recordRef === '_SOFTREF_') { // RTE files? if ($RTEoriginal = $this->getRTEoriginalFilename(basename($fI['ID_absFile']))) { $RTEoriginal_absPath = dirname($fI['ID_absFile']).'/'.$RTEoriginal; if (@is_file($RTEoriginal_absPath)) { $RTEoriginal_ID = md5($RTEoriginal_absPath); $fileRec = array(); $fileRec['filesize'] = filesize($RTEoriginal_absPath); $fileRec['filename'] = basename($RTEoriginal_absPath); $fileRec['filemtime'] = filemtime($RTEoriginal_absPath); $fileRec['record_ref'] = '_RTE_COPY_ID:'.$fI['ID']; $this->dat['header']['files'][$fI['ID']]['RTE_ORIG_ID'] = $RTEoriginal_ID; // Setting this data in the header $this->dat['header']['files'][$RTEoriginal_ID] = $fileRec; // ... and finally add the heavy stuff: $fileRec['content'] = t3lib_div::getUrl($RTEoriginal_absPath); $fileRec['content_md5'] = md5($fileRec['content']); $this->dat['files'][$RTEoriginal_ID] = $fileRec; } else { $this->error('RTE original file "'.substr($RTEoriginal_absPath,strlen(PATH_site)).'" was not found!'); } } // Files with external media? // This is only done with files grabbed by a softreference parser since it is deemed improbable that hard-referenced files should undergo this treatment. $html_fI = pathinfo(basename($fI['ID_absFile'])); if ($this->includeExtFileResources && t3lib_div::inList($this->extFileResourceExtensions,strtolower($html_fI['extension']))) { $uniquePrefix = '###'.md5(time()).'###'; if (strtolower($html_fI['extension'])==='css') { $prefixedMedias = explode($uniquePrefix, eregi_replace('(url[[:space:]]*\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\))', '\1'.$uniquePrefix.'\2'.$uniquePrefix.'\3', $fileRec['content'])); } else { // html, htm: $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml'); $prefixedMedias = explode($uniquePrefix, $htmlParser->prefixResourcePath($uniquePrefix,$fileRec['content'],array(),$uniquePrefix)); } $htmlResourceCaptured = FALSE; foreach($prefixedMedias as $k => $v) { if ($k%2) { $EXTres_absPath = t3lib_div::resolveBackPath(dirname($fI['ID_absFile']).'/'.$v); $EXTres_absPath = t3lib_div::getFileAbsFileName($EXTres_absPath); if ($EXTres_absPath && t3lib_div::isFirstPartOfStr($EXTres_absPath,PATH_site.$this->fileadminFolderName.'/') && @is_file($EXTres_absPath)) { $htmlResourceCaptured = TRUE; $EXTres_ID = md5($EXTres_absPath); $this->dat['header']['files'][$fI['ID']]['EXT_RES_ID'][] = $EXTres_ID; $prefixedMedias[$k] = '{EXT_RES_ID:'.$EXTres_ID.'}'; // Add file to memory if it is not set already: if (!isset($this->dat['header']['files'][$EXTres_ID])) { $fileRec = array(); $fileRec['filesize'] = filesize($EXTres_absPath); $fileRec['filename'] = basename($EXTres_absPath); $fileRec['filemtime'] = filemtime($EXTres_absPath); $fileRec['record_ref'] = '_EXT_PARENT_:'.$fI['ID']; $fileRec['parentRelFileName'] = $v; // Media relative to the HTML file. // Setting this data in the header $this->dat['header']['files'][$EXTres_ID] = $fileRec; // ... and finally add the heavy stuff: $fileRec['content'] = t3lib_div::getUrl($EXTres_absPath); $fileRec['content_md5'] = md5($fileRec['content']); $this->dat['files'][$EXTres_ID] = $fileRec; } } } } if ($htmlResourceCaptured) { $this->dat['files'][$fI['ID']]['tokenizedContent'] = implode('', $prefixedMedias); } } } } else $this->error($fI['ID_absFile'].' was larger ('.t3lib_div::formatSize(filesize($fI['ID_absFile'])).') than the maxFileSize ('.t3lib_div::formatSize($this->maxFileSize).')! Skipping.'); } else $this->error($fI['ID_absFile'].' was not a file! Skipping.'); } /** * DB relations flattend to 1-dim array. * The list will be unique, no table/uid combination will appear twice. * * @param array 2-dim Array of database relations organized by table key * @return array 1-dim array where entries are table:uid and keys are array with table/id */ function flatDBrels($dbrels) { $list = array(); foreach($dbrels as $dat) { if ($dat['type']=='db') { foreach($dat['itemArray'] as $i) { $list[$i['table'].':'.$i['id']] = $i; } } if ($dat['type']=='flex' && is_array($dat['flexFormRels']['db'])) { foreach($dat['flexFormRels']['db'] as $subList) { foreach($subList as $i) { $list[$i['table'].':'.$i['id']] = $i; } } } } return $list; } /** * Soft References flattend to 1-dim array. * * @param array 2-dim Array of database relations organized by table key * @return array 1-dim array where entries are arrays with properties of the soft link found and keys are a unique combination of field, spKey, structure path if applicable and token ID */ function flatSoftRefs($dbrels) { $list = array();#debug($dbrels); foreach($dbrels as $field => $dat) { if (is_array($dat['softrefs']['keys'])) { foreach($dat['softrefs']['keys'] as $spKey => $elements) { if (is_array($elements)) { foreach($elements as $subKey => $el) { $lKey = $field.':'.$spKey.':'.$subKey; $list[$lKey] = array_merge(array('field' => $field, 'spKey' => $spKey),$el); // Add file_ID key to header - slightly "risky" way of doing this because if the calculation changes for the same value in $this->records[...] this will not work anymore! if ($el['subst'] && $el['subst']['relFileName']) { $list[$lKey]['file_ID'] = md5(PATH_site.$el['subst']['relFileName']); } } } } } if ($dat['type']=='flex' && is_array($dat['flexFormRels']['softrefs'])) { foreach($dat['flexFormRels']['softrefs'] as $structurePath => $subSoftrefs) { if (is_array($subSoftrefs['keys'])) { foreach($subSoftrefs['keys'] as $spKey => $elements) { foreach($elements as $subKey => $el) { $lKey = $field.':'.$structurePath.':'.$spKey.':'.$subKey; $list[$lKey] = array_merge(array('field' => $field, 'spKey' => $spKey, 'structurePath' => $structurePath),$el); // Add file_ID key to header - slightly "risky" way of doing this because if the calculation changes for the same value in $this->records[...] this will not work anymore! if ($el['subst'] && $el['subst']['relFileName']) { $list[$lKey]['file_ID'] = md5(PATH_site.$el['subst']['relFileName']); } } } } } } }#debug($list); return $list; } /************************** * * File Output * *************************/ /** * This compiles and returns the data content for an exported file * * @param string Type of output; "xml" gives xml, otherwise serialized array, possibly compressed. * @return string The output file stream */ function compileMemoryToFileContent($type='') { if ($type=='xml') { $out = $this->createXML(); } else { $compress = $this->doOutputCompress(); $out = ''; // adding header: $out.= $this->addFilePart(serialize($this->dat['header']),$compress); // adding records: $out.= $this->addFilePart(serialize($this->dat['records']),$compress); // adding files: $out.= $this->addFilePart(serialize($this->dat['files']),$compress); } return $out; } /** * Creates XML string from input array * * @return string XML content */ function createXML() { // Options: $options = array( 'alt_options' => array( '/header' => array( 'disableTypeAttrib' => TRUE, 'clearStackPath' => TRUE, 'parentTagMap' => array( 'files' => 'file', 'records' => 'table', 'table' => 'rec', 'rec:rels' => 'relations', 'relations' => 'element', 'filerefs' => 'file', 'pid_lookup' => 'page_contents', 'header:relStaticTables' => 'static_tables', 'static_tables' => 'tablename', 'excludeMap' => 'item', 'softrefCfg' => 'softrefExportMode', 'extensionDependencies' => 'extkey', 'softrefs' => 'softref_element', ), 'alt_options' => array( '/pagetree' => array( 'disableTypeAttrib' => TRUE, 'useIndexTagForNum' => 'node', 'parentTagMap' => array( 'node:subrow' => 'node' ) ),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -