pretty-link
Last commit date
classes
17 years ago
images
17 years ago
includes
17 years ago
pretty-link.php
15 years ago
prli-config.php
17 years ago
prli-links.php
17 years ago
prli-reports.php
17 years ago
prli.php
17 years ago
readme.txt
17 years ago
screenshot-1.png
17 years ago
screenshot-2.png
17 years ago
screenshot-3.png
17 years ago
screenshot-4.png
17 years ago
prli.php
74 lines
| 1 | <?php |
| 2 | /* This file tracks clicks */ |
| 3 | |
| 4 | require_once(dirname(__FILE__) . '/../../../wp-config.php'); |
| 5 | |
| 6 | // reverse compatibility -- get rid of this within the next couple of releases |
| 7 | if( !isset($_GET['sprli']) and isset($_GET['s']) ) |
| 8 | $_GET['sprli'] = $_GET['s']; |
| 9 | |
| 10 | if( $_GET['sprli'] != null and $_GET['sprli'] != '' ) |
| 11 | { |
| 12 | $slug = $_GET['sprli']; |
| 13 | |
| 14 | $click_table = $wpdb->prefix . "prli_clicks"; |
| 15 | $pretty_links_table = $wpdb->prefix . "prli_links"; |
| 16 | |
| 17 | $query = "SELECT * FROM $pretty_links_table WHERE slug='$slug' LIMIT 1"; |
| 18 | $pretty_link = $wpdb->get_row($query); |
| 19 | |
| 20 | $first_click = false; |
| 21 | |
| 22 | $click_ip = $_SERVER['REMOTE_ADDR']; |
| 23 | $click_browser = $_SERVER['HTTP_USER_AGENT']; |
| 24 | |
| 25 | //Set Cookie if it doesn't exist |
| 26 | $cookie_name = 'prli_click_' . $pretty_link->id; |
| 27 | $cookie_expire_time = time()+60*60*24*30; // Expire in 30 days |
| 28 | |
| 29 | if($_COOKIE[$cookie_name] == null) |
| 30 | { |
| 31 | setcookie($cookie_name,$slug,$cookie_expire_time); |
| 32 | $first_click = true; |
| 33 | } |
| 34 | |
| 35 | //Record Click in DB |
| 36 | $insert = "INSERT INTO $click_table (link_id,ip,browser,first_click,created_at) VALUES ($pretty_link->id,'$click_ip','$click_browser','$first_click',NOW())"; |
| 37 | |
| 38 | $results = $wpdb->query( $insert ); |
| 39 | |
| 40 | $param_string = ''; |
| 41 | |
| 42 | if(isset($pretty_link->forward_params) and $pretty_link->forward_params and isset($_GET) and count($_GET) > 1) |
| 43 | { |
| 44 | $first_param = true; |
| 45 | foreach($_GET as $key => $value) |
| 46 | { |
| 47 | // Ignore the 'sprli' parameter |
| 48 | if($key != 'sprli') |
| 49 | { |
| 50 | if($first_param) |
| 51 | { |
| 52 | $param_string = (preg_match("#\?#", $pretty_link->url)?"&":"?"); |
| 53 | $first_param = false; |
| 54 | } |
| 55 | else |
| 56 | $param_string .= "&"; |
| 57 | |
| 58 | $param_string .= "$key=$value"; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | //Redirect to Product URL |
| 64 | if(isset($pretty_link->track_as_img) and $pretty_link->track_as_img) |
| 65 | { |
| 66 | $size = getimagesize($pretty_link->url); |
| 67 | header('Content-Type: '.$size['mime']); |
| 68 | echo file_get_contents($pretty_link->url.$param_string); |
| 69 | } |
| 70 | else |
| 71 | header("Location: $pretty_link->url".$param_string); |
| 72 | } |
| 73 | ?> |
| 74 |