@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | * Domain name of GTM |
| 25 | 25 | * @var string |
| 26 | 26 | */ |
| 27 | - private static $gtm_domain = 'www.googletagmanager.com'; |
|
| 27 | + private static $gtm_domain = 'www.googletagmanager.com'; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Holds the GTM ID |
| 31 | 31 | * @var string |
| 32 | 32 | */ |
| 33 | - private $gtm_id = null; |
|
| 33 | + private $gtm_id = null; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Process the request |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | * @param $delegate |
| 39 | 39 | * @return |
| 40 | 40 | */ |
| 41 | - public function process(HTTPRequest $request, callable $delegate) { |
|
| 41 | + public function process(HTTPRequest $request, callable $delegate) { |
|
| 42 | 42 | |
| 43 | - $response = $delegate($request); |
|
| 43 | + $response = $delegate($request); |
|
| 44 | 44 | |
| 45 | - if ($this->getIsAdmin($request) === true) { |
|
| 45 | + if ($this->getIsAdmin($request) === true) { |
|
| 46 | 46 | return $response; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - $config = SiteConfig::current_site_config(); |
|
| 50 | - $this->gtm_id = $config->GTMID; |
|
| 51 | - if ($this->gtm_id != "") { |
|
| 49 | + $config = SiteConfig::current_site_config(); |
|
| 50 | + $this->gtm_id = $config->GTMID; |
|
| 51 | + if ($this->gtm_id != "") { |
|
| 52 | 52 | $this->addBodyTag($response); |
| 53 | 53 | $this->addHeadTag($response); |
| 54 | 54 | $this->addPrefetch($response); |
@@ -56,32 +56,32 @@ discard block |
||
| 56 | 56 | return $response; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - private function addBodyTag(&$response) { |
|
| 60 | - $data = ArrayData::create(['GTMID' => $this->gtm_id]); |
|
| 61 | - $tag = $data->renderWith('BodySnippet'); |
|
| 62 | - $body = $response->getBody(); |
|
| 63 | - $pattern = '/\<body.*\>/'; |
|
| 64 | - $replace = '${0}' . "\n" . $tag; |
|
| 65 | - $newBody = preg_replace($pattern, $replace, $body); |
|
| 59 | + private function addBodyTag(&$response) { |
|
| 60 | + $data = ArrayData::create([ 'GTMID' => $this->gtm_id ]); |
|
| 61 | + $tag = $data->renderWith('BodySnippet'); |
|
| 62 | + $body = $response->getBody(); |
|
| 63 | + $pattern = '/\<body.*\>/'; |
|
| 64 | + $replace = '${0}' . "\n" . $tag; |
|
| 65 | + $newBody = preg_replace($pattern, $replace, $body); |
|
| 66 | 66 | $response->setBody($newBody); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - private function addHeadTag(&$response) { |
|
| 70 | - $data = ArrayData::create(['GTMID' => $this->gtm_id]); |
|
| 71 | - $tag = $data->renderWith('HeadSnippet'); |
|
| 72 | - $body = $response->getBody(); |
|
| 73 | - $body = str_replace('<head>', "<head>" . $tag, $body); |
|
| 69 | + private function addHeadTag(&$response) { |
|
| 70 | + $data = ArrayData::create([ 'GTMID' => $this->gtm_id ]); |
|
| 71 | + $tag = $data->renderWith('HeadSnippet'); |
|
| 72 | + $body = $response->getBody(); |
|
| 73 | + $body = str_replace('<head>', "<head>" . $tag, $body); |
|
| 74 | 74 | $response->setBody($body); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - private function addPrefetch(&$response) { |
|
| 78 | - $atts = [ |
|
| 77 | + private function addPrefetch(&$response) { |
|
| 78 | + $atts = [ |
|
| 79 | 79 | 'rel' => 'dns-prefetch', |
| 80 | 80 | 'href' => $this->config()->get('gtm_domain') |
| 81 | 81 | ]; |
| 82 | - $pfTag = "\n" . HTML::createTag('link', $atts) . "\n"; |
|
| 83 | - $body = $response->getBody(); |
|
| 84 | - $body = str_replace('<head>', "<head>" . $pfTag, $body); |
|
| 82 | + $pfTag = "\n" . HTML::createTag('link', $atts) . "\n"; |
|
| 83 | + $body = $response->getBody(); |
|
| 84 | + $body = str_replace('<head>', "<head>" . $pfTag, $body); |
|
| 85 | 85 | $response->setBody($body); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,13 +92,13 @@ discard block |
||
| 92 | 92 | * @param HTTPRequest $request |
| 93 | 93 | * @return bool |
| 94 | 94 | */ |
| 95 | - private function getIsAdmin(HTTPRequest $request) { |
|
| 96 | - $adminPaths = static::config()->get('admin_url_paths'); |
|
| 97 | - $adminPaths[] = AdminRootController::config()->get('url_base') . '/'; |
|
| 98 | - $adminPaths[] = 'dev/'; |
|
| 99 | - $currentPath = rtrim($request->getURL(), '/') . '/'; |
|
| 100 | - foreach ($adminPaths as $adminPath) { |
|
| 101 | - if (substr($currentPath, 0, strlen($adminPath)) === $adminPath) { |
|
| 95 | + private function getIsAdmin(HTTPRequest $request) { |
|
| 96 | + $adminPaths = static::config()->get('admin_url_paths'); |
|
| 97 | + $adminPaths[ ] = AdminRootController::config()->get('url_base') . '/'; |
|
| 98 | + $adminPaths[ ] = 'dev/'; |
|
| 99 | + $currentPath = rtrim($request->getURL(), '/') . '/'; |
|
| 100 | + foreach ($adminPaths as $adminPath) { |
|
| 101 | + if (substr($currentPath, 0, strlen($adminPath)) === $adminPath) { |
|
| 102 | 102 | return true; |
| 103 | 103 | } |
| 104 | 104 | } |