[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZImageShellHandler class 4 // 5 // Created on: <16-Oct-2003 14:22:43 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezimageshellhandler.php 30 */ 31 32 /*! 33 \class eZImageShellHandler ezimageshellhandler.php 34 \ingroup eZImage 35 \brief The class eZImageShellHandler does 36 37 */ 38 39 include_once ( 'lib/ezimage/classes/ezimagehandler.php' ); 40 41 class eZImageShellHandler extends eZImageHandler 42 { 43 /*! 44 Constructor 45 */ 46 function eZImageShellHandler( $handlerName, $isEnabled = true, $outputRewriteType = EZ_IMAGE_HANDLER_REPLACE_SUFFIX, 47 $supportedInputMIMETypes = false, $supportedOutputMIMETypes = false, 48 $conversionRules = false, $filters = false, $mimeTagMap = false) 49 { 50 $this->eZImageHandler( $handlerName, $isEnabled, $outputRewriteType, 51 $supportedInputMIMETypes, $supportedOutputMIMETypes, 52 $conversionRules, $filters, $mimeTagMap ); 53 $this->Path = false; 54 $this->Executable = false; 55 $this->PreParameters = false; 56 $this->PostParameters = false; 57 $this->UseTypeTag = false; 58 $this->QualityParameters = false; 59 } 60 61 /*! 62 Creates the shell string and runs the executable. 63 */ 64 function convert( &$manager, $sourceMimeData, &$destinationMimeData, $filters = false ) 65 { 66 $argumentList = array(); 67 $executable = $this->Executable; 68 if ( eZSys::osType() == 'win32' and $this->ExecutableWin32 ) 69 $executable = $this->ExecutableWin32; 70 else if ( eZSys::osType() == 'mac' and $this->ExecutableMac ) 71 $executable = $this->ExecutableMac; 72 else if ( eZSys::osType() == 'unix' and $this->ExecutableUnix ) 73 $executable = $this->ExecutableUnix; 74 if ( $this->Path ) 75 $executable = $this->Path . '/' . $executable; 76 $argumentList[] = $executable; 77 78 if ( $this->PreParameters ) 79 $argumentList[] = $this->PreParameters; 80 81 $qualityParameters = $this->QualityParameters; 82 83 if ( $qualityParameters and 84 isset( $qualityParameters[$destinationMimeData['name']] ) ) 85 { 86 $qualityParameter = $qualityParameters[$destinationMimeData['name']]; 87 $outputQuality = $manager->qualityValue( $destinationMimeData['name'] ); 88 if ( $outputQuality ) 89 { 90 $qualityArgument = eZSys::createShellArgument( $qualityParameter, array( '%1' => $outputQuality ) ); 91 $argumentList[] = $qualityArgument; 92 } 93 } 94 95 if ( $filters !== false ) 96 { 97 foreach ( $filters as $filterData ) 98 { 99 $argumentList[] = $this->textForFilter( $filterData ); 100 } 101 } 102 103 $argumentList[] = eZSys::escapeShellArgument( $sourceMimeData['url'] ); 104 105 $destinationURL = $destinationMimeData['url']; 106 if ( $this->UseTypeTag ) 107 $destinationURL = $this->tagForMIMEType( $destinationMimeData ) . $this->UseTypeTag . $destinationURL; 108 $argumentList[] = eZSys::escapeShellArgument( $destinationURL ); 109 110 if ( $this->PostParameters ) 111 $argumentList[] = $this->PostParameters; 112 113 $systemString = implode( ' ', $argumentList ); 114 // print( $systemString . "<br/>" ); 115 $error = system( $systemString, $returnCode ); 116 117 if ( $returnCode == 0 ) 118 { 119 if ( !file_exists( $destinationMimeData['url'] ) ) 120 { 121 eZDebug::writeError( "Unknown destination file: " . $destinationMimeData['url'], "eZImageShellHandler(" . $this->HandlerName . ")" ); 122 return false; 123 } 124 $this->changeFilePermissions( $destinationMimeData['url'] ); 125 return true; 126 } 127 else 128 { 129 eZDebug::writeWarning( "Failed executing: $systemString, Error: $error, Return: $returnCode", 'eZImageShellHandler::convert' ); 130 return false; 131 } 132 133 } 134 135 /*! 136 Creates a new image handler for shell executable from INI settings. 137 The INI settings are read from ini file \a $iniFilename and group \a $iniGroup. 138 If \a $iniFilename is not supplied \c image.ini is used. 139 */ 140 function &createFromINI( $iniGroup, $iniFilename = false ) 141 { 142 if ( !$iniFilename ) 143 $iniFilename = 'image.ini'; 144 145 $handler = false; 146 include_once ( 'lib/ezutils/classes/ezini.php' ); 147 $ini =& eZINI::instance( $iniFilename ); 148 if ( !$ini ) 149 { 150 eZDebug::writeError( "Failed loading ini file $iniFilename", 151 'eZImageShellHandler::createFromINI' ); 152 return $handler; 153 } 154 155 if ( $ini->hasGroup( $iniGroup ) ) 156 { 157 $name = $iniGroup; 158 if ( $ini->hasVariable( $iniGroup, 'Name' ) ) 159 $name = $ini->variable( $iniGroup, 'Name' ); 160 $inputMimeList = false; 161 $outputMimeList = false; 162 if ( $ini->hasVariable( $iniGroup, 'InputMIMEList' ) ) 163 $inputMimeList = $ini->variable( $iniGroup, 'InputMIMEList' ); 164 if ( $ini->hasVariable( $iniGroup, 'OutputMIMEList' ) ) 165 $outputMimeList = $ini->variable( $iniGroup, 'OutputMIMEList' ); 166 $qualityParameters = false; 167 if ( $ini->hasVariable( $iniGroup, 'QualityParameters' ) ) 168 { 169 $qualityParametersRaw = $ini->variable( $iniGroup, 'QualityParameters' ); 170 foreach ( $qualityParametersRaw as $qualityParameterRaw ) 171 { 172 $elements = explode( ';', $qualityParameterRaw ); 173 $qualityParameters[$elements[0]] = $elements[1]; 174 } 175 } 176 $conversionRules = false; 177 if ( $ini->hasVariable( $iniGroup, 'ConversionRules' ) ) 178 { 179 $conversionRules = array(); 180 $rules = $ini->variable( $iniGroup, 'ConversionRules' ); 181 foreach ( $rules as $ruleString ) 182 { 183 $ruleItems = explode( ';', $ruleString ); 184 if ( count( $ruleItems ) >= 2 ) 185 { 186 $conversionRules[] = array( 'from' => $ruleItems[0], 187 'to' => $ruleItems[1] ); 188 } 189 } 190 } 191 $isEnabled = $ini->variable( $iniGroup, 'IsEnabled' ) == 'true'; 192 $path = false; 193 $executable = false; 194 $preParameters = false; 195 $postParameters = false; 196 if ( $ini->hasVariable( $iniGroup, 'ExecutablePath' ) ) 197 $path = $ini->variable( $iniGroup, 'ExecutablePath' ); 198 if ( !$ini->hasVariable( $iniGroup, 'Executable' ) ) 199 { 200 eZDebug::writeError( "No Executable setting for group $iniGroup in ini file $iniFilename", 201 'eZImageShellHandler::createFromINI' ); 202 return $handler; 203 } 204 $executable = $ini->variable( $iniGroup, 'Executable' ); 205 $executableWin32 = false; 206 $executableMac = false; 207 $executableUnix = false; 208 $ini->assign( $iniGroup, 'ExecutableWin32', $executableWin32 ); 209 $ini->assign( $iniGroup, 'ExecutableMac', $executableMac ); 210 $ini->assign( $iniGroup, 'ExecutableUnix', $executableUnix ); 211 212 if ( $ini->hasVariable( $iniGroup, 'ExecutablePath' ) ) 213 $path = $ini->variable( $iniGroup, 'ExecutablePath' ); 214 if ( $ini->hasVariable( $iniGroup, 'ExecutablePath' ) ) 215 $path = $ini->variable( $iniGroup, 'ExecutablePath' ); 216 if ( $ini->hasVariable( $iniGroup, 'PreParameters' ) ) 217 $preParameters = $ini->variable( $iniGroup, 'PreParameters' ); 218 if ( $ini->hasVariable( $iniGroup, 'PostParameters' ) ) 219 $postParameters = $ini->variable( $iniGroup, 'PostParameters' ); 220 $useTypeTag = false; 221 if ( $ini->hasVariable( $iniGroup, 'UseTypeTag' ) ) 222 { 223 $useTypeTag = $ini->variable( $iniGroup, 'UseTypeTag' ); 224 } 225 $outputRewriteType = EZ_IMAGE_HANDLER_REPLACE_SUFFIX; 226 $filters = false; 227 if ( $ini->hasVariable( $iniGroup, 'Filters' ) ) 228 { 229 $filterRawList = $ini->variable( $iniGroup, 'Filters' ); 230 $filters = array(); 231 foreach ( $filterRawList as $filterRawItem ) 232 { 233 $filter = eZImageHandler::createFilterDefinitionFromINI( $filterRawItem ); 234 $filters[] = $filter; 235 } 236 } 237 $mimeTagMap = false; 238 if ( $ini->hasVariable( $iniGroup, 'MIMETagMap' ) ) 239 { 240 $mimeTagMapList = $ini->variable( $iniGroup, 'MIMETagMap' ); 241 $mimeTagMap = array(); 242 foreach ( $mimeTagMapList as $mimeTagMapItem ) 243 { 244 $mimeTagMapArray = explode( ';', $mimeTagMapItem ); 245 if ( count( $mimeTagMapArray ) >= 2 ) 246 $mimeTagMap[$mimeTagMapArray[0]] = $mimeTagMapArray[1]; 247 } 248 } 249 $handler = new eZImageShellHandler( $name, $isEnabled, 250 $outputRewriteType, 251 $inputMimeList, $outputMimeList, 252 $conversionRules, $filters, $mimeTagMap ); 253 $handler->Path = $path; 254 $handler->Executable = $executable; 255 $handler->ExecutableWin32 = $executableWin32; 256 $handler->ExecutableMac = $executableMac; 257 $handler->ExecutableUnix = $executableUnix; 258 $handler->PreParameters = $preParameters; 259 $handler->PostParameters = $postParameters; 260 $handler->UseTypeTag = $useTypeTag; 261 $handler->QualityParameters = $qualityParameters; 262 return $handler; 263 } 264 return $handler; 265 } 266 267 /// \privatesection 268 var $Path; 269 var $Executable; 270 var $PreParameters; 271 var $PostParameters; 272 } 273 274 class eZImageShellFactory extends eZImageFactory 275 { 276 /*! 277 Initializes the factory with the name \c 'shell' 278 */ 279 function eZImageShellFactory() 280 { 281 $this->eZImageFactory( 'shell' ); 282 } 283 284 /*! 285 \reimp 286 Creates eZImageShellHandler objects and returns them. 287 */ 288 function &produceFromINI( $iniGroup, $iniFilename = false ) 289 { 290 $convertHandler =& eZImageShellHandler::createFromINI( $iniGroup, $iniFilename ); 291 return $convertHandler; 292 } 293 } 294 295 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |