Plugin Directory

Changeset 1344313


Ignore:
Timestamp:
02/05/2016 09:53:34 PM (10 years ago)
Author:
Space_Studio
Message:

Updated to 0.8

Location:
click-tweet
Files:
17 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • click-tweet/trunk/assets/js/click-and-tweet-admin.js

    r1338428 r1344313  
    88    });
    99
     10    $('[name="click_and_tweet_settings[url_shorteners]"]').on('change', function(){
     11        if ($(this).val() == "bitly") {
     12            $('.bitly-shortener').show();
     13        } else {
     14            $('.bitly-shortener').hide();
     15        }
     16    });
     17
    1018    var myOptions = {
    1119        defaultColor: false,
     
    1321        palettes: ['#55acee','','','','']
    1422    };
    15    
     23
    1624    $('.tweet-color-field').wpColorPicker(myOptions);
    1725
  • click-tweet/trunk/click-and-tweet.php

    r1338428 r1344313  
    44 * Plugin URI: http://spacestud.io
    55 * Description: Quote text in your WordPress posts for easy sharing on twitter.
    6  * Version: 0.6.3
     6 * Version: 0.8
    77 * Author: Space Studio
    88 * Author URI: http://spacestud.io
     
    5757     * @var string
    5858     */
    59     protected $version = '0.6.3';
     59    protected $version = '0.8';
    6060
    6161    /**
     
    103103        'none' => 'None',
    104104        'wp' => 'WordPress',
    105         'google' => 'Google'
     105        'google' => 'Google',
     106        'bitly' => 'Bitly'
    106107    ];
    107108
     
    435436        );
    436437
     438        add_settings_field(
     439            $id = 'bitly_access_code',
     440            $title = '',
     441            $callback = array($this, 'callbackBitlyShortenerField'),
     442            $page = 'click_and_tweet_settings',
     443            $section = 'url_shortener_section',
     444            $args = ['class' => (isset($this->settings['url_shorteners']) && $this->settings['url_shorteners'] == 'bitly') ? 'bitly-shortener' : 'bitly-shortener hidden']
     445        );
    437446
    438447        add_settings_section(
     
    586595    }
    587596
     597    /**
     598     * callback function for the bitly shortener field.
     599     */
     600    public function callbackBitlyShortenerField()
     601    {
     602        $setting = isset($this->settings['bitly_access_code']) ? ($this->settings['bitly_access_code']) : '';
     603        $html = "<p><strong>Access Token</strong></p>";
     604        $html .= "<input type='text' name='click_and_tweet_settings[bitly_access_code]' value='$setting' class='regular-text' placeholder='Bitly Access Token'/>";
     605        $html .= '<p class="description"><a href=\https://space-studio.gitbooks.io/click-tweet-plugin/content/PLUGINSETTINGS.html\>Read Documentation</a></p>';
     606        echo $html;
     607    }
    588608    /**
    589609     * sanitizes the setting for the twitter handle and adds '@' to the beginning.
     
    729749
    730750                return $url = $this->getGoogleShortUrl();
     751            }
     752            if($this->settings['url_shorteners'] == 'bitly') {
     753
     754                return $url = $this->getBitlyShortUrl();
    731755            }
    732756        }
     
    901925
    902926    /**
     927     * shortens the url using bitly
     928     * @return $bitlyShortUrl
     929     */
     930    public function getBitlyShortUrl()
     931    {
     932        global $post;
     933
     934        if (!$accessToken = $this->settings['bitly_access_code']) {
     935            return $bitlyShortUrl = get_permalink();
     936        }
     937
     938        $url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$accessToken.'&longUrl='.get_permalink();
     939        $bitlyShortUrl = get_permalink();
     940
     941        if(! $bitlyShortUrl = get_post_meta($post->ID, 'click_and_tweet_bitly_url', true)) {
     942
     943            $response = wp_remote_post( $url, array(
     944                'method' => 'GET',
     945                'headers' => array('content-type' => 'application/json'),
     946                'body' => json_encode(array('longUrl' => get_permalink()))
     947            ));
     948
     949            $urlBody = json_decode(($response['body']), true);
     950            $urlData = $urlBody['data'];
     951
     952            if(in_array('url', $urlData)) {
     953                $bitlyShortUrl = $urlData['url'];
     954                add_post_meta($post->ID, 'click_and_tweet_bitly_url', $bitlyShortUrl);
     955            }
     956
     957        }
     958
     959        return $bitlyShortUrl;
     960    }
     961
     962    /**
    903963     * Checks to see if the post was updated to get new permalink.
    904964     */
  • click-tweet/trunk/readme.txt

    r1338428 r1344313  
    4747
    4848== Changelog ==
     49= 0.8 =
     50* Added bitly integration.
     51
    4952= 0.6.3 =
    5053* Styling enhancements.
Note: See TracChangeset for help on using the changeset viewer.