Plugin Directory

Changeset 1325869


Ignore:
Timestamp:
01/11/2016 03:18:53 PM (10 years ago)
Author:
Space_Studio
Message:

Created tag 0.2.

Location:
click-tweet/tags/0.2
Files:
5 deleted
3 edited
5 copied

Legend:

Unmodified
Added
Removed
  • click-tweet/tags/0.2/assets/css/click-and-tweet-editor.css

    r1312087 r1325869  
    1919    display: block;
    2020    position: absolute;
    21     padding: 25px 15px;
     21    padding: 25px 15px 40px;
    2222    min-width: 200px;
    2323    min-height:  80px;
     
    105105    z-index: 1000;
    106106}
    107 
    108 .click-and-tweet-tooltip label{
     107.click-and-tweet-tooltip label:not(.blue){
     108    display: block;
     109    padding: 3px;
     110    font-size: 0.8em;
     111}
     112.click-and-tweet-tooltip label.blue{
    109113    background: #55acee;
    110114    display: inline-block;
     
    163167    color: #55acee;
    164168}
     169
     170.click-and-tweet-tooltip .panel .more-link{
     171    font-size: 1.6em;
     172    text-align: right;
     173    color: #FFF;
     174    text-decoration: none;
     175    position: absolute;
     176    bottom: 0px;
     177    right: 10px;
     178}
     179
     180.click-and-tweet-tooltip .panel .back-link{
     181    font-size: 1.6em;
     182    text-align: right;
     183    color: #FFF;
     184    text-decoration: none;
     185    position: absolute;
     186    bottom: 0px;
     187    left: 10px;
     188}
     189
     190.click-and-tweet-tooltip .panel .back-link small{
     191    font-size: 0.5em;
     192    vertical-align: middle;
     193    padding-left: 5px;
     194}
     195
     196.click-and-tweet-tooltip select{
     197    width: 100%;
     198    font-size: 2em;
     199}
  • click-tweet/tags/0.2/assets/css/click-and-tweet.css

    r1312087 r1325869  
    2424    padding-top: 100%;
    2525}
     26
     27.click-and-tweet-card{
     28    display: block;
     29    width:100%;
     30    max-width: 640px;
     31    padding:1.625rem;
     32    margin: 2.6rem auto;
     33    background-color: #FFFFFF;
     34    border: solid 1px #EEE;
     35    -webkit-border-radius: 0.4rem;
     36    border-radius: 0.4rem;
     37    -webkit-box-shadow: 0 0 3px 0 rgba(0,0,0,0.025);
     38    box-shadow: 0 0 3px 0 rgba(0,0,0,0.025);
     39    position: relative;
     40}
     41
     42.click-and-tweet-card .click-and-tweet-twitter-logo{
     43    background-image: url('../img/twitter-logo.png');
     44    background-position: center;
     45    background-size: contain;
     46    background-repeat: no-repeat;
     47    display: block;
     48    height: 2.8em;
     49    width: 2.8em;
     50    position: relative;
     51}
     52
     53.click-and-tweet-card .click-and-tweet-twitter-logo:before{
     54    content: "";
     55    display: block;
     56    padding-top: 100%;
     57}
     58
     59.click-and-tweet-card .click-and-tweet-twitter-logo a{
     60    display: block;
     61    width:100%;
     62    height: 100%;
     63    position: absolute;
     64    top: 0;
     65    left: 0;
     66    text-indent: -9999px;
     67}
     68
     69.click-and-tweet-card .click-and-tweet-card-link{
     70    display:block;
     71    text-align: left;
     72}
     73
     74.click-and-tweet-card.left-center .click-and-tweet-twitter-logo{
     75    position: absolute;
     76    top: 50%;
     77    left: 1.625rem;
     78    -webkit-transform: translateY(-50%);
     79    transform: translateY(-50%);
     80}
     81
     82.click-and-tweet-card.left-center .click-and-tweet-card-link{
     83    padding-left: 4.625em;
     84
     85}
     86
     87.click-and-tweet-card.left-top .click-and-tweet-twitter-logo{
     88    position: absolute;
     89    top: 12.5%;
     90    left: 1rem;
     91}
     92
     93.click-and-tweet-card.left-top .click-and-tweet-card-link{
     94    padding-left: 3em;
     95}
     96
     97.click-and-tweet-card.left-bottom .click-and-tweet-twitter-logo{
     98    position: absolute;
     99    bottom: 12.5%;
     100    left: 1rem;
     101}
     102
     103.click-and-tweet-card.left-bottom .click-and-tweet-card-link{
     104    padding-left: 3em;
     105}
     106
     107.click-and-tweet-card.right-center .click-and-tweet-twitter-logo{
     108    position: absolute;
     109    top: 50%;
     110    right: 1.625rem;
     111    -webkit-transform: translateY(-50%);
     112    transform: translateY(-50%);
     113}
     114
     115.click-and-tweet-card.right-center .click-and-tweet-card-link{
     116    padding-right: 4.625em;
     117}
     118
     119.click-and-tweet-card.right-top .click-and-tweet-twitter-logo{
     120    position: absolute;
     121    top: 12.5%;
     122    right: 1rem;
     123}
     124
     125.click-and-tweet-card.right-top .click-and-tweet-card-link{
     126    padding-right: 3em;
     127}
     128
     129.click-and-tweet-card.right-bottom .click-and-tweet-twitter-logo{
     130    position: absolute;
     131    bottom: 12.5%;
     132    right: 1rem;
     133}
     134
     135.click-and-tweet-card.right-bottom .click-and-tweet-card-link{
     136    padding-right: 3em;
     137}
     138
     139.click-and-tweet-card.center-top {
     140    padding-top: 3.5em;
     141}
     142.click-and-tweet-card.center-top .click-and-tweet-twitter-logo{
     143    position: absolute;
     144    top: 4%;
     145    left: 50%;
     146    -webkit-transform: translateX(-50%);
     147    transform: translateX(-50%);
     148}
     149
     150.click-and-tweet-card.center-bottom {
     151    padding-bottom: 3.5em;
     152}
     153
     154.click-and-tweet-card.center-bottom .click-and-tweet-twitter-logo{
     155    position: absolute;
     156    bottom: 4%;
     157    left: 50%;
     158    -webkit-transform: translateX(-50%);
     159    transform: translateX(-50%);
     160}
     161
     162.click-and-tweet-card.center-top .click-and-tweet-card-link,
     163.click-and-tweet-card.center-bottom .click-and-tweet-card-link{
     164    text-align: center;
     165}
  • click-tweet/tags/0.2/assets/js/click-and-tweet-tinymce-plugin.js

    r1312087 r1325869  
    11(function($) {
    22    tinymce.PluginManager.add('click_and_tweet', function(ed, url) {
    3         var activeShortcode, editorEditable = true;
     3        var activeShortcode, editorEditable = true, shortcodeAdded = false, activeSpan;
     4
     5        var defaults = {
     6            handle : click_and_tweet.defaultUsername || null,
     7            layout : click_and_tweet.defaultLayout || null,
     8            inlinePosition : click_and_tweet.defaultInlinePosition || null,
     9            cardPosition : click_and_tweet.defaultCardPosition || null
     10        };
     11
     12        var inlineTweetPositions = {
     13            '' : 'Default',
     14            'left' : 'Left',
     15            'right' : 'Right'
     16        };
     17
     18        var cardTweetPositions = {
     19            '' : 'Default',
     20            'center-top': 'Center Top',
     21            'center-bottom': 'Center Bottom',
     22            'left-center': 'Left Center',
     23            'left-top': 'Left Top',
     24            'left-bottom': 'Left Bottom',
     25            'right-center': 'Right Center',
     26            'right-top': 'Right Top',
     27            'right-bottom': 'Right Bottom'
     28        };
    429
    530        /**
     
    2651                            content : text
    2752                        });
     53                        shortcodeAdded = true;
    2854                    }
    2955                }
     
    4066        ed.on('click', function(e) {
    4167            toggleTooltip(e);
    42 
     68            togglePanel(e);
    4369            closeToolTip(e);
     70            updatePositionSelectOnChange(e);
    4471
    4572            if ($(e.target).is('input[type="text"]')) {
     
    7198                                'data-handle' : shortcode.attrs.named.handle || '',
    7299                                'data-hashtag' : shortcode.attrs.named.hashtag || '',
     100                                'data-related' : shortcode.attrs.named.related || '',
     101                                'data-layout' : shortcode.attrs.named.layout || '',
     102                                'data-position' : shortcode.attrs.named.position || '',
    73103                            }
    74104                        }) + spacer;
    75105            });
     106            activeSpan = result;
    76107            event.content = result;
     108        });
     109
     110        ed.on('SetContent', function(event) {
     111            if(shortcodeAdded){
     112                //Trigger open here
     113                shortcodeAdded = false;
     114            }
    77115        });
    78116
     
    94132                        handle : $(e).data('handle') || '',
    95133                        hashtag : $(e).data('hashtag') || '',
     134                        related : $(e).data('related') || '',
     135                        layout : $(e).data('layout') || '',
     136                        position : $(e).data('position') || ''
    96137                    }
    97138                });
     
    113154            var tooltip = '<div class="click-and-tweet-tooltip mceNonEditable" contenteditable="false">' +
    114155                            '<span class="close">&times;</span>' +
    115                             '<div>' +
    116                                 '<label>@</label>' +
    117                                 '<input type="text" name="handle" class="click-and-tweet-hash mceEditable" contenteditable="true" placeholder="@username">' +
     156                            '<div class="panel default">' +
     157                                '<div>' +
     158                                    '<label class="blue">@</label>' +
     159                                    '<input type="text" name="handle" class="click-and-tweet-username mceEditable" contenteditable="true" placeholder="@username">' +
     160                                '</div>' +
     161                                '<div>' +
     162                                    '<label class="blue">#</label>' +
     163                                    '<input type="text" name="hashtag" class="click-and-tweet-hash mceEditable" contenteditable="true" placeholder="#hashtag">' +
     164                                '</div>' +
     165                                '<div>' +
     166                                    '<label class="blue">@</label>' +
     167                                    '<input type="text" name="related" class="click-and-tweet-related mceEditable" contenteditable="true" placeholder="@relatedUsername">' +
     168                                '</div>' +
     169                                '<a class="toggle-panel more-link" data-panel="more" title="More">&middot;&middot;&middot;</a>' +
    118170                            '</div>' +
    119                             '<div>' +
    120                                 '<label>#</label>' +
    121                                 '<input type="text" name="hashtag" class="click-and-tweet-hash mceEditable" contenteditable="true" placeholder="#hashtag">' +
     171                            '<div class="panel more" style="display: none;">' +
     172                                '<div>' +
     173                                    '<label>Layout</label>' +
     174                                    '<select class="click-to-tweet-layout" name="layout">' +
     175                                        '<option value="inline">Inline</option>' +
     176                                        '<option value="card">Card</option>' +
     177                                    '</select>' +
     178                                '</div>' +
     179                                '<div>' +
     180                                    '<label>Position</label>' +
     181                                    '<select class="click-to-tweet-layout-position" name="position"></select>' +
     182                                '</div>' +
     183                                '<a class="toggle-panel back-link" data-panel="default" title="Back">&lsaquo;<small>Back</small></a>' +
    122184                            '</div>' +
    123185                          '</div>';
     
    159221                activeShortcode = '';
    160222                toggleEditable();
     223            }
     224        }
     225
     226        /**
     227         * Close the tooltip
     228         */
     229        function togglePanel(e)
     230        {
     231            if ($($(e.target)[0]).hasClass('toggle-panel') || $($(e.target)[0]).parent().hasClass('toggle-panel')) {
     232                var target = ($($(e.target)[0]).parent().hasClass('toggle-panel')) ? $($(e.target)[0]).parent() : $($(e.target)[0]);
     233                var panel = target.data('panel');
     234                target.closest('.click-and-tweet-tooltip').find('.panel').hide();
     235                target.closest('.click-and-tweet-tooltip').find('.panel.' + panel).show();
     236                return false;
    161237            }
    162238        }
     
    198274            //Determine the y position of the tooltip
    199275            switch (true) {
    200                 case targetYOffset >= maxYOffset :
     276                case targetYOffset >= maxYOffset && maxYOffset > 0 :
    201277                    yClassName = 'top';
    202278                    break;
     
    264340            setTimeout(function () {
    265341                var shortcode = element;
    266                 var inputs = $('.click-and-tweet-tooltip', ed.getBody()).find('input[type="text"]');
     342                var inputs = $('.click-and-tweet-tooltip', ed.getBody()).find('input[type="text"], select');
    267343
    268344                inputs.each(function(i,e){
     
    270346                });
    271347
    272                 inputs.on('keyup', function(){
     348                inputs.on('keyup change', function(){
    273349                    shortcode.attr('data-' + $(this).attr('name'), $(this).val());
    274350                });
     
    283359        function setInputFields(e, parent)
    284360        {
    285             var defaults = {
    286                 handle : click_and_tweet.defaultUsername || null
    287             };
    288 
    289             var value = parent[0].dataset[$(e).attr('name')] || '';
    290 
    291             $(e).val(value);
     361            if( typeof parent[0].dataset[$(e).attr('name')] !== 'undefined'){
     362                var value = parent[0].dataset[$(e).attr('name')] || '';
     363                if(value) $(e).val(value);
     364            }
     365
     366            if($(e).attr('name') == 'layout'){
     367                updatePositionSelect(e);
     368            }
    292369
    293370            if($(e).attr('name') == 'handle' && defaults.handle) $(e).attr('placeholder', defaults.handle);
     
    326403            }
    327404        }
     405
     406        /**
     407         * Update the position select options
     408         */
     409        function updatePositionSelect(e)
     410        {
     411            e = e.currentTarget || e;
     412            var options = ($(e).val() == 'card') ? cardTweetPositions : inlineTweetPositions;
     413            var layout = $('.click-to-tweet-layout', ed.getBody());
     414            var layoutPosition = $('.click-to-tweet-layout-position', ed.getBody());
     415
     416            layoutPosition.empty();
     417            $.each(options, function(value,key) {
     418              layoutPosition.append($("<option></option>").attr("value", value).text(key));
     419            });
     420        }
     421
     422        /**
     423         * Update the position select options when the layout select changes
     424         */
     425        function updatePositionSelectOnChange(e)
     426        {
     427            if(e.target.className == 'click-to-tweet-layout'){
     428                $('.click-to-tweet-layout', ed.getBody()).on('change', function(e){
     429                    updatePositionSelect(e);
     430                });
     431            }
     432        }
    328433    });
    329434
  • click-tweet/tags/0.2/click-and-tweet.php

    r1312087 r1325869  
    44 * Plugin URI: http://spacestud.io
    55 * Description: Quote text in your WordPress posts for easy sharing on twitter.
    6  * Version: 0.1.0
     6 * Version: 0.2.0
    77 * Author: Space Studio
    88 * Author URI: http://spacestud.io
     
    2727
    2828/**
     29 * Activation Hook
     30 */
     31register_activation_hook(__FILE__, array('ClickAndTweet', 'activation'));
     32
     33/**
     34 * Deactivation Hook
     35 */
     36register_deactivation_hook(__FILE__, array('ClickAndTweet', 'deactivation'));
     37
     38/**
     39 * Uninstall Hook
     40 */
     41register_uninstall_hook(__FILE__, array('ClickAndTweet', 'uninstall'));
     42
     43/**
    2944 * Click & Tweet
    3045 */
     
    4358     * @var string
    4459     */
    45     protected $optionName = 'click_and_tweet_settings';
     60    static $pluginOptionName = 'click_and_tweet_settings';
     61
     62    /**
     63     * Plugin option name.
     64     *
     65     * @var string
     66     */
     67    public $optionName = 'click_and_tweet_settings';
     68
     69    /**
     70     * Inline Layout Positions
     71     *
     72     * @var array
     73     */
     74    protected $inlinePositions = ['left' => 'Left', 'right' => 'Right'];
     75
     76    /**
     77     * Card Layout Positions
     78     *
     79     * @var array
     80     */
     81    protected $cardPositions = [
     82        'center-top' => 'Center Top',
     83        'center-bottom' => 'Center Bottom',
     84        'left-center' => 'Left Center',
     85        'left-top' => 'Left Top',
     86        'left-bottom' => 'Left Bottom',
     87        'right-center' => 'Right Center',
     88        'right-top' => 'Right Top',
     89        'right-bottom' => 'Right Bottom'
     90    ];
    4691
    4792    /**
     
    5095    public function __construct()
    5196    {
     97        $this->optionName = self::$pluginOptionName;
     98
    5299        $this->settings = get_option($this->optionName);
    53100
     
    64111    public function adminInit()
    65112    {
    66         register_activation_hook(__FILE__, array($this, 'activation'));
    67         register_deactivation_hook(__FILE__, array($this, 'deactivation'));
    68113        add_action('admin_init', array($this, 'registerSettings'));
    69114        add_action('admin_init', array($this, 'editorStyle'));
     
    87132    public function enqueueAdminScripts($hook)
    88133    {
    89             //var_dump($hook); die;
     134
    90135        $adminPages = array('settings_page_click-and-tweet', 'post.php');
    91136        if (!in_array($hook, $adminPages)) {
     
    110155        );
    111156
     157        //sets the values for username, inline positions, and card positions as long as they are selected, to change the default.
    112158        if(!empty($this->settings['use_default_username']) && isset($this->settings['default_username'])) {
    113159            $data['defaultUsername'] = $this->settings['default_username'];
     160        }
     161
     162        if(!empty($this->settings['inline_tweet_position'])) {
     163            $data['defaultInlinePosition'] = $this->settings['inline_tweet_position'];
     164        }
     165
     166        if(!empty($this->settings['card_tweet_position'])) {
     167            $data['defaultCardPosition'] = $this->settings['card_tweet_position'];
    114168        }
    115169
     
    153207
    154208    /**
    155      * Plugin Activation.
    156      */
    157     public function activation()
     209     * Plugin Activation. Sets the default settings.
     210     */
     211    public static function activation()
     212    {
     213        $option = get_option(self::$pluginOptionName);
     214
     215        if(!isset($option['inline_tweet_position'])) {
     216            $option['inline_tweet_position'] = 'right';
     217            update_option(self::$pluginOptionName, $option);
     218        }
     219
     220        if(!isset($option['card_tweet_position'])) {
     221            $option['card_tweet_position'] = 'left-center';
     222            update_option(self::$pluginOptionName, $option);
     223        }
     224    }
     225
     226    /**
     227     * Plugin Deactivation.
     228     */
     229    public static function deactivation()
    158230    {
    159231        //
     
    161233
    162234    /**
    163      * Plugin Deactivation.
    164      */
    165     public function deactivation()
    166     {
    167         //
    168     }
    169 
    170     /**
    171235     * Function to uninstall the plugin
    172236     */
    173     public function uninstall()
    174     {
    175         // If uninstall is not called from WordPress, exit
    176         if (!defined('WP_UNINSTALL_PLUGIN')) {
    177             exit();
    178         }
    179 
     237    public static function uninstall()
     238    {
    180239        delete_option($this->optionName);
    181240
     
    207266                <h2>Click & Tweet Settings</h2>
    208267                <p>&nbsp;</p>
     268
    209269                <form class="" action="options.php" method="post" enctype="multipart/form-data">
    210270                    <?php
     
    256316        );
    257317
     318        add_settings_field(
     319            $id = 'use_twitter_shortlink',
     320            $title = 'Url Shortlink',
     321            $callback = array($this, 'callbackTwitterShortlinkField'),
     322            $page = 'click_and_tweet_settings',
     323            $section = 'click_and_tweet_settings'
     324        );
     325
     326        add_settings_field(
     327            $id = 'use_auto_truncate',
     328            $title = 'Auto Truncate',
     329            $callback = array($this, 'callbackTwitterAutoTruncateField'),
     330            $page = 'click_and_tweet_settings',
     331            $section = 'click_and_tweet_settings'
     332        );
     333
     334        add_settings_field(
     335            $id = 'inline_tweet_position',
     336            $title = 'Default Inline Position',
     337            $callback = array($this, 'callbackInlineTweetPositionField'),
     338            $page = 'click_and_tweet_settings',
     339            $section = 'layout_positioning'
     340        );
     341
     342        add_settings_field(
     343            $id = 'card_tweet_position',
     344            $title = 'Default Card Position',
     345            $callback = array($this, 'callbackCardPositionField'),
     346            $page = 'click_and_tweet_settings',
     347            $section = 'layout_positioning'
     348        );
    258349
    259350        add_settings_section(
    260351            $id = 'click_and_tweet_settings',
    261             $title = '',
     352            $title = 'General Settings',
    262353            $callback = array($this, 'callbackTwitterHandleSection'),
    263354            $page = 'click_and_tweet_settings'
    264355        );
     356
     357        add_settings_section(
     358            $id = 'layout_positioning',
     359            $title = 'Layout and Positioning',
     360            $callback = array($this, 'callbackLayoutSection'),
     361            $page = 'click_and_tweet_settings'
     362        );
    265363    }
    266364
     
    273371    }
    274372
     373    public function callbackLayoutSection()
     374    {
     375        echo '';
     376    }
    275377
    276378    /**
     
    296398    }
    297399
     400    /*
     401     * function to turn the twitter shortlink on or off.
     402     */
     403    public function callbackTwitterShortlinkField()
     404    {
     405        $checked_yes = (isset($this->settings['use_twitter_shortlink']) && $this->settings['use_twitter_shortlink'] == 1) ? 'checked' : '';
     406        $checked_no = (!isset($this->settings['use_twitter_shortlink']) || $this->settings['use_twitter_shortlink'] == 0) ? 'checked' : '';
     407        $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";
     408        $html .= "<p class='description'>Display Shortlink Url instead of Permalink.</p>";
     409        echo $html;
     410    }
     411
     412    /*
     413     * function to call back the Auto Truncate Settings field.
     414     */
     415     public function callbackTwitterAutoTruncateField()
     416     {
     417        $checked_yes = (isset($this->settings['use_auto_truncate']) && $this->settings['use_auto_truncate'] == 1) ? 'checked' : '';
     418        $checked_no = (!isset($this->settings['use_auto_truncate']) || $this->settings['use_auto_truncate'] == 0) ? 'checked' : '';
     419        $html = "<input type='radio' name='click_and_tweet_settings[use_auto_truncate]' value='1' $checked_yes /> On <input type='radio' name='click_and_tweet_settings[use_auto_truncate]' value='0' $checked_no /> Off";
     420        $html .= "<p class='description'>Auto truncate text to avoid exceeding 140 characters on Twitter.</p>";
     421        echo $html;
     422     }
     423
     424    /**
     425     * callback function that returns a select menu of inline tweet Positions
     426     */
     427    public function callbackInlineTweetPositionField()
     428    {
     429        $options = '';
     430        $selected = isset($this->settings['inline_tweet_position']) ? $this->settings['inline_tweet_position'] : '';
     431
     432        foreach ($this->inlinePositions as $key => $value) {
     433            $isSelected = ($key == $selected) ? ' selected' : '';
     434            $options .= "<option value=\"$key\"$isSelected>$value</option>";
     435        }
     436
     437        $selectMenu = "<select name=\"click_and_tweet_settings[inline_tweet_position]\">$options</select>";
     438
     439        echo $selectMenu;
     440    }
     441
     442    /**
     443     * callback function that returns a select menu of card Positions
     444     */
     445    public function callbackCardPositionField()
     446    {
     447        $options = '';
     448        $selected = isset($this->settings['card_tweet_position']) ? $this->settings['card_tweet_position'] : '';
     449
     450        foreach ($this->cardPositions as $key => $value) {
     451            $isSelected = ($key == $selected) ? ' selected' : '';
     452            $options .= "<option value=\"$key\"$isSelected>$value</option>";
     453        }
     454
     455        $selectMenu = "<select name=\"click_and_tweet_settings[card_tweet_position]\">$options</select>";
     456
     457        echo $selectMenu;
     458    }
     459
    298460    /**
    299461     * sanitizes the setting for the twitter handle and adds '@' to the beginning.
     
    351513    public function clickAndTweetShortCode($atts, $content)
    352514    {
    353         $linkAttributes = "href=\"{$this->shortcodeUrl($atts, $content)}\"
    354                             target=\"_blank\"
    355                             class=\"click-and-tweet-inline\"";
    356 
    357         $twitterLogo = "<span class=\"click-and-tweet-twitter-logo\"></span>";
    358 
    359         $linkContent = "{$content}{$twitterLogo}";
    360 
    361         $content = "<a {$linkAttributes}>{$linkContent}</a>";
    362 
     515        $content = (isset($atts['layout']) && ($atts['layout'] == 'card')) ? $this->cardTweet($atts, $content) : $this->inlineTweet($atts, $content);
    363516        return $content;
    364517    }
     
    384537    private function getQuery($atts = array(), $content)
    385538    {
     539        $text = html_entity_decode($content);
     540        $username = $this->getUsername($atts);
     541        $url = $this->getUrl();
     542        $hashtags = $this->getHashtags($atts);
     543        $related = $this->getRelated($atts);
     544
    386545        $query = [
    387             'text' => html_entity_decode($content),
    388             'url' => get_permalink(),
    389             'hashtags' => $this->getHastags($atts)
     546            'text' => $this->autoTruncate($text, $username, $url, $hashtags),
     547            'url' => $url,
     548            'hashtags' =>  $hashtags,
     549            'related' => $related
    390550        ];
    391551
    392         if($via = $this->getUsername($atts)) $query['via'] = $via;
     552        if($username) $query['via'] = $username;
     553
     554        if($related) $query['related'] = $related;
    393555
    394556        return $query;
     557    }
     558
     559    /**
     560     * Auto Truncates the tweet to prevent the tweet from exceeding 140 characters
     561     * @param  string $text, $username, $url, $hashtag
     562     * @return string $text
     563     */
     564    private function autoTruncate($text, $username, $url, $hashtag)
     565    {
     566        $more = "...";
     567        $moreLength = strlen($more);
     568        $textLength = strlen($text);
     569        $usernameLength = ($username) ? strlen($username) + 1 : 0;
     570        $viaLength = ($username) ? 4 : 0;
     571        $hashtagCount = (!empty($hashtag) && count(explode(',',$hashtag)) > 1) ? count(explode(',',$hashtag)) : 0;
     572        $hashtagLength = strlen($hashtag) + $hashtagCount + 1;
     573        $urlLength = (strlen($url) >= 23) ? 21 : strlen($url) + 1;
     574
     575        $totalLength = $textLength + $hashtagLength + $viaLength + $usernameLength + $urlLength + $moreLength;
     576        $x = $hashtagLength + $viaLength + $usernameLength + $urlLength + $moreLength;
     577
     578        if(isset($this->settings['use_auto_truncate']) && ($this->settings['use_auto_truncate'] == 1)) {
     579            if($totalLength > 140) {
     580                $text = wp_html_excerpt($text, $totalLength - 140);
     581                $y = 140 - $x;
     582                $text = wp_html_excerpt($text, $y - 3, $more);
     583            }
     584        }
     585
     586        return $text;
     587    }
     588
     589    /**
     590     * Get the url for the tweet
     591     * @return string
     592     */
     593    private function getUrl()
     594    {
     595        if((isset($this->settings['use_twitter_shortlink']) && $this->settings['use_twitter_shortlink'] == 1)) {
     596            return $url = wp_get_shortlink();
     597        }
     598
     599        return $url = get_permalink();;
    395600    }
    396601
     
    405610                           isset($this->settings['default_username']) ? $this->settings['default_username'] : '';
    406611        $handle = (!empty($atts['handle'])) ? $atts['handle'] : $defaultUsername;
    407 
    408612        $username = trim(str_replace('@', '', $handle));
    409613
    410614        return $username;
    411 
    412615    }
    413616
     
    417620     * @return $hashtags
    418621     */
    419     private function getHastags($atts = array())
     622    private function getHashtags($atts = array())
    420623    {
    421624        if(isset($atts['hashtag'])){
    422625            $hashtags = $atts['hashtag'];
    423             $hashtags = str_replace('#', '', $hashtags);
     626            $hashtags = trim(str_replace('#', '', $hashtags));
    424627            $hashtags = explode(' ', $hashtags);
    425628            $hashtags = implode(',', $hashtags);
     629            $hashtags = rtrim($hashtags, ',');
     630
    426631            return $hashtags;
    427632        }
    428633
    429634        return $hashtags = '';
     635    }
     636
     637    /**
     638     * Get related usernames
     639     * @param  array $atts
     640     * @return string $related
     641     */
     642    private function getRelated($atts)
     643    {
     644        if(isset($atts['related'])){
     645            $related = $atts['related'];
     646            $related = str_replace('@', '', $related);
     647            $related = explode(' ', $related);
     648            $related =  implode(',', $related);
     649
     650            return $related;
     651        }
     652
     653        return $related = '';
     654    }
     655
     656    /**
     657     * Create an inline tweet
     658     * @param  array $atts
     659     * @param  string $content
     660     * @return string
     661     */
     662    public function inlineTweet($atts, $content)
     663    {
     664        $position = (!empty($atts['position'])) ? ' '.$atts['position']  : ' '.$this->settings['inline_tweet_position'];
     665
     666        $linkAttributes = "href=\"{$this->shortcodeUrl($atts, $content)}\"
     667                            target=\"_blank\"
     668                            title=\"Click & Tweet this!\"
     669                            class=\"click-and-tweet-inline$position\"";
     670
     671        $twitterLogo = "<span class=\"click-and-tweet-twitter-logo\"></span>";
     672
     673        $linkContent = (isset($position) && trim($position) == 'left') ? "{$twitterLogo}{$content}" : "{$content}{$twitterLogo}";
     674
     675        $content = "<a {$linkAttributes}>{$linkContent}</a>";
     676
     677        return $content;
     678    }
     679
     680    /**
     681     * Create a tweet card
     682     * @param  array $atts
     683     * @param  string $content
     684     * @return string
     685     */
     686    public function cardTweet($atts, $content)
     687    {
     688        $position = (!empty($atts['position'])) ? ' '.$atts['position']  : ' '.$this->settings['card_tweet_position'];
     689
     690        $linkAttributes = "href=\"{$this->shortcodeUrl($atts, $content)}\"
     691                            target=\"_blank\"
     692                            title=\"Click & Tweet this!\"
     693                            class=\"click-and-tweet-card-link$position\"";
     694
     695        $twitterLogo = "<span class=\"click-and-tweet-twitter-logo\">
     696                            <a href=\"{$this->shortcodeUrl($atts, $content)}\" target=\"_blank\" title=\"Click & Tweet this!\">
     697                                Click & Tweet this!
     698                            </a>
     699                        </span>";
     700
     701        $linkContent = "{$content}";
     702
     703        $content = "<div class=\"click-and-tweet-card$position\">{$twitterLogo}<a {$linkAttributes}>{$linkContent}</a></div>";
     704
     705        return $content;
    430706    }
    431707}
  • click-tweet/tags/0.2/readme.txt

    r1312107 r1325869  
    11=== Click & Tweet ===
    2 Contributors: Space_Studio, tlaverdure
     2Contributors: Space_Studio, tlaverdure, bbearchell
    33Tags: twitter, click, tweet, click-to-tweet, click-and-tweet, inline-tweet, tweet-card
    44Requires at least: 3.8
     
    1010
    1111== Description ==
    12 Why Use It?
     12###Why Use It?
    1313
    1414Surely you’d jump on the opportunity to use a tool that practically allows your content to market itself. Too good to be true? We all know the power and reach that Twitter has as a marketing tool. So we created this Click & Tweet plugin to provide your users with an enticing, simple way to share the content on your website. By doing this, you not only increase your audience, but also strengthen your authority as the opinions of peers hold a lot of weight today when it comes to backing a brand.
    1515
    1616Share buttons can become just an afterthought, and by the last sentence users are probably already considering where to turn their attention next. The Click & Tweet plugin allows site owners to highlight what they consider to be the most “tweetable” phrases. Now when the reader comes across a key sentence or phrase that the author has highlighted, he can simply click the link at the end of the sentence and send the pre-formatted tweet. You have the ability to format the tweet to include a mention of your Twitter username, add hashtags, and a link back to your website.
     17
     18###Documentation
     19Read the documentation here:
     20
     21[Documentation](https://space-studio.gitbooks.io/click-tweet-plugin/content/)
    1722
    1823== Installation ==
     
    3944
    4045== Changelog ==
     46= 0.2.0 =
     47* Added the option to create tweet cards.
     48* Added layout and positioning settings, allowing you to edit where you want the twitter logo on both inline tweets and tweet cards.
     49* Added a related username field to allow addition of related username.
     50* Bug Fixes
     51
    4152= 0.1.0 =
    4253* Initial release of plugin.
Note: See TracChangeset for help on using the changeset viewer.