function views_xhtml_hCard_render in Views Datasource 5
File
- ./
views_xhtml.module, line 144 - Provides Views plugin for rendering node content as XHTML microformats.
Code
function views_xhtml_hCard_render($vid, $nodes, $type) {
$view = views_load_view($vid);
$fields = _views_get_fields();
$xhtml = "\r\n";
$xhtml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
$xhtml .= '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"' . ">\r\n";
$xhtml .= '<head>' . "\r\n";
$xhtml .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\r\n";
$xhtml .= ' <meta name="KEYWORDS" content="hCards" />' . "\r\n";
$xhtml .= ' <title>hCards</title>' . "\r\n";
$xhtml .= '</head>' . "\r\n";
$xhtml .= '<body>' . "\r\n";
foreach ($nodes as $node) {
$hcard = array(
'adr' => array(
'type' => '',
'post-office-box' => '',
'street-address' => array(),
'extended-address' => '',
'region' => '',
'locality' => '',
'postal-code' => '',
'country-name' => '',
),
'agent' => array(),
'bday' => '',
'class' => '',
'category' => array(),
'email' => array(),
'fn' => '',
'n' => array(
'honorific-prefix' => '',
'given-name' => '',
'additional-name' => '',
'family-name' => '',
'honorific-suffix' => '',
),
'nickname' => '',
'org' => array(
'organization-name' => '',
'organization-unit' => array(),
),
'photo' => '',
'tel' => array(),
);
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== false) {
$label = $field['label'] ? $field['label'] : $fields[$field['fullname']]['name'];
/*strip illegal XML characters*/
$label = views_xhtml_strip_illegal_chars($label);
$value = views_xhtml_strip_illegal_chars(views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view));
if (is_null($value) || $value === '') {
continue;
}
if (stripos($label, 'address-type') !== FALSE) {
$hcard['adr']['type'] = $value;
}
if (stripos($label, 'post-office-box') !== FALSE) {
$hcard['adr']['post-office-box'] = $value;
}
if (stripos($label, 'street-address') !== FALSE) {
$hcard['adr']['street-address'][] = $value;
}
if (stripos($label, 'extended-address') !== FALSE) {
$hcard['adr']['extended-address'] = $value;
}
if (stripos($label, 'region') !== FALSE) {
$hcard['adr']['region'] = $value;
}
if (stripos($label, 'locality') !== FALSE) {
$hcard['adr']['locality'] = $value;
}
if (stripos($label, 'postal-code') !== FALSE) {
$hcard['adr']['postal-code'] = $value;
}
if (stripos($label, 'country-name') !== FALSE) {
$hcard['adr']['country-name'] = $value;
}
if (stripos($label, 'agent') !== FALSE) {
$hcard['agent'][] = $value;
}
if (stripos($label, 'bday') !== FALSE) {
if (preg_match('/\\d/', $value)) {
if (strtotime($value)) {
$value = date(DATE_ISO8601, strtotime($value));
}
}
$hcard['bday'] = $value;
}
if (stripos($label, 'class') !== FALSE) {
$hcard['class'] = $value;
}
if (stripos($label, 'category') !== FALSE) {
$hcard['category'][] = $value;
}
if (stripos($label, 'email') !== FALSE) {
$hcard['email'][$label] = $value;
}
if (stripos($label, 'honorific-prefix') !== FALSE) {
$hcard['n']['honorific-prefix'] = $value;
}
if (stripos($label, 'given-name') !== FALSE) {
$hcard['n']['given-name'] = $value;
}
if (stripos($label, 'additional-name') !== FALSE) {
$hcard['n']['additional-name'] = $value;
}
if (stripos($label, 'family-name') !== FALSE) {
$hcard['n']['family-name'] = $value;
}
if (stripos($label, 'honorific-suffix') !== FALSE) {
$hcard['n']['honorific-suffix'] = $value;
}
if (stripos($label, 'fn') !== FALSE) {
$hcard['fn'] = $value;
}
if (stripos($label, 'nickname') !== FALSE) {
$hcard['nickname'] = $value;
}
if (stripos($label, 'organization-name') !== FALSE) {
$hcard['org']['organization-name'] = $value;
}
if (stripos($label, 'organization-unit') !== FALSE) {
$hcard['org']['organization-unit'][] = $value;
}
if (stripos($label, 'photo') !== FALSE) {
$hcard['photo'] = $value;
}
if (stripos(trim(str_ireplace("Profile:", '', $label)), 'tel') === 0) {
$hcard['tel'][$label] = $value;
}
}
else {
continue;
}
}
$xhtml .= '<div class = "vcard">' . "\r\n";
if ($hcard['photo'] != '') {
$xhtml .= ' <img class="photo" alt="photo" title="photo" style="height:96px;width:96px" src="' . $hcard['photo'] . '"/>' . "<br/>\r\n";
}
if ($hcard['fn']) {
$xhtml .= ' <span class="fn">' . $hcard['fn'] . '</span>' . "<br/>\r\n";
}
if ($hcard['nickname']) {
$xhtml .= ' <span class="nickname">' . $hcard['nickname'] . '</span>' . "<br/>\r\n";
}
$name = $hcard['n'];
if ($hcard['fn']) {
$xhtml .= ' <span class = "n">' . "\r\n";
}
else {
$xhtml .= ' <span class = "fn n">' . "\r\n";
}
if ($name['honorific-prefix'] !== '') {
$xhtml .= ' <span class="honorific-prefix">' . $name['honorific-prefix'] . '</span>' . "\r\n";
}
if ($name['given-name'] !== '') {
$xhtml .= ' <span class="given-name">' . $name['given-name'] . '</span>' . "\r\n";
}
if ($name['additional-name'] !== '') {
$xhtml .= ' <span class="additional-name">' . $name['additional-name'] . '</span>' . "\r\n";
}
if ($name['family-name'] !== '') {
$xhtml .= ' <span class="family-name">' . $name['family-name'] . '</span>' . "\r\n";
}
if ($name['honorific-suffix'] !== '') {
$xhtml .= ' <span class="honorific-suffix">' . $name['honorific-suffix'] . '</span>' . "\r\n";
}
$xhtml .= ' </span><br/>' . "\r\n";
if ($hcard['nickname'] !== '') {
$xhtml .= ' <span class="nickname">' . $hcard['nickname'] . '</span><br/>' . "\r\n";
}
$org = $hcard['org'];
$xhtml .= ' <span class="org">' . "\r\n";
if ($org['organization-name'] !== '') {
$xhtml .= ' <span class="organization name">' . $org['organization-name'] . '</span><br/>' . "\r\n";
}
$org_units = $org['organization-unit'];
foreach ($org_units as $org_unit) {
$xhtml .= ' <span class="organization-unit">' . $org_unit . '</span>' . "<br/>\r\n";
}
$xhtml .= ' </span>' . "\r\n";
$address = $hcard['adr'];
$xhtml .= ' <span class = "adr">' . "\r\n";
if ($address['type'] !== '') {
$xhtml .= ' <span class="type">' . $address['type'] . '</span>' . "<br/>\r\n";
}
if ($address['post-office-box'] !== '') {
$xhtml .= ' <span class="post-office-box">' . $address['post-office-box'] . '</span>' . "<br/>\r\n";
}
$street_addresses = $address['street-address'];
foreach ($street_addresses as $street_address) {
$xhtml .= ' <span class="street-address">' . $street_address . '</span>' . "<br/>\r\n";
}
if ($address['extended-address'] !== '') {
$xhtml .= ' <span class="extended-address">' . $address['extended-address'] . '</span>' . "<br/>\r\n";
}
if ($address['region'] !== '') {
$xhtml .= ' <span class="region">' . $address['region'] . '</span>' . "<br/>\r\n";
}
if ($address['locality'] !== '') {
$xhtml .= ' <span class="locality">' . $address['locality'] . '</span>' . "<br/>\r\n";
}
if ($address['postal-code'] !== '') {
$xhtml .= ' <span class="postal-code">' . $address['postal-code'] . '</span>' . "<br/>\r\n";
}
if ($address['country-name'] !== '') {
$xhtml .= ' <span class="country-name">' . $address['country-name'] . '</span>' . "\r\n";
}
$xhtml .= ' </span><br/>' . "\r\n";
$agents = $hcard['agent'];
foreach ($agents as $agent) {
$xhtml .= ' <span class="agent">' . $agent . '</span>' . "<br/>\r\n";
}
$birthday = $hcard['bday'];
$birthday_timestamp = false;
if ($birthday !== '') {
$birthday_timestamp = strtotime($birthday);
if ($birthday_timestamp) {
$xhtml .= ' <span class="bday" title="' . date(DATE_ISO8601, $birthday_timestamp) . '">' . $birthday . '</span>' . "<br/>\r\n";
}
else {
$xhtml .= ' <span class="bday">' . $birthday . '</span>' . "<br/>\r\n";
}
}
$class = $hcard['class'];
if ($class !== '') {
$xhtml .= ' <span class="class">' . $class . '</span>' . "<br/>\r\n";
}
$categories = $hcard['category'];
foreach ($categories as $category) {
$xhtml .= ' <span class="category">' . $category . '</span>' . "<br/>\r\n";
}
if ($hcard['email']) {
$email_addrs = $hcard['email'];
foreach ($email_addrs as $email_type => $email_addr) {
$xhtml .= ' <span class="email">' . "\r\n" . ' <span class="type">' . trim(str_ireplace("Profile:", '', $email_type)) . ': </span>' . "\r\n" . ' <a class="value" href="mailto:' . $email_addr . '">' . $email_addr . '</a>' . "\r\n" . ' </span>' . "<br/>\r\n";
}
}
if ($hcard['tel']) {
$tel_nos = $hcard['tel'];
foreach ($tel_nos as $tel_no_type => $tel_no) {
$xhtml .= ' <span class="tel">' . '<span class="type">' . trim(str_ireplace("Profile:", '', $tel_no_type)) . ': </span>' . '<span class="value">' . $tel_no . '</span>' . '</span>' . "<br/>\r\n";
}
}
$xhtml .= '</div>' . "\r\n";
}
$xhtml .= '</body>' . "\r\n";
$xhtml .= '</html>' . "\r\n";
drupal_set_header('Content-Type: text/html');
//var_dump($view);
print $xhtml;
module_invoke_all('exit');
exit;
//return $xhtml;
}