Browse code

Do not execute hook if template buffes is lacking a html head

Benjamin Roth authored on13/12/2019 19:11:56
Showing1 changed files
... ...
@@ -14,7 +14,7 @@ class TemplateListener
14 14
 {
15 15
   public function onOutputFrontendTemplate($strBuffer)
16 16
   {
17
-    if (($rootPage = \PageModel::findByPk($GLOBALS['objPage']->rootId)) !== null && $rootPage->cookieconsent_enable)
17
+    if (strpos($strBuffer, '<head>') && ($rootPage = \PageModel::findByPk($GLOBALS['objPage']->rootId)) !== null && $rootPage->cookieconsent_enable)
18 18
     {
19 19
       $Template = new \FrontendTemplate('cookieconsent');
20 20
       $arrServices = deserialize($rootPage->cookieconsent_services);
... ...
@@ -89,16 +89,13 @@ class TemplateListener
89 89
       $Template->services = $strServices;
90 90
       $Template->privacy_policy_link = $rootPage->cookieconsent_link != '' ? "'".$rootPage->cookieconsent_link."'" : "null";
91 91
 
92
-      if (strpos($strBuffer, '<head>'))
93
-      {
94
-        $GLOBALS['TL_CSS'][] = 'system/modules/eSM_cookieconsent/assets/css/cc_style_override.css|screen';
92
+      $GLOBALS['TL_CSS'][] = 'system/modules/eSM_cookieconsent/assets/css/cc_style_override.css|screen';
95 93
 
96
-        $strInject = '<script src="'.\Environment::get('path').'/system/modules/eSM_cookieconsent/assets/js/lib/cookieconsent.min.js"></script>';
94
+      $strInject = '<script src="'.\Environment::get('path').'/system/modules/eSM_cookieconsent/assets/js/lib/cookieconsent.min.js"></script>';
97 95
 
98
-        $strInject .= $Template->parse();
96
+      $strInject .= $Template->parse();
99 97
 
100
-        $strBuffer = str_replace('<head>', '<head>' . $strInject, $strBuffer);
101
-      }
98
+      $strBuffer = str_replace('<head>', '<head>' . $strInject, $strBuffer);
102 99
     }
103 100
 
104 101
     return $strBuffer;