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
|
|
|
add_action( 'init', array( $this, 'init' ) ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function init() { |
25
|
|
|
// Show only to users with the capability required to manage their Publicize connections. |
26
|
|
|
/** |
27
|
|
|
* Filter what user capability is required to use the publicize form on the edit post page. Useful if publish post capability has been removed from role. |
28
|
|
|
* |
29
|
|
|
* @module publicize |
30
|
|
|
* |
31
|
|
|
* @since 4.1.0 |
32
|
|
|
* |
33
|
|
|
* @param string $capability User capability needed to use publicize |
34
|
|
|
*/ |
35
|
|
|
$capability = apply_filters( 'jetpack_publicize_capability', 'publish_posts' ); |
36
|
|
|
if ( ! current_user_can( $capability ) ) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// assets (css, js) |
41
|
|
|
add_action( 'load-settings_page_sharing', array( &$this, 'load_assets' ) ); |
42
|
|
|
add_action( 'admin_head-post.php', array( &$this, 'post_page_metabox_assets' ) ); |
43
|
|
|
add_action( 'admin_head-post-new.php', array( &$this, 'post_page_metabox_assets' ) ); |
44
|
|
|
|
45
|
|
|
// management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen) |
46
|
|
|
add_action( 'pre_admin_screen_sharing', array( &$this, 'admin_page' ) ); |
47
|
|
|
add_action( 'post_submitbox_misc_actions', array( &$this, 'post_page_metabox' ) ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still |
52
|
|
|
*/ |
53
|
|
|
function sharing_menu() { |
54
|
|
|
add_submenu_page( |
55
|
|
|
'options-general.php', |
56
|
|
|
__( 'Sharing Settings', 'jetpack' ), |
57
|
|
|
__( 'Sharing', 'jetpack' ), |
58
|
|
|
'publish_posts', |
59
|
|
|
'sharing', |
60
|
|
|
array( &$this, 'wrapper_admin_page' ) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function wrapper_admin_page() { |
65
|
|
|
Jetpack_Admin_Page::wrap_ui( array( &$this, 'management_page' ), array( 'is-wide' => true ) ); |
66
|
|
|
} |
67
|
|
|
/** |
68
|
|
|
* Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. |
69
|
|
|
*/ |
70
|
|
|
function management_page() { ?> |
71
|
|
|
<div class="wrap"> |
72
|
|
|
<div class="icon32" id="icon-options-general"><br /></div> |
73
|
|
|
<h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1> |
74
|
|
|
|
75
|
|
|
<?php |
76
|
|
|
/** This action is documented in modules/sharedaddy/sharing.php */ |
77
|
|
|
do_action( 'pre_admin_screen_sharing' ); |
78
|
|
|
?> |
79
|
|
|
|
80
|
|
|
</div> <?php |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* styling for the sharing screen and popups |
85
|
|
|
* JS for the options and switching |
86
|
|
|
*/ |
87
|
|
|
function load_assets() { |
88
|
|
|
wp_enqueue_script( |
89
|
|
|
'publicize', |
90
|
|
|
Jetpack::get_file_url_for_environment( |
91
|
|
|
'_inc/build/publicize/assets/publicize.min.js', |
92
|
|
|
'modules/publicize/assets/publicize.js' |
93
|
|
|
), |
94
|
|
|
array( 'jquery', 'thickbox' ), |
95
|
|
|
'20121019' |
96
|
|
|
); |
97
|
|
|
if ( is_rtl() ) { |
98
|
|
|
wp_enqueue_style( 'publicize', plugins_url( 'assets/rtl/publicize-rtl.css', __FILE__ ), array(), '20180301' ); |
99
|
|
|
} else { |
100
|
|
|
wp_enqueue_style( 'publicize', plugins_url( 'assets/publicize.css', __FILE__ ), array(), '20180301' ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
Jetpack_Admin_Page::load_wrapper_styles(); |
104
|
|
|
wp_enqueue_style( 'social-logos' ); |
105
|
|
|
|
106
|
|
|
add_thickbox(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public static function connected_notice( $service_name ) { ?> |
110
|
|
|
<div class='updated'> |
111
|
|
|
<p><?php |
112
|
|
|
|
113
|
|
|
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
114
|
|
|
$platform = 'WordPress.com'; |
115
|
|
|
} else { |
116
|
|
|
$platform = 'Jetpack'; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
printf( |
120
|
|
|
__( 'You have successfully connected your %1$s account with %2$s.', '1: Service Name (Facebook, Twitter, ...), 2. WordPress.com or Jetpack', 'jetpack' ), |
121
|
|
|
Publicize::get_service_label( $service_name ), |
122
|
|
|
$platform |
123
|
|
|
); ?></p> |
124
|
|
|
</div><?php |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public static function denied_notice() { ?> |
128
|
|
|
<div class='updated'> |
129
|
|
|
<p><?php _e ( "You have chosen not to connect your blog. Please click 'accept' when prompted if you wish to connect your accounts.", 'jetpack' ); ?></p> |
130
|
|
|
</div><?php |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Lists the current user's publicized accounts for the blog |
135
|
|
|
* looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring |
136
|
|
|
*/ |
137
|
|
|
function admin_page() { |
138
|
|
|
$_blog_id = get_current_blog_id(); |
139
|
|
|
?> |
140
|
|
|
|
141
|
|
|
<form action="" id="publicize-form"> |
142
|
|
|
<h2 id="publicize"><?php _e( 'Publicize', 'jetpack' ) ?></h2> |
143
|
|
|
|
144
|
|
|
<?php |
145
|
|
|
if ( ! empty( $_GET['action'] ) && 'deny' == $_GET['action'] ) { |
146
|
|
|
$this->denied_notice(); |
147
|
|
|
} |
148
|
|
|
?> |
149
|
|
|
|
150
|
|
|
<p> |
151
|
|
|
<?php esc_html_e( 'Connect your blog to popular social networking sites and automatically share new posts with your friends.', 'jetpack' ) ?> |
152
|
|
|
<?php esc_html_e( 'You can make a connection for just yourself or for all users on your blog. Shared connections are marked with the (Shared) text.', 'jetpack' ); ?> |
153
|
|
|
</p> |
154
|
|
|
|
155
|
|
|
<?php |
156
|
|
|
if ( $this->in_jetpack ) { |
|
|
|
|
157
|
|
|
$doc_link = "http://jetpack.com/support/publicize/"; |
158
|
|
|
} else { |
159
|
|
|
$doc_link = "http://en.support.wordpress.com/publicize/"; |
160
|
|
|
} |
161
|
|
|
?> |
162
|
|
|
|
163
|
|
|
<p>→ <a href="<?php echo esc_url( $doc_link ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'More information on using Publicize.', 'jetpack' ); ?></a></p> |
164
|
|
|
|
165
|
|
|
<?php if ( isset( $_GET['publicize_popup'] ) ): ?> |
166
|
|
|
<div id="publicize-popup-notify"> |
167
|
|
|
<a href="javascript:close();"> |
168
|
|
|
<?php esc_html_e( 'Click here to close window and go back to editor.', 'jetpack' )?> |
169
|
|
|
</a> |
170
|
|
|
</div> |
171
|
|
|
<?php endif; ?> |
172
|
|
|
|
173
|
|
|
<div id="publicize-services-block"> |
174
|
|
|
<?php |
175
|
|
|
$services = $this->publicize->get_services( 'all' ); |
176
|
|
|
$total_num_of_services = count ( $services ); |
177
|
|
|
$service_num = 0;?> |
178
|
|
|
|
179
|
|
|
<div class='left'> |
180
|
|
|
|
181
|
|
|
<?php |
182
|
|
|
foreach ( $services as $name => $service ) : |
183
|
|
|
$connect_url = $this->publicize->connect_url( $name ); |
184
|
|
|
if ( $service_num == ( round ( ( $total_num_of_services / 2 ), 0 ) ) ) |
185
|
|
|
echo "</div><div class='right'>"; |
186
|
|
|
$service_num++; |
187
|
|
|
?> |
188
|
|
|
<div class="publicize-service-entry" <?php if ( $service_num > 0 ): ?>class="connected"<?php endif; ?> > |
189
|
|
|
<div id="<?php echo esc_attr( $name ); ?>" class="publicize-service-left"> |
190
|
|
|
<a href="<?php echo esc_url( $connect_url ); ?>" id="service-link-<?php echo esc_attr( $name ); ?>" target="_top"><?php echo $this->publicize->get_service_label( $name ); ?></a> |
191
|
|
|
</div> |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
<div class="publicize-service-right"> |
195
|
|
|
<?php if ( $this->publicize->is_enabled( $name ) && $connections = $this->publicize->get_connections( $name ) ) : ?> |
196
|
|
|
<ul> |
197
|
|
|
<?php |
198
|
|
|
foreach( $connections as $c ) : |
199
|
|
|
$id = $this->publicize->get_connection_id( $c ); |
200
|
|
|
$disconnect_url = $this->publicize->disconnect_url( $name, $id ); |
201
|
|
|
|
202
|
|
|
$cmeta = $this->publicize->get_connection_meta( $c ); |
203
|
|
|
$profile_link = $this->publicize->get_profile_link( $name, $c ); |
204
|
|
|
$connection_display = $this->publicize->get_display_name( $name, $c ); |
205
|
|
|
|
206
|
|
|
$options_nonce = wp_create_nonce( 'options_page_' . $name . '_' . $id ); ?> |
207
|
|
|
|
208
|
|
|
<?php if ( $this->publicize->show_options_popup( $name, $c ) ): ?> |
209
|
|
|
<script type="text/javascript"> |
210
|
|
|
jQuery(document).ready( function($) { |
211
|
|
|
showOptionsPage.call( |
212
|
|
|
this, |
213
|
|
|
'<?php echo esc_js( $name ); ?>', |
214
|
|
|
'<?php echo esc_js( $options_nonce ); ?>', |
215
|
|
|
'<?php echo esc_js( $id ); ?>' |
216
|
|
|
); |
217
|
|
|
} ); |
218
|
|
|
</script> |
219
|
|
|
<?php endif; ?> |
220
|
|
|
|
221
|
|
|
<li class="publicize-connection" data-connection-id="<?php echo esc_attr( $id ); ?>"> |
222
|
|
|
<?php esc_html_e( 'Connected as:', 'jetpack' ); ?> |
223
|
|
|
<?php |
224
|
|
|
if ( !empty( $profile_link ) ) : ?> |
225
|
|
|
<a class="publicize-profile-link" href="<?php echo esc_url( $profile_link ); ?>" target="_top"> |
226
|
|
|
<?php echo esc_html( $connection_display ); ?> |
227
|
|
|
</a><?php |
228
|
|
|
else : |
229
|
|
|
echo esc_html( $connection_display ); |
230
|
|
|
endif; |
231
|
|
|
?> |
232
|
|
|
|
233
|
|
|
<?php if ( 0 == $cmeta['connection_data']['user_id'] ) : ?> |
234
|
|
|
<small>(<?php esc_html_e( 'Shared', 'jetpack' ); ?>)</small> |
235
|
|
|
|
236
|
|
|
<?php if ( current_user_can( $this->publicize->GLOBAL_CAP ) ) : ?> |
237
|
|
|
<a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top">×</a> |
238
|
|
|
<?php endif; ?> |
239
|
|
|
|
240
|
|
|
<?php else : ?> |
241
|
|
|
<a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top">×</a> |
242
|
|
|
<?php endif; ?> |
243
|
|
|
|
244
|
|
|
<br/> |
245
|
|
|
<div class="pub-connection-test test-in-progress" id="pub-connection-test-<?php echo esc_attr( $id ); ?>" > |
246
|
|
|
</div> |
247
|
|
|
</li> |
248
|
|
|
|
249
|
|
|
<?php |
250
|
|
|
endforeach; |
251
|
|
|
?> |
252
|
|
|
</ul> |
253
|
|
|
<?php endif; ?> |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
|
257
|
|
|
<?php |
258
|
|
|
$connections = $this->publicize->get_connections( $name ); |
259
|
|
|
if ( empty ( $connections ) ) { ?> |
260
|
|
|
<a id="<?php echo esc_attr( $name ); ?>" class="publicize-add-connection button" href="<?php echo esc_url( $connect_url ); ?>" target="_top"><?php echo esc_html( __( 'Connect', 'jetpack' ) ); ?></a> |
261
|
|
|
<?php } else { ?> |
262
|
|
|
<a id="<?php echo esc_attr( $name ); ?>" class="publicize-add-connection button add-new" href="<?php echo esc_url( $connect_url ); ?>" target="_top"><?php echo esc_html( __( 'Add New', 'jetpack' ) ); ?></a> |
263
|
|
|
<?php } ?> |
264
|
|
|
</div> |
265
|
|
|
</div> |
266
|
|
|
<?php endforeach; ?> |
267
|
|
|
</div> |
268
|
|
|
<script> |
269
|
|
|
(function($){ |
270
|
|
|
$('.pub-disconnect-button').on('click', function(e){ if ( confirm( '<?php echo esc_js( __( 'Are you sure you want to stop Publicizing posts to this connection?', 'jetpack' ) ); ?>' ) ) { |
271
|
|
|
return true; |
272
|
|
|
} else { |
273
|
|
|
e.preventDefault(); |
274
|
|
|
return false; |
275
|
|
|
} |
276
|
|
|
}) |
277
|
|
|
})(jQuery); |
278
|
|
|
</script> |
279
|
|
|
</div> |
280
|
|
|
|
281
|
|
|
<?php wp_nonce_field( "wpas_posts_{$_blog_id}", "_wpas_posts_{$_blog_id}_nonce" ); ?> |
282
|
|
|
<input type="hidden" id="wpas_ajax_blog_id" name="wpas_ajax_blog_id" value="<?php echo $_blog_id; ?>" /> |
283
|
|
|
</form><?php |
284
|
|
|
|
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public static function global_checkbox( $service_name, $id ) { |
288
|
|
|
global $publicize; |
289
|
|
|
if ( current_user_can( $publicize->GLOBAL_CAP ) ) : ?> |
290
|
|
|
<p> |
291
|
|
|
<input id="globalize_<?php echo $service_name; ?>" type="checkbox" name="global" value="<?php echo wp_create_nonce( 'publicize-globalize-' . $id ) ?>" /> |
292
|
|
|
<label for="globalize_<?php echo $service_name; ?>"><?php _e( 'Make this connection available to all users of this blog?', 'jetpack' ); ?></label> |
293
|
|
|
</p> |
294
|
|
|
<?php endif; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
function broken_connection( $service_name, $id ) { ?> |
298
|
|
|
<div id="thickbox-content"> |
299
|
|
|
<div class='error'> |
300
|
|
|
<p><?php printf( __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), Publicize::get_service_label( $service_name ) ); ?></p> |
301
|
|
|
</div> |
302
|
|
|
</div><?php |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
public static function options_page_other( $service_name ) { |
306
|
|
|
// Nonce check |
307
|
|
|
check_admin_referer( "options_page_{$service_name}_" . $_REQUEST['connection'] ); |
308
|
|
|
?> |
309
|
|
|
<div id="thickbox-content"> |
310
|
|
|
<?php |
311
|
|
|
ob_start(); |
312
|
|
|
Publicize_UI::connected_notice( $service_name ); |
313
|
|
|
$update_notice = ob_get_clean(); |
314
|
|
|
if ( ! empty( $update_notice ) ) |
315
|
|
|
echo $update_notice; |
316
|
|
|
?> |
317
|
|
|
|
318
|
|
|
<?php Publicize_UI::global_checkbox( $service_name, $_REQUEST['connection'] ); ?> |
319
|
|
|
|
320
|
|
|
<p style="text-align: center;"> |
321
|
|
|
<input type="submit" value="<?php esc_attr_e( 'OK', 'jetpack' ) ?>" class="button <?php echo $service_name; ?>-options save-options" name="save" data-connection="<?php echo esc_attr( $_REQUEST['connection'] ); ?>" rel="<?php echo wp_create_nonce( 'save_'.$service_name.'_token_' . $_REQUEST['connection'] ) ?>" /> |
322
|
|
|
</p> <br /> |
323
|
|
|
</div> |
324
|
|
|
<?php |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* CSS for styling the publicize message box and counter that displays on the post page. |
329
|
|
|
* There is also some JavaScript for length counting and some basic display effects. |
330
|
|
|
*/ |
331
|
|
|
function post_page_metabox_assets() { |
332
|
|
|
global $post; |
333
|
|
|
$user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; |
|
|
|
|
334
|
|
|
|
335
|
|
|
$default_prefix = $this->publicize->default_prefix; |
336
|
|
|
$default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) ); |
337
|
|
|
|
338
|
|
|
$default_message = $this->publicize->default_message; |
339
|
|
|
$default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) ); |
340
|
|
|
|
341
|
|
|
$default_suffix = $this->publicize->default_suffix; |
342
|
|
|
$default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); ?> |
343
|
|
|
|
344
|
|
|
<script type="text/javascript"> |
345
|
|
|
jQuery( function($) { |
346
|
|
|
var wpasTitleCounter = $( '#wpas-title-counter' ), |
347
|
|
|
wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).length, |
348
|
|
|
wpasTitle = $('#wpas-title').keyup( function() { |
349
|
|
|
var length = wpasTitle.val().length; |
350
|
|
|
wpasTitleCounter.text( length ); |
351
|
|
|
if ( wpasTwitterCheckbox && length > 256 ) { |
352
|
|
|
wpasTitleCounter.addClass( 'wpas-twitter-length-limit' ); |
353
|
|
|
} else { |
354
|
|
|
wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' ); |
355
|
|
|
} |
356
|
|
|
} ), |
357
|
|
|
authClick = false; |
358
|
|
|
|
359
|
|
|
$('#publicize-disconnected-form-show').click( function() { |
360
|
|
|
$('#publicize-form').slideDown( 'fast' ); |
361
|
|
|
$(this).hide(); |
362
|
|
|
} ); |
363
|
|
|
|
364
|
|
|
$('#publicize-disconnected-form-hide').click( function() { |
365
|
|
|
$('#publicize-form').slideUp( 'fast' ); |
366
|
|
|
$('#publicize-disconnected-form-show').show(); |
367
|
|
|
} ); |
368
|
|
|
|
369
|
|
|
$('#publicize-form-edit').click( function() { |
370
|
|
|
$('#publicize-form').slideDown( 'fast', function() { |
371
|
|
|
wpasTitle.focus(); |
372
|
|
|
if ( !wpasTitle.text() ) { |
373
|
|
|
var url = $('#shortlink').length ? $('#shortlink').val() : ''; |
374
|
|
|
|
375
|
|
|
var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, '$("#title").val()', 'url' ); printf( $default_suffix, 'url' ); ?>' ); |
376
|
|
|
|
377
|
|
|
wpasTitle.append( defaultMessage.replace( /<[^>]+>/g,'') ); |
378
|
|
|
|
379
|
|
|
var selBeg = defaultMessage.indexOf( $("#title").val() ); |
380
|
|
|
if ( selBeg < 0 ) { |
381
|
|
|
selBeg = 0; |
382
|
|
|
selEnd = 0; |
383
|
|
|
} else { |
384
|
|
|
selEnd = selBeg + $("#title").val().length; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
var domObj = wpasTitle.get(0); |
388
|
|
|
if ( domObj.setSelectionRange ) { |
389
|
|
|
domObj.setSelectionRange( selBeg, selEnd ); |
390
|
|
|
} else if ( domObj.createTextRange ) { |
391
|
|
|
var r = domObj.createTextRange(); |
392
|
|
|
r.moveStart( 'character', selBeg ); |
393
|
|
|
r.moveEnd( 'character', selEnd ); |
394
|
|
|
r.select(); |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
wpasTitle.keyup(); |
398
|
|
|
} ); |
399
|
|
|
$('#publicize-defaults').hide(); |
400
|
|
|
$(this).hide(); |
401
|
|
|
return false; |
402
|
|
|
} ); |
403
|
|
|
|
404
|
|
|
$('#publicize-form-hide').click( function() { |
405
|
|
|
var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) { |
406
|
|
|
return $.trim( $(el).parent( 'label' ).text() ); |
407
|
|
|
} ); |
408
|
|
|
$('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show(); |
409
|
|
|
$('#publicize-form-edit').show(); |
410
|
|
|
return false; |
411
|
|
|
} ); |
412
|
|
|
|
413
|
|
|
$('.authorize-link').click( function() { |
414
|
|
|
if ( authClick ) { |
415
|
|
|
return false; |
416
|
|
|
} |
417
|
|
|
authClick = true; |
418
|
|
|
$(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' ); |
419
|
|
|
$.ajaxSetup( { async: false } ); |
420
|
|
|
|
421
|
|
|
if ( window.wp && window.wp.autosave ) { |
422
|
|
|
window.wp.autosave.server.triggerSave(); |
423
|
|
|
} else { |
424
|
|
|
autosave(); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
return true; |
428
|
|
|
} ); |
429
|
|
|
|
430
|
|
|
$( '.pub-service' ).click( function() { |
431
|
|
|
var service = $(this).data( 'service' ), |
432
|
|
|
fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />'; |
433
|
|
|
$( '#add-publicize-check' ).append( fakebox ); |
434
|
|
|
} ); |
435
|
|
|
|
436
|
|
|
publicizeConnTestStart = function() { |
437
|
|
|
$( '#pub-connection-tests' ) |
438
|
|
|
.removeClass( 'below-h2' ) |
439
|
|
|
.removeClass( 'error' ) |
440
|
|
|
.removeClass( 'publicize-token-refresh-message' ) |
441
|
|
|
.addClass( 'test-in-progress' ) |
442
|
|
|
.html( '' ); |
443
|
|
|
$.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete ); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
publicizeConnRefreshClick = function( event ) { |
447
|
|
|
event.preventDefault(); |
448
|
|
|
var popupURL = event.currentTarget.href; |
449
|
|
|
var popupTitle = event.currentTarget.title; |
450
|
|
|
// open a popup window |
451
|
|
|
// when it is closed, kick off the tests again |
452
|
|
|
var popupWin = window.open( popupURL, popupTitle, '' ); |
453
|
|
|
var popupWinTimer= window.setInterval( function() { |
454
|
|
|
if ( popupWin.closed !== false ) { |
455
|
|
|
window.clearInterval( popupWinTimer ); |
456
|
|
|
publicizeConnTestStart(); |
457
|
|
|
} |
458
|
|
|
}, 500 ); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
publicizeConnTestComplete = function( response ) { |
462
|
|
|
var testsSelector = $( '#pub-connection-tests' ); |
463
|
|
|
testsSelector |
464
|
|
|
.removeClass( 'test-in-progress' ) |
465
|
|
|
.removeClass( 'below-h2' ) |
466
|
|
|
.removeClass( 'error' ) |
467
|
|
|
.removeClass( 'publicize-token-refresh-message' ) |
468
|
|
|
.html( '' ); |
469
|
|
|
|
470
|
|
|
// If any of the tests failed, show some stuff |
471
|
|
|
var somethingShownAlready = false; |
472
|
|
|
var facebookNotice = false; |
473
|
|
|
$.each( response.data, function( index, testResult ) { |
474
|
|
|
|
475
|
|
|
// find the li for this connection |
476
|
|
|
if ( ! testResult.connectionTestPassed && testResult.userCanRefresh ) { |
477
|
|
|
if ( ! somethingShownAlready ) { |
478
|
|
|
testsSelector |
479
|
|
|
.addClass( 'below-h2' ) |
480
|
|
|
.addClass( 'error' ) |
481
|
|
|
.addClass( 'publicize-token-refresh-message' ) |
482
|
|
|
.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>" ); |
483
|
|
|
somethingShownAlready = true; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
if ( testResult.userCanRefresh ) { |
487
|
|
|
testsSelector.append( '<p/>' ); |
488
|
|
|
$( '<a/>', { |
489
|
|
|
'class' : 'pub-refresh-button button', |
490
|
|
|
'title' : testResult.refreshText, |
491
|
|
|
'href' : testResult.refreshURL, |
492
|
|
|
'text' : testResult.refreshText, |
493
|
|
|
'target' : '_refresh_' + testResult.serviceName |
494
|
|
|
} ) |
495
|
|
|
.appendTo( testsSelector.children().last() ) |
496
|
|
|
.click( publicizeConnRefreshClick ); |
497
|
|
|
} |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
if( ! testResult.connectionTestPassed && ! testResult.userCanRefresh ) { |
501
|
|
|
|
502
|
|
|
$( '#wpas-submit-' + testResult.unique_id ).prop( "checked", false ).prop( "disabled", true ); |
503
|
|
|
if ( ! facebookNotice ) { |
504
|
|
|
var message = '<p>' |
505
|
|
|
+ testResult.connectionTestMessage |
506
|
|
|
+ '</p><p>' |
507
|
|
|
+ ' <a class="button" href="<?php echo esc_url( admin_url( 'options-general.php?page=sharing' ) ); ?>" rel="noopener noreferrer" target="_blank">' |
508
|
|
|
+ '<?php echo esc_html( __( 'Update Your Sharing Settings' ,'jetpack' ) ); ?>' |
509
|
|
|
+ '</a>' |
510
|
|
|
+ '<p>'; |
511
|
|
|
|
512
|
|
|
testsSelector |
513
|
|
|
.addClass( 'below-h2' ) |
514
|
|
|
.addClass( 'error' ) |
515
|
|
|
.addClass( 'publicize-token-refresh-message' ) |
516
|
|
|
.append( message ); |
517
|
|
|
facebookNotice = true; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
|
523
|
|
|
} ); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
$( document ).ready( function() { |
527
|
|
|
// If we have the #pub-connection-tests div present, kick off the connection test |
528
|
|
|
if ( $( '#pub-connection-tests' ).length ) { |
529
|
|
|
publicizeConnTestStart(); |
530
|
|
|
} |
531
|
|
|
} ); |
532
|
|
|
|
533
|
|
|
} ); |
534
|
|
|
</script> |
535
|
|
|
|
536
|
|
|
<style type="text/css"> |
537
|
|
|
#publicize { |
538
|
|
|
line-height: 1.5; |
539
|
|
|
} |
540
|
|
|
#publicize ul { |
541
|
|
|
margin: 4px 0 4px 6px; |
542
|
|
|
} |
543
|
|
|
#publicize li { |
544
|
|
|
margin: 0; |
545
|
|
|
} |
546
|
|
|
#publicize textarea { |
547
|
|
|
margin: 4px 0 0; |
548
|
|
|
width: 100% |
549
|
|
|
} |
550
|
|
|
#publicize ul.not-connected { |
551
|
|
|
list-style: square; |
552
|
|
|
padding-left: 1em; |
553
|
|
|
} |
554
|
|
|
#publicize-title:before { |
555
|
|
|
content: "\f237"; |
556
|
|
|
font: normal 20px/1 dashicons; |
557
|
|
|
speak: none; |
558
|
|
|
margin-left: -1px; |
559
|
|
|
padding-right: 3px; |
560
|
|
|
vertical-align: top; |
561
|
|
|
-webkit-font-smoothing: antialiased; |
562
|
|
|
color: #82878c; |
563
|
|
|
} |
564
|
|
|
.post-new-php .authorize-link, .post-php .authorize-link { |
565
|
|
|
line-height: 1.5em; |
566
|
|
|
} |
567
|
|
|
.post-new-php .authorize-message, .post-php .authorize-message { |
568
|
|
|
margin-bottom: 0; |
569
|
|
|
} |
570
|
|
|
#poststuff #publicize .updated p { |
571
|
|
|
margin: .5em 0; |
572
|
|
|
} |
573
|
|
|
.wpas-twitter-length-limit { |
574
|
|
|
color: red; |
575
|
|
|
} |
576
|
|
|
</style><?php |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* Controls the metabox that is displayed on the post page |
581
|
|
|
* Allows the user to customize the message that will be sent out to the social network, as well as pick which |
582
|
|
|
* networks to publish to. Also displays the character counter and some other information. |
583
|
|
|
*/ |
584
|
|
|
function post_page_metabox() { |
585
|
|
|
global $post; |
586
|
|
|
|
587
|
|
|
if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) ) |
588
|
|
|
return; |
589
|
|
|
|
590
|
|
|
$user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; |
|
|
|
|
591
|
|
|
$services = $this->publicize->get_services( 'connected' ); |
592
|
|
|
$available_services = $this->publicize->get_services( 'all' ); |
593
|
|
|
|
594
|
|
|
if ( ! is_array( $available_services ) ) |
595
|
|
|
$available_services = array(); |
596
|
|
|
|
597
|
|
|
if ( ! is_array( $services ) ) |
598
|
|
|
$services = array(); |
599
|
|
|
?> |
600
|
|
|
<div id="publicize" class="misc-pub-section misc-pub-section-last"> |
601
|
|
|
<span id="publicize-title"> |
602
|
|
|
<?php esc_html_e( 'Publicize:', 'jetpack' ); ?> |
603
|
|
|
<?php if ( 0 < count( $services ) ) : ?> |
604
|
|
|
<?php list( $publicize_form, $active ) = $this->get_metabox_form_connected(); ?> |
605
|
|
|
<span id="publicize-defaults"> |
606
|
|
|
<?php foreach ( $active as $item ) : ?> |
607
|
|
|
<strong><?php echo esc_html( $item ); ?></strong> |
608
|
|
|
<?php endforeach; ?> |
609
|
|
|
</span> |
610
|
|
|
<a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a> <a href="<?php echo esc_url( admin_url( 'options-general.php?page=sharing' ) ); ?>" rel="noopener noreferrer" target="_blank"><?php _e( 'Settings', 'jetpack' ); ?></a><br /> |
611
|
|
|
<?php else : ?> |
612
|
|
|
<?php $publicize_form = $this->get_metabox_form_disconnected( $available_services ); ?> |
613
|
|
|
<strong><?php echo __( 'Not Connected', 'jetpack' ); ?></strong> |
614
|
|
|
<a href="#" id="publicize-disconnected-form-show"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a><br /> |
615
|
|
|
<?php endif; ?> |
616
|
|
|
</span> |
617
|
|
|
<?php |
618
|
|
|
/** |
619
|
|
|
* Filter the Publicize details form. |
620
|
|
|
* |
621
|
|
|
* @module publicize |
622
|
|
|
* |
623
|
|
|
* @since 2.0.0 |
624
|
|
|
* |
625
|
|
|
* @param string $publicize_form Publicize Details form appearing above Publish button in the editor. |
626
|
|
|
*/ |
627
|
|
|
echo apply_filters( 'publicize_form', $publicize_form ); |
628
|
|
|
?> |
629
|
|
|
</div> <?php // #publicize |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* Generates HTML content for connections form. |
634
|
|
|
* |
635
|
|
|
* Retrieves current connection list and generates HTML form. |
636
|
|
|
* |
637
|
|
|
* @since Unknown |
638
|
|
|
* |
639
|
|
|
* @global WP_Post $post The current post instance being published. |
640
|
|
|
* |
641
|
|
|
* @return array { |
642
|
|
|
* Array of content for generating connection form. |
643
|
|
|
* |
644
|
|
|
* @type string HTML content of form |
645
|
|
|
* @type array { |
646
|
|
|
* Array of connection labels for active connections only. |
647
|
|
|
* |
648
|
|
|
* @type string Connection label string. |
649
|
|
|
* } |
650
|
|
|
* } |
651
|
|
|
*/ |
652
|
|
|
private function get_metabox_form_connected() { |
653
|
|
|
global $post; |
654
|
|
|
$active_list = array(); |
655
|
|
|
|
656
|
|
|
$all_done = $this->publicize->done_sharing_post(); |
657
|
|
|
$connection_list = $this->publicize->get_filtered_connection_data(); |
658
|
|
|
|
659
|
|
|
ob_start(); |
660
|
|
|
?> |
661
|
|
|
<div id="publicize-form" class="hide-if-js"> |
662
|
|
|
<ul> |
663
|
|
|
<?php |
664
|
|
|
|
665
|
|
|
foreach ( $connection_list as $c ) { |
666
|
|
|
if ( $c['active'] ) { |
667
|
|
|
$active_list[] = $c['label']; |
668
|
|
|
} |
669
|
|
|
?> |
670
|
|
|
<li> |
671
|
|
|
<label for="wpas-submit-<?php echo esc_attr( $c['unique_id'] ); ?>"> |
672
|
|
|
<input type="checkbox" name="wpas[submit][<?php echo $c['unique_id']; ?>]" id="wpas-submit-<?php echo $c['unique_id']; ?>" class="wpas-submit-<?php echo $c['name']; ?>" value="1" <?php |
673
|
|
|
checked( true, $c['checked'] ); |
674
|
|
|
if ( $c['disabled'] ) { |
675
|
|
|
echo 'disabled="disabled"'; |
676
|
|
|
} |
677
|
|
|
?> /> |
678
|
|
|
<?php |
679
|
|
|
if ( $c['hidden_checkbox'] ) { |
680
|
|
|
// Need to submit a value to force a global connection to post |
681
|
|
|
echo '<input type="hidden" name="wpas[submit][' . $c['unique_id'] . ']" value="1" />'; |
682
|
|
|
} |
683
|
|
|
echo esc_html( $c['label'] ); |
684
|
|
|
?> |
685
|
|
|
</label> |
686
|
|
|
</li> |
687
|
|
|
<?php |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
if ( $title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true ) ) { |
691
|
|
|
$title = esc_html( $title ); |
692
|
|
|
} else { |
693
|
|
|
$title = ''; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
?> |
697
|
|
|
</ul> |
698
|
|
|
|
699
|
|
|
<label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label> |
700
|
|
|
<span id="wpas-title-counter" class="alignright hide-if-no-js">0</span> |
701
|
|
|
|
702
|
|
|
<textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo $title; ?></textarea> |
703
|
|
|
|
704
|
|
|
<a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> |
705
|
|
|
<input type="hidden" name="wpas[0]" value="1" /> |
706
|
|
|
|
707
|
|
|
</div> |
708
|
|
|
<?php if ( ! $all_done ) : ?> |
709
|
|
|
<div id="pub-connection-tests"></div> |
710
|
|
|
<?php endif; ?> |
711
|
|
|
<?php // #publicize-form |
712
|
|
|
return array( ob_get_clean(), $active_list ); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
|
716
|
|
|
private function get_metabox_form_disconnected( $available_services ) { |
717
|
|
|
ob_start(); |
718
|
|
|
?><div id="publicize-form" class="hide-if-js"> |
719
|
|
|
<div id="add-publicize-check" style="display: none;"></div> |
720
|
|
|
|
721
|
|
|
<?php _e( 'Connect to', 'jetpack' ); ?>: |
722
|
|
|
|
723
|
|
|
<ul class="not-connected"> |
724
|
|
|
<?php foreach ( $available_services as $service_name => $service ) : ?> |
725
|
|
|
<li> |
726
|
|
|
<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 ) ) ); ?>" rel="noopener noreferrer" target="_blank" href="<?php echo esc_url( $this->publicize->connect_url( $service_name ) ); ?>"> |
727
|
|
|
<?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?> |
728
|
|
|
</a> |
729
|
|
|
</li> |
730
|
|
|
<?php endforeach; ?> |
731
|
|
|
</ul> |
732
|
|
|
<a href="#" class="hide-if-no-js button" id="publicize-disconnected-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> |
733
|
|
|
</div><?php // #publicize-form |
734
|
|
|
return ob_get_clean(); |
735
|
|
|
} |
736
|
|
|
} |
737
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: