Making WordPress.org

Ticket #3003: 3003.diff

File 3003.diff, 8.7 KB (added by dipesh.kakadiya, 8 years ago)

Fixed #2100 and #2907 and Setting reset on data fetch

  • classes/tggr-source-flickr.php

    diff --git a/classes/tggr-source-flickr.php b/classes/tggr-source-flickr.php
    index 4847d62..45033af 100755
    a b if ( ! class_exists( 'TGGRSourceFlickr' ) ) { 
    137137                 * @param string $hashtag
    138138                 */
    139139                public function import_new_items( $hashtag ) {
     140                        if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'] )  ){
     141                                return;
     142                        }
    140143                        $media = self::get_new_media(
    141144                                TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'],
    142145                                $hashtag,
  • classes/tggr-source-google.php

    diff --git a/classes/tggr-source-google.php b/classes/tggr-source-google.php
    index 883bf75..5308d14 100755
    a b if ( ! class_exists( 'TGGRSourceGoogle' ) ) { 
    135135                 * @param string $hashtag
    136136                 */
    137137                public function import_new_items( $hashtag ) {
     138                        if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'] )  ){
     139                                return;
     140                        }
     141
    138142                        $activities = self::get_new_activities(
    139143                                TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'],
    140144                                $hashtag
    if ( ! class_exists( 'TGGRSourceGoogle' ) ) { 
    264268                                'name'     => $postmeta['author_name'][0],
    265269                                'username' => $postmeta['author_name'][0],
    266270                                'image'    => $postmeta['author_image_url'][0],
     271                                'userId'   => $postmeta['author_id'][0],
    267272                        );
    268273
    269274                        $item['itemMeta'] = array(
  • classes/tggr-source-instagram.php

    diff --git a/classes/tggr-source-instagram.php b/classes/tggr-source-instagram.php
    index bdd6097..2da018f 100755
    a b if ( ! class_exists( 'TGGRSourceInstagram' ) ) { 
    2929                 */
    3030                protected function __construct() {
    3131                        $this->view_folder   = dirname( __DIR__ ) . '/views/'. str_replace( '.php', '', basename( __FILE__ ) );
    32                         $this->setting_names = array( 'Client ID', 'Highlighted Accounts', 'Banned Accounts', '_newest_media_id' );
     32                        $this->setting_names = array( 'Client ID', 'Client Secret', 'Redirect URL', 'Access Token', 'Highlighted Accounts', 'Banned Accounts', '_newest_media_id' );
    3333
    3434                        foreach ( $this->setting_names as $key ) {
    3535                                $this->default_settings[ strtolower( str_replace( ' ', '_', $key ) ) ] = '';
    if ( ! class_exists( 'TGGRSourceInstagram' ) ) { 
    136136                 * @param string $hashtag
    137137                 */
    138138                public function import_new_items( $hashtag ) {
     139                        if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['client_id'] )
     140                             || empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['access_token'] ) ){
     141                                return;
     142                        }
    139143                        $media = self::get_new_media(
    140144                                TGGRSettings::get_instance()->settings[ __CLASS__ ]['client_id'],
     145                                TGGRSettings::get_instance()->settings[ __CLASS__ ]['access_token'],
    141146                                $hashtag,
    142147                                TGGRSettings::get_instance()->settings[ __CLASS__ ]['_newest_media_id']
    143148                        );
    if ( ! class_exists( 'TGGRSourceInstagram' ) ) { 
    152157                 * @mvc Model
    153158                 *
    154159                 * @param string $client_id
     160                 * @param string $access_token
    155161                 * @param string $hashtag
    156162                 * @param string $max_id The ID of the most recent item that is already saved in the database
    157163                 * @return mixed string|false
    158164                 */
    159                 protected static function get_new_media( $client_id, $hashtag, $max_id ) {
     165                protected static function get_new_media( $client_id, $access_token, $hashtag, $max_id ) {
    160166                        $response = $media = false;
    161167
    162                         if ( $client_id && $hashtag ) {
     168                        // url for SELF posts https://api.instagram.com/v1/users/self/media/recent/?access_token=XXXX
     169                        if ( $access_token && $hashtag ) {
    163170                                $url = sprintf(
    164                                         '%s/v1/tags/%s/media/recent?client_id=%s',
     171                                        '%s/v1/users/self/media/recent?access_token=%s&count=6',
    165172                                        self::API_URL,
    166                                         urlencode( str_replace( '#', '', $hashtag ) ),
    167                                         urlencode( $client_id )
     173                                        urlencode( $access_token )
    168174                                );
    169175
    170176                                $response = wp_remote_get( $url );
  • classes/tggr-source-twitter.php

    diff --git a/classes/tggr-source-twitter.php b/classes/tggr-source-twitter.php
    index 624222c..ca4c8ea 100755
    a b if ( ! class_exists( 'TGGRSourceTwitter' ) ) { 
    217217                 * @param string $hashtag
    218218                 */
    219219                public function import_new_items( $hashtag ) {
     220
     221                        if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['consumer_key'] )
     222                             || empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['consumer_secret'] )
     223                             || empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['consumer_key'] ) ){
     224                                return;
     225                        }
     226
    220227                        $tweets = self::get_new_hashtagged_tweets(
    221228                                TGGRSettings::get_instance()->settings[ __CLASS__ ]['_bearer_token'],
    222229                                $hashtag,
  • javascript/components/google/index.jsx

    diff --git a/javascript/components/google/index.jsx b/javascript/components/google/index.jsx
    index 39777ae..73428b4 100755
    a b export default React.createClass({ 
    2828
    2929                return (
    3030                        <div className={ item.itemMeta.cssClasses }>
    31                                 <a className="tggr-author-profile clearfix" href={ url + author.username } rel="nofollow">
    32                                         { author.image && <img src={ author.image } alt="" className="tggr-author-avatar" /> }
     31                                <a className="tggr-author-profile clearfix" href={ url + author.userId } rel="nofollow">
     32                                { author.image && <img src={ author.image } alt="" className="tggr-author-avatar" /> }
    3333                                        <span className="tggr-author-name">{ author.name }</span>
    3434                                        <span className="tggr-author-username">@{ author.username }</span>
    3535                                </a>
  • views/tggr-source-instagram/page-settings-section-header.php

    diff --git a/views/tggr-source-instagram/page-settings-section-header.php b/views/tggr-source-instagram/page-settings-section-header.php
    index 5f753b2..7f34b36 100755
    a b  
    1 <p>You can obtain the Client ID by logging into <a href="https://www.instagram.com/developer/">Instagram's developer portal</a>, and then registering a new client.</p>
     1<p>Instructions:</p>
     2<p>1. You can obtain the Client ID &amp; Client Secret by logging into <a href="https://www.instagram.com/developer/">Instagram's developer portal</a>, and then registering a new client. Insert them to the fields bellow and click 'Save Changes'.</p>
     3<p></p>
     4<p>2. Copy the Redirect URL from the field below and paste it in your <strong>Valid redirect URIs</strong> field in your Instagram API Client Settings.</p>
     5<p></p>
     6<p>3. <a href="" id="get_access_token">Click here to get your Access Token!</a> - After the Access Token is in the field please press Save Changes.</p>
     7<p></p>
     8<?php
     9$tggroptions = get_option( 'tggr_settings', array() );
     10$cid = $tggroptions['TGGRSourceInstagram']['client_id'];
     11$cse = $tggroptions['TGGRSourceInstagram']['client_secret'];
     12$cre = $tggroptions['TGGRSourceInstagram']['redirect_url'];
     13$fat = $tggroptions['TGGRSourceInstagram']['access_token'];
     14
     15if ( ! empty( $_GET['code'] ) ) {
     16        $icode = sanitize_text_field( $_GET['code'] );
     17} else {
     18        $icode = '';
     19}
     20
     21if ( $icode !== '' && $fat === '' ) {
     22
     23        $uri = 'https://api.instagram.com/oauth/access_token';
     24        $data = [
     25                'client_id' => $cid,
     26                'client_secret' => $cse,
     27                'grant_type' => 'authorization_code',
     28                'redirect_uri' => $cre,
     29                'code' => $icode,
     30        ];
     31
     32        $ch = curl_init();
     33
     34        curl_setopt( $ch, CURLOPT_URL, $uri ); // uri
     35        curl_setopt( $ch, CURLOPT_POST, true ); // POST
     36        curl_setopt( $ch, CURLOPT_POSTFIELDS, $data ); // POST DATA
     37        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // RETURN RESULT true
     38        curl_setopt( $ch, CURLOPT_HEADER, 0 ); // RETURN HEADER false
     39        curl_setopt( $ch, CURLOPT_NOBODY, 0 ); // NO RETURN BODY false / we need the body to return
     40        curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); // VERIFY SSL HOST false
     41        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); // VERIFY SSL PEER false
     42
     43        $result = json_decode( curl_exec( $ch ), true ); // execute curl
     44
     45        $at = $result['access_token'];
     46
     47        if ( $at !== '' ) {
     48                ?>
     49        <script>
     50            (function( $ ) {
     51                $( document ).ready( function() {
     52                    $( '#tggr_instagram_access_token' ).val( '<?php echo $at; ?>' );
     53                });
     54            })( jQuery );
     55        </script>
     56                <?php
     57        }
     58}
     59?>
     60<script>
     61    (function( $ ) {
     62        $( document ).ready( function() {
     63            var redirect_url = '<?php echo $cre; ?>';
     64            if ( ! redirect_url ){
     65                redirect_url = window.location.href;
     66            }
     67            $( '#tggr_instagram_redirect_url' ).val(redirect_url);
     68            $( '#get_access_token' ).attr('href', 'https://www.instagram.com/oauth/authorize/?client_id=' + $('#tggr_instagram_client_id').val() + '&redirect_uri=' + $( '#tggr_instagram_redirect_url' ).val() + '&response_type=code');
     69        });
     70    })( jQuery );
     71</script>
     72 No newline at end of file