function _process()
 {
     $urlSeparator = "_";
     $simple_search = Sanitize::getInt($this->data, 'simple_search');
     $keywords = Sanitize::getVar($this->data, 'keywords');
     $criteria = isset($this->data['Search']) ? Sanitize::getInt($this->data['Search'], 'criteria_id') : null;
     $dir = str_replace(array(',', ' '), array($urlSeparator, ''), Sanitize::getString($this->data, 'dir'));
     $cat = str_replace(array(',', ' '), array($urlSeparator, ''), Sanitize::getString($this->data, 'cat'));
     $section = str_replace(array(',', ' '), array($urlSeparator, ''), Sanitize::getString($this->data, 'section'));
     /*J15*/
     $order = Sanitize::getVar($this->data, 'order');
     $query_type = Sanitize::getVar($this->data, 'search_query_type');
     $scope = Sanitize::getVar($this->data, 'contentoptions');
     $author = Sanitize::getString($this->data, 'author');
     $categories = Sanitize::getVar($this->data, 'categories');
     $menu_id = Sanitize::getInt($this->data, 'menu_id');
     $tmpl_suffix = Sanitize::getString($this->data, 'tmpl_suffix');
     $illegal_chars = array('#', '/', '?', ':', urldecode('%E3%80%80'));
     // Last one is japanese double space
     $sort = '';
     # Load Routes helper
     App::import('Helper', 'routes', 'jreviews');
     $Routes = new RoutesHelper();
     // Replace ampersands with temp string to be replaced back as urlencoded ampersand further below
     $keywords = str_replace(array_keys($this->KeywordReplacementMask), array_values($this->KeywordReplacementMask), $keywords);
     # Get the Itemid
     $menu_id_param = $menu_id > 0 ? $menu_id : '';
     $url_params = '';
     # SIMPLE SEARCH
     if ($simple_search) {
         # Build the query string
         if (trim($keywords) != '') {
             $url_params .= (cmsFramework::mosCmsSef() ? '' : '/') . 'keywords' . _PARAM_CHAR . str_replace(' ', '+', urlencode(str_replace($illegal_chars, ' ', $keywords)));
         }
         !empty($dir) and $url_params .= "/dir" . _PARAM_CHAR . $dir;
         !empty($section) and $url_params .= "/cat" . _PARAM_CHAR . 's' . $section;
         /*J15*/
         !empty($cat) and $url_params .= "/cat" . _PARAM_CHAR . $cat;
         !empty($tmpl_suffix) and $url_params .= '/tmpl_suffix' . _PARAM_CHAR . $tmpl_suffix;
         !empty($order) and $sort = '/order' . _PARAM_CHAR . $order;
         # Checks if need to keep the Itemid on the result page
         if ($this->Config->search_itemid && $menu_id) {
             $url = $Routes->search_results($menu_id_param, '');
         } else {
             $url = $Routes->search_results(null, '');
         }
         $url = cmsFramework::route($url . $url_params . $sort);
         $url = str_replace(array_keys($this->KeywordReplacementUrl), array_values($this->KeywordReplacementUrl), $url);
         cmsFramework::redirect($url);
         exit;
     }
     # ADVANCED SEARCH
     $url_params = array();
     $criteria_param = $criteria ? (cmsFramework::mosCmsSef() ? '' : '/') . 'criteria:' . $criteria : '';
     // Search query type
     !empty($query_type) and $url_params[] = "query" . _PARAM_CHAR . $query_type;
     !empty($dir) != '' and $url_params[] = "dir" . _PARAM_CHAR . $dir;
     // Listing and reviews
     if ($keywords) {
         if ($scope) {
             $url_params[] = "scope" . _PARAM_CHAR . urlencode(implode($urlSeparator, $scope));
         }
         $url_params[] = "keywords" . _PARAM_CHAR . urlencode(str_replace($illegal_chars, ' ', $keywords));
     }
     // Author
     !empty($author) and $url_params[] = "author" . _PARAM_CHAR . urlencode($author);
     // Categories
     if (is_array($categories)) {
         // Remove empty values from array
         foreach ($categories as $index => $value) {
             if (empty($value)) {
                 unset($categories[$index]);
             }
         }
         if (!empty($categories)) {
             $cat = urlencode(implode($urlSeparator, $categories));
             !empty($cat) and $url_params[] = "cat" . _PARAM_CHAR . $cat;
         }
     } elseif ($categories != '') {
         // Single select category list
         !empty($categories) and $url_params[] = "cat" . _PARAM_CHAR . $categories;
     }
     // First pass to process numeric values, need to merge operator and operand into one parameter
     if (isset($this->data['Field'])) {
         foreach ($this->data['Field']['Listing'] as $key => $value) {
             if (substr($key, -9, 9) == '_operator') {
                 $operand = substr($key, 0, -9);
                 if (is_array($this->data['Field']['Listing'][$operand]) && is_numeric($this->data['Field']['Listing'][$operand][0]) || is_numeric($this->data['Field']['Listing'][$operand])) {
                     $this->data['Field']['Listing'][$operand] = $value . $urlSeparator . trim(implode('_', $this->data['Field']['Listing'][$operand]));
                 } elseif (is_array($this->data['Field']['Listing'][$operand]) && trim($this->data['Field']['Listing'][$operand][0]) != '' || !is_array($this->data['Field']['Listing'][$operand]) && trim($this->data['Field']['Listing'][$operand]) != '') {
                     // Assume it's a date field
                     $this->data['Field']['Listing'][$operand] = $value . $urlSeparator . "date_" . implode('_', $this->data['Field']['Listing'][$operand]);
                 } else {
                     $this->data['Field']['Listing'][$operand] = '';
                 }
                 // Remove trailing separator char
                 $this->data['Field']['Listing'][$operand] = rtrim($this->data['Field']['Listing'][$operand], $urlSeparator);
             }
         }
         // Second pass to process everything
         foreach ($this->data['Field']['Listing'] as $key => $value) {
             $key_parts = explode("_", $key);
             $imploded_value = '';
             if (substr($key, 0, 3) == "jr_" && substr($key, -9, 9) != '_operator' && @$key_parts[2] != 'reset') {
                 // multiple option field
                 if (is_array($value)) {
                     if (is_array($value[0]) && !empty($value[0])) {
                         $imploded_value = implode($urlSeparator, $value[0]);
                     } elseif (!is_array($value[0]) && implode('', $value) != '') {
                         $imploded_value = implode($urlSeparator, $value);
                     }
                     if ($key != '' && $imploded_value != '') {
                         $url_params[] = "{$key}" . _PARAM_CHAR . urlencode(trim($imploded_value));
                     }
                     // single option field
                 } elseif (!is_array($value) && trim($value) != '') {
                     $url_params[] = "{$key}" . _PARAM_CHAR . urlencode(trim($value));
                 }
             }
         }
     }
     // End isset $this->Data['Field']
     !empty($tmpl_suffix) and $url_params[] = 'tmpl_suffix' . _PARAM_CHAR . $tmpl_suffix;
     $url_params[] = "order" . _PARAM_CHAR . ($order ? $order : $this->Config->list_order_default);
     # Remove empty values from array
     foreach ($url_params as $index => $value) {
         if (empty($value)) {
             unset($url_params[$index]);
         }
     }
     $url_params = (cmsFramework::mosCmsSef() ? '' : '/') . implode('/', $url_params);
     # Uncomment this line and comment the one below to keep the Itemid on the result page
     if ($this->Config->search_itemid && $menu_id) {
         $url = $Routes->search_results($menu_id_param, '');
     } else {
         $url = $Routes->search_results(null, '');
     }
     // Params outside route function because it messes up the urlencoding
     $url = cmsFramework::route($url . $criteria_param . $url_params);
     $url = str_replace(array_keys($this->KeywordReplacementUrl), array_values($this->KeywordReplacementUrl), $url);
     cmsFramework::redirect($url);
 }
Example #2
0
 /**
  * Creates the json object used for map rendering
  *     
  * @param array $results listings
  * @param mixed $fields  custom fields, required when using the GeoMaps module
  * @param mixed $options mapUI options to override globals when using GeoMaps module
  */
 function makeJsonObject(&$results, &$fields = array(), $options = array())
 {
     $www_base = array_shift(pathinfo(WWW_ROOT));
     // Required for thumbnail path
     $paths = array(S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . 'default' . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . 'default' . DS . 'theme_images' . DS);
     $path = fileExistsInPath(array('name' => '', 'suffix' => '', 'ext' => ''), $paths);
     App::import('Helper', array('html', 'routes', 'custom_fields', 'thumbnail'));
     $Html = new HtmlHelper();
     $Routes = new RoutesHelper();
     $CustomFields = new CustomFieldsHelper();
     $Thumbnail = new ThumbnailHelper();
     $Thumbnail->app = 'jreviews';
     $Thumbnail->name = $this->c->name;
     $Thumbnail->action = $this->c->action;
     $Routes->Config = $CustomFields->Config = $Thumbnail->Config = $this->c->Config;
     $Routes->Access = $CustomFields->Access = $Thumbnail->Access = $this->c->Access;
     $Routes->Html = $CustomFields->Html = $Thumbnail->Html = $Html;
     $CustomFields->viewTheme = $Thumbnail->viewTheme =& $this->c->viewTheme;
     $CustomFields->viewSuffix =& $this->c->viewSuffix;
     // Check format of results because we may need to re-format and add fields for Geomaps module
     $first = current($results);
     if (!isset($first['Listing'])) {
         $results = $this->buildListingArray($results, $fields);
     }
     // PaidListings - remove unpaid info
     Configure::read('PaidListings') and PaidListingsComponent::processPaidData($results);
     $marker_icons = array();
     $infowindow_data = array();
     $i = 1;
     $map_counter = 0;
     $default_icon = $this->c->name == 'categories' ? 'numbered' : 'default';
     if (!empty($results)) {
         $infowindow_fields = str_replace(" ", "", Sanitize::getString($this->c->Config, 'geomaps.infowindow_fields'));
         $infowindow_fields = $infowindow_fields != '' ? explode(",", $infowindow_fields) : array();
         foreach ($results as $key => $result) {
             $results[$key] = $this->injectDistanceGroup($result);
             // Override global setting for map display in lists if at least one listing has map enabled
             // For it's listing type and has valid coordinates
             if ($this->c->name == 'categories' && isset($result['ListingType']) && Sanitize::getBool($result['ListingType']['config'], 'geomaps.enable_map_list', true)) {
                 if (isset($result['Geomaps']) && abs($result['Geomaps']['lat']) > 0 && abs($result['Geomaps']['lon']) > 0) {
                     $map_counter++;
                 }
             }
             // Add menu id if not already there
             if (!isset($result['Listing']['menu_id'])) {
                 $results[$key]['Listing']['menu_id'] = $this->c->Menu->getCategory(array('cat_id' => $result['Listing']['cat_id'], 'dir_id' => $result['Directory']['dir_id'], 'section_id' => isset($result['Listing']['section_id']) ? $result['Listing']['section_id'] : null, 'listing' => $result['Listing']['listing_id']));
             }
             $listing_index = ($this->c->page - 1) * $this->c->limit + $i++;
             // Process and add icon info
             $icon = isset($result['Geomaps']) ? json_decode($result['Geomaps']['icon'], true) : array();
             $results[$key]['Geomaps']['icon'] = '';
             $icon_name = $default_icon;
             if (!empty($icon)) {
                 $foundIcon = false;
                 // Check if custom field assigned
                 if ($icon['field'] != '' && substr($icon['field'], 0, 3) == 'jr_') {
                     if (isset($result['Field']['pairs'][$icon['field']]) && isset($result['Field']['pairs'][$icon['field']]['image'][0])) {
                         $icon_name = substr($result['Field']['pairs'][$icon['field']]['image'][0], 0, strpos($result['Field']['pairs'][$icon['field']]['image'][0], '.'));
                         $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $result['Field']['pairs'][$icon['field']]['image'][0];
                         $foundIcon = true;
                     }
                 } elseif ($icon['cat'] != '' && !$foundIcon) {
                     $icon_name = substr($icon['cat'], 0, strpos($icon['cat'], '.'));
                     if ($icon_name != 'default') {
                         $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $icon['cat'];
                     }
                 }
             }
             if (isset($result['Geomaps']) && $result['Geomaps']['lat'] != '' && $result['Geomaps']['lon'] != '' && $result['Geomaps']['lat'] != 0 && $result['Geomaps']['lon']) {
                 # Create infowindow JSON object
                 // start with standard fields
                 $infowindow = array('id' => $result['Listing']['listing_id'], 'url' => str_replace(array($www_base, '&'), array('', '&'), $Routes->content('', $results[$key], array('return_url' => true))), 'index' => $listing_index, 'title' => $result['Listing']['title'], 'image' => str_replace($www_base, '', $Thumbnail->thumb($result, 0, array('tn_mode' => $this->c->Config->list_thumb_mode, 'location' => 'list', 'dimensions' => array($this->c->Config->list_image_resize), 'return_src' => 1))), 'featured' => $result['Listing']['featured'], 'rating_scale' => $this->c->Config->rating_scale, 'user_rating' => $result['Review']['user_rating'], 'user_rating_count' => $result['Review']['user_rating_count'], 'editor_rating' => $result['Review']['editor_rating'], 'editor_rating_count' => $result['Review']['editor_rating_count'], 'lat' => (double) $result['Geomaps']['lat'], 'lon' => (double) $result['Geomaps']['lon'], 'icon' => $icon_name);
                 if (!empty($result['Field']['pairs'])) {
                     # Limit fields will included in the payload json object
                     $result['Field']['pairs'] = array_intersect_key($result['Field']['pairs'], array_flip($infowindow_fields));
                     foreach ($result['Field']['pairs'] as $name => $fieldArray) {
                         $infowindow['field'][$name] = $CustomFields->field($name, $result);
                     }
                 }
                 $infowindow_data['id' . $result['Listing']['listing_id']] = $infowindow;
             }
         }
     }
     $this->c->Config->{'geomaps.enable_map_list'} = $map_counter;
     $mapUI = array();
     $zoom = '';
     switch ($this->c->name) {
         case 'categories':
             $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_list', 'buttons');
             //buttons|menu|none
             $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_list', 'G_NORMAL_MAP');
             $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_list', 1);
             $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_list', 1);
             $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_list', 1);
             $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_list', 1);
             $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_list', 1);
             $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_list', 0);
             $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_list', 0);
             $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_list', 1);
             $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_list', 0);
             $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30);
             break;
         case 'com_content':
             $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_detail', 'buttons');
             //buttons|menu|none
             $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_detail', 'G_NORMAL_MAP');
             $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_detail', 1);
             $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_detail', 1);
             $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_detail', 1);
             $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_detail', 1);
             $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_detail', 1);
             $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_detail', 0);
             $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_detail', 0);
             $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_detail', 1);
             $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', '');
             $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_detail', 0);
             $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30);
             break;
         case 'module_geomaps':
             $maptypes = Sanitize::getString($options, 'ui_maptype', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_module', 'buttons') : Sanitize::getString($options, 'ui_maptype');
             //buttons|menu|none
             $maptype_def = Sanitize::getString($options, 'ui_maptype_def', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_module', 'G_NORMAL_MAP') : Sanitize::getString($options, 'ui_maptype_def', 'G_NORMAL_MAP');
             $map = Sanitize::getInt($options, 'ui_map', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.map_module', 1) : Sanitize::getBool($options, 'ui_map');
             $hybrid = Sanitize::getInt($options, 'ui_hybrid', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_module', 1) : Sanitize::getBool($options, 'ui_hybrid');
             $satellite = Sanitize::getInt($options, 'ui_satellite', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_module', 1) : Sanitize::getBool($options, 'ui_satellite');
             $terrain = Sanitize::getInt($options, 'ui_terrain', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_module', 1) : Sanitize::getBool($options, 'ui_terrain');
             $panzoom = Sanitize::getInt($options, 'ui_panzoom', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_module', 1) : Sanitize::getBool($options, 'ui_panzoom');
             $scale = Sanitize::getInt($options, 'ui_scale', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_module', 0) : Sanitize::getBool($options, 'ui_scale');
             $scrollwheel = Sanitize::getInt($options, 'ui_scrollwheel', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_module', 0) : Sanitize::getBool($options, 'ui_scrollwheel');
             $doubleclick = Sanitize::getInt($options, 'ui_doubleclick', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_module', 1) : Sanitize::getBool($options, 'ui_doubleclick');
             $mapUI['title']['trim'] = Sanitize::getInt($options, 'ui_trimtitle_module', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.trimtitle_module', 30) : Sanitize::getBool($options, 'ui_trimtitle_module');
             $mapUI['title']['trimchars'] = Sanitize::getInt($options, 'ui_trimtitle_chars', 2) == '2' ? Sanitize::getInt($this->c->Config, 'geomaps.ui.trimtitle_chars', 30) : Sanitize::getInt($options, 'ui_trimtitle_chars');
             if (Sanitize::getString($options, 'detail_view', 1)) {
                 $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', '');
             }
             break;
     }
     switch ($maptypes) {
         case 'buttons':
             $mapUI['controls']['maptypecontrol'] = true;
             $mapUI['controls']['menumaptypecontrol'] = false;
             break;
         case 'menu':
             $mapUI['controls']['maptypecontrol'] = false;
             $mapUI['controls']['menumaptypecontrol'] = true;
             break;
         default:
             $mapUI['controls']['maptypecontrol'] = false;
             $mapUI['controls']['menumaptypecontrol'] = false;
     }
     $mapUI['maptypes']['def'] = $maptype_def;
     $mapUI['maptypes']['map'] = $map;
     $mapUI['maptypes']['hybrid'] = $hybrid;
     $mapUI['maptypes']['satellite'] = $satellite;
     $mapUI['maptypes']['terrain'] = $terrain;
     if ($panzoom) {
         $mapUI['controls']['smallzoomcontrol3d'] = true;
         $mapUI['controls']['largemapcontrol3d'] = true;
     } else {
         $mapUI['controls']['smallzoomcontrol3d'] = false;
         $mapUI['controls']['largemapcontrol3d'] = false;
     }
     $mapUI['controls']['scalecontrol'] = $scale;
     $mapUI['zoom']['scrollwheel'] = $scrollwheel;
     $mapUI['zoom']['doubleclick'] = $doubleclick;
     $mapUI['zoom']['start'] = $zoom;
     $mapUI['anchor']['x'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_x', 0);
     $mapUI['anchor']['y'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_y', 0);
     unset($Html, $Routes, $CustomFields, $Thumbnail);
     return json_encode(array('count' => count($infowindow_data), 'mapUI' => $mapUI, 'infowindow' => Sanitize::getString($this->c->Config, 'geomaps.infowindow', '_google'), 'icons' => $this->processIcons($marker_icons), 'payload' => $infowindow_data));
 }
Example #3
0
 /**
  * Creates the json object used for map rendering
  *     
  * @param array $results listings
  * @param mixed $fields  custom fields, required when using the GeoMaps module
  * @param mixed $options mapUI options to override globals when using GeoMaps module
  */
 function makeJsonObject(&$results, &$fields = array(), $options = array())
 {
     $www_base = array_shift(pathinfo(WWW_ROOT));
     // Required for thumbnail path
     $paths = array(S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . 'default' . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . 'default' . DS . 'theme_images' . DS);
     $path = fileExistsInPath(array('name' => '', 'suffix' => '', 'ext' => ''), $paths);
     App::import('Helper', array('html', 'routes', 'custom_fields', 'thumbnail'));
     $Html = new HtmlHelper();
     $Routes = new RoutesHelper();
     $CustomFields = new CustomFieldsHelper();
     $Thumbnail = new ThumbnailHelper();
     $Thumbnail->app = 'jreviews';
     $Thumbnail->name = $this->c->name;
     $Thumbnail->action = $this->c->action;
     $Routes->Config = $CustomFields->Config = $Thumbnail->Config = $this->c->Config;
     $Routes->Access = $CustomFields->Access = $Thumbnail->Access = $this->c->Access;
     $Routes->Html = $CustomFields->Html = $Thumbnail->Html = $Html;
     $CustomFields->viewTheme = $Thumbnail->viewTheme =& $this->c->viewTheme;
     $CustomFields->viewSuffix =& $this->c->viewSuffix;
     // Check format of results because we may need to re-format and add fields for Geomaps module
     $first = current($results);
     if (!isset($first['Listing'])) {
         $results = $this->buildListingArray($results, $fields);
     }
     // PaidListings - remove unpaid info
     Configure::read('PaidListings') and PaidListingsComponent::processPaidData($results);
     $marker_icons = array();
     $infowindow_data = array();
     $i = 1;
     $default_icon = $this->c->name == 'categories' ? 'numbered' : 'default';
     // make sure we only have the numeric part of the id from request when checking against listing ids
     $request_id = explode(':', JRequest::getVar('id'));
     $request_id = $request_id[0];
     if (!empty($results)) {
         foreach ($results as $key => $result) {
             $results[$key] = $this->injectDistanceGroup($result);
             // Add menu id if not already there
             if (!isset($result['Listing']['menu_id'])) {
                 $results[$key]['Listing']['menu_id'] = $this->c->Menu->getCategory($result['Listing']['cat_id'], $result['Listing']['section_id'], $result['Directory']['dir_id'], $result['Listing']['listing_id']);
             }
             // Added to support extra coordinates
             //$coords = $result["Field"]["groups"]["Location Info"]["Fields"]["jr_extracoords"]["value"][0];
             //$xtracoords = $CustomFields->field('jr_extracoords', $listing, false, false);
             if (isset($result["Field"]["groups"]["Location Info"]) && isset($result["Field"]["groups"]["Location Info"]["Fields"]["jr_extracoords"])) {
                 $coords = $result["Field"]["groups"]["Location Info"]["Fields"]["jr_extracoords"]["value"][0];
                 if ($coords) {
                     $coords = json_decode($coords);
                     $results[$key]["ExtraCoords"] = $coords;
                     if (JRequest::getString("option") != "com_content") {
                         $results[$key]["ExtraCoords"] = 0;
                     }
                     // HTGMOD
                 }
             } elseif (isset($result["Field"]["pairs"]["jr_extracoords"])) {
                 //detail page
                 $coords = $result["Field"]["pairs"]["jr_extracoords"]["value"][0];
                 if ($coords) {
                     $coords = json_decode($coords);
                     $results[$key]["ExtraCoords"] = $coords;
                     if ($results[$key]["Listing"]["listing_id"] != $request_id) {
                         // "if the current listing_id in the loop == the listing_id being viewed on the detail page...."
                         $results[$key]["ExtraCoords"] = 0;
                     }
                 }
             }
             $listing_index = ($this->c->page - 1) * $this->c->limit + $i++;
             // Process and add icon info
             $icon = isset($result['Geomaps']) ? json_decode($result['Geomaps']['icon'], true) : array();
             $results[$key]['Geomaps']['icon'] = '';
             $icon_name = $default_icon;
             if (!empty($icon)) {
                 $foundIcon = false;
                 // Check if custom field assigned
                 if ($icon['field'] != '' && substr($icon['field'], 0, 3) == 'jr_') {
                     if (isset($result['Field']['pairs'][$icon['field']]) && isset($result['Field']['pairs'][$icon['field']]['image'][0])) {
                         $icon_name = substr($result['Field']['pairs'][$icon['field']]['image'][0], 0, strpos($result['Field']['pairs'][$icon['field']]['image'][0], '.'));
                         $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $result['Field']['pairs'][$icon['field']]['image'][0];
                         $foundIcon = true;
                     }
                 } elseif ($icon['cat'] != '' && !$foundIcon) {
                     $icon_name = substr($icon['cat'], 0, strpos($icon['cat'], '.'));
                     if ($icon_name != 'default') {
                         $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $icon['cat'];
                     }
                 }
             }
             if (isset($result['Geomaps']) && $result['Geomaps']['lat'] != '' && $result['Geomaps']['lon'] != '' && $result['Geomaps']['lat'] != 0 && $result['Geomaps']['lon']) {
                 # Create infowindow JSON object
                 // start with standard fields
                 $infowindow = array('id' => $result['Listing']['listing_id'], 'url' => str_replace(array($www_base, '&'), array('', '&'), $Routes->content('', $results[$key], array('return_url' => true))), 'index' => $listing_index, 'title' => $result['Listing']['title'], 'image' => str_replace($www_base, '', $Thumbnail->thumb($result, 0, 'scale', 'list', array($this->c->Config->list_image_resize), array('return_src' => 1))), 'featured' => $result['Listing']['featured'], 'rating_scale' => $this->c->Config->rating_scale, 'user_rating' => $result['Review']['user_rating'], 'user_rating_count' => $result['Review']['user_rating_count'], 'editor_rating' => $result['Review']['editor_rating'], 'editor_rating_count' => $result['Review']['editor_rating_count'], 'lat' => (double) $result['Geomaps']['lat'], 'lon' => (double) $result['Geomaps']['lon'], 'icon' => $icon_name);
                 // Added for Hooked
                 $infowindow['criteria_id'] = $result['Criteria']['criteria_id'];
                 if (isset($results[$key]["ExtraCoords"])) {
                     $infowindow['extracoords'] = $results[$key]["ExtraCoords"];
                 }
                 if (isset($results[$key]['Listing']['relations'])) {
                     $infowindow['relations'] = $results[$key]['Listing']['relations'];
                 }
                 if ($results[$key]['Listing']['section_id'] != 1) {
                     $infowindow['hascontent'] = 1;
                 } else {
                     if (isset($results[$key]['Listing']['summary']) && $results[$key]['Listing']['summary'] != '') {
                         $infowindow['hascontent'] = 1;
                     } else {
                         $infowindow['hascontent'] = 0;
                     }
                 }
                 if (!empty($result['Field']['pairs'])) {
                     foreach ($result['Field']['pairs'] as $name => $fieldArray) {
                         $infowindow['field'][$name] = $CustomFields->field($name, $result);
                     }
                 }
                 $infowindow_data['id' . $result['Listing']['listing_id']] = $infowindow;
             }
         }
     }
     $mapUI = array();
     $zoom = '';
     switch ($this->c->name) {
         case 'categories':
             $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_list', 'buttons');
             //buttons|menu|none
             $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_list', 'G_NORMAL_MAP');
             $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_list', 1);
             $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_list', 1);
             $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_list', 1);
             $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_list', 1);
             $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_list', 1);
             $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_list', 0);
             $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_list', 0);
             $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_list', 1);
             $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_list', 0);
             $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30);
             break;
         case 'com_content':
             $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_detail', 'buttons');
             //buttons|menu|none
             $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_detail', 'G_NORMAL_MAP');
             $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_detail', 1);
             $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_detail', 1);
             $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_detail', 1);
             $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_detail', 1);
             $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_detail', 1);
             $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_detail', 0);
             $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_detail', 0);
             $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_detail', 1);
             $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', '');
             $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_detail', 0);
             $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30);
             break;
         case 'module_geomaps':
             $maptypes = Sanitize::getString($options, 'ui_maptype', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_module', 'buttons') : Sanitize::getString($options, 'ui_maptype');
             //buttons|menu|none
             $maptype_def = Sanitize::getString($options, 'ui_maptype_def', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_module', 'G_NORMAL_MAP') : Sanitize::getString($options, 'ui_maptype_def', 'G_NORMAL_MAP');
             $map = Sanitize::getInt($options, 'ui_map', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.map_module', 1) : Sanitize::getBool($options, 'ui_map');
             $hybrid = Sanitize::getInt($options, 'ui_hybrid', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_module', 1) : Sanitize::getBool($options, 'ui_hybrid');
             $satellite = Sanitize::getInt($options, 'ui_satellite', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_module', 1) : Sanitize::getBool($options, 'ui_satellite');
             $terrain = Sanitize::getInt($options, 'ui_terrain', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_module', 1) : Sanitize::getBool($options, 'ui_terrain');
             $panzoom = Sanitize::getInt($options, 'ui_panzoom', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_module', 1) : Sanitize::getBool($options, 'ui_panzoom');
             $scale = Sanitize::getInt($options, 'ui_scale', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_module', 0) : Sanitize::getBool($options, 'ui_scale');
             $scrollwheel = Sanitize::getInt($options, 'ui_scrollwheel', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_module', 0) : Sanitize::getBool($options, 'ui_scrollwheel');
             $doubleclick = Sanitize::getInt($options, 'ui_doubleclick', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_module', 1) : Sanitize::getBool($options, 'ui_doubleclick');
             $mapUI['title']['trim'] = Sanitize::getInt($options, 'ui_trimtitle_module', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.trimtitle_module', 30) : Sanitize::getBool($options, 'ui_trimtitle_module');
             $mapUI['title']['trimchars'] = Sanitize::getInt($options, 'ui_trimtitle_chars', 2) == '2' ? Sanitize::getInt($this->c->Config, 'geomaps.ui.trimtitle_chars', 30) : Sanitize::getInt($options, 'ui_trimtitle_chars');
             if (Sanitize::getString($options, 'detail_view', 1)) {
                 $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', '');
             }
             break;
     }
     switch ($maptypes) {
         case 'buttons':
             $mapUI['controls']['maptypecontrol'] = true;
             $mapUI['controls']['menumaptypecontrol'] = false;
             break;
         case 'menu':
             $mapUI['controls']['maptypecontrol'] = false;
             $mapUI['controls']['menumaptypecontrol'] = true;
             break;
         default:
             $mapUI['controls']['maptypecontrol'] = false;
             $mapUI['controls']['menumaptypecontrol'] = false;
     }
     $mapUI['maptypes']['def'] = $maptype_def;
     $mapUI['maptypes']['map'] = $map;
     $mapUI['maptypes']['hybrid'] = $hybrid;
     $mapUI['maptypes']['satellite'] = $satellite;
     $mapUI['maptypes']['terrain'] = $terrain;
     if ($panzoom) {
         $mapUI['controls']['smallzoomcontrol3d'] = true;
         $mapUI['controls']['largemapcontrol3d'] = true;
     } else {
         $mapUI['controls']['smallzoomcontrol3d'] = false;
         $mapUI['controls']['largemapcontrol3d'] = false;
     }
     $mapUI['controls']['scalecontrol'] = $scale;
     $mapUI['zoom']['scrollwheel'] = $scrollwheel;
     $mapUI['zoom']['doubleclick'] = $doubleclick;
     $mapUI['zoom']['start'] = $zoom;
     $mapUI['anchor']['x'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_x', 0);
     $mapUI['anchor']['y'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_y', 0);
     unset($Html, $Routes, $CustomFields, $Thumbnail);
     return json_encode(array('count' => count($infowindow_data), 'mapUI' => $mapUI, 'infowindow' => Sanitize::getString($this->c->Config, 'geomaps.infowindow', '_google'), 'icons' => $this->processIcons($marker_icons), 'payload' => $infowindow_data));
 }