app/Customize/Service/LandingPageService.php line 84

Open in your IDE?
  1. <?php
  2. namespace Customize\Service;
  3. use Symfony\Component\HttpFoundation\Cookie;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. use Symfony\Component\HttpFoundation\Response;
  7. class LandingPageService
  8. {
  9.     const COOKIE_NAME 'landing_page_data';
  10.     const COOKIE_EXPIRES 60 60 24 30;
  11.     const COOKIE_PATH '/';
  12.     /**
  13.      * @var \Symfony\Component\HttpFoundation\Request|null
  14.      */
  15.     private $request;
  16.     public function __construct(
  17.         RequestStack $requestStack
  18.     ) {
  19.         $this->request $requestStack->getMasterRequest();
  20.     }
  21.     /**
  22.      * @return mixed
  23.      */
  24.     public function get()
  25.     {
  26.         return $this->request->cookies->get(self::COOKIE_NAME);
  27.     }
  28.     /**
  29.      * @return $this
  30.      */
  31.     public function remove()
  32.     {
  33.         //
  34.         $this->request->cookies->remove(self::COOKIE_NAME);
  35.         //
  36.         return $this;
  37.     }
  38.     public function isCompletePage(Request $request)
  39.     {
  40.         return preg_match('!^(shopping_complete)!'$request->get('_route'));
  41.     }
  42.     public function isLandingPage(Request $request)
  43.     {
  44.         return !preg_match('!^(shopping|_wdt)!'$request->get('_route'));
  45.     }
  46.     /**
  47.      * リクエストが広告からのものか判定する
  48.      *
  49.      * @link https://bitbucket.org/lm91/backoffice/src/1bc74d936615bd8e312b61135145056f04186ef0/app/html/backoffice/application/modules/default/controllers/commons/class/comp-navi/CompNavi.php#lines-216:265
  50.      * @param Request $request
  51.      * @return bool
  52.      */
  53.     public function isAdvertised(Request $request)
  54.     {
  55.         return $request->get('utm_source') || $request->get('gclid');
  56.     }
  57.     /**
  58.      * @return array
  59.      */
  60.     public function retrieveLandingPageData()
  61.     {
  62.         $matches = array();
  63.         $referer $this->request->server->get('HTTP_REFERER');
  64.         $uri $this->request->getRequestUri();
  65.         $search_keyword '';
  66.         $search_site_key 99;
  67.         if (preg_match('@^https?://www.google.co.jp/@'$referer)) {
  68.             preg_match("/[?&]q=([^&]+)/"$referer$matches);
  69.             $search_site_key 1;
  70.         } else if (preg_match('@^https?://www.bing.com/@'$referer)) {
  71.             preg_match("/[?&]q=([^&]+)/"$referer$matches);
  72.             $search_site_key 2;
  73.         } elseif (preg_match('@^https?://search.yahoo.co.jp/@'$referer)) {
  74.             preg_match("/[?&]p=([^&]+)/"$referer$matches);
  75.             $search_site_key 3;
  76.         }
  77.         if ($matches) {
  78.             $search_keyword urldecode($matches[1]);
  79.         }
  80.         $land_page_data = array(
  81.             'landing_page_search_keyword' => $search_keyword,
  82.             'landing_page_path' => $uri,
  83.             'landing_page_search_site' => $search_site_key,
  84.         );
  85.         //
  86.         return $land_page_data;
  87.     }
  88. }