You are here

function contentanalysis_parse_context_node_edit in Content Analysis 6

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

Normalizes context data inputed by node edit form

Parameters

$the_context: Initialized context formated array

Return value

A normalized context array

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

File

./contentanalysis.module, line 631

Code

function contentanalysis_parse_context_node_edit($context) {

  // create dumby node from inputs
  if ($context['nid'] && is_numeric($context['nid'])) {
    $context['node'] = node_load($context['nid']);
  }
  if (!$context['node']) {
    global $user;
    $context['node'] = new stdClass();
    if ($context['nid'] && is_numeric($context['nid'])) {
      $context['node']->nid = $context['nid'];
    }
    $context['node']->status = 1;
    $context['node']->uid = $user->uid;
    $context['node']->created = time();
    $context['node']->changed = time();
    $context['node']->promote = 1;
    $context['node']->sticky = 0;
    $context['node']->language = 'en';
  }
  $context['node']->type = $context['inputs']['node_type'];
  $context['node']->title = $context['title'];
  $context['node']->body = $context['body'];
  $context['node']->teaser = node_teaser($context['body']);
  $context['node']->format = $context['inputs']['body_input_filter'];
  $context['node_body'] = $context['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'];
  }
  $context['body_notags'] = strip_tags($context['body']);
  if (!$context['page_title']) {
    $context['page_title'] = $context['title'];
  }
  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;
  }
  if (module_exists('nodewords')) {
    $default_nodewords = nodewords_load_tags();
    if (is_null($context['meta_description'])) {
      if (function_exists('nodewords_metatag_from_node_content')) {

        // function used in versions prior to 6.12.9
        $description = nodewords_metatag_from_node_content($context['node'], '');
      }
      elseif (function_exists('nodewords_metatag_from_node_content')) {

        // function new to 6.12.9
        $description = nodewords_metatag_from_teaser($context['node'], '');
      }
      if ($description) {
        $context['meta_description'] = $description;
      }
      else {
        $context['meta_description'] = $default_nodewords['description']['value'];
      }
    }
    if (is_null($context['meta_keywords'])) {
      $context['meta_keywords'] = $default_nodewords['keywords']['value'];
    }
  }
  return $context;
}