1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// Exit if accessed directly |
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
5
|
|
|
exit; |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Return if twitter account is found |
10
|
|
|
* @return bool If the Twitter object exists |
11
|
|
|
*/ |
12
|
|
|
function ppp_twitter_enabled() { |
13
|
1 |
|
global $ppp_social_settings; |
14
|
|
|
|
15
|
1 |
|
if ( isset( $ppp_social_settings['twitter'] ) && !empty( $ppp_social_settings['twitter'] ) ) { |
16
|
|
|
return true; |
17
|
|
|
} |
18
|
|
|
|
19
|
1 |
|
return false; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Register Twitter as a servcie |
24
|
|
|
* @param array $services The registered services |
25
|
|
|
* @return array With Twitter added |
26
|
|
|
*/ |
27
|
|
|
function ppp_tw_register_service( $services = array() ) { |
28
|
1 |
|
$services[] = 'tw'; |
29
|
|
|
|
30
|
1 |
|
return $services; |
31
|
|
|
} |
32
|
|
|
add_filter( 'ppp_register_social_service', 'ppp_tw_register_service', 10, 1 ); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The Twitter Icon |
36
|
|
|
* @param string $string The default icon |
37
|
|
|
* @return string The HTML for the Twitter Icon |
38
|
|
|
*/ |
39
|
|
|
function ppp_tw_account_list_icon( $string = '' ) { |
40
|
1 |
|
$string .= '<span class="dashicons icon-ppp-tw"></span>'; |
41
|
|
|
|
42
|
1 |
|
return $string; |
43
|
|
|
} |
44
|
|
|
add_filter( 'ppp_account_list_icon-tw', 'ppp_tw_account_list_icon', 10, 1 ); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The avatar for the connected Twitter Account |
48
|
|
|
* @param string $string Default avatar string |
49
|
|
|
* @return string The Twitter avatar |
50
|
|
|
*/ |
51
|
|
|
function ppp_tw_account_list_avatar( $string = '' ) { |
52
|
|
|
|
53
|
|
|
if ( ppp_twitter_enabled() ) { |
54
|
|
|
global $ppp_social_settings; |
55
|
|
|
$avatar_url = $ppp_social_settings['twitter']['user']->profile_image_url_https; |
56
|
|
|
$string .= '<img class="ppp-social-icon" src="' . $avatar_url . '" />'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $string; |
60
|
|
|
} |
61
|
|
|
add_filter( 'ppp_account_list_avatar-tw', 'ppp_tw_account_list_avatar', 10, 1 ); |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The name of the connected Twitter account for the list view |
65
|
|
|
* @param string $string The default name |
66
|
|
|
* @return string The name from Twitter |
67
|
|
|
*/ |
68
|
|
|
function ppp_tw_account_list_name( $string = '' ) { |
69
|
|
|
|
70
|
|
|
if ( ppp_twitter_enabled() ) { |
71
|
|
|
global $ppp_social_settings; |
72
|
|
|
$string .= $ppp_social_settings['twitter']['user']->name; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $string; |
76
|
|
|
} |
77
|
|
|
add_filter( 'ppp_account_list_name-tw', 'ppp_tw_account_list_name', 10, 1 ); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* The actions for the Twitter account list |
81
|
|
|
* @param string $string The default actions |
82
|
|
|
* @return string The actions buttons HTML for Twitter |
83
|
|
|
*/ |
84
|
|
|
function ppp_tw_account_list_actions( $string = '' ) { |
85
|
|
|
|
86
|
|
|
if ( ! ppp_twitter_enabled() ) { |
87
|
|
|
global $ppp_twitter_oauth, $ppp_social_settings; |
88
|
|
|
$tw_auth = $ppp_twitter_oauth->ppp_verify_twitter_credentials(); |
|
|
|
|
89
|
|
|
$tw_authurl = $ppp_twitter_oauth->ppp_get_twitter_auth_url(); |
90
|
|
|
|
91
|
|
|
$string .= '<a href="' . $tw_authurl . '"><img src="' . PPP_URL . '/includes/images/sign-in-with-twitter-gray.png" /></a>'; |
92
|
|
|
} else { |
93
|
|
|
$string .= '<a class="button-primary" href="' . admin_url( 'admin.php?page=ppp-social-settings&ppp_social_disconnect=true&ppp_network=twitter' ) . '" >' . __( 'Disconnect from Twitter', 'ppp-txt' ) . '</a> '; |
94
|
|
|
$string .= '<a class="button-secondary" href="https://twitter.com/settings/applications" target="blank">' . __( 'Revoke Access via Twitter', 'ppp-txt' ) . '</a>'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $string; |
98
|
|
|
} |
99
|
|
|
add_filter( 'ppp_account_list_actions-tw', 'ppp_tw_account_list_actions', 10, 1 ); |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Listen for the oAuth tokens and verifiers from Twitter when in admin |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
function ppp_capture_twitter_oauth() { |
106
|
|
|
if ( isset( $_REQUEST['oauth_verifier'] ) && isset( $_REQUEST['oauth_token'] ) ) { |
107
|
|
|
$current_screen = get_current_screen(); |
108
|
|
|
if ( 'user-edit' === $current_screen->base ) { |
109
|
|
|
$user_id = ! empty( $_GET['user_id'] ) && is_numeric( $_GET['user_id'] ) ? $_GET['user_id'] : false; |
110
|
|
|
$twitter = new PPP_Twitter_User( $user_id ); |
111
|
|
|
$twitter->init(); |
112
|
|
|
$redirect = admin_url( 'user-edit.php?updated=1&user_id=' . $user_id ); |
113
|
|
|
} else { |
114
|
|
|
global $ppp_twitter_oauth; |
115
|
|
|
$ppp_twitter_oauth->ppp_initialize_twitter(); |
116
|
|
|
$redirect = admin_url( 'admin.php?page=ppp-social-settings' ); |
117
|
|
|
} |
118
|
|
|
?> |
119
|
|
|
<meta http-equiv="refresh" content="0;URL=<?php echo $redirect; ?>"> |
120
|
|
|
<?php |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
add_action( 'admin_head', 'ppp_capture_twitter_oauth', 10 ); |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Listen for the disconnect from Twitter |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
function ppp_disconnect_twitter() { |
130
|
|
|
if ( ! empty( $_GET['user_id'] ) ) { |
131
|
|
|
$user_id = (int) sanitize_text_field( $_GET['user_id'] ); |
132
|
|
|
if ( $user_id !== get_current_user_id() || ! current_user_can( 'manage_options' ) ) { |
133
|
|
|
wp_die( __( 'Unable to disconnect Twitter account', 'ppp-txt' ) ); |
134
|
|
|
} |
135
|
|
|
delete_user_meta( $user_id, '_ppp_twitter_data' ); |
136
|
|
|
} else { |
137
|
|
|
global $ppp_social_settings; |
138
|
|
|
$ppp_social_settings = get_option( 'ppp_social_settings' ); |
139
|
|
|
if ( isset( $ppp_social_settings['twitter'] ) ) { |
140
|
|
|
unset( $ppp_social_settings['twitter'] ); |
141
|
|
|
update_option( 'ppp_social_settings', $ppp_social_settings ); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
add_action( 'ppp_disconnect-twitter', 'ppp_disconnect_twitter', 10 ); |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Given a message, sends a tweet |
149
|
|
|
* @param string $message The Text to share as the body of the tweet |
150
|
|
|
* @return object The Results from the Twitter API |
151
|
|
|
*/ |
152
|
|
|
function ppp_send_tweet( $message, $post_id, $use_media = false, $name = '' ) { |
|
|
|
|
153
|
|
|
global $ppp_twitter_oauth; |
154
|
|
|
|
155
|
|
|
return apply_filters( 'ppp_twitter_tweet', $ppp_twitter_oauth->ppp_tweet( ppp_entities_and_slashes( $message ), $use_media ) ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Send out a scheduled share to Twitter |
160
|
|
|
* |
161
|
|
|
* @since 2.3 |
162
|
|
|
* @param integer $post_id The Post ID to share fore |
163
|
|
|
* @param integer $index The index in the shares |
164
|
|
|
* @param string $name The name of the Cron |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
|
|
function ppp_tw_scheduled_share( $post_id = 0, $index = 1, $name = '' ) { |
168
|
|
|
global $ppp_options, $wp_logs, $wp_filter; |
169
|
|
|
|
170
|
|
|
$post_meta = get_post_meta( $post_id, '_ppp_tweets', true ); |
171
|
|
|
$this_share = $post_meta[ $index ]; |
172
|
|
|
$attachment_id = isset( $this_share['attachment_id'] ) ? $this_share['attachment_id'] : false; |
173
|
|
|
|
174
|
|
|
$share_message = ppp_tw_build_share_message( $post_id, $name ); |
175
|
|
|
|
176
|
|
|
if ( empty( $attachment_id ) && ! empty( $this_share['image'] ) ) { |
177
|
|
|
$media = $this_share['image']; |
178
|
|
|
} else { |
179
|
|
|
$use_media = ppp_tw_use_media( $post_id, $index ); |
180
|
|
|
$media = ppp_post_has_media( $post_id, 'tw', $use_media, $attachment_id ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$status = ppp_send_tweet( $share_message, $post_id, $media ); |
184
|
|
|
|
185
|
|
|
$log_title = ppp_tw_build_share_message( $post_id, $name, false, false ); |
186
|
|
|
|
187
|
|
|
$log_data = array( |
188
|
|
|
'post_title' => $log_title, |
189
|
|
|
'post_content' => '', |
190
|
|
|
'post_parent' => $post_id, |
191
|
|
|
'log_type' => 'ppp_share' |
192
|
|
|
); |
193
|
|
|
|
194
|
|
|
$log_meta = array( |
195
|
|
|
'network' => 'tw', |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
$log_entry = WP_Logging::insert_log( $log_data, $log_meta ); |
199
|
|
|
|
200
|
|
|
update_post_meta( $log_entry, '_ppp_share_status', $status ); |
201
|
|
|
|
202
|
|
|
if ( ! empty( $status->id_str ) ) { |
203
|
|
|
$post = get_post( $post_id ); |
204
|
|
|
$author_id = $post->post_author; |
205
|
|
|
$author_rt = get_user_meta( $author_id, '_ppp_share_scheduled', true ); |
206
|
|
|
|
207
|
|
|
if ( $author_rt ) { |
208
|
|
|
$twitter_user = new PPP_Twitter_User( $author_id ); |
209
|
|
|
$twitter_user->retweet( $status->id_str ); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
add_action( 'ppp_share_scheduled_tw', 'ppp_tw_scheduled_share', 10, 3 ); |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Combines the results from ppp_generate_share_content and ppp_generate_link into a single string |
218
|
|
|
* @param int $post_id The Post ID |
219
|
|
|
* @param string $name The 'name' element from the Cron |
220
|
|
|
* @param boolean $scheduled If the item is being requsted by a scheduled post |
221
|
|
|
* @param bool $include_link If a link should be included in the text |
222
|
|
|
* @return string The Full text for the social share |
223
|
|
|
*/ |
224
|
|
|
function ppp_tw_build_share_message( $post_id, $name, $scheduled = true, $include_link = true ) { |
225
|
|
|
$share_content = ppp_tw_generate_share_content( $post_id, $name ); |
226
|
|
|
|
227
|
|
|
if ( $include_link ) { |
228
|
|
|
$share_link = ppp_generate_link( $post_id, $name, $scheduled ); |
229
|
|
|
$share_content = $share_content . ' ' . $share_link; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
return apply_filters( 'ppp_tw_build_share_message', $share_content ); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Generate the content for the shares |
237
|
|
|
* @param int $post_id The Post ID |
238
|
|
|
* @param string $name The 'Name' from the cron |
239
|
|
|
* @return string The Content to include in the social media post |
240
|
|
|
*/ |
241
|
|
|
function ppp_tw_generate_share_content( $post_id, $name, $is_scheduled = true ) { |
242
|
|
|
global $ppp_options; |
243
|
|
|
$default_text = isset( $ppp_options['default_text'] ) ? $ppp_options['default_text'] : ''; |
244
|
|
|
$ppp_tweets = get_post_meta( $post_id, '_ppp_tweets', true ); |
245
|
|
|
|
246
|
|
|
if ( $is_scheduled && ! empty( $ppp_tweets ) ) { |
247
|
|
|
$ppp_post_override_data = get_post_meta( $post_id, '_ppp_post_override_data', true ); |
|
|
|
|
248
|
|
|
$name_array = explode( '_', $name ); |
249
|
|
|
$index = $name_array[1]; |
250
|
|
|
$share_content = $ppp_tweets[$index]['text']; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
// If an override was found, use it, otherwise try the default text content |
254
|
|
|
$share_content = ( isset( $share_content ) && !empty( $share_content ) ) ? $share_content : $default_text; |
255
|
|
|
|
256
|
|
|
// If the content is still empty, just use the post title |
257
|
|
|
$share_content = ( isset( $share_content ) && !empty( $share_content ) ) ? $share_content : get_the_title( $post_id ); |
258
|
|
|
|
259
|
|
|
return apply_filters( 'ppp_share_content', $share_content, array( 'post_id' => $post_id ) ); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Return if media is supported for this scheduled tweet |
264
|
|
|
* @param int $post_id The Post ID |
265
|
|
|
* @param int $index The index of this tweet in the _ppp_tweets data |
266
|
|
|
* @return bool Whether or not this tweet should contain a media post |
267
|
|
|
*/ |
268
|
|
|
function ppp_tw_use_media( $post_id, $index ) { |
269
|
|
|
if ( empty( $post_id ) || empty( $index ) ) { |
270
|
|
|
return false; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
$share_data = get_post_meta( $post_id, '_ppp_tweets', true ); |
274
|
|
|
$use_media = ! empty( $share_data[$index]['attachment_id'] ) || ! empty( $share_data[$index]['image'] ) ? true : false; |
275
|
|
|
|
276
|
|
|
return $use_media; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Sets the constants for the oAuth tokens for Twitter |
281
|
|
|
* @param array $social_tokens The tokens stored in the transient |
282
|
|
|
* @return void |
283
|
|
|
*/ |
284
|
|
|
function ppp_set_tw_token_constants( $social_tokens ) { |
285
|
|
|
if ( !empty( $social_tokens ) && property_exists( $social_tokens, 'twitter' ) ) { |
286
|
|
|
define( 'PPP_TW_CONSUMER_KEY', $social_tokens->twitter->consumer_token ); |
287
|
|
|
define( 'PPP_TW_CONSUMER_SECRET', $social_tokens->twitter->consumer_secret ); |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
add_action( 'ppp_set_social_token_constants', 'ppp_set_tw_token_constants', 10, 1 ); |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Register Twitter for the Social Media Accounts section |
294
|
|
|
* @param array $tabs Array of existing tabs |
295
|
|
|
* @return array The Array of existing tabs with Twitter added |
296
|
|
|
*/ |
297
|
|
|
function ppp_tw_add_admin_tab( $tabs ) { |
298
|
|
|
$tabs['tw'] = array( 'name' => __( 'Twitter', 'ppp-txt' ), 'class' => 'icon-ppp-tw' ); |
299
|
|
|
|
300
|
|
|
return $tabs; |
301
|
|
|
} |
302
|
|
|
add_filter( 'ppp_admin_tabs', 'ppp_tw_add_admin_tab', 10, 1 ); |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Register the Twitter connection area for the Social Media Accounts section |
306
|
|
|
* @param array $content The existing content tokens |
307
|
|
|
* @return array The content tokens with Twitter added |
308
|
|
|
*/ |
309
|
|
|
function ppp_tw_register_admin_social_content( $content ) { |
310
|
|
|
$content[] = 'tw'; |
311
|
|
|
|
312
|
|
|
return $content; |
313
|
|
|
} |
314
|
|
|
add_filter( 'ppp_admin_social_content', 'ppp_tw_register_admin_social_content', 10, 1 ); |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Register the Twitter metabox tab |
318
|
|
|
* @param array $tabs The tabs |
319
|
|
|
* @return array The tabs with Twitter added |
320
|
|
|
*/ |
321
|
|
|
function ppp_tw_add_meta_tab( $tabs ) { |
322
|
|
|
global $ppp_social_settings; |
323
|
|
|
if ( !isset( $ppp_social_settings['twitter'] ) ) { |
324
|
|
|
return $tabs; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
$tabs['tw'] = array( 'name' => __( 'Twitter', 'ppp-txt' ), 'class' => 'icon-ppp-tw' ); |
328
|
|
|
|
329
|
|
|
return $tabs; |
330
|
|
|
} |
331
|
|
|
add_filter( 'ppp_metabox_tabs', 'ppp_tw_add_meta_tab', 10, 1 ); |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Register the metabox content for Twitter |
335
|
|
|
* @param array $content The existing metabox tokens |
336
|
|
|
* @return array The metabox tokens with Twitter added |
337
|
|
|
*/ |
338
|
|
|
function ppp_tw_register_metabox_content( $content ) { |
339
|
|
|
global $ppp_social_settings; |
340
|
|
|
if ( !isset( $ppp_social_settings['twitter'] ) ) { |
341
|
|
|
return $content; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
$content[] = 'tw'; |
345
|
|
|
|
346
|
|
|
return $content; |
347
|
|
|
} |
348
|
|
|
add_filter( 'ppp_metabox_content', 'ppp_tw_register_metabox_content', 10, 1 ); |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Returns the stored Twitter data for a post |
352
|
|
|
* |
353
|
|
|
* @since 2.3 |
354
|
|
|
* @param array $post_meta Array of meta data (empty) |
355
|
|
|
* @param int $post_id The Post ID to get the meta for |
356
|
|
|
* @return array The stored Twitter shares for a post |
357
|
|
|
*/ |
358
|
|
|
function ppp_tw_get_post_meta( $post_meta, $post_id ) { |
|
|
|
|
359
|
|
|
return get_post_meta( $post_id, '_ppp_tweets', true ); |
360
|
|
|
} |
361
|
|
|
add_filter( 'ppp_get_scheduled_items_tw', 'ppp_tw_get_post_meta', 10, 2 ); |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Registers the thumbnail size for Twitter |
365
|
|
|
* @return void |
366
|
|
|
*/ |
367
|
|
|
function ppp_tw_register_thumbnail_size() { |
368
|
|
|
add_image_size( 'ppp-tw-share-image', 1024, 512, true ); |
369
|
|
|
} |
370
|
|
|
add_action( 'ppp_add_image_sizes', 'ppp_tw_register_thumbnail_size' ); |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* The callback that adds Twitter metabox content |
374
|
|
|
* @param object $post The post object |
375
|
|
|
* @return void Displays the metabox content |
376
|
|
|
*/ |
377
|
|
|
function ppp_tw_add_metabox_content( $post ) { |
378
|
|
|
global $ppp_options, $ppp_share_settings, $has_past_shares; |
379
|
|
|
$has_past_shares = 0; |
380
|
|
|
?> |
381
|
|
|
<p> |
382
|
|
|
<div class="ppp-post-override-wrap"> |
383
|
|
|
<p><h3><?php _e( 'Share on Twitter', 'ppp-txt' ); ?></h3></p> |
384
|
|
|
<div id="ppp-tweet-fields" class="ppp-tweet-fields"> |
385
|
|
|
<div id="ppp-tweet-fields" class="ppp-meta-table-wrap"> |
386
|
|
|
<table class="widefat ppp-repeatable-table" width="100%" cellpadding="0" cellspacing="0"> |
387
|
|
|
<thead> |
388
|
|
|
<tr> |
389
|
|
|
<th style="width: 100px"><?php _e( 'Date', 'ppp-txt' ); ?></th> |
390
|
|
|
<th style="width: 75px;"><?php _e( 'Time', 'ppp-txt' ); ?></th> |
391
|
|
|
<th><?php _e( 'Text', 'ppp-txt' ); ?></th> |
392
|
|
|
<th style"width: 200px;"><?php _e( 'Image', 'ppp-txt' ); ?></th> |
393
|
|
|
<th style="width: 10px;"></th> |
394
|
|
|
</tr> |
395
|
|
|
</thead> |
396
|
|
|
<tbody> |
397
|
|
|
<?php ppp_render_tweet_share_on_publish_row(); ?> |
398
|
|
|
<?php $tweets = get_post_meta( $post->ID, '_ppp_tweets', true ); ?> |
399
|
|
|
<?php if ( ! empty( $tweets ) ) : ?> |
400
|
|
|
|
401
|
|
|
<?php foreach ( $tweets as $key => $value ) : |
402
|
|
|
$date = isset( $value['date'] ) ? $value['date'] : ''; |
403
|
|
|
$time = isset( $value['time'] ) ? $value['time'] : ''; |
404
|
|
|
$text = isset( $value['text'] ) ? $value['text'] : ''; |
405
|
|
|
$image = isset( $value['image'] ) ? $value['image'] : ''; |
406
|
|
|
$attachment_id = isset( $value['attachment_id'] ) ? $value['attachment_id'] : ''; |
407
|
|
|
|
408
|
|
|
$args = apply_filters( 'ppp_tweet_row_args', compact( 'date','time','text','image','attachment_id' ), $value ); |
409
|
|
|
?> |
410
|
|
|
|
411
|
|
|
<?php ppp_render_tweet_row( $key, $args, $post->ID ); ?> |
412
|
|
|
|
413
|
|
|
|
414
|
|
|
<?php endforeach; ?> |
415
|
|
|
|
416
|
|
|
<?php |
417
|
|
|
if ( ! empty( $has_past_shares ) && count ( $tweets ) == $has_past_shares ) { |
418
|
|
|
$args = array( |
419
|
|
|
'date' => '', |
420
|
|
|
'time' => '', |
421
|
|
|
'text' => '', |
422
|
|
|
'image' => '', |
423
|
|
|
'attachment_id' => '', |
424
|
|
|
); |
425
|
|
|
|
426
|
|
|
|
427
|
|
|
ppp_render_tweet_row( $key + 1, $args, $post->ID ); |
|
|
|
|
428
|
|
|
} |
429
|
|
|
?> |
430
|
|
|
|
431
|
|
|
<?php else: ?> |
432
|
|
|
|
433
|
|
|
<?php ppp_render_tweet_row( 1, array( 'date' => '', 'time' => '', 'text' => '', 'image' => '', 'attachment_id' => '' ), $post->ID, 1 ); ?> |
|
|
|
|
434
|
|
|
|
435
|
|
|
<?php endif; ?> |
436
|
|
|
|
437
|
|
|
<tr> |
438
|
|
|
<td class="submit" colspan="4" style="float: none; clear:both; background:#fff;"> |
439
|
|
|
<a class="button-secondary ppp-add-repeatable" style="margin: 6px 0;"><?php _e( 'Add New Tweet', 'ppp-txt' ); ?></a> |
440
|
|
|
<?php if ( ! empty( $has_past_shares ) ) : ?> |
441
|
|
|
<a class="button-secondary ppp-view-all" style="margin: 6px 0;"><?php _e( 'Toggle Past Tweets', 'ppp-txt' ); ?></a> |
442
|
|
|
<?php endif; ?> |
443
|
|
|
</td> |
444
|
|
|
</tr> |
445
|
|
|
</tbody> |
446
|
|
|
</table> |
447
|
|
|
</div> |
448
|
|
|
</div><!--end #edd_variable_price_fields--> |
449
|
|
|
|
450
|
|
|
<p><?php _e( 'Do not include links in your text, this will be added automatically.', 'ppp-txt' ); ?></p> |
451
|
|
|
<p style="display: none;" id="ppp-show-conflict-warning"><?php printf( __( 'Items highlighted in red have a time assigned that is within %d minutes of an already scheduled Tweet', 'ppp-txt' ), floor( ppp_get_default_conflict_window() / 60 ) ); ?></p> |
452
|
|
|
</div> |
453
|
|
|
</p> |
454
|
|
|
<?php |
455
|
|
|
} |
456
|
|
|
add_action( 'ppp_generate_metabox_content-tw', 'ppp_tw_add_metabox_content', 10, 1 ); |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Generates the 'share on publish row' of the Twitter Metabox content |
460
|
|
|
* |
461
|
|
|
* @since 2.3 |
462
|
|
|
* @return void |
463
|
|
|
*/ |
464
|
|
|
function ppp_render_tweet_share_on_publish_row() { |
465
|
|
|
global $post, $ppp_share_settings; |
466
|
|
|
$default_text = !empty( $ppp_options['default_text'] ) ? $ppp_options['default_text'] : __( 'Social Text', 'ppp-txt' ); |
|
|
|
|
467
|
|
|
|
468
|
|
|
$ppp_post_exclude = get_post_meta( $post->ID, '_ppp_post_exclude', true ); |
|
|
|
|
469
|
|
|
|
470
|
|
|
$ppp_share_on_publish = get_post_meta( $post->ID, '_ppp_share_on_publish', true ); |
471
|
|
|
$show_share_on_publish = false; |
472
|
|
|
|
473
|
|
|
$share_by_default = empty( $ppp_share_settings['twitter']['share_on_publish'] ) ? false : true; |
474
|
|
|
|
475
|
|
|
if ( $ppp_share_on_publish == '1' || ( $ppp_share_on_publish == '' && $share_by_default ) ) { |
476
|
|
|
$show_share_on_publish = true; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
$ppp_share_on_publish_text = get_post_meta( $post->ID, '_ppp_share_on_publish_text', true ); |
480
|
|
|
$ppp_share_on_publish_include_image = get_post_meta( $post->ID, '_ppp_share_on_publish_include_image', true ); |
481
|
|
|
|
482
|
|
|
$disabled = ( $post->post_status === 'publish' && time() > strtotime( $post->post_date ) ) ? true : false; |
483
|
|
|
?> |
484
|
|
|
<tr class="ppp-tweet-wrapper ppp-repeatable-row on-publish-row"> |
485
|
|
|
<td colspan="2" class="ppp-on-plublish-date-column"> |
486
|
|
|
<input <?php if ( $disabled ): ?>readonly<?php endif; ?> type="checkbox" name="_ppp_share_on_publish" id="ppp_share_on_publish" value="1" <?php checked( true, $show_share_on_publish, true ); ?> /> |
487
|
|
|
<label for="ppp_share_on_publish"><?php _e( 'Tweet On Publish', 'ppp-txt' ); ?></label> |
488
|
|
|
</td> |
489
|
|
|
|
490
|
|
|
<td> |
491
|
|
|
<input <?php if ( $disabled ): ?>readonly<?php endif; ?> class="ppp-tweet-text-repeatable" type="text" name="_ppp_share_on_publish_text" value="<?php echo esc_attr( $ppp_share_on_publish_text ); ?>" /> |
492
|
|
|
<?php $length = ! empty( $args['text'] ) ? strlen( $args['text'] ) : 0; ?> |
|
|
|
|
493
|
|
|
<span class="ppp-text-length"><?php echo $length; ?></span> |
494
|
|
|
</td> |
495
|
|
|
|
496
|
|
|
<td style="width: 200px" colspan="2"> |
497
|
|
|
<input class="ppp-tw-featured-image-input" <?php if ( $disabled ): ?>readonly<?php endif; ?> id="ppp-share-on-publish-image" type="checkbox" name="_ppp_share_on_publish_include_image" value="1" <?php checked( '1', $ppp_share_on_publish_include_image, true ); ?>/> |
498
|
|
|
<label for="ppp-share-on-publish-image"><?php _e( 'Featured Image', 'ppp-txt' ); ?></label> |
499
|
|
|
</td> |
500
|
|
|
|
501
|
|
|
</tr> |
502
|
|
|
<?php |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* Generates the row for a scheduled Tweet in the metabox |
507
|
|
|
* |
508
|
|
|
* @param int $key The array index |
509
|
|
|
* @param array $args Arguements/Data for the specific index |
510
|
|
|
* @param int $post_id The post ID |
511
|
|
|
* @return void |
512
|
|
|
*/ |
513
|
|
|
function ppp_render_tweet_row( $key, $args = array(), $post_id ) { |
|
|
|
|
514
|
|
|
global $post, $has_past_shares; |
515
|
|
|
|
516
|
|
|
$share_time = strtotime( $args['date'] . ' ' . $args['time'] ); |
517
|
|
|
$readonly = current_time( 'timestamp' ) > $share_time ? 'readonly="readonly" ' : false; |
518
|
|
|
$no_date = ! empty( $readonly ) ? ' hasDatepicker' : ''; |
519
|
|
|
$hide = ! empty( $readonly ) ? 'display: none;' : ''; |
520
|
|
|
$shared = ! empty( $readonly ) ? 'past-share' : ''; |
521
|
|
|
|
522
|
|
|
if ( ! empty( $readonly ) ) { |
523
|
|
|
$has_past_shares++; |
524
|
|
|
} |
525
|
|
|
?> |
526
|
|
|
<tr class="ppp-tweet-wrapper ppp-repeatable-row ppp-repeatable-twitter scheduled-row <?php echo $shared; ?>" data-key="<?php echo esc_attr( $key ); ?>"> |
527
|
|
|
<td> |
528
|
|
|
<input <?php echo $readonly; ?>type="text" class="share-date-selector<?php echo $no_date; ?>" name="_ppp_tweets[<?php echo $key; ?>][date]" placeholder="mm/dd/yyyy" value="<?php echo $args['date']; ?>" /> |
529
|
|
|
</td> |
530
|
|
|
|
531
|
|
|
<td> |
532
|
|
|
<input <?php echo $readonly; ?>type="text" class="share-time-selector" name="_ppp_tweets[<?php echo $key; ?>][time]" value="<?php echo $args['time']; ?>" /> |
533
|
|
|
</td> |
534
|
|
|
|
535
|
|
|
<td> |
536
|
|
|
<input <?php echo $readonly; ?>class="ppp-tweet-text-repeatable" type="text" name="_ppp_tweets[<?php echo $key; ?>][text]" value="<?php echo esc_attr( $args['text'] ); ?>" /> |
537
|
|
|
<?php $length = ! empty( $args['text'] ) ? strlen( $args['text'] ) : 0; ?> |
538
|
|
|
<span class="ppp-text-length"><?php echo $length; ?></span> |
539
|
|
|
</td> |
540
|
|
|
|
541
|
|
|
<td class="ppp-repeatable-upload-wrapper" style="width: 200px"> |
542
|
|
|
<div class="ppp-repeatable-upload-field-container"> |
543
|
|
|
<input type="hidden" name="_ppp_tweets[<?php echo $key; ?>][attachment_id]" class="ppp-repeatable-attachment-id-field" value="<?php echo esc_attr( absint( $args['attachment_id'] ) ); ?>"/> |
544
|
|
|
<input <?php echo $readonly; ?>type="text" class="ppp-repeatable-upload-field ppp-upload-field" name="_ppp_tweets[<?php echo $key; ?>][image]" placeholder="<?php _e( 'Upload or Enter URL', 'ppp-txt' ); ?>" value="<?php echo esc_attr( $args['image'] ); ?>" /> |
545
|
|
|
|
546
|
|
|
<span class="ppp-upload-file" style="<?php echo $hide; ?>"> |
547
|
|
|
<a href="#" title="<?php _e( 'Insert File', 'ppp-txt' ) ?>" data-uploader-title="<?php _e( 'Insert File', 'ppp-txt' ); ?>" data-uploader-button-text="<?php _e( 'Insert', 'ppp-txt' ); ?>" class="ppp-upload-file-button" onclick="return false;"> |
548
|
|
|
<span class="dashicons dashicons-upload"></span> |
549
|
|
|
</a> |
550
|
|
|
</span> |
551
|
|
|
|
552
|
|
|
</div> |
553
|
|
|
</td> |
554
|
|
|
|
555
|
|
|
<td> |
556
|
|
|
<a href="#" class="ppp-repeatable-row ppp-remove-repeatable" data-type="twitter" style="background: url(<?php echo admin_url('/images/xit.gif'); ?>) no-repeat;<?php echo $hide; ?>">×</a> |
557
|
|
|
</td> |
558
|
|
|
|
559
|
|
|
</tr> |
560
|
|
|
<?php |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* Save the items in our meta boxes |
565
|
|
|
* @param int $post_id The Post ID being saved |
566
|
|
|
* @param object $post The Post Object being saved |
567
|
|
|
* @return int The Post ID |
568
|
|
|
*/ |
569
|
|
|
function ppp_tw_save_post_meta_boxes( $post_id, $post ) { |
570
|
|
|
|
571
|
35 |
|
if ( ! ppp_should_save( $post_id, $post ) ) { |
572
|
35 |
|
return; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
$ppp_post_exclude = ( isset( $_REQUEST['_ppp_post_exclude'] ) ) ? $_REQUEST['_ppp_post_exclude'] : '0'; |
|
|
|
|
576
|
|
|
|
577
|
|
|
$ppp_share_on_publish = ( isset( $_REQUEST['_ppp_share_on_publish'] ) ) ? $_REQUEST['_ppp_share_on_publish'] : '0'; |
578
|
|
|
$ppp_share_on_publish_text = ( isset( $_REQUEST['_ppp_share_on_publish_text'] ) ) ? $_REQUEST['_ppp_share_on_publish_text'] : ''; |
579
|
|
|
$ppp_share_on_publish_include_image = ( isset( $_REQUEST['_ppp_share_on_publish_include_image'] ) ) ? $_REQUEST['_ppp_share_on_publish_include_image'] : ''; |
580
|
|
|
|
581
|
|
|
|
582
|
|
|
update_post_meta( $post_id, '_ppp_share_on_publish', $ppp_share_on_publish ); |
583
|
|
|
update_post_meta( $post_id, '_ppp_share_on_publish_text', $ppp_share_on_publish_text ); |
584
|
|
|
update_post_meta( $post_id, '_ppp_share_on_publish_include_image', $ppp_share_on_publish_include_image ); |
585
|
|
|
|
586
|
|
|
$tweet_data = isset( $_REQUEST['_ppp_tweets'] ) ? $_REQUEST['_ppp_tweets'] : array(); |
587
|
|
|
foreach ( $tweet_data as $index => $tweet ) { |
588
|
|
|
$tweet_data[ $index ]['text'] = sanitize_text_field( $tweet['text'] ); |
589
|
|
|
} |
590
|
|
|
update_post_meta( $post_id, '_ppp_tweets', $tweet_data ); |
591
|
|
|
|
592
|
|
|
} |
593
|
|
|
add_action( 'save_post', 'ppp_tw_save_post_meta_boxes', 10, 2 ); // save the custom fields |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* Determines if the post should be shared on publish |
597
|
|
|
* @param string $old_status The old post status |
598
|
|
|
* @param string $new_status The new post status |
599
|
|
|
* @param object $post The Post Object |
600
|
|
|
* @return void Shares the post |
601
|
|
|
*/ |
602
|
|
|
function ppp_tw_share_on_publish( $new_status, $old_status, $post ) { |
|
|
|
|
603
|
|
|
global $ppp_options; |
604
|
|
|
|
605
|
|
|
$from_meta = get_post_meta( $post->ID, '_ppp_share_on_publish', true ); |
606
|
|
|
$from_post = isset( $_POST['_ppp_share_on_publish'] ); |
607
|
|
|
|
608
|
|
|
if ( empty( $from_meta ) && empty( $from_post ) ) { |
609
|
|
|
return; |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
// Determine if we're seeing the share on publish in meta or $_POST |
613
|
|
|
if ( $from_meta && !$from_post ) { |
614
|
|
|
$ppp_share_on_publish_text = get_post_meta( $post->ID, '_ppp_share_on_publish_text', true ); |
615
|
|
|
$use_media = get_post_meta( $post->ID, '_ppp_share_on_publish_include_image', true ); |
616
|
|
|
} else { |
617
|
|
|
$ppp_share_on_publish_text = isset( $_POST['_ppp_share_on_publish_text'] ) ? $_POST['_ppp_share_on_publish_text'] : ''; |
618
|
|
|
$use_media = isset( $_POST['_ppp_share_on_publish_include_image'] ) ? $_POST['_ppp_share_on_publish_include_image'] : false; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
$share_content = ( !empty( $ppp_share_on_publish_text ) ) ? $ppp_share_on_publish_text : ppp_tw_generate_share_content( $post->ID, null, false ); |
622
|
|
|
$share_content = apply_filters( 'ppp_share_content', $share_content, array( 'post_id' => $post->ID ) ); |
623
|
|
|
$name = 'sharedate_0_' . $post->ID; |
624
|
|
|
$media = ppp_post_has_media( $post->ID, 'tw', $use_media ); |
625
|
|
|
$share_link = ppp_generate_link( $post->ID, $name, true ); |
626
|
|
|
|
627
|
|
|
$status = ppp_send_tweet( $share_content . ' ' . $share_link, $post->ID, $media ); |
628
|
|
|
|
629
|
|
|
$log_title = ppp_tw_build_share_message( $post->ID, $name, false, false ); |
630
|
|
|
|
631
|
|
|
$log_data = array( |
632
|
|
|
'post_title' => $log_title, |
633
|
|
|
'post_content' => json_encode( $status ), |
634
|
|
|
'post_parent' => $post->ID, |
635
|
|
|
'log_type' => 'ppp_share' |
636
|
|
|
); |
637
|
|
|
|
638
|
|
|
$log_meta = array( |
639
|
|
|
'network' => 'tw', |
640
|
|
|
); |
641
|
|
|
|
642
|
|
|
$log_entry = WP_Logging::insert_log( $log_data, $log_meta ); |
|
|
|
|
643
|
|
|
|
644
|
|
|
if ( ! empty( $status->id_str ) ) { |
645
|
|
|
$author_id = $post->post_author; |
646
|
|
|
$author_rt = get_user_meta( $author_id, '_ppp_share_on_publish', true ); |
647
|
|
|
|
648
|
|
|
if ( $author_rt ) { |
649
|
|
|
$twitter_user = new PPP_Twitter_User( $author_id ); |
650
|
|
|
$twitter_user->retweet( $status->id_str ); |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
} |
654
|
|
|
} |
655
|
|
|
add_action( 'ppp_share_on_publish', 'ppp_tw_share_on_publish', 10, 3 ); |
656
|
|
|
|
657
|
|
|
/** |
658
|
|
|
* Generate the timestamps and names for the scheduled Twitter shares |
659
|
|
|
* |
660
|
|
|
* @since 2.3 |
661
|
|
|
* @param array $times The times to save |
662
|
|
|
* @param int $post_id The Post ID of the item being saved |
663
|
|
|
* @return array Array of timestamps and cron names |
664
|
|
|
*/ |
665
|
|
|
function ppp_tw_generate_timestamps( $times, $post_id ) { |
666
|
1 |
|
$ppp_tweets = get_post_meta( $post_id, '_ppp_tweets', true ); |
667
|
|
|
|
668
|
1 |
|
if ( empty( $ppp_tweets ) ) { |
669
|
1 |
|
$ppp_tweets = array(); |
670
|
1 |
|
} |
671
|
|
|
|
672
|
1 |
|
foreach ( $ppp_tweets as $key => $data ) { |
673
|
1 |
|
if ( ! array_filter( $data ) ) { |
674
|
|
|
continue; |
675
|
|
|
} |
676
|
|
|
|
677
|
1 |
|
$timestamp = ppp_generate_timestamp( $data['date'], $data['time'] ); |
678
|
|
|
|
679
|
1 |
|
if ( $timestamp > current_time( 'timestamp', 1 ) ) { // Make sure the timestamp we're getting is in the future |
680
|
1 |
|
$time_key = strtotime( date_i18n( 'd-m-Y H:i:s', $timestamp , true ) ) . '_tw'; |
681
|
1 |
|
$times[ $time_key ] = 'sharedate_' . $key . '_' . $post_id . '_tw'; |
682
|
1 |
|
} |
683
|
|
|
|
684
|
1 |
|
} |
685
|
|
|
|
686
|
1 |
|
return $times; |
687
|
|
|
} |
688
|
|
|
add_filter( 'ppp_get_timestamps', 'ppp_tw_generate_timestamps', 10, 2 ); |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* Returns if the Twitter Cards are enabled |
692
|
|
|
* |
693
|
|
|
* @since 2.2 |
694
|
|
|
* @return bool If the user has checked to enable Twitter cards |
695
|
|
|
*/ |
696
|
|
|
function ppp_tw_cards_enabled() { |
697
|
|
|
global $ppp_share_settings; |
698
|
|
|
|
699
|
|
|
$ret = false; |
700
|
|
|
|
701
|
|
|
if ( ! empty( $ppp_share_settings['twitter']['cards_enabled'] ) ) { |
702
|
|
|
$ret = true; |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
return apply_filters( 'ppp_tw_cards_enabled', $ret ); |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
/** |
709
|
|
|
* Output the Twitter Card Meta |
710
|
|
|
* |
711
|
|
|
* @since 2.2 |
712
|
|
|
* @return void |
713
|
|
|
*/ |
714
|
|
|
function ppp_tw_card_meta() { |
715
|
|
|
|
716
|
|
|
if ( ! is_single() || ! ppp_twitter_enabled() || ! ppp_tw_cards_enabled() ) { |
717
|
|
|
return; |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
global $post, $ppp_options; |
721
|
|
|
|
722
|
|
|
if ( ! array_key_exists( $post->post_type, $ppp_options['post_types'] ) ) { |
723
|
|
|
return; |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
echo ppp_tw_get_cards_meta(); |
727
|
|
|
} |
728
|
|
|
add_action( 'wp_head', 'ppp_tw_card_meta', 10 ); |
729
|
|
|
|
730
|
|
|
/** |
731
|
|
|
* Generates the Twitter Card Content |
732
|
|
|
* |
733
|
|
|
* @since 2.2 |
734
|
|
|
* @return string The Twitter card Meta tags |
735
|
|
|
*/ |
736
|
|
|
function ppp_tw_get_cards_meta() { |
737
|
|
|
|
738
|
|
|
$return = ''; |
739
|
|
|
|
740
|
|
|
if ( ! is_single() || ! ppp_tw_cards_enabled() ) { |
741
|
|
|
return $return; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
global $post, $ppp_social_settings; |
745
|
|
|
|
746
|
|
|
|
747
|
|
|
if ( empty( $post ) ) { |
748
|
|
|
return; |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
$elements = ppp_tw_default_meta_elements(); |
752
|
|
|
foreach ( $elements as $name => $content ) { |
753
|
|
|
$return .= '<meta name="' . $name . '" content="' . $content . '" />' . "\n"; |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
return apply_filters( 'ppp_tw_card_meta', $return ); |
757
|
|
|
|
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* Sets an array of names and content for Twitter Card Meta |
762
|
|
|
* for easy filtering by devs |
763
|
|
|
* |
764
|
|
|
* @since 2.2 |
765
|
|
|
* @return array The array of keys and values for the Twitter Meta |
766
|
|
|
*/ |
767
|
|
|
function ppp_tw_default_meta_elements() { |
768
|
|
|
global $post, $ppp_social_settings; |
769
|
|
|
|
770
|
|
|
$elements = array(); |
771
|
|
|
|
772
|
|
|
$image_url = ppp_post_has_media( $post->ID, 'tw', true ); |
773
|
|
|
if ( $image_url ) { |
774
|
|
|
$elements['twitter:card'] = 'summary_large_image'; |
775
|
|
|
$elements['twitter:image:src'] = $image_url; |
776
|
|
|
} else { |
777
|
|
|
$elements['twitter:card'] = 'summary'; |
778
|
|
|
} |
779
|
|
|
|
780
|
|
|
$elements['twitter:site'] = '@' . $ppp_social_settings['twitter']['user']->screen_name; |
781
|
|
|
$elements['twitter:title'] = esc_attr( strip_tags( $post->post_title ) ); |
782
|
|
|
$elements['twitter:description'] = esc_attr( ppp_tw_get_card_description() ); |
783
|
|
|
|
784
|
|
|
$author_twitter_handle = get_user_meta( $post->post_author, 'twitter', true ); |
785
|
|
|
if ( ! empty( $author_twitter_handle ) ) { |
786
|
|
|
|
787
|
|
|
if ( strpos( $author_twitter_handle, '@' ) === false ) { |
788
|
|
|
$author_twitter_handle = '@' . $author_twitter_handle; |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
$elements['twitter:creator'] = esc_attr( strip_tags( $author_twitter_handle ) ); |
792
|
|
|
|
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
return apply_filters( 'ppp_tw_card_elements', $elements ); |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* Given a post, will give the post excerpt or the truncated post content to fit in a Twitter Card |
800
|
|
|
* |
801
|
|
|
* @since 2.2 |
802
|
|
|
* @return string The post excerpt/description |
803
|
|
|
*/ |
804
|
|
|
function ppp_tw_get_card_description() { |
805
|
|
|
global $post; |
806
|
|
|
|
807
|
|
|
if ( ! is_single() || empty( $post ) ) { |
808
|
|
|
return false; |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
$excerpt = $post->post_excerpt; |
812
|
|
|
|
813
|
|
|
if ( empty( $excerpt ) ) { |
814
|
|
|
$excerpt = ppp_tw_format_card_description( $post->content ); |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
return apply_filters( 'ppp_tw_card_desc', $excerpt ); |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
/** |
821
|
|
|
* Format a given string for the excerpt |
822
|
|
|
* |
823
|
|
|
* @since 2.3 |
824
|
|
|
* @param string $excerpt The string to possibly truncate |
825
|
|
|
* @return string The description, truncated if over 200 characters |
826
|
|
|
*/ |
827
|
|
|
function ppp_tw_format_card_description( $excerpt ) { |
828
|
1 |
|
$max_len = apply_filters( 'ppp_tw_cart_desc_length', 200 ); |
829
|
1 |
|
$excerpt = strip_tags( $excerpt ); |
830
|
|
|
|
831
|
1 |
|
if ( strlen( $excerpt ) > $max_len ) { |
832
|
|
|
$excerpt_pre = substr( $excerpt, 0, $max_len ); |
833
|
|
|
$last_space = strrpos( $excerpt_pre, ' ' ); |
834
|
|
|
$excerpt = substr( $excerpt_pre, 0, $last_space ) . '...'; |
835
|
|
|
} |
836
|
|
|
|
837
|
1 |
|
return $excerpt; |
838
|
|
|
} |
839
|
|
|
|
840
|
|
|
/** |
841
|
|
|
* Add a Twitter method to the profile editor |
842
|
|
|
* |
843
|
|
|
* @since 2.2.4 |
844
|
|
|
* @param array $user_contactmethods List of user contact methods for the profile editor |
845
|
|
|
* @return array List of contact methods with twitter added |
846
|
|
|
*/ |
847
|
|
|
function ppp_tw_add_contact_method( $user_contactmethods ) { |
848
|
|
|
|
849
|
|
|
if ( ! isset( $user_contactmethods['twitter'] ) ) { |
850
|
|
|
$user_contactmethods['twitter'] = __( 'Twitter', 'ppp-txt' ); |
851
|
|
|
} |
852
|
|
|
// Returns the contact methods |
853
|
|
|
return $user_contactmethods; |
854
|
|
|
} |
855
|
|
|
add_filter( 'user_contactmethods', 'ppp_tw_add_contact_method' ); |
856
|
|
|
|
857
|
|
|
|
858
|
|
|
/** |
859
|
|
|
* Adds in the Post Promoter Pro Preferences Profile Section |
860
|
|
|
* |
861
|
|
|
* @since 2.2.7 |
862
|
|
|
* @param object $user The User object being viewed |
863
|
|
|
* @return void Displays HTML |
864
|
|
|
*/ |
865
|
|
|
function ppp_tw_profile_settings( $user ) { |
866
|
|
|
|
867
|
|
|
if ( $user->ID == get_current_user_id() && ! current_user_can( 'edit_posts' ) ) { |
868
|
|
|
return; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
if ( $user->ID !== get_current_user_id() && ! current_user_can( 'manage_options' ) ) { |
872
|
|
|
return; |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
$connected = false; |
876
|
|
|
?> |
877
|
|
|
<h3><?php _e( 'Post Promoter Pro', 'ppp-txt' ); ?></h3> |
878
|
|
|
<table class="form-table"> |
879
|
|
|
<tr> |
880
|
|
|
<th><?php _e( 'Connect to Twitter', 'ppp-txt' ); ?></th> |
881
|
|
|
<td> |
882
|
|
|
<?php |
883
|
|
|
$twitter = new PPP_Twitter_User( get_current_user_id() ); |
884
|
|
|
$tw_user = get_user_meta( $user->ID, '_ppp_twitter_data', true ); |
885
|
|
|
if ( empty( $tw_user ) ) { |
886
|
|
|
$tw_authurl = $twitter->get_auth_url( admin_url( 'user-edit.php?user_id=' . $user->ID ) ); |
887
|
|
|
|
888
|
|
|
echo '<a href="' . $tw_authurl . '"><img src="' . PPP_URL . '/includes/images/sign-in-with-twitter-gray.png" /></a>'; |
889
|
|
|
} else { |
890
|
|
|
$connected = true; |
891
|
|
|
?> |
892
|
|
|
<p><strong><?php _e( 'Signed in as', 'ppp-txt' ); ?>: </strong><?php echo $tw_user['user']->screen_name; ?></p> |
893
|
|
|
<p> |
894
|
|
|
<a class="button-primary" href="<?php echo admin_url( 'user-edit.php?user_id=' . $user->ID . '&ppp_social_disconnect=true&ppp_network=twitter&user_id=' . $user->ID ); ?>" ><?php _e( 'Disconnect from Twitter', 'ppp-txt' ); ?></a> |
895
|
|
|
<a class="button-secondary" href="https://twitter.com/settings/applications" target="blank"><?php _e( 'Revoke Access via Twitter', 'ppp-txt' ); ?></a> |
896
|
|
|
</p> |
897
|
|
|
<?php |
898
|
|
|
} |
899
|
|
|
?> |
900
|
|
|
</td> |
901
|
|
|
</tr> |
902
|
|
|
|
903
|
|
|
<?php if ( $connected ) : ?> |
904
|
|
|
<?php |
905
|
|
|
$share_on_publish = get_user_meta( $user->ID, '_ppp_share_on_publish', true ); |
906
|
|
|
$share_scheduled = get_user_meta( $user->ID, '_ppp_share_scheduled' , true ); |
907
|
|
|
?> |
908
|
|
|
<tr> |
909
|
|
|
<th><?php _e( 'Sharing Options', 'ppp-txt' ); ?></th> |
910
|
|
|
<td> |
911
|
|
|
<input type="checkbox" <?php checked( true, $share_on_publish, true ); ?>name="share_on_publish" value="1" id="share-on-publish" /> <label for="share-on-publish"><?php _e( 'Retweet my posts when they are published', 'ppp-txt' ); ?></label> |
912
|
|
|
<p class="description"><?php printf( __( 'Retweet the primary account as %s when it Tweets on publishing my posts.', 'ppp-txt' ), $tw_user['user']->screen_name ); ?></p> |
913
|
|
|
</td> |
914
|
|
|
</tr> |
915
|
|
|
<tr> |
916
|
|
|
<th></th> |
917
|
|
|
<td> |
918
|
|
|
<input type="checkbox" <?php checked( true, $share_scheduled, true ); ?> name="share_scheduled" value="1" id="share-scheduled" /> <label for="share-scheduled"><?php _e( 'Retweet scheduled shares of my posts', 'ppp-txt' ); ?></label> |
919
|
|
|
<p class="description"><?php printf( __( 'When the primary account schedules a Tweet for one of my posts, Retweet it as %s.', 'ppp-txt' ), $tw_user['user']->screen_name ); ?></p> |
920
|
|
|
</td> |
921
|
|
|
</tr> |
922
|
|
|
|
923
|
|
|
<?php endif; ?> |
924
|
|
|
</table> |
925
|
|
|
<?php |
926
|
|
|
} |
927
|
|
|
add_action( 'show_user_profile', 'ppp_tw_profile_settings' ); |
928
|
|
|
add_action( 'edit_user_profile', 'ppp_tw_profile_settings' ); |
929
|
|
|
|
930
|
|
|
/** |
931
|
|
|
* Saves the User Profile Settings |
932
|
|
|
* |
933
|
|
|
* @since 2.2.7 |
934
|
|
|
* @param int $user_id The User ID being saved |
935
|
|
|
* @return void Saves to Usermeta |
936
|
|
|
*/ |
937
|
|
|
function ppp_tw_save_profile( $user_id ) { |
938
|
|
|
|
939
|
|
|
$share_on_publish = ! empty( $_POST['share_on_publish'] ) ? true : false; |
940
|
|
|
$share_scheduled = ! empty( $_POST['share_scheduled'] ) ? true : false; |
941
|
|
|
|
942
|
|
|
update_user_meta( $user_id, '_ppp_share_on_publish', $share_on_publish ); |
943
|
|
|
update_user_meta( $user_id, '_ppp_share_scheduled' , $share_scheduled ); |
944
|
|
|
|
945
|
|
|
} |
946
|
|
|
add_action( 'personal_options_update', 'ppp_tw_save_profile' ); |
947
|
|
|
add_action( 'edit_user_profile_update', 'ppp_tw_save_profile' ); |
948
|
|
|
|
949
|
|
|
function ppp_tw_calendar_on_publish_event( $events, $post_id ) { |
950
|
|
|
$share_on_publish = get_post_meta( $post_id, '_ppp_share_on_publish', true ); |
951
|
|
|
|
952
|
|
|
if ( ! empty( $share_on_publish ) ) { |
953
|
|
|
$share_text = get_post_meta( $post_id, '_ppp_share_on_publish_text', true ); |
954
|
|
|
$events[] = array( |
955
|
|
|
'id' => $post_id . '-share-on-publish', |
956
|
|
|
'title' => ( ! empty( $share_text ) ) ? $share_text : ppp_tw_generate_share_content( $post_id, null, false ), |
957
|
|
|
'start' => date_i18n( 'Y-m-d/TH:i:s', strtotime( get_the_date( null, $post_id ) . ' ' . get_the_time( null, $post_id ) ) + 1 ), |
958
|
|
|
'end' => date_i18n( 'Y-m-d/TH:i:s', strtotime( get_the_date( null, $post_id ) . ' ' . get_the_time( null, $post_id ) ) + 1 ), |
959
|
|
|
'className' => 'ppp-calendar-item-tw cal-post-' . $post_id, |
960
|
|
|
'belongsTo' => $post_id, |
961
|
|
|
); |
962
|
|
|
} |
963
|
|
|
|
964
|
|
|
return $events; |
965
|
|
|
} |
966
|
|
|
add_filter( 'ppp_calendar_on_publish_event', 'ppp_tw_calendar_on_publish_event', 10, 2 ); |
967
|
|
|
|
968
|
|
|
function ppp_tw_get_post_shares( $items, $post_id ) { |
969
|
|
|
$tweets = get_post_meta( $post_id, '_ppp_tweets', true ); |
970
|
|
|
if ( empty( $tweets ) ) { return $items; } |
971
|
|
|
|
972
|
|
|
foreach ( $tweets as $key => $tweet ) { |
973
|
|
|
$items[] = array( 'id' => $key, 'service' => 'tw' ); |
974
|
|
|
} |
975
|
|
|
return $items; |
976
|
|
|
} |
977
|
|
|
add_filter( 'ppp_get_post_scheduled_shares', 'ppp_tw_get_post_shares', 10, 2 ); |
978
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.