/** * Parse contact details into the Contact object * @param array $contact * @return Sabre\VObject\Component */ public static function toVcard($contact) { $vcard = new \Sabre\VObject\Component('VCARD'); $vcard->setUID(); $vcard = self::_addPropertyStrings($contact, $vcard); if (isset($contact[self::CONTACT_PHONE])) { foreach ($contact[self::CONTACT_PHONE] as $phone) { if (!isset($phone['value'])) { continue; } $vcard->addProperty(self::CONTACT_PHONE, $phone['value']); $line = count($vcard->children) - 1; foreach ($phone['type'] as $type) { $vcard->children[$line]->parameters[] = new \Sabre\VObject\Parameter('TYPE', $type); } } } if (isset($contact[self::CONTACT_CATEGORIES])) { $categories = array(); foreach ($contact[self::CONTACT_CATEGORIES] as $categoryId) { $categoryData = Request::getGroupDetails($categoryId); preg_match('/<title>(.*)<\\/title>/i', $categoryData, $matches); if (@$matches[1]) { $categories[] = $matches[1]; } } if (count($categories)) { $vcard->setString(self::CONTACT_CATEGORIES, implode(',', $categories)); } } if (isset($contact[self::CONTACT_ADDRESS])) { foreach ($contact[self::CONTACT_ADDRESS] as $address) { $vcard->addProperty(self::CONTACT_ADDRESS, $address); $line = count($vcard->children) - 1; $vcard->children[$line]->parameters[] = new \Sabre\VObject\Parameter('TYPE', $address['type']); } } if (isset($contact[self::CONTACT_EMAIL])) { foreach ($contact[self::CONTACT_EMAIL] as $email) { $vcard->addProperty(self::CONTACT_EMAIL, $email['value']); $line = count($vcard->children) - 1; $vcard->children[$line]->parameters[] = new \Sabre\VObject\Parameter('TYPE', $email['type']); } } if (isset($contact[self::CONTACT_PHOTO]) && !empty($contact[self::CONTACT_PHOTO])) { $data = Request::getContactImage($contact[self::CONTACT_PHOTO]); $img = new \OC_Image(); if ($img->loadFromData($data)) { $vcard->addProperty(self::CONTACT_PHOTO, $img->__toString(), array('ENCODING' => 'b', 'TYPE' => $img->mimeType())); } else { App::log('Unable to parse the image provided by Google. ', \OCP\Util::WARN); } } return $vcard; }