/**
  * 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;
     }
 }
 /**
  * Unzips a zip file in the given path.
  *
  * Uses unzip binary if available, otherwise a pure PHP unzip is used.
  *
  * @param string $file		Full path to zip file
  * @param string $path		Path to change to before extracting
  * @return boolean	True on success, false in failure
  */
 public static function unzip($file, $path)
 {
     if (strlen($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'])) {
         chdir($path);
         $cmd = $GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'] . ' -o ' . escapeshellarg($file);
         t3lib_utility_Command::exec($cmd, $list, $ret);
         return $ret === 0;
     } else {
         // we use a pure PHP unzip
         $unzip = t3lib_div::makeInstance('tx_em_Tools_Unzip', $file);
         $ret = $unzip->extract(array('add_path' => $path));
         return is_array($ret);
     }
 }
 /**
  * Compile the command for running ImageMagick/GraphicsMagick.
  *
  * @param string $command Command to be run: identify, convert or combine/composite
  * @param string $parameters The parameters string
  * @param string $path Override the default path (e.g. used by the install tool)
  * @return string Compiled command that deals with IM6 & GraphicsMagick
  */
 public static function imageMagickCommand($command, $parameters, $path = '')
 {
     return t3lib_utility_Command::imageMagickCommand($command, $parameters, $path);
 }
 /**
  * Helper function to check for a working diff tool on a system.
  *
  * Tests same file to be sure there is not any error message.
  *
  * @return boolean TRUE if a diff tool was found, FALSE otherwise
  */
 protected function isDiffToolAvailable()
 {
     $filePath = t3lib_extMgm::extPath('phpunit') . 'Tests/Unit/Backend/Fixtures/LoadMe.php';
     // Makes sure everything is sent to the stdOutput.
     $executeCommand = $GLOBALS['TYPO3_CONF_VARS']['BE']['diff_path'] . ' 2>&1 ' . $filePath . ' ' . $filePath;
     $result = array();
     t3lib_utility_Command::exec($executeCommand, $result);
     return empty($result);
 }
 /**
  * Converts a png file to jpg.
  * This converts a png file to jpg.
  *
  * @param string $theFile the filename with path
  * @return string new filename
  */
 public static function png_to_jpg_by_imagemagick($theFile)
 {
     if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] && strtolower(substr($theFile, -4, 4)) == '.png' && @is_file($theFile)) {
         // IM
         $newFile = substr($theFile, 0, -4) . '.jpg';
         $cmd = t3lib_div::imageMagickCommand('convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']);
         t3lib_utility_Command::exec($cmd);
         $theFile = $newFile;
         if (@is_file($newFile)) {
             t3lib_div::fixPermissions($newFile);
         }
         // unlink old file?? May be bad idea because TYPO3 would then recreate the file every time as
         // TYPO3 thinks the file is not generated because it's missing!! So do not unlink $theFile here!!
     }
     return $theFile;
 }
 /**
  * Checks if command line version of the OpenSSL is available and can be
  * executed successfully.
  *
  * @return void
  * @see tx_rsaauth_abstract_backend::isAvailable()
  */
 public function isAvailable()
 {
     $result = false;
     if ($this->opensslPath) {
         // If path exists, test that command runs and can produce output
         $test = t3lib_utility_Command::exec($this->opensslPath . ' version');
         $result = substr($test, 0, 8) == 'OpenSSL ';
     }
     return $result;
 }
 /**
  * Executes a ImageMagick "combine" (or composite in newer times) on four filenames - $input, $overlay and $mask as input files and $output as the output filename (written to)
  * Can be used for many things, mostly scaling and effects.
  *
  * @param	string		The relative (to PATH_site) image filepath, bottom file
  * @param	string		The relative (to PATH_site) image filepath, overlay file (top)
  * @param	string		The relative (to PATH_site) image filepath, the mask file (grayscale)
  * @param	string		The relative (to PATH_site) image filepath, output filename (written to)
  * @param	[type]		$handleNegation: ...
  * @return	void
  */
 function combineExec($input, $overlay, $mask, $output, $handleNegation = FALSE)
 {
     if (!$this->NO_IMAGE_MAGICK) {
         $params = '-colorspace GRAY +matte';
         if ($handleNegation) {
             if ($this->maskNegate) {
                 $params .= ' ' . $this->maskNegate;
             }
         }
         $theMask = $this->randomName() . '.' . $this->gifExtension;
         $this->imageMagickExec($mask, $theMask, $params);
         $cmd = t3lib_div::imageMagickCommand('combine', '-compose over +matte ' . $this->wrapFileName($input) . ' ' . $this->wrapFileName($overlay) . ' ' . $this->wrapFileName($theMask) . ' ' . $this->wrapFileName($output));
         // +matte = no alpha layer in output
         $this->IM_commands[] = array($output, $cmd);
         $ret = t3lib_utility_Command::exec($cmd);
         t3lib_div::fixPermissions($output);
         // Change the permissions of the file
         if (is_file($theMask)) {
             @unlink($theMask);
         }
         return $ret;
     }
 }
Esempio n. 8
0
 /**
  * Create the thumbnail
  * Will exit before return if all is well.
  *
  * @return	void
  */
 function main()
 {
     global $TYPO3_CONF_VARS;
     // If file exists, we make a thumbsnail of the file.
     if ($this->input && file_exists($this->input)) {
         // Check file extension:
         $reg = array();
         if (preg_match('/(.*)\\.([^\\.]*$)/', $this->input, $reg)) {
             $ext = strtolower($reg[2]);
             $ext = $ext == 'jpeg' ? 'jpg' : $ext;
             if ($ext == 'ttf') {
                 $this->fontGif($this->input);
                 // Make font preview... (will not return)
             } elseif (!t3lib_div::inList($this->imageList, $ext)) {
                 $this->errorGif('Not imagefile!', $ext, basename($this->input));
             }
         } else {
             $this->errorGif('Not imagefile!', 'No ext!', basename($this->input));
         }
         // ... so we passed the extension test meaning that we are going to make a thumbnail here:
         if (!$this->size) {
             $this->size = $this->sizeDefault;
         }
         // default
         // I added extra check, so that the size input option could not be fooled to pass other values. That means the value is exploded, evaluated to an integer and the imploded to [value]x[value]. Furthermore you can specify: size=340 and it'll be translated to 340x340.
         $sizeParts = explode('x', $this->size . 'x' . $this->size);
         // explodes the input size (and if no "x" is found this will add size again so it is the same for both dimensions)
         $sizeParts = array(t3lib_div::intInRange($sizeParts[0], 1, 1000), t3lib_div::intInRange($sizeParts[1], 1, 1000));
         // Cleaning it up, only two parameters now.
         $this->size = implode('x', $sizeParts);
         // Imploding the cleaned size-value back to the internal variable
         $sizeMax = max($sizeParts);
         // Getting max value
         // Init
         $outpath = PATH_site . $this->outdir;
         // Should be - ? 'png' : 'gif' - , but doesn't work (ImageMagick prob.?)
         // René: png work for me
         $thmMode = t3lib_div::intInRange($TYPO3_CONF_VARS['GFX']['thumbnails_png'], 0);
         $outext = $ext != 'jpg' || $thmMode & 2 ? $thmMode & 1 ? 'png' : 'gif' : 'jpg';
         $outfile = 'tmb_' . substr(md5($this->input . $this->mtime . $this->size), 0, 10) . '.' . $outext;
         $this->output = $outpath . $outfile;
         if ($TYPO3_CONF_VARS['GFX']['im']) {
             // If thumbnail does not exist, we generate it
             if (!file_exists($this->output)) {
                 $parameters = '-sample ' . $this->size . ' ' . $this->wrapFileName($this->input) . '[0] ' . $this->wrapFileName($this->output);
                 $cmd = t3lib_div::imageMagickCommand('convert', $parameters);
                 t3lib_utility_Command::exec($cmd);
                 if (!file_exists($this->output)) {
                     $this->errorGif('No thumb', 'generated!', basename($this->input));
                 } else {
                     t3lib_div::fixPermissions($this->output);
                 }
             }
             // The thumbnail is read and output to the browser
             if ($fd = @fopen($this->output, 'rb')) {
                 header('Content-type: image/' . $outext);
                 fpassthru($fd);
                 fclose($fd);
             } else {
                 $this->errorGif('Read problem!', '', $this->output);
             }
         } else {
             exit;
         }
     } else {
         $this->errorGif('No valid', 'inputfile!', basename($this->input));
     }
 }
 /**
  * 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;
 }
Esempio n. 10
0
 /**
  * Returns the contents of a specific file within the ZIP
  *
  * @return	string	contents
  */
 function getZIPFileContents($ZIPfile, $filename)
 {
     if (file_exists($ZIPfile)) {
         // Unzipping SXW file, getting filelist:
         $tempPath = PATH_site . 'typo3temp/tx_tsconfighelp_ziptemp/';
         t3lib_div::mkdir($tempPath);
         $this->unzip($ZIPfile, $tempPath);
         $output = t3lib_div::getURL($tempPath . $filename);
         $cmd = 'rm -r "' . $tempPath . '"';
         t3lib_utility_Command::exec($cmd);
         return $output;
     }
 }
Esempio n. 11
0
    /**
     * Main function. Will generate the information to display for the item set internally.
     *
     * @param	string		<a> tag closing/returning.
     * @return	void
     */
    function renderFileInfo($returnLinkTag)
    {
        // Initialize object to work on the image:
        $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
        $imgObj->init();
        $imgObj->mayScaleUp = 0;
        $imgObj->absPrefix = PATH_site;
        // Read Image Dimensions (returns false if file was not an image type, otherwise dimensions in an array)
        $imgInfo = '';
        $imgInfo = $imgObj->getImageDimensions($this->file);
        // File information
        $fI = t3lib_div::split_fileref($this->file);
        $ext = $fI['fileext'];
        $code = '';
        // Setting header:
        $fileName = t3lib_iconWorks::getSpriteIconForFile($ext) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', TRUE) . ':</strong> ' . $fI['file'];
        if (t3lib_div::isFirstPartOfStr($this->file, PATH_site)) {
            $code .= '<a href="../' . substr($this->file, strlen(PATH_site)) . '" target="_blank">' . $fileName . '</a>';
        } else {
            $code .= $fileName;
        }
        $code .= ' &nbsp;&nbsp;<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.filesize') . ':</strong> ' . t3lib_div::formatSize(@filesize($this->file)) . '<br />
			';
        if (is_array($imgInfo)) {
            $code .= '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.dimensions') . ':</strong> ' . $imgInfo[0] . 'x' . $imgInfo[1] . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.pixels');
        }
        $this->content .= $this->doc->section('', $code);
        $this->content .= $this->doc->divider(2);
        // If the file was an image...:
        if (is_array($imgInfo)) {
            $imgInfo = $imgObj->imageMagickConvert($this->file, 'web', '346', '200m', '', '', '', 1);
            $imgInfo[3] = '../' . substr($imgInfo[3], strlen(PATH_site));
            $code = '<br />
				<div align="center">' . $returnLinkTag . $imgObj->imgTag($imgInfo) . '</a></div>';
            $this->content .= $this->doc->section('', $code);
        } else {
            $this->content .= $this->doc->spacer(10);
            $lowerFilename = strtolower($this->file);
            // Archive files:
            if (TYPO3_OS != 'WIN' && !$GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
                if ($ext == 'zip') {
                    $code = '';
                    $t = array();
                    t3lib_utility_Command::exec('unzip -l ' . $this->file, $t);
                    if (is_array($t)) {
                        reset($t);
                        next($t);
                        next($t);
                        next($t);
                        while (list(, $val) = each($t)) {
                            $parts = explode(' ', trim($val), 7);
                            $code .= '
								' . $parts[6] . '<br />';
                        }
                        $code = '
							<span class="nobr">' . $code . '
							</span>
							<br /><br />';
                    }
                    $this->content .= $this->doc->section('', $code);
                } elseif ($ext == 'tar' || $ext == 'tgz' || substr($lowerFilename, -6) == 'tar.gz' || substr($lowerFilename, -5) == 'tar.z') {
                    $code = '';
                    if ($ext == 'tar') {
                        $compr = '';
                    } else {
                        $compr = 'z';
                    }
                    $t = array();
                    t3lib_utility_Command::exec('tar t' . $compr . 'f ' . $this->file, $t);
                    if (is_array($t)) {
                        foreach ($t as $val) {
                            $code .= '
								' . $val . '<br />';
                        }
                        $code .= '
								 -------<br/>
								 ' . count($t) . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.files');
                        $code = '
							<span class="nobr">' . $code . '
							</span>
							<br /><br />';
                    }
                    $this->content .= $this->doc->section('', $code);
                }
            } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
                $this->content .= $this->doc->section('', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.cannotDisplayArchive'));
            }
            // Font files:
            if ($ext == 'ttf') {
                $thumbScript = 'thumbs.php';
                $check = basename($this->file) . ':' . filemtime($this->file) . ':' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
                $params = '&file=' . rawurlencode($this->file);
                $params .= '&md5sum=' . t3lib_div::shortMD5($check);
                $url = $thumbScript . '?&dummy=' . $GLOBALS['EXEC_TIME'] . $params;
                $thumb = '<br />
					<div align="center">' . $returnLinkTag . '<img src="' . htmlspecialchars($url) . '" border="0" title="' . htmlspecialchars(trim($this->file)) . '" alt="" /></a></div>';
                $this->content .= $this->doc->section('', $thumb);
            }
        }
        // References:
        $this->content .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'), $this->makeRef('_FILE', $this->file));
    }
 /**
  * Creates an array with pointers to divisions of document.
  * ONLY for PDF files at this point. All other types will have an array with a single element with the value "0" (zero) coming back.
  *
  * @param	string		File extension
  * @param	string		Absolute filename (must exist and be validated OK before calling function)
  * @return	array		Array of pointers to sections that the document should be divided into
  */
 function fileContentParts($ext, $absFile)
 {
     $cParts = array(0);
     switch ($ext) {
         case 'pdf':
             // Getting pdf-info:
             $cmd = $this->app['pdfinfo'] . ' ' . escapeshellarg($absFile);
             t3lib_utility_Command::exec($cmd, $res);
             $pdfInfo = $this->splitPdfInfo($res);
             unset($res);
             if (intval($pdfInfo['pages'])) {
                 $cParts = array();
                 // Calculate mode
                 if ($this->pdf_mode > 0) {
                     $iter = ceil($pdfInfo['pages'] / $this->pdf_mode);
                 } else {
                     $iter = t3lib_div::intInRange(abs($this->pdf_mode), 1, $pdfInfo['pages']);
                 }
                 // Traverse and create intervals.
                 for ($a = 0; $a < $iter; $a++) {
                     $low = floor($a * ($pdfInfo['pages'] / $iter)) + 1;
                     $high = floor(($a + 1) * ($pdfInfo['pages'] / $iter));
                     $cParts[] = $low . '-' . $high;
                 }
             }
             break;
     }
     return $cParts;
 }
 /**
  * Unzipping file (action=7)
  * This is permitted only if the user has fullAccess or if the file resides
  *
  * @param	array		$cmds['data'] is the zip-file. $cmds['target'] is the target directory. If not set we'll default to the same directory as the file is in.
  * @return	boolean		Returns true on success
  */
 function func_unzip($cmds)
 {
     if (!$this->isInit || $this->dont_use_exec_commands) {
         return FALSE;
     }
     $theFile = $cmds['data'];
     if (@is_file($theFile)) {
         $fI = t3lib_div::split_fileref($theFile);
         if (!isset($cmds['target'])) {
             $cmds['target'] = $fI['path'];
         }
         $theDest = $this->is_directory($cmds['target']);
         // Clean up destination directory
         if ($theDest) {
             if ($this->actionPerms['unzipFile']) {
                 if ($fI['fileext'] == 'zip') {
                     if ($this->checkIfFullAccess($theDest)) {
                         if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
                             // No way to do this under windows.
                             $cmd = $this->unzipPath . 'unzip -qq "' . $theFile . '" -d "' . $theDest . '"';
                             t3lib_utility_Command::exec($cmd);
                             $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', array($theFile, $theDest));
                             return TRUE;
                         } else {
                             $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', array($theFile, $theDest));
                         }
                     } else {
                         $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
                     }
                 } else {
                     $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
                 }
             } else {
                 $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
             }
         } else {
             $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
         }
     } else {
         $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
     }
 }
 /**
  * execute commandline tool pdfinfo to extract pdf informations from file
  *
  * @param string $file
  * @return array The pdf informations as array
  */
 public function getPdfInfo($file)
 {
     if ($this->fileInfo->getIsFile()) {
         if ($this->fileInfo->getExtension() == 'pdf' && $this->isAppArraySet) {
             $cmd = $this->app['pdfinfo'] . ' ' . escapeshellarg($file);
             if (TYPO3_VERSION_INTEGER >= 7000000) {
                 \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd, $pdfInfoArray);
             } else {
                 t3lib_utility_Command::exec($cmd, $pdfInfoArray);
             }
             $pdfInfo = $this->splitPdfInfo($pdfInfoArray);
             unset($pdfInfoArray);
             return $pdfInfo;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Esempio n. 15
0
 /**
  * Checks if a command is valid or not, updates global variables
  *
  * @param	string		the command that should be executed. eg: "convert"
  * @param	string		executer for the command. eg: "perl"
  * @return	boolean		false if cmd is not found, or -1 if the handler is not found
  */
 public static function checkCommand($cmd, $handler = '')
 {
     if (!self::init()) {
         return FALSE;
     }
     if ($handler && !self::checkCommand($handler)) {
         return -1;
     }
     // Already checked and valid
     if (self::$applications[$cmd]['valid']) {
         return TRUE;
     }
     // Is set but was (above) not true
     if (isset(self::$applications[$cmd]['valid'])) {
         return FALSE;
     }
     foreach (self::$paths as $path => $validPath) {
         // Ignore invalid (false) paths
         if ($validPath) {
             if (TYPO3_OS == 'WIN') {
                 // Windows OS
                 // TODO Why is_executable() is not called here?
                 if (@is_file($path . $cmd)) {
                     self::$applications[$cmd]['app'] = $cmd;
                     self::$applications[$cmd]['path'] = $path;
                     self::$applications[$cmd]['valid'] = TRUE;
                     return TRUE;
                 }
                 if (@is_file($path . $cmd . '.exe')) {
                     self::$applications[$cmd]['app'] = $cmd . '.exe';
                     self::$applications[$cmd]['path'] = $path;
                     self::$applications[$cmd]['valid'] = TRUE;
                     return TRUE;
                 }
             } else {
                 // Unix-like OS
                 $filePath = realpath($path . $cmd);
                 if ($filePath && @is_executable($filePath)) {
                     self::$applications[$cmd]['app'] = $cmd;
                     self::$applications[$cmd]['path'] = $path;
                     self::$applications[$cmd]['valid'] = TRUE;
                     return TRUE;
                 }
             }
         }
     }
     // Try to get the executable with the command 'which'.
     // It does the same like already done, but maybe on other paths
     if (TYPO3_OS != 'WIN') {
         $cmd = @t3lib_utility_Command::exec('which ' . $cmd);
         if (@is_executable($cmd)) {
             self::$applications[$cmd]['app'] = $cmd;
             self::$applications[$cmd]['path'] = dirname($cmd) . '/';
             self::$applications[$cmd]['valid'] = TRUE;
             return TRUE;
         }
     }
     return FALSE;
 }