diff -u b/views/theme/views_views_json_style.theme.inc b/views/theme/views_views_json_style.theme.inc --- b/views/theme/views_views_json_style.theme.inc +++ b/views/theme/views_views_json_style.theme.inc @@ -236,7 +236,7 @@ } function template_preprocess_views_views_json_style_autocomplete(&$vars) { - // Use simple theme suggestion + // Use simple theme suggestion. $vars['theme_hook_suggestion'] = 'views_views_json_style_simple'; $view = $vars["view"]; @@ -248,8 +248,9 @@ $option_defs = $vars['view']->style_plugin->option_definition(); $bitmasks = $option_defs['encoding']['contains']; $bitmask = NULL; - foreach($bitmasks as $mask_key => $_bitmask) { - if(isset($options[$mask_key]) && $options[$mask_key] && !is_array($options[$mask_key])) { + foreach ($bitmasks as $mask_key => $_bitmask) { + $mask_options = &$options[$mask_key]; + if (isset($mask_options) && $mask_options && !is_array($mask_options)) { $bitmask = $bitmask | constant($_bitmask['bitmask']); } } @@ -257,17 +258,32 @@ $autocomplete = array(); foreach ($rows as $row) { - /* First field is the key and second is the value */ + // First field is the key and second is the value. $k = 0; foreach ($row as $field) { if ($options["field_output"] == "normal") { 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 ($plaintext_output) { + $decoded_content = html_entity_decode($field->content, ENT_QUOTES); + $content = strip_tags($decoded_content); + } + else { + $content = $field->content; + } + if (!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 ($plaintext_output) { + $content[$n] = strip_tags($oc); + } + else { + $content[$n] = $oc; + } + } } } elseif ($options["field_output"] == "raw") { @@ -276,16 +292,18 @@ } else { $content = array(); - foreach ($field->raw as $n => $oc) $content[$n] = $plaintext_output ? strip_tags($oc) : $oc; + foreach ($field->raw as $n => $oc) { + $content[$n] = $plaintext_output ? strip_tags($oc) : $oc; + } } } - // First field is the key + // First field is the key. if ($k++ == 0) { $label = $content; } else { - // Second field is value, so now we can stop + // Second field is value, so now we can stop. break; } }