|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Only user facing pieces of Publicize are found here. |
|
5
|
|
|
*/ |
|
6
|
|
|
class Publicize_UI { |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Contains an instance of class 'publicize' which loads Keyring, sets up services, etc. |
|
10
|
|
|
*/ |
|
11
|
|
|
public $publicize; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Hooks into WordPress to display the various pieces of UI and load our assets |
|
15
|
|
|
*/ |
|
16
|
|
|
function __construct() { |
|
17
|
|
|
global $publicize; |
|
18
|
|
|
|
|
19
|
|
|
$this->publicize = $publicize = new Publicize; |
|
20
|
|
|
|
|
21
|
|
|
// assets (css, js) |
|
22
|
|
|
add_action( 'admin_head-post.php', array( $this, 'post_page_metabox_assets' ) ); |
|
23
|
|
|
add_action( 'admin_head-post-new.php', array( $this, 'post_page_metabox_assets' ) ); |
|
24
|
|
|
|
|
25
|
|
|
// management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen) |
|
26
|
|
|
add_action( 'pre_admin_screen_sharing', array( $this, 'admin_page' ) ); |
|
27
|
|
|
add_action( 'post_submitbox_misc_actions', array( $this, 'post_page_metabox' ) ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still |
|
32
|
|
|
*/ |
|
33
|
|
|
function sharing_menu() { |
|
34
|
|
|
add_submenu_page( 'options-general.php', __( 'Sharing Settings', 'jetpack' ), __( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', array( $this, 'management_page' ) ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. |
|
40
|
|
|
*/ |
|
41
|
|
|
function management_page() { ?> |
|
42
|
|
|
<div class="wrap"> |
|
43
|
|
|
<div class="icon32" id="icon-options-general"><br /></div> |
|
44
|
|
|
<h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1> |
|
45
|
|
|
|
|
46
|
|
|
<?php |
|
47
|
|
|
/** This action is documented in modules/sharedaddy/sharing.php */ |
|
48
|
|
|
do_action( 'pre_admin_screen_sharing' ); |
|
49
|
|
|
?> |
|
50
|
|
|
|
|
51
|
|
|
</div> <?php |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function admin_page() { |
|
55
|
|
|
?> |
|
56
|
|
|
<h3 id="publicize"><?php esc_html_e( 'Publicize', 'jetpack' ) ?></h3> |
|
57
|
|
|
<p><?php esc_html_e( 'Connect social media services to automatically share new posts.', 'jetpack' ) ?></p> |
|
58
|
|
|
<h4><?php |
|
59
|
|
|
printf( |
|
60
|
|
|
wp_kses( |
|
61
|
|
|
__( "We've recently made some updates to Publicize. Please visit the <a href='%s'>WordPress.com sharing page</a> to manage your publicize connections or use the button below.", 'jetpack' ), |
|
62
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
63
|
|
|
), |
|
64
|
|
|
esc_url( publicize_calypso_url() ) |
|
65
|
|
|
); |
|
66
|
|
|
?> |
|
67
|
|
|
</h4> |
|
68
|
|
|
|
|
69
|
|
|
<a href="<?php echo esc_url( publicize_calypso_url() ); ?>" class="button button-primary"><?php esc_html_e( 'Publicize Settings', 'jetpack' ); ?></a> |
|
70
|
|
|
|
|
71
|
|
|
<?php |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* CSS for styling the publicize message box and counter that displays on the post page. |
|
76
|
|
|
* There is also some Javascript for length counting and some basic display effects. |
|
77
|
|
|
*/ |
|
78
|
|
|
function post_page_metabox_assets() { |
|
79
|
|
|
global $post; |
|
80
|
|
|
$user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$default_prefix = $this->publicize->default_prefix; |
|
83
|
|
|
$default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) ); |
|
84
|
|
|
|
|
85
|
|
|
$default_message = $this->publicize->default_message; |
|
86
|
|
|
$default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) ); |
|
87
|
|
|
|
|
88
|
|
|
$default_suffix = $this->publicize->default_suffix; |
|
89
|
|
|
$default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); ?> |
|
90
|
|
|
|
|
91
|
|
|
<script type="text/javascript"> |
|
92
|
|
|
jQuery( function($) { |
|
93
|
|
|
var wpasTitleCounter = $( '#wpas-title-counter' ), |
|
94
|
|
|
wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).size(), |
|
95
|
|
|
wpasTitle = $('#wpas-title').keyup( function() { |
|
96
|
|
|
var length = wpasTitle.val().length; |
|
97
|
|
|
wpasTitleCounter.text( length ); |
|
98
|
|
|
if ( wpasTwitterCheckbox && length > 140 ) { |
|
99
|
|
|
wpasTitleCounter.addClass( 'wpas-twitter-length-limit' ); |
|
100
|
|
|
} else { |
|
101
|
|
|
wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' ); |
|
102
|
|
|
} |
|
103
|
|
|
} ), |
|
104
|
|
|
authClick = false; |
|
105
|
|
|
|
|
106
|
|
|
$('#publicize-disconnected-form-show').click( function() { |
|
107
|
|
|
$('#publicize-form').slideDown( 'fast' ); |
|
108
|
|
|
$(this).hide(); |
|
109
|
|
|
} ); |
|
110
|
|
|
|
|
111
|
|
|
$('#publicize-disconnected-form-hide').click( function() { |
|
112
|
|
|
$('#publicize-form').slideUp( 'fast' ); |
|
113
|
|
|
$('#publicize-disconnected-form-show').show(); |
|
114
|
|
|
} ); |
|
115
|
|
|
|
|
116
|
|
|
$('#publicize-form-edit').click( function() { |
|
117
|
|
|
$('#publicize-form').slideDown( 'fast', function() { |
|
118
|
|
|
wpasTitle.focus(); |
|
119
|
|
|
if ( !wpasTitle.text() ) { |
|
120
|
|
|
var url = $('#shortlink').size() ? $('#shortlink').val() : ''; |
|
121
|
|
|
|
|
122
|
|
|
var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, '$("#title").val()', 'url' ); printf( $default_suffix, 'url' ); ?>' ); |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
wpasTitle.append( defaultMessage.replace( /<[^>]+>/g,'') ); |
|
125
|
|
|
|
|
126
|
|
|
var selBeg = defaultMessage.indexOf( $("#title").val() ); |
|
127
|
|
|
if ( selBeg < 0 ) { |
|
128
|
|
|
selBeg = 0; |
|
129
|
|
|
selEnd = 0; |
|
130
|
|
|
} else { |
|
131
|
|
|
selEnd = selBeg + $("#title").val().length; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
var domObj = wpasTitle.get(0); |
|
135
|
|
|
if ( domObj.setSelectionRange ) { |
|
136
|
|
|
domObj.setSelectionRange( selBeg, selEnd ); |
|
137
|
|
|
} else if ( domObj.createTextRange ) { |
|
138
|
|
|
var r = domObj.createTextRange(); |
|
139
|
|
|
r.moveStart( 'character', selBeg ); |
|
140
|
|
|
r.moveEnd( 'character', selEnd ); |
|
141
|
|
|
r.select(); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
wpasTitle.keyup(); |
|
145
|
|
|
} ); |
|
146
|
|
|
$('#publicize-defaults').hide(); |
|
147
|
|
|
$(this).hide(); |
|
148
|
|
|
return false; |
|
149
|
|
|
} ); |
|
150
|
|
|
|
|
151
|
|
|
$('#publicize-form-hide').click( function() { |
|
152
|
|
|
var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) { |
|
153
|
|
|
return $.trim( $(el).parent( 'label' ).text() ); |
|
154
|
|
|
} ); |
|
155
|
|
|
$('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show(); |
|
156
|
|
|
$('#publicize-form-edit').show(); |
|
157
|
|
|
return false; |
|
158
|
|
|
} ); |
|
159
|
|
|
|
|
160
|
|
|
$('.authorize-link').click( function() { |
|
161
|
|
|
if ( authClick ) { |
|
162
|
|
|
return false; |
|
163
|
|
|
} |
|
164
|
|
|
authClick = true; |
|
165
|
|
|
$(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' ); |
|
166
|
|
|
$.ajaxSetup( { async: false } ); |
|
167
|
|
|
|
|
168
|
|
|
if ( window.wp && window.wp.autosave ) { |
|
169
|
|
|
window.wp.autosave.server.triggerSave(); |
|
170
|
|
|
} else { |
|
171
|
|
|
autosave(); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
return true; |
|
175
|
|
|
} ); |
|
176
|
|
|
|
|
177
|
|
|
$( '.pub-service' ).click( function() { |
|
178
|
|
|
var service = $(this).data( 'service' ), |
|
179
|
|
|
fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />'; |
|
180
|
|
|
$( '#add-publicize-check' ).append( fakebox ); |
|
181
|
|
|
} ); |
|
182
|
|
|
|
|
183
|
|
|
publicizeConnTestStart = function() { |
|
184
|
|
|
$( '#pub-connection-tests' ) |
|
185
|
|
|
.removeClass( 'below-h2' ) |
|
186
|
|
|
.removeClass( 'error' ) |
|
187
|
|
|
.removeClass( 'publicize-token-refresh-message' ) |
|
188
|
|
|
.addClass( 'test-in-progress' ) |
|
189
|
|
|
.html( '' ); |
|
190
|
|
|
$.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete ); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
publicizeConnRefreshClick = function( event ) { |
|
194
|
|
|
event.preventDefault(); |
|
195
|
|
|
var popupURL = event.currentTarget.href; |
|
196
|
|
|
var popupTitle = event.currentTarget.title; |
|
197
|
|
|
// open a popup window |
|
198
|
|
|
// when it is closed, kick off the tests again |
|
199
|
|
|
var popupWin = window.open( popupURL, popupTitle, '' ); |
|
200
|
|
|
var popupWinTimer= window.setInterval( function() { |
|
201
|
|
|
if ( popupWin.closed !== false ) { |
|
202
|
|
|
window.clearInterval( popupWinTimer ); |
|
203
|
|
|
publicizeConnTestStart(); |
|
204
|
|
|
} |
|
205
|
|
|
}, 500 ); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
publicizeConnTestComplete = function( response ) { |
|
209
|
|
|
var testsSelector = $( '#pub-connection-tests' ); |
|
210
|
|
|
testsSelector |
|
211
|
|
|
.removeClass( 'test-in-progress' ) |
|
212
|
|
|
.removeClass( 'below-h2' ) |
|
213
|
|
|
.removeClass( 'error' ) |
|
214
|
|
|
.removeClass( 'publicize-token-refresh-message' ) |
|
215
|
|
|
.html( '' ); |
|
216
|
|
|
|
|
217
|
|
|
// If any of the tests failed, show some stuff |
|
218
|
|
|
var somethingShownAlready = false; |
|
219
|
|
|
$.each( response.data, function( index, testResult ) { |
|
220
|
|
|
// find the li for this connection |
|
221
|
|
|
if ( ! testResult.connectionTestPassed ) { |
|
222
|
|
|
if ( ! somethingShownAlready ) { |
|
223
|
|
|
testsSelector |
|
224
|
|
|
.addClass( 'below-h2' ) |
|
225
|
|
|
.addClass( 'error' ) |
|
226
|
|
|
.addClass( 'publicize-token-refresh-message' ) |
|
227
|
|
|
.append( "<p><?php echo esc_html( __( 'Before you hit Publish, please refresh the following connection(s) to make sure we can Publicize your post:', 'jetpack' ) ); ?></p>" ); |
|
228
|
|
|
somethingShownAlready = true; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
if ( testResult.userCanRefresh ) { |
|
232
|
|
|
testsSelector.append( '<p/>' ); |
|
233
|
|
|
$( '<a/>', { |
|
234
|
|
|
'class' : 'pub-refresh-button button', |
|
235
|
|
|
'title' : testResult.refreshText, |
|
236
|
|
|
'href' : testResult.refreshURL, |
|
237
|
|
|
'text' : testResult.refreshText, |
|
238
|
|
|
'target' : '_refresh_' + testResult.serviceName |
|
239
|
|
|
} ) |
|
240
|
|
|
.appendTo( testsSelector.children().last() ) |
|
241
|
|
|
.click( publicizeConnRefreshClick ); |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
} ); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
$( document ).ready( function() { |
|
248
|
|
|
// If we have the #pub-connection-tests div present, kick off the connection test |
|
249
|
|
|
if ( $( '#pub-connection-tests' ).length ) { |
|
250
|
|
|
publicizeConnTestStart(); |
|
251
|
|
|
} |
|
252
|
|
|
} ); |
|
253
|
|
|
|
|
254
|
|
|
} ); |
|
255
|
|
|
</script> |
|
256
|
|
|
|
|
257
|
|
|
<style type="text/css"> |
|
258
|
|
|
#publicize { |
|
259
|
|
|
line-height: 1.5; |
|
260
|
|
|
} |
|
261
|
|
|
#publicize ul { |
|
262
|
|
|
margin: 4px 0 4px 6px; |
|
263
|
|
|
} |
|
264
|
|
|
#publicize li { |
|
265
|
|
|
margin: 0; |
|
266
|
|
|
} |
|
267
|
|
|
#publicize textarea { |
|
268
|
|
|
margin: 4px 0 0; |
|
269
|
|
|
width: 100% |
|
270
|
|
|
} |
|
271
|
|
|
#publicize ul.not-connected { |
|
272
|
|
|
list-style: square; |
|
273
|
|
|
padding-left: 1em; |
|
274
|
|
|
} |
|
275
|
|
|
.post-new-php .authorize-link, .post-php .authorize-link { |
|
276
|
|
|
line-height: 1.5em; |
|
277
|
|
|
} |
|
278
|
|
|
.post-new-php .authorize-message, .post-php .authorize-message { |
|
279
|
|
|
margin-bottom: 0; |
|
280
|
|
|
} |
|
281
|
|
|
#poststuff #publicize .updated p { |
|
282
|
|
|
margin: .5em 0; |
|
283
|
|
|
} |
|
284
|
|
|
.wpas-twitter-length-limit { |
|
285
|
|
|
color: red; |
|
286
|
|
|
} |
|
287
|
|
|
</style><?php |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Controls the metabox that is displayed on the post page |
|
292
|
|
|
* Allows the user to customize the message that will be sent out to the social network, as well as pick which |
|
293
|
|
|
* networks to publish to. Also displays the character counter and some other information. |
|
294
|
|
|
*/ |
|
295
|
|
|
function post_page_metabox() { |
|
296
|
|
|
global $post; |
|
297
|
|
|
|
|
298
|
|
|
if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) ) |
|
299
|
|
|
return; |
|
300
|
|
|
|
|
301
|
|
|
$user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; |
|
|
|
|
|
|
302
|
|
|
$services = $this->publicize->get_services( 'connected' ); |
|
303
|
|
|
$available_services = $this->publicize->get_services( 'all' ); |
|
304
|
|
|
|
|
305
|
|
|
if ( ! is_array( $available_services ) ) |
|
306
|
|
|
$available_services = array(); |
|
307
|
|
|
|
|
308
|
|
|
if ( ! is_array( $services ) ) |
|
309
|
|
|
$services = array(); |
|
310
|
|
|
|
|
311
|
|
|
$active = array(); ?> |
|
312
|
|
|
|
|
313
|
|
|
<div id="publicize" class="misc-pub-section misc-pub-section-last"> |
|
314
|
|
|
<?php |
|
315
|
|
|
_e( 'Publicize:', 'jetpack' ); |
|
316
|
|
|
|
|
317
|
|
|
if ( 0 < count( $services ) ) : |
|
318
|
|
|
ob_start(); |
|
319
|
|
|
?> |
|
320
|
|
|
|
|
321
|
|
|
<div id="publicize-form" class="hide-if-js"> |
|
322
|
|
|
<ul> |
|
323
|
|
|
|
|
324
|
|
|
<?php |
|
325
|
|
|
// We can set an _all flag to indicate that this post is completely done as |
|
326
|
|
|
// far as Publicize is concerned. Jetpack uses this approach. All published posts in Jetpack |
|
327
|
|
|
// have Publicize disabled. |
|
328
|
|
|
$all_done = get_post_meta( $post->ID, $this->publicize->POST_DONE . 'all', true ) || ( $this->in_jetpack && 'publish' == $post->post_status ); |
|
|
|
|
|
|
329
|
|
|
|
|
330
|
|
|
// We don't allow Publicizing to the same external id twice, to prevent spam |
|
331
|
|
|
$service_id_done = (array) get_post_meta( $post->ID, $this->publicize->POST_SERVICE_DONE, true ); |
|
332
|
|
|
|
|
333
|
|
|
foreach ( $services as $name => $connections ) { |
|
334
|
|
|
foreach ( $connections as $connection ) { |
|
335
|
|
|
$connection_data = ''; |
|
336
|
|
View Code Duplication |
if ( method_exists( $connection, 'get_meta' ) ) |
|
337
|
|
|
$connection_data = $connection->get_meta( 'connection_data' ); |
|
338
|
|
|
elseif ( ! empty( $connection['connection_data'] ) ) |
|
339
|
|
|
$connection_data = $connection['connection_data']; |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* Filter whether a post should be publicized to a given service. |
|
343
|
|
|
* |
|
344
|
|
|
* @module publicize |
|
345
|
|
|
* |
|
346
|
|
|
* @since 2.0.0 |
|
347
|
|
|
* |
|
348
|
|
|
* @param bool true Should the post be publicized to a given service? Default to true. |
|
349
|
|
|
* @param int $post->ID Post ID. |
|
350
|
|
|
* @param string $name Service name. |
|
351
|
|
|
* @param array $connection_data Array of information about all Publicize details for the site. |
|
352
|
|
|
*/ |
|
353
|
|
|
if ( ! $continue = apply_filters( 'wpas_submit_post?', true, $post->ID, $name, $connection_data ) ) { |
|
354
|
|
|
continue; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
View Code Duplication |
if ( ! empty( $connection->unique_id ) ) { |
|
358
|
|
|
$unique_id = $connection->unique_id; |
|
359
|
|
|
} else if ( ! empty( $connection['connection_data']['token_id'] ) ) { |
|
360
|
|
|
$unique_id = $connection['connection_data']['token_id']; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
// Should we be skipping this one? |
|
364
|
|
|
$skip = ( |
|
365
|
|
|
( |
|
366
|
|
|
in_array( $post->post_status, array( 'publish', 'draft', 'future' ) ) |
|
367
|
|
|
&& |
|
368
|
|
|
get_post_meta( $post->ID, $this->publicize->POST_SKIP . $unique_id, true ) |
|
|
|
|
|
|
369
|
|
|
) |
|
370
|
|
|
|| |
|
371
|
|
|
( |
|
372
|
|
|
is_array( $connection ) |
|
373
|
|
|
&& |
|
374
|
|
|
( |
|
375
|
|
|
( isset( $connection['meta']['external_id'] ) && ! empty( $service_id_done[ $name ][ $connection['meta']['external_id'] ] ) ) |
|
376
|
|
|
|| |
|
377
|
|
|
// Jetpack's connection data looks a little different. |
|
378
|
|
|
( isset( $connection['external_id'] ) && ! empty( $service_id_done[ $name ][ $connection['external_id'] ] ) ) |
|
379
|
|
|
) |
|
380
|
|
|
) |
|
381
|
|
|
); |
|
382
|
|
|
|
|
383
|
|
|
// Was this connections (OR, old-format service) already Publicized to? |
|
384
|
|
|
$done = ( 1 == get_post_meta( $post->ID, $this->publicize->POST_DONE . $unique_id, true ) || 1 == get_post_meta( $post->ID, $this->publicize->POST_DONE . $name, true ) ); // New and old style flags |
|
385
|
|
|
|
|
386
|
|
|
// If this one has already been publicized to, don't let it happen again |
|
387
|
|
|
$disabled = ''; |
|
388
|
|
|
if ( $done ) |
|
389
|
|
|
$disabled = ' disabled="disabled"'; |
|
390
|
|
|
|
|
391
|
|
|
// If this is a global connection and this user doesn't have enough permissions to modify |
|
392
|
|
|
// those connections, don't let them change it |
|
393
|
|
|
$cmeta = $this->publicize->get_connection_meta( $connection ); |
|
394
|
|
|
$hidden_checkbox = false; |
|
395
|
|
|
if ( !$done && ( 0 == $cmeta['connection_data']['user_id'] && !current_user_can( $this->publicize->GLOBAL_CAP ) ) ) { |
|
396
|
|
|
$disabled = ' disabled="disabled"'; |
|
397
|
|
|
/** |
|
398
|
|
|
* Filters the checkboxes for global connections with non-prilvedged users. |
|
399
|
|
|
* |
|
400
|
|
|
* @module publicize |
|
401
|
|
|
* |
|
402
|
|
|
* @since 3.7.0 |
|
403
|
|
|
* |
|
404
|
|
|
* @param bool $checked Indicates if this connection should be enabled. Default true. |
|
405
|
|
|
* @param int $post->ID ID of the current post |
|
406
|
|
|
* @param string $name Name of the connection (Facebook, Twitter, etc) |
|
407
|
|
|
* @param array $connection Array of data about the connection. |
|
408
|
|
|
*/ |
|
409
|
|
|
$hidden_checkbox = apply_filters( 'publicize_checkbox_global_default', true, $post->ID, $name, $connection ); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
// Determine the state of the checkbox (on/off) and allow filtering |
|
413
|
|
|
$checked = $skip != 1 || $done; |
|
414
|
|
|
/** |
|
415
|
|
|
* Filter the checkbox state of each Publicize connection appearing in the post editor. |
|
416
|
|
|
* |
|
417
|
|
|
* @module publicize |
|
418
|
|
|
* |
|
419
|
|
|
* @since 2.0.1 |
|
420
|
|
|
* |
|
421
|
|
|
* @param bool $checked Should the Publicize checkbox be enabled for a given service. |
|
422
|
|
|
* @param int $post->ID Post ID. |
|
423
|
|
|
* @param string $name Service name. |
|
424
|
|
|
* @param array $connection Array of connection details. |
|
425
|
|
|
*/ |
|
426
|
|
|
$checked = apply_filters( 'publicize_checkbox_default', $checked, $post->ID, $name, $connection ); |
|
427
|
|
|
|
|
428
|
|
|
// Force the checkbox to be checked if the post was DONE, regardless of what the filter does |
|
429
|
|
|
if ( $done ) { |
|
430
|
|
|
$checked = true; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
// This post has been handled, so disable everything |
|
434
|
|
|
if ( $all_done ) { |
|
435
|
|
|
$disabled = ' disabled="disabled"'; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
$label = sprintf( |
|
439
|
|
|
_x( '%1$s: %2$s', 'Service: Account connected as', 'jetpack' ), |
|
440
|
|
|
esc_html( $this->publicize->get_service_label( $name ) ), |
|
441
|
|
|
esc_html( $this->publicize->get_display_name( $name, $connection ) ) |
|
442
|
|
|
); |
|
443
|
|
|
if ( !$skip || $done ) { |
|
444
|
|
|
$active[] = $label; |
|
445
|
|
|
} |
|
446
|
|
|
?> |
|
447
|
|
|
<li> |
|
448
|
|
|
<label for="wpas-submit-<?php echo esc_attr( $unique_id ); ?>"> |
|
449
|
|
|
<input type="checkbox" name="wpas[submit][<?php echo $unique_id; ?>]" id="wpas-submit-<?php echo $unique_id; ?>" class="wpas-submit-<?php echo $name; ?>" value="1" <?php |
|
450
|
|
|
checked( true, $checked ); |
|
451
|
|
|
echo $disabled; |
|
452
|
|
|
?> /> |
|
453
|
|
|
<?php |
|
454
|
|
|
if ( $hidden_checkbox ) { |
|
455
|
|
|
// Need to submit a value to force a global connection to post |
|
456
|
|
|
echo '<input type="hidden" name="wpas[submit][' . $unique_id . ']" value="1" />'; |
|
457
|
|
|
} |
|
458
|
|
|
echo esc_html( $label ); |
|
459
|
|
|
?> |
|
460
|
|
|
</label> |
|
461
|
|
|
</li> |
|
462
|
|
|
<?php |
|
463
|
|
|
} |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
if ( $title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true ) ) { |
|
467
|
|
|
$title = esc_html( $title ); |
|
468
|
|
|
} else { |
|
469
|
|
|
$title = ''; |
|
470
|
|
|
} |
|
471
|
|
|
?> |
|
472
|
|
|
|
|
473
|
|
|
</ul> |
|
474
|
|
|
|
|
475
|
|
|
<label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label> |
|
476
|
|
|
<span id="wpas-title-counter" class="alignright hide-if-no-js">0</span> |
|
477
|
|
|
|
|
478
|
|
|
<textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo $title; ?></textarea> |
|
479
|
|
|
|
|
480
|
|
|
<a href="#" class="hide-if-no-js" id="publicize-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a> |
|
481
|
|
|
<input type="hidden" name="wpas[0]" value="1" /> |
|
482
|
|
|
|
|
483
|
|
|
</div> |
|
484
|
|
|
<div id="pub-connection-tests"></div> |
|
485
|
|
|
<?php // #publicize-form |
|
486
|
|
|
|
|
487
|
|
|
$publicize_form = ob_get_clean(); |
|
488
|
|
|
else : |
|
489
|
|
|
echo " " . __( 'Not Connected', 'jetpack' ); |
|
490
|
|
|
ob_start(); |
|
491
|
|
|
?> |
|
492
|
|
|
|
|
493
|
|
|
<div id="publicize-form" class="hide-if-js"> |
|
494
|
|
|
<div id="add-publicize-check" style="display: none;"></div> |
|
495
|
|
|
|
|
496
|
|
|
<strong><?php _e( 'Connect to', 'jetpack' ); ?>:</strong> |
|
497
|
|
|
|
|
498
|
|
|
<ul class="not-connected"> |
|
499
|
|
|
<?php foreach ( $available_services as $service_name => $service ) : ?> |
|
500
|
|
|
<li> |
|
501
|
|
|
<a class="pub-service" data-service="<?php echo esc_attr( $service_name ); ?>" title="<?php echo esc_attr( sprintf( __( 'Connect and share your posts on %s', 'jetpack' ), $this->publicize->get_service_label( $service_name ) ) ); ?>" target="_blank" href="<?php echo $this->publicize->connect_url( $service_name ); ?>"> |
|
502
|
|
|
<?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?> |
|
503
|
|
|
</a> |
|
504
|
|
|
</li> |
|
505
|
|
|
<?php endforeach; ?> |
|
506
|
|
|
</ul> |
|
507
|
|
|
|
|
508
|
|
|
<?php if ( 0 < count( $services ) ) : ?> |
|
509
|
|
|
<a href="#" class="hide-if-no-js" id="publicize-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a> |
|
510
|
|
|
<?php else : ?> |
|
511
|
|
|
<a href="#" class="hide-if-no-js" id="publicize-disconnected-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a> |
|
512
|
|
|
<?php endif; ?> |
|
513
|
|
|
</div> <?php // #publicize-form |
|
514
|
|
|
|
|
515
|
|
|
$publicize_form = ob_get_clean(); |
|
516
|
|
|
endif; |
|
517
|
|
|
?> |
|
518
|
|
|
|
|
519
|
|
|
<span id="publicize-defaults"><strong><?php echo join( '</strong>, <strong>', array_map( 'esc_html', $active ) ); ?></strong></span><br /> |
|
520
|
|
|
|
|
521
|
|
|
<?php if ( 0 < count( $services ) ) : ?> |
|
522
|
|
|
<a href="#" id="publicize-form-edit"><?php _e( 'Edit Details', 'jetpack' ); ?></a> <a href="<?php echo admin_url( 'options-general.php?page=sharing' ); ?>" target="_blank"><?php _e( 'Settings', 'jetpack' ); ?></a><br /> |
|
523
|
|
|
<?php else : ?> |
|
524
|
|
|
<a href="#" id="publicize-disconnected-form-show"><?php _e( 'Show', 'jetpack' ); ?></a><br /> |
|
525
|
|
|
<?php endif; ?> |
|
526
|
|
|
|
|
527
|
|
|
<?php |
|
528
|
|
|
/** |
|
529
|
|
|
* Filter the Publicize details form. |
|
530
|
|
|
* |
|
531
|
|
|
* @module publicize |
|
532
|
|
|
* |
|
533
|
|
|
* @since 2.0.0 |
|
534
|
|
|
* |
|
535
|
|
|
* @param string $publicize_form Publicize Details form appearing above Publish button in the editor. |
|
536
|
|
|
*/ |
|
537
|
|
|
echo apply_filters( 'publicize_form', $publicize_form ); |
|
538
|
|
|
?> |
|
539
|
|
|
|
|
540
|
|
|
</div> <?php // #publicize |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
} |
|
544
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.