Latest Tweets Widget - Version 1.0.6

Version Description

  • Enabled translations and added pt_BR
  • Switched dates to use i18n date formatter
Download this release

Release Info

Developer timwhitlock
Plugin Icon 128x128 Latest Tweets Widget
Version 1.0.6
Comparing to
See all releases

Code changes from version 1.0.5 to 1.0.6

lang/README.md CHANGED
@@ -1,5 +1,13 @@
1
  # Translating Twitter API Wordpress Plugin
2
 
3
- Translations aren't implemented yet, but the plugin is set up for it.
4
- If you'd like to translate this plugin into your language, please get in touch.
5
 
 
 
 
 
 
 
 
 
1
  # Translating Twitter API Wordpress Plugin
2
 
3
+ Translations are in their infancy for this project.
4
+ If you'd like to translate this plugin into your language, please [get in touch](https://twitter.com/timwhitlock).
5
 
6
+ Messages here are for the admin screens plus common Twitter-related phrases you might need in your plugin.
7
+
8
+
9
+ ### Contributers:
10
+
11
+ Many thanks to the following translators:
12
+
13
+ * **pt_BR** [Leandro Dimitrio](http://wordpress.org/support/profile/leandrodimitrio)
lang/twitter-api-pt_BR.mo ADDED
Binary file
lang/twitter-api-pt_BR.po ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Twitter API Wordpress plugin\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: Fri, 22 Feb 2013 17:50:38 +0000\n"
6
+ "PO-Revision-Date: Tue, 16 Apr 2013 12:03:09 +0100\n"
7
+ "Last-Translator: \n"
8
+ "Language-Team: \n"
9
+ "Language: Portuguese (Brazil)\n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
+ "X-Generator: Loco http://localise.biz \n"
15
+ "X-Loco-Author: Tim Whitlock\n"
16
+ "X-Loco-Source-Locale: en_GB\n"
17
+ "X-Loco-Target-Locale: pt_BR\n"
18
+ "X-Poedit-SourceCharset: UTF-8\n"
19
+
20
+ #: Asset just-now
21
+ msgid "Just now"
22
+ msgstr "Agora mesmo"
23
+
24
+ #: Asset minutes-ago-singular
25
+ msgid "%u minute ago"
26
+ msgid_plural "%u minutes ago"
27
+ msgstr[0] "1 minuto atrás"
28
+ msgstr[1] "%u minutos atrás"
29
+
30
+ #: Asset hours-ago-singular
31
+ msgid "About an hour ago"
32
+ msgid_plural "About %u hours ago"
33
+ msgstr[0] "Cerca de uma hora atrás"
34
+ msgstr[1] "Cerca de %u horas atrás"
35
+
36
+ #: Asset yesterday-at
37
+ msgid "Yesterday at "
38
+ msgstr "Ontem às"
39
+
40
+ #: Asset http-status-100
41
+ msgid "Continue"
42
+ msgstr "Continuar"
43
+
44
+ #: Asset http-status-101
45
+ msgid "Switching Protocols"
46
+ msgstr "Trocando protocolos"
47
+
48
+ #: Asset http-status-200
49
+ msgid "OK"
50
+ msgstr "OK"
51
+
52
+ #: Asset http-status-201
53
+ msgid "Created"
54
+ msgstr "Criado"
55
+
56
+ #: Asset http-status-202
57
+ msgid "Accepted"
58
+ msgstr "Aceito"
59
+
60
+ #: Asset http-status-203
61
+ msgid "Non-Authoritative Information"
62
+ msgstr "Informação não-autoritativa"
63
+
64
+ #: Asset http-status-204
65
+ msgid "No Content"
66
+ msgstr "Sem conteúdo"
67
+
68
+ #: Asset http-status-205
69
+ msgid "Reset Content"
70
+ msgstr "Resetar conteúdo"
71
+
72
+ #: Asset http-status-206
73
+ msgid "Partial Content"
74
+ msgstr "Conteúdo parcial"
75
+
76
+ #: Asset http-status-300
77
+ msgid "Multiple Choices"
78
+ msgstr "Múltipla escolha"
79
+
80
+ #: Asset http-status-301
81
+ msgid "Moved Permanently"
82
+ msgstr "Movido permanentemente"
83
+
84
+ #: Asset http-status-302
85
+ msgid "Found"
86
+ msgstr "Encontrado(a)"
87
+
88
+ #: Asset http-status-303
89
+ msgid "See Other"
90
+ msgstr "Ver outros"
91
+
92
+ #: Asset http-status-304
93
+ msgid "Not Modified"
94
+ msgstr "Não modificado"
95
+
96
+ #: Asset http-status-305
97
+ msgid "Use Proxy"
98
+ msgstr ""
99
+
100
+ #: Asset http-status-307
101
+ msgid "Temporary Redirect"
102
+ msgstr ""
103
+
104
+ #: Asset http-status-400
105
+ msgid "Bad Request"
106
+ msgstr ""
107
+
108
+ #: Asset http-status-401
109
+ msgid "Authorization Required"
110
+ msgstr ""
111
+
112
+ #: Asset http-status-402
113
+ msgid "Payment Required"
114
+ msgstr ""
115
+
116
+ #: Asset http-status-403
117
+ msgid "Forbidden"
118
+ msgstr ""
119
+
120
+ #: Asset http-status-404
121
+ msgid "Not Found"
122
+ msgstr ""
123
+
124
+ #: Asset http-status-405
125
+ msgid "Method Not Allowed"
126
+ msgstr ""
127
+
128
+ #: Asset http-status-406
129
+ msgid "Not Acceptable"
130
+ msgstr ""
131
+
132
+ #: Asset http-status-407
133
+ msgid "Proxy Authentication Required"
134
+ msgstr ""
135
+
136
+ #: Asset http-status-408
137
+ msgid "Request Time-out"
138
+ msgstr ""
139
+
140
+ #: Asset http-status-409
141
+ msgid "Conflict"
142
+ msgstr ""
143
+
144
+ #: Asset http-status-410
145
+ msgid "Gone"
146
+ msgstr ""
147
+
148
+ #: Asset http-status-411
149
+ msgid "Length Required"
150
+ msgstr ""
151
+
152
+ #: Asset http-status-412
153
+ msgid "Precondition Failed"
154
+ msgstr ""
155
+
156
+ #: Asset http-status-413
157
+ msgid "Request Entity Too Large"
158
+ msgstr ""
159
+
160
+ #: Asset http-status-414
161
+ msgid "Request-URI Too Large"
162
+ msgstr ""
163
+
164
+ #: Asset http-status-415
165
+ msgid "Unsupported Media Type"
166
+ msgstr ""
167
+
168
+ #: Asset http-status-416
169
+ msgid "Requested range not satisfiable"
170
+ msgstr ""
171
+
172
+ #: Asset http-status-417
173
+ msgid "Expectation Failed"
174
+ msgstr ""
175
+
176
+ #: Asset http-status-429
177
+ msgid "Twitter API rate limit exceeded"
178
+ msgstr ""
179
+
180
+ #: Asset http-status-500
181
+ msgid "Twitter server error"
182
+ msgstr ""
183
+
184
+ #: Asset http-status-501
185
+ msgid "Not Implemented"
186
+ msgstr ""
187
+
188
+ #: Asset http-status-502
189
+ msgid "Twitter is not responding"
190
+ msgstr ""
191
+
192
+ #: Asset http-status-503
193
+ msgid "Twitter is too busy to respond"
194
+ msgstr ""
195
+
196
+ #: Asset http-status-504
197
+ msgid "Gateway Time-out"
198
+ msgstr ""
199
+
200
+ #: Asset http-status-505
201
+ msgid "HTTP Version not supported"
202
+ msgstr ""
203
+
204
+ #: Asset notice-unconfigured
205
+ msgid "Twitter application is not fully configured"
206
+ msgstr ""
207
+
208
+ #: Asset warning-no-apc
209
+ msgid "Cannot enable Twitter API cache without APC extension"
210
+ msgstr ""
211
+
212
+ #: Asset warning-unauthed
213
+ msgid "Twitter client not authenticated"
214
+ msgstr ""
215
+
216
+ #: Asset error-twitter-invalid-param
217
+ msgid "Invalid Twitter parameter"
218
+ msgstr ""
219
+
220
+ #: Asset error-twitter-generic
221
+ msgid "Twitter error #%d"
222
+ msgstr ""
223
+
224
+ #: Asset error-twitter-malformed
225
+ msgid "Malformed response from Twitter"
226
+ msgstr ""
227
+
228
+ #: Asset error-wordpress-http
229
+ msgid "Wordpress HTTP request failure"
230
+ msgstr ""
231
+
232
+ #: Asset error-oauth-invalid-token
233
+ msgid "Invalid OAuth token"
234
+ msgstr ""
235
+
236
+ #: Asset error-oauth-empty-key
237
+ msgid "Key required even if secret is empty"
238
+ msgstr ""
239
+
240
+ #: Asset twitter-api-authentication-settings
241
+ msgid "Twitter API Authentication Settings"
242
+ msgstr ""
243
+
244
+ #: Asset label-details-available-in
245
+ msgid "These details are available in"
246
+ msgstr "Detalhes disponíveis em"
247
+
248
+ #: Asset label-your-twitter-dashboard
249
+ msgid "your Twitter dashboard"
250
+ msgstr "seu painel do Twitter"
251
+
252
+ #: Asset admin-fatal-denied
253
+ msgid "You don't have permission to manage Twitter API settings"
254
+ msgstr "Você não tem permissão para gerenciar a API do Twitter"
255
+
256
+ #: Asset admin-notice-unconfigured
257
+ msgid "Twitter application not fully configured"
258
+ msgstr "Aplicação do Twitter não totalmente configurada"
259
+
260
+ #: Asset admin-notice-unauthed
261
+ msgid "Plugin not yet authenticated with Twitter"
262
+ msgstr "Plugin ainda não autenticado com o Twitter"
263
+
264
+ #: Asset admin-notice-authenticated
265
+ msgid "Authenticated as @%s"
266
+ msgstr "Autenticado como @%s"
267
+
268
+ #: Asset label-twitter-api
269
+ msgid "Twitter API"
270
+ msgstr "API do Twitter"
271
+
272
+ #: Asset save-settings
273
+ msgid "Save settings"
274
+ msgstr "Salvar"
275
+
276
+ #: Asset latest-tweets
277
+ msgid "Latest Tweets"
278
+ msgstr ""
279
+
280
+ #: Asset widget-title
281
+ msgid "Widget title"
282
+ msgstr ""
283
+
284
+ #: Asset twitter-handle
285
+ msgid "Twitter handle"
286
+ msgstr ""
287
+
288
+ #: Asset number-of-tweets
289
+ msgid "Number of tweets"
290
+ msgstr ""
291
+
292
+ #: Asset show-retweets
293
+ msgid "Show Retweets"
294
+ msgstr ""
295
+
296
+ #: Asset show-replies
297
+ msgid "Show Replies"
298
+ msgstr ""
lang/twitter-api.pot CHANGED
@@ -3,7 +3,7 @@ msgstr ""
3
  "Project-Id-Version: Twitter API Wordpress plugin\n"
4
  "Report-Msgid-Bugs-To: \n"
5
  "POT-Creation-Date: Fri, 22 Feb 2013 17:50:38 +0000\n"
6
- "PO-Revision-Date: Sun, 24 Feb 2013 11:44:51 +0000\n"
7
  "Last-Translator: \n"
8
  "Language-Team: \n"
9
  "Language: English (UK)\n"
@@ -28,7 +28,7 @@ msgstr[0] ""
28
  msgstr[1] ""
29
 
30
  #: Asset hours-ago-singular
31
- msgid "About %u hour ago"
32
  msgid_plural "About %u hours ago"
33
  msgstr[0] ""
34
  msgstr[1] ""
@@ -268,3 +268,31 @@ msgstr ""
268
  #: Asset label-twitter-api
269
  msgid "Twitter API"
270
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  "Project-Id-Version: Twitter API Wordpress plugin\n"
4
  "Report-Msgid-Bugs-To: \n"
5
  "POT-Creation-Date: Fri, 22 Feb 2013 17:50:38 +0000\n"
6
+ "PO-Revision-Date: Tue, 16 Apr 2013 12:03:09 +0100\n"
7
  "Last-Translator: \n"
8
  "Language-Team: \n"
9
  "Language: English (UK)\n"
28
  msgstr[1] ""
29
 
30
  #: Asset hours-ago-singular
31
+ msgid "About an hour ago"
32
  msgid_plural "About %u hours ago"
33
  msgstr[0] ""
34
  msgstr[1] ""
268
  #: Asset label-twitter-api
269
  msgid "Twitter API"
270
  msgstr ""
271
+
272
+ #: Asset save-settings
273
+ msgid "Save settings"
274
+ msgstr ""
275
+
276
+ #: Asset latest-tweets
277
+ msgid "Latest Tweets"
278
+ msgstr ""
279
+
280
+ #: Asset widget-title
281
+ msgid "Widget title"
282
+ msgstr ""
283
+
284
+ #: Asset twitter-handle
285
+ msgid "Twitter handle"
286
+ msgstr ""
287
+
288
+ #: Asset number-of-tweets
289
+ msgid "Number of tweets"
290
+ msgstr ""
291
+
292
+ #: Asset show-retweets
293
+ msgid "Show Retweets"
294
+ msgstr ""
295
+
296
+ #: Asset show-replies
297
+ msgid "Show Replies"
298
+ msgstr ""
lang/update.sh ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #
3
+ # Script pulls down latest translations from Loco system.
4
+ # The API key is read-only and accesses this project only.
5
+ #
6
+
7
+ cd "`dirname $0`"
8
+
9
+ function loco {
10
+ if [ "enGB" = "$1$2" ]; then
11
+ wget "http://localise.biz/api/export/locale/$1-$2.po?key=535225653ef7eb710e53c8e421e335e1" -O "twitter-api.pot"
12
+ else
13
+ wget "http://localise.biz/api/export/locale/$1-$2.po?key=535225653ef7eb710e53c8e421e335e1" -O "twitter-api-$1_$2.po"
14
+ msgfmt "twitter-api-$1_$2.po" -o "twitter-api-$1_$2.mo"
15
+ fi
16
+ }
17
+
18
+ loco en GB
19
+ loco pt BR
20
+
21
+
latest-tweets.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Latest Tweets
4
  Plugin URI: http://wordpress.org/extend/plugins/latest-tweets-widget/
5
  Description: Provides a sidebar widget showing latest tweets - compatible with the new Twitter API 1.1
6
  Author: Tim Whitlock
7
- Version: 1.0.5
8
  Author URI: http://timwhitlock.info/
9
  */
10
 
@@ -22,6 +22,7 @@ function latest_tweets_render( $screen_name, $count, $rts, $ats ){
22
  try {
23
  if( ! function_exists('twitter_api_get') ){
24
  require_once dirname(__FILE__).'/lib/twitter-api.php';
 
25
  }
26
  // We could cache the rendered HTML right here, but this keeps caching abstracted in library
27
  twitter_api_enable_cache( 300 );
@@ -109,7 +110,7 @@ class Latest_Tweets_Widget extends WP_Widget {
109
  'type' => 'bool'
110
  ),
111
  );
112
- parent::__construct( $id_base, $name, $widget_options, $control_options );
113
  }
114
 
115
  /* ensure no missing keys in instance params */
@@ -186,7 +187,7 @@ if( is_admin() ){
186
  // extra visibility of API settings link
187
  function latest_tweets_plugin_row_meta( $links, $file ){
188
  if( false !== strpos($file,'/latest-tweets.php') ){
189
- $links[] = '<a href="options-general.php?page=twitter-api-admin"><strong>Connect</strong></a>';
190
  }
191
  return $links;
192
  }
4
  Plugin URI: http://wordpress.org/extend/plugins/latest-tweets-widget/
5
  Description: Provides a sidebar widget showing latest tweets - compatible with the new Twitter API 1.1
6
  Author: Tim Whitlock
7
+ Version: 1.0.6
8
  Author URI: http://timwhitlock.info/
9
  */
10
 
22
  try {
23
  if( ! function_exists('twitter_api_get') ){
24
  require_once dirname(__FILE__).'/lib/twitter-api.php';
25
+ _twitter_api_init_l10n();
26
  }
27
  // We could cache the rendered HTML right here, but this keeps caching abstracted in library
28
  twitter_api_enable_cache( 300 );
110
  'type' => 'bool'
111
  ),
112
  );
113
+ parent::__construct( $id_base, __($name), $widget_options, $control_options );
114
  }
115
 
116
  /* ensure no missing keys in instance params */
187
  // extra visibility of API settings link
188
  function latest_tweets_plugin_row_meta( $links, $file ){
189
  if( false !== strpos($file,'/latest-tweets.php') ){
190
+ $links[] = '<a href="options-general.php?page=twitter-api-admin"><strong>'.esc_attr__('Connect to Twitter').'</strong></a>';
191
  }
192
  return $links;
193
  }
lib/twitter-api-admin.php CHANGED
@@ -57,7 +57,7 @@ function twitter_api_admin_render_form(){
57
  <input type="text" size="64" name="saf_twitter[access_secret]" id="twitter-api--access-secret" value="<?php echo esc_html($access_secret)?>" />
58
  </p>
59
  <p class="submit">
60
- <input type="submit" class="button-primary" value="Save settings" />
61
  </p>
62
  <small>
63
  <?php echo esc_html__('These details are available in')?>
@@ -87,7 +87,7 @@ function twitter_api_admin_render_login( $consumer_key, $consumer_secret ){
87
  // we're storing permanently - not using session here, because WP provides no session API.
88
  _twitter_api_config( array( 'request_secret' => $Token->secret ) );
89
  $href = $Token->get_authorization_url();
90
- echo '<p><a class="button-primary" href="',esc_html($href),'">Connect to Twitter</a></p>';
91
  echo '<p>&nbsp;</p>';
92
  }
93
 
57
  <input type="text" size="64" name="saf_twitter[access_secret]" id="twitter-api--access-secret" value="<?php echo esc_html($access_secret)?>" />
58
  </p>
59
  <p class="submit">
60
+ <input type="submit" class="button-primary" value="<?php echo esc_html__('Save settings')?>" />
61
  </p>
62
  <small>
63
  <?php echo esc_html__('These details are available in')?>
87
  // we're storing permanently - not using session here, because WP provides no session API.
88
  _twitter_api_config( array( 'request_secret' => $Token->secret ) );
89
  $href = $Token->get_authorization_url();
90
+ echo '<p><a class="button-primary" href="',esc_html($href),'">'.esc_html__('Connect to Twitter').'</a></p>';
91
  echo '<p>&nbsp;</p>';
92
  }
93
 
lib/twitter-api-core.php CHANGED
@@ -283,6 +283,15 @@ class TwitterApiClient {
283
  $http = self::http_request( $endpoint, $conf );
284
  $data = json_decode( $http['body'], true );
285
  $status = $http['response']['code'];
 
 
 
 
 
 
 
 
 
286
  // unserializable array assumed to be serious error
287
  if( ! is_array($data) ){
288
  $err = array(
@@ -307,15 +316,6 @@ class TwitterApiClient {
307
  if( isset($cachekey) ){
308
  _twitter_api_cache_set( $cachekey, $data, $this->cache_ttl );
309
  }
310
- // remember current rate limits for this endpoint
311
- $this->last_call = $path;
312
- if( isset($http['headers']['x-rate-limit-limit']) ) {
313
- $this->last_rate[$path] = array (
314
- 'limit' => (int) $http['headers']['x-rate-limit-limit'],
315
- 'remaining' => (int) $http['headers']['x-rate-limit-remaining'],
316
- 'reset' => (int) $http['headers']['x-rate-limit-reset'],
317
- );
318
- }
319
  return $data;
320
  }
321
 
@@ -430,6 +430,14 @@ class TwitterOAuthParams {
430
  return str_replace( '%7E', '~', rawurlencode($val) );
431
  }
432
 
 
 
 
 
 
 
 
 
433
  public function __construct( array $args = array() ){
434
  $this->args = $args + array (
435
  'oauth_version' => '1.0',
@@ -458,9 +466,7 @@ class TwitterOAuthParams {
458
  }
459
 
460
  public function serialize(){
461
- $str = http_build_query( $this->args );
462
- $str = str_replace( '%7E', '~', $str );
463
- return $str;
464
  }
465
 
466
  public function sign_hmac( $http_method, $http_rsc ){
@@ -587,26 +593,3 @@ class TwitterApiRateLimitException extends TwitterApiException {
587
 
588
 
589
 
590
-
591
- /**
592
- * Enable localisation when ready.
593
- * Currently merging into default domain.
594
- * This works, but no translations available yet.
595
- *
596
- function _twitter_api_init_l10n(){
597
- $locales = array( get_locale(), 'en_GB' );
598
- while( $locale = array_shift($locales) ){
599
- $mo = twitter_api_basedir().'/lang/twitter-api-'.$locale.'.mo';
600
- if( file_exists($mo) ){
601
- load_textdomain( 'default', $mo );
602
- return;
603
- }
604
- }
605
- }
606
-
607
- add_action( 'init', '_twitter_api_init_l10n' );
608
- */
609
-
610
-
611
-
612
-
283
  $http = self::http_request( $endpoint, $conf );
284
  $data = json_decode( $http['body'], true );
285
  $status = $http['response']['code'];
286
+ // remember current rate limits for this endpoint
287
+ $this->last_call = $path;
288
+ if( isset($http['headers']['x-rate-limit-limit']) ) {
289
+ $this->last_rate[$path] = array (
290
+ 'limit' => (int) $http['headers']['x-rate-limit-limit'],
291
+ 'remaining' => (int) $http['headers']['x-rate-limit-remaining'],
292
+ 'reset' => (int) $http['headers']['x-rate-limit-reset'],
293
+ );
294
+ }
295
  // unserializable array assumed to be serious error
296
  if( ! is_array($data) ){
297
  $err = array(
316
  if( isset($cachekey) ){
317
  _twitter_api_cache_set( $cachekey, $data, $this->cache_ttl );
318
  }
 
 
 
 
 
 
 
 
 
319
  return $data;
320
  }
321
 
430
  return str_replace( '%7E', '~', rawurlencode($val) );
431
  }
432
 
433
+ private static function urlencode_params( array $args ){
434
+ $pairs = array();
435
+ foreach( $args as $key => $val ){
436
+ $pairs[] = rawurlencode($key).'='.rawurlencode($val);
437
+ }
438
+ return str_replace( '%7E', '~', implode( '&', $pairs ) );
439
+ }
440
+
441
  public function __construct( array $args = array() ){
442
  $this->args = $args + array (
443
  'oauth_version' => '1.0',
466
  }
467
 
468
  public function serialize(){
469
+ return self::urlencode_params( $this->args );
 
 
470
  }
471
 
472
  public function sign_hmac( $http_method, $http_rsc ){
593
 
594
 
595
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/twitter-api-utils.php CHANGED
@@ -60,7 +60,7 @@ function twitter_api_relative_date( $strdate ){
60
  // within last hour? X minutes ago
61
  if( $tdiff < 3600 ){
62
  $idiff = (int) floor( $tdiff / 60 );
63
- return sprintf( _n( '%u minute ago', '%u minutes ago', $idiff ), $idiff );
64
  }
65
  // within same day? About X hours ago
66
  $samey = ($y === $yy) and
@@ -68,41 +68,38 @@ function twitter_api_relative_date( $strdate ){
68
  $samed = ($d === $dd);
69
  if( ! empty($samed) ){
70
  $hdiff = (int) floor( $tdiff / 3600 );
71
- return sprintf( _n( 'About %u hour ago', 'About %u hours ago', $hdiff ), $hdiff );
72
  }
 
73
  // within 24 hours?
74
  if( $tdiff < 86400 ){
75
- return __('Yesterday at ').twitter_api_date_format('g:i A', $tt );
76
  }
77
- // else return formatted date, e.g. "Oct 20th 2008 9:27 PM GMT" */
78
- return twitter_api_date_format('M jS Y g:i A', $tt );
 
79
  }
80
 
81
 
82
 
83
  /**
84
- * Abstraction of date formatting for older PHP versions
85
- * - DateTime class requires PHP >= 5.2
86
- * - DateTime::setTimestamp requires PHP >= 5.3
 
 
 
 
 
 
 
 
87
  * @internal
88
  */
89
- function twitter_api_date_format( $f, $t ){
90
- static $oldphp;
91
- if( ! isset($oldphp) ){
92
- $oldphp = 0 > version_compare(PHP_VERSION, '5.3');
93
- }
94
- if( $oldphp ){
95
- return date( $f, $t );
96
- }
97
- // using DateTime instance to avoid empty timezone warnings and such
98
- static $dt;
99
- if( ! isset($dt) ){
100
- $tz = ini_get('date.timezone') or $tz = 'Europe/London';
101
- $tz = new DateTimeZone( $tz );
102
- $dt = new DateTime;
103
- $dt->setTimezone( $tz );
104
- }
105
- $dt->setTimestamp( $t );
106
- return $dt->format( $f );
107
  }
108
 
 
60
  // within last hour? X minutes ago
61
  if( $tdiff < 3600 ){
62
  $idiff = (int) floor( $tdiff / 60 );
63
+ return sprintf( _n( '1 minute ago', '%u minutes ago', $idiff ), $idiff );
64
  }
65
  // within same day? About X hours ago
66
  $samey = ($y === $yy) and
68
  $samed = ($d === $dd);
69
  if( ! empty($samed) ){
70
  $hdiff = (int) floor( $tdiff / 3600 );
71
+ return sprintf( _n( 'About an hour ago', 'About %u hours ago', $hdiff ), $hdiff );
72
  }
73
+ $tf = get_option('time_format') or $tf = 'g:i A';
74
  // within 24 hours?
75
  if( $tdiff < 86400 ){
76
+ return __('Yesterday at').date_i18n(' '.$tf, $tt );
77
  }
78
+ // else return formatted date, e.g. "Oct 20th 2008 9:27 PM" */
79
+ $df = get_option('date_format') or $df= 'M jS Y';
80
+ return date_i18n( $df.' '.$tf, $tt );
81
  }
82
 
83
 
84
 
85
  /**
86
+ * Clean Emoji icons out of tweet text.
87
+ * Wordpress isn't escaping these strings properly for database insertion.
88
+ */
89
+ function twitter_api_strip_emoji( $text ){
90
+ // replace all control and private use unicode sequences
91
+ return preg_replace_callback('/\p{C}/u', '_twitter_api_strip_emoji_replace', $text );
92
+ }
93
+
94
+
95
+
96
+ /**
97
  * @internal
98
  */
99
+ function _twitter_api_strip_emoji_replace( array $r ){
100
+ // emoticons start at U+1F601 (\xF0\x9F\x98\x81)
101
+ // @todo plain text mappings for common smileys
102
+ return '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
 
105
+
lib/twitter-api.php CHANGED
@@ -137,3 +137,25 @@ function twitter_api_oauth_access_token( $consumer_key, $consumer_secret, $reque
137
  if( is_admin() ){
138
  twitter_api_include('core','admin');
139
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  if( is_admin() ){
138
  twitter_api_include('core','admin');
139
  }
140
+
141
+
142
+
143
+ /**
144
+ * Enable localisation with static list of available translations.
145
+ * Messages merged into default domain.
146
+ */
147
+ function _twitter_api_init_l10n(){
148
+ static $map = array (
149
+ 'pt_BR' => 'pt_BR',
150
+ );
151
+ if( preg_match('/^([a-z]{2})[\-_\s]([a-z]{2})$/i', get_locale(), $r ) ){
152
+ $locale = strtolower($r[1]).'_'.strtoupper($r[2]);
153
+ if( isset($map[$locale]) ){
154
+ $locale = $map[$locale];
155
+ $mofile = twitter_api_basedir().'/lang/twitter-api-'.$locale.'.mo';
156
+ load_textdomain( 'default', $mofile );
157
+ }
158
+ }
159
+ }
160
+
161
+ add_action( 'init', '_twitter_api_init_l10n' );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://timwhitlock.info/donate-to-a-project/
4
  Tags: twitter, tweets, oauth, api, rest, api, widget, sidebar
5
  Requires at least: 3.5.1
6
  Tested up to: 3.5.1
7
- Stable tag: 1.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -49,6 +49,11 @@ Once your site is authenticated you can configure the widget as follows:
49
 
50
  See the 'Other Notes' tab for theming information.
51
 
 
 
 
 
 
52
  = How I do know what my OAuth settings are? =
53
 
54
  These details are available in the [Twitter dashboard](https://dev.twitter.com/apps)
@@ -66,6 +71,10 @@ Do so at your own risk.
66
 
67
  == Changelog ==
68
 
 
 
 
 
69
  = 1.0.5 =
70
  * Moved widget title outside latest-tweets wrapper
71
  * Using WordPress 'transient' cache when APC not available
4
  Tags: twitter, tweets, oauth, api, rest, api, widget, sidebar
5
  Requires at least: 3.5.1
6
  Tested up to: 3.5.1
7
+ Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
49
 
50
  See the 'Other Notes' tab for theming information.
51
 
52
+ = Why do I have to register my own Twitter app? =
53
+
54
+ Because I'm proving code, not a service. If I set up a Twitter app for this plugin I'd be responsible for every person who uses it.
55
+ If Twitter closed my account or revoked my keys every instance of this plugin would break. Twitter also place limits on the number of users that can connect to a single app.
56
+
57
  = How I do know what my OAuth settings are? =
58
 
59
  These details are available in the [Twitter dashboard](https://dev.twitter.com/apps)
71
 
72
  == Changelog ==
73
 
74
+ = 1.0.6 =
75
+ * Enabled translations and added pt_BR
76
+ * Switched dates to use i18n date formatter
77
+
78
  = 1.0.5 =
79
  * Moved widget title outside latest-tweets wrapper
80
  * Using WordPress 'transient' cache when APC not available