2 // vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
3 // +--------------------------------------------------------------------+
5 // +--------------------------------------------------------------------+
6 // | This file is part of Hooks. |
8 // | Hooks is free software; you can redistribute it and/or modify it |
9 // | under the terms of the GNU General Public License as published by |
10 // | the Free Software Foundation; either version 2 of the License, or |
11 // | (at your option) any later version. |
13 // | Hooks 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. |
18 // | You should have received a copy of the GNU General Public License |
19 // | along with Hooks; if not, write to the Free Software Foundation, |
20 // | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 // +--------------------------------------------------------------------+
22 // | Created: lun ene 6 17:22:31 ART 2003 |
23 // | Authors: Leandro Lucarella <luca@lugmen.org.ar> |
24 // +--------------------------------------------------------------------+
30 * General file utilities functions.
32 * This is a group of static functions for getting file info and other
36 * @author Leandro Lucarella <luca@lugmen.org.ar>
44 * Splits a filename into path, filename and extension.
46 * @param string $file Filename to split.
48 * @return array Array where the first element (index 0) is the
49 * path, the second is the name and the third is the
55 function splitFilename($file)
57 $path = preg_split('|/|', $file);
58 $file = array_pop($path);
60 if (strstr($file, '.')) {
61 preg_match('|([^/]+?)(\.([^\.]*))?$|', $file, $m);
62 $file = @$m[1] . ((@$m[2] == '.' ) ? '.' : '');
65 $dir = count($path) ? join('/', $path) : '';
66 return array($dir, $file, $ext);
70 * Tells if a file is readable looking in the include path.
72 * @param string $file Name of the file to look for.
74 * @return bool True if file is readable, false if not.
79 function isReadableInclude($file)
81 list($dir, $page, $ext) = File_Util::splitFilename($file);
82 if (is_readable($file)) {
85 $include_path = array_unique(preg_split('/:/', ini_get('include_path')));
86 foreach ($include_path as $path) {
87 if (is_readable("$path/$file")) {
95 * Gets the last modification date/time for a file.
97 * @param string $file Name of the file to get the last modification
99 * @param string $format Format (see strftime).
101 * @return string Formated string with the last modification
108 function lastModified($file, $format = '%c')
110 return strftime($format, filemtime($file));
115 // This is a workarround to live until PHP 4.3 is out and we can use the
116 // native get_file_contents() function. We don't care about
117 // $use_include_file option.
118 function file_get_contents($file, $use_include_file = false)
120 if (@is_readable($file)) {
121 $var = join('', file($file));