[4898] | 1 | <?php |
---|
| 2 | /*********************************************** |
---|
| 3 | * File : z_ical.php |
---|
| 4 | * Project : Z-Push |
---|
| 5 | * Descr : |
---|
| 6 | * |
---|
| 7 | * Created : 01.12.2008 |
---|
| 8 | * |
---|
| 9 | * Zarafa Deutschland GmbH, www.zarafaserver.de |
---|
| 10 | * This file is distributed under GPL v2. |
---|
| 11 | * Consult LICENSE file for details |
---|
| 12 | ************************************************/ |
---|
| 13 | |
---|
| 14 | class ZPush_ical{ |
---|
| 15 | function ZPush_ical($store){ |
---|
| 16 | $this->_store = $store; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | /* |
---|
| 20 | * Function reads calendar part and puts mapi properties into an array. |
---|
| 21 | */ |
---|
| 22 | function extractProps($ical, &$mapiprops) { |
---|
| 23 | //mapping between partstat in ical and MAPI Meeting Response classes as well as icons |
---|
| 24 | $aClassMap = array( |
---|
| 25 | "ACCEPTED" => array("class" => "IPM.Schedule.Meeting.Resp.Pos", "icon" => 0x405), |
---|
| 26 | "DECLINED" => array("class" => "IPM.Schedule.Meeting.Resp.Neg", "icon" => 0x406), |
---|
| 27 | "TENTATIVE" => array("class" => "IPM.Schedule.Meeting.Resp.Tent", "icon" => 0x407), |
---|
| 28 | "NEEDS-ACTION" => array("class" => "IPM.Schedule.Meeting.Request", "icon" => 0x404), //iphone |
---|
| 29 | "REQ-PARTICIPANT" => array("class" => "IPM.Schedule.Meeting.Request", "icon" => 0x404), //nokia |
---|
| 30 | ); |
---|
| 31 | |
---|
| 32 | $aical = array_map("rtrim", preg_split("/[\n]/", $ical)); |
---|
| 33 | $elemcount = count($aical); |
---|
| 34 | $i=0; |
---|
| 35 | $nextline = $aical[0]; |
---|
| 36 | //last element is empty |
---|
| 37 | while ($i < $elemcount - 1) { |
---|
| 38 | $line = $nextline; |
---|
| 39 | //if a line starts with a space or a tab it belongs to the previous line |
---|
| 40 | $nextline = $aical[$i+1]; |
---|
| 41 | if (strlen($nextline) == 0) { |
---|
| 42 | $i++; |
---|
| 43 | continue; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | while ($nextline{0} == " " || $nextline{0} == "\t") { |
---|
| 47 | $line .= substr($nextline, 1); |
---|
| 48 | $nextline = $aical[++$i + 1]; |
---|
| 49 | } |
---|
| 50 | switch (strtoupper($line)) { |
---|
| 51 | case "BEGIN:VCALENDAR": |
---|
| 52 | case "BEGIN:VEVENT": |
---|
| 53 | case "END:VEVENT": |
---|
| 54 | case "END:VCALENDAR": |
---|
| 55 | break; |
---|
| 56 | default: |
---|
| 57 | unset ($field, $data, $prop_pos, $property); |
---|
| 58 | if (ereg ("([^:]+):(.*)", $line, $line)){ |
---|
| 59 | $field = $line[1]; |
---|
| 60 | $data = $line[2]; |
---|
| 61 | $property = $field; |
---|
| 62 | $prop_pos = strpos($property,';'); |
---|
| 63 | if ($prop_pos !== false) $property = substr($property, 0, $prop_pos); |
---|
| 64 | $property = strtoupper($property); |
---|
| 65 | |
---|
| 66 | switch ($property) { |
---|
| 67 | case 'DTSTART': |
---|
| 68 | $data = $this->getTimestampFromStreamerDate($data); |
---|
| 69 | $namedStartTime = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x820d"); |
---|
| 70 | $mapiprops[$namedStartTime] = $data; |
---|
| 71 | $namedCommonStart = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062008-0000-0000-C000-000000000046}:0x8516"); |
---|
| 72 | $mapiprops[$namedCommonStart] = $data; |
---|
| 73 | $clipStart = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8235"); |
---|
| 74 | $mapiprops[$clipStart] = $data; |
---|
| 75 | $mapiprops[PR_START_DATE] = $data; |
---|
| 76 | break; |
---|
| 77 | |
---|
| 78 | case 'DTEND': |
---|
| 79 | $data = $this->getTimestampFromStreamerDate($data); |
---|
| 80 | $namedEndTime = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x820e"); |
---|
| 81 | $mapiprops[$namedEndTime] = $data; |
---|
| 82 | $namedCommonEnd = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062008-0000-0000-C000-000000000046}:0x8517"); |
---|
| 83 | $mapiprops[$namedCommonEnd] = $data; |
---|
| 84 | $clipEnd = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8236"); |
---|
| 85 | $mapiprops[$clipEnd] = $data; |
---|
| 86 | $mapiprops[PR_END_DATE] = $data; |
---|
| 87 | break; |
---|
| 88 | |
---|
| 89 | case 'UID': |
---|
| 90 | $goid = GetPropIDFromString($this->_store, "PT_BINARY:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x3"); |
---|
| 91 | $goid2 = GetPropIDFromString($this->_store, "PT_BINARY:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x23"); |
---|
| 92 | $mapiprops[$goid] = $mapiprops[$goid2] = hex2bin($data); |
---|
| 93 | break; |
---|
| 94 | |
---|
| 95 | case 'ATTENDEE': |
---|
| 96 | $fields = explode(";", $field); |
---|
| 97 | foreach ($fields as $field) { |
---|
| 98 | $prop_pos = strpos($field, '='); |
---|
| 99 | if ($prop_pos !== false) { |
---|
| 100 | switch (substr($field, 0, $prop_pos)) { |
---|
| 101 | case 'PARTSTAT' : $partstat = substr($field, $prop_pos+1); break; |
---|
| 102 | case 'CN' : $cn = substr($field, $prop_pos+1); break; |
---|
| 103 | case 'ROLE' : $role = substr($field, $prop_pos+1); break; |
---|
| 104 | case 'RSVP' : $rsvp = substr($field, $prop_pos+1); break; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | if (isset($partstat) && isset($aClassMap[$partstat]) && |
---|
| 109 | |
---|
| 110 | (!isset($mapiprops[PR_MESSAGE_CLASS]) || $mapiprops[PR_MESSAGE_CLASS] == "IPM.Schedule.Meeting.Request")) { |
---|
| 111 | $mapiprops[PR_MESSAGE_CLASS] = $aClassMap[$partstat]['class']; |
---|
| 112 | $mapiprops[PR_ICON_INDEX] = $aClassMap[$partstat]['icon']; |
---|
| 113 | } |
---|
| 114 | // START ADDED dw2412 to support meeting requests on HTC Android Mail App |
---|
| 115 | elseif (isset($role) && isset($aClassMap[$role]) && |
---|
| 116 | (!isset($mapiprops[PR_MESSAGE_CLASS]) || $mapiprops[PR_MESSAGE_CLASS] == "IPM.Schedule.Meeting.Request")) { |
---|
| 117 | $mapiprops[PR_MESSAGE_CLASS] = $aClassMap[$role]['class']; |
---|
| 118 | $mapiprops[PR_ICON_INDEX] = $aClassMap[$role]['icon']; |
---|
| 119 | } |
---|
| 120 | // END ADDED dw2412 to support meeting requests on HTC Android Mail App |
---|
| 121 | if (!isset($cn)) $cn = ""; |
---|
| 122 | $data = str_replace ("MAILTO:", "", $data); |
---|
| 123 | $attendee[] = array ('name' => stripslashes($cn), 'email' => stripslashes($data)); |
---|
| 124 | break; |
---|
| 125 | |
---|
| 126 | case 'ORGANIZER': |
---|
| 127 | $field = str_replace("ORGANIZER;CN=", "", $field); |
---|
| 128 | $data = str_replace ("MAILTO:", "", $data); |
---|
| 129 | $organizer[] = array ('name' => stripslashes($field), 'email' => stripslashes($data)); |
---|
| 130 | break; |
---|
| 131 | |
---|
| 132 | case 'LOCATION': |
---|
| 133 | $data = str_replace("\\n", "<br />", $data); |
---|
| 134 | $data = str_replace("\\t", " ", $data); |
---|
| 135 | $data = str_replace("\\r", "<br />", $data); |
---|
| 136 | $data = stripslashes($data); |
---|
| 137 | $namedLocation = GetPropIDFromString($this->_store, "PT_STRING8:{00062002-0000-0000-C000-000000000046}:0x8208"); |
---|
| 138 | $mapiprops[$namedLocation] = $data; |
---|
| 139 | $tneflocation = GetPropIDFromString($this->_store, "PT_STRING8:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x2"); |
---|
| 140 | $mapiprops[$tneflocation] = $data; |
---|
| 141 | break; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | break; |
---|
| 145 | } |
---|
| 146 | $i++; |
---|
| 147 | |
---|
| 148 | } |
---|
| 149 | $useTNEF = GetPropIDFromString($this->_store, "PT_BOOLEAN:{00062008-0000-0000-C000-000000000046}:0x8582"); |
---|
| 150 | $mapiprops[$useTNEF] = true; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /* |
---|
| 154 | * Converts an YYYYMMDDTHHMMSSZ kind of string into an unixtimestamp |
---|
| 155 | * |
---|
| 156 | * @param string $data |
---|
| 157 | * @return long |
---|
| 158 | */ |
---|
| 159 | function getTimestampFromStreamerDate ($data) { |
---|
| 160 | $data = str_replace('Z', '', $data); |
---|
| 161 | $data = str_replace('T', '', $data); |
---|
| 162 | |
---|
| 163 | preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})([0-9]{0,2})/', $data, $regs); |
---|
| 164 | if ($regs[1] < 1970) { |
---|
| 165 | $regs[1] = '1971'; |
---|
| 166 | } |
---|
| 167 | return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | ?> |
---|