PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/add-ons/ical/functions/ical_parser.php

https://github.com/jcplat/console-seolan
PHP | 702 lines | 488 code | 47 blank | 167 comment | 107 complexity | ba6dbcc927d398217b7b78a6a0a40799 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. // Version 2.3.1
  3. // Modifications :
  4. // define('BASE', 'add-ons/ical/');
  5. // mettre en comm les includes de init,draw_functions,/overlapping_events
  6. // ajouter $mArray_begin et $mArray_end
  7. // commenter tout le if ($phpiCal_config->save_parsed_cals == 'yes')
  8. // $cal_filelist=array($filename)
  9. // commenter include(BASE.'functions/parse/parse_tzs.php');
  10. // commenter tous le if (isset($master_array) && is_array($master_array) && $phpiCal_config->save_parsed_cals == 'yes')
  11. // commenter toute la fin
  12. // remplacer count acev 52
  13. // SUM,LOC DESCr : $data=addslashes($this->unescapeICSText($data));
  14. // + parese/end_vevent.php
  15. // Ajouter toutes les global
  16. // COmmenter $master_array['calendar_name'] = $calendar_name;
  17. // remplacer les unset par des =null (unset foirreux sur global)
  18. // Ajouter gestion alarm/trigger et ajouter trigger dans les champs a effacer
  19. // Modifier traitement attendee et ajouter csattendee dans les champs a effacer
  20. // AJouty last-modified + $modified dans champs a effacer
  21. // date_functions.php : ajouter ...([0-9]{0,2}) (l254) et $regs[6] (l267)à extractDateTime, return '' à match_tz
  22. // ajout checkEvent + ajout appel UID,LAST-MODIFIED + ajout->checked, ->gotonext
  23. if(!defined('BASE')) define('BASE', 'add-ons/ical/');
  24. //include_once(BASE.'functions/init.inc.php');
  25. require_once(BASE.'functions/date_functions.php');
  26. //include_once(BASE.'functions/draw_functions.php');
  27. //include_once(BASE.'functions/parse/overlapping_events.php');
  28. include_once(BASE.'functions/parse/recur_functions.php');
  29. global $week_start_day,$daysofweek_lang, $daysofweekshort_lang, $daysofweekreallyshort_lang, $monthsofyear_lang, $monthsofyear_lang, $monthsofyearshort_lang,$tz_array, $summary,$cpath, $timeFormat, $dateFormat_week,$tz_array, $phpiCal_config, $calendar_tz,$count, $mArray_begin, $mArray_end, $except_dates, $start_date, $start_date_unixtime,$end_range_unixtime,$until_unixtime, $day_offset, $current_view, $recur_data,$bymonth, $byweekno, $bymonthday, $year, $start_unixtime, $freq_type,$byweekno, $year, $freq_type, $wkst, $wkst3char,$byyearday, $year,$bymonthday, $year,$freq_type, $byday, $bymonth,$byweekno, $wkst3char, $year, $month, $start_unixtime, $summary, $bymonth, $byyearday,$byweekno,$byyearday,$bymonthday,$byday,$bysetpos;
  30. //include_once(BASE.'functions/timezones.php'); // A mettre après la declaration des globales
  31. $timeFormat = 'H:i';
  32. $timeFormat_small = 'g:i';
  33. // For date formatting, see note below
  34. $dateFormat_day = '%A %e %B';
  35. $dateFormat_week = '%e %B';
  36. $dateFormat_week_list = '%a %e %b';
  37. $dateFormat_week_jump = '%e %b';
  38. $dateFormat_month = '%B %Y';
  39. $dateFormat_month_list = '%A %e %B';
  40. $dateFormat_year = '%Y';
  41. $mArray_begin = mktime (0,0,0,1,1,1970);
  42. $mArray_end = mktime (0,0,0,12,31,2037);
  43. $uids=array();
  44. // reading the file if it's allowed
  45. $filecomplete=false;
  46. $parse_file = true;
  47. /*
  48. if ($phpiCal_config->save_parsed_cals == 'yes') {
  49. if (sizeof ($cal_filelist) > 1) {
  50. $parsedcal = $phpiCal_config->tmp_dir.'/parsedcal-'.urlencode($cpath.'::'.$cal_filename).'-'.$this_year;
  51. if (file_exists($parsedcal)) {
  52. $fd = fopen($parsedcal, 'r');
  53. $contents = fread($fd, filesize($parsedcal));
  54. fclose($fd);
  55. $master_array = unserialize($contents);
  56. $z=1;
  57. $y=0;
  58. $webcal_mtime = time() - ($phpiCal_config->webcal_hours * 3600);
  59. if (sizeof($master_array['-4']) == (sizeof($cal_filelist))) {
  60. foreach ($master_array['-4'] as $temp_array) {
  61. $mtime = $master_array['-4'][$z]['mtime'];
  62. $fname = $master_array['-4'][$z]['filename'];
  63. $wcalc = $master_array['-4'][$z]['webcal'];
  64. if ($wcalc == 'no') $realcal_mtime = filemtime($fname);
  65. if (isset($realcal_mtime) && ($mtime == $realcal_mtime) && ($wcalc == 'no')) {
  66. $y++;
  67. } elseif (($wcalc == 'yes') && ($mtime > $webcal_mtime)) {
  68. //echo date('H:i',$mtime). ' > '. date('H:i',$webcal_mtime);
  69. $y++;
  70. }
  71. $z++;
  72. }
  73. foreach ($master_array['-3'] as $temp_array) {
  74. if (isset($temp_array) && $temp_array !='') $caldisplaynames[] = $temp_array;
  75. }
  76. if ($y == sizeof($cal_filelist)) {
  77. if ($master_array['-1'] == 'valid cal file') {
  78. $parse_file = false;
  79. $calendar_name = $master_array['calendar_name'];
  80. $calendar_tz = $master_array['calendar_tz'];
  81. }
  82. }
  83. }
  84. }
  85. if ($parse_file == true) unset($master_array);
  86. } else {
  87. foreach ($cal_filelist as $filename) {
  88. $realcal_mtime = filemtime($filename);
  89. $parsedcal = $phpiCal_config->tmp_dir.'/parsedcal-'.urlencode($cpath.'::'.$cal_filename).'-'.$this_year;
  90. if (file_exists($parsedcal)) {
  91. $parsedcal_mtime = filemtime($parsedcal);
  92. if ($realcal_mtime == $parsedcal_mtime) {
  93. $fd = fopen($parsedcal, 'r');
  94. $contents = fread($fd, filesize($parsedcal));
  95. fclose($fd);
  96. $master_array = unserialize($contents);
  97. if ($master_array['-1'] == 'valid cal file') {
  98. $parse_file = false;
  99. $calendar_name = $master_array['calendar_name'];
  100. $calendar_tz = $master_array['calendar_tz'];
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. */
  108. if ($parse_file) {
  109. $overlap_array = array ();
  110. $uid_counter = 0;
  111. }
  112. $cal_filelist=array($filename);
  113. $calnumber = 1;
  114. foreach ($cal_filelist as $cal_key=>$filename) {
  115. // Find the real name of the calendar.
  116. //$actual_calname = getCalendarName($filename);
  117. if ($parse_file) {
  118. // Let's see if we're doing a webcal
  119. $is_webcal = FALSE;
  120. if (substr($filename, 0, 7) == 'http://' || substr($filename, 0, 8) == 'https://' || substr($filename, 0, 9) == 'webcal://') {
  121. $is_webcal = TRUE;
  122. $cal_webcalPrefix = str_replace('http://','webcal://',$filename);
  123. $cal_httpPrefix = str_replace('webcal://','http://',$filename);
  124. $cal_httpsPrefix = str_replace('webcal://','https://',$filename);
  125. $cal_httpsPrefix = str_replace('http://','https://',$cal_httpsPrefix);
  126. $filename = $cal_httpPrefix;
  127. $master_array['-4'][$calnumber]['webcal'] = 'yes';
  128. $actual_mtime = time();
  129. } else {
  130. $actual_mtime = @filemtime($filename);
  131. }
  132. //include(BASE.'functions/parse/parse_tzs.php');
  133. $ifile = @fopen($filename, "r");
  134. if ($ifile == FALSE) exit(error($lang['l_error_cantopen'], $filename));
  135. $nextline = fgets($ifile, 1024);
  136. if (trim($nextline) != 'BEGIN:VCALENDAR') exit(error($lang['l_error_invalidcal'], $filename));
  137. // Set a value so we can check to make sure $master_array contains valid data
  138. $master_array['-1'] = 'valid cal file';
  139. // Set default calendar name - can be overridden by X-WR-CALNAME
  140. $calendar_name = $cal_filename;
  141. //$master_array['calendar_name'] = $calendar_name;
  142. // read file in line by line
  143. // XXX end line is skipped because of the 1-line readahead
  144. $this->tmp->gotonext=false;
  145. while (!feof($ifile)) {
  146. $line = $nextline;
  147. $nextline = fgets($ifile, 1024);
  148. $nextline = ereg_replace("[\r\n]", "", $nextline);
  149. // handle continuation lines that start with either a space or a tab (MS Outlook)
  150. while (isset($nextline{0}) && ($nextline{0} == " " || $nextline{0} == "\t")) {
  151. $line = $line . substr($nextline, 1);
  152. $nextline = fgets($ifile, 1024);
  153. $nextline = ereg_replace("[\r\n]", "", $nextline);
  154. }
  155. $line = str_replace('\n',"\n",$line);
  156. $line = trim(stripslashes($line));
  157. if($this->tmp->gotonext && $line!='BEGIN:VEVENT' && $line!='END:VCALENDAR') continue;
  158. switch ($line) {
  159. case 'END:VCALENDAR':
  160. $filecomplete=true;
  161. break;
  162. case 'BEGIN:VFREEBUSY':
  163. case 'BEGIN:VEVENT':
  164. // each of these vars were being set to an empty string
  165. $start_time=$end_time=$start_date=$end_date=
  166. $allday_start=$allday_end=$start=$end=$the_duration=
  167. $beginning=$start_of_vevent=
  168. $valarm_description=$start_unixtime=$end_unixtime=$display_end_tmp=$end_time_tmp1=
  169. $recurrence_id=$uid=$rrule=$until_check=
  170. $until=$byweek=$byweekno=
  171. $byminute=$byhour=$bysecond=$csattendee=$trigger=$modified=$this->tmp->gotonext=$this->tmp->tzrchecked=$this->tmp->tzrevent=null;
  172. $interval = 1;
  173. $sequence = 0;
  174. $summary = '';
  175. $description = '';
  176. $status = '';
  177. $class = '';
  178. $location = '';
  179. $url = '';
  180. $geo = '';
  181. $type = '';
  182. $other = '';
  183. $wkst = 'MO';
  184. $vtodo_categories = '';
  185. $except_dates = array();
  186. $except_times = array();
  187. $rrule_array = array();
  188. $byday = array();
  189. $bymonth = array();
  190. $bymonthday = array();
  191. $byyearday = array();
  192. $bysetpos = array();
  193. $first_duration = TRUE;
  194. $count = 52;
  195. $valarm_set = FALSE;
  196. $attendee = array();
  197. $organizer = array();
  198. break;
  199. case 'END:VFREEBUSY':
  200. case 'END:VEVENT':
  201. include BASE."functions/parse/end_vevent.php";
  202. break;
  203. case 'END:VTODO':
  204. if (($vtodo_priority == '') && ($status == 'COMPLETED')) {
  205. $vtodo_sort = 11;
  206. } elseif ($vtodo_priority == '') {
  207. $vtodo_sort = 10;
  208. } else {
  209. $vtodo_sort = $vtodo_priority;
  210. }
  211. // CLASS support
  212. if (isset($class)) {
  213. if ($class == 'PRIVATE') {
  214. $summary = '**PRIVATE**';
  215. $description = '**PRIVATE**';
  216. } elseif ($class == 'CONFIDENTIAL') {
  217. $summary = '**CONFIDENTIAL**';
  218. $description = '**CONFIDENTIAL**';
  219. }
  220. }
  221. $master_array['-2']["$vtodo_sort"]["$uid"] = array (
  222. 'start_date' => $start_date,
  223. 'start_time' => $start_time,
  224. 'vtodo_text' => $summary,
  225. 'due_date'=> $due_date,
  226. 'due_time'=> $due_time,
  227. 'completed_date' => $completed_date,
  228. 'completed_time' => $completed_time,
  229. 'priority' => $vtodo_priority,
  230. 'status' => $status,
  231. 'class' => $class,
  232. 'categories' => $vtodo_categories,
  233. 'description' => $description,
  234. 'calname' => $actual_calname,
  235. 'geo' => $geo,
  236. 'url' => $url
  237. );
  238. $start_date= $start_time= $due_date= $due_time= $completed_date= $completed_time= $vtodo_priority= $status= $class= $vtodo_categories= $summary= $description=null;
  239. $vtodo_set = FALSE;
  240. break;
  241. case 'BEGIN:VTODO':
  242. $vtodo_set = TRUE;
  243. $summary = '';
  244. $due_date = '';
  245. $due_time = '';
  246. $completed_date = '';
  247. $completed_time = '';
  248. $vtodo_priority = '';
  249. $vtodo_categories = '';
  250. $status = '';
  251. $class = '';
  252. $description = '';
  253. break;
  254. case 'BEGIN:VALARM':
  255. $valarm_set = TRUE;
  256. break;
  257. case 'END:VALARM':
  258. $valarm_set = FALSE;
  259. break;
  260. default:
  261. unset ($field, $data, $prop_pos, $property);
  262. if (ereg ("([^:]+):(.*)", $line, $line)){
  263. $field = $line[1];
  264. $data = $line[2];
  265. $property = strtoupper($field);
  266. $prop_pos = strpos($property,';');
  267. if ($prop_pos !== false) $property = substr($property,0,$prop_pos);
  268. switch ($property) {
  269. // Start VTODO Parsing
  270. //
  271. case 'DUE':
  272. $datetime = extractDateTime($data, $property, $field);
  273. $due_date = $datetime[1];
  274. $due_time = $datetime[2];
  275. break;
  276. case 'COMPLETED':
  277. $datetime = extractDateTime($data, $property, $field);
  278. $completed_date = $datetime[1];
  279. $completed_time = $datetime[2];
  280. break;
  281. case 'PRIORITY':
  282. $vtodo_priority = "$data";
  283. break;
  284. case 'STATUS':
  285. $status = "$data";
  286. break;
  287. case 'GEO':
  288. $geo = "$data";
  289. break;
  290. case 'CLASS':
  291. $class = "$data";
  292. break;
  293. case 'CATEGORIES':
  294. $vtodo_categories = $this->unescapeICSText($data);
  295. break;
  296. //
  297. // End VTODO Parsing
  298. case 'DTSTART':
  299. $datetime = extractDateTime($data, $property, $field);
  300. $start_unixtime = $datetime[0];
  301. $start_date = $datetime[1];
  302. $start_time = $datetime[2];
  303. $allday_start = $datetime[3];
  304. $start_tz = $datetime[4];
  305. preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})/', $data, $regs);
  306. $vevent_start_date = $regs[1] . $regs[2] . $regs[3];
  307. $day_offset = dayCompare($start_date, $vevent_start_date);
  308. break;
  309. case 'DTEND':
  310. $datetime = extractDateTime($data, $property, $field);
  311. $end_unixtime = $datetime[0];
  312. $end_date = $datetime[1];
  313. $end_time = $datetime[2];
  314. $allday_end = $datetime[3];
  315. break;
  316. case 'EXDATE':
  317. $data = split(",", $data);
  318. foreach ($data as $exdata) {
  319. $exdata = str_replace('T', '', $exdata);
  320. $exdata = str_replace('Z', '', $exdata);
  321. preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})/', $exdata, $regs);
  322. $except_dates[] = $regs[1] . $regs[2] . $regs[3];
  323. // Added for Evolution, since they dont think they need to tell me which time to exclude.
  324. if ($regs[4] == '' && isset($start_time) && $start_time != '') {
  325. $except_times[] = $start_time;
  326. } else {
  327. $except_times[] = $regs[4] . $regs[5];
  328. }
  329. }
  330. break;
  331. case 'SUMMARY':
  332. $data=addslashes($this->unescapeICSText($data));
  333. if ($valarm_set == FALSE) {
  334. $summary = $data;
  335. } else {
  336. $valarm_summary = $data;
  337. }
  338. break;
  339. case 'DESCRIPTION':
  340. $data=addslashes($this->unescapeICSText($data));
  341. if ($valarm_set == FALSE) {
  342. $description = $data;
  343. } else {
  344. $valarm_description = $data;
  345. }
  346. break;
  347. case 'RECURRENCE-ID':
  348. $parts = explode(';', $field);
  349. foreach($parts as $part) {
  350. $eachval = split('=',$part);
  351. if ($eachval[0] == 'RECURRENCE-ID') {
  352. // do nothing
  353. } elseif ($eachval[0] == 'TZID') {
  354. $recurrence_id['tzid'] = $eachval[1];
  355. } elseif ($eachval[0] == 'RANGE') {
  356. $recurrence_id['range'] = $eachval[1];
  357. } elseif ($eachval[0] == 'VALUE') {
  358. $recurrence_id['value'] = $eachval[1];
  359. } else {
  360. $recurrence_id[] = $eachval[1];
  361. }
  362. }
  363. unset($parts, $part, $eachval);
  364. $data = str_replace('T', '', $data);
  365. $data = str_replace('Z', '', $data);
  366. ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})', $data, $regs);
  367. $recurrence_id['date'] = $regs[1] . $regs[2] . $regs[3];
  368. $recurrence_id['time'] = $regs[4] . $regs[5];
  369. $recur_unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]);
  370. if (isset($recurrence_id['tzid'])) {
  371. $offset_tmp = chooseOffset($recur_unixtime, $recurrence_id['tzid']);
  372. } elseif (isset($calendar_tz)) {
  373. $offset_tmp = chooseOffset($recur_unixtime, $calendar_tz);
  374. } else {
  375. $offset_tmp = chooseOffset($recur_unixtime);
  376. }
  377. $recur_unixtime = calcTime($offset_tmp, @$server_offset_tmp, $recur_unixtime);
  378. $recurrence_id['date'] = date('Ymd', $recur_unixtime);
  379. $recurrence_id['time'] = date('Hi', $recur_unixtime);
  380. $recurrence_d = date('Ymd', $recur_unixtime);
  381. $recurrence_t = date('Hi', $recur_unixtime);
  382. unset($server_offset_tmp);
  383. break;
  384. case 'SEQUENCE':
  385. $sequence = $data;
  386. break;
  387. case 'UID':
  388. $uid = $data;
  389. $uids[]=$uid;
  390. checkEvent($this,$uid,$modified);
  391. break;
  392. case 'X-WR-CALNAME':
  393. $actual_calname = $data;
  394. $master_array['calendar_name'] = $actual_calname;
  395. $cal_displaynames[$cal_key] = $actual_calname;
  396. break;
  397. case 'X-WR-TIMEZONE':
  398. $calendar_tz = $data;
  399. $master_array['calendar_tz'] = $calendar_tz;
  400. break;
  401. case 'DURATION':
  402. if (($first_duration == TRUE) && (!stristr($field, '=DURATION'))) {
  403. ereg ('^P([0-9]{1,2}[W])?([0-9]{1,3}[D])?([T]{0,1})?([0-9]{1,2}[H])?([0-9]{1,2}[M])?([0-9]{1,2}[S])?', $data, $duration);
  404. $weeks = str_replace('W', '', $duration[1]);
  405. $days = str_replace('D', '', $duration[2]);
  406. $hours = str_replace('H', '', $duration[4]);
  407. $minutes = str_replace('M', '', $duration[5]);
  408. $seconds = str_replace('S', '', $duration[6]);
  409. $the_duration = ($weeks * 60 * 60 * 24 * 7) + ($days * 60 * 60 * 24) + ($hours * 60 * 60) + ($minutes * 60) + ($seconds);
  410. $first_duration = FALSE;
  411. }
  412. break;
  413. case 'RRULE':
  414. $data = str_replace ('RRULE:', '', $data);
  415. $rrule = split (';', $data);
  416. foreach ($rrule as $recur) {
  417. ereg ('(.*)=(.*)', $recur, $regs);
  418. $rrule_array[$regs[1]] = $regs[2];
  419. }
  420. break;
  421. case 'ATTENDEE':
  422. $aname=ereg_replace (".*;CN=([^;]*).*", "\\1", $field);
  423. preg_match('#\[CS\] (.+) \((.+)\)#',$aname,$cn);
  424. if(count($cn)==3){
  425. $csattendee[]=array('name'=>trim($cn[2]),'own'=>trim($cn[1]));
  426. }else{
  427. $attendee[] = array ('name' => $aname,
  428. 'email' => ereg_replace (".*mailto:(.*).*", "\\1", $data),
  429. 'RSVP' => ereg_replace (".*RSVP=([^;]*).*", "\\1", $field),
  430. 'PARSTAT' => ereg_replace (".*PARTSTAT=([^;]*).*", "\\1", $field),
  431. 'ROLE' => ereg_replace (".*ROLE=([^;]*).*", "\\1", $field));
  432. }
  433. break;
  434. case 'ORGANIZER':
  435. $field = str_replace("ORGANIZER;CN=", "", $field);
  436. $data = str_replace ("mailto:", "", $data);
  437. $organizer[] = array ('name' => stripslashes($field), 'email' => stripslashes($data));
  438. break;
  439. case 'LOCATION':
  440. $data=addslashes($this->unescapeICSText($data));
  441. $location = $data;
  442. break;
  443. case 'URL':
  444. $url = $data;
  445. break;
  446. case 'TRIGGER':
  447. $data=str_ireplace('-', '', $data);
  448. ereg ('^P([0-9]{1,2}[W])?([0-9]{1,2}[D])?([T]{0,1})?([0-9]{1,2}[H])?([0-9]{1,2}[M])?', $data, $duration);
  449. $alw = str_ireplace('W', '', $duration[1]);
  450. $ald = str_ireplace('D', '', $duration[2]);
  451. $alh = str_ireplace('H', '', $duration[4]);
  452. $alm = str_ireplace('M', '', $duration[5]);
  453. $trigger = ($alw * 60 * 24 * 7) + ($ald * 60 * 24) + ($alh * 60) + ($alm);
  454. break;
  455. case 'LAST-MODIFIED':
  456. $tmp = extractDateTime($data, $property, $field);
  457. $modified = date('Y-m-d H:i:s',strtotime('GMT',$tmp[0]));
  458. checkEvent($this,$uid,$modified);
  459. break;
  460. default:
  461. if(strpos(':',$data) > 1) $other .= $data;
  462. }
  463. }
  464. }
  465. }
  466. }
  467. if (!isset($master_array['-3'][$calnumber])) $master_array['-3'][$calnumber] = $actual_calname;
  468. if (!isset($master_array['-4'][$calnumber]['mtime'])) $master_array['-4'][$calnumber]['mtime'] = $actual_mtime;
  469. if (!isset($master_array['-4'][$calnumber]['filename'])) $master_array['-4'][$calnumber]['filename'] = $filename;
  470. if (!isset($master_array['-4'][$calnumber]['webcal'])) $master_array['-4'][$calnumber]['webcal'] = 'no';
  471. $calnumber = $calnumber + 1;
  472. }
  473. if($filecomplete){
  474. if ($parse_file) {
  475. // Sort the array by absolute date.
  476. if (isset($master_array) && is_array($master_array)) {
  477. ksort($master_array);
  478. reset($master_array);
  479. // sort the sub (day) arrays so the times are in order
  480. foreach (array_keys($master_array) as $k) {
  481. if (isset($master_array[$k]) && is_array($master_array[$k])) {
  482. ksort($master_array[$k]);
  483. reset($master_array[$k]);
  484. }
  485. }
  486. }
  487. /*
  488. // write the new master array to the file
  489. if (isset($master_array) && is_array($master_array) && $phpiCal_config->save_parsed_cals == 'yes') {
  490. $write_me = serialize($master_array);
  491. $fd = @fopen($parsedcal, 'w');
  492. if ($fd == FALSE) exit(error($lang['l_error_cache'], $filename));
  493. @fwrite($fd, $write_me);
  494. @fclose($fd);
  495. @touch($parsedcal, $realcal_mtime);
  496. }
  497. */
  498. }
  499. /*
  500. // Set a calender name for all calenders combined
  501. if ($cal == $phpiCal_config->ALL_CALENDARS_COMBINED) {
  502. $calendar_name = $all_cal_comb_lang;
  503. }
  504. example of how to customize the display name sort order
  505. if(in_array('US Holidays',$cal_displaynames)){
  506. unset($cal_displaynames[array_search('US Holidays',$cal_displaynames)]);
  507. array_unshift($cal_displaynames, 'US Holidays');
  508. }
  509. $cal_displayname = urldecode(implode(', ', $cal_displaynames)); #reset this with the correct names
  510. $template_started = getmicrotime();
  511. */
  512. $xsetcat=&XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tcatevt);
  513. $xsetlink=&XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tlinks);
  514. $tzruids=array();
  515. foreach($this->categories as $oid=>$cat) $tzrcategories[$cat['name']]=$oid;
  516. foreach($master_array as $day=>&$dayevs){
  517. if($day<1) continue;
  518. foreach($dayevs as $hour=>&$hourevs){
  519. foreach($hourevs as $uid=>&$ev){
  520. $ar=array();
  521. if(!empty($ev['tzrgotonext'])) continue;
  522. // Vérification de la timezone
  523. if(empty($ev['timezone'])){
  524. $ev['timezone']='GMT';
  525. }elseif(strtotime($ev['timezone'])===false){
  526. $ev['timezone']=$this->diary['tz'];
  527. }
  528. // Heures
  529. if($hour=='-1'){
  530. $ar['begin']=date('Y-m-d 00:00:00',$ev['start_unixtime']);
  531. $ar['end']=date('Y-m-d 23:59:00',$ev['end_unixtime']-1);
  532. $ar['allday']=1;
  533. }else{
  534. $mystart=strtotime($ev['timezone'],$ev['start_unixtime']);
  535. $ar['begin']=gmdate('Y-m-d H:i:s',$mystart);
  536. $ar['end']=gmdate('Y-m-d H:i:s',strtotime($ev['timezone'],$ev['end_unixtime']));
  537. $ar['allday']=0;
  538. }
  539. // Titres, descr, lieu
  540. $ar['text']=$ev['event_text'];
  541. $ar['descr']=$ev['description'];
  542. $ar['place']=$ev['location'];
  543. // Categorie
  544. if(!isset($tzrcategories[$ev['categories']])) {
  545. $ret=$xsetcat->procInput(array('name'=>$ev['categories'],'time'=>60,'visib'=>'PR','recall'=>0,'commun'=>2,'allday'=>0,
  546. 'tplentry'=>TZR_RETURN_DATA));
  547. $tzrcategories[$ev['categories']]=$ret['oid'];
  548. }
  549. $ar['cat']=$tzrcategories[$ev['categories']];
  550. // Visibilité
  551. if($ev['class']=="PRIVATE") $ar['visib']="PR";
  552. elseif($ev['class']=="PUBLIC") $ar['visib']="PU";
  553. elseif($ev['class']=="CONFIDENTIAL") $ar['visib']="OC";
  554. elseif(!empty($this->diary['defvisi'])) $ar['visib']=$this->diary['defvisi'];
  555. else $ev['visib']='PR';
  556. // UIDI
  557. $ar['UIDI']=$uid;
  558. // KOID Source
  559. if(empty($tzruids[$uid])) $ar['KOIDS']=null;
  560. else $ar['KOIDS']=$tzruids[$uid];
  561. $ar['KOIDD']=$this->diary['KOID'];
  562. // Repetition : dans le cas d'une regle non gérée par la console, on enregistre la regle directement
  563. $tmp=implode(';',$ev['rrule']);
  564. if(!preg_match('/^(RRULE|FREQ|DAILY|WEEKLY|MONTHLY|YEARLY|UNTIL|EXDATE|VALUE|COUNT|DATE|INTERVAL=1|[;:=0-9 TZ-])*$/i',$tmp)){
  565. $ar['rrule']=$tmp;
  566. $ar['repet']=$ar['end_rep'];
  567. }elseif(!empty($ev['recur']['FREQ'])){
  568. $ar['rrule']='';
  569. $ar['repet']=strtoupper($ev['recur']['FREQ']);
  570. if($ev['recur']['UNTIL']) $ar['end_rep']=$ev['recur']['UNTIL'];
  571. else{
  572. if(empty($ev['recur']['COUNT'])) $ev['recur']['COUNT']=52;
  573. $ar['end_rep']=date('Ymd',strtotime($day.' +'.$ev['recur']['COUNT'].' '.$ev['recur']['FREQ_TYPE']));
  574. }
  575. }
  576. $ar['except']=implode(";",$ev['exdate']); // A verifier
  577. // Rappel
  578. $ar['recall']=$ev['alarm'];
  579. $ar['isrecall']=0;
  580. // Invités
  581. $atts=array();
  582. foreach($ev['attendee'] as $att) $atts[]=$att['email'];
  583. $ar['attext']=implode("\r\n",$atts);
  584. $tlinks=array();
  585. foreach($ev['csattendee'] as $z=>$csatt){
  586. $rs=&selectQuery('select ag.KOID from '.$this->tagenda.' as ag left outer join USERS as u on u.KOID=ag.OWN '.
  587. 'where TRIM(REPLACE(ag.name,":","-"))="'.$csatt['name'].'" and '.
  588. 'TRIM(REPLACE(u.fullnam,":","-"))="'.$csatt['own'].'"');
  589. if($rs->rowCount()>0){
  590. $ors=$rs->fetch();
  591. $tlinks[]=$ors['KOID'];
  592. }
  593. }
  594. // Date de modif
  595. if(!empty($ev['modified'])) $ar['UPD']=$ev['modified'];
  596. // Efacement ancien
  597. if(!empty($ev['tzrevent']) && empty($ar['KOIDS'])){
  598. $this->delEvt(array('koid'=>$ev['tzrevent']['KOID'],'noalert'=>true));
  599. $ar['newoid']=$ev['tzrevent']['KOID'];
  600. }
  601. // Insertion
  602. $ret=$this->xsetevt->procInput($ar);
  603. $xsetlink->procInput(array('KOIDE'=>$ret['oid'],'KOIDD'=>$this->diary['KOID'],'UPD'=>$modified));
  604. foreach($tlinks as $doid) $xsetlink->procInput(array('KOIDE'=>$ret['oid'],'KOIDD'=>$doid,'UPD'=>$modified));
  605. if(empty($tzruids[$uid])) $tzruids[$uid]=$ret['oid'];
  606. }
  607. }
  608. }
  609. if($this->synchro){
  610. // Suppression des evenements qui ont été supprimé
  611. $rs=&selectQuery('SELECT e.* FROM '.$this->tlinks.' as l left outer join '.$this->tevt.' as e on e.KOID=l.KOIDE '.
  612. 'WHERE l.KOIDD="'.$this->diary['KOID'].'" and (e.KOIDS is null or e.KOIDS="")');
  613. //foreach($uids as $tt) $a.=$tt."\n";
  614. //$a.="=======\n";
  615. while($rs && ($l=$rs->fetch())){
  616. //$a.=$l['KOID']." - ".$l['UIDI']."\n";
  617. if(!empty($l['KOID']) && !in_array($l['KOID'],$uids) && !in_array($l['UIDI'],$uids) &&
  618. in_array($this->diary['KOID'],$this->getAuthorizedDiaries('rwv'))){
  619. //$a.='-del';
  620. $this->delEvt(array('koid'=>$l['KOID'],'noalert'=>true,'_options'=>array('local'=>true)));
  621. }
  622. }
  623. //file_put_contents('/var/www/restricted/ssh/private08/www/tt.txt',$a);
  624. }
  625. }
  626. function checkEvent(&$mod,$uid,$modified,$setmodified){
  627. if(!empty($uid) && (!empty($modified) || $setmodifieed)){
  628. $mod->tmp->tzrchecked=true;
  629. $rs=&selectQuery("SELECT e.* FROM {$mod->tevt} as e left outer join {$mod->tlinks} as l on e.KOID=l.KOIDE ".
  630. "where (e.UIDI='$uid' || e.KOID='$uid') AND l.KOIDD='{$mod->diary['KOID']}'");
  631. if($rs && $rs->rowCount()>0) {
  632. $mod->tmp->tzrevent=$tzrevent=$rs->fetch();
  633. if(!(($tzrevent['UPD'] < $modified || $setmodified && empty($modified)) && $mod->diary['KOID']==$tzrevent['KOIDD'] && ($tzrevent['visib']=='PU' || in_array($mod->diary['KOID'],$mod->getAuthorizedDiaries('rwv'))))){
  634. $mod->tmp->gotonext=true;
  635. }
  636. }
  637. }
  638. }
  639. //var_dump($master_array);
  640. //die('ok1');
  641. //If you want to see the values in the arrays, uncomment below.
  642. #print '<pre>';
  643. #var_dump($phpiCal_config);
  644. #print_r($master_array);
  645. #var_dump($overlap_array['20081211']);
  646. //print_r($day_array);
  647. //print_r($rrule_array);
  648. //print_r($byday_arr);
  649. //print_r($recurrence_delete);
  650. //print_r($cal_displaynames);
  651. //print_r($cal_filelist);
  652. //print_r($tz_array);
  653. #print '</pre>';
  654. ?>