From aa201211dd345d2f21be5bbb02c074d6853d7846 Mon Sep 17 00:00:00 2001 From: pdontthink Date: Thu, 28 Sep 2006 14:17:15 +0000 Subject: [PATCH] Moving sm_print_r back to globals.php; tired of it not being available when developing - that's what it's for, more than being available for actual code use as a string function in a file that's not included high enough. Also new directory parsing fxn. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11751 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/global.php | 103 ++++++++++++++++++++++++++++++++++++++++++ functions/strings.php | 39 ---------------- 2 files changed, 103 insertions(+), 39 deletions(-) diff --git a/functions/global.php b/functions/global.php index 3e7e0ec4..fbbac6fc 100644 --- a/functions/global.php +++ b/functions/global.php @@ -429,3 +429,106 @@ function php_self () { return ''; } + + +/** + * Find files in a given directory optionally limited to only + * those with the given file extension. If the directory is + * not found or cannot be opened, no error is generated; only + * an empty file list is returned. +FIXME: do we WANT to throw an error or a notice or... or return FALSE? + * + * @param string $directory_path The path (relative or absolute) + * to the desired directory. + * @param string $extension The file extension filter (optional; + * default is to return all files. + * @param boolean $return_filenames_only When TRUE, only file names + * are returned, otherwise the + * $directory_path string is + * prepended to each file in + * the returned list (optional; + * default is filename only) + * + * @return array The requested file list. + * + * @since 1.5.2 + * + */ +function list_files($directory_path, $extension='', $return_filenames_only=TRUE) { + + $files = array(); + +//FIXME: do we want to place security restrictions here like only allowing +// directories under SM_PATH? + // validate given directory + // + if (empty($directory_path) + || !is_dir($directory_path) + || !($DIR = opendir($directory_path))) { + return $files; + } + + + // parse through the files + // + $extension = '.' . trim($extension, '.'); + while (($file = readdir($DIR)) !== false) { + + if ($file == '.' || $file == '..') continue; + + if (empty($extension) + || strrpos($file, $extension) === (strlen($file) - strlen($extension))) { + $files[] = ($return_filenames_only + ? $file + : $directory_path . '/' . $file); + } + + } + closedir($DIR); + + + return $files; + +} + + +/** + * Print variable + * + * sm_print_r($some_variable, [$some_other_variable [, ...]]); + * + * Debugging function - does the same as print_r, but makes sure special + * characters are converted to htmlentities first. This will allow + * values like to be displayed. + * The output is wrapped in <
> and <
> tags. + * Since 1.4.2 accepts unlimited number of arguments. + * @since 1.4.1 + * @return void + */ +function sm_print_r() { + ob_start(); // Buffer output + foreach(func_get_args() as $var) { + print_r($var); + echo "\n"; + // php has get_class_methods function that can print class methods + if (is_object($var)) { + // get class methods if $var is object + $aMethods=get_class_methods(get_class($var)); + // make sure that $aMethods is array and array is not empty + if (is_array($aMethods) && $aMethods!=array()) { + echo "Object methods:\n"; + foreach($aMethods as $method) { + echo '* ' . $method . "\n"; + } + } + echo "\n"; + } + } + $buffer = ob_get_contents(); // Grab the print_r output + ob_end_clean(); // Silently discard the output & stop buffering + print '
';
+    print htmlentities($buffer);
+    print '
'; +} + + diff --git a/functions/strings.php b/functions/strings.php index b804a6f0..68ffbe1e 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -818,45 +818,6 @@ function makeComposeLink($url, $text = null, $target='') { return makeInternalLink($url, $text, '_blank'); } -/** - * Print variable - * - * sm_print_r($some_variable, [$some_other_variable [, ...]]); - * - * Debugging function - does the same as print_r, but makes sure special - * characters are converted to htmlentities first. This will allow - * values like to be displayed. - * The output is wrapped in <
> and <
> tags. - * Since 1.4.2 accepts unlimited number of arguments. - * @since 1.4.1 - * @return void - */ -function sm_print_r() { - ob_start(); // Buffer output - foreach(func_get_args() as $var) { - print_r($var); - echo "\n"; - // php has get_class_methods function that can print class methods - if (is_object($var)) { - // get class methods if $var is object - $aMethods=get_class_methods(get_class($var)); - // make sure that $aMethods is array and array is not empty - if (is_array($aMethods) && $aMethods!=array()) { - echo "Object methods:\n"; - foreach($aMethods as $method) { - echo '* ' . $method . "\n"; - } - } - echo "\n"; - } - } - $buffer = ob_get_contents(); // Grab the print_r output - ob_end_clean(); // Silently discard the output & stop buffering - print '
';
-    print htmlentities($buffer);
-    print '
'; -} - /** * version of fwrite which checks for failure * @param resource $fp -- 2.25.1