本文整理汇总了PHP中TYPO3\CMS\Core\Utility\CommandUtility类的典型用法代码示例。如果您正苦于以下问题:PHP CommandUtility类的具体用法?PHP CommandUtility怎么用?PHP CommandUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* 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: createFont
/**
* 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: render
/**
* @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: findImageMagick6InPaths
/**
* 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: isDiffToolAvailable
/**
* 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: parseCoreData
/**
* @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: startServerAction
/**
* 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: render
/**
* @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: render
/**
* @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: findGraphicsMagickInPaths
/**
* 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;
}
示例11: getContent
/**
* 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: readPngGif
/**
* 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: checkExec
/**
* 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: isAvailable
/**
* 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: _checkImageMagick_getVersion
/**
* 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);
}