function index($params)
 {
     /*        if($this->_user->id === 0) 
             {
                 $this->cacheAction = Configure::read('Cache.expires');        
             }*/
     $this->action = 'directory';
     // Set view file
     # Read module params
     $dir_id = isset($this->params['module']) ? cleanIntegerCommaList(Sanitize::getString($this->params['module'], 'dir_ids')) : '';
     $conditions = array();
     $order = array();
     $cat_id = '';
     $section_id = '';
     if ($this->cmsVersion == CMS_JOOMLA15) {
         $directories = $this->Directory->getTree($dir_id, true);
     } else {
         $directories = $this->Category->findTree(array('level' => $this->Config->dir_category_levels, 'menu_id' => true, 'dir_id' => $dir_id, 'pad_char' => ''));
     }
     if ($menu_id = Sanitize::getInt($this->params, 'Itemid')) {
         $menuParams = $this->Menu->getMenuParams($menu_id);
     }
     # Category auto detect
     $ids = CommonController::_discoverIDs($this);
     extract($ids);
     if ($this->cmsVersion == CMS_JOOMLA15 && ($cat_id != '' && $section_id == '')) {
         $cat_id = cleanIntegerCommaList($cat_id);
         $sql = "SELECT section FROM #__categories WHERE id IN (" . $cat_id . ")";
         $this->_db->setQuery($sql);
         $section_id = $this->_db->loadResult();
     }
     $this->set(array('directories' => $directories, 'dir_id' => $dir_id, 'cat_id' => is_numeric($cat_id) && $cat_id > 0 ? $cat_id : false, 'section_id' => $section_id));
     return $this->render('modules', 'directories');
 }
 function index($params)
 {
     $this->action = 'directory';
     // Set view file
     # Read module params
     $dir_id = cleanIntegerCommaList(Sanitize::getString($this->params['module'], 'dir_ids'));
     $conditions = array();
     $order = array();
     $cat_id = '';
     $section_id = '';
     $directories = $this->Directory->getTree($dir_id, true);
     if ($menu_id = Sanitize::getInt($this->params, 'Itemid')) {
         $menuParams = $this->Menu->getMenuParams($menu_id);
     }
     # Category auto detect
     $ids = CommonController::_discoverIDs($this);
     extract($ids);
     if ($cat_id != '' && $section_id == '') {
         $cat_id = cleanIntegerCommaList($cat_id);
         $sql = "SELECT section FROM #__categories WHERE id IN (" . $cat_id . ")";
         $this->_db->setQuery($sql);
         $section_id = $this->_db->loadResult();
     }
     $this->set(array('directories' => $directories, 'cat_id' => is_numeric($cat_id) && $cat_id > 0 ? $cat_id : false, 'section_id' => $section_id));
     return $this->render('modules', 'directories');
 }
 function index()
 {
     global $Itemid;
     $cat_id = null;
     $conditions = array();
     $joins = array();
     $order = array();
     $menu_id = '';
     // Read module params
     $dir_id = Sanitize::getString($this->params['module'], 'dir');
     $section_id = Sanitize::getString($this->params, 'section');
     $cat_id = Sanitize::getString($this->params['module'], 'cat');
     $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     $itemid_options = Sanitize::getString($this->params['module'], 'itemid_options');
     $itemid_hc = Sanitize::getInt($this->params['module'], 'hc_itemid');
     $field = Sanitize::getString($this->params['module'], 'field');
     $option_length = Sanitize::getInt($this->params['module'], 'fieldoption_length');
     $custom_params = Sanitize::getString($this->params['module'], 'custom_params');
     $sort = Sanitize::getString($this->params['module'], 'fieldoption_order');
     # Set menu id
     switch ($itemid_options) {
         case 'none':
             $menu_id = '';
             break;
         case 'current':
             break;
         case 'hardcode':
             $menu_id = $itemid_hc;
             break;
     }
     # Category auto detect
     if (Sanitize::getInt($this->params['module'], 'catauto')) {
         $ids = CommonController::_discoverIDs($this);
         extract($ids);
     }
     $this->FieldOption->modelUnbind(array('FieldOption.value AS `FieldOption.value`', 'FieldOption.fieldid AS `FieldOption.fieldid`', 'FieldOption.image AS `FieldOption.image`', 'FieldOption.ordering AS `FieldOption.ordering`', 'FieldOption.optionid AS `FieldOption.optionid`', 'FieldOption.text AS `FieldOption.text`'));
     $fields[] = 'FieldOption.optionid AS `FieldOption.optionid`';
     $fields[] = 'FieldOption.value AS `FieldOption.value`';
     if ($option_length) {
         $fields[] = 'IF(CHAR_LENGTH(FieldOption.text)>' . $option_length . ',CONCAT(SUBSTR(FieldOption.text,1,' . $option_length . '),"..."),FieldOption.text) AS `FieldOption.text`';
     } else {
         $fields[] = 'FieldOption.text AS `FieldOption.text`';
     }
     $joins[] = 'INNER JOIN #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid';
     $order[] = 'FieldOption.' . $sort;
     $field_options = $this->FieldOption->findAll(array('fields' => $fields, 'conditions' => 'Field.name = "' . $field . '"', 'joins' => $joins, 'order' => $order));
     # Send variables to view template
     $this->set(array('field' => $field, 'field_options' => $field_options, 'section_ids' => $section_id, 'category_ids' => $cat_id, 'criteria_id' => $criteria_id, 'menu_id' => $menu_id, 'custom_params' => $custom_params));
     return $this->render('modules', 'fields');
 }
Esempio n. 4
0
 function index()
 {
     global $Itemid;
     $cat_id = null;
     $conditions = array();
     $joins = array();
     $order = array();
     $menu_id = '';
     // Read module params
     $itemid_options = Sanitize::getString($this->params['module'], 'itemid_options');
     $itemid_hc = Sanitize::getInt($this->params['module'], 'hc_itemid');
     $field = Sanitize::getString($this->params['module'], 'field');
     $custom_params = Sanitize::getString($this->params['module'], 'custom_params');
     $dir_id = Sanitize::getString($this->params['module'], 'dir');
     $section_id = Sanitize::getString($this->params, 'section');
     $cat_id = Sanitize::getString($this->params['module'], 'cat');
     $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     # Set menu id
     switch ($itemid_options) {
         case 'none':
             $menu_id = '';
             break;
         case 'current':
             break;
         case 'hardcode':
             $menu_id = $itemid_hc;
             break;
     }
     # Category auto detect
     if (Sanitize::getInt($this->params['module'], 'catauto')) {
         $ids = CommonController::_discoverIDs($this);
         extract($ids);
     }
     # Send variables to view template
     $this->set(array('field' => $field, 'dir_id' => $dir_id, 'section_ids' => $section_id, 'category_ids' => $cat_id, 'criteria_id' => $criteria_id, 'menu_id' => $menu_id, 'custom_params' => $custom_params));
     return $this->render('modules', 'range');
 }
 function listings()
 {
     // Initialize variables
     $id = Sanitize::getInt($this->params, 'id');
     $option = Sanitize::getString($this->params, 'option');
     $view = Sanitize::getString($this->params, 'view');
     $menu_id = Sanitize::getString($this->params, 'Itemid');
     // Read params
     $cat_id = '';
     $criteria_ids = '';
     $in_detail_view = false;
     $detail_view = 1;
     $dir_id = Sanitize::getString($this->params, 'dir');
     $section_id = Sanitize::getString($this->params, 'section');
     $cat_id = Sanitize::getString($this->params, 'cat');
     $extension = 'com_content';
     $custom_where = null;
     $custom_fields = array();
     $click2search_auto = false;
     $cache = 0;
     $radius = 0;
     $mode = 0;
     if (isset($this->params['module'])) {
         // Read module parameters
         $click2search_auto = Sanitize::getBool($this->params['module'], 'click2search_auto', false);
         $custom_where = Sanitize::getString($this->params['module'], 'custom_where');
         $filter = Sanitize::getString($this->params['module'], 'filter');
         $detail_view = Sanitize::getString($this->params['module'], 'detail_view', 1);
         $dir_id = Sanitize::getString($this->params['module'], 'dir');
         $section_id = Sanitize::getString($this->params['module'], 'section');
         $cat_id = Sanitize::getString($this->params['module'], 'category');
         $listing_id = Sanitize::getString($this->params['module'], 'listing');
         $criteria_ids = Sanitize::getString($this->params['module'], 'criteria');
         $limit_results = Sanitize::getInt($this->params['module'], 'limit_results');
         $mode = Sanitize::getInt($this->params['module'], 'mode', 0);
         $custom_fields = str_replace(" ", "", Sanitize::getString($this->Config, 'geomaps.infowindow_fields'));
         $custom_fields = $custom_fields != '' ? explode(",", $custom_fields) : array();
         /**
          * 0 - Normal
          * 1 - GeoTargeting
          * 2 - Custom center and zoom
          */
         $radius = Sanitize::getInt($this->params['module'], 'radius');
         $cache = $mode == 1 ? 0 : Sanitize::getInt($this->params['module'], 'cache_map');
         $custom_lat = Sanitize::getFloat($this->params['module'], 'custom_lat');
         $custom_lon = Sanitize::getFloat($this->params['module'], 'custom_lon');
         if ($mode == 2 && ($custom_lat == 0 || $custom_lon == 0)) {
             echo __t("You selected the Custom Center mode, but did not specify the coordinates.");
             return;
         }
     }
     # Prevent sql injection
     $token = Sanitize::getString($this->params, 'token');
     $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false));
     $filters = $listing_id != '' || $dir_id != '' || $section_id != '' || $cat_id != '';
     if (!$filters && $id > 0 && 'article' == $view && 'com_content' == $option) {
         $sql = "SELECT catid FROM #__content WHERE id = " . $id;
         $this->_db->setQuery($sql);
         $cat_id_host_page = $this->_db->loadResult();
         if (!empty($cat_id_host_page) && $this->Category->isJreviewsCategory($cat_id_host_page)) {
             $in_detail_view = true;
             $cat_id = $cat_id_host_page;
         }
     }
     $detail_view = $this->params['module']['detail_view'] = (int) ($detail_view && $in_detail_view);
     # Custom WHERE
     $tokenMatch and $custom_where and $conditions[] = $custom_where;
     if ($click2search_auto && isset($this->params['tag'])) {
         $field = 'jr_' . Sanitize::getString($this->params['tag'], 'field');
         $value = Sanitize::getString($this->params['tag'], 'value');
         $query = "SELECT Field.type FROM #__jreviews_fields AS Field WHERE Field.name = " . $this->quote($field);
         $this->_db->setQuery($query);
         $type = $this->_db->loadResult();
         if (in_array($type, array('select', 'selectmultiple', 'checkboxes', 'radiobuttons'))) {
             $conditions[] = "Field.{$field} LIKE " . $this->quoteLike('*' . $value . '*');
         } else {
             $conditions[] = "Field.{$field} = " . $this->quote($value);
         }
     }
     # Category auto detect
     if (isset($this->params['module']) && Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') {
         $ids = CommonController::_discoverIDs($this);
         extract($ids);
     }
     $autodetect = compact('dir_id', 'section_id', 'cat_id');
     // Check for cached version if cache enabled
     if ($cache) {
         $params = array();
         foreach ($this->params as $key => $value) {
             if ((!is_array($value) || $key == 'module') && !in_array($key, array('page', 'limit', 'order', 'Itemid'))) {
                 $params[$key] = $value;
             }
         }
         $cache_key = array_merge($params, $autodetect, Sanitize::getVar($this->params, 'tag', array()));
         $json_filename = 'geomaps_' . md5(serialize($cache_key)) . '.json';
         $json_data = S2Cache::read($json_filename);
         if ($json_data && $json_data != '') {
             $this->set('json_data', $json_data);
             S2Cache::write($json_filename, $json_data);
             return $this->render('modules', 'geomaps');
         }
     }
     $this->Listing->fields = array('Listing.id AS `Listing.listing_id`', 'Listing.title AS `Listing.title`', 'Listing.images AS `Listing.images`', 'CASE WHEN CHAR_LENGTH(Listing.alias) THEN Listing.alias ELSE "" END AS `Listing.slug`', 'Category.id AS `Listing.cat_id`', 'CASE WHEN CHAR_LENGTH(Category.alias) THEN Category.alias ELSE Category.title END AS `Category.slug`', 'Listing.sectionid AS `Listing.section_id`', 'JreviewsCategory.criteriaid AS `Criteria.criteria_id`', 'JreviewsCategory.dirid AS `Directory.dir_id`', 'JreviewsCategory.marker_icon AS `Geomaps.icon`', 'Field.featured AS `Listing.featured`', 'Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', "Field.{$this->jr_lat} `Geomaps.lat`", "Field.{$this->jr_lon} `Geomaps.lon`", 'ListingType.state AS `Criteria.state`', 'ListingType.config AS `ListingType.config`');
     if ($custom_lon != '' and $custom_lat != '') {
         $this->set('CustomCenter', array('lon' => $custom_lon, 'lat' => $custom_lat));
     }
     // Geo Targeting OR Custom Center modes
     if ($mode == 1 || $mode == 2) {
         if ($mode == 1) {
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, 'http://www.geoplugin.net/php.gp?ip=' . s2GetIpAddress());
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
             $geoData = unserialize(curl_exec($ch));
             curl_close($ch);
             if (!empty($geoData) && isset($geoData['geoplugin_latitude']) && $geoData['geoplugin_latitude'] != '' && $geoData['geoplugin_longitude'] != '') {
                 $center = array('lon' => $geoData['geoplugin_longitude'], 'lat' => $geoData['geoplugin_latitude']);
             }
             $this->set('geoLocation', $geoData);
         }
         if ($mode == 2) {
             $center = array('lon' => $custom_lon, 'lat' => $custom_lat);
         }
         if (!empty($center) && $radius > 0) {
             $distanceIn = Sanitize::getString($this->Config, 'geomaps.radius_metric', 'mi');
             $degreeDistance = $distanceIn == 'mi' ? 69.172 : 40076 / 360;
             // Send center coordinates to theme
             $this->set('GeomapsCenter', $center);
             $lat_range = $radius / $degreeDistance;
             $lon_range = $radius / abs(cos($center['lat'] * pi() / 180) * $degreeDistance);
             $min_lat = $center['lat'] - $lat_range;
             $max_lat = $center['lat'] + $lat_range;
             $min_lon = $center['lon'] - $lon_range;
             $max_lon = $center['lon'] + $lon_range;
             $squareArea = "`Field`.{$this->jr_lat} BETWEEN {$min_lat} AND {$max_lat} AND `Field`.{$this->jr_lon} BETWEEN {$min_lon} AND {$max_lon}";
             $conditions[] = $squareArea;
         }
     }
     // Create marker_icons array
     $marker_icons = array();
     $icon_fields = array();
     $field_images = array();
     $query = "SELECT DISTINCT marker_icon FROM #__jreviews_categories WHERE marker_icon != ''";
     $this->_db->setQuery($query);
     $icon_rows = $this->_db->loadAssocList();
     foreach ($icon_rows as $icons) {
         $icon = (array) json_decode($icons['marker_icon']);
         if ($icon['field'] != '') {
             $icon_fields[$icon['field']] = "'" . $icon['field'] . "'";
         }
     }
     if (!empty($icon_fields)) {
         foreach ($icon_fields as $field_key => $field) {
             if (substr($field_key, 0, 3) == 'jr_') {
                 $this->Listing->fields[] = "Field.{$field_key} AS `Field.{$field_key}`";
             }
         }
     }
     if (!empty($custom_fields)) {
         foreach ($custom_fields as $field) {
             $this->Listing->fields[] = "Field.{$field} AS `Field.{$field}`";
         }
     }
     $this->Listing->joins = array("LEFT JOIN #__categories AS Category ON Listing.catid = Category.id", 'ParentCategory' => "LEFT JOIN #__categories AS ParentCategory ON Category.lft BETWEEN ParentCategory.lft AND ParentCategory.rgt", "LEFT JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.id AND Totals.extension = 'com_content'", "LEFT JOIN #__jreviews_content AS `Field` ON Field.contentid = Listing.id", "INNER JOIN #__jreviews_categories AS JreviewsCategory ON Listing.catid = JreviewsCategory.id AND JreviewsCategory.`option` = 'com_content'", "LEFT JOIN #__jreviews_criteria AS ListingType ON JreviewsCategory.criteriaid = ListingType.id", "LEFT JOIN #__jreviews_directories AS Directory ON JreviewsCategory.dirid = Directory.id");
     // Don't regroup the results by model name keys to save time
     $this->Listing->primaryKey = false;
     # Set conditionals based on configuration parameters
     if ($detail_view) {
         $conditions[] = 'Listing.id = ' . $id;
     }
     if (!empty($cat_id)) {
         $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')' : 'ParentCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
     }
     if ($this->cmsVersion == CMS_JOOMLA15) {
         unset($this->Listing->joins['ParentCategory']);
     }
     empty($cat_id) and !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')';
     empty($cat_id) and !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')';
     empty($cat_id) and !empty($criteria_id) and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')';
     if ($listing_id) {
         $conditions[] = 'Listing.id IN (' . $listing_id . ')';
     }
     if ($filter == 'featured' && !$detail_view) {
         $conditions[] = 'Field.featured = 1';
     }
     $conditions[] = "Field.{$this->jr_lat} <> ''";
     $conditions[] = "Field.{$this->jr_lon} <> ''";
     $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )'));
     if ($this->cmsVersion == CMS_JOOMLA15) {
         //                    $conditions[] = 'Section.access <= ' . $this->Access->getAccessId();
         $conditions[] = 'Category.access <= ' . $this->Access->getAccessId();
         $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId();
     } else {
         $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')';
         $conditions[] = 'Listing.access IN (' . $this->Access->getAccessLevels() . ')';
     }
     // Paid Listings - add plan cat id
     isset($this->PaidListings) and $this->PaidListings->applyBeforeFindListingChanges($this->Listing);
     $listings = $this->Listing->findAll(array('conditions' => $conditions, 'limit' => $limit_results), array());
     $custom_fields = array_filter(array_merge($custom_fields, array_keys($icon_fields)));
     $fieldOptionValues = array();
     // Extract custom field values to avoid loading all options for each fields
     // It's a trade-off between that and doing a foreach on all listings
     foreach ($listings as $key => $row) {
         $listings[$key]['Criteria']['state'] = $row['Criteria.state'];
         $listings[$key]['ListingType']['config'] = json_decode($row['ListingType.config'], true);
         unset($listings[$key]['Criteria.state'], $listings[$key]['ListingType.config']);
         foreach ($custom_fields as $field) {
             $optionValue = Sanitize::getVar($row, 'Field.' . $field);
             if ($optionValue != '' && $optionValue != '**') {
                 $fieldOptionValues = array_merge($fieldOptionValues, array_filter(explode('*', $optionValue)));
             }
         }
     }
     $fields = $this->Field->getFields($custom_fields, 'listing', $fieldOptionValues);
     $json_data = $this->Geomaps->makeJsonObject($listings, $fields, $this->params['module']);
     $this->set('json_data', $json_data);
     if ($cache) {
         S2Cache::write($json_filename, $json_data);
     }
     return $this->render('modules', 'geomaps');
 }
 function index()
 {
     /*        if($this->_user->id === 0) 
             {
                 $this->cacheAction = Configure::read('Cache.expires');        
             }*/
     // Required for ajax pagination to remember module settings
     $ids = $conditions = $joins = $order = $having = array();
     $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id'));
     if (!isset($this->params['module'])) {
         $this->params['module'] = array();
     }
     // For direct calls to the controller
     # Find the correct set of params to use
     if ($this->ajaxRequest && Sanitize::getInt($this->params, 'listing_id')) {
         $this->params['module'] = array_merge($this->params['module'], $this->__processListingTypeWidgets($conditions));
     } elseif ($this->ajaxRequest && empty($this->params['module']) && $module_id) {
         $query = "SELECT params FROM #__modules WHERE id = " . $module_id;
         $this->_db->setQuery($query);
         $this->params['module'] = stringToArray($this->_db->loadResult());
     }
     if ($this->abort) {
         return $this->ajaxResponse('', false);
     }
     # Read module parameters
     $dir_id = Sanitize::getString($this->params['module'], 'dir');
     $section_id = Sanitize::getString($this->params['module'], 'section');
     $cat_id = Sanitize::getString($this->params['module'], 'category');
     $listing_id = Sanitize::getString($this->params['module'], 'listing');
     $created_by = Sanitize::getString($this->params['module'], 'owner');
     $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5);
     $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10));
     $extension = Sanitize::getString($this->params['module'], 'extension');
     $extension = $extension != '' ? $extension : 'com_content';
     $sort = Sanitize::getString($this->params['module'], 'listing_order');
     if (in_array($sort, array('random', 'featuredrandom'))) {
         srand((double) microtime() * 1000000);
         $this->params['rand'] = rand();
     }
     # Prevent sql injection
     $token = Sanitize::getString($this->params, 'token');
     $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false));
     isset($this->params['module']) and $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix');
     if (isset($this->Listing)) {
         $this->Listing->_user = $this->_user;
         // This parameter determines the module mode
         $custom_order = Sanitize::getString($this->params['module'], 'custom_order');
         $custom_where = Sanitize::getString($this->params['module'], 'custom_where');
         if ($extension != 'com_content' && in_array($sort, array('topratededitor', 'featuredrandom', 'rhits'))) {
             echo "You have selected the {$sort} mode which is not supported for components other than com_content. Please read the tooltips in the module parameters for more info on allowed settings.";
             return;
         }
         # Category auto detect
         if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') {
             $ids = CommonController::_discoverIDs($this);
             extract($ids);
         }
         # Set conditionals based on configuration parameters
         if ($extension == 'com_content') {
             // Perform tag replacement for listing_id to allow for related listing queries
             if (Sanitize::getString($this->params, 'view') == 'article' && $custom_where != '') {
                 $curr_listing_id = Sanitize::getInt($this->params, 'id');
                 $custom_where = str_replace('{listing_id}', $curr_listing_id, $custom_where);
             }
             // Only works for core articles
             $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )'));
             if ($this->cmsVersion == CMS_JOOMLA15) {
                 //                    $conditions[] = 'Section.access <= ' . $this->Access->getAccessId();
                 $conditions[] = 'Category.access <= ' . $this->Access->getAccessId();
                 $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId();
             } else {
                 $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')';
                 $conditions[] = 'Listing.access IN (' . $this->Access->getAccessLevels() . ')';
             }
             // Remove unnecessary fields from model query
             $this->Listing->modelUnbind(array('Listing.fulltext AS `Listing.description`', 'Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`', 'User.email AS `User.email`'));
             if (!empty($cat_id)) {
                 $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')' : 'ParentCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
             } else {
                 unset($this->Listing->joins['ParentCategory']);
             }
             empty($cat_id) and !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')';
             empty($cat_id) and !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')';
             empty($cat_id) and !empty($criteria_id) and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')';
         } else {
             if (Sanitize::getInt($this->params['module'], 'cat_auto') && method_exists($this->Listing, 'catUrlParam')) {
                 if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) {
                     $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
                 }
             } elseif ($cat_id) {
                 $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
             }
         }
         $listing_id and $conditions[] = "Listing.{$this->Listing->realKey} IN (" . cleanIntegerCommaList($listing_id) . ")";
         switch ($sort) {
             case 'random':
                 $order[] = 'RAND(' . $this->params['rand'] . ')';
                 break;
             case 'featured':
                 $conditions[] = 'Field.featured = 1';
                 break;
             case 'featuredrandom':
                 $conditions[] = 'Field.featured = 1';
                 $order[] = 'RAND(' . $this->params['rand'] . ')';
                 break;
             case 'topratededitor':
                 //                    $conditions[] = 'Totals.editor_rating > 0';
                 $sort = 'editor_rating';
                 break;
                 // Editor rating sorting options dealt with in the Listing->processSorting method
         }
         # Custom WHERE
         $tokenMatch and $custom_where and $conditions[] = $custom_where;
         # Filtering options
         $having = array();
         // Listings submitted in the past x days
         $entry_period = Sanitize::getInt($this->params['module'], 'filter_listing_period');
         if ($entry_period > 0 && $this->Listing->dateKey) {
             $conditions[] = "Listing.{$this->Listing->dateKey} >= DATE_SUB('" . _CURRENT_SERVER_TIME . "', INTERVAL {$entry_period} DAY)";
         }
         // Listings with reviews submitted in past x days
         $review_period = Sanitize::getInt($this->params['module'], 'filter_review_period');
         if ($review_period > 0) {
             $conditions[] = "Review.created >= DATE_SUB(CURDATE(), INTERVAL {$review_period} DAY)";
             $joins[] = 'LEFT JOIN #__jreviews_comments AS Review ON Listing.' . $this->Listing->realKey . ' = Review.pid';
         }
         // Listings with review count higher than
         $filter_review_count = Sanitize::getInt($this->params['module'], 'filter_review_count');
         $filter_review_count > 0 and $conditions[] = "Totals.user_rating_count >= " . $filter_review_count;
         // Listings with avg rating higher than
         $filter_avg_rating = Sanitize::getFloat($this->params['module'], 'filter_avg_rating');
         $filter_avg_rating > 0 and $conditions[] = 'Totals.user_rating  >= ' . $filter_avg_rating;
         $this->Listing->group = array();
         // Exlude listings without ratings from the results
         $join_direction = in_array($sort, array('rating', 'rrating', 'topratededitor', 'reviews')) ? 'INNER' : 'LEFT';
         $this->Listing->joins['Total'] = "{$join_direction} JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.{$this->Listing->realKey} AND Totals.extension = " . $this->quote($extension);
         # Modify query for correct ordering. Change FIELDS, ORDER BY and HAVING BY directly in Listing Model variables
         if ($tokenMatch and $custom_order) {
             $this->Listing->order[] = $custom_order;
         } elseif (empty($order) && $extension == 'com_content') {
             $this->Listing->processSorting('module', $sort);
             // Modifies Listing model order var directly
         } elseif (empty($order) && ($order = $this->__processSorting($sort))) {
             $order = array($order);
         }
         $fields = array('Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.user_comment_count AS `Review.review_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', 'Totals.editor_comment_count AS `Review.editor_review_count`');
         $queryData = array('fields' => !isset($this->Listing->fields['editor_rating']) ? $fields : array(), 'joins' => $joins, 'conditions' => $conditions, 'limit' => $total, 'having' => $having);
         isset($order) and !empty($order) and $queryData['order'] = $order;
         // Trigger addFields for $listing results. Checked in Everywhere model
         $this->Listing->addFields = true;
         $listings = $this->Listing->findAll($queryData);
         $count = count($listings);
     } else {
         $listings = array();
         $count = 0;
     }
     unset($this->Listing);
     # Send variables to view template
     $this->set(array('autodetect_ids' => $ids, 'subclass' => 'listing', 'listings' => $listings, 'total' => $count, 'limit' => $limit));
     $this->_completeModuleParamsArray();
     $page = $this->ajaxRequest && empty($listings) ? '' : $this->render('modules', 'listings');
     /*        if($this->_user->id === 0 && $this->ajaxRequest) 
             {
                 $path = $this->here;
     
                 $this->here == '/' and $path = 'home';
                 
                 $cache_fname = Inflector::slug($path) . '.php';
              
                 $now = time();
     
                 $cacheTime = is_numeric($this->cacheAction) ? $now + $this->cacheAction : strtotime($this->cacheAction, $now);
              
                 $fileHeader = '<!--cachetime:' . $cacheTime . '-->'; 
                 
                 cache('views' . DS . $cache_fname, $fileHeader . $this->ajaxResponse($page,false), $this->cacheAction);
             }*/
     return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page;
 }
 function index()
 {
     /*        if($this->_user->id === 0) 
             {
                 $this->cacheAction = Configure::read('Cache.expires');        
             }   */
     $this->EverywhereAfterFind = true;
     // Triggers the afterFind in the Observer Model
     if (!isset($this->params['module'])) {
         $this->params['module'] = array();
     }
     // For direct calls to the controller
     $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id'));
     if (empty($this->params)) {
         $query = "SELECT params FROM #__modules WHERE id = " . $module_id;
         $this->_db->setQuery($query);
         $this->params['module'] = stringToArray($this->_db->loadResult());
     }
     $ids = $conditions = $joins = $order = array();
     # Read module parameters
     $extension = Sanitize::getString($this->params['module'], 'extension');
     $reviews_type = Sanitize::getString($this->params['module'], 'reviews_type');
     $custom_where = Sanitize::getString($this->params['module'], 'custom_where');
     $cat_id = Sanitize::getString($this->params['module'], 'category');
     $listing_id = Sanitize::getString($this->params['module'], 'listing');
     $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5);
     $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10));
     if ($extension == 'com_content') {
         $dir_id = Sanitize::getString($this->params['module'], 'dir');
         $section_id = Sanitize::getString($this->params['module'], 'section');
         $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     } else {
         $dir_id = null;
         $section_id = null;
         $criteria_id = null;
     }
     # Prevent sql injection
     $token = Sanitize::getString($this->params, 'token');
     $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false));
     isset($this->params['module']) and $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix');
     // This parameter determines the module mode
     $sort = Sanitize::getString($this->params['module'], 'reviews_order');
     if (in_array($sort, array('random'))) {
         srand((double) microtime() * 1000000);
         $this->params['rand'] = rand();
     }
     # Category auto detect
     if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') {
         $ids = CommonController::_discoverIDs($this);
         extract($ids);
     }
     $extension != '' and $conditions[] = "Review.mode = " . $this->quote($extension);
     # Set conditionals based on configuration parameters
     if ($extension == 'com_content') {
         $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() . ')';
         }
         if (!empty($cat_id)) {
             if ($this->cmsVersion == CMS_JOOMLA15) {
                 $conditions[] = 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')';
             } else {
                 $this->Review->joins['ParentCategory'] = "LEFT JOIN #__categories AS ParentCategory ON Category.lft BETWEEN ParentCategory.lft AND ParentCategory.rgt";
                 $conditions[] = 'ParentCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
             }
         }
         empty($cat_id) and !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')';
         empty($cat_id) and !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')';
         empty($cat_id) and !empty($criteria_id) and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')';
     } else {
         if (Sanitize::getInt($this->params['module'], 'cat_auto') && isset($this->Listing) && 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 (' . cleanIntegerCommaList($cat_id) . ')';
         }
     }
     $listing_id and $conditions[] = "Review.pid IN ( " . cleanIntegerCommaList($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':
             $order[] = 'RAND(' . $this->params['rand'] . ')';
             break;
         default:
             $order[] = $this->Review->processSorting('rdate');
             break;
     }
     switch ($reviews_type) {
         case 'all':
             break;
         case 'user':
             $conditions[] = 'Review.author = 0';
             break;
         case 'editor':
             $conditions[] = 'Review.author = 1';
             break;
     }
     # Custom WHERE
     $tokenMatch and $custom_where and $conditions[] = $custom_where;
     $queryData = 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('autodetect_ids' => $ids, 'reviews' => $reviews, 'total' => $count, 'limit' => $limit));
     $this->_completeModuleParamsArray();
     $page = $this->ajaxRequest && empty($reviews) ? '' : $this->render('modules', 'reviews');
     /*        if($this->_user->id === 0 && $this->ajaxRequest) 
             {
                 $path = $this->here;
     
                 $this->here == '/' and $path = 'home';
                 
                 $cache_fname = Inflector::slug($path) . '.php';
              
                 $now = time();
     
                 $cacheTime = is_numeric($this->cacheAction) ? $now + $this->cacheAction : strtotime($this->cacheAction, $now);
              
                 $fileHeader = '<!--cachetime:' . $cacheTime . '-->'; 
                 
                 cache('views' . DS . $cache_fname, $fileHeader . $this->ajaxResponse($page,false), $this->cacheAction);
             }*/
     return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page;
 }
 /**
  * Dynamically replace the field tags with their labels/form field equivalents
  */
 function afterFilter()
 {
     $output =& $this->output;
     $names = array();
     $labels = array();
     $select = array();
     $cat_tag = false;
     $date_field = false;
     $cat_auto = Sanitize::getInt($this->params['module'], 'cat_auto');
     $dir_id = $section_id = $cat_id = $criteria_id = '';
     # Initialize FormHelper
     $Form = new FormHelper();
     $CustomFields = new CustomFieldsHelper();
     $CustomFields->Config =& $this->Config;
     # Process custom field tag attributes
     foreach ($this->fieldTags as $key => $value) {
         $var = explode('|', $value);
         if (!strstr($value, '_label')) {
             $names[$var[0]] = $value;
         } elseif (strstr($value, '_label')) {
             $labels[] = substr($value, 0, -6);
         }
         if ($value == 'category') {
             $cat_tag = true;
             /************************/
             if (isset($var[1]) && $var[1] == 'm') {
                 $category_select_type = ' multiple="multiple"';
             }
             if (isset($var[2]) && (int) $var[2] > 0) {
                 $category_select_size = ' size="' . $var[2] . '"';
             }
             /************************/
         }
         if (isset($var[1]) && strtolower($var[1]) == 'm') {
             $select[$var[0]] = 'selectmultiple';
         } elseif (isset($var[1]) && strtolower($var[1]) == 's') {
             $select[$var[0]] = 'select';
         }
         $select_size[$var[0]] = isset($var[2]) ? $var[2] : 5;
         # Check for category select list
         if ($var[0] == 'category') {
             if (isset($var[1]) && strtolower($var[1]) == 's') {
                 $category_select_type = ' multiple="multiple"';
             }
             if (isset($var[2]) && (int) $var[2] > 0) {
                 $category_select_size = ' size="' . $var[2] . '"';
             }
         }
     }
     # Get selected values from url
     $entry = array();
     foreach ($this->params as $key => $value) {
         if (substr($key, 0, 3) == 'jr_') {
             $entry['Field']['pairs'][$key]['value'] = explode('_', $value);
         }
         // Add categories/sections
     }
     if (isset($this->params['tag'])) {
         $entry['Field']['pairs']['jr_' . $this->params['tag']['field']]['value'] = array($this->params['tag']['value']);
     }
     # Generate category list if tag found in view
     if ($cat_tag) {
         # Get module params before auto-detect
         $param_cat_id = Sanitize::getString($this->params['module'], 'cat_id');
         $param_dir_id = Sanitize::getString($this->params['module'], 'dir_id');
         $param_type_id = Sanitize::getString($this->params['module'], 'criteria_id');
         # Category auto detect
         $ids = CommonController::_discoverIDs($this);
         if ($cat_auto) {
             extract($ids);
         } elseif ($this->cmsVersion != CMS_JOOMLA15) {
             isset($ids['cat_id']) and $cat_id = $ids['cat_id'];
         }
         if ($this->cmsVersion == CMS_JOOMLA15 && $section_id == '' && $cat_id != '') {
             $sql = "SELECT section FROM #__categories WHERE id IN (" . $cat_id . ")";
             $this->_db->setQuery($sql);
             $section_id = $this->_db->loadResult();
         }
         $cat_id != '' and $this->params['module']['cat_id'] = $cat_id;
         $cat_id == '' and $section_id != '' and $this->params['module']['section_id'] = $section_id;
         $cat_id == '' and $criteria_id != '' and $this->params['module']['criteria_id'] = $criteria_id;
         if ($this->cmsVersion == CMS_JOOMLA15) {
             $categorySelect = $this->Category->categoryTree($this->_user->gid, $this->params);
         } else {
             $options = array('disabled' => false, 'cat_id' => !empty($param_cat_id) && !$cat_auto ? $param_cat_id : ($cat_auto ? $cat_id : ''), 'parent_id' => !empty($param_cat_id) && !$cat_auto ? $param_cat_id : ($cat_auto ? $cat_id : ''), 'dir_id' => !empty($param_dir_id) && !$cat_auto ? $param_dir_id : ($cat_auto ? $dir_id : ''), 'type_id' => !empty($param_type_id) && !$cat_auto ? $param_type_id : ($cat_auto ? $criteria_id : ''));
             if ($cat_auto && empty($options['cat_id'])) {
                 $options['level'] = 1;
             }
             $categories = $this->Category->getCategoryList($options);
             // Now get the parent and sibling categories
             if ($cat_auto && isset($categories[$cat_id]) && count($categories) == 1) {
                 $options['cat_id'] = $options['parent_id'] = $categories[$cat_id]->parent_id;
                 $categories = $this->Category->getCategoryList($options);
             }
             $categorySelect = $Form->select('data[categories]', array_merge(array(array('value' => null, 'text' => '- ' . __t("Select Category", true) . ' -')), $categories), $cat_id, array('class' => 'jrSelect'));
         }
         $output = str_replace('{' . $names['category'] . '}', $categorySelect, $output);
     }
     $fields = $this->Field->getFieldsArrayFromNames(array_keys($names), 'listing', $entry);
     # Replace label tags and change field type based on view atttributes
     if ($fields) {
         foreach ($fields as $key => $group) {
             foreach ($group['Fields'] as $name => $field) {
                 if (isset($select[$name])) {
                     $fields[$key]['Fields'][$name]['type'] = $select[$name];
                     $fields[$key]['Fields'][$name]['properties']['size'] = $select_size[$name];
                 } elseif ($fields[$key]['Fields'][$name]['type'] == 'textarea') {
                     $fields[$key]['Fields'][$name]['type'] = 'text';
                 }
                 if (in_array($name, $labels)) {
                     $output = str_replace('{' . $name . '_label}', $field['title'], $output);
                 }
                 if ($field['type'] == 'date') {
                     $date_field = true;
                 }
             }
         }
         $search = true;
         $location = 'listing';
         $CustomFields->form_id = Sanitize::getInt($this->params, 'module_id');
         $formFields = $CustomFields->getFormFields($fields, $location, $search, __t("Select", true));
         # Replace input tags
         foreach ($names as $key => $name) {
             if (isset($formFields["data[Field][Listing][{$key}]"])) {
                 $output = str_replace('{' . $names[$key] . '}', $formFields["data[Field][Listing][{$key}]"], $output);
             }
         }
         # Load js and css
         if ($date_field) {
             $Html = ClassRegistry::getClass('HtmlHelper');
             $Html->app = 'jreviews';
             $Libraries = ClassRegistry::getClass('LibrariesHelper');
             $Html->js(arrayFilter(array('jq.ui.core', 'jq.ui.datepicker'), $Libraries->js()));
             $Html->css(arrayFilter(array('jq.ui.core'), $Libraries->css()), false);
             ?>
             <script type="text/javascript">jreviews.datepicker();</script>
             <?php 
         }
     }
     return $output;
 }
 function index()
 {
     $this->EverywhereAfterFind = true;
     // Triggers the afterFind in the Observer Model
     if (!isset($this->params['module'])) {
         $this->params['module'] = array();
     }
     // For direct calls to the controller
     // Required for ajax pagination to remember module settings
     $Session = RegisterClass::getInstance('MvcSession');
     $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id'));
     if ($this->ajaxRequest) {
         $this->params = $Session->get('module_params' . $module_id, null, S2Paths::get('jreviews', 'S2_CMSCOMP'));
     } else {
         srand((double) microtime() * 1000000);
         $this->params['rand'] = rand();
         $Session->set('module_rand' . $module_id, $this->params['rand'], S2Paths::get('jreviews', 'S2_CMSCOMP'));
         $Session->set('module_params' . $module_id, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP'));
     }
     # Prevent sql injection
     $token = Sanitize::getString($this->params, 'token');
     $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false));
     $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix');
     $conditions = array();
     $joins = array();
     $order = array();
     # Read module parameters
     $extension = Sanitize::getString($this->params['module'], 'extension');
     $reviews_type = Sanitize::getString($this->params['module'], 'reviews_type');
     $custom_where = Sanitize::getString($this->params['module'], 'custom_where');
     $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_id = Sanitize::getString($this->params['module'], 'criteria');
     } else {
         $dir_id = null;
         $section_id = null;
         $criteria_id = null;
     }
     // This parameter determines the module mode
     $sort = Sanitize::getString($this->params['module'], 'reviews_order');
     # Category auto detect
     if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') {
         $ids = CommonController::_discoverIDs($this);
         extract($ids);
     }
     $extension != '' and $conditions[] = "Review.mode = " . $this->quote($extension);
     # Set conditionals based on configuration parameters
     if ($extension == 'com_content') {
         $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )', 'Listing.access <= ' . $this->_user->gid));
         $cat_id != '' and $conditions[] = 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')';
         $cat_id == '' and $section_id != '' and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')';
         $cat_id == '' and $dir_id != '' and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')';
         $cat_id == '' and $criteria_id != '' and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')';
     } else {
         if (Sanitize::getInt($this->params['module'], 'cat_auto') && isset($this->Listing) && 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 (' . cleanIntegerCommaList($cat_id) . ')';
         }
     }
     $listing_id and $conditions[] = "Review.pid IN ( " . cleanIntegerCommaList($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':
             $order[] = 'RAND(' . $this->params['rand'] . ')';
             break;
         default:
             $order[] = $this->Review->processSorting('rdate');
             break;
     }
     switch ($reviews_type) {
         case 'all':
             break;
         case 'user':
             $conditions[] = 'Review.author = 0';
             break;
         case 'editor':
             $conditions[] = 'Review.author = 1';
             break;
     }
     # Custom WHERE
     $tokenMatch and $custom_where and $conditions[] = $custom_where;
     $queryData = array('joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $this->module_limit, 'offset' => $this->module_offset);
     # 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);
     if (Sanitize::getInt($this->params['module'], 'ajax_nav', 1)) {
         unset($queryData['order']);
         $count = $this->Review->findCount($queryData, 'DISTINCT Review.id');
     } else {
         $count = $this->module_limit;
     }
     # Send variables to view template
     $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'reviews' => $reviews, 'total' => $count));
     $page = $this->render('modules', 'reviews');
     if ($this->ajaxRequest) {
         return $this->ajaxResponse($page, false);
     } else {
         return $page;
     }
 }
 function index()
 {
     global $Itemid;
     $cat_id = null;
     $conditions = array();
     $joins = array();
     $order = array();
     $menu_id = '';
     // Read module params
     $dir_id = Sanitize::getString($this->params['module'], 'dir');
     $section_id = Sanitize::getString($this->params, 'section');
     $cat_id = Sanitize::getString($this->params['module'], 'cat');
     $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     $itemid_options = Sanitize::getString($this->params['module'], 'itemid_options');
     $itemid_hc = Sanitize::getInt($this->params['module'], 'hc_itemid');
     $field = Sanitize::paranoid(Sanitize::getString($this->params['module'], 'field'), array('_'));
     $option_length = Sanitize::getInt($this->params['module'], 'fieldoption_length');
     $custom_params = Sanitize::getString($this->params['module'], 'custom_params');
     $sort = Sanitize::paranoid(Sanitize::getString($this->params['module'], 'fieldoption_order'));
     # Category auto detect
     if (Sanitize::getInt($this->params['module'], 'catauto')) {
         $ids = CommonController::_discoverIDs($this);
         extract($ids);
     }
     # Set menu id
     switch ($itemid_options) {
         case 'category':
             $click2searchUrl = 'index.php?option=com_jreviews&amp;Itemid={itemid}&amp;url=tag/{field}/{optionvalue}/';
             if (is_numeric($cat_id) && $cat_id > 0) {
                 $query = "\n\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\tdirid\n\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t#__jreviews_categories\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tid = " . (int) $cat_id . "\n\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t`option` = 'com_content'\n\t\t\t\t\t\t";
                 $this->_db->setQuery($query);
                 $dir_id = $this->_db->loadResult();
                 $menu_id = $this->Menu->getCategory(array('cat_id' => $cat_id, 'dir_id' => $dir_id));
             } elseif (is_numeric($dir_id) && $dir_id > 0) {
                 $menu_id = $this->Menu->getDir($dir_id);
             } else {
                 $click2searchUrl = 'index.php?option=com_jreviews&amp;Itemid=&amp;url=tag/{field}/{optionvalue}/';
             }
             $click2searchUrl = str_replace(array('{itemid}', '{field}', '/cat:{catid}', '/criteria:{criteriaid}'), array($menu_id, substr($field, 3), '', ''), $click2searchUrl);
             break;
         case 'search':
             // Need a criteria id. If not specified in the module settings, we can get it from the category id if one is detected
             if (empty($criteria_id) && $cat_id > 0) {
                 $query = "\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tcriteriaid\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t#__jreviews_categories\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tid = " . (int) $cat_id . "\n\t\t\t\t\t\t";
                 $this->_db->setQuery($query);
                 $criteria_id = $this->_db->loadResult();
             }
             $click2searchUrl = 'index.php?option=com_jreviews&amp;Itemid={itemid}&amp;url=tag/{field}/{optionvalue}/';
             if (is_numeric($criteria_id) && $criteria_id > 0) {
                 $menu_id = $this->Menu->get('jr_advsearch_' . $criteria_id);
             }
             if (empty($menu_id)) {
                 $menu_id = $this->Menu->get('jr_advsearch');
             }
             $click2searchUrl = str_replace(array('{itemid}', '{field}', '/cat:{catid}', '/criteria:{criteriaid}'), array($menu_id, substr($field, 3), '', ''), $click2searchUrl);
             break;
         case 'hardcode':
             $click2searchUrl = 'index.php?option=com_jreviews&amp;Itemid={itemid}&amp;url=tag/{field}/{optionvalue}/';
             $urlParamArray = array('dir' => $dir_id, 'criteria' => $criteria_id, 'cat' => $cat_id, 'section' => $section_id);
             $params = arrayToParams($urlParamArray);
             $click2searchUrl .= $params != '' ? $params . '/' : '';
             $menu_id = $itemid_hc;
             $click2searchUrl = str_ireplace(array('{itemid}', '{field}'), array($menu_id, substr($field, 3)), $click2searchUrl);
             break;
         case 'none':
         default:
             $click2searchUrl = 'index.php?option=com_jreviews&amp;Itemid=&amp;url=tag/{field}/{optionvalue}/';
             $urlParamArray = array('dir' => $dir_id, 'criteria' => $criteria_id, 'cat' => $cat_id, 'section' => $section_id);
             $params = arrayToParams($urlParamArray);
             $click2searchUrl .= $params != '' ? $params . '/' : '';
             $menu_id = $itemid_hc;
             $click2searchUrl = str_replace('{field}', substr($field, 3), $click2searchUrl);
             break;
     }
     $this->FieldOption->modelUnbind(array('FieldOption.value AS `FieldOption.value`', 'FieldOption.fieldid AS `FieldOption.fieldid`', 'FieldOption.image AS `FieldOption.image`', 'FieldOption.ordering AS `FieldOption.ordering`', 'FieldOption.optionid AS `FieldOption.optionid`', 'FieldOption.text AS `FieldOption.text`'));
     $fields[] = 'FieldOption.optionid AS `FieldOption.optionid`';
     $fields[] = 'FieldOption.value AS `FieldOption.value`';
     if ($option_length) {
         $fields[] = 'IF(CHAR_LENGTH(FieldOption.text)>' . $option_length . ',CONCAT(SUBSTR(FieldOption.text,1,' . $option_length . '),"..."),FieldOption.text) AS `FieldOption.text`';
     } else {
         $fields[] = 'FieldOption.text AS `FieldOption.text`';
     }
     $joins[] = 'INNER JOIN #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid';
     $order[] = 'FieldOption.' . $sort;
     $field_options = $this->FieldOption->findAll(array('fields' => $fields, 'conditions' => 'Field.name = ' . $this->quote($field), 'joins' => $joins, 'order' => $order));
     # Send variables to view template
     $this->set(array('field' => $field, 'click2searchUrl' => $click2searchUrl, 'field_options' => $field_options, 'custom_params' => $custom_params));
     return $this->render('modules', 'fields');
 }
 function index()
 {
     // Required for ajax pagination to remember module settings
     $Session = RegisterClass::getInstance('MvcSession');
     $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id'));
     if (!isset($this->params['module'])) {
         $this->params['module'] = array();
     }
     // For direct calls to the controller
     if ($this->ajaxRequest) {
         $this->params = $Session->get('module_params' . $module_id, null, S2Paths::get('jreviews', 'S2_CMSCOMP'));
     } else {
         srand((double) microtime() * 1000000);
         $this->params['rand'] = rand();
         $Session->set('module_rand' . $module_id, $this->params['rand'], S2Paths::get('jreviews', 'S2_CMSCOMP'));
         $Session->set('module_params' . $module_id, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP'));
     }
     # Prevent sql injection
     $token = Sanitize::getString($this->params, 'token');
     $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false));
     $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix');
     $conditions = array();
     $joins = array();
     $order = array();
     $having = array();
     # Read module parameters
     $dir_id = Sanitize::getString($this->params['module'], 'dir');
     $section_id = Sanitize::getString($this->params['module'], 'section');
     $cat_id = Sanitize::getString($this->params['module'], 'category');
     $listing_id = Sanitize::getString($this->params['module'], 'listing');
     $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     $limit = Sanitize::getString($this->params['module'], 'module_limit', 5);
     $extension = Sanitize::getString($this->params['module'], 'extension');
     $extension = $extension != '' ? $extension : 'com_content';
     if (isset($this->Listing)) {
         $this->Listing->_user = $this->_user;
         // This parameter determines the module mode
         $sort = Sanitize::getString($this->params['module'], 'listing_order');
         $custom_order = Sanitize::getString($this->params['module'], 'custom_order');
         $custom_where = Sanitize::getString($this->params['module'], 'custom_where');
         if ($extension != 'com_content' && in_array($sort, array('topratededitor', 'featuredrandom', 'rhits'))) {
             echo "You have selected the {$sort} mode which is not supported for components other than com_content. Please read the tooltips in the module parameters for more info on allowed settings.";
             return;
         }
         # Category auto detect
         if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') {
             $ids = CommonController::_discoverIDs($this);
             extract($ids);
         }
         # Set conditionals based on configuration parameters
         if ($extension == 'com_content') {
             // Only works for core articles
             $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )', 'Listing.access <= ' . $this->_user->gid));
             // Remove unnecessary fields from model query
             $this->Listing->modelUnbind(array('Listing.fulltext AS `Listing.description`', 'Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`', 'User.email AS `User.email`'));
             $cat_id != '' and $conditions[] = 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')';
             $cat_id == '' and $section_id != '' and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')';
             $cat_id == '' and $dir_id != '' and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')';
             $cat_id == '' and $criteria_id != '' and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')';
         } else {
             if (Sanitize::getInt($this->params['module'], 'cat_auto') && method_exists($this->Listing, 'catUrlParam')) {
                 if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) {
                     $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
                 }
             } elseif ($cat_id) {
                 $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
             }
         }
         $listing_id and $conditions[] = "Listing.{$this->Listing->realKey} IN (" . cleanIntegerCommaList($listing_id) . ")";
         switch ($sort) {
             case 'random':
                 $order[] = 'RAND(' . $this->params['rand'] . ')';
                 break;
             case 'featuredrandom':
                 $conditions[] = 'featured > 0';
                 $order[] = 'RAND(' . $this->params['rand'] . ')';
                 break;
             case 'topratededitor':
                 $conditions[] = 'Totals.editor_rating > 0';
                 break;
                 // Editor rating sorting options dealt with in the Listing->processSorting method
         }
         # Custom WHERE
         $tokenMatch and $custom_where and $conditions[] = $custom_where;
         # Filtering options
         $having = array();
         // Listings submitted in the past x days
         $entry_period = Sanitize::getInt($this->params['module'], 'filter_listing_period');
         if ($entry_period > 0 && $this->Listing->dateKey) {
             $conditions[] = "Listing.{$this->Listing->dateKey} >= DATE_SUB('" . _CURRENT_SERVER_TIME . "', INTERVAL {$entry_period} DAY)";
         }
         // Listings with reviews submitted in past x days
         $review_period = Sanitize::getInt($this->params['module'], 'filter_review_period');
         if ($review_period > 0) {
             $conditions[] = "Review.created >= DATE_SUB(CURDATE(), INTERVAL {$review_period} DAY)";
             $joins[] = 'LEFT JOIN #__jreviews_comments AS Review ON Listing.' . $this->Listing->realKey . ' = Review.pid';
         }
         // Listings with review count higher than
         $filter_review_count = Sanitize::getInt($this->params['module'], 'filter_review_count');
         $filter_review_count > 0 and $conditions[] = "Totals.user_rating_count >= " . $filter_review_count;
         // Listings with avg rating higher than
         $filter_avg_rating = Sanitize::getFloat($this->params['module'], 'filter_avg_rating');
         $filter_avg_rating > 0 and $conditions[] = 'Totals.user_rating  >= ' . $filter_avg_rating;
         $this->Listing->group = array();
         // Exlude listings without ratings from the results
         $join_direction = in_array($sort, array('rating', 'rrating', 'topratededitor', 'reviews')) ? 'INNER' : 'LEFT';
         $this->Listing->joins['Total'] = "{$join_direction} JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.{$this->Listing->realKey} AND Totals.extension = " . $this->quote($extension);
         # Modify query for correct ordering. Change FIELDS, ORDER BY and HAVING BY directly in Listing Model variables
         if ($tokenMatch and $custom_order) {
             $this->Listing->order[] = $custom_order;
         } elseif (empty($order) && $extension == 'com_content') {
             $this->Listing->processSorting($sort, '');
         } elseif (empty($order) && ($order = $this->_processSorting($sort))) {
             $order = array($order);
         }
         $queryData = array('fields' => array('Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.user_comment_count AS `Review.review_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', 'Totals.editor_comment_count AS `Review.editor_review_count`'), 'joins' => $joins, 'conditions' => $conditions, 'limit' => $this->module_limit, 'offset' => $this->module_offset, 'having' => $having);
         isset($order) and !empty($order) and $queryData['order'] = $order;
         // Trigger addFields for $listing results. Checked in Everywhere model
         $this->Listing->addFields = true;
         $listings = $this->Listing->findAll($queryData);
         if (Sanitize::getInt($this->params['module'], 'ajax_nav', 1)) {
             unset($queryData['joins']['Section'], $queryData['joins']['Category'], $queryData['joins']['Directory'], $queryData['joins']['Criteria'], $queryData['joins']['User'], $queryData['order']);
             $count = $this->Listing->findCount($queryData, 'DISTINCT Listing.' . $this->Listing->realKey);
         } else {
             $count = $this->module_limit;
         }
     } else {
         $listings = array();
         $count = 0;
     }
     unset($this->Listing);
     # Send variables to view template
     $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'subclass' => 'listing', 'listings' => $listings, 'total' => $count));
     $page = $this->render('modules', 'listings');
     if ($this->ajaxRequest) {
         return $this->ajaxResponse($page, false);
     } else {
         return $page;
     }
 }