'
. PHP_EOL;
} else {
$topshift = $progressAttr['top'];
$leftshift = 0;
$strHtml .= $tabs
. '
'
. PHP_EOL;
}
$topshift = 0;
// Start of progress meter border
$strHtml .= $tabs
. '
'
. PHP_EOL;
// Start of progress meter
if ($this->cellCount == 0) {
$strHtml .= $tabs
. '
'
. PHP_EOL;
} else {
$strHtml .= $tabs
. '
'
. PHP_EOL;
}
if ($this->orientation == HTML_PROGRESS2_BAR_HORIZONTAL) {
$progressHtml = $this->_getProgressHbarToHtml();
}
if ($this->orientation == HTML_PROGRESS2_BAR_VERTICAL) {
$progressHtml = $this->_getProgressVbarToHtml();
}
if ($this->orientation == HTML_PROGRESS2_POLYGONAL) {
$progressHtml = $this->_getProgressPolygonalToHtml();
}
if ($this->orientation == HTML_PROGRESS2_CIRCLE) {
$cellAttr = $this->getCellAttributes();
if (!isset($cellAttr[0]['background-image'])
|| !file_exists($cellAttr[0]['background-image'])) {
// creates default circle segments pictures :
// 'c0.png'->0% 'c1.png'->10%, 'c2.png'->20%, ... 'c10.png'->100%
$this->drawCircleSegments();
}
$progressHtml = $this->_getProgressCircleToHtml();
}
$strHtml .= $tabs
. $progressHtml
. PHP_EOL;
// Enf of progress meter
$strHtml .= $tabs
. '
'
. PHP_EOL;
// Enf of progress meter border
$strHtml .= $tabs
. '
'
. PHP_EOL;
$heightshift = $topshift + $progressAttr['height'];
$bottomdef = $topdef = false;
// Start of progress meter labels
foreach ($this->label as $name => $data) {
$width = $data['width'];
$height = $data['height'];
if ($progressAttr['position'] == 'relative') {
switch ($data['valign']) {
case 'top':
$style_pos = 'top:0;left:{_leftshift_}px;';
if ($topdef == false) {
if ($height == 0) {
$height = $progressAttr['height'];
}
$topshift += $height;
$heightshift += $height;
$topdef = true;
}
break;
case 'right':
$style_pos = 'top:{_topshift_}px;'
. 'left:{_rxshift_}px;';
break;
case 'bottom':
$style_pos = 'top:{_bottomshift_}px;'
. 'left:{_leftshift_}px;';
if ($bottomdef == false) {
if ($height == 0) {
$height = $progressAttr['height'];
}
$heightshift += $height;
$bottomdef = true;
}
break;
case 'left':
$style_pos = 'top:{_topshift_}px;left:0;';
if ($data['width'] > 0) {
$leftshift = $data['width'];
} else {
$leftshift = $progressAttr['width'];
}
$leftshift += $data['left'];
break;
case 'center':
$style_pos = 'top:{_topshift_}px;left:{_leftshift_}px;';
$width = $progressAttr['width'];
break;
}
$style_pos .= 'margin-top:' . $data['top'] . 'px;'
. 'margin-left:' . $data['left'] . 'px;';
if ($width > 0) {
$style_pos .= 'width:' . $width . 'px;';
}
} else {
$style_pos = 'top:' . $data['top'] . 'px;'
. 'left:' . $data['left'] . 'px;';
}
$style_cls = sprintf($data['class'], $name . $this->ident);
switch ($data['type']) {
case HTML_PROGRESS2_LABEL_TEXT:
$strHtml .= $tabs
. '
'
. $data['value']
. '
'
. PHP_EOL;
break;
case HTML_PROGRESS2_LABEL_BUTTON:
$strHtml .= $tabs
. '
'
. '
'
. PHP_EOL;
break;
case HTML_PROGRESS2_LABEL_STEP:
$strHtml .= $tabs
. '
'
. '
'
. PHP_EOL;
break;
case HTML_PROGRESS2_LABEL_PERCENT:
$strHtml .= $tabs
. '
'
. '
'
. PHP_EOL;
break;
case HTML_PROGRESS2_LABEL_CROSSBAR:
$strHtml .= $tabs
. '
'
. $data['value']
. '
'
. PHP_EOL;
break;
}
}
// End of Top progress meter frame
$strHtml .= $tabs
. '
'
. PHP_EOL;
$placeHolders = array(
'{_topshift_}', '{_leftshift_}', '{_heightshift_}', '{_rxshift_}',
'{_bottomshift_}'
);
$htmlElement = array(
$topshift, $leftshift, $heightshift,
($leftshift + $progressAttr['width']),
($topshift + $progressAttr['height'])
);
$strHtml = str_replace($placeHolders, $htmlElement, $strHtml);
return $strHtml;
}
/**
* Renders the new value of progress meter.
*
* This method should be used only to display initial state
* of the progress meter. Next steps to refresh display must use either
* moveStep() or moveNext() methods.
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access public
*/
function display()
{
$this->_status = 'show';
echo $this->toHtml();
}
/**
* Hides the progress meter.
*
* Once the process is over this method provides a solution
* to remove/hide the progress meter of the browser screen.
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access public
*/
function hide()
{
$bar = '';
echo $bar . PHP_EOL;
}
/**
* Delay execution.
*
* The HTML_Progress2::sleep() function delays program execution
* for the given number of milliseconds.
* This is the default user callback when none are defined.
*
* NOTE: The function {@link http://www.php.net/manual/en/function.usleep.php}
* did not work on Windows systems until PHP 5.0.0
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access public
* @see getAnimSpeed(), setAnimSpeed(), process()
*/
function sleep()
{
// convert delay from milliseconds to microseconds
$usecs = $this->animSpeed * 1000;
if ((substr(PHP_OS, 0, 3) == 'WIN') && (substr(PHP_VERSION, 0, 1) < '5')) {
for ($i = 0; $i < $usecs; $i++) {
}
} else {
usleep($usecs);
}
}
/**
* Sets the user progress callback function.
*
* The process() function will call the user-callback defined here by this
* setProgressHandler() method.
*
* The user-supplied progress function must return either positive
* for a step progression, using moveStep() method,
* or NULL for a standard progression, using moveNext() method.
*
* @param mixed $handler Name of function or a class-method.
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access public
* @throws HTML_PROGRESS2_ERROR_INVALID_CALLBACK
* @see process()
*/
function setProgressHandler($handler)
{
if (!is_callable($handler)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_CALLBACK,
'warning',
array('var' => '$handler',
'element' => 'valid Class-Method/Function',
'was' => 'callback',
'paramnum' => 1));
}
$this->_callback = $handler;
}
/**
* Performs the progress user process.
*
* This function call the user-specified progress function, defined by
* setProgressHandler() method. Default callback is
* the HTML_Progress2::sleep() method.
*
* @return mixed
* @since version 2.0.0 (2005-10-01)
* @access public
* @see sleep(), setProgressHandler()
*/
function process()
{
if ($this->_callback) {
return call_user_func_array($this->_callback,
array($this->value, &$this));
} else {
// when there is no valid user callback then default is to sleep a bit
$this->sleep();
}
}
/**
* Runs the progress meter.
*
* This function accept both modes: indeterminate and determinate,
* and execute all actions defined in the user callback identified by
* setProgressHandler() method.
*
* All observers are also notified of main changes (start, stop meter).
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access public
* @see process(), setProgressHandler()
*/
function run()
{
$this->_status = 'run';
$this->_postNotification('onSubmit',
array('handler' => __FUNCTION__,
'value' => $this->getValue()));
do {
$ret = $this->process();
if ($this->getPercentComplete() == 1) {
if ($this->indeterminate) {
$this->setValue(0);
} else {
break;
}
}
if (is_null($ret)) {
$this->moveNext();
} else {
$this->moveStep($ret);
}
} while (1);
$this->_postNotification('onLoad',
array('handler' => __FUNCTION__,
'value' => $this->getValue()));
}
/**
* Returns the progress meter identifier.
*
* Each progress meter has its own identifier. That allows to display more than
* only once meter at same time on same page.
*
* @return string
* @since version 2.0.0 (2005-10-01)
* @access public
* @see setIdent()
*/
function getIdent()
{
return $this->ident;
}
/**
* Sets the progress meter identifier.
*
* Each progress meter has its own identifier. That allows to display more than
* only once meter at same time on same page.
* If no identification string is given, then the default identifier will be
* six first characters of md5 hash value of the current unix timestamp.
*
* @param mixed $ident (optional) the new identification string.
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access public
* @see getIdent()
*/
function setIdent($ident = null)
{
if (is_null($ident)) {
$this->ident = 'PB' . substr(md5(microtime()), 0, 6);
} else {
$this->ident = $ident;
}
}
/**
* Attachs a new observer.
*
* Adds a new observer to the Event Dispatcher that will listen
* for all messages emitted by this HTML_Progress2 instance.
*
* @param mixed $callback PHP callback that will act as listener
* @param string $nName Expected notification name, serves as a filter
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access public
* @throws HTML_PROGRESS2_ERROR_INVALID_CALLBACK,
* HTML_PROGRESS2_ERROR_INVALID_INPUT
* @see removeListener()
*/
function addListener($callback, $nName = EVENT_DISPATCHER_GLOBAL)
{
if (!is_callable($callback)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_CALLBACK,
'exception',
array('var' => '$callback',
'element' => 'valid Class-Method/Function',
'was' => 'callback',
'paramnum' => 1));
} elseif (!is_string($nName)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$nName',
'was' => gettype($nName),
'expected' => 'string',
'paramnum' => 2));
}
$this->dispatcher =& Event_Dispatcher::getInstance('ProgressMeter');
$this->dispatcher->addObserver($callback, $nName);
$this->_observerCount++;
}
/**
* Removes a registered observer.
*
* Detachs a previously registered observer and remove the Event Dispatcher
* if there is no more observer registered.
*
* @param mixed $callback PHP callback that act as listener
* @param string $nName Expected notification name, serves as a filter
*
* @return bool True if observer was removed, false otherwise
* @since version 2.0.0 (2005-10-01)
* @access public
* @throws HTML_PROGRESS2_ERROR_INVALID_CALLBACK,
* HTML_PROGRESS2_ERROR_INVALID_INPUT
* @see addListener()
*/
function removeListener($callback, $nName = EVENT_DISPATCHER_GLOBAL)
{
if (!is_callable($callback)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_CALLBACK,
'exception',
array('var' => '$callback',
'element' => 'valid Class-Method/Function',
'was' => 'callback',
'paramnum' => 1));
} elseif (!is_string($nName)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$nName',
'was' => gettype($nName),
'expected' => 'string',
'paramnum' => 2));
}
$result = $this->dispatcher->removeObserver($callback, $nName);
if ($result) {
$this->_observerCount--;
if ($this->_observerCount == 0) {
unset($this->dispatcher);
}
}
return $result;
}
/**
* Register an external AJAX server to use for progress bar polling.
*
* Until version 2.2.0 Progress2 has only COMET (streaming) ability. With
* first alpha of 2.3.0 version, Progress2 has now AJAX (polling) ability.
* Use PEAR::HTML_AJAX package as backend.
*
* @param string $serverUrl the url the client should be making a request to
* @param array $stub (optional) list of proxy definition for
* @param array $client (optional) list of client libraries to use
*
* @return void
* @since version 2.3.0a1 (2007-01-17)
* @access public
* @throws HTML_PROGRESS2_ERROR_INVALID_INPUT,
* HTML_PROGRESS2_ERROR_INVALID_RESOURCE
* @see setupAJAX()
*/
function registerAJAX($serverUrl, $stub = array(), $client = array('all'))
{
if (!is_string($serverUrl)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$serverUrl',
'was' => gettype($serverUrl),
'expected' => 'string',
'paramnum' => 1));
} elseif (!HTML_Progress2::fileExists($serverUrl)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_RESOURCE,
'error',
array('var' => '$serverUrl',
'resource' => $serverUrl,
'expected' => 'AJAX server defined',
'paramnum' => 1));
} elseif (!is_array($stub)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$stub',
'was' => gettype($stub),
'expected' => 'array',
'paramnum' => 2));
} elseif (!is_array($client)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$client',
'was' => gettype($client),
'expected' => 'array',
'paramnum' => 3));
} elseif (count($client) == 0) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'error',
array('var' => '$client',
'was' => 'empty array',
'expected' => 'at least one client defined',
'paramnum' => 3));
}
$this->ajax = array('serverUrl' => $serverUrl,
'client' => $client, 'stub' => $stub);
}
/**
* Include all needed libraries, stubs, and set defaultServer
*
* @param string $serializer (optional) What encoding you are going to use
* for serializing/unserializing data
*
* @return string
* @since version 2.3.0a2 (2007-01-23)
* @access public
* @throws HTML_PROGRESS2_ERROR_INVALID_INPUT
* @see registerAJAX()
*/
function setupAJAX($serializer = null)
{
if (isset($serializer) && !is_string($serializer)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$serializer',
'was' => gettype($serializer),
'expected' => 'string',
'paramnum' => 1));
}
include_once 'HTML/AJAX/Helper.php';
// auto-register default AJAX values (server, client)
if (count($this->ajax) == 0) {
$this->ajax = array('serverUrl' => 'server.php',
'client' => array('all'), 'stub' => array()
);
}
$ajaxHelper = new HTML_AJAX_Helper();
$ajaxHelper->serverUrl = $this->ajax['serverUrl'];
$ajaxHelper->jsLibraries = $this->ajax['client'];
$ajaxHelper->stubs = $this->ajax['stub'];
$ret = $ajaxHelper->setupAJAX();
$setting = '';
if ($this->cell['class'] != 'cell%s') {
$setting .= PHP_EOL . 'HTML_Progress2.cellClass = ' .
$ajaxHelper->escape($this->cell['class']) . ';' ;
}
if ($this->cellCount != 10) {
$setting .= PHP_EOL
. 'HTML_Progress2.cellCount = ' . $this->cellCount . ';';
}
if ($this->minimum != 0) {
$setting .= PHP_EOL
. 'HTML_Progress2.minimum = ' . $this->minimum . ';';
}
if ($this->maximum != 100) {
$setting .= PHP_EOL
. 'HTML_Progress2.maximum = ' . $this->maximum . ';';
}
if (isset($serializer) && $serializer != 'JSON') {
$setting .= PHP_EOL
. 'HTML_Progress2.defaultEncoding = '
. $ajaxHelper->escape($serializer) . ';';
}
$setting .= PHP_EOL;
$ret .= $ajaxHelper->encloseInScript(PHP_EOL
. '//' . PHP_EOL);
return $ret;
}
/**
* Register an external AFLAX server to upload file with a progress meter.
*
* Pure PHP solution of upload file with a progress bar
* is only possible since PHP 5.2.0
* AFLAX stands for Asynchronous Flash and XML provides an upload file solution
* with integration of progress feedback.
*
* @param string $serverAflaxUrl Url of the Adobe Flash "aflax.swf" resource
* @param string $serverUploadUri Uri of the php script to handle uploaded files
* @param array $callback (optional) list of event handler
* for browse file dialog box
* @param array $extension (optional) list of file types
* for browse file dialog box
*
* @return void
* @since version 2.3.0a3 (2007-02-02)
* @access public
* @throws HTML_PROGRESS2_ERROR_INVALID_INPUT,
* HTML_PROGRESS2_ERROR_INVALID_RESOURCE
* @see setupAFLAX()
*/
function registerAFLAX($serverAflaxUrl, $serverUploadUri,
$callback = array(), $extension = array())
{
if (!is_string($serverAflaxUrl)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$serverAflaxUrl',
'was' => gettype($serverAflaxUrl),
'expected' => 'string',
'paramnum' => 1));
} elseif (!HTML_Progress2::fileExists($serverAflaxUrl)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_RESOURCE,
'error',
array('var' => '$serverAflaxUrl',
'resource' => $serverAflaxUrl,
'expected' => 'AFLAX server available',
'paramnum' => 1));
} elseif (!is_string($serverUploadUri)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$serverUploadUri',
'was' => gettype($serverUploadUri),
'expected' => 'string',
'paramnum' => 2));
} elseif (!HTML_Progress2::fileExists($serverUploadUri)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_RESOURCE,
'error',
array('var' => '$serverUploadUri',
'resource' => $serverUploadUri,
'expected' => 'Upload script handler available',
'paramnum' => 2));
} elseif (!is_array($callback)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$callback',
'was' => gettype($callback),
'expected' => 'array',
'paramnum' => 3));
} elseif (!is_array($extension)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$extension',
'was' => gettype($extension),
'expected' => 'array',
'paramnum' => 4));
}
$this->aflax = array('swf' => $serverAflaxUrl,
'php' => 'http://' . $_SERVER['HTTP_HOST'] .
dirname($_SERVER['PHP_SELF']) . '/' . $serverUploadUri,
'fext' => $extension, 'jscb' => $callback
);
}
/**
* Include all needed JS libraries
*
* @param boolean $raw (optional) html output with script tags or just JS links
* @param string $path (optional) directory, with no trailing slash,
* where to get HTML_Progress2_AFLAX.js
* and ajax.js files
*
* @return string
* @since version 2.3.0a3 (2007-02-02)
* @access public
* @throws HTML_PROGRESS2_ERROR_INVALID_INPUT,
* HTML_PROGRESS2_ERROR_INVALID_RESOURCE
* @see registerAFLAX()
*/
function setupAFLAX($raw = false, $path = null)
{
$ds = DIRECTORY_SEPARATOR;
if (!is_bool($raw)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$raw',
'was' => gettype($raw),
'expected' => 'boolean',
'paramnum' => 1));
} elseif (isset($path)) {
if (!is_string($path)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
array('var' => '$path',
'was' => gettype($path),
'expected' => 'string',
'paramnum' => 2));
} elseif (!is_dir($path)) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_RESOURCE,
'error',
array('var' => '$path',
'resource' => $path,
'expected' => 'directory',
'paramnum' => 2));
} elseif (!file_exists($js = $path . $ds . 'HTML_Progress2_AFLAX.js')) {
return $this->raiseError(HTML_PROGRESS2_ERROR_INVALID_RESOURCE,
'error',
array('var' => '$path',
'resource' => $js,
'expected' => 'directory with valid JS AFLAX handler',
'paramnum' => 2));
}
}
if (!$raw) {
$js = '' . PHP_EOL;
$js .= '' . PHP_EOL;
} else {
if (isset($path)) {
$js = $path;
} else {
$js = '@data_dir@' . $ds . '@package_name@';
if (strpos($js, '@'.'data_dir@') === 0) {
$js = dirname(__FILE__);
}
}
$js = ''
. PHP_EOL;
}
// auto-register default AFLAX values
if (count($this->aflax) == 0) {
$this->aflax = array('swf' => 'aflax.swf',
'php' => 'http://' . $_SERVER['HTTP_HOST'] .
dirname($_SERVER['PHP_SELF']) .
'/upload.php');
}
// default file types you can select on browse file dialog box
if (count($this->aflax['fext']) == 0) {
$extension = array(
array("Archives (*.zip, *.tar, *.tar.gz)",
"*.zip; *.tar; *.tar.gz"),
array("Images (*.jpg, *.jpeg, *.gif, *.png)",
"*.jpg; *.jpeg; *.gif; *.png")
);
$this->aflax['fext'] = $extension;
}
// default event handler JS function on browse file dialog box
if (count($this->aflax['jscb']) == 0) {
$callback = array(
'HTML_Progress2_AFLAX_Select',
'HTML_Progress2_AFLAX_Progress',
'HTML_Progress2_AFLAX_Complete',
'HTML_Progress2_AFLAX_HTTPError',
'HTML_Progress2_AFLAX_SecurityError',
'HTML_Progress2_AFLAX_IOError'
);
$this->aflax['jscb'] = $callback;
}
$js .= ''
. PHP_EOL;
return $js;
}
/**
* Checks whether the file exists in the include path
*
* Method used to check if a file (Ajax engine driver) is available
* and readable.
*
* @param string $fileName file name
*
* @return bool
* @since version 2.3.0a1 (2007-01-17)
* @access protected
* @static
*/
function fileExists($fileName)
{
foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
if (file_exists($path . DIRECTORY_SEPARATOR . $fileName) &&
is_readable($path . DIRECTORY_SEPARATOR . $fileName)) {
return true;
}
}
return false;
}
/**
* Refresh the progress meter display.
*
* @param integer $value new value of the progress meter
*
* @return void
* @since version 2.0.0RC2 (2005-08-01)
* @access private
* @see moveStep(), moveNext()
*/
function _refreshDisplay($value)
{
static $determinate;
foreach ($this->label as $name => $data) {
switch($data['type']) {
case HTML_PROGRESS2_LABEL_STEP:
if (!$this->indeterminate) {
$this->_changeLabelText($name,
intval(ceil($value / $this->increment))
. '/'
. intval(ceil($this->maximum / $this->increment)));
}
break;
case HTML_PROGRESS2_LABEL_PERCENT:
if (!$this->indeterminate) {
$this->_changeLabelText($name,
$this->getPercentComplete(false) . '%');
}
break;
case HTML_PROGRESS2_LABEL_CROSSBAR:
$this->_changeCrossItem($name);
break;
}
}
$bar = ob_get_clean();
if ($this->cellCount > 0) {
if ($this->indeterminate) {
if (isset($determinate)) {
$determinate++;
$progress = $determinate;
} else {
$progress = $determinate = 1;
}
} else {
$progress = (($this->value - $this->minimum) * $this->cellCount)
/ ($this->maximum - $this->minimum);
$determinate = 0;
}
$bar .= '';
} else {
$position = $this->_computePosition();
$orient = $this->orientation;
$cssText = '';
if ($orient == HTML_PROGRESS2_BAR_HORIZONTAL) {
if ($this->fillWay == 'reverse') {
$cssText .= 'left:' . $position['left'] . 'px;';
}
$cssText .= 'width:' . $position['width'] . 'px;';
}
if ($orient == HTML_PROGRESS2_BAR_VERTICAL) {
if ($this->fillWay == 'natural') {
$cssText .= 'top:' . $position['top'] . 'px;';
}
$cssText .= 'height:' . $position['height'] . 'px;';
}
$bar .= $this->_changeElementStyle($cssText);
}
echo $bar . PHP_EOL;
ob_start();
}
/**
* Returns a horizontal progress bar structure as HTML.
*
* @return string
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _getProgressHbarToHtml()
{
$tabs = $this->_getTabs();
$tab = $this->_getTab();
$way_natural = ($this->fillWay == 'natural');
$cellAttr = $this->getCellAttributes();
$cellCls = sprintf($cellAttr['class'], $this->ident);
$html = '';
if ($way_natural) {
$pos = $cellAttr['spacing'];
for ($i = 0; $i < $this->cellCount; $i++) {
$html .= $tabs . $tab
. '
' . PHP_EOL;
$pos += ($cellAttr['width'] + $cellAttr['spacing']);
}
} else {
$pos = $cellAttr['spacing'];
for ($i = $this->cellCount - 1; $i >= 0; $i--) {
$html .= $tabs . $tab
. '
' . PHP_EOL;
$pos += ($cellAttr['width'] + $cellAttr['spacing']);
}
}
return $html;
}
/**
* Returns a vertical progress bar structure as HTML.
*
* @return string
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _getProgressVbarToHtml()
{
$tabs = $this->_getTabs();
$tab = $this->_getTab();
$way_natural = ($this->fillWay == 'natural');
$cellAttr = $this->getCellAttributes();
$cellCls = sprintf($cellAttr['class'], $this->ident);
$html = '';
if ($way_natural) {
$pos = $cellAttr['spacing'];
for ($i = $this->cellCount - 1; $i >= 0; $i--) {
$html .= $tabs . $tab
. '
' . PHP_EOL;
$pos += ($cellAttr['height'] + $cellAttr['spacing']);
}
} else {
$pos = $cellAttr['spacing'];
for ($i = 0; $i < $this->cellCount; $i++) {
$html .= $tabs . $tab
. '
' . PHP_EOL;
$pos += ($cellAttr['height'] + $cellAttr['spacing']);
}
}
return $html;
}
/**
* Returns a polygonal progress structure as HTML.
*
* @return string
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _getProgressPolygonalToHtml()
{
$tabs = $this->_getTabs();
$tab = $this->_getTab();
$way_natural = ($this->fillWay == 'natural');
$cellAttr = $this->getCellAttributes();
$cellCls = sprintf($cellAttr['class'], $this->ident);
$coord = $this->getCellCoordinates();
$html = '';
if ($way_natural) {
for ($i = 0; $i < $this->cellCount; $i++) {
$top = $coord[$i][0] * $cellAttr['width'];
$left = $coord[$i][1] * $cellAttr['height'];
$html .= $tabs . $tab
. '
' . PHP_EOL;
}
} else {
$c = count($coord) - 1;
for ($i = 0; $i < $this->cellCount; $i++) {
$top = $coord[$c-$i][0] * $cellAttr['width'];
$left = $coord[$c-$i][1] * $cellAttr['height'];
$html .= $tabs . $tab
. '
' . PHP_EOL;
}
}
return $html;
}
/**
* Returns a circle progress structure as HTML.
*
* @return string
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _getProgressCircleToHtml()
{
$tabs = $this->_getTabs();
$tab = $this->_getTab();
$way_natural = ($this->fillWay == 'natural');
$cellAttr = $this->getCellAttributes();
$cellCls = sprintf($cellAttr['class'], $this->ident);
$html = '';
if ($way_natural) {
for ($i = 0; $i < $this->cellCount; $i++) {
$html .= $tabs . $tab
. '
'
. '
'
. PHP_EOL;
}
} else {
for ($i = 0; $i < $this->cellCount; $i++) {
$html .= $tabs . $tab
. '
'
. '
'
. PHP_EOL;
}
}
return $html;
}
/**
* Computes all coordinates of a standard polygon (square or rectangle).
*
* @param integer $w Polygon width
* @param integer $h Polygon height
*
* @return array
* @since version 2.0.0 (2005-10-01)
* @access private
* @see setCellCoordinates()
*/
function _computeCoordinates($w, $h)
{
$coord = array();
for ($y=0; $y<$h; $y++) {
if ($y == 0) {
// creates top side line
for ($x=0; $x<$w; $x++) {
$coord[] = array($y, $x);
}
} elseif ($y == ($h-1)) {
// creates bottom side line
for ($x=($w-1); $x>0; $x--) {
$coord[] = array($y, $x);
}
// creates left side line
for ($i=($h-1); $i>0; $i--) {
$coord[] = array($i, 0);
}
} else {
// creates right side line
$coord[] = array($y, $w - 1);
}
}
return $coord;
}
/**
* Updates the new size of progress bar, depending of cell size, cell count
* and border width.
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access private
* @see setOrientation(), setCellCount(), setCellAttributes(),
* setBorderAttributes()
*/
function _updateProgressSize()
{
if ($this->cellCount == 0) {
return;
}
$cell_width = $this->cell['width'];
$cell_height = $this->cell['height'];
$cell_spacing = $this->cell['spacing'];
$border_width = $this->border['width'];
$cell_count = $this->cellCount;
if ($this->orientation == HTML_PROGRESS2_BAR_HORIZONTAL) {
$w = ($cell_count * ($cell_width + $cell_spacing)) + $cell_spacing;
$h = $cell_height + (2 * $cell_spacing);
}
if ($this->orientation == HTML_PROGRESS2_BAR_VERTICAL) {
$w = $cell_width + (2 * $cell_spacing);
$h = ($cell_count * ($cell_height + $cell_spacing)) + $cell_spacing;
}
if ($this->orientation == HTML_PROGRESS2_POLYGONAL) {
$w = $cell_width * $this->_xgrid;
$h = $cell_height * $this->_ygrid;
}
if ($this->orientation == HTML_PROGRESS2_CIRCLE) {
$w = $cell_width;
$h = $cell_height;
}
$attr = array ('width' => $w, 'height' => $h);
$this->_updateAttrArray($this->_progress, $attr);
}
/**
* Calculate the new position in pixel of the progress bar value.
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _computePosition()
{
$orient = $this->orientation;
$progressAttr = $this->getProgressAttributes();
$min = $this->minimum;
$max = $this->maximum;
$step = $this->value;
$padding = 0;
if ($orient == HTML_PROGRESS2_BAR_HORIZONTAL) {
if ($this->fillWay == 'natural') {
$direction = 'right';
} else {
$direction = 'left';
}
} else {
if ($this->fillWay == 'natural') {
$direction = 'up';
} else {
$direction = 'down';
}
}
switch ($direction) {
case 'right':
case 'left':
$bar = $progressAttr['width'];
break;
case 'down':
case 'up':
$bar = $progressAttr['height'];
break;
}
$pixel = round(($step - $min) * ($bar - ($padding * 2)) / ($max - $min));
if ($step <= $min) {
$pixel = 0;
}
if ($step >= $max) {
$pixel = $bar - ($padding * 2);
}
switch ($direction) {
case 'right':
$position['left'] = $padding;
$position['top'] = $padding;
$position['width'] = $pixel;
$position['height'] = $progressAttr['height'] - ($padding * 2);
break;
case 'left':
$position['left'] = $progressAttr['width'] - $padding - $pixel;
$position['top'] = $padding;
$position['width'] = $pixel;
$position['height'] = $progressAttr['height'] - ($padding * 2);
break;
case 'down':
$position['left'] = $padding;
$position['top'] = $padding;
$position['width'] = $progressAttr['width'] - ($padding * 2);
$position['height'] = $pixel;
break;
case 'up':
$position['left'] = $padding;
$position['top'] = $progressAttr['height'] - $padding - $pixel;
$position['width'] = $progressAttr['width'] - ($padding * 2);
$position['height'] = $pixel;
break;
}
return $position;
}
/**
* Sends a DOM command (emulate firstChild.nodeValue)
* through a javascript function
* to change label value of a progress bar's element.
*
* @param string $element element name (label id.)
* @param string $text element value (label content)
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _changeLabelText($element, $text)
{
$cmd = '';
echo $cmd;
}
/**
* Sends a DOM command through a javascript function
* to change the next frame animation of a cross bar's element.
*
* @param string $element element name (cross id.)
*
* @return string
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _changeCrossItem($element)
{
$cmd = '';
echo $cmd;
}
/**
* Sends a DOM command (emulate cssText attribute) through a javascript function
* to change styles of a progress bar's element.
*
* @param string $styles styles of a DOM element
*
* @return string
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _changeElementStyle($styles)
{
$cmd = '';
return $cmd;
}
/**
* Post a new notification to all observers registered.
* This notification occured only if a dispatcher exists. That means if
* at least one observer was registered.
*
* @param string $event Name of the notification handler
* @param array $info (optional) Additional information about the notification
*
* @return void
* @since version 2.0.0RC2 (2005-08-01)
* @access private
*/
function _postNotification($event, $info = array())
{
if (isset($this->dispatcher)) {
$info['sender'] = get_class($this);
$info['time'] = microtime();
$this->dispatcher->post($this, $event, $info);
}
}
/**
* 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_Progress2_Error::_msgCallback()
* 'context_callback' A callback to generate context of error.
* Default is: HTML_Progress2_Error::getBacktrace()
* 'push_callback' A callback to determine whether to allow an error
* to be pushed or logged.
* Default is: HTML_Progress2_Error::_handleError()
* 'error_handler' A callback to manage all error raised.
* Default is: HTML_Progress2::_errorHandler()
* 'handler' Hash of params to configure all handlers
* (display, file, mail ...)
* There are only a display handler by default.
*
* @param array $prefs hash of params to configure error handler
*
* @return void
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _initErrorHandler($prefs = array())
{
// error message mapping callback
if (isset($prefs['message_callback'])
&& is_callable($prefs['message_callback'])) {
$this->_callback_message = $prefs['message_callback'];
} else {
$this->_callback_message = array('HTML_Progress2_Error', '_msgCallback');
}
// error context mapping callback
if (isset($prefs['context_callback'])
&& is_callable($prefs['context_callback'])) {
$this->_callback_context = $prefs['context_callback'];
} else {
$this->_callback_context = array('HTML_Progress2_Error', 'getBacktrace');
}
// determine whether to allow an error to be pushed or logged
if (isset($prefs['push_callback'])
&& is_callable($prefs['push_callback'])) {
$this->_callback_push = $prefs['push_callback'];
} else {
$this->_callback_push = array('HTML_Progress2_Error', '_handleError');
}
// default error handler will use PEAR_Error
if (isset($prefs['error_handler'])
&& is_callable($prefs['error_handler'])) {
$this->_callback_errorhandler = $prefs['error_handler'];
} else {
$this->_callback_errorhandler = array(&$this, '_errorHandler');
}
// any handler-specific settings
if (isset($prefs['handler'])) {
$this->_errorhandler_options = $prefs['handler'];
}
}
/**
* 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 integer $code Error code
* @param string $level Error level
* @param array $params Associative array of error parameters
*
* @return PEAR_Error
* @since version 2.0.0 (2005-10-01)
* @access private
*/
function _errorHandler($code, $level, $params)
{
include_once 'HTML/Progress2/Error.php';
$mode = call_user_func($this->_callback_push, $code, $level);
$message = call_user_func($this->_callback_message, $code, $params);
$userinfo['level'] = $level;
if (isset($this->_errorhandler_options['display'])) {
$userinfo['display'] = $this->_errorhandler_options['display'];
} else {
$userinfo['display'] = array();
}
if (isset($this->_errorhandler_options['log'])) {
$userinfo['log'] = $this->_errorhandler_options['log'];
} else {
$userinfo['log'] = array();
}
return PEAR::raiseError($message, $code,
$mode, null, $userinfo, 'HTML_Progress2_Error');
}
/**
* A basic wrapper around the default PEAR_Error object.
*
* This method throws any internal API error that could be raised
* due to a wrong programming. It will use your error handler system defined
* at class construction (by first argument).
*
* @return mixed
* @since version 2.0.0 (2005-10-01)
* @access public
* @see _errorHandler()
*/
function raiseError()
{
$args = func_get_args();
$err = call_user_func_array($this->_callback_errorhandler, $args);
if (is_null($err)) {
$err = array('code' => $args[0], 'level' => $args[1],
'params' => $args[2]);
}
array_push($this->_errorstack, $err);
return $err;
}
/**
* Determine whether there are errors into the HTML_Progress2 stack.
*
* This function gave you ability to be aware of API errors presence
* in user scripts.
*
* @return integer
* @since version 2.0.0 (2005-10-01)
* @access public
* @see getError(), raiseError()
*/
function hasErrors()
{
return count($this->_errorstack);
}
/**
* Pop an error off of the HTML_Progress2 stack.
*
* Get all error data (code, message, level, context)
* from an object (PEAR_Error, ...) or a simple php array.
*
* @return false|array|PEAR_Error
* @since version 2.0.0 (2005-10-01)
* @access public
* @see hasErrors(), raiseError()
*/
function getError()
{
return @array_shift($this->_errorstack);
}
}
?>