Exemple #1
0
 /**
  * Generate Open Search URL
  *
  * @access      public
  * @return      string
  */
 public function url()
 {
     // --------------------------------------
     // Set internal params
     // --------------------------------------
     $this->params->set();
     // --------------------------------------
     // Shortcut?
     // --------------------------------------
     $this->_get_shortcut();
     // --------------------------------------
     // Params to ignore
     // --------------------------------------
     $ignore = array('query', 'query_string', 'encode', 'cache', 'refresh', 'parse', 'shortcut');
     // --------------------------------------
     // Is there a query_string parameter?
     // This helps passing through params with an encoded string
     // while using GET vars
     // --------------------------------------
     if ($qs = $this->_extract_tagparam('query_string')) {
         $this->params->set($qs);
     }
     // --------------------------------------
     // Loop through tagparams and add them to the query string
     // --------------------------------------
     // init toggle array
     $toggle = array();
     // Override with tagparams
     foreach (ee()->TMPL->tagparams as $key => $val) {
         if (in_array($key, $ignore) || !is_string($val)) {
             continue;
         }
         // Decode value
         $val = low_format($val, 'ee-decode');
         // Check for toggle values
         if (substr($key, 0, 7) == 'toggle:') {
             $toggle[substr($key, 7)] = $val;
             continue;
         }
         // Add to query string
         $this->params->set($key, $val);
     }
     // --------------------------------------
     // Handle toggle values
     // --------------------------------------
     foreach ($toggle as $key => $val) {
         if ($current_val = $this->params->get($key)) {
             // Read current value
             list($values, $in) = low_explode_param($current_val);
             // check if value is there
             if (($i = array_search($val, $values)) === FALSE) {
                 // Not there, add it
                 $values[] = $val;
             } else {
                 // Is there, remove it
                 unset($values[$i]);
             }
             $val = low_implode_param($values, $in);
         }
         // Add the new value to the parameter array (could be NULL)
         $this->params->set($key, $val);
     }
     // --------------------------------------
     // Clean up the parameters before making the URL
     // --------------------------------------
     $params = array_filter($this->params->get(), 'low_not_empty');
     // --------------------------------------
     // Then compose the URL, encoded or not
     // --------------------------------------
     if (ee()->TMPL->fetch_param('encode', 'yes') == 'no') {
         // Build non-encoded URL
         $url = ee()->functions->fetch_site_index() . QUERY_MARKER . 'ACT=' . ee()->functions->fetch_action_id($this->package, 'catch_search') . AMP . http_build_query($params, '', AMP);
     } else {
         // Get the result page from the params
         $url = $this->_create_url($params);
     }
     return $url;
 }
 function low_merge_params($haystack, $needles, $as_param = FALSE)
 {
     // Prep the haystack
     if (!is_array($haystack)) {
         // Explode the param, forget about the 'not '
         list($haystack, ) = low_explode_param($haystack);
     }
     // Prep the needles
     if (!is_array($needles)) {
         list($needles, $in) = low_explode_param($needles);
     } else {
         $in = TRUE;
     }
     // Choose function to merge
     $method = $in ? 'array_intersect' : 'array_diff';
     // Do the merge thing
     $merged = $method($haystack, $needles);
     // Change back to parameter syntax if necessary
     if ($as_param) {
         $merged = low_implode_param($merged);
     }
     return $merged;
 }
Exemple #3
0
 /**
  * Prep parameters for keyword-less search
  */
 private function _prep_params()
 {
     // --------------------------------------
     // No keyword search means no excerpt from collection,
     // so we need to get the excerpt field from the
     // channel preferences. We'll do that here and store
     // the ids in cache for later use
     // --------------------------------------
     // Get channel excerpt data from DB
     ee()->db->select('channel_name, channel_id, search_excerpt')->from('channels');
     // Filter by given collections
     if ($this->_collections) {
         ee()->db->where_in('channel_id', low_flatten_results($this->_collections, 'channel_id'));
     }
     // Get the data
     $channels = ee()->db->get()->result_array();
     $this->_excerpts = low_flatten_results($channels, 'search_excerpt', 'channel_id');
     // --------------------------------------
     // If collections were given, we need to filter
     // the channel entries by channel, so we'll set
     // the channel parameter based on collections
     // --------------------------------------
     if ($this->_collections && $channels) {
         $channels = array_unique(low_flatten_results($channels, 'channel_name'));
         $this->params->set('channel', low_implode_param($channels));
     }
     // Remove low_search_score from the orderby parameter and adjust sort param accordingly
     $orderby = $this->params->get('orderby');
     if ($orderby && substr($orderby, 0, 16) == 'low_search_score') {
         $this->params->set('orderby', preg_replace('#^low_search_score\\|?#', '', $orderby));
         if ($sort = $this->params->get('sort')) {
             $this->params->set('sort', preg_replace('#^(asc|desc)\\|?#i', '', $sort));
         }
     }
 }