Publicize_UI

Only user facing pieces of Publicize are found here.

Defined (1)

The class is defined in the following location(s).

/modules/publicize/ui.php  
  1. class Publicize_UI { 
  2.  
  3. /** 
  4. * Contains an instance of class 'publicize' which loads Keyring, sets up services, etc. 
  5. */ 
  6. public $publicize; 
  7.  
  8. /** 
  9. * Hooks into WordPress to display the various pieces of UI and load our assets 
  10. */ 
  11. function __construct() { 
  12. global $publicize; 
  13.  
  14. $this->publicize = $publicize = new Publicize; 
  15.  
  16. // assets (css, js) 
  17. add_action( 'load-settings_page_sharing', array( &$this, 'load_assets' ) ); 
  18. add_action( 'admin_head-post.php', array( &$this, 'post_page_metabox_assets' ) ); 
  19. add_action( 'admin_head-post-new.php', array( &$this, 'post_page_metabox_assets' ) ); 
  20.  
  21. // management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen) 
  22. add_action( 'pre_admin_screen_sharing', array( &$this, 'admin_page' ) ); 
  23. add_action( 'post_submitbox_misc_actions', array( &$this, 'post_page_metabox' ) ); 
  24.  
  25. /** 
  26. * If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still 
  27. */ 
  28. function sharing_menu() { 
  29. add_submenu_page( 'options-general.php', __( 'Sharing Settings', 'jetpack' ), __( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', array( &$this, 'management_page' ) ); 
  30.  
  31.  
  32. /** 
  33. * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. 
  34. */ 
  35. function management_page() { ?> 
  36. <div class="wrap"> 
  37. <div class="icon32" id="icon-options-general"><br /></div> 
  38. <h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1> 
  39.  
  40. <?php 
  41. /** This action is documented in modules/sharedaddy/sharing.php */ 
  42. do_action( 'pre_admin_screen_sharing' ); 
  43. ?> 
  44.  
  45. </div> <?php 
  46.  
  47. /** 
  48. * styling for the sharing screen and popups 
  49. * JS for the options and switching 
  50. */ 
  51. function load_assets() { 
  52. wp_enqueue_script( 
  53. 'publicize',  
  54. plugins_url( 'assets/publicize.js', __FILE__ ),  
  55. array( 'jquery', 'thickbox' ),  
  56. '20121019' 
  57. ); 
  58. if( is_rtl() ) { 
  59. wp_enqueue_style( 'publicize', plugins_url( 'assets/rtl/publicize-rtl.css', __FILE__ ), array(), '20120925' ); 
  60. } else { 
  61. wp_enqueue_style( 'publicize', plugins_url( 'assets/publicize.css', __FILE__ ), array(), '20120925' ); 
  62.  
  63.  
  64. add_thickbox(); 
  65.  
  66. public static function connected_notice( $service_name ) { ?> 
  67. <div class='updated'> 
  68. <p><?php 
  69.  
  70. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  71. $platform = __( 'WordPress.com', 'jetpack' ); 
  72. } else { 
  73. $platform = __( 'Jetpack', 'jetpack' ); 
  74.  
  75. printf( 
  76. __( 'You have successfully connected your %1$s account with %2$s.', '1: Service Name (Facebook, Twitter, ...), 2. WordPress.com or Jetpack', 'jetpack' ),  
  77. Publicize::get_service_label( $service_name ),  
  78. $platform 
  79. ); ?></p> 
  80. </div><?php 
  81.  
  82. public static function denied_notice() { ?> 
  83. <div class='updated'> 
  84. <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> 
  85. </div><?php 
  86.  
  87. /** 
  88. * Lists the current user's publicized accounts for the blog 
  89. * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring 
  90. */ 
  91. function admin_page() { 
  92. $_blog_id = get_current_blog_id(); 
  93. ?> 
  94.  
  95. <form action="" id="publicize-form"> 
  96. <h2 id="publicize"><?php _e( 'Publicize', 'jetpack' ) ?></h2> 
  97.  
  98. <?php 
  99. if ( ! empty( $_GET['action'] ) && 'deny' == $_GET['action'] ) { 
  100. $this->denied_notice(); 
  101. ?> 
  102.  
  103. <p> 
  104. <?php esc_html_e( 'Connect your blog to popular social networking sites and automatically share new posts with your friends.', 'jetpack' ) ?> 
  105. <?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' ); ?> 
  106. </p> 
  107.  
  108. <?php 
  109. if ( $this->in_jetpack ) { 
  110. $doc_link = "http://jetpack.me/support/publicize/"; 
  111. } else { 
  112. $doc_link = "http://en.support.wordpress.com/publicize/"; 
  113. ?> 
  114.  
  115. <p>→ <a href="<?php echo esc_url( $doc_link ); ?>" target="_blank"><?php esc_html_e( 'More information on using Publicize.', 'jetpack' ); ?></a></p> 
  116.  
  117. <div id="publicize-services-block"> 
  118. <?php 
  119. $services = $this->publicize->get_services( 'all' ); 
  120. $total_num_of_services = count ( $services ); 
  121. $service_num = 0;?> 
  122.  
  123. <div class='left'> 
  124.  
  125. <?php 
  126. foreach ( $services as $name => $service ) : 
  127. $connect_url = $this->publicize->connect_url( $name ); 
  128. if ( $service_num == ( round ( ( $total_num_of_services / 2 ), 0 ) ) ) 
  129. echo "</div><div class='right'>"; 
  130. $service_num++; 
  131. ?> 
  132. <div class="publicize-service-entry" <?php if ( $service_num > 0 ): ?>class="connected"<?php endif; ?> > 
  133. <div id="<?php echo esc_attr( $name ); ?>" class="publicize-service-left"> 
  134. <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> 
  135. </div> 
  136.  
  137.  
  138. <div class="publicize-service-right"> 
  139. <?php if ( $this->publicize->is_enabled( $name ) && $connections = $this->publicize->get_connections( $name ) ) : ?> 
  140. <ul> 
  141. <?php 
  142. foreach( $connections as $c ) : 
  143. $id = $this->publicize->get_connection_id( $c ); 
  144. $disconnect_url = $this->publicize->disconnect_url( $name, $id ); 
  145.  
  146. $cmeta = $this->publicize->get_connection_meta( $c ); 
  147. $profile_link = $this->publicize->get_profile_link( $name, $c ); 
  148. $connection_display = $this->publicize->get_display_name( $name, $c ); 
  149.  
  150. $options_nonce = wp_create_nonce( 'options_page_' . $name . '_' . $id ); ?> 
  151.  
  152. <?php if ( $this->publicize->show_options_popup( $name, $c ) ): ?> 
  153. <script type="text/javascript"> 
  154. jQuery(document).ready( function($) { 
  155. showOptionsPage.call( 
  156. this,  
  157. '<?php echo esc_js( $name ); ?>',  
  158. '<?php echo esc_js( $options_nonce ); ?>',  
  159. '<?php echo esc_js( $id ); ?>' 
  160. ); 
  161. } ); 
  162. </script> 
  163. <?php endif; ?> 
  164.  
  165. <li class="publicize-connection" data-connection-id="<?php echo esc_attr( $id ); ?>"> 
  166. <?php esc_html_e( 'Connected as:', 'jetpack' ); ?> 
  167. <?php 
  168. if ( !empty( $profile_link ) ) : ?> 
  169. <a class="publicize-profile-link" href="<?php echo esc_url( $profile_link ); ?>" target="_top"> 
  170. <?php echo esc_html( $connection_display ); ?> 
  171. </a><?php 
  172. else : 
  173. echo esc_html( $connection_display ); 
  174. endif; 
  175. ?> 
  176.  
  177. <?php if ( 0 == $cmeta['connection_data']['user_id'] ) : ?> 
  178. <small>(<?php esc_html_e( 'Shared', 'jetpack' ); ?>)</small> 
  179.  
  180. <?php if ( current_user_can( $this->publicize->GLOBAL_CAP ) ) : ?> 
  181. <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top"></a> 
  182. <?php endif; ?> 
  183.  
  184. <?php else : ?> 
  185. <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top"></a> 
  186. <?php endif; ?> 
  187.  
  188. <br/> 
  189. <div class="pub-connection-test test-in-progress" id="pub-connection-test-<?php echo esc_attr( $id ); ?>" > 
  190. </div> 
  191. </li> 
  192.  
  193. <?php 
  194. endforeach; 
  195. ?> 
  196. </ul> 
  197. <?php endif; ?> 
  198.  
  199.  
  200.  
  201. <?php 
  202. $connections = $this->publicize->get_connections( $name ); 
  203. if ( empty ( $connections ) ) { ?> 
  204. <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> 
  205. <?php } else { ?> 
  206. <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> 
  207. <?php } ?> 
  208. </div> 
  209. </div> 
  210. <?php endforeach; ?> 
  211. </div> 
  212. <script> 
  213. (function($) { 
  214. $('.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' ) ); ?>' ) ) { 
  215. return true; 
  216. } else { 
  217. e.preventDefault(); 
  218. return false; 
  219. }) 
  220. })(jQuery); 
  221. </script> 
  222. </div> 
  223.  
  224. <?php wp_nonce_field( "wpas_posts_{$_blog_id}", "_wpas_posts_{$_blog_id}_nonce" ); ?> 
  225. <input type="hidden" id="wpas_ajax_blog_id" name="wpas_ajax_blog_id" value="<?php echo $_blog_id; ?>" /> 
  226. </form><?php 
  227.  
  228.  
  229. public static function global_checkbox( $service_name, $id ) { 
  230. global $publicize; 
  231. if ( current_user_can( $publicize->GLOBAL_CAP ) ) : ?> 
  232. <p> 
  233. <input id="globalize_<?php echo $service_name; ?>" type="checkbox" name="global" value="<?php echo wp_create_nonce( 'publicize-globalize-' . $id ) ?>" /> 
  234. <label for="globalize_<?php echo $service_name; ?>"><?php _e( 'Make this connection available to all users of this blog?', 'jetpack' ); ?></label> 
  235. </p> 
  236. <?php endif; 
  237.  
  238. function broken_connection( $service_name, $id ) { ?> 
  239. <div id="thickbox-content"> 
  240. <div class='error'> 
  241. <p><?php printf( __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), Publicize::get_service_label( $service_name ) ); ?></p> 
  242. </div> 
  243. </div><?php 
  244.  
  245. public static function options_page_other( $service_name ) { 
  246. // Nonce check 
  247. check_admin_referer( "options_page_{$service_name}_" . $_REQUEST['connection'] ); 
  248. ?> 
  249. <div id="thickbox-content"> 
  250. <?php 
  251. ob_start(); 
  252. Publicize_UI::connected_notice( $service_name ); 
  253. $update_notice = ob_get_clean(); 
  254. if ( ! empty( $update_notice ) ) 
  255. echo $update_notice; 
  256. ?> 
  257.  
  258. <?php Publicize_UI::global_checkbox( $service_name, $_REQUEST['connection'] ); ?> 
  259.  
  260. <p style="text-align: center;"> 
  261. <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'] ) ?>" /> 
  262. </p> <br /> 
  263. </div> 
  264. <?php 
  265.  
  266. /** 
  267. * CSS for styling the publicize message box and counter that displays on the post page. 
  268. * There is also some Javascript for length counting and some basic display effects. 
  269. */ 
  270. function post_page_metabox_assets() { 
  271. global $post; 
  272. $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; 
  273.  
  274. $default_prefix = $this->publicize->default_prefix; 
  275. $default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) ); 
  276.  
  277. $default_message = $this->publicize->default_message; 
  278. $default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) ); 
  279.  
  280. $default_suffix = $this->publicize->default_suffix; 
  281. $default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); ?> 
  282.  
  283. <script type="text/javascript"> 
  284. jQuery( function($) { 
  285. var wpasTitleCounter = $( '#wpas-title-counter' ),  
  286. wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).size(),  
  287. wpasTitle = $('#wpas-title').keyup( function() { 
  288. var length = wpasTitle.val().length; 
  289. wpasTitleCounter.text( length ); 
  290. if ( wpasTwitterCheckbox && length > 140 ) { 
  291. wpasTitleCounter.addClass( 'wpas-twitter-length-limit' ); 
  292. } else { 
  293. wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' ); 
  294. } ),  
  295. authClick = false; 
  296.  
  297. $('#publicize-disconnected-form-show').click( function() { 
  298. $('#publicize-form').slideDown( 'fast' ); 
  299. $(this).hide(); 
  300. } ); 
  301.  
  302. $('#publicize-disconnected-form-hide').click( function() { 
  303. $('#publicize-form').slideUp( 'fast' ); 
  304. $('#publicize-disconnected-form-show').show(); 
  305. } ); 
  306.  
  307. $('#publicize-form-edit').click( function() { 
  308. $('#publicize-form').slideDown( 'fast', function() { 
  309. wpasTitle.focus(); 
  310. if ( !wpasTitle.text() ) { 
  311. var url = $('#shortlink').size() ? $('#shortlink').val() : ''; 
  312.  
  313. var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, '$("#title").val()', 'url' ); printf( $default_suffix, 'url' ); ?>' ); 
  314.  
  315. wpasTitle.append( defaultMessage.replace( /<[^>]+>/g, '') ); 
  316.  
  317. var selBeg = defaultMessage.indexOf( $("#title").val() ); 
  318. if ( selBeg < 0 ) { 
  319. selBeg = 0; 
  320. selEnd = 0; 
  321. } else { 
  322. selEnd = selBeg + $("#title").val().length; 
  323.  
  324. var domObj = wpasTitle.get(0); 
  325. if ( domObj.setSelectionRange ) { 
  326. domObj.setSelectionRange( selBeg, selEnd ); 
  327. } else if ( domObj.createTextRange ) { 
  328. var r = domObj.createTextRange(); 
  329. r.moveStart( 'character', selBeg ); 
  330. r.moveEnd( 'character', selEnd ); 
  331. r.select(); 
  332. wpasTitle.keyup(); 
  333. } ); 
  334. $('#publicize-defaults').hide(); 
  335. $(this).hide(); 
  336. return false; 
  337. } ); 
  338.  
  339. $('#publicize-form-hide').click( function() { 
  340. var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) { 
  341. return $.trim( $(el).parent( 'label' ).text() ); 
  342. } ); 
  343. $('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show(); 
  344. $('#publicize-form-edit').show(); 
  345. return false; 
  346. } ); 
  347.  
  348. $('.authorize-link').click( function() { 
  349. if ( authClick ) { 
  350. return false; 
  351. authClick = true; 
  352. $(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' ); 
  353. $.ajaxSetup( { async: false } ); 
  354.  
  355. if ( window.wp && window.wp.autosave ) { 
  356. window.wp.autosave.server.triggerSave(); 
  357. } else { 
  358. autosave(); 
  359.  
  360. return true; 
  361. } ); 
  362.  
  363. $( '.pub-service' ).click( function() { 
  364. var service = $(this).data( 'service' ),  
  365. fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />'; 
  366. $( '#add-publicize-check' ).append( fakebox ); 
  367. } ); 
  368.  
  369. publicizeConnTestStart = function() { 
  370. $( '#pub-connection-tests' ) 
  371. .removeClass( 'below-h2' ) 
  372. .removeClass( 'error' ) 
  373. .removeClass( 'publicize-token-refresh-message' ) 
  374. .addClass( 'test-in-progress' ) 
  375. .html( '' ); 
  376. $.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete ); 
  377.  
  378. publicizeConnRefreshClick = function( event ) { 
  379. event.preventDefault(); 
  380. var popupURL = event.currentTarget.href; 
  381. var popupTitle = event.currentTarget.title; 
  382. // open a popup window 
  383. // when it is closed, kick off the tests again 
  384. var popupWin = window.open( popupURL, popupTitle, '' ); 
  385. var popupWinTimer= window.setInterval( function() { 
  386. if ( popupWin.closed !== false ) { 
  387. window.clearInterval( popupWinTimer ); 
  388. publicizeConnTestStart(); 
  389. }, 500 ); 
  390.  
  391. publicizeConnTestComplete = function( response ) { 
  392. var testsSelector = $( '#pub-connection-tests' ); 
  393. testsSelector 
  394. .removeClass( 'test-in-progress' ) 
  395. .removeClass( 'below-h2' ) 
  396. .removeClass( 'error' ) 
  397. .removeClass( 'publicize-token-refresh-message' ) 
  398. .html( '' ); 
  399.  
  400. // If any of the tests failed, show some stuff 
  401. var somethingShownAlready = false; 
  402. $.each( response.data, function( index, testResult ) { 
  403. // find the li for this connection 
  404. if ( ! testResult.connectionTestPassed ) { 
  405. if ( ! somethingShownAlready ) { 
  406. testsSelector 
  407. .addClass( 'below-h2' ) 
  408. .addClass( 'error' ) 
  409. .addClass( 'publicize-token-refresh-message' ) 
  410. .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>" ); 
  411. somethingShownAlready = true; 
  412.  
  413. if ( testResult.userCanRefresh ) { 
  414. testsSelector.append( '<p/>' ); 
  415. $( '<a/>', { 
  416. 'class' : 'pub-refresh-button button',  
  417. 'title' : testResult.refreshText,  
  418. 'href' : testResult.refreshURL,  
  419. 'text' : testResult.refreshText,  
  420. 'target' : '_refresh_' + testResult.serviceName 
  421. } ) 
  422. .appendTo( testsSelector.children().last() ) 
  423. .click( publicizeConnRefreshClick ); 
  424. } ); 
  425.  
  426. $( document ).ready( function() { 
  427. // If we have the #pub-connection-tests div present, kick off the connection test 
  428. if ( $( '#pub-connection-tests' ).length ) { 
  429. publicizeConnTestStart(); 
  430. } ); 
  431.  
  432. } ); 
  433. </script> 
  434.  
  435. <style type="text/css"> 
  436. #publicize { 
  437. line-height: 1.5; 
  438. #publicize ul { 
  439. margin: 4px 0 4px 6px; 
  440. #publicize li { 
  441. margin: 0; 
  442. #publicize textarea { 
  443. margin: 4px 0 0; 
  444. width: 100% 
  445. #publicize ul.not-connected { 
  446. list-style: square; 
  447. padding-left: 1em; 
  448. .post-new-php .authorize-link, .post-php .authorize-link { 
  449. line-height: 1.5em; 
  450. .post-new-php .authorize-message, .post-php .authorize-message { 
  451. margin-bottom: 0; 
  452. #poststuff #publicize .updated p { 
  453. margin: .5em 0; 
  454. .wpas-twitter-length-limit { 
  455. color: red; 
  456. </style><?php 
  457.  
  458. /** 
  459. * Controls the metabox that is displayed on the post page 
  460. * Allows the user to customize the message that will be sent out to the social network, as well as pick which 
  461. * networks to publish to. Also displays the character counter and some other information. 
  462. */ 
  463. function post_page_metabox() { 
  464. global $post; 
  465.  
  466. if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) ) 
  467. return; 
  468.  
  469. $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; 
  470. $services = $this->publicize->get_services( 'connected' ); 
  471. $available_services = $this->publicize->get_services( 'all' ); 
  472.  
  473. if ( ! is_array( $available_services ) ) 
  474. $available_services = array(); 
  475.  
  476. if ( ! is_array( $services ) ) 
  477. $services = array(); 
  478.  
  479. $active = array(); ?> 
  480.  
  481. <div id="publicize" class="misc-pub-section misc-pub-section-last"> 
  482. <?php 
  483. _e( 'Publicize:', 'jetpack' ); 
  484.  
  485. if ( 0 < count( $services ) ) : 
  486. ob_start(); 
  487. ?> 
  488.  
  489. <div id="publicize-form" class="hide-if-js"> 
  490. <ul> 
  491.  
  492. <?php 
  493. // We can set an _all flag to indicate that this post is completely done as 
  494. // far as Publicize is concerned. Jetpack uses this approach. All published posts in Jetpack 
  495. // have Publicize disabled. 
  496. $all_done = get_post_meta( $post->ID, $this->publicize->POST_DONE . 'all', true ) || ( $this->in_jetpack && 'publish' == $post->post_status ); 
  497.  
  498. // We don't allow Publicizing to the same external id twice, to prevent spam 
  499. $service_id_done = (array) get_post_meta( $post->ID, $this->publicize->POST_SERVICE_DONE, true ); 
  500.  
  501. foreach ( $services as $name => $connections ) { 
  502. foreach ( $connections as $connection ) { 
  503. $connection_data = ''; 
  504. if ( method_exists( $connection, 'get_meta' ) ) 
  505. $connection_data = $connection->get_meta( 'connection_data' ); 
  506. elseif ( ! empty( $connection['connection_data'] ) ) 
  507. $connection_data = $connection['connection_data']; 
  508.  
  509. /** 
  510. * Filter whether a post should be publicized to a given service. 
  511. * @module publicize 
  512. * @since 2.0.0 
  513. * @param bool true Should the post be publicized to a given service? Default to true. 
  514. * @param int $post->ID Post ID. 
  515. * @param string $name Service name. 
  516. * @param array $connection_data Array of information about all Publicize details for the site. 
  517. */ 
  518. if ( ! $continue = apply_filters( 'wpas_submit_post?', true, $post->ID, $name, $connection_data ) ) { 
  519. continue; 
  520.  
  521. if ( ! empty( $connection->unique_id ) ) { 
  522. $unique_id = $connection->unique_id; 
  523. } else if ( ! empty( $connection['connection_data']['token_id'] ) ) { 
  524. $unique_id = $connection['connection_data']['token_id']; 
  525.  
  526. // Should we be skipping this one? 
  527. $skip = ( 
  528. in_array( $post->post_status, array( 'publish', 'draft', 'future' ) ) 
  529. && 
  530. get_post_meta( $post->ID, $this->publicize->POST_SKIP . $unique_id, true ) 
  531. || 
  532. is_array( $connection ) 
  533. && 
  534. ( isset( $connection['meta']['external_id'] ) && ! empty( $service_id_done[ $name ][ $connection['meta']['external_id'] ] ) ) 
  535. || 
  536. // Jetpack's connection data looks a little different. 
  537. ( isset( $connection['external_id'] ) && ! empty( $service_id_done[ $name ][ $connection['external_id'] ] ) ) 
  538. ); 
  539.  
  540. // Was this connections (OR, old-format service) already Publicized to? 
  541. $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 
  542.  
  543. // If this one has already been publicized to, don't let it happen again 
  544. $disabled = ''; 
  545. if ( $done ) 
  546. $disabled = ' disabled="disabled"'; 
  547.  
  548. // If this is a global connection and this user doesn't have enough permissions to modify 
  549. // those connections, don't let them change it 
  550. $cmeta = $this->publicize->get_connection_meta( $connection ); 
  551. $hidden_checkbox = false; 
  552. if ( !$done && ( 0 == $cmeta['connection_data']['user_id'] && !current_user_can( $this->publicize->GLOBAL_CAP ) ) ) { 
  553. $disabled = ' disabled="disabled"'; 
  554. /** 
  555. * Filters the checkboxes for global connections with non-prilvedged users. 
  556. * @module publicize 
  557. * @since 3.7.0 
  558. * @param bool $checked Indicates if this connection should be enabled. Default true. 
  559. * @param int $post->ID ID of the current post 
  560. * @param string $name Name of the connection (Facebook, Twitter, etc) 
  561. * @param array $connection Array of data about the connection. 
  562. */ 
  563. $hidden_checkbox = apply_filters( 'publicize_checkbox_global_default', true, $post->ID, $name, $connection ); 
  564.  
  565. // Determine the state of the checkbox (on/off) and allow filtering 
  566. $checked = $skip != 1 || $done; 
  567. /** 
  568. * Filter the checkbox state of each Publicize connection appearing in the post editor. 
  569. * @module publicize 
  570. * @since 2.0.1 
  571. * @param bool $checked Should the Publicize checkbox be enabled for a given service. 
  572. * @param int $post->ID Post ID. 
  573. * @param string $name Service name. 
  574. * @param array $connection Array of connection details. 
  575. */ 
  576. $checked = apply_filters( 'publicize_checkbox_default', $checked, $post->ID, $name, $connection ); 
  577.  
  578. // Force the checkbox to be checked if the post was DONE, regardless of what the filter does 
  579. if ( $done ) { 
  580. $checked = true; 
  581.  
  582. // This post has been handled, so disable everything 
  583. if ( $all_done ) { 
  584. $disabled = ' disabled="disabled"'; 
  585.  
  586. $label = sprintf( 
  587. _x( '%1$s: %2$s', 'Service: Account connected as', 'jetpack' ),  
  588. esc_html( $this->publicize->get_service_label( $name ) ),  
  589. esc_html( $this->publicize->get_display_name( $name, $connection ) ) 
  590. ); 
  591. if ( !$skip || $done ) { 
  592. $active[] = $label; 
  593. ?> 
  594. <li> 
  595. <label for="wpas-submit-<?php echo esc_attr( $unique_id ); ?>"> 
  596. <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 
  597. checked( true, $checked ); 
  598. echo $disabled; 
  599. ?> /> 
  600. <?php 
  601. if ( $hidden_checkbox ) { 
  602. // Need to submit a value to force a global connection to post 
  603. echo '<input type="hidden" name="wpas[submit][' . $unique_id . ']" value="1" />'; 
  604. echo esc_html( $label ); 
  605. ?> 
  606. </label> 
  607. </li> 
  608. <?php 
  609.  
  610. if ( $title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true ) ) { 
  611. $title = esc_html( $title ); 
  612. } else { 
  613. $title = ''; 
  614. ?> 
  615.  
  616. </ul> 
  617.  
  618. <label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label> 
  619. <span id="wpas-title-counter" class="alignright hide-if-no-js">0</span> 
  620.  
  621. <textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo $title; ?></textarea> 
  622.  
  623. <a href="#" class="hide-if-no-js" id="publicize-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a> 
  624. <input type="hidden" name="wpas[0]" value="1" /> 
  625.  
  626. </div> 
  627. <div id="pub-connection-tests"></div> 
  628. <?php // #publicize-form 
  629.  
  630. $publicize_form = ob_get_clean(); 
  631. else : 
  632. echo " " . __( 'Not Connected', 'jetpack' ); 
  633. ob_start(); 
  634. ?> 
  635.  
  636. <div id="publicize-form" class="hide-if-js"> 
  637. <div id="add-publicize-check" style="display: none;"></div> 
  638.  
  639. <strong><?php _e( 'Connect to', 'jetpack' ); ?>:</strong> 
  640.  
  641. <ul class="not-connected"> 
  642. <?php foreach ( $available_services as $service_name => $service ) : ?> 
  643. <li> 
  644. <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 ); ?>"> 
  645. <?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?> 
  646. </a> 
  647. </li> 
  648. <?php endforeach; ?> 
  649. </ul> 
  650.  
  651. <?php if ( 0 < count( $services ) ) : ?> 
  652. <a href="#" class="hide-if-no-js" id="publicize-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a> 
  653. <?php else : ?> 
  654. <a href="#" class="hide-if-no-js" id="publicize-disconnected-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a> 
  655. <?php endif; ?> 
  656. </div> <?php // #publicize-form 
  657.  
  658. $publicize_form = ob_get_clean(); 
  659. endif; 
  660. ?> 
  661.  
  662. <span id="publicize-defaults"><strong><?php echo join( '</strong>, <strong>', array_map( 'esc_html', $active ) ); ?></strong></span><br /> 
  663.  
  664. <?php if ( 0 < count( $services ) ) : ?> 
  665. <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 /> 
  666. <?php else : ?> 
  667. <a href="#" id="publicize-disconnected-form-show"><?php _e( 'Show', 'jetpack' ); ?></a><br /> 
  668. <?php endif; ?> 
  669.  
  670. <?php 
  671. /** 
  672. * Filter the Publicize details form. 
  673. * @module publicize 
  674. * @since 2.0.0 
  675. * @param string $publicize_form Publicize Details form appearing above Publish button in the editor. 
  676. */ 
  677. echo apply_filters( 'publicize_form', $publicize_form ); 
  678. ?> 
  679.  
  680. </div> <?php // #publicize 
  681.