[2291] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[2291] | 23 | |
---|
| 24 | /** |
---|
| 25 | * returns $code if php syntax is correct |
---|
| 26 | * else return false |
---|
| 27 | * |
---|
| 28 | * @param string php code |
---|
| 29 | */ |
---|
| 30 | function eval_syntax($code) |
---|
| 31 | { |
---|
[2588] | 32 | $code = str_replace(array('<?php', '?>'), '', $code); |
---|
[2914] | 33 | if (function_exists('token_get_all')) |
---|
[2588] | 34 | { |
---|
[2914] | 35 | $b = 0; |
---|
| 36 | foreach (token_get_all($code) as $token) |
---|
| 37 | { |
---|
| 38 | if ('{' == $token) ++$b; |
---|
| 39 | else if ('}' == $token) --$b; |
---|
| 40 | } |
---|
| 41 | if ($b) return false; |
---|
| 42 | else |
---|
| 43 | { |
---|
| 44 | ob_start(); |
---|
| 45 | $eval = eval('if(0){' . $code . '}'); |
---|
| 46 | ob_end_clean(); |
---|
| 47 | if ($eval === false) return false; |
---|
| 48 | } |
---|
[2588] | 49 | } |
---|
| 50 | return '<?php' . $code . '?>'; |
---|
[2291] | 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * returns true or false if $str is bool |
---|
| 55 | * returns $str if $str is integer |
---|
| 56 | * else "$str" |
---|
| 57 | * |
---|
| 58 | * @param string |
---|
| 59 | */ |
---|
| 60 | function editarea_quote($value) |
---|
| 61 | { |
---|
| 62 | switch (gettype($value)) |
---|
| 63 | { |
---|
| 64 | case "boolean": |
---|
| 65 | return $value ? 'true' : 'false'; |
---|
| 66 | case "integer": |
---|
| 67 | return $value; |
---|
| 68 | default: |
---|
| 69 | return '"'.$value.'"'; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
[2588] | 73 | /** |
---|
| 74 | * returns bak file for restore |
---|
| 75 | * @param string |
---|
| 76 | */ |
---|
| 77 | function get_bak_file($file) |
---|
| 78 | { |
---|
| 79 | if (get_extension($file) == 'php') |
---|
| 80 | { |
---|
| 81 | return substr_replace($file, '.bak', strrpos($file , '.'), 0); |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | return $file . '.bak'; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * returns dirs and subdirs |
---|
| 91 | * retun array |
---|
| 92 | * @param string |
---|
| 93 | */ |
---|
| 94 | function get_rec_dirs($path='') |
---|
| 95 | { |
---|
| 96 | $options = array(); |
---|
| 97 | if (is_dir($path)) |
---|
| 98 | { |
---|
| 99 | $fh = opendir($path); |
---|
| 100 | while ($file = readdir($fh)) |
---|
| 101 | { |
---|
| 102 | $pathfile = $path . '/' . $file; |
---|
| 103 | if ($file != '.' and $file != '..' and $file != '.svn' and is_dir($pathfile)) |
---|
| 104 | { |
---|
| 105 | $options[$pathfile] = str_replace(array('./', '/'), array('', ' / '), $pathfile); |
---|
| 106 | $options = array_merge($options, get_rec_dirs($pathfile)); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | closedir($fh); |
---|
| 110 | } |
---|
| 111 | return $options; |
---|
| 112 | } |
---|
| 113 | |
---|
[2291] | 114 | ?> |
---|