Ejemplo n.º 1
0
                    $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);
}
OC_Cache::remove($tmpkey);
Ejemplo n.º 2
0
OCP\App::checkAppEnabled('contacts');
session_write_close();
//OCP\Util::writeLog('contacts', OCP\Util::getRequestUri(), OCP\Util::DEBUG);
function getStandardImage()
{
    OCP\Response::enableCaching();
    OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person.png'));
    exit;
}
if (!extension_loaded('gd') || !function_exists('gd_info')) {
    OCP\Util::writeLog('contacts', 'thumbnail.php. GD module not installed', OCP\Util::DEBUG);
    getStandardImage();
}
$id = $_GET['id'];
$caching = null;
$image = OCA\Contacts\App::cacheThumbnail($id);
if ($image !== false) {
    try {
        $modified = OCA\Contacts\App::lastModified($id);
    } catch (Exception $e) {
        getStandardImage();
    }
    // Force refresh if modified within the last minute.
    if (!is_null($modified)) {
        $caching = time() - $modified->format('U') > 60 ? null : 0;
        OCP\Response::setLastModifiedHeader($modified);
    }
    OCP\Response::enableCaching($caching);
    header('Content-Type: image/png');
    echo $image;
} else {