Ejemplo n.º 1
0
    }
    return $a['fullname'] < $b['fullname'] ? -1 : 1;
}
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$aid = isset($_GET['aid']) ? $_GET['aid'] : null;
$active_addressbooks = array();
if (is_null($aid)) {
    // Called initially to get the active addressbooks.
    $active_addressbooks = OCA\Contacts\Addressbook::active(OCP\USER::getUser());
} else {
    // called each time more contacts has to be shown.
    $active_addressbooks = array(OCA\Contacts\Addressbook::find($aid));
}
$lastModified = OCA\Contacts\App::lastModified();
if (!is_null($lastModified)) {
    OCP\Response::enableCaching();
    OCP\Response::setLastModifiedHeader($lastModified);
    OCP\Response::setETagHeader(md5($lastModified->format('U')));
}
session_write_close();
// create the addressbook associate array
$contacts_addressbook = array();
$ids = array();
foreach ($active_addressbooks as $addressbook) {
    $ids[] = $addressbook['id'];
    /*if(!isset($contacts_addressbook[$addressbook['id']])) {
    		$contacts_addressbook[$addressbook['id']]
    				= array('contacts' => array('type' => 'book',));
    		$contacts_addressbook[$addressbook['id']]['displayname']
Ejemplo n.º 2
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.º 3
0
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;
        }
        OCP\Response::enableCaching($caching);
        if (!is_null($modified)) {
            OCP\Response::setLastModifiedHeader($modified);
        }
        if ($etag) {
            OCP\Response::setETagHeader($etag);
        }
        if ($image->width() > $max_size || $image->height() > $max_size) {
            $image->resize($max_size);
        }
    }
Ejemplo n.º 4
0
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once __DIR__ . '/../loghandler.php';
$aid = isset($_POST['aid']) ? $_POST['aid'] : null;
if (!$aid) {
    $addressbooks = OCA\Contacts\Addressbook::all(OCP\User::getUser(), true, false);
    if (count($addressbooks) === 0) {
        bailOut(OCA\Contacts\App::$l10n->t('You have no addressbooks.'));
    } else {
        $aid = $addressbooks[0]['id'];
    }
}
$isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false;
$vcard = Sabre\VObject\Component::create('VCARD');
$uid = substr(md5(rand() . time()), 0, 10);
$vcard->add('UID', $uid);
$id = null;
try {
    $id = OCA\Contacts\VCard::add($aid, $vcard, null, $isnew);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
if (!$id) {
    bailOut('There was an error adding the contact.');
}
$lastmodified = OCA\Contacts\App::lastModified($vcard);
if (!$lastmodified) {
    $lastmodified = new DateTime();
}
OCP\JSON::success(array('data' => array('id' => $id, 'aid' => $aid, 'details' => OCA\Contacts\VCard::structureContact($vcard), 'lastmodified' => $lastmodified->format('U'))));
Ejemplo n.º 5
0
$name = isset($_POST['name']) ? $_POST['name'] : null;
$checksum = isset($_POST['checksum']) ? $_POST['checksum'] : null;
$l10n = OCA\Contacts\App::$l10n;
$multi_properties = array('EMAIL', 'TEL', 'IMPP', 'ADR', 'URL');
if (!$id) {
    bailOut(OCA\Contacts\App::$l10n->t('id is not set.'));
}
if (!$name) {
    bailOut(OCA\Contacts\App::$l10n->t('element name is not set.'));
}
if (!$checksum && in_array($name, $multi_properties)) {
    bailOut(OCA\Contacts\App::$l10n->t('checksum is not set.'));
}
$vcard = OCA\Contacts\App::getContactVCard($id);
if (!is_null($checksum)) {
    $line = OCA\Contacts\App::getPropertyLineByChecksum($vcard, $checksum);
    if (is_null($line)) {
        bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.'));
        exit;
    }
    unset($vcard->children[$line]);
} else {
    unset($vcard->{$name});
}
try {
    OCA\Contacts\VCard::edit($id, $vcard);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
OCP\JSON::success(array('data' => array('id' => $id, 'lastmodified' => OCA\Contacts\App::lastModified($vcard)->format('U'))));
Ejemplo n.º 6
0
//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 {
    getStandardImage();
}