Plugin Directory

Changeset 2193464


Ignore:
Timestamp:
11/15/2019 07:35:54 AM (6 years ago)
Author:
webcraftic
Message:

Add a notification when authorizing an Instagram account

Location:
instagram-slider-widget/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • instagram-slider-widget/trunk/admin/assets/css/jr-insta-admin.css

    r2188238 r2193464  
    8585    box-shadow: inset 0 0 0 rgba(0, 0, 0, 0.00) !important;
    8686}
     87.wis-help-text
     88{
     89    font-size: 16px;
     90    margin: 10px 0px 0px 10px;
     91}
     92.wis-help-text p
     93{
     94    font-size: 14px;
     95}
     96
    8797i.wis-shortcode-icon
    8898{
  • instagram-slider-widget/trunk/admin/pages/settings.php

    r2188238 r2193464  
    134134    }
    135135
    136     /**
    137      * Returns options for the Basic Settings screen.
    138      *
    139      * @since 1.0.0
    140      * @return array
    141      */
    142     public function getOptions() {
    143 
    144         $options = [];
    145 
    146         $options[] = [
    147             'type' => 'html',
    148             'html' => '<h3 style="margin-left:0">'.__('General','instagram-slider-widget').'</h3>'
    149         ];
    150 
    151         $options[] = [
    152             'type' => 'separator'
    153         ];
    154 
    155         $options[] = [
    156             'type'    => 'textbox',
    157             'name'    => 'insta_username',
    158             'title'   => __( 'Instagram account', 'instagram-slider-widget' ),
    159             'default' => '',
    160             'hint'    => __( 'Username of your Instagram account', 'instagram-slider-widget' )
    161         ];
    162 
    163         $options[] = [
    164             'type'    => 'textbox',
    165             'name'    => 'insta_password',
    166             'title'   => __( 'Instagram password', 'instagram-slider-widget' ),
    167             'default' => '',
    168             'hint'    => __( 'Password of your Instagram account', 'instagram-slider-widget' )
    169         ];
    170         //JS for set password type of textbox
    171         $options[] = [
    172             'type' => 'html',
    173             'html' => "<script>document.getElementById('{$this->plugin->getPrefix()}insta_password').setAttribute('type', 'password')</script>"
    174         ];
    175 
    176         return $options;
    177     }
    178 
    179136    public function indexAction() {
    180137
     
    201158        </script>
    202159        <?php
    203         // creating a form
    204         global $form;
    205         $form = new Wbcr_FactoryForms420_Form( [
    206             'scope' => substr( $this->plugin->getPrefix(), 0, - 1 ),
    207             'name'  => 'setting'
    208         ], $this->plugin );
    209 
    210         $form->setProvider( new Wbcr_FactoryForms420_OptionsValueProvider( $this->plugin ) );
    211 
    212         $form->add( $this->getOptions() );
    213 
    214         $wis_saved = WIS_Plugin::app()->request->post( $this->plugin->getPrefix() . 'saved', '' );
    215         if ( ! empty( $wis_saved ) ) {
    216             $wis_nonce = WIS_Plugin::app()->request->post( $this->plugin->getPrefix() . 'nonce', '' );
    217             if ( ! wp_verify_nonce( $wis_nonce, $this->plugin->getPrefix() . 'settings_form' ) ) {
    218                 wp_die( 'Permission error. You can not edit this page.' );
    219             }
    220             $form->save();
    221 
    222             do_action( 'wis/settings/after_form_save' );
    223         }
    224160        parent::indexAction();
    225161    }
  • instagram-slider-widget/trunk/admin/views/tab-license.php

    r2188238 r2193464  
    2020                               class="purchase-premium" target="_blank" rel="noopener">
    2121                            <span class="btn btn-gold btn-inner-wrap">
    22                             <?php printf( __( 'Upgrade to Premium for $%s', 'instagram-slider-widget' ), $this->premium->get_price() ) ?>
     22                            <?php printf( __( 'Upgrade to Premium', 'instagram-slider-widget' ), $this->premium->get_price() ) ?>
    2323                            </span>
    2424                            </a>
  • instagram-slider-widget/trunk/admin/views/tab-settings.php

    r2188238 r2193464  
    66    "redirect_uri"  => "http://instagram.cm-wp.com/?state=" . admin_url( 'admin.php?page=settings-' . WIS_Plugin::app()->getPluginName() ),
    77    "response_type" => "token",
     8    "scope" => "basic",
    89    //"hl" => "en"
    910];
    10 $autorize_url = "https://api.instagram.com/oauth/authorize/?" . http_build_query( $args );
     11$autorize_url = "https://instagram.com/oauth/authorize/?" . http_build_query( $args );
    1112
    1213?>
     
    1718            <div class="col-md-9">
    1819                <div class="row">
    19                     <div class="col-md-12">
     20                    <div class="col-md-12 wis-help-text">
    2021                        <p><?php
    2122                            echo __( 'Without authorization Instagram limits the number of requests, and after exceeding the limit asks to log in, so an error is displayed that no images were found.', 'instagram-slider-widget' ); ?>
     
    3839                            <span style="float: none; margin-top: 0;" class="spinner" id="wis-spinner"> </span>
    3940                        </div>
     41                        <div class="wis-help-text"><?php echo sprintf( __( "After adding an account, go to the <a href='%s'>widget settings</a> and change the \"Search Instagram for\" setting to Account", 'instagram-slider-widget' ), admin_url('widgets.php')) ?></div>
    4042                        <?php
    4143                        if ( count( $accounts ) ) : ?>
  • instagram-slider-widget/trunk/includes/class-wis_instagram_slider.php

    r2189602 r2193464  
    107107
    108108        wp_enqueue_style(  WIS_Plugin::app()->getPrefix() . 'instag-slider', WIS_PLUGIN_URL.'/assets/css/instag-slider.css', array(), WIS_Plugin::app()->getPluginVersion() );
    109         wp_enqueue_script( WIS_Plugin::app()->getPrefix() . 'jquery-pllexi-slider', WIS_PLUGIN_URL.'/assets/js/jquery.flexslider-min.js', array( 'jquery' ), WIS_Plugin::app()->getPluginVersion(), true );
     109        wp_enqueue_script( WIS_Plugin::app()->getPrefix() . 'jquery-pllexi-slider', WIS_PLUGIN_URL.'/assets/js/jquery.flexslider-min.js', array( 'jquery' ), WIS_Plugin::app()->getPluginVersion(), false );
    110110        wp_enqueue_style(  WIS_Plugin::app()->getPrefix() . 'wis-header', WIS_PLUGIN_URL.'/assets/css/wis-header.css', array(), WIS_Plugin::app()->getPluginVersion() );
    111111    }
     
    200200
    201201        $accounts = WIS_Plugin::app()->getOption( 'account_profiles');
     202        if(!is_array($accounts)) $accounts = array();
    202203        $sliders = $this->sliders;
    203204
     
    732733            $instagram_images = new WP_Query( $query_args );
    733734
    734             if ( $instagram_images->have_posts() ) {
     735            //if ( $instagram_images->have_posts() ) {
     736            if ( false ) {
    735737
    736738                $output = $slider_script . $images_div . $images_ul;
     
    10731075    }
    10741076
     1077    /**
     1078     * Get data from instagram by username
     1079     * @param  string    $username
     1080     * @return array
     1081     */
     1082    private function get_data_by_username( $username ) {
     1083
     1084        $url = str_replace( '{username}', urlencode( trim( $username ) ), self::USERNAME_URL );
     1085        $response = wp_remote_get( $url, array( 'sslverify' => false, 'timeout' => 60 ) );
     1086
     1087        if(strstr( $response['body'], '-cx-PRIVATE-Page__main' )) {
     1088            return ['error' => __( 'Account not found or for this account there are restrictions on Instagram by age', 'instagram-slider-widget' )];
     1089        }
     1090
     1091        $json = str_replace( 'window._sharedData = ', '', strstr( $response['body'], 'window._sharedData = ' ) );
     1092
     1093        // Compatibility for version of php where strstr() doesnt accept third parameter
     1094        if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
     1095            $json = strstr( $json, '</script>', true );
     1096        } else {
     1097            $json = substr( $json, 0, strpos( $json, '</script>' ) );
     1098        }
     1099        $json = rtrim( $json, ';' );
     1100
     1101        // Function json_last_error() is not available before PHP * 5.3.0 version
     1102        if ( function_exists( 'json_last_error' ) ) {
     1103
     1104            ( $results = json_decode( $json, true ) ) && json_last_error() == JSON_ERROR_NONE;
     1105
     1106        } else {
     1107            $results = json_decode( $json, true );
     1108        }
     1109
     1110        return $results;
     1111    }
     1112
    10751113    /**
    10761114     * Stores the fetched data from instagram in WordPress DB using transients
     
    10861124
    10871125        //$nr_images = $nr_images <= 12 ? $nr_images : 12;
    1088         $blocked_users = isset( $search_for['blocked_users'] ) && !empty( $search_for['blocked_users'] ) ? $search_for['blocked_users'] : false;
     1126        $blocked_users = isset( $search_for['blocked_users'] ) && !empty( $search_for['blocked_users'] ) ? str_replace( '@', '', $search_for['blocked_users'] ) : false;
    10891127        if ( isset( $search_for['account'] ) && !empty( $search_for['account'] ) ) {
    10901128            $search = 'account';
     
    11251163            if ( 'user' == $search ) {
    11261164
    1127                 $url = str_replace( '{username}', urlencode( trim( $search_string ) ), self::USERNAME_URL );
    1128                 $response = wp_remote_get( $url, array( 'sslverify' => false, 'timeout' => 60 ) );
    1129 
    1130                 if(strstr( $response['body'], '-cx-PRIVATE-Page__main' )) {
    1131                     return ['error' => __( 'Account not found or for this account there are restrictions on Instagram by age', 'instagram-slider-widget' )];
    1132                 }
    1133 
    1134                 $json = str_replace( 'window._sharedData = ', '', strstr( $response['body'], 'window._sharedData = ' ) );
    1135 
    1136                 // Compatibility for version of php where strstr() doesnt accept third parameter
    1137                 if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
    1138                     $json = strstr( $json, '</script>', true );
    1139                 } else {
    1140                     $json = substr( $json, 0, strpos( $json, '</script>' ) );
    1141                 }
    1142                 $json = rtrim( $json, ';' );
    1143 
    1144                 // Function json_last_error() is not available before PHP * 5.3.0 version
    1145                 if ( function_exists( 'json_last_error' ) ) {
    1146 
    1147                     ( $results = json_decode( $json, true ) ) && json_last_error() == JSON_ERROR_NONE;
    1148 
    1149 
    1150                 } else {
    1151                     $results = json_decode( $json, true );
    1152                 }
     1165                $results = $this->get_data_by_username($search_string);
     1166                if(isset($results['error'])) return $results['error'];
    11531167
    11541168                WIS_Plugin::app()->updateOption('profiles_data_by_username', $results);
     
    15871601                }
    15881602
    1589                 $url = str_replace( '{username}', urlencode( trim( $user ) ), self::USERNAME_URL );
    1590                 $response = wp_remote_get( $url, array( 'sslverify' => false, 'timeout' => 60 ) );
    1591 
    1592                 if ( is_wp_error( $response ) ) {
    1593 
    1594                     return $response->get_error_message();
    1595                 }
    1596 
    1597                 if ( $response['response']['code'] == 200 ) {
    1598 
    1599                     $results = json_decode( $response['body'], true );
    1600 
    1601                     if ( $results && is_array( $results ) ) {
    1602 
    1603                         $user_id = isset( $results['user']['id'] ) ? $results['user']['id'] : false;
    1604 
    1605                         if ( $user_id ) {
    1606 
    1607                             $user_ids[$user] = $user_id;
    1608 
    1609                             set_transient( 'jr_insta_user_ids', $user_ids );
    1610                         }
    1611                     }
    1612                 }
     1603                $results = $this->get_data_by_username($user);
     1604                if ( $results && is_array( $results ) ) {
     1605
     1606                    $results = $results['entry_data']['ProfilePage']['0']['graphql']['user'];
     1607                    $user_id = isset( $results['id'] ) ? $results['id'] : false;
     1608
     1609                    if ( $user_id ) {
     1610
     1611                        $user_ids[$user] = $user_id;
     1612
     1613                        set_transient( 'jr_insta_user_ids', $user_ids );
     1614                    }
     1615                }
    16131616            }
    16141617        }
  • instagram-slider-widget/trunk/instaram_slider.php

    r2189602 r2193464  
    33Plugin Name: Social Slider Widget
    44Plugin URI: https://cm-wp.com/instagram-slider-widget
    5 Version: 1.6.2
     5Version: 1.6.3
    66Description: Social Slider Widget is a responsive slider widget that shows 12 latest images from a public Instagram user and up to 18 images from a hashtag.
    77Author: creativemotion
  • instagram-slider-widget/trunk/readme.txt

    r2189602 r2193464  
    8686
    8787== Changelog ==
     88= 1.6.3 =
     89* Add a notification when authorizing an Instagram account
     90
    8891= 1.6.2 =
    8992* Bug fix
Note: See TracChangeset for help on using the changeset viewer.