PageRenderTime 59ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/php/HTML/Progress.php

https://bitbucket.org/adarshj/convenient_website
PHP | 2269 lines | 1077 code | 183 blank | 1009 comment | 168 complexity | 16a413e49d70bb7e5cdb6e3b0bc22118 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * The HTML_Progress class allow you to add a loading bar
  4. * to any of your xhtml document.
  5. * You should have a browser that accept DHTML feature.
  6. *
  7. * PHP versions 4 and 5
  8. *
  9. * LICENSE: This source file is subject to version 3.0 of the PHP license
  10. * that is available through the world-wide-web at the following URI:
  11. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  12. * the PHP License and are unable to obtain it through the web, please
  13. * send a note to license@php.net so we can mail you a copy immediately.
  14. *
  15. * @category HTML
  16. * @package HTML_Progress
  17. * @author Laurent Laville <pear@laurent-laville.org>
  18. * @copyright 1997-2005 The PHP Group
  19. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  20. * @version CVS: $Id: Progress.php,v 1.15 2005/07/25 13:11:26 farell Exp $
  21. * @link http://pear.php.net/package/HTML_Progress
  22. * @tutorial HTML_Progress.pkg
  23. */
  24. require_once 'HTML/Progress/DM.php';
  25. require_once 'HTML/Progress/UI.php';
  26. /**#@+
  27. * Progress Bar shape types
  28. *
  29. * @var integer
  30. * @since 0.6
  31. */
  32. define ('HTML_PROGRESS_BAR_HORIZONTAL', 1);
  33. define ('HTML_PROGRESS_BAR_VERTICAL', 2);
  34. /**#@-*/
  35. /**#@+
  36. * Progress Bar shape types
  37. *
  38. * @var integer
  39. * @since 1.2.0RC1
  40. */
  41. define ('HTML_PROGRESS_POLYGONAL', 3);
  42. define ('HTML_PROGRESS_CIRCLE', 4);
  43. /**#@-*/
  44. /**
  45. * Basic error code that indicate a wrong input
  46. *
  47. * @var integer
  48. * @since 1.0
  49. */
  50. define ('HTML_PROGRESS_ERROR_INVALID_INPUT', -100);
  51. /**
  52. * Basic error code that indicate a wrong callback definition.
  53. * Allows only function or class-method structure.
  54. *
  55. * @var integer
  56. * @since 1.1
  57. */
  58. define ('HTML_PROGRESS_ERROR_INVALID_CALLBACK',-101);
  59. /**
  60. * Basic error code that indicate a deprecated method
  61. * that may be removed at any time from a future version
  62. *
  63. * @var integer
  64. * @since 1.2.0RC1
  65. */
  66. define ('HTML_PROGRESS_DEPRECATED', -102);
  67. /**#@+
  68. * One of five possible return values from the error Callback
  69. *
  70. * @see HTML_Progress::_handleError
  71. * @var integer
  72. * @since 1.2.0
  73. */
  74. /**
  75. * If this is returned, then the error will be both pushed onto the stack
  76. * and logged.
  77. */
  78. define('HTML_PROGRESS_ERRORSTACK_PUSHANDLOG', 1);
  79. /**
  80. * If this is returned, then the error will only be pushed onto the stack,
  81. * and not logged.
  82. */
  83. define('HTML_PROGRESS_ERRORSTACK_PUSH', 2);
  84. /**
  85. * If this is returned, then the error will only be logged, but not pushed
  86. * onto the error stack.
  87. */
  88. define('HTML_PROGRESS_ERRORSTACK_LOG', 3);
  89. /**
  90. * If this is returned, then the error is completely ignored.
  91. */
  92. define('HTML_PROGRESS_ERRORSTACK_IGNORE', 4);
  93. /**
  94. * If this is returned, then the error will only be logged, but not pushed
  95. * onto the error stack because will halt script execution.
  96. */
  97. define('HTML_PROGRESS_ERRORSTACK_LOGANDDIE', 5);
  98. /**#@-*/
  99. /**#@+
  100. * Log types for PHP's native error_log() function
  101. *
  102. * @see HTML_Progress::_errorHandler
  103. * @var integer
  104. * @since 1.2.0
  105. */
  106. /**
  107. * Use PHP's system logger
  108. */
  109. define('HTML_PROGRESS_LOG_TYPE_SYSTEM', 0);
  110. /**
  111. * Use PHP's mail() function
  112. */
  113. define('HTML_PROGRESS_LOG_TYPE_MAIL', 1);
  114. /**
  115. * Append to a file
  116. */
  117. define('HTML_PROGRESS_LOG_TYPE_FILE', 3);
  118. /**#@-*/
  119. /**
  120. * Global error message callback.
  121. * This will be used to generate the error message
  122. * from the error code.
  123. *
  124. * @global false|string|array $GLOBALS['_HTML_PROGRESS_CALLBACK_MESSAGE']
  125. * @since 1.2.0
  126. * @access private
  127. * @see HTML_Progress::_initErrorHandler
  128. */
  129. $GLOBALS['_HTML_PROGRESS_CALLBACK_MESSAGE'] = false;
  130. /**
  131. * Global error context callback.
  132. * This will be used to generate the error context for an error.
  133. *
  134. * @global false|string|array $GLOBALS['_HTML_PROGRESS_CALLBACK_CONTEXT']
  135. * @since 1.2.0
  136. * @access private
  137. * @see HTML_Progress::_initErrorHandler
  138. */
  139. $GLOBALS['_HTML_PROGRESS_CALLBACK_CONTEXT'] = false;
  140. /**
  141. * Global error push callback.
  142. * This will be called every time an error is pushed onto the stack.
  143. * The return value will be used to determine whether to allow
  144. * an error to be pushed or logged.
  145. *
  146. * @global false|string|array $GLOBALS['_HTML_PROGRESS_CALLBACK_PUSH']
  147. * @since 1.2.0
  148. * @access private
  149. * @see HTML_Progress::_initErrorHandler
  150. */
  151. $GLOBALS['_HTML_PROGRESS_CALLBACK_PUSH'] = false;
  152. /**
  153. * Global error handler callback.
  154. * This will handle any errors raised by this package.
  155. *
  156. * @global false|string|array $GLOBALS['_HTML_PROGRESS_CALLBACK_ERRORHANDLER']
  157. * @since 1.2.0
  158. * @access private
  159. * @see HTML_Progress::_initErrorHandler
  160. */
  161. $GLOBALS['_HTML_PROGRESS_CALLBACK_ERRORHANDLER'] = false;
  162. /**
  163. * Global associative array of key-value pairs
  164. * that are used to specify any handler-specific settings.
  165. *
  166. * @global array $GLOBALS['_HTML_PROGRESS_ERRORHANDLER_OPTIONS']
  167. * @since 1.2.0
  168. * @access private
  169. * @see HTML_Progress::_initErrorHandler
  170. */
  171. $GLOBALS['_HTML_PROGRESS_ERRORHANDLER_OPTIONS'] = array();
  172. /**
  173. * Global error stack for this package.
  174. *
  175. * @global array $GLOBALS['_HTML_PROGRESS_ERRORSTACK']
  176. * @since 1.2.0
  177. * @access private
  178. * @see HTML_Progress::raiseError
  179. */
  180. $GLOBALS['_HTML_PROGRESS_ERRORSTACK'] = array();
  181. /**
  182. * The HTML_Progress class allow you to add a loading bar
  183. * to any of your xhtml document.
  184. * You should have a browser that accept DHTML feature.
  185. *
  186. * PHP versions 4 and 5
  187. *
  188. * LICENSE: This source file is subject to version 3.0 of the PHP license
  189. * that is available through the world-wide-web at the following URI:
  190. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  191. * the PHP License and are unable to obtain it through the web, please
  192. * send a note to license@php.net so we can mail you a copy immediately.
  193. *
  194. * @category HTML
  195. * @package HTML_Progress
  196. * @author Laurent Laville <pear@laurent-laville.org>
  197. * @copyright 1997-2005 The PHP Group
  198. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  199. * @version Release: 1.2.2
  200. * @link http://pear.php.net/package/HTML_Progress
  201. */
  202. class HTML_Progress
  203. {
  204. /**
  205. * Whether the progress bar is in determinate or indeterminate mode.
  206. * The default is false.
  207. * An indeterminate progress bar continuously displays animation indicating
  208. * that an operation of unknown length is occuring.
  209. *
  210. * @var boolean
  211. * @since 1.0
  212. * @access private
  213. * @see setIndeterminate(), isIndeterminate()
  214. */
  215. var $_indeterminate;
  216. /**
  217. * Whether to display a border around the progress bar.
  218. * The default is false.
  219. *
  220. * @var boolean
  221. * @since 1.0
  222. * @access private
  223. * @see setBorderPainted(), isBorderPainted()
  224. */
  225. var $_paintBorder;
  226. /**
  227. * Whether to textually display a string on the progress bar.
  228. * The default is false.
  229. * Setting this to true causes a textual display of the progress to be rendered
  230. * on the progress bar. If the $_progressString is null, the percentage of completion
  231. * is displayed on the progress bar. Otherwise, the $_progressString is rendered
  232. * on the progress bar.
  233. *
  234. * @var boolean
  235. * @since 1.0
  236. * @access private
  237. * @see setStringPainted(), isStringPainted()
  238. */
  239. var $_paintString;
  240. /**
  241. * An optional string that can be displayed on the progress bar.
  242. * The default is null.
  243. * Setting this to a non-null value does not imply that the string
  244. * will be displayed.
  245. *
  246. * @var string
  247. * @since 1.0
  248. * @access private
  249. * @see getString(), setString()
  250. */
  251. var $_progressString;
  252. /**
  253. * The data model (HTML_Progress_DM instance or extends)
  254. * handles any mathematical issues arising from assigning faulty values.
  255. *
  256. * @var object
  257. * @since 1.0
  258. * @access private
  259. * @see getDM(), setDM()
  260. */
  261. var $_DM;
  262. /**
  263. * The user interface (HTML_Progress_UI instance or extends)
  264. * handles look-and-feel of the progress bar.
  265. *
  266. * @var object
  267. * @since 1.0
  268. * @access private
  269. * @see getUI(), setUI()
  270. */
  271. var $_UI;
  272. /**
  273. * The label that uniquely identifies this progress object.
  274. *
  275. * @var string
  276. * @since 1.0
  277. * @access private
  278. * @see getIdent(), setIdent()
  279. */
  280. var $_ident;
  281. /**
  282. * Holds all HTML_Progress_Observer objects that wish to be notified of new messages.
  283. *
  284. * @var array
  285. * @since 1.0
  286. * @access private
  287. * @see getListeners(), addListener(), removeListener()
  288. */
  289. var $_listeners;
  290. /**
  291. * Delay in milisecond before each progress cells display.
  292. * 1000 ms === sleep(1)
  293. * <strong>usleep()</strong> function does not run on Windows platform.
  294. *
  295. * @var integer
  296. * @since 1.1
  297. * @access private
  298. * @see setAnimSpeed()
  299. */
  300. var $_anim_speed;
  301. /**
  302. * Callback, either function name or array(&$object, 'method')
  303. *
  304. * @var mixed
  305. * @since 1.2.0RC3
  306. * @access private
  307. * @see setProgressHandler()
  308. */
  309. var $_callback = null;
  310. /**
  311. * Constructor Summary
  312. *
  313. * o Creates a natural horizontal progress bar that displays ten cells/units
  314. * with no border and no progress string.
  315. * The initial and minimum values are 0, and the maximum is 100.
  316. * <code>
  317. * $bar = new HTML_Progress();
  318. * </code>
  319. *
  320. * o Creates a natural progress bar with the specified orientation, which can be
  321. * either HTML_PROGRESS_BAR_HORIZONTAL or HTML_PROGRESS_BAR_VERTICAL
  322. * By default, no border and no progress string are painted.
  323. * The initial and minimum values are 0, and the maximum is 100.
  324. * <code>
  325. * $bar = new HTML_Progress($orient);
  326. * </code>
  327. *
  328. * o Creates a natural horizontal progress bar with the specified minimum and
  329. * maximum. Sets the initial value of the progress bar to the specified
  330. * minimum, and the maximum that the progress bar can reach.
  331. * By default, no border and no progress string are painted.
  332. * <code>
  333. * $bar = new HTML_Progress($min, $max);
  334. * </code>
  335. *
  336. * o Creates a natural horizontal progress bar with the specified orientation,
  337. * minimum and maximum. Sets the initial value of the progress bar to the
  338. * specified minimum, and the maximum that the progress bar can reach.
  339. * By default, no border and no progress string are painted.
  340. * <code>
  341. * $bar = new HTML_Progress($orient, $min, $max);
  342. * </code>
  343. *
  344. * o Creates a natural horizontal progress that uses the specified model
  345. * to hold the progress bar's data.
  346. * By default, no border and no progress string are painted.
  347. * <code>
  348. * $bar = new HTML_Progress($model);
  349. * </code>
  350. *
  351. *
  352. * @param object $model (optional) Model that hold the progress bar's data
  353. * @param int $orient (optional) Orientation of progress bar
  354. * @param int $min (optional) Minimum value of progress bar
  355. * @param int $max (optional) Maximum value of progress bar
  356. * @param array $errorPrefs (optional) Always last argument of class constructor.
  357. * hash of params to configure PEAR_ErrorStack and loggers
  358. *
  359. * @since 1.0
  360. * @access public
  361. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  362. * @see setIndeterminate(),
  363. * setBorderPainted(), setStringPainted(), setString(),
  364. * setDM(), setUI(), setIdent()
  365. */
  366. function HTML_Progress()
  367. {
  368. $args = func_get_args();
  369. $num_args = func_num_args();
  370. if ($num_args > 0) {
  371. $errorPrefs = func_get_arg($num_args - 1);
  372. if (!is_array($errorPrefs)) {
  373. $errorPrefs = array();
  374. } else {
  375. $num_args--;
  376. }
  377. HTML_Progress::_initErrorHandler($errorPrefs);
  378. } else {
  379. HTML_Progress::_initErrorhandler();
  380. }
  381. $this->_listeners = array(); // none listeners by default
  382. $this->_DM = new HTML_Progress_DM(); // new instance of a progress DataModel
  383. $this->_UI = new HTML_Progress_UI(); // new instance of a progress UserInterface
  384. switch ($num_args) {
  385. case 1:
  386. if (is_object($args[0]) && (is_a($args[0], 'html_progress_dm'))) {
  387. /* object html_progress_dm extends */
  388. $this->_DM = &$args[0];
  389. } elseif (is_int($args[0])) {
  390. /* int orient */
  391. $this->_UI->setOrientation($args[0]);
  392. } else {
  393. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  394. array('var' => '$model | $orient',
  395. 'was' => (gettype($args[0]) == 'object') ?
  396. get_class($args[0]).' object' : gettype($args[0]),
  397. 'expected' => 'html_progress_dm object | integer',
  398. 'paramnum' => 1));
  399. }
  400. break;
  401. case 2:
  402. /* int min, int max */
  403. if (!is_int($args[0])) {
  404. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  405. array('var' => '$min',
  406. 'was' => $args[0],
  407. 'expected' => 'integer',
  408. 'paramnum' => 1));
  409. } elseif (!is_int($args[1])) {
  410. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  411. array('var' => '$max',
  412. 'was' => $args[1],
  413. 'expected' => 'integer',
  414. 'paramnum' => 2));
  415. } else {
  416. $this->_DM->setMinimum($args[0]);
  417. $this->_DM->setMaximum($args[1]);
  418. }
  419. break;
  420. case 3:
  421. /* int orient, int min, int max */
  422. if (!is_int($args[0])) {
  423. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  424. array('var' => '$orient',
  425. 'was' => $args[0],
  426. 'expected' => 'integer',
  427. 'paramnum' => 1));
  428. } elseif (!is_int($args[1])) {
  429. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  430. array('var' => '$min',
  431. 'was' => $args[1],
  432. 'expected' => 'integer',
  433. 'paramnum' => 2));
  434. } elseif (!is_int($args[2])) {
  435. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  436. array('var' => '$max',
  437. 'was' => $args[2],
  438. 'expected' => 'integer',
  439. 'paramnum' => 3));
  440. } else {
  441. $this->_UI->setOrientation($args[0]);
  442. $this->_DM->setMinimum($args[1]);
  443. $this->_DM->setMaximum($args[2]);
  444. }
  445. break;
  446. default:
  447. }
  448. $this->setString(null);
  449. $this->setStringPainted(false);
  450. $this->setBorderPainted(false);
  451. $this->setIndeterminate(false);
  452. $this->setIdent();
  453. $this->setAnimSpeed(0);
  454. // to fix a potential php config problem with PHP 4.2.0 : turn 'implicit_flush' ON
  455. ob_implicit_flush(1);
  456. }
  457. /**
  458. * Returns the current API version
  459. *
  460. * @return float
  461. * @since 0.1
  462. * @access public
  463. */
  464. function apiVersion()
  465. {
  466. return 1.2;
  467. }
  468. /**
  469. * Returns mode of the progress bar (determinate or not).
  470. *
  471. * @return boolean
  472. * @since 1.0
  473. * @access public
  474. * @see setIndeterminate()
  475. * @tutorial progress.isindeterminate.pkg
  476. */
  477. function isIndeterminate()
  478. {
  479. return $this->_indeterminate;
  480. }
  481. /**
  482. * Sets the $_indeterminate property of the progress bar, which determines
  483. * whether the progress bar is in determinate or indeterminate mode.
  484. * An indeterminate progress bar continuously displays animation indicating
  485. * that an operation of unknown length is occuring.
  486. * By default, this property is false.
  487. *
  488. * @param boolean $continuous whether countinuously displays animation
  489. *
  490. * @return void
  491. * @since 1.0
  492. * @access public
  493. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  494. * @see isIndeterminate()
  495. * @tutorial progress.setindeterminate.pkg
  496. */
  497. function setIndeterminate($continuous)
  498. {
  499. if (!is_bool($continuous)) {
  500. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  501. array('var' => '$continuous',
  502. 'was' => gettype($continuous),
  503. 'expected' => 'boolean',
  504. 'paramnum' => 1));
  505. }
  506. $this->_indeterminate = $continuous;
  507. }
  508. /**
  509. * Determines whether the progress bar border is painted or not.
  510. * The default is false.
  511. *
  512. * @return boolean
  513. * @since 1.0
  514. * @access public
  515. * @see setBorderPainted()
  516. * @tutorial progress.isborderpainted.pkg
  517. */
  518. function isBorderPainted()
  519. {
  520. return $this->_paintBorder;
  521. }
  522. /**
  523. * Sets the value of $_paintBorder property, which determines whether the
  524. * progress bar should paint its border. The default is false.
  525. *
  526. * @param boolean $paint whether the progress bar should paint its border
  527. *
  528. * @return void
  529. * @since 1.0
  530. * @access public
  531. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  532. * @see isBorderPainted()
  533. * @tutorial progress.setborderpainted.pkg
  534. */
  535. function setBorderPainted($paint)
  536. {
  537. if (!is_bool($paint)) {
  538. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  539. array('var' => '$paint',
  540. 'was' => gettype($paint),
  541. 'expected' => 'boolean',
  542. 'paramnum' => 1));
  543. }
  544. $this->_paintBorder = $paint;
  545. }
  546. /**
  547. * Determines whether the progress bar string is painted or not.
  548. * The default is false.
  549. * The progress bar displays the value returned by getPercentComplete() method
  550. * formatted as a percent such as 33%.
  551. *
  552. * @return boolean
  553. * @since 1.0
  554. * @access public
  555. * @see setStringPainted(), setString()
  556. * @tutorial progress.isstringpainted.pkg
  557. */
  558. function isStringPainted()
  559. {
  560. return $this->_paintString;
  561. }
  562. /**
  563. * Sets the value of $_paintString property, which determines whether the
  564. * progress bar should render a progress string. The default is false.
  565. *
  566. * @param boolean $paint whether the progress bar should render a string
  567. *
  568. * @return void
  569. * @since 1.0
  570. * @access public
  571. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  572. * @see isStringPainted(), setString()
  573. * @tutorial progress.setstringpainted.pkg
  574. */
  575. function setStringPainted($paint)
  576. {
  577. if (!is_bool($paint)) {
  578. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  579. array('var' => '$paint',
  580. 'was' => gettype($paint),
  581. 'expected' => 'boolean',
  582. 'paramnum' => 1));
  583. }
  584. $this->_paintString = $paint;
  585. }
  586. /**
  587. * Returns the current value of the progress string.
  588. * By default, the progress bar displays the value returned by
  589. * getPercentComplete() method formatted as a percent such as 33%.
  590. *
  591. * @return string
  592. * @since 1.0
  593. * @access public
  594. * @see setString(), isStringPainted()
  595. * @tutorial progress.getstring.pkg
  596. */
  597. function getString()
  598. {
  599. if ($this->isStringPainted() && !is_null($this->_progressString)) {
  600. return $this->_progressString;
  601. } else {
  602. return sprintf("%s", $this->getPercentComplete(false)).' %';
  603. }
  604. }
  605. /**
  606. * Sets the current value of the progress string. By default, this string
  607. * is null. If you have provided a custom progress string and want to revert
  608. * to the built-in-behavior, set the string back to null.
  609. * The progress string is painted only if the isStringPainted() method
  610. * returns true.
  611. *
  612. * @param string $str progress string
  613. *
  614. * @return void
  615. * @since 1.0
  616. * @access public
  617. * @see getString(), isStringPainted(), setStringPainted()
  618. * @tutorial progress.setstring.pkg
  619. */
  620. function setString($str)
  621. {
  622. $this->_progressString = $str;
  623. }
  624. /**
  625. * Returns the data model used by this progress bar.
  626. *
  627. * @return object
  628. * @since 1.0
  629. * @access public
  630. * @see setDM()
  631. */
  632. function &getDM()
  633. {
  634. return $this->_DM;
  635. }
  636. /**
  637. * Sets the data model used by this progress bar.
  638. *
  639. * @param string $model class name of a html_progress_dm extends object
  640. *
  641. * @return void
  642. * @since 1.0
  643. * @access public
  644. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  645. * @see getDM()
  646. */
  647. function setDM($model)
  648. {
  649. if (!class_exists($model)) {
  650. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  651. array('var' => '$model',
  652. 'was' => 'class does not exists',
  653. 'expected' => $model.' class defined',
  654. 'paramnum' => 1));
  655. }
  656. $_dm = new $model();
  657. if (!is_a($_dm, 'html_progress_dm')) {
  658. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  659. array('var' => '$model',
  660. 'was' => $model,
  661. 'expected' => 'HTML_Progress_DM extends',
  662. 'paramnum' => 1));
  663. }
  664. $this->_DM =& $_dm;
  665. }
  666. /**
  667. * Returns the progress bar's minimum value stored in the progress bar's data model.
  668. * The default value is 0.
  669. *
  670. * @return integer
  671. * @since 1.0
  672. * @access public
  673. * @see setMinimum(),
  674. * HTML_Progress_DM::getMinimum()
  675. * @tutorial dm.getminimum.pkg
  676. */
  677. function getMinimum()
  678. {
  679. return $this->_DM->getMinimum();
  680. }
  681. /**
  682. * Sets the progress bar's minimum value stored in the progress bar's data model.
  683. * If the minimum value is different from previous minimum, all change listeners
  684. * are notified.
  685. *
  686. * @param integer $min progress bar's minimal value
  687. *
  688. * @return void
  689. * @since 1.0
  690. * @access public
  691. * @see getMinimum(),
  692. * HTML_Progress_DM::setMinimum()
  693. * @tutorial dm.setminimum.pkg
  694. */
  695. function setMinimum($min)
  696. {
  697. $oldVal = $this->getMinimum();
  698. $this->_DM->setMinimum($min);
  699. if ($oldVal != $min) {
  700. $this->_announce(array('log' => 'setMinimum', 'value' => $min));
  701. }
  702. }
  703. /**
  704. * Returns the progress bar's maximum value stored in the progress bar's data model.
  705. * The default value is 100.
  706. *
  707. * @return integer
  708. * @since 1.0
  709. * @access public
  710. * @see setMaximum(),
  711. * HTML_Progress_DM::getMaximum()
  712. * @tutorial dm.getmaximum.pkg
  713. */
  714. function getMaximum()
  715. {
  716. return $this->_DM->getMaximum();
  717. }
  718. /**
  719. * Sets the progress bar's maximum value stored in the progress bar's data model.
  720. * If the maximum value is different from previous maximum, all change listeners
  721. * are notified.
  722. *
  723. * @param integer $max progress bar's maximal value
  724. *
  725. * @return void
  726. * @since 1.0
  727. * @access public
  728. * @see getMaximum(),
  729. * HTML_Progress_DM::setMaximum()
  730. * @tutorial dm.setmaximum.pkg
  731. */
  732. function setMaximum($max)
  733. {
  734. $oldVal = $this->getMaximum();
  735. $this->_DM->setMaximum($max);
  736. if ($oldVal != $max) {
  737. $this->_announce(array('log' => 'setMaximum', 'value' => $max));
  738. }
  739. }
  740. /**
  741. * Returns the progress bar's increment value stored in the progress bar's data model.
  742. * The default value is +1.
  743. *
  744. * @return integer
  745. * @since 1.0
  746. * @access public
  747. * @see setIncrement(),
  748. * HTML_Progress_DM::getIncrement()
  749. * @tutorial dm.getincrement.pkg
  750. */
  751. function getIncrement()
  752. {
  753. return $this->_DM->getIncrement();
  754. }
  755. /**
  756. * Sets the progress bar's increment value stored in the progress bar's data model.
  757. *
  758. * @param integer $inc progress bar's increment value
  759. *
  760. * @return void
  761. * @since 1.0
  762. * @access public
  763. * @see getIncrement(),
  764. * HTML_Progress_DM::setIncrement()
  765. * @tutorial dm.setincrement.pkg
  766. */
  767. function setIncrement($inc)
  768. {
  769. $this->_DM->setIncrement($inc);
  770. }
  771. /**
  772. * Returns the progress bar's current value, which is stored in the
  773. * progress bar's data model. The value is always between the minimum
  774. * and maximum values, inclusive.
  775. * By default, the value is initialized to be equal to the minimum value.
  776. *
  777. * @return integer
  778. * @since 1.0
  779. * @access public
  780. * @see setValue(), incValue(),
  781. * HTML_Progress_DM::getValue()
  782. * @tutorial dm.getvalue.pkg
  783. */
  784. function getValue()
  785. {
  786. return $this->_DM->getValue();
  787. }
  788. /**
  789. * Sets the progress bar's current value stored in the progress bar's data model.
  790. * If the new value is different from previous value, all change listeners
  791. * are notified.
  792. *
  793. * @param integer $val progress bar's current value
  794. *
  795. * @return void
  796. * @since 1.0
  797. * @access public
  798. * @see getValue(), incValue(),
  799. * HTML_Progress_DM::setValue()
  800. * @tutorial dm.setvalue.pkg
  801. */
  802. function setValue($val)
  803. {
  804. $oldVal = $this->getValue();
  805. $this->_DM->setValue($val);
  806. if ($oldVal != $val) {
  807. $this->_announce(array('log' => 'setValue', 'value' => $val));
  808. }
  809. }
  810. /**
  811. * Updates the progress bar's current value by adding increment value.
  812. * All change listeners are notified.
  813. *
  814. * @return void
  815. * @since 1.0
  816. * @access public
  817. * @see getValue(), setValue(),
  818. * HTML_Progress_DM::incValue()
  819. * @tutorial dm.incvalue.pkg
  820. */
  821. function incValue()
  822. {
  823. $this->_DM->incValue();
  824. $this->_announce(array('log' => 'incValue', 'value' => $this->_DM->getValue() ));
  825. }
  826. /**
  827. * Returns the percent complete for the progress bar. Note that this number is
  828. * between 0.00 and 1.00 or 0 and 100.
  829. *
  830. * @param boolean $float (optional) float or integer format
  831. *
  832. * @return mixed
  833. * @since 1.0
  834. * @access public
  835. * @see getValue(), getMaximum(),
  836. * HTML_Progress_DM::getPercentComplete()
  837. * @tutorial dm.getpercentcomplete.pkg
  838. */
  839. function getPercentComplete($float = true)
  840. {
  841. return $this->_DM->getPercentComplete($float);
  842. }
  843. /**
  844. * Returns the look-and-feel object that renders the progress bar.
  845. *
  846. * @return object
  847. * @since 1.0
  848. * @access public
  849. * @see setUI()
  850. */
  851. function &getUI()
  852. {
  853. return $this->_UI;
  854. }
  855. /**
  856. * Sets the look-and-feel object that renders the progress bar.
  857. *
  858. * @param string $ui class name of a html_progress_ui extends object
  859. *
  860. * @return void
  861. * @since 1.0
  862. * @access public
  863. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  864. * @see getUI()
  865. */
  866. function setUI($ui)
  867. {
  868. if (!class_exists($ui)) {
  869. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  870. array('var' => '$ui',
  871. 'was' => 'class does not exists',
  872. 'expected' => $ui.' class defined',
  873. 'paramnum' => 1));
  874. }
  875. $_ui = new $ui();
  876. if (!is_a($_ui, 'html_progress_ui')) {
  877. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  878. array('var' => '$ui',
  879. 'was' => $ui,
  880. 'expected' => 'HTML_Progress_UI extends',
  881. 'paramnum' => 1));
  882. }
  883. $this->_UI =& $_ui;
  884. }
  885. /**
  886. * Sets the look-and-feel model that renders the progress bar.
  887. *
  888. * @param string $file file name of model properties
  889. * @param string $type type of external ressource (phpArray, iniFile, XML ...)
  890. *
  891. * @return void
  892. * @since 1.0
  893. * @access public
  894. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  895. * @see setUI()
  896. * @tutorial progress.setmodel.pkg
  897. */
  898. function setModel($file, $type)
  899. {
  900. if (!file_exists($file)) {
  901. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  902. array('var' => '$file',
  903. 'was' => $file,
  904. 'expected' => 'file exists',
  905. 'paramnum' => 1));
  906. }
  907. include_once 'Config.php';
  908. $conf = new Config();
  909. if (!$conf->isConfigTypeRegistered($type)) {
  910. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  911. array('var' => '$type',
  912. 'was' => $type,
  913. 'expected' => implode (" | ", array_keys($GLOBALS['CONFIG_TYPES'])),
  914. 'paramnum' => 2));
  915. }
  916. $data = $conf->parseConfig($file, $type);
  917. $structure = $data->toArray(false);
  918. $progress =& $structure['root'];
  919. $ui = new HTML_Progress_UI();
  920. if (isset($progress['core']['speed'])) {
  921. $this->setAnimSpeed(intval($progress['core']['speed']));
  922. }
  923. if (isset($progress['core']['indeterminate'])) {
  924. $mode = (strtolower(trim($progress['core']['indeterminate'])) == 'true');
  925. $this->setIndeterminate($mode);
  926. }
  927. if (isset($progress['core']['increment'])) {
  928. $this->setIncrement(intval($progress['core']['increment']));
  929. }
  930. if (isset($progress['core']['javascript']) && file_exists($progress['core']['javascript'])) {
  931. $ui->setScript($progress['core']['javascript']);
  932. }
  933. if (isset($progress['orientation']['shape'])) {
  934. $ui->setOrientation(intval($progress['orientation']['shape']));
  935. }
  936. if (isset($progress['orientation']['fillway'])) {
  937. $ui->setFillWay($progress['orientation']['fillway']);
  938. }
  939. if (isset($progress['cell']['count'])) {
  940. $ui->setCellCount(intval($progress['cell']['count']));
  941. }
  942. if (isset($progress['cell']['font-family'])) {
  943. if (is_array($progress['cell']['font-family'])) {
  944. $progress['cell']['font-family'] = implode(",", $progress['cell']['font-family']);
  945. }
  946. }
  947. if (isset($progress['cell'])) {
  948. $ui->setCellAttributes($progress['cell']);
  949. }
  950. if (isset($progress['border'])) {
  951. $this->setBorderPainted(true);
  952. $ui->setBorderAttributes($progress['border']);
  953. }
  954. if (isset($progress['string']['font-family'])) {
  955. if (is_array($progress['string']['font-family'])) {
  956. $progress['string']['font-family'] = implode(",", $progress['string']['font-family']);
  957. }
  958. }
  959. if (isset($progress['string'])) {
  960. $this->setStringPainted(true);
  961. $ui->setStringAttributes($progress['string']);
  962. }
  963. if (isset($progress['progress'])) {
  964. $ui->setProgressAttributes($progress['progress']);
  965. }
  966. $this->_UI = $ui;
  967. }
  968. /**
  969. * Returns delay execution of the progress bar
  970. *
  971. * @return integer
  972. * @since 1.2.0RC1
  973. * @access public
  974. * @see setAnimSpeed()
  975. * @tutorial progress.getanimspeed.pkg
  976. */
  977. function getAnimSpeed()
  978. {
  979. return $this->_anim_speed;
  980. }
  981. /**
  982. * Set the delays progress bar execution for the given number of miliseconds.
  983. *
  984. * @param integer $delay Delay in milisecond.
  985. *
  986. * @return void
  987. * @since 1.1
  988. * @access public
  989. * @throws HTML_PROGRESS_ERROR_INVALID_INPUT
  990. * @see getAnimSpeed()
  991. * @tutorial progress.setanimspeed.pkg
  992. */
  993. function setAnimSpeed($delay)
  994. {
  995. if (!is_int($delay)) {
  996. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  997. array('var' => '$delay',
  998. 'was' => gettype($delay),
  999. 'expected' => 'integer',
  1000. 'paramnum' => 1));
  1001. } elseif ($delay < 0) {
  1002. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  1003. array('var' => '$delay',
  1004. 'was' => $delay,
  1005. 'expected' => 'greater than zero',
  1006. 'paramnum' => 1));
  1007. } elseif ($delay > 1000) {
  1008. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  1009. array('var' => '$delay',
  1010. 'was' => $delay,
  1011. 'expected' => 'less or equal 1000',
  1012. 'paramnum' => 1));
  1013. }
  1014. $this->_anim_speed = $delay;
  1015. }
  1016. /**
  1017. * Get the cascading style sheet to put inline on HTML document
  1018. *
  1019. * @return string
  1020. * @since 1.0
  1021. * @access public
  1022. * @see HTML_Progress_UI::getStyle()
  1023. * @tutorial ui.getstyle.pkg
  1024. */
  1025. function getStyle()
  1026. {
  1027. $ui = $this->getUI();
  1028. $lnEnd = $ui->_getLineEnd();
  1029. $style = $lnEnd . $ui->getStyle();
  1030. $style = str_replace('{%pIdent%}', '.'.$this->getIdent(), $style);
  1031. return $style;
  1032. }
  1033. /**
  1034. * Get the javascript code to manage progress bar.
  1035. *
  1036. * @return string JavaScript URL or inline code to manage progress bar
  1037. * @since 1.0
  1038. * @access public
  1039. * @see HTML_Progress_UI::getScript()
  1040. * @tutorial ui.getscript.pkg
  1041. */
  1042. function getScript()
  1043. {
  1044. $ui = $this->getUI();
  1045. $js =& $ui->getScript();
  1046. return $js;
  1047. }
  1048. /**
  1049. * Returns the progress bar structure in an array.
  1050. *
  1051. * @return array of progress bar properties
  1052. * @since 1.0
  1053. * @access public
  1054. */
  1055. function toArray()
  1056. {
  1057. $ui =& $this->getUI();
  1058. $dm =& $this->getDM();
  1059. $_structure = array();
  1060. $_structure['id'] = $this->getIdent();
  1061. $_structure['indeterminate'] = $this->isIndeterminate();
  1062. $_structure['borderpainted'] = $this->isBorderPainted();
  1063. $_structure['stringpainted'] = $this->isStringPainted();
  1064. $_structure['string'] = $this->_progressString;
  1065. $_structure['animspeed'] = $this->getAnimSpeed();
  1066. $_structure['ui']['classID'] = get_class($ui);
  1067. $_structure['ui']['orientation'] = $ui->getOrientation();
  1068. $_structure['ui']['fillway'] = $ui->getFillWay();
  1069. $_structure['ui']['cell'] = $ui->getCellAttributes();
  1070. $_structure['ui']['cell']['count'] = $ui->getCellCount();
  1071. $_structure['ui']['border'] = $ui->getBorderAttributes();
  1072. $_structure['ui']['string'] = $ui->getStringAttributes();
  1073. $_structure['ui']['progress'] = $ui->getProgressAttributes();
  1074. $_structure['ui']['script'] = $ui->getScript();
  1075. $_structure['dm']['classID'] = get_class($dm);
  1076. $_structure['dm']['minimum'] = $dm->getMinimum();
  1077. $_structure['dm']['maximum'] = $dm->getMaximum();
  1078. $_structure['dm']['increment'] = $dm->getIncrement();
  1079. $_structure['dm']['value'] = $dm->getValue();
  1080. $_structure['dm']['percent'] = $dm->getPercentComplete(false);
  1081. return $_structure;
  1082. }
  1083. /**
  1084. * Returns the progress structure as HTML.
  1085. *
  1086. * @return string HTML Progress bar
  1087. * @since 0.2
  1088. * @access public
  1089. */
  1090. function toHtml()
  1091. {
  1092. $strHtml = '';
  1093. $ui =& $this->_UI;
  1094. $tabs = $ui->_getTabs();
  1095. $tab = $ui->_getTab();
  1096. $lnEnd = $ui->_getLineEnd();
  1097. $comment = $ui->getComment();
  1098. $orient = $ui->getOrientation();
  1099. $progressAttr = $ui->getProgressAttributes();
  1100. $borderAttr = $ui->getBorderAttributes();
  1101. $stringAttr = $ui->getStringAttributes();
  1102. $valign = strtolower($stringAttr['valign']);
  1103. /**
  1104. * Adds a progress bar legend in html code is possible.
  1105. * See HTML_Common::setComment() method.
  1106. */
  1107. if (strlen($comment) > 0) {
  1108. $strHtml .= $tabs . "<!-- $comment -->" . $lnEnd;
  1109. }
  1110. $strHtml .= $tabs . "<div id=\"".$this->getIdent()."_progress\" class=\"".$this->getIdent()."\">" . $lnEnd;
  1111. $strHtml .= $tabs . "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" . $lnEnd;
  1112. $progressId = $this->getIdent().'_';
  1113. /**
  1114. * Creates all cells of progress bar in order
  1115. * depending of the FillWay and Orientation.
  1116. */
  1117. if ($orient == HTML_PROGRESS_BAR_HORIZONTAL) {
  1118. $progressHtml = $this->_getProgressHbar_toHtml();
  1119. }
  1120. if ($orient == HTML_PROGRESS_BAR_VERTICAL) {
  1121. $progressHtml = $this->_getProgressVbar_toHtml();
  1122. }
  1123. if ($orient == HTML_PROGRESS_POLYGONAL) {
  1124. $progressHtml = $this->_getProgressPolygonal_toHtml();
  1125. }
  1126. if ($orient == HTML_PROGRESS_CIRCLE) {
  1127. $cellAttr = $ui->getCellAttributes();
  1128. if (!isset($cellAttr[0]['background-image']) || !file_exists($cellAttr[0]['background-image'])) {
  1129. // creates default circle segments pictures :
  1130. // 'c0.png'->0% 'c1.png'->10%, 'c2.png'->20%, ... 'c10.png'->100%
  1131. $ui->drawCircleSegments();
  1132. }
  1133. $progressHtml = $this->_getProgressCircle_toHtml();
  1134. }
  1135. /**
  1136. * Progress Bar (2) alignment rules:
  1137. * - percent / messsage area (1)
  1138. *
  1139. * +---------------------------------------+
  1140. * | +t1---+ |
  1141. * | | (1) | |
  1142. * | +-----+ |
  1143. * | +t2---+ +-------------------+ +t3---+ |
  1144. * | | (1) | | | | | (2) | | | | | | (1) | |
  1145. * | +-----+ +-------------------+ +-----+ |
  1146. * | +t4---+ |
  1147. * | | (1) | |
  1148. * | +-----+ |
  1149. * +---------------------------------------+
  1150. */
  1151. if (($valign == 'left') || ($valign == 'right')) {
  1152. $tRows = 1;
  1153. $tCols = 2;
  1154. $ps = ($valign == 'left') ? 0 : 1;
  1155. } else {
  1156. $tRows = 2;
  1157. $tCols = 1;
  1158. $ps = ($valign == 'top') ? 0 : 1;
  1159. }
  1160. for ($r = 0 ; $r < $tRows ; $r++) {
  1161. $strHtml .= $tabs . "<tr>" . $lnEnd;
  1162. for ($c = 0 ; $c < $tCols ; $c++) {
  1163. if (($c == $ps) || ($r == $ps)) {
  1164. $id = $stringAttr['id'];
  1165. $strHtml .= $tabs . $tab . "<td class=\"$id\" id=\"$progressId$id\">" . $lnEnd;
  1166. $strHtml .= $tabs . $tab . $tab . $this->getString() . $lnEnd;
  1167. $ps = -1;
  1168. } else {
  1169. $class = $progressAttr['class'];
  1170. $strHtml .= $tabs . $tab ."<td class=\"$class\">" . $lnEnd;
  1171. $strHtml .= $tabs . $tab . $tab . "<div class=\"".$borderAttr['class']."\">" . $lnEnd;
  1172. $strHtml .= $progressHtml;
  1173. $strHtml .= $tabs . $tab . $tab . "</div>" . $lnEnd;
  1174. }
  1175. $strHtml .= $tabs . $tab ."</td>" . $lnEnd;
  1176. }
  1177. $strHtml .= $tabs . "</tr>" . $lnEnd;
  1178. }
  1179. $strHtml .= $tabs . "</table>" . $lnEnd;
  1180. $strHtml .= $tabs . "</div>" . $lnEnd;
  1181. return $strHtml;
  1182. }
  1183. /**
  1184. * Renders the new value of progress bar.
  1185. *
  1186. * @return void
  1187. * @since 0.2
  1188. * @access public
  1189. */
  1190. function display()
  1191. {
  1192. static $lnEnd;
  1193. static $cellAmount;
  1194. static $determinate;
  1195. if(!isset($lnEnd)) {
  1196. $ui =& $this->_UI;
  1197. $lnEnd = $ui->_getLineEnd();
  1198. $cellAmount = ($this->getMaximum() - $this->getMinimum()) / $ui->getCellCount();
  1199. }
  1200. if (function_exists('ob_get_clean')) {
  1201. $bar = ob_get_clean(); // use for PHP 4.3+
  1202. } else {
  1203. $bar = ob_get_contents(); // use for PHP 4.2+
  1204. ob_end_clean();
  1205. }
  1206. $bar .= $lnEnd;
  1207. $progressId = $this->getIdent().'_';
  1208. if ($this->isIndeterminate()) {
  1209. if (isset($determinate)) {
  1210. $determinate++;
  1211. $progress = $determinate;
  1212. } else {
  1213. $progress = $determinate = 1;
  1214. }
  1215. } else {
  1216. $progress = ($this->getValue() - $this->getMinimum()) / $cellAmount;
  1217. $determinate = 0;
  1218. }
  1219. $bar .= '<script type="text/javascript">self.setprogress("'.$progressId.'",'.((int) $progress).',"'.$this->getString().'",'.$determinate.'); </script>';
  1220. echo $bar;
  1221. ob_start();
  1222. }
  1223. /**
  1224. * Hides the progress bar.
  1225. *
  1226. * @return void
  1227. * @since 1.2.0RC3
  1228. * @access public
  1229. */
  1230. function hide()
  1231. {
  1232. $ui = $this->getUI();
  1233. $lnEnd = $ui->_getLineEnd();
  1234. $progressId = $this->getIdent().'_';
  1235. if (function_exists('ob_get_clean')) {
  1236. $bar = ob_get_clean(); // use for PHP 4.3+
  1237. } else {
  1238. $bar = ob_get_contents(); // use for PHP 4.2+
  1239. ob_end_clean();
  1240. }
  1241. $bar .= $lnEnd;
  1242. $bar .= '<script type="text/javascript">self.hideProgress("'.$progressId.'"); </script>';
  1243. echo $bar;
  1244. }
  1245. /**
  1246. * Default user callback when none are defined.
  1247. * Delay execution of progress meter for the given number of milliseconds.
  1248. *
  1249. * NOTE: The function {@link http://www.php.net/manual/en/function.usleep.php}
  1250. * did not work on Windows systems until PHP 5.0.0
  1251. *
  1252. * @return void
  1253. * @since 1.2.0RC3
  1254. * @access public
  1255. * @see getAnimSpeed(), setAnimSpeed(), process()
  1256. */
  1257. function sleep()
  1258. {
  1259. // convert delay from milliseconds to microseconds
  1260. $usecs = $this->getAnimSpeed()*1000;
  1261. if ((substr(PHP_OS, 0, 3) == 'WIN') && (substr(PHP_VERSION,0,1) < '5') ){
  1262. for ($i=0; $i<$usecs; $i++) { }
  1263. } else {
  1264. usleep($usecs);
  1265. }
  1266. }
  1267. /**
  1268. * Sets the user callback function that execute all actions pending progress
  1269. *
  1270. * @param mixed $handler Name of function or a class-method.
  1271. *
  1272. * @return void
  1273. * @since 1.2.0RC3
  1274. * @access public
  1275. * @throws HTML_PROGRESS_ERROR_INVALID_CALLBACK
  1276. * @see process()
  1277. */
  1278. function setProgressHandler($handler)
  1279. {
  1280. if (!is_callable($handler)) {
  1281. return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_CALLBACK, 'warning',
  1282. array('var' => '$handler',
  1283. 'element' => 'valid Class-Method/Function',
  1284. 'was' => 'element',
  1285. 'paramnum' => 1));
  1286. }
  1287. $this->_callback = $handler;
  1288. }
  1289. /**
  1290. * Performs the progress actions
  1291. *
  1292. * @return void
  1293. * @since 1.2.0RC3
  1294. * @access public
  1295. * @see sleep()
  1296. */
  1297. function process()
  1298. {
  1299. if (!$this->_callbackExists($this->_callback)) {
  1300. // when there is no valid user callback then default is to sleep a bit ...
  1301. $this->sleep();
  1302. } else {
  1303. call_user_func_array($this->_callback, array($this->getValue(), &$this));
  1304. }
  1305. }
  1306. /**
  1307. * Runs the progress bar (both modes: indeterminate and determinate),
  1308. * and execute all actions defined in user callback identified by
  1309. * method setProgressHandler.
  1310. *
  1311. * @return void
  1312. * @since 1.2.0RC3
  1313. * @access public
  1314. * @see process(), setProgressHandler()
  1315. */
  1316. function run()
  1317. {
  1318. do {
  1319. $this->display();
  1320. $this->process();
  1321. if ($this->getPercentComplete() == 1) {
  1322. if ($this->isIndeterminate()) {
  1323. $this->setValue(0);
  1324. } else {
  1325. return;
  1326. }
  1327. }
  1328. $this->incValue();
  1329. } while(1);
  1330. }
  1331. /**
  1332. * Returns the current identification string.
  1333. *
  1334. * @return string current Progress instance's identification string
  1335. * @since 1.0
  1336. * @access public
  1337. * @see setIdent()
  1338. */
  1339. function getIdent()
  1340. {
  1341. return $this->_ident;
  1342. }
  1343. /**
  1344. * Sets this Progress instance's identification string.
  1345. *
  1346. * @param mixed $ident (optional) the new identification string.
  1347. *
  1348. * @since 1.0
  1349. * @access public
  1350. * @see getIdent()
  1351. */
  1352. function setIdent($ident = null)
  1353. {
  1354. if (is_null($ident)) {
  1355. $this->_ident = 'p_' . substr(md5(microtime()), 0, 6);
  1356. } else {
  1357. $this->_ident = $ident;
  1358. }
  1359. }
  1360. /**
  1361. * Returns an array of all the listeners added to this progress bar.
  1362. *
  1363. * @return array
  1364. * @since 1.0
  1365. * @access public
  1366. * @see addListener(), removeListener()
  1367. * @tutorial progress.getlisteners.pkg
  1368. */
  1369. function getListeners()
  1370. {
  1371. return $this->_listeners;
  1372. }
  1373. /**
  1374. * Adds a HTML_Progress_Observer instance to the list of observers
  1375. * that are listening for messages emitted by this HTML_Progress instance.
  1376. *
  1377. * @param object $observer The HTML_Progress_Observer instance
  1378. * to attach as a listener.
  1379. *
  1380. * @return boolean True if the observer is successfully attached.
  1381. * @since 1.0
  1382. * @access public
  1383. * @see getListeners(), removeListener()
  1384. * @tutorial progress.addlistener.pkg
  1385. */
  1386. function addListener($observer)
  1387. {
  1388. if (!is_a($observer, 'HTML_Progress_Observer') &&
  1389. !is_a($observer, 'HTML_Progress_Monitor'))

Large files files are truncated, but you can click here to view the full file