From 7211eee1caba1b1d798449b6df6def86c50552ef Mon Sep 17 00:00:00 2001 From: patdenice Date: Wed, 13 Apr 2011 10:38:45 +0000 Subject: merge r10348 from trunk to branch 2.2 Clean code git-svn-id: http://piwigo.org/svn/branches/2.2@10349 68402e56-0260-453c-a942-63ccdbb3a9ee --- plugins/LocalFilesEditor/include/functions.inc.php | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 plugins/LocalFilesEditor/include/functions.inc.php (limited to 'plugins/LocalFilesEditor/include/functions.inc.php') diff --git a/plugins/LocalFilesEditor/include/functions.inc.php b/plugins/LocalFilesEditor/include/functions.inc.php new file mode 100644 index 000000000..b85887852 --- /dev/null +++ b/plugins/LocalFilesEditor/include/functions.inc.php @@ -0,0 +1,114 @@ +'), '', $code); + if (function_exists('token_get_all')) + { + $b = 0; + foreach (token_get_all($code) as $token) + { + if ('{' == $token) ++$b; + else if ('}' == $token) --$b; + } + if ($b) return false; + else + { + ob_start(); + $eval = eval('if(0){' . $code . '}'); + ob_end_clean(); + if ($eval === false) return false; + } + } + return ''; +} + +/** + * returns true or false if $str is bool + * returns $str if $str is integer + * else "$str" + * + * @param string + */ +function editarea_quote($value) +{ + switch (gettype($value)) + { + case "boolean": + return $value ? 'true' : 'false'; + case "integer": + return $value; + default: + return '"'.$value.'"'; + } +} + +/** + * returns bak file for restore + * @param string + */ +function get_bak_file($file) +{ + if (get_extension($file) == 'php') + { + return substr_replace($file, '.bak', strrpos($file , '.'), 0); + } + else + { + return $file . '.bak'; + } +} + +/** + * returns dirs and subdirs + * retun array + * @param string + */ +function get_rec_dirs($path='') +{ + $options = array(); + if (is_dir($path)) + { + $fh = opendir($path); + while ($file = readdir($fh)) + { + $pathfile = $path . '/' . $file; + if ($file != '.' and $file != '..' and $file != '.svn' and is_dir($pathfile)) + { + $options[$pathfile] = str_replace(array('./', '/'), array('', ' / '), $pathfile); + $options = array_merge($options, get_rec_dirs($pathfile)); + } + } + closedir($fh); + } + return $options; +} + +?> \ No newline at end of file -- cgit v1.2.3