Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #82 from scottsweb/81-json-changes
Browse files Browse the repository at this point in the history
More JSON changes - this time for usernames
  • Loading branch information
scottsweb committed Jan 11, 2018
2 parents da04cc8 + fbb7729 commit 2f79a91
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ In version 1.9.6 you can now use a filter to change the location of your custom

## Changelog

#### 2.0.2
* Use image sizes from JSON due to errors loading images

#### 2.0.1
* Fix hashtag support

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: scottsweb, codeforthepeople
Tags: instagram, widget, photos, photography, hipster, sidebar, widgets, simple
Requires at least: 4.4
Tested up to: 4.9.1
Stable tag: 2.0.1
Stable tag: 2.0.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -80,6 +80,9 @@ In version 1.9.6 you can now use a filter to change the location of your custom

== Changelog ==

= 2.0.2 =
* Use image sizes from JSON due to errors loading images

= 2.0.1 =
* Fix hashtag support

Expand Down
37 changes: 10 additions & 27 deletions wp-instagram-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: WP Instagram Widget
Plugin URI: https://github.com/scottsweb/wp-instagram-widget
Description: A WordPress widget for showing your latest Instagram photos.
Version: 2.0.1
Version: 2.0.2
Author: Scott Evans
Author URI: https://scott.ee
Text Domain: wp-instagram-widget
Expand Down Expand Up @@ -188,7 +188,7 @@ function scrape_instagram( $username ) {

$username = trim( strtolower( $username ) );

if ( false === ( $instagram = get_transient( 'instagram-a8-' . sanitize_title_with_dashes( $username ) ) ) ) {
if ( false === ( $instagram = get_transient( 'instagram-a9-' . sanitize_title_with_dashes( $username ) ) ) ) {

switch ( substr( $username, 0, 1 ) ) {
case '#':
Expand Down Expand Up @@ -233,7 +233,8 @@ function scrape_instagram( $username ) {
$instagram = array();

foreach ( $images as $image ) {
// the hashtag json is now completely different
// Note: keep hashtag support different until these JSON changes stabalise
// these are mostly the same again now
switch ( substr( $username, 0, 1 ) ) {
case '#':
if ( true === $image['node']['is_video'] ) {
Expand All @@ -253,32 +254,14 @@ function scrape_instagram( $username ) {
'time' => $image['node']['taken_at_timestamp'],
'comments' => $image['node']['edge_media_to_comment']['count'],
'likes' => $image['node']['edge_liked_by']['count'],
'thumbnail' => str_replace( 's150x150', 's160x160', preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][0]['src'] ) ),
'thumbnail' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][0]['src'] ),
'small' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][2]['src'] ),
'large' => preg_replace( '/^https?\:/i', '', $image['node']['thumbnail_resources'][4]['src'] ),
'original' => preg_replace( '/^https?\:/i', '', $image['node']['display_url'] ),
'type' => $type,
);
break;
default:
$image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['thumbnail_src'] );
$image['display_src'] = preg_replace( '/^https?\:/i', '', $image['display_src'] );

// handle both types of CDN url.
if ( ( strpos( $image['thumbnail_src'], 's640x640' ) !== false ) ) {
$image['thumbnail'] = str_replace( 's640x640', 's160x160', $image['thumbnail_src'] );
$image['small'] = str_replace( 's640x640', 's320x320', $image['thumbnail_src'] );
} else {
$urlparts = wp_parse_url( $image['thumbnail_src'] );
$pathparts = explode( '/', $urlparts['path'] );
array_splice( $pathparts, 3, 0, array( 's160x160' ) );
$image['thumbnail'] = '//' . $urlparts['host'] . implode( '/', $pathparts );
$pathparts[3] = 's320x320';
$image['small'] = '//' . $urlparts['host'] . implode( '/', $pathparts );
}

$image['large'] = $image['thumbnail_src'];

if ( true === $image['is_video'] ) {
$type = 'video';
} else {
Expand All @@ -296,10 +279,10 @@ function scrape_instagram( $username ) {
'time' => $image['date'],
'comments' => $image['comments']['count'],
'likes' => $image['likes']['count'],
'thumbnail' => $image['thumbnail'],
'small' => $image['small'],
'large' => $image['large'],
'original' => $image['display_src'],
'thumbnail' => preg_replace( '/^https?\:/i', '', $image['thumbnail_resources'][0]['src'] ),
'small' => preg_replace( '/^https?\:/i', '', $image['thumbnail_resources'][2]['src'] ),
'large' => preg_replace( '/^https?\:/i', '', $image['thumbnail_resources'][4]['src'] ),
'original' => preg_replace( '/^https?\:/i', '', $image['display_src'] ),
'type' => $type,
);

Expand All @@ -310,7 +293,7 @@ function scrape_instagram( $username ) {
// do not set an empty transient - should help catch private or empty accounts.
if ( ! empty( $instagram ) ) {
$instagram = base64_encode( serialize( $instagram ) );
set_transient( 'instagram-a8-' . sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS * 2 ) );
set_transient( 'instagram-a9-' . sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS * 2 ) );
}
}

Expand Down

0 comments on commit 2f79a91

Please sign in to comment.