1<?php
2//setlocale(LC_ALL, 'German_Germany.1252',"deu_deu",'de_DE@euro', 'de_DE', 'de', 'ge');
3function hcal_parseCommand($match) {
4# print $match."\n";
5  $start_yy = $start_mth = $start_day = $start_hh = $start_min = $start_sec  = '';
6  $end_yy   = $end_mth   = $end_day   = $end_hh   = $end_min   = $end_sec    = '';
7  if (strpos($match,'hcali') != 0) {
8    $match = html_entity_decode(substr($match, 8, -2));
9    $inlineentry = true;
10  } else {
11    $match = html_entity_decode(substr($match, 7, -2));
12    $inlineentry = false;
13  }
14  @list($time_info,$summary,$location) = explode('|',$match,3);
15  @list($start_info,$end_info) = explode(';',$time_info,2);
16  @list($start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data, $err) = hcal_parseEntry($start_info);
17  if (!isset($err)) {
18    if (isset($end_info)) {
19      @list($end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data, $err) = hcal_parseEntry($end_info);
20      if (!isset($end_data)) {
21	$end_data = strtotime($start_yy.'/'.$start_mth.'/'.$start_day.' '.$end_hh.':'.$end_min.':'.$end_sec);
22      }
23    }
24  }
25  return array($summary, $location,
26	       $start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data,
27	       $end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data,
28	       $err);
29}
30function hcal_parseEntry($time_info) {
31  $times = array();
32  if (!preg_match('/(\d{4}\/\d{2}\/\d{2})(\[\d{2}:\d{2}:\d{2}\])/',$time_info)) {
33    if (preg_match('/(\d{4}\/\d{2}\/\d{2})(\[\d{2}:\d{2}\])/',$time_info)) {
34      $time_info = str_replace(']',':00]',$time_info);
35    } else {
36      $err = "Wrong time format";
37    }
38  }
39  if (preg_match('/(\d{4}\/\d{2}\/\d{2})(\[\d{2}:\d{2}:\d{2}\])?/',$time_info,$times)) {
40    return hcal_parseDateTimeEntry($times);
41  } else if (preg_match('/(\[\d{2}:\d{2}:\d{2}\])?/',$time_info,$times)) {
42    return hcal_parseTimeEntry($times);
43  }
44  $time_yy = $time_mth = $time_day = $time_hh = $time_min = $time_sec = '';
45  return array($time_yy,$time_mth,$time_day,$time_hh,$time_min,$time_sec);
46}
47function hcal_parseDateTimeEntry($times) {
48  list(,$time_date,$time_time) = $times;
49  if (!isset($time_date)) { $err = 'No Time date';}
50  list($time_yy,$time_mth,$time_day) = explode('/',$time_date);
51  $time = strtotime($time_date);
52  if (isset($time_time)) {
53    $time_time = str_replace('[',null,$time_time);
54    $time_time = str_replace(']',null,$time_time);
55    @list($time_hh,$time_min,$time_sec) = explode(':',$time_time);
56    $time = strtotime($time_date." ".$time_time);
57  }
58  return array($time_yy,$time_mth,$time_day,$time_hh,$time_min,$time_sec, $time, $err);
59}
60function hcal_parseTimeEntry($times) {
61  @list($time_time) = $times;
62  $err = null;
63  if (isset($time_time)) {
64    $time_time = str_replace('[',null,$time_time);
65    $time_time = str_replace(']',null,$time_time);
66    @list($time_hh,$time_min,$time_sec) = explode(':',$time_time);
67  }
68  $time_yy = $time_mth = $time_day = '';
69  return array($time_yy,$time_mth,$time_day,$time_hh,$time_min,$time_sec,null,$err);
70}
71
72function hcal_parseDateEntry($time_date) {
73	@list($time_yy,$time_mth,$time_day) = explode('/',$time_date);
74	return array($time_yy,$time_mth,$time_day);
75}
76
77function hcal_parseTimeEntrie($time_time) {
78	@list($time_hh,$time_min,$time_sec) = explode(':',$time_time);
79	return array($time_hh,$time_min,$time_sec);
80}
81/*
82@list($summary, $location,
83      $start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data,
84      $end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data,
85      $err) = hcal_parseCommand("{{hcal>2008/07/02|Summary|Location}}");
86print $err." ";
87print date('d.F Y H:i:s',$start_data)." ";
88print date('d.F Y H:i:s',$end_data)."\n";
89@list($summary, $location,
90      $start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data,
91      $end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data,
92      $err) = hcal_parseCommand("{{hcal>2008/07/02[18:00:00]|Summary|Location}}");
93print $err." ";
94print date('d.F Y H:i:s',$start_data)." ";
95print date('d.F Y H:i:s',$end_data)."\n";
96@list($summary, $location,
97      $start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data,
98      $end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data,
99      $err) = hcal_parseCommand("{{hcal>2008/07/02[18:00:00];[19:00:00]|Summary|Location}}");
100print $err." ";
101print date('d.F Y H:i:s',$start_data)." ";
102print date('d.F Y H:i:s',$end_data)."\n";
103@list($summary, $location,
104      $start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data,
105      $end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data,
106      $err) = hcal_parseCommand("{{hcal>2008/07/02[18:00:00];2008/07/03[19:00:00]|Summary|Location}}");
107print $err." ";
108print date('d.F Y H:i:s',$start_data)." ";
109print date('d.F Y H:i:s',$end_data)."\n";
110@list($summary, $location,
111      $start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data,
112      $end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data,
113      $err) = hcal_parseCommand("{{hcal>2008/07/02[18:00];2008/07/03[19:00]|Summary|Location}}");
114print $err." ";
115print date('d.F Y H:i:s',$start_data)." ";
116print date('d.F Y H:i:s',$end_data)."\n";
117@list($summary, $location,
118      $start_yy,$start_mth,$start_day,$start_hh,$start_min,$start_sec,$start_data,
119      $end_yy,$end_mth,$end_day,$end_hh,$end_min,$end_sec,$end_data,
120      $err) = hcal_parseCommand("{{hcal>2008/07/02;2008/07/03|Summary|Location}}");
121print $err." ";
122print date('d.F Y H:i:s',$start_data)." ";
123print date('d.F Y H:i:s',$end_data)."\n";
124*/
125