コード例 #1
0
 /**
  * This method actually does the processing of files locally
  *
  * takes the original file (on remote storages this will be fetched from the remote server)
  * does the IM magic on the local server by creating a temporary typo3temp/ file
  * copies the typo3temp/ file to the processing folder of the target storage
  * removes the typo3temp/ file
  *
  * @param TaskInterface $task
  * @return array
  */
 public function process(TaskInterface $task)
 {
     $targetFile = $task->getTargetFile();
     // Merge custom configuration with default configuration
     $configuration = array_merge(array('width' => 64, 'height' => 64), $task->getConfiguration());
     $configuration['width'] = Utility\MathUtility::forceIntegerInRange($configuration['width'], 1, 1000);
     $configuration['height'] = Utility\MathUtility::forceIntegerInRange($configuration['height'], 1, 1000);
     $originalFileName = $targetFile->getOriginalFile()->getForLocalProcessing(FALSE);
     // Create a temporary file in typo3temp/
     if ($targetFile->getOriginalFile()->getExtension() === 'jpg') {
         $targetFileExtension = '.jpg';
     } else {
         $targetFileExtension = '.png';
     }
     // Create the thumb filename in typo3temp/preview_....jpg
     $temporaryFileName = Utility\GeneralUtility::tempnam('preview_') . $targetFileExtension;
     // Check file extension
     if ($targetFile->getOriginalFile()->getType() != Resource\File::FILETYPE_IMAGE && !Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $targetFile->getOriginalFile()->getExtension())) {
         // Create a default image
         $this->processor->getTemporaryImageWithText($temporaryFileName, 'Not imagefile!', 'No ext!', $targetFile->getOriginalFile()->getName());
     } else {
         // Create the temporary file
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . $this->processor->wrapFileName($originalFileName) . '[0] ' . $this->processor->wrapFileName($temporaryFileName);
             $cmd = Utility\GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1';
             Utility\CommandUtility::exec($cmd);
             if (!file_exists($temporaryFileName)) {
                 // Create a error gif
                 $this->processor->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', $targetFile->getOriginalFile()->getName());
             }
         }
     }
     return array('filePath' => $temporaryFileName);
 }
コード例 #2
0
 /**
  * create Font via Python with FontForge
  *
  * @param int $fontUid
  * @param object $currentFont
  * @return array
  */
 public static function createFont($fontUid, $currentFont)
 {
     // general vars
     $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fontawesomeplus']);
     $pathToPythonBin = escapeshellarg($extConf['pathToPython']);
     $pathToScript = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('fontawesomeplus') . 'Resources/Private/Python/fontawesomeplus.py';
     $iconRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\FileRepository::class);
     $iconReferences = $iconRepository->findByRelation('tx_fontawesomeplus_domain_model_font', 'icons', $fontUid);
     $svgArray = array();
     foreach ($iconReferences as $key => $value) {
         $svgArray[$key] = PATH_site . 'fileadmin' . $value->getIdentifier();
     }
     $unicodeArray = array();
     $i = hexdec(self::HEXADECIMAL);
     foreach ($svgArray as $key => $value) {
         $unicodeArray[$key] = $i . ',uni' . dechex($i);
         $i++;
     }
     $fontPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('fontawesomeplus') . 'Resources/Public/Contrib/' . self::FACONTRIB . '/fonts/fontawesome-webfont.svg';
     $fontForgeArray = CommandUtility::escapeShellArgument(json_encode(array_combine($svgArray, $unicodeArray), JSON_UNESCAPED_SLASHES));
     $fontName = strtolower(preg_replace(array('/\\s+/', '/[^a-zA-Z0-9]/'), array('-', ''), $currentFont->getTitle()));
     $comment = CommandUtility::escapeShellArgument(str_replace(array("\r\n", "\n", "\r"), ' ', $currentFont->getDescription()));
     $copyright = CommandUtility::escapeShellArgument('netweiser');
     $version = CommandUtility::escapeShellArgument($currentFont->getVersion());
     GeneralUtility::mkdir_deep(PATH_site . 'fileadmin/' . $currentFont->getDestination(), $fontName . '/fonts/');
     $savedir = PATH_site . 'fileadmin/' . $currentFont->getDestination() . $fontName . '/fonts/';
     CommandUtility::exec("{$pathToPythonBin} {$pathToScript} {$fontPath} {$fontForgeArray} {$fontName} {$comment} {$copyright} {$version} {$savedir} 2>&1", $feedback, $returnCode);
     if ((int) $returnCode !== 0) {
         return $feedback;
     }
 }
コード例 #3
0
ファイル: MarkdownViewHelper.php プロジェクト: fluidtypo3/vhs
 /**
  * @param string $text
  * @param boolean $trim
  * @param boolean $htmlentities
  * @throws Exception
  * @return string
  */
 public function render($text = null, $trim = true, $htmlentities = false)
 {
     if (null === $text) {
         $text = $this->renderChildren();
     }
     if (null === $text) {
         return null;
     }
     $cacheIdentifier = sha1($text);
     if (true === $this->cache->has($cacheIdentifier)) {
         return $this->cache->get($cacheIdentifier);
     }
     $this->markdownExecutablePath = CommandUtility::getCommand('markdown');
     if (false === is_executable($this->markdownExecutablePath)) {
         throw new Exception('Use of Markdown requires the "markdown" shell utility to be installed and accessible; this binary ' . 'could not be found in any of your configured paths available to this script', 1350511561);
     }
     if (true === (bool) $trim) {
         $text = trim($text);
     }
     if (true === (bool) $htmlentities) {
         $text = htmlentities($text);
     }
     $transformed = $this->transform($text);
     $this->cache->set($cacheIdentifier, $transformed);
     return $transformed;
 }
コード例 #4
0
 /**
  * Search for GraphicsMagick executables in given paths.
  *
  * @param array $searchPaths List of paths to search for
  * @return bool TRUE if graphics magick was found in path
  */
 protected function findImageMagick6InPaths(array $searchPaths)
 {
     $result = FALSE;
     foreach ($searchPaths as $path) {
         if (TYPO3_OS === 'WIN') {
             $executable = 'identify.exe';
         } else {
             $executable = 'identify';
         }
         if (@is_file($path . $executable)) {
             $command = escapeshellarg($path . $executable) . ' -version';
             $executingResult = FALSE;
             \TYPO3\CMS\Core\Utility\CommandUtility::exec($command, $executingResult);
             // First line of exec command should contain string GraphicsMagick
             $firstResultLine = array_shift($executingResult);
             // Example: "Version: ImageMagick 6.6.0-4 2012-05-02 Q16 http://www.imagemagick.org"
             if (strpos($firstResultLine, 'ImageMagick') !== FALSE) {
                 list(, $version) = explode('ImageMagick', $firstResultLine);
                 // Example: "6.6.0-4"
                 list($version) = explode(' ', trim($version));
                 if (version_compare($version, '6.0.0') >= 0) {
                     $this->foundPath = $path;
                     $result = TRUE;
                     break;
                 }
             }
         }
     }
     return $result;
 }
コード例 #5
0
 /**
  * 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 bool TRUE if a diff tool was found, FALSE otherwise
  */
 protected function isDiffToolAvailable()
 {
     $filePath = ExtensionManagementUtility::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();
     CommandUtility::exec($executeCommand, $result);
     return empty($result);
 }
コード例 #6
0
ファイル: CoreDataParser.php プロジェクト: rabe69/yag
 /**
  * @param $filePath
  * @return array
  */
 public function parseCoreData($filePath)
 {
     $imageMagicCommand = \TYPO3\CMS\Core\Utility\GeneralUtility::imageMagickCommand('identify', '-verbose');
     $imageMagicCommand .= ' ' . $filePath;
     \TYPO3\CMS\Core\Utility\CommandUtility::exec($imageMagicCommand, $result);
     $data = array();
     foreach ($result as $resultLine) {
         $chunks = explode(':', $resultLine);
         $data[trim($chunks[0])] = trim($chunks[1]);
     }
     return array('colorSpace' => $this->parseColorSpace($data), 'dpi' => $this->parseDPI($data));
 }
コード例 #7
0
 /**
  * Starts the Tika server
  *
  * @return void
  */
 public function startServerAction()
 {
     $command = CommandUtility::getCommand('java') . ' -jar ' . escapeshellarg(GeneralUtility::getFileAbsFileName($this->tikaConfiguration['tikaServerPath'], FALSE)) . ' -p ' . escapeshellarg($this->tikaConfiguration['tikaServerPort']);
     $command = escapeshellcmd($command);
     $process = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Tika\\Process', $command);
     $pid = $process->getPid();
     $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
     $registry->set('tx_tika', 'server.pid', $pid);
     // wait for Tika to start so that when we return to indexAction
     // it shows Tika running
     sleep(2);
     $this->forwardToIndex();
 }
コード例 #8
0
 /**
  * @return string
  */
 public function render()
 {
     $path = GeneralUtility::getFileAbsFileName($this->arguments['path']);
     if (FALSE === file_exists($path)) {
         return NULL;
     }
     $density = $this->arguments['density'];
     $rotate = $this->arguments['rotate'];
     $page = intval($this->arguments['page']);
     $background = $this->arguments['background'];
     $forceOverwrite = (bool) $this->arguments['forceOverwrite'];
     $width = $this->arguments['width'];
     $height = $this->arguments['height'];
     $minWidth = $this->arguments['minWidth'];
     $minHeight = $this->arguments['minHeight'];
     $maxWidth = $this->arguments['maxWidth'];
     $maxHeight = $this->arguments['maxHeight'];
     $filename = basename($path);
     $pageArgument = $page > 0 ? $page - 1 : 0;
     $colorspace = TRUE === isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace']) ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'] : 'RGB';
     $destination = GeneralUtility::getFileAbsFileName('typo3temp/vhs-pdf-' . $filename . '-page' . $page . '.png');
     if (FALSE === file_exists($destination) || TRUE === $forceOverwrite) {
         $arguments = '-colorspace ' . $colorspace;
         if (0 < intval($density)) {
             $arguments .= ' -density ' . $density;
         }
         if (0 !== intval($rotate)) {
             $arguments .= ' -rotate ' . $rotate;
         }
         $arguments .= ' "' . $path . '"[' . $pageArgument . ']';
         if (NULL !== $background) {
             $arguments .= ' -background "' . $background . '" -flatten';
         }
         $arguments .= ' "' . $destination . '"';
         $command = CommandUtility::imageMagickCommand('convert', $arguments);
         CommandUtility::exec($command);
     }
     $image = substr($destination, strlen(PATH_site));
     return parent::render($image, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
 }
コード例 #9
0
 /**
  * @return string
  */
 public function render()
 {
     $src = GeneralUtility::getFileAbsFileName($this->arguments['src']);
     if (false === file_exists($src)) {
         return null;
     }
     $density = $this->arguments['density'];
     $rotate = $this->arguments['rotate'];
     $page = (int) $this->arguments['page'];
     $background = $this->arguments['background'];
     $forceOverwrite = (bool) $this->arguments['forceOverwrite'];
     $filename = basename($src);
     $pageArgument = $page > 0 ? $page - 1 : 0;
     if (isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'])) {
         $colorspace = $GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'];
     } else {
         $colorspace = 'RGB';
     }
     $path = GeneralUtility::getFileAbsFileName('typo3temp/vhs-pdf-' . $filename . '-page' . $page . '.png');
     if (false === file_exists($path) || true === $forceOverwrite) {
         $arguments = '-colorspace ' . $colorspace;
         if (0 < (int) $density) {
             $arguments .= ' -density ' . $density;
         }
         if (0 !== (int) $rotate) {
             $arguments .= ' -rotate ' . $rotate;
         }
         $arguments .= ' "' . $src . '"[' . $pageArgument . ']';
         if (null !== $background) {
             $arguments .= ' -background "' . $background . '" -flatten';
         }
         $arguments .= ' "' . $path . '"';
         $command = CommandUtility::imageMagickCommand('convert', $arguments);
         CommandUtility::exec($command);
     }
     $this->preprocessImage($path);
     return $this->renderTag();
 }
コード例 #10
0
 /**
  * Search for GraphicsMagick executables in given paths.
  *
  * @param array $searchPaths List of pathes to search for
  * @return boolean TRUE if graphics magick was found in path
  */
 protected function findGraphicsMagickInPaths(array $searchPaths)
 {
     $result = FALSE;
     foreach ($searchPaths as $path) {
         if (TYPO3_OS === 'WIN') {
             $executable = 'gm.exe';
         } else {
             $executable = 'gm';
         }
         if (@is_file($path . $executable)) {
             $command = escapeshellarg($path . $executable) . ' -version';
             $executingResult = FALSE;
             \TYPO3\CMS\Core\Utility\CommandUtility::exec($command, $executingResult);
             // First line of exec command should contain string GraphicsMagick
             $firstResultLine = array_shift($executingResult);
             if (strpos($firstResultLine, 'GraphicsMagick') !== FALSE) {
                 $this->foundPath = $path;
                 $result = TRUE;
                 break;
             }
         }
     }
     return $result;
 }
 /**
  * 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
     $tempFileName = GeneralUtility::tempnam('xls_files-Indexer');
     // Delete if exists, just to be safe.
     @unlink($tempFileName);
     // generate and execute the pdftotext commandline tool
     $fileEscaped = CommandUtility::escapeShellArgument($file);
     $cmd = "{$this->app['xls2csv']} -c ' ' -q 0 -s8859-1 -dutf-8 {$fileEscaped} > {$tempFileName}";
     CommandUtility::exec($cmd);
     // check if the tempFile was successfully created
     if (@is_file($tempFileName)) {
         $content = GeneralUtility::getUrl($tempFileName);
         unlink($tempFileName);
     } else {
         return false;
     }
     // check if content was found
     if (strlen($content)) {
         return $content;
     } else {
         return false;
     }
 }
コード例 #12
0
 /**
  * Returns filename of the png/gif version of the input file (which can be png or gif).
  * If input file type does not match the wanted output type a conversion is made and temp-filename returned.
  *
  * @param string $theFile Filepath of image file
  * @param bool $output_png If TRUE, then input file is converted to PNG, otherwise to GIF
  * @return string|NULL If the new image file exists, its filepath is returned
  */
 public static function readPngGif($theFile, $output_png = false)
 {
     if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_enabled'] || !@is_file($theFile)) {
         return null;
     }
     $ext = strtolower(substr($theFile, -4, 4));
     if ((string) $ext == '.png' && $output_png || (string) $ext == '.gif' && !$output_png) {
         return $theFile;
     }
     if (!@is_dir(PATH_site . 'typo3temp/assets/images/')) {
         GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
     }
     $newFile = PATH_site . 'typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
     $cmd = GeneralUtility::imageMagickCommand('convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_path']);
     CommandUtility::exec($cmd);
     if (@is_file($newFile)) {
         GeneralUtility::fixPermissions($newFile);
         return $newFile;
     }
     return null;
 }
コード例 #13
0
 /**
  * check the availability of external programs
  *
  * @param string $progList Comma list of programs 'perl,python,pdftotext'
  * @return boolean Return FALSE if one program was not found
  * @todo Define visibility
  */
 public function checkExec($progList)
 {
     $ret = TRUE;
     $progList = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $progList, TRUE);
     foreach ($progList as $prog) {
         if (!\TYPO3\CMS\Core\Utility\CommandUtility::checkCommand($prog)) {
             // Program not found
             $this->errorPush(T3_ERR_SV_PROG_NOT_FOUND, 'External program not found: ' . $prog);
             $ret = FALSE;
         }
     }
     return $ret;
 }
コード例 #14
0
 /**
  * Checks if command line version of the OpenSSL is available and can be
  * executed successfully.
  *
  * @return bool
  * @see \TYPO3\CMS\Rsaauth\Backend\AbstractBackend::isAvailable()
  */
 public function isAvailable()
 {
     $result = FALSE;
     if ($this->opensslPath) {
         // If path exists, test that command runs and can produce output
         $test = CommandUtility::exec($this->opensslPath . ' version');
         $result = substr($test, 0, 8) === 'OpenSSL ';
     }
     return $result;
 }
コード例 #15
0
ファイル: Installer.php プロジェクト: noxludo/TYPO3v4-Core
 /**
  * Extracts the version number for ImageMagick
  *
  * @param string $file The program name to execute in order to find out the version number
  * @param string $path Path for the above program
  * @return string Version number of the found ImageMagick instance
  * @todo Define visibility
  */
 public function _checkImageMagick_getVersion($file, $path)
 {
     // Temporarily override some settings
     $im_version = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'];
     $combine_filename = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_combine_filename'];
     if ($file == 'gm') {
         $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] = 'gm';
         // Work-around, preventing execution of "gm gm"
         $file = 'identify';
         // Work-around - GM doesn't like to be executed without any arguments
         $parameters = '-version';
     } else {
         $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] = 'im5';
         // Override the combine_filename setting
         if ($file == 'combine' || $file == 'composite') {
             $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_combine_filename'] = $file;
         }
     }
     $cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::imageMagickCommand($file, $parameters, $path);
     $retVal = FALSE;
     \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd, $retVal);
     $string = $retVal[0];
     list(, $ver) = explode('Magick', $string);
     list($ver) = explode(' ', trim($ver));
     // Restore the values
     $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] = $im_version;
     $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_combine_filename'] = $combine_filename;
     return trim($ver);
 }
コード例 #16
0
 /**
  * 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 \TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand($command, $parameters, $path);
 }
コード例 #17
0
ファイル: StatusCheck.php プロジェクト: bauschan/tika
 /**
  * Checks whether the extension is configured to use a local Tika
  * application, and if so whether it's correctly configured.
  *
  * @return boolean TRUE if the extension is configured to use a local Tika app and if it's correctly configured, FALSE otherwise
  */
 protected function hasCompleteLocalTikaConfiguration()
 {
     $localConfigurationComplete = FALSE;
     if ($this->tikaConfiguration['extractor'] == 'tika' && is_file(GeneralUtility::getFileAbsFileName($this->tikaConfiguration['tikaPath'], FALSE)) && CommandUtility::checkCommand('java')) {
         $localConfigurationComplete = TRUE;
     }
     if ($this->tikaConfiguration['logging']) {
         $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
         $registryStatus = $registry->get('Tx_Tika', 'available');
         GeneralUtility::devLog('Has complete local Tika configuration: ' . ($localConfigurationComplete == TRUE ? 'yes' : 'no'), 'tika', 0, array('configuration' => $this->tikaConfiguration, 'javaFound' => CommandUtility::checkCommand('java'), 'tikaPath' => $this->tikaConfiguration['tikaPath'], 'absoluteTikaPath' => GeneralUtility::getFileAbsFileName($this->tikaConfiguration['tikaPath'], FALSE), 'absoluteTikaExists' => is_file(GeneralUtility::getFileAbsFileName($this->tikaConfiguration['tikaPath'], FALSE)) == TRUE ? 'yes' : 'no', 'registryStatus' => $registryStatus));
     }
     return $localConfigurationComplete;
 }
コード例 #18
0
 /**
  * Gets the current GIT revision and branch
  *
  * @return void
  */
 protected function getGitRevision()
 {
     if (!StringUtility::endsWith(TYPO3_version, '-dev') || \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::isFunctionDisabled('exec')) {
         return;
     }
     // check if git exists
     CommandUtility::exec('git --version', $_, $returnCode);
     if ((int) $returnCode !== 0) {
         // git is not available
         return;
     }
     $revision = trim(CommandUtility::exec('git rev-parse --short HEAD'));
     $branch = trim(CommandUtility::exec('git rev-parse --abbrev-ref HEAD'));
     if (!empty($revision) && !empty($branch)) {
         $this->systemInformation[] = array('title' => htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.gitrevision')), 'value' => sprintf('%s [%s]', $revision, $branch), 'icon' => $this->iconFactory->getIcon('sysinfo-git', Icon::SIZE_SMALL)->render());
     }
 }
コード例 #19
0
ファイル: Scheduler.php プロジェクト: rickymathew/TYPO3.CMS
 /**
  * Schedule the next run of scheduler
  * For the moment only the "at"-daemon is used, and only if it is enabled
  *
  * @return bool Successfully scheduled next execution using "at"-daemon
  * @see tx_scheduler::fetchTask()
  */
 public function scheduleNextSchedulerRunUsingAtDaemon()
 {
     if ((int) $this->extConf['useAtdaemon'] !== 1) {
         return false;
     }
     /** @var $registry Registry */
     $registry = GeneralUtility::makeInstance(Registry::class);
     // Get at job id from registry and remove at job
     $atJobId = $registry->get('tx_scheduler', 'atJobId');
     if (MathUtility::canBeInterpretedAsInteger($atJobId)) {
         shell_exec('atrm ' . (int) $atJobId . ' 2>&1');
     }
     // Can not use fetchTask() here because if tasks have just executed
     // they are not in the list of next executions
     $tasks = $this->fetchTasksWithCondition('');
     $nextExecution = false;
     foreach ($tasks as $task) {
         try {
             /** @var $task Task\AbstractTask */
             $tempNextExecution = $task->getNextDueExecution();
             if ($nextExecution === false || $tempNextExecution < $nextExecution) {
                 $nextExecution = $tempNextExecution;
             }
         } catch (\OutOfBoundsException $e) {
             // The event will not be executed again or has already ended - we don't have to consider it for
             // scheduling the next "at" run
         }
     }
     if ($nextExecution !== false) {
         if ($nextExecution > $GLOBALS['EXEC_TIME']) {
             $startTime = strftime('%H:%M %F', $nextExecution);
         } else {
             $startTime = 'now+1minute';
         }
         $cliDispatchPath = PATH_site . 'typo3/cli_dispatch.phpsh';
         list($cliDispatchPathEscaped, $startTimeEscaped) = CommandUtility::escapeShellArguments(array($cliDispatchPath, $startTime));
         $cmd = 'echo ' . $cliDispatchPathEscaped . ' scheduler | at ' . $startTimeEscaped . ' 2>&1';
         $output = shell_exec($cmd);
         $outputParts = '';
         foreach (explode(LF, $output) as $outputLine) {
             if (GeneralUtility::isFirstPartOfStr($outputLine, 'job')) {
                 $outputParts = explode(' ', $outputLine, 3);
                 break;
             }
         }
         if ($outputParts[0] === 'job' && MathUtility::canBeInterpretedAsInteger($outputParts[1])) {
             $atJobId = (int) $outputParts[1];
             $registry->set('tx_scheduler', 'atJobId', $atJobId);
         }
     }
     return true;
 }
コード例 #20
0
    /**
     * This method assembles a list of all defined executables search paths
     *
     * @return string HTML to display
     */
    protected function renderExecutablesSearchPathList()
    {
        $searchPaths = CommandUtility::getPaths(TRUE);
        $content = '<h3>' . $this->getLanguageService()->getLL('search_paths') . '</h3>';
        if (empty($searchPaths)) {
            $content .= '<p>' . $this->getLanguageService()->getLL('no_search_paths') . '</p>';
        } else {
            $content .= '
			<table class="table table-striped table-hover tx_sv_reportlist">
				<thead>
					<tr>
						<td>' . $this->getLanguageService()->getLL('path') . '</td>
						<td>' . $this->getLanguageService()->getLL('valid') . '</td>
					</tr>
				</thead>
				<tbody>';
            foreach ($searchPaths as $path => $isValid) {
                $pathAccessibleClass = 'danger';
                $pathAccessible = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:no');
                if ($isValid) {
                    $pathAccessibleClass = 'success';
                    $pathAccessible = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:yes');
                }
                $content .= '
					<tr class="' . $pathAccessibleClass . '">
						<td class="first-cell">' . GeneralUtility::fixWindowsFilePath($path) . '</td>
						<td class="last-cell">' . $pathAccessible . '</td>
					</tr>';
            }
            $content .= '
				</tbody>
			</table>';
        }
        return $content;
    }
コード例 #21
0
ファイル: TestSetup.php プロジェクト: rickymathew/TYPO3.CMS
 /**
  * Determine ImageMagick / GraphicsMagick version
  *
  * @return string Version
  */
 protected function determineImageMagickVersion()
 {
     $command = \TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand('identify', '-version');
     \TYPO3\CMS\Core\Utility\CommandUtility::exec($command, $result);
     $string = $result[0];
     list(, $version) = explode('Magick', $string);
     list($version) = explode(' ', trim($version));
     return trim($version);
 }
コード例 #22
0
ファイル: GeneralUtility.php プロジェクト: Gregpl/TYPO3.CMS
 /**
  * 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 CommandUtility::imageMagickCommand($command, $parameters, $path);
 }
コード例 #23
0
 /**
  * @param string $originalFileName
  * @param string $temporaryFileName
  * @param array $configuration
  */
 protected function resizeImage($originalFileName, $temporaryFileName, $configuration)
 {
     // Create the temporary file
     if (empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['im'])) {
         return;
     }
     if (file_exists($originalFileName)) {
         $arguments = CommandUtility::escapeShellArguments(array('width' => $configuration['width'], 'height' => $configuration['height'], 'originalFileName' => $originalFileName, 'temporaryFileName' => $temporaryFileName));
         $parameters = '-sample ' . $arguments['width'] . 'x' . $arguments['height'] . ' ' . $arguments['originalFileName'] . '[0] ' . $arguments['temporaryFileName'];
         $cmd = GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1';
         CommandUtility::exec($cmd);
     }
     if (!file_exists($temporaryFileName)) {
         // Create a error image
         $graphicalFunctions = $this->getGraphicalFunctionsObject();
         $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', basename($originalFileName));
     }
 }
コード例 #24
0
 /**
  * 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);
             \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd, $pdfInfoArray);
             $pdfInfo = $this->splitPdfInfo($pdfInfoArray);
             unset($pdfInfoArray);
             return $pdfInfo;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #25
0
 /**
  * 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 ImageMagick & GraphicsMagick
  * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9. - use CommandUtility directly
  */
 public static function imageMagickCommand($command, $parameters, $path = '')
 {
     self::logDeprecatedFunction();
     return CommandUtility::imageMagickCommand($command, $parameters, $path);
 }
コード例 #26
0
ファイル: AppService.php プロジェクト: AndreasA/ext-tika
 /**
  * The actual language detection
  *
  * @param string $localFilePath Path to a local file
  * @return string The file content's language
  */
 protected function detectLanguageFromLocalFile($localFilePath)
 {
     $tikaCommand = CommandUtility::getCommand('java') . ' -Dfile.encoding=UTF8' . ' -jar ' . escapeshellarg(GeneralUtility::getFileAbsFileName($this->configuration['tikaPath'], FALSE)) . ' -l' . ' ' . escapeshellarg($localFilePath);
     $language = trim(shell_exec($tikaCommand));
     $this->log('Language Detection using local Tika', array('file' => $localFilePath, 'tika command' => $tikaCommand, 'shell output' => $language));
     return $language;
 }
コード例 #27
0
 /**
  * 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 $ext File extension
  * @param string $absFile 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
  */
 public function fileContentParts($ext, $absFile)
 {
     $cParts = array(0);
     switch ($ext) {
         case 'pdf':
             $this->setLocaleForServerFileSystem();
             // Getting pdf-info:
             $cmd = $this->app['pdfinfo'] . ' ' . escapeshellarg($absFile);
             \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd, $res);
             $pdfInfo = $this->splitPdfInfo($res);
             unset($res);
             if ((int) $pdfInfo['pages']) {
                 $cParts = array();
                 // Calculate mode
                 if ($this->pdf_mode > 0) {
                     $iter = ceil($pdfInfo['pages'] / $this->pdf_mode);
                 } else {
                     $iter = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(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;
                 }
             }
             $this->setLocaleForServerFileSystem(TRUE);
             break;
         default:
     }
     return $cParts;
 }
コード例 #28
0
ファイル: ThumbnailView.php プロジェクト: khanhdeux/typo3test
 /**
  * Create the thumbnail
  * Will exit before return if all is well.
  *
  * @return void
  * @todo Define visibility
  */
 public function main()
 {
     // Clean output buffer to ensure no extraneous output exists
     ob_clean();
     // If file exists, we make a thumbnail of the file.
     if (is_object($this->image)) {
         // Check file extension:
         if ($this->image->getExtension() == 'ttf') {
             // Make font preview... (will not return)
             $this->fontGif($this->image);
         } elseif ($this->image->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $this->image->getExtension())) {
             $this->errorGif('Not imagefile!', 'No ext!', $this->image->getName());
         }
         // ... so we passed the extension test meaning that we are going to make a thumbnail here:
         // default
         if (!$this->size) {
             $this->size = $this->sizeDefault;
         }
         // 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.
         // explodes the input size (and if no "x" is found this will add size again so it is the same for both dimensions)
         $sizeParts = explode('x', $this->size . 'x' . $this->size);
         // Cleaning it up, only two parameters now.
         $sizeParts = array(MathUtility::forceIntegerInRange($sizeParts[0], 1, 1000), MathUtility::forceIntegerInRange($sizeParts[1], 1, 1000));
         // Imploding the cleaned size-value back to the internal variable
         $this->size = implode('x', $sizeParts);
         // Getting max value
         $sizeMax = max($sizeParts);
         // Init
         $outpath = PATH_site . $this->outdir;
         // Should be - ? 'png' : 'gif' - , but doesn't work (ImageMagick prob.?)
         // René: png work for me
         $thmMode = MathUtility::forceIntegerInRange($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png'], 0);
         $outext = $this->image->getExtension() != 'jpg' || $thmMode & 2 ? $thmMode & 1 ? 'png' : 'gif' : 'jpg';
         $outfile = 'tmb_' . substr(md5($this->image->getName() . $this->mtime . $this->size), 0, 10) . '.' . $outext;
         $this->output = $outpath . $outfile;
         if ($GLOBALS['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->image->getForLocalProcessing(FALSE)) . '[0] ' . $this->wrapFileName($this->output);
                 $cmd = GeneralUtility::imageMagickCommand('convert', $parameters);
                 \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd);
                 if (!file_exists($this->output)) {
                     $this->errorGif('No thumb', 'generated!', $this->image->getName());
                 } else {
                     GeneralUtility::fixPermissions($this->output);
                 }
             }
             // The thumbnail is read and output to the browser
             if ($fd = @fopen($this->output, 'rb')) {
                 $fileModificationTime = filemtime($this->output);
                 header('Content-Type: image/' . ($outext === 'jpg' ? 'jpeg' : $outext));
                 header('Last-Modified: ' . date('r', $fileModificationTime));
                 header('ETag: ' . md5($this->output) . '-' . $fileModificationTime);
                 // Expiration time is chosen arbitrary to 1 month
                 header('Expires: ' . date('r', $fileModificationTime + 30 * 24 * 60 * 60));
                 fpassthru($fd);
                 fclose($fd);
             } else {
                 $this->errorGif('Read problem!', '', $this->output);
             }
         } else {
             die;
         }
     } else {
         $this->errorGif('No valid', 'inputfile!', basename($this->image));
     }
 }
コード例 #29
0
 /**
  * Check if a given service is available, based on the executable files it depends on
  *
  * @param string $serviceType Type of service
  * @param string $serviceKey Specific key of the service
  * @param array $serviceDetails Information about the service
  * @return bool Service availability
  */
 public static function isServiceAvailable($serviceType, $serviceKey, $serviceDetails)
 {
     // If the service depends on external programs - check if they exists
     if (trim($serviceDetails['exec'])) {
         $executables = GeneralUtility::trimExplode(',', $serviceDetails['exec'], true);
         foreach ($executables as $executable) {
             // If at least one executable file is not available, exit early returning FALSE
             if (!CommandUtility::checkCommand($executable)) {
                 self::deactivateService($serviceType, $serviceKey);
                 return false;
             }
         }
     }
     // The service is available
     return true;
 }
コード例 #30
0
 /**
  * Unzipping file (action=7)
  * This is permitted only if the user has fullAccess or if the file resides
  *
  * @param array $cmds $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 bool Returns TRUE on success
  */
 public function func_unzip($cmds)
 {
     if (!$this->isInit || $this->dont_use_exec_commands) {
         return FALSE;
     }
     $theFile = $cmds['data'];
     if (!@is_file($theFile)) {
         $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
         return FALSE;
     }
     $fI = GeneralUtility::split_fileref($theFile);
     if (!isset($cmds['target'])) {
         $cmds['target'] = $fI['path'];
     }
     // Clean up destination directory
     // !!! Method has been put in the local driver, can be saftely removed
     $theDest = $this->is_directory($cmds['target']);
     if (!$theDest) {
         $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
         return FALSE;
     }
     if (!$this->actionPerms['unzipFile']) {
         $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
         return FALSE;
     }
     if ($fI['fileext'] != 'zip') {
         $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
         return FALSE;
     }
     if (!$this->checkIfFullAccess($theDest)) {
         $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
         return FALSE;
     }
     // !!! Method has been put in the sotrage driver, can be saftely removed
     if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
         // No way to do this under windows.
         $cmd = $this->unzipPath . 'unzip -qq ' . escapeshellarg($theFile) . ' -d ' . escapeshellarg($theDest);
         CommandUtility::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));
         return FALSE;
     }
 }