function contemplate_array_variables in Content Templates (Contemplate) 7
Same name and namespace in other branches
- 5 contemplate.module \contemplate_array_variables()
- 6 contemplate.module \contemplate_array_variables()
Recursive (and therefore magical) function goes through node object returns html representation of the node strings are clickable and insert into teaser/body fields
Parameters
$array: array to recurse through
$target: target field for javascript insert
$parents: used by recursion
$object: used by recursion
Return value
string - html dictionary list of $node elements
1 call to contemplate_array_variables()
- contemplate_examples in ./
contemplate.module - Load an example node and display its parts
File
- ./
contemplate.module, line 748 - Create templates to customize teaser and body content.
Code
function contemplate_array_variables($array, $target, $parents = FALSE, $object = FALSE, $depth = 0, &$recursion_limit_hit) {
global $_contemplate_fids;
if ($depth >= variable_get('contemplate_max_recursion_depth', 10)) {
$recursion_limit_hit++;
return '';
}
/**
* CCK fields are causing problems, they are added into the original array as $array['field_*']=>array();
* and they are also added into $array['content']['field_*']=>array() this array has not only
* the information for the CCK field, but also information for the whole node , even itself,
* $array['content']['field_*']['#node'] recursively, this leads to memory issues while traversing
* the array recursively
* Drupal 6
*/
if (isset($array['content']) && $parents == FALSE && $object == FALSE) {
// by default we will remove the content array, the user can choose to have this not done
if (variable_get('contemplate_remove_node_content', FALSE)) {
unset($array['content']);
}
}
if (is_object($array)) {
$array = (array) $array;
}
if (is_array($array)) {
$output = "<dl>\n";
foreach ($array as $field => $value) {
if ($parents) {
if ($object) {
$field = $parents . '->' . $field;
}
else {
if (is_int($field)) {
$field = $parents . '[' . $field . ']';
}
elseif ($field == 'und') {
// show $node->language for insertion into template http://drupal.org/node/1040748
$field = $parents . '[$node->language]';
}
else {
if ($field == 'fid') {
// make a note of the fields named "fid"
$_contemplate_fids[] = "\$node->" . $parents . '[\'' . $field . '\']';
}
$field = $parents . '[\'' . $field . '\']';
}
}
}
$type = '';
if (!is_string($value)) {
$type = ' (' . gettype($value) . ')';
}
if (!is_array($value) && !is_object($value)) {
if ($field == 'title' || drupal_substr($field, -9) == "['value']") {
$security = t('<span style="color:red;font-weight:bold">**</span>');
$insert = "'<?php print check_plain(\$node->" . addslashes($field) . ") ?>'";
}
else {
$security = '';
$insert = "'<?php print \$node->" . addslashes($field) . " ?>'";
}
$output .= "<dt><a href=\"#\" onclick=\"return insertAtCursor(document.getElementById('edit-{$target}'), {$insert});\" title=\"insert this variable into {$target}\">\$node->{$field}</a>{$security}{$type}</dt>\n";
}
else {
$output .= "<dt>\$node->{$field}{$type}</dt>\n";
}
$output .= "<dd>\n";
if (is_array($value)) {
$output .= contemplate_array_variables($value, $target, $field, FALSE, $depth + 1, $recursion_limit_hit);
}
elseif (is_object($value)) {
$output .= contemplate_array_variables((array) $value, $target, $field, TRUE, $depth + 1, $recursion_limit_hit);
}
else {
$value = is_bool($value) ? $value ? 'TRUE' : 'FALSE' : $value;
$output .= htmlspecialchars(print_r($value, TRUE)) . "\n";
}
$output .= "</dd>\n";
}
$output .= "</dl>\n";
}
return $output;
}