You are here

function views_rdf_sioc_xml_render in Views Datasource 5

1 call to views_rdf_sioc_xml_render()
theme_views_rdf_sioc in ./views_rdf.module

File

./views_rdf.module, line 263
Provides Views plugin for rendering node content as RDF.

Code

function views_rdf_sioc_xml_render($vid, $nodes, $type) {
  $view = views_load_view($vid);
  $result = views_build_view('items', $view);
  $fields = _views_get_fields();
  $users_xml = array();
  $nodes_xml = array();
  global $base_url;
  $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  $xml .= '<!-- generator="Drupal Views_Datasource.Module" -->' . "\n";
  $xml .= "<rdf:RDF\r\n";
  $xml .= "  xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\r\n";
  $xml .= "  xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\r\n";
  $xml .= "  xmlns:sioc=\"http://rdfs.org/sioc/ns#\"\r\n";
  $xml .= "  xmlns:sioct=\"http://rdfs.org/sioc/terms#\"\r\n";
  $xml .= "  xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\r\n";
  $xml .= "  xmlns:dcterms=\"http://purl.org/dc/terms/\"\r\n";
  $xml .= "  xmlns:admin=\"http://webns.net/mvcb/\"\r\n";
  $xml .= "  xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">\r\n";
  $xml .= "<foaf:Document rdf:about=\"" . url($view->real_url, NULL, NULL, true) . "\">\n";
  $xml .= "  <dc:title>SIOC profile for: " . variable_get('site_name', 'drupal') . "</dc:title>\n";
  $xml .= "  <dc:description>\n";
  $xml .= "    A SIOC profile describes the structure and contents of a weblog in a machine readable form. For more information please refer to http://sioc-project.org/.\n    A Post is an article or message posted by a User to a Forum or Site. A series of Posts \n    may be threaded if they share a common subject and are connected by reply or \n    by date relationships. Posts will have content and may also have attached \n    files, which can be edited or deleted by the Moderator of the Forum or Site that \n    contains the Post.\n";
  $xml .= "  </dc:description>\n";

  //$xml .= "  <foaf:primaryTopic rdf:resource=\"$node_url\"/>\n";
  $xml .= "  <admin:generatorAgent rdf:resource=\"http://drupal.org/project/views_datasource\"/>\n";
  $xml .= "</foaf:Document>\n";
  foreach ($nodes as $node) {
    $nid = false;
    $type = false;
    $created = false;
    $changed = false;
    $last_updated = false;
    $title = false;
    $body = false;
    $uid = false;
    $users_name = false;
    if ($node->nid) {
      $nid = $node->nid;
    }
    if ($node->node_title) {
      $title = $node->node_title;
    }
    if ($node->node_created) {
      $created = $node->node_created;
    }
    if ($node->node_changed) {
      $changed = $node->node_changed;
    }
    if ($node->node_type) {
      $type = $node->node_type;
    }
    if ($node->users_name) {
      $users_name = $node->users_name;
    }
    if ($node->node_comment_statistics_last_changed) {
      $last_updated = $node->node_comment_statistics_last_changed;
    }
    foreach ($view->field as $field) {
      if ($fields[$field['id']]['visible'] !== false) {
        $label = $field['label'] ? $field['label'] : $fields[$field['fullname']]['name'];

        /*strip illegal XML characters*/
        $value = views_rdf_strip_illegal_chars(views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view));
      }
      else {
        continue;
      }
      if (stripos($label, 'nodebody') !== false || stripos($label, 'node_body') !== false || stripos($label, 'body') !== false) {
        $body = $value;
        continue;
      }
    }
    if (!$nid) {
      drupal_set_message('The node nid field must be present.', 'error');
      return;
    }
    if (!$type) {
      drupal_set_message('The node type field must be present.', 'error');
      return;
    }
    if (!$created) {
      drupal_set_message('The node created field must be present.', 'error');
      return;
    }
    if (!$changed) {
      drupal_set_message('The node changed field must be present.', 'error');
      return;
    }
    if (!$last_updated) {
      drupal_set_message('The node last-updated field must be present.', 'error');
      return;
    }
    if (!$title) {
      drupal_set_message('The node title field must be present.', 'error');
      return;
    }
    if (!$body) {
      drupal_set_message('The node body field must be present.', 'error');
      return;
    }
    if (!$users_name) {
      drupal_set_message('The node author field must be present.', 'error');
      return;
    }
    $user = user_load(array(
      'name' => $users_name,
    ));
    if (!array_key_exists($user->uid, $users_xml)) {
      $users_xml[$user->uid] = rdf_sioc_xml_user_render($user);
    }
    else {
      continue;
    }
    if ($type == 'page' || $type == 'story' || $type == 'forum' || $type == 'blog') {
      $nodes_xml[$nid] = rdf_sioc_xml_story_render($nid, $title, $type, $created, $changed, $last_updated, $user->uid, $body, &$users_xml);
    }
  }

  //drupal_set_header('Content-Type: text/xml');

  //var_dump($view);

  //var_dump(rdf_sioc_xml_user_render($user));

  //var_dump(user_load(array('name' => $users_name)));
  $xml .= implode("", $users_xml);
  $xml .= implode("", $nodes_xml);
  drupal_set_header('Content-Type: application/rdf+xml');
  print $xml;
  module_invoke_all('exit');
  exit;
}