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/old/app/code/Soon/CsBlock/Block/Preference/CsBlock/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Soon/CsBlock/Block/Preference/CsBlock/CsBlock.php
<?php
/**
 * @license http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @author Hervé Guétin <[email protected]> <@herveguetin>
 * @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr)
 */

namespace Soon\CsBlock\Block\Preference\CsBlock;


use Aheadworks\Csblock\Block\Csblock as AwCsblock;
use Aheadworks\Csblock\Model\ResourceModel\Content\Collection;
use Aheadworks\Csblock\Model\Source\PageType;
use Aheadworks\Csblock\Model\Source\Position;

class CsBlock extends AwCsblock implements \Magento\Widget\Block\BlockInterface
{
    /**
     * @var AwCsblock
     */
    private $csBlock;
    /**
     * @var string
     */
    private $nameInLayout;

    /**
     * Path to template file in theme.
     * @var string
     */
    protected $_template = 'Soon_CsBlock::block.phtml';

    /**
     * @param AwCsblock $csblock
     * @return string
     */
    public function getUpdatedBlockContentHtml(AwCsblock $csblock)
    {
        $html = '';
        $this->csBlock = $csblock;
        $this->nameInLayout = $this->csBlock->getNameInLayout();
        $gmtTimestamp = strtotime($this->_dateTime->gmtDate()) + $this->_dateTime->getGmtOffset();
        $currentDate = date('Y-m-d', $gmtTimestamp);
        $currentTime = date('H,i,s', $gmtTimestamp);
        $csblockId = $csblock->getData('csblock_id');

        if (!$csblockId) {
            $csblockCollection = $this->_csblockCollectionFactory->create();
            $csblockCollection
                ->addCustomerGroupFilter($this->_customerSession->getCustomerGroupId())
                ->addPositionFilter($this->__getBlockPosition())
                ->addPageTypeFilter($this->__getBlockType())
                ->addDateFilter($currentDate)
                ->addTimeFilter($currentTime)
                ->addPatternFilter($gmtTimestamp)
                ->addStatusEnabledFilter();
            foreach ($csblockCollection->getItems() as $csblock) {
                if ($this->__canShow($csblock)) {
                    $html .= $this->getStaticBlockHtml($csblock->getId());
                }
            }
        } else {
            $this->csBlock = $csblock;

            $csblockCollection = $this->_csblockCollectionFactory->create();
            $csblockCollection
                ->addCustomerGroupFilter($this->_customerSession->getCustomerGroupId())
                ->addFieldToFilter('id', ['in' => [$csblockId]])
                ->addDateFilter($currentDate)
                ->addTimeFilter($currentTime)
                ->addPatternFilter($gmtTimestamp)
                ->addStatusEnabledFilter();

            foreach ($csblockCollection->getItems() as $csblock) {
                if ($this->__canShow($csblock)) {
                    $html .= $this->getStaticBlockHtml($csblock->getId());
                }
            }
        }

        return $html;
    }

    /**
     * @override required because of private access. Added some refactoring.
     * @return int|null
     */
    private function __getBlockPosition()
    {
        if ($this->_blockPosition === null) {
            if (false !== strpos($this->nameInLayout, 'menu_top')) {
                $this->_blockPosition = Position::MENU_TOP;
            }
            if (false !== strpos($this->nameInLayout, 'menu_bottom')) {
                $this->_blockPosition = Position::MENU_BOTTOM;
            }
            if (false !== strpos($this->nameInLayout, 'content_top')) {
                $this->_blockPosition = Position::CONTENT_TOP;
            }
            if (false !== strpos($this->nameInLayout, 'sidebar_top')) {
                $this->_blockPosition = Position::SIDEBAR_TOP;
            }
            if (false !== strpos($this->nameInLayout, 'sidebar_bottom')) {
                $this->_blockPosition = Position::SIDEBAR_BOTTOM;
            }
            if (false !== strpos($this->nameInLayout, 'page_bottom')) {
                $this->_blockPosition = Position::PAGE_BOTTOM;
            }
        }

        return $this->_blockPosition;
    }

    /**
     * @override required because of private access. Added some refactoring.
     * @return int|null
     */
    private function __getBlockType()
    {
        if ($this->_blockType === null) {
            if (false !== strpos($this->nameInLayout, 'csblock_product')) {
                $this->_blockType = PageType::PRODUCT_PAGE;
            }
            if (false !== strpos($this->nameInLayout, 'csblock_category')) {
                $this->_blockType = PageType::CATEGORY_PAGE;
            }
            if (false !== strpos($this->nameInLayout, 'csblock_category')) {
                $this->_blockType = PageType::CATEGORY_PAGE;
            }
            if (false !== strpos($this->nameInLayout, 'csblock_cart')) {
                $this->_blockType = PageType::SHOPPINGCART_PAGE;
            }
            if (false !== strpos($this->nameInLayout, 'csblock_home')) {
                $this->_blockType = PageType::HOME_PAGE;
            }
            if (false !== strpos($this->nameInLayout, 'csblock_checkout')) {
                $this->_blockType = PageType::CHECKOUT_PAGE;
            }
        }

        return $this->_blockType;
    }

    /**
     * @override required because of private access.
     * @param $csblock
     * @return bool|null
     */
    private function __canShow($csblock)
    {
        $result = true;
        switch ($csblock->getPageType()) {
            case PageType::PRODUCT_PAGE:
                $result = false;
                $currentProductId = $this->getProductId();
                if (null === $currentProductId) {
                    return $result;
                }
                $csblockModel = $this->_csblockFactory->create();
                $csblockModel->load($csblock->getId());
                $conditions = $csblockModel->getRuleModel()->getConditions();
                if (isset($conditions)) {
                    $match = $csblockModel->getRuleModel()->getMatchingProductIds();
                    if (in_array($currentProductId, $match)) {
                        $result = true;
                    }
                }
                break;
            case PageType::CATEGORY_PAGE:
                $result = false;
                $currentCategoryId = $this->__getCurrentCategoryId();
                if ($currentCategoryId && in_array($currentCategoryId, explode(',', $csblock->getCategoryIds()))) {
                    $result = true;
                }
                break;
        }

        return $result;
    }

    /**
     * @override required because of private access.
     * @return mixed
     */
    private function __getCurrentCategoryId()
    {
        return $this->_request->getParam('id', null);
    }

    /**
     * @override required because of private access.
     * Our custom logic to generate actual content
     *
     * @param int $getId
     * @return string
     */
    private function getStaticBlockHtml($getId)
    {
        /** @var Collection $contentCollection */
        $contentCollection = $this->_contentCollectionFactory->create();
        $contentCollection
            ->addBlockIdFilter($getId)
            ->addStoreFilter($this->_storeManager->getStore()->getId());;
        $html = '';
        foreach ($contentCollection->getItems() as $content) {
            $html .= $this->getLayout()
                ->createBlock('Soon\CsBlock\Block\ContentBlock', '', ['blockId' => $content->getData('static_block_id')])
                ->toHtml();
        }

        return $html;
    }

    /**
     * @return mixed
     */
    private function getProductId()
    {
        return $this->_request->getParam('id', null);
    }
}

Spamworldpro Mini