function bp_checkins_fs_logs()
{
    global $wpdb;
    $limit = 20;
    if (isset($_GET['paged'])) {
        $paged = $_GET['paged'];
    } else {
        $paged = 1;
    }
    $offset = $limit * ($paged - 1);
    $logs = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->base_prefix}bp_checkins_foursquare_logs ORDER BY id DESC LIMIT %d,%d", $offset, $limit));
    $total_logs = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->base_prefix}bp_checkins_foursquare_logs");
    $all_count = $total_logs;
    $max_pages = ceil($all_count / $limit);
    $timestamp = wp_next_scheduled('bp_checkins_cron_job');
    ?>
	<div class="wrap">
		<h2><?php 
    _e('BP Checkins : foursquare import logs', 'bp-checkins');
    ?>
</h2>
		<p class="description"><?php 
    printf(__('Next run for cron job : %s', 'bp-checkins'), bp_checkins_date($timestamp));
    ?>
</p>
		<div style="margin-top:1em">
			<table class="widefat fixed"> 
		    	<thead> 
		         	<tr> 
		            	<th scope="col"><?php 
    _e('User id', 'bp-checkins');
    ?>
</th> 
		            	<th scope="col"><?php 
    _e('Log type', 'bp-checkins');
    ?>
</th> 
		             	<th scope="col"><?php 
    _e('Log info', 'bp-checkins');
    ?>
</th> 
		          	</tr> 
		       	</thead> 
		       	<tbody> 
		        	<?php 
    foreach ($logs as $log) {
        ?>
						
						<tr><td><?php 
        echo $log->user_id;
        ?>
</td><td><?php 
        echo $log->type;
        ?>
</td><td><?php 
        echo $log->log;
        ?>
</td></tr>
		                 
					<?php 
    }
    ?>
		      	</tbody> 
		  	</table>
		</div>
		
		<div class="tablenav">
		   <?php 
    $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'total' => $max_pages, 'current' => $paged));
    ?>

		<?php 
    if ($page_links) {
        ?>
			<div class="tablenav-pages"><?php 
        $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s', number_format_i18n($offset + 1), number_format_i18n($offset + count($logs)), number_format_i18n($all_count), $page_links);
        echo $page_links_text . "</div>";
        ?>

		<?php 
    }
    ?>
		
	</div>
	<?php 
}
 function save_activity($foursquare_url = false, $user_id = false, $user_latest = 0)
 {
     if (empty($foursquare_url)) {
         return array('user_id' => $user_id, 'time' => date('Y-m-d H:i:s'), 'info' => __('No foursquare url were given', 'bp-checkins'), 'code' => 1);
     }
     $foursquare_api_request = new WP_Http();
     $foursquare_result = $foursquare_api_request->request($foursquare_url, array('sslverify' => false));
     if (!$foursquare_result || !empty($foursquare_result->errors)) {
         return array('user_id' => $user_id, 'time' => date('Y-m-d H:i:s'), 'info' => __('foursquare not responding', 'bp-checkins'), 'code' => 2);
     } else {
         $foursquare_parse_user_stream = $foursquare_result['body'];
         $foursquare_user_stream = json_decode($foursquare_parse_user_stream);
         if (!empty($foursquare_user_stream->meta->code) && !empty($foursquare_user_stream->meta->errorDetail)) {
             delete_user_meta($user_id, 'foursquare_token');
             return array('user_id' => $user_id, 'time' => date('Y-m-d H:i:s'), 'info' => __('user revoked his auth, meta deleted', 'bp-checkins'), 'code' => 3);
         } else {
             $user_checkins = $foursquare_user_stream->response->checkins->items;
             if (!$user_checkins || empty($user_checkins) || count($user_checkins) < 1) {
                 return array('user_id' => $user_id, 'time' => date('Y-m-d H:i:s'), 'info' => __('no new checkins', 'bp-checkins'), 'code' => 4);
             } else {
                 $from_user_link = bp_core_get_userlink($user_id);
                 $checkin_action = sprintf(__('%s added a <span class="foursquare-checkin">foursquare</span> checkin', 'bp-checkins'), $from_user_link);
                 $primary_link = bp_core_get_userlink($user_id, false, true);
                 $timestamp_latest = $user_latest;
                 $checkins_imported = 0;
                 foreach ($user_checkins as $checkin) {
                     if ($checkin->createdAt > $timestamp_latest) {
                         $timestamp_latest = $checkin->createdAt;
                     }
                     $foursquare_activity_args = array();
                     $foursquare_activity_meta_args = array();
                     $foursquare_activity_meta_args = array('bpci_activity_lat' => $checkin->venue->location->lat, 'bpci_activity_lng' => $checkin->venue->location->lng, 'bpci_activity_address' => $checkin->venue->name . ' (' . $checkin->venue->location->country . ')');
                     if ($checkin->photos->count > 0) {
                         $foursquare_activity_meta_args['bpci_picture'] = $checkin->photos->items[0]->sizes->items;
                     }
                     $foursquare_activity_args = array('user_id' => $user_id, 'action' => $checkin_action, 'content' => $checkin->shout, 'primary_link' => $primary_link, 'component' => 'checkins', 'type' => 'foursquare_checkin', 'secondary_item_id' => $checkin->id, 'recorded_time' => bp_checkins_date($checkin->createdAt), 'bp_checkins_meta' => $foursquare_activity_meta_args);
                     $checkins_imported += bp_checkins_post_foursquare_updates($foursquare_activity_args);
                 }
                 if (update_user_meta($user_id, 'foursquare_latest_timestamp', $timestamp_latest + 1)) {
                     return array('user_id' => $user_id, 'time' => date('Y-m-d H:i:s'), 'info' => sprintf(__('%d checkins imported', 'bp-checkins'), $checkins_imported), 'code' => 5);
                 }
             }
         }
     }
 }