app/Plugin/SeShareButton4/SeShareButton4Event.php line 45

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright(c) 2020 Shadow Enterprise, Inc. All rights reserved.
  4.  * http://www.shadow-ep.co.jp/
  5.  */
  6. namespace Plugin\SeShareButton4;
  7. use Eccube\Common\EccubeConfig;
  8. use Eccube\Event\TemplateEvent;
  9. use Plugin\SeShareButton4\Repository\ShareButtonConfigRepository;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class SeShareButton4Event implements EventSubscriberInterface
  12. {
  13.     protected $eccubeConfig;
  14.     protected $shareButtonConfigRepository;
  15.     /**
  16.      * コンストラクタ
  17.      */
  18.     public function __construct(
  19.         EccubeConfig $eccubeConfig,
  20.         ShareButtonConfigRepository $shareButtonConfigRepository
  21.     ) {
  22.         $this->eccubeConfig $eccubeConfig;
  23.         $this->shareButtonConfigRepository $shareButtonConfigRepository;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             'Product/detail.twig' => 'onDefaultProductDetailTwig',
  32.         ];
  33.     }
  34.     /**
  35.      * フロント -> 商品詳細
  36.      */
  37.     public function onDefaultProductDetailTwig(TemplateEvent $event)
  38.     {
  39.         $ShareButtonConfig $this->shareButtonConfigRepository->get();
  40.         // 基本となるサイズをここで調整する
  41.         $decodeInfo $ShareButtonConfig->getConfigJson();
  42.         // 画像が存在すればサイズを配列に追加する(デフォルトは20x20とする) - cssで処理させるので今後必要なら利用する
  43. /*
  44.         if ( $decodeInfo ) {
  45.             $permitExt = $this->eccubeConfig['Se_ShareButton_img_valid_extention'];
  46.             $permitExt = explode(',', str_replace('.', '', $permitExt));
  47.             $permitExt = array_flip($permitExt);
  48.             // get plugin dir
  49.             $pluginDir = $this->eccubeConfig['eccube_html_plugin_dir'];
  50.             foreach ( $decodeInfo as $key => $value ) {
  51.                 if ( isset($value['img']) && !empty($value['img']) ) {
  52.                     $imageFile = $pluginDir .'/SeShareButton4/assets/img/' .$value['img'];
  53.                     if ( file_exists($imageFile) ) {
  54.                         $extention = substr($imageFile, strrpos($imageFile, '.') + 1);
  55.                         if ( $extention == 'svg' ) {
  56.                             $decodeInfo[$key]['w'] = $decodeInfo[$key]['h'] = 20;
  57.                         } else 
  58.                         if ( isset($permitExt[strtolower($extention)]) ) {
  59.                             $imageSizes = getimagesize($imageFile);
  60.                             if ( isset($imageSizes[0]) && isset($imageSizes[1]) ) {
  61.                                 // 高さは20px固定とする?
  62.                                 $decodeInfo[$key]['h'] = 20;
  63.                                 $decodeInfo[$key]['w'] = round( ( 20 / (int)$imageSizes[1] ) * (int)$imageSizes[0], 2 );
  64.                             }
  65.                         }
  66.                     }
  67.                 }
  68.             }
  69.         }
  70. */
  71.         // JSで利用するので配列ではなくJSON型で渡す
  72.         $event->setParameter'ShareButtonConfig'json_encode($decodeInfo) );
  73.         $event->addSnippet('@SeShareButton4/product_detail.twig');
  74.     }
  75. }