-
Notifications
You must be signed in to change notification settings - Fork 7
/
HCard.php
124 lines (99 loc) · 3.27 KB
/
HCard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
class HCard {
public static function getLink( $url ) {
$url = trim($url);
$outUrl = $url;
if ( false === strpos( $outUrl, '://' ) ) {
$outUrl = 'http://'.$outUrl;
}
$linkText = $url;
if (preg_match("/^(https?:\/\/)?(www\.)?([^\/]+)\//", $url, $matches)) {
$linkText = $matches[3];
}
# $username = '';
# if (preg_match("/([-.a-zA-Z0-9_]+)\/?$/", $url, $matches)) {
# $username = $matches[1];
# if ( $username === $linkText ) {
# $username = '';
# }
# }
return "<a href='$outUrl' rel='me' class='url'>$linkText</a>";
}
public static function getEmail( $url ) {
$outUrl = $url;
if ( false === strpos( $url, ':' ) ) {
$outUrl = 'mailto:'.$url;
}
return "<a href='$outUrl' class='email'>$url</a>";
}
public static function getAIM( $url ) {
$outUrl = $url;
if ( false === strpos( $url, ':' ) ) {
$outUrl = 'aim:goim?screenname='.$url;
}
return "<a href='$outUrl' class='email'>$url</a>";
}
public static function getJabber( $url ) {
$outUrl = $url;
if ( false === strpos( $url, ':' ) ) {
$outUrl = 'xmpp:'.$url;
}
return "<a href='$outUrl' class='email'>$url</a>";
}
public static function getYahooMessenger( $url ) {
$outUrl = $url;
if ( false === strpos( $url, ':' ) ) {
$outUrl = 'ymsgr:sendIM?'.$url;
}
return "<a href='$outUrl' class='email'>$url</a>";
}
public static function getAddress( $line, $key = null ) {
$items = explode( ';', $line );
$pieces = array();
if ( $items[2] ) {
$pieces[] = "<span class='street-address'>${items[2]}</span>";
}
if ( $items[3] ) {
$pieces[] = "<span class='locality'>${items[3]}</span>";
}
if ( $items[4] ) {
$pieces[] = "<span class='region'>${items[4]}</span>";
}
if ( $items[5] ) {
$pieces[] = "<span class='postal-code'>${items[5]}</span>";
}
if ( $items[6] ) {
$pieces[] = "<span class='country-name'>${items[6]}</span>";
}
if ( !$pieces ) {
return '';
}
$output = implode( ',</p><p>', $pieces );
$keyClass='';
/*
if ( $key ) {
if ( false !== strpos( $key, 'type=HOME' ) ) {
$keyClass .= ' home';
} elseif( false !== strpos( $key, 'type=WORK' ) ) {
$keyClass .= ' work';
}
}
*/
return "<div class='adr$keyClass'><p>$output</p></div>";
}
public static function getTelephone( $line ) {
return "<span class='tel'>$line</span>";
}
public static function getOrganisation( $line ) {
$items = explode( ';', $line );
return "<span class='org'>${items[0]}</span>";
}
public static function getFN( $line ) {
return "<span class='fn'>$line</span>";
}
public static function getBDay( $line ) {
$date = date( 'jS F Y', strtotime($line) );
return "<abbr class='bday' title='$line'>$date</abbr>";
}
}
?>