/** * 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_format($str = '', $format = 'html') { // Encode/decode chars specifically for EE params $code = array('"' => '"', ''' => "'", '{' => '{', '}' => '}'); switch ($format) { case 'url': $str = urlencode($str); break; case 'html': $str = htmlspecialchars($str); $str = low_format($str, 'ee-encode'); break; case 'clean': $str = low_clean_string($str); break; case 'ee-encode': $str = str_replace(array_values($code), array_keys($code), $str); break; case 'ee-decode': $str = str_replace(array_keys($code), array_values($code), $str); break; } return $str; }
/** * Get vars */ public function get_vars($prefix = '') { $this->_filter(); $vars = array(); foreach ($this->_params as $key => $val) { // force string $val = (string) $val; $vars[$prefix . $key . ':raw'] = $val; $vars[$prefix . $key] = low_format($val); } return $vars; }