WP to Twitter - Version 3.0.0

Version Description

  • Handles case where post type identification could throw PHP warning if no post types were chosen to be Tweeted.
  • Eliminated outdated compatibility function.
  • Eliminated old update notices.
  • General code cleanup.
  • Code documentation.
  • Updated media uploading to use Uploads endpoint, replacing deprecated update_with_media endpoint. [WP Tweets PRO]
  • Simplifed short URL storage
  • Decreased widget cache life from 1 hour to 30 minutes.
  • Added fallback Normalizer class for cases when extension is not installed.
  • Added notes for the 100 HTTP code return error.
  • Moved Twitter server time check out of basic set-up & set up to only run on demand.
  • Minor design changes.
Download this release

Release Info

Developer joedolson
Plugin Icon 128x128 WP to Twitter
Version 3.0.0
Comparing to
See all releases

Code changes from version 2.9.8 to 3.0.0

css/styles.css CHANGED
@@ -12,12 +12,13 @@
12
  border: none;
13
  }
14
 
15
- legend {
16
  padding: 6px;
17
  background: #f3f3f3;
18
  width: 100%;
19
  border-radius: 3px 0 0 3px;
20
  color: #000;
 
21
  }
22
 
23
  #wp-to-twitter .resources {
@@ -54,6 +55,12 @@ legend {
54
  margin-top: 5px;
55
  }
56
 
 
 
 
 
 
 
57
  #wp-to-twitter .wpt-terms ul {
58
  -moz-column-count: 3;
59
  -moz-column-gap: 20px;
12
  border: none;
13
  }
14
 
15
+ #wp-to-twitter legend, #wpt-settings_page legend {
16
  padding: 6px;
17
  background: #f3f3f3;
18
  width: 100%;
19
  border-radius: 3px 0 0 3px;
20
  color: #000;
21
+ margin-top: 4px;
22
  }
23
 
24
  #wp-to-twitter .resources {
55
  margin-top: 5px;
56
  }
57
 
58
+ #wp-to-twitter .wpt-terms p {
59
+ text-align: right;
60
+ padding-bottom: 5px;
61
+ border-bottom: 1px solid #ddd;
62
+ }
63
+
64
  #wp-to-twitter .wpt-terms ul {
65
  -moz-column-count: 3;
66
  -moz-column-gap: 20px;
readme.txt CHANGED
@@ -6,7 +6,7 @@ Requires at least: 3.7.0
6
  Tested up to: 4.1
7
  License: GPLv2 or later
8
  Text Domain: wp-to-twitter
9
- Stable tag: 2.9.7
10
 
11
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
12
 
@@ -20,7 +20,7 @@ Yep. That's the basic functionality. But it's not the only thing you can do:
20
  * Recent Tweets Widget: Display recent Tweets. Fetch Tweets from your own or any other account.
21
  * Tweet Search Widget: Display the Tweets resulting from a search.
22
 
23
- [Upgrade to WP Tweets Pro](http://www.joedolson.com/wp-tweets-pro/) for Tweet scheduling, automatic re-tweeting, and more!
24
 
25
  WP to Twitter uses a customizable Tweet template for Tweets sent when updating or editing posts and pages or custom post types. You can customize your Tweet for each post, using custom template tags to generate the Tweet.
26
 
@@ -42,6 +42,7 @@ Upgrade to [WP Tweets Pro](http://www.joedolson.com/wp-tweets-pro/) for extra fe
42
  * Co-Tweet to site and author Twitter accounts
43
  * Preview and Tweet comments
44
  * Filter Tweets by taxonomy (categories, tags, or custom taxonomies)
 
45
  * [...and more!](http://www.joedolson.com/wp-tweets-pro/)
46
 
47
  Want to stay up to date on WP to Twitter? [Follow me on Twitter!](https://twitter.com/joedolson)
@@ -59,9 +60,23 @@ Translating my plug-ins is always appreciated. Visit <a href="http://translate.j
59
 
60
  = Future =
61
 
62
- * Use apply_filters( 'wpt_tweet_sentence', $tweet, $post_ID ) to pass custom taxonomy Tweet formats
63
  * Add regex filter to detect URLs typed into Tweet fields for counting/shortening purposes. [todo]
64
- * Replacement for incoming data that's already encoded? (e.g. &apos;)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  = 2.9.8 =
67
 
@@ -1059,7 +1074,7 @@ Right here: [WP to Twitter FAQ](http://www.joedolson.com/wp-to-twitter/support-2
1059
 
1060
  = How can I help you make WP to Twitter a better plug-in? =
1061
 
1062
- Writing and maintaining a plug-in is a lot of work. You can help me by providing detailed support requests (which saves me time), or by providing financial support, either via my [plug-in donations page](https://www.joedolson.com/donate/) or by [upgrading to WP Tweets Pro](https://www.joedolson.com/wp-tweets-pro/). Believe me, any small donation really makes a difference!
1063
 
1064
  == Screenshots ==
1065
 
@@ -1072,6 +1087,4 @@ Writing and maintaining a plug-in is a lot of work. You can help me by providing
1072
 
1073
  == Upgrade Notice ==
1074
 
1075
- 2.9.8: Updated User's Guide, related tasks.
1076
-
1077
- * 2.9.7 - Changes to fix bugs for WP Tweets PRO users.
6
  Tested up to: 4.1
7
  License: GPLv2 or later
8
  Text Domain: wp-to-twitter
9
+ Stable tag: 2.9.8
10
 
11
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
12
 
20
  * Recent Tweets Widget: Display recent Tweets. Fetch Tweets from your own or any other account.
21
  * Tweet Search Widget: Display the Tweets resulting from a search.
22
 
23
+ [Upgrade to WP Tweets Pro](http://www.joedolson.com/wp-tweets-pro/) and schedule Tweets, set up automatic reposts, upload images and more!
24
 
25
  WP to Twitter uses a customizable Tweet template for Tweets sent when updating or editing posts and pages or custom post types. You can customize your Tweet for each post, using custom template tags to generate the Tweet.
26
 
42
  * Co-Tweet to site and author Twitter accounts
43
  * Preview and Tweet comments
44
  * Filter Tweets by taxonomy (categories, tags, or custom taxonomies)
45
+ * Upload images to Twitter
46
  * [...and more!](http://www.joedolson.com/wp-tweets-pro/)
47
 
48
  Want to stay up to date on WP to Twitter? [Follow me on Twitter!](https://twitter.com/joedolson)
60
 
61
  = Future =
62
 
63
+ * Use apply_filters( 'wpt_tweet_sentence', $tweet, $post_ID ) to pass custom taxonomy Tweet formats - Pending WordPress support for taxonomy meta.
64
  * Add regex filter to detect URLs typed into Tweet fields for counting/shortening purposes. [todo]
65
+
66
+ = 3.0.0 =
67
+
68
+ * Handles case where post type identification could throw PHP warning if no post types were chosen to be Tweeted.
69
+ * Eliminated outdated compatibility function.
70
+ * Eliminated old update notices.
71
+ * General code cleanup.
72
+ * Code documentation.
73
+ * Updated media uploading to use Uploads endpoint, replacing deprecated update_with_media endpoint. [WP Tweets PRO]
74
+ * Simplifed short URL storage
75
+ * Decreased widget cache life from 1 hour to 30 minutes.
76
+ * Added fallback Normalizer class for cases when extension is not installed.
77
+ * Added notes for the 100 HTTP code return error.
78
+ * Moved Twitter server time check out of basic set-up & set up to only run on demand.
79
+ * Minor design changes.
80
 
81
  = 2.9.8 =
82
 
1074
 
1075
  = How can I help you make WP to Twitter a better plug-in? =
1076
 
1077
+ Writing and maintaining a plug-in is a lot of work. You can help me by providing detailed support requests (which saves me time), or by providing financial support, either via my [plug-in donations page](https://www.joedolson.com/donate/) or by [upgrading to WP Tweets Pro](https://www.joedolson.com/wp-tweets-pro/). Believe me, your donation really makes a difference!
1078
 
1079
  == Screenshots ==
1080
 
1087
 
1088
  == Upgrade Notice ==
1089
 
1090
+ * 3.0.0 - Changes storage format for short URL post meta. Upgrade cycle may take a while to process all posts.
 
 
wp-to-twitter-manager.php CHANGED
@@ -327,7 +327,6 @@ function wpt_update_settings() {
327
  }
328
  ?>
329
  <div class="wrap" id="wp-to-twitter">
330
- <?php wpt_commments_removed(); ?>
331
  <?php if ( $message ) { ?>
332
  <div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
333
  <?php
@@ -894,6 +893,7 @@ function wpt_sidebar() {
894
  </div>
895
  </div>
896
  </div>
 
897
  <?php if ( ! function_exists( 'wpt_pro_exists' ) ) { ?>
898
  <div class="ui-sortable meta-box-sortables">
899
  <div class="postbox">
@@ -905,13 +905,14 @@ function wpt_sidebar() {
905
  <strong><a
906
  href="http://www.joedolson.com/wp-tweets-pro/"><?php _e( 'Upgrade to <strong>WP Tweets PRO</strong>!', 'wp-to-twitter' ); ?></a></strong>
907
 
908
- <p><?php _e( 'Bonuses in the PRO upgrade:', 'wp-to-twitter' ); ?></p>
909
  <ul>
910
- <li><?php _e( 'Authors can post to their own Twitter accounts', 'wp-to-twitter' ); ?></li>
911
- <li><?php _e( 'Delay Tweets minutes or hours after you publish', 'wp-to-twitter' ); ?></li>
912
- <li><?php _e( 'Automatically schedule Tweets to post again later', 'wp-to-twitter' ); ?></li>
913
  <li><?php _e( 'Send Tweets for approved comments', 'wp-to-twitter' ); ?></li>
914
  <li><?php _e( 'Filter Tweets by category, tag, or custom taxonomy', 'wp-to-twitter' ); ?></li>
 
915
  </ul>
916
 
917
  </div>
@@ -923,6 +924,18 @@ function wpt_sidebar() {
923
  wpt_notes();
924
  }
925
  } ?>
 
 
 
 
 
 
 
 
 
 
 
 
926
  <div class="ui-sortable meta-box-sortables">
927
  <div class="postbox">
928
  <div class="handlediv"><span class="screen-reader-text">Click to toggle</span></div>
@@ -948,10 +961,76 @@ function wpt_sidebar() {
948
  <li><?php _e( "<code>#reference#</code>: Used only in co-tweeting. @reference to main account when posted to author account, @reference to author account in post to main account.", 'wp-to-twitter' ); ?></li>
949
  <?php } ?>
950
  </ul>
951
- <p><?php _e( "You can also create custom shortcodes to access WordPress custom fields. Use doubled square brackets surrounding the name of your custom field to add the value of that custom field to your status update. Example: <code>[[custom_field]]</code></p>", 'wp-to-twitter' ); ?>
 
 
 
 
 
 
 
 
952
  </div>
953
  </div>
954
  </div>
955
  </div>
956
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
957
  }
327
  }
328
  ?>
329
  <div class="wrap" id="wp-to-twitter">
 
330
  <?php if ( $message ) { ?>
331
  <div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
332
  <?php
893
  </div>
894
  </div>
895
  </div>
896
+
897
  <?php if ( ! function_exists( 'wpt_pro_exists' ) ) { ?>
898
  <div class="ui-sortable meta-box-sortables">
899
  <div class="postbox">
905
  <strong><a
906
  href="http://www.joedolson.com/wp-tweets-pro/"><?php _e( 'Upgrade to <strong>WP Tweets PRO</strong>!', 'wp-to-twitter' ); ?></a></strong>
907
 
908
+ <p><strong><?php _e( "What's in the premium add-on?", 'wp-to-twitter' ); ?></strong></p>
909
  <ul>
910
+ <li><?php _e( 'Post to multiple Twitter accounts', 'wp-to-twitter' ); ?></li>
911
+ <li><?php _e( 'Delay Tweets until after publishing', 'wp-to-twitter' ); ?></li>
912
+ <li><?php _e( 'Automatically schedule Tweets to post again', 'wp-to-twitter' ); ?></li>
913
  <li><?php _e( 'Send Tweets for approved comments', 'wp-to-twitter' ); ?></li>
914
  <li><?php _e( 'Filter Tweets by category, tag, or custom taxonomy', 'wp-to-twitter' ); ?></li>
915
+ <li><?php _e( 'Upload post images to Twitter', 'wp-to-twitter' ); ?></li>
916
  </ul>
917
 
918
  </div>
924
  wpt_notes();
925
  }
926
  } ?>
927
+
928
+ <div class="ui-sortable meta-box-sortables">
929
+ <div class="postbox">
930
+ <div class="handlediv"><span class="screen-reader-text">Click to toggle</span></div>
931
+ <h3 class='hndle'><?php _e( 'Twitter Time Check', 'wp-to-twitter' ); ?></h3>
932
+
933
+ <div class="inside server">
934
+ <?php wpt_do_server_check(); ?>
935
+ </div>
936
+ </div>
937
+ </div>
938
+
939
  <div class="ui-sortable meta-box-sortables">
940
  <div class="postbox">
941
  <div class="handlediv"><span class="screen-reader-text">Click to toggle</span></div>
961
  <li><?php _e( "<code>#reference#</code>: Used only in co-tweeting. @reference to main account when posted to author account, @reference to author account in post to main account.", 'wp-to-twitter' ); ?></li>
962
  <?php } ?>
963
  </ul>
964
+ <p>
965
+ <?php
966
+ _e( "Create custom shortcodes and access WordPress custom fields by using square brackets and the name of your custom field.", 'wp-to-twitter' );
967
+ ?>
968
+ <br />
969
+ <?php
970
+ _e( "<strong>Example:</strong> <code>[[custom_field]]</code>", 'wp-to-twitter' );
971
+ ?>
972
+ </p>
973
  </div>
974
  </div>
975
  </div>
976
  </div>
977
  <?php
978
+ }
979
+
980
+ function wpt_do_server_check( $test = false ) {
981
+ $wpt_server_string = get_option( 'wpt_server_string' );
982
+ if ( !$wpt_server_string || isset( $_GET['refresh_wpt_server_string'] ) || $test == true ) {
983
+ $server_time = date( DATE_COOKIE );
984
+ $response = wp_remote_get( "https://twitter.com/", array( 'timeout' => 30, 'redirection' => 1 ) );
985
+
986
+ if ( is_wp_error( $response ) ) {
987
+ $warning = '';
988
+ $error = $response->errors;
989
+ if ( is_array( $error ) ) {
990
+ $warning = "<ul>";
991
+ foreach ( $error as $k => $e ) {
992
+ foreach ( $e as $v ) {
993
+ $warning .= "<li>" . $v . "</li>";
994
+ }
995
+ }
996
+ $warning .= "</ul>";
997
+ }
998
+ $errors = "<li>" . $ssl . $warning . "</li>";
999
+ } else {
1000
+ $date = date( DATE_COOKIE, strtotime( $response['headers']['date'] ) );
1001
+ $errors = '';
1002
+ }
1003
+
1004
+ if ( ! is_wp_error( $response ) ) {
1005
+ if ( abs( strtotime( $server_time ) - strtotime( $response['headers']['date'] ) ) > 300 ) {
1006
+ $diff = __( 'Your time stamps are more than 5 minutes apart. Your server could lose its connection with Twitter.', 'wp-to-twitter' );
1007
+ } else {
1008
+ $diff = __( 'Your time stamp matches the Twitter server time', 'wp-to-twitter' );
1009
+ }
1010
+ $diff = "<li>$diff</li>";
1011
+ } else {
1012
+ $diff = "<li>" . __( 'WP to Twitter could not contact Twitter\'s remote server.', 'wp-to-twitter' ) . "</li>";
1013
+ }
1014
+
1015
+ $timezone = '<li>' . __( 'Your server timezone:', 'wp-to-twitter' ) . ' ' . date_default_timezone_get() . '</li>';
1016
+
1017
+ $search = array( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' );
1018
+ $replace = array( 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun' );
1019
+
1020
+ $server_time = str_replace( $search, $replace, $server_time );
1021
+ $date = str_replace( $search, $replace, $date );
1022
+
1023
+ $wpt_server_string =
1024
+ "<ul>
1025
+ <li>" . __( 'Your server time:', 'wp-to-twitter' ) . '<br /><code>' . $server_time . '</code>' . "</li>" .
1026
+ "<li>" . __( 'Twitter\'s server time: ', 'wp-to-twitter' ) . '<br /><code>' . $date . '</code>' . "</li>
1027
+ $timezone
1028
+ $diff
1029
+ $errors
1030
+ </ul>";
1031
+ update_option( 'wpt_server_string', $wpt_server_string );
1032
+ }
1033
+ echo $wpt_server_string;
1034
+ $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php?refresh_wpt_server_string=true' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php&amp;refresh_wpt_server_string=true' );
1035
+ echo "<p><a href='" . $admin_url . "'>" . __( 'Test again', 'wp-to-twitter' ) . "</a></p>";
1036
  }
wp-to-twitter-oauth.php CHANGED
@@ -121,9 +121,10 @@ function jd_update_oauth_settings( $auth = false, $post = false ) {
121
  $error_information = __( "WP to Twitter was unable to establish a connection to Twitter.", 'wp-to-twitter' );
122
  update_option( 'wpt_curl_error', "$error_information" );
123
  } else {
 
124
  $error_information = array(
125
  "http_code" => $connection->http_code,
126
- "status" => $connection->http_header['status']
127
  );
128
  $error_code = __( "Twitter response: http_code $error_information[http_code] - $error_information[status]", 'wp-to-twitter' );
129
  update_option( 'wpt_curl_error', $error_code );
@@ -180,27 +181,7 @@ function wtt_connect_oauth( $auth = false ) {
180
  echo '<div class="ui-sortable meta-box-sortables">';
181
  echo '<div class="postbox">';
182
  }
183
- $server_time = date( DATE_COOKIE );
184
- $response = wp_remote_get( "https://twitter.com/", array( 'timeout' => 1, 'redirection' => 1 ) );
185
- if ( is_wp_error( $response ) ) {
186
- $warning = '';
187
- $error = $response->errors;
188
- if ( is_array( $error ) ) {
189
- $warning = "<ul>";
190
- foreach ( $error as $k => $e ) {
191
- foreach ( $e as $v ) {
192
- $warning .= "<li>" . $v . "</li>";
193
- }
194
- }
195
- $warning .= "</ul>";
196
- }
197
- $ssl = __( "Connection Problems? If you're getting an SSL related error, you'll need to contact your host.", 'wp-to-twitter' );
198
- $date = __( "There was an error querying Twitter's servers", 'wp-to-twitter' );
199
- $errors = "<p>" . $ssl . "</p>" . $warning;
200
- } else {
201
- $date = date( DATE_COOKIE, strtotime( $response['headers']['date'] ) );
202
- $errors = '';
203
- }
204
  $class = ( $auth ) ? 'wpt-profile' : 'wpt-settings';
205
  $form = ( ! $auth ) ? '<form action="" method="post">' : '';
206
  $nonce = ( ! $auth ) ? wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false ) . '</form>' : '';
@@ -226,9 +207,6 @@ function wtt_connect_oauth( $auth = false ) {
226
  <div class="inside ' . $class . '">
227
  <div class="notes">
228
  <h4>' . __( 'WP to Twitter Set-up', 'wp-to-twitter' ) . '</h4>
229
- <p>' . __( 'Your server time:', 'wp-to-twitter' ) . ' <code>' . $server_time . '</code> ' . __( "Twitter's time:" ) . ' <code>' . $date . '</code>. ' . __( 'If these timestamps are not within 5 minutes of each other, your server will not connect to Twitter.', 'wp-to-twitter' ) . '</p>
230
- ' . $errors . '
231
- <p>' . __( 'Your server timezone (should be UTC,GMT,Europe/London or equivalent):', 'wp-to-twitter' ) . ' ' . date_default_timezone_get() . '</p>
232
  </div>
233
  <h4>' . __( '1. Register this site as an application on ', 'wp-to-twitter' ) . '<a href="https://apps.twitter.com/app/new/" target="_blank">' . __( 'Twitter\'s application registration page', 'wp-to-twitter' ) . '</a></h4>
234
  <ul>
@@ -293,11 +271,6 @@ function wtt_connect_oauth( $auth = false ) {
293
  } else {
294
  $submit = '<input type="checkbox" name="oauth_settings" value="wtt_twitter_disconnect" id="disconnect" /> <label for="disconnect">' . __( 'Disconnect your WordPress and Twitter Account', 'wp-to-twitter' ) . '</label>';
295
  }
296
- if ( ! is_wp_error( $response ) ) {
297
- $diff = ( abs( time() - strtotime( $response['headers']['date'] ) ) > 300 ) ? '<p> ' . __( 'Your time stamps are more than 5 minutes apart. Your server could lose its connection with Twitter.', 'wp-to-twitter' ) . '</p>' : '';
298
- } else {
299
- $diff = __( 'WP to Twitter could not contact Twitter\'s remote server. Here is the error triggered: ', 'wp-to-twitter' ) . $errors;
300
- }
301
 
302
  print( '
303
  <div class="handlediv"><span class="screen-reader-text">Click to toggle</span></div>
@@ -319,14 +292,8 @@ function wtt_connect_oauth( $auth = false ) {
319
  </div>
320
  </div>
321
  ' . $nonce . '
322
- <p>' . __( 'Your server time:', 'wp-to-twitter' ) . ' <code>' . $server_time . '</code>.<br />' . __( 'Twitter\'s server time: ', 'wp-to-twitter' ) . '<code>' . $date . '</code>.</p>
323
- ' . $errors . $diff . '</div>' );
324
- // sent as debugging
325
- global $wpt_server_string;
326
- $wpt_server_string =
327
- __( 'Your server time:', 'wp-to-twitter' ) . ' <code>' . $server_time . '</code>
328
- ' . __( 'Twitter\'s server time: ', 'wp-to-twitter' ) . '<code>' . $date . '</code>
329
- ' . $errors . $diff;
330
  }
331
  if ( ! $auth ) {
332
  echo "</div>";
121
  $error_information = __( "WP to Twitter was unable to establish a connection to Twitter.", 'wp-to-twitter' );
122
  update_option( 'wpt_curl_error', "$error_information" );
123
  } else {
124
+ $status = ( isset( $connection->http_header['status'] ) ) ? $connection->http_header['status'] : '404';
125
  $error_information = array(
126
  "http_code" => $connection->http_code,
127
+ "status" => $status
128
  );
129
  $error_code = __( "Twitter response: http_code $error_information[http_code] - $error_information[status]", 'wp-to-twitter' );
130
  update_option( 'wpt_curl_error', $error_code );
181
  echo '<div class="ui-sortable meta-box-sortables">';
182
  echo '<div class="postbox">';
183
  }
184
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  $class = ( $auth ) ? 'wpt-profile' : 'wpt-settings';
186
  $form = ( ! $auth ) ? '<form action="" method="post">' : '';
187
  $nonce = ( ! $auth ) ? wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false ) . '</form>' : '';
207
  <div class="inside ' . $class . '">
208
  <div class="notes">
209
  <h4>' . __( 'WP to Twitter Set-up', 'wp-to-twitter' ) . '</h4>
 
 
 
210
  </div>
211
  <h4>' . __( '1. Register this site as an application on ', 'wp-to-twitter' ) . '<a href="https://apps.twitter.com/app/new/" target="_blank">' . __( 'Twitter\'s application registration page', 'wp-to-twitter' ) . '</a></h4>
212
  <ul>
271
  } else {
272
  $submit = '<input type="checkbox" name="oauth_settings" value="wtt_twitter_disconnect" id="disconnect" /> <label for="disconnect">' . __( 'Disconnect your WordPress and Twitter Account', 'wp-to-twitter' ) . '</label>';
273
  }
 
 
 
 
 
274
 
275
  print( '
276
  <div class="handlediv"><span class="screen-reader-text">Click to toggle</span></div>
292
  </div>
293
  </div>
294
  ' . $nonce . '
295
+ </div>' );
296
+
 
 
 
 
 
 
297
  }
298
  if ( ! $auth ) {
299
  echo "</div>";
wp-to-twitter-shorteners.php CHANGED
@@ -242,39 +242,8 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
242
  function wpt_store_url( $post_ID, $url ) {
243
  if ( function_exists( 'jd_shorten_link' ) ) {
244
  $shortener = get_option( 'jd_shortener' );
245
- switch ( $shortener ) {
246
- case 0:
247
- case 1:
248
- case 4:
249
- $ext = '_wp';
250
- break;
251
- case 2:
252
- $ext = '_bitly';
253
- break;
254
- case 3:
255
- $ext = '_url';
256
- break;
257
- case 5:
258
- case 6:
259
- $ext = '_yourls';
260
- break;
261
- case 7:
262
- $ext = '_supr';
263
- break;
264
- case 8:
265
- $ext = '_goo';
266
- break;
267
- case 9:
268
- $ext = '_tfl';
269
- break;
270
- case 10:
271
- $ext = '_joturl';
272
- break;
273
- default:
274
- $ext = '_ind';
275
- }
276
- if ( get_post_meta( $post_ID, "_wp_jd$ext", true ) != $url ) {
277
- update_post_meta( $post_ID, "_wp_jd$ext", $url );
278
  }
279
  switch ( $shortener ) {
280
  case 0:
242
  function wpt_store_url( $post_ID, $url ) {
243
  if ( function_exists( 'jd_shorten_link' ) ) {
244
  $shortener = get_option( 'jd_shortener' );
245
+ if ( get_post_meta( $post_ID, '_wpt_short_url', true ) != $url ) {
246
+ update_post_meta( $post_ID, '_wpt_short_url', $url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
248
  switch ( $shortener ) {
249
  case 0:
wp-to-twitter.php CHANGED
@@ -3,11 +3,11 @@
3
  Plugin Name: WP to Twitter
4
  Plugin URI: http://www.joedolson.com/wp-to-twitter/
5
  Description: Posts a Tweet when you update your WordPress blog or post a link, using your URL shortening service. Rich in features for customizing and promoting your Tweets.
6
- Version: 2.9.8
7
  Author: Joseph Dolson
8
  Author URI: http://www.joedolson.com/
9
  */
10
- /* Copyright 2008-2014 Joseph C Dolson (email : plugins@joedolson.com)
11
 
12
  This program is free software; you can redistribute it and/or modify
13
  it under the terms of the GNU General Public License as published by
@@ -55,29 +55,9 @@ require_once( plugin_dir_path( __FILE__ ) . '/wpt-feed.php' );
55
  require_once( plugin_dir_path( __FILE__ ) . '/wpt-widget.php' );
56
 
57
  global $wpt_version;
58
- $wpt_version = "2.9.8";
59
  load_plugin_textdomain( 'wp-to-twitter', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
60
 
61
- function wpt_pro_compatibility() {
62
- global $wptp_version;
63
- $current_wptp_version = '1.7.2';
64
- if ( version_compare( $wptp_version, $current_wptp_version, '<' ) ) {
65
- echo "<div class='error notice'><p class='upgrade'>" . sprintf( __( 'The current version of WP Tweets PRO is <strong>%s</strong>. <a href="http://www.joedolson.com/account/">Update for best compatibility!</a>', 'wp-to-twitter' ), $current_wptp_version ) . "</p></div>";
66
- }
67
- }
68
-
69
- function wpt_commments_removed() {
70
- if ( isset( $_GET['dismiss'] ) ) {
71
- update_option( 'wpt_dismissed', 'true' );
72
- }
73
- if ( get_option( 'comment-published-update' ) == 1 && ! function_exists( 'wpt_pro_exists' ) && get_option( 'wpt_dismissed' ) != 'true' ) {
74
- $update_notice = sprintf( __( 'Tweeting of comments has been moved to <a href="%1$s">WP Tweets PRO</a>. You will need to upgrade in order to Tweet comments. <a href="%2$s">Dismiss</a>' ), 'http://www.joedolson.com/wp-tweets-pro/', admin_url( "options-general.php?page=wp-to-twitter/wp-to-twitter.php&dismiss=true" ) );
75
- if ( is_admin() ) {
76
- echo "<div class='updated'><p>" . ( $update_notice ) . "</p></div>";
77
- }
78
- }
79
- }
80
-
81
  // check for OAuth configuration
82
  function wpt_check_oauth( $auth = false ) {
83
  if ( ! function_exists( 'wtt_oauth_test' ) ) {
@@ -102,6 +82,7 @@ function wptotwitter_activate() {
102
  $prev_version = get_option( 'wp_to_twitter_version' );
103
  // this is a switch to plan for future versions
104
  $administrator = get_role( 'administrator' );
 
105
  $upgrade = version_compare( $prev_version, "2.4.0", "<" );
106
  if ( $upgrade ) {
107
  $perms = get_option( 'wtt_user_permissions' );
@@ -192,6 +173,7 @@ function wptotwitter_activate() {
192
  break;
193
  }
194
  }
 
195
  $upgrade = version_compare( $prev_version, "2.4.13", "<" );
196
  if ( $upgrade ) {
197
  $administrator->add_cap( 'wpt_can_tweet' );
@@ -213,9 +195,73 @@ function wptotwitter_activate() {
213
  if ( $upgrade ) {
214
  $administrator->add_cap( 'wpt_tweet_now' );
215
  }
 
 
 
 
 
 
 
216
  update_option( 'wp_to_twitter_version', $wpt_version );
217
  }
218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  // Function checks for an alternate URL to be Tweeted. Contribution by Bill Berry.
220
  function wpt_link( $post_ID ) {
221
  $ex_link = false;
@@ -273,7 +319,16 @@ function wpt_check_recent_tweet( $id, $auth ) {
273
  return false;
274
  }
275
 
276
- // This function performs the API post to Twitter
 
 
 
 
 
 
 
 
 
277
  function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false ) {
278
  $recent = wpt_check_recent_tweet( $id, $auth );
279
  $http_code = 0;
@@ -304,6 +359,8 @@ function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false
304
 
305
  return false;
306
  } else {
 
 
307
  // must be designated as media and have a valid attachment
308
  $attachment = ( $media ) ? wpt_post_attachment( $id ) : false;
309
  if ( $attachment ) {
@@ -313,41 +370,32 @@ function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false
313
  $attachment = false;
314
  }
315
  }
 
 
 
 
 
 
 
316
  // support for HTTP deprecated as of 1/14/2014 -- https://dev.twitter.com/discussions/24239
317
- $api = ( $media && $attachment ) ? "https://api.twitter.com/1.1/statuses/update_with_media.json" : "https://api.twitter.com/1.1/statuses/update.json";
318
  if ( wtt_oauth_test( $auth ) && ( $connection = wtt_oauth_connection( $auth ) ) ) {
319
- if ( $media && $attachment ) {
320
- $connection->media( $api, array(
321
- 'status' => $twit,
322
- 'source' => 'wp-to-twitter',
323
- 'include_entities' => 'true',
324
- 'id' => $id,
325
- 'auth' => $auth
326
- ) );
327
- } else {
328
- $connection->post( $api, array(
329
- 'status' => $twit,
330
- 'source' => 'wp-to-twitter',
331
- 'include_entities' => 'true'
332
- ) );
333
  }
 
334
  $http_code = ( $connection ) ? $connection->http_code : 'failed';
335
  } else if ( wtt_oauth_test( false ) && ( $connection = wtt_oauth_connection( false ) ) ) {
336
- if ( $media ) {
337
- $connection->media( $api, array(
338
- 'status' => $twit,
339
- 'source' => 'wp-to-twitter',
340
- 'include_entities' => 'true',
341
- 'id' => $id,
342
- 'auth' => $auth
343
- ) );
344
- } else {
345
- $connection->post( $api, array(
346
- 'status' => $twit,
347
- 'source' => 'wp-to-twitter',
348
- 'include_entities' => 'true'
349
- ) );
350
- }
351
  $http_code = ( $connection ) ? $connection->http_code : 'failed';
352
  }
353
  if ( empty( $connection ) ) {
@@ -362,6 +410,9 @@ function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false
362
  }
363
  $return = false;
364
  switch ( $http_code ) {
 
 
 
365
  case '200':
366
  $return = true;
367
  $error = __( "200 OK: Success!", 'wp-to-twitter' );
@@ -452,18 +503,39 @@ function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false
452
  }
453
  }
454
 
 
 
 
 
 
 
 
 
455
  function fake_normalize( $string ) {
456
- if ( version_compare( PHP_VERSION, '5.0.0', '>=' ) && function_exists( 'normalizer_normalize' ) && 1 == 2 ) {
457
  if ( normalizer_is_normalized( $string ) ) {
458
  return $string;
459
  }
460
 
461
  return normalizer_normalize( $string );
462
  } else {
463
- return preg_replace( '~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|mp);~i', '$1', htmlentities( $string, ENT_NOQUOTES, 'UTF-8' ) );
 
 
 
 
 
 
464
  }
465
  }
466
 
 
 
 
 
 
 
 
467
  function wpt_is_ssl( $url ) {
468
  if ( stripos( $url, 'https' ) ) {
469
  return true;
@@ -472,6 +544,9 @@ function wpt_is_ssl( $url ) {
472
  }
473
  }
474
 
 
 
 
475
  function wpt_in_allowed_category( $array ) {
476
  $allowed_categories = get_option( 'tweet_categories' );
477
  if ( is_array( $array ) && is_array( $allowed_categories ) ) {
@@ -486,6 +561,13 @@ function wpt_in_allowed_category( $array ) {
486
  }
487
  }
488
 
 
 
 
 
 
 
 
489
  function jd_post_info( $post_ID ) {
490
  $encoding = get_option( 'blog_charset' );
491
  if ( $encoding == '' ) {
@@ -541,14 +623,20 @@ function jd_post_info( $post_ID ) {
541
  $values['shortUrl'] = wpt_short_url( $post_ID );
542
  $values['postStatus'] = $post->post_status;
543
  $values['postType'] = $post->post_type;
 
 
 
 
 
 
 
544
  $values = apply_filters( 'wpt_post_info', $values, $post_ID );
545
 
546
  return $values;
547
  }
548
 
549
  /**
550
- * This is a terrible function, and badly needs to be rewritten.
551
- *
552
  * @param $post_id
553
  *
554
  * @return mixed
@@ -558,38 +646,17 @@ function wpt_short_url( $post_id ) {
558
  if ( ! $post_id ) {
559
  $post_id = $post_ID;
560
  }
561
- $short = get_post_meta( $post_id, '_wp_jd_bitly', true );
562
- if ( $short == "" ) {
563
- $short = get_post_meta( $post_id, '_wp_jd_goo', true );
564
- }
565
- if ( $short == "" ) {
566
- $short = get_post_meta( $post_id, '_wp_jd_supr', true );
567
- }
568
- if ( $short == "" ) {
569
- $short = get_post_meta( $post_id, '_wp_jd_wp', true );
570
- }
571
- if ( $short == "" ) {
572
- $short = get_post_meta( $post_id, '_wp_jd_ind', true );
573
- }
574
- if ( $short == "" ) {
575
- $short = get_post_meta( $post_id, '_wp_jd_yourls', true );
576
- }
577
- if ( $short == "" ) {
578
- $short = get_post_meta( $post_id, '_wp_jd_url', true );
579
- }
580
- if ( $short == "" ) {
581
- $short = get_post_meta( $post_id, '_wp_jd_joturl', true );
582
- }
583
- if ( $short == "" ) {
584
- $short = get_post_meta( $post_id, '_wp_jd_target', true );
585
- }
586
- if ( $short == "" ) {
587
- $short = get_post_meta( $post_id, '_wp_jd_clig', true );
588
- }
589
-
590
  return $short;
591
  }
592
 
 
 
 
 
 
 
 
593
  function wpt_post_with_media( $post_ID, $post_info = array() ) {
594
  $return = false;
595
  if ( isset( $post_info['wpt_image'] ) && $post_info['wpt_image'] == 1 ) {
@@ -607,6 +674,9 @@ function wpt_post_with_media( $post_ID, $post_info = array() ) {
607
  return apply_filters( 'wpt_upload_media', $return, $post_ID );
608
  }
609
 
 
 
 
610
  function wpt_category_limit( $post_type, $post_info, $post_ID ) {
611
  $post_type_cats = get_object_taxonomies( $post_type );
612
  $continue = true;
@@ -627,6 +697,14 @@ function wpt_category_limit( $post_type, $post_info, $post_ID ) {
627
  return apply_filters( 'wpt_filter_terms', $continue, $args );
628
  }
629
 
 
 
 
 
 
 
 
 
630
  function jd_twit( $post_ID, $type = 'instant' ) {
631
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $post_ID ) ) {
632
  return $post_ID;
@@ -795,7 +873,7 @@ function jd_twit( $post_ID, $type = 'instant' ) {
795
  foreach ( $wpt_selected_users as $acct ) {
796
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
797
  for ( $i = 1; $i <= $repeat; $i ++ ) {
798
- $continue = apply_filters( 'wpt_allow_reposts', true, $i, $post_ID );
799
  if ( $continue ) {
800
  $retweet = apply_filters( 'wpt_set_retweet_text', $template, $i );
801
  $retweet = jd_truncate_tweet( $retweet, $post_info, $post_ID, true, $acct );
@@ -854,7 +932,13 @@ function jd_twit( $post_ID, $type = 'instant' ) {
854
  return $post_ID;
855
  }
856
 
857
- // Add Tweets on links in Blogroll
 
 
 
 
 
 
858
  function jd_twit_link( $link_ID ) {
859
  wpt_check_version();
860
  $thislinkprivate = $_POST['link_visible'];
@@ -885,6 +969,13 @@ function jd_twit_link( $link_ID ) {
885
  }
886
  }
887
 
 
 
 
 
 
 
 
888
  function wpt_generate_hash_tags( $post_ID ) {
889
  $hashtags = '';
890
  $term_meta = $t_id = false;
@@ -944,7 +1035,9 @@ function wpt_generate_hash_tags( $post_ID ) {
944
  }
945
 
946
  add_action( 'admin_menu', 'jd_add_twitter_outer_box' );
947
-
 
 
948
  function jd_add_twitter_outer_box() {
949
  wpt_check_version();
950
  // add Twitter panel to post types where it's enabled.
@@ -960,6 +1053,9 @@ function jd_add_twitter_outer_box() {
960
  }
961
  }
962
 
 
 
 
963
  function jd_add_twitter_inner_box( $post ) {
964
  if ( current_user_can( 'wpt_can_tweet' ) ) {
965
  $is_pro = ( function_exists( 'wpt_pro_exists' ) ) ? 'pro' : 'free'; ?>
@@ -997,9 +1093,6 @@ function jd_add_twitter_inner_box( $post ) {
997
  $tweet_status = sprintf( __( 'Tweeting %s edits is disabled.', 'wp-to-twitter' ), $type );
998
  }
999
 
1000
- if ( current_user_can( 'manage_options' ) && function_exists( 'wpt_pro_exists' ) ) {
1001
- wpt_pro_compatibility();
1002
- }
1003
  if ( $status == 'publish' && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1004
  ?>
1005
  <div class='tweet-buttons'>
@@ -1172,6 +1265,14 @@ function jd_add_twitter_inner_box( $post ) {
1172
  }
1173
  }
1174
 
 
 
 
 
 
 
 
 
1175
  function wpt_show_tweets( $previous_tweets, $failed_tweets ) {
1176
  if ( ! is_array( $previous_tweets ) && $previous_tweets != '' ) {
1177
  $previous_tweets = array( 0 => $previous_tweets );
@@ -1226,6 +1327,9 @@ function wpt_show_tweets( $previous_tweets, $failed_tweets ) {
1226
  }
1227
 
1228
  add_action( 'admin_enqueue_scripts', 'wpt_admin_scripts', 10, 1 );
 
 
 
1229
  function wpt_admin_scripts() {
1230
  global $current_screen;
1231
  if ( $current_screen->base == 'post' || $current_screen->id == 'wp-tweets-pro_page_wp-to-twitter-schedule' ) {
@@ -1248,6 +1352,11 @@ function wpt_admin_scripts() {
1248
  }
1249
 
1250
  add_action( 'wp_ajax_wpt_tweet', 'wpt_ajax_tweet' );
 
 
 
 
 
1251
  function wpt_ajax_tweet() {
1252
  if ( ! check_ajax_referer( 'wpt-tweet-nonce', 'security', false ) ) {
1253
  echo "Invalid Security Check";
@@ -1301,7 +1410,10 @@ function wpt_ajax_tweet() {
1301
  die;
1302
  }
1303
 
1304
-
 
 
 
1305
  function wpt_admin_script() {
1306
  global $current_screen;
1307
  if ( $current_screen->base == 'post' || $current_screen->id == 'wp-tweets-pro_page_wp-to-twitter-schedule' ) {
@@ -1333,9 +1445,12 @@ function wpt_admin_script() {
1333
  }
1334
  }
1335
 
1336
- add_action( 'admin_head', 'wpt_admin_script' );
1337
-
1338
- // Post the Custom Tweet into the post meta table
 
 
 
1339
  function post_jd_twitter( $id ) {
1340
  if ( empty( $_POST ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $id ) || isset( $_POST['_inline_edit'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! wpt_in_post_type( $id ) ) {
1341
  return;
@@ -1364,16 +1479,7 @@ function post_jd_twitter( $id ) {
1364
  if ( isset( $_POST['wpt_clear_history'] ) && $_POST['wpt_clear_history'] == 'clear' ) {
1365
  delete_post_meta( $id, '_wpt_failed' );
1366
  delete_post_meta( $id, '_jd_wp_twitter' );
1367
- delete_post_meta( $id, '_wp_jd_supr' );
1368
- delete_post_meta( $id, '_wp_jd_ind' );
1369
- delete_post_meta( $id, '_wp_jd_bitly' );
1370
- delete_post_meta( $id, '_wp_jd_wp' );
1371
- delete_post_meta( $id, '_wp_jd_yourls' );
1372
- delete_post_meta( $id, '_wp_jd_url' );
1373
- delete_post_meta( $id, '_wp_jd_goo' );
1374
- delete_post_meta( $id, '_wp_jd_target' );
1375
- delete_post_meta( $id, '_wp_jd_clig' );
1376
- delete_post_meta( $id, '_wp_jd_joturl' );
1377
  }
1378
  // WPT PRO //
1379
  $update = apply_filters( 'wpt_insert_post', $_POST, $id );
@@ -1384,6 +1490,37 @@ function post_jd_twitter( $id ) {
1384
  }
1385
  }
1386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1387
  function wpt_twitter_profile() {
1388
  global $user_ID;
1389
  get_currentuserinfo();
@@ -1444,24 +1581,9 @@ function wpt_twitter_profile() {
1444
  }
1445
  }
1446
 
1447
- function wpt_custom_shortcodes( $sentence, $post_ID ) {
1448
- $pattern = '/([([\[\]?)([A-Za-z0-9-_])*(\]\]]?)+/';
1449
- $params = array( 0 => "[[", 1 => "]]" );
1450
- preg_match_all( $pattern, $sentence, $matches );
1451
- if ( $matches && is_array( $matches[0] ) ) {
1452
- foreach ( $matches[0] as $value ) {
1453
- $shortcode = "$value";
1454
- $field = str_replace( $params, "", $shortcode );
1455
- $custom = apply_filters( 'wpt_custom_shortcode', strip_tags( get_post_meta( $post_ID, $field, true ) ), $post_ID, $field );
1456
- $sentence = str_replace( $shortcode, $custom, $sentence );
1457
- }
1458
-
1459
- return $sentence;
1460
- } else {
1461
- return $sentence;
1462
- }
1463
- }
1464
-
1465
  function wpt_twitter_save_profile() {
1466
  global $user_ID;
1467
  get_currentuserinfo();
@@ -1480,7 +1602,10 @@ function wpt_twitter_save_profile() {
1480
  apply_filters( 'wpt_save_user', $edit_id, $_POST );
1481
  }
1482
 
1483
- // Add the administrative settings to the "Settings" menu.
 
 
 
1484
  function jd_addTwitterAdminPages() {
1485
  if ( function_exists( 'add_options_page' ) && ! function_exists( 'wpt_pro_functions' ) ) {
1486
  add_options_page( 'WP to Twitter', 'WP to Twitter', 'manage_options', __FILE__, 'wpt_update_settings' );
@@ -1488,12 +1613,18 @@ function jd_addTwitterAdminPages() {
1488
  }
1489
 
1490
  add_action( 'admin_head', 'jd_addTwitterAdminStyles' );
 
 
 
1491
  function jd_addTwitterAdminStyles() {
1492
  if ( isset( $_GET['page'] ) && ( $_GET['page'] == "wp-to-twitter" || $_GET['page'] == "wp-to-twitter/wp-to-twitter.php" || $_GET['page'] == "wp-tweets-pro" || $_GET['page'] == "wp-to-twitter-schedule" || $_GET['page'] == "wp-to-twitter-tweets" || $_GET['page'] == "wp-to-twitter-errors" ) ) {
1493
  wp_enqueue_style( 'wpt-styles', plugins_url( 'css/styles.css', __FILE__ ) );
1494
  }
1495
  }
1496
 
 
 
 
1497
  function wpt_plugin_action( $links, $file ) {
1498
  if ( $file == plugin_basename( dirname( __FILE__ ) . '/wp-to-twitter.php' ) ) {
1499
  $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php' );
@@ -1516,6 +1647,11 @@ if ( get_option( 'jd_individual_twitter_users' ) == '1' ) {
1516
  }
1517
 
1518
  add_action( 'in_plugin_update_message-wp-to-twitter/wp-to-twitter.php', 'wpt_plugin_update_message' );
 
 
 
 
 
1519
  function wpt_plugin_update_message() {
1520
  global $wpt_version;
1521
  $note = '';
@@ -1538,20 +1674,31 @@ if ( get_option( 'jd_twit_blogroll' ) == '1' ) {
1538
  add_action( 'save_post', 'wpt_twit', 16 );
1539
  add_action( 'save_post', 'post_jd_twitter', 10 );
1540
 
 
 
 
 
 
 
 
1541
  function wpt_in_post_type( $id ) {
1542
  $post_type_settings = get_option( 'wpt_post_types' );
1543
- $post_types = array_keys( $post_type_settings );
1544
- $type = get_post_type( $id );
1545
- if ( in_array( $type, $post_types ) ) {
1546
- if ( $post_type_settings[ $type ]['post-edited-update'] == '1' || $post_type_settings[ $type ]['post-published-update'] == '1' ) {
1547
- return true;
 
 
1548
  }
1549
  }
1550
-
1551
  return false;
1552
  }
1553
 
1554
  add_action( 'future_to_publish', 'wpt_future_to_publish', 16 );
 
 
 
1555
  function wpt_future_to_publish( $post ) {
1556
  $id = $post->ID;
1557
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
@@ -1560,6 +1707,9 @@ function wpt_future_to_publish( $post ) {
1560
  wpt_twit_future( $id );
1561
  }
1562
 
 
 
 
1563
  function wpt_twit( $id ) {
1564
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
1565
  return;
@@ -1574,6 +1724,11 @@ function wpt_twit( $id ) {
1574
  add_action( 'xmlrpc_publish_post', 'wpt_twit_xmlrpc' );
1575
  add_action( 'publish_phone', 'wpt_twit_xmlrpc' );
1576
 
 
 
 
 
 
1577
  function wpt_twit_future( $id ) {
1578
  set_transient( '_wpt_twit_future', $id, 10 );
1579
  // instant action has already run for this post. // prevent running actions twice (need both for older WP)
@@ -1585,6 +1740,11 @@ function wpt_twit_future( $id ) {
1585
  jd_twit( $id, 'future' );
1586
  }
1587
 
 
 
 
 
 
1588
  function wpt_twit_instant( $id ) {
1589
  set_transient( '_wpt_twit_instant', $id, 10 );
1590
  // future action has already run for this post.
@@ -1602,6 +1762,9 @@ function wpt_twit_instant( $id ) {
1602
  jd_twit( $id, 'instant' );
1603
  }
1604
 
 
 
 
1605
  function wpt_twit_xmlrpc( $id ) {
1606
  set_transient( '_wpt_twit_xmlrpc', $id, 10 );
1607
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
@@ -1612,12 +1775,18 @@ function wpt_twit_xmlrpc( $id ) {
1612
  }
1613
 
1614
  add_action( 'wpt_schedule_promotion_action', 'wpt_schedule_promotion' );
 
 
 
1615
  function wpt_schedule_promotion() {
1616
  if ( ! function_exists( 'wpt_pro_exists' ) && get_option( 'wpt_promotion_scheduled' ) == 1 ) {
1617
  update_option( 'wpt_promotion_scheduled', 2 );
1618
  }
1619
  }
1620
 
 
 
 
1621
  function wpt_dismiss_promotion() {
1622
  if ( isset( $_GET['dismiss'] ) && $_GET['dismiss'] == 'promotion' ) {
1623
  update_option( 'wpt_promotion_scheduled', 3 );
@@ -1627,6 +1796,9 @@ function wpt_dismiss_promotion() {
1627
  wpt_dismiss_promotion();
1628
 
1629
  add_action( 'admin_notices', 'wpt_promotion_notice' );
 
 
 
1630
  function wpt_promotion_notice() {
1631
  if ( current_user_can( 'activate_plugins' ) && get_option( 'wpt_promotion_scheduled' ) == 2 && get_option( 'jd_donations' ) != 1 ) {
1632
  $upgrade = "http://www.joedolson.com/wp-tweets-pro/";
@@ -1635,10 +1807,10 @@ function wpt_promotion_notice() {
1635
  }
1636
  }
1637
 
1638
- add_action( 'admin_menu', 'jd_addTwitterAdminPages' );
1639
-
1640
- /* Enqueue styles for Twitter feed */
1641
  add_action( 'wp_enqueue_scripts', 'wpt_stylesheet' );
 
 
 
1642
  function wpt_stylesheet() {
1643
  $apply = apply_filters( 'wpt_enqueue_feed_styles', true );
1644
  if ( $apply ) {
@@ -1649,6 +1821,13 @@ function wpt_stylesheet() {
1649
  }
1650
 
1651
  add_filter( 'wpt_enqueue_feed_styles', 'wpt_permit_feed_styles' );
 
 
 
 
 
 
 
1652
  function wpt_permit_feed_styles( $value ) {
1653
  if ( get_option( 'wpt_permit_feed_styles' ) == 1 ) {
1654
  $value = false;
3
  Plugin Name: WP to Twitter
4
  Plugin URI: http://www.joedolson.com/wp-to-twitter/
5
  Description: Posts a Tweet when you update your WordPress blog or post a link, using your URL shortening service. Rich in features for customizing and promoting your Tweets.
6
+ Version: 3.0.0
7
  Author: Joseph Dolson
8
  Author URI: http://www.joedolson.com/
9
  */
10
+ /* Copyright 2008-2015 Joseph C Dolson (email : plugins@joedolson.com)
11
 
12
  This program is free software; you can redistribute it and/or modify
13
  it under the terms of the GNU General Public License as published by
55
  require_once( plugin_dir_path( __FILE__ ) . '/wpt-widget.php' );
56
 
57
  global $wpt_version;
58
+ $wpt_version = "3.0.0";
59
  load_plugin_textdomain( 'wp-to-twitter', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  // check for OAuth configuration
62
  function wpt_check_oauth( $auth = false ) {
63
  if ( ! function_exists( 'wtt_oauth_test' ) ) {
82
  $prev_version = get_option( 'wp_to_twitter_version' );
83
  // this is a switch to plan for future versions
84
  $administrator = get_role( 'administrator' );
85
+ // version 2.4.0: 05/20/2012
86
  $upgrade = version_compare( $prev_version, "2.4.0", "<" );
87
  if ( $upgrade ) {
88
  $perms = get_option( 'wtt_user_permissions' );
173
  break;
174
  }
175
  }
176
+ // version 2.4.13: 10/12/2012
177
  $upgrade = version_compare( $prev_version, "2.4.13", "<" );
178
  if ( $upgrade ) {
179
  $administrator->add_cap( 'wpt_can_tweet' );
195
  if ( $upgrade ) {
196
  $administrator->add_cap( 'wpt_tweet_now' );
197
  }
198
+
199
+ $upgrade = version_compare( $prev_version, "2.9.8", "<" );
200
+ if ( $upgrade ) {
201
+ // migrate stored short URL fields.
202
+ wpt_migrate_url_meta();
203
+ }
204
+
205
  update_option( 'wp_to_twitter_version', $wpt_version );
206
  }
207
 
208
+
209
+ /* Function migrates post meta to new format. */
210
+ function wpt_migrate_url_meta() {
211
+ $posts = get_posts(
212
+ array( 'numberposts'=>-1, 'meta_query'=>
213
+ array(
214
+ array(
215
+ 'key' => '_wp_jd_target',
216
+ 'value' => 'http',
217
+ 'compare' => 'LIKE'
218
+ )
219
+ )
220
+ )
221
+ );
222
+ foreach ( $posts as $post ) {
223
+ $id = $post->ID;
224
+ $short = '';
225
+ if ( $short == "" ) {
226
+ $short = get_post_meta( $post_id, '_wp_jd_goo', true );
227
+ delete_post_meta( $id, '_wp_jd_goo' );
228
+ }
229
+ if ( $short == "" ) {
230
+ $short = get_post_meta( $post_id, '_wp_jd_supr', true );
231
+ delete_post_meta( $id, '_wp_jd_supr' );
232
+ }
233
+ if ( $short == "" ) {
234
+ $short = get_post_meta( $post_id, '_wp_jd_wp', true );
235
+ delete_post_meta( $id, '_wp_jd_wp' );
236
+ }
237
+ if ( $short == "" ) {
238
+ $short = get_post_meta( $post_id, '_wp_jd_ind', true );
239
+ delete_post_meta( $id, '_wp_jd_ind' );
240
+ }
241
+ if ( $short == "" ) {
242
+ $short = get_post_meta( $post_id, '_wp_jd_yourls', true );
243
+ delete_post_meta( $id, '_wp_jd_yourls' );
244
+ }
245
+ if ( $short == "" ) {
246
+ $short = get_post_meta( $post_id, '_wp_jd_url', true );
247
+ delete_post_meta( $id, '_wp_jd_url' );
248
+ }
249
+ if ( $short == "" ) {
250
+ $short = get_post_meta( $post_id, '_wp_jd_joturl', true );
251
+ delete_post_meta( $id, '_wp_jd_joturl' );
252
+ }
253
+ if ( $short == "" ) {
254
+ // don't delete target link
255
+ $short = get_post_meta( $post_id, '_wp_jd_target', true );
256
+ }
257
+ if ( $short == "" ) {
258
+ $short = get_post_meta( $post_id, '_wp_jd_clig', true );
259
+ delete_post_meta( $id, '_wp_jd_clig' );
260
+ }
261
+ update_post_meta( $id, '_wpt_short_url', $short );
262
+ }
263
+ }
264
+
265
  // Function checks for an alternate URL to be Tweeted. Contribution by Bill Berry.
266
  function wpt_link( $post_ID ) {
267
  $ex_link = false;
319
  return false;
320
  }
321
 
322
+ /**
323
+ * Performs the API post to Twitter
324
+ *
325
+ * @param string $twit Text of Tweet to be sent to Twitter
326
+ * @param integer $auth Author ID
327
+ * @param integer $id Post ID
328
+ * @param boolean $media Whether to upload media attached to the post specified in $id
329
+ *
330
+ * @return boolean Success of query.
331
+ */
332
  function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false ) {
333
  $recent = wpt_check_recent_tweet( $id, $auth );
334
  $http_code = 0;
359
 
360
  return false;
361
  } else {
362
+ // if this post has already been tweeted with Media, we can skip the upload phase.
363
+ $media_id = false;
364
  // must be designated as media and have a valid attachment
365
  $attachment = ( $media ) ? wpt_post_attachment( $id ) : false;
366
  if ( $attachment ) {
370
  $attachment = false;
371
  }
372
  }
373
+ $api = "https://api.twitter.com/1.1/statuses/update.json";
374
+ $upload_api = 'https://upload.twitter.com/1.1/media/upload.json';
375
+ $status = array(
376
+ 'status' => $twit,
377
+ 'source' => 'wp-to-twitter',
378
+ 'include_entities' => 'true'
379
+ );
380
  // support for HTTP deprecated as of 1/14/2014 -- https://dev.twitter.com/discussions/24239
 
381
  if ( wtt_oauth_test( $auth ) && ( $connection = wtt_oauth_connection( $auth ) ) ) {
382
+ if ( $media && $attachment && !$media_id ) {
383
+ $media_id = $connection->media( $upload_api, array( 'auth'=>$auth, 'media'=>$attachment ) );
384
+ if ( $media_id ) {
385
+ $status['media_ids'] = $media_id;
386
+ }
 
 
 
 
 
 
 
 
 
387
  }
388
+ $connection->post( $api, $status );
389
  $http_code = ( $connection ) ? $connection->http_code : 'failed';
390
  } else if ( wtt_oauth_test( false ) && ( $connection = wtt_oauth_connection( false ) ) ) {
391
+ if ( $media && $attachment && !$media_id ) {
392
+ $media_id = $connection->media( $upload_api, array( 'auth'=>$auth, 'media'=>$attachment ) );
393
+
394
+ if ( $media_id ) {
395
+ $status['media_ids'] = $media_id;
396
+ }
397
+ }
398
+ $connection->post( $api, $status );
 
 
 
 
 
 
 
399
  $http_code = ( $connection ) ? $connection->http_code : 'failed';
400
  }
401
  if ( empty( $connection ) ) {
410
  }
411
  $return = false;
412
  switch ( $http_code ) {
413
+ case '100':
414
+ $error = __( "100 Continue: Twitter received the header of your submission, but your server did not follow through by sending the body of the data.", 'wp-to-twitter' );
415
+ break;
416
  case '200':
417
  $return = true;
418
  $error = __( "200 OK: Success!", 'wp-to-twitter' );
503
  }
504
  }
505
 
506
+
507
+ /**
508
+ * For servers without PEAR normalize installed, approximates normalization. With normalizer, executes normalization on string.
509
+ *
510
+ * @param string Text to normalize
511
+ *
512
+ * @return string Normalized text.
513
+ */
514
  function fake_normalize( $string ) {
515
+ if ( version_compare( PHP_VERSION, '5.0.0', '>=' ) && function_exists( 'normalizer_normalize' ) ) {
516
  if ( normalizer_is_normalized( $string ) ) {
517
  return $string;
518
  }
519
 
520
  return normalizer_normalize( $string );
521
  } else {
522
+ $normalizer = new WPT_Normalizer();
523
+ if ( $normalizer->isNormalized( $string ) ) {
524
+ return $string;
525
+ }
526
+
527
+ return $normalizer->normalize( $string );
528
+ //return preg_replace( '~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|mp);~i', '$1', htmlentities( $string, ENT_NOQUOTES, 'UTF-8' ) );
529
  }
530
  }
531
 
532
+ /**
533
+ * Test URL to see if is pointing to https location.
534
+ *
535
+ * @param string $url
536
+ *
537
+ * @return boolean
538
+ */
539
  function wpt_is_ssl( $url ) {
540
  if ( stripos( $url, 'https' ) ) {
541
  return true;
544
  }
545
  }
546
 
547
+ /**
548
+ * Deprecated; still used if configured. Uses old option 'tweet_categories' and verifies whether category of current post allows it to be Tweeted.
549
+ */
550
  function wpt_in_allowed_category( $array ) {
551
  $allowed_categories = get_option( 'tweet_categories' );
552
  if ( is_array( $array ) && is_array( $allowed_categories ) ) {
561
  }
562
  }
563
 
564
+ /**
565
+ * Builds array of post info for use in Tweet functions.
566
+ *
567
+ * @param integer $post_ID Post ID.
568
+ *
569
+ * @return array Post data used in Tweet functions.
570
+ */
571
  function jd_post_info( $post_ID ) {
572
  $encoding = get_option( 'blog_charset' );
573
  if ( $encoding == '' ) {
623
  $values['shortUrl'] = wpt_short_url( $post_ID );
624
  $values['postStatus'] = $post->post_status;
625
  $values['postType'] = $post->post_type;
626
+ /**
627
+ * Filters post array to insert custom data that can be used in Tweet process.
628
+ *
629
+ * @param array $values
630
+ * @param integer $post_ID
631
+ * @return array $values
632
+ */
633
  $values = apply_filters( 'wpt_post_info', $values, $post_ID );
634
 
635
  return $values;
636
  }
637
 
638
  /**
639
+ * Retrieve stored short URL.
 
640
  * @param $post_id
641
  *
642
  * @return mixed
646
  if ( ! $post_id ) {
647
  $post_id = $post_ID;
648
  }
649
+ $short = get_post_meta( $post_id, '_wpt_short_url', true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650
  return $short;
651
  }
652
 
653
+ /**
654
+ * Identify whether a post should be uploading media. Test settings and verify whether post has images that can be uploaded.
655
+ *
656
+ * @param integer $post_ID
657
+ * @param array $post_info
658
+ * @return boolean
659
+ */
660
  function wpt_post_with_media( $post_ID, $post_info = array() ) {
661
  $return = false;
662
  if ( isset( $post_info['wpt_image'] ) && $post_info['wpt_image'] == 1 ) {
674
  return apply_filters( 'wpt_upload_media', $return, $post_ID );
675
  }
676
 
677
+ /**
678
+ * @deprecated
679
+ */
680
  function wpt_category_limit( $post_type, $post_info, $post_ID ) {
681
  $post_type_cats = get_object_taxonomies( $post_type );
682
  $continue = true;
697
  return apply_filters( 'wpt_filter_terms', $continue, $args );
698
  }
699
 
700
+ /**
701
+ * Set up a Tweet to be sent.
702
+ *
703
+ * @param integer $post_ID Post ID.
704
+ * @param string $type Publishing context (publishing, scheduled, xmlrpc, etc.)
705
+ *
706
+ * @return integer $post_ID
707
+ */
708
  function jd_twit( $post_ID, $type = 'instant' ) {
709
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $post_ID ) ) {
710
  return $post_ID;
873
  foreach ( $wpt_selected_users as $acct ) {
874
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
875
  for ( $i = 1; $i <= $repeat; $i ++ ) {
876
+ $continue = apply_filters( 'wpt_allow_reposts', true, $i, $post_ID, $acct );
877
  if ( $continue ) {
878
  $retweet = apply_filters( 'wpt_set_retweet_text', $template, $i );
879
  $retweet = jd_truncate_tweet( $retweet, $post_info, $post_ID, true, $acct );
932
  return $post_ID;
933
  }
934
 
935
+ /**
936
+ * Send Tweets on links in link manager. Only active if Link plug-in is installed.
937
+ *
938
+ * @param integer $link_ID Database ID for link.
939
+ *
940
+ * @return mixed boolean/integer link ID if successful, false if failure.
941
+ */
942
  function jd_twit_link( $link_ID ) {
943
  wpt_check_version();
944
  $thislinkprivate = $_POST['link_visible'];
969
  }
970
  }
971
 
972
+ /**
973
+ * Generate hash tags from tags set on post.
974
+ *
975
+ * @param integer $post_ID Post ID.
976
+ *
977
+ * @return string $hashtags Hashtags in format needed for Tweet.
978
+ */
979
  function wpt_generate_hash_tags( $post_ID ) {
980
  $hashtags = '';
981
  $term_meta = $t_id = false;
1035
  }
1036
 
1037
  add_action( 'admin_menu', 'jd_add_twitter_outer_box' );
1038
+ /**
1039
+ * Set up post meta box.
1040
+ */
1041
  function jd_add_twitter_outer_box() {
1042
  wpt_check_version();
1043
  // add Twitter panel to post types where it's enabled.
1053
  }
1054
  }
1055
 
1056
+ /**
1057
+ * Print post meta box
1058
+ */
1059
  function jd_add_twitter_inner_box( $post ) {
1060
  if ( current_user_can( 'wpt_can_tweet' ) ) {
1061
  $is_pro = ( function_exists( 'wpt_pro_exists' ) ) ? 'pro' : 'free'; ?>
1093
  $tweet_status = sprintf( __( 'Tweeting %s edits is disabled.', 'wp-to-twitter' ), $type );
1094
  }
1095
 
 
 
 
1096
  if ( $status == 'publish' && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1097
  ?>
1098
  <div class='tweet-buttons'>
1265
  }
1266
  }
1267
 
1268
+ /**
1269
+ * Format history of Tweets attempted on current post.
1270
+ *
1271
+ * @param array $previous_tweets Array of successfully sent Tweets on this post.
1272
+ * @param array $failed_tweets Array of failed Tweets sent on this post.
1273
+ *
1274
+ * @return string Formatted list of Tweets.
1275
+ */
1276
  function wpt_show_tweets( $previous_tweets, $failed_tweets ) {
1277
  if ( ! is_array( $previous_tweets ) && $previous_tweets != '' ) {
1278
  $previous_tweets = array( 0 => $previous_tweets );
1327
  }
1328
 
1329
  add_action( 'admin_enqueue_scripts', 'wpt_admin_scripts', 10, 1 );
1330
+ /**
1331
+ * Enqueue admin scripts for WP to Twitter and WP Tweets PRO.
1332
+ */
1333
  function wpt_admin_scripts() {
1334
  global $current_screen;
1335
  if ( $current_screen->base == 'post' || $current_screen->id == 'wp-tweets-pro_page_wp-to-twitter-schedule' ) {
1352
  }
1353
 
1354
  add_action( 'wp_ajax_wpt_tweet', 'wpt_ajax_tweet' );
1355
+ /**
1356
+ * Handle Tweets sent via Ajax Tweet Now/Schedule Tweet buttons.
1357
+ *
1358
+ * @return string Confirmation message indicating success or failure of Tweeting.
1359
+ */
1360
  function wpt_ajax_tweet() {
1361
  if ( ! check_ajax_referer( 'wpt-tweet-nonce', 'security', false ) ) {
1362
  echo "Invalid Security Check";
1410
  die;
1411
  }
1412
 
1413
+ add_action( 'admin_head', 'wpt_admin_script' );
1414
+ /**
1415
+ * Print scripts to WP Tweets PRO pages.
1416
+ */
1417
  function wpt_admin_script() {
1418
  global $current_screen;
1419
  if ( $current_screen->base == 'post' || $current_screen->id == 'wp-tweets-pro_page_wp-to-twitter-schedule' ) {
1445
  }
1446
  }
1447
 
1448
+ /**
1449
+ * Post the Custom Tweet & custom Tweet data into the post meta table
1450
+ *
1451
+ * @param integer $id Post ID.
1452
+ *
1453
+ */
1454
  function post_jd_twitter( $id ) {
1455
  if ( empty( $_POST ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $id ) || isset( $_POST['_inline_edit'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! wpt_in_post_type( $id ) ) {
1456
  return;
1479
  if ( isset( $_POST['wpt_clear_history'] ) && $_POST['wpt_clear_history'] == 'clear' ) {
1480
  delete_post_meta( $id, '_wpt_failed' );
1481
  delete_post_meta( $id, '_jd_wp_twitter' );
1482
+ delete_post_meta( $id, '_wpt_short_url' );
 
 
 
 
 
 
 
 
 
1483
  }
1484
  // WPT PRO //
1485
  $update = apply_filters( 'wpt_insert_post', $_POST, $id );
1490
  }
1491
  }
1492
 
1493
+ /**
1494
+ * Parse custom shortcodes
1495
+ *
1496
+ * @param string $sentence Tweet template
1497
+ * @param integer $post_ID Post ID.
1498
+ *
1499
+ * @return string $sentence with any custom shortcodes replaced with their appropriate content.
1500
+ */
1501
+ function wpt_custom_shortcodes( $sentence, $post_ID ) {
1502
+ $pattern = '/([([\[\]?)([A-Za-z0-9-_])*(\]\]]?)+/';
1503
+ $params = array( 0 => "[[", 1 => "]]" );
1504
+ preg_match_all( $pattern, $sentence, $matches );
1505
+ if ( $matches && is_array( $matches[0] ) ) {
1506
+ foreach ( $matches[0] as $value ) {
1507
+ $shortcode = "$value";
1508
+ $field = str_replace( $params, "", $shortcode );
1509
+ $custom = apply_filters( 'wpt_custom_shortcode', strip_tags( get_post_meta( $post_ID, $field, true ) ), $post_ID, $field );
1510
+ $sentence = str_replace( $shortcode, $custom, $sentence );
1511
+ }
1512
+
1513
+ return $sentence;
1514
+ } else {
1515
+ return $sentence;
1516
+ }
1517
+ }
1518
+
1519
+ /**
1520
+ * Show user profile data on Edit User pages.
1521
+ *
1522
+ * return @string Configuration forms for WP to Twitter user-specific settings.
1523
+ */
1524
  function wpt_twitter_profile() {
1525
  global $user_ID;
1526
  get_currentuserinfo();
1581
  }
1582
  }
1583
 
1584
+ /**
1585
+ * Save user profile data
1586
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1587
  function wpt_twitter_save_profile() {
1588
  global $user_ID;
1589
  get_currentuserinfo();
1602
  apply_filters( 'wpt_save_user', $edit_id, $_POST );
1603
  }
1604
 
1605
+ add_action( 'admin_menu', 'jd_addTwitterAdminPages' );
1606
+ /**
1607
+ * Add the administrative settings to the "Settings" menu.
1608
+ */
1609
  function jd_addTwitterAdminPages() {
1610
  if ( function_exists( 'add_options_page' ) && ! function_exists( 'wpt_pro_functions' ) ) {
1611
  add_options_page( 'WP to Twitter', 'WP to Twitter', 'manage_options', __FILE__, 'wpt_update_settings' );
1613
  }
1614
 
1615
  add_action( 'admin_head', 'jd_addTwitterAdminStyles' );
1616
+ /**
1617
+ * Add stylesheets to WP to Twitter pages.
1618
+ */
1619
  function jd_addTwitterAdminStyles() {
1620
  if ( isset( $_GET['page'] ) && ( $_GET['page'] == "wp-to-twitter" || $_GET['page'] == "wp-to-twitter/wp-to-twitter.php" || $_GET['page'] == "wp-tweets-pro" || $_GET['page'] == "wp-to-twitter-schedule" || $_GET['page'] == "wp-to-twitter-tweets" || $_GET['page'] == "wp-to-twitter-errors" ) ) {
1621
  wp_enqueue_style( 'wpt-styles', plugins_url( 'css/styles.css', __FILE__ ) );
1622
  }
1623
  }
1624
 
1625
+ /**
1626
+ * Add WP to Twitter links to plug-in information.
1627
+ */
1628
  function wpt_plugin_action( $links, $file ) {
1629
  if ( $file == plugin_basename( dirname( __FILE__ ) . '/wp-to-twitter.php' ) ) {
1630
  $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php' );
1647
  }
1648
 
1649
  add_action( 'in_plugin_update_message-wp-to-twitter/wp-to-twitter.php', 'wpt_plugin_update_message' );
1650
+ /**
1651
+ * Parse plugin update info to display in update list.
1652
+ *
1653
+ * @return string Notice from new version's readme.txt
1654
+ */
1655
  function wpt_plugin_update_message() {
1656
  global $wpt_version;
1657
  $note = '';
1674
  add_action( 'save_post', 'wpt_twit', 16 );
1675
  add_action( 'save_post', 'post_jd_twitter', 10 );
1676
 
1677
+ /**
1678
+ * Check whether a given post is in an allowed post type and has an update template configured.
1679
+ *
1680
+ * @param integer $id Post ID.
1681
+ *
1682
+ * @return boolean True if post is allowed, false otherwise.
1683
+ */
1684
  function wpt_in_post_type( $id ) {
1685
  $post_type_settings = get_option( 'wpt_post_types' );
1686
+ if ( is_array( $post_type_settings ) && !empty( $post_type_settings ) ) {
1687
+ $post_types = array_keys( $post_type_settings );
1688
+ $type = get_post_type( $id );
1689
+ if ( in_array( $type, $post_types ) ) {
1690
+ if ( $post_type_settings[ $type ]['post-edited-update'] == '1' || $post_type_settings[ $type ]['post-published-update'] == '1' ) {
1691
+ return true;
1692
+ }
1693
  }
1694
  }
 
1695
  return false;
1696
  }
1697
 
1698
  add_action( 'future_to_publish', 'wpt_future_to_publish', 16 );
1699
+ /**
1700
+ * Handle Tweeting posts scheduled for the future.
1701
+ */
1702
  function wpt_future_to_publish( $post ) {
1703
  $id = $post->ID;
1704
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
1707
  wpt_twit_future( $id );
1708
  }
1709
 
1710
+ /**
1711
+ * Handle Tweeting posts published directly.
1712
+ */
1713
  function wpt_twit( $id ) {
1714
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
1715
  return;
1724
  add_action( 'xmlrpc_publish_post', 'wpt_twit_xmlrpc' );
1725
  add_action( 'publish_phone', 'wpt_twit_xmlrpc' );
1726
 
1727
+ /**
1728
+ * For future posts, check transients to see whether this post has already been published. Prevents duplicate Tweet attempts in older versions of WP.
1729
+ *
1730
+ * @param integer $id Post ID.
1731
+ */
1732
  function wpt_twit_future( $id ) {
1733
  set_transient( '_wpt_twit_future', $id, 10 );
1734
  // instant action has already run for this post. // prevent running actions twice (need both for older WP)
1740
  jd_twit( $id, 'future' );
1741
  }
1742
 
1743
+ /**
1744
+ * For immediate posts, check transients to see whether this post has already been published. Prevents duplicate Tweet attempts in older versions of WP or cases where a future action is being run after the initial action.
1745
+ *
1746
+ * @param integer $id Post ID.
1747
+ */
1748
  function wpt_twit_instant( $id ) {
1749
  set_transient( '_wpt_twit_instant', $id, 10 );
1750
  // future action has already run for this post.
1762
  jd_twit( $id, 'instant' );
1763
  }
1764
 
1765
+ /**
1766
+ * Tweet XMLRPC posts.
1767
+ */
1768
  function wpt_twit_xmlrpc( $id ) {
1769
  set_transient( '_wpt_twit_xmlrpc', $id, 10 );
1770
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
1775
  }
1776
 
1777
  add_action( 'wpt_schedule_promotion_action', 'wpt_schedule_promotion' );
1778
+ /**
1779
+ * Set an option indicating that a job has been scheduled for promoting WP Tweets PRO.
1780
+ */
1781
  function wpt_schedule_promotion() {
1782
  if ( ! function_exists( 'wpt_pro_exists' ) && get_option( 'wpt_promotion_scheduled' ) == 1 ) {
1783
  update_option( 'wpt_promotion_scheduled', 2 );
1784
  }
1785
  }
1786
 
1787
+ /**
1788
+ * Dismiss promotion notice.
1789
+ */
1790
  function wpt_dismiss_promotion() {
1791
  if ( isset( $_GET['dismiss'] ) && $_GET['dismiss'] == 'promotion' ) {
1792
  update_option( 'wpt_promotion_scheduled', 3 );
1796
  wpt_dismiss_promotion();
1797
 
1798
  add_action( 'admin_notices', 'wpt_promotion_notice' );
1799
+ /**
1800
+ * Display promotion notice to admin users who have not donated or purchased WP Tweets PRO.
1801
+ */
1802
  function wpt_promotion_notice() {
1803
  if ( current_user_can( 'activate_plugins' ) && get_option( 'wpt_promotion_scheduled' ) == 2 && get_option( 'jd_donations' ) != 1 ) {
1804
  $upgrade = "http://www.joedolson.com/wp-tweets-pro/";
1807
  }
1808
  }
1809
 
 
 
 
1810
  add_action( 'wp_enqueue_scripts', 'wpt_stylesheet' );
1811
+ /**
1812
+ * Enqueue front-end styles for Twitter Feed widget if enabled.
1813
+ */
1814
  function wpt_stylesheet() {
1815
  $apply = apply_filters( 'wpt_enqueue_feed_styles', true );
1816
  if ( $apply ) {
1821
  }
1822
 
1823
  add_filter( 'wpt_enqueue_feed_styles', 'wpt_permit_feed_styles' );
1824
+ /**
1825
+ * Check whether Twitter Feed styles are enabled.
1826
+ *
1827
+ * @param boolean $value true if permitted.
1828
+ *
1829
+ * @return boolean $value False if settings disable styles.
1830
+ */
1831
  function wpt_permit_feed_styles( $value ) {
1832
  if ( get_option( 'wpt_permit_feed_styles' ) == 1 ) {
1833
  $value = false;
wpt-feed.php CHANGED
@@ -17,7 +17,7 @@ class WPT_TwitterFeed {
17
  'token' => '',
18
  'token_secret' => '',
19
  'screenname' => false,
20
- 'cache_expire' => 3600
21
  );
22
 
23
  public $st_last_error = false;
17
  'token' => '',
18
  'token_secret' => '',
19
  'screenname' => false,
20
+ 'cache_expire' => 1800
21
  );
22
 
23
  public $st_last_error = false;
wpt-functions.php CHANGED
@@ -218,6 +218,9 @@ if ( ! function_exists( 'mb_substr_replace' ) ) {
218
  }
219
  }
220
 
 
 
 
221
  function wtt_option_selected( $field, $value, $type = 'checkbox' ) {
222
  switch ( $type ) {
223
  case 'radio':
@@ -333,15 +336,13 @@ function wpt_get_support_form() {
333
  $plugins_string .= "$plugin_name: $plugin_version; $plugin_uri\n";
334
  }
335
  }
336
- global $wpt_server_string;
337
- $wpt_server_string = trim( strip_tags( $wpt_server_string ) );
338
  $data = "
339
  ================ Installation Data ====================
340
  ==WP to Twitter==
341
  Version: $version
342
  Twitter username: http://twitter.com/$wtt_twitter_username
343
  $license
344
- $wpt_server_string
345
 
346
  ==WordPress:==
347
  Version: $wp_version
@@ -457,4 +458,288 @@ function wpt_is_writable( $file ) {
457
  }
458
 
459
  return $is_writable;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  }
218
  }
219
  }
220
 
221
+ /**
222
+ * This function is obsolete; only exists for people using out of date versions of WP Tweets PRO.
223
+ */
224
  function wtt_option_selected( $field, $value, $type = 'checkbox' ) {
225
  switch ( $type ) {
226
  case 'radio':
336
  $plugins_string .= "$plugin_name: $plugin_version; $plugin_uri\n";
337
  }
338
  }
339
+
 
340
  $data = "
341
  ================ Installation Data ====================
342
  ==WP to Twitter==
343
  Version: $version
344
  Twitter username: http://twitter.com/$wtt_twitter_username
345
  $license
 
346
 
347
  ==WordPress:==
348
  Version: $wp_version
458
  }
459
 
460
  return $is_writable;
461
+ }
462
+
463
+ /**
464
+ * Normalizer is a PHP fallback implementation of the Normalizer class provided by the intl extension.
465
+ *
466
+ * It has been validated with Unicode 6.1 Normalization Conformance Test.
467
+ * See http://www.unicode.org/reports/tr15/ for detailed info about Unicode normalizations.
468
+ */
469
+ class WPT_Normalizer
470
+ {
471
+ const
472
+
473
+ NONE = 1,
474
+ FORM_D = 2, NFD = 2,
475
+ FORM_KD = 3, NFKD = 3,
476
+ FORM_C = 4, NFC = 4,
477
+ FORM_KC = 5, NFKC = 5;
478
+
479
+
480
+ protected static
481
+
482
+ $C, $D, $KD, $cC,
483
+ $ulen_mask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4),
484
+ $ASCII = "\x20\x65\x69\x61\x73\x6E\x74\x72\x6F\x6C\x75\x64\x5D\x5B\x63\x6D\x70\x27\x0A\x67\x7C\x68\x76\x2E\x66\x62\x2C\x3A\x3D\x2D\x71\x31\x30\x43\x32\x2A\x79\x78\x29\x28\x4C\x39\x41\x53\x2F\x50\x22\x45\x6A\x4D\x49\x6B\x33\x3E\x35\x54\x3C\x44\x34\x7D\x42\x7B\x38\x46\x77\x52\x36\x37\x55\x47\x4E\x3B\x4A\x7A\x56\x23\x48\x4F\x57\x5F\x26\x21\x4B\x3F\x58\x51\x25\x59\x5C\x09\x5A\x2B\x7E\x5E\x24\x40\x60\x7F\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
485
+
486
+
487
+ static function isNormalized($s, $form = self::NFC)
488
+ {
489
+ if (strspn($s, self::$ASCII) === strlen($s)) return true;
490
+ if (self::NFC === $form && preg_match('//u', $s) && !preg_match('/[^\x00-\x{2FF}]/u', $s)) return true;
491
+ return false; // Pretend false as quick checks implementented in PHP won't be so quick
492
+ }
493
+
494
+ static function normalize($s, $form = self::NFC)
495
+ {
496
+ if (!preg_match('//u', $s)) return false;
497
+
498
+ switch ($form)
499
+ {
500
+ case self::NONE: return $s;
501
+ case self::NFC: $C = true; $K = false; break;
502
+ case self::NFD: $C = false; $K = false; break;
503
+ case self::NFKC: $C = true; $K = true; break;
504
+ case self::NFKD: $C = false; $K = true; break;
505
+ default: return false;
506
+ }
507
+
508
+ if (!strlen($s)) return '';
509
+
510
+ if ($K && empty(self::$KD)) self::$KD = self::getData('compatibilityDecomposition');
511
+
512
+ if (empty(self::$D))
513
+ {
514
+ self::$D = self::getData('canonicalDecomposition');
515
+ self::$cC = self::getData('combiningClass');
516
+ }
517
+
518
+ if ($C)
519
+ {
520
+ if (empty(self::$C)) self::$C = self::getData('canonicalComposition');
521
+ return self::recompose(self::decompose($s, $K));
522
+ }
523
+ else return self::decompose($s, $K);
524
+ }
525
+
526
+ protected static function recompose($s)
527
+ {
528
+ $ASCII = self::$ASCII;
529
+ $compMap = self::$C;
530
+ $combClass = self::$cC;
531
+ $ulen_mask = self::$ulen_mask;
532
+
533
+ $result = $tail = '';
534
+
535
+ $i = $s[0] < "\x80" ? 1 : $ulen_mask[$s[0] & "\xF0"];
536
+ $len = strlen($s);
537
+
538
+ $last_uchr = substr($s, 0, $i);
539
+ $last_ucls = isset($combClass[$last_uchr]) ? 256 : 0;
540
+
541
+ while ($i < $len)
542
+ {
543
+ if ($s[$i] < "\x80")
544
+ {
545
+ // ASCII chars
546
+
547
+ if ($tail)
548
+ {
549
+ $last_uchr .= $tail;
550
+ $tail = '';
551
+ }
552
+
553
+ if ($j = strspn($s, $ASCII, $i+1))
554
+ {
555
+ $last_uchr .= substr($s, $i, $j);
556
+ $i += $j;
557
+ }
558
+
559
+ $result .= $last_uchr;
560
+ $last_uchr = $s[$i];
561
+ ++$i;
562
+ }
563
+ else
564
+ {
565
+ $ulen = $ulen_mask[$s[$i] & "\xF0"];
566
+ $uchr = substr($s, $i, $ulen);
567
+
568
+ if ($last_uchr < "\xE1\x84\x80" || "\xE1\x84\x92" < $last_uchr
569
+ || $uchr < "\xE1\x85\xA1" || "\xE1\x85\xB5" < $uchr
570
+ || $last_ucls)
571
+ {
572
+ // Table lookup and combining chars composition
573
+
574
+ $ucls = isset($combClass[$uchr]) ? $combClass[$uchr] : 0;
575
+
576
+ if (isset($compMap[$last_uchr . $uchr]) && (!$last_ucls || $last_ucls < $ucls))
577
+ {
578
+ $last_uchr = $compMap[$last_uchr . $uchr];
579
+ }
580
+ else if ($last_ucls = $ucls) $tail .= $uchr;
581
+ else
582
+ {
583
+ if ($tail)
584
+ {
585
+ $last_uchr .= $tail;
586
+ $tail = '';
587
+ }
588
+
589
+ $result .= $last_uchr;
590
+ $last_uchr = $uchr;
591
+ }
592
+ }
593
+ else
594
+ {
595
+ // Hangul chars
596
+
597
+ $L = ord($last_uchr[2]) - 0x80;
598
+ $V = ord($uchr[2]) - 0xA1;
599
+ $T = 0;
600
+
601
+ $uchr = substr($s, $i + $ulen, 3);
602
+
603
+ if ("\xE1\x86\xA7" <= $uchr && $uchr <= "\xE1\x87\x82")
604
+ {
605
+ $T = ord($uchr[2]) - 0xA7;
606
+ 0 > $T && $T += 0x40;
607
+ $ulen += 3;
608
+ }
609
+
610
+ $L = 0xAC00 + ($L * 21 + $V) * 28 + $T;
611
+ $last_uchr = chr(0xE0 | $L>>12) . chr(0x80 | $L>>6 & 0x3F) . chr(0x80 | $L & 0x3F);
612
+ }
613
+
614
+ $i += $ulen;
615
+ }
616
+ }
617
+
618
+ return $result . $last_uchr . $tail;
619
+ }
620
+
621
+ protected static function decompose($s, $c)
622
+ {
623
+ $result = '';
624
+
625
+ $ASCII = self::$ASCII;
626
+ $decompMap = self::$D;
627
+ $combClass = self::$cC;
628
+ $ulen_mask = self::$ulen_mask;
629
+ if ($c) $compatMap = self::$KD;
630
+
631
+ $c = array();
632
+ $i = 0;
633
+ $len = strlen($s);
634
+
635
+ while ($i < $len)
636
+ {
637
+ if ($s[$i] < "\x80")
638
+ {
639
+ // ASCII chars
640
+
641
+ if ($c)
642
+ {
643
+ ksort($c);
644
+ $result .= implode('', $c);
645
+ $c = array();
646
+ }
647
+
648
+ $j = 1 + strspn($s, $ASCII, $i+1);
649
+ $result .= substr($s, $i, $j);
650
+ $i += $j;
651
+ }
652
+ else
653
+ {
654
+ $ulen = $ulen_mask[$s[$i] & "\xF0"];
655
+ $uchr = substr($s, $i, $ulen);
656
+ $i += $ulen;
657
+
658
+ if (isset($combClass[$uchr]))
659
+ {
660
+ // Combining chars, for sorting
661
+
662
+ isset($c[$combClass[$uchr]]) || $c[$combClass[$uchr]] = '';
663
+ $c[$combClass[$uchr]] .= isset($compatMap[$uchr]) ? $compatMap[$uchr] : (isset($decompMap[$uchr]) ? $decompMap[$uchr] : $uchr);
664
+ }
665
+ else
666
+ {
667
+ if ($c)
668
+ {
669
+ ksort($c);
670
+ $result .= implode('', $c);
671
+ $c = array();
672
+ }
673
+
674
+ if ($uchr < "\xEA\xB0\x80" || "\xED\x9E\xA3" < $uchr)
675
+ {
676
+ // Table lookup
677
+
678
+ $j = isset($compatMap[$uchr]) ? $compatMap[$uchr] : (isset($decompMap[$uchr]) ? $decompMap[$uchr] : $uchr);
679
+
680
+ if ($uchr != $j)
681
+ {
682
+ $uchr = $j;
683
+
684
+ $j = strlen($uchr);
685
+ $ulen = $uchr[0] < "\x80" ? 1 : $ulen_mask[$uchr[0] & "\xF0"];
686
+
687
+ if ($ulen != $j)
688
+ {
689
+ // Put trailing chars in $s
690
+
691
+ $j -= $ulen;
692
+ $i -= $j;
693
+
694
+ if (0 > $i)
695
+ {
696
+ $s = str_repeat(' ', -$i) . $s;
697
+ $len -= $i;
698
+ $i = 0;
699
+ }
700
+
701
+ while ($j--) $s[$i+$j] = $uchr[$ulen+$j];
702
+
703
+ $uchr = substr($uchr, 0, $ulen);
704
+ }
705
+ }
706
+ }
707
+ else
708
+ {
709
+ // Hangul chars
710
+
711
+ $uchr = unpack('C*', $uchr);
712
+ $j = (($uchr[1]-224) << 12) + (($uchr[2]-128) << 6) + $uchr[3] - 0xAC80;
713
+
714
+ $uchr = "\xE1\x84" . chr(0x80 + (int) ($j / 588))
715
+ . "\xE1\x85" . chr(0xA1 + (int) (($j % 588) / 28));
716
+
717
+ if ($j %= 28)
718
+ {
719
+ $uchr .= $j < 25
720
+ ? ("\xE1\x86" . chr(0xA7 + $j))
721
+ : ("\xE1\x87" . chr(0x67 + $j));
722
+ }
723
+ }
724
+
725
+ $result .= $uchr;
726
+ }
727
+ }
728
+ }
729
+
730
+ if ($c)
731
+ {
732
+ ksort($c);
733
+ $result .= implode('', $c);
734
+ }
735
+
736
+ return $result;
737
+ }
738
+
739
+ protected static function getData($file)
740
+ {
741
+ $file = __DIR__ . '/unidata/' . $file . '.ser';
742
+ if (file_exists($file)) return unserialize(file_get_contents($file));
743
+ else return false;
744
+ }
745
  }
wpt-widget.php CHANGED
@@ -23,7 +23,7 @@ function wpt_get_twitter_feed( $atts, $content ) {
23
  extract( shortcode_atts( array(
24
  'id' => false,
25
  'num' => 10,
26
- 'duration' => 3600,
27
  'replies' => 0,
28
  'rts' => 1,
29
  'links' => 1,
@@ -534,9 +534,9 @@ function WPT_getTweets( $count = 20, $username = false, $options = false ) {
534
  $config['token'] = get_option( 'oauth_token' );
535
  $config['token_secret'] = get_option( 'oauth_token_secret' );
536
  $config['screenname'] = get_option( 'wtt_twitter_username' );
537
- $config['cache_expire'] = intval( apply_filters( 'wpt_cache_expire', 3600 ) );
538
  if ( $config['cache_expire'] < 1 ) {
539
- $config['cache_expire'] = 3600;
540
  }
541
  $config['directory'] = plugin_dir_path( __FILE__ );
542
 
23
  extract( shortcode_atts( array(
24
  'id' => false,
25
  'num' => 10,
26
+ 'duration' => 1800,
27
  'replies' => 0,
28
  'rts' => 1,
29
  'links' => 1,
534
  $config['token'] = get_option( 'oauth_token' );
535
  $config['token_secret'] = get_option( 'oauth_token_secret' );
536
  $config['screenname'] = get_option( 'wtt_twitter_username' );
537
+ $config['cache_expire'] = intval( apply_filters( 'wpt_cache_expire', 1800 ) );
538
  if ( $config['cache_expire'] < 1 ) {
539
+ $config['cache_expire'] = 1800;
540
  }
541
  $config['directory'] = plugin_dir_path( __FILE__ );
542
 
wpt_twitter_oauth.php CHANGED
@@ -24,7 +24,7 @@ if ( ! class_exists( 'jd_TwitterOAuth' ) ) {
24
  /* Contains the last API call. */
25
  public $url;
26
  /* Set up the API root URL. */
27
- public $host = "http://api.twitter.com/1.1/";
28
  /* Set timeout default. */
29
  public $format = 'json';
30
  /* Decode returned json data. */
@@ -38,19 +38,19 @@ if ( ! class_exists( 'jd_TwitterOAuth' ) ) {
38
  * Set API URLS
39
  */
40
  function accessTokenURL() {
41
- return "http://api.twitter.com/oauth/access_token";
42
  }
43
 
44
  function authenticateURL() {
45
- return "http://api.twitter.com/oauth/authenticate";
46
  }
47
 
48
  function authorizeURL() {
49
- return "http://api.twitter.com/oauth/authorize";
50
  }
51
 
52
  function requestTokenURL() {
53
- return "http://api.twitter.com/oauth/request_token";
54
  }
55
 
56
  /**
@@ -186,8 +186,7 @@ if ( ! class_exists( 'jd_TwitterOAuth' ) ) {
186
 
187
  return $response;
188
  }
189
-
190
-
191
  /**
192
  * Handles a status update that includes an image.
193
  *
@@ -198,6 +197,7 @@ if ( ! class_exists( 'jd_TwitterOAuth' ) ) {
198
  */
199
  function handleMediaRequest( $url, $args = array() ) {
200
  /* Load tmhOAuth for Media uploads only when needed: https://github.com/themattharris/tmhOAuth */
 
201
  if ( ! class_exists( 'tmhOAuth' ) ) {
202
  require_once( plugin_dir_path( __FILE__ ) . 'tmhOAuth/tmhOAuth.php' );
203
  require_once( plugin_dir_path( __FILE__ ) . 'tmhOAuth/tmhUtilities.php' );
@@ -225,83 +225,49 @@ if ( ! class_exists( 'jd_TwitterOAuth' ) ) {
225
  'user_secret' => $ots
226
  );
227
  $tmhOAuth = new tmhOAuth( $connect );
228
- $attachment = wpt_post_attachment( $args['id'] );
229
- // if install is at root, can query src path. Otherwise, need to take full image.
230
- $at_root = ( wp_make_link_relative( home_url() ) == home_url() || wp_make_link_relative( home_url() ) == '/' ) ? true : false;
231
- if ( $at_root ) {
232
- $image_sizes = get_intermediate_image_sizes();
233
- if ( in_array( 'large', $image_sizes ) ) {
234
- $size = 'large';
235
- } else {
236
- $size = array_pop( $image_sizes );
237
- }
238
- $upload = wp_get_attachment_image_src( $attachment, apply_filters( 'wpt_upload_image_size', $size ) );
239
- $path = get_home_path() . wp_make_link_relative( $upload[0] );
240
- $image = str_replace( '//', '/', $path );
241
  } else {
242
- $image = get_attached_file( $attachment );
243
  }
244
- $image = apply_filters( 'wpt_image_path', $image, $args );
245
-
 
 
 
246
  $mime_type = get_post_mime_type( $attachment );
247
  if ( ! $mime_type ) {
248
  $mime_type = 'image/jpeg';
249
  }
250
- // If images are remote, copy to local so they can be uploaded.
251
- $remote_images = ( get_option( 'wpt_remote_images' ) === 1 ) ? true : false;
252
- if ( $remote_images === true ) {
253
- $remote_image = wp_remote_get( $upload[0] );
254
- $image_data = wp_remote_retrieve_body( $remote_image );
255
- $filename = basename( $upload[0] );
256
- $upload_dir = wp_upload_dir();
257
- if ( wp_mkdir_p( $upload_dir['path'] ) ) {
258
- $image = $upload_dir['path'] . '/temp-' . $filename;
259
- } else {
260
- $image = $upload_dir['basedir'] . '/temp-' . $filename;
261
- }
262
- if ( strlen( $image_data ) > 0 ) {
263
- file_put_contents( $image, $image_data );
264
- } else {
265
- return false;
266
- }
267
- }
268
-
269
  $code = $tmhOAuth->request(
270
  'POST',
271
  $url,
272
- array(
273
- 'media[]' => "@{$image};type={$mime_type};filename={$image}",
274
- 'status' => $args['status'],
275
- ),
276
  true, // use auth
277
  true // multipart
278
  );
279
 
280
- $debug = array(
281
- 'media[]' => "@{$image};type={$mime_type};filename={$image}",
282
- 'status' => $args['status']
283
- );
284
-
285
- wpt_mail( "Media Submitted - Post ID #$args[id]", print_r( $debug, 1 ) );
286
  $response = $tmhOAuth->response['response'];
287
  $full = $tmhOAuth->response;
288
- wpt_mail( "Media Posted - Post ID #$args[id]", print_r( $full, 1 ) );
289
-
290
- // If a local image was created for uploading, delete it.
291
- if ( $remote_images === true ) {
292
- unlink( $image );
293
- }
294
 
295
  if ( is_wp_error( $response ) ) {
296
- return false;
297
  }
298
 
299
  $this->http_code = $code;
300
  $this->last_api_call = $url;
301
  $this->format = 'json';
302
  $this->http_header = $response;
303
-
304
- return $response;
 
 
305
  }
306
 
307
  /**
24
  /* Contains the last API call. */
25
  public $url;
26
  /* Set up the API root URL. */
27
+ public $host = "https://api.twitter.com/1.1/";
28
  /* Set timeout default. */
29
  public $format = 'json';
30
  /* Decode returned json data. */
38
  * Set API URLS
39
  */
40
  function accessTokenURL() {
41
+ return "https://api.twitter.com/oauth/access_token";
42
  }
43
 
44
  function authenticateURL() {
45
+ return "https://api.twitter.com/oauth/authenticate";
46
  }
47
 
48
  function authorizeURL() {
49
+ return "https://api.twitter.com/oauth/authorize";
50
  }
51
 
52
  function requestTokenURL() {
53
+ return "https://api.twitter.com/oauth/request_token";
54
  }
55
 
56
  /**
186
 
187
  return $response;
188
  }
189
+
 
190
  /**
191
  * Handles a status update that includes an image.
192
  *
197
  */
198
  function handleMediaRequest( $url, $args = array() ) {
199
  /* Load tmhOAuth for Media uploads only when needed: https://github.com/themattharris/tmhOAuth */
200
+ /* It's not possible to upload media using WP_HTTP, so this needs to use cURL. */
201
  if ( ! class_exists( 'tmhOAuth' ) ) {
202
  require_once( plugin_dir_path( __FILE__ ) . 'tmhOAuth/tmhOAuth.php' );
203
  require_once( plugin_dir_path( __FILE__ ) . 'tmhOAuth/tmhUtilities.php' );
225
  'user_secret' => $ots
226
  );
227
  $tmhOAuth = new tmhOAuth( $connect );
228
+ $attachment = $args['media'];
229
+
230
+ $image_sizes = get_intermediate_image_sizes();
231
+ if ( in_array( 'large', $image_sizes ) ) {
232
+ $size = 'large';
 
 
 
 
 
 
 
 
233
  } else {
234
+ $size = array_pop( $image_sizes );
235
  }
236
+ $upload = wp_get_attachment_image_src( $attachment, apply_filters( 'wpt_upload_image_size', $size ) );
237
+ $image_url = $upload[0];
238
+ $remote = wp_remote_get( $image_url );
239
+ $binary = wp_remote_retrieve_body( $remote );
240
+
241
  $mime_type = get_post_mime_type( $attachment );
242
  if ( ! $mime_type ) {
243
  $mime_type = 'image/jpeg';
244
  }
245
+ /* End New */
246
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  $code = $tmhOAuth->request(
248
  'POST',
249
  $url,
250
+ array( 'media' => "$binary" ),
 
 
 
251
  true, // use auth
252
  true // multipart
253
  );
254
 
 
 
 
 
 
 
255
  $response = $tmhOAuth->response['response'];
256
  $full = $tmhOAuth->response;
257
+ wpt_mail( "Media Posted - Media ID #$args[media]", print_r( $full, 1 ) );
 
 
 
 
 
258
 
259
  if ( is_wp_error( $response ) ) {
260
+ return '';
261
  }
262
 
263
  $this->http_code = $code;
264
  $this->last_api_call = $url;
265
  $this->format = 'json';
266
  $this->http_header = $response;
267
+ $response = json_decode( $response );
268
+ $media_id = $response->media_id_string;
269
+
270
+ return $media_id;
271
  }
272
 
273
  /**