aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/common.inc.php10
-rw-r--r--include/functions.inc.php30
-rw-r--r--include/functions_calendar.inc.php7
-rw-r--r--include/functions_html.inc.php38
-rw-r--r--include/functions_url.inc.php22
-rw-r--r--include/template.class.php2
6 files changed, 59 insertions, 50 deletions
diff --git a/include/common.inc.php b/include/common.inc.php
index a762eeade..1ddebfc9b 100644
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -21,10 +21,8 @@
// | USA. |
// +-----------------------------------------------------------------------+
-if (!defined('PHPWG_ROOT_PATH'))
-{
- die('Hacking attempt!');
-}
+defined('PHPWG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
+
// determine the initial instant to indicate the generation time of this page
$t1 = explode( ' ', microtime() );
$t2 = explode( '.', $t1[0] );
@@ -146,7 +144,7 @@ include(PHPWG_ROOT_PATH . 'include/template.class.php');
@mysql_select_db( $cfgBase ) or my_error( 'mysql_select_db', true );
defined('PWG_CHARSET') and defined('DB_CHARSET')
- or die('PWG_CHARSET and/or DB_CHARSET is not defined');
+ or fatal_error('PWG_CHARSET and/or DB_CHARSET is not defined');
if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
{
if (DB_CHARSET!='')
@@ -158,7 +156,7 @@ else
{
if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
{
- die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
+ fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
}
}
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 2acf287e9..6acfa0637 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -232,7 +232,7 @@ function mkgetdir($dir, $flags=MKGETDIR_DEFAULT)
umask($umask);
if ($mkd==false)
{
- !($flags&MKGETDIR_DIE_ON_ERROR) or trigger_error( "$dir ".l10n('no_write_access'), E_USER_ERROR);
+ !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
return false;
}
if( $flags&MKGETDIR_PROTECT_HTACCESS )
@@ -250,7 +250,7 @@ function mkgetdir($dir, $flags=MKGETDIR_DEFAULT)
{
if ( !is_writable($dir) )
{
- !($flags&MKGETDIR_DIE_ON_ERROR) or trigger_error( "$dir ".l10n('no_write_access'), E_USER_ERROR);
+ !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
return false;
}
}
@@ -945,29 +945,17 @@ function get_thumbnail_title($element_info)
// my_error returns (or send to standard output) the message concerning the
// error occured for the last mysql query.
-
function my_error($header, $die)
{
- $error = $header;
- $error.= "\n[mysql error ".mysql_errno().'] '.mysql_error()."\n";
-
- if (function_exists('debug_backtrace'))
- {
- $bt = debug_backtrace();
- for ($i=0; $i<count($bt); $i++)
- {
- $error .= "#$i\t".@$bt[$i]['function']." ".@$bt[$i]['file']."(".@@$bt[$i]['line'].")\n";
- }
- }
+ $error = "[mysql error ".mysql_errno().'] '.mysql_error()."\n";
+ $error .= $header;
if ($die)
{
- @set_status_header(500);
- echo( str_repeat( ' ', 300)."\n"); //IE doesn't error output if below a size
+ fatal_error($error);
}
echo("<pre>");
- trigger_error($error, $die ? E_USER_ERROR : E_USER_WARNING);
- !$die || die($error); // just in case the handler didnt die
+ trigger_error($error, E_USER_WARNING);
echo("</pre>");
}
@@ -1137,7 +1125,7 @@ function l10n_args($key_args, $sep = "\n")
}
else
{
- die('l10n_args: Invalid arguments');
+ fatal_error('l10n_args: Invalid arguments');
}
return $result;
@@ -1221,7 +1209,7 @@ SELECT param, value
if ((mysql_num_rows($result) == 0) and !empty($condition))
{
- die('No configuration data');
+ fatal_error('No configuration data');
}
while ($row = mysql_fetch_array($result))
@@ -1371,7 +1359,7 @@ function get_filter_page_value($value_name)
*/
function get_pwg_charset()
{
- defined('PWG_CHARSET') or die('load_language PWG_CHARSET undefined');
+ defined('PWG_CHARSET') or fatal_error('load_language PWG_CHARSET undefined');
return PWG_CHARSET;
}
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index baa72b927..1071b4d8e 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -115,10 +115,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
// Retrieve calendar field
- if ( !isset( $fields[ $page['chronology_field'] ] ) )
- {
- die('bad chronology field');
- }
+ isset( $fields[ $page['chronology_field'] ] ) or fatal_error('bad chronology field');
// Retrieve style
if ( !isset( $styles[ $page['chronology_style'] ] ) )
@@ -198,7 +195,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$page['items'] = array();
$must_show_list = false;
}
-
+
$page['comment'] = '';
$template->assign('FILE_CHRONOLOGY_VIEW', 'month_calendar.tpl');
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index ff03675b1..ca07a1e16 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -650,6 +650,44 @@ function page_not_found($msg, $alternate_url=null)
5 );
}
+/**
+ * exits the current script with 500 http code
+ * this method can be called at any time (does not use template/language/user etc...)
+ * @param string msg a message to display
+ */
+function fatal_error($msg)
+{
+ $btrace_msg = '';
+ if (function_exists('debug_backtrace'))
+ {
+ $bt = debug_backtrace();
+ for ($i=1; $i<count($bt); $i++)
+ {
+ $class = isset($bt[$i]['class']) ? (@$bt[$i]['class'].'::') : '';
+ $btrace_msg .= "#$i\t".$class.@$bt[$i]['function'].' '.@$bt[$i]['file']."(".@$bt[$i]['line'].")\n";
+ }
+ $btrace_msg = trim($btrace_msg);
+ $msg .= "\n";
+ }
+
+ $display = "<h1>Piwigo encountered a non recoverable error</h1>
+<pre style='font-size:larger;background:white;color:red;padding:1em;margin:0;clear:both;display:block;width:auto;height:auto;overflow:auto'>
+<b>$msg</b>
+$btrace_msg
+</pre>\n";
+
+ @set_status_header(500);
+ echo $display.str_repeat( ' ', 300); //IE doesn't error output if below a size
+
+ if ( function_exists('ini_set') )
+ {// if possible turn off error display (we display it)
+ ini_set('display_errors', false);
+ }
+ error_reporting( E_ALL );
+ trigger_error( strip_tags($msg).$btrace_msg, E_USER_ERROR );
+ die(0); // just in case
+}
+
/* returns the title to be displayed above thumbnails on tag page
*/
function get_tags_content_title()
diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php
index fa7114dea..9921237a6 100644
--- a/include/functions_url.inc.php
+++ b/include/functions_url.inc.php
@@ -219,10 +219,8 @@ function duplicate_picture_url($redefined = array(), $removed = array())
function make_picture_url($params)
{
global $conf;
- if (!isset($params['image_id']))
- {
- die('make_picture_url: image_id is a required parameter');
- }
+
+ isset($params['image_id']) or fatal_error('make_picture_url: image_id is a required parameter');
$url = get_root_url().'picture';
if ($conf['php_extension_in_urls'])
@@ -375,7 +373,7 @@ function make_section_in_url($params)
{
if (!isset($params['tags']) or count($params['tags']) == 0)
{
- die('make_section_in_url: require at least one tag');
+ fatal_error('make_section_in_url: require at least one tag');
}
$section_string.= '/tags';
@@ -406,24 +404,14 @@ function make_section_in_url($params)
}
case 'search' :
{
- if (!isset($params['search']))
- {
- die('make_section_in_url: require a search identifier');
- }
-
+ isset($params['search']) or fatal_error('make_section_in_url: require a search identifier');
$section_string.= '/search/'.$params['search'];
-
break;
}
case 'list' :
{
- if (!isset($params['list']))
- {
- die('make_section_in_url: require a list of items');
- }
-
+ isset($params['list']) or fatal_error('make_section_in_url: require a list of items');
$section_string.= '/list/'.implode(',', $params['list']);
-
break;
}
case 'none' :
diff --git a/include/template.class.php b/include/template.class.php
index dfe1562a3..7b4e4caf1 100644
--- a/include/template.class.php
+++ b/include/template.class.php
@@ -224,7 +224,7 @@ class Template {
{
if ( !isset($this->files[$handle]) )
{
- trigger_error("Template->parse(): Couldn't load template file for handle $handle", E_USER_ERROR);
+ fatal_error("Template->parse(): Couldn't load template file for handle $handle");
}
$this->smarty->assign( 'ROOT_URL', get_root_url() );