Browse Source

include published date for Instagram photos

if the photo has a location, the timezone is set on the published date
pull/39/head
Aaron Parecki 4 years ago
parent
commit
db8dba9f23
5 changed files with 22704 additions and 2 deletions
  1. +3
    -1
      README.md
  2. +1
    -0
      composer.json
  3. +17
    -1
      lib/Formats/Instagram.php
  4. +22680
    -0
      lib/Timezone.php
  5. +3
    -0
      tests/ParseTest.php

+ 3
- 1
README.md View File

@ -6,7 +6,9 @@ XRay
The contents of the URL is checked in the following order:
* A supported silo URL (coming soon)
* A silo URL from one of the following websites:
** Instagram
** (more coming soon)
* h-entry, h-event, h-card
* OEmbed (coming soon)
* OGP (coming soon)

+ 1
- 0
composer.json View File

@ -13,6 +13,7 @@
"controllers/Main.php",
"controllers/Parse.php",
"controllers/Token.php",
"lib/Timezone.php",
"lib/HTTPCurl.php",
"lib/HTTPStream.php",
"lib/HTTP.php",

+ 17
- 1
lib/Formats/Instagram.php View File

@ -2,6 +2,7 @@
namespace XRay\Formats;
use DOMDocument, DOMXPath;
use DateTime, DateTimeZone;
use Parse;
class Instagram {
@ -25,11 +26,14 @@ class Instagram {
]
);
$profiles = [];
// Fetch profile info for this user
$username = $photoData['owner']['username'];
$profile = self::_getInstagramProfile($username, $http);
if($profile) {
$entry['author'] = self::_buildHCardFromInstagramProfile($profile);
$profiles[] = $profile;
}
// Content and hashtags
@ -55,7 +59,6 @@ class Instagram {
}
$refs = [];
$profiles = [];
// Find person tags and fetch user profiles
if(array_key_exists('usertags', $photoData) && $photoData['usertags']['nodes']) {
@ -72,6 +75,9 @@ class Instagram {
}
}
// Published date
$published = DateTime::createFromFormat('U', $photoData['date']);
// Include venue data
$locations = [];
if($photoData['location']) {
@ -80,9 +86,19 @@ class Instagram {
$entry['location'] = [$location['url']];
$refs[$location['url']] = $location;
$locations[] = $location;
// Look up timezone
if($location['latitude']) {
$tz = \p3k\Timezone::timezone_for_location($location['latitude'], $location['longitude']);
if($tz) {
$published->setTimeZone(new DateTimeZone($tz));
}
}
}
}
$entry['published'] = $published->format('c');
$response = [
'data' => $entry
];

+ 22680
- 0
lib/Timezone.php
File diff suppressed because it is too large
View File


+ 3
- 0
tests/ParseTest.php View File

@ -392,6 +392,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('2017-01-05T23:31:32+00:00', $data['data']['published']);
$this->assertContains('planning', $data['data']['category']);
$this->assertContains('2017', $data['data']['category']);
$this->assertEquals('Kind of crazy to see the whole year laid out like this. #planning #2017', $data['data']['content']['text']);
@ -451,6 +452,8 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('XOXO Outpost', $venue['name']);
$this->assertEquals('45.5261002', $venue['latitude']);
$this->assertEquals('-122.6558081', $venue['longitude']);
// Setting a venue should set the timezone
$this->assertEquals('2016-12-10T21:48:56-08:00', $data['data']['published']);
}
}

Loading…
Cancel
Save