|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZImageAnalyzer class 00004 // 00005 // Created on: <03-Nov-2003 15:19:16 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezimageanalyzer.php 00032 */ 00033 00034 /*! \defgroup eZImageAnalyzer Image analysis 00035 \ingroup eZImage 00036 */ 00037 00038 /*! 00039 \class eZImageAnalyzer ezimageanalyzer.php 00040 \ingroup eZImageAnalyzer 00041 \brief The class eZImageAnalyzer does 00042 00043 */ 00044 00045 class eZImageAnalyzer 00046 { 00047 const MODE_INDEXED = 1; 00048 const MODE_TRUECOLOR = 2; 00049 00050 const TIMER_HUNDRETHS_OF_A_SECOND = 1; 00051 00052 const TRANSPARENCY_OPAQUE = 1; 00053 const TRANSPARENCY_TRANSPARENT = 2; 00054 const TRANSPARENCY_TRANSLUCENT = 3; 00055 00056 /*! 00057 Constructor 00058 */ 00059 function eZImageAnalyzer() 00060 { 00061 $this->Name = false; 00062 $this->MIMEList = array(); 00063 } 00064 00065 /*! 00066 \pure 00067 Process the file based on the MIME data \a $mimeData and returns 00068 information on the analysis. 00069 \return \c false if the analysis fails. 00070 */ 00071 function process( $mimeData, $parameters = array() ) 00072 { 00073 return false; 00074 } 00075 00076 /*! 00077 Creates an analyzer for the analyzer name \a $analyzerName and returns it. 00078 */ 00079 static function createForMIME( $mimeData ) 00080 { 00081 $analyzerData = eZImageAnalyzer::analyzerData(); 00082 $mimeType = $mimeData['name']; 00083 if ( !isset( $analyzerData['analyzer_map'][$mimeType] ) ) 00084 return false; 00085 $analyzerName = $analyzerData['analyzer_map'][$mimeType]; 00086 $handlerName = $analyzerData['analyzer'][$analyzerName]['handler']; 00087 return eZImageAnalyzer::create( $handlerName ); 00088 } 00089 00090 /*! 00091 Creates an analyzer for the analyzer name \a $analyzerName and returns it. 00092 */ 00093 static function create( $analyzerName ) 00094 { 00095 $analyzerData = eZImageAnalyzer::analyzerData(); 00096 if ( !isset( $analyzerData['handlers'][$analyzerName] ) ) 00097 { 00098 //include_once( 'lib/ezutils/classes/ezextension.php' ); 00099 if ( eZExtension::findExtensionType( array( 'ini-name' => 'image.ini', 00100 'repository-group' => 'AnalyzerSettings', 00101 'repository-variable' => 'RepositoryList', 00102 'extension-group' => 'AnalyzerSettings', 00103 'extension-variable' => 'ExtensionList', 00104 'extension-subdir' => 'imageanalyzer', 00105 'alias-group' => 'AnalyzerSettings', 00106 'alias-variable' => 'ImageAnalyzerAlias', 00107 'suffix-name' => 'imageanalyzer.php', 00108 'type-directory' => false, 00109 'type' => $analyzerName ), 00110 $result ) ) 00111 { 00112 $filepath = $result['found-file-path']; 00113 include_once( $filepath ); 00114 $className = $result['type'] . 'imageanalyzer'; 00115 $analyzerData['handlers'][$analyzerName] = array( 'classname' => $className, 00116 'filepath' => $filepath ); 00117 } 00118 else 00119 { 00120 eZDebug::writeWarning( "Could not locate Image Analyzer for $analyzerName", 00121 'eZImageAnalyzer::instance' ); 00122 } 00123 } 00124 if ( isset( $analyzerData['handlers'][$analyzerName] ) ) 00125 { 00126 $analyzer = $analyzerData['handlers'][$analyzerName]; 00127 $className = $analyzer['classname']; 00128 if ( class_exists( $className ) ) 00129 { 00130 return new $className(); 00131 } 00132 else 00133 { 00134 eZDebug::writeWarning( "The Image Analyzer class $className was not found, cannot create analyzer", 00135 'eZImageAnalyzer::instance' ); 00136 } 00137 } 00138 return false; 00139 } 00140 00141 /*! 00142 \static 00143 \private 00144 */ 00145 static function analyzerData() 00146 { 00147 $analyzerData =& $GLOBALS['eZImageAnalyzer']; 00148 if ( isset( $analyzerData ) ) 00149 return $analyzerData; 00150 00151 $ini = eZINI::instance( 'image.ini' ); 00152 $analyzerData['analyzers'] = $ini->variable( 'AnalyzerSettings', 'ImageAnalyzers' ); 00153 $analyzerData['mime_list'] = $ini->variable( 'AnalyzerSettings', 'AnalyzerMIMEList' ); 00154 $analyzerData['analyzer_map'] = array(); 00155 $analyzerData['analyzer'] = array(); 00156 return $analyzerData; 00157 } 00158 00159 /*! 00160 \static 00161 */ 00162 static function readAnalyzerSettingsFromINI() 00163 { 00164 $analyzerData = eZImageAnalyzer::analyzerData(); 00165 $ini = eZINI::instance( 'image.ini' ); 00166 foreach ( $analyzerData['analyzers'] as $analyzerName ) 00167 { 00168 $iniGroup = $analyzerName . 'Analyzer'; 00169 if ( $ini->hasGroup( $iniGroup ) ) 00170 { 00171 $handler = $ini->variable( $iniGroup, 'Handler' ); 00172 $mimeList = $ini->variable( $iniGroup, 'MIMEList' ); 00173 $analyzerData['analyzer'][$analyzerName] = array( 'handler' => $handler, 00174 'mime_list' => $mimeList ); 00175 foreach ( $mimeList as $mimeItem ) 00176 { 00177 $analyzerData['analyzer_map'][$mimeItem] = $analyzerName; 00178 } 00179 } 00180 else 00181 eZDebug::writeWarning( "INI group $iniGroup does not exist in image.ini", 00182 'eZImageAnalyzer::readAnalyzerSettingsFromINI' ); 00183 } 00184 00185 $GLOBALS['eZImageAnalyzer'] = $analyzerData; 00186 } 00187 00188 /// \privatesection 00189 00190 public $MIMEList; 00191 public $Name; 00192 } 00193 00194 ?>