/** * get Content of DOC file * * @param string $file * @return string The extracted content of the file */ public function getContent($file) { // create the tempfile which will contain the content if (TYPO3_VERSION_INTEGER >= 7000000) { $tempFileName = TYPO3\CMS\Core\Utility\GeneralUtility::tempnam('doc_files-Indexer'); } else { $tempFileName = t3lib_div::tempnam('doc_files-Indexer'); } // Delete if exists, just to be safe. @unlink($tempFileName); // generate and execute the pdftotext commandline tool $cmd = $this->app['catdoc'] . ' -s8859-1 -dutf-8 ' . escapeshellarg($file) . ' > ' . escapeshellarg($tempFileName); if (TYPO3_VERSION_INTEGER >= 7000000) { TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd); } else { t3lib_utility_Command::exec($cmd); } // check if the tempFile was successfully created if (@is_file($tempFileName)) { if (TYPO3_VERSION_INTEGER >= 7000000) { $content = TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($tempFileName); } else { $content = t3lib_div::getUrl($tempFileName); } unlink($tempFileName); } else { return false; } // check if content was found if (strlen($content)) { return $content; } else { return false; } }
/** * Index External URLs HTML content * * @param string URL, eg. "http://typo3.org/" * @return void * @see indexRegularDocument() */ function indexExternalUrl($externalUrl) { // Parse External URL: $qParts = parse_url($externalUrl); $fI = pathinfo($qParts['path']); $ext = strtolower($fI['extension']); // Get headers: $urlHeaders = $this->getUrlHeaders($externalUrl); if (stristr($urlHeaders['Content-Type'], 'text/html')) { $content = $this->indexExternalUrl_content = t3lib_div::getUrl($externalUrl); if (strlen($content)) { // Create temporary file: $tmpFile = t3lib_div::tempnam('EXTERNAL_URL'); if ($tmpFile) { t3lib_div::writeFile($tmpFile, $content); // Index that file: $this->indexRegularDocument($externalUrl, TRUE, $tmpFile, 'html'); // Using "TRUE" for second parameter to force indexing of external URLs (mtime doesn't make sense, does it?) unlink($tmpFile); } } } }
/** * Reads the content of an external file being indexed. * * @param string File extension, eg. "pdf", "doc" etc. * @param string Absolute filename of file (must exist and be validated OK before calling function) * @param string Pointer to section (zero for all other than PDF which will have an indication of pages into which the document should be splitted.) * @return array Standard content array (title, description, keywords, body keys) */ function readFileContent($ext, $absFile, $cPKey) { unset($contentArr); // Return immediately if initialization didn't set support up: if (!$this->supportedExtensions[$ext]) { return FALSE; } // Switch by file extension switch ($ext) { case 'pdf': if ($this->app['pdfinfo']) { // Getting pdf-info: $cmd = $this->app['pdfinfo'] . ' ' . escapeshellarg($absFile); exec($cmd, $res); $pdfInfo = $this->splitPdfInfo($res); unset($res); if (intval($pdfInfo['pages'])) { list($low, $high) = explode('-', $cPKey); // Get pdf content: $tempFileName = t3lib_div::tempnam('Typo3_indexer'); // Create temporary name @unlink($tempFileName); // Delete if exists, just to be safe. $cmd = $this->app['pdftotext'] . ' -f ' . $low . ' -l ' . $high . ' -enc UTF-8 -q ' . escapeshellarg($absFile) . ' ' . $tempFileName; exec($cmd); if (@is_file($tempFileName)) { $content = t3lib_div::getUrl($tempFileName); unlink($tempFileName); } else { $this->pObj->log_setTSlogMessage(sprintf($this->sL('LLL:EXT:indexed_search/locallang.xml:pdfToolsFailed'), $absFile), 2); } if (strlen($content)) { $contentArr = $this->pObj->splitRegularContent($this->removeEndJunk($content)); } } } break; case 'doc': if ($this->app['catdoc']) { $cmd = $this->app['catdoc'] . ' -d utf-8 ' . escapeshellarg($absFile); exec($cmd, $res); $content = implode(LF, $res); unset($res); $contentArr = $this->pObj->splitRegularContent($this->removeEndJunk($content)); } break; case 'pps': case 'ppt': if ($this->app['ppthtml']) { $cmd = $this->app['ppthtml'] . ' ' . escapeshellarg($absFile); exec($cmd, $res); $content = implode(LF, $res); unset($res); $content = $this->pObj->convertHTMLToUtf8($content); $contentArr = $this->pObj->splitHTMLContent($this->removeEndJunk($content)); $contentArr['title'] = basename($absFile); // Make sure the title doesn't expose the absolute path! } break; case 'xls': if ($this->app['xlhtml']) { $cmd = $this->app['xlhtml'] . ' -nc -te ' . escapeshellarg($absFile); exec($cmd, $res); $content = implode(LF, $res); unset($res); $content = $this->pObj->convertHTMLToUtf8($content); $contentArr = $this->pObj->splitHTMLContent($this->removeEndJunk($content)); $contentArr['title'] = basename($absFile); // Make sure the title doesn't expose the absolute path! } break; case 'sxi': case 'sxc': case 'sxw': case 'ods': case 'odp': case 'odt': if ($this->app['unzip']) { // Read content.xml: $cmd = $this->app['unzip'] . ' -p ' . escapeshellarg($absFile) . ' content.xml'; exec($cmd, $res); $content_xml = implode(LF, $res); unset($res); // Read meta.xml: $cmd = $this->app['unzip'] . ' -p ' . escapeshellarg($absFile) . ' meta.xml'; exec($cmd, $res); $meta_xml = implode(LF, $res); unset($res); $utf8_content = trim(strip_tags(str_replace('<', ' <', $content_xml))); $contentArr = $this->pObj->splitRegularContent($utf8_content); $contentArr['title'] = basename($absFile); // Make sure the title doesn't expose the absolute path! // Meta information $metaContent = t3lib_div::xml2tree($meta_xml); $metaContent = $metaContent['office:document-meta'][0]['ch']['office:meta'][0]['ch']; if (is_array($metaContent)) { $contentArr['title'] = $metaContent['dc:title'][0]['values'][0] ? $metaContent['dc:title'][0]['values'][0] : $contentArr['title']; $contentArr['description'] = $metaContent['dc:subject'][0]['values'][0] . ' ' . $metaContent['dc:description'][0]['values'][0]; // Keywords collected: if (is_array($metaContent['meta:keywords'][0]['ch']['meta:keyword'])) { foreach ($metaContent['meta:keywords'][0]['ch']['meta:keyword'] as $kwDat) { $contentArr['keywords'] .= $kwDat['values'][0] . ' '; } } } } break; case 'rtf': if ($this->app['unrtf']) { $cmd = $this->app['unrtf'] . ' ' . escapeshellarg($absFile); exec($cmd, $res); $fileContent = implode(LF, $res); unset($res); $fileContent = $this->pObj->convertHTMLToUtf8($fileContent); $contentArr = $this->pObj->splitHTMLContent($fileContent); } break; case 'txt': case 'csv': // Raw text $content = t3lib_div::getUrl($absFile); // TODO: Auto-registration of charset???? -> utf-8 (Current assuming western europe...) $content = $this->pObj->convertHTMLToUtf8($content, 'iso-8859-1'); $contentArr = $this->pObj->splitRegularContent($content); $contentArr['title'] = basename($absFile); // Make sure the title doesn't expose the absolute path! break; case 'html': case 'htm': $fileContent = t3lib_div::getUrl($absFile); $fileContent = $this->pObj->convertHTMLToUtf8($fileContent); $contentArr = $this->pObj->splitHTMLContent($fileContent); break; case 'xml': // PHP strip-tags() $fileContent = t3lib_div::getUrl($absFile); // Finding charset: preg_match('/^[[:space:]]*<\\?xml[^>]+encoding[[:space:]]*=[[:space:]]*["\'][[:space:]]*([[:alnum:]_-]+)[[:space:]]*["\']/i', substr($fileContent, 0, 200), $reg); $charset = $reg[1] ? $this->pObj->csObj->parse_charset($reg[1]) : 'utf-8'; // Converting content: $fileContent = $this->pObj->convertHTMLToUtf8(strip_tags(str_replace('<', ' <', $fileContent)), $charset); $contentArr = $this->pObj->splitRegularContent($fileContent); $contentArr['title'] = basename($absFile); // Make sure the title doesn't expose the absolute path! break; case 'jpg': // PHP EXIF // PHP EXIF case 'jpeg': // PHP EXIF // PHP EXIF case 'tif': // PHP EXIF if (function_exists('exif_read_data')) { $exif = exif_read_data($absFile, 'IFD0'); } else { $exif = FALSE; } if ($exif) { $comment = trim($exif['COMMENT'][0] . ' ' . $exif['ImageDescription']); // The comments in JPEG files are utf-8, while in Tif files they are 7-bit ascii. } else { $comment = ''; } $contentArr = $this->pObj->splitRegularContent($comment); $contentArr['title'] = basename($absFile); // Make sure the title doesn't expose the absolute path! break; default: return false; break; } // If no title (and why should there be...) then the file-name is set as title. This will raise the hits considerably if the search matches the document name. if (is_array($contentArr) && !$contentArr['title']) { $contentArr['title'] = str_replace('_', ' ', basename($absFile)); // Substituting "_" for " " because many filenames may have this instead of a space char. } return $contentArr; }
function spellCheckHandler($xml_parser, $string) { $incurrent = array(); $stringText = $string; $words = preg_split($this->parserCharset == 'utf-8' ? '/\\P{L}+/u' : '/\\W+/', $stringText); while (list(, $word) = each($words)) { $word = preg_replace('/ /' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '', $word); if ($word && !is_numeric($word)) { if ($this->pspell_is_available && !$this->forceCommandMode) { if (!pspell_check($this->pspell_link, $word)) { if (!in_array($word, $this->misspelled)) { if (sizeof($this->misspelled) != 0) { $this->suggestedWords .= ','; } $suggest = array(); $suggest = pspell_suggest($this->pspell_link, $word); if (sizeof($suggest) != 0) { $this->suggestionCount++; $this->suggestedWordCount += sizeof($suggest); } $this->suggestedWords .= '"' . $word . '":"' . implode(',', $suggest) . '"'; $this->misspelled[] = $word; unset($suggest); } if (!in_array($word, $incurrent)) { $stringText = preg_replace('/\\b' . $word . '\\b/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '<span class="htmlarea-spellcheck-error">' . $word . '</span>', $stringText); $incurrent[] = $word; } } } else { $tmpFileName = t3lib_div::tempnam($this->filePrefix); if (!($filehandle = fopen($tmpFileName, 'wb'))) { echo 'SpellChecker tempfile open error'; } if (!fwrite($filehandle, $word)) { echo 'SpellChecker tempfile write error'; } if (!fclose($filehandle)) { echo 'SpellChecker tempfile close error'; } $AspellCommand = 'cat ' . escapeshellarg($tmpFileName) . ' | ' . $this->AspellDirectory . ' -a check --mode=none --sug-mode=' . escapeshellarg($this->pspellMode) . $this->personalDictsArg . ' --lang=' . escapeshellarg($this->dictionary) . ' --encoding=' . escapeshellarg($this->aspellEncoding) . ' 2>&1'; $AspellAnswer = shell_exec($AspellCommand); $AspellResultLines = array(); $AspellResultLines = t3lib_div::trimExplode(LF, $AspellAnswer, 1); if (substr($AspellResultLines[0], 0, 6) == 'Error:') { echo "{$AspellAnswer}"; } t3lib_div::unlink_tempfile($tmpFileName); if (substr($AspellResultLines['1'], 0, 1) != '*') { if (!in_array($word, $this->misspelled)) { if (sizeof($this->misspelled) != 0) { $this->suggestedWords .= ','; } $suggest = array(); $suggestions = array(); if (substr($AspellResultLines['1'], 0, 1) == '&') { $suggestions = t3lib_div::trimExplode(':', $AspellResultLines['1'], 1); $suggest = t3lib_div::trimExplode(',', $suggestions['1'], 1); } if (sizeof($suggest) != 0) { $this->suggestionCount++; $this->suggestedWordCount += sizeof($suggest); } $this->suggestedWords .= '"' . $word . '":"' . implode(',', $suggest) . '"'; $this->misspelled[] = $word; unset($suggest); unset($suggestions); } if (!in_array($word, $incurrent)) { $stringText = preg_replace('/\\b' . $word . '\\b/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '<span class="htmlarea-spellcheck-error">' . $word . '</span>', $stringText); $incurrent[] = $word; } } unset($AspellResultLines); } $this->wordCount++; } } $this->text .= $stringText; unset($incurrent); return; }
/** * The main processing method if this class * * @return string Information of the template status or the taken actions as HTML string */ function main() { global $SOBE, $BE_USER, $LANG, $BACK_PATH, $TCA_DESCR, $TCA, $CLIENT, $TYPO3_CONF_VARS; global $tmpl, $tplRow, $theConstants; $edit = $this->pObj->edit; $e = $this->pObj->e; t3lib_div::loadTCA('sys_template'); // ************************** // Checking for more than one template an if, set a menu... // ************************** $manyTemplatesMenu = $this->pObj->templateMenu(); $template_uid = 0; if ($manyTemplatesMenu) { $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage']; } // ************************** // Initialize // ************************** $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid); // initialize if ($existTemplate) { $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid']; } // ************************** // Create extension template // ************************** $newId = $this->pObj->createTemplate($this->pObj->id, $saveId); if ($newId) { // switch to new template t3lib_utility_Http::redirect('index.php?id=' . $this->pObj->id . '&SET[templatesOnPage]=' . $newId); } if ($existTemplate) { // Update template ? $POST = t3lib_div::_POST(); if ($POST['submit'] || t3lib_div::testInt($POST['submit_x']) && t3lib_div::testInt($POST['submit_y']) || $POST['saveclose'] || t3lib_div::testInt($POST['saveclose_x']) && t3lib_div::testInt($POST['saveclose_y'])) { // Set the data to be saved $recData = array(); $alternativeFileName = array(); $resList = $tplRow['resources']; $tmp_upload_name = ''; $tmp_newresource_name = ''; // Set this to blank if (is_array($POST['data'])) { foreach ($POST['data'] as $field => $val) { switch ($field) { case 'constants': case 'config': case 'title': case 'sitetitle': case 'description': $recData['sys_template'][$saveId][$field] = $val; break; case 'resources': $tmp_upload_name = t3lib_div::upload_to_tempfile($_FILES['resources']['tmp_name']); // If there is an uploaded file, move it for the sake of safe_mode. if ($tmp_upload_name) { if ($tmp_upload_name != 'none' && $_FILES['resources']['name']) { $alternativeFileName[$tmp_upload_name] = trim($_FILES['resources']['name']); $resList = $tmp_upload_name . ',' . $resList; } } break; case 'new_resource': $newName = trim(t3lib_div::_GP('new_resource')); if ($newName) { $newName .= '.' . t3lib_div::_GP('new_resource_ext'); $tmp_newresource_name = t3lib_div::tempnam('new_resource_'); $alternativeFileName[$tmp_newresource_name] = $newName; $resList = $tmp_newresource_name . ',' . $resList; } break; case 'makecopy_resource': if (is_array($val)) { $resList = ',' . $resList . ','; foreach ($val as $k => $file) { $tmp_name = PATH_site . $TCA['sys_template']['columns']['resources']['config']['uploadfolder'] . '/' . $file; $resList = $tmp_name . ',' . $resList; } } break; case 'remove_resource': if (is_array($val)) { $resList = ',' . $resList . ','; foreach ($val as $k => $file) { $resList = str_replace(',' . $file . ',', ',', $resList); } } break; case 'totop_resource': if (is_array($val)) { $resList = ',' . $resList . ','; foreach ($val as $k => $file) { $resList = str_replace(',' . $file . ',', ',', $resList); $resList = ',' . $file . $resList; } } break; } } } $resList = implode(',', t3lib_div::trimExplode(',', $resList, 1)); if (strcmp($resList, $tplRow['resources'])) { $recData['sys_template'][$saveId]['resources'] = $resList; } if (count($recData)) { // Create new tce-object $tce = t3lib_div::makeInstance('t3lib_TCEmain'); $tce->stripslashes_values = 0; $tce->alternativeFileName = $alternativeFileName; // Initialize $tce->start($recData, array()); // Saved the stuff $tce->process_datamap(); // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php) $tce->clear_cacheCmd('all'); // tce were processed successfully $this->tce_processed = true; // re-read the template ... $this->initialize_editor($this->pObj->id, $template_uid); } // Unlink any uploaded/new temp files there was: t3lib_div::unlink_tempfile($tmp_upload_name); t3lib_div::unlink_tempfile($tmp_newresource_name); // If files has been edited: if (is_array($edit)) { if ($edit['filename'] && $tplRow['resources'] && t3lib_div::inList($tplRow['resources'], $edit['filename'])) { // Check if there are resources, and that the file is in the resourcelist. $path = PATH_site . $TCA['sys_template']['columns']['resources']['config']['uploadfolder'] . '/' . $edit['filename']; $fI = t3lib_div::split_fileref($edit['filename']); if (@is_file($path) && t3lib_div::getFileAbsFileName($path) && t3lib_div::inList($this->pObj->textExtensions, $fI['fileext'])) { // checks that have already been done.. Just to make sure // @TODO: Check if the hardcorded value already has a config member, otherwise create one if (filesize($path) < 30720) { // checks that have already been done.. Just to make sure t3lib_div::writeFile($path, $edit['file']); $theOutput .= $this->pObj->doc->spacer(10); $theOutput .= $this->pObj->doc->section('<font color=red>' . $GLOBALS['LANG']->getLL('fileChanged') . '</font>', sprintf($GLOBALS['LANG']->getLL('resourceUpdated'), $edit['filename']), 0, 0, 0, 1); // Clear cache - the file has probably affected the template setup // @TODO: Check if the edited file really had something to do with cached data and prevent this clearing if possible! $tce = t3lib_div::makeInstance('t3lib_TCEmain'); $tce->stripslashes_values = 0; $tce->start(array(), array()); $tce->clear_cacheCmd('all'); } } } } } // hook Post updating template/TCE processing if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'])) { $postTCEProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook']; if (is_array($postTCEProcessingHook)) { $hookParameters = array('POST' => $POST, 'tce' => $tce); foreach ($postTCEProcessingHook as $hookFunction) { t3lib_div::callUserFunction($hookFunction, $hookParameters, $this); } } } $theOutput .= $this->pObj->doc->spacer(5); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('templateInformation'), t3lib_iconWorks::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . htmlspecialchars($tplRow['title']) . '</strong>' . htmlspecialchars(trim($tplRow['sitetitle']) ? ' - (' . $tplRow['sitetitle'] . ')' : ''), 0, 1); if ($manyTemplatesMenu) { $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu); $theOutput .= $this->pObj->doc->divider(5); } #$numberOfRows= t3lib_div::intInRange($this->pObj->MOD_SETTINGS["ts_template_editor_TArows"],0,150); #if (!$numberOfRows) $numberOfRows = 35; // If abort pressed, nothing should be edited: if ($POST['abort'] || t3lib_div::testInt($POST['abort_x']) && t3lib_div::testInt($POST['abort_y']) || $POST['saveclose'] || t3lib_div::testInt($POST['saveclose_x']) && t3lib_div::testInt($POST['saveclose_y'])) { unset($e); } if ($e['title']) { $outCode = '<input type="Text" name="data[title]" value="' . htmlspecialchars($tplRow['title']) . '"' . $this->pObj->doc->formWidth() . '>'; $outCode .= '<input type="Hidden" name="e[title]" value="1">'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('title'), $outCode); } if ($e['sitetitle']) { $outCode = '<input type="Text" name="data[sitetitle]" value="' . htmlspecialchars($tplRow['sitetitle']) . '"' . $this->pObj->doc->formWidth() . '>'; $outCode .= '<input type="Hidden" name="e[sitetitle]" value="1">'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('sitetitle'), $outCode); } if ($e['description']) { $outCode = '<textarea name="data[description]" rows="5" class="fixed-font enable-tab"' . $this->pObj->doc->formWidthText(48, '', '') . '>' . t3lib_div::formatForTextarea($tplRow['description']) . '</textarea>'; $outCode .= '<input type="Hidden" name="e[description]" value="1">'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('description'), $outCode); } if ($e['resources']) { // Upload $outCode = '<input type="File" name="resources"' . $this->pObj->doc->formWidth() . ' size="50">'; $outCode .= '<input type="Hidden" name="data[resources]" value="1">'; $outCode .= '<input type="Hidden" name="e[resources]" value="1">'; $outCode .= '<BR>' . $GLOBALS['LANG']->getLL('allowedExtensions') . ' <strong>' . $TCA['sys_template']['columns']['resources']['config']['allowed'] . '</strong>'; $outCode .= '<BR>' . $GLOBALS['LANG']->getLL('maxFilesize') . ' <strong>' . t3lib_div::formatSize($TCA['sys_template']['columns']['resources']['config']['max_size'] * 1024) . '</strong>'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('uploadResource'), $outCode); // New $opt = explode(',', $this->pObj->textExtensions); $optTags = ''; foreach ($opt as $extVal) { $optTags .= '<option value="' . $extVal . '">.' . $extVal . '</option>'; } $outCode = '<input type="text" name="new_resource"' . $this->pObj->doc->formWidth(20) . '> <select name="new_resource_ext">' . $optTags . '</select>'; $outCode .= '<input type="Hidden" name="data[new_resource]" value="1">'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('newTextResource'), $outCode); // Make copy $rL = $this->resourceListForCopy($this->pObj->id, $template_uid); if ($rL) { $theOutput .= $this->pObj->doc->spacer(20); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('copyResource'), $rL); } // Update resource list $rL = $this->procesResources($tplRow['resources'], 1); if ($rL) { $theOutput .= $this->pObj->doc->spacer(20); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('updateResourceList'), $rL); } } if ($e['constants']) { $outCode = '<textarea name="data[constants]" rows="' . $numberOfRows . '" wrap="off" class="fixed-font enable-tab"' . $this->pObj->doc->formWidthText(48, 'width:98%;height:70%', 'off') . ' class="fixed-font">' . t3lib_div::formatForTextarea($tplRow['constants']) . '</textarea>'; $outCode .= '<input type="Hidden" name="e[constants]" value="1">'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants'), ''); $theOutput .= $this->pObj->doc->sectionEnd() . $outCode; } if ($e['file']) { $path = PATH_site . $TCA['sys_template']['columns']['resources']['config']['uploadfolder'] . '/' . $e[file]; $fI = t3lib_div::split_fileref($e[file]); if (@is_file($path) && t3lib_div::inList($this->pObj->textExtensions, $fI['fileext'])) { if (filesize($path) < $TCA['sys_template']['columns']['resources']['config']['max_size'] * 1024) { $fileContent = t3lib_div::getUrl($path); $outCode = $GLOBALS['LANG']->getLL('file') . ' <strong>' . $e[file] . '</strong><BR>'; $outCode .= '<textarea name="edit[file]" rows="' . $numberOfRows . '" wrap="off" class="fixed-font enable-tab"' . $this->pObj->doc->formWidthText(48, 'width:98%;height:70%', 'off') . ' class="fixed-font">' . t3lib_div::formatForTextarea($fileContent) . '</textarea>'; $outCode .= '<input type="Hidden" name="edit[filename]" value="' . $e[file] . '">'; $outCode .= '<input type="Hidden" name="e[file]" value="' . htmlspecialchars($e[file]) . '">'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editResource'), ''); $theOutput .= $this->pObj->doc->sectionEnd() . $outCode; } else { $theOutput .= $this->pObj->doc->spacer(15); $fileToBig = sprintf($GLOBALS['LANG']->getLL('filesizeExceeded'), $TCA['sys_template']['columns']['resources']['config']['max_size']); $filesizeNotAllowed = sprintf($GLOBALS['LANG']->getLL('notAllowed'), $TCA['sys_template']['columns']['resources']['config']['max_size']); $theOutput .= $this->pObj->doc->section('<font color=red>' . $fileToBig . '</font>', $filesizeNotAllowed, 0, 0, 0, 1); } } } if ($e['config']) { $outCode = '<textarea name="data[config]" rows="' . $numberOfRows . '" wrap="off" class="fixed-font enable-tab"' . $this->pObj->doc->formWidthText(48, "width:98%;height:70%", "off") . ' class="fixed-font">' . t3lib_div::formatForTextarea($tplRow["config"]) . '</textarea>'; if (t3lib_extMgm::isLoaded('tsconfig_help')) { $url = $BACK_PATH . 'wizard_tsconfig.php?mode=tsref'; $params = array('formName' => 'editForm', 'itemName' => 'data[config]'); $outCode .= '<a href="#" onClick="vHWin=window.open(\'' . $url . t3lib_div::implodeArrayForUrl('', array('P' => $params)) . '\',\'popUp' . $md5ID . '\',\'height=500,width=780,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;">' . t3lib_iconWorks::getSpriteIcon('actions-system-typoscript-documentation-open', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:tsRef', true))) . '</a>'; } $outCode .= '<input type="Hidden" name="e[config]" value="1">'; $theOutput .= $this->pObj->doc->spacer(15); $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup'), ''); $theOutput .= $this->pObj->doc->sectionEnd() . $outCode; } // Processing: $outCode = ''; $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('title'), htmlspecialchars($tplRow['title']), 'title'); $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('sitetitle'), htmlspecialchars($tplRow['sitetitle']), 'sitetitle'); $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('description'), nl2br(htmlspecialchars($tplRow['description'])), 'description'); $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('resources'), $this->procesResources($tplRow['resources']), 'resources'); $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('constants'), sprintf($GLOBALS['LANG']->getLL('editToView'), trim($tplRow[constants]) ? count(explode(LF, $tplRow[constants])) : 0), 'constants'); $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('setup'), sprintf($GLOBALS['LANG']->getLL('editToView'), trim($tplRow[config]) ? count(explode(LF, $tplRow[config])) : 0), 'config'); $outCode = '<br /><br /><table class="t3-table-info">' . $outCode . '</table>'; // Edit all icon: $outCode .= '<br /><a href="#" onClick="' . t3lib_BEfunc::editOnClick(rawurlencode('&createExtension=0') . '&edit[sys_template][' . $tplRow['uid'] . ']=edit', $BACK_PATH, '') . '"><strong>' . t3lib_iconWorks::getSpriteIcon('actions-document-open', array('title' => $GLOBALS['LANG']->getLL('editTemplateRecord'))) . $GLOBALS['LANG']->getLL('editTemplateRecord') . '</strong></a>'; $theOutput .= $this->pObj->doc->section('', $outCode); // hook after compiling the output if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'])) { $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook']; if (is_array($postOutputProcessingHook)) { $hookParameters = array('theOutput' => &$theOutput, 'POST' => $POST, 'e' => $e, 'tplRow' => $tplRow, 'numberOfRows' => $numberOfRows); foreach ($postOutputProcessingHook as $hookFunction) { t3lib_div::callUserFunction($hookFunction, $hookParameters, $this); } } } } else { $theOutput .= $this->pObj->noTemplate(1); } return $theOutput; }
/** * Writes the file from import array to temp dir and returns the filename of it. * * @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" * @return string Absolute filename of the temporary filename of the file. In ->alternativeFileName the original name is set. */ function import_addFileNameToBeCopied($fI) { if (is_array($this->dat['files'][$fI['ID']])) { $tmpFile = t3lib_div::tempnam('import_temp_'); t3lib_div::writeFile($tmpFile, $this->dat['files'][$fI['ID']]['content']); clearstatcache(); if (@is_file($tmpFile)) { $this->unlinkFiles[] = $tmpFile; if (filesize($tmpFile) == $this->dat['files'][$fI['ID']]['filesize']) { $this->alternativeFileName[$tmpFile] = $fI['filename']; $this->alternativeFilePath[$tmpFile] = $this->dat['files'][$fI['ID']]['relFileRef']; return $tmpFile; } else { $this->error('Error: temporary file ' . $tmpFile . ' had a size (' . filesize($tmpFile) . ') different from the original (' . $this->dat['files'][$fI['ID']]['filesize'] . ')', 1); } } else { $this->error('Error: temporary file ' . $tmpFile . ' was not written as it should have been!', 1); } } else { $this->error('Error: No file found for ID ' . $fI['ID'], 1); } }
/** * Will move an uploaded file (normally in "/tmp/xxxxx") to a temporary filename in PATH_site."typo3temp/" from where TYPO3 can use it under safe_mode. * Use this function to move uploaded files to where you can work on them. * REMEMBER to use t3lib_div::unlink_tempfile() afterwards - otherwise temp-files will build up! They are NOT automatically deleted in PATH_site."typo3temp/"! * Usage: 6 * * @param string The temporary uploaded filename, eg. $_FILES['[upload field name here]']['tmp_name'] * @return string If a new file was successfully created, return its filename, otherwise blank string. * @see unlink_tempfile(), upload_copy_move() */ function upload_to_tempfile($uploadedFileName) { if (is_uploaded_file($uploadedFileName)) { $tempFile = t3lib_div::tempnam('upload_temp_'); move_uploaded_file($uploadedFileName, $tempFile); return @is_file($tempFile) ? $tempFile : ''; } }
/** * Produce a diff (using the "diff" application) between two strings * The function will write the two input strings to temporary files, then execute the diff program, delete the temp files and return the result. * * @param string String 1 * @param string String 2 * @return array The result from the exec() function call. * @access private */ function getDiff($str1, $str2) { // Create file 1 and write string $file1 = t3lib_div::tempnam('diff1_'); t3lib_div::writeFile($file1, $str1); // Create file 2 and write string $file2 = t3lib_div::tempnam('diff2_'); t3lib_div::writeFile($file2, $str2); // Perform diff. $cmd = $GLOBALS['TYPO3_CONF_VARS']['BE']['diff_path'] . ' ' . $this->diffOptions . ' ' . $file1 . ' ' . $file2; $res = array(); t3lib_utility_Command::exec($cmd, $res); unlink($file1); unlink($file2); return $res; }
/** * Pass the content through tidy - a little program that cleans up HTML-code. * Requires $this->TYPO3_CONF_VARS['FE']['tidy'] to be true and $this->TYPO3_CONF_VARS['FE']['tidy_path'] to contain the filename/path of tidy including clean-up arguments for tidy. See default value in TYPO3_CONF_VARS in t3lib/config_default.php * * @param string The page content to clean up. Will be written to a temporary file which "tidy" is then asked to clean up. File content is read back and returned. * @return string Returns the */ function tidyHTML($content) { if ($this->TYPO3_CONF_VARS['FE']['tidy'] && $this->TYPO3_CONF_VARS['FE']['tidy_path']) { $oldContent = $content; $fname = t3lib_div::tempnam('typo3_tidydoc_'); // Create temporary name @unlink($fname); // Delete if exists, just to be safe. $fp = fopen($fname, 'wb'); // Open for writing fputs($fp, $content); // Put $content @fclose($fp); // Close exec($this->TYPO3_CONF_VARS['FE']['tidy_path'] . ' ' . $fname, $output); // run the $content through 'tidy', which formats the HTML to nice code. @unlink($fname); // Delete the tempfile again $content = implode(LF, $output); if (!trim($content)) { $content = $oldContent; // Restore old content due empty return value. $GLOBALS['TT']->setTSlogMessage('"tidy" returned an empty value!', 2); } $GLOBALS['TT']->setTSlogMessage('"tidy" content lenght: ' . strlen($content), 0); } return $content; }
/** * Fetches metadata and stores it to the corresponding place. This includes the mirror list, * extension XML files. * * @param string Type of data to fetch: (mirrors) * @param boolean If true the method doesn't produce any output * @return void */ function fetchMetaData($metaType) { global $TYPO3_CONF_VARS; $content = ''; switch ($metaType) { case 'mirrors': $mfile = t3lib_div::tempnam('mirrors'); $mirrorsFile = t3lib_div::getURL($this->MOD_SETTINGS['mirrorListURL'], 0, array(TYPO3_user_agent)); if ($mirrorsFile === false) { t3lib_div::unlink_tempfile($mfile); $content = '<p>' . sprintf($GLOBALS['LANG']->getLL('ext_import_list_not_updated'), $this->MOD_SETTINGS['mirrorListURL']) . ' ' . $GLOBALS['LANG']->getLL('translation_problems') . '</p>'; } else { t3lib_div::writeFile($mfile, $mirrorsFile); $mirrors = implode('', gzfile($mfile)); t3lib_div::unlink_tempfile($mfile); $mirrors = $this->xmlHandler->parseMirrorsXML($mirrors); if (is_array($mirrors) && count($mirrors)) { t3lib_BEfunc::getModuleData($this->MOD_MENU, array('extMirrors' => serialize($mirrors)), $this->MCONF['name'], '', 'extMirrors'); $this->MOD_SETTINGS['extMirrors'] = serialize($mirrors); $content = '<p>' . sprintf($GLOBALS['LANG']->getLL('ext_import_list_updated'), count($mirrors)) . '</p>'; } else { $content = '<p>' . $mirrors . '<br />' . $GLOBALS['LANG']->getLL('ext_import_list_empty') . '</p>'; } } break; case 'extensions': $this->fetchMetaData('mirrors'); // if we fetch the extensions anyway, we can as well keep this up-to-date $mirror = $this->getMirrorURL(); $extfile = $mirror . 'extensions.xml.gz'; $extmd5 = t3lib_div::getURL($mirror . 'extensions.md5', 0, array(TYPO3_user_agent)); if (is_file(PATH_site . 'typo3temp/extensions.xml.gz')) { $localmd5 = md5_file(PATH_site . 'typo3temp/extensions.xml.gz'); } // count cached extensions. If cache is empty re-fill it $cacheCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('extkey', 'cache_extensions'); if ($extmd5 === false) { $content .= '<p>' . sprintf($GLOBALS['LANG']->getLL('ext_import_md5_not_updated'), $mirror . 'extensions.md5') . $GLOBALS['LANG']->getLL('translation_problems') . '</p>'; } elseif ($extmd5 == $localmd5 && $cacheCount) { $flashMessage = t3lib_div::makeInstance('t3lib_FlashMessage', $GLOBALS['LANG']->getLL('ext_import_list_unchanged'), $GLOBALS['LANG']->getLL('ext_import_list_unchanged_header'), t3lib_FlashMessage::INFO); $content .= $flashMessage->render(); } else { $extXML = t3lib_div::getURL($extfile, 0, array(TYPO3_user_agent)); if ($extXML === false) { $content .= '<p>' . sprintf($GLOBALS['LANG']->getLL('ext_import_list_unchanged'), $extfile) . ' ' . $GLOBALS['LANG']->getLL('translation_problems') . '</p>'; } else { t3lib_div::writeFile(PATH_site . 'typo3temp/extensions.xml.gz', $extXML); $content .= $this->xmlHandler->parseExtensionsXML(PATH_site . 'typo3temp/extensions.xml.gz'); } } break; } return $content; }
/** * The actual sprite generator, renders the command for Im/GM and executes * * @return void */ protected function generateGraphic() { $iconParameters = array(); $tempSprite = t3lib_div::tempnam($this->spriteName); $filePath = array('mainFile' => PATH_site . $this->spriteFolder . $this->spriteName . '.png', 'gifFile' => NULL); // create black true color image with given size $newSprite = imagecreatetruecolor($this->spriteWidth, $this->spriteHeight); imagesavealpha($newSprite, TRUE); // make it transparent imagefill($newSprite, 0, 0, imagecolorallocatealpha($newSprite, 0, 255, 255, 127)); foreach ($this->iconsData as $icon) { $function = 'imagecreatefrom' . strtolower($icon['fileExtension']); if (function_exists($function)) { $currentIcon = $function($icon['fileName']); imagecopy($newSprite, $currentIcon, $icon['left'], $icon['top'], 0, 0, $icon['width'], $icon['height']); } } imagepng($newSprite, $tempSprite . '.png'); if ($this->generateGIFCopy) { $filePath['gifFile'] = PATH_site . $this->spriteFolder . $this->spriteName . '.gif'; $gifSprite = imagecreatetruecolor($this->spriteWidth, $this->spriteHeight); // make it transparent imagefill($gifSprite, 0, 0, imagecolorallocate($gifSprite, 127, 127, 127)); foreach ($this->iconsData as $icon) { $function = 'imagecreatefrom' . strtolower($icon['fileExtension']); if (function_exists($function)) { $currentIcon = $function($icon['fileName']); imagecopy($gifSprite, $currentIcon, $icon['left'], $icon['top'], 0, 0, $icon['width'], $icon['height']); } } imagecolortransparent($gifSprite, imagecolorallocate($gifSprite, 127, 127, 127)); imagegif($gifSprite, $tempSprite . '.gif'); } t3lib_div::upload_copy_move($tempSprite . '.png', $filePath['mainFile']); t3lib_div::unlink_tempfile($tempSprite . '.png'); if ($this->generateGIFCopy) { t3lib_div::upload_copy_move($tempSprite . '.gif', $filePath['gifFile']); t3lib_div::unlink_tempfile($tempSprite . '.gif'); } }
function div_arrayToCsvFile($aData, $sFilePath = FALSE, $sFSep = ";", $sLSep = "\r\n", $sStringWrap = "\"") { if ($sFilePath === FALSE) { $sFilePath = t3lib_div::tempnam("csv-" . strftime("%Y.%m.%d-%Hh%Mm%Ss" . "-")) . ".csv"; } else { $sFilePath = tx_ameosformidable::toServerPath($sFilePath); } tx_ameosformidable::file_writeBin($sFilePath, tx_ameosformidable::div_arrayToCsvString($aData, $sFSep, $sLSep, $sStringWrap), FALSE); return $sFilePath; }
/** * Create a temporary file. * * @param string File prefix. * @return string File name or FALSE */ function tempFile($filePrefix) { $absFile = t3lib_div::tempnam($filePrefix); if ($absFile) { $ret = TRUE; $this->registerTempFile($absFile); } else { $ret = FALSE; $this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not create temp file.'); } return $ret ? $absFile : FALSE; }
/** * Creates a fake extension with a given table definition. * * @param string $tableDefinition SQL script to create the extension's tables * @return void */ protected function createFakeExtension($tableDefinition) { // Prepare a fake extension configuration $ext_tables = t3lib_div::tempnam('ext_tables'); t3lib_div::writeFile($ext_tables, $tableDefinition); $this->temporaryFiles[] = $ext_tables; $GLOBALS['TYPO3_LOADED_EXT']['test_dbal'] = array('ext_tables.sql' => $ext_tables); // Append our test table to the list of existing tables $GLOBALS['TYPO3_DB']->clearCachedFieldInfo(); $GLOBALS['TYPO3_DB']->_call('initInternalVariables'); }
/** * get Content of PDF file * * @param string $file * @return string The extracted content of the file */ public function getContent($file) { if (TYPO3_VERSION_INTEGER >= 6002000) { $this->fileInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_lib_fileinfo'); } else { $this->fileInfo = t3lib_div::makeInstance('tx_kesearch_lib_fileinfo'); } $this->fileInfo->setFile($file); // get PDF informations if (!($pdfInfo = $this->getPdfInfo($file))) { return false; } // proceed only of there are any pages found if (intval($pdfInfo['pages']) && $this->isAppArraySet) { // create the tempfile which will contain the content if (TYPO3_VERSION_INTEGER >= 7000000) { $tempFileName = TYPO3\CMS\Core\Utility\GeneralUtility::tempnam('pdf_files-Indexer'); } else { $tempFileName = t3lib_div::tempnam('pdf_files-Indexer'); } // Delete if exists, just to be safe. @unlink($tempFileName); // generate and execute the pdftotext commandline tool $cmd = $this->app['pdftotext'] . ' -enc UTF-8 -q ' . escapeshellarg($file) . ' ' . escapeshellarg($tempFileName); if (TYPO3_VERSION_INTEGER >= 7000000) { TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd); } else { t3lib_utility_Command::exec($cmd); } // check if the tempFile was successfully created if (@is_file($tempFileName)) { if (TYPO3_VERSION_INTEGER >= 7000000) { $content = TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($tempFileName); } else { $content = t3lib_div::getUrl($tempFileName); } unlink($tempFileName); } else { $this->addError('Content for file ' . $file . ' could not be extracted. Maybe it is encrypted?'); // return empty string if no content was found $content = ''; } return $this->removeEndJunk($content); } else { return false; } }