Esempio n. 1
0
                    if (!$property) {
                        OC_Cache::remove($tmpkey);
                        bailOut(OC_Contacts_App::$l10n->t('Error getting PHOTO property.'));
                    }
                    $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);
                    $vcard->addProperty('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType()));
                }
                $now = new DateTime();
                $vcard->setString('REV', $now->format(DateTime::W3C));
                if (!OC_Contacts_VCard::edit($id, $vcard)) {
                    bailOut(OC_Contacts_App::$l10n->t('Error saving contact.'));
                }
                OCP\JSON::success(array('data' => array('id' => $id, 'width' => $image->width(), 'height' => $image->height(), 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'))));
            } else {
                bailOut(OC_Contacts_App::$l10n->t('Error resizing image'));
            }
        } else {
            bailOut(OC_Contacts_App::$l10n->t('Error cropping image'));
        }
    } else {
        bailOut(OC_Contacts_App::$l10n->t('Error creating temporary image'));
    }
} else {
    bailOut(OC_Contacts_App::$l10n->t('Error finding image: ') . $tmpkey);
}
OC_Cache::remove($tmpkey);
Esempio n. 2
0
                    debug('Adding parameter: ' . $key);
                    if (is_array($parameter)) {
                        foreach ($parameter as $val) {
                            if (trim($val)) {
                                debug('Adding parameter: ' . $key . '=>' . $val);
                                $vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($val))));
                            }
                        }
                    } else {
                        if (trim($parameter)) {
                            $vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($parameter))));
                        }
                    }
                }
            }
            break;
        default:
            $vcard->setString($name, $value);
            break;
    }
    // Do checksum and be happy
    $checksum = md5($vcard->children[$line]->serialize());
}
//debug('New checksum: '.$checksum);
try {
    OC_Contacts_VCard::edit($id, $vcard);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
OCP\JSON::success(array('data' => array('line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'], 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'))));
Esempio n. 3
0
        //, $parameters);
        break;
}
$line = count($vcard->children) - 1;
// Apparently Sabre_VObject_Parameter doesn't do well with
// multiple values or I don't know how to do it. Tanghus.
foreach ($parameters as $key => $element) {
    if (is_array($element)) {
        // NOTE: Maybe this doesn't only apply for TYPE?
        // And it probably shouldn't be done here anyways :-/
        foreach ($element as $e) {
            if ($e != '' && !is_null($e)) {
                if (trim($e)) {
                    $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $e);
                }
            }
        }
    } else {
        if (trim($element)) {
            $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $element);
        }
    }
}
$checksum = md5($vcard->children[$line]->serialize());
try {
    OC_Contacts_VCard::edit($id, $vcard);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
OCP\JSON::success(array('data' => array('checksum' => $checksum, 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'))));
Esempio n. 4
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 ($image->loadFromBase64($contact->getAsString('PHOTO'))) {
        // OK
        $etag = md5($contact->getAsString('PHOTO'));
    } else {
        // Logo :-/
        if ($image->loadFromBase64($contact->getAsString('LOGO'))) {
            // OK
            $etag = md5($contact->getAsString('LOGO'));
        }
    }
    if ($image->valid()) {
        $modified = OC_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);
        }
        $max_size = 200;
        if ($image->width() > $max_size || $image->height() > $max_size) {
            $image->resize($max_size);
        }
Esempio n. 5
0
    bailOut(OC_Contacts_App::$l10n->t('Error parsing VCard for ID: "' . $id . '"'));
}
$details = OC_Contacts_VCard::structureContact($vcard);
// Make up for not supporting the 'N' field in earlier version.
if (!isset($details['N'])) {
    $details['N'] = array();
    $details['N'][0] = array($details['FN'][0]['value'], '', '', '', '');
}
// Don't wanna transfer the photo in a json string.
if (isset($details['PHOTO'])) {
    $details['PHOTO'] = true;
    //unset($details['PHOTO']);
} else {
    $details['PHOTO'] = false;
}
$lastmodified = OC_Contacts_App::lastModified($vcard);
if (!$lastmodified) {
    $lastmodified = new DateTime();
}
$permissions = OCP\Share::PERMISSION_CREATE | OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE;
$addressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($addressbook['userid'] != OCP\User::getUser()) {
    $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $card['addressbookid']);
    if ($sharedAddressbook) {
        $permissions = $sharedAddressbook['permissions'];
    }
}
$details['id'] = $id;
$details['displayname'] = $card['fullname'];
$details['addressbookid'] = $card['addressbookid'];
$details['lastmodified'] = $lastmodified->format('U');