[TASK] Remove XCLASS definitions from cache classes
[Packages/TYPO3.CMS.git] / t3lib / utility / class.t3lib_utility_command.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Class to handle system commands.
30 *
31 * @author Steffen Kamper <steffen@typo3.org>
32 */
33 final class t3lib_utility_Command {
34
35
36 /**
37 * Wrapper function for php exec function
38 * Needs to be central to have better control and possible fix for issues
39 *
40 * @static
41 * @param string $command
42 * @param NULL|array $output
43 * @param integer $returnValue
44 * @return NULL|array
45 */
46 public static function exec($command, &$output = NULL, &$returnValue = 0) {
47 if (TYPO3_OS == 'WIN' && version_compare(phpversion(), '5.3.0', '<')) {
48 $command = '"' . $command . '"';
49 }
50 $lastLine = exec($command, $output, $returnValue);
51 return $lastLine;
52 }
53
54 /**
55 * Compile the command for running ImageMagick/GraphicsMagick.
56 *
57 * @param string Command to be run: identify, convert or combine/composite
58 * @param string The parameters string
59 * @param string Override the default path (e.g. used by the install tool)
60 * @return string Compiled command that deals with IM6 & GraphicsMagick
61 */
62 public static function imageMagickCommand($command, $parameters, $path = '') {
63 $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
64 $isExt = (TYPO3_OS == 'WIN' ? '.exe' : '');
65 $switchCompositeParameters = FALSE;
66
67 if (!$path) {
68 $path = $gfxConf['im_path'];
69 }
70 $path = t3lib_div::fixWindowsFilePath($path);
71
72 $im_version = strtolower($gfxConf['im_version_5']);
73 $combineScript = $gfxConf['im_combine_filename'] ? trim($gfxConf['im_combine_filename']) : 'combine';
74
75 if ($command === 'combine') { // This is only used internally, has no effect outside
76 $command = 'composite';
77 }
78
79 // Compile the path & command
80 if ($im_version === 'gm') {
81 $switchCompositeParameters = TRUE;
82 $path = escapeshellarg($path . 'gm' . $isExt) . ' ' . $command;
83 } else {
84 if ($im_version === 'im6') {
85 $switchCompositeParameters = TRUE;
86 }
87 $path = escapeshellarg($path . (($command == 'composite') ? $combineScript : $command) . $isExt);
88 }
89
90 // strip profile information for thumbnails and reduce their size
91 if ($parameters && $command != 'identify' && $gfxConf['im_useStripProfileByDefault'] && $gfxConf['im_stripProfileCommand'] != '') {
92 if (strpos($parameters, $gfxConf['im_stripProfileCommand']) === FALSE) {
93 // Determine whether the strip profile action has be disabled by TypoScript:
94 if ($parameters !== '-version' && strpos($parameters, '###SkipStripProfile###') === FALSE) {
95 $parameters = $gfxConf['im_stripProfileCommand'] . ' ' . $parameters;
96 } else {
97 $parameters = str_replace('###SkipStripProfile###', '', $parameters);
98 }
99 }
100 }
101
102 $cmdLine = $path . ' ' . $parameters;
103
104 if ($command == 'composite' && $switchCompositeParameters) { // Because of some weird incompatibilities between ImageMagick 4 and 6 (plus GraphicsMagick), it is needed to change the parameters order under some preconditions
105 $paramsArr = t3lib_div::unQuoteFilenames($parameters);
106
107 if (count($paramsArr) > 5) { // The mask image has been specified => swap the parameters
108 $tmp = $paramsArr[count($paramsArr) - 3];
109 $paramsArr[count($paramsArr) - 3] = $paramsArr[count($paramsArr) - 4];
110 $paramsArr[count($paramsArr) - 4] = $tmp;
111 }
112
113 $cmdLine = $path . ' ' . implode(' ', $paramsArr);
114 }
115
116 return $cmdLine;
117 }
118
119 }
120
121 ?>