source: branches/2.1/plugins/LocalFilesEditor/functions.inc.php @ 6343

Last change on this file since 6343 was 6343, checked in by plg, 14 years ago

merge r6341 from trunk to branch 2.1

Fix incorrect permissions

File size: 3.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24/**
25 * returns $code if php syntax is correct
26 * else return false
27 *
28 * @param string php code
29 */
30function eval_syntax($code)
31{
32  $code = str_replace(array('<?php', '?>'), '', $code);
33  if (function_exists('token_get_all'))
34  {
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    }
49  }
50  return '<?php' . $code . '?>';
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 */
60function 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
73/**
74 * returns bak file for restore
75 * @param string
76 */
77function 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 */
94function 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
114?>
Note: See TracBrowser for help on using the repository browser.