diff --git a/readme.md b/readme.md index a9fdc2d..fd13822 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/readme.txt b/readme.txt index 7289f2d..930b7f8 100755 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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 diff --git a/wp-instagram-widget.php b/wp-instagram-widget.php index 0cb7c90..6989329 100644 --- a/wp-instagram-widget.php +++ b/wp-instagram-widget.php @@ -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 @@ -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 '#': @@ -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'] ) { @@ -253,7 +254,7 @@ 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'] ), @@ -261,24 +262,6 @@ function scrape_instagram( $username ) { ); 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 { @@ -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, ); @@ -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 ) ); } }