2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 SKYRIX Software AG
|
2014-01-10 03:06:31 +01:00
|
|
|
Copyright (C) 2005-2014 Inverse inc.
|
2010-06-30 18:53:23 +02:00
|
|
|
|
|
|
|
This file is part of SOGo.
|
2009-10-28 20:38:56 +01:00
|
|
|
|
2010-06-30 18:53:23 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
2009-10-28 20:38:56 +01:00
|
|
|
|
2010-06-30 18:53:23 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2009-10-28 20:38:56 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2010-07-16 21:35:25 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
|
|
|
|
2007-08-06 16:46:38 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2006-09-13 23:30:37 +02:00
|
|
|
#import <NGCards/NGVCard.h>
|
2010-07-16 21:35:25 +02:00
|
|
|
#import <NGCards/NGVCardPhoto.h>
|
2006-09-13 23:30:37 +02:00
|
|
|
#import <NGCards/CardElement.h>
|
|
|
|
#import <NGCards/NSArray+NGCards.h>
|
2006-09-19 16:09:03 +02:00
|
|
|
#import <NGExtensions/NSString+Ext.h>
|
2014-02-07 21:52:43 +01:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2013-01-30 14:40:27 +01:00
|
|
|
#import <SOGo/NSCalendarDate+SOGo.h>
|
|
|
|
#import <SOGo/SOGoDateFormatter.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2014-01-22 17:27:27 +01:00
|
|
|
|
|
|
|
#import <Contacts/NGVCard+SOGo.h>
|
2010-07-16 21:35:25 +02:00
|
|
|
#import <Contacts/SOGoContactObject.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
#import "UIxContactView.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxContactView
|
|
|
|
|
2010-07-16 21:35:25 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
photosURL = nil;
|
2010-10-27 17:18:14 +02:00
|
|
|
card = nil;
|
|
|
|
phones = nil;
|
|
|
|
homeAdr = nil;
|
|
|
|
workAdr = nil;
|
2010-07-16 21:35:25 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-07-16 21:35:25 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2011-12-30 21:39:07 +01:00
|
|
|
[card release];
|
2010-07-16 21:35:25 +02:00
|
|
|
[photosURL release];
|
|
|
|
[super dealloc];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 21:35:25 +02:00
|
|
|
/* accessors */
|
|
|
|
|
2011-08-08 16:20:46 +02:00
|
|
|
- (NSString *) _cardStringWithLabel: (NSString *) label
|
|
|
|
value: (NSString *) value
|
2014-02-13 18:11:25 +01:00
|
|
|
asLinkScheme: (NSString *) scheme
|
|
|
|
withLinkAttributes: (NSString *) attrs
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
|
|
|
NSMutableString *cardString;
|
|
|
|
|
2010-10-27 18:23:06 +02:00
|
|
|
cardString = [NSMutableString stringWithCapacity: 80];
|
2014-02-07 21:52:43 +01:00
|
|
|
value = [[value stringByReplacingString: @"\r" withString: @""] stringByEscapingHTMLString];
|
2010-10-27 18:23:06 +02:00
|
|
|
if ([value length] > 0)
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
2014-02-13 18:11:25 +01:00
|
|
|
if ([scheme length] > 0)
|
|
|
|
value = [NSString stringWithFormat: @"<a href=\"%@%@\" %@>%@</a>", scheme, value, attrs, value];
|
2011-08-08 16:20:46 +02:00
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
if (label)
|
2012-07-10 17:26:00 +02:00
|
|
|
[cardString appendFormat: @"<dt>%@</dt><dd>%@</dd>\n",
|
2006-09-13 23:30:37 +02:00
|
|
|
[self labelForKey: label], value];
|
|
|
|
else
|
2012-07-10 17:26:00 +02:00
|
|
|
[cardString appendFormat: @"<dt></dt><dd>%@</dd>\n", value];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return cardString;
|
|
|
|
}
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
- (NSString *) _cardStringWithLabel: (NSString *) label
|
|
|
|
value: (NSString *) value
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: label
|
|
|
|
value: value
|
2014-02-13 18:11:25 +01:00
|
|
|
asLinkScheme: nil
|
|
|
|
withLinkAttributes: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _cardStringWithLabel: (NSString *) label
|
|
|
|
value: (NSString *) value
|
|
|
|
asLinkScheme: (NSString *) scheme
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: label
|
|
|
|
value: value
|
|
|
|
asLinkScheme: scheme
|
|
|
|
withLinkAttributes: nil];
|
2011-11-14 17:07:04 +01:00
|
|
|
}
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (NSString *) displayName
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Display Name:"
|
2006-09-13 23:30:37 +02:00
|
|
|
value: [card fn]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) nickName
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Nickname:"
|
2006-09-13 23:30:37 +02:00
|
|
|
value: [card nickname]];
|
|
|
|
}
|
|
|
|
|
2008-08-21 19:42:31 +02:00
|
|
|
- (NSString *) fullName
|
|
|
|
{
|
2014-01-22 17:27:27 +01:00
|
|
|
return [card fullName];
|
2008-08-21 19:42:31 +02:00
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
- (NSString *) primaryEmail
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
2014-02-13 18:11:25 +01:00
|
|
|
NSString *email, *fn, *attrs;
|
2006-09-16 00:25:43 +02:00
|
|
|
|
|
|
|
email = [card preferredEMail];
|
2007-03-22 20:02:45 +01:00
|
|
|
if ([email length] > 0)
|
2012-05-08 20:58:57 +02:00
|
|
|
{
|
|
|
|
fn = [card fn];
|
|
|
|
fn = [fn stringByReplacingString: @"\"" withString: @""];
|
|
|
|
fn = [fn stringByReplacingString: @"'" withString: @"\\\'"];
|
2014-02-13 18:11:25 +01:00
|
|
|
attrs = [NSString stringWithFormat: @"onclick=\"return openMailTo('%@ <%@>');\"", fn, email];
|
2012-05-08 20:58:57 +02:00
|
|
|
}
|
2006-09-16 00:25:43 +02:00
|
|
|
else
|
2014-02-13 18:11:25 +01:00
|
|
|
{
|
|
|
|
attrs = nil;
|
|
|
|
}
|
2006-09-16 00:25:43 +02:00
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Email:"
|
2014-02-13 18:11:25 +01:00
|
|
|
value: email
|
|
|
|
asLinkScheme: @"mailto:"
|
|
|
|
withLinkAttributes: attrs];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
2012-07-05 19:17:50 +02:00
|
|
|
- (NSArray *) secondaryEmails
|
2007-03-22 20:02:45 +01:00
|
|
|
{
|
2012-07-05 19:35:02 +02:00
|
|
|
NSMutableArray *secondaryEmails;
|
2014-02-13 18:11:25 +01:00
|
|
|
NSString *email, *fn, *attrs;
|
2014-01-22 17:27:27 +01:00
|
|
|
NSArray *emails;
|
2007-03-22 20:02:45 +01:00
|
|
|
|
2014-01-22 17:27:27 +01:00
|
|
|
emails = [card secondaryEmails];
|
2012-07-05 19:35:02 +02:00
|
|
|
secondaryEmails = [NSMutableArray array];
|
2014-02-13 18:11:25 +01:00
|
|
|
attrs = nil;
|
2007-12-21 17:57:11 +01:00
|
|
|
|
|
|
|
// We might not have a preferred item but rather something like this:
|
|
|
|
// EMAIL;TYPE=work:dd@ee.com
|
|
|
|
// EMAIL;TYPE=home:ff@gg.com
|
2010-07-16 16:11:14 +02:00
|
|
|
//
|
|
|
|
// or:
|
|
|
|
//
|
|
|
|
// EMAIL;TYPE=INTERNET:a@a.com
|
|
|
|
// EMAIL;TYPE=INTERNET,HOME:b@b.com
|
|
|
|
//
|
|
|
|
// In this case, we always return the entry NOT matching the primaryEmail
|
2007-12-21 17:57:11 +01:00
|
|
|
if ([emails count] > 0)
|
2007-03-22 20:02:45 +01:00
|
|
|
{
|
2010-07-16 16:11:14 +02:00
|
|
|
int i;
|
2007-12-21 19:23:48 +01:00
|
|
|
|
2010-07-16 16:11:14 +02:00
|
|
|
for (i = 0; i < [emails count]; i++)
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
email = [[emails objectAtIndex: i] flattenedValuesForKey: @""];
|
2014-01-22 17:27:27 +01:00
|
|
|
fn = [card fn];
|
|
|
|
fn = [fn stringByReplacingString: @"\"" withString: @""];
|
|
|
|
fn = [fn stringByReplacingString: @"'" withString: @"\\\'"];
|
2014-02-13 18:11:25 +01:00
|
|
|
attrs = [NSString stringWithFormat: @"onclick=\"return openMailTo('%@ <%@>');\"", fn, email];
|
2014-01-22 17:27:27 +01:00
|
|
|
|
|
|
|
[secondaryEmails addObject: [self _cardStringWithLabel: nil
|
2014-02-13 18:11:25 +01:00
|
|
|
value: email
|
|
|
|
asLinkScheme: @"mailto:"
|
|
|
|
withLinkAttributes: attrs]];
|
2014-01-22 17:27:27 +01:00
|
|
|
}
|
2007-03-22 20:02:45 +01:00
|
|
|
}
|
2012-07-05 19:17:50 +02:00
|
|
|
else
|
|
|
|
{
|
2012-07-10 17:26:00 +02:00
|
|
|
[secondaryEmails addObject: [self _cardStringWithLabel: nil
|
2014-02-13 18:11:25 +01:00
|
|
|
value: nil]];
|
2012-07-05 19:17:50 +02:00
|
|
|
}
|
2007-03-22 20:02:45 +01:00
|
|
|
|
2012-07-05 19:17:50 +02:00
|
|
|
|
2012-07-05 19:35:02 +02:00
|
|
|
return secondaryEmails;
|
2007-03-22 20:02:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) screenName
|
|
|
|
{
|
2014-02-13 18:11:25 +01:00
|
|
|
NSString *screenName;
|
2007-03-22 20:02:45 +01:00
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
screenName = [[card uniqueChildWithTag: @"x-aim"] flattenedValuesForKey: @""];
|
2007-03-22 20:02:45 +01:00
|
|
|
|
2014-02-13 18:11:25 +01:00
|
|
|
return [self _cardStringWithLabel: @"Screen Name:"
|
|
|
|
value: screenName
|
|
|
|
asLinkScheme: @"aim:goim?screenname="];
|
2007-03-22 20:02:45 +01:00
|
|
|
}
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (NSString *) preferredTel
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Phone Number:"
|
2014-02-13 18:11:25 +01:00
|
|
|
value: [card preferredTel] asLinkScheme: @"tel:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) preferredAddress
|
|
|
|
{
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2010-10-27 18:23:06 +02:00
|
|
|
- (NSString *) categories
|
|
|
|
{
|
|
|
|
NSString *categories;
|
|
|
|
|
|
|
|
categories = [[card categories] componentsJoinedByString: @", "];
|
|
|
|
return [self _cardStringWithLabel: @"Categories:"
|
|
|
|
value: categories];
|
|
|
|
}
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (BOOL) hasTelephones
|
|
|
|
{
|
|
|
|
if (!phones)
|
|
|
|
phones = [card childrenWithTag: @"tel"];
|
|
|
|
|
|
|
|
return ([phones count] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workPhone
|
|
|
|
{
|
2010-07-05 04:06:01 +02:00
|
|
|
// We do this (exclude FAX) in order to avoid setting the WORK number as the FAX
|
|
|
|
// one if we do see the FAX field BEFORE the WORK number.
|
2014-02-13 18:11:25 +01:00
|
|
|
return [self _cardStringWithLabel: @"Work:" value: [card workPhone] asLinkScheme: @"tel:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homePhone
|
|
|
|
{
|
2014-02-13 18:11:25 +01:00
|
|
|
return [self _cardStringWithLabel: @"Home:" value: [card homePhone] asLinkScheme: @"tel:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) fax
|
|
|
|
{
|
2014-02-13 18:11:25 +01:00
|
|
|
return [self _cardStringWithLabel: @"Fax:" value: [card fax] asLinkScheme: @"tel:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) mobile
|
|
|
|
{
|
2014-02-13 18:11:25 +01:00
|
|
|
return [self _cardStringWithLabel: @"Mobile:" value: [card mobile] asLinkScheme: @"tel:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) pager
|
|
|
|
{
|
2014-02-13 18:11:25 +01:00
|
|
|
return [self _cardStringWithLabel: @"Pager:" value: [card pager] asLinkScheme: @"tel:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasHomeInfos
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
NSArray *elements;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"adr"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"home"];
|
|
|
|
if ([elements count] > 0)
|
|
|
|
{
|
|
|
|
result = YES;
|
|
|
|
homeAdr = [elements objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = ([[card childrenWithTag: @"url"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"home"] count] > 0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homePobox
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [self _cardStringWithLabel: nil
|
|
|
|
value: [homeAdr flattenedValueAtIndex: 0
|
|
|
|
forKey: @""]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homeExtendedAddress
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [self _cardStringWithLabel: nil
|
|
|
|
value: [homeAdr flattenedValueAtIndex: 1
|
|
|
|
forKey: @""]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homeStreetAddress
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [self _cardStringWithLabel: nil
|
|
|
|
value: [homeAdr flattenedValueAtIndex: 2
|
|
|
|
forKey: @""]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homeCityAndProv
|
|
|
|
{
|
|
|
|
NSString *city, *prov;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
city = [homeAdr flattenedValueAtIndex: 3 forKey: @""];
|
|
|
|
prov = [homeAdr flattenedValueAtIndex: 4 forKey: @""];
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2009-10-13 16:10:17 +02:00
|
|
|
data = [NSMutableString string];
|
2006-09-13 23:30:37 +02:00
|
|
|
[data appendString: city];
|
|
|
|
if ([city length] > 0 && [prov length] > 0)
|
|
|
|
[data appendString: @", "];
|
|
|
|
[data appendString: prov];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homePostalCodeAndCountry
|
|
|
|
{
|
|
|
|
NSString *postalCode, *country;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
postalCode = [homeAdr flattenedValueAtIndex: 5 forKey: @""];
|
|
|
|
country = [homeAdr flattenedValueAtIndex: 6 forKey: @""];
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2009-10-13 16:10:17 +02:00
|
|
|
data = [NSMutableString string];
|
2006-09-13 23:30:37 +02:00
|
|
|
[data appendString: postalCode];
|
|
|
|
if ([postalCode length] > 0 && [country length] > 0)
|
|
|
|
[data appendFormat: @", ", country];
|
|
|
|
[data appendString: country];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
2010-06-30 22:30:30 +02:00
|
|
|
- (NSString *) _formattedURL: (NSString *) url
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
2014-02-17 17:12:09 +01:00
|
|
|
NSRange schemaR;
|
|
|
|
NSString *schema, *data;
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
if ([url length] > 0)
|
2010-06-30 22:30:30 +02:00
|
|
|
{
|
2014-02-17 17:12:09 +01:00
|
|
|
schemaR = [url rangeOfString: @"://"];
|
|
|
|
if (schemaR.length > 0)
|
|
|
|
{
|
|
|
|
schema = [url substringToIndex: schemaR.location + schemaR.length];
|
|
|
|
data = [url substringFromIndex: schemaR.location + schemaR.length];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
schema = @"http://";
|
|
|
|
data = url;
|
|
|
|
}
|
2006-09-16 00:25:43 +02:00
|
|
|
}
|
2011-12-30 21:39:07 +01:00
|
|
|
else
|
2014-02-17 17:12:09 +01:00
|
|
|
{
|
|
|
|
schema = nil;
|
|
|
|
data = nil;
|
|
|
|
}
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2014-02-17 17:12:09 +01:00
|
|
|
return [self _cardStringWithLabel: nil
|
|
|
|
value: data
|
|
|
|
asLinkScheme: schema
|
|
|
|
withLinkAttributes: @"target=\"_blank\""];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 22:30:30 +02:00
|
|
|
|
|
|
|
- (NSString *) _urlOfType: (NSString *) aType
|
|
|
|
{
|
|
|
|
NSArray *elements;
|
|
|
|
NSString *url;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"url"
|
2014-02-17 17:12:09 +01:00
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: aType];
|
2010-06-30 22:30:30 +02:00
|
|
|
if ([elements count] > 0)
|
2011-11-14 17:07:04 +01:00
|
|
|
url = [[elements objectAtIndex: 0] flattenedValuesForKey: @""];
|
2010-06-30 22:30:30 +02:00
|
|
|
else
|
|
|
|
url = nil;
|
|
|
|
|
|
|
|
return [self _formattedURL: url];
|
|
|
|
}
|
|
|
|
|
2006-09-16 00:25:43 +02:00
|
|
|
- (NSString *) homeUrl
|
|
|
|
{
|
2010-06-30 22:30:30 +02:00
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _urlOfType: @"home"];
|
|
|
|
|
|
|
|
if (!s || [s length] == 0)
|
|
|
|
{
|
|
|
|
NSArray *elements;
|
|
|
|
NSString *workURL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"url"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"work"];
|
|
|
|
workURL = nil;
|
|
|
|
|
|
|
|
if ([elements count] > 0)
|
2011-11-14 17:07:04 +01:00
|
|
|
workURL = [[elements objectAtIndex: 0] flattenedValuesForKey: @""];
|
2010-06-30 22:30:30 +02:00
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"url"];
|
|
|
|
|
|
|
|
if (workURL && [elements count] > 1)
|
|
|
|
{
|
|
|
|
for (i = 0; i < [elements count]; i++)
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
if ([[[elements objectAtIndex: i] flattenedValuesForKey: @""]
|
|
|
|
caseInsensitiveCompare: workURL] != NSOrderedSame)
|
2010-06-30 22:30:30 +02:00
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
s = [[elements objectAtIndex: i] flattenedValuesForKey: @""];
|
2010-06-30 22:30:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (!workURL && [elements count] > 0)
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
s = [[elements objectAtIndex: 0] flattenedValuesForKey: @""];
|
2010-06-30 22:30:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s && [s length] > 0)
|
|
|
|
s = [self _formattedURL: s];
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
2006-09-16 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (BOOL) hasWorkInfos
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
NSArray *elements;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"adr"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"work"];
|
|
|
|
if ([elements count] > 0)
|
|
|
|
{
|
|
|
|
result = YES;
|
|
|
|
workAdr = [elements objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = (([[card childrenWithTag: @"url"
|
|
|
|
andAttribute: @"type"
|
2008-07-08 13:32:43 +02:00
|
|
|
havingValue: @"work"] count] > 0)
|
2006-09-13 23:30:37 +02:00
|
|
|
|| [[card childrenWithTag: @"org"] count] > 0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workTitle
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [card title]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workService
|
|
|
|
{
|
2010-06-30 18:53:23 +02:00
|
|
|
NSMutableArray *orgServices;
|
2011-11-14 17:07:04 +01:00
|
|
|
NSArray *values;
|
|
|
|
CardElement *org;
|
|
|
|
NSString *service, *services;
|
|
|
|
NSUInteger count, max;
|
2006-09-13 23:30:37 +02:00
|
|
|
|
|
|
|
org = [card org];
|
2011-11-14 17:07:04 +01:00
|
|
|
values = [org valuesForKey: @""];
|
|
|
|
max = [values count];
|
|
|
|
if (max > 1)
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
orgServices = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 1; count < max; count++)
|
|
|
|
{
|
|
|
|
service = [org flattenedValueAtIndex: count forKey: @""];
|
|
|
|
if ([service length] > 0)
|
|
|
|
[orgServices addObject: service];
|
|
|
|
}
|
2010-06-30 18:53:23 +02:00
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
services = [orgServices componentsJoinedByString: @", "];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
services = nil;
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: services];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workCompany
|
|
|
|
{
|
2014-01-22 17:27:27 +01:00
|
|
|
return [self _cardStringWithLabel: nil value: [card workCompany]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workPobox
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [self _cardStringWithLabel: nil
|
|
|
|
value: [workAdr flattenedValueAtIndex: 0
|
|
|
|
forKey: @""]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workExtendedAddress
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [self _cardStringWithLabel: nil
|
|
|
|
value: [workAdr flattenedValueAtIndex: 1
|
|
|
|
forKey: @""]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workStreetAddress
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [self _cardStringWithLabel: nil
|
|
|
|
value: [workAdr flattenedValueAtIndex: 2
|
|
|
|
forKey: @""]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workCityAndProv
|
|
|
|
{
|
|
|
|
NSString *city, *prov;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
city = [workAdr flattenedValueAtIndex: 3 forKey: @""];
|
|
|
|
prov = [workAdr flattenedValueAtIndex: 4 forKey: @""];
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2009-10-13 16:10:17 +02:00
|
|
|
data = [NSMutableString string];
|
2006-09-13 23:30:37 +02:00
|
|
|
[data appendString: city];
|
|
|
|
if ([city length] > 0 && [prov length] > 0)
|
2012-07-10 17:26:00 +02:00
|
|
|
[data appendString: @" "];
|
2006-09-13 23:30:37 +02:00
|
|
|
[data appendString: prov];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workPostalCodeAndCountry
|
|
|
|
{
|
|
|
|
NSString *postalCode, *country;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
postalCode = [workAdr flattenedValueAtIndex: 5 forKey: @""];
|
|
|
|
country = [workAdr flattenedValueAtIndex: 6 forKey: @""];
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2009-10-13 16:10:17 +02:00
|
|
|
data = [NSMutableString string];
|
2006-09-13 23:30:37 +02:00
|
|
|
[data appendString: postalCode];
|
|
|
|
if ([postalCode length] > 0 && [country length] > 0)
|
2012-07-10 17:26:00 +02:00
|
|
|
[data appendFormat: @" ", country];
|
2006-09-13 23:30:37 +02:00
|
|
|
[data appendString: country];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workUrl
|
|
|
|
{
|
2007-04-02 23:14:53 +02:00
|
|
|
return [self _urlOfType: @"work"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasOtherInfos
|
|
|
|
{
|
2006-09-18 17:29:06 +02:00
|
|
|
return ([[card note] length] > 0
|
|
|
|
|| [[card bday] length] > 0
|
|
|
|
|| [[card tz] length] > 0);
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) bday
|
|
|
|
{
|
2013-01-30 14:40:27 +01:00
|
|
|
SOGoDateFormatter *dateFormatter;
|
2014-01-22 17:27:27 +01:00
|
|
|
NSCalendarDate *date;
|
|
|
|
NSString *bday;
|
|
|
|
|
|
|
|
date = [card birthday];
|
|
|
|
bday = nil;
|
2013-01-30 14:40:27 +01:00
|
|
|
|
2014-01-22 17:27:27 +01:00
|
|
|
if (date)
|
2013-01-30 14:40:27 +01:00
|
|
|
{
|
|
|
|
dateFormatter = [[[self context] activeUser] dateFormatterInContext: context];
|
|
|
|
bday = [dateFormatter formattedDate: date];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: @"Birthday:" value: bday];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) tz
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Timezone:" value: [card tz]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) note
|
|
|
|
{
|
2006-09-19 16:09:03 +02:00
|
|
|
NSString *note;
|
|
|
|
|
|
|
|
note = [card note];
|
|
|
|
if (note)
|
|
|
|
{
|
|
|
|
note = [note stringByReplacingString: @"\r\n"
|
|
|
|
withString: @"<br />"];
|
|
|
|
note = [note stringByReplacingString: @"\n"
|
|
|
|
withString: @"<br />"];
|
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Note:" value: note];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* hrefs */
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (NSString *) completeHrefForMethod: (NSString *) _method
|
|
|
|
withParameter: (NSString *) _param
|
|
|
|
forKey: (NSString *) _key
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
NSString *href;
|
|
|
|
|
|
|
|
[self setQueryParameter:_param forKey:_key];
|
|
|
|
href = [self completeHrefForMethod:[self ownMethodName]];
|
|
|
|
[self setQueryParameter:nil forKey:_key];
|
2006-09-19 16:50:11 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return href;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)attributesTabLink {
|
|
|
|
return [self completeHrefForMethod:[self ownMethodName]
|
|
|
|
withParameter:@"attributes"
|
|
|
|
forKey:@"tab"];
|
|
|
|
}
|
|
|
|
- (NSString *)debugTabLink {
|
|
|
|
return [self completeHrefForMethod:[self ownMethodName]
|
|
|
|
withParameter:@"debug"
|
|
|
|
forKey:@"tab"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* action */
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
card = [[self clientObject] vCard];
|
2006-09-16 00:25:43 +02:00
|
|
|
if (card)
|
|
|
|
{
|
2011-12-30 21:39:07 +01:00
|
|
|
[card retain];
|
2006-09-16 00:25:43 +02:00
|
|
|
phones = nil;
|
|
|
|
homeAdr = nil;
|
|
|
|
workAdr = nil;
|
|
|
|
}
|
|
|
|
else
|
2006-09-19 16:50:11 +02:00
|
|
|
return [NSException exceptionWithHTTPStatus: 404 /* Not Found */
|
|
|
|
reason: @"could not locate contact"];
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-02-13 15:50:00 +01:00
|
|
|
- (BOOL) hasPhoto
|
|
|
|
{
|
|
|
|
return [[self clientObject] hasPhoto];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) photoURL
|
2010-07-16 21:35:25 +02:00
|
|
|
{
|
|
|
|
NSURL *soURL;
|
|
|
|
|
2012-02-13 15:50:00 +01:00
|
|
|
soURL = [[self clientObject] soURL];
|
2010-07-16 21:35:25 +02:00
|
|
|
|
2012-02-13 15:50:00 +01:00
|
|
|
return [NSString stringWithFormat: @"%@/photo", [soURL absoluteString]];
|
2010-07-16 21:35:25 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* UIxContactView */
|