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

Merge branch 'master' of https://github.com/unaio/una

AntonLV 3 лет назад
Родитель
Сommit
85ddbb690f

+ 1 - 1
inc/utils.inc.php

@@ -625,7 +625,7 @@ function dbgTiming($sStartMicrotime)
 
 function echoJson($a)
 {
-	header('Content-type: text/html; charset=utf-8');
+	header('Content-Type: application/json; charset=utf-8');
 
 	echo json_encode($a);
 }

+ 23 - 38
modules/boonex/profiler/classes/BxProfiler.php

@@ -73,15 +73,15 @@ class BxProfiler extends BxDol
     // output profiler debug panel
     function output ()
     {
-        $iPageTIme = $this->_getCurrentDelay ();
-        if (isset($this->aConf['long_page']) && $iPageTIme > $this->aConf['long_page'])
-            $this->logPageOpen ($iPageTIme);
+        $iPageTime = $this->_getCurrentDelay ();
+        if (isset($this->aConf['long_page']) && $iPageTime > $this->aConf['long_page'])
+            $this->logPageOpen ($iPageTime);
 
         switch (getParam('bx_profiler_show_debug_panel')) {
         case 'all':
             break;
         case 'admins':
-            if (!$GLOBALS['logged']['admin'])
+            if (!isset($GLOBALS['logged']) || !$GLOBALS['logged']['admin'])
                 return;
             break;
         case 'none':
@@ -105,17 +105,23 @@ class BxProfiler extends BxDol
         foreach ($aJs as $sJsPath)
             $sJsCss .= $this->oTemplate->addJs($sJsPath, 1);
 
-        $sContentType = $this->_getHeaderContentType();
-        if ('text/html' == $sContentType) {
-            echo $sJsCss;
-            echo $this->_plankMain ();
-            echo $this->_plankMenus ();
-            echo $this->_plankTemplates ();
-            echo $this->_plankInjections ();
-            echo $this->_plankPagesBlocks ();
-            echo $this->_plankSql ();
-            echo $this->_plankModules ();
-            echo $this->_plankAlerts ();
+        $sPlanks  = $this->_plankMain ();
+        $sPlanks .= $this->_plankMenus ();
+        $sPlanks .= $this->_plankTemplates ();
+        $sPlanks .= $this->_plankInjections ();
+        $sPlanks .= $this->_plankPagesBlocks ();
+        $sPlanks .= $this->_plankSql ();
+        $sPlanks .= $this->_plankModules ();
+        $sPlanks .= $this->_plankAlerts ();
+
+        echo ob_get_clean();
+
+        $sContentType = $this->oTemplate->getHeaderContentType();
+        if ('text/html' == $sContentType) {            
+            echo $sJsCss . $sPlanks;
+        } 
+        else if ('application/json' == $sContentType) {
+            echo $sPlanks;
         }
     }
 
@@ -566,7 +572,7 @@ class BxProfiler extends BxDol
         $sAlerts = count($GLOBALS['bx_profiler']->_aAlerts) . ' alerts responses (' . $this->_formatTime($iTimeAlerts, 3) . ')';
 
         return $this->oTemplate->plank(
-            $this->oTemplate->nameValue('Alerts:', $sAlerts) .
+            $this->oTemplate->nameValue('Alerts:', $sAlerts),
             $this->oTemplate->table($GLOBALS['bx_profiler']->_aAlerts)
         );
     }
@@ -590,14 +596,7 @@ class BxProfiler extends BxDol
     {
         if (isset($GLOBALS['bx_profiler_disable']) || isset($_GET['bx_profiler_disable']))
             return true;
-        if (
-            preg_match('/gzip_loader\.php/', $_SERVER['PHP_SELF']) ||
-            preg_match('/get_rss_feed\.php/', $_SERVER['PHP_SELF']) ||
-            preg_match('/fields\.parse\.php/', $_SERVER['PHP_SELF']) ||
-            preg_match('/flash/', $_SERVER['PHP_SELF']) ||
-            preg_match('/forum/', $_SERVER['PHP_SELF'])
-        )
-            return true;
+
         return false;
     }
 
@@ -662,20 +661,6 @@ class BxProfiler extends BxDol
         }
         return $s;
     }
-
-    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;
-    }
 }
 
 $GLOBALS['bx_profiler'] = new BxProfiler(BX_DOL_START);

+ 1 - 0
modules/boonex/profiler/classes/BxProfilerAlertsResponse.php

@@ -17,6 +17,7 @@ class BxProfilerAlertsResponse extends BxDolAlertsResponse
     public function response($oAlert)
     {
         if ('system' == $oAlert->sUnit && 'begin' == $oAlert->sAction) {
+            ob_start();
             require_once(BX_DIRECTORY_PATH_MODULES . 'boonex/profiler/classes/BxProfiler.php');
         }
     }

+ 47 - 2
modules/boonex/profiler/classes/BxProfilerTemplate.php

@@ -22,13 +22,23 @@ class BxProfilerTemplate extends BxDolModuleTemplate
 
     function plank($sTitle, $sContent = '')
     {
+        static $i = 0;
+        $i++;
         if ($this->_isAjaxOutput) {
-            if (function_exists('fb')) {
+            if (!headers_sent() && function_exists('fb')) {
                 if ($sContent && is_array($sContent))
                     fb($sContent, $sTitle, FirePHP::TABLE);
                 else
                     fb($sTitle . $sContent);
             }
+            elseif (!headers_sent()) {
+                if ($sContent && is_array($sContent)) {
+                    $sContentEnc = json_encode($sContent);
+                    header("X-Una-Profiler-$i: $sTitle" . ($sContent && $sContentEnc < 4000 ? '; ' . $sContentEnc : ''));
+                } else {
+                    header("X-Una-Profiler-$i: $sTitle" . ($sContent && $sContent < 4000 ? '; ' . $sContent : ''));
+                }
+            }
             return '';
         }
         if ($sContent)
@@ -84,10 +94,14 @@ class BxProfilerTemplate extends BxDolModuleTemplate
 
     function _isAjaxRequest ()
     {
+        if ('application/json' == $this->getHeaderContentType()) 
+            return true;
+
         if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
             return true;
         if (isset($_GET['bx_profiler_ajax_request']))
             return true;
+
         if (preg_match('/vote\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
             return true;
         if (preg_match('/image_transcoder\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
@@ -97,12 +111,43 @@ class BxProfilerTemplate extends BxDolModuleTemplate
         if (preg_match('/storage_uploader\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
             return true;
         if (preg_match('/searchKeywordContent\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
-            return true;
+            return true;        
         if (preg_match('/menu\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
             return true;
+        if (preg_match('/gzip_loader\.php/', $_SERVER['PHP_SELF']))
+            return true;
+        if (preg_match('/get_rss_feed\.php/', $_SERVER['PHP_SELF']))
+            return true;
         return false;
     }
 
+    function addCss($mixedFiles, $bDynamic = false)
+    {
+        if ($this->_isAjaxOutput)
+            return '';
+        return parent::addCss($mixedFiles, $bDynamic);
+    }
+
+    function addJs($mixedFiles, $bDynamic = false)
+    {
+        if ($this->_isAjaxOutput)
+            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;
+    }
 }
 
 /** @} */

+ 1 - 1
modules/boonex/tasks/classes/BxTasksModule.php

@@ -550,7 +550,7 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
 				}
 				$aTasksVars[] = array(
 					'id' => $aTask[$CNF['FIELD_ID']],
-					'title' => $aTask[$CNF['FIELD_TITLE']],
+					'title' => bx_process_output($aTask[$CNF['FIELD_TITLE']]),
 					'created' => bx_time_js($aTask[$CNF['FIELD_ADDED']]),
 					'class' => $aTask[$CNF['FIELD_COMPLETED']] == 1 ? 'completed' : 'uncompleted',
 					'due' => $aTask[$CNF['FIELD_DUEDATE']] > 0 ? bx_time_js($aTask[$CNF['FIELD_DUEDATE']]) : '',