Subversion Repositories Applications.gtt

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 jpm 1
<?php
2
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP version 4                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2002 The PHP Group                                |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.0 of the PHP license,       |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
16
// | Authors: Davey Shafik <davey@pixelated-dreams.com>                   |
17
// +----------------------------------------------------------------------+
18
//
19
// $Id: Info.php,v 1.19 2005/01/03 17:33:43 davey Exp $
20
 
21
require_once 'PEAR/Remote.php';
22
require_once 'PEAR/Registry.php';
23
 
24
/**
25
 * PEAR_Info generate phpinfo() style PEAR information
26
 */
27
 
28
class PEAR_Info
29
{
30
 
31
    /**
32
     * PEAR_Info Constructor
33
     * @param pear_dir string[optional]
34
     * @return bool
35
     * @access public
36
     */
37
 
38
    function PEAR_Info($pear_dir = FALSE, $pear_user_config = FALSE)
39
    {
40
        if($pear_user_config === FALSE) {
41
            $this->config = new PEAR_Config();
42
        } else {
43
           $this->config = new PEAR_Config($pear_user_config);
44
        }
45
        if ($pear_dir != FALSE) {
46
            $this->config->set('php_dir',$pear_dir);
47
        }
48
        if (defined('PEAR_INFO_PROXY')) {
49
            $this->config->set('http_proxy',PEAR_INFO_PROXY);
50
        }
51
        $this->r = new PEAR_Remote($this->config);
52
        $this->reg = new PEAR_Registry($this->config->get('php_dir'));
53
        // get PEARs packageInfo to show version number at the top of the HTML
54
        $pear = $this->reg->packageInfo("PEAR");
55
        $this->list_options = false;
56
        if ($this->config->get('preferred_state') == 'stable') {
57
            $this->list_options = true;
58
        }
59
        ob_start();
60
        ?>
61
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
62
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
63
    <head>
64
        <title>PEAR :: PEAR_Info()</title>
65
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
66
        <style type="text/css">
67
            body {background-color: #ffffff; color: #000000; white-space: normal;}
68
            body, td, th, h1, h2 {font-family: sans-serif;}
69
            a:link {color: #006600; text-decoration: none;}
70
            a:visited { color: #003300; text-decoration: none;}
71
            a:hover {text-decoration: underline;}
72
            table {border-collapse: collapse; width: 600px; max-width: 600px; margin-left: auto; margin-right: auto; border: 0px; padding: 0px;}
73
            td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
74
            h1 {font-size: 150%; text-align: center;}
75
            h2 {font-size: 125%; text-align: center;}
76
            .p {text-align: left;}
77
            .e {background-color: #006600; font-weight: bold; color: #FFFFFF; width: 100px;}
78
            .e a:link { color: #FFFFFF; }
79
            .e a:visited { color: #FFFFFF; }
80
            .h {background-color: #339900; font-weight: bold;}
81
            .v {background-color: #D9D9D9;}
82
            img {float: right; border: 0px;}
83
        </style>
84
    </head>
85
    <body>
86
        <table>
87
            <tr class="h">
88
                <td>
89
                    <a href="http://pear.php.net/"><img src="<?php echo $_SERVER['PHP_SELF'];?>?pear_image=true" alt="PEAR Logo" /></a><h1 class="p">PEAR <?php echo $pear['version']; ?></h1>
90
                </td>
91
            </tr>
92
        </table>
93
    <?php
94
            if (!isset($_GET['credits'])) {
95
                echo '<h1><a href="' .$_SERVER['PHP_SELF']. '?credits=true">PEAR Credits</a></h1>';
96
                // Get packageInfo and Show the HTML for the Packages
97
                $this->getConfig();
98
                echo '<br />';
99
                $this->getPackages();
100
 
101
            } else {
102
                $this->getCredits();
103
            }
104
        ?>
105
    </body>
106
</html>
107
        <?php
108
        $this->info = ob_get_contents();
109
        ob_end_clean();
110
        /* With later versions of this where we properly implement the CLI such and stuff
111
        this will return the actual status of whether or not creating the PEAR_Info object worked */
112
        return true;
113
    }
114
 
115
    /**
116
     * Set PEAR http_proxy for remote calls
117
     * @param proxy string
118
     * @return bool
119
     * @access public
120
     */
121
 
122
    function setProxy($proxy)
123
    {
124
        define('PEAR_INFO_PROXY',$proxy);
125
        return true;
126
    }
127
 
128
    /**
129
     * Retrieve and format PEAR Packages info
130
     * @return void
131
     * @access private
132
     */
133
 
134
    function getPackages()
135
    {
136
        $latest = @$this->r->call('package.listLatestReleases');
137
        $available = $this->reg->listPackages();
138
        if (PEAR::isError($available)) {
139
            echo '<h1 style="font-size: 12px;">An Error occured fetching the package list. Please try again.</h1>';
140
            return FALSE;
141
        }
142
        if (!is_array($available)) {
143
            echo '<h1 style="font-size: 12px;">The package list could not be fetched from the remote server. Please try again.</h1>';
144
            return FALSE;
145
        }
146
        natcasesort($available);
147
        if ((PEAR::isError($latest)) || (!is_array($latest))) {
148
            $latest = FALSE;
149
        }
150
        $packages = '';
151
        foreach ($available as $name) {
152
            $installed = $this->reg->packageInfo($name);
153
            if (strlen($installed['package']) > 1) {
154
                if (!isset($old_index)) {
155
                    $old_index = '';
156
                }
157
                $current_index = $name{0};
158
                if (strtolower($current_index) != strtolower($old_index)) {
159
                    $packages .= '<a name="' .$current_index. '"></a>';
160
                    $old_index = $current_index;
161
                    $this->index[] = $current_index;
162
                }
163
                $packages .= '
164
        <h2><a name="pkg_' .trim($installed['package']). '">' .trim($installed['package']). '</a></h2>
165
        <table>
166
            <tr class="v">
167
                <td class="e">
168
                    Summary
169
                </td>
170
                <td>
171
                    ' .nl2br(htmlentities(trim($installed['summary']))). '
172
                </td>
173
            </tr>
174
            <tr class="v">
175
                <td class="e">
176
                    Version
177
                </td>
178
                <td>
179
                    ' .trim($installed['version']). '
180
                </td>
181
            </tr>
182
            <tr class="v">
183
                <td class="e">
184
                    Description
185
                </td>
186
                <td>
187
                    ' .nl2br(htmlentities(trim($installed['description']))). '
188
                </td>
189
            </tr>
190
            <tr class="v">
191
                <td class="e">
192
                    State
193
                </td>
194
                <td>
195
                    ' .trim($installed['release_state']). '
196
                </td>
197
            </tr>
198
            <tr class="v">
199
                <td class="e">
200
                    Information
201
                </td>
202
            </tr>';
203
            if ($latest != FALSE) {
204
            	if (isset($latest[$installed['package']])) {
205
                	if (version_compare($latest[$installed['package']]['version'],$installed['version'],'>')) {
206
	                    $packages .= '<tr class="v">
207
	                    <td class="e">
208
	                        Latest Version
209
	                    </td>
210
	                    <td>
211
	                        <a href="http://pear.php.net/get/' .trim($installed['package']). '">' .$latest[$installed['package']]['version'] . '</a>
212
	                        ('. $latest[$installed['package']]['state']. ')
213
	                    </td>
214
	                    </tr>';
215
	                }
216
            	}
217
            }
218
        $packages .= '          <tr>
219
                <td colspan="2" class="v"><a href="#top">Top</a></td>
220
            </tr>
221
        </table>';
222
            }
223
        }
224
        ?>
225
        <h2><a name="top">PEAR Packages</a></h2>
226
        <table style="padding: 3px;">
227
            <tr>
228
                <td class="e">
229
                    Index
230
                </td>
231
            </tr>
232
            <tr>
233
                <td class ="v" style="text-align: center">
234
        <?php
235
        foreach ($this->index as $i) {
236
            ?>
237
            | <a href="#<?php echo $i; ?>"><?php echo strtoupper($i); ?></a>
238
            <?php
239
        }
240
        ?>|
241
                </td>
242
            </tr>
243
        </table>
244
        <br />
245
        <?php
246
        echo $packages;
247
    }
248
 
249
    /**
250
     * Retrieves and formats the PEAR Config data
251
     * @return void
252
     * @access private
253
     */
254
 
255
    function getConfig()
256
    {
257
        $keys = $this->config->getKeys();
258
        sort($keys);
259
        ?>
260
        <h2>PEAR Config</h2>
261
        <table>
262
        <?php
263
        foreach ($keys as $key) {
264
            if (($key != 'password') && ($key != 'username') && ($key != 'sig_keyid') && ($key != 'http_proxy')) {
265
                ?>
266
                <tr class="v">
267
                    <td class="e"><?php echo $key; ?></td>
268
                    <td><?php echo $this->config->get($key); ?></td>
269
                </tr>
270
                <?php
271
            }
272
        }
273
        ?>
274
        </table>
275
        <?php
276
    }
277
 
278
    /**
279
     * Retrieves and formats the PEAR Credits
280
     * @return void
281
     * @access private
282
     */
283
 
284
    function getCredits()
285
    {
286
        ?>
287
        <h1>PEAR Credits</h1>
288
        <table>
289
            <tr class="h">
290
                <td>
291
                    PEAR Website Team
292
                </td>
293
            </tr>
294
            <tr class="v">
295
                <td>
296
                    <a href="http://pear.php.net/account-info.php?handle=ssb">Stig Bakken</a>,
297
                    <a href="http://pear.php.net/account-info.php?handle=cox">Thomas V.V.Cox</a>,
298
                    <a href="http://pear.php.net/account-info.php?handle=mj">Martin Jansen</a>,
299
                    <a href="http://pear.php.net/account-info.php?handle=cmv">Colin Viebrock</a>,
300
                    <a href="http://pear.php.net/account-info.php?handle=richard">Richard Heyes</a>
301
                </td>
302
            </tr>
303
        </table>
304
        <br />
305
        <table>
306
            <tr class="h">
307
                <td>
308
                    PEAR documentation team
309
                </td>
310
            </tr>
311
            <tr class="v">
312
                <td>
313
                    <a href="http://pear.php.net/account-info.php?handle=cox">Thomas V.V.Cox</a>,
314
                    <a href="http://pear.php.net/account-info.php?handle=mj">Martin Jansen</a>,
315
                    <a href="http://pear.php.net/account-info.php?handle=alexmerz">Alexander Merz</a>
316
                </td>
317
            </tr>
318
        </table>
319
        <?php
320
        $available = $this->reg->listPackages();
321
 
322
        if (PEAR::isError($available)) {
323
            echo '<h1 style="font-size: 12px;">An Error occured fetching the credits from the remote server. Please try again.</h1>';
324
            return FALSE;
325
        }
326
        if (!is_array($available)) {
327
            echo '<h1 style="font-size: 12px;">The credits could not be fetched from the remote server. Please try again.</h1>';
328
            return FALSE;
329
        }
330
        echo '<br /><table border="0" cellpadding="3" width="600">';
331
        echo '<tr class="h"><td>Package</td><td>Maintainers</td></tr>';
332
        foreach ($available as $name) {
333
            $installed = $this->reg->packageInfo($name);
334
            if (strlen($installed['package']) > 1) {
335
                ?>
336
                <tr>
337
                    <td class="e">
338
                        <a href="http://pear.php.net/<?php echo trim(strtolower($installed['package'])); ?>"><?php echo trim($installed['package']); ?></a>
339
 
340
                    </td>
341
                    <td class="v">
342
                        <?php
343
                        $maintainers = array();
344
                        foreach ($installed['maintainers'] as $i) {
345
                            $maintainers[] = '<a href="http://pear.php.net/account-info.php?handle=' .$i['handle']. '">' .htmlentities($i['name']). '</a>' .' (' .$i['role']. ')';
346
                        }
347
                        echo implode(', ',$maintainers);
348
                        ?>
349
                    </td>
350
                </tr>
351
                <?php
352
            }
353
        }
354
        echo '</table>';
355
    }
356
 
357
    /**
358
     * outputs the PEAR logo
359
     * @return void
360
     * @access public
361
     */
362
 
363
    function pearImage()
364
    {
365
        $pear_image = 'R0lGODlhaAAyAMT/AMDAwP3+/TWaAvD47Pj89vz++zebBDmcBj6fDEekFluvKmu3PvX68ujz4XvBS8LgrNXqxeHw1ZnPaa/dgvv9+cLqj8LmltD2msnuls';
366
        $pear_image .= '3xmszwmf7+/f///wAAAAAAAAAAACH5BAEAAAAALAAAAABoADIAQAX/ICCOZGmeaKqubOtWWjwJphLLgH1XUu//C1Jisfj9YLEKQnSY3GaixWQqQTkYHM4';
367
        $pear_image .= 'AMulNLJFC9pEwIW/odKU8cqTfsWoTTtcomU4ZjbR4ZP+AgYKCG0EiZ1AuiossEhwEXRMEg5SVWQ6MmZqKWD0QlqCUEHubpaYlExwRPRZioZZVp7KzKQoS';
368
        $pear_image .= 'DxANDLsNXA5simd2FcQYb4YAc2jEU80TmAAIztPCMcjKdg4OEsZJmwIWWQPQI4ikIwtoVQnddgrv8PFlCWgYCwkI+fp5dkvJ/IlUKMCy6tYrDhNIIKLFE';
369
        $pear_image .= 'AWCTxse+ABD4SClWA0zovAjcUJFi6EwahxZwoGqHhFA/4IqoICkyxQSKkbo0gDkuBXV4FRAJkRCnTgi2P28IcEfk5xpWppykFJVuScmEvDTEETAVJ6bEp';
370
        $pear_image .= 'ypcADPkz3pvKVAICHChkC7siQ08zVqu4Q6hgIFEFZuEn/KMgRUkaBmAQs+cEHgIiHVH5EAFpIgW4+NT6LnaqhDwe/Ov7YOmWZp4MkiAWBIl0kAVsJWuzc';
371
        $pear_image .= 'YpdiNgddc0E8cKBAu/FElBwagMb88ZZKDRAkWJtkWhHh3wwUbKHQJN3wQAaXGR2LpArv5oFHRR34C7Mf6oLXZNfqBgNI7oOLhj1f8PaGpygHQ0xtP8MDV';
372
        $pear_image .= 'KwYTSKcgxr9/hS6/pCCAAg5M4B9/sWh1YP9/XSgQWRML/idBfKUc4IBET9lFjggKhDYZAELZJYEBI2BDB3ouNBEABwE8gAwiCcSYgAKqPdEVAG7scM8BP';
373
        $pear_image .= 'PZ4AIlM+OgjAgpMhRE24OVoBwsIFEGFA7ZkQQBWienWxmRa7XDjKZXhBdAeSmKQwgLuUVLICa6VEKIGcK2mQWoVZHCBXJblJUFkY06yAXlGsPIHBEYdYi';
374
        $pear_image .= 'WHb+WQBgaIJqqoHFNpgMGB7dT5ZQuG/WbBAIAUEEFNfwxAWpokTIXJAWdgoJ9kRFG2g5eDRpXSBpEIF0oEQFaZhDbaSFANRgqcJoEDRARLREtxOQpsPO9';
375
        $pear_image .= '06ZUeJgjQB6dZUPBAdwcF8KLXXRVQaKFcsRRLJ6vMiiCNKxRE8ECZKgUA3Va4arOAAqdGRWO7uMZH5AL05gvsjQbg6y4NCjQ1kw8TVGcbdoKGKx8j3bGH';
376
        $pear_image .= '7nARBArqwi0gkFJBrZiXBQRbHoIgnhSjcEBKfD7c3HMhz+JIQSY3t8GGKW+SUhfUajxGzKd0IoHBNkNQK86ZYEqdzYA8AHQpqXRUm80oHs1CAgMoBxzRq';
377
        $pear_image .= 'vzs9CIKECC1JBp7enUpfXHApwVYNAfo16c4IrYPLVdSAJVob7IAtCBFQGHcs/RRdiUDPHA33oADEAIAOw==';
378
        header('content-type: image/gif');
379
        echo base64_decode($pear_image);
380
    }
381
 
382
    /**
383
     * Shows PEAR_Info output
384
     * @return void
385
     * @access public
386
     */
387
 
388
    function show()
389
    {
390
        echo $this->info;
391
    }
392
 
393
    /**
394
     * Check if a package is installed
395
     */
396
 
397
    function packageInstalled($package_name, $version = null, $pear_user_config = null)
398
    {
399
        if(is_null($pear_user_config)) {
400
            $config = new PEAR_Config();
401
        } else {
402
            $config = new PEAR_Config($pear_user_config);
403
        }
404
 
405
        $reg = new PEAR_Registry($config->get('php_dir'));
406
 
407
        if (is_null($version)) {
408
            return $reg->packageExists($package_name);
409
        } else {
410
            $installed = $reg->packageInfo($package_name);
411
            return version_compare($version, $installed['version'], '<=');
412
        }
413
    }
414
}
415
 
416
if (isset($_GET['pear_image'])) {
417
    PEAR_Info::pearImage();
418
    exit;
419
}
420
?>