Skip to content

Commit

Permalink
Foursquare: Respect off-the-grid check-ins
Browse files Browse the repository at this point in the history
Mark them as Private posts, and mark their geodata as non-public
Fixes #15
  • Loading branch information
Beau Lebens committed Mar 18, 2018
1 parent 916aad7 commit c8a4aaa
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions importers/keyring-importer-foursquare.php
Expand Up @@ -173,17 +173,22 @@ function extract_posts_from_data( $raw ) {
$post_content .= "\n\n<blockquote class='foursquare-note'>" . $post->shout . "</blockquote>";
}

// Include geo Data
// Include geo Data. Note if it was an "off the grid" check-in
$geo = array(
'lat' => $post->venue->location->lat,
'long' => $post->venue->location->lng,
);
if ( ! empty( $post->private ) && 1 == $post->private ) {
$geo['public'] = 0;
} else {
$geo['public'] = 1;
}

// Pull out any media/photos
$photos = array();
if ( $post->photos->count > 0 ) {
foreach ( $post->photos->items as $photo ) {
$photos[] = $photo->prefix . "original" . $photo->suffix;
$photos[] = $photo->prefix . 'original' . $photo->suffix;
}
}

Expand Down Expand Up @@ -267,6 +272,11 @@ function insert_posts() {
// Looks like a duplicate
$skipped++;
} else {
// Set this as a private post, because it was "off the grid"
if ( 0 === $geo['public'] ) {
$post['post_status'] = 'private';
}

$post_id = wp_insert_post( $post );

if ( is_wp_error( $post_id ) ) {
Expand Down Expand Up @@ -296,9 +306,9 @@ function insert_posts() {

// Store geodata if it's available
if ( ! empty( $geo ) ) {
add_post_meta( $post_id, 'geo_latitude', $geo['lat'] );
add_post_meta( $post_id, 'geo_latitude', $geo['lat'] );
add_post_meta( $post_id, 'geo_longitude', $geo['long'] );
add_post_meta( $post_id, 'geo_public', 1 );
add_post_meta( $post_id, 'geo_public', $geo['public'] );
}

add_post_meta( $post_id, 'raw_import_data', wp_slash( json_encode( $foursquare_raw ) ) );
Expand Down

0 comments on commit c8a4aaa

Please sign in to comment.