c28d86685a8a28c064fdd6cbc21d7da050d468ad
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / common.inc.php
1 <?php\r
2 /**\r
3  * Common information needed by all portions of the application\r
4  *\r
5  * phpDocumentor :: automatic documentation generator\r
6  * \r
7  * PHP versions 4 and 5\r
8  *\r
9  * Copyright (c) 2001-2007 Gregory Beaver\r
10  * \r
11  * LICENSE:\r
12  * \r
13  * This library is free software; you can redistribute it\r
14  * and/or modify it under the terms of the GNU Lesser General\r
15  * Public License as published by the Free Software Foundation;\r
16  * either version 2.1 of the License, or (at your option) any\r
17  * later version.\r
18  * \r
19  * This library is distributed in the hope that it will be useful,\r
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
22  * Lesser General Public License for more details.\r
23  * \r
24  * You should have received a copy of the GNU Lesser General Public\r
25  * License along with this library; if not, write to the Free Software\r
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
27  *\r
28  * @category  ToolsAndUtilities\r
29  * @package   phpDocumentor\r
30  * @author    Greg Beaver <cellog@php.net>\r
31  * @copyright 2001-2007 Gregory Beaver\r
32  * @license   http://www.opensource.org/licenses/lgpl-license.php LGPL\r
33  * @version   CVS: $Id: common.inc.php,v 1.13 2007/10/06 22:57:15 ashnazg Exp $\r
34  * @filesource\r
35  * @link      http://www.phpdoc.org\r
36  * @link      http://pear.php.net/PhpDocumentor\r
37  * @see       parserDocBlock, parserInclude, parserPage, parserClass\r
38  * @see       parserDefine, parserFunction, parserMethod, parserVar\r
39  * @since     1.0rc1\r
40  * @todo      CS cleanup - change package to PhpDocumentor\r
41  * @todo      CS cleanup - rename constant to TOKENIZER_EXT\r
42  */\r
43 \r
44 /* phpDocumentor version */\r
45 if ('@PEAR-DIR@' != '@'.'PEAR-DIR@') {\r
46     /** @ignore */\r
47     define("PHPDOCUMENTOR_VER", "@VER@");\r
48 } else {\r
49     define("PHPDOCUMENTOR_VER", "1.4.0");\r
50 }\r
51 \r
52 /* phpDocumentor URL */\r
53 define("PHPDOCUMENTOR_WEBSITE", "http://www.phpdoc.org");\r
54 \r
55 // set the correct path delimiter\r
56 define('SMART_PATH_DELIMITER', DIRECTORY_SEPARATOR); \r
57 \r
58 define('tokenizer_ext', extension_loaded('tokenizer') \r
59     && version_compare(phpversion(), "4.3.0", ">="));\r
60 \r
61 // we just replace all the \ with / so that we can just operate on /\r
62 define('PATH_DELIMITER', '/'); // set the correct path delimiter\r
63 \r
64 define('PHPDOCUMENTOR_WINDOWS', substr(PHP_OS, 0, 3) == 'WIN');\r
65 \r
66 define('_IN_PHP5', \r
67     phpversion() == '5.0.0RC1-dev' || phpversion() == '5.0.0RC2-dev' \r
68     || version_compare(phpversion(), '5.0.0', 'ge'));\r
69 \r
70 // determine which "clone" class to set, based on PHP major version\r
71 $cloneClassDir  = 'PhpDocumentor' . DIRECTORY_SEPARATOR . 'phpDocumentor';\r
72 $cloneClassFile = 'clone.inc.php';\r
73 if ('@VER@' == '@'.'VER@') {\r
74     // we're _not_ in a PEAR installation\r
75     $cloneClassDir = dirname(__FILE__);\r
76 }\r
77 if (_IN_PHP5) {\r
78     // we _are_ in PHP5\r
79     $cloneClassFile = 'clone5.inc.php';\r
80 }\r
81 require_once $cloneClassDir . DIRECTORY_SEPARATOR . $cloneClassFile;\r
82 \r
83 // make arg arrays available\r
84 if (isset($_SERVER['argv'])) {\r
85     $argv = $_SERVER['argv'];\r
86     $argc = $_SERVER['argc'];\r
87 }\r
88 \r
89 /**\r
90  * used in phpdoc.php and new_phpdoc.php \r
91  *\r
92  * @param string $directory a directory string\r
93  *\r
94  * @return array an array of directory contents\r
95  * @todo CS cleanup - rename function to PhpDocumentor_ConfigFileList\r
96  */\r
97 function phpDocumentor_ConfigFileList($directory)\r
98 {\r
99     $ret = array();\r
100     if (@is_dir($directory)) {\r
101         $ret = array();\r
102 \r
103         // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix\r
104         $d = @dir($directory); \r
105 \r
106         while ($d && $entry=$d->read()) {\r
107             $getentry = false;\r
108             if (strcmp($entry, ".") != 0 && strcmp($entry, "..") != 0) {\r
109                 if (substr($entry, 0, 1) != ".") $getentry = true;\r
110             }\r
111             if ($getentry == true) {\r
112                 if (strpos($entry, '.ini'))\r
113                 if (is_file($directory . PATH_DELIMITER . $entry)) {\r
114                     $ret[] = str_replace('.ini', '', $entry);\r
115                 }\r
116             }\r
117         }\r
118         if ($d) $d->close();\r
119     } else {\r
120     }\r
121     return $ret;\r
122 }\r
123 \r
124 \r
125 /**\r
126  * Parse an .ini file\r
127  * \r
128  * Works like {@link parse_ini_file}, except it will take a section like:\r
129  *\r
130  * <pre>\r
131  * [MYVAR]\r
132  * value1\r
133  * value2\r
134  * value3\r
135  * </pre>\r
136  *\r
137  * and return an associative array(MYVAR => array(value1, value2, value3))\r
138  *\r
139  * @param string $filename         full path to the ini file\r
140  * @param bool   $process_sections add an associative index \r
141  *                                 for each section [in brackets]\r
142  *\r
143  * @return array\r
144  * @todo CS cleanup - rename function to PhpDocumentor_parse_ini_file\r
145  */\r
146 function phpDocumentor_parse_ini_file($filename, $process_sections = false)\r
147 {\r
148     $ini_array = array();\r
149     $sec_name  = "";\r
150     $lines     = @file($filename);\r
151     if (!$lines) return $lines;\r
152     foreach ($lines as $line) {\r
153         // code by Greg Beaver, ignore comments\r
154         if ($line[0] == ';') continue;\r
155         $line = trim($line);\r
156         \r
157         if ($line == "") {\r
158             continue;\r
159         }\r
160         if ($line[0] == "[" && $line[strlen($line) - 1] == "]") {\r
161             $sec_name = substr($line, 1, strlen($line) - 2);\r
162         } else {\r
163             if (strpos($line, "=")) {\r
164                 $pos      = strpos($line, "=");\r
165                 $property = trim(substr($line, 0, $pos));\r
166                 // code by Greg Beaver\r
167                 if (substr($property, 0, 1) == '"' && substr($property, -1) == '"') {\r
168                     $property = \r
169                         stripcslashes(substr($property, 1, count($property) - 2));\r
170                 }\r
171                 $value = trim(substr($line, $pos + 1));\r
172                 if ($value == 'false') $value = false;\r
173                 if ($value == 'true') $value = true;\r
174                 if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {\r
175                     $value = stripcslashes(substr($value, 1, count($value) - 2));\r
176                 }\r
177                 // done additions\r
178                 \r
179                 if ($process_sections) {\r
180                     if ($sec_name != '')\r
181                     $ini_array[$sec_name][$property] = $value;\r
182                     else\r
183                     $ini_array[$property] = $value;\r
184                 } else {\r
185                     $ini_array[$property] = $value;\r
186                 }\r
187             } else {\r
188                 // code by Greg Beaver\r
189                 if (trim($line[0]) == ';') continue;\r
190                 if ($process_sections) {\r
191                     $ini_array[$sec_name][] = trim($line);\r
192                 }\r
193                 // done additions\r
194             }\r
195         }\r
196     }\r
197     return $ini_array;\r
198 }\r
199 \r
200 \r
201 /**\r
202  * construct an "array_key_exists()" method\r
203  * if the runtime PHP version doesn't have one\r
204  * \r
205  * @todo CS Cleanup - can't avoid "prefixed by package" error\r
206  * @todo depend on PHP_Compat for this?\r
207  */\r
208 if (!function_exists('array_key_exists')) {\r
209     /** \r
210      * Determines if a given key exists in a given array\r
211      *\r
212      * @param mixed $key    key to search for\r
213      * @param array $search the array of keys to search\r
214      *\r
215      * @return bool whether or not the key was found\r
216      * @ignore\r
217      */\r
218     function array_key_exists($key, $search)\r
219     {\r
220         foreach ($search as $keys => $nul) {\r
221             if ($key == $keys) return true;\r
222         }\r
223         return false;\r
224     }\r
225 }\r
226 \r
227 /**\r
228  * construct an "is_a()" method\r
229  * if the runtime PHP version doesn't have one\r
230  * \r
231  * @todo CS Cleanup - can't avoid "prefixed by package" error\r
232  * @todo depend on PHP_Compat for this?\r
233  */\r
234 if (!function_exists('is_a')) {\r
235     /**\r
236      * Determines if one item "is" an object of the other item\r
237      *\r
238      * @param string $classname  the class in question\r
239      * @param string $classquery the "is it a" class\r
240      *\r
241      * @return bool whether or not the class "is" one\r
242      * @ignore\r
243      */\r
244     function is_a($classname, $classquery)\r
245     {\r
246         $father = get_parent_class($classname);\r
247         if (strtolower($father) == strtolower($classquery)) {\r
248             return true;\r
249         } elseif (!empty($father)) {\r
250             return is_a($father, $classquery);\r
251         } else {\r
252             return false;\r
253         }\r
254     }\r
255 }\r
256 \r
257 \r
258 /**\r
259  * Debugging output\r
260  *\r
261  * @param string $s the "debug message" string to echo out\r
262  *\r
263  * @return void\r
264  * @todo CS Cleanup - can't avoid "prefixed by package" error\r
265  */\r
266 /*\r
267 * Taken out since ATutor has a function called debug as well. \r
268 * Redeclaring function error otherwise.  \r
269 function debug($s)\r
270 {\r
271     echo "$s\n";\r
272 }\r
273 */\r
274 \r
275 /**\r
276  * Returns a formatted var_dump for debugging purposes.\r
277  *\r
278  * @param string $s string to display\r
279  * @param mixed  $v unlimited number of variables to display with var_dump()\r
280  *\r
281  * @return void\r
282  */\r
283 function fancy_debug($s,$v)\r
284 {\r
285     if (isset($GLOBALS['dont_debug']) && $GLOBALS['dont_debug']) return;\r
286     debug($s."\n\n</pre><blockquote><pre>");\r
287     var_dump($v);\r
288     if (func_num_args()>2) {\r
289         for ($i=2;$i<func_num_args();$i++) {\r
290             $a = func_get_arg($i);\r
291             // debug(" ");\r
292             var_dump($a);\r
293         }\r
294     }\r
295     debug("</pre></blockquote><pre>\n\n");\r
296 }\r
297 \r
298 /**\r
299  * Returns a lower-cased version of get_class for PHP 5\r
300  *\r
301  * get_class() returns case as declared in the file in PHP 5\r
302  *\r
303  * @param object $object the object to get the classname for\r
304  *\r
305  * @return string the class name of the given object\r
306  * @todo CS cleanup - rename function to PhpDocumentor_get_class\r
307  */\r
308 function phpDocumentor_get_class($object)\r
309 {\r
310     return strtolower(get_class($object));\r
311 }\r
312 \r
313 ?>\r