OSDN Git Service

BugTrack2/151: Cut unused lines from recent.dat
[pukiwiki/pukiwiki.git] / lib / file.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: file.php,v 1.51 2006/03/06 15:16:43 henoheno Exp $
4 // Copyright (C)
5 //   2002-2006 PukiWiki Developers Team
6 //   2001-2002 Originally written by yu-ji
7 // License: GPL v2 or (at your option) any later version
8 //
9 // File related functions
10
11 // Get source(wiki text) data of the page
12 function get_source($page = NULL, $lock = TRUE)
13 {
14         $array = array();
15
16         if (is_page($page)) {
17                 $path  = get_filename($page);
18
19                 if ($lock) {
20                         $fp = @fopen($path, 'r');
21                         if ($fp == FALSE) return $array;
22                         flock($fp, LOCK_SH);
23                 }
24
25                 // Removing line-feeds: Because file() doesn't remove them.
26                 $array = str_replace("\r", '', file($path));
27
28                 if ($lock) {
29                         flock($fp, LOCK_UN);
30                         @fclose($fp);
31                 }
32         }
33
34         return $array;
35 }
36
37 // Get last-modified filetime of the page
38 function get_filetime($page)
39 {
40         return is_page($page) ? filemtime(get_filename($page)) - LOCALZONE : 0;
41 }
42
43 // Get physical file name of the page
44 function get_filename($page)
45 {
46         return DATA_DIR . encode($page) . '.txt';
47 }
48
49 // Put a data(wiki text) into a physical file(diff, backup, text)
50 function page_write($page, $postdata, $notimestamp = FALSE)
51 {
52         global $trackback;
53
54         if (PKWK_READONLY) return; // Do nothing
55
56         $postdata = make_str_rules($postdata);
57
58         // Create and write diff
59         $oldpostdata = is_page($page) ? join('', get_source($page)) : '';
60         $diffdata    = do_diff($oldpostdata, $postdata);
61         file_write(DIFF_DIR, $page, $diffdata);
62
63         // Create backup
64         make_backup($page, $postdata == ''); // Is $postdata null?
65
66         // Create wiki text
67         file_write(DATA_DIR, $page, $postdata, $notimestamp);
68
69         if ($trackback) {
70                 // TrackBack Ping
71                 $_diff = explode("\n", $diffdata);
72                 $plus  = join("\n", preg_replace('/^\+/', '', preg_grep('/^\+/', $_diff)));
73                 $minus = join("\n", preg_replace('/^-/',  '', preg_grep('/^-/',  $_diff)));
74                 tb_send($page, $plus, $minus);
75         }
76
77         links_update($page);
78 }
79
80 // Modify original text with user-defined / system-defined rules
81 function make_str_rules($source)
82 {
83         global $str_rules, $fixed_heading_anchor;
84
85         $lines = explode("\n", $source);
86         $count = count($lines);
87
88         $modify    = TRUE;
89         $multiline = 0;
90         $matches   = array();
91         for ($i = 0; $i < $count; $i++) {
92                 $line = & $lines[$i]; // Modify directly
93
94                 // Ignore null string and preformatted texts
95                 if ($line == '' || $line{0} == ' ' || $line{0} == "\t") continue;
96
97                 // Modify this line?
98                 if ($modify) {
99                         if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
100                             $multiline == 0 &&
101                             preg_match('/#[^{]*(\{\{+)\s*$/', $line, $matches)) {
102                                 // Multiline convert plugin start
103                                 $modify    = FALSE;
104                                 $multiline = strlen($matches[1]); // Set specific number
105                         }
106                 } else {
107                         if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
108                             $multiline != 0 &&
109                             preg_match('/^\}{' . $multiline . '}\s*$/', $line)) {
110                                 // Multiline convert plugin end
111                                 $modify    = TRUE;
112                                 $multiline = 0;
113                         }
114                 }
115                 if ($modify === FALSE) continue;
116
117                 // Replace with $str_rules
118                 foreach ($str_rules as $pattern => $replacement)
119                         $line = preg_replace('/' . $pattern . '/', $replacement, $line);
120                 
121                 // Adding fixed anchor into headings
122                 if ($fixed_heading_anchor &&
123                     preg_match('/^(\*{1,3}.*?)(?:\[#([A-Za-z][\w-]*)\]\s*)?$/', $line, $matches) &&
124                     (! isset($matches[2]) || $matches[2] == '')) {
125                         // Generate unique id
126                         $anchor = generate_fixed_heading_anchor_id($matches[1]);
127                         $line = rtrim($matches[1]) . ' [#' . $anchor . ']';
128                 }
129         }
130
131         // Multiline part has no stopper
132         if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
133             $modify === FALSE && $multiline != 0)
134                 $lines[] = str_repeat('}', $multiline);
135
136         return implode("\n", $lines);
137 }
138
139 // Generate ID
140 function generate_fixed_heading_anchor_id($seed)
141 {
142         // A random alphabetic letter + 7 letters of random strings from md()
143         return chr(mt_rand(ord('a'), ord('z'))) .
144                 substr(md5(uniqid(substr($seed, 0, 100), TRUE)),
145                 mt_rand(0, 24), 7);
146 }
147
148 // Read top N lines as an array
149 // (Use PHP file() function if you want to get ALL lines)
150 function file_head($file, $count = 1)
151 {
152         $buffer = 8192;
153         $index  = 0;
154         $array  = array();
155
156         $fp = @fopen($file, 'r');
157         if ($fp == FALSE) return FALSE;
158         set_file_buffer($fp, 0);
159
160         flock($fp, LOCK_SH);
161         while (! feof($fp)) {
162                 $line = fgets($fp, $buffer);
163                 if ($line != FALSE) $array[] = $line;
164                 if (++$index >= $count) break;
165         }
166         flock($fp, LOCK_UN);
167
168         if(! fclose($fp)) return FALSE;
169
170         return $array;
171 }
172
173 // Output to a file
174 function file_write($dir, $page, $str, $notimestamp = FALSE)
175 {
176         global $update_exec, $_msg_invalidiwn, $notify, $notify_diff_only, $notify_subject;
177         global $whatsdeleted, $maxshow_deleted;
178
179         if (PKWK_READONLY) return; // Do nothing
180
181         if (! is_pagename($page))
182                 die_message(str_replace('$1', htmlspecialchars($page),
183                             str_replace('$2', 'WikiName', $_msg_invalidiwn)));
184
185         $page      = strip_bracket($page);
186         $file      = $dir . encode($page) . '.txt';
187         $timestamp = FALSE;
188
189         if ($str === '') {
190                 if ($dir == DATA_DIR && file_exists($file)) {
191                         // File deletion
192                         unlink($file);
193                         add_recent($page, $whatsdeleted, '', $maxshow_deleted); // RecentDeleted
194                 }
195         } else {
196                 // File replacement (Edit)
197                 $str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
198
199                 if ($notimestamp && file_exists($file))
200                         $timestamp = filemtime($file) - LOCALZONE;
201
202                 $fp = fopen($file, 'a') or die('fopen() failed: ' .
203                         htmlspecialchars(basename($dir) . '/' . encode($page) . '.txt') .       
204                         '<br />' . "\n" .
205                         'Maybe permission is not writable or filename is too long');
206                 set_file_buffer($fp, 0);
207
208                 flock($fp, LOCK_EX);
209
210                 // Write
211                 ftruncate($fp, 0);
212                 rewind($fp);
213                 fputs($fp, $str);
214
215                 flock($fp, LOCK_UN);
216
217                 fclose($fp);
218
219                 if ($timestamp) pkwk_touch_file($file, $timestamp + LOCALZONE);
220         }
221
222         // Clear is_page() cache
223         is_page($page, TRUE);
224
225         // Update RecentChanges
226         if (! $timestamp && $dir == DATA_DIR)
227                 put_lastmodified();
228
229         // Execute $update_exec here
230         if ($update_exec && $dir == DATA_DIR)
231                 system($update_exec . ' > /dev/null &');
232
233         if ($notify && $dir == DIFF_DIR) {
234                 if ($notify_diff_only) $str = preg_replace('/^[^-+].*\n/m', '', $str);
235
236                 $footer['ACTION'] = 'Page update';
237                 $footer['PAGE']   = & $page;
238                 $footer['URI']    = get_script_uri() . '?' . rawurlencode($page);
239                 $footer['USER_AGENT']  = TRUE;
240                 $footer['REMOTE_ADDR'] = TRUE;
241
242                 pkwk_mail_notify($notify_subject, $str, $footer) or
243                         die('pkwk_mail_notify(): Failed');
244         }
245 }
246
247 // Update RecentDeleted
248 function add_recent($page, $recentpage, $subject = '', $limit = 0)
249 {
250         if (PKWK_READONLY || $limit == 0 || $page == '' || $recentpage == '' ||
251             check_non_list($page)) return;
252
253         // Load
254         $lines = $matches = array();
255         foreach (get_source($recentpage) as $line)
256                 if (preg_match('/^-(.+) - (\[\[.+\]\])$/', $line, $matches))
257                         $lines[$matches[2]] = $line;
258
259         $_page = '[[' . $page . ']]';
260
261         // Remove a report about the same page
262         if (isset($lines[$_page])) unset($lines[$_page]);
263
264         // Add
265         array_unshift($lines, '-' . format_date(UTIME) . ' - ' . $_page .
266                 htmlspecialchars($subject) . "\n");
267
268         // Get latest $limit reports
269         $lines = array_splice($lines, 0, $limit);
270
271         // Update
272         $fp = fopen(get_filename($recentpage), 'w') or
273                 die_message('Cannot write page file ' .
274                 htmlspecialchars($recentpage) .
275                 '<br />Maybe permission is not writable or filename is too long');
276         set_file_buffer($fp, 0);
277         flock($fp, LOCK_EX);
278         rewind($fp);
279         fputs($fp, '#freeze'    . "\n");
280         fputs($fp, '#norelated' . "\n"); // :)
281         fputs($fp, join('', $lines));
282         flock($fp, LOCK_UN);
283         fclose($fp);
284 }
285
286 // Update RecentChanges
287 function put_lastmodified()
288 {
289         global $maxshow, $whatsnew, $autolink;
290
291         if (PKWK_READONLY) return; // Do nothing
292
293         // Get whole page list
294         $pages = get_existpages();
295
296         // Check ALL filetime
297         $recent_pages = array();
298         foreach($pages as $page)
299                 if ($page != $whatsnew && ! check_non_list($page))
300                         $recent_pages[$page] = get_filetime($page);
301
302         // Sort decending order of last-modification date
303         arsort($recent_pages, SORT_NUMERIC);
304
305         // Cut unused lines
306         $recent_pages = array_splice($recent_pages, 0, $maxshow);
307
308         // Create recent.dat (for recent.inc.php)
309         $file = 'recent.dat';
310         $fp = fopen(CACHE_DIR . $file, 'w') or
311                 die_message('Cannot write file ' .
312                 'CACHE_DIR/' . $file . '<br />' . "\n" .
313                 'Maybe permission is not writable');
314
315         set_file_buffer($fp, 0);
316         flock($fp, LOCK_EX);
317         rewind($fp);
318         foreach ($recent_pages as $page=>$time)
319                 fputs($fp, $time . "\t" . $page . "\n");
320         flock($fp, LOCK_UN);
321         fclose($fp);
322
323         // Create RecentChanges
324         $fp = fopen(get_filename($whatsnew), 'w') or
325                 die_message('Cannot write file ' .
326                 htmlspecialchars($whatsnew) . '<br />' . "\n" .
327                 'Maybe permission is not writable or filename is too long');
328
329         set_file_buffer($fp, 0);
330         flock($fp, LOCK_EX);
331         rewind($fp);
332
333         foreach (array_keys($recent_pages) as $page) {
334                 $time      = $recent_pages[$page];
335                 $s_lastmod = htmlspecialchars(format_date($time));
336                 $s_page    = htmlspecialchars($page);
337                 fputs($fp, '-' . $s_lastmod . ' - [[' . $s_page . ']]' . "\n");
338         }
339         fputs($fp, '#norelated' . "\n"); // :)
340         flock($fp, LOCK_UN);
341         fclose($fp);
342
343         // For AutoLink
344         if ($autolink) {
345                 list($pattern, $pattern_a, $forceignorelist) =
346                         get_autolink_pattern($pages);
347
348                 $file = 'autolink.dat';
349                 $fp = fopen(CACHE_DIR . $file, 'w') or
350                         die_message('Cannot write file ' .
351                         'CACHE_DIR/' . $file . '<br />' . "\n" .
352                         'Maybe permission is not writable');
353                 
354                 set_file_buffer($fp, 0);
355                 flock($fp, LOCK_EX);
356                 rewind($fp);
357                 fputs($fp, $pattern   . "\n");
358                 fputs($fp, $pattern_a . "\n");
359                 fputs($fp, join("\t", $forceignorelist) . "\n");
360                 flock($fp, LOCK_UN);
361                 fclose($fp);
362         }
363 }
364
365 // Get elapsed date of the page
366 function get_pg_passage($page, $sw = TRUE)
367 {
368         global $show_passage;
369         if (! $show_passage) return '';
370
371         $time = get_filetime($page);
372         $pg_passage = ($time != 0) ? get_passage($time) : '';
373
374         return $sw ? '<small>' . $pg_passage . '</small>' : ' ' . $pg_passage;
375 }
376
377 // Last-Modified header
378 function header_lastmod($page = NULL)
379 {
380         global $lastmod;
381
382         if ($lastmod && is_page($page)) {
383                 pkwk_headers_sent();
384                 header('Last-Modified: ' .
385                         date('D, d M Y H:i:s', get_filetime($page)) . ' GMT');
386         }
387 }
388
389 // Get a page list of this wiki
390 function get_existpages($dir = DATA_DIR, $ext = '.txt')
391 {
392         $aryret = array();
393
394         $pattern = '((?:[0-9A-F]{2})+)';
395         if ($ext != '') $ext = preg_quote($ext, '/');
396         $pattern = '/^' . $pattern . $ext . '$/';
397
398         $dp = @opendir($dir) or
399                 die_message($dir . ' is not found or not readable.');
400         $matches = array();
401         while ($file = readdir($dp))
402                 if (preg_match($pattern, $file, $matches))
403                         $aryret[$file] = decode($matches[1]);
404         closedir($dp);
405
406         return $aryret;
407 }
408
409 // Get PageReading(pronounce-annotated) data in an array()
410 function get_readings()
411 {
412         global $pagereading_enable, $pagereading_kanji2kana_converter;
413         global $pagereading_kanji2kana_encoding, $pagereading_chasen_path;
414         global $pagereading_kakasi_path, $pagereading_config_page;
415         global $pagereading_config_dict;
416
417         $pages = get_existpages();
418
419         $readings = array();
420         foreach ($pages as $page) 
421                 $readings[$page] = '';
422
423         $deletedPage = FALSE;
424         $matches = array();
425         foreach (get_source($pagereading_config_page) as $line) {
426                 $line = chop($line);
427                 if(preg_match('/^-\[\[([^]]+)\]\]\s+(.+)$/', $line, $matches)) {
428                         if(isset($readings[$matches[1]])) {
429                                 // This page is not clear how to be pronounced
430                                 $readings[$matches[1]] = $matches[2];
431                         } else {
432                                 // This page seems deleted
433                                 $deletedPage = TRUE;
434                         }
435                 }
436         }
437
438         // If enabled ChaSen/KAKASI execution
439         if($pagereading_enable) {
440
441                 // Check there's non-clear-pronouncing page
442                 $unknownPage = FALSE;
443                 foreach ($readings as $page => $reading) {
444                         if($reading == '') {
445                                 $unknownPage = TRUE;
446                                 break;
447                         }
448                 }
449
450                 // Execute ChaSen/KAKASI, and get annotation
451                 if($unknownPage) {
452                         switch(strtolower($pagereading_kanji2kana_converter)) {
453                         case 'chasen':
454                                 if(! file_exists($pagereading_chasen_path))
455                                         die_message('ChaSen not found: ' . $pagereading_chasen_path);
456
457                                 $tmpfname = tempnam(realpath(CACHE_DIR), 'PageReading');
458                                 $fp = fopen($tmpfname, 'w') or
459                                         die_message('Cannot write temporary file "' . $tmpfname . '".' . "\n");
460                                 foreach ($readings as $page => $reading) {
461                                         if($reading != '') continue;
462                                         fputs($fp, mb_convert_encoding($page . "\n",
463                                                 $pagereading_kanji2kana_encoding, SOURCE_ENCODING));
464                                 }
465                                 fclose($fp);
466
467                                 $chasen = "$pagereading_chasen_path -F %y $tmpfname";
468                                 $fp     = popen($chasen, 'r');
469                                 if($fp === FALSE) {
470                                         unlink($tmpfname);
471                                         die_message('ChaSen execution failed: ' . $chasen);
472                                 }
473                                 foreach ($readings as $page => $reading) {
474                                         if($reading != '') continue;
475
476                                         $line = fgets($fp);
477                                         $line = mb_convert_encoding($line, SOURCE_ENCODING,
478                                                 $pagereading_kanji2kana_encoding);
479                                         $line = chop($line);
480                                         $readings[$page] = $line;
481                                 }
482                                 pclose($fp);
483
484                                 unlink($tmpfname) or
485                                         die_message('Temporary file can not be removed: ' . $tmpfname);
486                                 break;
487
488                         case 'kakasi':  /*FALLTHROUGH*/
489                         case 'kakashi':
490                                 if(! file_exists($pagereading_kakasi_path))
491                                         die_message('KAKASI not found: ' . $pagereading_kakasi_path);
492
493                                 $tmpfname = tempnam(realpath(CACHE_DIR), 'PageReading');
494                                 $fp       = fopen($tmpfname, 'w') or
495                                         die_message('Cannot write temporary file "' . $tmpfname . '".' . "\n");
496                                 foreach ($readings as $page => $reading) {
497                                         if($reading != '') continue;
498                                         fputs($fp, mb_convert_encoding($page . "\n",
499                                                 $pagereading_kanji2kana_encoding, SOURCE_ENCODING));
500                                 }
501                                 fclose($fp);
502
503                                 $kakasi = "$pagereading_kakasi_path -kK -HK -JK < $tmpfname";
504                                 $fp     = popen($kakasi, 'r');
505                                 if($fp === FALSE) {
506                                         unlink($tmpfname);
507                                         die_message('KAKASI execution failed: ' . $kakasi);
508                                 }
509
510                                 foreach ($readings as $page => $reading) {
511                                         if($reading != '') continue;
512
513                                         $line = fgets($fp);
514                                         $line = mb_convert_encoding($line, SOURCE_ENCODING,
515                                                 $pagereading_kanji2kana_encoding);
516                                         $line = chop($line);
517                                         $readings[$page] = $line;
518                                 }
519                                 pclose($fp);
520
521                                 unlink($tmpfname) or
522                                         die_message('Temporary file can not be removed: ' . $tmpfname);
523                                 break;
524
525                         case 'none':
526                                 $patterns = $replacements = $matches = array();
527                                 foreach (get_source($pagereading_config_dict) as $line) {
528                                         $line = chop($line);
529                                         if(preg_match('|^ /([^/]+)/,\s*(.+)$|', $line, $matches)) {
530                                                 $patterns[]     = $matches[1];
531                                                 $replacements[] = $matches[2];
532                                         }
533                                 }
534                                 foreach ($readings as $page => $reading) {
535                                         if($reading != '') continue;
536
537                                         $readings[$page] = $page;
538                                         foreach ($patterns as $no => $pattern)
539                                                 $readings[$page] = mb_convert_kana(mb_ereg_replace($pattern,
540                                                         $replacements[$no], $readings[$page]), 'aKCV');
541                                 }
542                                 break;
543
544                         default:
545                                 die_message('Unknown kanji-kana converter: ' . $pagereading_kanji2kana_converter . '.');
546                                 break;
547                         }
548                 }
549
550                 if($unknownPage || $deletedPage) {
551
552                         asort($readings); // Sort by pronouncing(alphabetical/reading) order
553                         $body = '';
554                         foreach ($readings as $page => $reading)
555                                 $body .= '-[[' . $page . ']] ' . $reading . "\n";
556
557                         page_write($pagereading_config_page, $body);
558                 }
559         }
560
561         // Pages that are not prounouncing-clear, return pagenames of themselves
562         foreach ($pages as $page) {
563                 if($readings[$page] == '')
564                         $readings[$page] = $page;
565         }
566
567         return $readings;
568 }
569
570 // Get a list of encoded files (must specify a directory and a suffix)
571 function get_existfiles($dir, $ext)
572 {
573         $pattern = '/^(?:[0-9A-F]{2})+' . preg_quote($ext, '/') . '$/';
574         $aryret = array();
575         $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
576         while ($file = readdir($dp))
577                 if (preg_match($pattern, $file))
578                         $aryret[] = $dir . $file;
579         closedir($dp);
580         return $aryret;
581 }
582
583 // Get a list of related pages of the page
584 function links_get_related($page)
585 {
586         global $vars, $related;
587         static $links = array();
588
589         if (isset($links[$page])) return $links[$page];
590
591         // If possible, merge related pages generated by make_link()
592         $links[$page] = ($page == $vars['page']) ? $related : array();
593
594         // Get repated pages from DB
595         $links[$page] += links_get_related_db($vars['page']);
596
597         return $links[$page];
598 }
599
600 // _If needed_, re-create the file to change/correct ownership into PHP's
601 // NOTE: Not works for Windows
602 function pkwk_chown($filename, $preserve_time = TRUE)
603 {
604         static $php_uid; // PHP's UID
605
606         if (! isset($php_uid)) {
607                 if (extension_loaded('posix')) {
608                         $php_uid = posix_getuid(); // Unix
609                 } else {
610                         $php_uid = 0; // Windows
611                 }
612         }
613
614         // Lock for pkwk_chown()
615         $lockfile = CACHE_DIR . 'pkwk_chown.lock';
616         $flock = fopen($lockfile, 'a') or
617                 die('pkwk_chown(): fopen() failed for: CACHEDIR/' .
618                         basename(htmlspecialchars($lockfile)));
619         flock($flock, LOCK_EX) or die('pkwk_chown(): flock() failed for lock');
620
621         // Check owner
622         $stat = stat($filename) or
623                 die('pkwk_chown(): stat() failed for: '  . basename(htmlspecialchars($filename)));
624         if ($stat[4] === $php_uid) {
625                 // NOTE: Windows always here
626                 $result = TRUE; // Seems the same UID. Nothing to do
627         } else {
628                 $tmp = $filename . '.' . getmypid() . '.tmp';
629
630                 // Lock source $filename to avoid file corruption
631                 // NOTE: Not 'r+'. Don't check write permission here
632                 $ffile = fopen($filename, 'r') or
633                         die('pkwk_chown(): fopen() failed for: ' .
634                                 basename(htmlspecialchars($filename)));
635
636                 // Try to chown by re-creating files
637                 // NOTE:
638                 //   * touch() before copy() is for 'rw-r--r--' instead of 'rwxr-xr-x' (with umask 022).
639                 //   * (PHP 4 < PHP 4.2.0) touch() with the third argument is not implemented and retuns NULL and Warn.
640                 //   * @unlink() before rename() is for Windows but here's for Unix only
641                 flock($ffile, LOCK_EX) or die('pkwk_chown(): flock() failed');
642                 $result = touch($tmp) && copy($filename, $tmp) &&
643                         ($preserve_time ? (touch($tmp, $stat[9], $stat[8]) || touch($tmp, $stat[9])) : TRUE) &&
644                         rename($tmp, $filename);
645                 flock($ffile, LOCK_UN) or die('pkwk_chown(): flock() failed');
646
647                 fclose($ffile) or die('pkwk_chown(): fclose() failed');
648
649                 if ($result === FALSE) @unlink($tmp);
650         }
651
652         // Unlock for pkwk_chown()
653         flock($flock, LOCK_UN) or die('pkwk_chown(): flock() failed for lock');
654         fclose($flock) or die('pkwk_chown(): fclose() failed for lock');
655
656         return $result;
657 }
658
659 // touch() with trying pkwk_chown()
660 function pkwk_touch_file($filename, $time = FALSE, $atime = FALSE)
661 {
662         // Is the owner incorrected and unable to correct?
663         if (! file_exists($filename) || pkwk_chown($filename)) {
664                 if ($time === FALSE) {
665                         $result = touch($filename);
666                 } else if ($atime === FALSE) {
667                         $result = touch($filename, $time);
668                 } else {
669                         $result = touch($filename, $time, $atime);
670                 }
671                 return $result;
672         } else {
673                 die('pkwk_touch_file(): Invalid UID and (not writable for the directory or not a flie): ' .
674                         htmlspecialchars(basename($filename)));
675         }
676 }
677 ?>