| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Parse a folder and wait with an HTML Progress bar
|
|
|
4 |
*
|
|
|
5 |
* This example show the new options|features available with API 1.8.0
|
|
|
6 |
*
|
|
|
7 |
* PHP versions 4 and 5
|
|
|
8 |
*
|
|
|
9 |
* @category PHP
|
|
|
10 |
* @package PHP_CompatInfo
|
|
|
11 |
* @author Laurent Laville <pear@laurent-laville.org>
|
|
|
12 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD
|
|
|
13 |
* @version CVS: $Id: pci180_parsefolder_tohtml.php,v 1.2 2008/07/22 20:26:45 farell Exp $
|
|
|
14 |
* @link http://pear.php.net/package/PHP_CompatInfo
|
|
|
15 |
* @since version 1.8.0b4 (2008-06-18)
|
|
|
16 |
* @ignore
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
require_once 'HTML/Progress2.php';
|
|
|
20 |
require_once 'PHP/CompatInfo.php';
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* @ignore
|
|
|
24 |
*/
|
|
|
25 |
class myClass
|
|
|
26 |
{
|
|
|
27 |
function doSomething()
|
|
|
28 |
{
|
|
|
29 |
global $bar;
|
|
|
30 |
|
|
|
31 |
// You may also use, all others renderer available
|
|
|
32 |
$driverType = 'html';
|
|
|
33 |
$driverOptions = array('args' => array('output-level' => 18));
|
|
|
34 |
|
|
|
35 |
$info = new PHP_CompatInfo($driverType, $driverOptions);
|
|
|
36 |
$info->addListener(array(&$bar, 'notify'));
|
|
|
37 |
$dir = 'C:\Temp\beehiveforum082\forum';
|
|
|
38 |
$opt = array();
|
|
|
39 |
|
|
|
40 |
// You may use the new unified method parseData(), parseDir() became an alias
|
|
|
41 |
$info->parseData($dir, $opt);
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* @ignore
|
|
|
47 |
*/
|
|
|
48 |
class myBar extends HTML_Progress2
|
|
|
49 |
{
|
|
|
50 |
// number of file to parse
|
|
|
51 |
var $_fileCount;
|
|
|
52 |
|
|
|
53 |
function myBar()
|
|
|
54 |
{
|
|
|
55 |
parent::HTML_Progress2();
|
|
|
56 |
|
|
|
57 |
$this->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'txt1');
|
|
|
58 |
$this->setLabelAttributes('txt1', array(
|
|
|
59 |
'valign' => 'top',
|
|
|
60 |
'left' => 0,
|
|
|
61 |
));
|
|
|
62 |
$this->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'txt2');
|
|
|
63 |
$this->setLabelAttributes('txt2', array(
|
|
|
64 |
'valign' => 'bottom',
|
|
|
65 |
'left' => 0,
|
|
|
66 |
));
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
function notify(&$notification)
|
|
|
70 |
{
|
|
|
71 |
$notifyName = $notification->getNotificationName();
|
|
|
72 |
$notifyInfo = $notification->getNotificationInfo();
|
|
|
73 |
|
|
|
74 |
switch ($notifyName) {
|
|
|
75 |
case PHP_COMPATINFO_EVENT_AUDITSTARTED :
|
|
|
76 |
$this->_fileCount = $notifyInfo['dataCount'];
|
|
|
77 |
// to keep the good proportion with default increment (+1)
|
|
|
78 |
$this->setMaximum($this->_fileCount);
|
|
|
79 |
break;
|
|
|
80 |
case PHP_COMPATINFO_EVENT_FILESTARTED :
|
|
|
81 |
$current = $notifyInfo['fileindex'];
|
|
|
82 |
$max = $this->_fileCount;
|
|
|
83 |
$file = basename($notifyInfo['filename']);
|
|
|
84 |
|
|
|
85 |
$this->setLabelAttributes('txt1',
|
|
|
86 |
array('value' => $current.'/'.$max.' files'));
|
|
|
87 |
$this->setLabelAttributes('txt2',
|
|
|
88 |
array('value' => $file));
|
|
|
89 |
break;
|
|
|
90 |
case PHP_COMPATINFO_EVENT_FILEFINISHED :
|
|
|
91 |
$this->moveNext();
|
|
|
92 |
break;
|
|
|
93 |
case PHP_COMPATINFO_EVENT_AUDITFINISHED :
|
|
|
94 |
$this->hide(); // progress bar hidden
|
|
|
95 |
break;
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
set_time_limit(0); // because parsing a huge folder may exceed 30 seconds
|
|
|
101 |
$bar = new myBar();
|
|
|
102 |
?>
|
|
|
103 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
|
104 |
"http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
|
105 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
|
106 |
<head>
|
|
|
107 |
<title>Parse a folder and wait with an HTML progress bar</title>
|
|
|
108 |
<style type="text/css">
|
|
|
109 |
<!--
|
|
|
110 |
<?php echo $bar->getStyle(); ?>
|
|
|
111 |
|
|
|
112 |
body {
|
|
|
113 |
background-color: #FFFFFF;
|
|
|
114 |
}
|
|
|
115 |
-->
|
|
|
116 |
</style>
|
|
|
117 |
<?php echo $bar->getScript(false); ?>
|
|
|
118 |
</head>
|
|
|
119 |
<body>
|
|
|
120 |
|
|
|
121 |
<?php
|
|
|
122 |
$bar->display();
|
|
|
123 |
|
|
|
124 |
$process = new myClass();
|
|
|
125 |
$process->doSomething();
|
|
|
126 |
?>
|
|
|
127 |
|
|
|
128 |
</body>
|
|
|
129 |
</html>
|