Merge branch 'tanghus_contacts'

This commit is contained in:
Thomas Tanghus 2012-01-09 20:41:16 +01:00
commit 5817bd10ba
8 changed files with 88 additions and 113 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -42,31 +42,21 @@ 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..?
if( !is_null($id)/* || count($contacts)*/){
if(is_null($id)) $id = $contacts[0]['id'];
if(is_null($id) && count($contacts) > 0) {
$id = $contacts[0]['id'];
}
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);
// $details = OC_Contacts_VCard::structureContact($vcard);
// }
// Include Style and Script
OC_Util::addScript('contacts','interface');

View File

@ -1,3 +1,29 @@
/**
* ownCloud - Addressbook
*
* @author Jakob Sack
* @copyright 2011 Jakob Sack mail@jakobsack.de
* @copyright 2011-2012 Thomas Tanghus <thomas@tanghus.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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){

View File

@ -25,15 +25,14 @@
<?php echo $_['property']['value']; ?>
<?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?>
<?php
$types = array();
foreach($_['property']['parameters']['TYPE'] as $type):
foreach($_['property']['parameters']['TYPE'] as $type) {
if (isset($_['phone_types'][strtoupper($type)])){
$types[]=$_['phone_types'][strtoupper($type)];
}
else{
$types[]=$l->t(ucwords(strtolower($type)));
}
endforeach;
}
$label = join(' ', $types);
?>
(<?php echo $label; ?>)

View File

@ -45,7 +45,7 @@
<p class="contacts_property_name"><label for="tel"><?php echo $l->t('Phone'); ?></label></p>
<p class="contacts_property_data"><input id="tel" type="phone" name="value" value="<?php echo $_['property']['value'] ?>">
<select id="tel_type<?php echo $_['property']['checksum'] ?>" name="parameters[TYPE][]" multiple="multiple" data-placeholder="<?php echo $l->t('Type') ?>">
<?php echo html_select_options($_['phone_types'], isset($_['property']['parameters']['TYPE'])?$_['property']['parameters']['TYPE']:'') ?>
<?php echo html_select_options($_['phone_types'], isset($_['property']['parameters']['TYPE'])?$_['property']['parameters']['TYPE']:array()) ?>
</select></p>
<?php elseif($_['property']['name']=='EMAIL'): ?>
<p class="contacts_property_name"><label for="email"><?php echo $l->t('Email'); ?></label></p>

View File

@ -2,8 +2,8 @@
/**
* ownCloud - Addressbook
*
* @author Jakob Sack
* @copyright 2011 Jakob Sack mail@jakobsack.de
* @author Thomas Tanghus
* @copyright 2011-2012 Thomas Tanghus <thomas@tanghus.net>
*
* 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.');