|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZBinaryFile class 00004 // 00005 // Created on: <30-Apr-2002 16:47:08 bf> 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 /*! 00032 \class eZMedia ezmedia.php 00033 \ingroup eZDatatype 00034 \brief The class eZMedia handles registered media files 00035 00036 */ 00037 00038 //include_once( "lib/ezdb/classes/ezdb.php" ); 00039 //include_once( "kernel/classes/ezpersistentobject.php" ); 00040 //include_once( "kernel/classes/ezcontentclassattribute.php" ); 00041 00042 class eZMedia extends eZPersistentObject 00043 { 00044 function eZMedia( $row ) 00045 { 00046 $this->eZPersistentObject( $row ); 00047 } 00048 00049 static function definition() 00050 { 00051 return array( "fields" => array( "contentobject_attribute_id" => array( 'name' => "ContentObjectAttributeID", 00052 'datatype' => 'integer', 00053 'default' => 0, 00054 'required' => true, 00055 'foreign_class' => 'eZContentObjectAttribute', 00056 'foreign_attribute' => 'id', 00057 'multiplicity' => '1..*' ), 00058 "version" => array( 'name' => "Version", 00059 'datatype' => 'integer', 00060 'default' => 0, 00061 'required' => true ), 00062 "filename" => array( 'name' => "Filename", 00063 'datatype' => 'string', 00064 'default' => '', 00065 'required' => true ), 00066 "original_filename" => array( 'name' => "OriginalFilename", 00067 'datatype' => 'string', 00068 'default' => '', 00069 'required' => true ), 00070 "mime_type" => array( 'name' => "MimeType", 00071 'datatype' => 'string', 00072 'default' => '', 00073 'required' => true ), 00074 "width" => array( 'name' => "Width", 00075 'datatype' => 'integer', 00076 'default' => 0, 00077 'required' => true ), 00078 "height" => array( 'name' => "Height", 00079 'datatype' => 'integer', 00080 'default' => 0, 00081 'required' => true ), 00082 "has_controller" => array( 'name' => "HasController", 00083 'datatype' => 'integer', 00084 'default' => 0, 00085 'required' => true ), 00086 "controls" => array( 'name' => "Controls", 00087 'datatype' => 'string', 00088 'default' => '', 00089 'required' => true ), 00090 "is_autoplay" => array( 'name' => "IsAutoplay", 00091 'datatype' => 'integer', 00092 'default' => 0, 00093 'required' => true ), 00094 "pluginspage" => array( 'name' => "Pluginspage", 00095 'datatype' => 'string', 00096 'default' => '', 00097 'required' => true ), 00098 "quality" => array( 'name' => 'Quality', 00099 'datatype' => 'string', 00100 'default' => '', 00101 'required' => true ), 00102 "is_loop" => array( 'name' => "IsLoop", 00103 'datatype' => 'integer', 00104 'default' => 0, 00105 'required' => true ) ), 00106 "keys" => array( "contentobject_attribute_id", "version" ), 00107 'function_attributes' => array( 'filesize' => 'filesize', 00108 'filepath' => 'filepath', 00109 'mime_type_category' => 'mimeTypeCategory', 00110 'mime_type_part' => 'mimeTypePart' ), 00111 "relations" => array( "contentobject_attribute_id" => array( "class" => "ezcontentobjectattribute", 00112 "field" => "id" ), 00113 "version" => array( "class" => "ezcontentobjectattribute", 00114 "field" => "version" )), 00115 "class_name" => "eZMedia", 00116 "name" => "ezmedia" ); 00117 } 00118 00119 function fileSize() 00120 { 00121 $fileInfo = $this->storedFileInfo(); 00122 00123 require_once( 'kernel/classes/ezclusterfilehandler.php' ); 00124 $file = eZClusterFileHandler::instance( $fileInfo['filepath'] ); 00125 00126 if ( $file->exists() ) 00127 { 00128 return $file->size(); 00129 } 00130 00131 return 0; 00132 } 00133 00134 function filePath() 00135 { 00136 $fileInfo = $this->storedFileInfo(); 00137 return $fileInfo['filepath']; 00138 } 00139 00140 function mimeTypeCategory() 00141 { 00142 $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) ); 00143 return $types[0]; 00144 } 00145 00146 function mimeTypePart() 00147 { 00148 $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) ); 00149 return $types[1]; 00150 } 00151 00152 static function create( $contentObjectAttributeID, $version ) 00153 { 00154 $row = array( "contentobject_attribute_id" => $contentObjectAttributeID, 00155 "version" => $version, 00156 "filename" => "", 00157 "original_filename" => "", 00158 "mime_type" => "", 00159 "width" => "0", 00160 "height" => "0", 00161 "controller" => true, 00162 "autoplay" => true, 00163 "pluginspage" => "", 00164 "is_loop" => false, 00165 "quality" => "", 00166 "controls" => "" 00167 ); 00168 return new eZMedia( $row ); 00169 } 00170 00171 static function fetch( $id, $version, $asObject = true ) 00172 { 00173 if( $version == null ) 00174 { 00175 return eZPersistentObject::fetchObjectList( eZMedia::definition(), 00176 null, 00177 array( "contentobject_attribute_id" => $id ), 00178 null, 00179 null, 00180 $asObject ); 00181 } 00182 else 00183 { 00184 return eZPersistentObject::fetchObject( eZMedia::definition(), 00185 null, 00186 array( "contentobject_attribute_id" => $id, 00187 "version" => $version ), 00188 $asObject ); 00189 } 00190 } 00191 00192 static function fetchByFileName( $filename, $version = null, $asObject = true ) 00193 { 00194 if ( $version == null ) 00195 { 00196 return eZPersistentObject::fetchObjectList( eZMedia::definition(), 00197 null, 00198 array( 'filename' => $filename ), 00199 null, 00200 null, 00201 $asObject ); 00202 } 00203 else 00204 { 00205 return eZPersistentObject::fetchObject( eZMedia::definition(), 00206 null, 00207 array( 'filename' => $filename, 00208 'version' => $version ), 00209 $asObject ); 00210 } 00211 } 00212 00213 static function removeByID( $id, $version ) 00214 { 00215 if( $version == null ) 00216 { 00217 eZPersistentObject::removeObject( eZMedia::definition(), 00218 array( "contentobject_attribute_id" => $id ) ); 00219 } 00220 else 00221 { 00222 eZPersistentObject::removeObject( eZMedia::definition(), 00223 array( "contentobject_attribute_id" => $id, 00224 "version" => $version ) ); 00225 } 00226 } 00227 00228 function storedFileInfo() 00229 { 00230 $fileName = $this->attribute( 'filename' ); 00231 $mimeType = $this->attribute( 'mime_type' ); 00232 $originalFileName = $this->attribute( 'original_filename' ); 00233 00234 $storageDir = eZSys::storageDirectory(); 00235 00236 $group = ''; 00237 $type = ''; 00238 if ( $mimeType ) 00239 list( $group, $type ) = explode( '/', $mimeType ); 00240 00241 $filePath = $storageDir . '/original/' . $group . '/' . $fileName; 00242 00243 return array( 'filename' => $fileName, 00244 'original_filename' => $originalFileName, 00245 'filepath' => $filePath, 00246 'mime_type' => $mimeType ); 00247 } 00248 00249 public $ContentObjectAttributeID; 00250 public $Filename; 00251 public $OriginalFilename; 00252 public $MimeType; 00253 public $Width; 00254 public $Height; 00255 public $HasController; 00256 public $Controls; 00257 public $IsLoop; 00258 public $IsAutoplay; 00259 public $Pluginspage; 00260 public $Quality; 00261 } 00262 00263 ?>