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); }
/** * Generates the dropdown list for number of items per page * @return html select list */ function display_items_per_page() { $args = func_get_args(); if (func_num_args() == 2) { $this->update_id = array_shift($args); $items_per_page = array_shift($args); } else { $items_per_page = array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50); } $Form = ClassRegistry::getClass('FormHelper'); $segments = ''; $url_param = array(); $passedArgs = $this->passedArgs; if ($this->ajaxRequest) { foreach ($items_per_page as $limit) { $selectList[] = array('value' => $limit, 'text' => $limit); } $selected = $this->limit; //Sanitize::getInt($this->data,'limit'); $onchange = ($this->ajax_scroll ? "jQuery('#" . $this->scroll_id . "').scrollTo(500,100);" : '') . " \r\n var \$form = jQuery(this).parents('form');\r\n \$form.find('input[name="data[page]"]').val(1);\r\n \$form.find('input[name="data[limit]"]').val(this.value);\r\n \$form.find('input[name="data[action]"]').val('{$this->action}');\r\n jQuery.post(s2AjaxUri,\$form.serialize(),function(s2Out){jQuery('#{$this->update_id}').html(s2Out);},'html');\r\n "; return __t("Results per page", true) . ': ' . $Form->select('order_limit', $selectList, $selected, array('onchange' => $onchange)); } else { foreach ($items_per_page as $limit) { if (defined('MVC_FRAMEWORK_ADMIN')) { $url = $this->base_url . 'page' . _PARAM_CHAR . '1/limit' . _PARAM_CHAR . $limit; } else { $url = cmsFramework::route($this->base_url . '/page' . _PARAM_CHAR . '1/limit' . _PARAM_CHAR . $limit . (cmsFramework::mosCmsSef() ? '' : '/')); } $selectList[] = array('value' => $url, 'text' => $limit); } if (defined('MVC_FRAMEWORK_ADMIN')) { $selected = $this->base_url . 'page' . _PARAM_CHAR . '1/limit' . _PARAM_CHAR . $this->limit; } else { $selected = cmsFramework::route($this->base_url . '/page' . _PARAM_CHAR . '1/limit' . _PARAM_CHAR . $this->limit . (cmsFramework::mosCmsSef() ? '' : '/')); } return __t("Results per page", true) . ': ' . $Form->select('order_limit', $selectList, $selected, array('onchange' => "window.location=this.value")); } }