You are here

function contentanalysis_parse_context_node_load in Content Analysis 6

Same name and namespace in other branches
  1. 8 contentanalysis.module \contentanalysis_parse_context_node_load()
  2. 7 contentanalysis.module \contentanalysis_parse_context_node_load()

Normalizes context data inputed from the node_load function

Parameters

$context: Initialized context formated array

Return value

A normalized context array

1 call to contentanalysis_parse_context_node_load()
contentanalysis_parse_context in ./contentanalysis.module
Inspects context to select a normalizing context parser

File

./contentanalysis.module, line 725

Code

function contentanalysis_parse_context_node_load($context) {
  dsm($context);
  if (!$context['nid']) {
    return $context;
  }
  $node = node_load($context['nid']);
  $context['node'] = $node;
  $context['title'] = !is_null($context['title']) ? $context['title'] : $node->title;
  if (is_null($context['page_title'])) {
    $context_title = $context['title'];
    $context_page_title = $context['title'];
    if (module_exists('page_title')) {
      $page_title_pattern = variable_get('page_title_type_' . (isset($node->type) ? $node->type : ''), '');
      if (empty($page_title_pattern)) {
        $page_title_pattern = variable_get('page_title_default', '[page-title] | [site-name]');
      }
      $page_title_pattern = str_replace('[page-title]', $context_page_title && !is_null($context_page_title) ? $context_page_title : $context_title, $page_title_pattern);
      $page_title_pattern = str_replace('[title]', check_plain($context_title), $page_title_pattern);
      $page_title_pattern = str_replace('[title-raw]', $context_title, $page_title_pattern);
      $types = array();
      if (isset($node)) {
        $types['node'] = $node;
      }
      $types['page_title'] = NULL;
      $context['page_title'] = token_replace_multiple($page_title_pattern, $types);
    }
  }
  else {
    $context['page_title'] = $context['title'] ? $context['title'] : $node->title;
  }
  if (is_null($context['node_body'])) {
    $context['node_body'] = $node->body;
  }

  // TODO: make this more robust to include CCK fields
  if (is_null($context['body'])) {
    $context['body'] = $context['node_body'];
  }
  if (variable_get('contentanalysis_node_parse_nodetitle_prepend', 1)) {
    $h = $context['title'];
    $p = variable_get('contentanalysis_node_parse_nodetitle_tags', '<h2>[node_title]</h2>');
    if (strpos($p, '[node_title]') !== FALSE) {
      $h = str_replace('[node_title]', $h, $p);
    }
    $context['body'] = "<h1>" . $h . "</h1> " . $context['body'];
  }
  if (is_null($context['body_notags'])) {
    $context['body_notags'] = strip_tags($context['body']);
  }
  if (isset($node->nodewords)) {
    if (is_null($context['meta_keywords'])) {
      $context['meta_keywords'] = $context['inputs']['meta_keywords'] ? $context['inputs']['meta_keywords'] : $node->nodewords['keywords'];
    }
    if (is_null($context['meta_description'])) {
      $context['meta_description'] = $context['inputs']['meta_description'] ? $context['inputs']['meta_description'] : $node->nodewords['description'];
    }
  }
  if (is_null($context['path'])) {
    $path = 'node/' . $context['nid'];
    $path_alias = drupal_get_path_alias($path);
    $context['path'] = $path_alias ? $path_alias : $path;
  }
  if (is_null($context['url'])) {
    $url = 'http';
    if ($_SERVER["HTTPS"] == "on") {
      $url .= "s";
    }
    $url .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
      $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"];
    }
    else {
      $url .= $_SERVER["SERVER_NAME"];
    }
    $url .= base_path();
    $url .= $context['path'];
    $context['url'] = $url;
  }
  return $context;
}