Changeset 1253854
- Timestamp:
- 09/26/2015 06:03:43 AM (10 years ago)
- Location:
- tweetthis/trunk
- Files:
-
- 2 added
- 12 edited
-
assets/css/admin.css (modified) (3 diffs)
-
assets/css/public-main.css (modified) (1 diff)
-
assets/css/tinymce-dialog.css (modified) (1 diff)
-
assets/images/tweetdis-square.jpg (added)
-
assets/images/tweetdis-wide.jpg (added)
-
assets/js/tinymce-dialog.js (modified) (16 diffs)
-
includes/ajax-actions.php (modified) (4 diffs)
-
includes/settings.php (modified) (5 diffs)
-
includes/setup.php (modified) (3 diffs)
-
includes/share-handler.php (modified) (8 diffs)
-
includes/tinymce-dialog.html (modified) (1 diff)
-
includes/tools.php (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
-
tweetthis.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tweetthis/trunk/assets/css/admin.css
r1205394 r1253854 74 74 vertical-align: bottom; 75 75 } 76 #TT_sidebar div.TT_tweetdis_ad { 77 text-align: center; 78 margin-top: 30px; 79 } 76 80 77 81 #TT_content { … … 111 115 } 112 116 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 113 123 /* Responsive changes for narrow screens */ 114 124 @media (max-width: 1250px) { … … 123 133 margin-right: auto; 124 134 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; 125 153 } 126 154 } -
tweetthis/trunk/assets/css/public-main.css
r1128858 r1253854 48 48 margin-right: 2px; 49 49 margin-bottom: -4px; 50 50 } 51 .TT_wrapper a.TT_tweet_link img { 51 52 display: inline; /* In case themes override default img display */ 52 53 } -
tweetthis/trunk/assets/css/tinymce-dialog.css
r1148668 r1253854 6 6 * http://stackoverflow.com/a/16186970/2523144 7 7 */ 8 . ui-widget-overlay {9 z-index: 10000 !important;8 .tt-jqui .ui-widget-overlay { 9 z-index: 100000 !important; 10 10 position: fixed !important; 11 11 } 12 . ui-dialog {13 z-index: 1000 01!important;12 .tt-jqui .ui-dialog { 13 z-index: 100099 !important; 14 14 } 15 15 -
tweetthis/trunk/assets/js/tinymce-dialog.js
r1205394 r1253854 24 24 var accordionSections; 25 25 26 var previewTimeout = false; 27 26 28 27 29 $(window).load(function() { // Only execute the following after the entire page has loaded. … … 35 37 inputs = { 36 38 'text': $('#TT_tinymce_dialog_text'), 39 'display_mode': $('#TT_tinymce_dialog_display_mode'), 37 40 'url': $('#TT_tinymce_dialog_url_override'), 38 41 'twitter_handles': $('#TT_tinymce_dialog_twitter_handle_override'), … … 93 96 94 97 // Get passed arguments 98 post_id = args['post_id']; 95 99 post_url = args['post_url']; 96 100 post_url_is_placeholder = args['post_url_is_placeholder']; … … 149 153 150 154 // 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 }); 153 159 }); 154 160 155 161 // 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 }); 158 166 159 167 if( inputs['url'].val() === post_url && post_url_is_placeholder ) { … … 166 174 167 175 // 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 }); 170 180 }); 171 181 172 182 // 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 }); 175 187 }); 176 188 177 189 // 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 }); 180 194 }); 181 195 182 196 // On remove checkbox changes, update preview 183 197 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 }); 185 201 186 202 // Also, disable the override fields for good measure … … 193 209 }); 194 210 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 }); 196 214 197 215 // Also, disable the override fields for good measure … … 204 222 }); 205 223 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 }); 207 227 208 228 // Also, disable the hidden hashtags box for good measure … … 215 235 }); 216 236 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 }); 218 240 219 241 // Also, disable the hidden hashtags box for good measure … … 231 253 // Counter 232 254 var text = auto_url_shortener_length_equiv($(this).val()); 233 var text = $(this).val();255 //var text = $(this).val(); 234 256 235 257 var count = text.length; 236 258 if (count > 140) { 237 259 var wrap = '<span style="color: red; font-size: 1.3em; ">'; 260 var warning = ''; 238 261 239 262 // Too long, truncate the preview … … 243 266 var wrap = '<span style="color: red;">'; 244 267 var warning = ''; 268 269 // Nearing too long, truncate the preview so URLs are shortened 270 tt_truncate_preview(); 245 271 } 246 272 else if (count >= 120) { … … 283 309 if( get_clean_hidden_urls(true) ) { 284 310 shortcode += ' hidden_urls="' + (get_clean_hidden_urls()) + '"'; 311 } 312 if( get_clean_display_mode() !== false ) { 313 shortcode += ' display_mode="' + (get_clean_display_mode()) + '"'; 285 314 } 286 315 … … 444 473 ***********************************************/ 445 474 /** 446 * Generates and returnsa string representation of what the user's Tweet This box475 * Generates and inserts into preview a string representation of what the user's Tweet This box 447 476 * will tweet out. 448 *449 * @return {string} String representation of the resultant tweet.450 477 */ 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 } 496 547 497 548 /** … … 499 550 */ 500 551 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 502 563 } 503 564 … … 602 663 } 603 664 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 604 676 /** 605 677 * Replaces detected links with 22 characters. Twitter automatically shortens links … … 612 684 */ 613 685 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; 616 695 } 617 696 … … 712 791 713 792 // Load defaults into preview 714 preview.val(tt_preview_string()); 793 tt_preview_string(function(text) { 794 preview.val(text); 795 }); 715 796 716 797 // Ensure all change listeners know we changed the preview -
tweetthis/trunk/includes/ajax-actions.php
r1147416 r1253854 1 1 <?php 2 2 /** 3 * This file contains the handlers for all AJAX requests. 3 * This file contains the handlers for all AJAX requests. 4 4 * IT MUST ONLY OUTPUT JSON STRINGS FOR RECOGNITION DURING AJAX CALLS 5 5 */ … … 21 21 */ 22 22 public static function navigate() { 23 ob_start(); 23 24 if( !empty( $_POST['tt_action'] ) ) { 24 25 $action = $_POST['tt_action']; … … 30 31 $action = ''; 31 32 } 32 33 ob_end_clean(); 34 33 35 switch( $action ) { 34 36 case 'get_tinymce_dialog_params': 35 37 self::get_tinymce_dialog_params(); 36 38 break; 39 case 'get_tweet_content': 40 self::get_tweet_content(); 41 break; 37 42 } // end switch 38 43 39 die();44 wp_die(); 40 45 } // end function navigate( ... 41 46 42 47 43 48 44 49 ///////////////////////// 45 50 /// Handler Functions /// 46 51 ///////////////////////// 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. 47 64 48 65 protected static function get_tinymce_dialog_params() { 49 // Since this crap is done via AJAX, any "requiring" or "including" has to be50 // 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 will53 // die in stupendous glory.54 //55 // In addition, because this is an AJAX handler page called from a TinyMCE dialog56 // box, there's some missing WordPress contextual information that can cause57 // unexpected output when we include/require certain files.58 // Therefore, the use of an output buffer is highly recommended, and necessary59 // in certain cases. Buffer any output during includes/requires, then erase60 // the buffer, then output what you want to output.61 66 ob_start(); 62 require( './tools.php' );67 require( dirname(__FILE__) . '/tools.php' ); 63 68 ob_end_clean(); 64 69 … … 67 72 echo json_encode( $sets ); 68 73 } 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 70 106 } // end if ( !class_exists( ... -
tweetthis/trunk/includes/settings.php
r1205394 r1253854 226 226 add_settings_field( 227 227 'tt_display_mode', // Setting ID 228 'D isplay Mode',// Setting Title228 'Default Display Mode', // Setting Title 229 229 array( 'TT_Settings', 230 230 'field_helper_radio' ), // Content Callback … … 497 497 ); 498 498 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 499 519 // Custom CSS 500 520 add_settings_field( … … 513 533 'help_text'=>'Override default CSS rules for "Tweet This".', 514 534 515 'style'=>'min-width: 500px; min-height: 300px;'535 'style'=>'min-width: 600px; min-height: 300px;', 516 536 ) 517 537 ); … … 782 802 <li>Improve this plugin on <a target="_blank" href='https://github.com/jtmorris/tweet-this'>GitHub</a></li> 783 803 </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> 784 813 </div> 785 814 … … 816 845 </div> 817 846 <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'>829 847 <h3>Get Help / Report a Bug</h3> 830 848 <p> -
tweetthis/trunk/includes/setup.php
r1205394 r1253854 188 188 autoOpen: false, 189 189 modal: true, 190 minHeight: 600, 191 maxHeight: 900, 190 maxHeight: 950, 192 191 resizable: false, 193 192 width: 650, … … 220 219 include( TT_ROOT_PATH . '/includes/tinymce-dialog.html' ); 221 220 } 222 } 221 } 223 222 public static function hooks_helper_tinymce_plugin( $plugin_array ) { 224 223 // We need to be in the admin, editing a post or page to include … … 387 386 'button_location' => 'row1', 388 387 'insert_shortcode_behavior' => 'auto', 389 'display_mode' => 'box' 388 'display_mode' => 'box', 389 'template' => '{{{text}}}{{ {hidden_hashtags}}}{{ {hidden_urls}}}{{ {post_url}}}{{ via {twitter_handles}}}' 390 390 ); 391 391 -
tweetthis/trunk/includes/share-handler.php
r1203632 r1253854 14 14 protected $my_url_is_placeholder = false; 15 15 protected $my_twitter_handles = null; 16 protected $my_post_id = 0; 16 17 17 18 /** … … 26 27 * @param boolean $remove_hidden_hashtags Whether to include hidden hashtags or not. 27 28 * @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. 28 32 */ 29 33 public function __construct( $text='', $custom_url=false, $custom_twitter_handles=false, 30 34 $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 ) { 32 36 33 37 // 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 ) ) { 37 42 $this->my_url = $custom_url; 38 43 } 39 44 40 if ( $custom_twitter_handles) {45 if ( !empty( $custom_twitter_handles ) ) { 41 46 $this->my_twitter_handles = $custom_twitter_handles; 42 47 } 43 48 44 if ( $custom_hidden_hashtags) {49 if ( !empty( $custom_hidden_hashtags ) ) { 45 50 $this->my_hidden_hashtags = $custom_hidden_hashtags; 46 51 } 47 52 48 if ( $custom_hidden_urls) {53 if ( !empty( $custom_hidden_urls ) ) { 49 54 $this->my_hidden_urls = $custom_hidden_urls; 50 55 } 51 56 52 57 // 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 ) ) { 54 61 $this->my_twitter_handles = ''; 55 62 } 56 63 57 if( $remove_url) {64 if( filter_var( $remove_url, FILTER_VALIDATE_BOOLEAN ) ) { 58 65 $this->my_url = ''; 59 66 } 60 67 61 if( $remove_hidden_hashtags) {68 if( filter_var( $remove_hidden_hashtags, FILTER_VALIDATE_BOOLEAN ) ) { 62 69 $this->my_hidden_hashtags = ''; 63 70 } 64 71 65 if( $remove_hidden_urls) {72 if( filter_var( $remove_hidden_urls, FILTER_VALIDATE_BOOLEAN ) ) { 66 73 $this->my_hidden_urls = ''; 67 74 } … … 94 101 $retval .= '<div class="TT_text">'; 95 102 $retval .= '<a class="TT_tweet_link" href="' . $url . '" target="_blank">'; 96 $retval .= $this->generate_ text();103 $retval .= $this->generate_visible_text(); 97 104 $retval .= '</a>'; 98 105 $retval .= '</div>'; … … 138 145 139 146 $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">'; 141 148 if( $image_too ) { 142 149 $retval .= '<img src="' . TT_ROOT_URL . 'assets/images/twitter-icons/' . $options['twitter_icon'] . '.png" />'; … … 152 159 153 160 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(); 167 162 168 163 // Now, generate the URL … … 185 180 } 186 181 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() { 188 261 return $this->my_text; 189 262 } … … 200 273 if ( !empty($this->my_twitter_handles) ) { 201 274 if ( $include_via ) { 202 return "via " .$this->my_twitter_handles;275 return $this->my_twitter_handles; 203 276 } 204 277 else { … … 261 334 262 335 if ( $options['use_shortlink'] ) { 336 echo "HERE"; 263 337 // Yes, we need a shortlink. 264 338 -
tweetthis/trunk/includes/tinymce-dialog.html
r1147416 r1253854 9 9 <td> 10 10 <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> 11 24 </td> 12 25 </tr> -
tweetthis/trunk/includes/tools.php
r1205394 r1253854 7 7 if ( !class_exists( 'TT_Tools' ) ) { 8 8 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 9 30 /** 10 31 * Parses the ./tweet-this/assets/images/twitter-icons directory for … … 212 233 213 234 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 ); 216 237 } 217 238 else { // Nothing fancy, just the URL as a string … … 221 242 } 222 243 catch( Exception $e ) { 244 $id = 0; 223 245 $post_url = TT_Tools::placeholder_shortlink(); 224 246 $is_placeholder = false; … … 227 249 // default Twitter handles and hidden hashtags 228 250 $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, '' ); 232 254 233 255 // 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, '' ); 242 262 243 263 return array( 264 'post_id' => $id, 244 265 'post_url' => $post_url, 245 266 'post_url_is_placeholder' => $is_placeholder, … … 255 276 ); 256 277 } 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 } 257 296 } // end class 258 297 } // end if( !class_exists( ... -
tweetthis/trunk/readme.txt
r1205394 r1253854 4 4 Tags: twitter, tweet, social, sharing 5 5 Requires at least: 3.9 6 Tested up to: 4. 2.27 Stable tag: 1. 5.26 Tested up to: 4.3.1 7 Stable tag: 1.6.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 105 105 106 106 == 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. 107 113 = 1.5.2 = 108 114 * Fix jQuery UI theme scope issues introduced in last update. -
tweetthis/trunk/tweetthis.php
r1205394 r1253854 4 4 * Plugin URI: http://tweetthis.jtmorris.net 5 5 * 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.26 * Version: 1.6.0 7 7 * Author: John Morris 8 8 * Author URI: http://jtmorris.net
Note: See TracChangeset
for help on using the changeset viewer.