From d91a4fcaf3ffc0783f7aef6767d7b15773808eb5 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 2 Jan 2012 20:24:05 +0100 Subject: [PATCH 1/5] Changed SQL queries for looking up contacts to only query once and sort at the same time. --- apps/contacts/ajax/addcard.php | 1 - apps/contacts/ajax/contacts.php | 15 --------------- apps/contacts/index.php | 17 ----------------- 3 files changed, 33 deletions(-) diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php index 54c455e515..9d782246a0 100644 --- a/apps/contacts/ajax/addcard.php +++ b/apps/contacts/ajax/addcard.php @@ -61,6 +61,5 @@ foreach( $add as $propname){ $vcard->addProperty($propname, $value, $prop_parameters); } $id = OC_Contacts_VCard::add($aid,$vcard->serialize()); -OC_Log::write('contacts','ajax/addcard.php - adding id: '.$id,OC_Log::DEBUG); OC_Contacts_App::renderDetails($id, $vcard); diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index 54ad3e4c10..cf86764105 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -12,21 +12,6 @@ OC_JSON::checkAppEnabled('contacts'); $ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser()); $contacts = OC_Contacts_VCard::all($ids); -//OC_Log::write('contacts','contacts.php: '.count($contacts).' contacts.',OC_Log::DEBUG); -/* -$addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser()); -$contacts = array(); -foreach( $addressbooks as $addressbook ){ - $addressbookcontacts = OC_Contacts_VCard::all($addressbook['id']); - foreach( $addressbookcontacts as $contact ){ - if(is_null($contact['fullname'])){ - continue; - } - $contacts[] = $contact; - } -} -usort($contacts,'contacts_namesort'); -*/ $tmpl = new OC_TEMPLATE("contacts", "part.contacts"); $tmpl->assign('contacts', $contacts); $page = $tmpl->fetchPage(); diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 5ab6f293ab..b392b195a9 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -42,23 +42,6 @@ OC_App::setActiveNavigationEntry( 'contacts_index' ); // Load a specific user? $id = isset( $_GET['id'] ) ? $_GET['id'] : null; -/* -// sort addressbooks (use contactsort) -usort($addressbooks,'contacts_namesort'); - -$contacts = array(); -foreach( $addressbooks as $addressbook ){ - $addressbookcontacts = OC_Contacts_VCard::all($addressbook['id']); - foreach( $addressbookcontacts as $contact ){ - if(is_null($contact['fullname'])){ - continue; - } - $contacts[] = $contact; - } -} - -usort($contacts,'contacts_namesort'); -*/ $details = array(); // FIXME: This cannot work..? From 85ab3b3924b0e66f3cb3f4e84222b08dd3d882bc Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 2 Jan 2012 22:34:52 +0100 Subject: [PATCH 2/5] Modified thumbnail.php to use OC_Image. Cut out 50 loc ;-) --- apps/contacts/thumbnail.php | 104 +++++++++++------------------------- 1 file changed, 31 insertions(+), 73 deletions(-) diff --git a/apps/contacts/thumbnail.php b/apps/contacts/thumbnail.php index bf0a6e96a5..622718d65c 100644 --- a/apps/contacts/thumbnail.php +++ b/apps/contacts/thumbnail.php @@ -2,8 +2,8 @@ /** * ownCloud - Addressbook * - * @author Jakob Sack - * @copyright 2011 Jakob Sack mail@jakobsack.de + * @author Thomas Tanghus + * @copyright 2011-2012 Thomas Tanghus * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -26,7 +26,7 @@ OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('contacts'); if(!function_exists('imagecreatefromjpeg')) { - OC_Log::write('contacts','GD module not installed',OC_Log::ERROR); + OC_Log::write('contacts','thumbnail.php. GD module not installed',OC_Log::DEBUG); header('Content-Type: image/png'); // TODO: Check if it works to read the file and echo the content. return 'img/person.png'; @@ -46,13 +46,16 @@ $l10n = new OC_L10N('contacts'); $card = OC_Contacts_VCard::find( $id ); if( $card === false ){ - echo $l10n->t('Contact could not be found.'); + OC_Log::write('contacts','thumbnail.php. Contact could not be found.',OC_Log::ERROR); + //echo $l10n->t('Contact could not be found.'); exit(); } +// FIXME: Is this check necessary? It just takes up CPU time. $addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] ); if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - echo $l10n->t('This is not your contact.'); // This is a weird error, why would it come up? (Better feedback for users?) + OC_Log::write('contacts','thumbnail.php. Wrong contact/addressbook - WTF?',OC_Log::ERROR); + //echo $l10n->t('This is not your contact.'); // This is a weird error, why would it come up? (Better feedback for users?) exit(); } @@ -60,17 +63,14 @@ $content = OC_VObject::parse($card['carddata']); // invalid vcard if( is_null($content)){ - echo $l10n->t('This card is not RFC compatible.'); + OC_Log::write('contacts','thumbnail.php. The VCard for ID '.$id.' is not RFC compatible',OC_Log::ERROR); + getStandardImage(); exit(); } -// define the width and height for the thumbnail -// note that theese dimmensions are considered the maximum dimmension and are not fixed, -// because we have to keep the image ratio intact or it will be deformed -$thumbnail_width = 23; -$thumbnail_height = 23; +$thumbnail_size = 23; -// Photo :-) +// Finf the photo from VCard. foreach($content->children as $child){ if($child->name == 'PHOTO'){ foreach($child->parameters as $parameter){ @@ -78,73 +78,31 @@ foreach($content->children as $child){ $mime = $parameter->value; } } - $data = base64_decode($child->value); - $src_img = imagecreatefromstring($data); - if ($src_img !== false) { - //gets the dimmensions of the image - $width_orig=imageSX($src_img); - $height_orig=imageSY($src_img); - $ratio_orig = $width_orig/$height_orig; - - if ($thumbnail_width/$thumbnail_height > $ratio_orig) { - $new_height = $thumbnail_width/$ratio_orig; - $new_width = $thumbnail_width; - } else { - $new_width = $thumbnail_height*$ratio_orig; - $new_height = $thumbnail_height; - } - - $x_mid = $new_width/2; //horizontal middle - $y_mid = $new_height/2; //vertical middle - - $process = imagecreatetruecolor(round($new_width), round($new_height)); - if ($process == false) { + $image = new OC_Image(); + if($image->loadFromBase64($child->value)) { + if($image->centerCrop()) { + if($image->resize($thumbnail_size)) { + if(!$image()) { + OC_Log::write('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OC_Log::ERROR); + getStandardImage(); + exit(); + } + } else { + OC_Log::write('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OC_Log::ERROR); + getStandardImage(); + exit(); + } + }else{ + OC_Log::write('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OC_Log::ERROR); getStandardImage(); - //echo 'Error creating process image: '.$new_width.'x'.$new_height; - OC_Log::write('contacts','Error creating process image for '.$id.' '.$new_width.'x'.$new_height,OC_Log::ERROR); - imagedestroy($process); - imagedestroy($src_img); exit(); } - - imagecopyresampled($process, $src_img, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); - if ($process == false) { - getStandardImage(); - //echo 'Error resampling process image: '.$new_width.'x'.$new_height; - OC_Log::write('contacts','Error resampling process image for '.$id.' '.$new_width.'x'.$new_height,OC_Log::ERROR); - imagedestroy($process); - imagedestroy($src_img); - exit(); - } - $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height); - if ($process == false) { - getStandardImage(); - //echo 'Error creating thumb image: '.$thumbnail_width.'x'.$thumbnail_height; - OC_Log::write('contacts','Error creating thumb image for '.$id.' '.$thumbnail_width.'x'.$thumbnail_height,OC_Log::ERROR); - imagedestroy($process); - imagedestroy($src_img); - exit(); - } - imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height); - if ($thumb !== false) { - header('Content-Type: image/png'); - imagepng($thumb); - } else { - getStandardImage(); - OC_Log::write('contacts','Error resampling thumb image for '.$id.' '.$thumbnail_width.'x'.$thumbnail_height,OC_Log::ERROR); - //echo 'An error occurred resampling thumb.'; - } - imagedestroy($thumb); - imagedestroy($process); - imagedestroy($src_img); - } - else { + } else { + OC_Log::write('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OC_Log::ERROR); getStandardImage(); + exit(); } exit(); } } getStandardImage(); - -// Not found :-( -//echo $l10n->t('This card does not contain a photo.'); From 47548fb8c612b5a61b00b03b525fd168fe940451 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 2 Jan 2012 23:14:58 +0100 Subject: [PATCH 3/5] Fixed showing first contact if non is selected. --- apps/contacts/index.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/contacts/index.php b/apps/contacts/index.php index b392b195a9..b7c88236a8 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -45,11 +45,17 @@ $id = isset( $_GET['id'] ) ? $_GET['id'] : null; $details = array(); // FIXME: This cannot work..? -if( !is_null($id)/* || count($contacts)*/){ - if(is_null($id)) $id = $contacts[0]['id']; - $vcard = OC_Contacts_App::getContactVCard($id); - $details = OC_Contacts_VCard::structureContact($vcard); +if(is_null($id) && count($contacts) > 0) { + $id = $contacts[0]['id']; } +$vcard = OC_Contacts_App::getContactVCard($id); +$details = OC_Contacts_VCard::structureContact($vcard); + +// if( !is_null($id)/* || count($contacts)*/){ +// if(is_null($id)) $id = $contacts[0]['id']; +// $vcard = OC_Contacts_App::getContactVCard($id); +// $details = OC_Contacts_VCard::structureContact($vcard); +// } // Include Style and Script OC_Util::addScript('contacts','interface'); From 604ca61d78881e3a1a0a41e4b50ef4cb7c1eeaf0 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 4 Jan 2012 22:36:34 +0100 Subject: [PATCH 4/5] Some cleanup, better error messages and such. --- apps/contacts/index.php | 7 ++++--- apps/contacts/js/interface.js | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/contacts/index.php b/apps/contacts/index.php index b7c88236a8..0b705e71b5 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -48,9 +48,10 @@ $details = array(); if(is_null($id) && count($contacts) > 0) { $id = $contacts[0]['id']; } -$vcard = OC_Contacts_App::getContactVCard($id); -$details = OC_Contacts_VCard::structureContact($vcard); - +if(!is_null($id)) { + $vcard = OC_Contacts_App::getContactVCard($id); + $details = OC_Contacts_VCard::structureContact($vcard); +} // if( !is_null($id)/* || count($contacts)*/){ // if(is_null($id)) $id = $contacts[0]['id']; // $vcard = OC_Contacts_App::getContactVCard($id); diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js index 35639ef6cc..b9f75bdf71 100644 --- a/apps/contacts/js/interface.js +++ b/apps/contacts/js/interface.js @@ -1,3 +1,29 @@ +/** + * ownCloud - Addressbook + * + * @author Jakob Sack + * @copyright 2011 Jakob Sack mail@jakobsack.de + * @copyright 2011-2012 Thomas Tanghus + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + * TODO: + * If you add a contact, its thumbnail doesnt show in the list. But when you add another one it shows up, but not for the second contact added. + * Place a new contact in correct alphabetic order + */ + + Contacts={ UI:{ showCardDAVUrl:function(username, bookname){ From 978a08ab1c5e425210e8128e6d8efa432d593571 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 9 Jan 2012 01:17:04 +0100 Subject: [PATCH 5/5] Fixed Phone types not being saved correctly when adding them. --- apps/contacts/ajax/addproperty.php | 20 ++++++++++++++++++- apps/contacts/templates/part.property.php | 5 ++--- .../templates/part.setpropertyform.php | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php index 98877805b4..0122cf019c 100644 --- a/apps/contacts/ajax/addproperty.php +++ b/apps/contacts/ajax/addproperty.php @@ -34,13 +34,31 @@ $name = $_POST['name']; $value = $_POST['value']; $parameters = isset($_POST['parameters'])?$_POST['parameters']:array(); -$property = $vcard->addProperty($name, $value, $parameters); +$property = $vcard->addProperty($name, $value); //, $parameters); $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) && strtoupper($key) == 'TYPE') { + // FIXME: 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)){ + $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$e); + } + } + } +} + OC_Contacts_VCard::edit($id,$vcard->serialize()); +$adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); + $tmpl = new OC_Template('contacts','part.property'); +$tmpl->assign('adr_types',$adr_types); +$tmpl->assign('phone_types',$phone_types); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($property,$line)); $page = $tmpl->fetchPage(); diff --git a/apps/contacts/templates/part.property.php b/apps/contacts/templates/part.property.php index d930a9ca99..e401039750 100644 --- a/apps/contacts/templates/part.property.php +++ b/apps/contacts/templates/part.property.php @@ -25,15 +25,14 @@ t(ucwords(strtolower($type))); } - endforeach; + } $label = join(' ', $types); ?> () diff --git a/apps/contacts/templates/part.setpropertyform.php b/apps/contacts/templates/part.setpropertyform.php index 8635d7db1c..3e0b8d49b5 100644 --- a/apps/contacts/templates/part.setpropertyform.php +++ b/apps/contacts/templates/part.setpropertyform.php @@ -45,7 +45,7 @@