%2F * - & -> & * - & -> & (avoids double "&" encoding) * * @author oncletom * @version 1.0 * @since 1.1 beta * @return $encoded_uri String Encoded URI * @param $uri String Uri to encode */ function encodeParameters($uri) { $parsed_uri = parse_url($uri); $qs_original = $parsed_uri['query']; $qs = str_replace(array('/', '&', '&'), array('%2F', '&', '&'), $qs_original); return str_replace($qs_original, $qs, $uri); } /** * Filter an hexa code to return it with a prefix, if needed * * @author oncletom * @version 2.0 * @since 1.3 * @return $color String * @param $color String Hexadecimal color to filter * @param $prefix Boolean[optional] Add a hash prefix or not * * @todo add a better filter which checks hexa code and more */ function getHexadecimalFromString($color, $prefix = true) { // no need to go further if (!$color) { return ''; } $color = preg_replace('/[^a-fA-F0-9]/U', '', $color); $prefix = (bool)$prefix && $color ? '#' : ''; return $prefix.$color; } /** * Render a tracking image thanks to some parameters * * @author oncletom * @version 1.0 * @since 1.3 * @return String Tracking image HTML code * @param Array $options * @param Array $params * @param Boolean $render[optional] */ function getTrackingImage($options, $params, $render = null) { $render = is_null($render) ? (bool)get_option('awshortcode_tracking_image') : (bool)$render; $query_string = array(); if (function_exists('http_build_query')) { $query_string = http_build_query($params, '', '&'); } /* * @todo remove that when PHP4 support ends */ else { foreach ($params as $key => $value) { $query_string[] = sprintf('%s=%s', $key, $value); } $query_string = implode('&', $query_string); } $uri = sprintf( 'http://www.assoc-amazon.%s/e/ir?%s', $options['tld'], $query_string ); return ''; } }