Better Click To Tweet - Version 3.3

Version Description

  • fixed a bug that was creating (rare, server-configuration-related) "Fatal Error" notices for mb_strlen() and related multibyte functions.
  • various code tweaks for readability and compliance with WordPress standards.
Download this release

Release Info

Developer ben.meredith@gmail.com
Plugin Icon 128x128 Better Click To Tweet
Version 3.3
Comparing to
See all releases

Code changes from version 3.2.2 to 3.3

Files changed (2) hide show
  1. better-click-to-tweet.php +118 -20
  2. readme.txt +8 -1
better-click-to-tweet.php CHANGED
@@ -2,7 +2,7 @@
2
/*
3
Plugin Name: Better Click To Tweet
4
Description: The only Click To Tweet plugin to add translation support. The only Click To Tweet plugin to take into account your Twitter username's length in truncating long tweets, or to correctly take into account non-Roman characters. Simply put, as Click To Tweet plugins go, this one is, well, BETTER.
5
- Version: 3.2.2
6
Author: Ben Meredith
7
Author URI: http://benandjacq.com
8
Plugin URI: https://wordpress.org/plugins/better-click-to-tweet/
@@ -12,89 +12,181 @@ Text Domain: better-click-to-tweet
12
include 'bctt_options.php';
13
include 'bctt-i18n.php';
14
15
- defined( 'ABSPATH' ) or die( "No script kiddies please!" );
16
17
function bctt_shorten( $input, $length, $ellipsis = true, $strip_html = true ) {
18
if ( $strip_html ) {
19
$input = strip_tags( $input );
20
}
21
- if ( mb_strlen( $input ) <= $length ) {
22
- return $input;
23
- }
24
- $last_space = mb_strrpos( mb_substr( $input, 0, $length) , ' ');
25
- $trimmed_text = mb_substr( $input, 0, $last_space );
26
- if ( $ellipsis ) {
27
- $trimmed_text .= '…';
28
- }
29
- return $trimmed_text;
30
};
31
32
function bctt_shortcode( $atts ) {
33
extract( shortcode_atts( array(
34
'tweet' => '',
35
'via' => 'yes',
36
'url' => 'yes',
37
), $atts ) );
38
$handle = get_option( 'bctt-twitter-handle' );
39
- $handle_length = ( 6 + mb_strlen($handle));
40
41
if ( !empty( $handle ) && $via != 'no' ) {
42
$handle_code = "&via=" . $handle . "&related=" . $handle;
43
} else {
44
$handle_code = '';
45
}
46
47
if( $via != 'yes') {
48
$handle = '';
49
$handle_code = '';
50
$handle_length = 0;
51
}
52
53
$text = $tweet;
54
if( $url != 'no' ){
55
if ( get_option('bctt-short-url') != false ) {
56
$bcttURL = '&url=' . wp_get_shortlink();
57
- }
58
- else {
59
$bcttURL = '&url=' . get_permalink();
60
}
61
} else {
62
$bcttURL = '';
63
}
64
$bcttBttn = sprintf( __( 'Click To Tweet', 'better-click-to-tweet' ) );
65
if( $url != 'no'){
66
$short = bctt_shorten( $text, ( 117 - ( $handle_length ) ) );
67
- }
68
- else {
69
$short = bctt_shorten( $text, ( 140 - ( $handle_length ) ) );
70
}
71
if ( !is_feed() ) {
72
- return "<div class='bctt-click-to-tweet'><span class='bctt-ctt-text'><a href='https://twitter.com/intent/tweet?text=" . urlencode($short) . $handle_code . $bcttURL."' target='_blank'>".$short."</a></span><a href='https://twitter.com/intent/tweet?text=" . urlencode($short) . $handle_code . $bcttURL . "' target='_blank' class='bctt-ctt-btn'>" . $bcttBttn . "</a></div>";} else {
73
return "<hr /><p><em>" . $short . "</em><br /><a href='https://twitter.com/intent/tweet?text=" . urlencode($short) . $handle_code . $bcttURL . "' target='_blank' class='bctt-ctt-btn'>" . $bcttBttn . "</a><br /><hr />";
74
- };
75
- }
76
77
add_shortcode('bctt', 'bctt_shortcode');
78
79
/*
80
* Load the stylesheet to style the output
81
*/
82
83
function bctt_scripts () {
84
wp_register_style( 'bcct_style', plugins_url( 'assets/css/styles.css', __FILE__ ), false, '1.0', 'all' );
85
wp_enqueue_style('bcct_style');
86
};
87
88
add_action('wp_enqueue_scripts', 'bctt_scripts');
89
90
/*
91
* Delete options and shortcode on uninstall
92
*/
93
94
function bctt_on_uninstall(){
95
96
- delete_option( 'bctt-twitter-handle' );
97
delete_option( 'bctt-short-url');
98
remove_shortcode( 'bctt' );
99
100
};
@@ -102,11 +194,17 @@ function bctt_on_uninstall(){
102
register_uninstall_hook( __FILE__, 'bctt_on_uninstall' );
103
104
function bctt_options_link($links) {
105
$settingsText = sprintf( __( 'Settings', 'better-click-to-tweet'));
106
$settings_link = '<a href="options-general.php?page=better-click-to-tweet">'.$settingsText.'</a>';
107
array_unshift( $links, $settings_link );
108
return $links;
109
}
110
$bcttlink = plugin_basename(__FILE__);
111
add_filter("plugin_action_links_$bcttlink", 'bctt_options_link' );
112
2
/*
3
Plugin Name: Better Click To Tweet
4
Description: The only Click To Tweet plugin to add translation support. The only Click To Tweet plugin to take into account your Twitter username's length in truncating long tweets, or to correctly take into account non-Roman characters. Simply put, as Click To Tweet plugins go, this one is, well, BETTER.
5
+ Version: 3.3
6
Author: Ben Meredith
7
Author URI: http://benandjacq.com
8
Plugin URI: https://wordpress.org/plugins/better-click-to-tweet/
12
include 'bctt_options.php';
13
include 'bctt-i18n.php';
14
15
+ defined( 'ABSPATH' ) or die( "No soup for you. You leave now." );
16
+
17
+ /*
18
+ * Strips the html, shortens the text (after checking for mb_internal_encoding compatibility)
19
+ * and adds an ellipsis is the text has been shortened
20
+ *
21
+ * @param $input
22
+ * @param $length
23
+ * @param $ellipsis
24
+ * @param $strip_html
25
+ */
26
27
function bctt_shorten( $input, $length, $ellipsis = true, $strip_html = true ) {
28
+
29
if ( $strip_html ) {
30
$input = strip_tags( $input );
31
}
32
+
33
+ /*
34
+ * Checks to see if the mbstring php extension is loaded, for optimal truncation.
35
+ * If it's not, it bails and counts the characters based on utf-8.
36
+ * What this means for users is that non-Roman characters will only be counted
37
+ * correctly if that extension is loaded. Contact your server admin to enable the extension.
38
+ */
39
+
40
+ if ( function_exists( 'mb_internal_encoding' ) ) {
41
+ if ( mb_strlen( $input ) <= $length ) {
42
+ return $input;
43
+ }
44
+
45
+ $last_space = mb_strrpos( mb_substr( $input, 0, $length ) , ' ' );
46
+ $trimmed_text = mb_substr( $input, 0, $last_space );
47
+
48
+ if ( $ellipsis ) {
49
+ $trimmed_text .= '…';
50
+ }
51
+
52
+ return $trimmed_text;
53
+
54
+ } else {
55
+
56
+ if ( strlen( $input ) <= $length ) {
57
+ return $input;
58
+ }
59
+
60
+ $last_space = strrpos( substr( $input, 0, $length ) , ' ' );
61
+ $trimmed_text = substr( $input, 0, $last_space );
62
+
63
+ if ( $ellipsis ) {
64
+ $trimmed_text .= '…';
65
+ }
66
+
67
+ return $trimmed_text;
68
+ }
69
};
70
71
+ /*
72
+ * Creates the bctt shortcode
73
+ *
74
+ * @since 0.1
75
+ * @param $atts
76
+ *
77
+ */
78
+
79
function bctt_shortcode( $atts ) {
80
+
81
extract( shortcode_atts( array(
82
'tweet' => '',
83
'via' => 'yes',
84
'url' => 'yes',
85
), $atts ) );
86
+
87
$handle = get_option( 'bctt-twitter-handle' );
88
+
89
+ if ( function_exists( 'mb_internal_encoding' ) ) {
90
+
91
+ $handle_length = ( 6 + mb_strlen($handle));
92
+
93
+ } else {
94
+
95
+ $handle_length = ( 6 + strlen($handle));
96
+
97
+ }
98
99
if ( !empty( $handle ) && $via != 'no' ) {
100
+
101
$handle_code = "&via=" . $handle . "&related=" . $handle;
102
+
103
} else {
104
+
105
$handle_code = '';
106
+
107
}
108
109
if( $via != 'yes') {
110
+
111
$handle = '';
112
$handle_code = '';
113
$handle_length = 0;
114
+
115
}
116
117
$text = $tweet;
118
+
119
if( $url != 'no' ){
120
+
121
if ( get_option('bctt-short-url') != false ) {
122
+
123
$bcttURL = '&url=' . wp_get_shortlink();
124
+
125
+ } else {
126
+
127
$bcttURL = '&url=' . get_permalink();
128
+
129
}
130
+
131
} else {
132
+
133
$bcttURL = '';
134
+
135
}
136
+
137
$bcttBttn = sprintf( __( 'Click To Tweet', 'better-click-to-tweet' ) );
138
+
139
if( $url != 'no'){
140
+
141
$short = bctt_shorten( $text, ( 117 - ( $handle_length ) ) );
142
+
143
+ } else {
144
+
145
$short = bctt_shorten( $text, ( 140 - ( $handle_length ) ) );
146
+
147
}
148
+
149
if ( !is_feed() ) {
150
+
151
+ return "<div class='bctt-click-to-tweet'><span class='bctt-ctt-text'><a href='https://twitter.com/intent/tweet?text=" . urlencode($short) . $handle_code . $bcttURL."' target='_blank'>".$short."</a></span><a href='https://twitter.com/intent/tweet?text=" . urlencode($short) . $handle_code . $bcttURL . "' target='_blank' class='bctt-ctt-btn'>" . $bcttBttn . "</a></div>";
152
+ } else {
153
+
154
return "<hr /><p><em>" . $short . "</em><br /><a href='https://twitter.com/intent/tweet?text=" . urlencode($short) . $handle_code . $bcttURL . "' target='_blank' class='bctt-ctt-btn'>" . $bcttBttn . "</a><br /><hr />";
155
+
156
+ };
157
+ }
158
159
add_shortcode('bctt', 'bctt_shortcode');
160
161
/*
162
* Load the stylesheet to style the output
163
+ *
164
+ * @since 0.1
165
+ *
166
*/
167
168
function bctt_scripts () {
169
+
170
wp_register_style( 'bcct_style', plugins_url( 'assets/css/styles.css', __FILE__ ), false, '1.0', 'all' );
171
+
172
wp_enqueue_style('bcct_style');
173
+
174
};
175
176
add_action('wp_enqueue_scripts', 'bctt_scripts');
177
178
/*
179
* Delete options and shortcode on uninstall
180
+ *
181
+ * @since 0.1
182
*/
183
184
function bctt_on_uninstall(){
185
186
+ delete_option( 'bctt-twitter-handle' );
187
+
188
delete_option( 'bctt-short-url');
189
+
190
remove_shortcode( 'bctt' );
191
192
};
194
register_uninstall_hook( __FILE__, 'bctt_on_uninstall' );
195
196
function bctt_options_link($links) {
197
+
198
$settingsText = sprintf( __( 'Settings', 'better-click-to-tweet'));
199
+
200
$settings_link = '<a href="options-general.php?page=better-click-to-tweet">'.$settingsText.'</a>';
201
+
202
array_unshift( $links, $settings_link );
203
+
204
return $links;
205
+
206
}
207
+
208
$bcttlink = plugin_basename(__FILE__);
209
add_filter("plugin_action_links_$bcttlink", 'bctt_options_link' );
210
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
Tags: click to tweet, twitter, tweet, twitter plugin, Twitter boxes, share, social media, post, posts, plugin, auto post, bitly, bit.ly, yourls, yourls.org
5
Requires at least: 3.8
6
Tested up to: 4.1
7
- Stable tag: 3.2.2
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -97,6 +97,10 @@ I want to maximize the usefulness of this plugin by translating it into multiple
97
98
== Changelog ==
99
100
= 3.2.2 =
101
* fixed bug that was causing the URL not to display on certain clicks after the 3.2 update (thanks @aa_stardust for the heads up!)
102
@@ -148,6 +152,9 @@ I want to maximize the usefulness of this plugin by translating it into multiple
148
149
== Upgrade Notice ==
150
151
= 3.2.2 =
152
* fixed bug that was causing the URL not to display on certain clicks after the 3.2 update (thanks @aa_stardust for the heads up!)
153
4
Tags: click to tweet, twitter, tweet, twitter plugin, Twitter boxes, share, social media, post, posts, plugin, auto post, bitly, bit.ly, yourls, yourls.org
5
Requires at least: 3.8
6
Tested up to: 4.1
7
+ Stable tag: 3.3
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
97
98
== Changelog ==
99
100
+ = 3.3 =
101
+ * fixed a bug that was creating (rare, server-configuration-related) "Fatal Error" notices for `mb_strlen()` and related multibyte functions.
102
+ * various code tweaks for readability and compliance with WordPress standards.
103
+
104
= 3.2.2 =
105
* fixed bug that was causing the URL not to display on certain clicks after the 3.2 update (thanks @aa_stardust for the heads up!)
106
152
153
== Upgrade Notice ==
154
155
+ = 3.3 =
156
+ * fixed a bug for users experiencing Fatal Errors related to multibyte string functions.
157
+
158
= 3.2.2 =
159
* fixed bug that was causing the URL not to display on certain clicks after the 3.2 update (thanks @aa_stardust for the heads up!)
160