<?php
namespace Customize\Service;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
class LandingPageService
{
const COOKIE_NAME = 'landing_page_data';
const COOKIE_EXPIRES = 60 * 60 * 24 * 30;
const COOKIE_PATH = '/';
/**
* @var \Symfony\Component\HttpFoundation\Request|null
*/
private $request;
public function __construct(
RequestStack $requestStack
) {
$this->request = $requestStack->getMasterRequest();
}
/**
* @return mixed
*/
public function get()
{
return $this->request->cookies->get(self::COOKIE_NAME);
}
/**
* @return $this
*/
public function remove()
{
//
$this->request->cookies->remove(self::COOKIE_NAME);
//
return $this;
}
public function isCompletePage(Request $request)
{
return preg_match('!^(shopping_complete)!', $request->get('_route'));
}
public function isLandingPage(Request $request)
{
return !preg_match('!^(shopping|_wdt)!', $request->get('_route'));
}
/**
* リクエストが広告からのものか判定する
*
* @link https://bitbucket.org/lm91/backoffice/src/1bc74d936615bd8e312b61135145056f04186ef0/app/html/backoffice/application/modules/default/controllers/commons/class/comp-navi/CompNavi.php#lines-216:265
* @param Request $request
* @return bool
*/
public function isAdvertised(Request $request)
{
return $request->get('utm_source') || $request->get('gclid');
}
/**
* @return array
*/
public function retrieveLandingPageData()
{
$matches = array();
$referer = $this->request->server->get('HTTP_REFERER');
$uri = $this->request->getRequestUri();
$search_keyword = '';
$search_site_key = 99;
if (preg_match('@^https?://www.google.co.jp/@', $referer)) {
preg_match("/[?&]q=([^&]+)/", $referer, $matches);
$search_site_key = 1;
} else if (preg_match('@^https?://www.bing.com/@', $referer)) {
preg_match("/[?&]q=([^&]+)/", $referer, $matches);
$search_site_key = 2;
} elseif (preg_match('@^https?://search.yahoo.co.jp/@', $referer)) {
preg_match("/[?&]p=([^&]+)/", $referer, $matches);
$search_site_key = 3;
}
if ($matches) {
$search_keyword = urldecode($matches[1]);
}
$land_page_data = array(
'landing_page_search_keyword' => $search_keyword,
'landing_page_path' => $uri,
'landing_page_search_site' => $search_site_key,
);
//
return $land_page_data;
}
}