Plugin Directory

Changeset 2268880


Ignore:
Timestamp:
03/27/2020 07:18:22 AM (6 years ago)
Author:
mnmlthms
Message:

new v1.3

Location:
wp-my-instagram
Files:
24 added
6 edited

Legend:

Unmodified
Added
Removed
  • wp-my-instagram/trunk/inc/public/main.php

    r2153183 r2268880  
    128128           
    129129            $output = '';
    130 
    131             $media_array = array();
    132130
    133131            if( self::get_cache( $scrape_key, (int) $args['limit'], $use_hashtag ) ){
  • wp-my-instagram/trunk/js/script.js

    r1694302 r2268880  
    11/**
    2  * WP Social Counter
     2 * wp-my-instagram
    33 * This only run once to reduce page load time.
    44 *
     
    1212    $(document).ready(function(){
    1313
    14         var $blocks = $('.wp-my-instagram.wpmi[data-cached="false"]'),
    15             args = {};
     14        var $blocks = $('.wp-my-instagram.wpmi[data-cached="false"]');
    1615
    17         if( $blocks.length ){
     16        var data_storage = [];
    1817
    19             $blocks.each(function(){
     18        var fetch_data = function( id, args ){
     19
     20            var settings = {
     21                    username: '',
     22                    hashtag: '',
     23                    limit: 6,
     24                    popular: false
     25                };
     26           
     27
     28            $.extend( true, settings, args );
     29
     30
     31            var username = settings.username || false,
     32                hashtag = settings.hashtag || false,
     33                hashtag_popular = settings.popular || false,
     34                base_url = 'https://instagram.com/',
     35                url = base_url + username;
     36
     37
     38            if( !username && !hashtag ){
     39                console.log( 'No hashtag or username provided.');
     40                return;
     41            }
     42
     43            // if use hashtag
     44            if( hashtag ){
     45                url = base_url + 'explore/tags/' + hashtag;
     46            }
     47
     48            $.ajax({
     49                type: 'GET',
     50                url: url,
     51                async: true,
     52                cache: false
     53            }).done( function (data) {
     54                   
     55                if( hashtag ){
     56                    var hashtag_media_key = hashtag_popular ? 'edge_hashtag_to_top_posts' : 'edge_hashtag_to_media';
     57                   
     58                    data = JSON.parse(data.split("window._sharedData = ")[1].split(";<\/script>")[0]).entry_data.TagPage[0].graphql.hashtag[hashtag_media_key].edges;
     59                }else{
     60                    data = JSON.parse(data.split("window._sharedData = ")[1].split(";<\/script>")[0]).entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges;
     61                }
     62
     63                if( data ){
     64                   
     65                    var images = [];
     66
     67                    for (var property in data) {
     68                        var image_data = data[property]['node'];
     69                        var image_args = {};
     70                       
     71                        // thumbnail
     72                        image_args['thumbnail'] = ( ( image_data || {} ).thumbnail_resources[0] || {} ).src || '';
     73
     74                        // xsmall
     75                        image_args['xsmall'] = ( ( image_data || {} ).thumbnail_resources[1] || {} ).src || '';
     76
     77                        // small
     78                        image_args['small'] = ( ( image_data || {} ).thumbnail_resources[2] || {} ).src || '';
     79
     80                        // medium
     81                        image_args['medium'] = ( ( image_data || {} ).thumbnail_resources[3] || {} ).src || '';
     82
     83                        // Large
     84                        image_args['large'] = ( image_data || {} ).thumbnail_src || '';
     85
     86                        // Full
     87                        image_args['original'] = ( image_data || {} ).display_url || '';;
     88
     89                        // link
     90                        image_args['url'] = image_data.shortcode ? '//instagram.com/p/' + image_data.shortcode : '';
     91
     92                        // type
     93                        image_args['type'] = image_data.is_video ? 'video' : 'image';
     94
     95                        // description
     96                        image_args['description'] = (((( image_data || {} ).edge_media_to_caption || {}).edges[0] || {} ).node || {} ).text || '';
     97
     98                        // time
     99                        image_args['time'] = image_data['taken_at_timestamp'] || '';
     100
     101                        // Comments:
     102                        image_args['comments'] = (( image_data || {} ).edge_media_to_comment || {}).count || '';
     103
     104                        // Likes
     105                        image_args['likes'] = image_data['edge_liked_by']['count'] || '';
     106
     107                        // finally push image data to images
     108                        images[images.length] = image_args;
     109
     110                        // Break when reaches the limit
     111                        if( images.length === parseInt(settings.limit) ){
     112                            break;
     113                        }
     114                    }
     115
     116                    if( images.length ){
     117                        $(document.body).trigger( 'wp-my-instagram-load', { id: id, args: settings, images: images } );
     118                    }
     119
     120                }
     121               
     122            });
     123        }
     124
     125        // fetch_data({ username: 'aesthetic', limit: 7, hashtag: 'pixel4', popular: false });
     126        // fetch_data({ username: 'aesthetic', limit: 10, hashtag: '', popular: false });
     127
     128
     129        $(document.body).on( 'wp-my-instagram-load', function( e, data ){
     130
     131            $.ajax({
     132                url: wpMyInstagramVars.ajaxurl,
     133                type: 'POST',
     134                async: true,
     135                cache: false,
     136                // dataType: 'json',
     137                data: {
     138                    action: 'wpmi-request-cache',
     139                    security: wpMyInstagramVars.nonce,
     140                    data: data
     141                }
     142            }).done( function( response ){
     143
     144                if( response && response.data ){
     145                    for (var key in response.data ) {
     146                        var $wmmi = $( '#' + key + '.wp-my-instagram.wpmi' );
     147                        $('.wpmi-list', $wmmi).html( response.data[key] ),
     148                        $wmmi.attr('data-cached', 'true' );
     149                    }
     150
     151                }
     152               
     153            });
     154        });
     155
     156        if( $blocks.length ){
     157
     158            $blocks.each(function( index ){
    20159                var $el = $(this),
    21160                    id = $el.attr('id');
    22161
    23                 args[id] = $el.data('args');
     162                // init data
     163                fetch_data( id, $el.data('args') );
     164
    24165            });
    25 
    26             if( args ){
    27 
    28                 $.ajax({
    29                     url: wpMyInstagramVars.ajaxurl,
    30                     type: 'GET',
    31                     async: true,
    32                     cache: false,
    33                     // dataType: 'json',
    34                     data: {
    35                         action: 'wpmi-init-cache',
    36                         security: wpMyInstagramVars.nonce,
    37                         args: args
    38                     }
    39                 }).done( function( response ){
    40 
    41                     if( response && response.data ){
    42                         for (var key in response.data ) {
    43                             var $wmmi = $( '#' + key + '.wp-my-instagram.wpmi' );
    44                             $('.wpmi-list', $wmmi).html( response.data[key] ),
    45                             $wmmi.attr('data-cached', 'true' );
    46                         }
    47                     }
    48                    
    49                 });
    50             }
    51         }
     166        }
    52167
    53168    });
  • wp-my-instagram/trunk/js/script.min.js

    r1694302 r2268880  
    1 !function(a){"use strict";a(document).ready(function(){var t=a('.wp-my-instagram.wpmi[data-cached="false"]'),n={};t.length&&(t.each(function(){var t=a(this),r=t.attr("id");n[r]=t.data("args")}),n&&a.ajax({url:wpMyInstagramVars.ajaxurl,type:"GET",async:!0,cache:!1,data:{action:"wpmi-init-cache",security:wpMyInstagramVars.nonce,args:n}}).done(function(t){if(t&&t.data)for(var n in t.data){var r=a("#"+n+".wp-my-instagram.wpmi");a(".wpmi-list",r).html(t.data[n]),r.attr("data-cached","true")}}))})}(window.jQuery);
     1!function(c){"use strict";c(document).ready(function(){var a=c('.wp-my-instagram.wpmi[data-cached="false"]');c(document.body).on("wp-my-instagram-load",function(a,e){c.ajax({url:wpMyInstagramVars.ajaxurl,type:"POST",async:!0,cache:!1,data:{action:"wpmi-request-cache",security:wpMyInstagramVars.nonce,data:e}}).done(function(a){if(a&&a.data)for(var e in a.data){var t=c("#"+e+".wp-my-instagram.wpmi");c(".wpmi-list",t).html(a.data[e]),t.attr("data-cached","true")}})}),a.length&&a.each(function(a){var e=c(this);!function(n,a){var o={username:"",hashtag:"",limit:6,popular:!1};c.extend(!0,o,a);var e=o.username||!1,d=o.hashtag||!1,m=o.popular||!1,t="https://instagram.com/",r=t+e;e||d?(d&&(r=t+"explore/tags/"+d),c.ajax({type:"GET",url:r,async:!0,cache:!1}).done(function(a){if(d){var e=m?"edge_hashtag_to_top_posts":"edge_hashtag_to_media";a=JSON.parse(a.split("window._sharedData = ")[1].split(";<\/script>")[0]).entry_data.TagPage[0].graphql.hashtag[e].edges}else a=JSON.parse(a.split("window._sharedData = ")[1].split(";<\/script>")[0]).entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges;if(a){var t=[];for(var r in a){var s=a[r].node,i={};if(i.thumbnail=((s||{}).thumbnail_resources[0]||{}).src||"",i.xsmall=((s||{}).thumbnail_resources[1]||{}).src||"",i.small=((s||{}).thumbnail_resources[2]||{}).src||"",i.medium=((s||{}).thumbnail_resources[3]||{}).src||"",i.large=(s||{}).thumbnail_src||"",i.original=(s||{}).display_url||"",i.url=s.shortcode?"//instagram.com/p/"+s.shortcode:"",i.type=s.is_video?"video":"image",i.description=((((s||{}).edge_media_to_caption||{}).edges[0]||{}).node||{}).text||"",i.time=s.taken_at_timestamp||"",i.comments=((s||{}).edge_media_to_comment||{}).count||"",i.likes=s.edge_liked_by.count||"",t[t.length]=i,t.length===parseInt(o.limit))break}t.length&&c(document.body).trigger("wp-my-instagram-load",{id:n,args:o,images:t})}})):console.log("No hashtag or username provided.")}(e.attr("id"),e.data("args"))})})}(window.jQuery);
  • wp-my-instagram/trunk/langs/wp-my-instagram.pot

    r2153183 r2268880  
    1 # Copyright (C) 2019 WP Instant Feeds
     1# Copyright (C) 2020 WP Instant Feeds
    22# This file is distributed under the same license as the WP Instant Feeds package.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: WP Instant Feeds 1.2.0\n"
     5"Project-Id-Version: WP Instant Feeds 1.3.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-my-instagram\n"
    7 "POT-Creation-Date: 2019-09-08 22:02:19+00:00\n"
     7"POT-Creation-Date: 2020-03-27 07:14:58+00:00\n"
    88"MIME-Version: 1.0\n"
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
     11"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n"
    1212"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1313"Language-Team: LANGUAGE <LL@li.org>\n"
     
    1717msgstr ""
    1818
    19 #: inc/public/main.php:222
     19#: inc/public/main.php:220
    2020msgid "Unable to communicate with Instagram."
    2121msgstr ""
    2222
    23 #: inc/public/main.php:225
     23#: inc/public/main.php:223
    2424msgid "Instagram did not return a 200."
    2525msgstr ""
    2626
    27 #: inc/public/main.php:233 inc/public/main.php:256 inc/public/main.php:260
     27#: inc/public/main.php:231 inc/public/main.php:254 inc/public/main.php:258
    2828msgid "Instagram has returned invalid data."
    2929msgstr ""
    3030
    31 #: inc/public/main.php:373
     31#: inc/public/main.php:371
    3232msgid "Instagram did not return any images."
    3333msgstr ""
    3434
    35 #: inc/public/main.php:384
     35#: inc/public/main.php:382
    3636msgid "This param must be array."
    3737msgstr ""
  • wp-my-instagram/trunk/readme.txt

    r2153183 r2268880  
    55Requires at least: 3.9
    66Tested up to: 5.2.3
    7 Stable tag: 1.2.0
     7Stable tag: 1.3.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6464
    6565== Changelog ==
     66
     67= 1.3.0 - Mar 26 2020 =
     68* Better feed getter ;)
    6669
    6770= 1.2.0 - SEP 8 2019 =
  • wp-my-instagram/trunk/wp-my-instagram.php

    r2153183 r2268880  
    44Plugin URI: https://wordpress.org/plugins/wp-my-instagram
    55Description: Display Instagram feeds on your site from your Instagram account
    6 Version: 1.2.0
     6Version: 1.3.0
    77Author: mnmlthms
    88Author URI: http://mnmlthms.com
     
    2929if ( ! defined( 'ABSPATH' ) ) exit;
    3030
    31 define( 'WP_MY_INSTAGRAM_VERSION', '1.2.0' );
     31define( 'WP_MY_INSTAGRAM_VERSION', '1.3.0' );
    3232define( 'WP_MY_INSTAGRAM_OPTION', 'wp_my_instagram' );
    3333
     
    9797            add_action( 'wp_ajax_nopriv_wpmi-init-cache', array( $this, 'ajax_load_cache') );
    9898
     99            add_action( 'wp_ajax_wpmi-request-cache', array( $this, 'ajax_load_cache_js') );
     100            add_action( 'wp_ajax_nopriv_wpmi-request-cache', array( $this, 'ajax_load_cache_js') );
     101
     102
    99103        }
    100104
     
    120124                'ajaxurl'   => admin_url( 'admin-ajax.php' )
    121125            ) );
     126        }
     127
     128        public function ajax_load_cache_js(){
     129
     130            $nonce_key = 'wpmi-init-cache-nonce';
     131
     132            check_ajax_referer( $nonce_key, 'security' );
     133
     134            $response = array(
     135                'success' => true
     136            );
     137
     138            $data = $_REQUEST['data'];
     139
     140            $output = array();
     141
     142            if( !class_exists( 'WP_My_Instagram_Main' ) ){
     143
     144                require_once( 'inc/public/main.php' );
     145               
     146            }
     147
     148            if( !empty( $data['images'] ) ){
     149                $scrape_key = !empty( $data['args']['hashtag'] ) ? $data['args']['hashtag'] : $data['args']['username'];
     150                $scrape_key = strtolower( $scrape_key );
     151                $scrape_key = str_replace( '@', '', $scrape_key );
     152                $scrape_key = trim( $scrape_key );
     153                $scrape_key = !empty( $data['args']['hashtag'] ) ? $data['args']['hashtag'] : $data['args']['username'];
     154
     155                $cache_name = WP_My_Instagram_Main::get_cache_name( $scrape_key, $data['args']['limit'], (boolean) $data['args']['hashtag'] );
     156                $cache_time = apply_filters( 'wpmi_cache_time', HOUR_IN_SECONDS*2 );
     157
     158                // do not set an empty transient - should help catch private or empty accounts
     159                if ( ! empty( $data['images'] ) ) {
     160                    set_transient( $cache_name, base64_encode( serialize( $data['images'] ) ), $cache_time );
     161                }
     162
     163                ob_start();
     164                // cache
     165                WP_My_Instagram_Main::make_items( $data['images'], $data['args'] );
     166                $items = ob_get_clean();
     167                $output[$data['id']] = $items;
     168
     169                $response['data'] = $output;
     170            }else{
     171                $response['success'] = false;
     172                $response['data'] = esc_html( 'Something went wrong! Please try again' );
     173            }
     174
     175            wp_send_json( $response );
     176
     177            wp_die(1);
    122178        }
    123179        /**
Note: See TracChangeset for help on using the changeset viewer.