Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * PEAR::CompatInfo Web frontend
4
 *
5
 * PHP versions 4 and 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CompatInfo
9
 * @author   Laurent Laville <pear@laurent-laville.org>
10
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
11
 * @version  CVS: $Id: ci_frontend.php,v 1.6 2008/07/22 20:26:45 farell Exp $
12
 * @link     http://pear.php.net/package/PHP_CompatInfo
13
 * @ignore
14
 */
15
 
16
require_once 'PEAR/Registry.php';
17
require_once 'HTML/QuickForm.php';
18
require_once 'HTML/QuickForm/advmultiselect.php';
19
 
20
if (version_compare(phpversion(), '5.0.0', '<')) {
21
    include_once 'PHP/Compat.php';
22
    PHP_Compat::loadFunction('array_combine');
23
}
24
 
25
session_start();
26
$sess =& $_SESSION;
27
 
28
$config = new PEAR_Config();
29
$pear_install_dir = $config->get('php_dir');
30
$reg = new PEAR_Registry($pear_install_dir);
31
 
32
if (count($sess) == 0) {
33
 
34
    // PEAR packages installed from each channel
35
    $allpackages = $reg->listAllPackages();
36
    foreach ($allpackages as $channel => $packages) {
37
        if ($packages) {
38
            sort($packages, SORT_ASC);
39
            foreach ($packages as $package) {
40
                $info = &$reg->getPackage($package, $channel);
41
                if (is_object($info)) {
42
                    $name          = $info->getPackage();
43
                    $version       = $info->getVersion();
44
                    $release_state = $info->getState();
45
                } else {
46
                    $name          = $info['package'];
47
                    $version       = $info['version'];
48
                    $release_state = $info['state'];
49
                }
50
                $sess['packages'][$channel][] = "$name $version ($release_state)";
51
            }
52
        } else {
53
            $sess['packages'][$channel] = array();
54
        }
55
    }
56
 
57
    // channels
58
    $channels = array_keys($sess['packages']);
59
    array_unshift($channels, '');
60
    $sess['channels'] = array_combine($channels, $channels);
61
 
62
    // packages
63
    $names[''] = array();
64
    foreach ($sess['packages'] as $c => $p) {
65
        if (count($p)) {
66
            $l = array();
67
            foreach ($p as $k) {
68
                list($n, $v, $s) = explode(' ', $k);
69
                $l[] = $n;
70
            }
71
            $names[$c] = array_combine($l, $p);
72
        } else {
73
            $names[$c] = array();
74
        }
75
    }
76
    $sess['pkgnames'] = $names;
77
 
78
    // PHP internal functions
79
    $func = get_defined_functions();
80
    sort($func['internal']);
81
    $sess['phpfunctions'] = $func['internal'];
82
}
83
 
84
// ignore functions
85
$ignore_functions = array_combine($sess['phpfunctions'], $sess['phpfunctions']);
86
 
87
// web frontend
88
$form = new HTML_QuickForm('cife');
89
$form->removeAttribute('name');        // XHTML compliance
90
 
91
// header
92
$form->addElement('header', 'cife_hdr', 'CompatInfo :: Web frontend');
93
 
94
// ignore functions
95
$ams1 =& $form->addElement('advmultiselect', 'ignore_functions', null,
96
    $ignore_functions,
97
    array('size' => 5, 'style' => 'width:250px;', 'class' => 'pool'));
98
$ams1->setLabel(array('PHP functions:', 'available', 'ignore'));
99
 
100
// packages installed
101
$pkgInstalled =& $form->addElement('hierselect', 'package', null, array('class' => 'flat'), '&nbsp;');
102
$pkgInstalled->setLabel('Packages installed:');
103
$pkgInstalled->setOptions(array($sess['channels'], $sess['pkgnames']));
104
$form->addElement('submit', 'filelist', 'File List');
105
 
106
// ignore files
107
$safe = $form->getSubmitValues();
108
 
109
if (isset($safe['filelist'])) {
110
    $package = &$reg->getPackage($safe['package'][1], $safe['package'][0]);
111
    $files   = array();
112
 
113
    $filelist = $package->getFilelist();
114
    foreach ($filelist as $name => $atts) {
115
        if (isset($atts['role']) && $atts['role'] != 'php') {
116
            continue;
117
        }
118
        if (!preg_match('/\.php$/', $name)) {
119
            continue;
120
        }
121
        $files[] = $atts['installed_as'];
122
    }
123
    $sess['phpfiles'] = $files;
124
    $labels = str_replace($pear_install_dir . DIRECTORY_SEPARATOR, '', $files);
125
    $ignore_files = array_combine($files, $labels);
126
 
127
} else {
128
    $ignore_files = array();
129
}
130
 
131
$ams2 =& $form->addElement('advmultiselect', 'ignore_files', null,
132
    $ignore_files,
133
    array('size' => 5, 'style' => 'width:300px;', 'class' => 'pool'));
134
$ams2->setLabel(array('Package files (role=php):', 'available', 'ignore'));
135
 
136
// dump options
137
$dump =& $form->addElement('checkbox', 'dump');
138
$dump->setLabel('Dump:');
139
$dump->setText('PHP min version only');
140
 
141
$dbg =& $form->addElement('checkbox', 'dbg');
142
$dbg->setLabel('Debug:');
143
$dbg->setText('Extra output');
144
 
145
// commands
146
$form->addElement('submit', 'process', 'Process');
147
$form->addElement('submit', 'abort', 'Abort');
148
 
149
// initial values
150
$form->setDefaults(array(
151
    'ignore_functions' => array(),
152
    'ignore_files' => array(),
153
    'dump' => true
154
    ));
155
 
156
?>
157
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
158
    "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
159
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
160
<head>
161
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
162
<title>PEAR::PHP_CompatInfo Web frontend </title>
163
<style type="text/css">
164
<!--
165
body {
166
  background-color: #FFF;
167
  font-family: Verdana, Arial, helvetica;
168
  font-size: 10pt;
169
}
170
 
171
.error {
172
  color: red;
173
  font-weight: bold;
174
}
175
 
176
.dump {
177
  background-color: #EEE;
178
  color: black;
179
}
180
 
181
table.pool {
182
  border: 0;
183
  background-color: #339900;
184
  width:450px;
185
}
186
table.pool th {
187
  font-size: 80%;
188
  font-style: italic;
189
  text-align: left;
190
}
191
table.pool select {
192
  color: white;
193
  background-color: #006600;
194
}
195
 
196
.inputCommand {
197
    background-color: #d0d0d0;
198
    border: 1px solid #7B7B88;
199
    width: 7em;
200
    margin-bottom: 2px;
201
}
202
 -->
203
</style>
204
<script type="text/javascript">
205
//<![CDATA[
206
<?php
207
echo $ams1->getElementJs();
208
 
209
echo $ams2->getElementJs();
210
?>
211
//]]>
212
</script>
213
</head>
214
<body>
215
<?php
216
if ($form->validate()) {
217
    $safe = $form->getSubmitValues();
218
 
219
    if (isset($safe['ignore_files'])) {
220
        $ignore_files = $safe['ignore_files'];
221
    } else {
222
        $ignore_files = array();
223
    }
224
    if (isset($safe['ignore_functions'])) {
225
        $ignore_functions = $safe['ignore_functions'];
226
    } else {
227
        $ignore_functions = array();
228
    }
229
 
230
    if (!isset($sess['phpfiles']) && !isset($safe['abort'])) {
231
        echo '<p class="error">Please get file list before to process.</p>';
232
    } else {
233
        if (isset($safe['process'])) {
234
 
235
            include_once 'PHP/CompatInfo.php';
236
 
237
            $info = new PHP_CompatInfo();
238
 
239
            $options = array(
240
                'debug' => (isset($safe['dbg'])),
241
                'ignore_files' => $ignore_files,
242
                'ignore_functions' => $ignore_functions
243
                );
244
 
245
            $res = $info->parseArray($sess['phpfiles'], $options);
246
 
247
            $php = $res['version'];
248
 
249
            echo "<h1>CompatInfo for package {$safe['package'][1]}</h1>";
250
            echo "<h2>PHP $php min is required</h2>";
251
 
252
            if (!isset($safe['dump'])) {
253
                echo '<pre class="dump">';
254
                var_dump($res);
255
                echo '</pre>';
256
            }
257
        }
258
 
259
        if (isset($safe['process']) || isset($safe['abort'])) {
260
            // cleansweep before quit
261
            $_SESSION = array();
262
            session_destroy();
263
            if (isset($safe['abort'])) {
264
                echo '<h1>Task was aborted !</h1>';
265
            }
266
            exit();
267
        }
268
    }
269
}
270
 
271
$form->display();
272
?>
273
</body>
274
</html>