]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/CompatInfo.php
Avoid warning
[SourceForge/phpwiki.git] / tests / CompatInfo.php
1 <?php
2 /* Get the Compatibility info for phpwiki
3    http://pear.php.net/package/PHP_CompatInfo
4
5    $Id$
6 */
7 /*
8  * Copyright (C) 2004 Reini Urban <rurban@x-ray.at>
9  *
10  * This file is part of PhpWiki.
11  * 
12  * PhpWiki is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  * 
17  * PhpWiki is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with PhpWiki; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25  */
26  
27
28 require_once 'PHP/CompatInfo.php';
29
30 function out_row($row, $header = false) {
31     if (empty($row)) return;
32     echo "<tr>";
33     $tag = $header ? "th" : "td";
34     // link to file?
35     $file = $row[0];
36     if (!empty($file) and substr($file,0,3) != '<b>' and $file != 'File') {
37         $row[0] = '<a href="'.$PHP_SELF.'?file='.urlencode($file).'">'.$file.'</a>';
38     }
39     foreach ($row as $r) { 
40         echo "<$tag>", empty($r) ? '&nbsp;' : "$r", "</$tag>"; 
41     }
42     echo "</tr>\n";
43 }
44
45 $info = new PHP_CompatInfo;
46 $dir = str_replace(array('\\','/'), '/', dirname(__FILE__));
47 $dir = preg_replace('/\/'.basename(dirname(__FILE__)).'$/', '', $dir);
48 $debug = !empty($_GET['debug']);
49 $detail = !empty($_GET['detail']);
50 // echo $dir;
51 $options = array('file_ext'     => array('php'),
52                  'ignore_files' => array(__FILE__),
53                  'recurse_dir'  => true,
54                  'ignore_functions' => array(),
55                  'debug' => $debug or $detail,
56                  );
57 // var_dump($options);
58 set_time_limit(240);
59 $cols = array('File','Version','Extensions','Constants');
60
61 if (empty($_GET['file'])) {
62     $file = false;
63     echo "<h1>All Files</h1>\n";
64     echo " Show Details: <a href=\"",$_SERVER["SCRIPT_NAME"],"?detail=1\">YES</a>";
65     echo " <a href=\"",$_SERVER["SCRIPT_NAME"],"\">NO</a> <br>\n";
66     $r = $info->parseFolder($dir, $options);
67 } else {
68     $file = urldecode($_GET['file']);
69     echo "<h1>File $file</h1>\n";
70     echo " Show Details: <a href=\"",$_SERVER["SCRIPT_NAME"],"?file=$file&detail=1\">YES</a>";
71     echo " <a href=\"",$_SERVER["SCRIPT_NAME"],"?file=$file\">NO</a> <br>\n";
72     echo " =&gt; <a href=\"",$_SERVER["SCRIPT_NAME"],"\">Back to All Files</a><br>\n";
73     $r = $info->parseFile("$dir/$file", $options);
74 }
75
76 echo "<table border=\"1\">\n";
77
78 out_row($cols,1);
79
80 foreach ($r as $key => $info) {
81
82     if ($key == 'extensions')
83         out_row(array("<b>$key</b>", '', join(', ',$info), ''));
84     elseif ($key == 'constants')
85         out_row(array("<b>$key</b>", '', '', join(', ',$info)));
86     elseif ($key == 'version')
87         out_row(array("<b>$key</b>", $info, '', ''));
88     elseif ($key == 'ignored_files')
89         out_row(array("<b>$key</b>", join(',',$info), ''));
90     else{
91         if (empty($_GET['file'])) {
92             $file = str_replace(array('\\','/'),'/',$key);
93             if (strlen($key) > strlen($dir))
94                 $file = substr(str_replace($dir,'',$file),1);
95             if (!isset($info['extensions'][0])) {
96                 $ext = '';
97             } else {
98                 $ext = array_shift($info['extensions']);
99             }
100             if (!isset($info['constants'][0])) {
101                 $const = '';
102             } else {
103                 $const = array_shift($info['constants']);
104             }
105             out_row(array($file, $info['version'], $ext, $const));
106             
107             if (is_array($info['extensions'])
108                 and sizeof($info['extensions']) >= sizeof($info['constants'])) {
109                 foreach ($info['extensions'] as $i => $ext) {
110                     if (isset($info['constants'][$i])) {
111                         $const = $info['constants'][$i];
112                     } else {
113                         $const = '';
114                     }
115                     out_row(array('','', $ext, $const));
116                 }
117             } elseif (is_array($info['constants'])) {
118                 foreach ($info['constants'] as $i => $const) {
119                     if (isset($info['extensions'][$i])) {
120                         $ext = $info['extensions'][$i];
121                     } else {
122                         $ext = '';
123                     }
124                     out_row(array('', '', $ext, $const));
125                 }
126             }
127         }
128         if ($detail and is_array($info)) {
129             out_row(array('<b><i>DETAIL</i></b>','Version','Function','Extension'),1);
130             unset($info['version']);
131             unset($info['constants']);
132             unset($info['extensions']);
133             if (!empty($_GET['file'])) {
134                 $version = $key;
135                 foreach ($info as $func) {
136                     out_row(array('',$version,$func['function'],$func['extension']));
137                 }
138             } else {
139                 foreach ($info as $version => $functions) {
140                     foreach ($functions as $func) {
141                         out_row(array('',$version,$func['function'],$func['extension']));
142                     }
143                 }
144             }
145         }
146     }
147 }
148 echo "</table>\n";
149
150 if ($debug) {
151     echo "<pre>\n";
152     var_dump ($r);
153     echo "</pre>\n";
154 }
155
156 // (c-file-style: "gnu")
157 // Local Variables:
158 // mode: php
159 // tab-width: 8
160 // c-basic-offset: 4
161 // c-hanging-comment-ender-p: nil
162 // indent-tabs-mode: nil
163 // End:    
164 ?>