<?php
define ('REFERAL_STRING', 'id');
define ('DELIMITER', '=');
define ('SEARCHREFCODE', 'xxxx');
define ('DEFAULTREFCODE', '0');
// variables 2 work with cookies
define ('COOKIE_PREFIX', 'RefLinXid');
$expire = time() + 31536000;
define ('COOKIE_ESPIRITY', $expire);
$AdvertRefCode = DEFAULTREFCODE;
function CheckRefererAndSetUpCookie() {
if (isset($_GET[REFERAL_STRING])){
// get ref code
$RefCode = trim($_GET[REFERAL_STRING]);
// set up cookie
setcookie('blog_aid', $RefCode, 0, '/');
} else {
//check if cookie was already setted up by smbd
if ($_COOKIE['blog_aid'])
$RefCode = $_COOKIE['blog_aid'];
else {
$RefCode = DEFAULTREFCODE;
setcookie('blog_aid', $RefCode, 0, '/');
}
}
return $RefCode;
}
//print_r($_COOKIE);
//print $_COOKIE['blog_aid'];
//print CheckRefererAndSetUpCookie();
function reflinks($content) {
global $AdvertRefCode;
$content = str_ireplace(REFERAL_STRING.DELIMITER.SEARCHREFCODE,REFERAL_STRING.DELIMITER.$AdvertRefCode,$content);
return $content;
}
$AdvertRefCode = CheckRefererAndSetUpCookie();
add_filter('the_content', 'reflinks');
?>