OCP\Util::writeLog('contacts', 'photo.php. GD module not installed', OCP\Util::DEBUG); getStandardImage(); } $contact = OC_Contacts_App::getContactVCard($id); $image = new OC_Image(); if (!$image) { getStandardImage(); } // invalid vcard if (is_null($contact)) { OCP\Util::writeLog('contacts', 'photo.php. The VCard for ID ' . $id . ' is not RFC compatible', OCP\Util::ERROR); } else { OCP\Response::enableCaching($caching); OC_Contacts_App::setLastModifiedHeader($contact); // Photo :-) if ($image->loadFromBase64($contact->getAsString('PHOTO'))) { // OK OCP\Response::setETagHeader(md5($contact->getAsString('PHOTO'))); } else { // Logo :-/ if ($image->loadFromBase64($contact->getAsString('LOGO'))) { // OK OCP\Response::setETagHeader(md5($contact->getAsString('LOGO'))); } } if ($image->valid()) { $max_size = 200; if ($image->width() > $max_size || $image->height() > $max_size) { $image->resize($max_size); } }
*/ // Firefox and Konqueror tries to download application/json for me. --Arthur OCP\JSON::setContentTypeHeader('text/plain'); OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); require_once 'loghandler.php'; if (!isset($_GET['id'])) { bailOut(OCA\Contacts\App::$l10n->t('No contact ID was submitted.')); } $contact = OCA\Contacts\App::getContactVCard($_GET['id']); // invalid vcard if (is_null($contact)) { bailOut(OCA\Contacts\App::$l10n->t('Error reading contact photo.')); } else { $image = new OC_Image(); if (!isset($contact->PHOTO) || !$image->loadFromBase64((string) $contact->PHOTO)) { if (isset($contact->LOGO)) { $image->loadFromBase64((string) $contact->LOGO); } } if ($image->valid()) { $tmpkey = 'contact-photo-' . $contact->UID; if (OC_Cache::set($tmpkey, $image->data(), 600)) { OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpkey))); exit; } else { bailOut(OCA\Contacts\App::$l10n->t('Error saving temporary file.')); } } else { bailOut(OCA\Contacts\App::$l10n->t('The loading photo is not valid.')); }
public static function cacheThumbnail($id, \OC_Image $image = null) { if (\OC_Cache::hasKey(self::THUMBNAIL_PREFIX . $id)) { return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id); } if (is_null($image)) { $vcard = self::getContactVCard($id); // invalid vcard if (is_null($vcard)) { \OCP\Util::writeLog('contacts', __METHOD__ . ' The VCard for ID ' . $id . ' is not RFC compatible', \OCP\Util::ERROR); return false; } $image = new \OC_Image(); if (!isset($vcard->PHOTO)) { return false; } if (!$image->loadFromBase64((string) $vcard->PHOTO)) { return false; } } if (!$image->centerCrop()) { \OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t crop thumbnail for ID ' . $id, \OCP\Util::ERROR); return false; } if (!$image->resize(self::THUMBNAIL_SIZE)) { \OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t resize thumbnail for ID ' . $id, \OCP\Util::ERROR); return false; } // Cache for around a month \OC_Cache::set(self::THUMBNAIL_PREFIX . $id, $image->data(), 3000000); \OCP\Util::writeLog('contacts', 'Caching ' . $id, \OCP\Util::DEBUG); return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id); }
$contact = OC_Contacts_App::getContactVCard($id); // invalid vcard if (is_null($contact)) { OCP\Util::writeLog('contacts', 'thumbnail.php. The VCard for ID ' . $id . ' is not RFC compatible', OCP\Util::ERROR); getStandardImage(); exit; } OCP\Response::enableCaching($caching); OC_Contacts_App::setLastModifiedHeader($contact); $thumbnail_size = 23; // Find the photo from VCard. $image = new OC_Image(); $photo = $contact->getAsString('PHOTO'); if ($photo) { OCP\Response::setETagHeader(md5($photo)); if ($image->loadFromBase64($photo)) { if ($image->centerCrop()) { if ($image->resize($thumbnail_size)) { if ($image->show()) { // done exit; } else { OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t display thumbnail for ID ' . $id, OCP\Util::ERROR); } } else { OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t resize thumbnail for ID ' . $id, OCP\Util::ERROR); } } else { OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t crop thumbnail for ID ' . $id, OCP\Util::ERROR); } } else {
} if (!extension_loaded('gd') || !function_exists('gd_info')) { OCP\Util::writeLog('contacts', 'photo.php. GD module not installed', OCP\Util::DEBUG); getStandardImage(); } $contact = OCA\Contacts\App::getContactVCard($id); $image = new OC_Image(); if (!$image || !$contact) { getStandardImage(); } // invalid vcard if (is_null($contact)) { OCP\Util::writeLog('contacts', 'photo.php. The VCard for ID ' . $id . ' is not RFC compatible', OCP\Util::ERROR); } else { // Photo :-) if (isset($contact->PHOTO) && $image->loadFromBase64((string) $contact->PHOTO)) { // OK $etag = md5($contact->PHOTO); } else { // Logo :-/ if (isset($contact->LOGO) && $image->loadFromBase64((string) $contact->LOGO)) { // OK $etag = md5($contact->LOGO); } } if ($image->valid()) { $modified = OCA\Contacts\App::lastModified($contact); // Force refresh if modified within the last minute. if (!is_null($modified)) { $caching = time() - $modified->format('U') > 60 ? null : 0; }