- global $last_updated_file, $current_time;
-
- $file = fopen($last_updated_file, 'r');
-
- if ($file) {
- $last = fgets($file);
- } else {
- print "Unable to read $last_updated_file. Using current time.\n";
- return $current_time;
- }
-
- fclose($file);
-
- return $last;
+ global $last_updated_file, $current_time;
+ $last = $current_time;
+
+ if (file_exists($last_updated_file) &&
+ ($file = fopen($last_updated_file, 'r'))) {
+ $last = fgets($file);
+ } else {
+ print "$last_updated_file doesn't exit. Trying to create it...\n";
+ $file = fopen($last_updated_file, 'w+') or
+ die("Can't open $last_updated_file for writing!\n");
+ print 'Success. Using current time (' . date('r', $last) .
+ ") to look for new notices.\n";
+ }
+
+ fclose($file);
+ return $last;