Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezimageshellhandler.php
Go to the documentation of this file.
1 <?php
18 class eZImageShellHandler extends eZImageHandler
19 {
20 public function __construct( $handlerName, $isEnabled = true, $outputRewriteType = self::REPLACE_SUFFIX,
21 $supportedInputMIMETypes = false, $supportedOutputMIMETypes = false,
22 $conversionRules = false, $filters = false, $mimeTagMap = false)
23 {
24 parent::__construct( $handlerName, $isEnabled, $outputRewriteType,
25 $supportedInputMIMETypes, $supportedOutputMIMETypes,
26 $conversionRules, $filters, $mimeTagMap );
27 $this->Path = false;
28 $this->Executable = false;
29 $this->PreParameters = false;
30 $this->PostParameters = false;
31 $this->UseTypeTag = false;
32 $this->QualityParameters = false;
33 $this->FrameRangeParameters = false;
34 }
35
39 function convert( $manager, $sourceMimeData, &$destinationMimeData, $filters = false )
40 {
41 $argumentList = array();
42 $executable = $this->Executable;
43 if ( eZSys::osType() == 'win32' and $this->ExecutableWin32 )
44 $executable = $this->ExecutableWin32;
45 else if ( eZSys::osType() == 'mac' and $this->ExecutableMac )
46 $executable = $this->ExecutableMac;
47 else if ( eZSys::osType() == 'unix' and $this->ExecutableUnix )
48 $executable = $this->ExecutableUnix;
49 if ( $this->Path )
50 $executable = $this->Path . eZSys::fileSeparator() . $executable;
51 if ( eZSys::osType() == 'win32' )
52 $executable = "\"$executable\"";
53
54 $argumentList[] = $executable;
55
56 if ( $this->PreParameters )
57 $argumentList[] = $this->PreParameters;
58
59 $frameRangeParameters = $this->FrameRangeParameters;
60 if ( $frameRangeParameters && isset( $frameRangeParameters[$sourceMimeData['name']] ) )
61 {
62 $sourceMimeData['url'] .= $frameRangeParameters[$sourceMimeData['name']];
63 }
64
65 // Issue EZP-21357:
66 // ImageMagick has it's own meta-characters support, hence:
67 // $ convert 'File*.jpg'' ...
68 // Still expand File*.jpg as the shell would do, however, this is only true for the file's basename part and not
69 // for the whole path.
70 $argumentList[] = eZSys::escapeShellArgument(
71 $sourceMimeData['dirpath'] . DIRECTORY_SEPARATOR . addcslashes(
72 $sourceMimeData['filename'],
73 // ImageMagick meta-characters
74 '~*?[]{}<>'
75 )
76 );
77
78 $qualityParameters = $this->QualityParameters;
79 if ( $qualityParameters and
80 isset( $qualityParameters[$destinationMimeData['name']] ) )
81 {
82 $qualityParameter = $qualityParameters[$destinationMimeData['name']];
83 $outputQuality = $manager->qualityValue( $destinationMimeData['name'] );
84 if ( $outputQuality )
85 {
86 $qualityArgument = eZSys::createShellArgument( $qualityParameter, array( '%1' => $outputQuality ) );
87 $argumentList[] = $qualityArgument;
88 }
89 }
90
91 if ( $filters !== false )
92 {
93 foreach ( $filters as $filterData )
94 {
95 $argumentList[] = $this->textForFilter( $filterData );
96 }
97 }
98
99 $destinationURL = $destinationMimeData['url'];
100 if ( $this->UseTypeTag )
101 $destinationURL = $this->tagForMIMEType( $destinationMimeData ) . $this->UseTypeTag . $destinationURL;
102 $argumentList[] = eZSys::escapeShellArgument( $destinationURL );
103
104 if ( $this->PostParameters )
105 $argumentList[] = $this->PostParameters;
106
107 $systemString = implode( ' ', $argumentList );
108
109 system( $systemString, $returnCode );
110
111 if ( $returnCode == 0 )
112 {
113 if ( !file_exists( $destinationMimeData['url'] ) )
114 {
115 eZDebug::writeError( 'Unknown destination file: ' . $destinationMimeData['url'] . " when executing '$systemString'", 'eZImageShellHandler(' . $this->HandlerName . ')' );
116 return false;
117 }
118 $this->changeFilePermissions( $destinationMimeData['url'] );
119 return true;
120 }
121 else
122 {
123 eZDebug::writeWarning( "Failed executing: $systemString, Error code: $returnCode", __METHOD__ );
124 return false;
125 }
126
127 }
128
134 static function createFromINI( $iniGroup, $iniFilename = false )
135 {
136 if ( !$iniFilename )
137 $iniFilename = 'image.ini';
138
139 $handler = false;
140 $ini = eZINI::instance( $iniFilename );
141 if ( !$ini )
142 {
143 eZDebug::writeError( "Failed loading ini file $iniFilename", __METHOD__ );
144 return $handler;
145 }
146
147 if ( $ini->hasGroup( $iniGroup ) )
148 {
149 $name = $iniGroup;
150 if ( $ini->hasVariable( $iniGroup, 'Name' ) )
151 $name = $ini->variable( $iniGroup, 'Name' );
152 $inputMimeList = false;
153 $outputMimeList = false;
154 if ( $ini->hasVariable( $iniGroup, 'InputMIMEList' ) )
155 $inputMimeList = $ini->variable( $iniGroup, 'InputMIMEList' );
156 if ( $ini->hasVariable( $iniGroup, 'OutputMIMEList' ) )
157 $outputMimeList = $ini->variable( $iniGroup, 'OutputMIMEList' );
158 $qualityParameters = array();
159 if ( $ini->hasVariable( $iniGroup, 'QualityParameters' ) )
160 {
161 $qualityParametersRaw = $ini->variable( $iniGroup, 'QualityParameters' );
162 foreach ( $qualityParametersRaw as $qualityParameterRaw )
163 {
164 $elements = explode( ';', $qualityParameterRaw );
165 $qualityParameters[$elements[0]] = $elements[1];
166 }
167 }
168 $frameRangeParameters = array();
169 if ( $ini->hasVariable( $iniGroup, 'FrameRangeParameters' ) )
170 {
171 foreach ( $ini->variable( $iniGroup, 'FrameRangeParameters' ) as $frameRangeParameter )
172 {
173 $elements = explode( ';', $frameRangeParameter );
174 $frameRangeParameters[$elements[0]] = $elements[1];
175 }
176 }
177
178 $conversionRules = false;
179 if ( $ini->hasVariable( $iniGroup, 'ConversionRules' ) )
180 {
181 $conversionRules = array();
182 $rules = $ini->variable( $iniGroup, 'ConversionRules' );
183 foreach ( $rules as $ruleString )
184 {
185 $ruleItems = explode( ';', $ruleString );
186 if ( count( $ruleItems ) >= 2 )
187 {
188 $conversionRules[] = array( 'from' => $ruleItems[0],
189 'to' => $ruleItems[1] );
190 }
191 }
192 }
193 $isEnabled = $ini->variable( $iniGroup, 'IsEnabled' ) == 'true';
194 $path = false;
195 $executable = false;
196 $preParameters = false;
197 $postParameters = false;
198 if ( $ini->hasVariable( $iniGroup, 'ExecutablePath' ) )
199 $path = $ini->variable( $iniGroup, 'ExecutablePath' );
200 if ( !$ini->hasVariable( $iniGroup, 'Executable' ) )
201 {
202 eZDebug::writeError( "No Executable setting for group $iniGroup in ini file $iniFilename", __METHOD__ );
203 return $handler;
204 }
205 $executable = $ini->variable( $iniGroup, 'Executable' );
206 $executableWin32 = false;
207 $executableMac = false;
208 $executableUnix = false;
209 $ini->assign( $iniGroup, 'ExecutableWin32', $executableWin32 );
210 $ini->assign( $iniGroup, 'ExecutableMac', $executableMac );
211 $ini->assign( $iniGroup, 'ExecutableUnix', $executableUnix );
212
213 if ( $ini->hasVariable( $iniGroup, 'ExecutablePath' ) )
214 $path = $ini->variable( $iniGroup, 'ExecutablePath' );
215 if ( $ini->hasVariable( $iniGroup, 'PreParameters' ) )
216 $preParameters = $ini->variable( $iniGroup, 'PreParameters' );
217 if ( $ini->hasVariable( $iniGroup, 'PostParameters' ) )
218 $postParameters = $ini->variable( $iniGroup, 'PostParameters' );
219 $useTypeTag = false;
220 if ( $ini->hasVariable( $iniGroup, 'UseTypeTag' ) )
221 {
222 $useTypeTag = $ini->variable( $iniGroup, 'UseTypeTag' );
223 }
224 $outputRewriteType = self::REPLACE_SUFFIX;
225 $filters = false;
226 if ( $ini->hasVariable( $iniGroup, 'Filters' ) )
227 {
228 $filterRawList = $ini->variable( $iniGroup, 'Filters' );
229 $filters = array();
230 foreach ( $filterRawList as $filterRawItem )
231 {
232 $filter = eZImageHandler::createFilterDefinitionFromINI( $filterRawItem );
233 $filters[] = $filter;
234 }
235 }
236 $mimeTagMap = false;
237 if ( $ini->hasVariable( $iniGroup, 'MIMETagMap' ) )
238 {
239 $mimeTagMapList = $ini->variable( $iniGroup, 'MIMETagMap' );
240 $mimeTagMap = array();
241 foreach ( $mimeTagMapList as $mimeTagMapItem )
242 {
243 $mimeTagMapArray = explode( ';', $mimeTagMapItem );
244 if ( count( $mimeTagMapArray ) >= 2 )
245 $mimeTagMap[$mimeTagMapArray[0]] = $mimeTagMapArray[1];
246 }
247 }
248 $handler = new eZImageShellHandler( $name, $isEnabled,
249 $outputRewriteType,
250 $inputMimeList, $outputMimeList,
251 $conversionRules, $filters, $mimeTagMap );
252 $handler->Path = $path;
253 $handler->Executable = $executable;
254 $handler->ExecutableWin32 = $executableWin32;
255 $handler->ExecutableMac = $executableMac;
256 $handler->ExecutableUnix = $executableUnix;
257 $handler->PreParameters = $preParameters;
258 $handler->PostParameters = $postParameters;
259 $handler->UseTypeTag = $useTypeTag;
260 $handler->QualityParameters = $qualityParameters;
261 $handler->FrameRangeParameters = $frameRangeParameters;
262 return $handler;
263 }
264 return $handler;
265 }
266
268 public $Path;
269 public $Executable;
270 public $PreParameters;
271 public $PostParameters;
272
273 public $ExecutableWin32;
274 public $ExecutableMac;
275 public $ExecutableUnix;
276 public $HandlerName;
277 public $SupportedInputMIMETypes;
278 public $SupportedOutputMIMETypes;
279 public $ConversionRules;
280 public $OutputRewriteType;
281 public $Filters;
282 public $FilterMap;
283 public $SupportImageFilters;
284 public $MIMETagMap;
285 public $IsEnabled;
286 public $UseTypeTag;
287 public $QualityParameters;
288 public $FrameRangeParameters;
289 }
290
291 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZImageHandler
The class eZImageHandler does.
Definition: ezimagehandler.php:19
eZImageHandler\tagForMIMEType
tagForMIMEType( $mimeData)
Definition: ezimagehandler.php:96
eZImageHandler\createFilterDefinitionFromINI
static createFilterDefinitionFromINI( $filterText)
Definition: ezimagehandler.php:128
eZImageHandler\changeFilePermissions
static changeFilePermissions( $filepath)
Definition: ezimagehandler.php:257
eZImageHandler\textForFilter
textForFilter( $filterData)
Definition: ezimagehandler.php:167
eZImageHandler\REPLACE_SUFFIX
const REPLACE_SUFFIX
Definition: ezimagehandler.php:34
eZImageShellHandler
The class eZImageShellHandler does.
Definition: ezimageshellhandler.php:19
eZImageShellHandler\$SupportedInputMIMETypes
$SupportedInputMIMETypes
Definition: ezimageshellhandler.php:277
eZImageShellHandler\$UseTypeTag
$UseTypeTag
Definition: ezimageshellhandler.php:286
eZImageShellHandler\$PostParameters
$PostParameters
Definition: ezimageshellhandler.php:271
eZImageShellHandler\$SupportedOutputMIMETypes
$SupportedOutputMIMETypes
Definition: ezimageshellhandler.php:278
eZImageShellHandler\$PreParameters
$PreParameters
Definition: ezimageshellhandler.php:270
eZImageShellHandler\$Executable
$Executable
Definition: ezimageshellhandler.php:269
eZImageShellHandler\__construct
__construct( $handlerName, $isEnabled=true, $outputRewriteType=self::REPLACE_SUFFIX, $supportedInputMIMETypes=false, $supportedOutputMIMETypes=false, $conversionRules=false, $filters=false, $mimeTagMap=false)
Definition: ezimageshellhandler.php:20
eZImageShellHandler\$MIMETagMap
$MIMETagMap
Definition: ezimageshellhandler.php:284
eZImageShellHandler\$FrameRangeParameters
$FrameRangeParameters
Definition: ezimageshellhandler.php:288
eZImageShellHandler\$ExecutableUnix
$ExecutableUnix
Definition: ezimageshellhandler.php:275
eZImageShellHandler\createFromINI
static createFromINI( $iniGroup, $iniFilename=false)
Definition: ezimageshellhandler.php:134
eZImageShellHandler\$QualityParameters
$QualityParameters
Definition: ezimageshellhandler.php:287
eZImageShellHandler\$Filters
$Filters
Definition: ezimageshellhandler.php:281
eZImageShellHandler\convert
convert( $manager, $sourceMimeData, &$destinationMimeData, $filters=false)
Definition: ezimageshellhandler.php:39
eZImageShellHandler\$ConversionRules
$ConversionRules
Definition: ezimageshellhandler.php:279
eZImageShellHandler\$Path
$Path
Definition: ezimageshellhandler.php:268
eZImageShellHandler\$SupportImageFilters
$SupportImageFilters
Definition: ezimageshellhandler.php:283
eZImageShellHandler\$HandlerName
$HandlerName
Definition: ezimageshellhandler.php:276
eZImageShellHandler\$ExecutableWin32
$ExecutableWin32
Definition: ezimageshellhandler.php:273
eZImageShellHandler\$ExecutableMac
$ExecutableMac
Definition: ezimageshellhandler.php:274
eZImageShellHandler\$FilterMap
$FilterMap
Definition: ezimageshellhandler.php:282
eZImageShellHandler\$OutputRewriteType
$OutputRewriteType
Definition: ezimageshellhandler.php:280
eZImageShellHandler\$IsEnabled
$IsEnabled
Definition: ezimageshellhandler.php:285
eZSys\createShellArgument
static createShellArgument( $argumentText, array $replaceList)
Definition: ezsys.php:312
eZSys\escapeShellArgument
static escapeShellArgument( $argument)
Definition: ezsys.php:290
eZSys\osType
static osType()
Definition: ezsys.php:221
eZSys\fileSeparator
static fileSeparator()
Definition: ezsys.php:255
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.