Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezimagealiashandler.php
Go to the documentation of this file.
1 <?php
27 class eZImageAliasHandler
28 {
34 public function __construct( $contentObjectAttribute )
35 {
36 $this->ContentObjectAttributeData = array();
37 if ( is_object( $contentObjectAttribute ) )
38 {
39 $this->ContentObjectAttributeData['id'] = $contentObjectAttribute->attribute( 'id' );
40 $this->ContentObjectAttributeData['contentobject_id'] = $contentObjectAttribute->attribute( 'contentobject_id' );
41 $this->ContentObjectAttributeData['version'] = $contentObjectAttribute->attribute( 'version' );
42 $this->ContentObjectAttributeData['language_code'] = $contentObjectAttribute->attribute( 'language_code' );
43 $this->ContentObjectAttributeData['can_translate'] = $contentObjectAttribute->attribute( 'can_translate' );
44 $this->ContentObjectAttributeData['data_text'] = $contentObjectAttribute->attribute( 'data_text' );
45 $this->ContentObjectAttributeData['DataTypeCustom'] = $contentObjectAttribute->DataTypeCustom;
46 if ( !is_array( $this->ContentObjectAttributeData['DataTypeCustom'] ) )
47 {
48 $this->ContentObjectAttributeData['DataTypeCustom'] = array();
49 }
50 }
51 else
52 {
53 eZDebug::writeWarning( 'Invalid eZContentObjectAttribute', __METHOD__ );
54 }
55 }
56
63 function attributes()
64 {
65 $imageManager = eZImageManager::factory();
66 $aliasList = $imageManager->aliasList();
67 return array_merge( array( 'alternative_text',
68 'original_filename',
69 'is_valid' ),
70 array_keys( $aliasList ) );
71 }
72
77 function hasAttribute( $attributeName )
78 {
79 if ( in_array( $attributeName,
80 array( 'alternative_text',
81 'original_filename',
82 'is_valid' ) ) )
83 return true;
84
85 $imageManager = eZImageManager::factory();
86 if ( $imageManager->hasAlias( $attributeName ) )
87 return true;
88 return false;
89 }
90
95 function attribute( $attributeName )
96 {
97 if ( in_array( $attributeName,
98 array( 'alternative_text',
99 'original_filename',
100 'is_valid' ) ) )
101 {
102 return $this->attributeFromOriginal( $attributeName );
103 }
104 $aliasName = $attributeName;
105 return $this->imageAlias( $aliasName );
106 }
107
113 function &attributeFromOriginal( $attributeName )
114 {
115 $originalAlias = $this->attribute( 'original' );
116 if ( $originalAlias )
117 return $originalAlias[$attributeName];
118 $retValue = null;
119 return $retValue;
120 }
121
129 function setAttribute( $attributeName, $attributeValue )
130 {
131 if ( in_array( $attributeName,
132 array( 'alternative_text',
133 'original_filename' ) ) )
134 {
135 $aliasList = $this->aliasList();
136 foreach ( array_keys( $aliasList ) as $aliasName )
137 {
138 $this->setAliasAttribute( $aliasName, $attributeName, $attributeValue );
139 }
140 if ( $attributeName == 'alternative_text' )
141 {
142 $text = $this->displayText( $attributeValue );
143 foreach ( array_keys( $aliasList ) as $aliasName )
144 {
145 $this->setAliasAttribute( $aliasName, 'text', $text );
146 }
147 }
148 $this->recreateDOMTree();
149 $this->setStorageRequired();
150 return true;
151 }
152 return false;
153 }
154
162 function isImageOwner()
163 {
164 $originalData = $this->originalAttributeData();
165 return ( $originalData['attribute_id'] == false ||
166 ( $originalData['attribute_id'] == $this->ContentObjectAttributeData['id'] &&
167 $originalData['attribute_version'] == $this->ContentObjectAttributeData['version'] &&
168 $originalData['attribute_language'] == $this->ContentObjectAttributeData['language_code'] ) );
169 }
170
182 function imageSerialNumber()
183 {
184 $serialNumber = $this->imageSerialNumberRaw();
185 if ( $serialNumber < 1 )
186 {
187 $serialNumber = 1;
188 }
189 return $serialNumber;
190 }
191
195 function increaseImageSerialNumber()
196 {
197 $this->setImageSerialNumber( $this->imageSerialNumberRaw() + 1 );
198 }
199
203 function resetImageSerialNumber()
204 {
205 $this->setImageSerialNumber( 0 );
206 }
207
214 function displayText( $alternativeText = null )
215 {
216 if ( $alternativeText === null )
217 $text = $this->attribute( 'alternative_text' );
218 else
219 $text = $alternativeText;
220
221 return $text;
222 }
223
227 function directoryPath()
228 {
229 $aliasList = $this->aliasList();
230 if ( isset( $aliasList['original'] ) )
231 {
232 return $aliasList['original']['dirpath'];
233 }
234 return false;
235 }
236
247 function imageName( $contentObjectAttribute, $contentVersion, $language = false )
248 {
249 if ( $language === false )
250 {
251 if ( is_object( $contentObjectAttribute ) ) // for backward compatibility when eZImageAliasHandler used $this->contentObjectAttribute
252 {
253 $language = $contentObjectAttribute->attribute( 'language_code' );
254 }
255 else
256 {
257 $language = $contentObjectAttribute['language_code'];
258 }
259 }
260 $objectName = $contentVersion->versionName( $language );
261 if ( !$objectName )
262 {
263 $objectName = $contentVersion->name( $language );
264 if ( !$objectName )
265 {
266 $objectName = $this->attribute( 'alternative_text' );
267 if ( !$objectName )
268 {
269 $objectName = ezpI18n::tr( 'kernel/classes/datatypes', 'image', 'Default image name' );
270 }
271 }
272 }
273 $objectName = eZImageAliasHandler::normalizeImageName( $objectName );
274 $objectName = $this->trimToFileSystemFileName( $objectName ) . $this->imageSerialNumber();
275
276 return $objectName;
277 }
278
286 function imageNameByNode( $contentObjectAttribute, $mainNode, $language = false )
287 {
288 if ( $language === false )
289 {
290 if ( is_object( $contentObjectAttribute ) ) // for backward compatibility when eZImageAliasHandler used $this->contentObjectAttribute
291 {
292 $language = $contentObjectAttribute->attribute( 'language_code' );
293 }
294 else
295 {
296 $language = $contentObjectAttribute['language_code'];
297 }
298 }
299 $objectName = $mainNode->getName( $language );
300 if ( !$objectName )
301 {
302 $objectName = $this->attribute( 'alternative_text' );
303 if ( !$objectName )
304 {
305 $objectName = ezpI18n::tr( 'kernel/classes/datatypes', 'image', 'Default image name' );
306 }
307 }
308 $objectName = eZImageAliasHandler::normalizeImageName( $objectName );
309 return $this->trimToFileSystemFileName( $objectName );
310 }
311
319 function imagePath( $contentObjectAttribute, $contentVersion, $isImageOwner = null )
320 {
321 $useVersion = false;
322 if ( $isImageOwner === null )
323 $isImageOwner = $this->isImageOwner();
324 if ( $contentVersion->attribute( 'status' ) == eZContentObjectVersion::STATUS_PUBLISHED or
325 !$isImageOwner )
326 {
327 $contentObject = $contentVersion->attribute( 'contentobject' );
328 $mainNode = $contentObject->attribute( 'main_node' );
329 if ( !$mainNode )
330 {
331 $ini = eZINI::instance( 'image.ini' );
332 $contentImageSubtree = $ini->variable( 'FileSettings', 'VersionedImages' );
333 $pathString = $contentImageSubtree;
334 $useVersion = true;
335 }
336 else
337 {
338 $ini = eZINI::instance( 'image.ini' );
339 $contentImageSubtree = $ini->variable( 'FileSettings', 'PublishedImages' );
340 $pathString = $mainNode->pathWithNames();
341 $pathString = function_exists( 'mb_strtolower' ) ? mb_strtolower( $pathString ) : strtolower( $pathString );
342 $pathString = $contentImageSubtree . '/' . $pathString;
343 }
344 }
345 else
346 {
347 $ini = eZINI::instance( 'image.ini' );
348 $contentImageSubtree = $ini->variable( 'FileSettings', 'VersionedImages' );
349 $pathString = $contentImageSubtree;
350 $useVersion = true;
351 }
352 $attributeData = $this->originalAttributeData();
353 $attributeID = $attributeData['attribute_id'];
354 $attributeVersion = $attributeData['attribute_version'];
355 $attributeLanguage = $attributeData['attribute_language'];
356 if ( $useVersion )
357 $identifierString = $attributeID . '/' . $attributeVersion . '-' . $attributeLanguage;
358 else
359 $identifierString = $attributeID . '-' . $attributeVersion . '-' . $attributeLanguage;
360 $imagePath = eZSys::storageDirectory() . '/' . $pathString . '/' . $identifierString;
361 return $imagePath;
362 }
363
369 function imagePathByNode( $contentObjectAttribute, $mainNode )
370 {
371 $pathString = $mainNode->pathWithNames();
372 $pathString = function_exists( 'mb_strtolower' ) ? mb_strtolower( $pathString ) : strtolower( $pathString );
373
374 $ini = eZINI::instance( 'image.ini' );
375 $contentImageSubtree = $ini->variable( 'FileSettings', 'PublishedImages' );
376 $attributeData = $this->originalAttributeData();
377 $attributeID = $attributeData['attribute_id'];
378 $attributeVersion = $attributeData['attribute_version'];
379 $attributeLanguage = $attributeData['attribute_language'];
380 $pathParts = array( eZSys::storageDirectory(), $contentImageSubtree );
381 if ( $pathString != '' )
382 {
383 //Make sure that all folders are smaller than the FS limit
384 foreach ( explode( '/', $pathString ) as $folder )
385 {
386 $pathParts[] = $this->trimToFileSystemFileName( $folder );
387 }
388 }
389 $pathParts[] = $attributeID . '-' . $attributeVersion . '-' . $attributeLanguage;
390 $imagePath = implode( '/', $pathParts );
391 return $imagePath;
392 }
393
403 private function trimToFileSystemFileName( $longName, $limit = 200 )
404 {
405 if ( strlen( $longName ) <= $limit )
406 {
407 return $longName;
408 }
409
410 return mb_strcut( $longName, 0, $limit, "utf-8" );
411 }
412
419 function imageAlias( $aliasName )
420 {
421 $imageManager = eZImageManager::factory();
422 if ( !$imageManager->hasAlias( $aliasName ) )
423 {
424 return null;
425 }
426
427 $aliasList = $this->aliasList();
428 if ( array_key_exists( $aliasName, $aliasList ) )
429 {
430 return $aliasList[$aliasName];
431 }
432 else
433 {
434 $original = $aliasList['original'];
435 $basename = $original['basename'];
436 if ( $imageManager->createImageAlias( $aliasName, $aliasList,
437 array( 'basename' => $basename ) ) )
438 {
439 $text = $this->displayText( $original['alternative_text'] );
440 $originalFilename = $original['original_filename'];
441 foreach ( $aliasList as $aliasKey => $alias )
442 {
443 $alias['original_filename'] = $originalFilename;
444 $alias['text'] = $text;
445 if ( $alias['url'] )
446 {
447 $aliasFile = eZClusterFileHandler::instance( $alias['url'] );
448 if( $aliasFile->exists() )
449 $alias['filesize'] = $aliasFile->size();
450 }
451 if ( $alias['is_new'] )
452 {
453 eZImageFile::appendFilepath( $this->ContentObjectAttributeData['id'], $alias['url'] );
454 }
455 $aliasList[$aliasKey] = $alias;
456 }
457 $this->setAliasList( $aliasList );
458 $this->addImageAliases( $aliasList );
459 $aliasList = $this->aliasList();
460 return $aliasList[$aliasName];
461 }
462 }
463
464 return null;
465 }
466
472 protected function setAliasList( $aliasList )
473 {
474 $this->ContentObjectAttributeData['DataTypeCustom']['alias_list'] = $aliasList;
475 }
476
477 /*
478 Set alias variation
479
480 \param alias name
481 \param variation array
482 */
483 protected function setAliasVariation( $aliasName, $variation )
484 {
485 $this->ContentObjectAttributeData['DataTypeCustom']['alias_list'][$aliasName] = $variation;
486 }
487
495 protected function setAliasAttribute( $aliasName, $attributeName, $value )
496 {
497 $this->ContentObjectAttributeData['DataTypeCustom']['alias_list'][$aliasName][$attributeName] = $value;
498 }
499
507 function aliasList( $checkValidity = true )
508 {
509 if ( $checkValidity && isset( $this->ContentObjectAttributeData['DataTypeCustom']['alias_list'] ) )
510 {
511 return $this->ContentObjectAttributeData['DataTypeCustom']['alias_list'];
512 }
513
514 eZDebug::accumulatorStart('imageparse', 'XML', 'Image XML parsing' );
515
516 $domTree = new DOMDocument( '1.0', 'utf-8' );
517
518 $xmlString = $this->ContentObjectAttributeData['data_text'];
519
520 $success = false;
521 if ( $xmlString != '' )
522 {
523 $success = $domTree->loadXML( $xmlString );
524 }
525
526 if ( !$success )
527 {
528 $this->generateXMLData();
529 $xmlString = $this->ContentObjectAttributeData['data_text'];
530 $success = $domTree->loadXML( $xmlString );
531 }
532
533 $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'] = $domTree;
534 $imageNodeArray = $domTree->getElementsByTagName( "ezimage" );
535
536 $aliasList = array();
537
538 // I think this is a bug in the plain package or related to the bug I filed
539 // about the image datatype serialization
540 // http://ez.no/bugs/view/8821 ezpm Error: (eZFileHandler::copy) Unable to open source file in read mode
541 if ( $imageNodeArray->length == 0 )
542 {
543 return $aliasList;
544 }
545
546 $imageNode = $imageNodeArray->item( 0 );
547
548 $imageInfoNodeArray = $imageNode->getElementsByTagName( "information" );
549 $imageVariationNodeArray = $imageNode->getElementsByTagName( "alias" );
550 $imageOriginalArray = $imageNode->getElementsByTagName( "original" );
551
552 $aliasEntry = array();
553
554 $alternativeText = $imageNode->getAttribute( 'alternative_text' );
555 $originalFilename = $imageNode->getAttribute( 'original_filename' );
556 $basename = $imageNode->getAttribute( 'basename' );
557 $displayText = $this->displayText( $alternativeText );
558
559 $originalData = array( 'attribute_id' => '',
560 'attribute_version' => '',
561 'attribute_language' => '' );
562 if ( $imageOriginalArray->length > 0 )
563 {
564 $imageOriginalNode = $imageOriginalArray->item( 0 );
565 $originalData = array( 'attribute_id' => $imageOriginalNode->getAttribute( 'attribute_id' ),
566 'attribute_version' => $imageOriginalNode->getAttribute( 'attribute_version' ),
567 'attribute_language' => $imageOriginalNode->getAttribute( 'attribute_language' ) );
568 }
569 if ( strlen( $originalData['attribute_id'] ) == 0 ||
570 strlen( $originalData['attribute_version'] ) == 0 ||
571 strlen( $originalData['attribute_language'] ) == 0 )
572 {
573 $originalData = array( 'attribute_id' => $this->ContentObjectAttributeData['id'],
574 'attribute_version' => $this->ContentObjectAttributeData['version'],
575 'attribute_language' => $this->ContentObjectAttributeData['language_code'] );
576 }
577 $this->setOriginalAttributeData( $originalData );
578
579 $aliasEntry['name'] = 'original';
580 $aliasEntry['width'] = $imageNode->getAttribute( 'width' );
581 $aliasEntry['height'] = $imageNode->getAttribute( 'height' );
582 $aliasEntry['mime_type'] = $imageNode->getAttribute( 'mime_type' );
583 $aliasEntry['filename'] = $imageNode->getAttribute( 'filename' );
584 $aliasEntry['suffix'] = $imageNode->getAttribute( 'suffix' );
585 $aliasEntry['dirpath'] = $imageNode->getAttribute( 'dirpath' );
586 $aliasEntry['basename'] = $basename;
587 $aliasEntry['alternative_text'] = $alternativeText;
588 $aliasEntry['text'] = $displayText;
589 $aliasEntry['original_filename'] = $originalFilename;
590 $aliasEntry['url'] = $imageNode->getAttribute( 'url' );
591 $aliasEntry['alias_key'] = $imageNode->getAttribute( 'alias_key' );
592 $aliasEntry['timestamp'] = $imageNode->getAttribute( 'timestamp' );
593 $aliasEntry['full_path'] = $aliasEntry['url'];
594 $aliasEntry['is_valid'] = $imageNode->getAttribute( 'is_valid' );
595 $aliasEntry['is_new'] = false;
596 $aliasEntry['filesize'] = false;
597
598 if ( $aliasEntry['url'] )
599 {
600 $aliasFile = eZClusterFileHandler::instance( $aliasEntry['url'] );
601
602 if ( $aliasFile->exists() )
603 $aliasEntry['filesize'] = $aliasFile->size();
604 }
605
606 $imageInformation = false;
607 if ( $imageInfoNodeArray->length > 0 )
608 {
609 $imageInfoNode = $imageInfoNodeArray->item( 0 );
610 $imageInformation = $this->parseInformationNode( $imageInfoNode );
611 }
612 $aliasEntry['info'] = $imageInformation;
613
614 $serialNumber = $imageNode->getAttribute( 'serial_number' );
615 if ( $serialNumber )
616 {
617 $this->setImageSerialNumber( $serialNumber );
618 }
619
620 $aliasList['original'] = $aliasEntry;
621
622 if ( $imageVariationNodeArray->length > 0 )
623 {
624 $imageManager = eZImageManager::factory();
625 foreach ( $imageVariationNodeArray as $imageVariation )
626 {
627 $aliasEntry = array();
628 $aliasEntry['name'] = $imageVariation->getAttribute( 'name' );
629 $aliasEntry['width'] = $imageVariation->getAttribute( 'width' );
630 $aliasEntry['height'] = $imageVariation->getAttribute( 'height' );
631 $aliasEntry['mime_type'] = $imageVariation->getAttribute( 'mime_type' );
632 $aliasEntry['filename'] = $imageVariation->getAttribute( 'filename' );
633 $aliasEntry['suffix'] = $imageVariation->getAttribute( 'suffix' );
634 $aliasEntry['dirpath'] = $imageVariation->getAttribute( 'dirpath' );
635 $aliasEntry['alias_key'] = $imageVariation->getAttribute( 'alias_key' );
636 $aliasEntry['timestamp'] = $imageVariation->getAttribute( 'timestamp' );
637 $aliasEntry['is_valid'] = $imageVariation->getAttribute( 'is_valid' );
638 $aliasEntry['url'] = $imageVariation->getAttribute( 'url' );
639 $aliasEntry['basename'] = $basename;
640 $aliasEntry['alternative_text'] = $alternativeText;
641 $aliasEntry['text'] = $displayText;
642 $aliasEntry['original_filename'] = $originalFilename;
643 $aliasEntry['full_path'] = $aliasEntry['url'];
644 $aliasEntry['is_new'] = false;
645 $aliasEntry['info'] = $imageInformation;
646
647 if ( $aliasEntry['url'] )
648 {
649 $aliasFile = eZClusterFileHandler::instance( $aliasEntry['url'] );
650
651 if ( $aliasFile->exists() )
652 $aliasEntry['filesize'] = $aliasFile->size();
653 }
654
655 if ( $imageManager->isImageAliasValid( $aliasEntry ) || !$checkValidity )
656 {
657 $aliasList[$aliasEntry['name']] = $aliasEntry;
658 }
659 }
660 }
661 if ( $checkValidity )
662 $this->setAliasList( $aliasList );
663 eZDebug::accumulatorStop( 'imageparse' );
664 return $aliasList;
665 }
666
675 static function removeAllAliases( $contentObjectAttribute )
676 {
678 $handler = $contentObjectAttribute->attribute( 'content' );
679 if ( !$handler->isImageOwner() )
680 {
681 return;
682 }
683 $attributeData = $handler->originalAttributeData();
684 $files = eZImageFile::fetchForContentObjectAttribute( $attributeData['attribute_id'], false );
685 $dirs = array();
686
687 foreach ( $files as $filepath )
688 {
689 $file = eZClusterFileHandler::instance( $filepath );
690 if ( $file->exists() )
691 {
692 $file->fileDelete( $filepath );
693 $dirs[] = eZDir::dirpath( $filepath );
694 }
695 }
696 $dirs = array_unique( $dirs );
697 foreach ( $dirs as $dirpath )
698 {
699 eZDir::cleanupEmptyDirectories( $dirpath );
700 }
701 eZImageFile::removeForContentObjectAttribute( $attributeData['attribute_id'] );
702 }
703
708 public function purgeAllAliases()
709 {
710 $aliasList = $this->aliasList( false );
711 ezpEvent::getInstance()->notify( 'image/purgeAliases', array( $aliasList['original']['url'] ) );
712 unset( $aliasList['original'] ); // keeping original
713
714 foreach ( $aliasList as $alias )
715 {
716 if ( $alias['is_valid'] && !empty( $alias['url'] ) )
717 $this->removeAliasFile( $alias['url'] );
718
719 // remove entry from DOM model
720 $doc = $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'];
721 $domXPath = new DOMXPath( $doc );
722 foreach ( $domXPath->query( "//alias[@name='{$alias['name']}']") as $aliasNode )
723 {
724 $aliasNode->parentNode->removeChild( $aliasNode );
725 }
726 }
727
728 if ( isset( $doc ) )
729 $this->storeDOMTree( $doc, true, false );
730 }
731
738 function removeAliases()
739 {
740 $aliasList = $this->aliasList();
741 foreach ( $aliasList as $alias )
742 {
743 if ( $alias['is_valid'] && !empty( $alias['url'] ) )
744 $this->removeAliasFile( $alias['url'] );
745 }
746
747 if ( !empty( $aliasList['original']['url'] ) )
748 {
749 ezpEvent::getInstance()->notify( 'image/removeAliases', array( $aliasList['original']['url'] ) );
750 }
751
752 $this->generateXMLData();
753 }
754
764 public function removeAliasFile( $aliasFile )
765 {
766 if ( $aliasFile == '' )
767 throw new InvalidArgumentException( "Expecting image file path" );
768
769 // We only delete the eZImageFile if it isn't referenced by attributes of the same id but different version/language
770 if ( eZImageFile::isReferencedByOtherAttributes(
771 $aliasFile,
772 $this->ContentObjectAttributeData['id'],
773 $this->ContentObjectAttributeData['version'],
774 $this->ContentObjectAttributeData['language_code'] ) )
775 {
776 return;
777 }
778
779 eZImageFile::removeObject(
780 eZImageFile::definition(),
781 array(
782 'contentobject_attribute_id' => $this->ContentObjectAttributeData['id'],
783 'filepath' => $aliasFile
784 )
785 );
786
787 // We only remove the image file if other eZImageFile of the same attribute use it (other versions)
788 if ( eZImageFile::isReferencedByOtherImageFiles( $aliasFile, $this->ContentObjectAttributeData['id'] ) )
789 {
790 return;
791 }
792
793 // finally, remove file if applicable
794 $file = eZClusterFileHandler::instance( $aliasFile );
795 if ( !$file->exists() )
796 {
797 eZDebug::writeError( "Image file {$aliasFile} does not exist, could not remove from disk", __METHOD__ );
798 return;
799 }
800 $file->delete();
801 eZDir::cleanupEmptyDirectories( dirname( $aliasFile ) );
802 }
803
809 function updateAliasPath( $dirpath, $name )
810 {
811 if ( !file_exists( $dirpath ) )
812 {
813 eZDir::mkdir( $dirpath, false, true );
814 }
815 $aliasList = $this->aliasList();
816 $this->resetImageSerialNumber();
817
818 foreach ( $aliasList as $aliasName => $alias )
819 {
820 if ( $alias['dirpath'] != $dirpath )
821 {
822 $oldDirpath = $alias['url'];
823 $oldURL = $alias['url'];
824 $basename = $name;
825 if ( $aliasName != 'original' )
826 $basename .= '_' . $aliasName;
827 eZMimeType::changeFileData( $alias, $dirpath, $basename );
828 $alias['full_path'] = $alias['url'];
829 if ( $this->isImageOwner() )
830 {
831 if ( $oldURL == '' )
832 {
833 continue;
834 }
835
836 $fileHandler = eZClusterFileHandler::instance();
837 $fileHandler->fileMove( $oldURL, $alias['url'] );
838
839 eZDir::cleanupEmptyDirectories( $oldDirpath );
840 eZImageFile::moveFilepath( $this->ContentObjectAttributeData['id'], $oldURL, $alias['url'] );
841 }
842 else
843 {
844 $fileHandler = eZClusterFileHandler::instance();
845 $fileHandler->fileLinkCopy( $oldURL, $alias['url'], false );
846
847 // we still move the file if no other attribute from the current content uses it
848 if ( count( eZImageFile::fetchImageAttributesByFilepath( $oldURL, $this->ContentObjectAttributeData['id'] ) ) == 1 )
849 {
850 eZImageFile::moveFilepath( $this->ContentObjectAttributeData['id'], $oldURL, $alias['url'] );
851 }
852 else
853 {
854 eZImageFile::appendFilepath( $this->ContentObjectAttributeData['id'], $alias['url'] );
855 }
856 }
857 $this->setAliasVariation( $aliasName, $alias );
858 }
859 }
860
861 $this->recreateDOMTree();
862 $this->setStorageRequired();
863 }
864
871 function createOriginalAttributeXMLData( $originalNode, $originalData )
872 {
873 $originalNode->setAttribute( 'attribute_id', $originalData['attribute_id'] );
874 $originalNode->setAttribute( 'attribute_version', $originalData['attribute_version'] );
875 $originalNode->setAttribute( 'attribute_language', $originalData['attribute_language'] );
876 }
877
883 function recreateDOMTree()
884 {
885 $aliasList = $this->aliasList();
886 $doc = new DOMDocument( '1.0', 'utf-8' );
887 $imageNode = $doc->createElement( "ezimage" );
888 $doc->appendChild( $imageNode );
889
890 $originalNode = $doc->createElement( "original" );
891 $imageNode->appendChild( $originalNode );
892
893 $imageManager = eZImageManager::factory();
894
895 $aliasName = 'original';
896
897 $originalData = $this->originalAttributeData();
898 $this->createOriginalAttributeXMLData( $originalNode, $originalData );
899
900 $imageNode->setAttribute( 'serial_number', $this->imageSerialNumber() );
901 $imageNode->setAttribute( 'is_valid', $aliasList[$aliasName]['is_valid'] );
902 $imageNode->setAttribute( 'filename', $aliasList[$aliasName]['filename'] );
903 $imageNode->setAttribute( 'suffix', $aliasList[$aliasName]['suffix'] );
904 $imageNode->setAttribute( 'basename', $aliasList[$aliasName]['basename'] );
905 $imageNode->setAttribute( 'dirpath', $aliasList[$aliasName]['dirpath'] );
906 $imageNode->setAttribute( 'url', $aliasList[$aliasName]['url'] );
907 $imageNode->setAttribute( 'original_filename', $aliasList[$aliasName]['original_filename'] );
908 $imageNode->setAttribute( 'mime_type', $aliasList[$aliasName]['mime_type'] );
909 $imageNode->setAttribute( 'width', $aliasList[$aliasName]['width'] );
910 $imageNode->setAttribute( 'height', $aliasList[$aliasName]['height'] );
911 $imageNode->setAttribute( 'alternative_text', $aliasList[$aliasName]['alternative_text'] );
912 $imageNode->setAttribute( 'alias_key', $imageManager->createImageAliasKey( $imageManager->alias( $aliasName ) ) );
913 $imageNode->setAttribute( 'timestamp', $aliasList[$aliasName]['timestamp'] );
914
915 $filename = $aliasList[$aliasName]['url'];
916 if ( $filename )
917 {
918 $imageFile = eZClusterFileHandler::instance( $filename );
919
920 $fetchedFilePath = $imageFile->fetchUnique();
921
922 //(Cluster) Get mime data of real file, and fetch info by image analizer.
923 $mimeDataTemp = eZMimeType::findByFileContents( $fetchedFilePath );
924 $imageManager->analyzeImage( $mimeDataTemp );
925
926 //(Cluster) Get mime data of a file which does not really exist on file system. We need this to build correct imageInformationNode.
927 $mimeData = eZMimeType::findByURL( $filename );
928 if ( isset( $mimeDataTemp['info'] ) )
929 $mimeData['info'] = $mimeDataTemp['info'];
930
931 $this->createImageInformationNode( $imageNode, $mimeData );
932 $imageFile->fileDeleteLocal( $fetchedFilePath );
933 }
934
935 foreach ( $aliasList as $aliasName => $alias )
936 {
937 if ( $aliasName == 'original' )
938 continue;
939 $this->addImageAliasToXML( $doc, $alias );
940 }
941
942 $this->setDOMTree( $doc );
943 }
944
950 function domTree()
951 {
952 $contentObjectAttributeData = $this->ContentObjectAttributeData;
953 if ( isset( $contentObjectAttributeData['DataTypeCustom']['dom_tree'] ) )
954 {
955 return $contentObjectAttributeData['DataTypeCustom']['dom_tree'];
956 }
957
958 $dom = new DOMDocument( '1.0', 'utf-8' );
959 $xmlString = $contentObjectAttributeData['data_text'];
960 $success = $xmlString == '' ? false : $dom->loadXML( $xmlString );
961 if ( !$success )
962 {
963 $this->generateXMLData();
964 $xmlString = $this->ContentObjectAttributeData['data_text'];
965 $success = $dom->loadXML( $xmlString );
966 }
967
968 $contentObjectAttributeData['DataTypeCustom']['dom_tree'] = $dom;
969
970 return $dom;
971 }
972
984 function parseInformationNode( $imageInfoNode )
985 {
986 $imageInformation = array();
987
988 $attributes = $imageInfoNode->attributes;
989 foreach ( $attributes as $attribute )
990 {
991 $imageInformation[$attribute->name] = $attribute->value;
992 }
993
994 $children = $imageInfoNode->childNodes;
995 foreach ( $children as $child )
996 {
997 if ( $child->nodeType != XML_ELEMENT_NODE )
998 {
999 continue;
1000 }
1001
1002 $childName = false;
1003 if ( isset ( $child->localName ) )
1004 {
1005 $childName = $child->localName;
1006 }
1007
1008 if ( $childName == 'array' )
1009 {
1010 $name = $child->getAttribute( 'name' );
1011 $items = $child->getElementsByTagName( 'item' );
1012 $array = array();
1013 foreach ( $items as $item )
1014 {
1015 $itemValue = $item->textContent;
1016 if ( $item->getAttribute( 'base64' ) == '1' )
1017 {
1018 $array[$item->getAttribute( 'key' )] = base64_decode( $itemValue );
1019 }
1020 else
1021 {
1022 $array[$item->getAttribute( 'key' )] = $itemValue;
1023 }
1024 }
1025 ksort( $array );
1026 $imageInformation[$name] = $array;
1027 }
1028 else if ( $childName == 'serialized' )
1029 {
1030 $name = $child->getAttribute( 'name' );
1031 $data = $child->getAttribute( 'data' );
1032 $imageInformation[$name] = unserialize( $data );
1033 }
1034 }
1035
1036 return $imageInformation;
1037 }
1038
1045 function normalizeImageName( $imageName )
1046 {
1047 // Initialize transformation system
1048 $trans = eZCharTransform::instance();
1049
1050 $imageName = eZURLAliasML::convertToAlias( $imageName );
1051 return $imageName;
1052 }
1053
1064 function setHTTPFile( $httpFile )
1065 {
1066 $this->ContentObjectAttributeData['DataTypeCustom']['http_file'] = $httpFile;
1067 }
1068
1076 function httpFile( $release = false )
1077 {
1078 if ( isset( $this->ContentObjectAttributeData['DataTypeCustom']['http_file'] ) )
1079 {
1080 $httpFile = $this->ContentObjectAttributeData['DataTypeCustom']['http_file'];
1081 if ( $release )
1082 {
1083 unset( $this->ContentObjectAttributeData['DataTypeCustom']['http_file'] );
1084 }
1085 return $httpFile;
1086 }
1087
1088 return false;
1089 }
1090
1099 function initializeFromHTTPFile( $httpFile, $imageAltText = false )
1100 {
1101 $this->increaseImageSerialNumber();
1102
1103 $mimeData = eZMimeType::findByFileContents( $httpFile->attribute( 'filename' ) );
1104 if ( !$mimeData['is_valid'] )
1105 {
1106 $mimeData = eZMimeType::findByName( $httpFile->attribute( 'mime_type' ) );
1107 if ( !$mimeData['is_valid'] )
1108 {
1109 $mimeData = eZMimeType::findByURL( $httpFile->attribute( 'original_filename' ) );
1110 }
1111 }
1112 $this->removeAliases();
1113 $this->setOriginalAttributeDataValues( $this->ContentObjectAttributeData['id'],
1114 $this->ContentObjectAttributeData['version'],
1115 $this->ContentObjectAttributeData['language_code'] );
1116 $contentVersion = eZContentObjectVersion::fetchVersion( $this->ContentObjectAttributeData['version'],
1117 $this->ContentObjectAttributeData['contentobject_id'] );
1118 $objectName = $this->imageName( $this->ContentObjectAttributeData, $contentVersion );
1119 $objectPathString = $this->imagePath( $this->ContentObjectAttributeData, $contentVersion, true );
1120
1121 eZMimeType::changeBaseName( $mimeData, $objectName );
1122 eZMimeType::changeDirectoryPath( $mimeData, $objectPathString );
1123
1124 $httpFile->store( false, false, $mimeData );
1125
1126 $originalFilename = $httpFile->attribute( 'original_filename' );
1127 return $this->initialize( $mimeData, $originalFilename, $imageAltText );
1128 }
1129
1135 function initializeFromFile( $filename, $imageAltText = false, $originalFilename = false )
1136 {
1137 if ( !file_exists( $filename ) )
1138 {
1139 $contentObjectID = isset( $this->ContentObjectAttributeData['contentobject_id'] ) ? $this->ContentObjectAttributeData['contentobject_id'] : 0;
1140 $contentObjectAttributeID = isset( $this->ContentObjectAttributeData['id'] ) ? $this->ContentObjectAttributeData['id'] : 0;
1141 $version = isset( $this->ContentObjectAttributeData['version'] ) ? $this->ContentObjectAttributeData['version'] : 0;
1142 $contentObject = eZContentObject::fetch( $contentObjectID );
1143 $contentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID, $version );
1144 $contentObjectAttributeName = '';
1145 $contentObjectName = '';
1146
1147 if ( $contentObject instanceof eZContentObject )
1148 $contentObjectName = $contentObject->attribute('name');
1149
1150 if ( $contentObjectAttribute instanceof eZContentObjectAttribute )
1151 $contentObjectAttributeName = $contentObjectAttribute->attribute( 'contentclass_attribute_name' );
1152
1153 eZDebug::writeError( "The image '$filename' does not exist, cannot initialize image attribute: '$contentObjectAttributeName' (id: $contentObjectAttributeID) for content object: '$contentObjectName' (id: $contentObjectID)", __METHOD__ );
1154 return false;
1155 }
1156
1157 $this->increaseImageSerialNumber();
1158
1159 if ( !$originalFilename )
1160 $originalFilename = basename( $filename );
1161 $mimeData = eZMimeType::findByFileContents( $filename );
1162 if ( !$mimeData['is_valid'] and
1163 $originalFilename != $filename )
1164 {
1165 $mimeData = eZMimeType::findByFileContents( $originalFilename );
1166 }
1167
1168 $this->removeAliases();
1169 $this->setOriginalAttributeDataValues( $this->ContentObjectAttributeData['id'],
1170 $this->ContentObjectAttributeData['version'],
1171 $this->ContentObjectAttributeData['language_code'] );
1172 $contentVersion = eZContentObjectVersion::fetchVersion( $this->ContentObjectAttributeData['version'],
1173 $this->ContentObjectAttributeData['contentobject_id'] );
1174 $objectName = $this->imageName( $this->ContentObjectAttributeData, $contentVersion );
1175 $objectPathString = $this->imagePath( $this->ContentObjectAttributeData, $contentVersion, true );
1176
1177 eZMimeType::changeBaseName( $mimeData, $objectName );
1178 eZMimeType::changeDirectoryPath( $mimeData, $objectPathString );
1179 if ( !file_exists( $mimeData['dirpath'] ) )
1180 {
1181 eZDir::mkdir( $mimeData['dirpath'], false, true );
1182 }
1183
1184 eZFileHandler::copy( $filename, $mimeData['url'] );
1185
1186 return $this->initialize( $mimeData, $originalFilename, $imageAltText );
1187 }
1188
1196 function initialize( $mimeData, $originalFilename, $imageAltText = false )
1197 {
1198 $imageManager = eZImageManager::factory();
1199
1200 $this->setOriginalAttributeDataValues( $this->ContentObjectAttributeData['id'],
1201 $this->ContentObjectAttributeData['version'],
1202 $this->ContentObjectAttributeData['language_code'] );
1203
1204 $aliasList = array( 'original' => $mimeData );
1205 $aliasList['original']['alternative_text'] = $imageAltText;
1206 $aliasList['original']['original_filename'] = $originalFilename;
1207
1208 $fileHandler = eZClusterFileHandler::instance();
1209 $filePath = $mimeData['url'];
1210 $fileHandler->fileStore( $filePath, 'image', false, $mimeData['name'] );
1211
1212 if ( $imageManager->createImageAlias( 'original', $aliasList, array( 'basename' => $mimeData['basename'] ) ) )
1213 {
1214 $mimeData = $aliasList['original'];
1215 $mimeData['name'] = $mimeData['mime_type'];
1216 $aliasList['original']['original_filename'] = $originalFilename;
1217 }
1218
1219 if ( $aliasList['original']['url'] )
1220 {
1221 $aliasFile = eZClusterFileHandler::instance( $aliasList['original']['url'] );
1222 if( $aliasFile->exists() )
1223 $aliasList['original']['filesize'] = $aliasFile->size();
1224 }
1225
1226 // refetch the original image
1227 $fileHandler->fileFetch( $filePath );
1228
1229 $imageManager->analyzeImage( $mimeData );
1230
1231 $doc = new DOMDocument( '1.0', 'utf-8' );
1232 $imageNode = $doc->createElement( "ezimage" );
1233 $doc->appendChild( $imageNode );
1234
1235 $width = false;
1236 $height = false;
1237 $info = getimagesize( $mimeData['url'] );
1238 if ( $info )
1239 {
1240 $width = $info[0];
1241 $height = $info[1];
1242 }
1243
1244 $originalNode = $doc->createElement( "original" );
1245 $imageNode->appendChild( $originalNode );
1246 $attributeData = $this->originalAttributeData();
1247 $this->createOriginalAttributeXMLData( $originalNode, $attributeData );
1248
1249 $imageNode->setAttribute( 'serial_number', $this->imageSerialNumber() );
1250 $imageNode->setAttribute( 'is_valid', true );
1251 $imageNode->setAttribute( 'filename', $mimeData['filename'] );
1252 $imageNode->setAttribute( 'suffix', $mimeData['suffix'] );
1253 $imageNode->setAttribute( 'basename', $mimeData['basename'] );
1254 $imageNode->setAttribute( 'dirpath', $mimeData['dirpath'] );
1255 $imageNode->setAttribute( 'url', $mimeData['url'] );
1256 $imageNode->setAttribute( 'original_filename', $originalFilename );
1257 $imageNode->setAttribute( 'mime_type', $mimeData['name'] );
1258 $imageNode->setAttribute( 'width', $width );
1259 $imageNode->setAttribute( 'height', $height );
1260 $imageNode->setAttribute( 'alternative_text', $imageAltText );
1261 $imageNode->setAttribute( 'alias_key', $imageManager->createImageAliasKey( $imageManager->alias( 'original' ) ) );
1262 $imageNode->setAttribute( 'timestamp', time() );
1263
1264 $this->createImageInformationNode( $imageNode, $mimeData );
1265
1266 $this->setDOMTree( $doc );
1267
1268 $this->setAliasList( $aliasList );
1269
1270 eZImageFile::appendFilepath( $this->ContentObjectAttributeData['id'], $mimeData['url'] );
1271
1272 $fileHandler->fileDeleteLocal( $filePath );
1273
1274 return true;
1275 }
1276
1277 function createImageInformationNode( $imageNode, $mimeData )
1278 {
1279 $dom = $imageNode->ownerDocument;
1280 if ( isset( $mimeData['info'] ) and
1281 $mimeData['info'] )
1282 {
1283 $imageInfoNode = $dom->createElement( 'information' );
1284 $info = $mimeData['info'];
1285 foreach ( $info as $infoItemName => $infoItem )
1286 {
1287 if ( is_array( $infoItem ) )
1288 {
1289 $hasScalarValues = true;
1290 foreach ( $infoItem as $infoArrayItem )
1291 {
1292 if ( is_array( $infoArrayItem ) )
1293 {
1294 $hasScalarValues = false;
1295 break;
1296 }
1297 }
1298 if ( !$hasScalarValues )
1299 {
1300 $toRemove = array();
1301 foreach ( $infoItem as $key => $value )
1302 {
1303 if ( is_string( $value ) && !ctype_print( $value ) )
1304 {
1305 $toRemove[] = $key;
1306 }
1307 }
1308
1309 if ( count( $toRemove ) > 0 )
1310 {
1311 eZDebug::writeDebug( 'removing image information items containing non-printable characters: ' . implode( ', ', $toRemove ) );
1312
1313 foreach ( $toRemove as $remove )
1314 {
1315 unset( $infoItem[$remove] );
1316 }
1317 }
1318
1319 unset( $serializedNode );
1320 $serializedNode = $dom->createElement( 'serialized' );
1321 $serializedNode->setAttribute( 'name', $infoItemName );
1322 $serializedNode->setAttribute( 'data', serialize( $infoItem ) );
1323
1324 $imageInfoNode->appendChild( $serializedNode );
1325 }
1326 else
1327 {
1328 unset( $arrayNode );
1329 $arrayNode = $dom->createElement( 'array' );
1330 $arrayNode->setAttribute( 'name', $infoItemName );
1331
1332 $imageInfoNode->appendChild( $arrayNode );
1333 foreach ( $infoItem as $infoArrayKey => $infoArrayItem )
1334 {
1335 unset( $arrayItemNode );
1336 $arrayItemNode = $dom->createElement( 'item' );
1337 $arrayItemNode->appendChild( $dom->createTextNode( base64_encode( $infoArrayItem ) ) );
1338 $arrayItemNode->setAttribute( 'key', $infoArrayKey );
1339 $arrayItemNode->setAttribute( 'base64', 1 );
1340
1341 $arrayNode->appendChild( $arrayItemNode );
1342 }
1343 }
1344 }
1345 else
1346 {
1347 $infoItem = iconv( mb_detect_encoding( $infoItem ), 'UTF-8//IGNORE', $infoItem );
1348 $imageInfoNode->setAttribute( $infoItemName, $infoItem );
1349 }
1350 }
1351 $imageNode->appendChild( $imageInfoNode );
1352 }
1353 }
1354
1358 function addImageAliases( $imageAliasList )
1359 {
1360 $domTree = $this->domTree();
1361 foreach ( $imageAliasList as $imageAliasName => $imageAlias )
1362 {
1363 if ( $imageAlias['is_new'] )
1364 {
1365 $this->addImageAliasToXML( $domTree, $imageAlias );
1366 $this->setAliasAttribute( $imageAliasName, 'is_new', false );
1367 }
1368 }
1369 $attr = false;
1370 $this->storeDOMTree( $domTree, true, $attr );
1371 }
1372
1376 function addImageAlias( $imageAlias )
1377 {
1378 $domTree = $this->domTree();
1379 $this->addImageAliasToXML( $domTree, $imageAlias );
1380 $attr = false;
1381 $this->storeDOMTree( $domTree, true, $attr );
1382
1383 }
1384
1388 function addImageAliasToXML( $domTree, $imageAlias )
1389 {
1390 $imageVariationNodeArray = $domTree->getElementsByTagName( 'alias' );
1391 $imageNode = false;
1392 foreach ( $imageVariationNodeArray as $imageVariation )
1393 {
1394 $aliasEntryName = $imageVariation->getAttribute( 'name' );
1395 if ( $aliasEntryName == $imageAlias['name'] )
1396 {
1397 $imageNode = $imageVariation;
1398 break;
1399 }
1400 }
1401 if ( !$imageNode )
1402 {
1403 $rootNode = $domTree->documentElement;
1404
1405 $imageNode = $domTree->createElement( "alias" );
1406 $rootNode->appendChild( $imageNode );
1407 }
1408 else
1409 {
1410 $imageNode->removeAttribute( 'name' );
1411 $imageNode->removeAttribute( 'filename' );
1412 $imageNode->removeAttribute( 'suffix' );
1413 $imageNode->removeAttribute( 'dirpath' );
1414 $imageNode->removeAttribute( 'url' );
1415 $imageNode->removeAttribute( 'mime_type' );
1416 $imageNode->removeAttribute( 'width' );
1417 $imageNode->removeAttribute( 'height' );
1418 $imageNode->removeAttribute( 'alias_key' );
1419 $imageNode->removeAttribute( 'timestamp' );
1420 $imageNode->removeAttribute( 'is_valid' );
1421 }
1422 $imageNode->setAttribute( 'name', $imageAlias['name'] );
1423 $imageNode->setAttribute( 'filename', $imageAlias['filename'] );
1424 $imageNode->setAttribute( 'suffix', $imageAlias['suffix'] );
1425 $imageNode->setAttribute( 'dirpath', $imageAlias['dirpath'] );
1426 $imageNode->setAttribute( 'url', $imageAlias['url'] );
1427 $imageNode->setAttribute( 'mime_type', $imageAlias['mime_type'] );
1428 $imageNode->setAttribute( 'width', $imageAlias['width'] );
1429 $imageNode->setAttribute( 'height', $imageAlias['height'] );
1430 $imageNode->setAttribute( 'alias_key', $imageAlias['alias_key'] );
1431 $imageNode->setAttribute( 'timestamp', $imageAlias['timestamp'] );
1432 $imageNode->setAttribute( 'is_valid', $imageAlias['is_valid'] );
1433 }
1434
1438 function setDOMTree( $domTree )
1439 {
1440 $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'] = $domTree;
1441 $this->ContentObjectAttributeData['DataTypeCustom']['is_storage_required'] = true;
1442 }
1443
1447 function storeDOMTree( $domTree, $storeAttribute, $contentObjectAttributeRef )
1448 {
1449 if ( !$domTree )
1450 return false;
1451 $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'] = $domTree;
1452 $this->ContentObjectAttributeData['DataTypeCustom']['is_storage_required'] = false;
1453 $xmlString = $domTree->saveXML();
1454 $this->ContentObjectAttributeData['data_text'] = $xmlString;
1455
1456 if ( $storeAttribute )
1457 {
1458 if ( is_object( $contentObjectAttributeRef ) )
1459 {
1460 $contentObjectAttribute = $contentObjectAttributeRef;
1461 }
1462 else
1463 {
1464 $contentObjectAttribute = eZContentObjectAttribute::fetch( $this->ContentObjectAttributeData['id'],
1465 $this->ContentObjectAttributeData['version'] );
1466 }
1467
1468 if ( is_object( $contentObjectAttribute ) )
1469 {
1470 $contentObjectAttribute->setAttribute( 'data_text', $xmlString );
1471 $contentObjectAttribute->storeData();
1472 }
1473 else
1474 {
1475 eZDebug::writeError( "Invalid objectAttribute: id = " . $this->ContentObjectAttributeData['id'] .
1476 " version = " . $this->ContentObjectAttributeData['version'] ,
1477 __METHOD__ );
1478 }
1479 }
1480
1481 return true;
1482 }
1483
1488 function store( $contentObjectAttribute )
1489 {
1490 $domTree = $this->domTree();
1491 if ( $domTree )
1492 {
1493 if ( is_object( $contentObjectAttribute ) )
1494 {
1495 $this->storeDOMTree( $domTree, false, $contentObjectAttribute );
1496
1497 $contentObjectAttribute->setAttribute( 'data_text', $this->ContentObjectAttributeData['data_text'] );
1498 $contentObjectAttribute->storeData();
1499 }
1500 else
1501 {
1502 $this->storeDOMTree( $domTree, true, $contentObjectAttribute );
1503
1504 }
1505 }
1506
1507 $this->setStorageRequired( false );
1508 }
1509
1514 function isStorageRequired()
1515 {
1516 return isset( $this->ContentObjectAttributeData['DataTypeCustom']['is_storage_required'] ) ?
1517 $this->ContentObjectAttributeData['DataTypeCustom']['is_storage_required'] :
1518 false;
1519 }
1520
1525 function setStorageRequired( $require = true )
1526 {
1527 $this->ContentObjectAttributeData['DataTypeCustom']['is_storage_required'] = $require;
1528 }
1529
1537 function originalAttributeData()
1538 {
1539 $contentObjectAttributeData = $this->ContentObjectAttributeData;
1540 if ( isset( $contentObjectAttributeData['DataTypeCustom']['original_data'] ) )
1541 return $contentObjectAttributeData['DataTypeCustom']['original_data'];
1542
1543 $originalData = array( 'attribute_id' => $contentObjectAttributeData['id'],
1544 'attribute_version' => $contentObjectAttributeData['version'],
1545 'attribute_language' => $contentObjectAttributeData['language_code'] );
1546 $this->setOriginalAttributeData( $originalData );
1547 return $originalData;
1548 }
1549
1554 function setOriginalAttributeData( $originalData )
1555 {
1556 $this->ContentObjectAttributeData['DataTypeCustom']['original_data'] = $originalData;
1557
1558 $domTree = $this->domTree();
1559 $imageOriginalArray = $domTree->getElementsByTagName( "original" );
1560 if ( $imageOriginalArray->length > 0 )
1561 {
1562 $imageOriginalNode = $imageOriginalArray->item( 0 );
1563 $this->createOriginalAttributeXMLData( $imageOriginalNode, $originalData );
1564 }
1565 }
1566
1573 function setOriginalAttributeDataFromAttribute( $contentObjectAttribute )
1574 {
1575 $originalImageHandler = $contentObjectAttribute->attribute( 'content' );
1576 $originalAttributeData = $originalImageHandler->originalAttributeData();
1577 $domTree = $originalImageHandler->domTree();
1578 $this->setDOMTree( $domTree );
1579 if ( $originalAttributeData['attribute_id'] )
1580 {
1581 $this->setOriginalAttributeData( $originalAttributeData );
1582 }
1583 else
1584 {
1585 $this->setOriginalAttributeDataValues( $contentObjectAttribute->attribute( 'id' ),
1586 $contentObjectAttribute->attribute( 'version' ),
1587 $contentObjectAttribute->attribute( 'language_code' ) );
1588 }
1589 }
1590
1596 function setOriginalAttributeDataValues( $attributeID, $attributeVersion, $attributeLanguage )
1597 {
1598 $this->setOriginalAttributeData( array( 'attribute_id' => $attributeID,
1599 'attribute_version' => $attributeVersion,
1600 'attribute_language' => $attributeLanguage ) );
1601 }
1602
1608 function setImageSerialNumber( $val )
1609 {
1610 $this->ContentObjectAttributeData['DataTypeCustom']['serial_number'] = $val;
1611 }
1612
1619 private function imageSerialNumberRaw()
1620 {
1621 return isset( $this->ContentObjectAttributeData['DataTypeCustom']['serial_number'] ) ?
1622 $this->ContentObjectAttributeData['DataTypeCustom']['serial_number'] :
1623 0;
1624 }
1625
1629 function generateXMLData()
1630 {
1631 $doc = new DOMDocument( '1.0', 'utf-8' );
1632 $imageNode = $doc->createElement( "ezimage" );
1633 $doc->appendChild( $imageNode );
1634
1635 $fileName = false;
1636
1637 $imageManager = eZImageManager::factory();
1638
1639 $mimeData = eZMimeType::findByFileContents( $fileName );
1640 $imageManager->analyzeImage( $mimeData );
1641
1642 $imageNode->setAttribute( 'serial_number', false );
1643 $imageNode->setAttribute( 'is_valid', false );
1644 $imageNode->setAttribute( 'filename', $fileName );
1645 $imageNode->setAttribute( 'suffix', false );
1646 $imageNode->setAttribute( 'basename', false );
1647 $imageNode->setAttribute( 'dirpath', false );
1648 $imageNode->setAttribute( 'url', false );
1649 $imageNode->setAttribute( 'original_filename', false );
1650 $imageNode->setAttribute( 'mime_type', false );
1651 $imageNode->setAttribute( 'width', false );
1652 $imageNode->setAttribute( 'height', false );
1653 $imageNode->setAttribute( 'alternative_text', false );
1654 $imageNode->setAttribute( 'alias_key', $imageManager->createImageAliasKey( $imageManager->alias( 'original' ) ) );
1655 $imageNode->setAttribute( 'timestamp', time() );
1656
1657 $this->createImageInformationNode( $imageNode, $mimeData );
1658
1659 $this->storeDOMTree( $doc, true, false );
1660 }
1661
1664 public $ContentObjectAttributeData;
1666 public $ContentObjectAttribute;
1667
1668 }
1669 ?>
eZCharTransform\instance
static instance()
Definition: ezchartransform.php:434
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZContentObjectAttribute
Encapsulates the data for an object attribute.
Definition: ezcontentobjectattribute.php:20
eZContentObjectAttribute\fetch
static fetch( $id, $version, $asObject=true, $field_filters=null)
Definition: ezcontentobjectattribute.php:136
eZContentObjectVersion\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: ezcontentobjectversion.php:30
eZContentObjectVersion\fetchVersion
static fetchVersion( $version, $contentObjectID, $asObject=true)
Definition: ezcontentobjectversion.php:166
eZContentObject
Definition: ezcontentobject.php:17
eZContentObject\fetch
static fetch( $id, $asObject=true)
Definition: ezcontentobject.php:885
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:588
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZDebug\accumulatorStart
static accumulatorStart( $key, $inGroup=false, $name=false, $recursive=false)
Definition: ezdebug.php:1361
eZDebug\accumulatorStop
static accumulatorStop( $key, $recursive=false)
Definition: ezdebug.php:1389
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZDir\dirpath
static dirpath( $filepath)
Definition: ezdir.php:129
eZDir\cleanupEmptyDirectories
static cleanupEmptyDirectories( $dir)
Definition: ezdir.php:95
eZFileHandler\copy
static copy( $sourceFilename, $destinationFilename)
Definition: ezfilehandler.php:356
eZImageAliasHandler
Internal manager for the eZImage datatype.
Definition: ezimagealiashandler.php:28
eZImageAliasHandler\parseInformationNode
parseInformationNode( $imageInfoNode)
Definition: ezimagealiashandler.php:984
eZImageAliasHandler\setDOMTree
setDOMTree( $domTree)
Definition: ezimagealiashandler.php:1438
eZImageAliasHandler\setOriginalAttributeDataFromAttribute
setOriginalAttributeDataFromAttribute( $contentObjectAttribute)
Definition: ezimagealiashandler.php:1573
eZImageAliasHandler\recreateDOMTree
recreateDOMTree()
Definition: ezimagealiashandler.php:883
eZImageAliasHandler\hasAttribute
hasAttribute( $attributeName)
Definition: ezimagealiashandler.php:77
eZImageAliasHandler\imagePathByNode
imagePathByNode( $contentObjectAttribute, $mainNode)
Definition: ezimagealiashandler.php:369
eZImageAliasHandler\trimToFileSystemFileName
trimToFileSystemFileName( $longName, $limit=200)
Definition: ezimagealiashandler.php:403
eZImageAliasHandler\generateXMLData
generateXMLData()
Definition: ezimagealiashandler.php:1629
eZImageAliasHandler\purgeAllAliases
purgeAllAliases()
Definition: ezimagealiashandler.php:708
eZImageAliasHandler\imageSerialNumber
imageSerialNumber()
Definition: ezimagealiashandler.php:182
eZImageAliasHandler\originalAttributeData
originalAttributeData()
Definition: ezimagealiashandler.php:1537
eZImageAliasHandler\$ContentObjectAttributeData
$ContentObjectAttributeData
Definition: ezimagealiashandler.php:1664
eZImageAliasHandler\imageAlias
imageAlias( $aliasName)
Definition: ezimagealiashandler.php:419
eZImageAliasHandler\imagePath
imagePath( $contentObjectAttribute, $contentVersion, $isImageOwner=null)
Definition: ezimagealiashandler.php:319
eZImageAliasHandler\removeAliases
removeAliases()
Definition: ezimagealiashandler.php:738
eZImageAliasHandler\addImageAlias
addImageAlias( $imageAlias)
Definition: ezimagealiashandler.php:1376
eZImageAliasHandler\increaseImageSerialNumber
increaseImageSerialNumber()
Definition: ezimagealiashandler.php:195
eZImageAliasHandler\attributes
attributes()
Definition: ezimagealiashandler.php:63
eZImageAliasHandler\setHTTPFile
setHTTPFile( $httpFile)
Definition: ezimagealiashandler.php:1064
eZImageAliasHandler\createImageInformationNode
createImageInformationNode( $imageNode, $mimeData)
Definition: ezimagealiashandler.php:1277
eZImageAliasHandler\imageName
imageName( $contentObjectAttribute, $contentVersion, $language=false)
Definition: ezimagealiashandler.php:247
eZImageAliasHandler\setAttribute
setAttribute( $attributeName, $attributeValue)
Definition: ezimagealiashandler.php:129
eZImageAliasHandler\initializeFromHTTPFile
initializeFromHTTPFile( $httpFile, $imageAltText=false)
Definition: ezimagealiashandler.php:1099
eZImageAliasHandler\$ContentObjectAttribute
$ContentObjectAttribute
Deprecated. Contains a reference to the object attribute.
Definition: ezimagealiashandler.php:1666
eZImageAliasHandler\setOriginalAttributeDataValues
setOriginalAttributeDataValues( $attributeID, $attributeVersion, $attributeLanguage)
Definition: ezimagealiashandler.php:1596
eZImageAliasHandler\initialize
initialize( $mimeData, $originalFilename, $imageAltText=false)
Definition: ezimagealiashandler.php:1196
eZImageAliasHandler\normalizeImageName
normalizeImageName( $imageName)
Definition: ezimagealiashandler.php:1045
eZImageAliasHandler\storeDOMTree
storeDOMTree( $domTree, $storeAttribute, $contentObjectAttributeRef)
Definition: ezimagealiashandler.php:1447
eZImageAliasHandler\__construct
__construct( $contentObjectAttribute)
Definition: ezimagealiashandler.php:34
eZImageAliasHandler\httpFile
httpFile( $release=false)
Definition: ezimagealiashandler.php:1076
eZImageAliasHandler\imageNameByNode
imageNameByNode( $contentObjectAttribute, $mainNode, $language=false)
Definition: ezimagealiashandler.php:286
eZImageAliasHandler\createOriginalAttributeXMLData
createOriginalAttributeXMLData( $originalNode, $originalData)
Definition: ezimagealiashandler.php:871
eZImageAliasHandler\setAliasVariation
setAliasVariation( $aliasName, $variation)
Definition: ezimagealiashandler.php:483
eZImageAliasHandler\attributeFromOriginal
& attributeFromOriginal( $attributeName)
Definition: ezimagealiashandler.php:113
eZImageAliasHandler\setStorageRequired
setStorageRequired( $require=true)
Definition: ezimagealiashandler.php:1525
eZImageAliasHandler\addImageAliasToXML
addImageAliasToXML( $domTree, $imageAlias)
Definition: ezimagealiashandler.php:1388
eZImageAliasHandler\imageSerialNumberRaw
imageSerialNumberRaw()
Definition: ezimagealiashandler.php:1619
eZImageAliasHandler\initializeFromFile
initializeFromFile( $filename, $imageAltText=false, $originalFilename=false)
Definition: ezimagealiashandler.php:1135
eZImageAliasHandler\isImageOwner
isImageOwner()
Definition: ezimagealiashandler.php:162
eZImageAliasHandler\setAliasList
setAliasList( $aliasList)
Definition: ezimagealiashandler.php:472
eZImageAliasHandler\displayText
displayText( $alternativeText=null)
Definition: ezimagealiashandler.php:214
eZImageAliasHandler\setImageSerialNumber
setImageSerialNumber( $val)
Definition: ezimagealiashandler.php:1608
eZImageAliasHandler\setAliasAttribute
setAliasAttribute( $aliasName, $attributeName, $value)
Definition: ezimagealiashandler.php:495
eZImageAliasHandler\attribute
attribute( $attributeName)
Definition: ezimagealiashandler.php:95
eZImageAliasHandler\aliasList
aliasList( $checkValidity=true)
Definition: ezimagealiashandler.php:507
eZImageAliasHandler\updateAliasPath
updateAliasPath( $dirpath, $name)
Definition: ezimagealiashandler.php:809
eZImageAliasHandler\directoryPath
directoryPath()
Definition: ezimagealiashandler.php:227
eZImageAliasHandler\store
store( $contentObjectAttribute)
Definition: ezimagealiashandler.php:1488
eZImageAliasHandler\resetImageSerialNumber
resetImageSerialNumber()
Definition: ezimagealiashandler.php:203
eZImageAliasHandler\addImageAliases
addImageAliases( $imageAliasList)
Definition: ezimagealiashandler.php:1358
eZImageAliasHandler\domTree
domTree()
Definition: ezimagealiashandler.php:950
eZImageAliasHandler\isStorageRequired
isStorageRequired()
Definition: ezimagealiashandler.php:1514
eZImageAliasHandler\setOriginalAttributeData
setOriginalAttributeData( $originalData)
Definition: ezimagealiashandler.php:1554
eZImageAliasHandler\removeAliasFile
removeAliasFile( $aliasFile)
Definition: ezimagealiashandler.php:764
eZImageFile\isReferencedByOtherImageFiles
static isReferencedByOtherImageFiles( $filepath, $attributeId)
Definition: ezimagefile.php:263
eZImageFile\appendFilepath
static appendFilepath( $contentObjectAttributeID, $filepath, $ignoreUnique=false)
Definition: ezimagefile.php:184
eZImageFile\removeForContentObjectAttribute
static removeForContentObjectAttribute( $contentObjectAttributeID)
Definition: ezimagefile.php:216
eZImageFile\fetchForContentObjectAttribute
static fetchForContentObjectAttribute( $contentObjectAttributeID, $asObject=false)
Definition: ezimagefile.php:50
eZImageFile\moveFilepath
static moveFilepath( $contentObjectAttributeID, $oldFilepath, $newFilepath)
Definition: ezimagefile.php:172
eZImageFile\isReferencedByOtherAttributes
static isReferencedByOtherAttributes( $filepath, $attributeId, $attributeVersion, $languageCode)
Definition: ezimagefile.php:230
eZImageFile\fetchImageAttributesByFilepath
static fetchImageAttributesByFilepath( $filepath, $contentObjectAttributeID)
Definition: ezimagefile.php:80
eZImageFile\definition
static definition()
Definition: ezimagefile.php:20
eZImageManager\factory
static factory()
Definition: ezimagemanager.php:1399
eZMimeType\findByName
static findByName( $mimeName, $returnDefault=true)
Definition: ezmimetype.php:197
eZMimeType\changeDirectoryPath
static changeDirectoryPath(&$mimeInfo, $dirpath)
Definition: ezmimetype.php:155
eZMimeType\changeFileData
static changeFileData(&$mimeInfo, $dirpath=false, $basename=false, $suffix=false, $filename=false)
Definition: ezmimetype.php:168
eZMimeType\findByFileContents
static findByFileContents( $url, $returnDefault=true)
Definition: ezmimetype.php:308
eZMimeType\findByURL
static findByURL( $url, $returnDefault=true)
Definition: ezmimetype.php:227
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZSys\storageDirectory
static storageDirectory()
Definition: ezsys.php:514
eZURLAliasML\convertToAlias
static convertToAlias( $urlElement, $defaultValue=false)
Definition: ezurlaliasml.php:2292
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+.