![]() 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/fooman/pdfdesign-m2/src/Block/DesignOne/ |
<?php /** * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Fooman\PdfDesign\Block\DesignOne; use Fooman\PdfCore\Helper\ParamKey; use Magento\Framework\View\Element\Template\Context; use Magento\Store\Model\ScopeInterface; use Magento\Framework\Module\Dir; /** * Block class for adaptive icons */ class Icons extends \Fooman\PdfCore\Block\Pdf\Block { const PRIMARY_COLOUR_PLACEHOLDER = '***FOOMAN_PRIMARY_COLOUR***'; const SECONDARY_COLOUR_PLACEHOLDER = '***FOOMAN_SECONDARY_COLOUR***'; /** * @var ParamKey */ private $paramKeyHelper; /** * @var \Magento\Framework\Module\Dir\Reader */ private $moduleReader; /** * @var \Magento\Framework\Filesystem\Io\File */ private $file; /** * @var \Magento\Directory\Model\RegionFactory */ private $regionFactory; /** * @var \Magento\Directory\Model\CountryFactory */ private $countryFactory; private $storeAddresses = []; /** * @param Context $context * @param ParamKey $paramKeyHelper * @param Dir\Reader $moduleReader * @param \Magento\Framework\Filesystem\Io\File $file * @param \Magento\Directory\Model\RegionFactory $regionFactory * @param \Magento\Directory\Model\CountryFactory $countryFactory * @param array $data */ public function __construct( Context $context, ParamKey $paramKeyHelper, \Magento\Framework\Module\Dir\Reader $moduleReader, \Magento\Framework\Filesystem\Io\File $file, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, array $data = [] ) { $this->paramKeyHelper = $paramKeyHelper; $this->moduleReader = $moduleReader; $this->file = $file; $this->regionFactory = $regionFactory; $this->countryFactory = $countryFactory; parent::__construct($context, $data); } /** * @param array $params * * @return mixed */ public function getEncodedParams(array $params) { return $this->paramKeyHelper->getEncodedParams($params); } public function getStoreAddressElements() { $storeId = $this->getStoreId(); if (!isset($this->storeAddresses[$storeId])) { $addressElements = []; $street = $this->_scopeConfig->getValue( 'general/store_information/street_line1', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); if ($street) { $addressElements['street1'] = $street; } $street2 = $this->_scopeConfig->getValue( 'general/store_information/street_line2', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); if ($street2) { $addressElements['street2'] = $street2; } if ($this->getCity()) { $addressElements['city'] = $this->getCity(); } $postCode = $this->_scopeConfig->getValue( 'general/store_information/postcode', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); if ($postCode) { $addressElements['postcode'] = $postCode; } $region = $this->getRegion(); if ($region) { $addressElements['region']= $region; } $country = $this->getCountry(); if ($country) { $addressElements['country'] = $country; } $this->storeAddresses[$storeId] = $addressElements; } return $this->storeAddresses[$storeId]; } public function getCity() { return $this->_scopeConfig->getValue( 'general/store_information/city', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); } public function getStreetAddress() { $streets = []; $streetOne = $this->_scopeConfig->getValue( 'general/store_information/street_line1', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); $streetTwo = $this->_scopeConfig->getValue( 'general/store_information/street_line2', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); if ($streetOne) { $streets[] = $streetOne; } if ($streetTwo) { $streets[] = $streetTwo; } return implode(', ', $streets); } public function getPostcode() { return $this->_scopeConfig->getValue( 'general/store_information/postcode', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); } public function getRegion() { $regionId = $this->_scopeConfig->getValue( 'general/store_information/region_id', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); if (is_numeric($regionId)) { // @phpstan-ignore-next-line it's using an @api class return $this->regionFactory->create() ->load($regionId) ->getName(); } return $regionId; } public function getCountry() { $countryId = $this->_scopeConfig->getValue( 'general/store_information/country_id', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); if (!$countryId) { return ''; } $locale = $this->_scopeConfig->getValue( 'general/locale/code', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); return $this->countryFactory->create() ->loadByCode($countryId) ->getName($locale); } public function getPhone() { return trim((string) $this->_scopeConfig->getValue( 'general/store_information/phone', ScopeInterface::SCOPE_STORE, $this->getStoreId() )); } public function getEmail() { return trim((string)$this->_scopeConfig->getValue( 'trans_email/ident_custom1/email', ScopeInterface::SCOPE_STORE, $this->getStoreId() )); } public function getWebsite($colour = 'black') { $url = (string)$this->_scopeConfig->getValue( 'web/unsecure/base_url', ScopeInterface::SCOPE_STORE, $this->getStoreId() ); $urlProtFree = rtrim(str_replace(['https://', 'http://'], '', $url), '/'); return sprintf('<a style="color:%s; text-decoration: none;" href="%s">%s</a>', $colour, $url, $urlProtFree); } public function getSvgIconAsString($iconName, $primColour, $secColour) { $fileContents = $this->file->read( $this->moduleReader->getModuleDir(Dir::MODULE_VIEW_DIR, 'Fooman_PdfDesign') . '/frontend/web/images/svg/pdf-design-1/' . $iconName . '.svg' ); $processedFileContents = str_replace( [self::PRIMARY_COLOUR_PLACEHOLDER, self::SECONDARY_COLOUR_PLACEHOLDER], [$primColour, $secColour], $fileContents ); return '@' . $processedFileContents; } }