Contact: fix display of links

pull/17/head
Francis Lachapelle 2014-02-13 12:11:25 -05:00
parent 70266155d3
commit 35b108e645
1 changed files with 41 additions and 30 deletions

View File

@ -67,7 +67,8 @@
- (NSString *) _cardStringWithLabel: (NSString *) label
value: (NSString *) value
url: (NSString *) url
asLinkScheme: (NSString *) scheme
withLinkAttributes: (NSString *) attrs
{
NSMutableString *cardString;
@ -75,8 +76,8 @@
value = [[value stringByReplacingString: @"\r" withString: @""] stringByEscapingHTMLString];
if ([value length] > 0)
{
if ([url length] > 0)
value = [NSString stringWithFormat: @"<a href=\"%@:%@\">%@</a>", url, value, value];
if ([scheme length] > 0)
value = [NSString stringWithFormat: @"<a href=\"%@%@\" %@>%@</a>", scheme, value, attrs, value];
if (label)
[cardString appendFormat: @"<dt>%@</dt><dd>%@</dd>\n",
@ -93,7 +94,18 @@
{
return [self _cardStringWithLabel: label
value: value
url: nil];
asLinkScheme: nil
withLinkAttributes: nil];
}
- (NSString *) _cardStringWithLabel: (NSString *) label
value: (NSString *) value
asLinkScheme: (NSString *) scheme
{
return [self _cardStringWithLabel: label
value: value
asLinkScheme: scheme
withLinkAttributes: nil];
}
- (NSString *) displayName
@ -115,7 +127,7 @@
- (NSString *) primaryEmail
{
NSString *email, *fn, *mailTo;
NSString *email, *fn, *attrs;
email = [card preferredEMail];
if ([email length] > 0)
@ -123,26 +135,28 @@
fn = [card fn];
fn = [fn stringByReplacingString: @"\"" withString: @""];
fn = [fn stringByReplacingString: @"'" withString: @"\\\'"];
mailTo = [NSString stringWithFormat: @"<a href=\"mailto:%@\""
@" onclick=\"return openMailTo('%@ <%@>');\">"
@"%@</a>", email, fn, email, email];
attrs = [NSString stringWithFormat: @"onclick=\"return openMailTo('%@ <%@>');\"", fn, email];
}
else
mailTo = nil;
{
attrs = nil;
}
return [self _cardStringWithLabel: @"Email:"
value: mailTo];
value: email
asLinkScheme: @"mailto:"
withLinkAttributes: attrs];
}
- (NSArray *) secondaryEmails
{
NSMutableArray *secondaryEmails;
NSString *email, *fn, *mailTo;
NSString *email, *fn, *attrs;
NSArray *emails;
emails = [card secondaryEmails];
secondaryEmails = [NSMutableArray array];
mailTo = nil;
attrs = nil;
// We might not have a preferred item but rather something like this:
// EMAIL;TYPE=work:dd@ee.com
@ -164,18 +178,18 @@
fn = [card fn];
fn = [fn stringByReplacingString: @"\"" withString: @""];
fn = [fn stringByReplacingString: @"'" withString: @"\\\'"];
mailTo = [NSString stringWithFormat: @"<a href=\"mailto:%@\""
@" onclick=\"return openMailTo('%@ <%@>');\">"
@"%@</a>", email, fn, email, email];
attrs = [NSString stringWithFormat: @"onclick=\"return openMailTo('%@ <%@>');\"", fn, email];
[secondaryEmails addObject: [self _cardStringWithLabel: nil
value: mailTo]];
value: email
asLinkScheme: @"mailto:"
withLinkAttributes: attrs]];
}
}
else
{
[secondaryEmails addObject: [self _cardStringWithLabel: nil
value: mailTo]];
value: nil]];
}
@ -184,22 +198,19 @@
- (NSString *) screenName
{
NSString *screenName, *goim;
NSString *screenName;
screenName = [[card uniqueChildWithTag: @"x-aim"] flattenedValuesForKey: @""];
if ([screenName length] > 0)
goim = [NSString stringWithFormat: @"<a href=\"aim:goim?screenname=%@\""
@">%@</a>", screenName, screenName];
else
goim = nil;
return [self _cardStringWithLabel: @"Screen Name:" value: goim];
return [self _cardStringWithLabel: @"Screen Name:"
value: screenName
asLinkScheme: @"aim:goim?screenname="];
}
- (NSString *) preferredTel
{
return [self _cardStringWithLabel: @"Phone Number:"
value: [card preferredTel] url: @"tel"];
value: [card preferredTel] asLinkScheme: @"tel:"];
}
- (NSString *) preferredAddress
@ -228,27 +239,27 @@
{
// 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.
return [self _cardStringWithLabel: @"Work:" value: [card workPhone] url: @"tel"];
return [self _cardStringWithLabel: @"Work:" value: [card workPhone] asLinkScheme: @"tel:"];
}
- (NSString *) homePhone
{
return [self _cardStringWithLabel: @"Home:" value: [card homePhone] url: @"tel"];
return [self _cardStringWithLabel: @"Home:" value: [card homePhone] asLinkScheme: @"tel:"];
}
- (NSString *) fax
{
return [self _cardStringWithLabel: @"Fax:" value: [card fax] url: @"tel"];
return [self _cardStringWithLabel: @"Fax:" value: [card fax] asLinkScheme: @"tel:"];
}
- (NSString *) mobile
{
return [self _cardStringWithLabel: @"Mobile:" value: [card mobile] url: @"tel"];
return [self _cardStringWithLabel: @"Mobile:" value: [card mobile] asLinkScheme: @"tel:"];
}
- (NSString *) pager
{
return [self _cardStringWithLabel: @"Pager:" value: [card pager] url: @"tel"];
return [self _cardStringWithLabel: @"Pager:" value: [card pager] asLinkScheme: @"tel:"];
}
- (BOOL) hasHomeInfos