function getListingFavorites($listing_id, $user_id, $passedArgs) { $conditions = array(); $avatar = Sanitize::getInt($passedArgs['module'], 'avatar', 1); // Only show users with avatars $count = Sanitize::getInt($passedArgs['module'], 'module_limit', 5); $module_id = Sanitize::getInt($passedArgs, 'module_id'); $rand = Sanitize::getFloat($passedArgs, 'rand'); $fields = array('Community.' . $this->realKey . ' AS `User.user_id`', 'User.name AS `User.name`', 'User.username AS `User.username`'); if ($avatar) { $conditions[] = 'Community.thumb <> "components/com_community/assets/default_thumb.jpg"'; } if ($listing_id) { $conditions[] = 'Community.' . $this->realKey . ' in (SELECT user_id FROM #__jreviews_favorites WHERE content_id = ' . $listing_id . ')'; } $order = array('RAND(' . $rand . ')'); $joins = array('LEFT JOIN #__users AS User ON Community.' . $this->realKey . ' = User.id'); $profiles = $this->findAll(array('fields' => $fields, 'conditions' => $conditions, 'order' => $order, 'joins' => $joins)); if (Sanitize::getInt($passedArgs['module'], 'ajax_nav', 1)) { $fields = array('count(Community.' . $this->realKey . ')'); $group = array('Community.' . $this->realKey); $this->count = $this->findCount(array('fields' => $fields, 'conditions' => $conditions, 'group' => $group, 'joins' => $joins)); } else { $this->count = Sanitize::getInt($passedArgs['module'], 'module_limit', 5); } return $this->addProfileInfo($profiles, 'User', 'user_id'); }
function getListingFavorites($listing_id, $user_id, $passedArgs) { $conditions = array(); $avatar = Sanitize::getInt($passedArgs['module'], 'avatar', 1); // Only show users with avatars $module_id = Sanitize::getInt($passedArgs, 'module_id'); $rand = Sanitize::getFloat($passedArgs, 'rand'); $limit = Sanitize::getInt($passedArgs['module'], 'module_total', 10); $fields = array('Community.' . $this->realKey . ' AS `User.user_id`', 'User.name AS `User.name`', 'User.username AS `User.username`'); $avatar and $conditions[] = 'Community.thumb <> "components/com_community/assets/default_thumb.jpg" AND Community.thumb <> "components/com_community/assets/user_thumb.png" AND Community.thumb <> ""'; $listing_id and $conditions[] = 'Community.' . $this->realKey . ' in (SELECT user_id FROM #__jreviews_favorites WHERE content_id = ' . $listing_id . ')'; $order = array('RAND(' . $rand . ')'); $joins = array('LEFT JOIN #__users AS User ON Community.' . $this->realKey . ' = User.id'); $profiles = $this->findAll(array('fields' => $fields, 'conditions' => $conditions, 'order' => $order, 'joins' => $joins, 'limit' => $limit)); return $this->addProfileInfo($profiles, 'User', 'user_id'); }
function getListingFavorites($listing_id, $user_id, $passedArgs) { $avatar = Sanitize::getInt($passedArgs['module'], 'avatar', 1); // Only show users with avatars $module_id = Sanitize::getInt($passedArgs, 'module_id'); $rand = Sanitize::getFloat($passedArgs, 'rand'); $limit = Sanitize::getInt($passedArgs['module'], 'module_total', 10); $fields = array('Community.id AS `User.user_id`', 'User.name AS `User.name`', 'User.username AS `User.username`'); $conditions = array('Community.approved = 1', 'Community.confirmed = 1'); $avatar and $conditions[] = 'Community.avatar IS NOT NULL'; $listing_id and $conditions[] = 'Community.id in (SELECT user_id FROM #__jreviews_favorites WHERE content_id = ' . $listing_id . ')'; $order = array('RAND(' . $rand . ')'); $joins = array('LEFT JOIN #__users AS User ON Community.id = User.id'); $profiles = $this->findAll(array('fields' => $fields, 'conditions' => $conditions, 'order' => $order, 'joins' => $joins, 'limit' => $limit)); return $this->addProfileInfo($profiles, 'User', 'user_id'); }
function startup(&$controller) { $this->c =& $controller; if (!$this->runPlugin($controller)) { return false; } // Initialize vars $center = array(); $address = ''; $lat = 0; $lon = 0; if (!isset($controller->Config)) { $controller->Config = Configure::read('JreviewsSystem.Config'); } if (!isset($controller->Access)) { $controller->Config = Configure::read('JreviewsSystem.Access'); } $this->max_radius = Sanitize::getInt($controller->Config, 'geomaps.max_radius', $this->max_radius); $this->jr_lat = Sanitize::getString($controller->Config, 'geomaps.latitude'); $this->jr_lon = Sanitize::getString($controller->Config, 'geomaps.longitude'); if ($this->jr_lat == '' || $this->jr_lon == '') { return false; } // Setup vars used in startup and other plugin methods $this->google_url = Sanitize::getString($this->c->Config, 'geomaps.google_url', 'http://maps.google.com'); $this->google_api_key = trim(Sanitize::getString($controller->Config, 'geomaps.google_key')); $this->google_api_url = $this->google_url . "/maps?file=api&v=2&async=2&key={$this->google_api_key}&sensor=false"; $search_method = Sanitize::getString($controller->Config, 'geomaps.search_method', 'address'); // address/disabled $search_address_field = Sanitize::getString($controller->Config, 'geomaps.advsearch_input'); $default_radius = Sanitize::getString($controller->Config, 'geomaps.radius'); $this->distance_metric = array('mi' => __t("Miles", true), 'km' => __t("Km", true)); $this->distance_in = Sanitize::getString($controller->Config, 'geomaps.radius_metric', 'mi'); $this->jr_address1 = Sanitize::getString($controller->Config, 'geomaps.address1'); $this->jr_address2 = Sanitize::getString($controller->Config, 'geomaps.address2'); $this->jr_city = Sanitize::getString($controller->Config, 'geomaps.city'); $this->jr_state = Sanitize::getString($controller->Config, 'geomaps.state'); $this->jr_postal_code = Sanitize::getString($controller->Config, 'geomaps.postal_code'); $this->jr_country = Sanitize::getString($controller->Config, 'geomaps.country'); $this->country_def = Sanitize::getString($controller->Config, 'geomaps.default_country'); $this->gid = $controller->Access->gid; $this->address_fields = array_filter(array('address1' => $this->jr_address1, 'address2' => $this->jr_address2, 'city' => $this->jr_city, 'state' => $this->jr_state, 'postal_code' => $this->jr_postal_code, 'country' => $this->jr_country)); $this->geo_fields = array('lat' => $this->jr_lat, 'lon' => $this->jr_lon); $this->c->set(array('address_fields' => $this->address_fields, 'geo_fields' => $this->geo_fields)); /** * Address search checks */ if (isset($controller->data['Field']['Listing'])) { $address = Sanitize::getString($controller->data['Field']['Listing'], $search_address_field); } else { $address = Sanitize::getString($controller->params, $search_address_field); $lat = Sanitize::getFloat($controller->params, $this->jr_lat); $lon = Sanitize::getFloat($controller->params, $this->jr_lon); } /** * Plugin does different things for different controller methods */ switch ($controller->name) { case 'com_content': $this->published = true; $controller->Listing->cacheCallbacks[] = 'plgAfterAfterFind'; $controller->Listing->fields[] = "`Field`.{$this->jr_lat} AS `Geomaps.lat`"; $controller->Listing->fields[] = "`Field`.{$this->jr_lon} AS `Geomaps.lon`"; $controller->Listing->fields[] = "JreviewsCategory.marker_icon AS `Geomaps.icon`"; break; case 'listings': switch ($controller->action) { // Load the geomaps js library case 'create': // Submit a new listing // Submit a new listing case 'edit': // Edit a listing $this->published = true; $Html = new HtmlHelper(); $Html->app = 'jreviews'; $jsGlobals = 'var GeomapsGoogleApi = "' . $this->google_api_url . '";'; $jsGlobals .= 'var jr_lat = "' . $this->jr_lat . '";'; $jsGlobals .= 'var jr_lon = "' . $this->jr_lon . '";'; $jsGlobals .= 'var jr_country_def = "' . $this->country_def . '";'; $jsGlobals .= 'var geoAddressObj = {};'; foreach ($this->address_fields as $key => $field) { $jsGlobals .= "geoAddressObj.{$key} = '{$field}';"; } cmsFramework::addScript($controller->makeJS($jsGlobals), true); $Html->js('geomaps', true); if ($controller->action == 'edit') { $mapit_field = Sanitize::getString($controller->Config, 'geomaps.mapit_field'); if ($mapit_field) { $response = "jQuery(document).ready(function() { \r\n jQuery('#{$mapit_field}','#jr_listingForm').after('<span id=\"gm_geocode\">\r\n <input class=\"jrButton\" type=\"button\" onclick=\"geomaps.mapPopupSimple();\" value=\"" . __t("Map it", true) . "\" /> \r\n <input class=\"jrButton\" type=\"button\" onclick=\"geomaps.clearLatLng();\" value=\"" . __t("Clear LatLng", true) . "\" />\r\n </span>');\r\n });"; cmsFramework::addScript($controller->makeJS($response), true); } } break; // Add geomaps buttons after form is loaded // Add geomaps buttons after form is loaded case '_loadForm': // New listing - Loads submit listing form after category selection $this->published = true; $mapit_field = Sanitize::getString($controller->Config, 'geomaps.mapit_field'); if ($mapit_field) { $response = array(); $response[] = "\r\n jQuery('#gm_geocode').remove();jQuery('#{$mapit_field}','#jr_listingForm').after('<span id=\"gm_geocode\"><input class=\"jrButton\" type=\"button\" onclick=\"geomaps.mapPopupSimple();\" value=\"" . __t("Map it", true) . "\" /> <input class=\"jrButton\" type=\"button\" onclick=\"geomaps.clearLatLng();\" value=\"" . __t("Clear LatLng", true) . "\" /></span>');\r\n jQuery('#gm_geocode').find(':input').removeAttr('disabled');\r\n "; $controller->afterAjaxResponse = $response; } break; case '_save': // Checks if $isNew = Sanitize::getInt($controller->data['Listing'], 'id', 0) == 0 ? true : false; if (Sanitize::getInt($controller->Config, 'geomaps.autogeocode_new') && $isNew && isset($controller->data['Field']) && (Sanitize::getFloat($controller->data['Field']['Listing'], $this->jr_lat, null) == null || Sanitize::getFloat($controller->data['Field']['Listing'], $this->jr_lon, null) == null)) { // Build whole address from fields $address = ''; foreach ($this->address_fields as $key => $field) { ${$field} = Sanitize::getVar($controller->data['Field']['Listing'], $field, ''); if (${$field} != '') { $address .= ' ' . ${$field}; } elseif ($field == 'section') { $address .= " " . Sanitize::getString($controller->data, 'section'); } elseif ($field == 'parent_category') { $address .= " " . Sanitize::getString($controller->data, 'parent_category'); } elseif ($field == 'category') { $address .= " " . Sanitize::getString($controller->data, 'category'); } } if ($address != '' && !Sanitize::getVar($controller->data['Field']['Listing'], $this->jr_country, false) && $this->country_def != '') { $address .= ' ' . $this->country_def; } if ($address != '') { // Geocode address App::import('Component', 'geocoding'); $Geocoding = ClassRegistry::getClass('GeocodingComponent'); $Geocoding->Config =& $controller->Config; $response = $Geocoding->geocode($address); if ($response['status'] == 200) { $controller->data['Field']['Listing'][$this->jr_lat] = $response['lat']; $controller->data['__raw']['Field']['Listing'][$this->jr_lat] = $response['lat']; $controller->data['Field']['Listing'][$this->jr_lon] = $response['lon']; $controller->data['__raw']['Field']['Listing'][$this->jr_lon] = $response['lon']; } } } break; } break; case 'admin_listings': switch ($controller->action) { case 'index': case 'browse': case 'moderation': App::import('Helper', 'html'); $Html = new HtmlHelper(); $Html->app = 'jreviews'; $jsGlobals = 'var GeomapsGoogleApi = "' . $this->google_api_url . '";'; $jsGlobals .= 'var jr_lat = "' . $this->jr_lat . '";'; $jsGlobals .= 'var jr_lon = "' . $this->jr_lon . '";'; $jsGlobals .= 'var jr_country_def = "' . $this->country_def . '";'; $jsGlobals .= 'var geoAddressObj = {};'; foreach ($this->address_fields as $key => $field) { $jsGlobals .= "geoAddressObj.{$key} = '{$field}';"; } if ($controller->action == 'moderation') { ?> <script type="text/javascript"> /* <![CDATA[ */ <?php echo $jsGlobals; ?> if(null==jQuery('body').data('geomaps')){ jQuery.getScript('<?php echo $this->locateScript('geomaps'); ?> ',function(){jQuery('body').data('geomaps',1)}); } /* ]]> */ </script> <?php } else { cmsFramework::addScript($controller->makeJS($jsGlobals), true); $Html->js('geomaps', true); } break; case 'edit': $mapit_field = Sanitize::getString($controller->Config, 'geomaps.mapit_field'); if ($mapit_field) { $response = "jQuery('#{$mapit_field}').after('<span id=\"gm_geocode\"><input class=\"jrButton\" type=\"button\" onclick=\"geomaps.mapPopupSimple();\" value=\"" . __t("Map it", true) . "\" /> <input class=\"jrButton\" type=\"button\" onclick=\"geomaps.clearLatLng();\" value=\"" . __t("Clear LatLng", true) . "\" /></span>');"; $controller->pluginResponse = $response; } break; } break; // A search was performed, make distance the default ordering and copy the entered address to the search address field // A search was performed, make distance the default ordering and copy the entered address to the search address field case 'search': if ($search_method == 'disabled' || $address == '') { return; } if ($controller->action == '_process') { $this->published = true; // Enable the callbacks for this controller/method // Make distance the default ordering $controller->Config->list_order_default = 'distance'; if ($address != '' && in_array($search_method, array('address'))) { $controller->data['Field']['Listing'][$search_address_field] = $address; // Append default country if ($this->country_def != '') { $address .= ' ' . $this->country_def; } // Geocode address App::import('Component', 'geocoding'); $Geocoding = ClassRegistry::getClass('GeocodingComponent'); $Geocoding->Config =& $controller->Config; $response = $Geocoding->geocode($address); if ($response['status'] == 200) { $center = $response; } if ($center && !empty($center)) { $controller->data['Field']['Listing'][$this->jr_lat] = $center['lat']; $controller->data['Field']['Listing'][$this->jr_lon] = $center['lon']; unset($controller->data['Field']['Listing'][$this->jr_lat . '_operator']); unset($controller->data['Field']['Listing'][$this->jr_lon . '_operator']); } } } break; // Display search results // Display search results case 'categories': $controller->Listing->fields[] = "`Field`.{$this->jr_lat} AS `Geomaps.lat`"; $controller->Listing->fields[] = "`Field`.{$this->jr_lon} AS `Geomaps.lon`"; $controller->Listing->fields[] = "JreviewsCategory.marker_icon AS `Geomaps.icon`"; $this->published = true; // Enable the callbacks for this controller/method if ($search_method == 'disabled' || $lat == 0 || $lon == 0) { return; } if ($controller->action == 'search') { $radius = min(Sanitize::getFloat($controller->params, $this->radius_field, $default_radius), $this->max_radius); if ($search_method == 'disabled') { $this->published = false; return; } if ($lat != 0 && $lon != 0) { Configure::write('geomaps.enabled', true); // Used to show the Distance ordering in the jreviews.php helper in JReviews. $center = array('lat' => $lat, 'lon' => $lon); // Send center coordinates to theme $controller->set('GeomapsCenter', $center); $sort = $controller->params['order'] = Sanitize::getString($controller->params, 'order', 'distance'); // Clear address and coordinate field from parameters because it shouldn't be used on distance searches. Instead we use lat/lon via custom condition below unset($controller->params[$search_address_field], $controller->params['url'][$search_address_field], $controller->params[$this->jr_lat], $controller->params['url'][$this->jr_lat], $controller->params[$this->jr_lon], $controller->params['url'][$this->jr_lon]); $controller->passedArgs['url'] = preg_replace('/\\/' . $search_address_field . _PARAM_CHAR . '[\\p{L}-\\s0-9]+/i', '', $controller->passedArgs['url']); $controller->passedArgs['url'] = preg_replace('/\\/' . $search_address_field . _PARAM_CHAR . '[a-z0-9-\\s]+/i', '', $controller->passedArgs['url']); // One above doesn't work well in all cases, but required for non-latin characters in address $controller->passedArgs['url'] = preg_replace('/\\/' . $this->jr_lat . _PARAM_CHAR . '[\\-a-z0-9\\.\\s]+/i', '', $controller->passedArgs['url']); $controller->passedArgs['url'] = preg_replace('/\\/' . $this->jr_lon . _PARAM_CHAR . '[\\-a-z0-9\\.\\s]+/i', '', $controller->passedArgs['url']); // Create a square around the center to limite the number of rows processed in the zip code table // http://www.free-zipcodes.com/ // http://www.mysqlconf.com/mysql2008/public/schedule/detail/347 $degreeDistance = $this->distance_in == 'mi' ? 69.172 : 40076 / 360; $lat_range = $radius / $degreeDistance; $lon_range = $radius / abs(cos($center['lat'] * pi() / 180) * $degreeDistance); $min_lat = $center['lat'] - $lat_range; $max_lat = $center['lat'] + $lat_range; $min_lon = $center['lon'] - $lon_range; $max_lon = $center['lon'] + $lon_range; $squareArea = "`Field`.{$this->jr_lat} BETWEEN {$min_lat} AND {$max_lat} AND `Field`.{$this->jr_lon} BETWEEN {$min_lon} AND {$max_lon}"; // calculate the distance between two sets of longitude/latitude coordinates // From http://www.mysqlconf.com/mysql2008/public/schedule/detail/347 if ($this->distance_in == 'km') { $controller->Listing->fields['distance'] = "6371 * 2 * ASIN(SQRT( POWER(SIN(({$center['lat']} - {$this->jr_lat}) * pi()/180 / 2), 2) + \r\n COS({$center['lat']} * pi()/180) * COS({$this->jr_lat} * pi()/180) * POWER(SIN(({$center['lon']} -{$this->jr_lon}) * pi()/180 / 2), 2) )) AS `Geomaps.distance`"; } if ($this->distance_in == 'mi') { $controller->Listing->fields['distance'] = "3956 * 2 * ASIN(SQRT( POWER(SIN(({$center['lat']} - {$this->jr_lat}) * pi()/180 / 2), 2) + \r\n COS({$center['lat']} * pi()/180) * COS({$this->jr_lat} * pi()/180) * POWER(SIN(({$center['lon']} -{$this->jr_lon}) * pi()/180 / 2), 2) )) AS `Geomaps.distance`"; } $controller->Listing->conditions[] = $squareArea; if ($sort == 'distance') { $controller->Listing->order[] = '`Geomaps.distance` ASC'; } // Makes sure that only listings within given radius are shown because square limit might include further points // $controller->Listing->having[] = '`Geomaps.distance` <= ' . (int) $radius; // Override search theme suffix $theme_suffix = Sanitize::getString($controller->Config, 'geomaps.search_suffix'); if ($theme_suffix != '') { $controller->viewSuffix = $theme_suffix; } } } break; } }
function listings() { // Initialize variables $id = Sanitize::getInt($this->params, 'id'); $option = Sanitize::getString($this->params, 'option'); $view = Sanitize::getString($this->params, 'view'); $menu_id = Sanitize::getString($this->params, 'Itemid'); // Read params $cat_id = ''; $criteria_ids = ''; $in_detail_view = false; $detail_view = 1; $dir_id = Sanitize::getString($this->params, 'dir'); $section_id = Sanitize::getString($this->params, 'section'); $cat_id = Sanitize::getString($this->params, 'cat'); $extension = 'com_content'; $custom_where = null; $custom_fields = array(); $click2search_auto = false; $cache = 0; $radius = 0; $mode = 0; if (isset($this->params['module'])) { // Read module parameters $click2search_auto = Sanitize::getBool($this->params['module'], 'click2search_auto', false); $custom_where = Sanitize::getString($this->params['module'], 'custom_where'); $filter = Sanitize::getString($this->params['module'], 'filter'); $detail_view = Sanitize::getString($this->params['module'], 'detail_view', 1); $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $cat_id = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); $criteria_ids = Sanitize::getString($this->params['module'], 'criteria'); $limit_results = Sanitize::getInt($this->params['module'], 'limit_results'); $mode = Sanitize::getInt($this->params['module'], 'mode', 0); $custom_fields = str_replace(" ", "", Sanitize::getString($this->Config, 'geomaps.infowindow_fields')); $custom_fields = $custom_fields != '' ? explode(",", $custom_fields) : array(); /** * 0 - Normal * 1 - GeoTargeting * 2 - Custom center and zoom */ $radius = Sanitize::getInt($this->params['module'], 'radius'); $cache = $mode == 1 ? 0 : Sanitize::getInt($this->params['module'], 'cache_map'); $custom_lat = Sanitize::getFloat($this->params['module'], 'custom_lat'); $custom_lon = Sanitize::getFloat($this->params['module'], 'custom_lon'); if ($mode == 2 && ($custom_lat == 0 || $custom_lon == 0)) { echo __t("You selected the Custom Center mode, but did not specify the coordinates."); return; } } # Prevent sql injection $token = Sanitize::getString($this->params, 'token'); $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false)); $filters = $listing_id != '' || $dir_id != '' || $section_id != '' || $cat_id != ''; if (!$filters && $id > 0 && 'article' == $view && 'com_content' == $option) { $sql = "SELECT catid FROM #__content WHERE id = " . $id; $this->_db->setQuery($sql); $cat_id_host_page = $this->_db->loadResult(); if (!empty($cat_id_host_page) && $this->Category->isJreviewsCategory($cat_id_host_page)) { $in_detail_view = true; $cat_id = $cat_id_host_page; } } $detail_view = $this->params['module']['detail_view'] = (int) ($detail_view && $in_detail_view); # Custom WHERE $tokenMatch and $custom_where and $conditions[] = $custom_where; if ($click2search_auto && isset($this->params['tag'])) { $field = 'jr_' . Sanitize::getString($this->params['tag'], 'field'); $value = Sanitize::getString($this->params['tag'], 'value'); $query = "SELECT Field.type FROM #__jreviews_fields AS Field WHERE Field.name = " . $this->quote($field); $this->_db->setQuery($query); $type = $this->_db->loadResult(); if (in_array($type, array('select', 'selectmultiple', 'checkboxes', 'radiobuttons'))) { $conditions[] = "Field.{$field} LIKE " . $this->quoteLike('*' . $value . '*'); } else { $conditions[] = "Field.{$field} = " . $this->quote($value); } } # Category auto detect if (isset($this->params['module']) && Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') { $ids = CommonController::_discoverIDs($this); extract($ids); } $autodetect = compact('dir_id', 'section_id', 'cat_id'); // Check for cached version if cache enabled if ($cache) { $params = array(); foreach ($this->params as $key => $value) { if ((!is_array($value) || $key == 'module') && !in_array($key, array('page', 'limit', 'order', 'Itemid'))) { $params[$key] = $value; } } $cache_key = array_merge($params, $autodetect, Sanitize::getVar($this->params, 'tag', array())); $json_filename = 'geomaps_' . md5(serialize($cache_key)) . '.json'; $json_data = S2Cache::read($json_filename); if ($json_data && $json_data != '') { $this->set('json_data', $json_data); S2Cache::write($json_filename, $json_data); return $this->render('modules', 'geomaps'); } } $this->Listing->fields = array('Listing.id AS `Listing.listing_id`', 'Listing.title AS `Listing.title`', 'Listing.images AS `Listing.images`', 'CASE WHEN CHAR_LENGTH(Listing.alias) THEN Listing.alias ELSE "" END AS `Listing.slug`', 'Category.id AS `Listing.cat_id`', 'CASE WHEN CHAR_LENGTH(Category.alias) THEN Category.alias ELSE Category.title END AS `Category.slug`', 'Listing.sectionid AS `Listing.section_id`', 'JreviewsCategory.criteriaid AS `Criteria.criteria_id`', 'JreviewsCategory.dirid AS `Directory.dir_id`', 'JreviewsCategory.marker_icon AS `Geomaps.icon`', 'Field.featured AS `Listing.featured`', 'Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', "Field.{$this->jr_lat} `Geomaps.lat`", "Field.{$this->jr_lon} `Geomaps.lon`", 'ListingType.state AS `Criteria.state`', 'ListingType.config AS `ListingType.config`'); if ($custom_lon != '' and $custom_lat != '') { $this->set('CustomCenter', array('lon' => $custom_lon, 'lat' => $custom_lat)); } // Geo Targeting OR Custom Center modes if ($mode == 1 || $mode == 2) { if ($mode == 1) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.geoplugin.net/php.gp?ip=' . s2GetIpAddress()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $geoData = unserialize(curl_exec($ch)); curl_close($ch); if (!empty($geoData) && isset($geoData['geoplugin_latitude']) && $geoData['geoplugin_latitude'] != '' && $geoData['geoplugin_longitude'] != '') { $center = array('lon' => $geoData['geoplugin_longitude'], 'lat' => $geoData['geoplugin_latitude']); } $this->set('geoLocation', $geoData); } if ($mode == 2) { $center = array('lon' => $custom_lon, 'lat' => $custom_lat); } if (!empty($center) && $radius > 0) { $distanceIn = Sanitize::getString($this->Config, 'geomaps.radius_metric', 'mi'); $degreeDistance = $distanceIn == 'mi' ? 69.172 : 40076 / 360; // Send center coordinates to theme $this->set('GeomapsCenter', $center); $lat_range = $radius / $degreeDistance; $lon_range = $radius / abs(cos($center['lat'] * pi() / 180) * $degreeDistance); $min_lat = $center['lat'] - $lat_range; $max_lat = $center['lat'] + $lat_range; $min_lon = $center['lon'] - $lon_range; $max_lon = $center['lon'] + $lon_range; $squareArea = "`Field`.{$this->jr_lat} BETWEEN {$min_lat} AND {$max_lat} AND `Field`.{$this->jr_lon} BETWEEN {$min_lon} AND {$max_lon}"; $conditions[] = $squareArea; } } // Create marker_icons array $marker_icons = array(); $icon_fields = array(); $field_images = array(); $query = "SELECT DISTINCT marker_icon FROM #__jreviews_categories WHERE marker_icon != ''"; $this->_db->setQuery($query); $icon_rows = $this->_db->loadAssocList(); foreach ($icon_rows as $icons) { $icon = (array) json_decode($icons['marker_icon']); if ($icon['field'] != '') { $icon_fields[$icon['field']] = "'" . $icon['field'] . "'"; } } if (!empty($icon_fields)) { foreach ($icon_fields as $field_key => $field) { if (substr($field_key, 0, 3) == 'jr_') { $this->Listing->fields[] = "Field.{$field_key} AS `Field.{$field_key}`"; } } } if (!empty($custom_fields)) { foreach ($custom_fields as $field) { $this->Listing->fields[] = "Field.{$field} AS `Field.{$field}`"; } } $this->Listing->joins = array("LEFT JOIN #__categories AS Category ON Listing.catid = Category.id", 'ParentCategory' => "LEFT JOIN #__categories AS ParentCategory ON Category.lft BETWEEN ParentCategory.lft AND ParentCategory.rgt", "LEFT JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.id AND Totals.extension = 'com_content'", "LEFT JOIN #__jreviews_content AS `Field` ON Field.contentid = Listing.id", "INNER JOIN #__jreviews_categories AS JreviewsCategory ON Listing.catid = JreviewsCategory.id AND JreviewsCategory.`option` = 'com_content'", "LEFT JOIN #__jreviews_criteria AS ListingType ON JreviewsCategory.criteriaid = ListingType.id", "LEFT JOIN #__jreviews_directories AS Directory ON JreviewsCategory.dirid = Directory.id"); // Don't regroup the results by model name keys to save time $this->Listing->primaryKey = false; # Set conditionals based on configuration parameters if ($detail_view) { $conditions[] = 'Listing.id = ' . $id; } if (!empty($cat_id)) { $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')' : 'ParentCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } if ($this->cmsVersion == CMS_JOOMLA15) { unset($this->Listing->joins['ParentCategory']); } empty($cat_id) and !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')'; empty($cat_id) and !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')'; empty($cat_id) and !empty($criteria_id) and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')'; if ($listing_id) { $conditions[] = 'Listing.id IN (' . $listing_id . ')'; } if ($filter == 'featured' && !$detail_view) { $conditions[] = 'Field.featured = 1'; } $conditions[] = "Field.{$this->jr_lat} <> ''"; $conditions[] = "Field.{$this->jr_lon} <> ''"; $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )')); if ($this->cmsVersion == CMS_JOOMLA15) { // $conditions[] = 'Section.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Category.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId(); } else { $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')'; $conditions[] = 'Listing.access IN (' . $this->Access->getAccessLevels() . ')'; } // Paid Listings - add plan cat id isset($this->PaidListings) and $this->PaidListings->applyBeforeFindListingChanges($this->Listing); $listings = $this->Listing->findAll(array('conditions' => $conditions, 'limit' => $limit_results), array()); $custom_fields = array_filter(array_merge($custom_fields, array_keys($icon_fields))); $fieldOptionValues = array(); // Extract custom field values to avoid loading all options for each fields // It's a trade-off between that and doing a foreach on all listings foreach ($listings as $key => $row) { $listings[$key]['Criteria']['state'] = $row['Criteria.state']; $listings[$key]['ListingType']['config'] = json_decode($row['ListingType.config'], true); unset($listings[$key]['Criteria.state'], $listings[$key]['ListingType.config']); foreach ($custom_fields as $field) { $optionValue = Sanitize::getVar($row, 'Field.' . $field); if ($optionValue != '' && $optionValue != '**') { $fieldOptionValues = array_merge($fieldOptionValues, array_filter(explode('*', $optionValue))); } } } $fields = $this->Field->getFields($custom_fields, 'listing', $fieldOptionValues); $json_data = $this->Geomaps->makeJsonObject($listings, $fields, $this->params['module']); $this->set('json_data', $json_data); if ($cache) { S2Cache::write($json_filename, $json_data); } return $this->render('modules', 'geomaps'); }
function index() { /* if($this->_user->id === 0) { $this->cacheAction = Configure::read('Cache.expires'); }*/ // Required for ajax pagination to remember module settings $ids = $conditions = $joins = $order = $having = array(); $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id')); if (!isset($this->params['module'])) { $this->params['module'] = array(); } // For direct calls to the controller # Find the correct set of params to use if ($this->ajaxRequest && Sanitize::getInt($this->params, 'listing_id')) { $this->params['module'] = array_merge($this->params['module'], $this->__processListingTypeWidgets($conditions)); } elseif ($this->ajaxRequest && empty($this->params['module']) && $module_id) { $query = "SELECT params FROM #__modules WHERE id = " . $module_id; $this->_db->setQuery($query); $this->params['module'] = stringToArray($this->_db->loadResult()); } if ($this->abort) { return $this->ajaxResponse('', false); } # Read module parameters $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $cat_id = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); $created_by = Sanitize::getString($this->params['module'], 'owner'); $criteria_id = Sanitize::getString($this->params['module'], 'criteria'); $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5); $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10)); $extension = Sanitize::getString($this->params['module'], 'extension'); $extension = $extension != '' ? $extension : 'com_content'; $sort = Sanitize::getString($this->params['module'], 'listing_order'); if (in_array($sort, array('random', 'featuredrandom'))) { srand((double) microtime() * 1000000); $this->params['rand'] = rand(); } # Prevent sql injection $token = Sanitize::getString($this->params, 'token'); $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false)); isset($this->params['module']) and $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); if (isset($this->Listing)) { $this->Listing->_user = $this->_user; // This parameter determines the module mode $custom_order = Sanitize::getString($this->params['module'], 'custom_order'); $custom_where = Sanitize::getString($this->params['module'], 'custom_where'); if ($extension != 'com_content' && in_array($sort, array('topratededitor', 'featuredrandom', 'rhits'))) { echo "You have selected the {$sort} mode which is not supported for components other than com_content. Please read the tooltips in the module parameters for more info on allowed settings."; return; } # Category auto detect if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') { $ids = CommonController::_discoverIDs($this); extract($ids); } # Set conditionals based on configuration parameters if ($extension == 'com_content') { // Perform tag replacement for listing_id to allow for related listing queries if (Sanitize::getString($this->params, 'view') == 'article' && $custom_where != '') { $curr_listing_id = Sanitize::getInt($this->params, 'id'); $custom_where = str_replace('{listing_id}', $curr_listing_id, $custom_where); } // Only works for core articles $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )')); if ($this->cmsVersion == CMS_JOOMLA15) { // $conditions[] = 'Section.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Category.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId(); } else { $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')'; $conditions[] = 'Listing.access IN (' . $this->Access->getAccessLevels() . ')'; } // Remove unnecessary fields from model query $this->Listing->modelUnbind(array('Listing.fulltext AS `Listing.description`', 'Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`', 'User.email AS `User.email`')); if (!empty($cat_id)) { $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')' : 'ParentCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } else { unset($this->Listing->joins['ParentCategory']); } empty($cat_id) and !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')'; empty($cat_id) and !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')'; empty($cat_id) and !empty($criteria_id) and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')'; } else { if (Sanitize::getInt($this->params['module'], 'cat_auto') && method_exists($this->Listing, 'catUrlParam')) { if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) { $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } } elseif ($cat_id) { $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } } $listing_id and $conditions[] = "Listing.{$this->Listing->realKey} IN (" . cleanIntegerCommaList($listing_id) . ")"; switch ($sort) { case 'random': $order[] = 'RAND(' . $this->params['rand'] . ')'; break; case 'featured': $conditions[] = 'Field.featured = 1'; break; case 'featuredrandom': $conditions[] = 'Field.featured = 1'; $order[] = 'RAND(' . $this->params['rand'] . ')'; break; case 'topratededitor': // $conditions[] = 'Totals.editor_rating > 0'; $sort = 'editor_rating'; break; // Editor rating sorting options dealt with in the Listing->processSorting method } # Custom WHERE $tokenMatch and $custom_where and $conditions[] = $custom_where; # Filtering options $having = array(); // Listings submitted in the past x days $entry_period = Sanitize::getInt($this->params['module'], 'filter_listing_period'); if ($entry_period > 0 && $this->Listing->dateKey) { $conditions[] = "Listing.{$this->Listing->dateKey} >= DATE_SUB('" . _CURRENT_SERVER_TIME . "', INTERVAL {$entry_period} DAY)"; } // Listings with reviews submitted in past x days $review_period = Sanitize::getInt($this->params['module'], 'filter_review_period'); if ($review_period > 0) { $conditions[] = "Review.created >= DATE_SUB(CURDATE(), INTERVAL {$review_period} DAY)"; $joins[] = 'LEFT JOIN #__jreviews_comments AS Review ON Listing.' . $this->Listing->realKey . ' = Review.pid'; } // Listings with review count higher than $filter_review_count = Sanitize::getInt($this->params['module'], 'filter_review_count'); $filter_review_count > 0 and $conditions[] = "Totals.user_rating_count >= " . $filter_review_count; // Listings with avg rating higher than $filter_avg_rating = Sanitize::getFloat($this->params['module'], 'filter_avg_rating'); $filter_avg_rating > 0 and $conditions[] = 'Totals.user_rating >= ' . $filter_avg_rating; $this->Listing->group = array(); // Exlude listings without ratings from the results $join_direction = in_array($sort, array('rating', 'rrating', 'topratededitor', 'reviews')) ? 'INNER' : 'LEFT'; $this->Listing->joins['Total'] = "{$join_direction} JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.{$this->Listing->realKey} AND Totals.extension = " . $this->quote($extension); # Modify query for correct ordering. Change FIELDS, ORDER BY and HAVING BY directly in Listing Model variables if ($tokenMatch and $custom_order) { $this->Listing->order[] = $custom_order; } elseif (empty($order) && $extension == 'com_content') { $this->Listing->processSorting('module', $sort); // Modifies Listing model order var directly } elseif (empty($order) && ($order = $this->__processSorting($sort))) { $order = array($order); } $fields = array('Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.user_comment_count AS `Review.review_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', 'Totals.editor_comment_count AS `Review.editor_review_count`'); $queryData = array('fields' => !isset($this->Listing->fields['editor_rating']) ? $fields : array(), 'joins' => $joins, 'conditions' => $conditions, 'limit' => $total, 'having' => $having); isset($order) and !empty($order) and $queryData['order'] = $order; // Trigger addFields for $listing results. Checked in Everywhere model $this->Listing->addFields = true; $listings = $this->Listing->findAll($queryData); $count = count($listings); } else { $listings = array(); $count = 0; } unset($this->Listing); # Send variables to view template $this->set(array('autodetect_ids' => $ids, 'subclass' => 'listing', 'listings' => $listings, 'total' => $count, 'limit' => $limit)); $this->_completeModuleParamsArray(); $page = $this->ajaxRequest && empty($listings) ? '' : $this->render('modules', 'listings'); /* if($this->_user->id === 0 && $this->ajaxRequest) { $path = $this->here; $this->here == '/' and $path = 'home'; $cache_fname = Inflector::slug($path) . '.php'; $now = time(); $cacheTime = is_numeric($this->cacheAction) ? $now + $this->cacheAction : strtotime($this->cacheAction, $now); $fileHeader = '<!--cachetime:' . $cacheTime . '-->'; cache('views' . DS . $cache_fname, $fileHeader . $this->ajaxResponse($page,false), $this->cacheAction); }*/ return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page; }
function listings() { // Initialize variables $id = Sanitize::getInt($this->params, 'id'); $option = Sanitize::getString($this->params, 'option'); $view = Sanitize::getString($this->params, 'view'); $task = Sanitize::getString($this->params, 'task'); $menu_id = Sanitize::getString($this->params, 'Itemid'); // Read params $cat_id = ''; $criteria_ids = ''; $detail_view = 1; $dir_id = Sanitize::getString($this->params, 'dir'); $section_id = Sanitize::getString($this->params, 'section'); $cat_id = Sanitize::getString($this->params, 'cat'); $extension = 'com_content'; $custom_where = null; $custom_fields = array(); $click2search_auto = false; $cache = 0; $radius = 0; $mode = 0; $fishingmap = 0; $this->set('listing_id', $id); $extracoords = array(); if (isset($this->params['module'])) { // Read module parameters $click2search_auto = Sanitize::getBool($this->params['module'], 'click2search_auto', false); $custom_where = Sanitize::getString($this->params['module'], 'custom_where'); $filter = Sanitize::getString($this->params['module'], 'filter'); $detail_view = Sanitize::getString($this->params['module'], 'detail_view', 1); $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $cat_id = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); $criteria_ids = Sanitize::getString($this->params['module'], 'criteria'); $custom_fields = Sanitize::getString($this->params['module'], 'custom_fields', ''); $custom_fields = $custom_fields != '' ? explode(',', str_replace(' ', '', $custom_fields)) : array(); $limit_results = Sanitize::getInt($this->params['module'], 'limit_results'); $mode = Sanitize::getInt($this->params['module'], 'mode', 0); /** * 0 - Normal * 1 - GeoTargeting * 2 - Custom center and zoom */ $radius = Sanitize::getInt($this->params['module'], 'radius'); $cache = $mode == 1 ? 0 : Sanitize::getInt($this->params['module'], 'cache_map'); $custom_lat = Sanitize::getFloat($this->params['module'], 'custom_lat'); $custom_lon = Sanitize::getFloat($this->params['module'], 'custom_lon'); if ($mode == 2 && ($custom_lat == 0 || $custom_lon == 0)) { echo __t("You selected the Custom Center mode, but did not specify the coordinates."); return; } // Added for Hooked $extracoords = $this->params['module']['extracoords']; //$extracoords = ""; $fishingmap = Sanitize::getInt($this->params['module'], 'fishingmap', 0); } $in_detail_view = $id > 0 && ('article' == $view || 'view' == $task) && 'com_content' == $option; $detail_view = $this->params['module']['detail_view'] = $detail_view && $in_detail_view; # Custom WHERE if ($custom_where) { $conditions[] = $custom_where; } if ($click2search_auto && isset($this->params['tag'])) { $field = 'jr_' . Sanitize::getString($this->params['tag'], 'field'); $value = Sanitize::getString($this->params['tag'], 'value'); $query = "SELECT Field.type FROM #__jreviews_fields AS Field WHERE Field.name = " . $this->quote($field); $this->_db->setQuery($query); $type = $this->_db->loadResult(); if (in_array($type, array('select', 'selectmultiple', 'checkboxes', 'radiobuttons'))) { $conditions[] = "Field.{$field} LIKE " . $this->quoteLike('*' . $value . '*'); } else { $conditions[] = "Field.{$field} = " . $this->quote($value); } } # Category auto detect if (isset($this->params['module']) && Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') { // Only works for core articles switch ($option) { case 'com_jreviews': # Get url params for current controller/action $url = Sanitize::getString($this->passedArgs, 'url'); $route['url']['url'] = $url; $route = S2Router::parse($route); // $route = $route['url']; $dir_id = Sanitize::getString($route, 'dir'); $section_id = Sanitize::getString($route, 'section'); $cat_id = Sanitize::getString($route, 'cat'); $criteria_ids = Sanitize::getString($route, 'criteria'); if ($cat_id != '') { $category_ids = $this->makeParamsUsable($cat_id); $category_ids = explode(",", $category_ids); $this->cleanArray($category_ids); $cat_id = implode(",", $category_ids); } elseif ($section_id != '') { $cat_id = $this->sectionToCat($section_id); } elseif ($criteria_ids != '') { // check criteriaids { $criteriaids_url = $this->makeParamsUsable($criteria_ids); $cat_id = $this->criteriaToCat($criteria_ids); } else { //Discover the params from the menu_id $params = $this->Menu->getMenuParams($menu_id); $dir_id = Sanitize::getString($params, 'dirid'); $cat_id = Sanitize::getString($params, 'catid'); $section_id = Sanitize::getString($params, 'sectionid'); } break; case 'com_content': if ('article' == $view || 'view' == $task) { $sql = "SELECT catid FROM #__content WHERE id = " . $id; $this->_db->setQuery($sql); $cat_id = $this->_db->loadResult(); } elseif ($view == "section") { $cat_id = $this->sectionToCat($id); } elseif ($view == "category") { $cat_id = $id; } break; default: // $cat_id = null; // Catid not detected because the page is neither content nor jreviews break; } } $autodetect = compact('dir_id', 'section_id', 'cat_id'); // Check for cached version if cache enabled if ($cache) { $params = array(); foreach ($this->params as $key => $value) { if ((!is_array($value) || $key == 'module') && !in_array($key, array('page', 'limit', 'order', 'Itemid'))) { $params[$key] = $value; } } $cache_key = array_merge($params, $autodetect, Sanitize::getVar($this->params, 'tag', array())); $json_filename = 'geomaps_' . md5(serialize($cache_key)) . '.json'; $json_data = S2Cache::read($json_filename); if ($json_data && $json_data != '') { $this->set('json_data', $json_data); S2Cache::write($json_filename, $json_data); return $this->render('modules', 'geomaps'); } } $this->Listing->fields = array('Listing.id AS `Listing.listing_id`', 'Listing.title AS `Listing.title`', 'Listing.images AS `Listing.images`', 'CASE WHEN CHAR_LENGTH(Listing.alias) THEN Listing.alias ELSE "" END AS `Listing.slug`', 'Category.id AS `Listing.cat_id`', 'CASE WHEN CHAR_LENGTH(Category.alias) THEN Category.alias ELSE Category.title END AS `Category.slug`', 'Listing.sectionid AS `Listing.section_id`', 'JreviewsCategory.criteriaid AS `Criteria.criteria_id`', 'JreviewsCategory.dirid AS `Directory.dir_id`', 'Field.featured AS `Listing.featured`', 'Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', "Field.{$this->jr_lat} `Geomaps.lat`", "Field.{$this->jr_lon} `Geomaps.lon`", 'JreviewsCategory.marker_icon AS `Geomaps.icon`'); if ($fishingmap) { $this->Listing->fields[] = 'GROUP_CONCAT(Related.id2) AS `Listing.relations`'; } // Geo Targeting OR Custom Center modes if ($mode == 1 || $mode == 2) { if ($mode == 1) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.geoplugin.net/php.gp?ip=' . s2GetIpAddress()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $geoData = unserialize(curl_exec($ch)); curl_close($ch); if (!empty($geoData) && $geoData['geoplugin_latitude'] != '' && $geoData['geoplugin_longitude'] != '') { $center = array('lon' => $geoData['geoplugin_longitude'], 'lat' => $geoData['geoplugin_latitude']); } $this->set('geoLocation', $geoData); } if ($mode == 2) { $center = array('lon' => $custom_lon, 'lat' => $custom_lat); } if (!empty($center) && $radius > 0) { $distanceIn = Sanitize::getString($this->Config, 'geomaps.radius_metric', 'mi'); $degreeDistance = $distanceIn == 'mi' ? 69.172 : 40076 / 360; // Send center coordinates to theme $this->set('GeomapsCenter', $center); $lat_range = $radius / $degreeDistance; $lon_range = $radius / abs(cos($center['lat'] * pi() / 180) * $degreeDistance); $min_lat = $center['lat'] - $lat_range; $max_lat = $center['lat'] + $lat_range; $min_lon = $center['lon'] - $lon_range; $max_lon = $center['lon'] + $lon_range; $squareArea = "`Field`.{$this->jr_lat} BETWEEN {$min_lat} AND {$max_lat} AND `Field`.{$this->jr_lon} BETWEEN {$min_lon} AND {$max_lon}"; // Added for Hooked if ($extracoords) { $squareArea = "((" . $squareArea . ")"; foreach ($extracoords as $extra) { $e_lat = $extra->y; $e_lon = $extra->x; $lon_range = $radius / abs(cos($e_lat * pi() / 180) * $degreeDistance); $min_lat = $e_lat - $lat_range; $max_lat = $e_lat + $lat_range; $min_lon = $e_lon - $lon_range; $max_lon = $e_lon + $lon_range; $squareArea .= " OR (`Field`.{$this->jr_lat} BETWEEN {$min_lat} AND {$max_lat} AND `Field`.{$this->jr_lon} BETWEEN {$min_lon} AND {$max_lon})"; } $squareArea .= ")"; } $conditions[] = $squareArea; } } // Create marker_icons array $marker_icons = array(); $icon_fields = array(); $field_images = array(); $query = "SELECT DISTINCT marker_icon FROM #__jreviews_categories WHERE marker_icon != ''"; $this->_db->setQuery($query); $icon_rows = $this->_db->loadAssocList(); foreach ($icon_rows as $icons) { $icon = (array) json_decode($icons['marker_icon']); if ($icon['field'] != '') { $icon_fields[$icon['field']] = "'" . $icon['field'] . "'"; } } if (!empty($icon_fields)) { foreach ($icon_fields as $field_key => $field) { $this->Listing->fields[] = "Field.{$field_key} AS `Field.{$field_key}`"; } } if (!empty($custom_fields)) { foreach ($custom_fields as $field) { $this->Listing->fields[] = "Field.{$field} AS `Field.{$field}`"; } } $this->Listing->joins = array("LEFT JOIN #__categories AS Category ON Listing.catid = Category.id", "LEFT JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.id AND Totals.extension = 'com_content'", "LEFT JOIN #__jreviews_content AS `Field` ON Field.contentid = Listing.id", "INNER JOIN #__jreviews_categories AS JreviewsCategory ON Listing.catid = JreviewsCategory.id AND JreviewsCategory.`option` = 'com_content'", "LEFT JOIN #__jreviews_directories AS Directory ON JreviewsCategory.dirid = Directory.id"); if ($fishingmap) { $this->Listing->joins[] = "LEFT JOIN #__relate_listings AS Related ON Related.id1 = Listing.id"; } // Don't regroup the results by model name keys to save time $this->Listing->primaryKey = false; # Set conditionals based on configuration parameters if ($detail_view) { $conditions[] = 'Listing.id = ' . $id; } if ($dir_id) { $conditions[] = 'JreviewsCategory.dirid IN (' . $dir_id . ')'; } if ($section_id) { $conditions[] = 'Listing.sectionid IN (' . $section_id . ')'; } if ($cat_id) { $conditions[] = 'Listing.catid IN (' . $cat_id . ')'; } if ($listing_id) { $conditions[] = 'Listing.id IN (' . $listing_id . ')'; } if ($filter == 'featured' && !$detail_view) { $conditions[] = 'Field.featured = 1'; } $conditions[] = "Field.{$this->jr_lat} <> ''"; $conditions[] = "Field.{$this->jr_lon} <> ''"; $conditions[] = 'Listing.state = 1'; if ($fishingmap) { $this->Listing->group = array('Listing.id'); } // Paid Listings - add plan cat id isset($this->PaidListings) and $this->PaidListings->applyBeforeFindListingChanges($this->Listing); $listings = $this->Listing->findAll(array('conditions' => $conditions, 'limit' => $limit_results), array()); $custom_fields = array_filter(array_merge($custom_fields, array_keys($icon_fields))); $fields = $this->Field->getFields($custom_fields); $json_data = $this->Geomaps->makeJsonObject($listings, $fields, $this->params['module']); $this->set('json_data', $json_data); if ($cache) { S2Cache::write($json_filename, $json_data); } return $this->render('modules', 'geomaps'); }
function save(&$data, $location = 'listing', $isNew, &$validFields) { $msg = ''; $fieldLocation = inflector::camelize($location); // Check if there are custom fields to save or exit if (isset($data['Field']) && (!is_array($data['Field'][$fieldLocation]) || count($data['Field'][$fieldLocation]) == 1)) { return $msg; } // Define field types that accept predefined options to store the reference values $optionsArray = array("select", "selectmultiple", "checkboxes", "radiobuttons"); if (!empty($validFields)) { foreach ($validFields as $validField) { $fieldName = $validField['name']; $inputValue = ''; if (Sanitize::getVar($data['Field'][$fieldLocation], $fieldName, '') != '' || $validField['type'] == 'code' && Sanitize::getVar($data['__raw']['Field'][$fieldLocation], $fieldName, '') != '') { switch ($validField['type']) { case 'selectmultiple': case 'checkboxes': //Checks for types with options $multi_options = Sanitize::getVar($data['Field'][$fieldLocation], $fieldName, ''); $inputValue = '*' . implode('*', $multi_options) . '*'; break; case 'select': case 'radiobuttons': //Checks for types with options $inputValue = '*' . Sanitize::getString($data['Field'][$fieldLocation], $fieldName) . '*'; break; case 'code': // Affiliate code left unfiltered $inputValue = Sanitize::getString($data['__raw']['Field'][$fieldLocation], $fieldName, ''); break; case 'decimal': $inputValue = Sanitize::getFloat($data['Field'][$fieldLocation], $fieldName); break; case 'integer': $inputValue = Sanitize::getInt($data['Field'][$fieldLocation], $fieldName); break; case 'date': if (Sanitize::getString($data['Field'][$fieldLocation], $fieldName) != '' && Sanitize::getString($data['Field'][$fieldLocation], $fieldName) != null) { $inputValue = strftime(_CURRENT_SERVER_TIME_FORMAT, strtotime(Sanitize::getString($data['Field'][$fieldLocation], $fieldName))); } else { $inputValue = ''; } break; case 'textarea': case 'text': if (isset($validField['_params']['allow_html']) && $validField['_params']['allow_html'] == 1) { $inputValue = Sanitize::stripScripts(Sanitize::getVar($data['__raw']['Field'][$fieldLocation], $fieldName)); $inputValue = stripslashes($inputValue); } else { $inputValue = Sanitize::getString($data['Field'][$fieldLocation], $fieldName, ''); } break; case 'website': case 'email': $inputValue = Sanitize::stripScripts(Sanitize::getVar($data['Field'][$fieldLocation], $fieldName)); break; default: $inputValue = Sanitize::getVar($data['Field'][$fieldLocation], $fieldName); break; } # Modify form post arrays to current values if ($inputValue === '' || $inputValue === '**') { $inputValue = ''; } $data['Field'][$fieldLocation][$fieldName] = $inputValue; } else { // To clear multiple choice fields switch ($validField['type']) { case 'decimal': case 'integer': $data['Field'][$fieldLocation][$fieldName] = null; break; default: $data['Field'][$fieldLocation][$fieldName] = ''; break; } } // Debug custom fields array $msg .= "{$validField['name']}=>{$inputValue}" . "<br />"; } } # Need to check if jreviews_content or jreviews_reviews record exists to decide whether to insert or update the table if ($location == 'review') { App::import('Model', 'jreviews_review_field', 'jreviews'); $JreviewsReviewFieldModel = new JreviewsReviewFieldModel(); $recordExists = $JreviewsReviewFieldModel->findCount(array('conditions' => array('JreviewsReviewField.reviewid= ' . $data['Field']['Review']['reviewid']))); } else { App::import('Model', 'jreviews_content', 'jreviews'); $JreviewsContentModel = new JreviewsContentModel(); $recordExists = $JreviewsContentModel->findCount(array('conditions' => array('JreviewsContent.contentid = ' . $data['Listing']['id']))); } $dbAction = $recordExists ? 'update' : 'insert'; if ($location == 'review') { $this->{$dbAction}('#__jreviews_review_fields', $fieldLocation, $data['Field'], 'reviewid'); } else { if (Configure::read('PaidListings.enabled') && Sanitize::getInt($data, 'paid_category')) { # PaidListings integration - saves all fields to jreviews_paid_listing_fields table and removes unpaid fields from jreviews_content table $PaidListingField = RegisterClass::getInstance('PaidListingFieldModel'); $PaidListingField->save($data); } $this->{$dbAction}('#__jreviews_content', $fieldLocation, $data['Field'], 'contentid'); } }
function index() { // Required for ajax pagination to remember module settings $Session = RegisterClass::getInstance('MvcSession'); $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id')); if (!isset($this->params['module'])) { $this->params['module'] = array(); } // For direct calls to the controller if ($this->ajaxRequest) { $this->params = $Session->get('module_params' . $module_id, null, S2Paths::get('jreviews', 'S2_CMSCOMP')); } else { srand((double) microtime() * 1000000); $this->params['rand'] = rand(); $Session->set('module_rand' . $module_id, $this->params['rand'], S2Paths::get('jreviews', 'S2_CMSCOMP')); $Session->set('module_params' . $module_id, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP')); } # Prevent sql injection $token = Sanitize::getString($this->params, 'token'); $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false)); $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); $conditions = array(); $joins = array(); $order = array(); $having = array(); # Read module parameters $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $cat_id = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); $criteria_id = Sanitize::getString($this->params['module'], 'criteria'); $limit = Sanitize::getString($this->params['module'], 'module_limit', 5); $extension = Sanitize::getString($this->params['module'], 'extension'); $extension = $extension != '' ? $extension : 'com_content'; if (isset($this->Listing)) { $this->Listing->_user = $this->_user; // This parameter determines the module mode $sort = Sanitize::getString($this->params['module'], 'listing_order'); $custom_order = Sanitize::getString($this->params['module'], 'custom_order'); $custom_where = Sanitize::getString($this->params['module'], 'custom_where'); if ($extension != 'com_content' && in_array($sort, array('topratededitor', 'featuredrandom', 'rhits'))) { echo "You have selected the {$sort} mode which is not supported for components other than com_content. Please read the tooltips in the module parameters for more info on allowed settings."; return; } # Category auto detect if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') { $ids = CommonController::_discoverIDs($this); extract($ids); } # Set conditionals based on configuration parameters if ($extension == 'com_content') { // Only works for core articles $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )', 'Listing.access <= ' . $this->_user->gid)); // Remove unnecessary fields from model query $this->Listing->modelUnbind(array('Listing.fulltext AS `Listing.description`', 'Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`', 'User.email AS `User.email`')); $cat_id != '' and $conditions[] = 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')'; $cat_id == '' and $section_id != '' and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')'; $cat_id == '' and $dir_id != '' and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')'; $cat_id == '' and $criteria_id != '' and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')'; } else { if (Sanitize::getInt($this->params['module'], 'cat_auto') && method_exists($this->Listing, 'catUrlParam')) { if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) { $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } } elseif ($cat_id) { $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } } $listing_id and $conditions[] = "Listing.{$this->Listing->realKey} IN (" . cleanIntegerCommaList($listing_id) . ")"; switch ($sort) { case 'random': $order[] = 'RAND(' . $this->params['rand'] . ')'; break; case 'featuredrandom': $conditions[] = 'featured > 0'; $order[] = 'RAND(' . $this->params['rand'] . ')'; break; case 'topratededitor': $conditions[] = 'Totals.editor_rating > 0'; break; // Editor rating sorting options dealt with in the Listing->processSorting method } # Custom WHERE $tokenMatch and $custom_where and $conditions[] = $custom_where; # Filtering options $having = array(); // Listings submitted in the past x days $entry_period = Sanitize::getInt($this->params['module'], 'filter_listing_period'); if ($entry_period > 0 && $this->Listing->dateKey) { $conditions[] = "Listing.{$this->Listing->dateKey} >= DATE_SUB('" . _CURRENT_SERVER_TIME . "', INTERVAL {$entry_period} DAY)"; } // Listings with reviews submitted in past x days $review_period = Sanitize::getInt($this->params['module'], 'filter_review_period'); if ($review_period > 0) { $conditions[] = "Review.created >= DATE_SUB(CURDATE(), INTERVAL {$review_period} DAY)"; $joins[] = 'LEFT JOIN #__jreviews_comments AS Review ON Listing.' . $this->Listing->realKey . ' = Review.pid'; } // Listings with review count higher than $filter_review_count = Sanitize::getInt($this->params['module'], 'filter_review_count'); $filter_review_count > 0 and $conditions[] = "Totals.user_rating_count >= " . $filter_review_count; // Listings with avg rating higher than $filter_avg_rating = Sanitize::getFloat($this->params['module'], 'filter_avg_rating'); $filter_avg_rating > 0 and $conditions[] = 'Totals.user_rating >= ' . $filter_avg_rating; $this->Listing->group = array(); // Exlude listings without ratings from the results $join_direction = in_array($sort, array('rating', 'rrating', 'topratededitor', 'reviews')) ? 'INNER' : 'LEFT'; $this->Listing->joins['Total'] = "{$join_direction} JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.{$this->Listing->realKey} AND Totals.extension = " . $this->quote($extension); # Modify query for correct ordering. Change FIELDS, ORDER BY and HAVING BY directly in Listing Model variables if ($tokenMatch and $custom_order) { $this->Listing->order[] = $custom_order; } elseif (empty($order) && $extension == 'com_content') { $this->Listing->processSorting($sort, ''); } elseif (empty($order) && ($order = $this->_processSorting($sort))) { $order = array($order); } $queryData = array('fields' => array('Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.user_comment_count AS `Review.review_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', 'Totals.editor_comment_count AS `Review.editor_review_count`'), 'joins' => $joins, 'conditions' => $conditions, 'limit' => $this->module_limit, 'offset' => $this->module_offset, 'having' => $having); isset($order) and !empty($order) and $queryData['order'] = $order; // Trigger addFields for $listing results. Checked in Everywhere model $this->Listing->addFields = true; $listings = $this->Listing->findAll($queryData); if (Sanitize::getInt($this->params['module'], 'ajax_nav', 1)) { unset($queryData['joins']['Section'], $queryData['joins']['Category'], $queryData['joins']['Directory'], $queryData['joins']['Criteria'], $queryData['joins']['User'], $queryData['order']); $count = $this->Listing->findCount($queryData, 'DISTINCT Listing.' . $this->Listing->realKey); } else { $count = $this->module_limit; } } else { $listings = array(); $count = 0; } unset($this->Listing); # Send variables to view template $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'subclass' => 'listing', 'listings' => $listings, 'total' => $count)); $page = $this->render('modules', 'listings'); if ($this->ajaxRequest) { return $this->ajaxResponse($page, false); } else { return $page; } }