diff --git a/www/php/remind.php b/www/php/remind.php new file mode 100644 index 00000000..5922f86d --- /dev/null +++ b/www/php/remind.php @@ -0,0 +1,94 @@ + 0, + 'error' => 'Could not find any Rem2PS data'); + } + + $line = fgets($fp); + if ($line === false) { + return array('success' => 0, + 'error' => 'Unexpected end-of-file'); + } + + $line = trim($line); + list($month, $year, $days_in_mon, $first_day, $monday_flag) = explode(' ', $line); + $retval = array('month' => $month, + 'year' => $year, + 'days_in_mon' => $days_in_mon, + 'first_day' => $first_day, + 'monday_flag' => $monday_flag); + + $line = fgets($fp); + if ($line === false) { + return array('success' => 0, + 'error' => 'Unexpected end-of-file'); + } + + $line = trim($line); + $retval['day_names'] = explode(' ', $line); + + $line = fgets($fp); + if ($line === false) { + return array('success' => 0, + 'error' => 'Unexpected end-of-file'); + } + $line = trim($line); + + list($m, $n) = explode(' ', $line); + $retval['prev'] = array('month' => $m, 'days' => $n); + + $line = fgets($fp); + if ($line === false) { + return array('success' => 0, + 'error' => 'Unexpected end-of-file'); + } + $line = trim($line); + + list($m, $n) = explode(' ', $line); + $retval['next'] = array('month' => $m, 'days' => $n); + + $line_info = 0; + + $entries = array(); + while (1) { + $line = fgets($fp); + if ($line === false) break; + $line = trim($line); + if ($line == '# rem2ps end') break; + if (strpos($line, '# fileinfo ') === 0) { + list($lno, $fname) = explode(' ', substr($line, 12), 2); + $lineinfo = array('file' => $fname, 'line' => $lno); + continue; + } + list($date, $special, $tags, $duration, $time, $body) = explode(' ', $line, 6); + $entry = array('date' => $date, + 'special' => $special, + 'tags' => $tags, + 'duration' => $duration, + 'time' => $time, + 'body' => $body); + if (is_array($lineinfo)) { + $entry['line'] = $lineinfo['line']; + $entry['file'] = $lineinfo['file']; + $lineinfo = 0; + } + $entries[] = $entry; + } + $retval['entries'] = $entries; + return array('success' => 1, 'results' => $retval); + } + +$fp = popen('rem -p -l', 'r'); +$ans = parse_remind_output($fp); +pclose($fp); +print_r($ans); + +?> \ No newline at end of file