function xhtml_hcard_render($view) { $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 ($view->result 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 ($node as $field_label => $field_value) { $label = views_rdf_strip_illegal_chars($field_label); $value = views_xml_strip_illegal_chars(views_xml_is_date($field_value)); $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields if (is_null($value) || $value === '') { continue; } //$xhtml .= "$label:$value"; 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(EXHIBIT_DATE_FORMAT, 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($label, 'tel') === 0) { $hcard['tel'][$label] = $value; } } $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']; if ($birthday !== '') { $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">' . $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">' . $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"; if ($view->override_path) { //inside live preview print htmlspecialchars($xhtml); } else { drupal_set_header('Content-Type: text/html'); print $xhtml; //var_dump($view); module_invoke_all('exit'); exit; } }
function xml_atom_render($view) { global $base_url; $xml .= '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; $xml .= '<!-- generator="Drupal Views_Datasource.Module" -->' . "\n"; $xml .= '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">' . "\n"; $xml .= ' <title>' . $view->name . '</title>' . "\n"; $xml .= ' <link rel="alternate" type="text/html" href="' . $base_url . '"/>' . "\n"; $xml .= ' <link rel ="self" type="application/atom+xml" href="' . $base_url . '/' . $view->display_handler->options['path'] . '"/>' . "\n"; $xml .= ' <id>' . $base_url . '/' . $view->display_handler->options['path'] . '</id>' . "\n"; //use path as id $xml .= ' <updated>###feed_updated###</updated>' . "\n"; //will set later $xml .= ' <generator>Views Datasource module</generator>' . "\n"; $feed_last_updated = 0; foreach ($view->result as $node) { $entry = array(); foreach ($node as $field_name => $field_value) { $label = views_xml_strip_illegal_chars($field_name); $value = views_xml_strip_illegal_chars(views_xml_is_date($field_value)); if (is_null($value) || $value === '') { continue; } // if (preg_match('/\d/', $value)) { // if (strtotime($value)) // $value = date(DATE_ISO8601, strtotime($value)); // } $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields if (strtolower($label) == 'nid') { $entry['nid'] = $value; } if (strtolower($label) == 'updated' || strtolower($label) == 'updated date' || strtolower($label) == 'node_changed') { if (intval($value)) { //timestamp $entry['updated'] = intval($value); } else { if (getdate($value)) { //string date $entry['updated'] = strtotime($value); } } } if (strtolower($label) == 'title' || strtolower($label) == 'node_title') { $entry['title'] = $value; } if (strtolower($label) == 'link') { $entry['link'] = $value; } if (strtolower($label) == 'published' || strtolower($label) == 'node_created') { if (intval($value)) { //timestamp $entry['published'] = intval($value); } else { if (getdate($value)) { //string date $entry['published'] = strtotime($value); } } } if (strtolower($label) == 'author' || strtolower($label) == 'users_name') { $entry['author'] = $value; } if (strtolower($label) == 'email' || strtolower($label) == 'users_mail') { $entry['email'] = $value; } if (strtolower($label) == 'content' || strtolower($label) == 'node_revisions_body') { $entry['content'] = $value; } if (strtolower($label) == 'summary' || strtolower($label) == 'node_teaser' || strtolower($label) == 'node_revisions_teaser') { $entry['summary'] = $value; } } if (isset($entry['nid']) && isset($entry['updated']) && isset($entry['link']) && isset($entry['title']) && isset($entry['published'])) { if (parse_url($entry['link'])) { $link = $entry['link']; } else { print '<b style="color:red">The link URL is not valid.</b>'; return; } } elseif (isset($entry['nid']) && isset($entry['updated']) && isset($entry['title']) && isset($entry['published'])) { //make the entry path with base_url + nid { $entry['link'] = $base_url . '/index.php?q=node/' . $entry['nid']; } else { print '<b style="color:red">The fields "nid", "title", "post date", and "updated date" must exist.'; return; } $link = $entry['link']; $link_url = parse_url($link); $nid = $entry['nid']; $updated = $entry['updated']; if ($updated > $feed_last_updated) { $feed_last_updated = $updated; } //Overall feed updated is the most recent node updated timestamp $title = $entry['title']; $published = $entry['published']; $author = $entry['author']; $email = $entry['email']; $content = $entry['content']; $summary = $entry['summary']; //Create an id for the entry using tag URIs $id = 'tag:' . $link_url['host'] . ',' . date('Y-m-d', $updated) . ':' . $link_url['path'] . '?' . $link_url['query']; $xml .= ' <entry>' . "\n"; $xml .= ' <id>' . $id . '</id>' . "\n"; $xml .= ' <updated>' . date(DATE_ATOM, $updated) . '</updated>' . "\n"; $xml .= ' <title type="text">' . $title . '</title>' . "\n"; $xml .= ' <link rel="alternate" type="text/html" href="' . $link . '"/>' . "\n"; $xml .= ' <published>' . date(DATE_ATOM, $published) . '</published>' . "\n"; if ($author) { if ($email) { $xml .= ' <author><name>' . $author . '</name><email>' . $email . '</email></author>' . "\n"; } else { $xml .= ' <author><name>' . $author . '</name></author>' . "\n"; } } if ($content) { $xml .= ' <content type="html" xml:base="' . $base_url . '"><![CDATA[' . $content . ']]></content>' . "\n"; } if ($summary) { $xml .= ' <summary type="html" xml:base="' . $base_url . '"><![CDATA[' . $summary . ']]></summary>' . "\n"; } $xml .= ' </entry>' . "\n"; } $xml .= '</feed>' . "\n"; $xml = str_replace('###feed_updated###', date(DATE_ATOM, $feed_last_updated), $xml); if ($view->override_path) { //inside live preview print htmlspecialchars($xml); } else { drupal_set_header('Content-Type: application/atom+xml'); print $xml; //var_dump($label); module_invoke_all('exit'); exit; } }
function rdf_sioc_xml_user_render($node, $uid = null, $user_name = null, $user_email = null) { if (func_num_args() == 1) { foreach ($node as $field_label => $field_value) { $label = views_rdf_strip_illegal_chars($field_label); $value = views_xml_strip_illegal_chars(views_xml_is_date($field_value)); if (is_null($value) || $value === '') { continue; } // if (strtotime($value)) // $value = date(DATE_ISO8601, strtotime($value)); if (strtolower($label) == 'id' || strtolower($label) == 'uid') { $uid = $value; } if (strtolower($label) == 'name' || strtolower($label) == 'users_name') { $user_name = $value; } if (strtolower($label) == 'email' || strtolower($label) == 'users_mail') { $user_email = $value; } } if (empty($user_name)) { return; } } $xml .= "<foaf:Person rdf:about=\"" . url('user/' . $uid, array('absolute' => true)) . "\">\n"; $xml .= " <foaf:name>{$user_name}</foaf:name>\n"; $xml .= " <foaf:mbox_sha1sum>" . md5('mailto:' . $user_email) . "</foaf:mbox_sha1sum>\n"; $xml .= " <foaf:holdsAccount>\n"; $xml .= " <sioc:User rdf:nodeID=\"{$uid}\">\n"; $xml .= " <sioc:name>{$user_name}</sioc:name>\n"; $xml .= " <sioc:email rdf:resource=\"mailto:{$user_email}\"/>\n"; $xml .= " <sioc:email_sha1>" . md5('mailto:' . $user_email) . "</sioc:email_sha1>\n"; $xml .= " <sioc:link rdf:resource=\"" . url('user/' . $uid, array('absolute' => true)) . "\" rdfs:label=\"{$user_name}\"/>\n"; $roles = array(); $roles_query = db_query("SELECT r.name AS name, r.rid AS rid FROM {users_roles} ur, {role} r WHERE ur.uid = %d AND ur.rid = r.rid", $uid); while ($role = db_fetch_object($roles_query)) { $roles[$role->rid] = $role->name; } if (count($roles) > 0) { $xml .= " <sioc:has_function>\n"; foreach ($roles as $rid => $name) { $xml .= " <sioc:Role><rdfs:label><![CDATA[{$name}]]></rdfs:label></sioc:Role>\n"; } $xml .= " </sioc:has_function>\n"; } $xml .= " </sioc:User>\n"; $xml .= " </foaf:holdsAccount>\n"; $xml .= "</foaf:Person>\n"; return $xml; }