Olá,
Preciso de uma ajudinha urgente antes de abrir o meu site que adiei devido a uma alteração em mente.
Tenho um script, generador de links, do tipo adf.ly, mas quero transforma-lo num script PTP.
No script que tenho, quando geramos um novo link, quando entramos nele, teremos que esperar 5 segundos e ainda temos que clicar no "Skip Ads".
Mas... eu quero que ele redireccione directamente para o site gerado.
Para aqueles que não perceberam, (não sei explicar bem), é isto que basicamente quero fazer:
Percebo mesmo muito minimamente de PHP, portanto não sei como fazer.
Tenho aqui os 2 ficheiros PHP que acho que são só esses que fazem essas tais funções.
Index.php :
<?php
ini_set('display_errors', 0);
require_once '../global.php';
require_once ROOT_PATH . '/inc/analyzer.class.php';
function kill() { System::redirect(SITE_LOCATION); exit; };
if (isset($_GET['uid']) && isset($_GET['url'])) {
$G_UID = intval($_GET['uid']);
$G_URL_R = $G_UID . '/' . ($_GET['adt'] != 1 ? 'banner/' : '');
$G_URL = $_SERVER['REQUEST_URI'];
$G_URL = substr($G_URL, strpos($G_URL, $G_URL_R) + strlen($G_URL_R));
$G_ADT = $_GET['adt'] != 1 ? 'Top Banner' : 'Interstitial';
$urlsb = substr($G_URL, 0, strpos($G_URL, '://'));
if (!$urlsb) {
$G_URL = 'http://' . $G_URL;
}
if (!is_numeric($G_UID) || !Utilities::validateURL($G_URL)) {
kill();
}
} else if(!preg_match('|^[0-9a-zA-Z]{1,6}$|', $_GET['to'])) {
kill();
}
$G_SHORT = false;
if ($G_UID && $G_URL && $G_ADT) {
$surl = SITE_LOCATION;
$db = System::getDB();
$user = $G_UID;
if ($tmp = $db->getField($_GLOBAL['TABLES']['LINKS'], 'short_url',
"`long_url`='{$G_URL}' AND `adtype`='{$G_ADT}' AND `user`='{$user}'")) {
$short = $tmp;
$data = System::getDB()->getRows($_GLOBAL['TABLES']['LINKS'], "`short_url`='{$short}'", '', '1');
} else {
$data = array('long_url' => $G_URL, 'adtype' => $G_ADT, 'user' => $user);
$db->query('LOCK TABLES ' . $_GLOBAL['TABLES']['LINKS'] . ' WRITE;');
$lid = $db->insert($_GLOBAL['TABLES']['LINKS'], $data);
$db->query('UNLOCK TABLES');
$short = $surl . System::shortenID($lid);
$db->update($_GLOBAL['TABLES']['LINKS'], array('short_url' => $short), "`id`='{$lid}'");
$data = System::getDB()->getRows($_GLOBAL['TABLES']['LINKS'], "`id`='{$lid}'", '', '1');
}
$G_SHORT = $short;
} else {
$surl = Utilities::removeURLQueries(Utilities::getCurrentURL());
$data = System::getDB()->getRows($_GLOBAL['TABLES']['LINKS'], "`short_url`='{$surl}'", '', '1');
}
$lid = $data['id'];
$oid = $data['user'];
$url = $data['long_url'];
$title = $data['title'];
$adtyp = $data['adtype'] == 'Interstitial' ? 1 : 2;
if (!$url) kill();
$HTTP_REFERER = !$_SERVER["HTTP_REFERER"] ? getenv('HTTP_REFERER') : $_SERVER["HTTP_REFERER"];
if ($data['adtype'] == 'None') {
$analyzer = new Analyzer($lid, $oid, 0, $HTTP_REFERER);
$analyzer->_record($adtype);
System::redirect($url);
}
function get_ad() {
global $_GLOBAL, $data, $HTTP_REFERER;
$a = new Analyzer(0, 0, 0);
if ($a->_isCrawler()) die('Crawlers are not allowed here');
$db = System::getDB();
$t = $data['adtype'] != 'Interstitial' ? 'Banner' : 'Interstitial';
$cc = $a->country($a->ip());
$ci = $db->getField($_GLOBAL['TABLES']['PACKAGES'], 'id', "`code`='{$cc}' AND `advert_type`='{$t}'");
$c = $db->getRows($_GLOBAL['TABLES']['CAMPAIGNS'], "`status`='2' AND `advert_type`='{$t}'");
$valid = array();
$date = date('j');
for ($i = 0; $i < count($c); $i++) {
if (Utilities::float_cmp($c[$i]['spent_day'], $date) !== 0) {
$db->update($_GLOBAL['TABLES']['CAMPAIGNS'], array('spent_today' => '0', 'spent_day' => date('d')), "`id`='{$c[$i]['id']}'");
}
if (Utilities::float_cmp($c[$i]['daily_budget'], 0) == 1 && Utilities::float_cmp($c[$i]['spent_today'], $c[$i]['daily_budget']) == -1) continue;
$pkg = explode(';', $c[$i]['packages']);
foreach ($pkg as $p) {
$t = explode(',', $p);
if ($t[0] == $ci || $t[0] == '1' || $t[0] == '242') $valid[] = $c[$i];
}
}
return $valid[rand(0, count($valid) - 1)];
}
$AD = get_ad();
$aid = $AD['id'] | 0;
if ($adtyp == 2) {
$analyzer = new Analyzer($lid, $oid, $aid, $HTTP_REFERER);
$analyzer->_record('top_banner', 3);
}
$_user = new User($_GLOBAL['TABLES']['USERS'], $oid, System::getDB());
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title ? $title : SITE_PAGE_TITLE; ?></title>
<meta http-equiv="X-UA-Compatible" content="IE=8; IE=9" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<?php echo SITE_LOCATION; ?>css/style.css.php?fly" />
<script type="text/javascript" src="<?php echo SITE_LOCATION; ?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo SITE_LOCATION; ?>js/jquery.libs.js"></script>
</head>
<body style="background:#FFFFFF;">
<noscript>
<div style="padding: 5px; background-color: red; color: #ffffff; text-align:center; margin-top: 10px; margin-bottom: 10px;">
Your browser currently does not support javascript or you have javascript turned off.
This site will have very limited functionality without javascript.
Please use a modern browser with javascript or enable the javascript option.
</div>
</noscript>
<div class="fly_head" style="max-height:115px;">
<?php if ($adtyp == 2) { ?>
<div class="logo" style="display:inline-block;font-weight:bold;margin:0;max-height:100px;"></div>
<div class="fly_banner" style="margin:0 20px;display:inline-block;" align="center">
<a href="#">
<img src="<?php echo $AD['website_banner']; ?>" width="720px" height="90px" border="0" />
</a>
</div>
<div style="float:right;display:inline-block;margin:5px 0;width:100px;text-align:right;font-size:11px;">
<a href="#" class="close"><img src="<?php echo SITE_LOCATION; ?>images/close.png" border="0" /></a>
<a href="#" style="font-weight:600;position:absolute;color:white;text-decoration:none;top:90px;right:20px;">
ADVERTISEMENT
</a>
</div>
<?php } else { ?>
<div class="logo" style="display:inline-block;font-weight:bold;margin:5px 0;max-height:115px;"></div>
<div style="float:right;display:inline-block;margin:20px 0;">
Please wait...<span id="redirectin">1</span>
</div>
<?php } ?>
<div style="clear:both;"></div>
</div>
<div class="fly_head_bottom">
<?php if ($adtyp != 2) { ?>
<div style="display:inline-block;">
<a href="<?php echo SITE_LOCATION; ?>?r=<?php echo $oid; ?>" class="uc" target="_blank"><?php echo SITE_NAME; ?></a>
shorten urls and earn money
</div>
<div style="float:right;display:inline-block;">
<a href="<?php echo SITE_LOCATION; ?>advertising.php" class="uc" target="_blank">
</a>
</div>
<?php } ?>
<div style="clear:both;"></div>
</div>
<?php
$src = $adtyp == 1 ? $AD['website_url'] : $url;
echo "<iframe class='fly_frame' src='{$src}' scrolling='auto' frameborder='0' style='width:100%;'></iframe>";
?>
<script type="text/javascript">
<?php
function get_js_03() {
global $AD, $aid, $lid, $oid, $adtyp, $url, $HTTP_REFERER;
ob_start();
?>
$(document).ready(function() {
$('iframe.fly_frame').height($(document).height()-$('div.fly_head').height()-($('div.fly_head_bottom').height()*2));
});
$('iframe.fly_frame').ready(function() {
<?php if ($adtyp == 1) { ?>
var a0x1 = -2;
var rr = function() {
if (a0x1 < 0) {
$.post('<?php echo SITE_LOCATION; ?>links/ajax.fly.php',{opt:'check_log',args:{lid:<?php echo $lid; ?>,oid:<?php echo $oid; ?>}},
function(r) {
var j = eval('(' + r + ')');
if (j.message && a0x1 != -2) {
clearInterval(si);
var skip_ad = $('<div class="skip_btn"><a href="#">SKIP AD >></a></div>');
$('div.fly_head span#redirectin').parent().css('margin', '6px').html(skip_ad);
skip_ad.click(function() {
$.post('<?php echo SITE_LOCATION; ?>links/ajax.fly.php',
{opt:'make_log',args:{aid:<?php echo $aid; ?>,lid:<?php echo $lid; ?>,oid:<?php echo $oid; ?>,ref: <?php echo "'{$HTTP_REFERER}'"; ?>}},
function(rr) {
var jj = eval('(' + rr + ')');
if (jj.message && a0x1 != -2) {
top.location.href = jj.message.url;
}
}
);
skip_ad.html('Loading Page...');
});
} else {
a0x1 = 0;
}
}
);
} else {
$('span#redirectin').text(a0x1--);
}
}; rr();
var si = setInterval(rr, 0);
<?php } else { ?>
$('div.fly_banner a').click(function() {
$.post('<?php echo SITE_LOCATION; ?>links/ajax.fly.php',{opt:'click_log',args:{aid:<?php echo $aid; ?>,lid:<?php echo $lid; ?>,oid:<?php echo $oid; ?>,ref: <?php echo "'{$HTTP_REFERER}'"; ?>}},
function() {
top.location.href = '<?php echo $AD['website_url']; ?>';
}
);
});
$('div.fly_head a.close').click(function() {
$('div.fly_head').remove();
$('div.fly_head_bottom').remove();
top.location.href = '<?php echo $url; ?>';
});
<?php } ?>
});
<?php
$c = ob_get_contents();
ob_end_clean();
return $c;
}
echo Utilities::JSPack(get_js_03());
?>
</script>
<?php if ($ga = $_user->get('ga_code')) { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo $ga; ?>']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<?php } ?>
</body>
</html>
ajax.fly.php
<?php
define('AJAX_FLY_PHP_INCLUDED', true);
require_once '../global.php';
$OPT = $_GET['opt'];
$POPT = $_POST['opt'];
$RET = array('error' => false, 'message' => false);
if ($POPT == 'check_log') {
$lid = intval($_POST['args']['lid']);
$oid = intval($_POST['args']['oid']);
$vlo = SITE_SESSION_PREPEND . "view_{$lid}_{$oid}";
if ($lid > 0 && $oid >= 0) {
$view_time = 0;
$cookie = $_COOKIE[$vlo] | false;
if ($cookie && $cookie > 0) {
$view_time = gettimeofday(true) - $cookie;
} else {
setcookie($vlo, gettimeofday(true));
}
if ($view_time > 0) $RET['message'] = array('url' => '#');
}
} else if ($POPT == 'make_log') {
$aid = intval($_POST['args']['aid']);
$lid = intval($_POST['args']['lid']);
$oid = intval($_POST['args']['oid']);
$ref = mysql_escape_string(trim($_POST['args']['ref']));
$vlo = SITE_SESSION_PREPEND . "view_{$lid}_{$oid}";
$cookie = $_COOKIE[$vlo] | false;
$view_time = $cookie && $cookie > 0 ? gettimeofday(true) - $cookie : 0;
if ($view_time > 0) {
require_once ROOT_PATH . '/inc/analyzer.class.php';
$analyzer = new Analyzer($lid, $oid, $aid, $ref);
$adtype = System::getDB()->getField($_GLOBAL['TABLES']['LINKS'], 'adtype', "`id`='{$lid}'");
$analyzer->_record($adtype, $view_time - 0);
setcookie($vlo, 0);
$RET['message'] = array('url'=>System::getDB()->getField($_GLOBAL['TABLES']['LINKS'],
'long_url', "`id`='{$lid}'")
);
}
} else if ($POPT == 'click_log') {
$aid = intval($_POST['args']['aid']);
$lid = intval($_POST['args']['lid']);
$oid = intval($_POST['args']['oid']);
$ref = mysql_escape_string(trim($_POST['args']['ref']));
require_once ROOT_PATH . '/inc/analyzer.class.php';
$analyzer = new Analyzer($lid, $oid, $aid, $ref);
$RET['message'] = $analyzer->_recordClick();
}
die(json_encode($RET));
Se for mais fácil para quem me ajudar, falar por skype, aqui tem:
Precisava isto urgentemente para abrir o meu website.
Obrigado por toda a ajuda.