Merge branch 'tanghus_contacts'
This commit is contained in:
commit
5817bd10ba
|
@ -61,6 +61,5 @@ foreach( $add as $propname){
|
||||||
$vcard->addProperty($propname, $value, $prop_parameters);
|
$vcard->addProperty($propname, $value, $prop_parameters);
|
||||||
}
|
}
|
||||||
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
|
$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);
|
OC_Contacts_App::renderDetails($id, $vcard);
|
||||||
|
|
|
@ -34,13 +34,31 @@ $name = $_POST['name'];
|
||||||
$value = $_POST['value'];
|
$value = $_POST['value'];
|
||||||
$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
|
$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
|
||||||
|
|
||||||
$property = $vcard->addProperty($name, $value, $parameters);
|
$property = $vcard->addProperty($name, $value); //, $parameters);
|
||||||
|
|
||||||
$line = count($vcard->children) - 1;
|
$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());
|
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 = 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));
|
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($property,$line));
|
||||||
$page = $tmpl->fetchPage();
|
$page = $tmpl->fetchPage();
|
||||||
|
|
||||||
|
|
|
@ -12,21 +12,6 @@ OC_JSON::checkAppEnabled('contacts');
|
||||||
|
|
||||||
$ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser());
|
$ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser());
|
||||||
$contacts = OC_Contacts_VCard::all($ids);
|
$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 = new OC_TEMPLATE("contacts", "part.contacts");
|
||||||
$tmpl->assign('contacts', $contacts);
|
$tmpl->assign('contacts', $contacts);
|
||||||
$page = $tmpl->fetchPage();
|
$page = $tmpl->fetchPage();
|
||||||
|
|
|
@ -42,31 +42,21 @@ OC_App::setActiveNavigationEntry( 'contacts_index' );
|
||||||
|
|
||||||
// Load a specific user?
|
// Load a specific user?
|
||||||
$id = isset( $_GET['id'] ) ? $_GET['id'] : null;
|
$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();
|
$details = array();
|
||||||
|
|
||||||
// FIXME: This cannot work..?
|
// FIXME: This cannot work..?
|
||||||
if( !is_null($id)/* || count($contacts)*/){
|
if(is_null($id) && count($contacts) > 0) {
|
||||||
if(is_null($id)) $id = $contacts[0]['id'];
|
$id = $contacts[0]['id'];
|
||||||
|
}
|
||||||
|
if(!is_null($id)) {
|
||||||
$vcard = OC_Contacts_App::getContactVCard($id);
|
$vcard = OC_Contacts_App::getContactVCard($id);
|
||||||
$details = OC_Contacts_VCard::structureContact($vcard);
|
$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
|
// Include Style and Script
|
||||||
OC_Util::addScript('contacts','interface');
|
OC_Util::addScript('contacts','interface');
|
||||||
|
|
|
@ -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={
|
Contacts={
|
||||||
UI:{
|
UI:{
|
||||||
showCardDAVUrl:function(username, bookname){
|
showCardDAVUrl:function(username, bookname){
|
||||||
|
|
|
@ -25,15 +25,14 @@
|
||||||
<?php echo $_['property']['value']; ?>
|
<?php echo $_['property']['value']; ?>
|
||||||
<?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?>
|
<?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?>
|
||||||
<?php
|
<?php
|
||||||
$types = array();
|
foreach($_['property']['parameters']['TYPE'] as $type) {
|
||||||
foreach($_['property']['parameters']['TYPE'] as $type):
|
|
||||||
if (isset($_['phone_types'][strtoupper($type)])){
|
if (isset($_['phone_types'][strtoupper($type)])){
|
||||||
$types[]=$_['phone_types'][strtoupper($type)];
|
$types[]=$_['phone_types'][strtoupper($type)];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$types[]=$l->t(ucwords(strtolower($type)));
|
$types[]=$l->t(ucwords(strtolower($type)));
|
||||||
}
|
}
|
||||||
endforeach;
|
}
|
||||||
$label = join(' ', $types);
|
$label = join(' ', $types);
|
||||||
?>
|
?>
|
||||||
(<?php echo $label; ?>)
|
(<?php echo $label; ?>)
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
<p class="contacts_property_name"><label for="tel"><?php echo $l->t('Phone'); ?></label></p>
|
<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'] ?>">
|
<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') ?>">
|
<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>
|
</select></p>
|
||||||
<?php elseif($_['property']['name']=='EMAIL'): ?>
|
<?php elseif($_['property']['name']=='EMAIL'): ?>
|
||||||
<p class="contacts_property_name"><label for="email"><?php echo $l->t('Email'); ?></label></p>
|
<p class="contacts_property_name"><label for="email"><?php echo $l->t('Email'); ?></label></p>
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
/**
|
/**
|
||||||
* ownCloud - Addressbook
|
* ownCloud - Addressbook
|
||||||
*
|
*
|
||||||
* @author Jakob Sack
|
* @author Thomas Tanghus
|
||||||
* @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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
@ -26,7 +26,7 @@ OC_Util::checkLoggedIn();
|
||||||
OC_Util::checkAppEnabled('contacts');
|
OC_Util::checkAppEnabled('contacts');
|
||||||
|
|
||||||
if(!function_exists('imagecreatefromjpeg')) {
|
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');
|
header('Content-Type: image/png');
|
||||||
// TODO: Check if it works to read the file and echo the content.
|
// TODO: Check if it works to read the file and echo the content.
|
||||||
return 'img/person.png';
|
return 'img/person.png';
|
||||||
|
@ -46,13 +46,16 @@ $l10n = new OC_L10N('contacts');
|
||||||
|
|
||||||
$card = OC_Contacts_VCard::find( $id );
|
$card = OC_Contacts_VCard::find( $id );
|
||||||
if( $card === false ){
|
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();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Is this check necessary? It just takes up CPU time.
|
||||||
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
|
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
|
||||||
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
|
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();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,17 +63,14 @@ $content = OC_VObject::parse($card['carddata']);
|
||||||
|
|
||||||
// invalid vcard
|
// invalid vcard
|
||||||
if( is_null($content)){
|
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();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// define the width and height for the thumbnail
|
$thumbnail_size = 23;
|
||||||
// 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;
|
|
||||||
|
|
||||||
// Photo :-)
|
// Finf the photo from VCard.
|
||||||
foreach($content->children as $child){
|
foreach($content->children as $child){
|
||||||
if($child->name == 'PHOTO'){
|
if($child->name == 'PHOTO'){
|
||||||
foreach($child->parameters as $parameter){
|
foreach($child->parameters as $parameter){
|
||||||
|
@ -78,73 +78,31 @@ foreach($content->children as $child){
|
||||||
$mime = $parameter->value;
|
$mime = $parameter->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data = base64_decode($child->value);
|
$image = new OC_Image();
|
||||||
$src_img = imagecreatefromstring($data);
|
if($image->loadFromBase64($child->value)) {
|
||||||
if ($src_img !== false) {
|
if($image->centerCrop()) {
|
||||||
//gets the dimmensions of the image
|
if($image->resize($thumbnail_size)) {
|
||||||
$width_orig=imageSX($src_img);
|
if(!$image()) {
|
||||||
$height_orig=imageSY($src_img);
|
OC_Log::write('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OC_Log::ERROR);
|
||||||
$ratio_orig = $width_orig/$height_orig;
|
getStandardImage();
|
||||||
|
exit();
|
||||||
if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
|
}
|
||||||
$new_height = $thumbnail_width/$ratio_orig;
|
|
||||||
$new_width = $thumbnail_width;
|
|
||||||
} else {
|
} else {
|
||||||
$new_width = $thumbnail_height*$ratio_orig;
|
OC_Log::write('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OC_Log::ERROR);
|
||||||
$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) {
|
|
||||||
getStandardImage();
|
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();
|
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{
|
}else{
|
||||||
|
OC_Log::write('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OC_Log::ERROR);
|
||||||
getStandardImage();
|
getStandardImage();
|
||||||
OC_Log::write('contacts','Error resampling thumb image for '.$id.' '.$thumbnail_width.'x'.$thumbnail_height,OC_Log::ERROR);
|
exit();
|
||||||
//echo 'An error occurred resampling thumb.';
|
|
||||||
}
|
}
|
||||||
imagedestroy($thumb);
|
} else {
|
||||||
imagedestroy($process);
|
OC_Log::write('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OC_Log::ERROR);
|
||||||
imagedestroy($src_img);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
getStandardImage();
|
getStandardImage();
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getStandardImage();
|
getStandardImage();
|
||||||
|
|
||||||
// Not found :-(
|
|
||||||
//echo $l10n->t('This card does not contain a photo.');
|
|
||||||
|
|
Loading…
Reference in New Issue