![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-media-gallery-metadata/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\MediaGalleryMetadata\Model; use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterface; use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterfaceFactory; /** * Get metadata from IPTC block */ class GetIptcMetadata { private const IPTC_TITLE = '2#005'; private const IPTC_DESCRIPTION = '2#120'; private const IPTC_KEYWORDS = '2#025'; /** * @var MetadataInterfaceFactory */ private $metadataFactory; /** * @param MetadataInterfaceFactory $metadataFactory */ public function __construct( MetadataInterfaceFactory $metadataFactory ) { $this->metadataFactory = $metadataFactory; } /** * Parse metadata * * @param string $data * @return MetadataInterface */ public function execute(string $data): MetadataInterface { $title = null; $description = null; $keywords = []; if (is_callable('iptcparse')) { $iptcData = iptcparse($data); if (!empty($iptcData[self::IPTC_TITLE][0])) { $title = trim($iptcData[self::IPTC_TITLE][0]); } if (!empty($iptcData[self::IPTC_DESCRIPTION][0])) { $description = trim($iptcData[self::IPTC_DESCRIPTION][0]); } if (!empty($iptcData[self::IPTC_KEYWORDS][0])) { $keywords = array_values($iptcData[self::IPTC_KEYWORDS]); } } return $this->metadataFactory->create([ 'title' => $title, 'description' => $description, 'keywords' => !empty($keywords) ? $keywords : null ]); } }