Explorar el Código

#44 - profiler module

Alex Trofimov hace 12 años
padre
commit
2612841cf8

+ 1 - 1
inc/classes/BxDolTemplate.php

@@ -1284,7 +1284,7 @@ class BxDolTemplate extends BxDol implements iBxDolSingleton {
     	if(is_array($mixed) && isset($mixed['url']) && isset($mixed['path'])) {
     		$sPathFile = realpath($mixed['path']);
     		$aInfoFile = pathinfo($sPathFile);
-    		if($aInfoFile['extension'] != 'less')
+    		if (!isset($aInfoFile['extension']) || $aInfoFile['extension'] != 'less')
     			return $mixed;
 
 			$sPathRoot = realpath(BX_DIRECTORY_PATH_ROOT);

+ 0 - 4
inc/params.inc.php

@@ -6,7 +6,3 @@
  */
 defined('BX_DOL') or die('hack attempt');
 
-if (defined('BX_PROFILER') && BX_PROFILER) 
-    require_once(BX_DIRECTORY_PATH_MODULES . 'boonex/profiler/classes/BxProfiler.php');
-
-

+ 56 - 48
modules/boonex/profiler/classes/BxProfiler.php

@@ -1,28 +1,23 @@
-<?
-/***************************************************************************
-*                            Dolphin Smart Community Builder
-*                              -------------------
-*     begin                : Mon Mar 23 2006
-*     copyright            : (C) 2007 BoonEx Group
-*     website              : http://www.boonex.com
-* This file is part of Dolphin - Smart Community Builder
-*
-* Dolphin is free software; you can redistribute it and/or modify it under
-* the terms of the GNU General Public License as published by the
-* Free Software Foundation; either version 2 of the
-* License, or  any later version.
-*
-* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-* See the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License along with Dolphin,
-* see license.txt file; if not, write to marketing@boonex.com
-***************************************************************************/
-
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Profiler Profiler
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+define ('BX_PROFILER', true);
 define ('BX_PROFILER_DISPLAY', 1);
 
-require_once(BX_DIRECTORY_PATH_MODULES . 'boonex/profiler/install/config.php');
 
+require_once(BX_DIRECTORY_PATH_PLUGINS . 'php-error/php_error.php');
+\php_error\reportErrors();
+
+
+require_once(BX_DIRECTORY_PATH_MODULES . 'boonex/profiler/install/config.php');
 $GLOBALS['bx_profiler_module'] = array (
     'title' => $aConfig['title'],
     'vendor' => $aConfig['vendor'],
@@ -32,9 +27,11 @@ $GLOBALS['bx_profiler_module'] = array (
     'db_prefix' => $aConfig['db_prefix'],
 );
 
+bx_import('BxDolStudioTemplate');
 bx_import('Template', $GLOBALS['bx_profiler_module']);
 bx_import('Config', $GLOBALS['bx_profiler_module']);
 
+
 class BxProfiler {
 
     var $oConfig, $oTemplate;
@@ -57,16 +54,14 @@ class BxProfiler {
     var $_sLogMaxArgLength = 64;
     var $_sLogFilename = 64;
 
-    /**
-     * constructor
-     */
     function BxProfiler($iTimeStart) {
 
         $this->oConfig = new BxProfilerConfig ($GLOBALS['bx_profiler_module']);
         $this->oTemplate = new BxProfilerTemplate ($this->oConfig);
+        $this->oTemplateAdmin = BxDolStudioTemplate::getInstance();
 
         $aCss = array (
-            BX_DOL_URL_MODULES.'boonex/profiler/templates/base/css/profiler.css',
+            BX_DOL_URL_MODULES.'boonex/profiler/template/css/profiler.css',
             BX_DOL_URL_PLUGINS.'jush/jush.css',
         );
         $aJs = array (
@@ -76,12 +71,12 @@ class BxProfiler {
         );
 
         foreach ($aCss as $sCssUrl) {
-            $this->oTemplate->addCss ($sCssUrl);
-            $this->oTemplate->addCssAdmin ($sCssUrl);
+            $this->oTemplate->addCss($sCssUrl);
+            $this->oTemplateAdmin->addCss($sCssUrl);
         }
         foreach ($aJs as $sJsUrl) {
             $this->oTemplate->addJs($sJsUrl);
-            $this->oTemplate->addJsAdmin($sJsUrl);
+            $this->oTemplateAdmin->addJs($sJsUrl);
         }
 
         if (getParam ('bx_profiler_long_sql_queries_log'))
@@ -94,9 +89,7 @@ class BxProfiler {
         $this->_iTimeStart = $iTimeStart;
     }
 
-    /**
-     * output profiler info
-     */
+    // output profiler debug panel
     function output () {
 
         $iPageTIme = $this->_getCurrentDelay ();
@@ -114,13 +107,17 @@ class BxProfiler {
         default:
             return;
         }
-        echo $this->_plankMain ();
-        echo $this->_plankMenus ();
-        echo $this->_plankTemplates ();
-        echo $this->_plankInjections ();
-        echo $this->_plankPagesBlocks ();
-        echo $this->_plankSql ();
-        echo $this->_plankModules ();
+
+        $sContentType = $this->_getHeaderContentType();
+        if ('text/html' == $sContentType) {
+            echo $this->_plankMain ();
+            echo $this->_plankMenus ();
+            echo $this->_plankTemplates ();
+            echo $this->_plankInjections ();
+            echo $this->_plankPagesBlocks ();
+            echo $this->_plankSql ();
+            echo $this->_plankModules ();
+        }
     }
 
     function _logBegin ($s) {
@@ -135,7 +132,7 @@ class BxProfiler {
     }
 
     function _appendToLog ($s) {
-        $f = fopen ( BX_DIRECTORY_PATH_MODULES . $GLOBALS['bx_profiler_module']['path'] . 'log/profiler.log', 'a');
+        $f = fopen ( BX_DIRECTORY_PATH_ROOT . 'logs/bx_profiler.log', 'a');
         if (!$f)
             return;
         fwrite($f, $s);
@@ -182,7 +179,7 @@ class BxProfiler {
         ++$this->_aModulesLevel;
         $this->_aModulesNames[$aModule['title']] = isset($this->_aModulesNames[$aModule['title']]) ? $this->_aModulesNames[$aModule['title']] + 1 : 1;
         $this->_aModules[$sHash] = array (
-            'name' => str_repeat('&#160;&#160;', $this->_aModulesLevel-1) . $aModule['title'],
+            'name' => str_repeat("--", $this->_aModulesLevel-1) . $aModule['title'],
             'type' => $sType,
             'class/file' => $sClassFile,
             'method' => $sMethod,
@@ -242,7 +239,7 @@ class BxProfiler {
     }
 
     function endPage (&$sContent) {
-        if (!$this->_sPageIndex)
+        if (!$this->_sPageIndex || !isset($this->_aPages[$this->_sPageIndex]['begin']))
             return;
         $iTime = $this->_calcTime ($this->_aPages[$this->_sPageIndex]['begin']);
         unset ($this->_aPages[$this->_sPageIndex]['begin']);
@@ -597,12 +594,23 @@ class BxProfiler {
         }
         return $s;
     }
-}
 
-if (BX_PROFILER) {
-    $GLOBALS['bx_profiler'] = new BxProfiler($GLOBALS['bx_profiler_start']);
-    if (!$GLOBALS['bx_profiler']->_isProfilerDisabled())
-        register_shutdown_function (array ($GLOBALS['bx_profiler'], 'output'));
+    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);
+if (!$GLOBALS['bx_profiler']->_isProfilerDisabled())
+    register_shutdown_function (array ($GLOBALS['bx_profiler'], 'output'));
+
+/** @} */

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

@@ -0,0 +1,30 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Profiler Profiler
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+/**
+ * alerts handler
+ */
+class BxProfilerAlertsResponse extends BxDolAlertsResponse 
+{
+    public function __construct() 
+    {
+        parent::__construct();
+    }
+    
+    public function response($oAlert) 
+    {
+        if ('system' == $oAlert->sUnit && 'begin' == $oAlert->sAction) {
+            require_once(BX_DIRECTORY_PATH_MODULES . 'boonex/profiler/classes/BxProfiler.php');
+        }
+    }
+}
+
+/** @} */

+ 11 - 21
modules/boonex/profiler/classes/BxProfilerConfig.php

@@ -1,23 +1,13 @@
-<?
-/***************************************************************************
-*                            Dolphin Smart Community Builder
-*                              -------------------
-*     begin                : Mon Mar 23 2006
-*     copyright            : (C) 2007 BoonEx Group
-*     website              : http://www.boonex.com
-* This file is part of Dolphin - Smart Community Builder
-*
-* Dolphin is free software; you can redistribute it and/or modify it under
-* the terms of the GNU General Public License as published by the
-* Free Software Foundation; either version 2 of the
-* License, or  any later version.
-*
-* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-* See the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License along with Dolphin,
-* see license.txt file; if not, write to marketing@boonex.com
-***************************************************************************/
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Profiler Profiler
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
 
 bx_import('BxDolModuleConfig');
 
@@ -30,4 +20,4 @@ class BxProfilerConfig extends BxDolModuleConfig {
     }
 }
 
-?>
+/** @} */

+ 11 - 21
modules/boonex/profiler/classes/BxProfilerDb.php

@@ -1,23 +1,13 @@
-<?
-/***************************************************************************
-*                            Dolphin Smart Community Builder
-*                              -------------------
-*     begin                : Mon Mar 23 2006
-*     copyright            : (C) 2007 BoonEx Group
-*     website              : http://www.boonex.com
-* This file is part of Dolphin - Smart Community Builder
-*
-* Dolphin is free software; you can redistribute it and/or modify it under
-* the terms of the GNU General Public License as published by the
-* Free Software Foundation; either version 2 of the
-* License, or  any later version.
-*
-* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-* See the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License along with Dolphin,
-* see license.txt file; if not, write to marketing@boonex.com
-***************************************************************************/
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Profiler Profiler
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
 
 bx_import('BxDolModuleDb');
 
@@ -37,4 +27,4 @@ class BxProfilerDb extends BxDolModuleDb {
     }
 }
 
-?>
+/** @} */

+ 11 - 68
modules/boonex/profiler/classes/BxProfilerModule.php

@@ -1,23 +1,13 @@
-<?php
-/***************************************************************************
-*                            Dolphin Smart Community Builder
-*                              -------------------
-*     begin                : Mon Mar 23 2006
-*     copyright            : (C) 2007 BoonEx Group
-*     website              : http://www.boonex.com
-* This file is part of Dolphin - Smart Community Builder
-*
-* Dolphin is free software; you can redistribute it and/or modify it under
-* the terms of the GNU General Public License as published by the
-* Free Software Foundation; either version 2 of the
-* License, or  any later version.
-*
-* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-* See the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License along with Dolphin,
-* see license.txt file; if not, write to marketing@boonex.com
-***************************************************************************/
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Profiler Profiler
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
 
 bx_import('BxDolModule');
 
@@ -26,13 +16,6 @@ bx_import('BxDolModule');
  *
  * This module estimate timining, like page openings, mysql queries execution and service calls.
  * Also it can log too long queries, so you can later investigate these bottle necks and speedup whole script.
- *
- * To enable profiler you need install it and add the following lines to the beginning of inc/header.inc.php file
- *
- * define ('BX_PROFILER', true);
- * if (BX_PROFILER && !isset($GLOBALS['bx_profiler_start']))
- *     $GLOBALS['bx_profiler_start'] = microtime ();
- *
  */
 class BxProfilerModule extends BxDolModule {
 
@@ -47,49 +30,9 @@ class BxProfilerModule extends BxDolModule {
         $this->_oTemplate->pageCode($this->_aModule['title']);
     }
 
-    function actionAdministration () {
-
-        if (!$this->isAdmin()) {
-            $this->_oTemplate->displayAccessDenied ();
-            return;
-        }
-
-        $this->_oTemplate->pageStart();
-
-        $iId = $this->_oDb->getSettingsCategory();
-        if(empty($iId)) {
-            echo MsgBox(_t('_sys_request_page_not_found_cpt'));
-            $this->_oTemplate->pageCodeAdmin (_t('_bx_profiler_administration'));
-            return;
-        }
-
-        bx_import('BxDolAdminSettings');
-
-        $mixedResult = '';
-        if(isset($_POST['save']) && isset($_POST['cat'])) {
-            $oSettings = new BxDolAdminSettings($iId);
-            $mixedResult = $oSettings->saveChanges($_POST);
-        }
-
-        $oSettings = new BxDolAdminSettings($iId);
-        $sResult = $oSettings->getForm();
-
-        if($mixedResult !== true && !empty($mixedResult))
-            $sResult = $mixedResult . $sResult;
-
-        $aVars = array (
-            'content' => $sResult,
-        );
-        echo $this->_oTemplate->adminBlock ($this->_oTemplate->parseHtmlByName('default_padding', $aVars), _t('_bx_profiler_administration'));
-
-        $this->_oTemplate->addCssAdmin ('main.css');
-        $this->_oTemplate->addCssAdmin ('forms_adv.css');
-        $this->_oTemplate->pageCodeAdmin (_t('_bx_profiler_administration'));
-    }
-
     function isAdmin () {
         return $GLOBALS['logged']['admin'];
     }
 }
 
-?>
+/** @} */

+ 11 - 21
modules/boonex/profiler/classes/BxProfilerTemplate.php

@@ -1,23 +1,13 @@
-<?
-/***************************************************************************
-*                            Dolphin Smart Community Builder
-*                              -------------------
-*     begin                : Mon Mar 23 2006
-*     copyright            : (C) 2007 BoonEx Group
-*     website              : http://www.boonex.com
-* This file is part of Dolphin - Smart Community Builder
-*
-* Dolphin is free software; you can redistribute it and/or modify it under
-* the terms of the GNU General Public License as published by the
-* Free Software Foundation; either version 2 of the
-* License, or  any later version.
-*
-* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-* See the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License along with Dolphin,
-* see license.txt file; if not, write to marketing@boonex.com
-***************************************************************************/
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Profiler Profiler
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
 
 bx_import('BxDolModuleTemplate');
 
@@ -118,4 +108,4 @@ class BxProfilerTemplate extends BxDolModuleTemplate {
 
 }
 
-?>
+/** @} */

+ 5 - 10
modules/boonex/profiler/install/config.php

@@ -39,7 +39,7 @@ $aConfig = array(
      */
     'install' => array(
         'show_introduction' => 0,
-        'change_permissions' => 1,
+        'change_permissions' => 0,
         'execute_sql' => 1,
         'update_languages' => 1,
         'recompile_main_menu' => 0,
@@ -57,11 +57,11 @@ $aConfig = array(
         'recompile_permalinks' => 0,
         'recompile_alerts' => 0,
         'clear_db_cache' => 0,
-        'show_conclusion' => 1,
+        'show_conclusion' => 0,
     ),
     'uninstall' => array (
         'show_introduction' => 0,
-        'change_permissions' => 1,
+        'change_permissions' => 0,
         'execute_sql' => 1,
         'update_languages' => 1,
         'recompile_main_menu' => 0,
@@ -79,7 +79,7 @@ $aConfig = array(
         'recompile_permalinks' => 0,
         'recompile_alerts' => 0,
         'clear_db_cache' => 0,
-        'show_conclusion' => 1,
+        'show_conclusion' => 0,
     ),
     'enable' => array(
         'execute_sql' => 1,
@@ -132,11 +132,7 @@ $aConfig = array(
     /**
      * Permissions Section
      */
-    'install_permissions' => array(
-        'writable' => array(
-            'log/'
-        ),
-    ),
+    'install_permissions' => array(),
     'uninstall_permissions' => array(),
 
     /**
@@ -153,4 +149,3 @@ $aConfig = array(
 );
 
 /** @} */
-

+ 0 - 6
modules/boonex/profiler/install/info/inst_concl.html

@@ -1,6 +0,0 @@
-To complete installation add the following lines to the beginning of inc/header.inc.php file:
-
-define ('BX_PROFILER', true);
-if (BX_PROFILER && !isset($GLOBALS['bx_profiler_start']))
-    $GLOBALS['bx_profiler_start'] = microtime ();
-

+ 0 - 5
modules/boonex/profiler/install/info/uninst_concl.html

@@ -1,5 +0,0 @@
-To complete un-installation remove the following lines from the beginning of inc/header.inc.php file:
-
-define ('BX_PROFILER', true);
-if (BX_PROFILER && !isset($GLOBALS['bx_profiler_start']))
-    $GLOBALS['bx_profiler_start'] = microtime ();

+ 0 - 1
modules/boonex/profiler/install/installer.php

@@ -35,4 +35,3 @@ class BxProfilerInstaller extends BxDolStudioInstaller {
 }
 
 /** @} */
-

+ 6 - 1
modules/boonex/profiler/install/sql/disable.sql

@@ -1,2 +1,7 @@
 -- settings
-DELETE FROM `top`, `toc`, `to` USING `sys_options_types` AS `top` LEFT JOIN `sys_options_categories` AS `toc` ON `top`.`id`=`toc`.`type_id` LEFT JOIN `sys_options` AS `to` ON `toc`.`id`=`to`.`category_id` WHERE `top`.`name`='bx_profiler';
+DELETE FROM `top`, `toc`, `to` USING `sys_options_types` AS `top` LEFT JOIN `sys_options_categories` AS `toc` ON `top`.`id`=`toc`.`type_id` LEFT JOIN `sys_options` AS `to` ON `toc`.`id`=`to`.`category_id` WHERE `top`.`name`='bx_profiler';
+
+-- ALERTS
+SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = 'bx_profiler' LIMIT 1);
+DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
+DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;

+ 11 - 1
modules/boonex/profiler/install/sql/enable.sql

@@ -36,4 +36,14 @@ SET @iCategoryId = LAST_INSERT_ID();
 INSERT INTO `sys_options` (`category_id`, `name`, `value`, `caption`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 (@iCategoryId, 'bx_profiler_long_page_log', 'on', 'Log long page opens', 'checkbox', '', '', '', 1),
 (@iCategoryId, 'bx_profiler_long_page_time', '5', 'Time in seconds of long page open', 'digit', '', '', '', 2),
-(@iCategoryId, 'bx_profiler_long_page_debug', '', 'Log additionad debug info with each long page open', 'checkbox', '', '', '', 3);
+(@iCategoryId, 'bx_profiler_long_page_debug', '', 'Log additionad debug info with each long page open', 'checkbox', '', '', '', 3);
+
+-- ALERTS
+
+INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `eval`) VALUES 
+('bx_profiler', 'BxProfilerAlertsResponse', 'modules/boonex/profiler/classes/BxProfilerAlertsResponse.php', '');
+SET @iHandler := LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('system', 'begin', @iHandler);
+

+ 1 - 0
plugins/php-error/.htaccess

@@ -0,0 +1 @@
+Deny from all

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 4363 - 0
plugins/php-error/php_error.php


+ 2 - 2
storage.php

@@ -5,7 +5,7 @@
  * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
  */
 
-ob_start();
+//ob_start();
 
 require_once('./inc/header.inc.php');
 
@@ -30,7 +30,7 @@ if (!$sRemoteId) {
     exit;
 }
 
-ob_end_clean();
+//ob_end_clean();
 
 if (!$oStorage->download($sRemoteId, $sToken)) {
     $iError = $oStorage->getErrorCode();

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio