Created
November 21, 2013 23:37
-
-
Save andiraduta/7591955 to your computer and use it in GitHub Desktop.
Quicklink tool in caz ca site-ul 2Parale este nefunctional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
$user_2p = ''; // your 2parale user | |
$pass_2p = ''; // your 2parale pass | |
function get_page($link) { | |
global $user_2p, $pass_2p; | |
$ch = curl_init($link); | |
curl_setopt($ch, CURLOPT_USERPWD, $user_2p . ":" . $pass_2p); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0"); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
return $response; | |
} | |
function recursive_campaign_list($url, &$campaigns, &$page) { | |
$response = get_page($url); | |
$json_obj = json_decode($response); | |
foreach($json_obj as $c) { | |
$campaigns[$c->campaign->unique_code] = $c->campaign->name . ' ('. $c->campaign->main_url .')'; | |
} | |
// it has more results -> get next page | |
if( count($json_obj) == 50 ) { | |
$page++; | |
recursive_campaign_list($url.'&page='.$page, $campaigns, $page); | |
} | |
} | |
if( !isset($_SESSION['aff_code']) ) { | |
$response = get_page('http://api.2parale.ro/users/loggedin.json'); | |
$json_obj = json_decode($response); | |
$_SESSION['aff_code'] = $json_obj->user->unique_code; | |
} | |
if( !isset($_SESSION['campaigns']) ) { | |
$page = 1; | |
$campaigns = array(); | |
$url = "http://api.2parale.ro/campaigns.json?perpage=50"; | |
recursive_campaign_list($url, $campaigns, $page); | |
$_SESSION['campaigns'] = $campaigns; | |
} | |
if( isset($_POST['convert']) ) { | |
$unique = $_POST['campaign']; | |
$redirect_to = urlencode($_POST['url']); | |
$quicklink_url = "http://event.2parale.ro/events/click?ad_type=quicklink&aff_code=".$_SESSION['aff_code']."&unique=".$unique."&redirect_to=".$redirect_to; | |
} | |
?> | |
<html> | |
<head> | |
<title>2P Tool</title> | |
</head> | |
<body> | |
<?php echo isset($quicklink_url) ? '<p>Quicklink: <a href="'.$quicklink_url.'">'.$quicklink_url.'</a></p>': ''; ?> | |
<form action="" method="POST"> | |
<select name="campaign" style="width: 300px;"> | |
<?php | |
foreach( $_SESSION['campaigns'] as $uc => $camp ) { | |
echo '<option value="'.$uc.'">'.$camp.'</option>'; | |
} | |
?> | |
</select> | |
<input type="text" size="50" name="url" /> | |
<input type="submit" name="convert" value="Quicklink!" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment