Plugin Directory

Changeset 1253854


Ignore:
Timestamp:
09/26/2015 06:03:43 AM (10 years ago)
Author:
jtmorris
Message:

v1.6.0

Location:
tweetthis/trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • tweetthis/trunk/assets/css/admin.css

    r1205394 r1253854  
    7474            vertical-align: bottom;
    7575        }
     76        #TT_sidebar div.TT_tweetdis_ad {
     77            text-align: center;
     78            margin-top: 30px;
     79        }
    7680
    7781#TT_content {
     
    111115}
    112116
     117#TT-shortcode-creator-dialog .loading {
     118    background: #CCC url( '../images/ajax-loader.gif' ) no-repeat 50% 50%;
     119    -webkit-transition: background-color 0;
     120    transition: background-color 0;
     121}
     122
    113123/* Responsive changes for narrow screens */
    114124@media (max-width: 1250px) {
     
    123133        margin-right: auto;
    124134        min-height: 0;
     135    }
     136
     137    /* TweetDis ad switch */
     138    #TT_tweetdis_square {
     139        display: none;
     140    }
     141    #TT_tweetdis_wide {
     142        display: inline;
     143    }
     144}
     145
     146@media (min-width: 1250px) {
     147    /* TweetDis ad switch */
     148    #TT_tweetdis_square {
     149        display: inline;
     150    }
     151    #TT_tweetdis_wide {
     152        display: none;
    125153    }
    126154}
  • tweetthis/trunk/assets/css/public-main.css

    r1128858 r1253854  
    4848            margin-right: 2px;
    4949            margin-bottom: -4px;
    50 
     50        }
     51        .TT_wrapper a.TT_tweet_link img {
    5152            display: inline;  /* In case themes override default img display */
    5253        }
  • tweetthis/trunk/assets/css/tinymce-dialog.css

    r1148668 r1253854  
    66 * http://stackoverflow.com/a/16186970/2523144
    77 */
    8  .ui-widget-overlay {
    9     z-index: 10000 !important;
     8 .tt-jqui .ui-widget-overlay {
     9    z-index: 100000 !important;
    1010    position: fixed !important;
    1111 }
    12  .ui-dialog {
    13     z-index: 100001 !important;
     12 .tt-jqui .ui-dialog {
     13    z-index: 100099 !important;
    1414 }
    1515
  • tweetthis/trunk/assets/js/tinymce-dialog.js

    r1205394 r1253854  
    2424    var accordionSections;
    2525
     26    var previewTimeout = false;
     27
    2628
    2729    $(window).load(function() { //  Only execute the following after the entire page has loaded.
     
    3537        inputs = {
    3638            'text': $('#TT_tinymce_dialog_text'),
     39            'display_mode': $('#TT_tinymce_dialog_display_mode'),
    3740            'url': $('#TT_tinymce_dialog_url_override'),
    3841            'twitter_handles': $('#TT_tinymce_dialog_twitter_handle_override'),
     
    9396
    9497            //  Get passed arguments
     98            post_id = args['post_id'];
    9599            post_url = args['post_url'];
    96100            post_url_is_placeholder = args['post_url_is_placeholder'];
     
    149153
    150154            //  On text change, update preview
    151             inputs['text'].on('change keyup paste', function() {
    152                 preview.val(tt_preview_string()).change();
     155            inputs['text'].on('input keyup paste', function() {
     156                tt_preview_string(function(text) {
     157                    preview.val(text).change();
     158                });
    153159            });
    154160
    155161            //  On URL change, update preview and hide any URL warnings
    156             inputs['url'].on('change keyup paste', function() {
    157                 preview.val(tt_preview_string()).change();
     162            inputs['url'].on('input keyup paste', function() {
     163                tt_preview_string(function(text) {
     164                    preview.val(text).change();
     165                });
    158166
    159167                if( inputs['url'].val() === post_url && post_url_is_placeholder ) {
     
    166174
    167175            //  On Twitter handles change, update preview
    168             inputs['twitter_handles'].on('change keyup paste', function() {
    169                 preview.val(tt_preview_string()).change();
     176            inputs['twitter_handles'].on('input keyup paste', function() {
     177                tt_preview_string(function(text) {
     178                    preview.val(text).change();
     179                });
    170180            });
    171181
    172182            //  On hidden hashtags change, update preview
    173             inputs['hidden_hashtags'].on('change keyup paste', function() {
    174                 preview.val(tt_preview_string()).change();
     183            inputs['hidden_hashtags'].on('input keyup paste', function() {
     184                tt_preview_string(function(text) {
     185                    preview.val(text).change();
     186                });
    175187            });
    176188
    177189            //  On hidden URLS change, update preview
    178             inputs['hidden_urls'].on('change keyup paste', function() {
    179                 preview.val(tt_preview_string()).change();
     190            inputs['hidden_urls'].on('input keyup paste', function() {
     191                tt_preview_string(function(text) {
     192                    preview.val(text).change();
     193                });
    180194            });
    181195
    182196            //  On remove checkbox changes, update preview
    183197            inputs['remove_twitter_handles'].on('change keyup paste', function() {
    184                 preview.val(tt_preview_string()).change();
     198                tt_preview_string(function(text) {
     199                    preview.val(text).change();
     200                });
    185201
    186202                //  Also, disable the override fields for good measure
     
    193209            });
    194210            inputs['remove_url'].on('change keyup paste', function() {
    195                 preview.val(tt_preview_string()).change();
     211                tt_preview_string(function(text) {
     212                    preview.val(text).change();
     213                });
    196214
    197215                //  Also, disable the override fields for good measure
     
    204222            });
    205223            inputs['remove_hidden_hashtags'].on('change keyup paste', function() {
    206                 preview.val(tt_preview_string()).change();
     224                tt_preview_string(function(text) {
     225                    preview.val(text).change();
     226                });
    207227
    208228                //  Also, disable the hidden hashtags box for good measure
     
    215235            });
    216236            inputs['remove_hidden_urls'].on('change keyup paste', function() {
    217                 preview.val(tt_preview_string()).change();
     237                tt_preview_string(function(text) {
     238                    preview.val(text).change();
     239                });
    218240
    219241                //  Also, disable the hidden hashtags box for good measure
     
    231253                //  Counter
    232254                var text = auto_url_shortener_length_equiv($(this).val());
    233                 var text = $(this).val();
     255                //var text = $(this).val();
    234256
    235257                var count = text.length;
    236258                if (count > 140) {
    237259                    var wrap = '<span style="color: red; font-size: 1.3em; ">';
     260                    var warning = '';
    238261
    239262                    //  Too long, truncate the preview
     
    243266                    var wrap = '<span style="color: red;">';
    244267                    var warning = '';
     268
     269                    //  Nearing too long, truncate the preview so URLs are shortened
     270                    tt_truncate_preview();
    245271                }
    246272                else if (count >= 120) {
     
    283309                if( get_clean_hidden_urls(true) ) {
    284310                    shortcode += ' hidden_urls="' + (get_clean_hidden_urls()) + '"';
     311                }
     312                if( get_clean_display_mode() !== false ) {
     313                    shortcode += ' display_mode="' + (get_clean_display_mode()) + '"';
    285314                }
    286315
     
    444473    ***********************************************/
    445474    /**
    446      * Generates and returns a string representation of what the user's Tweet This box
     475     * Generates and inserts into preview a string representation of what the user's Tweet This box
    447476     * will tweet out.
    448      *
    449      * @return   {string}   String representation of the resultant tweet.
    450477     */
    451     function tt_preview_string() {
    452         var text = inputs['text'].val();
    453 
    454         //  Are we supposed to remove anything from the tweet?
    455         var remove_twits           = inputs['remove_twitter_handles'].prop('checked');
    456         var remove_url             = inputs['remove_url'].prop('checked');
    457         var remove_hidden_hashtags = inputs['remove_hidden_hashtags'].prop('checked');
    458         var remove_hidden_urls     = inputs['remove_hidden_urls'].prop('checked');
    459 
    460         //  Was Twitter handles, default hashtags, or the URL overriden?
    461         //  If so, we want those.  If not, we want the defaults.
    462         var twits = default_twitter_handles;
    463         var hashtags = default_hidden_hashtags;
    464         var hidden_urls = default_hidden_urls;
    465         var url = post_url;
    466 
    467         if( get_clean_twitter_handles() || remove_twits ) {
    468             twits = get_clean_twitter_handles();
    469         }
    470         if( get_clean_url() || remove_url ) {
    471             url = get_clean_url();
    472         }
    473         if( get_clean_hidden_hashtags() || remove_hidden_hashtags ) {
    474             hashtags = get_clean_hidden_hashtags();
    475         }
    476         if( get_clean_hidden_urls() || remove_hidden_urls ) {
    477             hidden_urls = get_clean_hidden_urls();
    478         }
    479 
    480         var retval = text;
    481         if(hashtags) {
    482             retval += ' ' + hashtags;
    483         }                   
    484         if ( hidden_urls ) {
    485             retval += ' ' + hidden_urls;
    486         }
    487         if ( url ) {
    488             retval += ' ' + url;
    489         }
    490         if (twits) {
    491             retval +=' via ' + twits;
    492         }
    493 
    494         return retval;
    495     }
     478    function tt_preview_string( funcToRun ) {
     479        //  Reset our AJAX timeout countdown by clearing the old one, then
     480        //  creating a new one.
     481        if( previewTimeout ) {
     482            clearTimeout( previewTimeout );
     483        }
     484
     485        $("#TT_tinymce_tweet_preview").addClass("loading");
     486        previewTimeout = setTimeout(function() {
     487            tt_preview_string_helper( funcToRun );
     488        }, 1500);
     489    }
     490        function tt_preview_string_helper( funcToRun ) {
     491            var data = {};
     492            data.text = get_clean_text();
     493            data.post_id = post_id;
     494
     495            //  Are we supposed to remove anything from the tweet?
     496            data.remove_twitter_handles = inputs['remove_twitter_handles'].prop('checked');
     497            data.remove_url             = inputs['remove_url'].prop('checked');
     498            data.remove_hidden_hashtags = inputs['remove_hidden_hashtags'].prop('checked');
     499            data.remove_hidden_urls     = inputs['remove_hidden_urls'].prop('checked');
     500
     501            //  Was Twitter handles, default hashtags, or the URL overriden?
     502            //  If so, we want those.  If not, we want the defaults.
     503            data.custom_twitter_handles = default_twitter_handles;
     504            data.custom_hidden_hashtags = default_hidden_hashtags;
     505            data.custom_hidden_urls     = default_hidden_urls;
     506            data.custom_url             = '';
     507
     508            if( get_clean_twitter_handles() || data.remove_twitter_handles ) {
     509                data.custom_twitter_handles = get_clean_twitter_handles();
     510            }
     511            if( get_clean_url() || data.remove_url ) {
     512                data.custom_url = get_clean_url();
     513            }
     514            if( get_clean_hidden_hashtags() || data.remove_hidden_hashtags ) {
     515                data.custom_hidden_hashtags = get_clean_hidden_hashtags();
     516            }
     517            if( get_clean_hidden_urls() || data.remove_hidden_urls ) {
     518                data.custom_hidden_urls = get_clean_hidden_urls();
     519            }
     520
     521            //  Define actions
     522            data.action = 'tt_ajax';
     523            data.tt_action = 'get_tweet_content';
     524
     525            //  Use AJAX to generate text as it will be generated in the final product
     526            $.ajax({
     527                type: "post",
     528                url: ajaxurl,
     529                dataType: 'json',
     530                //dataType: 'text', //  Uncomment this and look at JS Console output to debug PHP errors
     531                data: data,
     532                success: function(retval, status) {
     533                    logToConsole("Tweet preview content retrieved successfully.");
     534                    logToConsole("AJAX data: " + JSON.stringify(retval));
     535                    funcToRun(retval.data);
     536                },
     537                error: function(jqXHR, textStatus, errorThrown) {
     538                    logToConsole("Error getting preview content using AJAX.");
     539                    logToConsole("AJAX error message: " + errorThrown);
     540                },
     541                complete: function() {
     542                    //  Remove loading GIF
     543                    $("#TT_tinymce_tweet_preview").removeClass("loading");
     544                }
     545            });
     546        }
    496547
    497548    /**
     
    499550     */
    500551    function tt_truncate_preview() {
    501         preview.val(preview.val().substr(0,140));   //  First 140 characters
     552        var text = preview.val();
     553
     554        if( text.length > 130 ) {
     555            //  We're nearing a full tweet. Let's shorten the URLs visually now.
     556            //  Shorten URLS
     557            text = auto_url_shortener_length_equiv(text);
     558            logToConsole( text );
     559        }
     560
     561        //  Truncate
     562        preview.val(text.substr(0,140));    //  First 140 characters
    502563    }
    503564
     
    602663    }
    603664
     665    function get_clean_display_mode() {
     666        dm = inputs['display_mode'].val();
     667
     668        if( dm == 'box' || dm == 'button_link' ) {
     669            return dm;
     670        }
     671        else {
     672            return false;
     673        }
     674    }
     675
    604676    /**
    605677     * Replaces detected links with 22 characters.  Twitter automatically shortens links
     
    612684     */
    613685    function auto_url_shortener_length_equiv(text) {
    614         var shrt = text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi, '1234567890123456789012');
    615         return shrt;
     686        var matches = text.match(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi);
     687        if( matches ) {
     688            for( var index in matches ) {
     689                var m = matches[index];
     690                text = text.replace(m, m.substr(0,18) + ' ...');
     691            }
     692        }
     693
     694        return text;
    616695    }
    617696
     
    712791
    713792        //  Load defaults into preview
    714         preview.val(tt_preview_string());
     793        tt_preview_string(function(text) {
     794            preview.val(text);
     795        });
    715796
    716797        //  Ensure all change listeners know we changed the preview
  • tweetthis/trunk/includes/ajax-actions.php

    r1147416 r1253854  
    11<?php
    22/**
    3  * This file contains the handlers for all AJAX requests. 
     3 * This file contains the handlers for all AJAX requests.
    44 * IT MUST ONLY OUTPUT JSON STRINGS FOR RECOGNITION DURING AJAX CALLS
    55 */
     
    2121         */
    2222        public static function navigate() {
     23            ob_start();
    2324            if( !empty( $_POST['tt_action'] )  ) {
    2425                $action = $_POST['tt_action'];
     
    3031                $action = '';
    3132            }
    32            
     33            ob_end_clean();
     34
    3335            switch( $action ) {
    3436                case 'get_tinymce_dialog_params':
    3537                    self::get_tinymce_dialog_params();
    3638                    break;
     39                case 'get_tweet_content':
     40                    self::get_tweet_content();
     41                    break;
    3742            }   //  end switch
    3843
    39             die();
     44            wp_die();
    4045        }   //  end function navigate( ...
    4146
    42        
     47
    4348
    4449        /////////////////////////
    4550        /// Handler Functions ///
    4651        /////////////////////////
     52        //  Since this crap is done via AJAX, any "requiring" or "including" has to be
     53        //  done when the AJAX is called.  Meaning it can't be done at the top of the page,
     54        //  it has to be done in the actual function called... Here.  Don't believe me?
     55        //  Try moving this to the top of the file and running the plugin.  It will
     56        //  die in stupendous glory.
     57        //
     58        //  In addition, because this is an AJAX handler page called from a TinyMCE dialog
     59        //  box, there's some missing WordPress contextual information that can cause
     60        //  unexpected output when we include/require certain files.
     61        //  Therefore, the use of an output buffer is highly recommended, and necessary
     62        //  in certain cases.  Buffer any output during includes/requires, then erase
     63        //  the buffer, then output what you want to output.
    4764
    4865        protected static function get_tinymce_dialog_params() {
    49             //  Since this crap is done via AJAX, any "requiring" or "including" has to be
    50             //  done when the AJAX is called.  Meaning it can't be done at the top of the page,
    51             //  it has to be done in the actual function called... Here.  Don't believe me?
    52             //  Try moving this to the top of the file and running the plugin.  It will
    53             //  die in stupendous glory.
    54             // 
    55             //  In addition, because this is an AJAX handler page called from a TinyMCE dialog
    56             //  box, there's some missing WordPress contextual information that can cause
    57             //  unexpected output when we include/require certain files.
    58             //  Therefore, the use of an output buffer is highly recommended, and necessary
    59             //  in certain cases.  Buffer any output during includes/requires, then erase
    60             //  the buffer, then output what you want to output.
    6166            ob_start();
    62             require( './tools.php' );
     67            require( dirname(__FILE__) . '/tools.php' );
    6368            ob_end_clean();
    6469
     
    6772            echo json_encode( $sets );
    6873        }
    69     }   //  end class   
     74
     75        protected static function get_tweet_content() {
     76            ob_start();
     77            require( dirname(__FILE__) . '/share-handler.php' );
     78            ob_end_clean();
     79
     80            $p = $_POST;
     81            $defaults = array( 'text'=>'', 'custom_url'=>'', 'custom_twitter_handles'=>'',
     82                'custom_hidden_hashtags'=>'', 'custom_hidden_urls'=>'', 'remove_twitter_handles'=>'',
     83                'remove_url'=>'', 'remove_hidden_hashtags'=>'', 'remove_hidden_urls'=>'' );
     84
     85            //  Merge passed values with defaults
     86            $p = array_merge( $defaults, $p );
     87
     88            //  Convert empty values to boolean false to play along nicely with TT_Share_Handler
     89            $p = TT_Tools::empty_to_false( $p );
     90
     91
     92            $SH = new TT_Share_Handler( $p['text'], $p['custom_url'], $p['custom_twitter_handles'],
     93                $p['custom_hidden_hashtags'], $p['custom_hidden_urls'], $p['remove_twitter_handles'],
     94                $p['remove_url'], $p['remove_hidden_hashtags'], $p['remove_hidden_urls'], $p['post_id'] );
     95
     96            $data = $SH->generate_actual_text();
     97            //  Generate JSON response
     98            $json = json_encode( array(
     99                'status' => true,
     100                'data'   => $data
     101            ) );
     102
     103            echo $json;
     104        }
     105    }   //  end class
    70106}   //  end if ( !class_exists( ...
  • tweetthis/trunk/includes/settings.php

    r1205394 r1253854  
    226226            add_settings_field(
    227227                'tt_display_mode',          //  Setting ID
    228                 'Display Mode',             //  Setting Title
     228                'Default Display Mode',     //  Setting Title
    229229                array( 'TT_Settings',
    230230                    'field_helper_radio' ), //  Content Callback
     
    497497            );
    498498
     499            //  Template
     500            add_settings_field(
     501                'tt_template',
     502                'Tweet Element Template',
     503
     504                array( 'TT_Settings',
     505                    'field_helper_textarea' ),
     506
     507                TT_FILENAME,
     508                'tweet_this_advanced',
     509
     510                array(
     511                    'name' => 'template',
     512
     513                    'help_text' => 'Customize the order of elements, and their separators, in resulting tweets. Template tags (in the following format "{{ separator {tag_name}}}") are replaced with the corresponding content. Leave blank to use default. Default: "{{{text}}}{{ {hidden_hashtags}}}{{ {hidden_urls}}}{{ {post_url}}}{{ via {twitter_handles}}}"<br /><a href="http://tweetthis.jtmorris.net/posts/introducing-the-tweet-element-template/" target="_blank">Read this article</a> for more detail and examples.',
     514
     515                    'style'=>'min-width: 600px;'
     516                )
     517            );
     518
    499519            //  Custom CSS
    500520            add_settings_field(
     
    513533                    'help_text'=>'Override default CSS rules for "Tweet This".',
    514534
    515                     'style'=>'min-width: 500px; min-height: 300px;'
     535                    'style'=>'min-width: 600px; min-height: 300px;',
    516536                )
    517537            );
     
    782802                        <li>Improve this plugin on <a target="_blank" href='https://github.com/jtmorris/tweet-this'>GitHub</a></li>
    783803                    </ul>
     804                </div>
     805
     806                <div class='TT_sidebar_box'>
     807                    <div class="TT_tweetdis_ad">
     808                        <a target="_blank" href="http://jtmorris.timsoulo.hop.clickbank.net">
     809                            <img id="TT_tweetdis_square" src="<?php echo TT_ROOT_URL; ?>/assets/images/tweetdis-square.jpg" />
     810                            <img id="TT_tweetdis_wide" src="<?php echo TT_ROOT_URL; ?>/assets/images/tweetdis-wide.jpg" />
     811                        </a>
     812                    </div>
    784813                </div>
    785814
     
    816845                </div>
    817846                <div class='TT_sidebar_box'>
    818                     <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    819                     <!-- Tweet This Dashboard -->
    820                     <ins class="adsbygoogle"
    821                          style="display:inline-block;width:336px;height:280px"
    822                          data-ad-client="ca-pub-4623469134243566"
    823                          data-ad-slot="9769490937"></ins>
    824                     <script>
    825                     (adsbygoogle = window.adsbygoogle || []).push({});
    826                     </script>
    827                 </div>
    828                 <div class='TT_sidebar_box'>
    829847                    <h3>Get Help / Report a Bug</h3>
    830848                    <p>
  • tweetthis/trunk/includes/setup.php

    r1205394 r1253854  
    188188                                autoOpen: false,
    189189                                modal: true,
    190                                 minHeight: 600,
    191                                 maxHeight: 900,
     190                                maxHeight: 950,
    192191                                resizable: false,
    193192                                width: 650,
     
    220219                    include( TT_ROOT_PATH . '/includes/tinymce-dialog.html' );
    221220                }
    222             }           
     221            }
    223222            public static function hooks_helper_tinymce_plugin( $plugin_array ) {
    224223                //  We need to be in the admin, editing a post or page to include
     
    387386                    'button_location' => 'row1',
    388387                    'insert_shortcode_behavior' => 'auto',
    389                     'display_mode' => 'box'
     388                    'display_mode' => 'box',
     389                    'template' => '{{{text}}}{{ {hidden_hashtags}}}{{ {hidden_urls}}}{{ {post_url}}}{{ via {twitter_handles}}}'
    390390                );
    391391
  • tweetthis/trunk/includes/share-handler.php

    r1203632 r1253854  
    1414        protected $my_url_is_placeholder = false;
    1515        protected $my_twitter_handles = null;
     16        protected $my_post_id = 0;
    1617
    1718        /**
     
    2627         * @param boolean $remove_hidden_hashtags Whether to include hidden hashtags or not.
    2728         * @param boolean $remove_hidden_urls     Whether to include hidden URLS or not.
     29         * @param int     $post_id                The ID# of the post. Defaults to zero, which to WordPress means
     30         *                                        the current post. When using AJAX, post ID must be specified as there
     31         *                                        is no current post context.
    2832         */
    2933        public function __construct( $text='', $custom_url=false, $custom_twitter_handles=false,
    3034            $custom_hidden_hashtags=false, $custom_hidden_urls=false, $remove_twitter_handles=false, $remove_url=false,
    31             $remove_hidden_hashtags=false, $remove_hidden_urls=false ) {
     35            $remove_hidden_hashtags=false, $remove_hidden_urls=false, $post_id=0 ) {
    3236
    3337            //  Get values
    34             $this->my_text = $text;
    35 
    36             if ( $custom_url ) {
     38            $this->my_text    = $text;
     39            $this->my_post_id = $post_id;
     40
     41            if ( !empty( $custom_url ) ) {
    3742                $this->my_url = $custom_url;
    3843            }
    3944
    40             if ( $custom_twitter_handles ) {
     45            if ( !empty( $custom_twitter_handles ) ) {
    4146                $this->my_twitter_handles = $custom_twitter_handles;
    4247            }
    4348
    44             if ( $custom_hidden_hashtags ) {
     49            if ( !empty( $custom_hidden_hashtags ) ) {
    4550                $this->my_hidden_hashtags = $custom_hidden_hashtags;
    4651            }
    4752
    48             if ( $custom_hidden_urls ) {
     53            if ( !empty( $custom_hidden_urls ) ) {
    4954                $this->my_hidden_urls = $custom_hidden_urls;
    5055            }
    5156
    5257            //  If we're removing anything, remove it
    53             if( $remove_twitter_handles ) {
     58            //  The variable may contain string representation of booleans (e.g. "false"),
     59            //  so filter the variable.
     60            if( filter_var( $remove_twitter_handles, FILTER_VALIDATE_BOOLEAN ) ) {
    5461                $this->my_twitter_handles = '';
    5562            }
    5663
    57             if( $remove_url ) {
     64            if( filter_var( $remove_url, FILTER_VALIDATE_BOOLEAN ) ) {
    5865                $this->my_url = '';
    5966            }
    6067
    61             if( $remove_hidden_hashtags ) {
     68            if( filter_var( $remove_hidden_hashtags, FILTER_VALIDATE_BOOLEAN ) ) {
    6269                $this->my_hidden_hashtags = '';
    6370            }
    6471
    65             if( $remove_hidden_urls ) {
     72            if( filter_var( $remove_hidden_urls, FILTER_VALIDATE_BOOLEAN ) ) {
    6673                $this->my_hidden_urls = '';
    6774            }
     
    94101                $retval .= '<div class="TT_text">';
    95102                    $retval .= '<a class="TT_tweet_link" href="' . $url . '" target="_blank">';
    96                         $retval .= $this->generate_text();
     103                        $retval .= $this->generate_visible_text();
    97104                    $retval .= '</a>';
    98105                $retval .= '</div>';
     
    138145
    139146            $retval .= '<span class="TT_wrapper">';
    140                 $retval .= '<a title="' . htmlentities( $this->generate_text() ) . '" class="TT_tweet_link" href="' . $url . '" target="_blank">';
     147                $retval .= '<a title="' . htmlentities( $this->generate_visible_text() ) . '" class="TT_tweet_link" href="' . $url . '" target="_blank">';
    141148                    if( $image_too ) {
    142149                        $retval .= '<img src="' . TT_ROOT_URL . 'assets/images/twitter-icons/' . $options['twitter_icon'] . '.png" />';
     
    152159
    153160        protected function generate_share_url() {
    154             //  Put all the tweet pieces into an array which we'll implode with a space as glue
    155             $ttext = array(
    156                 $this->generate_text(),
    157                 $this->generate_hidden_hashtags_for_url(),
    158                 $this->generate_hidden_urls_for_url(),
    159                 $this->generate_post_url(),
    160                 $this->generate_twitter_handles_for_url()
    161             );
    162             //  Remove any empty array entries
    163             $ttext = array_filter( $ttext );
    164             //  Implode the tweet array into a string.
    165             $ttext = implode( ' ', $ttext );
    166 
     161            $ttext = self::generate_actual_text();
    167162
    168163            //  Now, generate the URL
     
    185180        }
    186181
    187         protected function generate_text() {
     182        public function generate_actual_text() {
     183            //  Get tweet template
     184            $options = get_option( 'tt_plugin_options' );
     185
     186            $template = null;
     187            if( array_key_exists( 'template', $options ) ) {
     188                $template = $options['template'];
     189            }
     190            if( empty( $template ) ) {  //  Use default value
     191                $template = '{{{text}}}{{ {hidden_hashtags}}}{{ {hidden_urls}}}{{ {post_url}}}{{ via {twitter_handles}}}';
     192            }
     193
     194            //  Substitute values in place of template tags
     195            $telem_names = array(
     196                '{text}',
     197                '{hidden_hashtags}',
     198                '{hidden_urls}',
     199                '{post_url}',
     200                '{twitter_handles}'
     201            );
     202            $telem_vals = array(
     203                $this->generate_visible_text(),
     204                $this->generate_hidden_hashtags_for_url(),
     205                $this->generate_hidden_urls_for_url(),
     206                $this->generate_post_url( $this->my_post_id ),
     207                $this->generate_twitter_handles_for_url()
     208            );
     209
     210            $re = "/[{{].*?.*?}}{2,2}/";
     211            preg_match_all( $re, $template, $split_t ); //  Split by template tag
     212            $split_t = $split_t[0];
     213            //  $split_t should have array like this:
     214            //      array(
     215            //          {{{text}}},
     216            //          {{ {hidden_hashtags}}},
     217            //          {{ {hidden_urls}}},
     218            //          {{ {post_url}}},
     219            //          {{ via {twitter_handles}}}
     220            //      )
     221            foreach( $split_t as $tkey=>$t ) {
     222                foreach( $telem_names as $nkey=>$name ) {
     223                    //  Does $t even contain this name?
     224                    if( strpos( $t, $name ) !== false ) {
     225                        //  Yes, this name is in our $t... process it.
     226                        $value = $telem_vals[$nkey];
     227                        if( !empty( $value ) ) {
     228                            //  Replace template tag with this value
     229                            $split_t[$tkey] = str_replace( $name, $value, $t );
     230                        }
     231                        else {
     232                            //  No value to put in... delete this entry altogether
     233                            unset( $split_t[$tkey] );
     234                        }
     235                    }
     236                }
     237            }
     238
     239            //  Delete template tag openers and closers, and remove altogether if nothing is left
     240            foreach( $split_t as $i=>$v ) {
     241                $nv = str_replace( '{{', '', $v );
     242                $nv = str_replace( '}}', '', $nv );
     243
     244                if( empty( $nv ) ) {
     245                    //  This thing is empty... delete it
     246                    unset( $split_t[$i] );
     247                }
     248                else {
     249                    //  Replace with this new value
     250                    $split_t[$i] = $nv;
     251                }
     252            }
     253
     254            //  Implode the string
     255            $end_result = implode( '', $split_t );
     256
     257            return $end_result;
     258        }
     259
     260        protected function generate_visible_text() {
    188261            return $this->my_text;
    189262        }
     
    200273            if ( !empty($this->my_twitter_handles) ) {
    201274                if ( $include_via ) {
    202                     return "via " . $this->my_twitter_handles;
     275                    return $this->my_twitter_handles;
    203276                }
    204277                else {
     
    261334
    262335                if ( $options['use_shortlink'] ) {
     336                    echo "HERE";
    263337                    //  Yes, we need a shortlink.
    264338
  • tweetthis/trunk/includes/tinymce-dialog.html

    r1147416 r1253854  
    99                        <td>
    1010                            <textarea id="TT_tinymce_dialog_text"></textarea>
     11                        </td>
     12                    </tr>
     13                    <tr>
     14                        <th scope="row">Display Mode</th>
     15                        <td>
     16                            <select id="TT_tinymce_dialog_display_mode">
     17                                <option value="" selected="selected">Default</option>
     18                                <option value="box">Box</option>
     19                                <option value="button_link">Button Link</option>
     20                            </select>
     21                            <p class='tt_admin_help_text'>
     22                                Change the display mode of this Tweet This shortcode.
     23                            </p>
    1124                        </td>
    1225                    </tr>
  • tweetthis/trunk/includes/tools.php

    r1205394 r1253854  
    77if ( !class_exists( 'TT_Tools' ) ) {
    88    class TT_Tools {
     9        /**
     10         * If variable is empty (checked using PHP empty()), returns boolean false. Otherwise
     11         * returns variable content. Iterates across all elements if $var is array and changes
     12         * empty values to boolean false.
     13         * @param  mixed $var The variable to check. If array, it is checked element-wise.
     14         * @return mixed      Either boolean false if single $var is empty, $var with empty elements
     15         * set to false if array, or $var itself.
     16         */
     17        public static function empty_to_false( $var ) {
     18            if( empty( $var ) ) {
     19                $var = false;
     20            }
     21            else if( is_array( $var ) ) {
     22                foreach( $var as $key=>$v ) {
     23                    $var[$key] = self::empty_to_false( $v );
     24                }
     25            }
     26
     27            return $var;
     28        }
     29
    930        /**
    1031         * Parses the ./tweet-this/assets/images/twitter-icons directory for
     
    212233
    213234                if( is_array( $urlarr ) ) { //  Shortlink w/ qualifying info in array
    214                     $post_url = $urlarr['shortlink'];
    215                     $is_placeholder = $url['is_placeholder'];
     235                    $post_url = self::get_arr_value( 'shortlink', $urlarr, '' );
     236                    $is_placeholder = self::get_arr_value( 'is_placeholder', $urlarr, false );
    216237                }
    217238                else {  //  Nothing fancy, just the URL as a string
     
    221242            }
    222243            catch( Exception $e ) {
     244                $id = 0;
    223245                $post_url = TT_Tools::placeholder_shortlink();
    224246                $is_placeholder = false;
     
    227249            //  default Twitter handles and hidden hashtags
    228250            $options = get_option( 'tt_plugin_options' );
    229             $twits = $options['default_twitter_handles'];
    230             $hashtags = $options['default_hidden_hashtags'];
    231             $hidden_urls = $options['default_hidden_urls'];
     251            $twits = self::get_arr_value( 'default_twitter_handles', $options, '' );
     252            $hashtags = self::get_arr_value( 'default_hidden_hashtags', $options, '' );
     253            $hidden_urls = self::get_arr_value( 'default_hidden_urls', $options, '' );
    232254
    233255            //  dialog customization options
    234             $insert_sc_behavior = $options['insert_shortcode_behavior'];
    235             $hide_preview = $options['disable_preview'];
    236             $hide_handles = $options['disable_handles'];
    237             $hide_post_url = $options['disable_post_url'];
    238             $hide_hidden = $options['disable_hidden'];
    239             $hide_char_count = $options['disable_char_count'];
    240 
    241            
     256            $insert_sc_behavior = self::get_arr_value( 'insert_shortcode_behavior', $options, '' );
     257            $hide_preview = self::get_arr_value( 'disable_preview', $options, '' );
     258            $hide_handles = self::get_arr_value( 'disable_handles', $options, '' );
     259            $hide_post_url = self::get_arr_value( 'disable_post_url', $options, '' );
     260            $hide_hidden = self::get_arr_value( 'disable_hidden', $options, '' );
     261            $hide_char_count = self::get_arr_value( 'disable_char_count', $options, '' );
    242262
    243263            return array(
     264                'post_id'  => $id,
    244265                'post_url' => $post_url,
    245266                'post_url_is_placeholder' => $is_placeholder,
     
    255276            );
    256277        }
     278
     279        /**
     280         * Returns the value in the given array with the given key. If no such
     281         * array entry, $default is returned. Essentially, this automates the
     282         * array_key_exists( $key, $arr ) ? $arr[$key] : 'foobar' type checks
     283         * @param  string $key     The array key.
     284         * @param  array  $arr     The array.
     285         * @param  mixed  $default The value to return if array key doesn't exist. Defaults to null.
     286         * @return mixed           The array value or $default if array key doesn't exist.
     287         */
     288        public static function get_arr_value( $key, $arr, $default = null ) {
     289            if( array_key_exists( $key, $arr) ) {
     290                return $arr[$key];
     291            }
     292            else {
     293                return $default;
     294            }
     295        }
    257296    }   //  end class
    258297}   //  end if( !class_exists( ...
  • tweetthis/trunk/readme.txt

    r1205394 r1253854  
    44Tags: twitter, tweet, social, sharing
    55Requires at least: 3.9
    6 Tested up to: 4.2.2
    7 Stable tag: 1.5.2
     6Tested up to: 4.3.1
     7Stable tag: 1.6.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    105105
    106106== Changelog ==
     107= 1.6.0 =
     108* Added tweet templating capability. Read more about this here: [http://tweetthis.jtmorris.net/posts/introducing-the-tweet-element-template/](http://tweetthis.jtmorris.net/posts/introducing-the-tweet-element-template/).
     109* Circumvented jQuery UI interference from Express Curate plugin.
     110* Fixed PHP notices interfering with AJAX calls when WP_DEBUG is enabled.
     111* Added display mode override option to Shortcode Creator Dialog box.
     112* Moved generation of previews in Shortcode Creator Dialog box to the same method that generates resulting tweet, thus reducing potential for bugs and simplifying future extensability.
    107113= 1.5.2 =
    108114* Fix jQuery UI theme scope issues introduced in last update.
  • tweetthis/trunk/tweetthis.php

    r1205394 r1253854  
    44 * Plugin URI: http://tweetthis.jtmorris.net
    55 * Description: Tweet This offers easily embedded, stylish tweetable content boxes in your posts and pages. Get your visitors sharing on Twitter today!
    6  * Version: 1.5.2
     6 * Version: 1.6.0
    77 * Author: John Morris
    88 * Author URI: http://jtmorris.net
Note: See TracChangeset for help on using the changeset viewer.