diff --git a/views/theme/views_views_json_style.theme.inc b/views/theme/views_views_json_style.theme.inc
index da61e45..5987f02 100644
--- a/views/theme/views_views_json_style.theme.inc
+++ b/views/theme/views_views_json_style.theme.inc
@@ -21,7 +21,7 @@ function template_preprocess_views_views_json_style_simple(&$vars) {
$top_child_object = $options["top_child_object"];
$plaintext_output = $options["plaintext_output"];
$objects = array();
-
+
// Create bitmask for json_encode.
$option_defs = $vars['view']->style_plugin->option_definition();
$bitmasks = $option_defs['encoding']['contains'];
@@ -45,12 +45,29 @@ function template_preprocess_views_views_json_style_simple(&$vars) {
$label = $plaintext_output ? strip_tags($field->id) : $field->id;
}
if (!$field->is_multiple) {
- $content = $plaintext_output ? strip_tags(html_entity_decode($field->content, ENT_QUOTES)) : $field->content;
- $content = mb_check_encoding($content, 'UTF-8') ? $content : utf8_encode($content);
+ if (is_array($field->content)) {
+ $content = array();
+ foreach ($field->content as $key => $value) {
+ $safe = $plaintext_output ? strip_tags(html_entity_decode($value, ENT_QUOTES)) : $value;
+ $safe = mb_check_encoding($safe, 'UTF-8') ? $safe : utf8_encode($safe);
+ $content[$key] = $safe;
+ }
+ } else {
+ $content = $plaintext_output ? strip_tags(html_entity_decode($field->content, ENT_QUOTES)) : $field->content;
+ $content = mb_check_encoding($content, 'UTF-8') ? $content : utf8_encode($content);
+ }
}
else {
$content = array();
- foreach ($field->content as $n => $oc) $content[$n] = ($plaintext_output ? strip_tags($oc) : $oc);
+ foreach ($field->content as $n => $oc) {
+ if (is_array($oc)) {
+ foreach ($oc as $key => $value) {
+ $content[$n][$key] = ($plaintext_output ? strip_tags($value) : $value);
+ }
+ } else {
+ $content[$n] = ($plaintext_output ? strip_tags($oc) : $oc);
+ }
+ }
}
}
elseif ($options["field_output"] == "raw") {
@@ -60,7 +77,15 @@ function template_preprocess_views_views_json_style_simple(&$vars) {
}
else {
$content = array();
- foreach ($field->raw as $n => $oc) $content[$n] = $plaintext_output ? strip_tags($oc) : $oc;
+ foreach ($field->raw as $n => $oc) {
+ if (is_array($oc)) {
+ foreach ($oc as $key => $value) {
+ $content[$n][$key] = ($plaintext_output ? strip_tags($value) : $value);
+ }
+ } else {
+ $content[$n] = ($plaintext_output ? strip_tags($oc) : $oc);
+ }
+ }
}
}
diff --git a/views_json.module b/views_json.module
index 6ddd2f4..4ae798a 100644
--- a/views_json.module
+++ b/views_json.module
@@ -171,18 +171,49 @@ function _views_json_render_fields($view, $row) {
$img_match = array();
$src_match = array();
- if (is_array($field_output)) {
- foreach ($field_output as $i => $f) {
- if (preg_match("/]+>/i", $f, $img_match)) {
- if (preg_match('/(src)="([^"]*)"/i', $img_match[0], $src_match))
- $field_output[$i] = ($src_match[2]);
+ if(isset($field->options['type'])){
+ if (is_array($field_output) && $field->options['type'] == 'image') {
+ foreach ($field_output as $i => $f) {
+ if (preg_match("/]+>/i", $f, $img_match)) {
+ if (preg_match('/(src)="([^"]*)"/i', $img_match[0], $src_match)) {
+ $field_output[$i]['src'] = $src_match[2];
+ $field_output[$i]['alt'] = '';
+
+ if (preg_match('/(alt)="([^"]*)"/i', $img_match[0], $alt_match)) {
+ $field_output[$i]['alt'] = $alt_match[2];
+ }
+ }
+ }
}
}
- }
- else {
- if (preg_match("/]+>/i", $field_output, $img_match)) {
- if (preg_match('/(src)="([^"]*)"/i', $img_match[0], $src_match))
- $field_output = ($src_match[2]);
+ else if ($field->options['type'] == 'image' ) {
+ // if field's type was an image. we just get the path.
+ if (preg_match_all("/]+>/i", $field_output, $img_matches)) {
+ $field_output = array();
+
+ if (sizeof($img_matches[0]) > 1) {
+ $field_is_multiple = TRUE;
+ foreach ( $img_matches[0] as $i => $img_match ) {
+ if (preg_match('/(src)="([^"]*)"/i', $img_match, $src_match)) {
+ $field_output[$i]['src'] = $src_match[2];
+ $field_output[$i]['alt'] = '';
+
+ if (preg_match('/(alt)="([^"]*)"/i', $img_match, $alt_match)) {
+ $field_output[$i]['alt'] = $alt_match[2];
+ }
+ }
+ }
+ } else {
+ if (preg_match('/(src)="([^"]*)"/i', $img_matches[0][0], $src_match)) {
+ $field_output['src'] = $src_match[2];
+ $field_output['alt'] = '';
+
+ if (preg_match('/(alt)="([^"]*)"/i', $img_matches[0][0], $alt_match)) {
+ $field_output['alt'] = $alt_match[2];
+ }
+ }
+ }
+ }
}
}