_UI;
$tabs = $ui->_getTabs();
$tab = $ui->_getTab();
$lnEnd = $ui->_getLineEnd();
$way_natural = ($ui->getFillWay() == 'natural');
$cellAttr = $ui->getCellAttributes();
$cellCount = $ui->getCellCount();
$progressId = $this->getIdent().'_';
$progressHtml = "";
if ($way_natural) {
// inactive cells first
$pos = $cellAttr['spacing'];
for ($i=$cellCount-1; $i>=0; $i--) {
$progressHtml .= $tabs . $tab . $tab;
$progressHtml .= "
=0; $i--) {
$progressHtml .= $tabs . $tab . $tab;
$progressHtml .= "
_UI;
$tabs = $ui->_getTabs();
$tab = $ui->_getTab();
$lnEnd = $ui->_getLineEnd();
$way_natural = ($ui->getFillWay() == 'natural');
$cellAttr = $ui->getCellAttributes();
$cellCount = $ui->getCellCount();
$coord = $ui->_coordinates;
$progressId = $this->getIdent().'_';
$progressHtml = "";
if ($way_natural) {
// inactive cells first
for ($i=0; $i<$cellCount; $i++) {
$top = $coord[$i][0] * $cellAttr['width'];
$left = $coord[$i][1] * $cellAttr['height'];
$progressHtml .= $tabs . $tab . $tab;
$progressHtml .= "
_UI;
$tabs = $ui->_getTabs();
$tab = $ui->_getTab();
$lnEnd = $ui->_getLineEnd();
$way_natural = ($ui->getFillWay() == 'natural');
$cellAttr = $ui->getCellAttributes();
$cellCount = $ui->getCellCount();
$progressId = $this->getIdent().'_';
$progressHtml = "";
if ($way_natural) {
// inactive cells first
for ($i=0; $i<$cellCount; $i++) {
$progressHtml .= $tabs . $tab . $tab;
$progressHtml .= "
" . $lnEnd;
}
} else {
// inactive cells first
for ($i=0; $i<$cellCount; $i++) {
$progressHtml .= $tabs . $tab . $tab;
$progressHtml .= "
" . $lnEnd;
}
}
return $progressHtml;
}
/**
* Checks for callback function existance
*
* @param mixed $callback a callback, like one used by call_user_func()
*
* @return boolean
* @since 1.2.0RC3
* @access private
*/
function _callbackExists($callback)
{
if (is_string($callback)) {
return function_exists($callback);
} elseif (is_array($callback) && is_object($callback[0])) {
return method_exists($callback[0], $callback[1]);
} else {
return false;
}
}
/**
* Initialize Error Handler
*
* Parameter '$prefs' contains a hash of options to define the error handler.
* You may find :
* 'message_callback' A callback to generate message body.
* Default is: HTML_Progress::_msgCallback()
* 'context_callback' A callback to generate context of error.
* Default is: HTML_Progress::_getBacktrace()
* 'push_callback' A callback to determine whether to allow an error
* to be pushed or logged.
* Default is: HTML_Progress::_handleError()
* 'error_handler' A callback to manage all error raised.
* Default is: HTML_Progress::_errorHandler()
* 'handler' Hash of params to configure all handlers (display, file, mail ...)
* There are only a display handler by default with options below:
*
* array('display' => array('conf' => $options));
* // where $options are:
* $options = array(
* 'lineFormat' => '%1$s: %2$s %3$s',
* 'contextFormat' => ' in %3$s (file %1$s at line %2$s)'
* );
*
*
* @param array $prefs hash of params to configure error handler
*
* @return void
* @since 1.2.0
* @access private
* @static
*/
function _initErrorHandler($prefs = array())
{
// error message mapping callback
if (isset($prefs['message_callback']) && is_callable($prefs['message_callback'])) {
$GLOBALS['_HTML_PROGRESS_CALLBACK_MESSAGE'] = $prefs['message_callback'];
} else {
$GLOBALS['_HTML_PROGRESS_CALLBACK_MESSAGE'] = array('HTML_Progress', '_msgCallback');
}
// error context mapping callback
if (isset($prefs['context_callback']) && is_callable($prefs['context_callback'])) {
$GLOBALS['_HTML_PROGRESS_CALLBACK_CONTEXT'] = $prefs['context_callback'];
} else {
$GLOBALS['_HTML_PROGRESS_CALLBACK_CONTEXT'] = array('HTML_Progress', '_getBacktrace');
}
// determine whether to allow an error to be pushed or logged
if (isset($prefs['push_callback']) && is_callable($prefs['push_callback'])) {
$GLOBALS['_HTML_PROGRESS_CALLBACK_PUSH'] = $prefs['push_callback'];
} else {
$GLOBALS['_HTML_PROGRESS_CALLBACK_PUSH'] = array('HTML_Progress', '_handleError');
}
// default error handler will use PEAR_Error
if (isset($prefs['error_handler']) && is_callable($prefs['error_handler'])) {
$GLOBALS['_HTML_PROGRESS_CALLBACK_ERRORHANDLER'] = $prefs['error_handler'];
} else {
$GLOBALS['_HTML_PROGRESS_CALLBACK_ERRORHANDLER'] = array('HTML_Progress', '_errorHandler');
}
// only a display handler is set by default with specific settings
$conf = array('lineFormat' => '
%1$s: %2$s %3$s',
'contextFormat' => ' in
%3$s (file
%1$s at line
%2$s)'
);
$optionsHandler['display'] = array('conf' => $conf);
if (isset($prefs['handler'])) {
$optionsHandler = array_merge($optionsHandler, $prefs['handler']);
}
$GLOBALS['_HTML_PROGRESS_ERRORHANDLER_OPTIONS'] = $optionsHandler;
}
/**
* Default callback to generate error messages for any instance
*
* @param array $err current error structure with context info
*
* @return string
* @since 1.2.0RC1
* @access private
* @static
*/
function _msgCallback($err)
{
$messages = HTML_Progress::_getErrorMessage();
$mainmsg = $messages[$err['code']];
if (count($err['params'])) {
foreach ($err['params'] as $name => $val) {
if (is_array($val)) {
$val = implode(', ', $val);
}
$mainmsg = str_replace('%' . $name . '%', $val, $mainmsg);
}
}
return $mainmsg;
}
/**
* Standard file/line number/function/class context callback
*
* @return false|array
* @since 1.2.0
* @access private
* @static
*/
function _getBacktrace()
{
if (function_exists('debug_backtrace')) {
$backtrace = debug_backtrace(); // PHP 4.3+
$backtrace = $backtrace[count($backtrace)-1];
} else {
$backtrace = false; // PHP 4.1.x, 4.2.x (no context info available)
}
return $backtrace;
}
/**
* Standard callback, this will be called every time an error
* is pushed onto the stack. The return value will be used to determine
* whether to allow an error to be pushed or logged.
* Dies if the error is an exception (and would have died anyway)
*
* @param array $err current error structure with context info
*
* @return null|HTML_PROGRESS_ERRORSTACK_* constant
* @since 1.2.0RC2
* @access private
* @static
* @see HTML_PROGRESS_ERRORSTACK_PUSHANDLOG, HTML_PROGRESS_ERRORSTACK_PUSH,
* HTML_PROGRESS_ERRORSTACK_LOG, HTML_PROGRESS_ERRORSTACK_IGNORE,
* HTML_PROGRESS_ERRORSTACK_LOGANDDIE
*
*/
function _handleError($err)
{
if ($err['level'] == 'exception') {
return HTML_PROGRESS_ERRORSTACK_LOGANDDIE;
}
}
/**
* Standard error handler that will use PEAR_Error object
*
* To improve performances, the PEAR.php file is included dynamically.
* The file is so included only when an error is triggered. So, in most
* cases, the file isn't included and perfs are much better.
*
* @param array $err current error structure with context info
*
* @return PEAR_Error
* @since 1.2.0
* @access private
* @static
*/
function _errorHandler($err)
{
include_once 'PEAR.php';
$e = PEAR::raiseError($err['message'], $err['code'], PEAR_ERROR_RETURN, E_USER_ERROR,
$err['context']);
if (isset($err['context'])) {
$file = $err['context']['file'];
$line = $err['context']['line'];
$func = $err['context']['class'];
$func .= $err['context']['type'];
$func .= $err['context']['function'];
}
$display_errors = ini_get('display_errors');
$log_errors = ini_get('log_errors');
$display = $GLOBALS['_HTML_PROGRESS_ERRORHANDLER_OPTIONS']['display'];
if ($display_errors) {
$lineFormat = $display['conf']['lineFormat'];
$contextFormat = $display['conf']['contextFormat'];
$context = sprintf($contextFormat, $file, $line, $func);
printf($lineFormat."
\n", ucfirst($err['level']), $err['message'], $context);
}
if ($log_errors) {
if (isset($GLOBALS['_HTML_PROGRESS_ERRORHANDLER_OPTIONS']['error_log'])) {
$error_log = $GLOBALS['_HTML_PROGRESS_ERRORHANDLER_OPTIONS']['error_log'];
$message_type = $error_log['name'];
$destination = '';
$extra_headers = '';
$send = true;
switch ($message_type) {
case HTML_PROGRESS_LOG_TYPE_SYSTEM:
break;
case HTML_PROGRESS_LOG_TYPE_MAIL:
$destination = $error_log['conf']['destination'];
$extra_headers = $error_log['conf']['extra_headers'];
break;
case HTML_PROGRESS_LOG_TYPE_FILE:
$destination = $error_log['conf']['destination'];
break;
default:
$send = false;
}
if ($send) {
/**
* String containing the format of a log line.
* Position arguments are:
* $1 -> timestamp
* $2 -> ident
* $3 -> level
* $4 -> message
* $5 -> context
*/
if (isset($error_log['conf']['lineFormat'])) {
$lineFormat = $error_log['conf']['lineFormat'];
} else {
$lineFormat = '%1$s %2$s [%3$s] %4$s %5$s';
}
/**
* String containing the timestamp format
*/
if (isset($error_log['conf']['timeFormat'])) {
$timeFormat = $error_log['conf']['timeFormat'];
} else {
$timeFormat = '%b %d %H:%M:%S';
}
/**
* String containing the error execution context format
*/
if (isset($error_log['conf']['contextFormat'])) {
$contextFormat = $error_log['conf']['contextFormat'];
} else {
$contextFormat = strip_tags($display['conf']['contextFormat']);
}
/**
* String containing the end-on-line character sequence
*/
if (isset($error_log['conf']['eol'])) {
$eol = $error_log['conf']['eol'];
} else {
$eol = "\n";
}
$context = sprintf($contextFormat, $file, $line, $func);
$message = sprintf($lineFormat,
strftime($timeFormat, $err['time']),
$error_log['ident'],
$err['level'],
$err['message'],
$context);
error_log($message.$eol, $message_type, $destination, $extra_headers);
}
}
}
return $e;
}
/**
* Error Message Template array
*
* @return string
* @since 1.0
* @access private
*/
function _getErrorMessage()
{
$messages = array(
HTML_PROGRESS_ERROR_INVALID_INPUT =>
'invalid input, parameter #%paramnum% '
. '"%var%" was expecting '
. '"%expected%", instead got "%was%"',
HTML_PROGRESS_ERROR_INVALID_CALLBACK =>
'invalid callback, parameter #%paramnum% '
. '"%var%" expecting %element%,'
. ' instead got "%was%" does not exists',
HTML_PROGRESS_DEPRECATED =>
'method is deprecated '
. 'use %newmethod% instead of %oldmethod%'
);
return $messages;
}
/**
* Add an error to the stack
*
* @param integer $code Error code.
* @param string $level The error level of the message.
* @param array $params Associative array of error parameters
*
* @return NULL|PEAR_Error PEAR_Error instance,
* with context info if PHP 4.3.0+
* @since 1.2.0RC1
* @access public
* @static
* @see hasErrors(), getError()
*/
function raiseError($code, $level, $params)
{
// obey at protocol
if (error_reporting() == 0) {
return;
}
// grab error context
$context = call_user_func($GLOBALS['_HTML_PROGRESS_CALLBACK_CONTEXT']);
// save error
$time = explode(' ', microtime());
$time = $time[1] + $time[0];
$err = array(
'code' => $code,
'params' => $params,
'package' => 'HTML_Progress',
'level' => $level,
'time' => $time,
'context' => $context
);
// set up the error message, if necessary
$err['message'] = call_user_func($GLOBALS['_HTML_PROGRESS_CALLBACK_MESSAGE'], $err);
$push = $log = true;
$die = false;
$action = call_user_func($GLOBALS['_HTML_PROGRESS_CALLBACK_PUSH'], $err);
switch($action){
case HTML_PROGRESS_ERRORSTACK_IGNORE:
$push = $log = false;
break;
case HTML_PROGRESS_ERRORSTACK_PUSH:
$log = false;
break;
case HTML_PROGRESS_ERRORSTACK_LOG:
$push = false;
break;
case HTML_PROGRESS_ERRORSTACK_LOGANDDIE:
$push = false;
$die = true;
break;
// anything else returned has the same effect as pushandlog
}
$e = false;
if ($push) {
array_unshift($GLOBALS['_HTML_PROGRESS_ERRORSTACK'], $err);
}
if ($log) {
// default callback returns a PEAR_Error object
$e = call_user_func($GLOBALS['_HTML_PROGRESS_CALLBACK_ERRORHANDLER'], $err);
}
if ($die) {
die();
}
return $e;
}
/**
* Determine whether there are errors into the HTML_Progress stack
*
* @return integer
* @since 1.2.0RC3
* @access public
* @static
* @see getError(), raiseError()
*/
function hasErrors()
{
return count($GLOBALS['_HTML_PROGRESS_ERRORSTACK']);
}
/**
* Pop an error off of the HTML_Progress stack
*
* @return false|array
* @since 1.2.0RC3
* @access public
* @static
* @see hasErrors(), raiseError()
*/
function getError()
{
return @array_shift($GLOBALS['_HTML_PROGRESS_ERRORSTACK']);
}
}
?>