src/EventSubscriber/DomainParkingSubscriber.php line 20

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-07-02
  5.  * Time: 18:22
  6.  */
  7. namespace App\EventSubscriber;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  11. use Symfony\Component\HttpKernel\Event\RequestEvent;
  12. use Symfony\Component\HttpKernel\KernelEvents;
  13. class DomainParkingSubscriber implements EventSubscriberInterface
  14. {
  15.     const DOMAIN_PARKING_HEADER 'X-Domain-Parking';
  16.     public function onRequest(RequestEvent $event): void
  17.     {
  18.         $request $event->getRequest();
  19.         if (empty($request->headers->get(self::DOMAIN_PARKING_HEADER))) {
  20.             return;
  21.         }
  22.         $response = new Response($this->domainParkingPageHtml(), Response::HTTP_OK);
  23.         $event->setResponse($response);
  24.     }
  25.     /**
  26.      * @inheritDoc
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             KernelEvents::REQUEST => ['onRequest'150],
  32.         ];
  33.     }
  34.     private function domainParkingPageHtml(): string
  35.     {
  36.         return <<<HTML
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40.     <meta charset="utf-8">
  41.     <style type="text/css">
  42.         html, body, #partner, iframe {
  43.             height: 100%;
  44.             width: 100%;
  45.             margin: 0;
  46.             padding: 0;
  47.             border: 0;
  48.             outline: 0;
  49.             font-size: 100%;
  50.             vertical-align: baseline;
  51.             background: transparent;
  52.         }
  53.         body {
  54.             overflow: hidden;
  55.         }
  56.     </style>
  57.     <meta content="NOW" name="expires">
  58.     <meta content="index, follow, all" name="GOOGLEBOT">
  59.     <meta content="index, follow, all" name="robots">
  60.     <!-- Following Meta-Tag fixes scaling-issues on mobile devices -->
  61.     <meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0;
  62.             user-scalable=0;" name="viewport">
  63. </head>
  64. <body>
  65. <div id="partner"></div>
  66. <script type="text/javascript">
  67.     function getParam() {
  68.         var query = window.location.search.substring(1);
  69.         var vars = query.split("&");
  70.         for (var i = 0; i < vars.length; i++) {
  71.             var pair = vars[i].split("=");
  72.             if (pair[0] == 'domain') {
  73.                 return pair[1];
  74.             }
  75.         }
  76.         return  window.location.host;
  77.     }
  78.     ;
  79.     document.write(
  80.         '<script type="text/javascript" language="JavaScript"'
  81.         + 'src="//sedoparking.com/frmpark/'
  82.         + getParam() + '/'
  83.         + 'sedopark'
  84.         + '/park.js">'
  85.         + '<\/script>'
  86.     );
  87. </script>
  88. </body>
  89. </html>
  90. HTML;
  91.     }
  92. }