function parseVFB($lines, &$line_no) { for (; $line_no < sizeof($lines); $line_no++) { $line = $lines[$line_no]; if ($i = strpos($line, ":")) { $field = substr($line, 0, $i); $value = substr($line, $i + 1); switch (strtolower($field)) { case 'begin': $line_no++; $vfb_loc[strtolower($value)] = parseVFB($lines, $line_no); break; case 'dtend': case 'dtstart': case 'dtstamp': $vfb_loc[strtolower($field)] = parseVFB_date($value); break; case 'freebusy': if ($i = strpos($value, "/")) { $val['starttime'] = parseVFB_date(substr($value, 0, $i)); $val['endtime'] = parseVFB_date(substr($value, $i + 1)); } $vfb_loc[strtolower($field)][] = $val; break; case 'end': return $vfb_loc; default: $vfb_loc[strtolower($field)] = $value; } } } return $vfb_loc; }
function readFBfromContact($emailaddress, $starttime, $endtime) { $email1address = GetPropIDFromString($this->_defaultstore, "PT_STRING8:{00062004-0000-0000-C000-000000000046}:0x8083"); $email2address = GetPropIDFromString($this->_defaultstore, "PT_STRING8:{00062004-0000-0000-C000-000000000046}:0x8093"); $email3address = GetPropIDFromString($this->_defaultstore, "PT_STRING8:{00062004-0000-0000-C000-000000000046}:0x80A3"); $internetfb = GetPropIDFromString($this->_defaultstore, "PT_STRING8:{00062004-0000-0000-C000-000000000046}:0x80D8"); $rows = $this->readResolveRecipientsfromContacts($emailaddress); foreach ($rows as $entry) { $res['displayname'] = w2u($entry[PR_DISPLAY_NAME]); $res['type'] = 2; if (isset($entry[$email1address]) && $entry[$email1address] == $emailaddress) { $res['emailaddress'] = $entry[$email1address]; } else { if (isset($entry[$email2address]) && $entry[$email2address] == $emailaddress) { $res['emailaddress'] = $entry[$email2address]; } else { if (isset($entry[$email3address]) && $entry[$email3address] == $emailaddress) { $res['emailaddress'] = $entry[$email3address]; } } } $entries = array(); if (isset($entry[$internetfb])) { if ($fb_file = file_get_contents($entry[$internetfb])) { $lines = preg_split('/\\n/', str_replace("\r", "", $fb_file)); $line_no = 0; $vfb = parseVFB($lines, $line_no); if (isset($vfb['vcalendar']['vfreebusy']['freebusy'])) { foreach ($vfb['vcalendar']['vfreebusy']['freebusy'] as $value) { if ($value['starttime'] > $starttime || $value['endtime'] < $endtime) { $entries[] = array('start' => $value['starttime'] < $starttime ? $starttime : $value['starttime'], 'end' => $value['endtime'] > $endtime ? $endtime : $value['endtime'], 'status' => '2'); } } } } } $res['entries'] = $entries; $result[$emailaddress][] = $res; } return $result; }