Changeset 382285
- Timestamp:
- 05/07/2011 11:31:23 PM (15 years ago)
- Location:
- wp-tweet-button/trunk
- Files:
-
- 4 edited
-
inc/settings.frame.inc.php (modified) (1 diff)
-
inc/settings.inc.php (modified) (9 diffs)
-
readme.txt (modified) (4 diffs)
-
wp-tweet-button.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-tweet-button/trunk/inc/settings.frame.inc.php
r356478 r382285 6 6 <div id="<?php echo $this->pluginslug; ?>-mbox-general" class="wrap"> 7 7 <?php screen_icon('options-general'); ?> 8 <h2><? echo $this->pluginlabel; ?></h2>8 <h2><?php echo $this->pluginlabel; ?></h2> 9 9 <?php 10 10 wp_nonce_field($this->pluginslug.'-mbox-general'); -
wp-tweet-button/trunk/inc/settings.inc.php
r375255 r382285 24 24 if ($thisobj->tw_get_option('tw_url_shortener_google_token') !=''){ 25 25 echo '<p><a href="'.$thisobj->settingsuri.'&goauth=delete" class="button">'.__ ('Remove authorization data',$thisobj->txtdom).'</a></p>'; 26 ?><input type="hidden" value="<?php echo $thisobj->tw_get_option('tw_url_shortener_google_token');?>" name="tw_url_shortener_google_token" /><? 26 ?><input type="hidden" value="<?php echo $thisobj->tw_get_option('tw_url_shortener_google_token');?>" name="tw_url_shortener_google_token" /><?php 27 27 } else { 28 28 $gsparams = http_build_query( … … 33 33 ) 34 34 ); 35 ?><input type="button" class="button" value="Authorize goo.gl tracking" onclick="window.location = '<?php echo $google_auth_url;?>';"/><br /><?php 35 36 $google_auth_url = 'https://www.google.com/accounts/AuthSubRequest' . '?' . $gsparams; 36 ?><input type="button" class="button" value="Authorize goo.gl tracking" onclick="window.location = '<?php echo $google_auth_url;?>';"/><br /><?37 37 } 38 38 } … … 118 118 <div class="floatleft180" style="clear:left;"> 119 119 <?php echo tw_checkbox_input($this, 'tw_display_front','Front page (home)'); ?> 120 121 120 </div> 122 121 <div class="floatleft100"> … … 135 134 if (function_exists("bnc_wptouch_is_mobile")) { 136 135 ?> 137 <div class="floatleft1 80">136 <div class="floatleft100"> 138 137 <?php echo tw_checkbox_input($this, 'tw_display_mobile','Mobile (WPTouch)'); ?> 139 138 </div> … … 141 140 } 142 141 ?> 142 <div class="floatleft180" style="clear:left;"> 143 <?php echo tw_checkbox_input($this, 'tw_ex_after_archive','No After in Archives'); ?> 144 </div> 143 145 <div class="floatleft180" style="clear:left;"> 144 146 <?php echo tw_checkbox_input($this, 'tw_ex_after_home','No After on Front page'); ?> … … 247 249 <p> 248 250 <code>%POSTTITLE%</code> - <?php _e('The post\'s title.',$this->txtdom);?><br /> 251 <code>%POSTCONTENT%</code> - <?php _e('The post\'s content.',$this->txtdom);?><br /> 249 252 <code>%BLOGTITLE%</code> - <?php _e('The blog\'s name.',$this->txtdom);?> 250 253 <code>%BLOGHASHTAGS%</code> - <?php _e('#Hash tags generated using blog tags.',$this->txtdom);?> … … 269 272 <input type="hidden" value="<?php echo $this->tw_get_option('tw_auto_tweet_token_secret');?>" name="tw_auto_tweet_token_secret" /> 270 273 <p><?php _e('When posts are:',$this->txtdom); ?><br /> 271 <!-- input type="checkbox" value="1" <?php272 if ($this->tw_get_option('tw_auto_tweet_token') == '' || $this->tw_get_option('tw_auto_tweet_token_secret') == '') echo 'disabled="disabled"';273 if ($this->tw_get_option('tw_auto_tweet_posts') == '1') echo 'checked="checked"';274 ?> name="tw_auto_tweet_posts" id="tw_auto_tweet_posts" />275 <label for="tw_auto_tweet_posts"><?php _e('Created',$this->txtdom); ?></label -->276 274 <?php echo tw_checkbox_input($this, 'tw_auto_tweet_posts','Created'); ?><br /> 277 275 <?php echo tw_checkbox_input($this, 'tw_auto_tweet_posts_onsave','Saved'); ?><br /> 278 279 <!-- input type="checkbox" value="1" <?php280 if ($this->tw_get_option('tw_auto_tweet_token') == '' || $this->tw_get_option('tw_auto_tweet_token_secret') == '') echo 'disabled="disabled"';281 if ($this->tw_get_option('tw_auto_tweet_posts_onsave') == '1') echo 'checked="checked"';282 ?> name="tw_auto_tweet_posts_onsave" id="tw_auto_tweet_posts_onsave" />283 <label for="tw_auto_tweet_posts_onsave"><?php _e('Saved',$this->txtdom); ?></label --><br />284 276 </p> 285 277 <p><?php _e('When pages are:',$this->txtdom); ?><br /> 286 278 <?php echo tw_checkbox_input($this, 'tw_auto_tweet_pages','Created'); ?><br /> 287 279 <?php echo tw_checkbox_input($this, 'tw_auto_tweet_pages_onsave','Saved'); ?><br /> 288 289 <!-- input type="checkbox" value="1" <?php290 if ($this->tw_get_option('tw_auto_tweet_token') == '' || $this->tw_get_option('tw_auto_tweet_token_secret') == '') echo 'disabled="disabled"';291 if ($this->tw_get_option('tw_auto_tweet_pages') == '1') echo 'checked="checked"';292 ?> name="tw_auto_tweet_pages" id="tw_auto_tweet_pages" />293 <label for="tw_auto_tweet_pages"><?php _e('Created',$this->txtdom); ?></label><br />294 295 <input type="checkbox" value="1" <?php296 if ($this->tw_get_option('tw_auto_tweet_token') == '' || $this->tw_get_option('tw_auto_tweet_token_secret') == '') echo 'disabled="disabled"';297 if ($this->tw_get_option('tw_auto_tweet_pages_onsave') == '1') echo 'checked="checked"';298 ?> name="tw_auto_tweet_pages_onsave" id="tw_auto_tweet_pages_onsave" />299 <label for="tw_auto_tweet_pages_onsave"><?php _e('Saved',$this->txtdom); ?></label><br / -->300 280 </p> 301 281 <p> 302 <?php _e('If the tweet text + url is too long ',$this->txtdom);?> 303 <select name="tw_auto_tweet_strip" id="tw_auto_tweet_strip"> 304 <option value="url" <?php if ($this->tw_get_option('tw_auto_tweet_strip') == 'url') echo 'selected="selected"'; ?>><?php _e('remove the URL',$this->txtdom);?></option> 305 <option value="text" <?php if ($this->tw_get_option('tw_auto_tweet_strip') == 'text') echo 'selected="selected"'; ?>><?php _e('remove the text',$this->txtdom);?></option> 306 <option value="stext" <?php if ($this->tw_get_option('tw_auto_tweet_strip') == 'stext') echo 'selected="selected"'; ?>><?php _e('shorten the text',$this->txtdom);?></option> 307 <option value="tryall" <?php if ($this->tw_get_option('tw_auto_tweet_strip') == 'tryall') echo 'selected="selected"'; ?>><?php _e('try anything that works',$this->txtdom);?></option> 308 <option value="notweet" <?php if ($this->tw_get_option('tw_auto_tweet_strip') == 'notweet') echo 'selected="selected"'; ?>><?php _e('do not auto-tweet',$this->txtdom);?></option> 309 </select> 310 </p><?php 282 <?php echo tw_checkbox_input($this, 'tw_auto_long_tweet_mode','Long Tweet Mode'); ?><br /> 283 <?php _e('When enabled, automatically generated tweets will consist of the first part of your entry followed by a link. Use this option to override the "Default Tweet text" setting.',$this->txtdom);?> 284 </p> 285 <?php 311 286 } ?> 312 287 … … 474 449 <select name="tw_hook_prio" id="tw_hook_prio" title="<?php echo $this->tw_get_option('tw_hook_prio');?>" class="w99c29c"> 475 450 <option value="75">75 (Default)</option> 476 <option <? =($this->tw_get_option('tw_hook_prio')=='101')?'selected="selected"':'';?> value="101">101</option>477 <option <? =($this->tw_get_option('tw_hook_prio')=='501')?'selected="selected"':'';?> value="501">501</option>478 <option <? =($this->tw_get_option('tw_hook_prio')=='1001')?'selected="selected"':'';?> value="1001">1001</option>451 <option <?php echo ($this->tw_get_option('tw_hook_prio')=='101')?'selected="selected"':'';?> value="101">101</option> 452 <option <?php echo ($this->tw_get_option('tw_hook_prio')=='501')?'selected="selected"':'';?> value="501">501</option> 453 <option <?php echo ($this->tw_get_option('tw_hook_prio')=='1001')?'selected="selected"':'';?> value="1001">1001</option> 479 454 </select> 480 455 <script type="text/javascript"> … … 557 532 </div> 558 533 <p style="margin-left:20px;"> 559 <?php echo sprintf(__("<a href='%1\$s' class='button'>Show settings for diagnostics</a>"), $this->settingsuri.'&showdiag=1');?> 534 <?php echo sprintf(__("<a href='%1\$s' class='button'>Show settings for diagnostics</a>"), $this->settingsuri.'&showdiag=1');?> 560 535 <?php echo sprintf(__("<a href='%1\$s' target='_blank' class='button'>Report a bug</a>"), 'http://0xtc.com/plugins/wp-tweet-button');?> 561 <?php echo sprintf(__("<a href='%1\$s' target='_blank' class='button'>Hire the author</a>"), 'http://0xtc.com/contact');?>562 536 </p> 563 537 <p style="margin-left:20px;margin-top:20px;"> -
wp-tweet-button/trunk/readme.txt
r375255 r382285 3 3 Tags: twitter, tweet button, retweet, tweet, autotweet, WP Tweet Button, advanced, tweeting, social media, button, SEO, share, shortener, goo.gl, awe.sm, b2l.me, bit.ly, cli.gs, sl.ly, snipr, su.pr, tinyurl, analytics, google analytics, campaign, campaign tracking, auto tweeting, auto posts, auto tweet, android 4 4 Requires at least: 3.0 5 Tested up to: 3.1. 15 Tested up to: 3.1.2 6 6 Stable tag: trunk 7 7 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6331357 … … 21 21 * Can be set to vertical, horizontal or no counter. 22 22 * Authors can configure their own Twitter accounts on their profile pages. (WP3.x only) 23 * Supports **Auto-Tweeting** posts.23 * Supports customizable **Auto-Tweeting**. 24 24 * Supports all Tweet Button languages. 25 25 * Supports exclusion by custom post type … … 27 27 * **Google Analytics** support for campaign tracking. 28 28 * Option to switch between '{text} {link} via {@user}' and 'RT {@user} {text} {link}' formats. 29 * Templatable Tweet texts using tags (`%POST TITLE%`, `%BLOGTITLE%`, `%BLOGHASHTAGS%`, `%BLOGHASHCATS%`).29 * Templatable Tweet texts using tags (`%POSTCONTENT%`, `%POSTTITLE%`, `%BLOGTITLE%`, `%BLOGHASHTAGS%`, `%BLOGHASHCATS%`). 30 30 * Supports data tag output. 31 31 * Includes hooks for 3rd party developers. … … 130 130 == Changelog == 131 131 132 = 2.1.0 = 133 * Added option to exclude button blow posts in the archives (No After in Archives) 134 * Optimized code resulting in cleaner text cuts 135 * Added support for %POSTCONTENT% variable in tweet customizations 136 * Added "Long Tweet Mode" (In case you don't want to use %POSTCONTENT% as your "Custom text"). This allows you to auto-tweet the first part of your content followed by a link that takes the reader to the entry on your site. 137 * Links are included in all Autotweets by default. Options to decide action has been removed. 138 132 139 = 2.0.9 = 133 140 * Added support for # Analytics query delimiter (for people that use setAllowAnchor). Enabling this option may require clearing your shortlink cache by using the "Delete all previously saved shortlinks when I save." option. -
wp-tweet-button/trunk/wp-tweet-button.php
r375255 r382285 2 2 /* 3 3 Plugin Name: WP Tweet Button 4 Version: 2. 0.94 Version: 2.1.0 5 5 Plugin URI: http://0xtc.com/plugins/wp-tweet-button 6 6 Description: The WordPress implementation of the official Twitter Tweet Button. … … 102 102 'tw_display_mobile'=>'', 103 103 'tw_ex_after_home'=>'', 104 'tw_ex_after_archive'=>'', 104 105 'tw_bwdata_attr'=> '', 105 106 'tw_use_rel_me'=> '', … … 116 117 'tw_auto_tweet_pages_onsave'=>'', 117 118 'tw_auto_tweet_strip'=>'stext', 119 'tw_auto_long_tweet_mode'=>'', 118 120 'tw_script_infooter'=>'0', 119 121 'tw_prev_content_dup'=>'1' … … 130 132 'tw_display_search', 131 133 'tw_ex_after_home', 134 'tw_ex_after_archive', 132 135 'tw_display_archive', 133 136 'tw_display_page', … … 148 151 'tw_auto_tweet_posts_onsave'=>'', 149 152 'tw_auto_tweet_pages_onsave'=>'', 153 'tw_auto_long_tweet_mode'=>'', 150 154 'tw_no_https_shortlinks', 151 155 'tw_prev_content_dup', … … 470 474 * This function decides the format of the tweet text based on preferences and limitations. 471 475 */ 472 function tw_get_text($entitydecode=false ){476 function tw_get_text($entitydecode=false,$dots=true){ 473 477 $activepost = $this->tw_get_activepost(); 474 478 if (get_post_meta($activepost->ID, '_twitterrelated_custom_text', true)){ … … 480 484 } else { 481 485 $tw_text = $this->tw_get_option('tw_text'); 482 // if ($tw_text=='entry_title') { $button_data_text = $activepost->post_title;}483 486 if ($tw_text=='entry_title') { $button_data_text = get_the_title($activepost->ID);} 484 // if ($tw_text=='page_title') { $button_data_text = $activepost->post_title .' - '. get_bloginfo('name');}485 487 if ($tw_text=='page_title') { $button_data_text = get_the_title($activepost->ID) .' - '. get_bloginfo('name');} 486 488 if ($tw_text=='blog_title') { $button_data_text = get_bloginfo('name');} 487 489 if ($tw_text=='custom_title') { $button_data_text = $this->tw_preptext(stripslashes($this->tw_get_option('tw_text_custom')));} 490 $button_data_text = trim ($button_data_text); 491 $maxlen = 140; 492 $maxlen = $maxlen - strlen($this->tw_get_option('tw_via')); // username 493 $maxlen = $maxlen - 1; // @ 494 $maxlen = $maxlen - 1; // [space] 495 if ($this->tw_get_option('tw_text_format')=='VIA') $maxlen = $maxlen - 3; 496 if ($this->tw_get_option('tw_text_format')=='RT') $maxlen = $maxlen - 2; 497 $maxlen = $maxlen - 1; // [space] 498 if ($dots) $maxlen = $maxlen - 19; // link 499 if ($dots) $maxlen = $maxlen - 1; // [space] 500 $n_button_data_text = $this->tw_clean_trim ($button_data_text,$maxlen, $dots); 501 $button_data_text = $n_button_data_text; 488 502 } 489 503 return $button_data_text; 490 504 } 491 505 506 507 508 /** 509 * Applies formatting and transformations to texts. 510 */ 511 function tw_clean_trim($text,$len,$dots=true){ 512 if (strlen($text)<=$len){return $text;} 513 if ($dots) {$spacing = 4;}else{$spacing=0;} 514 $string = wordwrap(trim($text), $len - $spacing); 515 $string = substr($string, 0, strpos($string, "\n")); 516 if ($dots && (strlen($string)<=(strlen($text)+$spacing))){ 517 $string .= '... '; 518 } 519 return $string; 520 521 } 492 522 /** 493 523 * Applies formatting and transformations to texts. … … 496 526 $activepost = $this->tw_get_activepost(); 497 527 $tmptxt = null; 498 // $tmptxt= str_replace('%POSTTITLE%', $activepost->post_title, $text);499 $tmptxt= str_replace('%POSTTITLE%', get_the_title($activepost->ID), $t ext);528 $tmptxt= str_replace('%POSTCONTENT%', strip_tags($activepost->post_content), $text); 529 $tmptxt= str_replace('%POSTTITLE%', get_the_title($activepost->ID), $tmptxt); 500 530 $tmptxt= str_replace('%BLOGTITLE%', get_bloginfo('name'), $tmptxt); 501 531 $tmptxt= str_replace('%BLOGHASHTAGS%', $this->tw_get_hash_tags(), $tmptxt); … … 546 576 547 577 if ($this->tw_get_option('tw_auto_tweet_posts_onsave')=='1' || $this->tw_get_option('tw_auto_tweet_pages_onsave')=='1'){ 548 add_action('publish_post', array(&$this, 'tw_send_auto_tweet'),100,1);578 add_action('publish_post', array(&$this, 'tw_send_auto_tweet'),100,1); 549 579 add_action('xmlrpc_publish_post', array(&$this, 'tw_send_auto_tweet'),100,1); 550 add_action('publish_page', array(&$this, 'tw_send_auto_tweet'),100,1);580 add_action('publish_page', array(&$this, 'tw_send_auto_tweet'),100,1); 551 581 } 552 582 … … 830 860 $button_data_via=null; 831 861 $button_data_status_id = null; 832 $button_data_url = 'data-url="' . $this->tw_get_the_url(true) . '"'; 862 $theurl = $this->tw_get_the_url(true); 863 $button_data_url = 'data-url="' . $theurl . '"'; 833 864 $viauser = $this->tw_get_twitter_name(); 834 865 if ($viauser){ … … 847 878 // $button_data_status_id = 'data-status-id="'.$tid.'"'; 848 879 } 849 $button_data_text = 'data-text="'.$textprefix . htmlspecialchars($this->tw_get_text( )).'"';880 $button_data_text = 'data-text="'.$textprefix . htmlspecialchars($this->tw_get_text(null)).'"'; 850 881 $button_data_related = 'data-related="'.$this->tw_get_related_text().'"'; 851 882 $button_data_count = 'data-count="'.$this->tw_get_option('tw_count').'"'; … … 872 903 if ($bwdata==true && !is_feed()){return false;} 873 904 $viauser = $this->tw_get_twitter_name(); 874 $button = '?url=' . urlencode($this->tw_get_the_url(true)); 905 $theurl = $this->tw_get_the_url(true); 906 $button = '?url=' . urlencode($theurl); 875 907 if ($viauser){ 876 908 if ($this->tw_get_option('tw_text_format')=='VIA' || $this->tw_get_option('tw_use_rel_me')=='1') { … … 944 976 function tw_get_long_url($addtrack=false, $addlang=true) { 945 977 global $my_transposh_plugin; 946 if (!in_the_loop() && is_home()){return home_url();} 978 if (!in_the_loop() && is_home()){return home_url();} 947 979 $activepost = $this->tw_get_activepost(); 948 980 $perms=null; … … 1141 1173 $alignment = $this->tw_get_option('tw_align'); 1142 1174 if ($alignment!='none' && $this->tw_get_option('tw_align')!=null && $alignment!=''){ 1143 if ($alignment=='right') $alignstr = ';float:right;margin-left:10px;'; 1144 if ($alignment=='left') $alignstr = ';float:left;margin-right:10px;'; 1145 if ($alignment=='center') $alignstr = ';float:none;margin:0 auto;text-align:center;'; 1146 } 1147 1148 if ($this->tw_get_option('tw_nostyle_feed') == ''){ 1149 $StyleStrDiv = ' style="' . $this->tw_get_option('tw_style_c') . $alignstr . '"'; 1175 if ($alignment=='right') $alignstr = 'float:right;margin-left:10px;'; 1176 if ($alignment=='left') $alignstr = 'float:left;margin-right:10px;'; 1177 if ($alignment=='center') $alignstr = 'float:none;margin:0 auto;text-align:center;'; 1178 } 1179 $dssep = null; 1180 $userstyle = $this->tw_get_option('tw_style_c'); 1181 if ($userstyle!=''){ 1182 if (substr($userstyle, -1)==';'){$dssep='';}else{$dssep=';';} 1183 } 1184 if (($this->tw_get_option('tw_nostyle_feed') == '1') && (is_feed()=='1')){ 1185 $StyleStrDiv = ''; 1186 $StyleStrBtn = ''; 1187 } else { 1188 $StyleStrDiv = ' style="' . $this->tw_get_option('tw_style_c') .$dssep. $alignstr . '"'; 1150 1189 $StyleStrBtn = ' style="width:55px;height:22px;background:transparent url(\''. WP_PLUGIN_URL.'/wp-tweet-button/tweetn.png\') no-repeat 0 0;text-align:left;text-indent:-9999px;display:block;"'; 1151 } else {1152 $StyleStrDiv = '';1153 $StyleStrBtn = '';1154 1190 } 1155 1191 if ($this->ismanual){$btnidattr='m';}else{$btnidattr='';} … … 1207 1243 return str_replace('[tweetbutton]', $button, $content); 1208 1244 } else if ($where == 'beforeandafter') { 1209 if ($this->tw_get_option('tw_ex_after_home') && (is_home() || is_front_page())){ 1245 if ( 1246 ($this->tw_get_option('tw_ex_after_home') && (is_home() || is_front_page())) || 1247 ($this->tw_get_option('tw_ex_after_archive') && (is_archive())) 1248 ) { 1210 1249 $this->hasbutton[$post->ID] = 1; 1211 1250 return $button . $content; 1212 } else { 1213 $this->hasbutton[$post->ID] = 1; 1214 return $button . $content . $button; 1215 } 1251 } 1252 $this->hasbutton[$post->ID] = 1; 1253 return $button . $content . $button; 1216 1254 } else if ($where == 'before') { 1217 1255 $this->hasbutton[$post->ID] = 1; … … 1355 1393 $this->postid = $thepost->ID; 1356 1394 } 1357 if ($thepost->post_type == 'revision' || ($thepost->post_status != 'publish' && $thepost->post_status != 'future') || $thepost->post_password != '' ) return false; 1395 if ($thepost->post_type == 'revision' || ($thepost->post_status != 'publish' && $thepost->post_status != 'future') || $thepost->post_password != '' ) return false; 1358 1396 if ( 1359 1397 ( 1360 (($this->tw_get_option('tw_auto_tweet_posts') == '1' || $this->tw_get_option('tw_auto_tweet_posts_onsave') == '1') && $post_type_object->hierarchical=='') || 1361 (($this->tw_get_option('tw_auto_tweet_pages') == '1' || $this->tw_get_option('tw_auto_tweet_pages_onsave') == '1') && $post_type_object->hierarchical=='1') 1398 (($this->tw_get_option('tw_auto_tweet_posts') == '1' || $this->tw_get_option('tw_auto_tweet_posts_onsave') == '1') && $post_type_object->hierarchical=='') || // posts 1399 (($this->tw_get_option('tw_auto_tweet_pages') == '1' || $this->tw_get_option('tw_auto_tweet_pages_onsave') == '1') && $post_type_object->hierarchical=='1') // pages 1362 1400 ) && 1363 $this->tw_get_option('tw_auto_tweet_token') != '' &&1364 $this->tw_get_option('tw_auto_tweet_token_secret') != '' &&1365 (get_post_meta($thepost->ID, '_tw_do_not_send_auto_tweet',true) == '') &&1366 ($_POST['tw_do_not_send_auto_tweet'] == '') &&1367 (get_post_meta($thepost->ID, '_tw_autotweeted',true) == '' || $_POST['tw_send_auto_tweet_again']==1)1401 $this->tw_get_option('tw_auto_tweet_token') != '' && 1402 $this->tw_get_option('tw_auto_tweet_token_secret') != '' && 1403 (get_post_meta($thepost->ID, '_tw_do_not_send_auto_tweet',true) == '') && 1404 ($_POST['tw_do_not_send_auto_tweet'] == '') && 1405 (get_post_meta($thepost->ID, '_tw_autotweeted',true) == '' || $_POST['tw_send_auto_tweet_again']==1) 1368 1406 ){ 1369 1407 $Post_data = array(); 1370 1408 $Post_data['r_oauth_token'] = $this->tw_get_option('tw_auto_tweet_token'); 1371 1409 $Post_data['r_oauth_token_secret'] = $this->tw_get_option('tw_auto_tweet_token_secret'); 1372 $tweet_text = $this->tw_validate_tweet($this->tw_get_text(),$this->tw_get_the_url()); 1410 if ($this->tw_get_option('tw_auto_long_tweet_mode')=='1'){ 1411 $tweet_text = $this->tw_validate_tweet(trim(strip_tags($thepost->post_content)),$this->tw_get_the_url()); 1412 } else { 1413 $tweet_text = $this->tw_validate_tweet($this->tw_get_text(null,false),$this->tw_get_the_url()); 1414 } 1373 1415 if ($tweet_text==false){return false;} 1416 1374 1417 $ctypes = array("ASCII", "UTF-8", "ISO-8859-15", "ISO-8859-1", "JIS", "EUC-JP"); 1375 1418 $enc = mb_detect_encoding($tweet_text,$ctypes); … … 1380 1423 if (strstr($content,'error')==false && $content != '' && strstr($content,'<') == false) { 1381 1424 add_post_meta($thepost->ID, '_tw_autotweeted', $content, TRUE) or update_post_meta($thepost->ID, '_tw_autotweeted', $content); 1425 } else { 1426 add_post_meta($thepost->ID, '_tw_autotweeted_errors', $content, TRUE) or update_post_meta($thepost->ID, '_tw_autotweeted_errors', $content); 1382 1427 } 1383 1428 return $content; … … 1390 1435 */ 1391 1436 function tw_validate_tweet($text, $url){ 1392 $max = 134;1437 // $tw_auto_tweet_strip = $this->tw_get_option('tw_auto_tweet_strip'); 1393 1438 if (strstr($url,admin_url())){return false;} 1394 if ($url==false){return false;} 1439 if ($url==false){ 1440 return false; 1441 } 1442 $max = 140; 1395 1443 $lurl = strlen($url); 1396 $ltext = strlen(trim($text))+1; 1397 if ($lurl+$ltext>$max){ 1398 if ($this->tw_get_option('tw_auto_tweet_strip')=='notweet'){ 1444 $ltext = strlen(trim($text)); 1445 $maxtextlen = $max - 1 - $lurl; 1446 if (($lurl+4+$ltext) > $max){ 1447 // The URL is longer than the maximum allowed tweet length. 1448 if ($lurl>$max ){ 1399 1449 return false; 1400 1450 } 1401 if ($this->tw_get_option('tw_auto_tweet_strip')=='url'){ 1402 if (strlen(trim($text))<=$max){ 1403 return trim($text); 1404 } else { 1405 return false; 1406 } 1407 } 1408 if ($this->tw_get_option('tw_auto_tweet_strip')=='text'){ 1409 if ($lurl<=$max){ 1410 return $url; 1411 } else return false; 1412 } 1413 if ($this->tw_get_option('tw_auto_tweet_strip')=='stext'){ 1414 $strmaxlen = $max - $lurl - 4; 1415 if (0 <= $strmaxlen){ 1416 $string = wordwrap($text, $strmaxlen); 1417 $string = substr($string, 0, strpos($string, "\n")); 1418 $stext = $string.'... '; 1419 } else { 1420 return false; 1421 } 1422 if (strlen($stext.$url)<=$max) { 1423 return $stext.$url; 1424 } else return false; 1425 } 1426 if ($this->tw_get_option('tw_auto_tweet_strip')=='tryall'){ 1427 $strmaxlen = $max - $lurl - 4; 1428 if (0 <= $strmaxlen){ 1429 $string = wordwrap($text, $strmaxlen); 1430 $string = substr($string, 0, strpos($string, "\n")); 1431 $stext = $string.'... '; 1432 if (strlen($stext.$url)<=$max) { 1433 return $stext.$url; 1434 } else { 1435 if (strlen(trim($text))<=$max){ 1436 return trim($text); 1437 } else { 1438 if ($lurl<=$max){ 1439 return $url; 1440 } else { 1441 $string = wordwrap($text, $max-4); 1442 $string = substr($string, 0, strpos($string, "\n")); 1443 $stext = $string.'... '; 1444 return $stext; 1445 } 1446 } 1447 } 1448 } else { 1449 if ($lurl<=$max){ 1450 return $url; 1451 } else { 1452 return substr($text, 0, $max-2).' 1453 '; 1454 } 1455 } 1456 } 1457 } else { 1458 return $text.' '.$url; 1451 1452 // The length of the URL is between 138 and 140 characters. We can't add a title, but we can use the URL. 1453 if ( 1454 ($lurl==$max ) || 1455 ( ($lurl>=$max-4) && ($lurl<=$max)) 1456 ){ 1457 return $url; 1458 } 1459 1460 $strmaxlen = $max - $lurl; 1461 $stext = $this->tw_clean_trim($text, $strmaxlen); 1462 1463 // We shrunk the text and tries to fit it along with the URL but alas, the text disappeared in the shrinking process. We can still use the URL. 1464 if (strlen($stext)<=4){ 1465 return $url; 1466 } 1467 1468 // Yey! We can return the shrunk text AND the URL, no problem. 1469 if (strlen($stext.' '.$url)<=$max) { 1470 return $stext.' '. $url; 1471 } 1472 return false; 1473 } else { 1474 return $text.'... '.$url; 1459 1475 } 1460 1476 }
Note: See TracChangeset
for help on using the changeset viewer.