function xhtml_hcalendar_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="hCalendars" />' . "\r\n";
    $xhtml .= '  <title>hCards</title>' . "\r\n";
    $xhtml .= '</head>' . "\r\n";
    $xhtml .= '<body>' . "\r\n";
    foreach ($view->result as $node) {
        $hcalendar = array();
        foreach ($node as $field_label => $field_value) {
            $label = views_rdf_strip_illegal_chars($field_label);
            $value = views_xml_strip_illegal_chars(views_xhtml_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;
            }
            if (stripos($label, 'class') !== FALSE) {
                $hcalendar['class'] = $value;
            }
            if (stripos($label, 'category') !== FALSE) {
                $hcalendar['category'][] = $value;
            }
            if (stripos($label, 'description') !== FALSE) {
                $hcalendar['description'] = $value;
            }
            if (stripos($label, 'summary') !== FALSE) {
                $hcalendar['summary'] = $value;
            }
            if (stripos($label, 'dtstart') !== FALSE || stripos($label, 'event_start') !== FALSE || stripos($label, 'eventstarttime') !== FALSE) {
                if (preg_match('/\\d/', $value)) {
                    if (strtotime($value)) {
                        $value = date(EXHIBIT_DATE_FORMAT, strtotime($value));
                    }
                }
                $hcalendar['dtstart'] = $value;
            }
            if (stripos($label, 'dtend') !== FALSE || stripos($label, 'event_end') !== FALSE || stripos($label, 'eventendtime') !== FALSE) {
                if (preg_match('/\\d/', $value)) {
                    if (strtotime($value)) {
                        $value = date(EXHIBIT_DATE_FORMAT, strtotime($value));
                    }
                }
                $hcalendar['dtend'] = $value;
            }
            if (stripos($label, 'duration') !== FALSE) {
                $hcalendar['duration'] = $value;
            }
            if (stripos($label, 'geo_latitude') !== FALSE) {
                $hcalendar['geo']['latitude'] = $value;
            }
            if (stripos($label, 'geo_longitude') !== FALSE) {
                $hcalendar['geo']['longitude'] = $value;
            }
            if (stripos($label, 'location') !== FALSE) {
                $hcalendar['location'] = $value;
            }
            if (stripos($label, 'status') !== FALSE) {
                $hcalendar['status'] = $value;
            }
            if (stripos($label, 'uid') !== FALSE) {
                $hcalendar['uid'] = $value;
            }
            if (stripos($label, 'url') !== FALSE) {
                $hcalendar['url'] = $value;
            }
            if (stripos($label, 'last_modified') !== FALSE) {
                if (preg_match('/\\d/', $value)) {
                    if (strtotime($value)) {
                        $value = date(EXHIBIT_DATE_FORMAT, strtotime($value));
                    }
                }
                $hcalendar['last-modified'] = $value;
            }
            if (stripos($label, 'address_type') !== FALSE) {
                $hcalendar['adr']['type'] = $value;
            }
            if (stripos($label, 'post_office_box') !== FALSE) {
                $hcalendar['adr']['post-office-box'] = $value;
            }
            if (stripos($label, 'street_address') !== FALSE) {
                $hcalendar['adr']['street-address'][] = $value;
            }
            if (stripos($label, 'extended_address') !== FALSE) {
                $hcalendar['adr']['extended-address'] = $value;
            }
            if (stripos($label, 'region') !== FALSE) {
                $hcalendar['adr']['region'] = $value;
            }
            if (stripos($label, 'locality') !== FALSE) {
                $hcalendar['adr']['locality'] = $value;
            }
            if (stripos($label, 'postal_code') !== FALSE) {
                $hcalendar['adr']['postal-code'] = $value;
            }
            if (stripos($label, 'country_name') !== FALSE) {
                $hcalendar['adr']['country-name'] = $value;
            }
        }
        $xhtml .= '<div class = "vevent">' . "\r\n";
        $class = $hcalendar['class'];
        if ($class) {
            $xhtml .= '  <span class="class">' . $class . '</span>' . "<br/>\r\n";
        }
        $categories = $hcalendar['category'];
        if ($categories) {
            foreach ($categories as $category) {
                $xhtml .= '  <span class="category">' . $category . '</span>' . "<br/>\r\n";
            }
        }
        $dtstart = $hcalendar['dtstart'];
        if ($dtstart) {
            $xhtml .= '  <span class="dtstart">' . $dtstart . '</span>' . "<br/>\r\n";
        }
        $summary = $hcalendar['summary'];
        if ($summary) {
            $xhtml .= '  <span class="summary">' . $summary . '</span>' . "<br/>\r\n";
        }
        $dtend = $hcalendar['dtend'];
        if ($dtend) {
            $xhtml .= '  <span class="dtend">' . $dtend . '</span>' . "<br/>\r\n";
        }
        $location = $hcalendar['location'];
        if ($location) {
            $xhtml .= '  <span class="location">' . $location . '</span>' . "<br/>\r\n";
        }
        $geo_latitude = $hcalendar['geo-latitude'];
        $geo_longitude = $hcalendar['geo-longitude'];
        if ($geo_latitude || $geo_longitude) {
            $xhtml .= "  <div class=\"geo\">\n";
            if ($location) {
                $xhtml .= "    {$location}: ";
            }
            if ($geo_latitude) {
                $xhtml .= "    <span class=\"latitude\">{$geo_latitude}</span>; ";
            }
            if ($geo_longitude) {
                $xhtml .= "    <span class=\"longitude\">{$geo_longitude}</span>";
            }
            $xhtml .= "  </div>\n";
        }
        $status = $hcalendar['status'];
        if ($status) {
            $xhtml .= '  <span class="status">' . $status . '</span>' . "<br/>\r\n";
        }
        $duration = $hcalendar['duration'];
        if ($duration) {
            $xhtml .= '  <span class="duration">' . $duration . '</span>' . "<br/>\r\n";
        }
        $uid = $hcalendar['uid'];
        if ($uid) {
            $xhtml .= '  <span class="uid">' . $uid . '</span>' . "<br/>\r\n";
        }
        $url = $hcalendar['url'];
        if ($url) {
            $xhtml .= '  <span class="url">' . $url . '</span>' . "<br/>\r\n";
        }
        $last_modified = $hcalendar['last-modified'];
        if ($last_modified) {
            $xhtml .= '  <span class="last-modified">' . $last_modified . '</span>' . "<br/>\r\n";
        }
        $description = $hcalendar['description'];
        if ($description) {
            $xhtml .= '  <span class="description">' . $description . '</span>' . "<br/>\r\n";
        }
        $adr = $hcalendar['adr'];
        if ($adr) {
            $xhtml .= "  <div class=\"adr\">\n";
            $adr_type = $adr['address-type'];
            if ($adr_type) {
                $xhtml .= '    <span class="address-type">' . $adr_type . '</span>' . "<br/>\r\n";
            }
            $xhtml .= "  </div>";
        }
        $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;
}
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;
}