Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | protected $publicize_settings_url = ''; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Hooks into WordPress to display the various pieces of UI and load our assets |
||
| 17 | */ |
||
| 18 | function __construct() { |
||
| 19 | global $publicize; |
||
| 20 | |||
| 21 | $this->publicize = $publicize = new Publicize; |
||
| 22 | |||
| 23 | add_action( 'init', array( $this, 'init' ) ); |
||
| 24 | } |
||
| 25 | |||
| 26 | function init() { |
||
| 27 | $this->publicize_settings_url = apply_filters_deprecated( |
||
| 28 | 'jetpack_override_publicize_settings_url', |
||
| 29 | array( admin_url( 'options-general.php?page=sharing' ) ), |
||
| 30 | '6.7', |
||
| 31 | false, |
||
| 32 | __( 'This filter will be removed in a future version of Jetpack', 'jetpack' ) |
||
| 33 | ); |
||
| 34 | |||
| 35 | // Show only to users with the capability required to manage their Publicize connections. |
||
| 36 | /** |
||
| 37 | * 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. |
||
| 38 | * |
||
| 39 | * @module publicize |
||
| 40 | * |
||
| 41 | * @since 4.1.0 |
||
| 42 | * |
||
| 43 | * @param string $capability User capability needed to use publicize |
||
| 44 | */ |
||
| 45 | $capability = apply_filters( 'jetpack_publicize_capability', 'publish_posts' ); |
||
| 46 | if ( ! current_user_can( $capability ) ) { |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | // assets (css, js) |
||
| 51 | if ( $this->in_jetpack ) { |
||
|
0 ignored issues
–
show
|
|||
| 52 | add_action( 'load-settings_page_sharing', array( $this, 'load_assets' ) ); |
||
| 53 | } |
||
| 54 | add_action( 'admin_head-post.php', array( $this, 'post_page_metabox_assets' ) ); |
||
| 55 | add_action( 'admin_head-post-new.php', array( $this, 'post_page_metabox_assets' ) ); |
||
| 56 | |||
| 57 | // management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen) |
||
| 58 | add_action( 'pre_admin_screen_sharing', array( $this, 'admin_page' ) ); |
||
| 59 | add_action( 'post_submitbox_misc_actions', array( $this, 'post_page_metabox' ) ); |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still |
||
| 64 | */ |
||
| 65 | function sharing_menu() { |
||
| 66 | add_submenu_page( |
||
| 67 | 'options-general.php', |
||
| 68 | __( 'Sharing Settings', 'jetpack' ), |
||
| 69 | __( 'Sharing', 'jetpack' ), |
||
| 70 | 'publish_posts', |
||
| 71 | 'sharing', |
||
| 72 | array( $this, 'wrapper_admin_page' ) |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | |||
| 76 | function wrapper_admin_page() { |
||
| 77 | Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ), array( 'is-wide' => true ) ); |
||
| 78 | } |
||
| 79 | /** |
||
| 80 | * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. |
||
| 81 | */ |
||
| 82 | function management_page() { ?> |
||
| 83 | <div class="wrap"> |
||
| 84 | <div class="icon32" id="icon-options-general"><br /></div> |
||
| 85 | <h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1> |
||
| 86 | |||
| 87 | <?php |
||
| 88 | /** This action is documented in modules/sharedaddy/sharing.php */ |
||
| 89 | do_action( 'pre_admin_screen_sharing' ); |
||
| 90 | ?> |
||
| 91 | |||
| 92 | </div> <?php |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * styling for the sharing screen and popups |
||
| 97 | * JS for the options and switching |
||
| 98 | */ |
||
| 99 | function load_assets() { |
||
| 100 | wp_enqueue_script( |
||
| 101 | 'publicize', |
||
| 102 | Jetpack::get_file_url_for_environment( |
||
| 103 | '_inc/build/publicize/assets/publicize.min.js', |
||
| 104 | 'modules/publicize/assets/publicize.js' |
||
| 105 | ), |
||
| 106 | array( 'jquery', 'thickbox' ), |
||
| 107 | '20121019' |
||
| 108 | ); |
||
| 109 | if ( is_rtl() ) { |
||
| 110 | wp_enqueue_style( 'publicize', plugins_url( 'assets/rtl/publicize-rtl.css', __FILE__ ), array(), '20180301' ); |
||
| 111 | } else { |
||
| 112 | wp_enqueue_style( 'publicize', plugins_url( 'assets/publicize.css', __FILE__ ), array(), '20180301' ); |
||
| 113 | } |
||
| 114 | |||
| 115 | Jetpack_Admin_Page::load_wrapper_styles(); |
||
| 116 | wp_enqueue_style( 'social-logos' ); |
||
| 117 | |||
| 118 | add_thickbox(); |
||
| 119 | } |
||
| 120 | |||
| 121 | public static function connected_notice( $service_name ) { ?> |
||
| 122 | <div class='updated'> |
||
| 123 | <p><?php |
||
| 124 | |||
| 125 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 126 | $platform = 'WordPress.com'; |
||
| 127 | } else { |
||
| 128 | $platform = 'Jetpack'; |
||
| 129 | } |
||
| 130 | |||
| 131 | printf( |
||
| 132 | /* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Site type (WordPress.com or Jetpack) */ |
||
| 133 | __( 'You have successfully connected your %1$s account with %2$s.', 'jetpack' ), |
||
| 134 | Publicize::get_service_label( $service_name ), |
||
| 135 | $platform |
||
| 136 | ); ?></p> |
||
| 137 | </div><?php |
||
| 138 | } |
||
| 139 | |||
| 140 | public static function denied_notice() { ?> |
||
| 141 | <div class='updated'> |
||
| 142 | <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> |
||
| 143 | </div><?php |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Lists the current user's publicized accounts for the blog |
||
| 148 | * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring |
||
| 149 | */ |
||
| 150 | function admin_page() { |
||
| 151 | $override_publicize_settings_page = apply_filters_deprecated( |
||
| 152 | 'jetpack_override_publicize_settings_page', |
||
| 153 | array( false ), |
||
| 154 | '6.7', |
||
| 155 | false, |
||
| 156 | __( 'This filter will be removed in a future version of Jetpack', 'jetpack' ) |
||
| 157 | ); |
||
| 158 | |||
| 159 | if ( $override_publicize_settings_page ) { |
||
| 160 | echo $override_publicize_settings_page; |
||
| 161 | return; |
||
| 162 | } |
||
| 163 | |||
| 164 | $_blog_id = get_current_blog_id(); |
||
| 165 | ?> |
||
| 166 | |||
| 167 | <form action="" id="publicize-form"> |
||
| 168 | <h2 id="publicize"><?php _e( 'Publicize', 'jetpack' ) ?></h2> |
||
| 169 | |||
| 170 | <?php |
||
| 171 | if ( ! empty( $_GET['action'] ) && 'deny' == $_GET['action'] ) { |
||
| 172 | $this->denied_notice(); |
||
| 173 | } |
||
| 174 | ?> |
||
| 175 | |||
| 176 | <p> |
||
| 177 | <?php esc_html_e( 'Connect your blog to popular social networking sites and automatically share new posts with your friends.', 'jetpack' ) ?> |
||
| 178 | <?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' ); ?> |
||
| 179 | </p> |
||
| 180 | |||
| 181 | <?php |
||
| 182 | if ( $this->in_jetpack ) { |
||
| 183 | $doc_link = "http://jetpack.com/support/publicize/"; |
||
| 184 | } else { |
||
| 185 | $doc_link = "http://en.support.wordpress.com/publicize/"; |
||
| 186 | } |
||
| 187 | ?> |
||
| 188 | |||
| 189 | <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> |
||
| 190 | |||
| 191 | <div id="publicize-services-block"> |
||
| 192 | <?php |
||
| 193 | $services = $this->publicize->get_services( 'all' ); |
||
| 194 | $total_num_of_services = count ( $services ); |
||
| 195 | $service_num = 0;?> |
||
| 196 | |||
| 197 | <div class='left'> |
||
| 198 | |||
| 199 | <?php |
||
| 200 | foreach ( $services as $service_name => $service ) : |
||
| 201 | $connect_url = $this->publicize->connect_url( $service_name ); |
||
| 202 | if ( $service_num == ( round ( ( $total_num_of_services / 2 ), 0 ) ) ) |
||
| 203 | echo "</div><div class='right'>"; |
||
| 204 | $service_num++; |
||
| 205 | ?> |
||
| 206 | <div class="publicize-service-entry" <?php if ( $service_num > 0 ): ?>class="connected"<?php endif; ?> > |
||
| 207 | <div id="<?php echo esc_attr( $service_name ); ?>" class="publicize-service-left"> |
||
| 208 | <a href="<?php echo esc_url( $connect_url ); ?>" id="service-link-<?php echo esc_attr( $service_name ); ?>" target="_top"><?php echo $this->publicize->get_service_label( $service_name ); ?></a> |
||
| 209 | </div> |
||
| 210 | |||
| 211 | |||
| 212 | <div class="publicize-service-right"> |
||
| 213 | <?php if ( $this->publicize->is_enabled( $service_name ) && $connections = $this->publicize->get_connections( $service_name ) ) : ?> |
||
| 214 | <ul> |
||
| 215 | <?php |
||
| 216 | foreach( $connections as $c ) : |
||
| 217 | $id = $this->publicize->get_connection_id( $c ); |
||
| 218 | $disconnect_url = $this->publicize->disconnect_url( $service_name, $id ); |
||
| 219 | |||
| 220 | $cmeta = $this->publicize->get_connection_meta( $c ); |
||
| 221 | $profile_link = $this->publicize->get_profile_link( $service_name, $c ); |
||
| 222 | $connection_display = $this->publicize->get_display_name( $service_name, $c ); |
||
| 223 | |||
| 224 | $options_nonce = wp_create_nonce( 'options_page_' . $service_name . '_' . $id ); ?> |
||
| 225 | |||
| 226 | <?php if ( $this->publicize->show_options_popup( $service_name, $c ) ): ?> |
||
| 227 | <script type="text/javascript"> |
||
| 228 | jQuery(document).ready( function($) { |
||
| 229 | showOptionsPage.call( |
||
| 230 | this, |
||
| 231 | '<?php echo esc_js( $service_name ); ?>', |
||
| 232 | '<?php echo esc_js( $options_nonce ); ?>', |
||
| 233 | '<?php echo esc_js( $id ); ?>' |
||
| 234 | ); |
||
| 235 | } ); |
||
| 236 | </script> |
||
| 237 | <?php endif; ?> |
||
| 238 | |||
| 239 | <li class="publicize-connection" data-connection-id="<?php echo esc_attr( $id ); ?>"> |
||
| 240 | <?php esc_html_e( 'Connected as:', 'jetpack' ); ?> |
||
| 241 | <?php |
||
| 242 | if ( !empty( $profile_link ) ) : ?> |
||
| 243 | <a class="publicize-profile-link" href="<?php echo esc_url( $profile_link ); ?>" target="_top"> |
||
| 244 | <?php echo esc_html( $connection_display ); ?> |
||
| 245 | </a><?php |
||
| 246 | else : |
||
| 247 | echo esc_html( $connection_display ); |
||
| 248 | endif; |
||
| 249 | ?> |
||
| 250 | |||
| 251 | <?php if ( 0 == $cmeta['connection_data']['user_id'] ) : ?> |
||
| 252 | <small>(<?php esc_html_e( 'Shared', 'jetpack' ); ?>)</small> |
||
| 253 | |||
| 254 | <?php if ( current_user_can( $this->publicize->GLOBAL_CAP ) ) : ?> |
||
| 255 | <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top">×</a> |
||
| 256 | <?php endif; ?> |
||
| 257 | |||
| 258 | <?php else : ?> |
||
| 259 | <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top">×</a> |
||
| 260 | <?php endif; ?> |
||
| 261 | |||
| 262 | <br/> |
||
| 263 | <div class="pub-connection-test test-in-progress" id="pub-connection-test-<?php echo esc_attr( $id ); ?>" > |
||
| 264 | </div> |
||
| 265 | </li> |
||
| 266 | |||
| 267 | <?php |
||
| 268 | endforeach; |
||
| 269 | ?> |
||
| 270 | </ul> |
||
| 271 | <?php endif; ?> |
||
| 272 | |||
| 273 | |||
| 274 | |||
| 275 | <?php |
||
| 276 | $connections = $this->publicize->get_connections( $service_name ); |
||
| 277 | if ( empty ( $connections ) ) { ?> |
||
| 278 | <a id="<?php echo esc_attr( $service_name ); ?>" class="publicize-add-connection button" href="<?php echo esc_url( $connect_url ); ?>" target="_top"><?php echo esc_html( __( 'Connect', 'jetpack' ) ); ?></a> |
||
| 279 | <?php } else { ?> |
||
| 280 | <a id="<?php echo esc_attr( $service_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> |
||
| 281 | <?php } ?> |
||
| 282 | </div> |
||
| 283 | </div> |
||
| 284 | <?php endforeach; ?> |
||
| 285 | </div> |
||
| 286 | <script> |
||
| 287 | (function($){ |
||
| 288 | $('.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' ) ); ?>' ) ) { |
||
| 289 | return true; |
||
| 290 | } else { |
||
| 291 | e.preventDefault(); |
||
| 292 | return false; |
||
| 293 | } |
||
| 294 | }) |
||
| 295 | })(jQuery); |
||
| 296 | </script> |
||
| 297 | </div> |
||
| 298 | |||
| 299 | <?php wp_nonce_field( "wpas_posts_{$_blog_id}", "_wpas_posts_{$_blog_id}_nonce" ); ?> |
||
| 300 | <input type="hidden" id="wpas_ajax_blog_id" name="wpas_ajax_blog_id" value="<?php echo $_blog_id; ?>" /> |
||
| 301 | </form><?php |
||
| 302 | |||
| 303 | } |
||
| 304 | |||
| 305 | public static function global_checkbox( $service_name, $id ) { |
||
| 306 | global $publicize; |
||
| 307 | if ( current_user_can( $publicize->GLOBAL_CAP ) ) : ?> |
||
| 308 | <p> |
||
| 309 | <input id="globalize_<?php echo $service_name; ?>" type="checkbox" name="global" value="<?php echo wp_create_nonce( 'publicize-globalize-' . $id ) ?>" /> |
||
| 310 | <label for="globalize_<?php echo $service_name; ?>"><?php _e( 'Make this connection available to all users of this blog?', 'jetpack' ); ?></label> |
||
| 311 | </p> |
||
| 312 | <?php endif; |
||
| 313 | } |
||
| 314 | |||
| 315 | function broken_connection( $service_name, $id ) { ?> |
||
| 316 | <div id="thickbox-content"> |
||
| 317 | <div class='error'> |
||
| 318 | <p><?php printf( |
||
| 319 | /* translators: %s: Service Name (Facebook, Twitter, ...) */ |
||
| 320 | __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), |
||
| 321 | Publicize::get_service_label( $service_name ) |
||
| 322 | ); ?></p> |
||
| 323 | </div> |
||
| 324 | </div><?php |
||
| 325 | } |
||
| 326 | |||
| 327 | public static function options_page_other( $service_name ) { |
||
| 328 | // Nonce check |
||
| 329 | check_admin_referer( "options_page_{$service_name}_" . $_REQUEST['connection'] ); |
||
| 330 | ?> |
||
| 331 | <div id="thickbox-content"> |
||
| 332 | <?php |
||
| 333 | ob_start(); |
||
| 334 | Publicize_UI::connected_notice( $service_name ); |
||
| 335 | $update_notice = ob_get_clean(); |
||
| 336 | if ( ! empty( $update_notice ) ) |
||
| 337 | echo $update_notice; |
||
| 338 | ?> |
||
| 339 | |||
| 340 | <?php Publicize_UI::global_checkbox( $service_name, $_REQUEST['connection'] ); ?> |
||
| 341 | |||
| 342 | <p style="text-align: center;"> |
||
| 343 | <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'] ) ?>" /> |
||
| 344 | </p> <br /> |
||
| 345 | </div> |
||
| 346 | <?php |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * CSS for styling the publicize message box and counter that displays on the post page. |
||
| 351 | * There is also some JavaScript for length counting and some basic display effects. |
||
| 352 | */ |
||
| 353 | function post_page_metabox_assets() { |
||
| 354 | global $post; |
||
| 355 | $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; |
||
|
0 ignored issues
–
show
$user_id is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 356 | |||
| 357 | $default_prefix = $this->publicize->default_prefix; |
||
| 358 | $default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) ); |
||
| 359 | |||
| 360 | $default_message = $this->publicize->default_message; |
||
| 361 | $default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) ); |
||
| 362 | |||
| 363 | $default_suffix = $this->publicize->default_suffix; |
||
| 364 | $default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); |
||
| 365 | |||
| 366 | $max_length = defined( 'JETPACK_PUBLICIZE_TWITTER_LENGTH' ) ? JETPACK_PUBLICIZE_TWITTER_LENGTH : 280; |
||
| 367 | $max_length = $max_length - 24; // t.co link, space |
||
| 368 | |||
| 369 | ?> |
||
| 370 | |||
| 371 | <script type="text/javascript"> |
||
| 372 | jQuery( function($) { |
||
| 373 | var wpasTitleCounter = $( '#wpas-title-counter' ), |
||
| 374 | wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).length, |
||
| 375 | postTitle = $( '#title' ), |
||
| 376 | wpasTitle = $( '#wpas-title' ).keyup( function() { |
||
| 377 | var postTitleVal, |
||
| 378 | length = wpasTitle.val().length; |
||
| 379 | |||
| 380 | if ( ! length ) { |
||
| 381 | length = wpasTitle.attr( 'placeholder' ).length; |
||
| 382 | } |
||
| 383 | |||
| 384 | wpasTitleCounter.text( length ).trigger( 'change' ); |
||
| 385 | } ), |
||
| 386 | authClick = false; |
||
| 387 | |||
| 388 | wpasTitleCounter.on( 'change', function( e ) { |
||
| 389 | if ( wpasTwitterCheckbox && parseInt( $( e.currentTarget ).text(), 10 ) > <?php echo (int) $max_length; ?> ) { |
||
| 390 | wpasTitleCounter.addClass( 'wpas-twitter-length-limit' ); |
||
| 391 | } else { |
||
| 392 | wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' ); |
||
| 393 | } |
||
| 394 | } ); |
||
| 395 | |||
| 396 | // Keep the postTitle and the placeholder in sync |
||
| 397 | postTitle.on( 'keyup', function( e ) { |
||
| 398 | var url = $( '#sample-permalink' ).text(); |
||
| 399 | var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, 'e.currentTarget.value', 'url' ); printf( $default_suffix, 'url' ); ?>' ) |
||
| 400 | .replace( /<[^>]+>/g,''); |
||
| 401 | |||
| 402 | wpasTitle.attr( 'placeholder', defaultMessage ); |
||
| 403 | wpasTitle.trigger( 'keyup' ); |
||
| 404 | } ); |
||
| 405 | |||
| 406 | // set the initial placeholder |
||
| 407 | postTitle.trigger( 'keyup' ); |
||
| 408 | |||
| 409 | // If a custom message has been provided, open the UI so the author remembers |
||
| 410 | if ( wpasTitle.val() && ! wpasTitle.prop( 'disabled' ) && wpasTitle.attr( 'placeholder' ) !== wpasTitle.val() ) { |
||
| 411 | $( '#publicize-form' ).show(); |
||
| 412 | $( '#publicize-defaults' ).hide(); |
||
| 413 | $( '#publicize-form-edit' ).hide(); |
||
| 414 | } |
||
| 415 | |||
| 416 | $('#publicize-disconnected-form-show').click( function() { |
||
| 417 | $('#publicize-form').slideDown( 'fast' ); |
||
| 418 | $(this).hide(); |
||
| 419 | } ); |
||
| 420 | |||
| 421 | $('#publicize-disconnected-form-hide').click( function() { |
||
| 422 | $('#publicize-form').slideUp( 'fast' ); |
||
| 423 | $('#publicize-disconnected-form-show').show(); |
||
| 424 | } ); |
||
| 425 | |||
| 426 | $('#publicize-form-edit').click( function() { |
||
| 427 | $('#publicize-form').slideDown( 'fast', function() { |
||
| 428 | var selBeg = 0, selEnd = 0; |
||
| 429 | wpasTitle.focus(); |
||
| 430 | |||
| 431 | if ( ! wpasTitle.text() ) { |
||
| 432 | wpasTitle.text( wpasTitle.attr( 'placeholder' ) ); |
||
| 433 | |||
| 434 | selBeg = wpasTitle.text().indexOf( postTitle.val() ); |
||
| 435 | if ( selBeg < 0 ) { |
||
| 436 | selBeg = 0; |
||
| 437 | } else { |
||
| 438 | selEnd = selBeg + postTitle.val().length; |
||
| 439 | } |
||
| 440 | |||
| 441 | var domObj = wpasTitle.get(0); |
||
| 442 | if ( domObj.setSelectionRange ) { |
||
| 443 | domObj.setSelectionRange( selBeg, selEnd ); |
||
| 444 | } else if ( domObj.createTextRange ) { |
||
| 445 | var r = domObj.createTextRange(); |
||
| 446 | r.moveStart( 'character', selBeg ); |
||
| 447 | r.moveEnd( 'character', selEnd ); |
||
| 448 | r.select(); |
||
| 449 | } |
||
| 450 | } |
||
| 451 | } ); |
||
| 452 | |||
| 453 | $('#publicize-defaults').hide(); |
||
| 454 | $(this).hide(); |
||
| 455 | return false; |
||
| 456 | } ); |
||
| 457 | |||
| 458 | $('#publicize-form-hide').click( function() { |
||
| 459 | var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) { |
||
| 460 | return $.trim( $(el).parent( 'label' ).text() ); |
||
| 461 | } ); |
||
| 462 | $('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show(); |
||
| 463 | $('#publicize-form-edit').show(); |
||
| 464 | return false; |
||
| 465 | } ); |
||
| 466 | |||
| 467 | $('.authorize-link').click( function() { |
||
| 468 | if ( authClick ) { |
||
| 469 | return false; |
||
| 470 | } |
||
| 471 | authClick = true; |
||
| 472 | $(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' ); |
||
| 473 | $.ajaxSetup( { async: false } ); |
||
| 474 | |||
| 475 | if ( window.wp && window.wp.autosave ) { |
||
| 476 | window.wp.autosave.server.triggerSave(); |
||
| 477 | } else { |
||
| 478 | autosave(); |
||
| 479 | } |
||
| 480 | |||
| 481 | return true; |
||
| 482 | } ); |
||
| 483 | |||
| 484 | $( '.pub-service' ).click( function() { |
||
| 485 | var service = $(this).data( 'service' ), |
||
| 486 | fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />'; |
||
| 487 | $( '#add-publicize-check' ).append( fakebox ); |
||
| 488 | } ); |
||
| 489 | |||
| 490 | publicizeConnTestStart = function() { |
||
| 491 | $( '#pub-connection-tests' ) |
||
| 492 | .removeClass( 'below-h2' ) |
||
| 493 | .removeClass( 'error' ) |
||
| 494 | .removeClass( 'publicize-token-refresh-message' ) |
||
| 495 | .addClass( 'test-in-progress' ) |
||
| 496 | .html( '' ); |
||
| 497 | $.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete ); |
||
| 498 | } |
||
| 499 | |||
| 500 | publicizeConnRefreshClick = function( event ) { |
||
| 501 | event.preventDefault(); |
||
| 502 | var popupURL = event.currentTarget.href; |
||
| 503 | var popupTitle = event.currentTarget.title; |
||
| 504 | // open a popup window |
||
| 505 | // when it is closed, kick off the tests again |
||
| 506 | var popupWin = window.open( popupURL, popupTitle, '' ); |
||
| 507 | var popupWinTimer= window.setInterval( function() { |
||
| 508 | if ( popupWin.closed !== false ) { |
||
| 509 | window.clearInterval( popupWinTimer ); |
||
| 510 | publicizeConnTestStart(); |
||
| 511 | } |
||
| 512 | }, 500 ); |
||
| 513 | } |
||
| 514 | |||
| 515 | publicizeConnTestComplete = function( response ) { |
||
| 516 | var testsSelector = $( '#pub-connection-tests' ); |
||
| 517 | testsSelector |
||
| 518 | .removeClass( 'test-in-progress' ) |
||
| 519 | .removeClass( 'below-h2' ) |
||
| 520 | .removeClass( 'error' ) |
||
| 521 | .removeClass( 'publicize-token-refresh-message' ) |
||
| 522 | .html( '' ); |
||
| 523 | |||
| 524 | // If any of the tests failed, show some stuff |
||
| 525 | var somethingShownAlready = false; |
||
| 526 | var facebookNotice = false; |
||
| 527 | $.each( response.data, function( index, testResult ) { |
||
| 528 | // find the li for this connection |
||
| 529 | if ( ! testResult.connectionTestPassed && testResult.userCanRefresh ) { |
||
| 530 | if ( ! somethingShownAlready ) { |
||
| 531 | testsSelector |
||
| 532 | .addClass( 'below-h2' ) |
||
| 533 | .addClass( 'error' ) |
||
| 534 | .addClass( 'publicize-token-refresh-message' ) |
||
| 535 | .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>" ); |
||
| 536 | somethingShownAlready = true; |
||
| 537 | } |
||
| 538 | |||
| 539 | if ( testResult.userCanRefresh ) { |
||
| 540 | testsSelector.append( '<p/>' ); |
||
| 541 | $( '<a/>', { |
||
| 542 | 'class' : 'pub-refresh-button button', |
||
| 543 | 'title' : testResult.refreshText, |
||
| 544 | 'href' : testResult.refreshURL, |
||
| 545 | 'text' : testResult.refreshText, |
||
| 546 | 'target' : '_refresh_' + testResult.serviceName |
||
| 547 | } ) |
||
| 548 | .appendTo( testsSelector.children().last() ) |
||
| 549 | .click( publicizeConnRefreshClick ); |
||
| 550 | } |
||
| 551 | } |
||
| 552 | |||
| 553 | if( ! testResult.connectionTestPassed && ! testResult.userCanRefresh ) { |
||
| 554 | $( '#wpas-submit-' + testResult.unique_id ).prop( "checked", false ).prop( "disabled", true ); |
||
| 555 | if ( ! facebookNotice ) { |
||
| 556 | var message = '<p>' |
||
| 557 | + testResult.connectionTestMessage |
||
| 558 | + '</p><p>' |
||
| 559 | + ' <a class="button" href="<?php echo esc_url( $this->publicize_settings_url ); ?>" rel="noopener noreferrer" target="_blank">' |
||
| 560 | + '<?php echo esc_html( __( 'Update Your Sharing Settings' ,'jetpack' ) ); ?>' |
||
| 561 | + '</a>' |
||
| 562 | + '<p>'; |
||
| 563 | |||
| 564 | testsSelector |
||
| 565 | .addClass( 'below-h2' ) |
||
| 566 | .addClass( 'error' ) |
||
| 567 | .addClass( 'publicize-token-refresh-message' ) |
||
| 568 | .append( message ); |
||
| 569 | facebookNotice = true; |
||
| 570 | } |
||
| 571 | } |
||
| 572 | } ); |
||
| 573 | } |
||
| 574 | |||
| 575 | $( document ).ready( function() { |
||
| 576 | // If we have the #pub-connection-tests div present, kick off the connection test |
||
| 577 | if ( $( '#pub-connection-tests' ).length ) { |
||
| 578 | publicizeConnTestStart(); |
||
| 579 | } |
||
| 580 | } ); |
||
| 581 | |||
| 582 | } ); |
||
| 583 | </script> |
||
| 584 | |||
| 585 | <style type="text/css"> |
||
| 586 | #publicize { |
||
| 587 | line-height: 1.5; |
||
| 588 | } |
||
| 589 | #publicize ul { |
||
| 590 | margin: 4px 0 4px 6px; |
||
| 591 | } |
||
| 592 | #publicize li { |
||
| 593 | margin: 0; |
||
| 594 | } |
||
| 595 | #publicize textarea { |
||
| 596 | margin: 4px 0 0; |
||
| 597 | width: 100% |
||
| 598 | } |
||
| 599 | #publicize ul.not-connected { |
||
| 600 | list-style: square; |
||
| 601 | padding-left: 1em; |
||
| 602 | } |
||
| 603 | #publicize-title:before { |
||
| 604 | content: "\f237"; |
||
| 605 | font: normal 20px/1 dashicons; |
||
| 606 | speak: none; |
||
| 607 | margin-left: -1px; |
||
| 608 | padding-right: 3px; |
||
| 609 | vertical-align: top; |
||
| 610 | -webkit-font-smoothing: antialiased; |
||
| 611 | color: #82878c; |
||
| 612 | } |
||
| 613 | .post-new-php .authorize-link, .post-php .authorize-link { |
||
| 614 | line-height: 1.5em; |
||
| 615 | } |
||
| 616 | .post-new-php .authorize-message, .post-php .authorize-message { |
||
| 617 | margin-bottom: 0; |
||
| 618 | } |
||
| 619 | #poststuff #publicize .updated p { |
||
| 620 | margin: .5em 0; |
||
| 621 | } |
||
| 622 | .wpas-twitter-length-limit { |
||
| 623 | color: red; |
||
| 624 | } |
||
| 625 | </style><?php |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Controls the metabox that is displayed on the post page |
||
| 630 | * Allows the user to customize the message that will be sent out to the social network, as well as pick which |
||
| 631 | * networks to publish to. Also displays the character counter and some other information. |
||
| 632 | */ |
||
| 633 | function post_page_metabox() { |
||
| 634 | global $post; |
||
| 635 | |||
| 636 | if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) ) |
||
| 637 | return; |
||
| 638 | |||
| 639 | $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; |
||
|
0 ignored issues
–
show
$user_id is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 640 | $services = $this->publicize->get_services( 'connected' ); |
||
| 641 | $available_services = $this->publicize->get_services( 'all' ); |
||
| 642 | |||
| 643 | if ( ! is_array( $available_services ) ) |
||
| 644 | $available_services = array(); |
||
| 645 | |||
| 646 | if ( ! is_array( $services ) ) |
||
| 647 | $services = array(); |
||
| 648 | ?> |
||
| 649 | <div id="publicize" class="misc-pub-section misc-pub-section-last"> |
||
| 650 | <span id="publicize-title"> |
||
| 651 | <?php esc_html_e( 'Publicize:', 'jetpack' ); ?> |
||
| 652 | <?php if ( 0 < count( $services ) ) : ?> |
||
| 653 | <?php list( $publicize_form, $active ) = $this->get_metabox_form_connected( $services ); ?> |
||
| 654 | <span id="publicize-defaults"> |
||
| 655 | <?php foreach ( $active as $item ) : ?> |
||
| 656 | <strong><?php echo esc_html( $item ); ?></strong> |
||
| 657 | <?php endforeach; ?> |
||
| 658 | </span> |
||
| 659 | <a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a> <a href="<?php echo esc_url( $this->publicize_settings_url ); ?>" rel="noopener noreferrer" target="_blank"><?php _e( 'Settings', 'jetpack' ); ?></a><br /> |
||
| 660 | <?php else : ?> |
||
| 661 | <?php $publicize_form = $this->get_metabox_form_disconnected( $available_services ); ?> |
||
| 662 | <strong><?php echo __( 'Not Connected', 'jetpack' ); ?></strong> |
||
| 663 | <a href="#" id="publicize-disconnected-form-show"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a><br /> |
||
| 664 | <?php endif; ?> |
||
| 665 | </span> |
||
| 666 | <?php |
||
| 667 | /** |
||
| 668 | * Filter the Publicize details form. |
||
| 669 | * |
||
| 670 | * @module publicize |
||
| 671 | * |
||
| 672 | * @since 2.0.0 |
||
| 673 | * |
||
| 674 | * @param string $publicize_form Publicize Details form appearing above Publish button in the editor. |
||
| 675 | */ |
||
| 676 | echo apply_filters( 'publicize_form', $publicize_form ); |
||
| 677 | ?> |
||
| 678 | </div> <?php // #publicize |
||
| 679 | } |
||
| 680 | |||
| 681 | private function get_metabox_form_connected( $services ) { |
||
| 682 | global $post; |
||
| 683 | $active = array(); |
||
| 684 | ob_start(); |
||
| 685 | ?> <div id="publicize-form" class="hide-if-js"> |
||
| 686 | <ul> |
||
| 687 | |||
| 688 | <?php |
||
| 689 | // We can set an _all flag to indicate that this post is completely done as |
||
| 690 | // far as Publicize is concerned. Jetpack uses this approach. All published posts in Jetpack |
||
| 691 | // have Publicize disabled. |
||
| 692 | $all_done = get_post_meta( $post->ID, $this->publicize->POST_DONE . 'all', true ) || ( $this->in_jetpack && 'publish' == $post->post_status ); |
||
| 693 | |||
| 694 | // We don't allow Publicizing to the same external id twice, to prevent spam |
||
| 695 | $service_id_done = (array) get_post_meta( $post->ID, $this->publicize->POST_SERVICE_DONE, true ); |
||
| 696 | |||
| 697 | // In addition to looking at $all_done, we also look through the currently active services |
||
| 698 | // To see if they are all done. |
||
| 699 | $all_services_done = true; |
||
| 700 | foreach ( $services as $service_name => $connections ) { |
||
| 701 | foreach ( $connections as $connection ) { |
||
| 702 | $connection_meta = $this->publicize->get_connection_meta( $connection ); |
||
| 703 | $connection_data = $connection_meta['connection_data']; |
||
| 704 | |||
| 705 | $unique_id = $this->publicize->get_connection_unique_id( $connection ); |
||
| 706 | |||
| 707 | // Was this connection (OR, old-format service) already Publicized to? |
||
| 708 | $done = ( 1 == get_post_meta( $post->ID, $this->publicize->POST_DONE . $unique_id, true ) || 1 == get_post_meta( $post->ID, $this->publicize->POST_DONE . $service_name, true ) ); // New and old style flags |
||
| 709 | $all_services_done = $all_services_done && $done; |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Filter whether a post should be publicized to a given service. |
||
| 713 | * |
||
| 714 | * @module publicize |
||
| 715 | * |
||
| 716 | * @since 2.0.0 |
||
| 717 | * |
||
| 718 | * @param bool true Should the post be publicized to a given service? Default to true. |
||
| 719 | * @param int $post->ID Post ID. |
||
| 720 | * @param string $service_name Service name. |
||
| 721 | * @param array $connection_data Array of information about all Publicize details for the site. |
||
| 722 | */ |
||
| 723 | if ( ! $continue = apply_filters( 'wpas_submit_post?', true, $post->ID, $service_name, $connection_data ) ) { |
||
| 724 | continue; |
||
| 725 | } |
||
| 726 | |||
| 727 | // Should we be skipping this one? |
||
| 728 | $skip = ( |
||
| 729 | ( |
||
| 730 | in_array( $post->post_status, array( 'publish', 'draft', 'future' ) ) |
||
| 731 | && |
||
| 732 | ( |
||
| 733 | // New flags |
||
| 734 | get_post_meta( $post->ID, $this->publicize->POST_SKIP . $unique_id, true ) |
||
| 735 | || |
||
| 736 | // Old flags |
||
| 737 | get_post_meta( $post->ID, $this->publicize->POST_SKIP . $service_name ) |
||
| 738 | ) |
||
| 739 | ) |
||
| 740 | || |
||
| 741 | ( |
||
| 742 | is_array( $connection ) |
||
| 743 | && |
||
| 744 | isset( $connection_meta['external_id'] ) && ! empty( $service_id_done[ $service_name ][ $connection_meta['external_id'] ] ) |
||
| 745 | ) |
||
| 746 | ); |
||
| 747 | |||
| 748 | // If this one has already been publicized to, don't let it happen again |
||
| 749 | $disabled = ''; |
||
| 750 | if ( $done ) { |
||
| 751 | $disabled = ' disabled="disabled"'; |
||
| 752 | } |
||
| 753 | |||
| 754 | // If this is a global connection and this user doesn't have enough permissions to modify |
||
| 755 | // those connections, don't let them change it |
||
| 756 | $cmeta = $this->publicize->get_connection_meta( $connection ); |
||
| 757 | $hidden_checkbox = false; |
||
| 758 | if ( !$done && ( 0 == $cmeta['connection_data']['user_id'] && !current_user_can( $this->publicize->GLOBAL_CAP ) ) ) { |
||
| 759 | $disabled = ' disabled="disabled"'; |
||
| 760 | /** |
||
| 761 | * Filters the checkboxes for global connections with non-prilvedged users. |
||
| 762 | * |
||
| 763 | * @module publicize |
||
| 764 | * |
||
| 765 | * @since 3.7.0 |
||
| 766 | * |
||
| 767 | * @param bool $checked Indicates if this connection should be enabled. Default true. |
||
| 768 | * @param int $post->ID ID of the current post |
||
| 769 | * @param string $service_name Name of the connection (Facebook, Twitter, etc) |
||
| 770 | * @param array $connection Array of data about the connection. |
||
| 771 | */ |
||
| 772 | $hidden_checkbox = apply_filters( 'publicize_checkbox_global_default', true, $post->ID, $service_name, $connection ); |
||
| 773 | } |
||
| 774 | |||
| 775 | // Determine the state of the checkbox (on/off) and allow filtering |
||
| 776 | $checked = $skip != 1 || $done; |
||
| 777 | /** |
||
| 778 | * Filter the checkbox state of each Publicize connection appearing in the post editor. |
||
| 779 | * |
||
| 780 | * @module publicize |
||
| 781 | * |
||
| 782 | * @since 2.0.1 |
||
| 783 | * |
||
| 784 | * @param bool $checked Should the Publicize checkbox be enabled for a given service. |
||
| 785 | * @param int $post->ID Post ID. |
||
| 786 | * @param string $service_name Service name. |
||
| 787 | * @param array $connection Array of connection details. |
||
| 788 | */ |
||
| 789 | $checked = apply_filters( 'publicize_checkbox_default', $checked, $post->ID, $service_name, $connection ); |
||
| 790 | |||
| 791 | // Force the checkbox to be checked if the post was DONE, regardless of what the filter does |
||
| 792 | if ( $done ) { |
||
| 793 | $checked = true; |
||
| 794 | } |
||
| 795 | $disabled = false; |
||
| 796 | // This service has been handled, so disable everything |
||
| 797 | if ( $done || $all_done ) { |
||
| 798 | $disabled = ' disabled="disabled"'; |
||
| 799 | } |
||
| 800 | |||
| 801 | $label = sprintf( |
||
| 802 | /* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Username on Service (@jetpack, ...) */ |
||
| 803 | __( '%1$s: %2$s', 'jetpack' ), |
||
| 804 | esc_html( $this->publicize->get_service_label( $service_name ) ), |
||
| 805 | esc_html( $this->publicize->get_display_name( $service_name, $connection ) ) |
||
| 806 | ); |
||
| 807 | |||
| 808 | if ( |
||
| 809 | $service_name === 'facebook' |
||
| 810 | && |
||
| 811 | ! $this->publicize->is_valid_facebook_connection( $connection ) |
||
| 812 | && |
||
| 813 | $this->publicize->is_connecting_connection( $connection ) |
||
| 814 | ) { |
||
| 815 | $skip = true; |
||
| 816 | $disabled = ' disabled="disabled"'; |
||
| 817 | $checked = false; |
||
| 818 | $hidden_checkbox = false; |
||
| 819 | } |
||
| 820 | |||
| 821 | if ( ( !$skip || $done ) && ! $disabled ) { |
||
| 822 | $active[] = $label; |
||
| 823 | } |
||
| 824 | |||
| 825 | ?> |
||
| 826 | <li> |
||
| 827 | <label for="wpas-submit-<?php echo esc_attr( $unique_id ); ?>"> |
||
| 828 | <input type="checkbox" name="wpas[submit][<?php echo $unique_id; ?>]" id="wpas-submit-<?php echo $unique_id; ?>" class="wpas-submit-<?php echo $service_name; ?>" value="1" <?php |
||
| 829 | checked( true, $checked ); |
||
| 830 | echo $disabled; |
||
| 831 | ?> /> |
||
| 832 | <?php |
||
| 833 | if ( $hidden_checkbox ) { |
||
| 834 | // Need to submit a value to force a global connection to post |
||
| 835 | echo '<input type="hidden" name="wpas[submit][' . $unique_id . ']" value="1" />'; |
||
| 836 | } |
||
| 837 | echo esc_html( $label ); |
||
| 838 | ?> |
||
| 839 | </label> |
||
| 840 | </li> |
||
| 841 | <?php |
||
| 842 | } |
||
| 843 | } |
||
| 844 | |||
| 845 | if ( $title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true ) ) { |
||
| 846 | $title = esc_html( $title ); |
||
| 847 | } else { |
||
| 848 | $title = ''; |
||
| 849 | } |
||
| 850 | ?> |
||
| 851 | |||
| 852 | </ul> |
||
| 853 | |||
| 854 | <label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label> |
||
| 855 | <span id="wpas-title-counter" class="alignright hide-if-no-js">0</span> |
||
| 856 | |||
| 857 | <textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done || $all_services_done ); ?>><?php echo $title; ?></textarea> |
||
| 858 | |||
| 859 | <a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> |
||
| 860 | <input type="hidden" name="wpas[0]" value="1" /> |
||
| 861 | |||
| 862 | </div> |
||
| 863 | <?php if ( ! $all_done ) : ?> |
||
| 864 | <div id="pub-connection-tests"></div> |
||
| 865 | <?php endif; ?> |
||
| 866 | <?php // #publicize-form |
||
| 867 | |||
| 868 | return array( ob_get_clean(), $active ); |
||
| 869 | } |
||
| 870 | |||
| 871 | private function get_metabox_form_disconnected( $available_services ) { |
||
| 872 | ob_start(); |
||
| 873 | ?><div id="publicize-form" class="hide-if-js"> |
||
| 874 | <div id="add-publicize-check" style="display: none;"></div> |
||
| 875 | |||
| 876 | <?php _e( 'Connect to', 'jetpack' ); ?>: |
||
| 877 | |||
| 878 | <ul class="not-connected"> |
||
| 879 | <?php foreach ( $available_services as $service_name => $service ) : ?> |
||
| 880 | <li> |
||
| 881 | <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 ) ); ?>"> |
||
| 882 | <?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?> |
||
| 883 | </a> |
||
| 884 | </li> |
||
| 885 | <?php endforeach; ?> |
||
| 886 | </ul> |
||
| 887 | <a href="#" class="hide-if-no-js button" id="publicize-disconnected-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> |
||
| 888 | </div><?php // #publicize-form |
||
| 889 | return ob_get_clean(); |
||
| 890 | } |
||
| 891 | } |
||
| 892 |
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: