Esempio n. 1
0
<?php

/**
 * Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$id = isset($_GET['id']) ? $_GET['id'] : null;
if (is_null($id)) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('No ID provided'))));
    exit;
}
$vcard = OC_Contacts_App::getContactVCard($id);
foreach ($vcard->children as $property) {
    if ($property->name == 'CATEGORIES') {
        $checksum = md5($property->serialize());
        OCP\JSON::success(array('data' => array('value' => $property->value, 'checksum' => $checksum)));
        exit;
    }
}
OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error setting checksum.'))));
OCP\JSON::checkAppEnabled('contacts');
function bailOut($msg)
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/currentphoto.php: ' . $msg, OCP\Util::ERROR);
    exit;
}
function debug($msg)
{
    OCP\Util::writeLog('contacts', 'ajax/currentphoto.php: ' . $msg, OCP\Util::DEBUG);
}
if (!isset($_GET['id'])) {
    bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
}
$tmpfname = tempnam(get_temp_dir(), "occOrig");
$contact = OC_Contacts_App::getContactVCard($_GET['id']);
$image = new OC_Image();
if (!$image) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
// invalid vcard
if (is_null($contact)) {
    bailOut(OC_Contacts_App::$l10n->t('Error reading contact photo.'));
} else {
    if (!$image->loadFromBase64($contact->getAsString('PHOTO'))) {
        $image->loadFromBase64($contact->getAsString('LOGO'));
    }
    if ($image->valid()) {
        if ($image->save($tmpfname)) {
            OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpfname)));
            exit;
Esempio n. 3
0
function getStandardImage()
{
    //OCP\Response::setExpiresHeader('P10D');
    OCP\Response::enableCaching();
    OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person_large.png'));
}
$id = isset($_GET['id']) ? $_GET['id'] : null;
$caching = isset($_GET['refresh']) ? 0 : null;
if (is_null($id)) {
    getStandardImage();
}
if (!extension_loaded('gd') || !function_exists('gd_info')) {
    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 {
<?php

foreach ($_['contacts'] as $contact) {
    $display = trim($contact['fullname']);
    if (!$display) {
        $vcard = OC_Contacts_App::getContactVCard($contact['id']);
        if (!is_null($vcard)) {
            $struct = OC_Contacts_VCard::structureContact($vcard);
            $display = isset($struct['EMAIL'][0]) ? $struct['EMAIL'][0]['value'] : '[UNKNOWN]';
        }
    }
    ?>
	<li role="button" book-id="<?php 
    echo $contact['addressbookid'];
    ?>
" data-id="<?php 
    echo $contact['id'];
    ?>
"><a href="index.php?id=<?php 
    echo $contact['id'];
    ?>
"><?php 
    echo htmlspecialchars($display);
    ?>
</a></li>
<?php 
}