Exemple #1
0
                    }
                    $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.'));
                }
                OCA\Contacts\App::cacheThumbnail($id, $image);
                OCP\JSON::success(array('data' => array('id' => $id, 'width' => $image->width(), 'height' => $image->height(), 'lastmodified' => OCA\Contacts\App::lastModified($vcard)->format('U'))));
            } else {
                bailOut(OCA\Contacts\App::$l10n->t('Error resizing image'));
            }
        } else {
            bailOut(OCA\Contacts\App::$l10n->t('Error cropping image'));
        }
    } else {
        bailOut(OCA\Contacts\App::$l10n->t('Error creating temporary image'));
    }
} else {
    bailOut(OCA\Contacts\App::$l10n->t('Error finding image: ') . $tmpkey);