You are here

function template_preprocess_views_views_rdf_style_sioc in Views Datasource 7

Same name and namespace in other branches
  1. 6 theme/views_views_rdf_style.theme.inc \template_preprocess_views_views_rdf_style_sioc()

Template preprocess for the SIOC vocabulary

Parameters

$vars:

Return value

unknown_type

File

views/theme/views_views_rdf_style.theme.inc, line 176
View template to render view fields as rdf.

Code

function template_preprocess_views_views_rdf_style_sioc(&$vars) {
  $view = $vars["view"];
  $rows = $vars["rows"];
  $options = $vars["options"];
  $link = $view->display_handler
    ->get_path();
  $url_options = array(
    'absolute' => TRUE,
  );
  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }
  $base = $view->base_table;
  $plaintext_output = $options["plaintext_output"];
  $vars["content_type"] = $options['content_type'] == 'default' ? 'application/atom+rdf' : $options['content_type'];
  $header = $options["header"];
  if (!$vars["header"]) {
    $vars["title"] = check_plain($view
      ->get_title() ? $view
      ->get_title() : $view->name);
    $vars["id"] = check_url($view
      ->get_url());
    $vars["updated"] = format_date(time(), 'custom', DATE_ATOM);
    $vars["author"] = _views_rdf_format_author($options["author"]);
    $vars['link'] = check_url(url($view->display_handler
      ->get_path(), $url_options));
  }
  else {
    $vars["header"] = $header;
  }
  $users = array();
  $nodes = array();
  if ($base == "users") {
    foreach ($rows as $row) {
      $user = array();
      foreach ($row as $field) {
        if ($options["field_output"] == "normal") {
          if ($field->label) {
            $label = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->label))) : $field->label;
          }
          else {
            $label = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->id))) : $field->id;
          }
          if (!$field->is_multiple) {
            $content = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->content))) : $field->content;
          }
          else {
            $content = array();
            foreach ($field->content as $n => $oc) {
              $content[$n] = $plaintext_output ? check_plain(html_entity_decode(strip_tags($oc))) : $oc;
            }
            $content = implode(" ", $content);
          }
        }
        elseif ($options["field_output"] == "raw") {
          $label = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->id))) : $field->id;
          if (!$field->is_multiple) {
            $content = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->content))) : $field->raw;
          }
          else {
            $content = array();
            foreach ($field->raw as $n => $oc) {
              $content[$n] = $plaintext_output ? check_plain(html_entity_decode(strip_tags($oc))) : $oc;
            }
            $content = implode(" ", $content);
          }
        }
        if (drupal_strtolower($label) == 'id' || drupal_strtolower($label) == 'uid' && !array_key_exists("uid", $user)) {
          $user["uid"] = $content;
          continue;
        }
        if (drupal_strtolower($label) == 'name' || drupal_strtolower($label) == 'users_name' && !array_key_exists("name", $user)) {
          $user["name"] = $content;
          continue;
        }
        if (drupal_strtolower($label) == 'mail' || drupal_strtolower($label) == 'email' || drupal_strtolower($label) == 'users_mail' && !array_key_exists("email", $user)) {
          $user["mail"] = $content;
          continue;
        }
      }
      $users[] = $user;
    }
  }
  if ($base == 'node') {
    foreach ($rows as $row) {
      $node = array();
      foreach ($row as $field) {
        if ($options["field_output"] == "normal") {
          if ($field->label) {
            $label = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->label))) : $field->label;
          }
          else {
            $label = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->id))) : $field->id;
          }
          $content = $plaintext_output ? check_plain(html_entity_decode(strip_tags($field->content))) : $field->content;
        }

        /* rdf:ID */
        if (!array_key_exists("id", $node)) {
          if (drupal_strtolower($label) == "id") {
            $node["id"] = $content;
            continue;
          }
        }

        /* use nid for rdf:ID if none specified */
        if (!array_key_exists("id", $node)) {
          if (drupal_strtolower($label) == "nid") {
            $node["id"] = $content;
            continue;
          }
        }

        /* RDF:created*/
        if (!array_key_exists("created", $node)) {
          if (drupal_strtolower($label) == "created") {
            $node["created"] = $content;
            continue;
          }
        }

        /* rdf:created */
        if (!array_key_exists("created", $node)) {
          if (drupal_strtolower($label) == "node_created" || drupal_strtolower($label) == "post date") {

            //_views_rdf_debug_stop("created");
            $node["created"] = $content;
            continue;
          }
        }

        /* rdf:type */
        if (!array_key_exists("type", $node)) {
          if (drupal_strtolower($label) == "type") {
            $node["type"] = $content;
            continue;
          }
        }

        /* rdf:type */
        if (!array_key_exists("type", $node)) {
          if (drupal_strtolower($label) == "node_type") {
            $node["type"] = $content;
            continue;
          }
        }

        /* rdf:changed */
        if (!array_key_exists("changed", $node)) {
          if (drupal_strtolower($label) == "changed") {
            $node["changed"] = $content;
            continue;
          }
        }

        /* use updatedcommented if no changed*/
        if (!array_key_exists("changed", $node)) {
          if (drupal_strtolower($label) == "updated/commented date") {
            $node["changed"] = $content;
            continue;
          }
        }

        /* use node_changed if no changed*/
        if (!array_key_exists("changed", $node)) {
          if (drupal_strtolower($label) == "node_changed") {
            $node["changed"] = $content;
            continue;
          }
        }

        /* rdf:last updated */
        if (!array_key_exists("last_updated", $node)) {
          if (drupal_strtolower($label) == "last_updated") {
            $node["last_updated"] = $content;
            continue;
          }
        }

        /* use lastupdateddate if no  last_updated */
        if (!array_key_exists("last_updated", $node)) {
          if (drupal_strtolower($label) == "updated date") {
            $node["last_updated"] = $content;
            continue;
          }
        }

        /* rdf:title */
        if (!array_key_exists("title", $node)) {
          if (drupal_strtolower($label) == "title") {
            $node["title"] = $content;
            continue;
          }
        }

        /* rdf title attribute */
        if (!array_key_exists("title", $node)) {
          if (drupal_strtolower($label) == "node_title") {
            $node["title"] = $content;
            continue;
          }
        }

        /* rdf body */
        if (!array_key_exists("body", $node)) {
          if (drupal_strtolower($label) == "body") {
            $node["body"] = $content;
          }
        }

        /* try node_revisions_body */
        if (!array_key_exists("body", $node)) {
          if (drupal_strtolower($label) == "node_revisions_body") {
            $node["body"] = $content;
          }
        }

        /* rdf uid */
        if (!array_key_exists("uid", $node)) {
          if (drupal_strtolower($label) == "uid") {
            $node["uid"] = $content;
          }
        }

        /* try users_uid for uid*/
        if (!array_key_exists("uid", $node)) {
          if (drupal_strtolower($label) == "users_uid") {
            $node["uid"] = $content;
          }
        }
      }
      if (array_key_exists("uid", $node)) {
        $user_obj = user_load($node["uid"]);
        $user["uid"] = $user_obj->uid;
        $user["name"] = $user_obj->name;
        $user["mail"] = $user_obj->mail;
      }
      if ($node["id"]) {
        $nodes[$node["id"]] = $node;
        if ($user) {
          $users[$node["id"]] = $user;
        }
      }
    }

    //for
  }

  //if
  $vars["nodes"] = $nodes;
  $vars["users"] = $users;

  //_views_rdf_debug_stop($nodes);

  //_views_rdf_debug_stop($users);
}