* $bar = new HTML_Progress();
*
*
* o Creates a natural progress bar with the specified orientation, which can be
* either HTML_PROGRESS_BAR_HORIZONTAL or HTML_PROGRESS_BAR_VERTICAL
* By default, no border and no progress string are painted.
* The initial and minimum values are 0, and the maximum is 100.
*
* $bar = new HTML_Progress($orient);
*
*
* o Creates a natural horizontal progress bar with the specified minimum and
* maximum. Sets the initial value of the progress bar to the specified
* minimum, and the maximum that the progress bar can reach.
* By default, no border and no progress string are painted.
*
* $bar = new HTML_Progress($min, $max);
*
*
* o Creates a natural horizontal progress bar with the specified orientation,
* minimum and maximum. Sets the initial value of the progress bar to the
* specified minimum, and the maximum that the progress bar can reach.
* By default, no border and no progress string are painted.
*
* $bar = new HTML_Progress($orient, $min, $max);
*
*
* o Creates a natural horizontal progress that uses the specified model
* to hold the progress bar's data.
* By default, no border and no progress string are painted.
*
* $bar = new HTML_Progress($model);
*
*
*
* @param object $model (optional) Model that hold the progress bar's data
* @param int $orient (optional) Orientation of progress bar
* @param int $min (optional) Minimum value of progress bar
* @param int $max (optional) Maximum value of progress bar
* @param array $errorPrefs (optional) Always last argument of class constructor.
* hash of params to configure PEAR_ErrorStack and loggers
*
* @since 1.0
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see setIndeterminate(),
* setBorderPainted(), setStringPainted(), setString(),
* setDM(), setUI(), setIdent()
*/
function HTML_Progress()
{
$args = func_get_args();
$num_args = func_num_args();
if ($num_args > 0) {
$errorPrefs = func_get_arg($num_args - 1);
if (!is_array($errorPrefs)) {
$errorPrefs = array();
} else {
$num_args--;
}
HTML_Progress::_initErrorHandler($errorPrefs);
} else {
HTML_Progress::_initErrorhandler();
}
$this->_listeners = array(); // none listeners by default
$this->_DM = new HTML_Progress_DM(); // new instance of a progress DataModel
$this->_UI = new HTML_Progress_UI(); // new instance of a progress UserInterface
switch ($num_args) {
case 1:
if (is_object($args[0]) && (is_a($args[0], 'html_progress_dm'))) {
/* object html_progress_dm extends */
$this->_DM = &$args[0];
} elseif (is_int($args[0])) {
/* int orient */
$this->_UI->setOrientation($args[0]);
} else {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$model | $orient',
'was' => (gettype($args[0]) == 'object') ?
get_class($args[0]).' object' : gettype($args[0]),
'expected' => 'html_progress_dm object | integer',
'paramnum' => 1));
}
break;
case 2:
/* int min, int max */
if (!is_int($args[0])) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$min',
'was' => $args[0],
'expected' => 'integer',
'paramnum' => 1));
} elseif (!is_int($args[1])) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$max',
'was' => $args[1],
'expected' => 'integer',
'paramnum' => 2));
} else {
$this->_DM->setMinimum($args[0]);
$this->_DM->setMaximum($args[1]);
}
break;
case 3:
/* int orient, int min, int max */
if (!is_int($args[0])) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$orient',
'was' => $args[0],
'expected' => 'integer',
'paramnum' => 1));
} elseif (!is_int($args[1])) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$min',
'was' => $args[1],
'expected' => 'integer',
'paramnum' => 2));
} elseif (!is_int($args[2])) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$max',
'was' => $args[2],
'expected' => 'integer',
'paramnum' => 3));
} else {
$this->_UI->setOrientation($args[0]);
$this->_DM->setMinimum($args[1]);
$this->_DM->setMaximum($args[2]);
}
break;
default:
}
$this->setString(null);
$this->setStringPainted(false);
$this->setBorderPainted(false);
$this->setIndeterminate(false);
$this->setIdent();
$this->setAnimSpeed(0);
// to fix a potential php config problem with PHP 4.2.0 : turn 'implicit_flush' ON
ob_implicit_flush(1);
}
/**
* Returns the current API version
*
* @return float
* @since 0.1
* @access public
*/
function apiVersion()
{
return 1.2;
}
/**
* Returns mode of the progress bar (determinate or not).
*
* @return boolean
* @since 1.0
* @access public
* @see setIndeterminate()
*/
function isIndeterminate()
{
return $this->_indeterminate;
}
/**
* Sets the $_indeterminate property of the progress bar, which determines
* whether the progress bar is in determinate or indeterminate mode.
* An indeterminate progress bar continuously displays animation indicating
* that an operation of unknown length is occuring.
* By default, this property is false.
*
* @param boolean $continuous whether countinuously displays animation
*
* @return void
* @since 1.0
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see isIndeterminate()
*/
function setIndeterminate($continuous)
{
if (!is_bool($continuous)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$continuous',
'was' => gettype($continuous),
'expected' => 'boolean',
'paramnum' => 1));
}
$this->_indeterminate = $continuous;
}
/**
* Determines whether the progress bar border is painted or not.
* The default is false.
*
* @return boolean
* @since 1.0
* @access public
* @see setBorderPainted()
*/
function isBorderPainted()
{
return $this->_paintBorder;
}
/**
* Sets the value of $_paintBorder property, which determines whether the
* progress bar should paint its border. The default is false.
*
* @param boolean $paint whether the progress bar should paint its border
*
* @return void
* @since 1.0
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see isBorderPainted()
*/
function setBorderPainted($paint)
{
if (!is_bool($paint)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$paint',
'was' => gettype($paint),
'expected' => 'boolean',
'paramnum' => 1));
}
$this->_paintBorder = $paint;
}
/**
* Determines whether the progress bar string is painted or not.
* The default is false.
* The progress bar displays the value returned by getPercentComplete() method
* formatted as a percent such as 33%.
*
* @return boolean
* @since 1.0
* @access public
* @see setStringPainted(), setString()
*/
function isStringPainted()
{
return $this->_paintString;
}
/**
* Sets the value of $_paintString property, which determines whether the
* progress bar should render a progress string. The default is false.
*
* @param boolean $paint whether the progress bar should render a string
*
* @return void
* @since 1.0
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see isStringPainted(), setString()
*/
function setStringPainted($paint)
{
if (!is_bool($paint)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$paint',
'was' => gettype($paint),
'expected' => 'boolean',
'paramnum' => 1));
}
$this->_paintString = $paint;
}
/**
* Returns the current value of the progress string.
* By default, the progress bar displays the value returned by
* getPercentComplete() method formatted as a percent such as 33%.
*
* @return string
* @since 1.0
* @access public
* @see setString(), isStringPainted()
*/
function getString()
{
if ($this->isStringPainted() && !is_null($this->_progressString)) {
return $this->_progressString;
} else {
return sprintf("%s", $this->getPercentComplete(false)).' %';
}
}
/**
* Sets the current value of the progress string. By default, this string
* is null. If you have provided a custom progress string and want to revert
* to the built-in-behavior, set the string back to null.
* The progress string is painted only if the isStringPainted() method
* returns true.
*
* @param string $str progress string
*
* @return void
* @since 1.0
* @access public
* @see getString(), isStringPainted(), setStringPainted()
*/
function setString($str)
{
$this->_progressString = $str;
}
/**
* Returns the data model used by this progress bar.
*
* @return object
* @since 1.0
* @access public
* @see setDM()
*/
function &getDM()
{
return $this->_DM;
}
/**
* Sets the data model used by this progress bar.
*
* @param string $model class name of a html_progress_dm extends object
*
* @return void
* @since 1.0
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see getDM()
*/
function setDM($model)
{
if (!class_exists($model)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$model',
'was' => 'class does not exists',
'expected' => $model.' class defined',
'paramnum' => 1));
}
$_dm = new $model();
if (!is_a($_dm, 'html_progress_dm')) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$model',
'was' => $model,
'expected' => 'HTML_Progress_DM extends',
'paramnum' => 1));
}
$this->_DM =& $_dm;
}
/**
* Returns the progress bar's minimum value stored in the progress bar's data model.
* The default value is 0.
*
* @return integer
* @since 1.0
* @access public
* @see setMinimum(),
* HTML_Progress_DM::getMinimum()
*/
function getMinimum()
{
return $this->_DM->getMinimum();
}
/**
* Sets the progress bar's minimum value stored in the progress bar's data model.
* If the minimum value is different from previous minimum, all change listeners
* are notified.
*
* @param integer $min progress bar's minimal value
*
* @return void
* @since 1.0
* @access public
* @see getMinimum(),
* HTML_Progress_DM::setMinimum()
*/
function setMinimum($min)
{
$oldVal = $this->getMinimum();
$this->_DM->setMinimum($min);
if ($oldVal != $min) {
$this->_announce(array('log' => 'setMinimum', 'value' => $min));
}
}
/**
* Returns the progress bar's maximum value stored in the progress bar's data model.
* The default value is 100.
*
* @return integer
* @since 1.0
* @access public
* @see setMaximum(),
* HTML_Progress_DM::getMaximum()
*/
function getMaximum()
{
return $this->_DM->getMaximum();
}
/**
* Sets the progress bar's maximum value stored in the progress bar's data model.
* If the maximum value is different from previous maximum, all change listeners
* are notified.
*
* @param integer $max progress bar's maximal value
*
* @return void
* @since 1.0
* @access public
* @see getMaximum(),
* HTML_Progress_DM::setMaximum()
*/
function setMaximum($max)
{
$oldVal = $this->getMaximum();
$this->_DM->setMaximum($max);
if ($oldVal != $max) {
$this->_announce(array('log' => 'setMaximum', 'value' => $max));
}
}
/**
* Returns the progress bar's increment value stored in the progress bar's data model.
* The default value is +1.
*
* @return integer
* @since 1.0
* @access public
* @see setIncrement(),
* HTML_Progress_DM::getIncrement()
*/
function getIncrement()
{
return $this->_DM->getIncrement();
}
/**
* Sets the progress bar's increment value stored in the progress bar's data model.
*
* @param integer $inc progress bar's increment value
*
* @return void
* @since 1.0
* @access public
* @see getIncrement(),
* HTML_Progress_DM::setIncrement()
*/
function setIncrement($inc)
{
$this->_DM->setIncrement($inc);
}
/**
* Returns the progress bar's current value, which is stored in the
* progress bar's data model. The value is always between the minimum
* and maximum values, inclusive.
* By default, the value is initialized to be equal to the minimum value.
*
* @return integer
* @since 1.0
* @access public
* @see setValue(), incValue(),
* HTML_Progress_DM::getValue()
*/
function getValue()
{
return $this->_DM->getValue();
}
/**
* Sets the progress bar's current value stored in the progress bar's data model.
* If the new value is different from previous value, all change listeners
* are notified.
*
* @param integer $val progress bar's current value
*
* @return void
* @since 1.0
* @access public
* @see getValue(), incValue(),
* HTML_Progress_DM::setValue()
*/
function setValue($val)
{
$oldVal = $this->getValue();
$this->_DM->setValue($val);
if ($oldVal != $val) {
$this->_announce(array('log' => 'setValue', 'value' => $val));
}
}
/**
* Updates the progress bar's current value by adding increment value.
* All change listeners are notified.
*
* @return void
* @since 1.0
* @access public
* @see getValue(), setValue(),
* HTML_Progress_DM::incValue()
*/
function incValue()
{
$this->_DM->incValue();
$this->_announce(array('log' => 'incValue', 'value' => $this->_DM->getValue() ));
}
/**
* Returns the percent complete for the progress bar. Note that this number is
* between 0.00 and 1.00 or 0 and 100.
*
* @param boolean $float (optional) float or integer format
*
* @return mixed
* @since 1.0
* @access public
* @see getValue(), getMaximum(),
* HTML_Progress_DM::getPercentComplete()
*/
function getPercentComplete($float = true)
{
return $this->_DM->getPercentComplete($float);
}
/**
* Returns the look-and-feel object that renders the progress bar.
*
* @return object
* @since 1.0
* @access public
* @see setUI()
*/
function &getUI()
{
return $this->_UI;
}
/**
* Sets the look-and-feel object that renders the progress bar.
*
* @param string $ui class name of a html_progress_ui extends object
*
* @return void
* @since 1.0
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see getUI()
*/
function setUI($ui)
{
if (!class_exists($ui)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$ui',
'was' => 'class does not exists',
'expected' => $ui.' class defined',
'paramnum' => 1));
}
$_ui = new $ui();
if (!is_a($_ui, 'html_progress_ui')) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$ui',
'was' => $ui,
'expected' => 'HTML_Progress_UI extends',
'paramnum' => 1));
}
$this->_UI =& $_ui;
}
/**
* Sets the look-and-feel model that renders the progress bar.
*
* @param string $file file name of model properties
* @param string $type type of external ressource (phpArray, iniFile, XML ...)
*
* @return void
* @since 1.0
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see setUI()
*/
function setModel($file, $type)
{
if (!file_exists($file)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$file',
'was' => $file,
'expected' => 'file exists',
'paramnum' => 1));
}
include_once 'Config.php';
$conf = new Config();
if (!$conf->isConfigTypeRegistered($type)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$type',
'was' => $type,
'expected' => implode (" | ", array_keys($GLOBALS['CONFIG_TYPES'])),
'paramnum' => 2));
}
$data = $conf->parseConfig($file, $type);
$structure = $data->toArray(false);
$progress =& $structure['root'];
$ui = new HTML_Progress_UI();
if (isset($progress['core']['speed'])) {
$this->setAnimSpeed(intval($progress['core']['speed']));
}
if (isset($progress['core']['indeterminate'])) {
$mode = (strtolower(trim($progress['core']['indeterminate'])) == 'true');
$this->setIndeterminate($mode);
}
if (isset($progress['core']['increment'])) {
$this->setIncrement(intval($progress['core']['increment']));
}
if (isset($progress['core']['javascript']) && file_exists($progress['core']['javascript'])) {
$ui->setScript($progress['core']['javascript']);
}
if (isset($progress['orientation']['shape'])) {
$ui->setOrientation(intval($progress['orientation']['shape']));
}
if (isset($progress['orientation']['fillway'])) {
$ui->setFillWay($progress['orientation']['fillway']);
}
if (isset($progress['cell']['count'])) {
$ui->setCellCount(intval($progress['cell']['count']));
}
if (isset($progress['cell']['font-family'])) {
if (is_array($progress['cell']['font-family'])) {
$progress['cell']['font-family'] = implode(",", $progress['cell']['font-family']);
}
}
if (isset($progress['cell'])) {
$ui->setCellAttributes($progress['cell']);
}
if (isset($progress['border'])) {
$this->setBorderPainted(true);
$ui->setBorderAttributes($progress['border']);
}
if (isset($progress['string']['font-family'])) {
if (is_array($progress['string']['font-family'])) {
$progress['string']['font-family'] = implode(",", $progress['string']['font-family']);
}
}
if (isset($progress['string'])) {
$this->setStringPainted(true);
$ui->setStringAttributes($progress['string']);
}
if (isset($progress['progress'])) {
$ui->setProgressAttributes($progress['progress']);
}
$this->_UI = $ui;
}
/**
* Returns delay execution of the progress bar
*
* @return integer
* @since 1.2.0RC1
* @access public
* @see setAnimSpeed()
*/
function getAnimSpeed()
{
return $this->_anim_speed;
}
/**
* Set the delays progress bar execution for the given number of miliseconds.
*
* @param integer $delay Delay in milisecond.
*
* @return void
* @since 1.1
* @access public
* @throws HTML_PROGRESS_ERROR_INVALID_INPUT
* @see getAnimSpeed()
*/
function setAnimSpeed($delay)
{
if (!is_int($delay)) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
array('var' => '$delay',
'was' => gettype($delay),
'expected' => 'integer',
'paramnum' => 1));
} elseif ($delay < 0) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$delay',
'was' => $delay,
'expected' => 'greater than zero',
'paramnum' => 1));
} elseif ($delay > 1000) {
return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
array('var' => '$delay',
'was' => $delay,
'expected' => 'less or equal 1000',
'paramnum' => 1));
}
$this->_anim_speed = $delay;
}
/**
* Get the cascading style sheet to put inline on HTML document
*
* @return string
* @since 1.0
* @access public
* @see HTML_Progress_UI::getStyle()
*/
function getStyle()
{
$ui = $this->getUI();
$lnEnd = $ui->_getLineEnd();
$style = $lnEnd . $ui->getStyle();
$style = str_replace('{%pIdent%}', '.'.$this->getIdent(), $style);
if (!$this->isBorderPainted()) {
$style = ereg_replace('border-width: [0-9]+px;', 'border-width: 0;', $style);
}
return $style;
}
/**
* Get the javascript code to manage progress bar.
*
* @return string JavaScript URL or inline code to manage progress bar
* @since 1.0
* @access public
* @see HTML_Progress_UI::getScript()
*/
function getScript()
{
$ui = $this->getUI();
$js = $ui->getScript();
return $js;
}
/**
* Returns the progress bar structure in an array.
*
* @return array of progress bar properties
* @since 1.0
* @access public
*/
function toArray()
{
$ui =& $this->getUI();
$dm =& $this->getDM();
$_structure = array();
$_structure['id'] = $this->getIdent();
$_structure['indeterminate'] = $this->isIndeterminate();
$_structure['borderpainted'] = $this->isBorderPainted();
$_structure['stringpainted'] = $this->isStringPainted();
$_structure['string'] = $this->_progressString;
$_structure['animspeed'] = $this->getAnimSpeed();
$_structure['ui']['classID'] = get_class($ui);
$_structure['ui']['orientation'] = $ui->getOrientation();
$_structure['ui']['fillway'] = $ui->getFillWay();
$_structure['ui']['cell'] = $ui->getCellAttributes();
$_structure['ui']['cell']['count'] = $ui->getCellCount();
$_structure['ui']['border'] = $ui->getBorderAttributes();
$_structure['ui']['string'] = $ui->getStringAttributes();
$_structure['ui']['progress'] = $ui->getProgressAttributes();
$_structure['ui']['script'] = $ui->getScript();
$_structure['dm']['classID'] = get_class($dm);
$_structure['dm']['minimum'] = $dm->getMinimum();
$_structure['dm']['maximum'] = $dm->getMaximum();
$_structure['dm']['increment'] = $dm->getIncrement();
$_structure['dm']['value'] = $dm->getValue();
$_structure['dm']['percent'] = $dm->getPercentComplete(false);
return $_structure;
}
/**
* Returns the progress structure as HTML.
*
* @return string HTML Progress bar
* @since 0.2
* @access public
*/
function toHtml()
{
$strHtml = '';
$ui =& $this->_UI;
$tabs = $ui->_getTabs();
$tab = $ui->_getTab();
$lnEnd = $ui->_getLineEnd();
$comment = $ui->getComment();
$orient = $ui->getOrientation();
$progressAttr = $ui->getProgressAttributes();
$borderAttr = $ui->getBorderAttributes();
$stringAttr = $ui->getStringAttributes();
$valign = strtolower($stringAttr['valign']);
/**
* Adds a progress bar legend in html code is possible.
* See HTML_Common::setComment() method.
*/
if (strlen($comment) > 0) {
$strHtml .= $tabs . "" . $lnEnd;
}
$strHtml .= $tabs . "" . $lnEnd; $strHtml .= $tabs . $tab . $tab . $this->getString() . $lnEnd; $ps = -1; } else { $class = $progressAttr['class']; $strHtml .= $tabs . $tab ." | " . $lnEnd;
$strHtml .= $tabs . $tab . $tab . " " . $lnEnd;
$strHtml .= $progressHtml;
$strHtml .= $tabs . $tab . $tab . " " . $lnEnd;
}
$strHtml .= $tabs . $tab ." | " . $lnEnd;
}
$strHtml .= $tabs . "
* 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."