function contentanalysis_parse_context_node_edit in Content Analysis 7
Same name and namespace in other branches
- 8 contentanalysis.module \contentanalysis_parse_context_node_edit()
- 6 contentanalysis.module \contentanalysis_parse_context_node_edit()
Normalizes context data inputted by node edit form
Parameters
$the_context: Initialized context formatted 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 655
Code
function contentanalysis_parse_context_node_edit($context, &$analysis) {
// create dummy node from inputs
if ($context['nid'] && is_numeric($context['nid'])) {
$context['node'] = node_load($context['nid']);
}
if (!array_key_exists('node', $context) || empty($context['node'])) {
$context['node'] = new stdClass();
$context['node']->type = 'article';
node_object_prepare($context['node']);
$context['node']->language = LANGUAGE_NONE;
}
$context['node']->title = $context['title'];
$context['node']->body[$context['node']->language][0]['value'] = $context['body'];
// Get teaser trim length if available from field.
if ($context['inputs']['body_summary']) {
$context['node']->body[$context['node']->language][0]['summary'] = $context['inputs']['body_summary'];
}
else {
if ($items = field_get_items('node', $context['node'], 'body')) {
$instance = field_info_instance('node', 'body', $context['node']->type);
$context['node']->body[$context['node']->language][0]['summary'] = text_summary($context['body'], $context['inputs']['body_input_filter'], $instance['display']['teaser']['settings']['trim_length']);
}
else {
$context['node']->body[$context['node']->language][0]['summary'] = text_summary($context['body'], $context['inputs']['body_input_filter']);
}
}
$context['node']->body[$context['node']->language][0]['format'] = $context['inputs']['body_input_filter'];
// force node_view to rebuild filtered node body
unset($context['node']->body[$context['node']->language][0]['safe_value']);
unset($context['node']->body[$context['node']->language][0]['safe_summary']);
$context['node_body'] = $context['body'];
// Extract node content if available.
if ($context['nid'] && is_numeric($context['nid'])) {
$node_view = node_view($context['node']);
$context['body'] = $node_view['body'][0]['#markup'];
}
else {
// Node has not been saved yet, just use $context['node']->body...
$context['body'] = $context['node']->body[$context['node']->language][0]['value'];
}
// prepend node title
if (variable_get('contentanalysis_node_parse_nodetitle_prepend', CONTENTANALYSIS_NODE_PARSE_NODETITLE_PREPEND_DEFAULT)) {
$h = $context['title'];
$p = variable_get('contentanalysis_node_parse_nodetitle_tags', CONTENTANALYSIS_NODE_PARSE_NODETITLE_TAGS_DEFAULT);
if (strpos($p, '[node:title]') !== FALSE) {
$h = str_replace('[node:title]', $h, $p);
}
$context['body'] = $h . "\n" . $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;
}
// Get Metatag context.
$context = contentanalysis_parse_context_metatags($context);
return $context;
}