Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Magento\SendFriend\Model; use Magento\Framework\Exception\LocalizedExcep..

Decoded Output download

<?php
  namespace Magento\SendFriend\Model; use Magento\Framework\Exception\LocalizedException as CoreException; use Magento\Framework\Stdlib\Cookie\CookieMetadata; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\App\ObjectManager; use Magento\Framework\Validator\EmailAddress; use Magento\Framework\Validator\ValidatorChain; class SendFriend extends \Magento\Framework\Model\AbstractModel { protected $_names = array(); protected $_emails = array(); protected $_sender = array(); protected $_product; protected $_sentCount; protected $_lastCookieValue = array(); protected $_sendfriendData = null; protected $_catalogImage = null; protected $_transportBuilder; protected $_storeManager; protected $_escaper; protected $inlineTranslation; protected $cookieManager; protected $remoteAddress; private $cookieMetadataFactory; public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Catalog\Helper\Image $catalogImage, \Magento\SendFriend\Helper\Data $sendfriendData, \Magento\Framework\Escaper $escaper, \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = array(), CookieMetadataFactory $cookieMetadataFactory = null) { $this->_storeManager = $storeManager; $this->_transportBuilder = $transportBuilder; $this->_catalogImage = $catalogImage; $this->_sendfriendData = $sendfriendData; $this->_escaper = $escaper; $this->remoteAddress = $remoteAddress; $this->cookieManager = $cookieManager; $this->inlineTranslation = $inlineTranslation; $this->cookieMetadataFactory = $cookieMetadataFactory ?? ObjectManager::getInstance()->get(CookieMetadataFactory::class); parent::__construct($context, $registry, $resource, $resourceCollection, $data); } protected function _construct() { $this->_init(\Magento\SendFriend\Model\ResourceModel\SendFriend::class); } public function send() { if ($this->isExceedLimit()) { throw new \Magento\Framework\Exception\LocalizedException(__("You've met your limit of %1 sends in an hour.", $this->getMaxSendsToFriend())); } $this->inlineTranslation->suspend(); $message = nl2br($this->_escaper->escapeHtml($this->getSender()->getMessage())); $sender = array("name" => $this->_escaper->escapeHtml($this->getSender()->getName()), "email" => $this->_escaper->escapeHtml($this->getSender()->getEmail())); foreach ($this->getRecipients()->getEmails() as $k => $email) { $name = $this->getRecipients()->getNames($k); $product = $this->getProduct(); $productImage = $this->_catalogImage->init($product, "sendfriend_small_image"); $this->_transportBuilder->setTemplateIdentifier($this->_sendfriendData->getEmailTemplate())->setTemplateOptions(array("area" => \Magento\Framework\App\Area::AREA_FRONTEND, "store" => $this->_storeManager->getStore()->getId()))->setFromByScope("general")->setReplyTo($sender["email"], $sender["name"])->setTemplateVars(array("name" => $name, "email" => $email, "product_name" => $this->getProduct()->getName(), "product_url" => $this->getProduct()->getUrlInStore(), "message" => $message, "sender_name" => $sender["name"], "sender_email" => $sender["email"], "product_image" => $productImage->getType() !== null ? $productImage->getUrl() : $productImage->getDefaultPlaceholderUrl()))->addTo($email, $name); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); } $this->inlineTranslation->resume(); $this->_incrementSentCount(); return $this; } public function validate() { $errors = array(); $name = $this->getSender()->getName(); if (empty($name)) { $errors[] = __("Please enter a sender name."); } $email = $this->getSender()->getEmail(); if (empty($email) || !ValidatorChain::is($email, EmailAddress::class)) { $errors[] = __("Invalid Sender Email"); } $message = $this->getSender()->getMessage(); if (empty($message)) { $errors[] = __("Please enter a message."); } if (!$this->getRecipients()->getEmails()) { $errors[] = __("Please specify at least one recipient."); } foreach ($this->getRecipients()->getEmails() as $email) { if (!ValidatorChain::is($email, EmailAddress::class)) { $errors[] = __("Please enter a correct recipient email address."); break; } } $maxRecipients = $this->getMaxRecipients(); if (count($this->getRecipients()->getEmails()) > $maxRecipients) { $errors[] = __("No more than %1 emails can be sent at a time.", $this->getMaxRecipients()); } if (empty($errors)) { return true; } return $errors; } public function setRecipients($recipients) { if (!is_array($recipients) || !isset($recipients["email"]) || !isset($recipients["name"]) || !is_array($recipients["email"]) || !is_array($recipients["name"])) { return $this; } $emails = array(); $names = array(); foreach ($recipients["email"] as $k => $email) { if (!isset($emails[$email]) && isset($recipients["name"][$k])) { $emails[$email] = true; $names[] = $recipients["name"][$k]; } } if ($emails) { $emails = array_keys($emails); } return $this->setData("_recipients", new \Magento\Framework\DataObject(array("emails" => $emails, "names" => $names))); } public function getRecipients() { $recipients = $this->_getData("_recipients"); if (!$recipients instanceof \Magento\Framework\DataObject) { $recipients = new \Magento\Framework\DataObject(array("emails" => array(), "names" => array())); $this->setData("_recipients", $recipients); } return $recipients; } public function setProduct($product) { return $this->setData("_product", $product); } public function getProduct() { $product = $this->_getData("_product"); if (!$product instanceof \Magento\Catalog\Model\Product) { throw new \Magento\Framework\Exception\LocalizedException(__("Please define a correct product instance.")); } return $product; } public function setSender($sender) { if (!is_array($sender)) { __("Invalid Sender Information"); } return $this->setData("_sender", new \Magento\Framework\DataObject($sender)); } public function getSender() { $sender = $this->_getData("_sender"); if (!$sender instanceof \Magento\Framework\DataObject) { throw new \Magento\Framework\Exception\LocalizedException(__("Please define the correct sender information.")); } return $sender; } public function getMaxSendsToFriend() { return $this->_sendfriendData->getMaxEmailPerPeriod(); } public function getMaxRecipients() { return $this->_sendfriendData->getMaxRecipients(); } public function canEmailToFriend() { return $this->_sendfriendData->isEnabled(); } public function isExceedLimit() { return $this->getSentCount() >= $this->getMaxSendsToFriend(); } public function getSentCount($useCache = true) { if ($useCache && $this->_sentCount !== null) { return $this->_sentCount; } switch ($this->_sendfriendData->getLimitBy()) { case \Magento\SendFriend\Helper\Data::CHECK_COOKIE: return $this->_sentCount = $this->_sentCountByCookies(false); case \Magento\SendFriend\Helper\Data::CHECK_IP: return $this->_sentCount = $this->_sentCountByIp(false); default: return 0; } } protected function _incrementSentCount() { switch ($this->_sendfriendData->getLimitBy()) { case \Magento\SendFriend\Helper\Data::CHECK_COOKIE: return $this->_sentCount = $this->_sentCountByCookies(true); case \Magento\SendFriend\Helper\Data::CHECK_IP: return $this->_sentCount = $this->_sentCountByIp(true); default: return 0; } } protected function _sentCountByCookies($increment = false) { $cookieName = $this->_sendfriendData->getCookieName(); $time = time(); $newTimes = array(); $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata(array(CookieMetadata::KEY_SAME_SITE => "Lax")); if (isset($this->_lastCookieValue[$cookieName])) { $oldTimes = $this->_lastCookieValue[$cookieName]; } else { $oldTimes = $this->cookieManager->getCookie($cookieName); } if ($oldTimes) { $oldTimes = explode(",", $oldTimes); foreach ($oldTimes as $oldTime) { $periodTime = $time - $this->_sendfriendData->getPeriod(); if (is_numeric($oldTime) && $oldTime >= $periodTime) { $newTimes[] = $oldTime; } } } if ($increment) { $newTimes[] = $time; $newValue = implode(",", $newTimes); $this->cookieManager->setSensitiveCookie($cookieName, $newValue, $sensitiveCookMetadata); $this->_lastCookieValue[$cookieName] = $newValue; } return count($newTimes); } protected function _sentCountByIp($increment = false) { $time = time(); $period = $this->_sendfriendData->getPeriod(); $websiteId = $this->_storeManager->getStore()->getWebsiteId(); if ($increment) { $this->_getResource()->deleteLogsBefore($time - $period); $this->_getResource()->addSendItem($this->remoteAddress->getRemoteAddress(true), $time, $websiteId); } return $this->_getResource()->getSendCount($this, $this->remoteAddress->getRemoteAddress(true), time() - $period, $websiteId); } } ?>

Did this file decode correctly?

Original Code

<?php
  namespace Magento\SendFriend\Model; use Magento\Framework\Exception\LocalizedException as CoreException; use Magento\Framework\Stdlib\Cookie\CookieMetadata; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\App\ObjectManager; use Magento\Framework\Validator\EmailAddress; use Magento\Framework\Validator\ValidatorChain; class SendFriend extends \Magento\Framework\Model\AbstractModel { protected $_names = array(); protected $_emails = array(); protected $_sender = array(); protected $_product; protected $_sentCount; protected $_lastCookieValue = array(); protected $_sendfriendData = null; protected $_catalogImage = null; protected $_transportBuilder; protected $_storeManager; protected $_escaper; protected $inlineTranslation; protected $cookieManager; protected $remoteAddress; private $cookieMetadataFactory; public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Catalog\Helper\Image $catalogImage, \Magento\SendFriend\Helper\Data $sendfriendData, \Magento\Framework\Escaper $escaper, \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = array(), CookieMetadataFactory $cookieMetadataFactory = null) { $this->_storeManager = $storeManager; $this->_transportBuilder = $transportBuilder; $this->_catalogImage = $catalogImage; $this->_sendfriendData = $sendfriendData; $this->_escaper = $escaper; $this->remoteAddress = $remoteAddress; $this->cookieManager = $cookieManager; $this->inlineTranslation = $inlineTranslation; $this->cookieMetadataFactory = $cookieMetadataFactory ?? ObjectManager::getInstance()->get(CookieMetadataFactory::class); parent::__construct($context, $registry, $resource, $resourceCollection, $data); } protected function _construct() { $this->_init(\Magento\SendFriend\Model\ResourceModel\SendFriend::class); } public function send() { if ($this->isExceedLimit()) { throw new \Magento\Framework\Exception\LocalizedException(__("\x59\157\165\47\x76\x65\x20\x6d\145\164\x20\171\x6f\x75\x72\x20\154\151\x6d\151\x74\40\x6f\146\40\x25\x31\40\x73\145\156\144\163\x20\x69\x6e\x20\141\156\x20\150\157\x75\162\x2e", $this->getMaxSendsToFriend())); } $this->inlineTranslation->suspend(); $message = nl2br($this->_escaper->escapeHtml($this->getSender()->getMessage())); $sender = array("\156\x61\155\x65" => $this->_escaper->escapeHtml($this->getSender()->getName()), "\x65\155\141\151\x6c" => $this->_escaper->escapeHtml($this->getSender()->getEmail())); foreach ($this->getRecipients()->getEmails() as $k => $email) { $name = $this->getRecipients()->getNames($k); $product = $this->getProduct(); $productImage = $this->_catalogImage->init($product, "\x73\x65\x6e\x64\146\162\x69\145\x6e\x64\137\163\x6d\x61\154\x6c\x5f\x69\x6d\141\x67\x65"); $this->_transportBuilder->setTemplateIdentifier($this->_sendfriendData->getEmailTemplate())->setTemplateOptions(array("\x61\x72\145\141" => \Magento\Framework\App\Area::AREA_FRONTEND, "\163\x74\157\162\x65" => $this->_storeManager->getStore()->getId()))->setFromByScope("\147\x65\x6e\145\x72\141\x6c")->setReplyTo($sender["\x65\155\141\x69\154"], $sender["\x6e\x61\155\145"])->setTemplateVars(array("\x6e\141\155\x65" => $name, "\x65\x6d\141\151\x6c" => $email, "\160\x72\x6f\x64\x75\143\x74\x5f\156\x61\x6d\145" => $this->getProduct()->getName(), "\160\x72\157\x64\165\143\164\137\165\x72\x6c" => $this->getProduct()->getUrlInStore(), "\155\x65\x73\163\141\x67\x65" => $message, "\163\x65\156\144\x65\x72\137\156\x61\x6d\145" => $sender["\x6e\x61\155\145"], "\x73\145\156\144\x65\x72\137\x65\155\x61\151\x6c" => $sender["\145\x6d\141\x69\154"], "\160\x72\x6f\144\x75\x63\x74\x5f\151\x6d\x61\x67\x65" => $productImage->getType() !== null ? $productImage->getUrl() : $productImage->getDefaultPlaceholderUrl()))->addTo($email, $name); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); } $this->inlineTranslation->resume(); $this->_incrementSentCount(); return $this; } public function validate() { $errors = array(); $name = $this->getSender()->getName(); if (empty($name)) { $errors[] = __("\x50\x6c\x65\141\x73\145\40\145\x6e\164\x65\x72\40\x61\40\163\145\156\x64\145\x72\x20\x6e\x61\155\145\56"); } $email = $this->getSender()->getEmail(); if (empty($email) || !ValidatorChain::is($email, EmailAddress::class)) { $errors[] = __("\x49\x6e\x76\141\x6c\151\144\x20\123\145\x6e\x64\x65\x72\x20\x45\155\141\151\x6c"); } $message = $this->getSender()->getMessage(); if (empty($message)) { $errors[] = __("\120\x6c\145\141\163\x65\x20\145\156\x74\145\x72\x20\141\40\x6d\x65\x73\x73\141\x67\145\56"); } if (!$this->getRecipients()->getEmails()) { $errors[] = __("\x50\154\x65\141\163\145\x20\x73\x70\x65\x63\151\x66\171\x20\x61\x74\x20\154\145\141\x73\164\40\x6f\156\145\x20\162\145\143\151\x70\151\x65\x6e\x74\x2e"); } foreach ($this->getRecipients()->getEmails() as $email) { if (!ValidatorChain::is($email, EmailAddress::class)) { $errors[] = __("\120\154\x65\141\163\x65\x20\x65\x6e\164\x65\x72\40\141\x20\x63\x6f\162\x72\145\143\164\40\x72\x65\x63\x69\160\x69\145\x6e\164\x20\145\155\x61\x69\x6c\x20\x61\x64\144\x72\x65\x73\163\x2e"); break; } } $maxRecipients = $this->getMaxRecipients(); if (count($this->getRecipients()->getEmails()) > $maxRecipients) { $errors[] = __("\116\157\x20\155\157\162\x65\x20\164\150\141\156\x20\x25\61\40\145\x6d\141\151\x6c\x73\40\143\x61\x6e\x20\x62\145\x20\x73\145\156\x74\x20\141\x74\40\x61\40\x74\151\x6d\x65\56", $this->getMaxRecipients()); } if (empty($errors)) { return true; } return $errors; } public function setRecipients($recipients) { if (!is_array($recipients) || !isset($recipients["\145\x6d\141\151\154"]) || !isset($recipients["\x6e\141\x6d\145"]) || !is_array($recipients["\145\x6d\x61\x69\154"]) || !is_array($recipients["\156\x61\155\x65"])) { return $this; } $emails = array(); $names = array(); foreach ($recipients["\145\x6d\141\x69\x6c"] as $k => $email) { if (!isset($emails[$email]) && isset($recipients["\156\x61\x6d\145"][$k])) { $emails[$email] = true; $names[] = $recipients["\x6e\x61\155\x65"][$k]; } } if ($emails) { $emails = array_keys($emails); } return $this->setData("\x5f\162\145\x63\151\x70\x69\x65\156\164\x73", new \Magento\Framework\DataObject(array("\145\x6d\141\x69\154\x73" => $emails, "\156\141\x6d\145\x73" => $names))); } public function getRecipients() { $recipients = $this->_getData("\137\x72\145\143\x69\x70\151\145\x6e\164\x73"); if (!$recipients instanceof \Magento\Framework\DataObject) { $recipients = new \Magento\Framework\DataObject(array("\145\155\141\151\x6c\x73" => array(), "\x6e\x61\x6d\x65\163" => array())); $this->setData("\137\x72\x65\143\151\160\x69\145\156\164\163", $recipients); } return $recipients; } public function setProduct($product) { return $this->setData("\137\160\162\x6f\x64\x75\x63\x74", $product); } public function getProduct() { $product = $this->_getData("\137\160\x72\x6f\x64\x75\143\x74"); if (!$product instanceof \Magento\Catalog\Model\Product) { throw new \Magento\Framework\Exception\LocalizedException(__("\120\x6c\x65\141\x73\x65\40\x64\x65\146\x69\x6e\x65\x20\141\40\x63\157\x72\x72\x65\x63\164\x20\x70\x72\x6f\x64\x75\x63\164\x20\151\156\x73\164\x61\156\x63\145\56")); } return $product; } public function setSender($sender) { if (!is_array($sender)) { __("\111\x6e\x76\141\154\151\144\x20\x53\145\156\x64\145\162\x20\x49\156\146\157\x72\x6d\x61\x74\x69\157\x6e"); } return $this->setData("\x5f\163\145\x6e\x64\x65\162", new \Magento\Framework\DataObject($sender)); } public function getSender() { $sender = $this->_getData("\x5f\163\x65\x6e\x64\145\x72"); if (!$sender instanceof \Magento\Framework\DataObject) { throw new \Magento\Framework\Exception\LocalizedException(__("\x50\x6c\145\141\163\145\x20\144\x65\x66\151\156\x65\40\x74\x68\145\40\x63\x6f\x72\x72\x65\x63\164\40\x73\145\156\x64\x65\x72\x20\x69\x6e\x66\x6f\162\x6d\x61\x74\x69\x6f\x6e\56")); } return $sender; } public function getMaxSendsToFriend() { return $this->_sendfriendData->getMaxEmailPerPeriod(); } public function getMaxRecipients() { return $this->_sendfriendData->getMaxRecipients(); } public function canEmailToFriend() { return $this->_sendfriendData->isEnabled(); } public function isExceedLimit() { return $this->getSentCount() >= $this->getMaxSendsToFriend(); } public function getSentCount($useCache = true) { if ($useCache && $this->_sentCount !== null) { return $this->_sentCount; } switch ($this->_sendfriendData->getLimitBy()) { case \Magento\SendFriend\Helper\Data::CHECK_COOKIE: return $this->_sentCount = $this->_sentCountByCookies(false); case \Magento\SendFriend\Helper\Data::CHECK_IP: return $this->_sentCount = $this->_sentCountByIp(false); default: return 0; } } protected function _incrementSentCount() { switch ($this->_sendfriendData->getLimitBy()) { case \Magento\SendFriend\Helper\Data::CHECK_COOKIE: return $this->_sentCount = $this->_sentCountByCookies(true); case \Magento\SendFriend\Helper\Data::CHECK_IP: return $this->_sentCount = $this->_sentCountByIp(true); default: return 0; } } protected function _sentCountByCookies($increment = false) { $cookieName = $this->_sendfriendData->getCookieName(); $time = time(); $newTimes = array(); $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata(array(CookieMetadata::KEY_SAME_SITE => "\x4c\141\170")); if (isset($this->_lastCookieValue[$cookieName])) { $oldTimes = $this->_lastCookieValue[$cookieName]; } else { $oldTimes = $this->cookieManager->getCookie($cookieName); } if ($oldTimes) { $oldTimes = explode("\x2c", $oldTimes); foreach ($oldTimes as $oldTime) { $periodTime = $time - $this->_sendfriendData->getPeriod(); if (is_numeric($oldTime) && $oldTime >= $periodTime) { $newTimes[] = $oldTime; } } } if ($increment) { $newTimes[] = $time; $newValue = implode("\54", $newTimes); $this->cookieManager->setSensitiveCookie($cookieName, $newValue, $sensitiveCookMetadata); $this->_lastCookieValue[$cookieName] = $newValue; } return count($newTimes); } protected function _sentCountByIp($increment = false) { $time = time(); $period = $this->_sendfriendData->getPeriod(); $websiteId = $this->_storeManager->getStore()->getWebsiteId(); if ($increment) { $this->_getResource()->deleteLogsBefore($time - $period); $this->_getResource()->addSendItem($this->remoteAddress->getRemoteAddress(true), $time, $websiteId); } return $this->_getResource()->getSendCount($this, $this->remoteAddress->getRemoteAddress(true), time() - $period, $websiteId); } }

Function Calls

None

Variables

None

Stats

MD5 d01c9a7b605bb8525dd64ab373354f61
Eval Count 0
Decode Time 86 ms