/** * @brief modifies a vcard property array with the image */ public function updateImageProperty(&$property, $entry, $version = null) { $image = new \OC_Image(); $image->loadFromData($entry); if (strcmp($version, '4.0') == 0) { $type = $image->mimeType(); } else { $arrayType = explode('/', $image->mimeType()); $type = strtoupper(array_pop($arrayType)); } $property->add('ENCODING', 'b'); $property->add('TYPE', $type); $property->setValue($image->__toString()); }
OCP\Util::writeLog('contacts', 'savecrop.php, x: ' . $x1 . ' y: ' . $y1 . ' w: ' . $w . ' h: ' . $h, OCP\Util::DEBUG); if ($image->crop($x1, $y1, $w, $h)) { if ($image->width() <= 200 && $image->height() <= 200 || $image->resize(200)) { $vcard = OCA\Contacts\App::getContactVCard($id); if (!$vcard) { OC_Cache::remove($tmpkey); bailOut(OCA\Contacts\App::$l10n->t('Error getting contact object.')); } if ($vcard->__isset('PHOTO')) { OCP\Util::writeLog('contacts', 'savecrop.php: PHOTO property exists.', OCP\Util::DEBUG); $property = $vcard->__get('PHOTO'); if (!$property) { OC_Cache::remove($tmpkey); bailOut(OCA\Contacts\App::$l10n->t('Error getting PHOTO property.')); } $property->setValue($image->__toString()); $property->parameters[] = new Sabre\VObject\Parameter('ENCODING', 'b'); $property->parameters[] = new Sabre\VObject\Parameter('TYPE', $image->mimeType()); $vcard->__set('PHOTO', $property); } else { OCP\Util::writeLog('contacts', 'savecrop.php: files: Adding PHOTO property.', OCP\Util::DEBUG); // For vCard 3.0 the type must be e.g. JPEG or PNG // For version 4.0 the full mimetype should be used. // https://tools.ietf.org/html/rfc2426#section-3.1.4 $type = $vcard->VERSION == '4.0' ? $image->mimeType() : strtoupper(array_pop(explode('/', $image->mimeType()))); $vcard->add('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $type)); } $now = new DateTime(); $vcard->{'REV'} = $now->format(DateTime::W3C); if (!OCA\Contacts\VCard::edit($id, $vcard)) { bailOut(OCA\Contacts\App::$l10n->t('Error saving contact.'));
/** * @brief modifies a vcard property array with the image */ public function updateVCardImageProperty(&$v_property, $ldap_entry, $version) { for ($i = 0; $i < count($v_property); $i++) { $image = new \OC_Image(); $image->loadFromData($ldap_entry); if (strcmp($version, '4.0') == 0) { $type = $image->mimeType(); } else { $arrayType = explode('/', $image->mimeType()); $type = strtoupper(array_pop($arrayType)); } $v_property[$i]->add('ENCODING', 'b'); $v_property[$i]->add('TYPE', $type); $v_property[$i]->setValue($image->__toString()); } }
// create a new file because of caching issues. if ($image->save($tmpfname)) { unlink($tmp_path); $card = OC_Contacts_App::getContactVCard($id); if (!$card) { unlink($tmpfname); bailOut('Error getting contact object.'); } if ($card->__isset('PHOTO')) { OCP\Util::writeLog('contacts', 'savecrop.php: PHOTO property exists.', OCP\Util::DEBUG); $property = $card->__get('PHOTO'); if (!$property) { unlink($tmpfname); bailOut('Error getting PHOTO property.'); } $property->setValue($image->__toString()); $property->parameters[] = new Sabre_VObject_Parameter('ENCODING', 'b'); $property->parameters[] = new Sabre_VObject_Parameter('TYPE', $image->mimeType()); $card->__set('PHOTO', $property); } else { OCP\Util::writeLog('contacts', 'savecrop.php: files: Adding PHOTO property.', OCP\Util::DEBUG); $card->addProperty('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType())); } $now = new DateTime(); $card->setString('REV', $now->format(DateTime::W3C)); if (!OC_Contacts_VCard::edit($id, $card)) { bailOut('Error saving contact.'); } unlink($tmpfname); //$result=array( "status" => "success", 'mime'=>$image->mimeType(), 'tmp'=>$tmp_path); $tmpl = new OCP\Template("contacts", "part.contactphoto");
/** * 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; }