Spamworldpro Mini Shell
Spamworldpro


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/cartforge.co/app/code/Mageplaza/Search/Helper/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/app/code/Mageplaza/Search/Helper/Media.php
<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_Search
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */

namespace Mageplaza\Search\Helper;

use Exception;
use Magento\Catalog\Helper\ImageFactory;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem;
use Magento\Framework\Image\AdapterFactory;
use Magento\Framework\ObjectManagerInterface;
use Magento\MediaStorage\Model\File\UploaderFactory;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\Core\Helper\Media as CoreMedia;

/**
 * Class Media
 * @package Mageplaza\Search\Helper
 */
class Media extends CoreMedia
{
    const TEMPLATE_MEDIA_PATH = 'mageplaza/search';

    /**
     * @var ImageFactory
     */
    protected $imageFactory;

    /**
     * @var $helperData
     */
    protected $helperData;

    /**
     * Media constructor.
     *
     * @param Context $context
     * @param ObjectManagerInterface $objectManager
     * @param StoreManagerInterface $storeManager
     * @param Filesystem $filesystem
     * @param UploaderFactory $uploaderFactory
     * @param AdapterFactory $adapterFactory
     * @param ImageFactory $imageFactory
     * @param Data $helperData
     *
     * @throws FileSystemException
     */
    public function __construct(
        Context $context,
        ObjectManagerInterface $objectManager,
        StoreManagerInterface $storeManager,
        Filesystem $filesystem,
        UploaderFactory $uploaderFactory,
        AdapterFactory $adapterFactory,
        ImageFactory $imageFactory,
        Data $helperData,
    ) {
        parent::__construct($context, $objectManager, $storeManager, $filesystem, $uploaderFactory, $adapterFactory);

        $this->imageFactory = $imageFactory;
        $this->helperData   = $helperData;
    }

    /**
     * Retrieve product image
     *
     * @param Product $product
     * @param string $imageId
     *
     * @return string
     */
    public function getProductImage($product, $imageId = 'mpsearch_image')
    {
        $imageUrl = $this->imageFactory->create()
            ->init($product, $imageId)
            ->getUrl();

        $baseMediaUrl = $this->getSearchMediaUrl();
        if (strpos($imageUrl, $baseMediaUrl) === 0) {
            $imageUrl = substr($imageUrl, strlen($baseMediaUrl));
        }

        return $imageUrl;
    }

    /**
     * @return string
     */
    public function getSearchMediaUrl()
    {
        return $this->getBaseMediaUrl() . '/catalog/product/';
    }

    /**
     * @param $fileName
     * @param $content
     */
    public function createJsFile($fileName, $content)
    {
        try {
            $this->mediaDirectory->writeFile($fileName, $content);
            $this->helperData->setVersionFile();
        } catch (Exception $e) {
            $this->_logger->critical($e->getMessage());
        }
    }

    /**
     * @return $this
     * @throws FileSystemException
     */
    public function removeJsPath()
    {
        $this->removePath(self::TEMPLATE_MEDIA_PATH);

        return $this;
    }
}

Spamworldpro Mini