function views_json_exhibit_render in Views Datasource 5
1 call to views_json_exhibit_render()
- theme_views_json_exhibit in ./views_json.module
File
- ./views_json.module, line 183
- views_json.module - provides Views plugin for rendering node content as JSON.
Code
function views_json_exhibit_render($vid, $nodes, $type) {
define('EXHIBIT_DATE_FORMAT', '%Y-%m-%d %H:%M:%S');
$view = views_load_view($vid);
$result = views_build_view('items', $view);
$fields = _views_get_fields();
$json = "{\n" . '"items"' . " : " . "\n" . str_repeat(" ", 4) . "[\n";
$total_node_count = count((array) $nodes);
$node_count = 0;
foreach ($nodes as $node) {
$json .= str_repeat(" ", 8) . "{\n";
$json .= str_repeat(" ", 12) . '"type" ' . " " . ": " . '"' . '##type##' . '",' . "\n";
$json .= str_repeat(" ", 12) . '"label" ' . " " . " : " . '"' . '##label##' . '",' . "\n";
$total_field_count = count((array) $view->field);
$field_count = 0;
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== false) {
$label = $field['label'] ? $field['label'] : $fields[$field['fullname']]['name'];
$label = trim(views_json_strip_illegal_chars(views_json_encode_special_chars($label)));
$value = trim(views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view));
if (is_null($value) || $value == '') {
continue;
}
$value = views_json_encode_special_chars($value);
$label = str_replace("Profile ", '', $label);
if ($label == 'type') {
$json = str_replace('##type##', $value, $json);
}
elseif ($label == 'label') {
$json = str_replace('##label##', $value, $json);
}
else {
$json .= str_repeat(" ", 12) . '"' . $label . '"' . " " . ": " . '"' . $value . '"' . (++$field_count == $total_field_count ? "" : ",") . "\n";
}
}
}
if (strpos($json, '##type##') !== false) {
$json = str_replace('##type##', isset($node->type) ? $node->type : 'Item', $json);
}
if (strpos($json, '##label##') !== false) {
$json = str_replace('##label##', isset($node->title) ? $node->title : 'none', $json);
}
$json .= str_repeat(" ", 8) . "}" . (++$node_count == $total_node_count ? "" : ",") . "\n\n";
}
$json .= str_repeat(" ", 4) . "]\n}";
drupal_set_header('Content-Type: text/javascript');
print $json;
module_invoke_all('exit');
exit;
}