![]() 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/Social/Block/Widget/ |
<?php /** * Copyright (c) 2019 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved. * https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * soon_social_m2 * cframery <[email protected]> <[email protected]> */ namespace Soon\Social\Block\Widget; use Magento\Framework\View\Element\Template; use Magento\Widget\Block\BlockInterface; use Soon\Social\Helper\Data as SocialHelper; /** * Class Share * @package Soon\Social\Block\Widget */ class Share extends Template implements BlockInterface { /** * @var \Soon\Social\Helper\Data */ protected $_socialHelper; /** * @var \Magento\Framework\UrlInterface */ protected $_urlInterface; /** * @var string */ protected $_template = "widget/share.phtml"; /** * Share constructor. * @param Context $context * @param SocialHelper $socialHelper * @param \Magento\Framework\UrlInterface $urlInterface * @param array $data */ public function __construct( Template\Context $context, SocialHelper $socialHelper, \Magento\Framework\UrlInterface $urlInterface, array $data = [] ) { parent::__construct($context, $data); $this->_socialHelper = $socialHelper; $this->_urlInterface = $urlInterface; } /** * @return string */ public function getCurrentUrl() { return rawurlencode($this->_urlInterface->getCurrentUrl()); } /** * Get Facebook share Url * * @return null|string */ public function getFacebookShareUrl() { if (!$this->getData('enable_facebook')) { return null; } return $this->escapeUrl("https://www.facebook.com/sharer/sharer.php?u={$this->getCurrentUrl()}"); } /** * Get Twitter share Url * * @return null|string */ public function getTwitterShareUrl() { if (!$this->getData('enable_twitter')) { return null; } $url = "http://twitter.com/intent/tweet" . "?text={$this->_getTitle()}" . "&url={$this->getCurrentUrl()}"; if ($twitterUsername = urlencode($this->_socialHelper->getStoreConfig('twitter/username'))) { $url .= "&via={$twitterUsername}"; } return $this->escapeUrl($url); } /** * Get Pinterest Url * * @return string */ public function getPinterestUrl() { if (!$this->getData('enable_pinterest')) { return null; } $url = "https://www.pinterest.com/pin/create/button/" . "?url={$this->getCurrentUrl()}"; return $this->escapeUrl($url); } /** * Get LinkedIn share Url * * @return string */ public function getLinkedInShareUrl() { if (!$this->getData('enable_linkedin')) { return null; } $url = "https://www.linkedin.com/shareArticle" . "?mini=true" . "&url={$this->getCurrentUrl()}"; if ($title = $this->_getTitle()) { $url .= "&title={$title}"; } return $this->escapeUrl($url); } /** * Get current title * * @return null|string */ protected function _getTitle() { if ($head = $this->getLayout()->getBlock('head')) { return rawurlencode($this->escapeQuote($head->getTitle())); } return null; } }