Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezmediatype.php
Go to the documentation of this file.
1 <?php
18 class eZMediaType extends eZDataType
19 {
20 const DATA_TYPE_STRING = "ezmedia";
21 const MAX_FILESIZE_FIELD = 'data_int1';
22 const MAX_FILESIZE_VARIABLE = '_ezmedia_max_filesize_';
23 const TYPE_FIELD = "data_text1";
24 const TYPE_VARIABLE = "_ezmedia_type_";
25
26 public function __construct()
27 {
28 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Media", 'Datatype name' ),
29 array( 'serialize_supported' => true ) );
30 $this->FileExtensionBlackListValidator = new eZFileExtensionBlackListValidator();
31 }
32
36 function postInitializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
37 {
38 if ( $currentVersion != false )
39 {
40 $contentObjectAttributeID = $originalContentObjectAttribute->attribute( "id" );
41 $version = $contentObjectAttribute->attribute( "version" );
42 $oldfile = eZMedia::fetch( $contentObjectAttributeID, $currentVersion );
43 if( $oldfile != null )
44 {
45 $oldfile->setAttribute( 'contentobject_attribute_id', $contentObjectAttribute->attribute( 'id' ) );
46 $oldfile->setAttribute( "version", $version );
47 $oldfile->store();
48 }
49 }
50 else
51 {
52 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
53 $version = $contentObjectAttribute->attribute( 'version' );
54
55 $media = eZMedia::create( $contentObjectAttributeID, $version );
56
57 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
58 $pluginPage = eZMediaType::pluginPage( $contentClassAttribute->attribute( 'data_text1' ) );
59
60 $media->setAttribute( 'quality', 'high' );
61 $media->setAttribute( 'pluginspage', $pluginPage );
62 $media->store();
63 }
64 }
65
70 function trashStoredObjectAttribute( $contentObjectAttribute, $version = null )
71 {
72 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
73 $sys = eZSys::instance();
74 $storage_dir = $sys->storageDirectory();
75
76 if ( $version == null )
77 $mediaFiles = eZMedia::fetch( $contentObjectAttributeID, null );
78 else
79 $mediaFiles = array( eZMedia::fetch( $contentObjectAttributeID, $version ) );
80
81 foreach ( $mediaFiles as $mediaFile )
82 {
83 if ( $mediaFile == null )
84 continue;
85 $mimeType = $mediaFile->attribute( "mime_type" );
86 list( $prefix, $suffix ) = explode( '/', $mimeType );
87 $orig_dir = $storage_dir . '/original/' . $prefix;
88 $fileName = $mediaFile->attribute( "filename" );
89
90 // Check if there are any other records in ezmedia that point to that fileName.
91 $mediaObjectsWithSameFileName = eZMedia::fetchByFileName( $fileName );
92
93 $filePath = $orig_dir . "/" . $fileName;
94 $file = eZClusterFileHandler::instance( $filePath );
95
96 if ( $file->exists() and count( $mediaObjectsWithSameFileName ) <= 1 )
97 {
98 // create dest filename in the same manner as eZHTTPFile::store()
99 // grab file's suffix
100 $fileSuffix = eZFile::suffix( $fileName );
101 // prepend dot
102 if ( $fileSuffix )
103 $fileSuffix = '.' . $fileSuffix;
104 // grab filename without suffix
105 $fileBaseName = basename( $fileName, $fileSuffix );
106 // create dest filename
107 $newFileName = md5( $fileBaseName . microtime() . mt_rand() ) . $fileSuffix;
108 $newFilePath = $orig_dir . "/" . $newFileName;
109
110 // rename the file, and update the database data
111 $file->move( $newFilePath );
112 $mediaFile->setAttribute( 'filename', $newFileName );
113 $mediaFile->store();
114 }
115 }
116 }
117
121 function deleteStoredObjectAttribute( $contentObjectAttribute, $version = null )
122 {
123 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
124 $sys = eZSys::instance();
125 $storage_dir = $sys->storageDirectory();
126 if ( $version == null )
127 {
128 $mediaFiles = eZMedia::fetch( $contentObjectAttributeID, null );
129 foreach ( $mediaFiles as $mediaFile )
130 {
131 $mimeType = $mediaFile->attribute( "mime_type" );
132 list( $prefix, $suffix ) = explode('/', $mimeType );
133 // $orig_dir = "var/storage/original/" . $prefix;
134 $orig_dir = $storage_dir . '/original/' . $prefix;
135 $fileName = $mediaFile->attribute( "filename" );
136
137 if ( $fileName == '' )
138 continue;
139
140 $file = eZClusterFileHandler::instance( $orig_dir . "/" . $fileName );
141 if ( $file->exists() )
142 $file->delete();
143 }
144 }
145 else
146 {
147 $mediaFiles = eZMedia::fetchByContentObjectID( $contentObjectAttribute->attribute( 'contentobject_id' ) );
148 $count = 0;
149 $currentBinaryFile = eZMedia::fetch( $contentObjectAttributeID, $version );
150 if ( $currentBinaryFile != null )
151 {
152 $mimeType = $currentBinaryFile->attribute( "mime_type" );
153 $currentFileName = $currentBinaryFile->attribute( "filename" );
154 list( $prefix, $suffix ) = is_string( $mimeType ) && $mimeType ? explode( '/', $mimeType ) : array( null, null );
155 // $orig_dir = "var/storage/original/" . $prefix;
156 $orig_dir = $storage_dir . '/original/' . $prefix;
157 foreach ( $mediaFiles as $mediaFile )
158 {
159 $fileName = $mediaFile->attribute( "filename" );
160 if( $currentFileName == $fileName )
161 $count += 1;
162 }
163 if ( $count == 1 && $currentFileName != '' )
164 {
165 $file = eZClusterFileHandler::instance( $orig_dir . "/" . $currentFileName );
166 if ( $file->exists() )
167 $file->delete();
168 }
169 }
170 }
171 eZMedia::removeByID( $contentObjectAttributeID, $version );
172 }
173
178 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
179 {
180 $classAttribute = $contentObjectAttribute->contentClassAttribute();
181 $httpFileName = $base . "_data_mediafilename_" . $contentObjectAttribute->attribute( "id" );
182 $maxSize = 1024 * 1024 * $classAttribute->attribute( self::MAX_FILESIZE_FIELD );
183 $mustUpload = false;
184
185 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
186 $version = $contentObjectAttribute->attribute( 'version' );
187 $media = eZMedia::fetch( $contentObjectAttributeID, $version );
188 $extensionsBlackList = implode(', ', $this->FileExtensionBlackListValidator->extensionsBlackList() );
189 if ( $media === null || !$media->attribute( 'filename' ) )
190 {
191 if ( $contentObjectAttribute->validateIsRequired() )
192 {
193 $mustUpload = true;
194 }
195 }
196 else
197 {
198 $state = $this->FileExtensionBlackListValidator->validate( $media->attribute( 'filename' ) );
199 if ( $state === eZInputValidator::STATE_INVALID || $state === eZInputValidator::STATE_INTERMEDIATE )
200 {
201 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
202 "A valid file is required. The following file extensions are blacklisted: $extensionsBlackList" ) );
203 return eZInputValidator::STATE_INVALID;
204 }
205 }
206
207 if ( isset( $_FILES[$httpFileName] ) && $_FILES[$httpFileName]['tmp_name'] !== '')
208 {
209 $state = $this->FileExtensionBlackListValidator->validate( $_FILES[$httpFileName]['name'] );
210 if ( $state === eZInputValidator::STATE_INVALID || $state === eZInputValidator::STATE_INTERMEDIATE )
211 {
212 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
213 "A valid file is required. The following file extensions are blacklisted: $extensionsBlackList" ) );
214 return eZInputValidator::STATE_INVALID;
215 }
216 }
217
218 $canFetchResult = eZHTTPFile::canFetch( $httpFileName, $maxSize );
219 if ( $mustUpload && $canFetchResult == eZHTTPFile::UPLOADEDFILE_DOES_NOT_EXIST )
220 {
221 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
222 'A valid media file is required.' ) );
223 return eZInputValidator::STATE_INVALID;
224 }
225 if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_PHP_LIMIT )
226 {
227 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
228 'The size of the uploaded file exceeds the limit set by upload_max_filesize directive in php.ini. Please contact the site administrator.') );
229 return eZInputValidator::STATE_INVALID;
230 }
231 if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_MAX_SIZE )
232 {
233 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
234 'The size of the uploaded file exceeds site maximum: %1 bytes.' ), $maxSize );
235 return eZInputValidator::STATE_INVALID;
236 }
237 return eZInputValidator::STATE_ACCEPTED;
238 }
239
243 function checkFileUploads()
244 {
245 $isFileUploadsEnabled = ini_get( 'file_uploads' ) != 0;
246 if ( !$isFileUploadsEnabled )
247 {
248 if ( empty( $GLOBALS['eZMediaTypeWarningAdded'] ) )
249 {
250 eZAppendWarningItem( array( 'error' => array( 'type' => 'kernel',
251 'number' => eZError::KERNEL_NOT_AVAILABLE ),
252 'text' => ezpI18n::tr( 'kernel/classes/datatypes',
253 'File uploading is not enabled. Please contact the site administrator to enable it.' ) ) );
254 $GLOBALS['eZMediaTypeWarningAdded'] = true;
255 }
256 }
257 }
258
264 function pluginPage( $mediaType )
265 {
266 $pluginPage = '';
267 switch( $mediaType )
268 {
269 case 'flash':
270 $pluginPage = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
271 break;
272 case 'quick_time':
273 $pluginPage = "http://quicktime.apple.com";
274 break;
275 case 'real_player' :
276 $pluginPage = "http://www.real.com/";
277 break;
278 case 'silverlight':
279 $pluginPage = "http://go.microsoft.com/fwlink/?LinkID=108182";
280 break;
281 case 'windows_media_player' :
282 $pluginPage = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" ;
283 break;
284 default:
285 $pluginPage = "";
286 break;
287 }
288
289 return $pluginPage;
290 }
291
295 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
296 {
297
298 eZMediaType::checkFileUploads();
299
300 if ( $this->validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) !== eZInputValidator::STATE_ACCEPTED )
301 {
302 return false;
303 }
304
305 $classAttribute = $contentObjectAttribute->contentClassAttribute();
306 $player = $classAttribute->attribute( "data_text1" );
307 $pluginPage = eZMediaType::pluginPage( $player );
308
309 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
310 $version = $contentObjectAttribute->attribute( "version" );
311 $width = $http->postVariable( $base . "_data_media_width_" . $contentObjectAttribute->attribute( "id" ) );
312 $height = $http->postVariable( $base . "_data_media_height_" . $contentObjectAttribute->attribute( "id" ) );
313 $quality = $http->hasPostVariable( $base . "_data_media_quality_" . $contentObjectAttribute->attribute( "id" ) ) ? $http->postVariable( $base . "_data_media_quality_" . $contentObjectAttribute->attribute( "id" ) ) : null;
314 if ( $http->hasPostVariable( $base . "_data_media_controls_" . $contentObjectAttribute->attribute( "id" ) ) )
315 $controls = $http->postVariable( $base . "_data_media_controls_" . $contentObjectAttribute->attribute( "id" ) );
316 else
317 $controls = null;
318
319 $media = eZMedia::fetch( $contentObjectAttributeID, $version );
320 if ( $media == null )
321 {
322 $media = eZMedia::create( $contentObjectAttributeID, $version );
323 }
324
325 $media->setAttribute( "contentobject_attribute_id", $contentObjectAttributeID );
326 $media->setAttribute( "version", $version );
327 $media->setAttribute( "width", $width );
328 $media->setAttribute( "height", $height );
329 $media->setAttribute( "quality", $quality );
330 $media->setAttribute( "controls", $controls );
331 $media->setAttribute( "pluginspage", $pluginPage );
332 if ( $http->hasPostVariable( $base . "_data_media_is_autoplay_" . $contentObjectAttribute->attribute( "id" ) ) )
333 $media->setAttribute( "is_autoplay", true );
334 else
335 $media->setAttribute( "is_autoplay", false );
336 if ( $http->hasPostVariable( $base . "_data_media_has_controller_" . $contentObjectAttribute->attribute( "id" ) ) )
337 $media->setAttribute( "has_controller", true );
338 else
339 $media->setAttribute( "has_controller", false );
340 if ( $http->hasPostVariable( $base . "_data_media_is_loop_" . $contentObjectAttribute->attribute( "id" ) ) )
341 $media->setAttribute( "is_loop", true );
342 else
343 $media->setAttribute( "is_loop", false );
344
345 $mediaFilePostVarName = $base . "_data_mediafilename_" . $contentObjectAttribute->attribute( "id" );
346 if ( eZHTTPFile::canFetch( $mediaFilePostVarName ) )
347 $mediaFile = eZHTTPFile::fetch( $mediaFilePostVarName );
348 else
349 $mediaFile = null;
350 if ( $mediaFile instanceof eZHTTPFile )
351 {
352 $mimeData = eZMimeType::findByFileContents( $mediaFile->attribute( "original_filename" ) );
353 $mime = $mimeData['name'];
354
355 if ( $mime == '' )
356 {
357 $mime = $mediaFile->attribute( "mime_type" );
358 }
359 $extension = eZFile::suffix( $mediaFile->attribute( "original_filename" ) );
360 $mediaFile->setMimeType( $mime );
361 if ( !$mediaFile->store( "original", $extension ) )
362 {
363 eZDebug::writeError( "Failed to store http-file: " . $mediaFile->attribute( "original_filename" ),
364 "eZMediaType" );
365 return false;
366 }
367
368 $orig_dir = $mediaFile->storageDir( "original" );
369 eZDebug::writeNotice( "dir=$orig_dir" );
370 $media->setAttribute( "filename", basename( $mediaFile->attribute( "filename" ) ) );
371 $media->setAttribute( "original_filename", $mediaFile->attribute( "original_filename" ) );
372 $media->setAttribute( "mime_type", $mime );
373
374 $filePath = $mediaFile->attribute( 'filename' );
375 $fileHandler = eZClusterFileHandler::instance();
376 $fileHandler->fileStore( $filePath, 'media', true, $mime );
377 }
378 else if ( $media->attribute( 'filename' ) == '' )
379 {
380 $media->remove();
381 return false;
382 }
383
384 $media->store();
385 $contentObjectAttribute->setContent( $media );
386 return true;
387 }
388
389 function storeObjectAttribute( $contentObjectAttribute )
390 {
391 }
392
393 function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters )
394 {
395 if ( $action == "delete_media" )
396 {
397 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
398 $version = $contentObjectAttribute->attribute( "version" );
399 $this->deleteStoredObjectAttribute( $contentObjectAttribute, $version );
400 $media = eZMedia::create( $contentObjectAttributeID, $version );
401 $contentObjectAttribute->setContent( $media );
402 }
403 }
404
408 function isHTTPFileInsertionSupported()
409 {
410 return true;
411 }
412
416 function isRegularFileInsertionSupported()
417 {
418 return true;
419 }
420
424 function insertHTTPFile( $object, $objectVersion, $objectLanguage,
425 $objectAttribute, $httpFile, $mimeData,
426 &$result )
427 {
428 $result = array( 'errors' => array(),
429 'require_storage' => false );
430 $attributeID = $objectAttribute->attribute( 'id' );
431
432 $media = eZMedia::fetch( $attributeID, $objectVersion );
433 if ( $media === null )
434 $media = eZMedia::create( $attributeID, $objectVersion );
435
436 $httpFile->setMimeType( $mimeData['name'] );
437 if ( !$httpFile->store( "original", false, false ) )
438 {
439 $result['errors'][] = array( 'description' => ezpI18n::tr( 'kernel/classes/datatypes/ezmedia',
440 'Failed to store media file %filename. Please contact the site administrator.', null,
441 array( '%filename' => $httpFile->attribute( "original_filename" ) ) ) );
442 return false;
443 }
444
445 $classAttribute = $objectAttribute->contentClassAttribute();
446 $player = $classAttribute->attribute( "data_text1" );
447 $pluginPage = eZMediaType::pluginPage( $player );
448
449 $media->setAttribute( "contentobject_attribute_id", $attributeID );
450 $media->setAttribute( "version", $objectVersion );
451 $media->setAttribute( "filename", basename( $httpFile->attribute( "filename" ) ) );
452 $media->setAttribute( "original_filename", $httpFile->attribute( "original_filename" ) );
453 $media->setAttribute( "mime_type", $mimeData['name'] );
454
455 // Setting width and height to zero means that the browser/player must find the size itself.
456 // In the future we will probably analyze the media file and find this information
457 $width = $height = 0;
458 // Quality is not known, so we don't set any
459 $quality = false;
460 // Not sure what this is for, set to false
461 $controls = false;
462 // We want to show controllers by default
463 $hasController = true;
464 // Don't play automatically
465 $isAutoplay = false;
466 // Don't loop movie
467 $isLoop = false;
468
469 $media->setAttribute( "width", $width );
470 $media->setAttribute( "height", $height );
471 $media->setAttribute( "quality", $quality );
472 $media->setAttribute( "controls", $controls );
473 $media->setAttribute( "pluginspage", $pluginPage );
474 $media->setAttribute( "is_autoplay", $isAutoplay );
475 $media->setAttribute( "has_controller", $hasController );
476 $media->setAttribute( "is_loop", $isLoop );
477
478 $filePath = $httpFile->attribute( 'filename' );
479 $fileHandler = eZClusterFileHandler::instance();
480 $fileHandler->fileStore( $filePath, 'mediafile', true, $mimeData['name'] );
481
482
483 $media->store();
484
485 $objectAttribute->setContent( $media );
486 return true;
487 }
488
492 function insertRegularFile( $object, $objectVersion, $objectLanguage,
493 $objectAttribute, $filePath,
494 &$result )
495 {
496 $result = array( 'errors' => array(),
497 'require_storage' => false );
498 $attributeID = $objectAttribute->attribute( 'id' );
499
500 $media = eZMedia::fetch( $attributeID, $objectVersion );
501 if ( $media === null )
502 $media = eZMedia::create( $attributeID, $objectVersion );
503
504 $fileName = basename( $filePath );
505 $mimeData = eZMimeType::findByFileContents( $filePath );
506 $storageDir = eZSys::storageDirectory();
507 list( $group, $type ) = explode( '/', $mimeData['name'] );
508 $destination = $storageDir . '/original/' . $group;
509
510 if ( !file_exists( $destination ) )
511 {
512 if ( !eZDir::mkdir( $destination, false, true ) )
513 {
514 return false;
515 }
516 }
517
518 // create dest filename in the same manner as eZHTTPFile::store()
519 // grab file's suffix
520 $fileSuffix = eZFile::suffix( $fileName );
521 // prepend dot
522 if( $fileSuffix )
523 $fileSuffix = '.' . $fileSuffix;
524 // grab filename without suffix
525 $fileBaseName = basename( $fileName, $fileSuffix );
526 // create dest filename
527 $destFileName = md5( $fileBaseName . microtime() . mt_rand() ) . $fileSuffix;
528 $destination = $destination . '/' . $destFileName;
529
530 copy( $filePath, $destination );
531
532 $fileHandler = eZClusterFileHandler::instance();
533 $fileHandler->fileStore( $destination, 'mediafile', true, $mimeData['name'] );
534
535 $classAttribute = $objectAttribute->contentClassAttribute();
536 $player = $classAttribute->attribute( "data_text1" );
537 $pluginPage = eZMediaType::pluginPage( $player );
538
539 $media->setAttribute( "contentobject_attribute_id", $attributeID );
540 $media->setAttribute( "version", $objectVersion );
541 $media->setAttribute( "filename", $destFileName );
542 $media->setAttribute( "original_filename", $fileName );
543 $media->setAttribute( "mime_type", $mimeData['name'] );
544
545 // Setting width and height to zero means that the browser/player must find the size itself.
546 // In the future we will probably analyze the media file and find this information
547 $width = $height = 0;
548 // Quality is not known, so we don't set any
549 $quality = false;
550 // Not sure what this is for, set to false
551 $controls = false;
552 // We want to show controllers by default
553 $hasController = true;
554 // Don't play automatically
555 $isAutoplay = false;
556 // Don't loop movie
557 $isLoop = false;
558
559 $media->setAttribute( "width", $width );
560 $media->setAttribute( "height", $height );
561 $media->setAttribute( "quality", $quality );
562 $media->setAttribute( "controls", $controls );
563 $media->setAttribute( "pluginspage", $pluginPage );
564 $media->setAttribute( "is_autoplay", $isAutoplay );
565 $media->setAttribute( "has_controller", $hasController );
566 $media->setAttribute( "is_loop", $isLoop );
567
568 $media->store();
569
570 $objectAttribute->setContent( $media );
571 return true;
572 }
573
577 function hasStoredFileInformation( $object, $objectVersion, $objectLanguage,
578 $objectAttribute )
579 {
580 return true;
581 }
582
586 function storedFileInformation( $object, $objectVersion, $objectLanguage,
587 $objectAttribute )
588 {
589 $mediaFile = eZMedia::fetch( $objectAttribute->attribute( "id" ),
590 $objectAttribute->attribute( "version" ) );
591 if ( $mediaFile )
592 {
593 return $mediaFile->storedFileInfo();
594 }
595 return false;
596 }
597
598 function storeClassAttribute( $attribute, $version )
599 {
600 }
601
602 function storeDefinedClassAttribute( $attribute )
603 {
604 }
605
606 function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
607 {
608 return eZInputValidator::STATE_ACCEPTED;
609 }
610
611 function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
612 {
613 }
614
615 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
616 {
617 $filesizeName = $base . self::MAX_FILESIZE_VARIABLE . $classAttribute->attribute( 'id' );
618 $typeName = $base . self::TYPE_VARIABLE . $classAttribute->attribute( 'id' );
619 if ( $http->hasPostVariable( $filesizeName ) )
620 {
621 $filesizeValue = $http->postVariable( $filesizeName );
622 $classAttribute->setAttribute( self::MAX_FILESIZE_FIELD, $filesizeValue );
623 }
624 if ( $http->hasPostVariable( $typeName ) )
625 {
626 $typeValue = $http->postVariable( $typeName );
627 $classAttribute->setAttribute( self::TYPE_FIELD, $typeValue );
628 }
629 }
630
634 function title( $contentObjectAttribute, $name = "original_filename" )
635 {
636 $mediaFile = eZMedia::fetch( $contentObjectAttribute->attribute( "id" ),
637 $contentObjectAttribute->attribute( "version" ) );
638
639 if ( $mediaFile != null )
640 $value = $mediaFile->attribute( $name );
641 else
642 $value = "";
643 return $value;
644 }
645
646 function hasObjectAttributeContent( $contentObjectAttribute )
647 {
648 $mediaFile = eZMedia::fetch( $contentObjectAttribute->attribute( "id" ),
649 $contentObjectAttribute->attribute( "version" ) );
650 if ( !$mediaFile )
651 return false;
652 if( $mediaFile->attribute( "filename" ) == "" )
653 return false;
654 return true;
655 }
656
657 function objectAttributeContent( $contentObjectAttribute )
658 {
659 $mediaFile = eZMedia::fetch( $contentObjectAttribute->attribute( "id" ),
660 $contentObjectAttribute->attribute( "version" ) );
661 if ( !$mediaFile )
662 {
663 $retValue = false;
664 return $retValue;
665 }
666 return $mediaFile;
667 }
668
669 function metaData( $contentObjectAttribute )
670 {
671 return "";
672 }
677 function toString( $objectAttribute )
678 {
679 $mediaFile = $objectAttribute->content();
680
681 if ( is_object( $mediaFile ) )
682 {
683 return implode( '|', array( $mediaFile->attribute( 'filepath' ), $mediaFile->attribute( 'original_filename' ) ) );
684 }
685 else
686 return '';
687 }
688
689
690
691 function fromString( $objectAttribute, $string )
692 {
693 if( !$string )
694 return true;
695
696 $result = array();
697 return $this->insertRegularFile( $objectAttribute->attribute( 'object' ),
698 $objectAttribute->attribute( 'version' ),
699 $objectAttribute->attribute( 'language_code' ),
700 $objectAttribute,
701 $string,
702 $result );
703
704 }
705
706 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
707 {
708 $maxSize = $classAttribute->attribute( self::MAX_FILESIZE_FIELD );
709 $type = $classAttribute->attribute( self::TYPE_FIELD );
710
711 $dom = $attributeParametersNode->ownerDocument;
712
713 $maxSizeNode = $dom->createElement( 'max-size' );
714 $maxSizeNode->appendChild( $dom->createTextNode( $maxSize ) );
715 $maxSizeNode->setAttribute( 'unit-size', 'mega' );
716 $attributeParametersNode->appendChild( $maxSizeNode );
717
718 $typeNode = $dom->createElement( 'type' );
719 $typeNode->appendChild( $dom->createTextNode( $type ) );
720 $attributeParametersNode->appendChild( $typeNode );
721 }
722
723 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
724 {
725 $sizeNode = $attributeParametersNode->getElementsByTagName( 'max-size' )->item( 0 );
726 $maxSize = $sizeNode->textContent;
727 $unitSize = $sizeNode->getAttribute( 'unit-size' );
728 $type = $attributeParametersNode->getElementsByTagName( 'type' )->item( 0 )->textContent;
729 $classAttribute->setAttribute( self::MAX_FILESIZE_FIELD, $maxSize );
730 $classAttribute->setAttribute( self::TYPE_FIELD, $type );
731 }
732
733 function serializeContentObjectAttribute( $package, $objectAttribute )
734 {
735
736 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
737
738 $mediaFile = $objectAttribute->attribute( 'content' );
739 if ( !$mediaFile )
740 {
741 // Media type content could not be found.
742 return $node;
743 }
744
745 $fileKey = md5( mt_rand() );
746
747 $fileInfo = $mediaFile->storedFileInfo();
748 $package->appendSimpleFile( $fileKey, $fileInfo['filepath'] );
749
750 $dom = $node->ownerDocument;
751
752 $mediaNode = $dom->createElement( 'media-file' );
753 $mediaNode->setAttribute( 'filesize', $mediaFile->attribute( 'filesize' ) );
754 $mediaNode->setAttribute( 'filename', $mediaFile->attribute( 'filename' ) );
755 $mediaNode->setAttribute( 'original-filename', $mediaFile->attribute( 'original_filename' ) );
756 $mediaNode->setAttribute( 'mime-type', $mediaFile->attribute( 'mime_type' ) );
757 $mediaNode->setAttribute( 'filekey', $fileKey );
758
759 $mediaNode->setAttribute( 'width', $mediaFile->attribute( 'width' ) );
760 $mediaNode->setAttribute( 'height', $mediaFile->attribute( 'height' ) );
761 $mediaNode->setAttribute( 'has-controller', $mediaFile->attribute( 'has_controller' ) );
762 $mediaNode->setAttribute( 'controls', $mediaFile->attribute( 'controls' ) );
763 $mediaNode->setAttribute( 'is-autoplay', $mediaFile->attribute( 'is_autoplay' ) );
764 $mediaNode->setAttribute( 'plugins-page', $mediaFile->attribute( 'pluginspage' ) );
765 $mediaNode->setAttribute( 'quality', $mediaFile->attribute( 'quality' ) );
766 $mediaNode->setAttribute( 'is-loop', $mediaFile->attribute( 'is_loop' ) );
767 $node->appendChild( $mediaNode );
768
769 return $node;
770 }
771
772 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
773 {
774 $mediaNode = $attributeNode->getElementsByTagName( 'media-file' )->item( 0 );
775 if ( !$mediaNode )
776 {
777 // No media type data found.
778 return;
779 }
780
781 $mediaFile = eZMedia::create( $objectAttribute->attribute( 'id' ), $objectAttribute->attribute( 'version' ) );
782
783 $sourcePath = $package->simpleFilePath( $mediaNode->getAttribute( 'filekey' ) );
784
785 $ini = eZINI::instance();
786 $mimeType = $mediaNode->getAttribute( 'mime-type' );
787 list( $mimeTypeCategory, $mimeTypeName ) = explode( '/', $mimeType );
788 $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/';
789 if ( !file_exists( $destinationPath ) )
790 {
791 if ( !eZDir::mkdir( $destinationPath, false, true ) )
792 {
793 return false;
794 }
795 }
796
797 $basename = basename( $mediaNode->getAttribute( 'filename' ) );
798 while ( file_exists( $destinationPath . $basename ) )
799 {
800 $basename = substr( md5( mt_rand() ), 0, 8 ) . '.' . eZFile::suffix( $mediaNode->getAttribute( 'filename' ) );
801 }
802
803 eZFileHandler::copy( $sourcePath, $destinationPath . $basename );
804 eZDebug::writeNotice( 'Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename, __METHOD__ );
805
806 $mediaFile->setAttribute( 'contentobject_attribute_id', $objectAttribute->attribute( 'id' ) );
807 $mediaFile->setAttribute( 'filename', $basename );
808 $mediaFile->setAttribute( 'original_filename', $mediaNode->getAttribute( 'original-filename' ) );
809 $mediaFile->setAttribute( 'mime_type', $mediaNode->getAttribute( 'mime-type' ) );
810
811 $mediaFile->setAttribute( 'width', $mediaNode->getAttribute( 'width' ) );
812 $mediaFile->setAttribute( 'height', $mediaNode->getAttribute( 'height' ) );
813 $mediaFile->setAttribute( 'has_controller', $mediaNode->getAttribute( 'has-controller' ) );
814 $mediaFile->setAttribute( 'controls', $mediaNode->getAttribute( 'controls' ) );
815 $mediaFile->setAttribute( 'is_autoplay', $mediaNode->getAttribute( 'is-autoplay' ) );
816 $mediaFile->setAttribute( 'pluginspage', $mediaNode->getAttribute( 'plugins-page' ) );
817 $mediaFile->setAttribute( 'quality', $mediaNode->getAttribute( 'quality' ) );
818 $mediaFile->setAttribute( 'is_loop', $mediaNode->getAttribute( 'is-loop' ) );
819
820 $fileHandler = eZClusterFileHandler::instance();
821 $fileHandler->fileStore( $destinationPath . $basename, 'mediafile', true );
822
823 $mediaFile->store();
824 }
825
826 function supportsBatchInitializeObjectAttribute()
827 {
828 return true;
829 }
830
833 private $FileExtensionBlackListValidator;
834 }
835
836 eZDataType::register( eZMediaType::DATA_TYPE_STRING, "eZMediaType" );
837
838 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZDataType\createContentObjectAttributeDOMNode
createContentObjectAttributeDOMNode( $objectAttribute)
Definition: ezdatatype.php:1371
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZError\KERNEL_NOT_AVAILABLE
const KERNEL_NOT_AVAILABLE
Definition: ezerror.php:29
eZFileExtensionBlackListValidator
The class eZFileExtensionBlackListValidator validates file extensions based on a blacklist.
Definition: ezfileextensionblacklistvalidator.php:17
eZFileHandler\copy
static copy( $sourceFilename, $destinationFilename)
Definition: ezfilehandler.php:356
eZFile\suffix
static suffix( $filename)
Definition: ezfile.php:102
eZHTTPFile
Provides access to HTTP post files.
Definition: ezhttpfile.php:23
eZHTTPFile\UPLOADEDFILE_EXCEEDS_MAX_SIZE
const UPLOADEDFILE_EXCEEDS_MAX_SIZE
Definition: ezhttpfile.php:27
eZHTTPFile\canFetch
static canFetch( $httpName, $maxSize=false)
Definition: ezhttpfile.php:203
eZHTTPFile\fetch
static fetch( $http_name)
Definition: ezhttpfile.php:269
eZHTTPFile\UPLOADEDFILE_EXCEEDS_PHP_LIMIT
const UPLOADEDFILE_EXCEEDS_PHP_LIMIT
Definition: ezhttpfile.php:26
eZHTTPFile\UPLOADEDFILE_DOES_NOT_EXIST
const UPLOADEDFILE_DOES_NOT_EXIST
Definition: ezhttpfile.php:25
eZInputValidator\STATE_INTERMEDIATE
const STATE_INTERMEDIATE
Definition: ezinputvalidator.php:80
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZMediaType
The class eZMediaType handles storage and playback of media files.
Definition: ezmediatype.php:19
eZMediaType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezmediatype.php:723
eZMediaType\$FileExtensionBlackListValidator
$FileExtensionBlackListValidator
Definition: ezmediatype.php:833
eZMediaType\deleteStoredObjectAttribute
deleteStoredObjectAttribute( $contentObjectAttribute, $version=null)
Definition: ezmediatype.php:121
eZMediaType\TYPE_VARIABLE
const TYPE_VARIABLE
Definition: ezmediatype.php:24
eZMediaType\fromString
fromString( $objectAttribute, $string)
Definition: ezmediatype.php:691
eZMediaType\insertHTTPFile
insertHTTPFile( $object, $objectVersion, $objectLanguage, $objectAttribute, $httpFile, $mimeData, &$result)
Definition: ezmediatype.php:424
eZMediaType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezmediatype.php:295
eZMediaType\fixupClassAttributeHTTPInput
fixupClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezmediatype.php:611
eZMediaType\__construct
__construct()
Definition: ezmediatype.php:26
eZMediaType\insertRegularFile
insertRegularFile( $object, $objectVersion, $objectLanguage, $objectAttribute, $filePath, &$result)
Definition: ezmediatype.php:492
eZMediaType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezmediatype.php:178
eZMediaType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezmediatype.php:20
eZMediaType\postInitializeObjectAttribute
postInitializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezmediatype.php:36
eZMediaType\MAX_FILESIZE_VARIABLE
const MAX_FILESIZE_VARIABLE
Definition: ezmediatype.php:22
eZMediaType\unserializeContentObjectAttribute
unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode)
Definition: ezmediatype.php:772
eZMediaType\checkFileUploads
checkFileUploads()
Definition: ezmediatype.php:243
eZMediaType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezmediatype.php:615
eZMediaType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezmediatype.php:657
eZMediaType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezmediatype.php:826
eZMediaType\title
title( $contentObjectAttribute, $name="original_filename")
Definition: ezmediatype.php:634
eZMediaType\hasStoredFileInformation
hasStoredFileInformation( $object, $objectVersion, $objectLanguage, $objectAttribute)
Definition: ezmediatype.php:577
eZMediaType\isHTTPFileInsertionSupported
isHTTPFileInsertionSupported()
Definition: ezmediatype.php:408
eZMediaType\isRegularFileInsertionSupported
isRegularFileInsertionSupported()
Definition: ezmediatype.php:416
eZMediaType\MAX_FILESIZE_FIELD
const MAX_FILESIZE_FIELD
Definition: ezmediatype.php:21
eZMediaType\storeDefinedClassAttribute
storeDefinedClassAttribute( $attribute)
Definition: ezmediatype.php:602
eZMediaType\pluginPage
pluginPage( $mediaType)
Definition: ezmediatype.php:264
eZMediaType\storedFileInformation
storedFileInformation( $object, $objectVersion, $objectLanguage, $objectAttribute)
Definition: ezmediatype.php:586
eZMediaType\metaData
metaData( $contentObjectAttribute)
Definition: ezmediatype.php:669
eZMediaType\TYPE_FIELD
const TYPE_FIELD
Definition: ezmediatype.php:23
eZMediaType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezmediatype.php:706
eZMediaType\toString
toString( $objectAttribute)
Definition: ezmediatype.php:677
eZMediaType\storeClassAttribute
storeClassAttribute( $attribute, $version)
Definition: ezmediatype.php:598
eZMediaType\storeObjectAttribute
storeObjectAttribute( $contentObjectAttribute)
Definition: ezmediatype.php:389
eZMediaType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezmediatype.php:606
eZMediaType\customObjectAttributeHTTPAction
customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters)
Definition: ezmediatype.php:393
eZMediaType\serializeContentObjectAttribute
serializeContentObjectAttribute( $package, $objectAttribute)
Definition: ezmediatype.php:733
eZMediaType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezmediatype.php:646
eZMediaType\trashStoredObjectAttribute
trashStoredObjectAttribute( $contentObjectAttribute, $version=null)
Definition: ezmediatype.php:70
eZMedia\fetchByFileName
static fetchByFileName( $filename, $version=null, $asObject=true)
Definition: ezmedia.php:163
eZMedia\create
static create( $contentObjectAttributeID, $version)
Definition: ezmedia.php:123
eZMedia\fetch
static fetch( $id, $version, $asObject=true)
Definition: ezmedia.php:142
eZMedia\fetchByContentObjectID
static fetchByContentObjectID( $contentObjectID, $languageCode=null, $asObject=true)
Definition: ezmedia.php:191
eZMedia\removeByID
static removeByID( $id, $version)
Definition: ezmedia.php:219
eZMimeType\findByFileContents
static findByFileContents( $url, $returnDefault=true)
Definition: ezmimetype.php:308
eZSys\storageDirectory
static storageDirectory()
Definition: ezsys.php:514
eZSys\instance
static instance()
Definition: ezsys.php:1272
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.