Plugin Directory

Changeset 1336467


Ignore:
Timestamp:
01/26/2016 04:48:13 PM (10 years ago)
Author:
Space_Studio
Message:

Update to version 0.6

Location:
click-tweet/trunk
Files:
4 edited

Legend:

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

    r1332391 r1336467  
    8383    width:100%;
    8484    max-width: 640px;
    85     padding: 4% 4% 8%;
     85    padding: 4%;
    8686    margin: 4% auto;
    8787    background-color: #FFFFFF;
     
    234234}
    235235
    236 .click-and-tweet-card.center-top {
    237     padding-top: 10%;
    238 }
    239 
    240236.click-and-tweet-card.center-top .click-and-tweet-twitter-logo{
    241     position: absolute;
    242     top: 6%;
    243237    left: 50%;
    244238    -webkit-transform: translateX(-50%);
     
    246240}
    247241
    248 .click-and-tweet-card.center-bottom {
    249     padding-bottom: 12%;
    250 }
    251 
    252242.click-and-tweet-card.center-bottom .click-and-tweet-twitter-logo{
    253     position: absolute;
    254     bottom: 20%;
    255243    left: 50%;
    256244    -webkit-transform: translateX(-50%);
     
    269257    text-align: center;
    270258    font-size: 14px;
    271     position: absolute;
    272     bottom: 1rem;
    273     left: 0;
    274259    opacity: 0.75;
    275260    font-weight: 300;
    276 }
     261    padding: 6px;
     262}
     263
     264/*Settings page*/
     265.tweet-color-setting .iris-palette{
     266    display: none;
     267}
     268.tweet-color-setting .iris-palette:first-child{
     269    display: block;
     270}
  • click-tweet/trunk/assets/js/click-and-tweet-admin.js

    r1331546 r1336467  
    88    });
    99
    10     $('.tweet-color-field').wpColorPicker();
     10    var myOptions = {
     11        defaultColor: false,
     12        hide: true,
     13        palettes: ['#55acee','','','','']
     14    };
     15
     16    $('.tweet-color-field').wpColorPicker(myOptions);
    1117
    1218});
  • click-tweet/trunk/click-and-tweet.php

    r1332391 r1336467  
    44 * Plugin URI: http://spacestud.io
    55 * Description: Quote text in your WordPress posts for easy sharing on twitter.
    6  * Version: 0.4.1
     6 * Version: 0.6
    77 * Author: Space Studio
    88 * Author URI: http://spacestud.io
     
    5757     * @var string
    5858     */
    59     protected $version = '0.4.1';
     59    protected $version = '0.6';
    6060
    6161    /**
     
    9797
    9898    /**
     99     * Types of url Shorteners
     100     * @var array
     101     */
     102    protected $urlShorteners = [
     103        'none' => 'None',
     104        'wp' => 'WordPress',
     105        'google' => 'Google'
     106    ];
     107
     108    /**
     109     * Google shortener api key
     110     * @var string
     111     */
     112    protected $clickAndTweetApiKey = 'AIzaSyBqZoC8D1Dif4NDQoN0GnVnAWFbwfXCT-Y';
     113
     114    /**
     115     *  Types of Posts
     116     * @var array
     117     */
     118    protected $postTypes = ['post', 'page'];
     119
     120    /**
    99121     * admin pages
    100122     * @var array
     
    122144
    123145        $this->init();
     146    }
     147
     148    /**
     149     * Allowed post types of plugin.
     150     * @return array
     151     */
     152    public function getPostTypes()
     153    {
     154        return apply_filters('click_and_tweet_post_types', $this->postTypes);
     155    }
     156
     157    /**
     158    * Checks to see if editor is allowed on post
     159    * @return boolean
     160    */
     161    public function isAllowed()
     162    {
     163        global $post;
     164
     165        if(in_array($post->post_type, $this->getPostTypes())){
     166            return true;
     167        }
     168        return false;
    124169    }
    125170
     
    143188        add_action('wp_enqueue_scripts', [$this, 'enqueueScripts']);
    144189        add_shortcode('clickandtweet', [$this, 'clickAndTweetShortCode']);
     190        add_action('post_updated', [$this, 'checkPermalinkChanges'], 10, 3);
    145191    }
    146192
     
    154200            return;
    155201        }
     202
     203        wp_enqueue_style(
     204            $handle = 'click-and-tweet-css',
     205            $src = plugins_url('/assets/css/click-and-tweet.css', __FILE__),
     206            $deps = false,
     207            $ver = $this->version,
     208            $media = ''
     209        );
    156210
    157211        wp_enqueue_style( 'wp-color-picker' );
     
    338392
    339393        add_settings_field(
    340             $id = 'use_twitter_shortlink',
    341             $title = 'Url Shortlink',
    342             $callback = array($this, 'callbackTwitterShortlinkField'),
    343             $page = 'click_and_tweet_settings',
    344             $section = 'click_and_tweet_settings'
    345         );
    346 
    347         add_settings_field(
    348394            $id = 'use_auto_truncate',
    349395            $title = 'Auto Truncate',
     
    374420            $callback = array($this, 'callbackTweetColorField'),
    375421            $page = 'click_and_tweet_settings',
    376             $section = 'appearance_settings'
    377         );
     422            $section = 'appearance_settings',
     423            $args = ['class' => 'tweet-color-setting']
     424        );
     425
     426        add_settings_field(
     427            $id = 'url_shorteners',
     428            $title = 'URL Shorteners',
     429            $callback = array($this, 'callbackUrlShortenerField'),
     430            $page = 'click_and_tweet_settings',
     431            $section = 'url_shortener_section'
     432        );
     433
    378434
    379435        add_settings_section(
     
    398454        );
    399455
     456        add_settings_section(
     457            $id = 'url_shortener_section',
     458            $title = 'URL Shorteners',
     459            $callback = array($this, 'callbackUrlShortenerSection'),
     460            $page = 'click_and_tweet_settings'
     461        );
    400462    }
    401463
     
    414476
    415477    public function callbackAppearanceSection()
     478    {
     479        echo '';
     480    }
     481
     482    public function callbackUrlShortenerSection()
    416483    {
    417484        echo '';
     
    436503        $html = "<input type='radio' name='click_and_tweet_settings[use_default_username]' value='1' $checked_yes /> On <input type='radio' name='click_and_tweet_settings[use_default_username]' value='0' $checked_no /> Off";
    437504        $html .= "<p class='description'>Display your username in tweets by default?</p>";
    438         echo $html;
    439     }
    440 
    441     /*
    442      * function to turn the twitter shortlink on or off.
    443      */
    444     public function callbackTwitterShortlinkField()
    445     {
    446         $checked_yes = (isset($this->settings['use_twitter_shortlink']) && $this->settings['use_twitter_shortlink'] == 1) ? 'checked' : '';
    447         $checked_no = (!isset($this->settings['use_twitter_shortlink']) || $this->settings['use_twitter_shortlink'] == 0) ? 'checked' : '';
    448         $html = "<input type='radio' name='click_and_tweet_settings[use_twitter_shortlink]' value='1' $checked_yes /> On <input type='radio' name='click_and_tweet_settings[use_twitter_shortlink]' value='0' $checked_no /> Off";
    449         $html .= "<p class='description'>Display Shortlink Url instead of Permalink.</p>";
    450505        echo $html;
    451506    }
     
    508563
    509564    }
     565
     566    /**
     567     * callback function for the url shortener field.
     568     */
     569    public function callbackUrlShortenerField()
     570    {
     571        $options = '';
     572        $selected = isset($this->settings['url_shorteners']) ? $this->settings['url_shorteners'] : '';
     573
     574        foreach ($this->urlShorteners as $key => $value) {
     575            $isSelected = ($key == $selected) ? ' selected' : '';
     576            $options .= "<option value=\"$key\"$isSelected>$value</option>";
     577        }
     578
     579        $selectMenu = "<select name=\"click_and_tweet_settings[url_shorteners]\">$options</select>";
     580
     581        echo $selectMenu;
     582
     583    }
     584
    510585    /**
    511586     * sanitizes the setting for the twitter handle and adds '@' to the beginning.
     
    525600    public function editorButton()
    526601    {
    527         if (get_user_option('rich_editing') == 'true') {
     602        if ($this->isAllowed() && get_user_option('rich_editing') == 'true') {
    528603            add_filter('mce_external_plugins', [$this, 'tinyMcePlugin']);
    529604            add_filter('mce_buttons', [$this, 'tinyMceButton']);
     
    642717    private function getUrl()
    643718    {
    644         if((isset($this->settings['use_twitter_shortlink']) && $this->settings['use_twitter_shortlink'] == 1)) {
    645             return $url = wp_get_shortlink();
    646         }
    647 
    648         return $url = get_permalink();;
     719        if(isset($this->settings['url_shorteners'])) {
     720
     721            if($this->settings['url_shorteners'] == 'wp') {
     722                return $url = wp_get_shortlink();
     723            }
     724
     725            if($this->settings['url_shorteners'] == 'google') {
     726
     727                return $url = $this->getGoogleShortUrl();
     728            }
     729        }
     730
     731        return $url = get_permalink();
    649732    }
    650733
     
    765848        $linkContent = "{$this->filterContent($content)}";
    766849
     850        switch($atts['position']) {
     851            case 'left-center':
     852            case 'left-top':
     853            case 'left-bottom':
     854            case 'right-center':
     855            case 'right-top':
     856            case 'right-bottom':
     857            case 'center-top':
     858                $tweet = "{$twitterLogo}<a {$linkAttributes}>{$linkContent}</a>";
     859                break;
     860            default:
     861                $tweet = "<a {$linkAttributes}>{$linkContent}</a>{$twitterLogo}";
     862        }
     863
    767864        $content = "<div class=\"click-and-tweet-card$position\">
    768                         {$twitterLogo}<a {$linkAttributes}>{$linkContent}</a>
     865                        $tweet
    769866                        <span class=\"call-to-action-text\">{$this->filterCallToAction()}</span>
    770867                    </div>";
    771868
    772869        return $content;
     870    }
     871
     872    /*
     873     * Function to get the url shortened using the google api.
     874     * Adds post meta if it doesnt exist.
     875     */
     876    public function getGoogleShortUrl()
     877    {
     878        global $post;
     879
     880        if(! $googleShortUrl = get_post_meta($post->ID, 'click_and_tweet_google_url', true)) {
     881
     882            $key = $this->clickAndTweetApiKey;
     883            $url = 'https://www.googleapis.com/urlshortener/v1/url?key='.$key;
     884
     885            $response = wp_remote_post( $url, array(
     886                'method' => 'POST',
     887                'headers' => array('content-type' => 'application/json'),
     888                'body' => json_encode(array('longUrl' => get_permalink())),
     889            ));
     890
     891            $urlBody = json_decode($response['body'], true);
     892            $googleShortUrl = $urlBody['id'];
     893
     894            add_post_meta($post->ID, 'click_and_tweet_google_url', $googleShortUrl);
     895
     896        }
     897
     898        return $googleShortUrl;
     899    }
     900
     901    /**
     902     * Checks to see if the post was updated to get new permalink.
     903     */
     904    public function checkPermalinkChanges($post_ID, $postAfterUpdate, $postBeforeUpdate)
     905    {
     906        global $post;
     907        if($postAfterUpdate->post_name != $postBeforeUpdate->post_name) {
     908            delete_post_meta($post->ID, 'click_and_tweet_google_url');
     909        }
    773910    }
    774911
  • click-tweet/trunk/readme.txt

    r1332391 r1336467  
    4747
    4848== Changelog ==
     49= 0.6 =
     50* Added Url Shortener option using Google Api.
     51* Added Twitters primary color as an option to the color palette.
     52* Added an action hook to specify post types for developers.
     53* Styling Enhancements on mobile devices.
     54
    4955= 0.4.1 =
    5056* Made some styling changes updates.
Note: See TracChangeset for help on using the changeset viewer.