///?args. Note if using these type of links it is recommended that you clearly indicate on your site that the link is to Amazon otherwise you might be in breach of the terms and conditions of your associates account.
Version: 1.2.6
Author: Paul Stuttard
Author URI: http://www.houseindorset.co.uk
*/
/*
Copyright 2012-2013 Paul Stuttard
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* The Redirect action function that is called when the Amazon Link plugin is Initialised
*/
function alx_redirect($settings, $al) {
$url = NULL;
$uri = $_SERVER['REQUEST_URI'];
parse_url(home_url(),$url);
$match = preg_match( '!'.$url['path'].'/'.$settings['redirect_word'].'(?:/(?P[A-Z0-9]{10})|/(?P[^/]{2,}))?(?:/(?PA|S|R|B))?(?:/(?Pmx|br|ca|cn|de|fr|in|it|es|jp|uk|us))?!', $uri, $args);
if ( $match ) {
$arg_position = strpos($uri,'?');
$opts = array();
if ($arg_position > 0) $opts['args'] = substr($uri,$arg_position+1);
// Get all named args
foreach ($args as $arg => $data) {
if (!is_int($arg) && !empty($data)) $opts[$arg] = $data;
}
// Extract the Hard coded Type if set
$type = !empty($opts['type']) ? $opts['type'] : '';
unset($opts['type']);
// If hard coded to a specific locale then disable localisation
if (isset($opts['default_cc'])) {
$asin = isset($opts['asin'])?$opts['asin']:'';
unset($opts['asin']);
$opts['asin'] = $asin;
$opts['localise']=0;
}
$opts['template_content'] = '%'.$type.'URL%';
$al->in_post=false;
$al->post_ID=NULL;
$url = $al->shortcode_expand($opts);
$url_bits = explode('?', $url, 2);
$url_bits[1] = str_replace(array('&', ' ','|','\''), array('&', '+','%7c','%27'), $url_bits[1]);
$url = $url_bits[0].'?'.$url_bits[1];
if (!empty($url)) {
//echo "