Exemplo n.º 1
0
 /**
  * Generate a VTODO from a SyncAppointment(Exception)
  * @param string $data
  * @param string $id
  * @return iCalComponent
  */
 private function _ParseASTaskToVTodo($data, $id)
 {
     $vtodo = new iCalComponent();
     $vtodo->SetType("VTODO");
     if (isset($data->body)) {
         $vtodo->AddProperty("DESCRIPTION", $data->body);
     }
     if (isset($data->asbody->data)) {
         if (isset($data->nativebodytype) && $data->nativebodytype == SYNC_BODYPREFERENCE_RTF) {
             $rtfparser = new rtf();
             $rtfparser->loadrtf(base64_decode($data->asbody->data));
             $rtfparser->output("ascii");
             $rtfparser->parse();
             $vtodo->AddProperty("DESCRIPTION", $rtfparser->out);
         } else {
             $vtodo->AddProperty("DESCRIPTION", $data->asbody->data);
         }
     }
     if (isset($data->complete)) {
         if ($data->complete == "0") {
             $vtodo->AddProperty("STATUS", "NEEDS-ACTION");
         } else {
             $vtodo->AddProperty("STATUS", "COMPLETED");
         }
     }
     if (isset($data->datecompleted)) {
         $vtodo->AddProperty("COMPLETED", gmdate("Ymd\\THis\\Z", $data->datecompleted));
     }
     if ($data->utcduedate) {
         $vtodo->AddProperty("DUE", gmdate("Ymd\\THis\\Z", $data->utcduedate));
     }
     if (isset($data->importance)) {
         if ($data->importance == "1") {
             $vtodo->AddProperty("PRIORITY", 6);
         } elseif ($data->importance == "2") {
             $vtodo->AddProperty("PRIORITY", 9);
         } else {
             $vtodo->AddProperty("PRIORITY", 1);
         }
     }
     if (isset($data->recurrence)) {
         $vtodo->AddProperty("RRULE", $this->_GenerateRecurrence($data->recurrence));
     }
     if ($data->reminderset && $data->remindertime) {
         $valarm = new iCalComponent();
         $valarm->SetType("VALARM");
         $valarm->AddProperty("ACTION", "DISPLAY");
         $valarm->AddProperty("TRIGGER;VALUE=DATE-TIME", gmdate("Ymd\\THis\\Z", $data->remindertime));
         $vtodo->AddComponent($valarm);
     }
     if (isset($data->sensitivity)) {
         switch ($data->sensitivity) {
             case "0":
                 $vtodo->AddProperty("CLASS", "PUBLIC");
                 break;
             case "2":
                 $vtodo->AddProperty("CLASS", "PRIVATE");
                 break;
             case "3":
                 $vtodo->AddProperty("CLASS", "CONFIDENTIAL");
                 break;
         }
     }
     if (isset($data->utcstartdate)) {
         $vtodo->AddProperty("DTSTART", gmdate("Ymd\\THis\\Z", $data->utcstartdate));
     }
     if (isset($data->subject)) {
         $vtodo->AddProperty("SUMMARY", $data->subject);
     }
     if (isset($data->rtf)) {
         $rtfparser = new rtf();
         $rtfparser->loadrtf(base64_decode($data->rtf));
         $rtfparser->output("ascii");
         $rtfparser->parse();
         $vtodo->AddProperty("DESCRIPTION", $rtfparser->out);
     }
     if (isset($data->categories) && is_array($data->categories)) {
         $vtodo->AddProperty("CATEGORIES", implode(",", $data->categories));
     }
     return $vtodo;
 }
Exemplo n.º 2
0
 private function rtf2text($data)
 {
     $rtf_body = new rtf();
     $rtf_body->loadrtf(base64_decode($data));
     $rtf_body->output("ascii");
     $rtf_body->parse();
     $r = $rtf_body->out;
     unset($rtf_body);
     return $r;
 }
Exemplo n.º 3
0
 function ChangeMessage($folderid, $id, $message)
 {
     debugLog('GContacts::ChangeMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     $this->service->enableRequestDebugLogging(STATE_DIR . '/zendlog.txt');
     //non mi funziona
     $doc = new DOMDocument();
     $doc->formatOutput = true;
     //bmain
     $xmlns2005 = 'http://schemas.google.com/g/2005';
     $xmlns2008 = 'http://schemas.google.com/contact/2008';
     $atomentry = array('name' => array('@attributes' => array('xmlns' => $xmlns2005), 'fullName' => array('@value' => u2wi($message->fileas)), 'givenName' => array('@value' => u2wi($message->firstname)), 'familyName' => array('@value' => u2wi($message->lastname)), 'nameSuffix' => array('@value' => u2wi($message->suffix))), 'organization' => array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#other"), 'orgName' => array('@value' => u2wi($message->companyname)), 'orgTitle' => array('@value' => u2wi($message->jobtitle))), 'nickname' => array('@attributes' => array('xmlns' => $xmlns2008), '@value' => u2wi($message->nickname)), 'birthday' => array('@attributes' => array('xmlns' => $xmlns2008, 'when' => u2wi($message->birthday))), 'website' => array('@attributes' => array('xmlns' => $xmlns2008, 'rel' => 'home-page', 'href' => u2wi($message->webpage))), 'event' => array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => 'anniversary', 'xmlns:default' => "http://schemas.google.com/g/2005"), 'default:when' => array('@attributes' => array('startTime' => u2wi($message->anniversary)))), 'structuredPostalAddress' => array(array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . '#home'), 'formattedAddress' => u2wi($message->homestreet) . "\n" . u2wi($message->homecity) . "\n" . u2wi($message->homestate) . "\n" . u2wi($message->homepostalcode) . "\n" . u2wi($message->homecountry), 'street' => u2wi($message->homestreet), 'postcode' => u2wi($message->homepostalcode), 'city' => u2wi($message->homecity), 'region' => u2wi($message->homestate), 'country' => u2wi($message->homecountry)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . '#work'), 'formattedAddress' => u2wi($message->businessstreet) . "\n" . u2wi($message->businesscity) . "\n" . u2wi($message->businessstate) . "\n" . u2wi($message->businesspostalcode) . "\n" . u2wi($message->businesscountry), 'street' => u2wi($message->businessstreet), 'postcode' => u2wi($message->businesspostalcode), 'city' => u2wi($message->businesscity), 'region' => u2wi($message->businessstate), 'country' => u2wi($message->businesscountry)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . '#other'), 'formattedAddress' => u2wi($message->otherstreet) . "\n" . u2wi($message->othercity) . "\n" . u2wi($message->otherstate) . "\n" . u2wi($message->otherpostalcode) . "\n" . u2wi($message->othercountry), 'street' => u2wi($message->otherstreet), 'postcode' => u2wi($message->otherpostalcode), 'city' => u2wi($message->othercity), 'region' => u2wi($message->otherstate), 'country' => u2wi($message->othercountry))), 'email' => array(array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#home", 'address' => u2wi($message->email1address))), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#work", 'address' => u2wi($message->email2address))), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#other", 'address' => u2wi($message->email3address)))), 'im' => array(array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#other", 'protocol' => 'http://schemas.google.com/g/2005#MSN', 'address' => u2wi($message->imaddress2)))), 'userDefinedField' => array(array('@attributes' => array('xmlns' => $xmlns2008, 'key' => 'Children', 'value' => u2wi($message->children))), array('@attributes' => array('xmlns' => $xmlns2008, 'key' => 'Spouse', 'value' => u2wi($message->spouse)))), 'phoneNumber' => array(array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#home"), '@value' => u2wi($message->homephonenumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#home"), '@value' => u2wi($message->home2phonenumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#work"), '@value' => u2wi($message->businessphonenumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#work"), '@value' => u2wi($message->business2phonenumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#mobile"), '@value' => u2wi($message->mobilephonenumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#pager"), '@value' => u2wi($message->pagernumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#other"), '@value' => u2wi($message->carphonenumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#home_fax"), '@value' => u2wi($message->homefaxnumber)), array('@attributes' => array('xmlns' => $xmlns2005, 'rel' => $xmlns2005 . "#work_fax"), '@value' => u2wi($message->businessfaxnumber))));
     //if no ID given -> create new event
     //if ID given -> load old event, modify it, save it
     if (!empty($id)) {
         try {
             debugLog("GContacts::ChangeMessage - Import data from existing contact");
             // perform query and get entry
             $query = new Zend_Gdata_Query(GCONTACTS_URL . '/' . $id);
             $entry = $this->service->getEntry($query);
             $success = $doc->loadXML($entry->getXML());
             // creo le stesse strutture
             //$xml = simplexml_load_string($entry->getXML());
             $root = $doc->getElementsByTagName("entry")->item(0);
         } catch (Exception $e) {
             debugLog("GContacts::ChangeMessage - ERROR! (" . $e->getMessage() . ")");
         }
     } else {
         try {
             debugLog("GContacts::ChangeMessage - Creating atom:entry structure");
             if ($doc->getElementsByTagName("entry")->length == 0) {
                 // create new entry
                 $entry = $doc->createElement('atom:entry');
                 $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom');
                 $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005');
                 $root = $doc->appendChild($entry);
             } else {
                 //only for internal debug
                 $root = $doc->getElementsByTagName("entry")->item(0);
             }
         } catch (Exception $e) {
             debugLog("GContacts::ChangeMessage - ERROR! (" . $e->getMessage() . ")");
             return false;
         }
     }
     $doc = AtoX($atomentry, $doc, $root);
     //emain
     /*
     	
     	if(!empty($message->fileas)){
     		$xml->name->fullName = u2wi($message->fileas);
     	} else {
     		$x= 1;
     	}
     
     		    foreach ($xml->email as $email) {
     			preg_match("/[_a-z0-9]+$/", $email['rel'], $matches);
     			$rel = $matches[0];
     			
     			//isset($email['primary']
     			switch ($rel) {
     			    case 'home':
     					if (!empty($message->email1address)) {
     						$email['address'] = $message->email1address;
     					}
     				break;
     			    case 'work':
     					if (!empty($message->email2address)) {
     						$email['address'] = $message->email2address;
     					}
     				break;
     			    case 'other':
     					if (!empty($message->email3address)) {
     						$email['address'] = $message->email3address;
     					}
     				break;
     			//    default:
     			//	break;
     			}
     			
     		    }
     */
     /*		  // add email element
     		  if (!empty($message->email1address)) {
     		    $email = $doc->createElement('gd:email');
     		    $email->setAttribute('address' , u2wi($message->email1address));
     		    $email->setAttribute('rel' ,'http://schemas.google.com/g/2005#home');
     		    $entry->appendChild($email);
     		  }
     		  if (!empty($message->email2address)) {
     		    $email = $doc->createElement('gd:email');
     		    $email->setAttribute('address' , u2wi($message->email2address));
     		    $email->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
     		    $entry->appendChild($email);
     		  }
     		  if (!empty($message->email3address)) {
     		    $email = $doc->createElement('gd:email');
     		    $email->setAttribute('address' , u2wi($message->email3address));
     		    $email->setAttribute('rel' ,'http://schemas.google.com/g/2005#other');
     		    $entry->appendChild($email);
     		  }
     
     */
     $fh = fopen(STATE_DIR . '/xml-put/' . (string) $message->fileas . '.xml', 'w');
     fwrite($fh, $doc->saveXML());
     $xml = simplexml_load_string($xmldata);
     fclose($fh);
     try {
         $newEntry = NULL;
         if (!empty($id)) {
             $extra_header = array();
             $extra_header['If-Match'] = '*';
             //$extra_header = array('If-Match'=>'*');
             $newEntry = $this->service->updateEntry($doc->saveXML(), $entry->getEditLink()->href, null, $extra_header);
             file_put_contents(STATE_DIR . "/obj_updateEntry_dump.txt", serialize($newEntry) . "\n\n", FILE_APPEND);
         } else {
             $newEntry = $this->service->insertEntry($doc->saveXML(), GCONTACTS_URL);
             file_put_contents(STATE_DIR . "/obj_insertEntry_dump.txt", serialize($newEntry) . "\n\n", FILE_APPEND);
         }
         //filter out real contact id without other garbage
         preg_match("/[_a-z0-9]+\$/", $newEntry->id, $matches);
         $contactid = $matches[0];
         $m = array();
         $m["id"] = (string) $contactid;
         $m["flags"] = "1";
         $m["mod"] = strtotime((string) $newEntry->getUpdated());
         debugLog("GCalendar::ChangeMessage - Inserted Entry: " . $m['id']);
         return $m;
     } catch (Exception $e) {
         debugLog("GContacts::ChangeMessage - ERROR! (" . $e->getMessage() . ")");
         return false;
     }
     return false;
     /*	$mapping = array(
     	    'fileas' => 'FN',
     	    'lastname;firstname;middlename;title;suffix' => 'N',
     	    'email1address' => 'EMAIL;INTERNET',
     	    'email2address' => 'EMAIL;INTERNET',
     	    'email3address' => 'EMAIL;INTERNET',
     	    'businessphonenumber' => 'TEL;WORK',
     	    'business2phonenumber' => 'TEL;WORK',
     	    'businessfaxnumber' => 'TEL;WORK;FAX',
     	    'homephonenumber' => 'TEL;HOME',
     	    'home2phonenumber' => 'TEL;HOME',
     	    'homefaxnumber' => 'TEL;HOME;FAX',
     	    'mobilephonenumber' => 'TEL;CELL',
     	    'carphonenumber' => 'TEL;CAR',
     	    'pagernumber' => 'TEL;PAGER',
     	    ';;businessstreet;businesscity;businessstate;businesspostalcode;businesscountry' => 'ADR;WORK',
     	    ';;homestreet;homecity;homestate;homepostalcode;homecountry' => 'ADR;HOME',
     	    ';;otherstreet;othercity;otherstate;otherpostalcode;othercountry' => 'ADR',
     	    'companyname' => 'ORG',
     	    'body' => 'NOTE',
     	    'jobtitle' => 'ROLE',
     	    'webpage' => 'URL',
     	    'nickname' => 'NICKNAME',
     	);
     */
     // Since in >=AS12.1 we have the airsyncbasebody object
     // By doing this hack we can continue using our current functions...
     if (isset($message->airsyncbasebody)) {
         switch ($message->airsyncbasebody->type) {
             case '3':
                 $message->rtf = $message->airsyncbasebody->data;
                 break;
             case '1':
                 $message->body = $message->airsyncbasebody->data;
                 break;
         }
     }
     // In case body is sent in rtf, convert it to ascii and use it as message body element so that we
     // can later on write it to file
     if (isset($message->rtf)) {
         // Nokia MfE 2.9.158 sends contact notes with RTF and Body element.
         // The RTF is empty, the body contains the note therefore we need to unpack the rtf
         // to see if it is realy empty and in case not, take the appointment body.
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         if (isset($message->body) && isset($rtf_body->out) && $rtf_body->out == "" && $message->body != "") {
             unset($message->rtf);
         }
         debugLog('vcarddir::RTFDATA:' . $message->rtf);
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         debugLog('vcarddir::RTFDATA-parsed:' . $rtf_body->out);
         //put rtf into body
         if ($rtf_body->out != "") {
             $message->body = $rtf_body->out;
         }
     }
     $data = "BEGIN:VCARD\nVERSION:2.1\nPRODID:Z-Push\n";
     foreach ($mapping as $k => $v) {
         $val = '';
         $ks = preg_split("/;/", $k);
         foreach ($ks as $i) {
             if (!empty($message->{$i})) {
                 $val .= $this->escape($message->{$i});
             }
             $val .= ';';
         }
         if (empty($val)) {
             continue;
         }
         $val = substr($val, 0, -1);
         if (strlen($val) > 50) {
             $data .= $v . ":\n\t" . substr(chunk_split($val, 50, "\n\t"), 0, -1);
         } else {
             $data .= $v . ':' . $val . "\n";
         }
     }
     if (!empty($message->categories)) {
         $data .= 'CATEGORIES:' . implode(',', $this->escape($message->categories)) . "\n";
     }
     if (!empty($message->picture)) {
         $data .= 'PHOTO;ENCODING=BASE64;TYPE=JPEG:' . "\n\t" . substr(chunk_split($message->picture, 50, "\n\t"), 0, -1);
     }
     if (isset($message->birthday)) {
         $data .= 'BDAY:' . date('Y-m-d', $message->birthday) . "\n";
     }
     $data .= "END:VCARD\n";
     // not supported: anniversary, assistantname, assistnamephonenumber, children, department, officelocation, radiophonenumber, spouse, rtf
     if (!$id) {
         if (!empty($message->fileas)) {
             $name = u2wi($message->fileas);
         } elseif (!empty($message->lastname)) {
             $name = $name = u2wi($message->lastname);
         } elseif (!empty($message->firstname)) {
             $name = $name = u2wi($message->firstname);
         } elseif (!empty($message->companyname)) {
             $name = $name = u2wi($message->companyname);
         } else {
             $name = 'unknown';
         }
         $name = preg_replace('/[^a-z0-9 _-]/i', '', $name);
         $entry = $name . '.vcf';
         $i = 0;
         while (file_exists($this->_path . '/' . $entry)) {
             $i++;
             $entry = $name . $i . '.vcf';
         }
         file_put_contents($this->_path . '/' . $entry, $data);
         ksort($this->_items);
         end($this->_items);
         if (key($this->_items) + 1 == 1) {
             $id = sprintf("1%09d", key($this->_items) + 1);
         } else {
             $id = key($this->_items) + 1;
         }
         $this->_items[$id] = $entry;
         file_put_contents(STATE_DIR . '/' . strtolower($this->_devid) . '/gcontacts_items_' . $this->_user, serialize($this->_items));
     } else {
         file_put_contents($this->_path . '/' . $this->_items[$id], $data);
     }
     return $this->StatMessage($folderid, $id);
 }
Exemplo n.º 4
0
 function ChangeMessage($folderid, $id, $message)
 {
     debugLog('iCalDir::ChangeMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     //        debugLog('iCalDir::ChangeMessage:' . print_r($message,1));
     // Since in >=AS12.1 we have the airsyncbasebody object
     // By doing this hack we can continue using our current functions...
     if (isset($message->airsyncbasebody)) {
         switch ($message->airsyncbasebody->type) {
             case '3':
                 $message->rtf = $message->airsyncbasebody->data;
                 break;
             case '1':
                 $message->body = $message->airsyncbasebody->data;
                 break;
         }
     }
     // In case body is sent in rtf, convert it to ascii and use it as message body element so that we
     // can later on write it to file
     if (isset($message->rtf)) {
         // Nokia MfE 2.9.158 sends contact notes with RTF and Body element.
         // The RTF is empty, the body contains the note therefore we need to unpack the rtf
         // to see if it is realy empty and in case not, take the appointment body.
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         if (isset($message->body) && isset($rtf_body->out) && $rtf_body->out == "" && $message->body != "") {
             unset($message->rtf);
         }
         //		    debugLog('iCalDir::RTFDATA:' . $message->rtf);
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         //		    debugLog('iCalDir::RTFDATA-parsed:' . $rtf_body->out);
         //put rtf into body
         if ($rtf_body->out != "") {
             $message->body = $rtf_body->out;
         }
     }
     $fieldmapping = array_flip($this->_mapping);
     //$message->uid
     //   ist vom iPhone nicht wirklich barauchbar..., vorerst *deaktiviert*
     //$message->timezone:
     //   der hier im $message enthaltene Wert ist utf8 codiert. Wenn man diesen decodiert
     //   bekommt man eine 172 Byte lange Structur bestehend aus Werten für die Zeitverschiebung
     //   des jeweiligen Eintrages. Im Hex-Editor sind z.B. die ersten 32 Bit das Offset zur UTC
     //   in Minuten, also für unsere Zeitzone wäre das -60 Minuten Weitere Infos dazu sind in
     //   der Datentypendokumentation der Acticesync Doku
     $data = "BEGIN:itacomCalendarEntry\nVERSION:1.0\nPRODID:MobileSync\nLASTCHANGED:" . date('Ymd:His') . "\n";
     foreach ($fieldmapping as $zpushobj => $icalfield) {
         switch ($zpushobj) {
             default:
                 $val = '';
                 // PHP split durch PHP.explode ersetzt da die Funktion ausläuft und ab PHP6 nicht mehr verfügbar sein wird!
                 $zpushfields = explode('->', $zpushobj);
                 if ($zpushfields[0] == "recurrence") {
                     if (!empty($message->recurrence->{$zpushfields}[1])) {
                         $val .= $this->escape($message->recurrence->{$zpushfields}[1]);
                     }
                     $val .= ';';
                 } else {
                     foreach ($zpushfields as $zpushfield) {
                         if (!empty($message->{$zpushfield})) {
                             $val .= $this->escape($message->{$zpushfield});
                         }
                         $val .= ';';
                     }
                 }
                 if (empty($val)) {
                     continue;
                 }
                 $val = substr($val, 0, -1);
                 $data .= strtoupper($icalfield);
                 if (strlen($val) > 50) {
                     $data .= ":\n\t" . substr(chunk_split($val, 50, "\n\t"), 0, -1);
                 } else {
                     $data .= ':' . $val . "\n";
                 }
         }
     }
     if (!isset($fieldmapping['uid'])) {
         $uid = $this->_uid();
         $data .= "UID:" . $uid . "\n";
     }
     $data .= "END:itacomCalendarEntry";
     //        debugLog('iCalDir::DATA:' . print_r($data,1));
     $data = utf8_encode($data);
     if (!$id) {
         // jeder Termin müsste eine Startzeit haben, auch sollten relativ wenig Termine zur elben zeit beginnen
         // dadurch sollten die ID's/Dateinamen ziemlich einzigartig bleiben, so das es nicht nötig sein sollte "_i" hinten an die Dateinmaen zu packen
         $name = $message->starttime;
         $entry = $name . '.iCal';
         $i = 0;
         while (file_exists($this->_path . '/' . $entry)) {
             $i++;
             $entry = $name . '_' . $i . '.iCal';
         }
         file_put_contents($this->_path . '/' . $entry, $data);
         /*			ksort($this->_items);
         			end($this->_items);
         			if (key($this->_items)+1 == 1) {
         				$id = sprintf("1%09d",key($this->_items)+1);
         			} else {
         				$id = key($this->_items)+1;
         			}
         */
         $id = $this->_itemid();
         $this->_items[$id] = $entry;
         file_put_contents(STATE_DIR . '/' . strtolower($this->_devid) . '/ical_items_' . $this->_user, serialize($this->_items));
     } else {
         file_put_contents($this->_path . '/' . $this->_items[$id], $data);
     }
     return $this->StatMessage($folderid, $id);
 }
Exemplo n.º 5
0
 function _setTask($mapimessage, $task)
 {
     mapi_setprops($mapimessage, array(PR_MESSAGE_CLASS => "IPM.Task"));
     // START ADDED dw2412 Take care about notes
     if (isset($task->airsyncbasebody)) {
         switch ($task->airsyncbasebody->type) {
             case '3':
                 $task->rtf = $task->airsyncbasebody->data;
                 break;
             case '1':
                 $task->body = $task->airsyncbasebody->data;
                 break;
         }
     }
     if (isset($task->rtf)) {
         // start dw2412
         // Nokia MfE 2.9.158 sends task notes with RTF and Body element.
         // The RTF is empty, the body contains the note therefore we need to unpack the rtf
         // to see if it is realy empty and in case not, take the task body.
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($task->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         if (isset($task->body) && isset($rtf_body->out) && $rtf_body->out == "" && $task->body != "") {
             unset($task->rtf);
         }
         // end dw2412
     }
     // END ADDED dw2412 Take care about notes
     // END ADDED dw2412 Take care about notes
     $this->_setPropsInMAPI($mapimessage, $task, $this->_taskmapping);
     if (isset($task->complete)) {
         if ($task->complete) {
             // Set completion to 100%
             // Set status to 'complete'
             mapi_setprops($mapimessage, array($this->_getPropIDFromString("PT_DOUBLE:{00062003-0000-0000-C000-000000000046}:0x8102") => 1.0, $this->_getPropIDFromString("PT_LONG:{00062003-0000-0000-C000-000000000046}:0x8101") => 2));
         } else {
             // Set completion to 0%
             // Set status to 'not started'
             mapi_setprops($mapimessage, array($this->_getPropIDFromString("PT_DOUBLE:{00062003-0000-0000-C000-000000000046}:0x8102") => 0.0, $this->_getPropIDFromString("PT_LONG:{00062003-0000-0000-C000-000000000046}:0x8101") => 0));
         }
     }
 }
Exemplo n.º 6
0
 function converttoical($icalcomponent, $message, $mapping, $allday = false)
 {
     foreach ($mapping as $k => $e) {
         if (isset($message->{$e}[0])) {
             $val = $message->{$e}[0];
             if (!is_object($val) && !is_array($val)) {
                 $val = trim($val);
             }
             if ($val != '') {
                 $k = strtoupper($k);
                 // if found $k in message convert and put in event
                 if ($e[1] == 0) {
                     $icalcomponent->setProperty($k, $val);
                 }
                 if ($e[1] == 1) {
                     $val = trim($val);
                     switch ($k) {
                         case "CLASS":
                             switch ($val) {
                                 case "0":
                                     $val = "PUBLIC";
                                     break;
                                 case "1":
                                     $val = "PRIVATE";
                                     break;
                                 case "2":
                                     $val = "PRIVATE";
                                     break;
                                 case "3":
                                     $val = "CONFIDENTIAL";
                                     break;
                             }
                             break;
                         case "STATUS":
                             switch ($val) {
                                 case "1":
                                     $val = "TENTATIVE";
                                     break;
                                 case "3":
                                     $val = "CONFIRMED";
                                     break;
                                 case "5":
                                     $val = "CANCELLED";
                                     break;
                             }
                             break;
                         case "TRANSP":
                             switch ($val) {
                                 case "0":
                                     $val = "TRANSPARENT";
                                     break;
                                 case "2":
                                     $val = "OPAQUE";
                                     break;
                                 default:
                                     $val = "OPAQUE";
                             }
                             break;
                         case "PRIORITY":
                             switch ($val) {
                                 case "0":
                                     $val = "9";
                                     break;
                                 case "1":
                                     $val = "5";
                                     break;
                                 case "2":
                                     $val = "1";
                                     break;
                                 default:
                                     $val = "";
                             }
                             break;
                     }
                     $icalcomponent->setProperty($k, $val);
                 }
                 if ($e[1] == 2) {
                     $icalcomponent->setProperty($k, $val);
                 }
                 if ($e[1] == 3) {
                     // convert to date
                     $val = $this->parseDate($val);
                     if ($allday) {
                         $icalcomponent->setProperty($k, $val, array('VALUE' => 'DATE'));
                     } else {
                         $icalcomponent->setProperty($k, $val);
                     }
                 }
                 if ($e[1] == 4) {
                     // extract organizers name and email
                     if (trim($val) != '') {
                         $icalcomponent->setProperty($k, $val);
                     }
                 }
                 if ($e[1] == 5) {
                     // recurrence?
                     switch (trim($val->type)) {
                         case "0":
                             $args['FREQ'] = "DAILY";
                             break;
                         case "1":
                             $args['FREQ'] = "WEEKLY";
                             break;
                         case "2":
                             $args['FREQ'] = "MONTHLY";
                             break;
                         case "3":
                             $args['FREQ'] = "MONTHLY";
                             break;
                         case "5":
                             $args['FREQ'] = "YEARLY";
                             break;
                         case "6":
                             $args['FREQ'] = "YEARLY";
                             break;
                     }
                     if (isset($val->dayofweek) && $val->dayofweek != "" && is_numeric($val->dayofweek)) {
                         $tmp = "0000000" . decbin($val->dayofweek);
                         $args["BYDAY"] = array();
                         $len = strlen($tmp);
                         if (isset($val->weekofmonth) && $val->weekofmonth != "" && is_numeric($val->weekofmonth)) {
                             $wn = $val->weekofmonth;
                             if (substr($tmp, $len - 1, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "SU"));
                             }
                             if (substr($tmp, $len - 2, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "MO"));
                             }
                             if (substr($tmp, $len - 3, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "TU"));
                             }
                             if (substr($tmp, $len - 4, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "WE"));
                             }
                             if (substr($tmp, $len - 5, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "TH"));
                             }
                             if (substr($tmp, $len - 6, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "FR"));
                             }
                             if (substr($tmp, $len - 7, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "SA"));
                             }
                         } else {
                             if (substr($tmp, $len - 1, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "SU"));
                             }
                             if (substr($tmp, $len - 2, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "MO"));
                             }
                             if (substr($tmp, $len - 3, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "TU"));
                             }
                             if (substr($tmp, $len - 4, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "WE"));
                             }
                             if (substr($tmp, $len - 5, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "TH"));
                             }
                             if (substr($tmp, $len - 6, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "FR"));
                             }
                             if (substr($tmp, $len - 7, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "SA"));
                             }
                         }
                     }
                     if (isset($val->dayofmonth) && $val->dayofmonth != "" && is_numeric($val->dayofmonth)) {
                         $args['BYMONTHDAY'] = $val->dayofmonth;
                     }
                     if (isset($val->monthofyear) && $val->monthofyear != "" && is_numeric($val->monthofyear)) {
                         $args['BYMONTH'] = $val->monthofyear;
                     }
                     $args['INTERVAL'] = 1;
                     if (isset($val->interval) && $val->interval != "") {
                         $args['INTERVAL'] = $val->interval;
                     }
                     if (isset($val->until) && $val->until != "") {
                         $args['UNTIL'] = $this->parseGMTDate($val->until);
                     }
                     if (isset($val->occurrences) && $val->occurrences != "") {
                         $args['COUNT'] = $val->occurrences;
                     }
                     $icalcomponent->setProperty($k, $args);
                 }
                 if ($e[1] == 6) {
                     if ($val != "") {
                         $val = $this->parseDate($val);
                         $icalcomponent->setProperty($k, $val);
                         $icalcomponent->setProperty("PERCENT_COMPLETE", 100);
                         $icalcomponent->setProperty("STATUS", "COMPLETED");
                     }
                 }
                 if ($e[1] == 7) {
                     $valarm = new valarm();
                     $valarm->setProperty("ACTION", "DISPLAY");
                     $valarm->setProperty("DESCRIPTION", $icalcomponent->getProperty("SUMMARY"));
                     $valarm->setProperty("TRIGGER", "-PT0H" . $val . "M0S");
                     $icalcomponent->setComponent($valarm);
                 }
                 if ($e[1] == 8) {
                     $valarm = new valarm();
                     $valarm->setProperty("ACTION", "DISPLAY");
                     $valarm->setProperty("DESCRIPTION", $icalcomponent->getProperty("SUMMARY"));
                     $valarm->setProperty("TRIGGER", array("timestamp" => $val));
                     $icalcomponent->setComponent($valarm);
                 }
                 if ($e[1] == 9 && is_array($val)) {
                     foreach ($val as $att) {
                         $icalcomponent->setProperty($k, $att->email, array("CN" => $att->name));
                     }
                 }
                 if ($e[1] == 10) {
                     require_once 'z_RTF.php';
                     $rtfparser = new rtf();
                     $rtfparser->loadrtf(base64_decode($val));
                     $rtfparser->output("ascii");
                     $rtfparser->parse();
                     $icalcomponent->setProperty($k, $rtfparser->out);
                 }
             }
         }
     }
     return $icalcomponent;
 }
Exemplo n.º 7
0
 function ChangeMessage($folderid, $id, $message)
 {
     debugLog('iConDir::ChangeMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     //        debugLog('iConDir::ChangeMessage:' . print_r($message,1));
     $fieldmapping = array_flip($this->_mapping);
     // Since in >=AS12.1 we have the airsyncbasebody object
     // By doing this hack we can continue using our current functions...
     if (isset($message->airsyncbasebody)) {
         switch ($message->airsyncbasebody->type) {
             case '3':
                 $message->rtf = $message->airsyncbasebody->data;
                 break;
             case '1':
                 $message->body = $message->airsyncbasebody->data;
                 break;
         }
     }
     // In case body is sent in rtf, convert it to ascii and use it as message body element so that we
     // can later on write it to file
     if (isset($message->rtf)) {
         // Nokia MfE 2.9.158 sends contact notes with RTF and Body element.
         // The RTF is empty, the body contains the note therefore we need to unpack the rtf
         // to see if it is realy empty and in case not, take the appointment body.
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         if (isset($message->body) && isset($rtf_body->out) && $rtf_body->out == "" && $message->body != "") {
             unset($message->rtf);
         }
         debugLog('iConDir::RTFDATA:' . $message->rtf);
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         debugLog('iConDir::RTFDATA-parsed:' . $rtf_body->out);
         //put rtf into body
         if ($rtf_body->out != "") {
             $message->body = $rtf_body->out;
         }
     }
     $data = "BEGIN:itacomContactEntry\nVERSION:1.0\nPRODID:MobileSync\nLASTCHANGED:" . date('Ymd:His') . "\n";
     #$data = "BEGIN:DVCARD\nVERSION:1.0\nPRODID:dvAS\n";
     foreach ($fieldmapping as $zpushobj => $iconfield) {
         switch ($zpushobj) {
             case 'categories':
                 if (!empty($message->categories)) {
                     $data .= strtoupper($iconfield) . ':' . implode(',', $this->escape($message->categories)) . "\n";
                 }
                 break;
             case 'birthday':
                 if (isset($message->birthday)) {
                     $data .= strtoupper($iconfield) . ':' . date('Y-m-d', $message->birthday) . "\n";
                 }
                 break;
             case 'picture':
                 if (!empty($message->picture)) {
                     $data .= strtoupper($iconfield) . ';ENCODING=BASE64;TYPE=JPEG:' . "\n\t" . substr(chunk_split($message->picture, 50, "\n\t"), 0, -1);
                 }
                 break;
             default:
                 $val = '';
                 // PHP.split durch PHP.explode ersetzt da die Funktion ausläuft und ab PHP6 nicht mehr verfügbar sein wird!
                 $zpushfields = explode('->', $zpushobj);
                 foreach ($zpushfields as $zpushfield) {
                     if (!empty($message->{$zpushfield})) {
                         $val .= $this->escape($message->{$zpushfield});
                     }
                     $val .= ';';
                 }
                 if (empty($val)) {
                     continue;
                 }
                 $val = substr($val, 0, -1);
                 $data .= strtoupper($iconfield);
                 if (strlen($val) > 50) {
                     $data .= ":\n\t" . substr(chunk_split($val, 50, "\n\t"), 0, -1);
                 } else {
                     $data .= ':' . $val . "\n";
                 }
         }
     }
     $data .= "END:itacomContactEntry";
     //        debugLog('iConDir::DATA:' . print_r($data,1));
     $data = utf8_encode($data);
     if (!$id) {
         if (!empty($message->fileas)) {
             $name = u2wi($message->fileas);
         } elseif (!empty($message->lastname)) {
             $name = $name = u2wi($message->lastname);
         } elseif (!empty($message->firstname)) {
             $name = $name = u2wi($message->firstname);
         } elseif (!empty($message->companyname)) {
             $name = $name = u2wi($message->companyname);
         } else {
             $name = 'unknown';
         }
         $name = preg_replace('/[^a-z0-9 _-]/i', '', $name);
         $entry = $name . '.iCon';
         $i = 0;
         while (file_exists($this->_path . '/' . $entry)) {
             $i++;
             $entry = $name . '_' . $i . '.iCon';
         }
         file_put_contents($this->_path . '/' . $entry, $data);
         /*			ksort($this->_items);
         			end($this->_items);
         			if (key($this->_items)+1 == 1)
         				$id = sprintf("1%09d",key($this->_items)+1);
         			else 
         				$id = key($this->_items)+1;
         */
         $entryid = $this->_itemid();
         $this->_items[$id] = $entry;
         file_put_contents(STATE_DIR . '/' . strtolower($this->_devid) . '/icon_items_' . $this->_user, serialize($this->_items));
     } else {
         file_put_contents($this->_path . '/' . $this->_items[$id], $data);
     }
     return $this->StatMessage($folderid, $id);
 }
Exemplo n.º 8
0
 /**
  * Convert received messagenote to egroupware plaintext note
  *
  * @param $body the plain body received
  * @param $body the rtf body data
  * @param $airsyncbasebody  object received from client
  *
  * @return string plaintext for eGroupware
  */
 public function messagenote2note($body, $rtf, $airsyncbasebody)
 {
     if (isset($airsyncbasebody)) {
         switch ($airsyncbasebody->type) {
             case '3':
                 $rtf = $airsyncbasebody->data;
                 //error_log("Airsyncbase RTF Body");
                 break;
             case '1':
                 $body = $airsyncbasebody->data;
                 //error_log("Airsyncbase Plain Body");
                 break;
         }
     }
     // Nokia MfE 2.9.158 sends contact notes with RTF and Body element.
     // The RTF is empty, the body contains the note therefore we need to unpack the rtf
     // to see if it is realy empty and in case not, take the appointment body.
     if (isset($message->rtf)) {
         error_log("RTF Body");
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         if (isset($body) && isset($rtf_body->out) && $rtf_body->out == "" && $body != "") {
             unset($rtf);
         }
         if ($rtf_body->out != "") {
             $body = $rtf_body->out;
         }
     }
     return $body;
 }
Exemplo n.º 9
0
<?php

error_reporting(0);
if (isset($_POST['preview'])) {
    echo '
<div align="center">
<h2>YOU POSTED</h2>' . $_POST['title'] . '<br><br><br>' . stripslashes($_POST['myTextArea']) . '</div>';
}
if (isset($_POST['rtf2html'])) {
    include 'parser.php';
    $r = new rtf(stripslashes($_POST['myTextArea']));
    $r->output("xml");
    $r->parse();
    if (count($r->err) == 0) {
        // no errors detected
        echo $r->out;
    }
}
Exemplo n.º 10
0
 function ChangeMessage($folderid, $id, $message)
 {
     debugLog('VCDir::ChangeMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     $mapping = array('fileas' => 'FN', 'lastname;firstname;middlename;title;suffix' => 'N', 'email1address' => 'EMAIL;INTERNET', 'email2address' => 'EMAIL;INTERNET', 'email3address' => 'EMAIL;INTERNET', 'businessphonenumber' => 'TEL;WORK', 'business2phonenumber' => 'TEL;WORK', 'businessfaxnumber' => 'TEL;WORK;FAX', 'homephonenumber' => 'TEL;HOME', 'home2phonenumber' => 'TEL;HOME', 'homefaxnumber' => 'TEL;HOME;FAX', 'mobilephonenumber' => 'TEL;CELL', 'carphonenumber' => 'TEL;CAR', 'pagernumber' => 'TEL;PAGER', ';;businessstreet;businesscity;businessstate;businesspostalcode;businesscountry' => 'ADR;WORK', ';;homestreet;homecity;homestate;homepostalcode;homecountry' => 'ADR;HOME', ';;otherstreet;othercity;otherstate;otherpostalcode;othercountry' => 'ADR', 'companyname' => 'ORG', 'body' => 'NOTE', 'jobtitle' => 'ROLE', 'webpage' => 'URL');
     // Since in >=AS12.1 we have the airsyncbasebody object
     // By doing this hack we can continue using our current functions...
     if (isset($message->airsyncbasebody)) {
         switch ($message->airsyncbasebody->type) {
             case '3':
                 $message->rtf = $message->airsyncbasebody->data;
                 break;
             case '1':
                 $message->body = $message->airsyncbasebody->data;
                 break;
         }
     }
     // In case body is sent in rtf, convert it to ascii and use it as message body element so that we
     // can later on write it to file
     if (isset($message->rtf)) {
         // Nokia MfE 2.9.158 sends contact notes with RTF and Body element.
         // The RTF is empty, the body contains the note therefore we need to unpack the rtf
         // to see if it is realy empty and in case not, take the appointment body.
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         if (isset($message->body) && isset($rtf_body->out) && $rtf_body->out == "" && $message->body != "") {
             unset($message->rtf);
         }
         debugLog('vcarddir::RTFDATA:' . $message->rtf);
         $rtf_body = new rtf();
         $rtf_body->loadrtf(base64_decode($message->rtf));
         $rtf_body->output("ascii");
         $rtf_body->parse();
         debugLog('vcarddir::RTFDATA-parsed:' . $rtf_body->out);
         //put rtf into body
         if ($rtf_body->out != "") {
             $message->body = $rtf_body->out;
         }
     }
     $data = "BEGIN:VCARD\nVERSION:2.1\nPRODID:Z-Push\n";
     foreach ($mapping as $k => $v) {
         $val = '';
         $ks = split(';', $k);
         foreach ($ks as $i) {
             if (!empty($message->{$i})) {
                 $val .= $this->escape($message->{$i});
             }
             $val .= ';';
         }
         if (empty($val)) {
             continue;
         }
         $val = substr($val, 0, -1);
         if (strlen($val) > 50) {
             $data .= $v . ":\n\t" . substr(chunk_split($val, 50, "\n\t"), 0, -1);
         } else {
             $data .= $v . ':' . $val . "\n";
         }
     }
     if (!empty($message->categories)) {
         $data .= 'CATEGORIES:' . implode(',', $this->escape($message->categories)) . "\n";
     }
     if (!empty($message->picture)) {
         $data .= 'PHOTO;ENCODING=BASE64;TYPE=JPEG:' . "\n\t" . substr(chunk_split($message->picture, 50, "\n\t"), 0, -1);
     }
     if (isset($message->birthday)) {
         $data .= 'BDAY:' . date('Y-m-d', $message->birthday) . "\n";
     }
     $data .= "END:VCARD";
     // not supported: anniversary, assistantname, assistnamephonenumber, children, department, officelocation, radiophonenumber, spouse, rtf
     if (!$id) {
         if (!empty($message->fileas)) {
             $name = u2wi($message->fileas);
         } elseif (!empty($message->lastname)) {
             $name = $name = u2wi($message->lastname);
         } elseif (!empty($message->firstname)) {
             $name = $name = u2wi($message->firstname);
         } elseif (!empty($message->companyname)) {
             $name = $name = u2wi($message->companyname);
         } else {
             $name = 'unknown';
         }
         $name = preg_replace('/[^a-z0-9 _-]/i', '', $name);
         $entry = $name . '.vcf';
         $i = 0;
         while (file_exists($this->_path . '/' . $entry)) {
             $i++;
             $entry = $name . $i . '.vcf';
         }
         file_put_contents($this->_path . '/' . $entry, $data);
         ksort($this->_items);
         end($this->_items);
         if (key($this->_items) + 1 == 1) {
             $id = sprintf("1%09d", key($this->_items) + 1);
         } else {
             $id = key($this->_items) + 1;
         }
         $this->_items[$id] = $entry;
         file_put_contents(STATE_DIR . '/' . strtolower($this->_devid) . '/vcard_items_' . $this->_user, serialize($this->_items));
     } else {
         file_put_contents($this->_path . '/' . $this->_items[$id], $data);
     }
     return $this->StatMessage($folderid, $id);
 }