"Fossies" - the Fresh Open Source Software Archive

Member "z-push/include/z_ical.php" (2 Aug 2013, 10372 Bytes) of package /linux/www/old/group-e_z-push_v3.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "z_ical.php" see the Fossies "Dox" file reference documentation.

    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             // start dw2412: Work with the DESCRIPTION Field to get all parts together...
   47             if (ereg ("([^:]+):(.*)", $line, $matches) &&
   48                 $matches[1] == "DESCRIPTION") {
   49                 while (!ereg ("([^:]+):(.*)", $nextline, $matches) ||
   50                     strtoupper(substr($matches[1],1)) != substr($matches[1],1)) {
   51                     $line .= "\n".$nextline;
   52                     $nextline = $aical[++$i + 1];
   53                 }
   54             }
   55             // end dw2412: Work with the DESCRIPTION Field to get all parts together...
   56 
   57             while ($nextline{0} == " " || $nextline{0} == "\t") {
   58                 $line .= substr($nextline, 1);
   59                 $nextline = $aical[++$i + 1];
   60             }
   61             switch (strtoupper($line)) {
   62                 case "BEGIN:VCALENDAR":
   63                 case "BEGIN:VEVENT":
   64                 case "END:VEVENT":
   65                 case "END:VCALENDAR":
   66                     break;
   67                 default:
   68                     unset ($field, $data, $prop_pos, $property);
   69                     if (ereg ("([^:]+):(.*)", $line, $line)){
   70                         $field = $line[1];
   71                         $data = $line[2];
   72                         $property = $field;
   73                         $prop_pos = strpos($property,';');
   74                         if ($prop_pos !== false) $property = substr($property, 0, $prop_pos);
   75                         $property = strtoupper($property);
   76 
   77                         switch ($property) {
   78                             case 'DTSTART':
   79                                 $data = $this->getTimestampFromStreamerDate($data);
   80                                 $namedStartTime = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x820d");
   81                                 $mapiprops[$namedStartTime] = $data;
   82                                 $namedCommonStart = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062008-0000-0000-C000-000000000046}:0x8516");
   83                                 $mapiprops[$namedCommonStart] = $data;               
   84                                 $clipStart = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8235");
   85                                 $mapiprops[$clipStart] = $data;
   86                                 $mapiprops[PR_START_DATE] = $data;
   87                                 break;
   88 
   89                             case 'DTEND':
   90                                 $data = $this->getTimestampFromStreamerDate($data);
   91                                 $namedEndTime = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x820e");
   92                                 $mapiprops[$namedEndTime] = $data;
   93                                 $namedCommonEnd = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062008-0000-0000-C000-000000000046}:0x8517");
   94                                 $mapiprops[$namedCommonEnd] = $data;
   95                                 $clipEnd = GetPropIDFromString($this->_store, "PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8236");
   96                                 $mapiprops[$clipEnd] = $data;
   97                                 $mapiprops[PR_END_DATE] = $data;
   98                                 break;
   99 
  100                             case 'UID':
  101                                 $goid = GetPropIDFromString($this->_store, "PT_BINARY:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x3");
  102                                 $goid2 = GetPropIDFromString($this->_store, "PT_BINARY:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x23");
  103                                 $mapiprops[$goid] = $mapiprops[$goid2] = hex2bin($data);
  104                                 break;
  105 
  106                             case 'ATTENDEE':
  107                                 $fields = explode(";", $field);
  108                                 foreach ($fields as $field) {
  109                                     $prop_pos     = strpos($field, '=');
  110                                     if ($prop_pos !== false) {
  111                                         switch (substr($field, 0, $prop_pos)) {
  112                                             case 'PARTSTAT'    : $partstat = substr($field, $prop_pos+1); break;
  113                                             case 'CN'        : $cn = substr($field, $prop_pos+1); break;
  114                                             case 'ROLE'        : $role = substr($field, $prop_pos+1); break;
  115                                             case 'RSVP'        : $rsvp = substr($field, $prop_pos+1); break;
  116                                         }
  117                                     }
  118                                 }
  119                                 if (isset($partstat) && isset($aClassMap[$partstat]) &&
  120                                     (!isset($mapiprops[PR_MESSAGE_CLASS]) || $mapiprops[PR_MESSAGE_CLASS] == "IPM.Schedule.Meeting.Request")) {
  121                                     $mapiprops[PR_MESSAGE_CLASS] = $aClassMap[$partstat]['class'];
  122                                     $mapiprops[PR_ICON_INDEX] = $aClassMap[$partstat]['icon'];
  123                                 } elseif (isset($role) && isset($aClassMap[$role]) &&
  124                                    (!isset($mapiprops[PR_MESSAGE_CLASS]) || $mapiprops[PR_MESSAGE_CLASS] == "IPM.Schedule.Meeting.Request")) {
  125                                     $mapiprops[PR_MESSAGE_CLASS] = $aClassMap[$role]['class'];
  126                                     $mapiprops[PR_ICON_INDEX] = $aClassMap[$role]['icon'];
  127                                 }
  128                                 if (!isset($cn)) $cn = ""; 
  129                                 $data         = str_replace ("MAILTO:", "", $data);
  130                                 $attendee[] = array ('name' => stripslashes($cn), 'email' => stripslashes($data));
  131                                 break;
  132 
  133                             case 'ORGANIZER':
  134                                 $field          = str_replace("ORGANIZER;CN=", "", $field);
  135                                 $data          = str_replace ("MAILTO:", "", $data);
  136                                 $organizer[] = array ('name' => stripslashes($field), 'email' => stripslashes($data));
  137                                 break;
  138 
  139                             case 'SUMMARY':
  140                                 $data = str_replace("\\n", "<br />", $data);
  141                                 $data = str_replace("\\t", "&nbsp;", $data);
  142                                 $data = str_replace("\\r", "<br />", $data);
  143                                 $data = stripslashes($data);
  144                                 $mapiprops[PR_SUBJECT] = $data;
  145                                 break;
  146 
  147                             // start dw2412: Work with the DESCRIPTION Field to get all parts together...
  148                             case 'DESCRIPTION':
  149                                 $data = str_replace("\\n", "<br />", $data);
  150                                 $data = str_replace("\\t", "&nbsp;", $data);
  151                                 $data = str_replace("\\r", "<br />", $data);
  152                                 $data = stripslashes($data);
  153                                 $mapiprops[PR_BODY] = $data;
  154                                 break;
  155                             // end dw2412: Work with the DESCRIPTION Field to get all parts together...
  156 
  157                             case 'LOCATION':
  158                                 $data = str_replace("\\n", "<br />", $data);
  159                                 $data = str_replace("\\t", "&nbsp;", $data);
  160                                 $data = str_replace("\\r", "<br />", $data);
  161                                 $data = stripslashes($data);
  162                                 $namedLocation = GetPropIDFromString($this->_store, "PT_STRING8:{00062002-0000-0000-C000-000000000046}:0x8208");
  163                                 $mapiprops[$namedLocation] = $data;
  164                                 $tneflocation = GetPropIDFromString($this->_store, "PT_STRING8:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x2");
  165                                 $mapiprops[$tneflocation] = $data;
  166                                 break;
  167                         }
  168                     }
  169                     break;
  170             }
  171             $i++;
  172 
  173         }
  174         $useTNEF = GetPropIDFromString($this->_store, "PT_BOOLEAN:{00062008-0000-0000-C000-000000000046}:0x8582");
  175         $mapiprops[$useTNEF] = true;
  176     }
  177 
  178     /*
  179      * Converts an YYYYMMDDTHHMMSSZ kind of string into an unixtimestamp
  180      *
  181      * @param string $data
  182      * @return long
  183      */
  184     function getTimestampFromStreamerDate ($data) {
  185         $data = str_replace('Z', '', $data);
  186         $data = str_replace('T', '', $data);
  187 
  188         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);
  189         if ($regs[1] < 1970) {
  190             $regs[1] = '1971';
  191         }
  192         return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
  193     }
  194 }
  195 
  196 ?>