CoreFiles by mySites.guru
SchemaorgPrepareImageTrait.php55 lines, 1,187 bytes, from Joomla_5.2.4-Stable-Full_Package.zip
Raw History Compare with 5.2.3
md5
b079316dfd5e481a2163e23bb096aae9
sha1
3e780ed6d1f3e3a3bc1a1776774c7ab2d76863a8
sha256
13bd5bebe2fc862f72f5a112b30c71c60e1877a0d375dc4fd34d20f5cd13c692
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Schemaorg;

use Joomla\CMS\HTML\HTMLHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Prepare images to be valid for JSON-LD output
 *
 * @since  5.0.0
 */
trait SchemaorgPrepareImageTrait
{
    /**
     * Prepare media image files
     *
     * @param   string|array $image
     *
     * @return  string|array
     *
     * @since   5.0.0
     */
    protected function prepareImage($image)
    {
        if (\is_array($image)) {
            // We don't handle references, they should be ok
            if (\count($image) === 1 && isset($image['@id'])) {
                return $image;
            }

            $newImages = [];

            foreach ($image as $img) {
                $newImages[] = $this->prepareImage($img);
            }

            return $newImages;
        }

        $img = HTMLHelper::_('cleanImageUrl', $image);

        return $img->url ?? null;
    }
}

The same content is in 148 releases, Joomla 5.0.0-rc to 6.2.1-rc1. See them all, or every version of this file.