<div id="user_image" title="<?php 
_e('Source', 'mymail');
?>
: Gravatar.com" data-email="<?php 
echo $post->post_title;
?>
" style="background-image:url(<?php 
echo $this->get_gravatar_uri($post->post_title);
?>
)"></div>
<?php 
if (mymail_option('track_users') && !empty($this->user_data['_meta']['ip'])) {
    $meta = $this->user_data['_meta'];
    $city = $country = '';
    if (mymail_option('trackcities')) {
        $city = mymail_ip2City($meta['ip']);
    }
    if (mymail_option('trackcountries')) {
        $country = mymail_ip2Country($meta['ip'], 'name');
    }
    ?>
<div id="user_location">
	<p>
		<?php 
    if (isset($city->city)) {
        echo '<a target="_blank" href="http://maps.google.com/maps?q=' . $city->latitude . ',' . $city->longitude . '">' . $city->city . '</a>, ';
    }
    if ($country != 'unknown') {
        echo $country;
    }
    ?>
    ?>
<br>&nbsp;&nbsp;<strong><?php 
    _e('Last update', 'mymail');
    ?>
: <?php 
    echo date(get_option('date_format') . ' ' . get_option('time_format'), get_option('mymail_countries') + get_option('gmt_offset') * 3600);
    ?>
 </strong><br>
		<?php 
    if ($geoipcity && is_file(mymail_option('cities_db'))) {
        ?>
			<strong><?php 
        _e('Your city', 'mymail');
        ?>
:</strong> <?php 
        echo mymail_ip2City('', 'city');
        ?>
<br>&nbsp;&nbsp;<strong><?php 
        _e('Last update', 'mymail');
        ?>
:<?php 
        echo date(get_option('date_format') . ' ' . get_option('time_format'), get_option('mymail_cities') + get_option('gmt_offset') * 3600);
        ?>
</strong>
		<?php 
    }
    ?>
			<p class="description">This product includes GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a></p>
			</td>
		</tr>
		<?php 
 public function handleReferrer()
 {
     //user preg_replace to remove unwanted whitespaces
     $target = isset($_REQUEST['t']) ? preg_replace('/\\s+/', '', $_REQUEST['t']) : NULL;
     $hash = isset($_REQUEST['k']) ? preg_replace('/\\s+/', '', $_REQUEST['k']) : NULL;
     $count = isset($_REQUEST['c']) ? intval($_REQUEST['c']) : NULL;
     $campaign_id = intval($_REQUEST['mymail']);
     if (!$campaign_id) {
         return;
     }
     //get user information
     $user = new WP_query(array('post_type' => 'subscriber', 'name' => $hash, 'posts_per_page' => 1));
     //user exists
     if ($user->post) {
         wp_cache_delete($user->post->ID, 'post' . '_meta');
         $user_campaign_data = get_post_meta($user->post->ID, 'mymail-campaigns', true);
         //update latest IP address
         if (mymail_option('track_users')) {
             $user_data = get_post_meta($user->post->ID, 'mymail-userdata', true);
             $user_data['_meta']['ip'] = mymail_get_ip();
         }
         //user has recieved this campaign
         if (isset($user_campaign_data[$campaign_id])) {
             //register clicks for campaign
             wp_cache_delete($campaign_id, 'post' . '_meta');
             $campaign_data = get_post_meta($campaign_id, 'mymail-campaign', true);
             $is_autoresponder = 'autoresponder' == get_post_status($campaign_id);
             //if users is here it must be openend
             if (!isset($user_campaign_data[$campaign_id]['open'])) {
                 $campaign_data['opens']++;
                 $user_campaign_data[$campaign_id]['open'] = current_time('timestamp');
                 //save user country
                 $country = mymail_ip2Country();
                 if (!isset($campaign_data['countries'][$country])) {
                     $campaign_data['countries'][$country] = 0;
                 }
                 $campaign_data['countries'][$country]++;
                 if (mymail_option('trackcities')) {
                     //save user city
                     $city = mymail_ip2City();
                     if ($city == 'unknown') {
                         $city = (object) array('country_code' => '', 'city' => '');
                     }
                     if (empty($city->country_code)) {
                         $city->country_code = $country;
                     }
                     if (empty($city->country_code)) {
                         $city->country_code = 'unknown';
                     }
                     if (!empty($city->country_code)) {
                         if (!isset($campaign_data['cities'][$city->country_code])) {
                             $campaign_data['cities'][$city->country_code] = array();
                         }
                         if (empty($city->city)) {
                             $city->city = 'unknown';
                             $city->latitude = 0;
                             $city->longitude = 0;
                         }
                         if (!isset($campaign_data['cities'][$city->country_code][$city->city])) {
                             $campaign_data['cities'][$city->country_code][$city->city] = array('lat' => $city->latitude, 'lng' => $city->longitude, 'opens' => 0);
                         }
                         $campaign_data['cities'][$city->country_code][$city->city]['opens']++;
                     }
                 }
             }
             $redirect_to = false;
             //target => link clicked
             if ($target) {
                 //unsubscribe ?
                 if (strpos($target, 'unsubscribe=' . md5($campaign_id . '_unsubscribe'))) {
                     $unsubscribe = true;
                     //change target for tracking
                     $target = add_query_arg('unsubscribe', '', html_entity_decode($target));
                 }
                 $redirect_to = html_entity_decode($target);
                 $target = apply_filters('mymail_click_target', $target, $campaign_id);
                 //if users first click
                 if (!isset($user_campaign_data[$campaign_id]['clicks'])) {
                     //increase unique clicks
                     $campaign_data['totaluniqueclicks']++;
                     $user_campaign_data[$campaign_id]['firstclick'] = current_time('timestamp');
                     global $mymail_subscriber;
                     $mymail_subscriber->add_new('click');
                 }
                 //increase target clicks
                 if (!isset($campaign_data['clicks'][$target])) {
                     $campaign_data['clicks'][$target] = array();
                 }
                 if (!isset($campaign_data['clicks'][$target][$count])) {
                     $campaign_data['clicks'][$target][$count] = 0;
                 }
                 $campaign_data['clicks'][$target][$count]++;
                 //increase total clicks
                 $campaign_data['totalclicks']++;
                 //register user click
                 if (!isset($user_campaign_data[$campaign_id]['totalclicks'])) {
                     $user_campaign_data[$campaign_id]['totalclicks'] = 0;
                 }
                 $user_campaign_data[$campaign_id]['totalclicks']++;
                 //increase target clicks
                 if (!isset($user_campaign_data[$campaign_id]['clicks'][$target])) {
                     $user_campaign_data[$campaign_id]['clicks'][$target] = 0;
                     //increase unique clicks
                     if (!isset($user_campaign_data[$campaign_id]['totaluniqueclicks'])) {
                         $user_campaign_data[$campaign_id]['totaluniqueclicks'] = 0;
                     }
                     $user_campaign_data[$campaign_id]['totaluniqueclicks']++;
                 }
                 $user_campaign_data[$campaign_id]['clicks'][$target]++;
             }
             //save
             $this->post_meta($user->post->ID, 'mymail-campaigns', $user_campaign_data);
             if (isset($user_data)) {
                 $this->post_meta($user->post->ID, 'mymail-userdata', $user_data);
             }
             $this->post_meta($campaign_id, 'mymail-campaign', $campaign_data);
         }
     }
     //no target => tracking image
     if (!$redirect_to) {
         header('Content-type: image/gif');
         # The transparent, beacon image
         echo chr(71) . chr(73) . chr(70) . chr(56) . chr(57) . chr(97) . chr(1) . chr(0) . chr(1) . chr(0) . chr(128) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(33) . chr(249) . chr(4) . chr(1) . chr(0) . chr(0) . chr(0) . chr(0) . chr(44) . chr(0) . chr(0) . chr(0) . chr(0) . chr(1) . chr(0) . chr(1) . chr(0) . chr(0) . chr(2) . chr(2) . chr(68) . chr(1) . chr(0) . chr(59);
         die;
     } else {
         //redirect in any case
         isset($unsubscribe) && $unsubscribe ? wp_redirect(mymail_option('homepage') ? add_query_arg(array('k' => $campaign_id, 'unsubscribe' => $hash), get_permalink(mymail_option('homepage'))) : get_bloginfo('url')) : wp_redirect($redirect_to, 301);
         exit;
     }
 }