Просмотр исходного кода

#836 Profiler: don't add output for AJAX requests

Alex Trofimov 3 лет назад
Родитель
Сommit
cc878032d0

+ 1 - 15
modules/boonex/profiler/classes/BxProfiler.php

@@ -116,7 +116,7 @@ class BxProfiler extends BxDol
 
         echo ob_get_clean();
 
-        $sContentType = bx_profiler_get_header_content_type();
+        $sContentType = $this->oTemplate->getHeaderContentType();
         if ('text/html' == $sContentType) {            
             echo $sJsCss . $sPlanks;
         } 
@@ -663,20 +663,6 @@ class BxProfiler extends BxDol
     }
 }
 
-function bx_profiler_get_header_content_type()
-{
-    $aHeaders = headers_list();
-    foreach ($aHeaders as $s) {
-        $a = explode(':', $s);
-        if (isset($a[0]) && isset($a[1]) && 'content-type' == strtolower(trim($a[0]))) {
-            $aa = explode(';', $a[1]);
-            return strtolower(trim($aa[0]));
-        }
-    }
-
-    return false;
-}
-
 $GLOBALS['bx_profiler'] = new BxProfiler(BX_DOL_START);
 if (!$GLOBALS['bx_profiler']->_isProfilerDisabled())
     register_shutdown_function (array ($GLOBALS['bx_profiler'], 'output'));

+ 15 - 1
modules/boonex/profiler/classes/BxProfilerTemplate.php

@@ -94,7 +94,7 @@ class BxProfilerTemplate extends BxDolModuleTemplate
 
     function _isAjaxRequest ()
     {
-        if ('application/json' == bx_profiler_get_header_content_type()) 
+        if ('application/json' == $this->getHeaderContentType()) 
             return true;
 
         if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
@@ -134,6 +134,20 @@ class BxProfilerTemplate extends BxDolModuleTemplate
             return '';
         return parent::addJs($mixedFiles, $bDynamic);
     }
+
+    function getHeaderContentType()
+    {
+        $aHeaders = headers_list();
+        foreach ($aHeaders as $s) {
+            $a = explode(':', $s);
+            if (isset($a[0]) && isset($a[1]) && 'content-type' == strtolower(trim($a[0]))) {
+                $aa = explode(';', $a[1]);
+                return strtolower(trim($aa[0]));
+            }
+        }
+
+        return false;
+    }
 }
 
 /** @} */