1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-01 13:24:10 +01:00

Line length...

This commit is contained in:
Thomas Tanghus 2012-08-02 05:02:36 +02:00
parent 76d1507677
commit a8c0bfe1d7
4 changed files with 79 additions and 35 deletions

View File

@ -13,7 +13,7 @@ function cmp($a, $b)
}
return ($a['displayname'] < $b['displayname']) ? -1 : 1;
}
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
@ -37,34 +37,49 @@ $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'] = $addressbook['displayname'];
$contacts_addressbook[$addressbook['id']]
= array('contacts' => array('type' => 'book',));
$contacts_addressbook[$addressbook['id']]['displayname']
= $addressbook['displayname'];
}
}
}
$contacts_alphabet = array();
$contacts_alphabet = array();
// get next 50 for each addressbook.
foreach($ids as $id) {
if($id) {
$contacts_alphabet = array_merge($contacts_alphabet, OC_Contacts_VCard::all($id, $start, 50));
$contacts_alphabet = array_merge(
$contacts_alphabet,
OC_Contacts_VCard::all($id, $start, 50)
);
}
}
// Our new array for the contacts sorted by addressbook
if($contacts_alphabet) {
foreach($contacts_alphabet as $contact) {
if(!isset($contacts_addressbook[$contact['addressbookid']])) { // It should never execute.
$contacts_addressbook[$contact['addressbookid']] = array('contacts' => array('type' => 'book',));
// This should never execute.
if(!isset($contacts_addressbook[$contact['addressbookid']])) {
$contacts_addressbook[$contact['addressbookid']] = array(
'contacts' => array('type' => 'book',)
);
}
$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]';
$display = isset($struct['EMAIL'][0])
? $struct['EMAIL'][0]['value']
: '[UNKNOWN]';
}
}
$contacts_addressbook[$contact['addressbookid']]['contacts'][] = array('type' => 'contact', 'id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'displayname' => htmlspecialchars($display));
$contacts_addressbook[$contact['addressbookid']]['contacts'][] = array(
'type' => 'contact',
'id' => $contact['id'],
'addressbookid' => $contact['addressbookid'],
'displayname' => htmlspecialchars($display)
);
}
}
unset($contacts_alphabet);

View File

@ -54,34 +54,39 @@ if($data) {
$w = ($w != -1 ? $w : $image->width());
$h = ($h != -1 ? $h : $image->height());
OCP\Util::writeLog('contacts',
'savecrop.php, x: '.$x1.' y: '.$y1.' w: '.$w.' h: '.$h,
'savecrop.php, x: '.$x1.' y: '.$y1.' w: '.$w.' h: '.$h,
OCP\Util::DEBUG);
if($image->crop($x1, $y1, $w, $h)) {
if(($image->width() <= 200 && $image->height() <= 200) || $image->resize(200)) {
if(($image->width() <= 200 && $image->height() <= 200)
|| $image->resize(200)) {
$card = OC_Contacts_App::getContactVCard($id);
if(!$card) {
OC_Cache::remove($tmpkey);
bailOut(OC_Contacts_App::$l10n->t('Error getting contact object.'));
bailOut(OC_Contacts_App::$l10n
->t('Error getting contact object.'));
}
if($card->__isset('PHOTO')) {
OCP\Util::writeLog('contacts',
'savecrop.php: PHOTO property exists.',
'savecrop.php: PHOTO property exists.',
OCP\Util::DEBUG);
$property = $card->__get('PHOTO');
if(!$property) {
OC_Cache::remove($tmpkey);
bailOut(OC_Contacts_App::$l10n->t('Error getting PHOTO property.'));
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());
$property->parameters[]
= new Sabre_VObject_Parameter('ENCODING', 'b');
$property->parameters[]
= new Sabre_VObject_Parameter('TYPE', $image->mimeType());
$card->__set('PHOTO', $property);
} else {
OCP\Util::writeLog('contacts',
'savecrop.php: files: Adding PHOTO property.',
'savecrop.php: files: Adding PHOTO property.',
OCP\Util::DEBUG);
$card->addProperty('PHOTO',
$image->__toString(), array('ENCODING' => 'b',
$card->addProperty('PHOTO',
$image->__toString(), array('ENCODING' => 'b',
'TYPE' => $image->mimeType()));
}
$now = new DateTime;

View File

@ -41,9 +41,9 @@ if(!$checksum) {
}
if(is_array($value)) {
$value = array_map('strip_tags', $value);
// NOTE: Important, otherwise the compound value will be
// NOTE: Important, otherwise the compound value will be
// set in the order the fields appear in the form!
ksort($value);
ksort($value);
//if($name == 'CATEGORIES') {
// $value = OC_Contacts_VCard::escapeDelimiters($value, ',');
//} else {
@ -56,12 +56,16 @@ if(is_array($value)) {
$vcard = OC_Contacts_App::getContactVCard( $id );
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
if(is_null($line)) {
bailOut(OC_Contacts_App::$l10n->t('Information about vCard is incorrect. Please reload the page: ').$checksum);
bailOut(OC_Contacts_App::$l10n->t(
'Information about vCard is incorrect. Please reload the page: ').$checksum
);
}
$element = $vcard->children[$line]->name;
if($element != $name) {
bailOut(OC_Contacts_App::$l10n->t('Something went FUBAR. ').$name.' != '.$element);
bailOut(OC_Contacts_App::$l10n->t(
'Something went FUBAR. ').$name.' != '.$element
);
}
/* preprocessing value */
@ -91,11 +95,13 @@ if(!$value) {
/* setting value */
switch($element) {
case 'BDAY':
// I don't use setDateTime() because that formats it as YYYYMMDD instead of YYYY-MM-DD
// which is what the RFC recommends.
// I don't use setDateTime() because that formats it as YYYYMMDD instead
// of YYYY-MM-DD which is what the RFC recommends.
$vcard->children[$line]->setValue($value);
$vcard->children[$line]->parameters = array();
$vcard->children[$line]->add(new Sabre_VObject_Parameter('VALUE', 'DATE'));
$vcard->children[$line]->add(
new Sabre_VObject_Parameter('VALUE', 'DATE')
);
debug('Setting value:'.$name.' '.$vcard->children[$line]);
break;
case 'CATEGORIES':
@ -114,7 +120,10 @@ if(!$value) {
debug('Adding parameter: '.$key);
foreach($parameter as $val) {
debug('Adding parameter: '.$key.'=>'.$val);
$vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($val))));
$vcard->children[$line]->add(new Sabre_VObject_Parameter(
$key,
strtoupper(strip_tags($val)))
);
}
}
}
@ -134,4 +143,8 @@ if(!OC_Contacts_VCard::edit($id, $vcard)) {
exit();
}
OCP\JSON::success(array('data' => array( 'line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'] )));
OCP\JSON::success(array('data' => array(
'line' => $line,
'checksum' => $checksum,
'oldchecksum' => $_POST['checksum']))
);

View File

@ -40,7 +40,8 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
'uri' => $i['uri'],
'principaluri' => 'principals/'.$i['userid'],
'{DAV:}displayname' => $i['displayname'],
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => $i['description'],
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description'
=> $i['description'],
'{http://calendarserver.org/ns/}getctag' => $i['ctag'],
);
}
@ -69,7 +70,8 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
case '{DAV:}displayname' :
$name = $newvalue;
break;
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV
. '}addressbook-description' :
$description = $newvalue;
break;
default :
@ -104,16 +106,23 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
case '{DAV:}displayname' :
$displayname = $newvalue;
break;
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' :
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV
. '}addressbook-description' :
$description = $newvalue;
break;
default :
throw new Sabre_DAV_Exception_BadRequest('Unknown property: ' . $property);
throw new Sabre_DAV_Exception_BadRequest('Unknown property: '
. $property);
}
}
OC_Contacts_Addressbook::addFromDAVData($principaluri, $url, $name, $description);
OC_Contacts_Addressbook::addFromDAVData(
$principaluri,
$url,
$name,
$description
);
}
/**
@ -182,7 +191,9 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
* @return bool
*/
public function updateCard($addressbookid, $carduri, $carddata) {
return OC_Contacts_VCard::editFromDAVData($addressbookid, $carduri, $carddata);
return OC_Contacts_VCard::editFromDAVData(
$addressbookid, $carduri, $carddata
);
}
/**