[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] setup/inc functions.inc.php
From: |
Dave Hall |
Subject: |
[Phpgroupware-cvs] setup/inc functions.inc.php |
Date: |
Sun, 24 Sep 2006 12:13:10 +0000 |
CVSROOT: /cvsroot/phpgroupware
Module name: setup
Changes by: Dave Hall <skwashd> 06/09/24 12:13:10
Modified files:
inc : functions.inc.php
Log message:
sync functionality with api version
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/setup/inc/functions.inc.php?cvsroot=phpgroupware&r1=1.52&r2=1.53
Patches:
Index: functions.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/setup/inc/functions.inc.php,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- functions.inc.php 5 May 2006 08:29:06 -0000 1.52
+++ functions.inc.php 24 Sep 2006 12:13:10 -0000 1.53
@@ -15,7 +15,7 @@
* option) any later version. *
\**************************************************************************/
- /* $Id: functions.inc.php,v 1.52 2006/05/05 08:29:06 sigurdne Exp $ */
+ /* $Id: functions.inc.php,v 1.53 2006/09/24 12:13:10 skwashd Exp $ */
// PHP5 compat fix
if (version_compare(phpversion(), '5.0') < 0)
@@ -39,11 +39,10 @@
require_once('../header.inc.php');
}
- if ( !function_exists('sha1') ) //sha1() is only available in PHP4.3+
see http://www.php.net/ChangeLog-4.php#4.3.0
+ if (!function_exists('html_entity_decode'))//html_entity_decode() is
only available in PHP4.3+
{
- echo 'phpGroupWare now requires PHP 4.3 or greater.<br />';
- echo 'Please contact your System Administrator';
- exit;
+ die('<h1>You appear to be using PHP ' . PHP_VERSION . "
phpGroupWare requires 4.3.0 or later <br>\n"
+ . 'Please contact your System Administrator</h1>');
}
/* If we included the header.inc.php, but it is somehow broken, cover
ourselves... */
@@ -95,9 +94,183 @@
{
$vars = array($m1,$m2,$m3,$m4,$m5,$m6,$m7,$m8,$m9,$m10);
}
- $value =
$GLOBALS['phpgw_setup']->translation->translate("$key", $vars );
- return $value;
+
+ if ( !isset($GLOBALS['phpgw']->translation) ||
!is_object($GLOBALS['phpgw']->translation) )
+ {
+ return sprintf( preg_replace('/(%\d)+/', '%s', $key),
$m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8, $m9, $m10) . ' *#*';
+ }
+ return $GLOBALS['phpgw']->translation->translate("$key", $vars);
+ }
+
+ /**
+ * cleans up a backtrace array and converts it to a string
+ *
+ * @internal this is such an ugly piece of code due to a reference to
the error context
+ * being in the backtrace and the error context can not be edited - see
php.net/set_error_handler
+ * @param array $bt php backtrace
+ * @return string the formatted backtrace, empty if the user is not an
admin
+ */
+ function phpgw_parse_backtrace($bt)
+ {
+ if ( !is_array($bt) )
+ {
+ return '';
+ }
+
+ $trace = array();
+ $trace[0] = array();
+
+ if ( isset($bt[0]['function']) )
+ {
+ $trace[0]['function'] = $bt[0]['function'];
+ }
+
+ if ( isset($bt[0]['args']) && is_array($bt[0]['args']) &&
count($bt[0]['args']) )
+ {
+ $trace[0]['args'] = array($bt[0]['args'][0],
$bt[0]['args'][1], $bt[0]['args'][2], $bt[0]['args'][3],
'***error_handler_content_data***');
+ }
+
+ if ( isset($bt[0]['file']) )
+ {
+ $trace[0]['file'] = $bt[0]['file'];
+ }
+
+ if ( isset($bt[0]['line']) )
+ {
+ $trace[0]['line'] = $bt[0]['line'];
+ }
+ unset($bt[0]);
+
+ foreach ( $bt as $num => $entry )
+ {
+ if ( isset($entry['file']) )
+ {
+ $trace[$num]['file'] = '/path/to/phpgroupware'
. substr($entry['file'], strlen(PHPGW_SERVER_ROOT) );
+ }
+
+ if ( isset($entry['line']) )
+ {
+ $trace[$num]['line'] = $entry['line'];
+ }
+
+ if ( isset($entry['line']) )
+ {
+ $trace[$num]['line'] = $entry['line'];
+ }
+
+ if ( isset($entry['type']) && isset($entry['class']) )
+ {
+ $trace[$num]['function'] =
"{$entry['class']}{$entry['type']}{$entry['function']}";
+ }
+ else
+ {
+ $trace[$num]['function'] = $entry['function'];
+ }
+
+ if ( isset($entry['args']) && is_array($entry['args'])
&& count($entry['args']) )
+ {
+ foreach ( $entry['args'] as $anum => $arg )
+ {
+ if ( is_array($arg) )
+ {
+ $trace[$num]['args'][$anum] =
print_r($arg, true);
+ continue;
+ }
+
+ // Drop passwords from backtrace
+ if ( (
isset($GLOBALS['phpgw_info']['server']['header_admin_password']) && $arg ==
$GLOBALS['phpgw_info']['server']['header_admin_password'] )
+ || ( isset(
$GLOBALS['phpgw_info']['server']['db_pass']) && $arg ==
$GLOBALS['phpgw_info']['server']['db_pass'] )
+ || (
isset($GLOBALS['phpgw_info']['user']['passwd']) && $arg ==
$GLOBALS['phpgw_info']['user']['passwd'] )
+ )
+ {
+ $trace[$num]['args'][$anum] =
'***PASSWORD***';
+ }
+ else
+ {
+ $trace[$num]['args'][$anum] =
$arg;
+ }
+ }
+ }
+ else
+ {
+ $trace[$num]['args'] = 'NONE';
+ }
+ }
+ return print_r($trace, true);
+ }
+
+ /**
+ * phpGroupWare Information level "error"
+ */
+ define('PHPGW_E_INFO', -512);
+
+ /**
+ * phpGroupWare debug level "error"
+ */
+ define('PHPGW_E_DEBUG', -1024);
+
+ /**
+ * phpGroupWare generic error handler
+ *
+ * @link http://php.net/set_error_handler
+ *
+ */
+ function phpgw_handle_error($error_level, $error_msg, $error_file,
$error_line, $error_context = array())
+ {
+ if ( error_reporting() == 0 ) // 0 == @function() so we ignore
it, as the dev requested
+ {
+ return true;
+ }
+
+ if ( !isset($GLOBALS['phpgw']->log)
+ || !is_object($GLOBALS['phpgw']->log) )
+ {
+ $GLOBALS['phpgw']->log = createObject('phpgwapi.log');
+ }
+
+ $log =& $GLOBALS['phpgw']->log;
+
+ $error_file = '/path/to/phpgroupware' . substr($error_file,
strlen(PHPGW_SERVER_ROOT) );
+
+ $bt = debug_backtrace();
+
+ $log_args = array
+ (
+ 'file' => $error_file,
+ 'line' => $error_line,
+ 'text' => "$error_msg\n" . phpgw_parse_backtrace($bt)
+ );
+
+ switch ( $error_level )
+ {
+ case E_USER_ERROR:
+ case E_ERROR:
+ $log_args['severity'] = 'F'; //all "ERRORS"
should be fatal
+ $log->fatal($log_args);
+ break;
+ case E_WARNING:
+ case E_USER_WARNING:
+ $log_args['severity'] = 'W';
+ $log->warn($log_args);
+ echo "\n<br>" . lang('ERROR Warning: %1 in %2
at line %3', $error_msg, $error_file, $error_line) . "<br>\n";
+ break;
+ case PHPGW_E_INFO:
+ $log_args['severity'] = 'I';
+ $log->info($log_args);
+ break;
+ case PHPGW_E_DEBUG:
+ $log_args['severity'] = 'D';
+ $log->info($log_args);
+ break;
+ case E_NOTICE:
+ case E_USER_NOTICE:
+ $log_args['severity'] = 'N';
+ $log->notice($log_args);
+ echo "\n<br>" . lang('ERROR Notice: %1 in %2 at
line %3', $error_msg, $error_file, $error_line) . "<br>\n"; //this will be
commented in the final version
+ //No default, we just ignore it, for now
+ }
}
+ set_error_handler('phpgw_handle_error');
/**
* Get a list of supported languages
- [Phpgroupware-cvs] setup/inc functions.inc.php,
Dave Hall <=