function _edit() { $this->autoRender = false; $this->autoLayout = false; $response = array(); $review_id = Sanitize::getInt($this->params, 'review_id'); $extension = $this->Review->getReviewExtension($review_id); // Dynamic loading Everywhere Model for given extension $this->Everywhere->loadListingModel($this, $extension); $fields = array('Criteria.id AS `Criteria.criteria_id`', 'Criteria.criteria AS `Criteria.criteria`', 'Criteria.state AS `Criteria.state`', 'Criteria.required AS `Criteria.required`', 'Criteria.tooltips AS `Criteria.tooltips`', 'Criteria.weights AS `Criteria.weights`', 'Criteria.config AS `ListingType.config`'); $review = $this->Review->findRow(array('fields' => $fields, 'conditions' => array('Review.id = ' . $review_id))); # Override global configuration isset($review['ListingType']) and $this->Config->override($review['ListingType']['config']); $review['Criteria']['required'] = explode("\n", Sanitize::getVar($review['Criteria'], 'required')); if (count($review['Criteria']['required']) != count($review['Criteria']['criteria'])) { $review['Criteria']['required'] = array_fill(0, count($review['Criteria']['criteria']), 1); } if (!$this->Access->canEditReview($review['User']['user_id'])) { return $this->ajaxError(s2Messages::accessDenied()); } # Set the theme suffix if ($review['Review']['extension'] == 'com_content') { $this->Theming->setSuffix(array('listing_id' => $review['Review']['listing_id'])); } # Get custom fields for review form is form is shown on page $review_fields = $this->Field->getFieldsArrayNew($review['Criteria']['criteria_id'], 'review', $review); $review['Review']['criteria_id'] = $review['Criteria']['criteria_id']; # Form integrity $this->set(array('User' => $this->_user, 'Access' => $this->Access, 'review' => $review, 'review_fields' => $review_fields, 'formTokenKeys' => $this->formTokenKeys)); return $this->ajaxUpdateDialog($this->render('reviews', 'create')); }
function overallRatings($listing, $page, $type = '') { $editor_reviews = $this->Config->getOverride('author_review', $listing['ListingType']['config']); $user_reviews = $this->Config->getOverride('user_reviews', $listing['ListingType']['config']); if (!($listing['Criteria']['state'] == 1 && ($editor_reviews || $user_reviews))) { return ''; } $ratings = '<div class="overall_ratings">'; // editor ratings if ($editor_reviews && $type != 'user') { $editor_rating = Sanitize::getVar($listing['Review'], 'editor_rating'); $editor_rating_count = Sanitize::getInt($listing['Review'], 'editor_rating_count'); $rating_stars = $this->drawStars($editor_rating, $this->Config->rating_scale, 'editor'); $rating_value = $this->round($editor_rating, $this->Config->rating_scale); $rating_count = $editor_rating_count > 1 ? ' (' . $editor_rating_count . ')' : ''; $ratings .= '<div class="overall_editor" title="' . __t("Editor rating", true) . '">'; $ratings .= '<span class="rating_label jrIcon jrIconEditorReview">' . __t("Editor rating", true) . '</span>'; $ratings .= '<div class="rating_stars">' . $rating_stars . '</div>'; $ratings .= '<span class="rating_value">' . $rating_value . $rating_count . '</span>'; $ratings .= '</div>'; } // user ratings if ($page == 'content' && $user_reviews && $type != 'editor') { $user_rating = Sanitize::getVar($listing['Review'], 'user_rating'); $rating_stars = $this->drawStars($user_rating, $this->Config->rating_scale, 'user'); $rating_value = $this->round($user_rating, $this->Config->rating_scale); $rating_count = Sanitize::getInt($listing['Review'], 'user_rating_count'); $review_s = ""; if ($rating_count > 1) { $review_s = "reviews"; } else { $review_s = "review"; } $ratings .= '<div class="overall_user rating" title="' . __t("User rating", true) . '">'; $ratings .= '<span class="rating_label jrIcon jrIconUserReviews">' . __t("User rating", true) . '</span>'; $ratings .= '<div class="rating_stars">' . $rating_stars . '</div>'; $ratings .= '<span class="rating_value average">' . $rating_value . '<span class="best"><span class="value-title" title="' . $this->Config->rating_scale . '"></span></span> (<span class="count">' . $rating_count . '</span> ' . $review_s . ')</span>'; $ratings .= '</div>'; } else { if ($page == 'list' && $user_reviews && $this->Config->list_show_user_rating && $type != 'editor') { $user_rating = Sanitize::getVar($listing['Review'], 'user_rating'); $rating_stars = $this->drawStars($user_rating, $this->Config->rating_scale, 'user'); $rating_value = $this->round($user_rating, $this->Config->rating_scale); $rating_count = Sanitize::getInt($listing['Review'], 'user_rating_count'); $review_s = ""; if ($rating_count > 1) { $review_s = "reviews"; } else { $review_s = "review"; } $ratings .= '<div class="overall_user" title="' . __t("User rating", true) . '">'; $ratings .= '<span class="rating_label jrIcon jrIconUserReviews">' . __t("User rating", true) . '</span>'; $ratings .= '<div class="rating_stars">' . $rating_stars . '</div>'; $ratings .= '<span class="rating_value">' . $rating_value . ' (<span class="count">' . $rating_count . '</span> ' . $review_s . ')</span>'; $ratings .= '</div>'; } } $ratings .= '</div>'; return $ratings; }
function _save() { $response = array(); $this->Config->twitter_oauth = Sanitize::getVar($this->data, 'twitter_oauth'); $this->Config->store(); $response[] = 'jreviews_admin.dialog.close();'; return $this->ajaxResponse($response); }
function beforeSave(&$data) { // Convert Control Value array to string if (isset($data['Group']['control_value'])) { $control_value = Sanitize::getVar($data['Group'], 'control_value'); $data['Group']['control_value'] = !empty($control_value) ? '*' . implode('*', $control_value) . '*' : ''; } else { $data['Group']['control_field'] = ''; } }
function _edit() { $this->autoRender = false; $this->autoLayout = false; $response = array(); $review_id = Sanitize::getInt($this->params, 'review_id'); $extension = $this->Review->getReviewExtension($review_id); // Dynamic loading Everywhere Model for given extension $this->Everywhere->loadListingModel($this, $extension); // unset($this->Review->joins['listings'],$this->Review->joins['jreviews_categories'],$this->Review->joins['criteria']); $fields = array('Criteria.id AS `Criteria.criteria_id`', 'Criteria.criteria AS `Criteria.criteria`', 'Criteria.state AS `Criteria.state`', 'Criteria.required AS `Criteria.required`', 'Criteria.tooltips AS `Criteria.tooltips`', 'Criteria.weights AS `Criteria.weights`'); $review = $this->Review->findRow(array('fields' => $fields, 'conditions' => array('Review.id = ' . $review_id))); $review['Criteria']['required'] = explode("\n", Sanitize::getVar($review['Criteria'], 'required')); if (count($review['Criteria']['required']) != count($review['Criteria']['criteria'])) { $review['Criteria']['required'] = array_fill(0, count($review['Criteria']['criteria']), 1); } if (!$this->Access->canEditReview($review['User']['user_id'])) { return $this->ajaxError(s2Messages::accessDenied()); } # Get custom fields for review form is form is shown on page $review_fields = $this->Field->getFieldsArrayNew($review['Criteria']['criteria_id'], 'review', $review); $this->set(array('User' => $this->_user, 'Access' => $this->Access, 'review' => $review, 'review_fields' => $review_fields)); return $this->ajaxUpdateDialog($this->render('reviews', 'create')); }
/** * 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)); }
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'); }
private function __relatedlistings(&$listing, &$settings, &$conditions) { $match = Sanitize::getString($settings, 'match'); $curr_fname = Sanitize::getString($settings, 'curr_fname'); $match_fname = Sanitize::getString($settings, 'match_fname'); $created_by = $listing['User']['user_id']; $listing_id = $listing['Listing']['listing_id']; $title = $listing['Listing']['title']; $custom_order = Sanitize::getString($settings, 'custom_order'); $custom_order and $this->Listing->order[] = $custom_order; switch ($match) { case 'id': // Specified field matches the current listing id if ($curr_fname != '') { $conditions[] = "`Field`.{$curr_fname} = " . (int) $listing_id; $conditions[] = 'Listing.id <> ' . $listing_id; } else { $this->abort = true; } break; case 'about': // Specified field matches the current listing id if ($curr_fname != '' && ($field = Sanitize::getVar($listing['Field']['pairs'], $curr_fname))) { $value = $field['type']['relatedlisting'] ? $field['real_value'][0] : $field['value'][0]; $conditions[] = "Listing.id = " . (int) $value; } else { $this->abort = true; } break; case 'field': // Specified field matches the current listing field of the same name $field_conditions = array(); if ($curr_fname != '' && ($field = Sanitize::getVar($listing['Field']['pairs'], $curr_fname))) { foreach ($field['value'] as $value) { if (in_array($field['type'], array('selectmultiple', 'checkboxes'))) { $field_conditions[] = "`Field`.{$curr_fname} LIKE " . $this->quoteLike('*' . $value . '*'); } elseif (in_array($field['type'], array('select', 'radiobuttons'))) { $field_conditions[] = "`Field`.{$curr_fname} = " . $this->quote('*' . $value . '*'); } elseif ($field['type'] == 'relatedlisting') { $value = $field['real_value'][0]; $field_conditions[] = "`Field`.{$curr_fname} = " . (int) $value; } else { $field_conditions[] = "`Field`.{$curr_fname} = " . $this->quote($value); } } !empty($field_conditions) and $conditions[] = '(' . implode(' OR ', $field_conditions) . ')'; $conditions[] = 'Listing.id <> ' . $listing_id; } else { $this->abort = true; } break; case 'diff_field': // Specified field matches a different field in the current listing $curr_listing_fname = $match_fname; $search_listing_fname = $curr_fname; $field_conditions = array(); if ($curr_listing_fname != '' && $search_listing_fname != '' && ($curr_field = Sanitize::getVar($listing['Field']['pairs'], $curr_listing_fname))) { if (!($search_field = Sanitize::getVar($listing['Field']['pairs'], $search_listing_fname))) { // Need to query the field type $query = "SELECT fieldid AS field_id,type FROM #__jreviews_fields WHERE name = " . $this->quote($search_listing_fname); $this->_db->setQuery($query); $search_field = array_shift($this->_db->loadAssocList()); } foreach ($curr_field['value'] as $value) { if (in_array($search_field['type'], array('selectmultiple', 'checkboxes'))) { $field_conditions[] = "`Field`.{$search_listing_fname} LIKE " . $this->quoteLike('*' . $value . '*'); } elseif (in_array($search_field['type'], array('select', 'radiobuttons'))) { $field_conditions[] = "`Field`.{$search_listing_fname} = " . $this->quote('*' . $value . '*'); } elseif ($search_field['type'] == 'relatedlisting') { $value = $curr_field['real_value'][0]; $field_conditions[] = "`Field`.{$search_listing_fname} = " . (int) $value; } else { $field_conditions[] = "`Field`.{$search_listing_fname} = " . $this->quote($value); } } !empty($field_conditions) and $conditions[] = '(' . implode(' OR ', $field_conditions) . ')'; $conditions[] = 'Listing.id <> ' . $listing_id; } else { $this->abort = true; } break; case 'title': // Specified field matches the current listing title if ($curr_fname != '') { // Need to find out the field type. First check if the field exists for this listing type if (!($field = Sanitize::getVar($listing['Field']['pairs'], $curr_fname))) { // Need to query the field type $query = "SELECT fieldid AS field_id,type FROM #__jreviews_fields WHERE name = " . $this->quote($curr_fname); $this->_db->setQuery($query); $field = array_shift($this->_db->loadAssocList()); } switch ($field['type']) { case 'relatedlisting': $this->abort = true; break; case 'text': $conditions[] = "`Field`.{$curr_fname} = " . $this->quote($title); break; case 'select': case 'selectmultiple': case 'radiobuttons': case 'checkboxes': # Need to find the option value using the option text $query = "\n SELECT \n value \n FROM \n #__jreviews_fieldoptions \n WHERE \n fieldid = " . (int) $field['field_id'] . "\n AND \n text = " . $this->quote($title); $this->_db->setQuery($query); $value = $this->_db->loadResult(); if ($value != '') { if (in_array($field['type'], array('select', 'radiobuttons'))) { $conditions[] = "`Field`.{$curr_fname} = " . $this->quote('*' . $value . '*'); } else { $conditions[] = "`Field`.{$curr_fname} LIKE " . $this->quoteLike('*' . $value . '*'); } } else { $this->abort = true; } break; } $conditions[] = 'Listing.id <> ' . $listing_id; } break; case 'owner': // The listing owner matches the current listing owner $conditions[] = 'Listing.created_by = ' . $created_by; $conditions[] = 'Listing.id <> ' . $listing_id; break; } }
$url_param = $url; $url = str_replace('menu', '', $url); $db = cmsFramework::getDB(); $query = "SELECT * FROM #__menu WHERE id = " . $menu_id; $db->setQuery($query); $menu = end($db->loadObjectList()); $mparams = getCmsVersion() == CMS_JOOMLA16 ? json_decode($menu->params, true) : stringToArray($menu->params); if (isset($mparams['action'])) { $action = paramsRoute((int) $mparams['action']); $_REQUEST['Itemid'] = $_GET['Itemid'] = $menu->id; // For default - home page menu unset($mparams['action']); $menu_params['data'] = $mparams; $filters = array('dir' => 'dirid', 'section' => 'sectionid', 'cat' => 'catid', 'criteria' => 'criteriaid'); foreach ($filters as $key => $key2) { $menu_params[$key] = Sanitize::getVar($mparams, $key2); is_array($menu_params[$key]) and $menu_params[$key] = implode(',', $menu_params[$key]); } // $menu_params['url'] = 'menu'; $menu_params['data']['component_menu'] = true; $menu_params['data']['controller'] = $action[0]; $menu_params['data']['action'] = $action[1]; } } $Dispatcher = new S2Dispatcher('jreviews'); echo $Dispatcher->dispatch($menu_params); unset($db, $User, $menu, $Dispatcher); function paramsRoute($action) { $a = array("100" => "m", "0" => array('directories', 'index'), "1" => array('categories', 'section'), "2" => array('categories', 'category'), "3" => array('listings', 'create'), "4" => array('categories', 'toprated'), "5" => array('categories', 'topratededitor'), "6" => array('categories', 'latest'), "7" => array('categories', 'popular'), "8" => array('categories', 'mostreviews'), "9" => array('categories', 'featured'), "10" => array('reviews', 'myreviews'), "11" => array('search', 'index'), "12" => array('categories', 'mylistings'), "13" => array('categories', 'favorites'), "14" => array('reviews', 'latest'), "15" => array('reviews', 'latest_user'), "16" => array('reviews', 'latest_editor'), "17" => array('discussions', 'latest'), "18" => array('reviews', 'rankings'), "19" => array('paidlistings', 'myaccount'), "20" => array('paidlistings_plans', 'index'), "21" => array('categories', 'custom')); return $a[$action];
if (getCmsVersion() == CMS_JOOMLA15) { define('_PLUGIN_DIR_NAME', 'plugins'); } else { define('_PLUGIN_DIR_NAME', 'mambots'); } } $query = "SELECT published,params FROM #__" . _PLUGIN_DIR_NAME . " WHERE element = 'jreviews' AND folder = 'content' LIMIT 1"; $CMS->_db->setQuery($query); $jrbot = current($CMS->_db->loadObjectList()); $params = stringToArray($jrbot->params); $published = $jrbot->published; if ((int) (!$published)) { return; } $frontpageOff = Sanitize::getVar($params, 'frontpage'); $blogLayoutOff = Sanitize::getVar($params, 'blog'); # Get theme, suffix and load CSS so it's not killed by the built-in cache if (getCmsVersion() == CMS_JOOMLA10 || getCmsVersion() == CMS_MAMBO46) { if ($option == 'com_content' && ($task == 'category' || $task == 'section' || $blogLayoutOff && $task == 'blogsection' || $blogLayoutOff && $task == 'blogcategory') || $frontpageOff && $option == 'com_frontpage') { return; } } elseif ($blogLayoutOff && $option == 'com_content' && ($view == 'category' || $view == 'section') && ($layout == 'blog' || $layout == 'blogfull')) { return; } elseif ($frontpageOff && $view == 'frontpage') { return; } jimport('joomla.plugin.plugin'); class plgContentJreviews extends JPlugin { function plgContentJreviews(&$subject, $params) {
function _changeOrder() { $row_id = Sanitize::getInt($this->params, 'entry_id'); $inc = Sanitize::getVar($this->params, 'direction'); // Move row $group = $this->Group->findRow(array('conditions' => array('groupid = ' . $row_id))); $group['Group']['groupid'] = $group['Group']['group_id']; unset($group['Group']['group_id']); $this->Group->Result = $group; $this->Group->move($inc, "type = '{$group['Group']['type']}'"); $this->data['Group']['type'] = $group['Group']['type']; return $this->index(); }
function __seo_fields(&$page) { if ($tag = Sanitize::getVar($this->params, 'tag')) { $field = 'jr_' . $tag['field']; // $value = $tag['value']; // Field value underscore fix: remove extra menu parameter not removed in routes regex $value = preg_replace(array('/_m[0-9]+$/', '/_m$/', '/_$/', '/:/'), array('', '', '', '-'), $tag['value']); $query = "\n SELECT \n fieldid,type,metatitle,metakey,metadesc \n FROM \n #__jreviews_fields \n WHERE \n name = " . $this->quote($field) . " AND `location` = 'content'\n "; $this->_db->setQuery($query); $meta = $this->_db->loadObjectList(); if ($meta) { $meta = $meta[0]; $multichoice = array('select', 'selectmultiple', 'checkboxes', 'radiobuttons'); if (in_array($meta->type, $multichoice)) { $query = "\n SELECT \n optionid, text \n FROM \n #__jreviews_fieldoptions \n WHERE \n fieldid = '{$meta->fieldid}' AND value = " . $this->quote(stripslashes($value)); $this->_db->setQuery($query); $fieldValue = array_shift($this->_db->loadAssocList()); $fieldValue = $fieldValue['text']; } else { $fieldValue = urldecode($value); } $page['title'] = $meta->metatitle == '' ? $fieldValue : str_replace("{FIELDVALUE}", $fieldValue, $meta->metatitle); $page['keywords'] = str_replace("{FIELDVALUE}", $fieldValue, $meta->metakey); $page['description'] = str_replace("{FIELDVALUE}", $fieldValue, $meta->metadesc); $page['show_title'] = $this->Config->seo_title; $page['show_description'] = $this->Config->seo_description; } } }
/** * Returns sef urls passed as posted data via curl * Used to get front end sef urls from admin side * */ function _sefUrl() { $sef_urls = array(); $urls = Sanitize::getVar($this->data, 'url'); if (empty($urls)) { return; } foreach ($urls as $key => $url) { $sef_urls[$key] = cmsFramework::route($url); } echo json_encode($sef_urls); }
/** * 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)); }
function loadWysiwygEditor() { return $this->in_groups(Sanitize::getVar($this->Config, 'addnewwysiwyg')); }
function delete() { $cat_ids = array(); $response = array(); $boxchecked = Sanitize::getInt($this->params['form'], 'boxchecked'); $cat_id = Sanitize::getInt($this->params['form'], 'cat_id'); $cat_ids = Sanitize::getVar($this->params['form'], 'cid'); if (!$boxchecked && $cat_id) { $cat_ids = array($cat_id); } if (!empty($cat_ids)) { $query = "\n SELECT\n COUNT(*)\n FROM\n #__jreviews_comments AS Review\n INNER JOIN\n #__content AS Content ON Content.id = Review.pid\n WHERE\n Review.mode = 'com_content'\n AND Content.catid IN ( " . implode(',', $cat_ids) . " )\n "; $this->_db->setQuery($query); $reviews = $this->_db->loadResult(); if (!empty($reviews)) { $response[] = "jreviews_admin.dialog.close();"; $response[] = "s2Alert('Some of the categories you are trying to delete have reviews and therefore cannot be deleted. Please choose categories without reviews or delete the reviews first.');"; return $this->ajaxResponse($response); } $response[] = 'jreviews_admin.dialog.close();'; foreach ($cat_ids as $cat_id) { $removed = $this->JreviewsCategory->delete('id', $cat_id); $removed and $response[] = "jreviews_admin.tools.removeRow('category{$cat_id}');"; } } return $this->ajaxResponse($response); }
function index() { $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 $listing_type_id = Sanitize::getInt($this->params, 'listingtype', false); # Find the correct set of params to use if ($this->ajaxRequest && $listing_type_id) { $listingType = $this->Criteria->getCriteria(array('criteria_id' => $listing_type_id)); if (isset($listingType['ListingType']['config']['userfavorites'])) { $userfavoritesParams = $listingType['ListingType']['config']['userfavorites']; $userfavoritesParams['criteria'] = implode(',', Sanitize::getVar($userfavoritesParams, 'criteria', array())); $this->params['module'] = array_merge($this->params['module'], $userfavoritesParams); } } 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()); } # Get cached vesion /* if($this->_user->id === 0) { $page = $this->cached($this->here); if($page) { return $this->ajaxRequest ? $this->ajaxResponse($page,false) : $page; } } */ srand((double) microtime() * 1000000); $this->params['rand'] = rand(); isset($this->params['module']) and $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); // Read the module parameters $img_width = Sanitize::getInt($this->params['module'], 'img_width', 50); $random_mode = Sanitize::getString($this->params['module'], 'random_mode', 'Random Users'); $favorites_mode = Sanitize::getString($this->params['module'], 'favorites_mode', 'Other users interested in {title}'); $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5); $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10)); # Get url params for current controller/action if (!$this->ajaxRequest) { $url = Sanitize::getString($_REQUEST, 'url'); $route['url']['url'] = $url; $route['data'] = array(); $route = S2Router::parse($route, true, 'jreviews'); # Check if page is listing detail $detail = Sanitize::getString($route['url'], 'extension', 'com_content') == 'com_content' && isset($route['data']) && Sanitize::getString($route['data'], 'controller') == 'listings' && Sanitize::getString($route['data'], 'action') == 'detail' ? true : false; # Initialize variables $listing_id = $detail ? Sanitize::getInt($route, 'id') : Sanitize::getInt($this->params, 'id'); $option = Sanitize::getString($this->params, 'option'); $view = Sanitize::getString($this->params, 'view'); $task = Sanitize::getString($this->params, 'task'); $listing_title = ''; } else { $detail = true; $listing_id = Sanitize::getInt($this->params, 'id'); } # Article auto-detect - only for com_content if ($detail || 'com_content' == $option && ('article' == $view || 'view' == $task)) { $query = "SELECT Listing.id, Listing.title FROM #__content AS Listing WHERE Listing.id = " . $listing_id; $this->_db->setQuery($query); $listing = current($this->_db->loadObjectList()); $listing_title = $listing->title; } else { $listing_id = null; } $profiles = $this->Community->getListingFavorites($listing_id, $this->_user->id, $this->params); $total = count($profiles); $this->set(array('profiles' => $profiles, 'listing_title' => $listing_title, 'limit' => $limit, 'total' => $total)); $this->_completeModuleParamsArray(); $page = $this->ajaxRequest && empty($profiles) ? '' : $this->render('modules', 'favorite_users'); # Save cached version /* if($this->_user->id ===0) { $this->cacheView('modules','userfavorites',$this->here, $page); } */ return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page; }
/** * Creates a thumbnail if it doesn't already exist and returns an array with full paths to original image and thumbnail * returns false if thumbnail cannot be created */ function makeThumb($listing_id, $image, $cat_image, $attributes = array()) { $imageName = ''; $this->catImage = false; $this->noImage = false; $tn_mode = Sanitize::getString($attributes, 'tn_mode', 'scale'); $location = Sanitize::getString($attributes, 'location', '_'); if ($location != '_') { $location = '_' . $location . '_'; } $dimensions = Sanitize::getVar($attributes, 'dimensions', array()); if (empty($dimensions)) { $dimensions = array($this->Config->list_image_resize); } if (isset($image['path']) && $image['path'] != '') { if (isset($image['skipthumb']) && $image['skipthumb'] === true) { return array('image' => $image['path'], 'thumbnail' => $image['path']); } $temp = explode('/', $image['path']); $imageName = $temp[count($temp) - 1]; $length = strlen($listing_id); if (substr($imageName, 0, $length + 1) == $listing_id . '_') { // Uploaded image already has entry id prepended so we remove it and put it before the content suffix $imageName = substr($imageName, $length + 1); } $thumbnail = "tn_" . $listing_id . $location . $imageName; $output = array('image' => $this->www . $image['path'], 'thumbnail' => $this->www_tn . $thumbnail); $image_path = trim(isset($image['basepath']) && $image['basepath'] ? $image['path'] : $this->path . $image['path']); // If in administration, then can't use relative path because it will include /administrator defined('MVC_FRAMEWORK_ADMIN') and strpos($image_path, PATH_ROOT) === false and $image_path = PATH_ROOT . str_replace(_DS, DS, $image_path); if ($imageName != '' && file_exists($image_path)) { $this->image_size = getimagesize($image_path); if (file_exists($this->path_tn . $thumbnail)) { // Thumbnail exists, so we check if current size is correct $thumbnailSize = getimagesize($this->path_tn . $thumbnail); // Checks the thumbnail width to see if it needs to be resized if ($thumbnailSize[0] == $dimensions[0] || $thumbnailSize[0] != $dimensions[0] && $this->image_size[0] < $dimensions[0] || $tn_mode == 'crop' && $thumbnailSize[0] == $thumbnailSize[1] && $thumbnailSize[0] == $dimensions[0]) { // No resizing is necessary $output['width'] = $thumbnailSize[0]; $output['height'] = $thumbnailSize[1]; return $output; } } // Create the thumbnail if ($newDimensions = $this->{$tn_mode}($image_path, $this->path_tn . $thumbnail, $dimensions)) { $output = array_merge($output, $newDimensions); return $output; } } } if ($this->Config->list_category_image && $cat_image != '') { $this->image_size = getimagesize($this->path . $cat_image); if ($this->image_size[0] == min($this->image_size[0], trim(intval($dimensions[0])))) { // Image is smaller (narrower) than thumb so no thumbnailing is done return array('width' => $this->image_size[0], 'height' => $this->image_size[1], 'image' => $this->www . $cat_image, 'thumbnail' => $this->www . $cat_image); } // Create category thumb $cat_tn = basename($cat_image); if ($newDimensions = $this->{$tn_mode}($this->path . $cat_image, $this->path_tn . 'tn' . $location . $cat_tn, $dimensions)) { $this->catImage = true; return array('width' => $newDimensions['width'], 'height' => $newDimensions['height'], 'image' => $this->www . $cat_image, 'thumbnail' => $this->www_tn . 'tn' . $location . $cat_tn); } } // Create NoImage thumb $this->viewSuffix = ''; $noImagePath = $this->locateThemeFile('theme_images', $this->Config->list_noimage_filename, ''); if ($noImagePath && $this->Config->list_noimage_image && $this->Config->list_noimage_filename != '') { $noImageWww = pathToUrl($noImagePath); $noImageThumbnailPath = $this->path_tn . 'tn' . $location . $this->Config->list_noimage_filename; $thumbExists = file_exists($noImageThumbnailPath); if ($thumbExists) { $noImageSize = getimagesize($noImageThumbnailPath); if ($this->image_size[0] == min($noImageSize[0], trim(intval($dimensions[0])))) { // Image is smaller (narrower) than thumb so no thumbnailing is done return array('width' => $noImageSize[0], 'height' => $noImageSize[1], 'image' => $noImageWww, 'thumbnail' => $noImageWww); } if ($noImageSize[0] != $dimensions[0]) { $newDimensions = $this->{$tn_mode}($noImagePath, $noImageThumbnailPath, $dimensions); } else { $newDimensions = array('width' => $noImageSize[0], 'height' => $noImageSize[1]); } } else { $newDimensions = $this->{$tn_mode}($noImagePath, $noImageThumbnailPath, $dimensions); } $this->noImage = true; return array('width' => $newDimensions['width'], 'height' => $newDimensions['height'], 'image' => $noImageWww, 'thumbnail' => $this->www_tn . 'tn' . $location . $this->Config->list_noimage_filename); } return false; }
function index() { $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model $module_id = Sanitize::getVar($this->params, 'module_id', Sanitize::getVar($this->data, 'module_id')); if (!Sanitize::getVar($this->params['module'], 'community')) { cmsFramework::noAccess(); return; } $conditions = array(); $joins = array(); $order = array(); // 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 module parameters $extension = Sanitize::getString($this->params['module'], 'extension'); $user_id = Sanitize::getInt($this->params, 'user', $this->_user->id); $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5); $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10)); if (!$user_id && !$this->_user->id) { cmsFramework::noAccess(); return; } $cat_id = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); if ($extension == 'com_content') { $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $criteria_ids = Sanitize::getString($this->params['module'], 'criteria'); } else { $dir_id = null; $section_id = null; $criteria_ids = null; } // This parameter determines the module mode $sort = Sanitize::getString($this->params['module'], 'reviews_order'); # Remove unnecessary fields from model query // $this->Review->modelUnbind(); !empty($extension) and $conditions[] = "Review.mode = '{$extension}'"; $conditions[] = "Review.userid = " . (int) $user_id; # Set conditionals based on configuration parameters if ($extension == 'com_content') { // Only works for core articles $conditions = array_merge($conditions, array('( 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.catid > 0')); 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() . ')'; } $conditions[] = $this->Access->canEditListing() ? 'Listing.state >= 0' : 'Listing.state = 1'; !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . $dir_id . ')'; !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . $section_id . ')'; if (!empty($cat_id)) { $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . $cat_id . ')' : 'ParentCategory.id IN (' . $cat_id . ')'; } else { unset($this->Listing->joins['ParentCategory']); } } 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 (' . $cat_id . ')'; } } elseif ($cat_id) { $conditions[] = 'JreviewsCategory.id IN (' . $cat_id . ')'; } } !empty($listing_id) and $conditions[] = "Review.pid IN ({$listing_id})"; $conditions[] = 'Review.published > 0'; switch ($sort) { case 'latest': $order[] = $this->Review->processSorting('rdate'); break; case 'helpful': $order[] = $this->Review->processSorting('helpful'); break; case 'random': srand((double) microtime() * 1000000); $this->params['rand'] = rand(); $order[] = 'RAND(' . $this->params['rand'] . ')'; break; default: $order[] = $this->Review->processSorting('rdate'); break; } $queryData = array('fields' => array(), 'joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $total); # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; // Excludes listing owner info in Everywhere component $this->Review->controller = 'module_reviews'; $reviews = $this->Review->findAll($queryData); $count = count($reviews); # Send variables to view template $this->set(array('module_id' => $module_id, 'reviews' => $reviews, 'total' => $count, 'limit' => $limit)); $this->_completeModuleParamsArray(); $page = $this->ajaxRequest && empty($reviews) ? '' : $this->render('community_plugins', 'community_myreviews'); return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page; }
function validate(&$data, $fieldLocation, $Access) { if (!isset($data['Field'])) { return; } $location = $fieldLocation == 'listing' ? 'content' : 'review'; $query = "\n SELECT \n groupid \n FROM \n #__jreviews_criteria \n WHERE \n id = " . (int) $data['Criteria']['id']; $this->_db->setQuery($query); $groupids = $this->_db->loadResult(); if ($groupids) { appLogMessage("*********Validate fields", 'database'); # PaidListings integration to remove hidden fields from validation $plan_fields = isset($data['Paid']) ? explode(",", Sanitize::getString($data['Paid'], 'fields')) : ''; !empty($plan_fields) and $plan_fields = "'" . implode("','", $plan_fields) . "'"; $queryData = array('conditions' => array('Field.groupid IN (' . $groupids . ')', 'Field.published = 1', "Field.location = '{$location}'")); $plan_fields != '' and $queryData['conditions'][] = "Field.name IN (" . $plan_fields . ")"; $fields = $this->findAll($queryData); if (!$fields) { return; } $valid_fields = array(); $fieldLocation = inflector::camelize($fieldLocation); foreach ($fields as $field) { // Check validation only for displayed fields *access rights* if (in_array($Access->gid, explode(",", $field['Field']['access']))) { $value = Sanitize::getVar($data['Field'][$fieldLocation], $field['Field']['name'], ''); // $value = isset($data['Field'][$fieldLocation][$field['Field']['name']]) ? $data['Field'][$fieldLocation][$field['Field']['name']] : ''; $label = sprintf(__t("You must fill in a valid value for %s.", true), $field['Field']['title']); $name = $field['Field']['name']; $type = $field['Field']['type']; $required = $field['Field']['required']; $valid_fields[] = $field['Field']; $regex = ''; if (!isset($field['Field']['_params']['valid_regex'])) { switch ($field['Field']['type']) { case 'integer': $regex = "^[0-9]+\$"; break; case 'decimal': $regex = "^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)\$"; break; case 'website': $regex = "^(ftp|http|https)+(:\\/\\/)+[a-z0-9_-]+\\.+[a-z0-9_-]"; break; case 'email': $regex = ".+@.*"; break; default: $regex = ''; break; } } elseif ($type != 'date') { $regex = $field['Field']['_params']['valid_regex']; } if (!is_array($value)) { $value = array($value); } elseif ($type == 'selectmultiple' && is_array($value[0])) { $data['Field'][$fieldLocation][$field['Field']['name']] = $data['Field'][$fieldLocation][$field['Field']['name']][0]; $value = $value[0]; } $value = trim(implode(',', $value)); $this->validateInput($value, $name, $type, $label, $required, $regex); } } return $valid_fields; } }
/** * Used in Administration in controllers: * admin_listings_controller.php * Also used in Frontend listings_controller.php in create function. */ function getList($section_id, $cat_ids = '') { $Access = Configure::read('JreviewsSystem.Access'); $query = "\n SELECT \n Category.id AS value, Category.title AS text, Criteria.config AS config, Criteria.id \n FROM \n #__categories AS Category\n RIGHT JOIN \n #__jreviews_categories AS JreviewsCategory ON JreviewsCategory.id = Category.id AND JreviewsCategory.`option` = 'com_content'\n LEFT JOIN\n #__jreviews_criteria AS Criteria On JreviewsCategory.criteriaid = Criteria.id\n WHERE \n Category.published = 1\n AND Category.section IN ({$section_id}) \n " . ($cat_ids != '' ? "\n AND Category.id IN ({$cat_ids})" : '') . "\n ORDER \n BY Category.title\n "; $this->_db->setQuery($query); $categories = $this->_db->loadObjectlist(); // For admin use return all categories if (defined('MVC_FRAMEWORK_ADMIN')) { return $categories; } foreach ($categories as $key => $cat) { if ($cat->config != '') { $config = json_decode($cat->config, true); if (!$Access->canAddListing(Sanitize::getVar($config, 'addnewaccess'))) { unset($categories[$key]); } } } return $categories; }
function _save() { /******************************************************************* * This method is processed inside an iframe * To access any of the DOM elements via jQuery it's necessary to prepend * all jQuery calls with $parentFrame (i.e. $parentFrame.jQuery) ********************************************************************/ $this->autoRender = false; $this->autoLayout = false; $response = array(); $parentFrame = 'window.parent'; $validation = ''; $listing_id = Sanitize::getInt($this->data['Listing'], 'id', 0); $isNew = $this->Listing->isNew = $listing_id == 0 ? true : false; $this->data['email'] = Sanitize::getString($this->data, 'email'); $this->data['name'] = Sanitize::getString($this->data, 'name'); $this->data['categoryid_hidden'] = Sanitize::getInt($this->data['Listing'], 'categoryid_hidden'); $cat_id = Sanitize::getVar($this->data['Listing'], 'catid'); $this->data['Listing']['catid'] = is_array($cat_id) ? (int) array_pop(array_filter($cat_id)) : (int) $cat_id; /*J16*/ $this->data['Listing']['title'] = Sanitize::getString($this->data['Listing'], 'title', ''); $this->data['Listing']['created_by_alias'] = Sanitize::getString($this->data, 'name', ''); if ($this->cmsVersion == CMS_JOOMLA15) { $this->data['sectionid_hidden'] = Sanitize::getInt($this->data['Listing'], 'sectionid_hidden'); $this->data['Listing']['sectionid'] = Sanitize::getInt($this->data['Listing'], 'sectionid'); } else { $this->data['Listing']['language'] = '*'; $this->data['Listing']['access'] = 1; } $category_id = $this->data['Listing']['catid'] ? $this->data['Listing']['catid'] : $this->data['categoryid_hidden']; # Get criteria info $criteria = $this->Criteria->findRow(array('conditions' => array('Criteria.id = (SELECT criteriaid FROM #__jreviews_categories WHERE id = ' . (int) $category_id . ' AND `option` = "com_content") '))); if (!$criteria) { $validation = __t("The category selected is invalid.", true, true); $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } $this->data['Criteria']['id'] = $criteria['Criteria']['criteria_id']; # Override global configuration isset($criteria['ListingType']) and $this->Config->override($criteria['ListingType']['config']); # Perform access checks if ($isNew && !$this->Access->canAddListing()) { return $this->makeJS("{$parentFrame}.s2Alert('" . __t("You are not allowed to submit listings in this category.", true, true) . "')"); } elseif (!$isNew) { $query = "SELECT created_by FROM #__content WHERE id = " . $listing_id; $this->_db->setQuery($query); $listing_owner = $this->_db->loadResult(); if (!$this->Access->canEditListing($listing_owner)) { return $this->makeJS("{$parentFrame}.s2Alert('" . s2Messages::accessDenied() . "')"); } } # Load the notifications observer model component and initialize it. # Done here so it only loads on save and not for all controlller actions. $this->components = array('security', 'notifications'); $this->__initComponents(); if ($this->invalidToken == true) { return $this->makeJS("{$parentFrame}.s2Alert('" . s2Messages::invalidToken() . "')"); } # Override configuration $category = $this->Category->findRow(array('conditions' => array('Category.id = ' . $this->data['Listing']['catid']))); $this->Config->override($category['ListingType']['config']); if ($this->Access->loadWysiwygEditor()) { $this->data['Listing']['introtext'] = Sanitize::stripScripts(Sanitize::stripWhitespace(Sanitize::getVar($this->data['__raw']['Listing'], 'introtext'))); $this->data['Listing']['fulltext'] = Sanitize::stripScripts(Sanitize::stripWhitespace(Sanitize::getVar($this->data['__raw']['Listing'], 'fulltext'))); $this->data['Listing']['introtext'] = html_entity_decode($this->data['Listing']['introtext'], ENT_QUOTES, cmsFramework::getCharset()); $this->data['Listing']['fulltext'] = html_entity_decode($this->data['Listing']['fulltext'], ENT_QUOTES, cmsFramework::getCharset()); } else { $this->data['Listing']['introtext'] = Sanitize::stripAll($this->data['Listing'], 'introtext', ''); if (isset($this->data['Listing']['fulltext'])) { $this->data['Listing']['fulltext'] = Sanitize::stripAll($this->data['Listing'], 'fulltext', ''); } else { $this->data['Listing']['fulltext'] = ''; } } $this->data['Listing']['introtext'] = str_replace('<br>', '<br />', $this->data['Listing']['introtext']); $this->data['Listing']['fulltext'] = str_replace('<br>', '<br />', $this->data['Listing']['fulltext']); if ($this->Access->canAddMeta()) { $this->data['Listing']['metadesc'] = Sanitize::getString($this->data['Listing'], 'metadesc'); $this->data['Listing']['metakey'] = Sanitize::getString($this->data['Listing'], 'metakey'); } // Title alias handling $slug = ''; $alias = Sanitize::getString($this->data['Listing'], 'alias'); if ($isNew && $alias == '') { $slug = S2Router::sefUrlEncode($this->data['Listing']['title']); if (trim(str_replace('-', '', $slug)) == '') { $slug = date("Y-m-d-H-i-s"); } } elseif ($alias != '') { // Alias filled in so we convert it to a valid alias $slug = S2Router::sefUrlEncode($alias); if (trim(str_replace('-', '', $slug)) == '') { $slug = date("Y-m-d-H-i-s"); } } $slug != '' and $this->data['Listing']['alias'] = $slug; # Check for duplicates switch ($this->Config->content_title_duplicates) { case 'category': // Checks for duplicates in the same category $query = "\r\n SELECT \r\n count(*) \r\n FROM \r\n #__content AS Listing WHERE Listing.title = " . $this->_db->Quote($this->data['Listing']['title']) . "\r\n AND Listing.state >= 0 \r\n AND Listing.catid = " . $this->data['Listing']['catid'] . (!$isNew ? " AND Listing.id <> " . $listing_id : ''); $this->_db->setQuery($query); $titleExists = $this->_db->loadResult(); break; case 'no': // Checks for duplicates all over the place $query = "\r\n SELECT \r\n count(*) \r\n FROM \r\n #__content AS Listing\r\n WHERE \r\n Listing.title = " . $this->_db->Quote($this->data['Listing']['title']) . "\r\n AND Listing.state >= 0\r\n " . (!$isNew ? " AND Listing.id <> " . $listing_id : ''); $this->_db->setQuery($query); $titleExists = $this->_db->loadResult(); break; case 'yes': // Duplicates are allowed, no checking necessary $titleExists = false; break; } if ($titleExists && $this->data['Listing']['title'] != '') { // if listing exists $validation = '<span>' . __t("A listing with that title already exists.", true, true) . "</span>"; $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } // Review form display check logic used several times below $revFormSetting = $this->Config->content_show_reviewform; if ($revFormSetting == 'noteditors' && !$this->Config->author_review) { $revFormSetting = 'all'; } $revFormEnabled = !isset($this->data['review_optional']) && $this->Access->canAddReview() && $isNew && ($revFormSetting == 'all' && ($this->Config->author_review || $this->Config->user_reviews) || $revFormSetting == 'authors' && $this->Access->isJreviewsEditor($this->_user->id) || $revFormSetting == 'noteditors' && !$this->Access->isJreviewsEditor($this->_user->id)); // Validation of content default input fields if ($this->cmsVersion == CMS_JOOMLA15) { if (!$this->data['Listing']['catid'] || !$this->data['Listing']['sectionid']) { $this->Listing->validateSetError("sec_cat", __t("You need to select both a section and a category.", true)); } } else { !$this->data['Listing']['catid'] and $this->Listing->validateSetError("sec_cat", __t("You need to select a category.", true)); } // Validate only if it's a new listing if ($isNew) { if (!$this->_user->id) { $this->Listing->validateInput($this->data['name'], "name", "text", __t("You must fill in your name.", true), $this->Config->content_name == "required" ? 1 : 0); $this->Listing->validateInput($this->data['email'], "email", "email", __t("You must fill in a valid email address.", true), $this->Config->content_email == "required" ? 1 : 0); $this->data['name'] = Sanitize::getString($this->data, 'name', ''); $this->data['email'] = Sanitize::getString($this->data, 'email', ''); } else { $this->data['name'] = $this->_user->name; $this->data['email'] = $this->_user->email; } } $this->Listing->validateInput($this->data['Listing']['title'], "title", "text", __t("You must fill in a title for the new listing.", true, true), 1); # Validate listing custom fields $listing_valid_fields =& $this->Field->validate($this->data, 'listing', $this->Access); $this->Listing->validateErrors = array_merge($this->Listing->validateErrors, $this->Field->validateErrors); $this->Listing->validateInput($this->data['Listing']['introtext'], "introtext", "text", __t("You must fill in a summary for the new listing.", true, true), $this->Config->content_summary == "required" ? 1 : 0); $this->Listing->validateInput($this->data['Listing']['fulltext'], "fulltext", "text", __t("You must fill in a description for the new listing.", true, true), $this->Config->content_description == "required" ? 1 : 0); # Validate review custom fields if ($revFormEnabled && $criteria['Criteria']['state']) { // Review inputs $this->data['Review']['userid'] = $this->_user->id; $this->data['Review']['email'] = $this->data['email']; $this->data['Review']['name'] = $this->data['name']; $this->data['Review']['username'] = Sanitize::getString($this->data, 'name', ''); $this->data['Review']['title'] = Sanitize::getString($this->data['Review'], 'title'); $this->data['Review']['location'] = Sanitize::getString($this->data['Review'], 'location'); // deprecated $this->data['Review']['comments'] = Sanitize::getString($this->data['Review'], 'comments'); // Review standard fields $this->Listing->validateInput($this->data['Review']['title'], "rev_title", "text", __t("You must fill in a title for the review.", true, true), $this->Config->reviewform_title == 'required' ? true : false); if ($criteria['Criteria']['state'] == 1) { $criteria_qty = $criteria['Criteria']['quantity']; $ratingErr = 0; if (!isset($this->data['Rating'])) { $ratingErr = $criteria_qty; } else { for ($i = 0; $i < $criteria_qty; $i++) { if (!isset($this->data['Rating']['ratings'][$i]) || (empty($this->data['Rating']['ratings'][$i]) || $this->data['Rating']['ratings'][$i] == 'undefined' || (double) $this->data['Rating']['ratings'][$i] > $this->Config->rating_scale)) { $ratingErr++; } } } $this->Listing->validateInput('', "rating", "text", sprintf(__t("You are missing a rating in %s criteria.", true, true), $ratingErr), $ratingErr); } // Review custom fields $this->Field->validateErrors = array(); // Clear any previous validation errors $review_valid_fields = $this->Field->validate($this->data, 'review', $this->Access); $this->Listing->validateErrors = array_merge($this->Listing->validateErrors, $this->Field->validateErrors); $this->Listing->validateInput($this->data['Review']['comments'], "comments", "text", __t("You must fill in your comment.", true, true), $this->Config->reviewform_comment == 'required' ? true : false); } // if ($revFormEnabled && $criteria['Criteria']['state']) # Validate image fields $this->Uploads->validateImages(); # Validate Captcha security code if ($isNew && $this->Access->showCaptcha()) { if (!isset($this->data['Captcha']['code'])) { $this->Listing->validateSetError("code", __t("The security code you entered was invalid.", true, true)); } elseif ($this->data['Captcha']['code'] == '') { $this->Listing->validateInput($this->data['Captcha']['code'], "code", "text", __t("You must fill in the security code.", true), 1); } else { if (!$this->Captcha->checkCode($this->data['Captcha']['code'], $this->ipaddress)) { $this->Listing->validateSetError("code", __t("The security code you entered was invalid.", true, true)); } } } # Get all validation messages $validation = $this->Listing->validateGetError() . $this->Uploads->getMsg(); # Validation failed if ($validation != '') { $response[] = "var parentForm = {$parentFrame}.jQuery('#jr_listingForm');"; $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "parentForm.find('.button').removeAttr('disabled');"; // Transform textareas into wysiwyg editors if ($this->Access->loadWysiwygEditor()) { App::import('Helper', 'Editor', 'jreviews'); $Editor = new EditorHelper(); $response[] = $parentFrame . '.' . $Editor->transform(true); } // Replace captcha with new instance if ($this->Access->in_groups($this->Config->security_image)) { $captcha = $this->Captcha->displayCode(); $response[] = "{$parentFrame}.jQuery('#captcha').attr('src','{$captcha['src']}');"; $response[] = "{$parentFrame}.jQuery('#jr_captchaCode').val('');"; } $response[] = "parentForm.find('.jr_loadingSmall').hide();"; return $this->makeJS($response); // Can't use ajaxResponse b/c we are in an iframe } # Validation passed, continue... if ($isNew) { $this->data['Listing']['created'] = _CURRENT_SERVER_TIME; //gmdate('Y-m-d H:i:s'); $this->data['Listing']['publish_up'] = _CURRENT_SERVER_TIME; //gmdate('Y-m-d H:i:s'); $this->data['Listing']['created_by'] = $this->_user->id; $this->data['Listing']['publish_down'] = NULL_DATE; $this->data['Field']['Listing']['email'] = $this->data['email']; // If visitor, assign name field to content Alias if (!$this->_user->id) { $this->data['Listing']['created_by_alias'] = $this->data['name']; } // Check moderation settings $this->data['Listing']['state'] = (int) (!$this->Access->moderateListing()); // If listing moderation is enabled, then the review is also moderated if (!$this->data['Listing']['state']) { $this->Config->moderation_reviews = $this->Config->moderation_editor_reviews = $this->Config->moderation_item; } } else { if ($this->Config->moderation_item_edit) { $this->data['Listing']['state'] = (int) (!$this->Access->moderateListing()); } $this->data['Listing']['modified'] = _CURRENT_SERVER_TIME; //gmdate('Y-m-d H:i:s'); $this->data['Listing']['modified_by'] = $this->_user->id; $query = 'SELECT images FROM #__content WHERE id = ' . $this->data['Listing']['id']; $this->_db->setQuery($query); $this->data['Listing']['images'] = $this->_db->loadResult(); // Check total number of images if (!$this->Uploads->checkImageCount($this->data['Listing']['images'])) { $validation .= '<span>' . sprintf(__t("The total number of images is limited to %s", true, true), $this->Config->content_images) . '</span><br />'; $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } } // Process images and update data array if ($this->Uploads->success) { $imageUploadPath = PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS; $this->Uploads->uploadImages($this->data['Listing']['id'], $imageUploadPath); if ($isNew) { // New item $currImages = $this->Uploads->images; } elseif ($this->data['Listing']['images'] != '') { // Editing and there are existing images $currImages = array_merge(explode("\n", $this->data['Listing']['images']), $this->Uploads->images); } else { // Editing and there are no existing images $currImages = $this->Uploads->images; } $this->data['Listing']['images'] = implode("\n", $currImages); } # Save listing $savedListing = $this->Listing->store($this->data); $listing_id = $this->data['Listing']['id']; if (!$savedListing) { $validation .= __t("The was a problem saving the listing", true, true); } // Error on listing save if ($validation != '') { $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } # Save listing custom fields $this->data['Field']['Listing']['contentid'] = $this->data['Listing']['id']; $this->Field->save($this->data, 'listing', $isNew, $listing_valid_fields); # Begin insert review in table if ($revFormEnabled && $criteria['Criteria']['state']) { // Get reviewer type, for now editor reviews don't work in Everywhere components $this->data['Review']['author'] = (int) $this->Access->isJreviewsEditor($this->_user->id); $this->data['Review']['mode'] = 'com_content'; $this->data['Review']['pid'] = (int) $this->data['Listing']['id']; // Force plugin loading on Review model $this->_initPlugins('Review'); $this->Review->isNew = true; $savedReview = $this->Review->save($this->data, $this->Access, $review_valid_fields); } # Before render callback if ($isNew && isset($this->Listing->plgBeforeRenderListingSaveTrigger)) { $plgBeforeRenderListingSave = $this->Listing->plgBeforeRenderListingSave(); switch ($plgBeforeRenderListingSave) { case '0': $this->data['Listing']['state'] = 1; break; case '1': $this->data['Listing']['state'] = 0; break; case '': break; default: return $plgBeforeRenderListingSave; break; } } # Moderation disabled if (!isset($this->data['Listing']['state']) || $this->data['Listing']['state']) { $fields = array('Criteria.criteria AS `Criteria.criteria`', 'Criteria.tooltips AS `Criteria.tooltips`'); $listing = $this->Listing->findRow(array('fields' => $fields, 'conditions' => array('Listing.id = ' . $listing_id)), array('afterFind')); # Facebook wall integration $fb_checkbox = Sanitize::getBool($this->data, 'fb_publish'); $facebook_integration = Sanitize::getBool($this->Config, 'facebook_enable') && Sanitize::getBool($this->Config, 'facebook_listings') && $fb_checkbox; $token = cmsFramework::getCustomToken($listing_id); $facebook_integration and $response[] = $parentFrame . '.jQuery.get(' . $parentFrame . '.s2AjaxUri+' . $parentFrame . '.jreviews.ajax_params()+\'&url=facebook/_postListing/id:' . $listing_id . '&' . $token . '=1\'); '; $url = cmsFramework::route($listing['Listing']['url']); $update_text = $isNew ? __t("Thank you for your submission.", true, true) : __t("The listing was successfully saved.", true, true); //JOEYG CODE //THE FOLLOWING GETS THE LISTING TYPE FROM THE DB FOR THE NEWLY SAVED LISTING //IF THE TYPE IS BUSINESS PROFILE OR PROJECT LISTING THEN DISPLAY THE after_submit.thtml file //ELSE DISPLAY NORMAL MESSAGE //IF WE ONLY WANT TO ADD THE after_submit.thtml if the listing is new then add if ($isNew) { $query = "SELECT `listing_type` FROM `jos_vpbd_content_criteria` WHERE `jos_vpbd_content_criteria`.`listing_id` = " . $this->data['Listing']['id']; $this->_db->setQuery($query); $jg_listing_type = $this->_db->loadResult(); if ($jg_listing_type == 2 || $jg_listing_type == 7) { $update_html = $this->render('listings', 'after_submit'); } else { $update_html = "<a href=\"{$url}\">" . __t("Click here to view your listing", true) . "</a>"; } //ends if/else } else { //not new $update_html = "<a href=\"{$url}\">" . __t("Click here to view your listing", true) . "</a>"; } //ends if($isNew) //ENDS JOEYG ALTER CODE $jsonObject = json_encode(compact('target_id', 'update_text', 'update_html')); $response[] = ' var $parentForm = ' . $parentFrame . '.jQuery(\'#jr_listingForm\'); $parentForm.scrollTo({duration:400,offset:-100}); $parentForm.s2ShowUpdate(' . $jsonObject . '); '; return $this->makeJS($response); } # Moderation enabled $update_text = __t("Thank you for your submission. It will be published once it is verified.", true); $update_html = '<div id=\\"s2Msgjr_listingForm\\" class=\\"jr_postUpdate\\">' . $update_text . '</div>'; $response[] = ' var $parentForm = ' . $parentFrame . '.jQuery(\'#jr_listingForm\'); $parentForm.scrollTo({duration:400,offset:-100},function(){ $parentForm.fadeOut(250,function(){$parentForm.html("' . $update_html . '").show();}); }); '; return $this->makeJS($response); }
function beforeFilter() { # These should be called in each controller where they are required instead of globally $this->_db = cmsFramework::getDB(); $this->_user = cmsFramework::getUser(); # Overcome host restrictions $query = "SET SQL_BIG_SELECTS=1"; $this->_db->setQuery($query); $this->_db->query(); # Fix Joomla bug when language filter is active with default language code hidden in url if (isset($this->params['lang'])) { $this->params['lang'] = cmsFramework::getUrlLanguageCode(); } # Init Access if (isset($this->Access)) { $this->Access->init($this->Config); } App::import('Component', 'theming', 'jreviews'); $this->Theming = ClassRegistry::getClass('ThemingComponent'); $this->Theming->startup($this); # Set pagination vars // First check url, then menu parameter. Otherwise the limit list in pagination doesn't respond b/c menu params always wins $this->limit = Sanitize::getInt($this->params, 'limit', Sanitize::getInt($this->data, 'limit_special', Sanitize::getInt($this->data, 'limit'))); // $this->passedArgs['limit'] = $this->limit; $this->page = Sanitize::getInt($this->data, 'page', Sanitize::getInt($this->params, 'page', 1)); if (!$this->limit) { if (Sanitize::getVar($this->params, 'action') == 'myreviews') { $this->limit = Sanitize::getInt($this->params, 'limit', $this->Config->user_limit); $this->params['default_limit'] = $this->Config->user_limit; } else { $this->limit = Sanitize::getInt($this->params, 'limit', $this->Config->list_limit); $this->params['default_limit'] = $this->Config->list_limit; } } if (Sanitize::getVar($this->params, 'action') == 'myreviews') { $this->params['default_limit'] = $this->Config->user_limit; } else { $this->params['default_limit'] = $this->Config->list_limit; } // Set a hard code limit to prevent abuse $this->limit = max(min($this->limit, 50), 1); // Need to normalize the limit var for modules if (isset($this->params['module'])) { $module_limit = Sanitize::getInt($this->params['module'], 'module_limit', 5); } else { $module_limit = 5; } $this->module_limit = Sanitize::getInt($this->data, 'module_limit', $module_limit); $this->module_page = Sanitize::getInt($this->data, 'module_page', 1); $this->module_page = $this->module_page === 0 ? 1 : $this->module_page; $this->module_offset = (int) ($this->module_page - 1) * $this->module_limit; if ($this->module_offset < 0) { $this->module_offset = 0; } $this->page = $this->page === 0 ? 1 : $this->page; $this->offset = (int) ($this->page - 1) * $this->limit; if ($this->offset < 0) { $this->offset = 0; } # Required further below for Community Model init if (!isset($this->Menu)) { App::import('Model', 'menu', 'jreviews'); $this->Menu = ClassRegistry::getClass('MenuModel'); } if (!$this->ajaxRequest) { if (!($menu_id = Configure::read('_public_menu_id'))) { # Find and set one public Itemid to use for Ajax requests $menu_id = ''; $menu_id = $this->Menu->get('jreviews_public'); $menu_id = $menu_id != '' ? $menu_id : 99999; Configure::write('_public_menu_id', $menu_id); } if (!($search_itemid = Configure::read('_search_itemid'))) { // Set search menu Itemid used in several of the controllers $option = Sanitize::getString($this->params, 'option'); $auto_itemid = Sanitize::getBool($this->Config, 'search_itemid', false); $hc_itemid = Sanitize::getInt($this->Config, 'search_itemid_hc', ''); $search_menuid = $this->Menu->get('jr_advsearch'); $search_itemid = ''; switch ($option) { case 'com_jreviews': // page Itemid is enabled if (!$auto_itemid && $hc_itemid > 0) { $search_itemid = $hc_itemid; } elseif (!$auto_itemid & $search_menuid > 0) { $search_itemid = $search_menuid; } break; default: // Non-JReviews pages - can't use current page Itemid if ($hc_itemid > 0) { $search_itemid = $hc_itemid; } else { $search_itemid = $search_menuid; } break; } $search_itemid == '' and $option == 'com_jreviews' and $search_itemid = Sanitize::getString($this->params, 'Itemid'); Configure::write('_search_itemid', $search_itemid); } $this->set(array('search_itemid' => $search_itemid, 'public_menu_id' => $menu_id)); } if (!defined('MVC_GLOBAL_JS_VARS') && !$this->ajaxRequest && $this->action != '_save') { # Add global javascript variables $this->assets['head-top'][] = '<script type="text/javascript"> /* <![CDATA[ */ var s2AjaxUri = "' . getAjaxUri() . '", jrLanguage = new Array(), jrVars = new Array(), datePickerImage = "' . $this->viewImages . 'calendar.gif", jrPublicMenu = ' . $menu_id . '; jrLanguage["cancel"] = "' . __t("Cancel", true) . '"; jrLanguage["submit"] = "' . __t("Submit", true) . '"; jrLanguage["clearDate"] = "' . __t("Clear", true) . '"; jrLanguage["field.select"] = "' . __t("-- Select --", true) . '"; jrLanguage["field.select_field"] = "' . __t("-- Select %s --", true) . '"; jrLanguage["field.no_results"] = "' . __t("No results found, try a different spelling.", true) . '"; jrLanguage["field.ui_help"] = "' . __t("Start typing for suggestions", true) . '"; jrLanguage["field.ui_add"] = "' . __t("Add", true) . '"; jrLanguage["compare.heading"] = "' . __t("Compare", true) . '"; jrLanguage["compare.compare_all"] = "' . __t("Compare All", true) . '"; jrLanguage["compare.remove_all"] = "' . __t("Remove All", true) . '"; jrLanguage["compare.select_more"] = "' . __t("You need to select more than one listing for comparison.", true) . '"; jrLanguage["compare.select_max"] = "' . __t("You selected maximum number of listings for comparison.", true) . '"; jrVars["locale"] = "' . cmsFramework::getLocale() . '"; /* ]]> */ </script>'; if ($item_id = Sanitize::getInt($this->params, 'Itemid')) { $menu = $this->Menu->getMenuParams($item_id); $meta_desc = Sanitize::getString($menu, 'menu-meta_description'); $meta_keys = Sanitize::getString($menu, 'menu-meta_keywords'); $meta_desc != '' and cmsFramework::meta('description', $meta_desc); $meta_keys != '' and cmsFramework::meta('keywords', $meta_keys); } define('MVC_GLOBAL_JS_VARS', 1); } # Dynamic Community integration loading $community_extension = Configure::read('Community.extension'); $community_extension = $community_extension != '' ? $community_extension : 'community_builder'; App::import('Model', $community_extension, 'jreviews'); $this->Community = new CommunityModel(); # Init plugin system $this->_initPlugins(); }
function section($directory, $section, $attributes = array()) { $dir_title = S2Router::sefUrlEncode($directory['Directory']['slug'], __t("and", true)); $section_title = S2Router::sefUrlEncode($section['slug'], __t("and", true)); $dir_id = $directory['Directory']['dir_id']; $section_id = $section['section_id']; if (Sanitize::getVar($attributes, 'image')) { $section['title'] = $this->Html->image(WWW_ROOT . 'images' . _DS . 'stories' . _DS . $section['image'], array('border' => 0, 'alt' => $section['title'])); unset($attributes['image']); } // Check if there's a jReviews menu for this section to prevent duplicate urls $menuModel = ClassRegistry::getClass('MenuModel'); $menu_id = $menuModel->get('jr_section_menu_id_' . $section_id); if ($menu_id) { if (!$menuModel->get('jr_manyIds_' . $menu_id)) { $url = sprintf($this->routes['menu'], $menu_id); return $this->Html->sefLink($section['title'], $url, $attributes); } } $menu_id = $section['menu_id']; if ($menu_id == '') { $this->routes['section'] = str_replace(array('_m%5$s', '&Itemid=%5$s'), '', $this->routes['section']); } $url = sprintf($this->routes['section'], $dir_title, $section_title, $dir_id, $section_id, $menu_id); return $this->Html->sefLink($section['title'], $url, $attributes); }
/** * Returns a json object of field options used to dynamicaly show and populate dependent fields * */ function _loadFieldData($json = true, $_data = array()) { !empty($_data) and $this->data = $_data; $fields = $field_options = $selected_values = $group_ids = array(); $selected_values_autocomplete = array(); $dependent_fields = $dependent_groups = $control_fields = $fields = $responses = array(); $location = strtolower(Sanitize::getString($this->data, 'fieldLocation', 'content')); $location == 'listing' and $location = 'content'; $recursive = Sanitize::getBool($this->data, 'recursive'); $field_names = Sanitize::getVar($this->data, 'fields'); $control_field = $field_names = is_array($field_names) ? array_filter($field_names) : array($field_names); $page_setup = Sanitize::getInt($this->data, 'page_setup', false); $control_value = Sanitize::getVar($this->data, 'value'); $entry_id = Sanitize::getInt($this->data, 'entry_id'); $referrer = Sanitize::getString($this->data, 'referrer'); $edit = (bool) $entry_id || is_array($control_value); // In adv. search module we make it work like edit for previously searched values which are passed as an array in $control_value # Access check # Need to pass token to validate the listing id and check user access. # Filter passed field names to fix those with double underscores which are checkboxes and radiobuttons foreach ($field_names as $key => $name) { if (substr_count($name, '_') > 1) { $tmp = explode('_', $name); array_pop($tmp); $field_names[$key] = implode('_', $tmp); } } $field_names = array_unique($field_names); /** * We are in edit mode. Find selected values */ if ($page_setup && $entry_id > 0) { # PaidListings integration if ($location == 'content' && Configure::read('PaidListings.enabled') && PaidPlanCategoryModel::isInPaidCategoryByListingId($entry_id)) { // Load the paid_listing_fields table instead of the jos_content table so users can see all their // fields when editing a listing Configure::write('ListingEdit', false); $curr_field_values = PaidListingFieldModel::edit($entry_id); if ($curr_field_values && !empty($curr_field_values)) { $curr_field_values = (array) array_shift($curr_field_values); $curr_field_values['contentid'] = $curr_field_values['element_id']; unset($curr_field_values['element_id'], $curr_field_values['email']); } } if (empty($curr_field_values)) { $query = $location == 'content' ? "SELECT * FROM #__jreviews_content WHERE contentid = {$entry_id}" : "SELECT * FROM #__jreviews_review_fields WHERE reviewid = {$entry_id}"; $this->_db->setQuery($query); $curr_field_values = array_shift($this->_db->loadAssocList()); } if (!empty($curr_field_values)) { foreach ($curr_field_values as $key => $val) { if (substr($key, 0, 3) == 'jr_') { $selected_values[$key] = $val != '' ? is_array($val) ? $val : array($val) : array(); } } } } elseif (is_array($control_value)) { $selected_values = $control_value; $control_value = ''; } /**************************************************************************************** * Control field option selected, so we find all dependent fields and groups * Need to look in FieldOptions, Fields and FieldGroups ****************************************************************************************/ if (!$page_setup) { # Find dependent FieldOptions $query = "\r\n SELECT \r\n DISTINCT Field.name\r\n FROM \r\n #__jreviews_fieldoptions AS FieldOption\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid AND (\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n )\r\n LEFT JOIN\r\n #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n ORDER BY \r\n FieldGroup.ordering, Field.ordering \r\n "; $this->_db->setQuery($query); $field_names = $this->_db->loadResultArray(); # Find dependent Fields $query = "\r\n SELECT \r\n DISTINCT Field.name\r\n FROM \r\n #__jreviews_fields AS Field\r\n LEFT JOIN\r\n #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n AND Field.control_field = " . $this->quote($control_field) . " AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n ORDER BY \r\n FieldGroup.ordering, Field.ordering \r\n "; $this->_db->setQuery($query); $field_names = is_array($field_names) ? array_merge($field_names, $this->_db->loadResultArray()) : $this->_db->loadResultArray(); # Find depedent Field Groups $query = "\r\n SELECT DISTINCT\r\n FieldGroup.groupid\r\n FROM \r\n #__jreviews_groups AS FieldGroup\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.groupid = FieldGroup.groupid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . " \r\n AND FieldGroup.type = " . $this->quote($location) . "\r\n AND FieldGroup.control_field = " . $this->quote($control_field) . "\r\n AND FieldGroup.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n ORDER BY\r\n FieldGroup.ordering\r\n "; $this->_db->setQuery($query); $group_ids = $this->_db->loadResultArray(); !empty($field_names) and $field_names = array_unique($field_names); if (empty($field_names) && empty($group_ids)) { return json_encode(compact('control_field', 'dependent_fields', 'dependent_groups', 'data')); } } # Get info for all fields $query = "\r\n SELECT \r\n Field.fieldid, Field.groupid, Field.title, Field.name, Field.type, Field.options, Field.control_field, Field.control_value, FieldGroup.name AS group_name\r\n FROM \r\n #__jreviews_fields AS Field \r\n LEFT JOIN\r\n #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n WHERE \r\n Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n AND (\r\n " . (!empty($field_names) ? "Field.name IN (" . $this->quote($field_names) . ")" : '') . "\r\n " . (!empty($field_names) && !empty($group_ids) ? " OR " : '') . "\r\n " . (!empty($group_ids) ? "Field.groupid IN (" . $this->quote($group_ids) . ")" : '') . "\r\n )\r\n ORDER BY \r\n FieldGroup.ordering, Field.ordering\r\n "; $this->_db->setQuery($query); $curr_form_fields = $this->_db->loadAssocList('name'); if (empty($curr_form_fields)) { return json_encode(compact('control_field', 'dependent_fields', 'dependent_groups', 'data')); } foreach ($curr_form_fields as $key => $curr_form_field) { $curr_form_fields[$key]['options'] = stringToArray($curr_form_field['options']); } /**************************************************************************************** * Check if fields have any dependents to avoid unnecessary ajax requests * Three tables need to be checked: fieldoptions, fields, and fieldgroups ****************************************************************************************/ # FieldOptions $query = "\r\n SELECT DISTINCT \r\n Field.name AS dependent_field, FieldOption.control_field\r\n FROM \r\n #__jreviews_fieldoptions AS FieldOption\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n AND FieldOption.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n " . (!$page_setup ? "AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n ORDER BY Field.ordering\r\n "; $this->_db->setQuery($query); $controlling_and_dependent_fields = $this->_db->loadAssocList(); # Fields $query = "\r\n SELECT DISTINCT\r\n Field.name AS dependent_field, Field.control_field\r\n FROM \r\n #__jreviews_fields AS Field\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n AND Field.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n " . (!$page_setup ? "AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n ORDER BY Field.ordering\r\n "; $this->_db->setQuery($query); $controlling_and_dependent_fields = is_array($controlling_and_dependent_fields) ? array_merge($controlling_and_dependent_fields, $this->_db->loadAssocList()) : $this->_db->loadAssocList(); # Groups $query = "\r\n SELECT DISTINCT\r\n FieldGroup.name AS dependent_group, FieldGroup.control_field\r\n FROM \r\n #__jreviews_groups AS FieldGroup\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.groupid = FieldGroup.groupid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . " \r\n AND FieldGroup.type = " . $this->quote($location) . "\r\n AND FieldGroup.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n " . (!$page_setup ? "AND FieldGroup.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n ORDER BY\r\n FieldGroup.ordering\r\n "; $this->_db->setQuery($query); $controlling_and_dependent_fields = is_array($controlling_and_dependent_fields) ? array_merge($controlling_and_dependent_fields, $this->_db->loadAssocList()) : $this->_db->loadAssocList(); #Extract controlling and dependent fields foreach ($controlling_and_dependent_fields as $row) { isset($row['dependent_field']) and $dependent_fields[$row['dependent_field']] = $row['dependent_field']; if (isset($row['dependent_group'])) { $group_name = str_replace(' ', '', $row['dependent_group']); $dependent_groups[$group_name] = $group_name; } $control_fields[$row['control_field']] = $row['control_field']; } $ids_to_names = $ids_to_names_autocomplete = $ids_to_names_noautocomplete = array(); $control_fields_array = array(); foreach ($curr_form_fields as $curr_form_field) { $ordering = Sanitize::getVar($curr_form_field['options'], 'option_ordering', null); $fields[$curr_form_field['name']]['name'] = $curr_form_field['name']; $fields[$curr_form_field['name']]['type'] = $curr_form_field['type']; $fields[$curr_form_field['name']]['group'] = $curr_form_field['group_name']; $fields[$curr_form_field['name']]['autocomplete'] = Sanitize::getVar($curr_form_field['options'], in_array($referrer, array('adv_search', 'adv_search_module')) ? 'autocomplete.search' : 'autocomplete', 0); $fields[$curr_form_field['name']]['autocompletetype'] = Sanitize::getVar($curr_form_field['options'], 'autocomplete.option_type', 'link'); $fields[$curr_form_field['name']]['autocompletepos'] = Sanitize::getVar($curr_form_field['options'], 'autocomplete.option_pos', 'after'); $fields[$curr_form_field['name']]['title'] = $curr_form_field['title']; $entry_id and $fields[$curr_form_field['name']]['selected'] = array(); !is_null($ordering) and $fields[$curr_form_field['name']]['order_by'] = !$ordering ? 'ordering' : 'text'; // Add selected value for text fields if (isset($selected_values[$curr_form_field['name']])) { switch ($fields[$curr_form_field['name']]['type']) { case 'date': if (isset($selected_values[$curr_form_field['name']][0])) { if ($selected_values[$curr_form_field['name']][0] == NULL_DATE) { $fields[$curr_form_field['name']]['selected'] = array(); } else { $fields[$curr_form_field['name']]['selected'] = array(str_replace(" 00:00:00", "", $selected_values[$curr_form_field['name']][0])); } } break; case 'relatedlisting': if (isset($selected_values[$curr_form_field['name']][0]) && $selected_values[$curr_form_field['name']][0] > 0) { $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']]; } break; case 'radiobuttons': case 'select': case 'checkboxes': case 'selectmultiple': if (!empty($selected_values[$curr_form_field['name']])) { $selected_values[$curr_form_field['name']] = explode('*', ltrim(rtrim($selected_values[$curr_form_field['name']][0], '*'), '*')); $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']]; } break; default: $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']]; break; } } // Add control related vars // If field is text type, then it has no control and we check the controlBy values if ($fields[$curr_form_field['name']]['type'] == 'text') { $fields[$curr_form_field['name']]['control'] = false; $fields[$curr_form_field['name']]['controlled'] = $curr_form_field['control_field'] != '' && $curr_form_field['control_value']; } else { $fields[$curr_form_field['name']]['control'] = $recursive ? true : in_array($curr_form_field['name'], $control_fields); $fields[$curr_form_field['name']]['controlled'] = in_array($curr_form_field['name'], $dependent_fields); } if (in_array($curr_form_field['groupid'], $group_ids)) { $fields[$curr_form_field['name']]['controlgroup'] = true; } // Create an array of field ids to field names used below to save on additional queries. // The initial field option values are loaded for the fields in this array if (!$page_setup || !$fields[$curr_form_field['name']]['autocomplete'] || !empty($fields[$curr_form_field['name']]['selected'])) { if (in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) { $ids_to_names[$curr_form_field['fieldid']] = $curr_form_field['name']; } if (!empty($fields[$curr_form_field['name']]['selected']) && $fields[$curr_form_field['name']]['autocomplete'] && in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) { $ids_to_names_autocomplete[$curr_form_field['fieldid']] = $curr_form_field['name']; $selected_values_autocomplete = array_merge($selected_values_autocomplete, $selected_values[$curr_form_field['name']]); } elseif (!$fields[$curr_form_field['name']]['autocomplete'] && in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) { $ids_to_names_noautocomplete[$curr_form_field['fieldid']] = $curr_form_field['name']; } } $control_fields_array[] = $curr_form_field['name']; } //prx($ids_to_names); //prx($ids_to_names_autocomplete); //prx($ids_to_names_noautocomplete); //prx('------------------BEGIN-------------------'); //prx($recursive); //prx($curr_form_fields); //prx($fields); //prx($control_fields); //prx('------------------END-------------------'); /**************************************************************************************** * Build the fields array for control and controlled fields ****************************************************************************************/ # For FieldOption-FieldOption relationships get field options ordered by a-z ASC to start building the fields array. if (!empty($ids_to_names)) { if ($edit) { if (!empty($ids_to_names_autocomplete)) { $query = "\r\n SELECT \r\n Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n FROM \r\n #__jreviews_fieldoptions AS FieldOption\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . " \r\n AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names_autocomplete)) . ") " : '1 = 1') . " \r\n " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n " . (!empty($selected_values_autocomplete) ? "AND FieldOption.value IN ( " . $this->quote($selected_values_autocomplete) . ")" : '') . "\r\n ORDER BY \r\n FieldOption.fieldid, FieldOption.text\r\n "; $this->_db->setQuery($query); $field_options_ac = $this->_db->loadAssocList(); } if (!empty($ids_to_names_noautocomplete)) { $query = "\r\n SELECT \r\n Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n FROM \r\n #__jreviews_fieldoptions AS FieldOption\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . " \r\n AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names_noautocomplete)) . ") " : '1 = 1') . " \r\n " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n ORDER BY \r\n FieldOption.fieldid, FieldOption.text\r\n "; $this->_db->setQuery($query); $field_options_noac = $this->_db->loadAssocList(); } empty($field_options_ac) and $field_options_ac = array(); empty($field_options_noac) and $field_options_noac = array(); $field_options = array_merge($field_options_ac, $field_options_noac); } else { $query = "\r\n SELECT \r\n Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n FROM \r\n #__jreviews_fieldoptions AS FieldOption\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . " \r\n AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names)) . ") " : '1 = 1') . " \r\n " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n ORDER BY \r\n FieldOption.fieldid, FieldOption.text\r\n "; $this->_db->setQuery($query); $field_options = $this->_db->loadAssocList(); } } # For FieldOption-Field relationships get field options ordered by a-z ASC to start building the fields array. if (!$page_setup && !empty($ids_to_names)) { $query = "\r\n SELECT \r\n Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n FROM \r\n #__jreviews_fieldoptions AS FieldOption\r\n LEFT JOIN\r\n #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n WHERE\r\n Field.published = 1 AND Field.location = " . $this->quote($location) . " \r\n AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names)) . ") " : '1 = 1') . " \r\n " . ($page_setup ? " AND Field.control_field = ''" : " AND Field.control_field = " . $this->quote($control_field) . " AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n ORDER BY \r\n FieldOption.fieldid, FieldOption.text\r\n "; $this->_db->setQuery($query); $field_options = array_merge($field_options, $this->_db->loadAssocList()); } foreach ($field_options as $field_option) { $field_id = $field_option['fieldid']; $field_name = $field_option['name']; unset($field_option['fieldid'], $field_option['name']); if (isset($ids_to_names[$field_id])) { $fields[$ids_to_names[$field_id]]['options'][] = $field_option; isset($selected_values[$field_name]) and $fields[$ids_to_names[$field_id]]['selected'] = $selected_values[$field_name]; } } if ($page_setup) { $control_field = array_values($control_fields_array); $dependent_fields = array(); } else { $control_field = $control_field; $dependent_fields = array_values($dependent_fields); } # Edit mode: for each control field that has a selected value find dependent field options foreach ($selected_values as $key => $val) { if (!empty($val) && $val != '' && in_array($key, $field_names)) { foreach ($val as $selected) { $res = $this->_loadFieldData(false, array('recursive' => true, 'fields' => $key, 'value' => array_shift($val), 'fieldLocation' => $location)); if (is_array($res)) { $responses[$res['control_field'][0]][$res['control_value']] = $res; foreach ($res['fields'] as $res_fields) { if (isset($selected_values[$res_fields['name']]) && !empty($res_fields['options']) && empty($fields[$res_fields['name']]['options'])) { $fields[$res_fields['name']] = $res_fields; $fields[$res_fields['name']]['selected'] = $selected_values[$res_fields['name']]; } } } elseif ($fields[$key]['type'] != 'text') { $responses[$key][$selected] = array('location' => $location, 'control_field' => array($key), 'control_value' => $selected, 'dependent_groups' => array(), 'dependent_fields' => array(), 'fields' => array()); } } } } /** DEBUG **/ //if($json) {prx(compact('page_setup','control_field','control_value','dependent_fields','dependent_groups','fields','responses'));} //if($json && !$page_setup) {prx(compact('page_setup','control_field','control_value','dependent_fields','dependent_groups','fields','responses'));} $dependent_groups = array_values($dependent_groups); $location = $location == 'content' ? 'Listing' : 'Review'; return $json ? json_encode(compact('page_setup', 'edit', 'location', 'control_field', 'control_value', 'dependent_groups', 'dependent_fields', 'fields', 'responses')) : compact('location', 'control_field', 'control_value', 'dependent_groups', 'dependent_fields', 'fields'); }
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); }
function relatedListingsJS($listing) { # Detail page widgets $key = 0; $listingtype = Sanitize::getInt($listing['Criteria'], 'criteria_id'); $listing_id = Sanitize::getInt($listing['Listing'], 'listing_id'); $listing_title = Sanitize::getString($listing['Listing'], 'title'); $ajax_init = true; $target_id = $target_class = ''; // Process related listings $related_listings = Sanitize::getVar($listing['ListingType']['config'], 'relatedlistings', array()); $related_listings = array_filter($related_listings); $created_by = Sanitize::getVar($listing['User'], 'user_id'); $field_pairs = $listing['Field']['pairs']; $type = 'relatedlistings'; // Created an array of tab ids => tab indices ?> <script type="text/javascript"> /* <![CDATA[ */ var jrTabArray = {}; jQuery(document).ready(function() { jQuery('.jr_tabs').find('li>a').each(function(i,t) { var tabId = jQuery(t).attr('href'); jrTabArray[tabId] = jQuery(t).parent('li'); }); }); /* ]]> */ </script> <?php foreach ($related_listings as $key => $related_listing) { if (!Sanitize::getInt($related_listing, 'enable', 0)) { continue; } $module_id = 10000 + $listing_id + $key; $target_id = Sanitize::getString($related_listing, 'target_id', 'jrRelatedListings'); $target_class = Sanitize::getString($related_listing, 'target_class'); $moduleParams = compact('module_id', 'ajax_init', 'listing_id', 'type', 'key'); extract($related_listing); $title = str_ireplace('{title}', $listing_title, __t(Sanitize::getString($related_listing, 'title'), true, true)); $title = htmlspecialchars($title, ENT_QUOTES, 'utf-8'); $targetElement = $target_class ? $target_class : $target_id; ?> <script type="text/javascript"> /* <![CDATA[ */ jQuery(document).ready(function() { jreviews.dispatch({'controller':'module_listings','action':'index', 'type':'json', 'data':<?php echo json_encode($moduleParams); ?> , 'onComplete':function(res){ var $<?php echo $targetElement; ?> = <?php if ($target_class) { ?> jQuery('.<?php echo $target_class; ?> ');<?php } else { ?> jQuery('#<?php echo $target_id; ?> ');<?php } ?> if(res.response != '') { var $widget = jQuery('<div id="<?php echo $targetElement; ?> Widget<?php echo $key; ?> "></div>').addClass('jrWidget') <?php if ($title != '') { ?> .append('<h4><?php echo $title; ?> </h4>')<?php } ?> .append(res.response); $<?php echo $targetElement; ?> .append($widget); var array = [0,1,2,3,4]; for(var i=0; i < array.length; i++) { array[i] = jQuery('#<?php echo $targetElement; ?> Widget'+ array[i]); } $<?php echo $targetElement; ?> .html(); for(var i=0; i < array.length; i++) { $<?php echo $targetElement; ?> .append(array[i]); } if(jrTabArray['#<?php echo $targetElement; ?> '] != undefined && $<?php echo $targetElement; ?> .html() != '') { jrTabArray['#<?php echo $targetElement; ?> '].show(); } } else { if(jrTabArray['#<?php echo $targetElement; ?> '] != undefined && $<?php echo $targetElement; ?> .html() == '') { jrTabArray['#<?php echo $targetElement; ?> '].hide(); } } jreviews.module.pageNavInit(<?php echo json_encode(compact('module_id', 'columns', 'orientation', 'slideshow', 'slideshow_interval', 'nav_position')); ?> ); } }); }); /* ]]> */ </script> <?php } // Process favorite users $key++; $module_id = 11000 + $listing_id; $userfavorites = Sanitize::getVar($listing['ListingType']['config'], 'userfavorites', array()); if (Sanitize::getBool($userfavorites, 'enable')) { $target_id = Sanitize::getString($userfavorites, 'target_id', 'jrRelatedListings'); $target_class = Sanitize::getString($userfavorites, 'target_class'); $id = $listing_id; $moduleParams = compact('module_id', 'listingtype', 'ajax_init', 'id'); extract($userfavorites); $title = str_ireplace('{title}', $listing_title, __t(Sanitize::getString($userfavorites, 'title'), true, true)); $title = htmlspecialchars($title, ENT_QUOTES, 'utf-8'); $targetElement = $target_class ? $target_class : $target_id; ?> <script type="text/javascript"> /* <![CDATA[ */ jQuery(document).ready(function() { jreviews.dispatch({'controller':'module_favorite_users','action':'index', 'type':'json', 'data':<?php echo json_encode($moduleParams); ?> , 'onComplete':function(res){ var $<?php echo $targetElement; ?> = <?php if ($target_class) { ?> jQuery('.<?php echo $target_class; ?> ');<?php } else { ?> jQuery('#<?php echo $target_id; ?> ');<?php } ?> if(res.response != '') { var $widget = jQuery('<div id="<?php echo $targetElement; ?> Widget<?php echo $key; ?> "></div>').addClass('jrWidget') <?php if ($title != '') { ?> .append('<h4><?php echo $title; ?> </h4>')<?php } ?> .append(res.response); $<?php echo $targetElement; ?> .append($widget); var array = [0,1,2,3,4]; for(var i=0; i < array.length; i++) { array[i] = jQuery('#<?php echo $targetElement; ?> Widget'+ array[i]); } $<?php echo $targetElement; ?> .html(); for(var i=0; i < array.length; i++) { $<?php echo $targetElement; ?> .append(array[i]); } if(jrTabArray['#<?php echo $targetElement; ?> '] != undefined && $<?php echo $targetElement; ?> .html() != '') { jrTabArray['#<?php echo $targetElement; ?> '].show(); } } else { if(jrTabArray['#<?php echo $targetElement; ?> '] != undefined && $<?php echo $targetElement; ?> .html() == '') { jrTabArray['#<?php echo $targetElement; ?> '].hide(); } } jreviews.module.pageNavInit(<?php echo json_encode(compact('module_id', 'columns', 'orientation', 'slideshow', 'slideshow_interval', 'nav_position')); ?> ); } }); }); /* ]]> */ </script> <?php } }
/** * Sets the correct view layout * * @param mixed $categories */ public function setLayout($options = array()) { if (Sanitize::getVar($options, 'categories')) { # Iterate from parent to child and overwrite the suffix if not null foreach ($options['categories'] as $category) { $category['Category']['tmpl'] != '' and $this->c->tmpl_list = $category['Category']['tmpl']; } } if ($this->c->action == 'search') { $this->c->tmpl_list = $this->listTypeConversion($this->c->Config->search_display_type); return; } # Add overrides for menus, url params if (null != Sanitize::getString($this->c->data, 'tmpl_list')) { $this->c->data['tmpl_list'] = Sanitize::getString($this->c->data, 'tmpl_list'); } elseif (null != Sanitize::getString($this->c->data, 'listview')) { $this->c->data['tmpl_list'] = Sanitize::getString($this->c->data, 'listview'); } elseif (null != Sanitize::getString($this->c->params, 'tmpl_list')) { $this->c->data['tmpl_list'] = Sanitize::getString($this->c->params, 'tmpl_list'); } else { $this->c->data['tmpl_list'] = null; } if (null != $this->c->data['tmpl_list']) { $this->c->tmpl_list = $tmpl_list = $this->listTypeConversion($this->c->data['tmpl_list']); } # Global layout empty($this->c->tmpl_list) and $this->c->tmpl_list = $this->listTypeConversion($this->c->Config->list_display_type); # Layout can be overriden for certain controller::actions if (method_exists($this, $this->c->action)) { $this->{$this->c->action}(); } }
function plgAfterSave(&$model) { $data = array(); App::import('Model', 'activity', 'jreviews'); App::import('Helper', 'routes', 'jreviews'); $Activity = new ActivityModel(); $Routes = RegisterClass::getInstance('RoutesHelper'); $data['Activity']['user_id'] = $this->c->_user->id; $data['Activity']['email'] = $this->c->_user->email; $data['Activity']['created'] = gmdate('Y-m-d H:i:s'); $data['Activity']['ipaddress'] = $this->c->ipaddress; $data['Activity']['activity_new'] = isset($model->data['insertid']) ? 1 : 0; switch ($this->activityModel->name) { case 'Claim': //Get the full listing info to create proper permalinks $listing = $this->c->Listing->findRow(array('conditions' => array('Listing.id = ' . (int) $model->data['Claim']['listing_id'])), array()); $permalink = $Routes->content('', $listing, array('return_url' => true)); $permalink = cmsFramework::makeAbsUrl($permalink); $data['Activity']['activity_type'] = 'claim'; $data['Activity']['listing_id'] = $model->data['Claim']['listing_id']; $data['Activity']['extension'] = 'com_content'; $data['Activity']['activity_new'] = 1; $data['Activity']['permalink'] = $permalink; $Activity->store($data); break; case 'Listing': // Skip logging of admin actions on user listings // if($this->c->_user->id != $model->data['Listing']['created_by']) break; //Get the full listing info to create proper permalinks $listing = $this->c->Listing->findRow(array('conditions' => array('Listing.id = ' . (int) $model->data['Listing']['id']))); $permalink = $Routes->content('', $listing, array('return_url' => true)); $permalink = cmsFramework::makeAbsUrl($permalink); $data['Activity']['activity_type'] = 'listing'; $data['Activity']['email'] = Sanitize::getString($model->data, 'email'); $data['Activity']['listing_id'] = $model->data['Listing']['id']; $data['Activity']['extension'] = 'com_content'; $data['Activity']['permalink'] = $permalink; $Activity->store($data); break; case 'Review': // Skip logging of admin actions on user listings // if($this->c->_user->id != $model->data['Review']['userid']) break; $data['Activity']['activity_type'] = 'review'; $data['Activity']['listing_id'] = $model->data['Review']['pid']; $data['Activity']['review_id'] = $model->data['Review']['id']; $data['Activity']['extension'] = $model->data['Review']['mode']; $data['Activity']['value'] = round(Sanitize::getVar($model->data, 'average_rating'), 0); $data['Activity']['permalink'] = $Routes->reviewDiscuss('', array('review_id' => $data['Activity']['review_id']), array('return_url' => true)); $Activity->store($data); break; case 'OwnerReply': // Skip logging of admin actions on user listings // if($this->c->_user->id != $model->data['Listing']['created_by']) break; $data['Activity']['activity_type'] = 'owner_reply'; $data['Activity']['listing_id'] = $model->data['Listing']['listing_id']; $data['Activity']['review_id'] = $model->data['OwnerReply']['id']; $data['Activity']['extension'] = $model->data['Listing']['extension']; // Editing not yet implemented so all replies are new $data['Activity']['activity_new'] = 1; $data['Activity']['permalink'] = $Routes->reviewDiscuss('', array('review_id' => $data['Activity']['review_id']), array('return_url' => true)); $Activity->store($data); break; case 'Discussion': // Skip logging of admin actions on user listings // if($this->c->_user->id != $model->data['Discussion']['user_id']) break; // Get listing id and extension $this->c->_db->setQuery("\n SELECT \n Review.pid AS listing_id, Review.`mode` AS extension\n FROM \n #__jreviews_comments AS Review\n WHERE \n Review.id = " . $model->data['Discussion']['review_id']); // Get listing owner id and check if it matches the current user if ($listing = current($this->c->_db->loadAssocList())) { $data['Activity']['activity_type'] = 'review_discussion'; $data['Activity']['listing_id'] = $listing['listing_id']; $data['Activity']['review_id'] = $model->data['Discussion']['review_id']; $data['Activity']['post_id'] = $model->data['Discussion']['discussion_id']; $data['Activity']['extension'] = $listing['extension']; $data['Activity']['permalink'] = $Routes->reviewDiscuss('', array('review_id' => $data['Activity']['review_id']), array('return_url' => true)); $Activity->store($data); } break; case 'Report': $data['Activity']['activity_type'] = $model->data['Report']['post_id'] ? 'discussion_report' : 'review_report'; $data['Activity']['listing_id'] = $model->data['Report']['listing_id']; $data['Activity']['review_id'] = $model->data['Report']['review_id']; $data['Activity']['extension'] = $model->data['Report']['extension']; // Editing not yet implemented so all replies are new $data['Activity']['activity_new'] = 1; $data['Activity']['permalink'] = $Routes->reviewDiscuss('', array('review_id' => $data['Activity']['review_id']), array('return_url' => true)); $Activity->store($data); break; case 'Vote': // Get listing id and extension $this->c->_db->setQuery("\n SELECT \n Review.pid AS listing_id, Review.`mode` AS extension\n FROM \n #__jreviews_comments AS Review\n WHERE \n Review.id = " . $model->data['Vote']['review_id']); // Get listing owner id and check if it matches the current user if ($listing = current($this->c->_db->loadAssocList())) { $data['Activity']['activity_type'] = 'helpful_vote'; $data['Activity']['listing_id'] = $listing['listing_id']; $data['Activity']['review_id'] = $model->data['Vote']['review_id']; $data['Activity']['helpful_vote_id'] = $model->data['Vote']['vote_id']; $data['Activity']['extension'] = $listing['extension']; $data['Activity']['value'] = $model->data['Vote']['vote_yes']; $data['Activity']['permalink'] = $Routes->reviewDiscuss('', array('review_id' => $data['Activity']['review_id']), array('return_url' => true)); $Activity->store($data); } break; } $this->published = false; // Run once. With paid listings it is possible for a plugin to run a 2nd time when the order is processed together with the listing (free) }
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'); }