Skip .svn dir. Leaving CVS dir in case it is left over in some people's downloaded...
[squirrelmail.git] / functions / global.php
CommitLineData
61d9ec71 1<?php
2
3/**
0c701a88 4 * global.php
61d9ec71 5 *
62f7daa5 6 * This includes code to update < 4.1.0 globals to the newer format
242342d0 7 * It also has some session register functions that work across various
62f7daa5 8 * php versions.
61d9ec71 9 *
4b5049de 10 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
4b4abf93 11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 12 * @version $Id$
d6c32258 13 * @package squirrelmail
61d9ec71 14 */
15
051f6245 16/**
2ca4c65a 17 */
7f62aaef 18define('SQ_INORDER',0);
19define('SQ_GET',1);
20define('SQ_POST',2);
21define('SQ_SESSION',3);
22define('SQ_COOKIE',4);
23define('SQ_SERVER',5);
24define('SQ_FORM',6);
a32985a5 25
202bcbcc 26
62f7daa5 27/**
28 * returns true if current php version is at mimimum a.b.c
29 *
97bdc607 30 * Called: check_php_version(4,1)
8b096f0a 31 * @param int a major version number
32 * @param int b minor version number
33 * @param int c release number
34 * @return bool
97bdc607 35 */
62f7daa5 36function check_php_version ($a = '0', $b = '0', $c = '0')
9697c5ab 37{
5673cabe 38 return version_compare ( PHP_VERSION, "$a.$b.$c", 'ge' );
9697c5ab 39}
40
97bdc607 41/**
62f7daa5 42 * returns true if the current internal SM version is at minimum a.b.c
43 * These are plain integer comparisons, as our internal version is
97bdc607 44 * constructed by us, as an array of 3 ints.
45 *
46 * Called: check_sm_version(1,3,3)
8b096f0a 47 * @param int a major version number
48 * @param int b minor version number
49 * @param int c release number
50 * @return bool
97bdc607 51 */
52function check_sm_version($a = 0, $b = 0, $c = 0)
53{
54 global $SQM_INTERNAL_VERSION;
55 if ( !isset($SQM_INTERNAL_VERSION) ||
56 $SQM_INTERNAL_VERSION[0] < $a ||
150c28d6 57 ( $SQM_INTERNAL_VERSION[0] == $a &&
58 $SQM_INTERNAL_VERSION[1] < $b) ||
59 ( $SQM_INTERNAL_VERSION[0] == $a &&
60 $SQM_INTERNAL_VERSION[1] == $b &&
97bdc607 61 $SQM_INTERNAL_VERSION[2] < $c ) ) {
62 return FALSE;
62f7daa5 63 }
64 return TRUE;
97bdc607 65}
66
67
8b096f0a 68/**
69 * Recursively strip slashes from the values of an array.
70 * @param array array the array to strip, passed by reference
71 * @return void
72 */
a32985a5 73function sqstripslashes(&$array) {
3aa17cf9 74 if(count($array) > 0) {
75 foreach ($array as $index=>$value) {
76 if (is_array($array[$index])) {
77 sqstripslashes($array[$index]);
78 }
79 else {
80 $array[$index] = stripslashes($value);
81 }
a32985a5 82 }
83 }
84}
85
8b096f0a 86/**
87 * Add a variable to the session.
88 * @param mixed $var the variable to register
89 * @param string $name the name to refer to this variable
90 * @return void
91 */
61d9ec71 92function sqsession_register ($var, $name) {
281c3d5b 93
94 sqsession_is_active();
95
04ce2477 96 $_SESSION[$name] = $var;
61d9ec71 97}
3aa17cf9 98
8b096f0a 99/**
100 * Delete a variable from the session.
101 * @param string $name the name of the var to delete
102 * @return void
103 */
61d9ec71 104function sqsession_unregister ($name) {
281c3d5b 105
106 sqsession_is_active();
107
abd74f7d 108 unset($_SESSION[$name]);
62f7daa5 109
dcc1cc82 110 session_unregister("$name");
61d9ec71 111}
3aa17cf9 112
8b096f0a 113/**
114 * Checks to see if a variable has already been registered
115 * in the session.
116 * @param string $name the name of the var to check
117 * @return bool whether the var has been registered
118 */
d7c82551 119function sqsession_is_registered ($name) {
120 $test_name = &$name;
121 $result = false;
62f7daa5 122
abd74f7d 123 if (isset($_SESSION[$test_name])) {
124 $result = true;
d7c82551 125 }
62f7daa5 126
d7c82551 127 return $result;
128}
129
54ce41dd 130
131/**
132 * Retrieves a form variable, from a set of possible similarly named
133 * form variables, based on finding a different, single field. This
68a7e1d6 134 * is intended to allow more than one same-named inputs in a single
135 * <form>, where the submit button that is clicked tells us which
54ce41dd 136 * input we should retrieve. An example is if we have:
137 * <select name="startMessage_1">
138 * <select name="startMessage_2">
b116fd78 139 * <input type="submit" name="form_submit_1" />
140 * <input type="submit" name="form_submit_2" />
68a7e1d6 141 * and we want to know which one of the select inputs should be
54ce41dd 142 * returned as $startMessage (without the suffix!), this function
143 * decides by looking for either "form_submit_1" or "form_submit_2"
144 * (both should not appear). In this example, $name should be
145 * "startMessage" and $indicator_field should be "form_submit".
146 *
147 * NOTE that form widgets must be named with the suffix "_1", "_2", "_3"
148 * and so on, or this function will not work.
149 *
150 * If more than one of the indicator fields is found, the first one
151 * (numerically) will win.
152 *
68a7e1d6 153 * If an indicator field is found without a matching input ($name)
139a4b99 154 * field, FALSE is returned.
155 *
68a7e1d6 156 * If no indicator fields are found, a field of $name *without* any
157 * suffix is searched for (but only if $fallback_no_suffix is TRUE),
139a4b99 158 * and if not found, FALSE is ultimately returned.
54ce41dd 159 *
160 * It should also be possible to use the same string for both
161 * $name and $indicator_field to look for the first possible
162 * widget with a suffix that can be found (and possibly fallback
163 * to a widget without a suffix).
164 *
165 * @param string name the name of the var to search
166 * @param mixed value the variable to return
167 * @param string indicator_field the name of the field upon which to base
168 * our decision upon (see above)
169 * @param int search constant defining where to look
170 * @param bool fallback_no_suffix whether or not to look for $name with
171 * no suffix when nothing else is found
172 * @param mixed default the value to assign to $value when nothing is found
173 * @param int typecast force variable to be cast to given type (please
174 * use SQ_TYPE_XXX constants or set to FALSE (default)
175 * to leave variable type unmolested)
176 *
177 * @return bool whether variable is found.
178 */
68a7e1d6 179function sqGetGlobalVarMultiple($name, &$value, $indicator_field,
180 $search = SQ_INORDER,
181 $fallback_no_suffix=TRUE, $default=NULL,
54ce41dd 182 $typecast=FALSE) {
183
1793f985 184 // Set arbitrary max limit -- should be much lower except on the
185 // search results page, if there are many (50 or more?) mailboxes
186 // shown, this may not be high enough. Is there some way we should
187 // automate this value?
188 //
189 $max_form_search = 100;
54ce41dd 190
191 for ($i = 1; $i <= $max_form_search; $i++) {
192 if (sqGetGlobalVar($indicator_field . '_' . $i, $temp, $search)) {
193 return sqGetGlobalVar($name . '_' . $i, $value, $search, $default, $typecast);
194 }
195 }
196
197
198 // no indicator field found; just try without suffix if allowed
199 //
200 if ($fallback_no_suffix) {
201 return sqGetGlobalVar($name, $value, $search, $default, $typecast);
202 }
203
204
205 // no dice, set default and return FALSE
206 //
207 if (!is_null($default)) {
208 $value = $default;
209 }
210 return FALSE;
211
212}
213
214
4cd8ae7d 215/**
2d055f0a 216 * Search for the var $name in $_SESSION, $_POST, $_GET, $_COOKIE, or $_SERVER
217 * and set it in provided var.
d1975c5b 218 *
2d055f0a 219 * If $search is not provided, or if it is SQ_INORDER, it will search $_SESSION,
220 * then $_POST, then $_GET. If $search is SQ_FORM it will search $_POST and
221 * $_GET. Otherwise, use one of the defined constants to look for a var in one
222 * place specifically.
d1975c5b 223 *
2d055f0a 224 * Note: $search is an int value equal to one of the constants defined above.
d1975c5b 225 *
2d055f0a 226 * Example:
227 * sqgetGlobalVar('username',$username,SQ_SESSION);
228 * // No quotes around last param, it's a constant - not a string!
d1975c5b 229 *
8b096f0a 230 * @param string name the name of the var to search
231 * @param mixed value the variable to return
232 * @param int search constant defining where to look
54ce41dd 233 * @param mixed default the value to assign to $value when nothing is found
c2b585c5 234 * @param int typecast force variable to be cast to given type (please
235 * use SQ_TYPE_XXX constants or set to FALSE (default)
236 * to leave variable type unmolested)
54ce41dd 237 *
8b096f0a 238 * @return bool whether variable is found.
4cd8ae7d 239 */
202bcbcc 240function sqgetGlobalVar($name, &$value, $search = SQ_INORDER, $default = NULL, $typecast = false) {
241
242 $result = false;
f79c19a4 243
4cd8ae7d 244 switch ($search) {
62f7daa5 245 /* we want the default case to be first here,
051f6245 246 so that if a valid value isn't specified,
247 all three arrays will be searched. */
d1975c5b 248 default:
d9ad2525 249 case SQ_INORDER: // check session, post, get
d1975c5b 250 case SQ_SESSION:
251 if( isset($_SESSION[$name]) ) {
4cd8ae7d 252 $value = $_SESSION[$name];
202bcbcc 253 $result = TRUE;
254 break;
d1975c5b 255 } elseif ( $search == SQ_SESSION ) {
256 break;
257 }
d9ad2525 258 case SQ_FORM: // check post, get
d1975c5b 259 case SQ_POST:
260 if( isset($_POST[$name]) ) {
4cd8ae7d 261 $value = $_POST[$name];
202bcbcc 262 $result = TRUE;
263 break;
d1975c5b 264 } elseif ( $search == SQ_POST ) {
27d0841c 265 break;
d1975c5b 266 }
267 case SQ_GET:
268 if ( isset($_GET[$name]) ) {
269 $value = $_GET[$name];
202bcbcc 270 $result = TRUE;
271 break;
62f7daa5 272 }
d1975c5b 273 /* NO IF HERE. FOR SQ_INORDER CASE, EXIT after GET */
274 break;
275 case SQ_COOKIE:
276 if ( isset($_COOKIE[$name]) ) {
277 $value = $_COOKIE[$name];
202bcbcc 278 $result = TRUE;
279 break;
d1975c5b 280 }
281 break;
282 case SQ_SERVER:
d1975c5b 283 if ( isset($_SERVER[$name]) ) {
284 $value = $_SERVER[$name];
202bcbcc 285 $result = TRUE;
286 break;
d1975c5b 287 }
288 break;
4cd8ae7d 289 }
202bcbcc 290 if ($result && $typecast) {
291 switch ($typecast) {
c2b585c5 292 case SQ_TYPE_INT: $value = (int) $value; break;
293 case SQ_TYPE_STRING: $value = (string) $value; break;
294 case SQ_TYPE_BOOL: $value = (bool) $value; break;
202bcbcc 295 default: break;
296 }
ced8272a 297 } else if (!$result && !is_null($default)) {
202bcbcc 298 $value = $default;
299 }
300 return $result;
4cd8ae7d 301}
302
8b096f0a 303/**
304 * Deletes an existing session, more advanced than the standard PHP
305 * session_destroy(), it explicitly deletes the cookies and global vars.
66c7cd3f 306 *
307 * WARNING: Older PHP versions have some issues with session management.
68a7e1d6 308 * See http://bugs.php.net/11643 (warning, spammed bug tracker) and
66c7cd3f 309 * http://bugs.php.net/13834. SID constant is not destroyed in PHP 4.1.2,
68a7e1d6 310 * 4.2.3 and maybe other versions. If you restart session after session
311 * is destroyed, affected PHP versions produce PHP notice. Bug should
66c7cd3f 312 * be fixed only in 4.3.0
8b096f0a 313 */
513db22c 314function sqsession_destroy() {
242342d0 315
281c3d5b 316 /*
317 * php.net says we can kill the cookie by setting just the name:
318 * http://www.php.net/manual/en/function.setcookie.php
319 * maybe this will help fix the session merging again.
320 *
321 * Changed the theory on this to kill the cookies first starting
322 * a new session will provide a new session for all instances of
323 * the browser, we don't want that, as that is what is causing the
324 * merging of sessions.
325 */
242342d0 326
716cc530 327 global $base_uri, $_COOKIE, $_SESSION;
f31687f6 328
68a7e1d6 329 if (isset($_COOKIE[session_name()]) && session_name()) sqsetcookie(session_name(), '', 0, $base_uri);
330 if (isset($_COOKIE['username']) && $_COOKIE['username']) sqsetcookie('username','',0,$base_uri);
331 if (isset($_COOKIE['key']) && $_COOKIE['key']) sqsetcookie('key','',0,$base_uri);
281c3d5b 332
333 $sessid = session_id();
334 if (!empty( $sessid )) {
abd74f7d 335 $_SESSION = array();
21e18f59 336 @session_destroy();
242342d0 337 }
281c3d5b 338}
242342d0 339
8b096f0a 340/**
281c3d5b 341 * Function to verify a session has been started. If it hasn't
342 * start a session up. php.net doesn't tell you that $_SESSION
343 * (even though autoglobal), is not created unless a session is
344 * started, unlike $_POST, $_GET and such
345 */
281c3d5b 346function sqsession_is_active() {
281c3d5b 347 $sessid = session_id();
348 if ( empty( $sessid ) ) {
3a1de9f1 349 sqsession_start();
281c3d5b 350 }
513db22c 351}
352
3a1de9f1 353/**
354 * Function to start the session and store the cookie with the session_id as
355 * HttpOnly cookie which means that the cookie isn't accessible by javascript
356 * (IE6 only)
357 */
358function sqsession_start() {
202bcbcc 359 global $base_uri;
7f62aaef 360
3a1de9f1 361 session_start();
202bcbcc 362 $session_id = session_id();
363
3a1de9f1 364 // session_starts sets the sessionid cookie buth without the httponly var
365 // setting the cookie again sets the httponly cookie attribute
9e56668f 366 sqsetcookie(session_name(),$session_id,false,$base_uri);
3a1de9f1 367}
368
369
370/**
371 * Set a cookie
372 * @param string $sName The name of the cookie.
373 * @param string $sValue The value of the cookie.
374 * @param int $iExpire The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch.
375 * @param string $sPath The path on the server in which the cookie will be available on.
376 * @param string $sDomain The domain that the cookie is available.
377 * @param boolean $bSecure Indicates that the cookie should only be transmitted over a secure HTTPS connection.
378 * @param boolean $bHttpOnly Disallow JS to access the cookie (IE6 only)
379 * @return void
380 */
716cc530 381function sqsetcookie($sName,$sValue='deleted',$iExpire=0,$sPath="",$sDomain="",$bSecure=false,$bHttpOnly=true) {
68a7e1d6 382 // if we have a secure connection then limit the cookies to https only.
383 if ($sName && isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
384 $bSecure = true;
202bcbcc 385 }
9c0f1780 386
387 // admin config can override the restriction of secure-only cookies
388 global $only_secure_cookies;
389 if (!$only_secure_cookies)
390 $bSecure = false;
391
68a7e1d6 392 if (false && check_php_version(5,2)) {
393 // php 5 supports the httponly attribute in setcookie, but because setcookie seems a bit
394 // broken we use the header function for php 5.2 as well. We might change that later.
395 //setcookie($sName,$sValue,(int) $iExpire,$sPath,$sDomain,$bSecure,$bHttpOnly);
396 } else {
397 if (!empty($Domain)) {
398 // Fix the domain to accept domains with and without 'www.'.
399 if (strtolower(substr($Domain, 0, 4)) == 'www.') $Domain = substr($Domain, 4);
400 $Domain = '.' . $Domain;
401
402 // Remove port information.
403 $Port = strpos($Domain, ':');
404 if ($Port !== false) $Domain = substr($Domain, 0, $Port);
405 }
716cc530 406 if (!$sValue) $sValue = 'deleted';
68a7e1d6 407 header('Set-Cookie: ' . rawurlencode($sName) . '=' . rawurlencode($sValue)
408 . (empty($iExpires) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', $iExpires) . ' GMT')
409 . (empty($sPath) ? '' : '; path=' . $sPath)
410 . (empty($sDomain) ? '' : '; domain=' . $sDomain)
411 . (!$bSecure ? '' : '; secure')
412 . (!$bHttpOnly ? '' : '; HttpOnly'), false);
413 }
202bcbcc 414}
415
416/**
417 * session_regenerate_id replacement for PHP < 4.3.2
418 *
419 * This code is borrowed from Gallery, session.php version 1.53.2.1
420 */
421if (!function_exists('session_regenerate_id')) {
422 function make_seed() {
423 list($usec, $sec) = explode(' ', microtime());
424 return (float)$sec + ((float)$usec * 100000);
425 }
426
427 function php_combined_lcg() {
428 mt_srand(make_seed());
429 $tv = gettimeofday();
430 $lcg['s1'] = $tv['sec'] ^ (~$tv['usec']);
431 $lcg['s2'] = mt_rand();
432 $q = (int) ($lcg['s1'] / 53668);
433 $lcg['s1'] = (int) (40014 * ($lcg['s1'] - 53668 * $q) - 12211 * $q);
434 if ($lcg['s1'] < 0) {
435 $lcg['s1'] += 2147483563;
436 }
437 $q = (int) ($lcg['s2'] / 52774);
438 $lcg['s2'] = (int) (40692 * ($lcg['s2'] - 52774 * $q) - 3791 * $q);
439 if ($lcg['s2'] < 0) {
440 $lcg['s2'] += 2147483399;
441 }
442 $z = (int) ($lcg['s1'] - $lcg['s2']);
443 if ($z < 1) {
444 $z += 2147483562;
445 }
446 return $z * 4.656613e-10;
447 }
3a1de9f1 448
202bcbcc 449 function session_regenerate_id() {
450 global $base_uri;
451 $tv = gettimeofday();
452 sqgetGlobalVar('REMOTE_ADDR',$remote_addr,SQ_SERVER);
453 $buf = sprintf("%.15s%ld%ld%0.8f", $remote_addr, $tv['sec'], $tv['usec'], php_combined_lcg() * 10);
454 session_id(md5($buf));
455 if (ini_get('session.use_cookies')) {
456 // at a later stage we use sqsetcookie. At this point just do
457 // what session_regenerate_id would do
458 setcookie(session_name(), session_id(), NULL, $base_uri);
459 }
460 return TRUE;
461 }
3a1de9f1 462}
7f62aaef 463
202bcbcc 464
7f62aaef 465/**
466 * php_self
467 *
468 * Creates an URL for the page calling this function, using either the PHP global
469 * REQUEST_URI, or the PHP global PHP_SELF with QUERY_STRING added. Before 1.5.1
470 * function was stored in function/strings.php.
471 *
472 * @return string the complete url for this page
473 * @since 1.2.3
474 */
475function php_self () {
476 if ( sqgetGlobalVar('REQUEST_URI', $req_uri, SQ_SERVER) && !empty($req_uri) ) {
477 return $req_uri;
478 }
479
480 if ( sqgetGlobalVar('PHP_SELF', $php_self, SQ_SERVER) && !empty($php_self) ) {
481
482 // need to add query string to end of PHP_SELF to match REQUEST_URI
483 //
484 if ( sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER) && !empty($query_string) ) {
485 $php_self .= '?' . $query_string;
486 }
487
488 return $php_self;
489 }
490
491 return '';
492}
aa201211 493
494
495/**
68a7e1d6 496 * Find files and/or directories in a given directory optionally
497 * limited to only those with the given file extension. If the
498 * directory is not found or cannot be opened, no error is generated;
8f32a0a3 499 * only an empty file list is returned.
aa201211 500FIXME: do we WANT to throw an error or a notice or... or return FALSE?
501 *
68a7e1d6 502 * @param string $directory_path The path (relative or absolute)
8f32a0a3 503 * to the desired directory.
504 * @param string $extension The file extension filter (optional;
505 * default is to return all files (dirs).
506 * @param boolean $return_filenames_only When TRUE, only file/dir names
aa201211 507 * are returned, otherwise the
508 * $directory_path string is
8f32a0a3 509 * prepended to each file/dir in
aa201211 510 * the returned list (optional;
8f32a0a3 511 * default is filename/dirname only)
512 * @param boolean $include_directories When TRUE, directories are
68a7e1d6 513 * included (optional; default
8f32a0a3 514 * DO include directories).
68a7e1d6 515 * @param boolean $directories_only When TRUE, ONLY directories
516 * are included (optional; default
8f32a0a3 517 * is to include files too).
518 * @param boolean $separate_files_and_directories When TRUE, files and
519 * directories are returned
520 * in separate lists, so
521 * the return value is
522 * formatted as a two-element
523 * array with the two keys
524 * "FILES" and "DIRECTORIES",
525 * where corresponding values
526 * are lists of either all
527 * files or all directories
528 * (optional; default do not
529 * split up return array).
68a7e1d6 530 *
aa201211 531 *
8f32a0a3 532 * @return array The requested file/directory list(s).
aa201211 533 *
534 * @since 1.5.2
535 *
536 */
8f32a0a3 537function list_files($directory_path, $extension='', $return_filenames_only=TRUE,
68a7e1d6 538 $include_directories=TRUE, $directories_only=FALSE,
8f32a0a3 539 $separate_files_and_directories=FALSE) {
aa201211 540
541 $files = array();
8f32a0a3 542 $directories = array();
aa201211 543
544//FIXME: do we want to place security restrictions here like only allowing
545// directories under SM_PATH?
546 // validate given directory
68a7e1d6 547 //
548 if (empty($directory_path)
549 || !is_dir($directory_path)
aa201211 550 || !($DIR = opendir($directory_path))) {
551 return $files;
552 }
553
8f32a0a3 554
555 if (!empty($extension)) $extension = '.' . trim($extension, '.');
556 $directory_path = rtrim($directory_path, '/');
557
558
aa201211 559 // parse through the files
560 //
aa201211 561 while (($file = readdir($DIR)) !== false) {
562
563 if ($file == '.' || $file == '..') continue;
564
8f32a0a3 565 if (!empty($extension)
68a7e1d6 566 && strrpos($file, $extension) !== (strlen($file) - strlen($extension)))
8f32a0a3 567 continue;
568
569 // only use is_dir() if we really need to (be as efficient as possible)
570 //
571 $is_dir = FALSE;
68a7e1d6 572 if (!$include_directories || $directories_only
8f32a0a3 573 || $separate_files_and_directories) {
574 if (is_dir($directory_path . '/' . $file)) {
575 if (!$include_directories) continue;
576 $is_dir = TRUE;
68a7e1d6 577 $directories[] = ($return_filenames_only
8f32a0a3 578 ? $file
579 : $directory_path . '/' . $file);
68a7e1d6 580 }
8f32a0a3 581 if ($directories_only) continue;
582 }
583
68a7e1d6 584 if (!$separate_files_and_directories
8f32a0a3 585 || ($separate_files_and_directories && !$is_dir)) {
68a7e1d6 586 $files[] = ($return_filenames_only
8f32a0a3 587 ? $file
588 : $directory_path . '/' . $file);
aa201211 589 }
590
591 }
592 closedir($DIR);
593
8f32a0a3 594
595 if ($directories_only) return $directories;
596 if ($separate_files_and_directories) return array('FILES' => $files,
597 'DIRECTORIES' => $directories);
aa201211 598 return $files;
599
600}
601
602
603/**
604 * Print variable
605 *
606 * sm_print_r($some_variable, [$some_other_variable [, ...]]);
607 *
608 * Debugging function - does the same as print_r, but makes sure special
609 * characters are converted to htmlentities first. This will allow
610 * values like <some@email.address> to be displayed.
611 * The output is wrapped in <<pre>> and <</pre>> tags.
612 * Since 1.4.2 accepts unlimited number of arguments.
613 * @since 1.4.1
614 * @return void
615 */
616function sm_print_r() {
617 ob_start(); // Buffer output
618 foreach(func_get_args() as $var) {
619 print_r($var);
620 echo "\n";
621 // php has get_class_methods function that can print class methods
622 if (is_object($var)) {
623 // get class methods if $var is object
624 $aMethods=get_class_methods(get_class($var));
625 // make sure that $aMethods is array and array is not empty
626 if (is_array($aMethods) && $aMethods!=array()) {
627 echo "Object methods:\n";
628 foreach($aMethods as $method) {
629 echo '* ' . $method . "\n";
630 }
631 }
632 echo "\n";
633 }
634 }
635 $buffer = ob_get_contents(); // Grab the print_r output
636 ob_end_clean(); // Silently discard the output & stop buffering
637 print '<div align="left"><pre>';
638 print htmlentities($buffer);
639 print '</pre></div>';
640}