You are here

function template_preprocess_views_views_xml_style_opml in Views Datasource 7

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

File

views/theme/views_views_xml_style.theme.inc, line 98
View template to render view fields as XML.

Code

function template_preprocess_views_views_xml_style_opml(&$vars) {
  $view = $vars["view"];
  $rows = $vars["rows"];
  $options = $vars["options"];
  $base = $view->base_table;
  $top_child_object = $options["top_child_object"];
  $root = "opml";
  $plaintext_output = $options["plaintext_output"];
  $vars["content_type"] = $options['content_type'] == 'default' ? 'text/html' : $options['content_type'];
  $header = $options["header"];
  $author = _views_xml_format_author($options["author"]);
  if (empty($header) || !$header) {
    $vars["title"] = $view
      ->get_title() ? $view
      ->get_title() : $view->name;
    $vars["dateCreated"] = format_date(time(), 'custom', DATE_RFC822);
    $vars["ownerName"] = $author["name"];
    $vars["ownerEmail"] = $author["email"];
    $vars["ownerId"] = $author["uri"];
    $vars["docs"] = url($view
      ->get_url(), array(
      'absolute' => TRUE,
    ));
  }
  else {
    $vars["header"] = $header;
  }
  $outlines = array();
  foreach ($rows as $row) {
    $outline = array();
    foreach ($row as $field) {
      if ($options["field_output"] == "normal") {
        if ($field->label) {
          $label = _views_xml_strip_illegal_xml_name_chars($plaintext_output ? check_plain(html_entity_decode(strip_tags($field->label))) : $field->label);
        }
        else {
          $label = _views_xml_strip_illegal_xml_name_chars($plaintext_output ? check_plain(html_entity_decode(strip_tags($field->id))) : $field->id);
        }
        if (!$field->is_multiple) {
          $content = _views_xml_strip_illegal_xml_attribute_value_chars($plaintext_output ? check_plain(html_entity_decode(strip_tags($field->content))) : $field->content);
        }
        else {
          $content = array();
          foreach ($field->content as $n => $oc) {
            $content[$n] = _views_xml_strip_illegal_xml_attribute_value_chars($plaintext_output ? check_plain(html_entity_decode(strip_tags($oc))) : $oc);
          }
        }
      }
      elseif ($options["field_output"] == "raw") {
        $label = _views_xml_strip_illegal_xml_name_chars($plaintext_output ? check_plain(html_entity_decode(strip_tags($field->id))) : $field->id);
        if (!$field->is_multiple) {
          $content = _views_xml_strip_illegal_xml_attribute_value_chars($plaintext_output ? check_plain(html_entity_decode(strip_tags($field->content))) : $field->raw);
        }
        else {
          $content = array();
          foreach ($field->raw as $n => $oc) {
            $content[$n] = _views_xml_strip_illegal_xml_attribute_value_chars($plaintext_output ? check_plain(html_entity_decode(strip_tags($oc))) : $oc);
          }
        }
      }

      /* OPML text attribute */
      if (!array_key_exists("text", $outline)) {
        if (drupal_strtolower($label) == "text") {
          $outline["text"] = $content;
          continue;
        }
        elseif (drupal_strtolower($label) == "body") {
          $outline["text"] = $content;
          continue;
        }
        elseif (drupal_strtolower($label) == "node_revisions_body") {
          $outline["text"] = $content;
          continue;
        }
      }

      /* OPML type attribute */
      if (!array_key_exists("type", $outline)) {
        if (drupal_strtolower($label) == "type") {
          $outline["type"] = $content;
          continue;
        }
        elseif (drupal_strtolower($label) == "node_type") {
          $outline["type"] = $content;
          continue;
        }
      }

      /* OPML isComment attribute */
      if (!array_key_exists("isComment", $outline)) {
        if (drupal_strtolower($label) == "iscomment") {
          $outline["isComment"] = $content;
          continue;
        }
      }

      /* OPML isBreakpoint attribute */
      if (!array_key_exists("isBreakpoint", $outline)) {
        if (drupal_strtolower($label) == "isbreakpoint") {
          $outline["isBreakpoint"] = $content;
          continue;
        }
      }

      /* OPML created attribute */
      if (!array_key_exists("created", $outline)) {
        $value = NULL;
        if (drupal_strtolower($label) == "created") {
          $value = $content;
        }
        elseif (drupal_strtolower($label) == "published") {
          $value = $content;
        }
        elseif (drupal_strtolower($label) == "node_created") {
          $value = $content;
        }
        elseif (drupal_strtolower($label) == "postdate") {
          $value = $content;
        }

        //        if ($value) {
        //          $value = $field->raw;
        //          if (intval($value))  // timestamp
        //            $value = format_date(intval($value), 'custom', DATE_RFC822);
        //          elseif (getdate($value))      // string date
        //            $value = format_date(strtotime($value), 'custom', DATE_RFC822);
        //          //otherwise just pass the string as is
        //          $outline["created"] = $value;
        //          continue;
        //        }
        if ($value) {
          $outline["created"] = $value;
        }

        //continue;
      }

      //Otherwise just use the $label and $content as attribute nam and value
      $outline[$label] = $content;
    }
    $outlines[] = $outline;
  }

  //_views_xml_debug_stop($outlines);
  $vars["outlines"] = $outlines;
}