Skip to content

Commit

Permalink
all api fix + settings pages.
Browse files Browse the repository at this point in the history
all apis fix.
tested & working
  • Loading branch information
mrxkon committed Jul 30, 2017
1 parent d5c3a52 commit 56825f5
Show file tree
Hide file tree
Showing 8 changed files with 15,925 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function markup_settings_fields( $field ) {
$class = get_called_class();
$setting = str_replace( $class::SETTINGS_PREFIX, '', $field['label_for'] );
$textarea_settings = array( 'highlighted_accounts', 'banned_accounts' );

$checkbox_settings = array( 'sandbox_mode' );
require( dirname( __DIR__ ) . '/views/media-sources-common/page-settings-fields.php' );
}

Expand Down
3 changes: 3 additions & 0 deletions wp-content/plugins/tagregator/classes/tggr-source-flickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public function validate_settings( $new_settings ) {
* @param string $hashtag
*/
public function import_new_items( $hashtag ) {
if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'] ) ){
return;
}
$media = self::get_new_media(
TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'],
$hashtag,
Expand Down
3 changes: 3 additions & 0 deletions wp-content/plugins/tagregator/classes/tggr-source-google.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public function validate_settings( $new_settings ) {
* @param string $hashtag
*/
public function import_new_items( $hashtag ) {
if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'] ) ){
return;
}
$activities = self::get_new_activities(
TGGRSettings::get_instance()->settings[ __CLASS__ ]['api_key'],
$hashtag
Expand Down
54 changes: 28 additions & 26 deletions wp-content/plugins/tagregator/classes/tggr-source-instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class TGGRSourceInstagram extends TGGRMediaSource {
*/
protected function __construct() {
$this->view_folder = dirname( __DIR__ ) . '/views/'. str_replace( '.php', '', basename( __FILE__ ) );
$this->setting_names = array( 'Client ID', 'Client Secret', 'Redirect URL', 'Access Token', 'Highlighted Accounts', 'Banned Accounts', '_newest_media_id' );
$this->setting_names = array( 'Client ID', 'Client Secret', 'Redirect URL', 'Access Token', 'Sandbox Mode', 'Highlighted Accounts', 'Banned Accounts', '_newest_media_id' );

foreach ( $this->setting_names as $key ) {
$this->default_settings[ strtolower( str_replace( ' ', '_', $key ) ) ] = '';
}

$this->default_settings[ 'sandbox_mode' ] = 1;
$this->default_settings[ '_newest_media_id' ] = 0;

$this->register_hook_callbacks();
Expand Down Expand Up @@ -136,11 +138,16 @@ public function validate_settings( $new_settings ) {
* @param string $hashtag
*/
public function import_new_items( $hashtag ) {
if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['client_id'] )
|| empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['access_token'] ) ){
return;
}
$media = self::get_new_media(
TGGRSettings::get_instance()->settings[ __CLASS__ ]['client_id'],
TGGRSettings::get_instance()->settings[ __CLASS__ ]['access_token'],
$hashtag,
TGGRSettings::get_instance()->settings[ __CLASS__ ]['_newest_media_id']
TGGRSettings::get_instance()->settings[ __CLASS__ ]['_newest_media_id'],
TGGRSettings::get_instance()->settings[ __CLASS__ ]['sandbox_mode']
);
$media = $this->remove_banned_items( $media, 'user', 'username' );

Expand All @@ -155,36 +162,31 @@ public function import_new_items( $hashtag ) {
* @param string $client_id
* @param string $access_token
* @param string $hashtag
* @param string $sandbox_mode
* @param string $max_id The ID of the most recent item that is already saved in the database
* @return mixed string|false
*/
protected static function get_new_media( $client_id, $access_token, $hashtag, $max_id ) {
protected static function get_new_media( $client_id, $access_token, $hashtag, $max_id, $sandbox_mode ) {
$response = $media = false;

// url for SELF posts https://api.instagram.com/v1/users/self/media/recent/?access_token=XXXX
/*
* $url = sprintf(
'%s/v1/users/self/media/recent?access_token=%s&count=6',
self::API_URL,
urlencode( $access_token )
);
*/
// url for PUBLIC tags // https://api.instagram.com/v1/tags/XXXX/media/recent/?access_token=XXXX
/*
* $url = sprintf(
'%s/v1/tags/%s/media/recent?access_token=%s',
self::API_URL,
urlencode( str_replace( '#', '', $hashtag ) ),
urlencode( $access_token )
);
*/

if ( $access_token && $hashtag ) {
$url = sprintf(
'%s/v1/users/self/media/recent?access_token=%s&count=6',
self::API_URL,
urlencode( $access_token )
);

if ( $sandbox_mode === '0' ){
// url for PUBLIC tags // https://api.instagram.com/v1/tags/XXXX/media/recent/?access_token=XXXX
$url = sprintf(
'%s/v1/tags/%s/media/recent?access_token=%s&count=9',
self::API_URL,
urlencode( str_replace( '#', '', $hashtag ) ),
urlencode( $access_token )
);
} else {
// url for SELF posts https://api.instagram.com/v1/users/self/media/recent/?access_token=XXXX
$url = sprintf(
'%s/v1/users/self/media/recent?access_token=%s&count=9',
self::API_URL,
urlencode( $access_token )
);
}

$response = wp_remote_get( $url );
$body = json_decode( wp_remote_retrieve_body( $response ) );
Expand Down
6 changes: 6 additions & 0 deletions wp-content/plugins/tagregator/classes/tggr-source-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ protected static function get_bearer_token( $credentials ) {
* @param string $hashtag
*/
public function import_new_items( $hashtag ) {
if ( empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['consumer_key'] )
|| empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['consumer_secret'] )
|| empty( TGGRSettings::get_instance()->settings[ __CLASS__ ]['consumer_key'] ) ){
return;
}

$tweets = self::get_new_hashtagged_tweets(
TGGRSettings::get_instance()->settings[ __CLASS__ ]['_bearer_token'],
$hashtag,
Expand Down
15,882 changes: 15,868 additions & 14 deletions wp-content/plugins/tagregator/javascript/front-end.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ class="large-text"
echo esc_textarea( TGGRSettings::get_instance()->settings[ $class ][ $setting ] );
?></textarea>

<?php elseif ( in_array( $setting, $checkbox_settings, true ) ) : ?>
<input type="hidden" name="<?php echo esc_attr( Tagregator::PREFIX ); ?>settings[<?php echo esc_attr( $class ); ?>][<?php echo esc_attr( $setting ); ?>] ); ?>" value="0" />
<input
type="checkbox"
id="<?php echo esc_attr( $class::SETTINGS_PREFIX . $setting ); ?>"
name="<?php echo esc_attr( Tagregator::PREFIX ); ?>settings[<?php echo esc_attr( $class ); ?>][<?php echo esc_attr( $setting ); ?>] ); ?>"
class="regular-text"
<?php checked( '1', esc_attr( TGGRSettings::get_instance()->settings[ $class ][ $setting ] )); ?>
value="1"/>
<?php _e( 'Enabled' ); ?>

<?php else: ?>

<input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<p>Instructions:</p>
<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>
<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 <strong>'Save Changes'</strong>.</p>
<p></p>
<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>
<p></p>
<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>
<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 click <strong>'Save Changes'</strong>.</p>
<p></p>
<p><strong>Note:</strong> Sandbox mode will retrieve your account's 9 latest posts ignoring the #hashtag. Non-sandbox will retrieve the latest hashtags posts from all instagram as long as there is permission for 'public_content' in your client.</p>
<?php

$tggroptions = get_option( 'tggr_settings', array() );

$cid = $tggroptions['TGGRSourceInstagram']['client_id'];
$cse = $tggroptions['TGGRSourceInstagram']['client_secret'];
$cre = $tggroptions['TGGRSourceInstagram']['redirect_url'];
Expand Down

0 comments on commit 56825f5

Please sign in to comment.