images
3 years ago
services
3 years ago
admin-sharing-rtl.css
3 years ago
admin-sharing-rtl.min.css
3 years ago
admin-sharing.css
3 years ago
admin-sharing.js
3 years ago
admin-sharing.min.css
3 years ago
amp-sharing.css
4 years ago
recaptcha.php
4 years ago
sharedaddy.php
3 years ago
sharing-service.php
3 years ago
sharing-sources.php
3 years ago
sharing.css
3 years ago
sharing.js
3 years ago
sharing.php
3 years ago
sharing.php
804 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Set up Sharing functionality and management in wp-admin. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 9 | |
| 10 | use Automattic\Jetpack\Assets; |
| 11 | use Automattic\Jetpack\Status; |
| 12 | |
| 13 | if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) { |
| 14 | define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 15 | define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Utilities to manage sharing settings from wp-admin. |
| 20 | */ |
| 21 | class Sharing_Admin { |
| 22 | |
| 23 | /** |
| 24 | * Constructor. |
| 25 | * Hook into WordPress to add our functionality. |
| 26 | */ |
| 27 | public function __construct() { |
| 28 | require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php'; |
| 29 | |
| 30 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 31 | add_action( 'admin_menu', array( $this, 'subscription_menu' ) ); |
| 32 | |
| 33 | // Insert our CSS and JS |
| 34 | add_action( 'load-settings_page_sharing', array( $this, 'sharing_head' ) ); |
| 35 | |
| 36 | // Catch AJAX |
| 37 | add_action( 'wp_ajax_sharing_save_services', array( $this, 'ajax_save_services' ) ); |
| 38 | add_action( 'wp_ajax_sharing_save_options', array( $this, 'ajax_save_options' ) ); |
| 39 | add_action( 'wp_ajax_sharing_new_service', array( $this, 'ajax_new_service' ) ); |
| 40 | add_action( 'wp_ajax_sharing_delete_service', array( $this, 'ajax_delete_service' ) ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Enqueue scripts and styles on the sharing settings page. |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | public function sharing_head() { |
| 49 | wp_enqueue_script( |
| 50 | 'sharing-js', |
| 51 | Assets::get_file_url_for_environment( |
| 52 | '_inc/build/sharedaddy/admin-sharing.min.js', |
| 53 | 'modules/sharedaddy/admin-sharing.js' |
| 54 | ), |
| 55 | array( 'jquery', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-form' ), |
| 56 | 2, |
| 57 | false |
| 58 | ); |
| 59 | |
| 60 | /** |
| 61 | * Filters the switch that if set to true allows Jetpack to use minified assets. Defaults to true |
| 62 | * if the SCRIPT_DEBUG constant is not set or set to false. The filter overrides it. |
| 63 | * |
| 64 | * @since 6.2.0 |
| 65 | * |
| 66 | * @param boolean $var should Jetpack use minified assets. |
| 67 | */ |
| 68 | $postfix = apply_filters( 'jetpack_should_use_minified_assets', true ) ? '.min' : ''; |
| 69 | if ( is_rtl() ) { |
| 70 | wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing-rtl' . $postfix . '.css', false, JETPACK__VERSION ); |
| 71 | } else { |
| 72 | wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing' . $postfix . '.css', false, JETPACK__VERSION ); |
| 73 | } |
| 74 | wp_enqueue_style( 'sharing', WP_SHARING_PLUGIN_URL . 'sharing.css', false, JETPACK__VERSION ); |
| 75 | |
| 76 | wp_enqueue_style( 'social-logos' ); |
| 77 | wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array(), 4, false ); |
| 78 | add_thickbox(); |
| 79 | |
| 80 | // On Jetpack sites, make sure we include CSS to style the admin page. |
| 81 | if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) { |
| 82 | Jetpack_Admin_Page::load_wrapper_styles(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Load the process that handles saving changes on the sharing settings page. |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | public function admin_init() { |
| 92 | if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonces are handled in process_requests. |
| 93 | $this->process_requests(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Save changes to sharing settings. |
| 99 | * |
| 100 | * @return void |
| 101 | */ |
| 102 | public function process_requests() { |
| 103 | if ( |
| 104 | isset( $_POST['_wpnonce'] ) |
| 105 | && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' ) |
| 106 | ) { |
| 107 | $sharer = new Sharing_Service(); |
| 108 | $sharer->set_global_options( $_POST ); |
| 109 | /** |
| 110 | * Fires when updating sharing settings. |
| 111 | * |
| 112 | * @module sharedaddy |
| 113 | * |
| 114 | * @since 1.1.0 |
| 115 | */ |
| 116 | do_action( 'sharing_admin_update' ); |
| 117 | |
| 118 | wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) ); |
| 119 | die(); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Register Sharing settings menu page. |
| 125 | */ |
| 126 | public function subscription_menu() { |
| 127 | if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) { |
| 128 | $active = Jetpack::get_active_modules(); |
| 129 | if ( |
| 130 | ! in_array( 'publicize', $active, true ) |
| 131 | && ! current_user_can( 'manage_options' ) |
| 132 | ) { |
| 133 | return; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | add_submenu_page( |
| 138 | 'options-general.php', |
| 139 | __( 'Sharing Settings', 'jetpack' ), |
| 140 | __( 'Sharing', 'jetpack' ), |
| 141 | 'publish_posts', |
| 142 | 'sharing', |
| 143 | array( $this, 'wrapper_admin_page' ) |
| 144 | ); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Save changes to sharing services via AJAX. |
| 149 | * |
| 150 | * @return void |
| 151 | */ |
| 152 | public function ajax_save_services() { |
| 153 | if ( |
| 154 | isset( $_POST['_wpnonce'] ) |
| 155 | && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' ) |
| 156 | && isset( $_POST['hidden'] ) |
| 157 | && isset( $_POST['visible'] ) |
| 158 | ) { |
| 159 | $sharer = new Sharing_Service(); |
| 160 | |
| 161 | $sharer->set_blog_services( |
| 162 | explode( ',', sanitize_text_field( wp_unslash( $_POST['visible'] ) ) ), |
| 163 | explode( ',', sanitize_text_field( wp_unslash( $_POST['hidden'] ) ) ) |
| 164 | ); |
| 165 | die(); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Create a new custom sharing service via AJAX. |
| 171 | * |
| 172 | * @return void |
| 173 | */ |
| 174 | public function ajax_new_service() { |
| 175 | if ( |
| 176 | isset( $_POST['_wpnonce'] ) |
| 177 | && isset( $_POST['sharing_name'] ) |
| 178 | && isset( $_POST['sharing_url'] ) |
| 179 | && isset( $_POST['sharing_icon'] ) |
| 180 | && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-new_service' ) |
| 181 | ) { |
| 182 | $sharer = new Sharing_Service(); |
| 183 | $service = $sharer->new_service( |
| 184 | sanitize_text_field( wp_unslash( $_POST['sharing_name'] ) ), |
| 185 | esc_url_raw( wp_unslash( $_POST['sharing_url'] ) ), |
| 186 | esc_url_raw( wp_unslash( $_POST['sharing_icon'] ) ) |
| 187 | ); |
| 188 | |
| 189 | if ( $service ) { |
| 190 | $this->output_service( $service->get_id(), $service ); |
| 191 | echo '<!--->'; |
| 192 | $service->button_style = 'icon-text'; |
| 193 | $this->output_preview( $service ); |
| 194 | |
| 195 | die(); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // Fail |
| 200 | die( '1' ); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Delete a sharing service via AJAX. |
| 205 | * |
| 206 | * @return void |
| 207 | */ |
| 208 | public function ajax_delete_service() { |
| 209 | if ( |
| 210 | isset( $_POST['_wpnonce'] ) |
| 211 | && isset( $_POST['service'] ) |
| 212 | && wp_verify_nonce( |
| 213 | sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), |
| 214 | 'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) ) |
| 215 | ) |
| 216 | ) { |
| 217 | $sharer = new Sharing_Service(); |
| 218 | $sharer->delete_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) ); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Save changes to sharing settings via AJAX. |
| 224 | * |
| 225 | * @return void |
| 226 | */ |
| 227 | public function ajax_save_options() { |
| 228 | if ( |
| 229 | isset( $_POST['_wpnonce'] ) |
| 230 | && isset( $_POST['service'] ) |
| 231 | && wp_verify_nonce( |
| 232 | sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), |
| 233 | 'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) ) |
| 234 | ) |
| 235 | ) { |
| 236 | $sharer = new Sharing_Service(); |
| 237 | $service = $sharer->get_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) ); |
| 238 | |
| 239 | if ( $service && $service instanceof Sharing_Advanced_Source ) { |
| 240 | $service->update_options( $_POST ); |
| 241 | |
| 242 | $sharer->set_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ), $service ); |
| 243 | } |
| 244 | |
| 245 | $this->output_service( $service->get_id(), $service, true ); |
| 246 | echo '<!--->'; |
| 247 | $service->button_style = 'icon-text'; |
| 248 | $this->output_preview( $service ); |
| 249 | die(); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Display a preview of a sharing service. |
| 255 | * |
| 256 | * @param object $service Sharing service object. |
| 257 | * |
| 258 | * @return void |
| 259 | */ |
| 260 | public function output_preview( $service ) { |
| 261 | $klasses = array( 'advanced', 'preview-item' ); |
| 262 | |
| 263 | if ( $service->button_style !== 'text' || $service->has_custom_button_style() ) { |
| 264 | $klasses[] = 'preview-' . $service->get_class(); |
| 265 | $klasses[] = 'share-' . $service->get_class(); |
| 266 | if ( $service->is_deprecated() ) { |
| 267 | $klasses[] = 'share-deprecated'; |
| 268 | } |
| 269 | |
| 270 | if ( $service->get_class() !== $service->get_id() ) { |
| 271 | $klasses[] = 'preview-' . $service->get_id(); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | echo '<li class="' . esc_attr( implode( ' ', $klasses ) ) . '">'; |
| 276 | $service->display_preview(); |
| 277 | echo '</li>'; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Display a specific sharing service. |
| 282 | * |
| 283 | * @param int $id Service unique ID. |
| 284 | * @param object $service Sharing service. |
| 285 | * @param bool $show_dropdown Display a dropdown. Not in use at the moment. |
| 286 | * |
| 287 | * @return void |
| 288 | */ |
| 289 | public function output_service( $id, $service, $show_dropdown = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 290 | $title = ''; |
| 291 | $klasses = array( 'service', 'advanced', 'share-' . $service->get_class() ); |
| 292 | $displayed_klasses = implode( ' ', $klasses ); |
| 293 | |
| 294 | if ( $service->is_deprecated() ) { |
| 295 | /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 296 | $title = sprintf( __( 'The %1$s service has shut down. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $service->get_name() ); |
| 297 | $klasses[] = 'share-deprecated'; |
| 298 | } |
| 299 | |
| 300 | ?> |
| 301 | <li class="<?php echo esc_attr( $displayed_klasses ); ?>" id="<?php echo esc_attr( $service->get_id() ); ?>" tabindex="0" title="<?php echo esc_attr( $title ); ?>"> |
| 302 | <span class="options-left"><?php echo esc_html( $service->get_name() ); ?></span> |
| 303 | <?php if ( 0 === strpos( $service->get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?> |
| 304 | <span class="close"><a href="#" class="remove">×</a></span> |
| 305 | <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>"> |
| 306 | <input type="hidden" name="action" value="sharing_delete_service" /> |
| 307 | <input type="hidden" name="service" value="<?php echo esc_attr( $id ); ?>" /> |
| 308 | <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options_' . $id ) ); ?>" /> |
| 309 | </form> |
| 310 | <?php endif; ?> |
| 311 | </li> |
| 312 | <?php |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Display admin UI within a Jetpack header and footer. |
| 317 | * |
| 318 | * @return void |
| 319 | */ |
| 320 | public function wrapper_admin_page() { |
| 321 | Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ), array( 'is-wide' => true ) ); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Sharing settings inner page structure. |
| 326 | * |
| 327 | * @return void |
| 328 | */ |
| 329 | public function management_page() { |
| 330 | $sharer = new Sharing_Service(); |
| 331 | $enabled = $sharer->get_blog_services(); |
| 332 | $global = $sharer->get_global_options(); |
| 333 | |
| 334 | $shows = array_values( get_post_types( array( 'public' => true ) ) ); |
| 335 | array_unshift( $shows, 'index' ); |
| 336 | |
| 337 | if ( ! function_exists( 'mb_stripos' ) ) { |
| 338 | echo '<div id="message" class="updated fade"><h3>' . esc_html__( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>'; |
| 339 | echo '<p>' . wp_kses( |
| 340 | sprintf( |
| 341 | /* Translators: placeholder is a link to a PHP support document. */ |
| 342 | __( 'This plugin will work without it, but multibyte support is used <a href="%s" rel="noopener noreferrer" target="_blank">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack' ), |
| 343 | 'https://www.php.net/manual/en/mbstring.installation.php' |
| 344 | ), |
| 345 | array( |
| 346 | 'a' => array( |
| 347 | 'href' => array(), |
| 348 | 'rel' => array(), |
| 349 | 'target' => array(), |
| 350 | ), |
| 351 | ) |
| 352 | ) . '</p></div>'; |
| 353 | } |
| 354 | |
| 355 | if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only used to display a message. |
| 356 | echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>'; |
| 357 | } |
| 358 | |
| 359 | if ( ! isset( $global['sharing_label'] ) ) { |
| 360 | $global['sharing_label'] = __( 'Share this:', 'jetpack' ); |
| 361 | } |
| 362 | ?> |
| 363 | |
| 364 | <div class="wrap"> |
| 365 | <div class="icon32" id="icon-options-general"><br /></div> |
| 366 | <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1> |
| 367 | |
| 368 | <?php |
| 369 | /** |
| 370 | * Fires at the top of the admin sharing settings screen. |
| 371 | * |
| 372 | * @module sharedaddy |
| 373 | * |
| 374 | * @since 1.6.0 |
| 375 | */ |
| 376 | do_action( 'pre_admin_screen_sharing' ); |
| 377 | ?> |
| 378 | |
| 379 | <?php if ( current_user_can( 'manage_options' ) ) : ?> |
| 380 | |
| 381 | <div class="share_manage_options"> |
| 382 | <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2> |
| 383 | <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p> |
| 384 | |
| 385 | <div id="services-config"> |
| 386 | <table id="available-services"> |
| 387 | <tr> |
| 388 | <td class="description"> |
| 389 | <h3><?php esc_html_e( 'Available Services', 'jetpack' ); ?></h3> |
| 390 | <p><?php esc_html_e( "Drag and drop the services you'd like to enable into the box below.", 'jetpack' ); ?></p> |
| 391 | <p><a href="#TB_inline?height=395&width=600&inlineId=new-service" class="thickbox" id="add-a-new-service"><?php esc_html_e( 'Add a new service', 'jetpack' ); ?></a></p> |
| 392 | </td> |
| 393 | <td class="services"> |
| 394 | <ul class="services-available" style="height: 100px;"> |
| 395 | <?php foreach ( $sharer->get_all_services_blog() as $id => $service ) : ?> |
| 396 | <?php |
| 397 | if ( ! isset( $enabled['all'][ $id ] ) ) { |
| 398 | $this->output_service( $id, $service ); |
| 399 | } |
| 400 | ?> |
| 401 | <?php endforeach; ?> |
| 402 | </ul> |
| 403 | <?php |
| 404 | if ( ( new Status() )->is_private_site() ) { |
| 405 | echo '<p><strong>' . esc_html__( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . '</strong></p>'; |
| 406 | } |
| 407 | ?> |
| 408 | <br class="clearing" /> |
| 409 | </td> |
| 410 | </tr> |
| 411 | </table> |
| 412 | |
| 413 | <table id="enabled-services"> |
| 414 | <tr> |
| 415 | <td class="description"> |
| 416 | <h3> |
| 417 | <?php esc_html_e( 'Enabled Services', 'jetpack' ); ?> |
| 418 | <img src="<?php echo esc_url( admin_url( 'images/loading.gif' ) ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> |
| 419 | </h3> |
| 420 | <p><?php esc_html_e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p> |
| 421 | </td> |
| 422 | <td class="services" id="share-drop-target"> |
| 423 | <h2 id="drag-instructions" |
| 424 | <?php |
| 425 | if ( is_countable( $enabled['visible'] ) && count( $enabled['visible'] ) > 0 ) { |
| 426 | echo ' style="display: none"';} |
| 427 | ?> |
| 428 | ><?php esc_html_e( 'Drag and drop available services here.', 'jetpack' ); ?></h2> |
| 429 | |
| 430 | <ul class="services-enabled"> |
| 431 | <?php foreach ( $enabled['visible'] as $id => $service ) : ?> |
| 432 | <?php $this->output_service( $id, $service, true ); ?> |
| 433 | <?php endforeach; ?> |
| 434 | |
| 435 | <li class="end-fix"></li> |
| 436 | </ul> |
| 437 | </td> |
| 438 | <td id="hidden-drop-target" class="services"> |
| 439 | <p><?php esc_html_e( 'Services dragged here will be hidden behind a share button.', 'jetpack' ); ?></p> |
| 440 | |
| 441 | <ul class="services-hidden"> |
| 442 | <?php foreach ( $enabled['hidden'] as $id => $service ) : ?> |
| 443 | <?php $this->output_service( $id, $service, true ); ?> |
| 444 | <?php endforeach; ?> |
| 445 | <li class="end-fix"></li> |
| 446 | </ul> |
| 447 | </td> |
| 448 | </tr> |
| 449 | </table> |
| 450 | |
| 451 | <table id="live-preview"> |
| 452 | <tr> |
| 453 | <td class="description"> |
| 454 | <h3><?php esc_html_e( 'Live Preview', 'jetpack' ); ?></h3> |
| 455 | </td> |
| 456 | <td class="services"> |
| 457 | <h2 <?php echo ( is_countable( $enabled['all'] ) && count( $enabled['all'] ) > 0 ) ? ' style="display: none"' : ''; ?>><?php esc_html_e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2> |
| 458 | <div class="sharedaddy sd-sharing-enabled"> |
| 459 | <?php if ( is_countable( $enabled['all'] ) && count( $enabled['all'] ) > 0 ) : ?> |
| 460 | <h3 class="sd-title"><?php echo esc_html( $global['sharing_label'] ); ?></h3> |
| 461 | <?php endif; ?> |
| 462 | <div class="sd-content"> |
| 463 | <ul class="preview"> |
| 464 | <?php foreach ( $enabled['visible'] as $id => $service ) : ?> |
| 465 | <?php $this->output_preview( $service ); ?> |
| 466 | <?php endforeach; ?> |
| 467 | |
| 468 | <?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?> |
| 469 | <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li> |
| 470 | <?php endif; ?> |
| 471 | </ul> |
| 472 | |
| 473 | <?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?> |
| 474 | <div class="sharing-hidden"> |
| 475 | <div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) === 1 ? 'width:150px;' : ''; ?>"> |
| 476 | <?php if ( count( $enabled['hidden'] ) === 1 ) : ?> |
| 477 | <ul style="background-image:none;"> |
| 478 | <?php else : ?> |
| 479 | <ul> |
| 480 | <?php endif; ?> |
| 481 | |
| 482 | <?php |
| 483 | foreach ( $enabled['hidden'] as $id => $service ) { |
| 484 | $this->output_preview( $service ); |
| 485 | } |
| 486 | ?> |
| 487 | </ul> |
| 488 | </div> |
| 489 | </div> |
| 490 | <?php endif; ?> |
| 491 | |
| 492 | <ul class="archive" style="display:none;"> |
| 493 | <?php |
| 494 | foreach ( $sharer->get_all_services_blog() as $id => $service ) : |
| 495 | if ( isset( $enabled['visible'][ $id ] ) ) { |
| 496 | $service = $enabled['visible'][ $id ]; |
| 497 | } elseif ( isset( $enabled['hidden'][ $id ] ) ) { |
| 498 | $service = $enabled['hidden'][ $id ]; |
| 499 | } |
| 500 | |
| 501 | $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later. |
| 502 | $service->smart = false; |
| 503 | $this->output_preview( $service ); |
| 504 | endforeach; |
| 505 | ?> |
| 506 | <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li> |
| 507 | </ul> |
| 508 | </div> |
| 509 | </div> |
| 510 | <br class="clearing" /> |
| 511 | </td> |
| 512 | </tr> |
| 513 | </table> |
| 514 | |
| 515 | <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="save-enabled-shares"> |
| 516 | <input type="hidden" name="action" value="sharing_save_services" /> |
| 517 | <input type="hidden" name="visible" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['visible'] ) ) ); ?>" /> |
| 518 | <input type="hidden" name="hidden" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['hidden'] ) ) ); ?>" /> |
| 519 | <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" /> |
| 520 | </form> |
| 521 | </div> |
| 522 | |
| 523 | <form method="post" action=""> |
| 524 | <table class="form-table"> |
| 525 | <tbody> |
| 526 | <tr valign="top"> |
| 527 | <th scope="row"><label><?php esc_html_e( 'Button style', 'jetpack' ); ?></label></th> |
| 528 | <td> |
| 529 | <select name="button_style" id="button_style"> |
| 530 | <option<?php echo ( $global['button_style'] === 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php esc_html_e( 'Icon + text', 'jetpack' ); ?></option> |
| 531 | <option<?php echo ( $global['button_style'] === 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php esc_html_e( 'Icon only', 'jetpack' ); ?></option> |
| 532 | <option<?php echo ( $global['button_style'] === 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php esc_html_e( 'Text only', 'jetpack' ); ?></option> |
| 533 | <option<?php echo ( $global['button_style'] === 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php esc_html_e( 'Official buttons', 'jetpack' ); ?></option> |
| 534 | </select> |
| 535 | </td> |
| 536 | </tr> |
| 537 | <tr valign="top"> |
| 538 | <th scope="row"><label><?php esc_html_e( 'Sharing label', 'jetpack' ); ?></label></th> |
| 539 | <td> |
| 540 | <input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" /> |
| 541 | </td> |
| 542 | </tr> |
| 543 | <?php |
| 544 | /** |
| 545 | * Filters the HTML at the beginning of the "Show button on" row. |
| 546 | * |
| 547 | * @module sharedaddy |
| 548 | * |
| 549 | * @since 2.1.0 |
| 550 | * |
| 551 | * @param string $var Opening HTML tag at the beginning of the "Show button on" row. |
| 552 | */ |
| 553 | echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 554 | ?> |
| 555 | <th scope="row"><label><?php esc_html_e( 'Show buttons on', 'jetpack' ); ?></label></th> |
| 556 | <td> |
| 557 | <?php |
| 558 | $br = false; |
| 559 | foreach ( $shows as $show ) : |
| 560 | if ( 'index' === $show ) { |
| 561 | $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' ); |
| 562 | } else { |
| 563 | $post_type_object = get_post_type_object( $show ); |
| 564 | $label = $post_type_object->labels->name; |
| 565 | } |
| 566 | ?> |
| 567 | <?php |
| 568 | if ( $br ) { |
| 569 | echo '<br />'; |
| 570 | } |
| 571 | ?> |
| 572 | <label><input type="checkbox"<?php checked( in_array( $show, $global['show'], true ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label> |
| 573 | <?php |
| 574 | $br = true; |
| 575 | endforeach; |
| 576 | ?> |
| 577 | </td> |
| 578 | <?php |
| 579 | /** |
| 580 | * Filters the HTML at the end of the "Show button on" row. |
| 581 | * |
| 582 | * @module sharedaddy |
| 583 | * |
| 584 | * @since 2.1.0 |
| 585 | * |
| 586 | * @param string $var Closing HTML tag at the end of the "Show button on" row. |
| 587 | */ |
| 588 | echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 589 | ?> |
| 590 | |
| 591 | <?php |
| 592 | /** |
| 593 | * Fires at the end of the sharing global options settings table. |
| 594 | * |
| 595 | * @module sharedaddy |
| 596 | * |
| 597 | * @since 1.1.0 |
| 598 | */ |
| 599 | do_action( 'sharing_global_options' ); |
| 600 | ?> |
| 601 | </tbody> |
| 602 | </table> |
| 603 | |
| 604 | <p class="submit"> |
| 605 | <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" /> |
| 606 | </p> |
| 607 | |
| 608 | <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" /> |
| 609 | </form> |
| 610 | |
| 611 | <div id="new-service" style="display: none"> |
| 612 | <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="new-service-form"> |
| 613 | <table class="form-table"> |
| 614 | <tbody> |
| 615 | <tr valign="top"> |
| 616 | <th scope="row" width="100"><label><?php esc_html_e( 'Service name', 'jetpack' ); ?></label></th> |
| 617 | <td> |
| 618 | <input type="text" name="sharing_name" id="new_sharing_name" size="40" /> |
| 619 | </td> |
| 620 | </tr> |
| 621 | <tr valign="top"> |
| 622 | <th scope="row" width="100"><label><?php esc_html_e( 'Sharing URL', 'jetpack' ); ?></label></th> |
| 623 | <td> |
| 624 | <input type="text" name="sharing_url" id="new_sharing_url" size="40" /> |
| 625 | |
| 626 | <p><?php esc_html_e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/> |
| 627 | <code>%post_id%</code>, <code>%post_title%</code>, <code>%post_slug%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_tags%</code>, <code>%home_url%</code></p> |
| 628 | </td> |
| 629 | </tr> |
| 630 | <tr valign="top"> |
| 631 | <th scope="row" width="100"><label><?php esc_html_e( 'Icon URL', 'jetpack' ); ?></label></th> |
| 632 | <td> |
| 633 | <input type="text" name="sharing_icon" id="new_sharing_icon" size="40" /> |
| 634 | <p><?php esc_html_e( 'Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack' ); ?></p> |
| 635 | </td> |
| 636 | </tr> |
| 637 | <tr valign="top" width="100"> |
| 638 | <th scope="row"></th> |
| 639 | <td> |
| 640 | <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" /> |
| 641 | <img src="<?php echo esc_url( admin_url( 'images/loading.gif' ) ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> |
| 642 | </td> |
| 643 | </tr> |
| 644 | |
| 645 | <?php |
| 646 | /** |
| 647 | * Fires after the custom sharing service form |
| 648 | * |
| 649 | * @module sharedaddy |
| 650 | * |
| 651 | * @since 1.1.0 |
| 652 | */ |
| 653 | do_action( 'sharing_new_service_form' ); |
| 654 | ?> |
| 655 | </tbody> |
| 656 | </table> |
| 657 | |
| 658 | <?php |
| 659 | /** |
| 660 | * Fires at the bottom of the admin sharing settings screen. |
| 661 | * |
| 662 | * @module sharedaddy |
| 663 | * |
| 664 | * @since 1.6.0 |
| 665 | */ |
| 666 | do_action( 'post_admin_screen_sharing' ); |
| 667 | ?> |
| 668 | |
| 669 | <div class="inerror" style="display: none; margin-top: 15px"> |
| 670 | <p><?php esc_html_e( 'An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack' ); ?></p> |
| 671 | </div> |
| 672 | |
| 673 | <input type="hidden" name="action" value="sharing_new_service" /> |
| 674 | <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-new_service' ) ); ?>" /> |
| 675 | </form> |
| 676 | </div> |
| 677 | </div> |
| 678 | |
| 679 | <?php endif; ?> |
| 680 | |
| 681 | |
| 682 | </div> |
| 683 | |
| 684 | <script type="text/javascript"> |
| 685 | var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>'; |
| 686 | <?php |
| 687 | // phpcs:disable WordPress.Security.NonceVerification.Recommended -- we handle the nonce on the PHP side. |
| 688 | if ( |
| 689 | isset( $_GET['create_new_service'] ) && isset( $_GET['name'] ) && isset( $_GET['url'] ) && isset( $_GET['icon'] ) |
| 690 | && 'true' == $_GET['create_new_service'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual |
| 691 | ) : |
| 692 | ?> |
| 693 | jQuery(document).ready(function() { |
| 694 | // Prefill new service box and then open it |
| 695 | jQuery( '#new_sharing_name' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['name'] ) ) ); ?>' ); |
| 696 | jQuery( '#new_sharing_url' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['url'] ) ) ); ?>' ); |
| 697 | jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['icon'] ) ) ); ?>' ); |
| 698 | jQuery( '#add-a-new-service' ).click(); |
| 699 | }); |
| 700 | <?php endif; ?> |
| 701 | </script> |
| 702 | <?php |
| 703 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Callback to get the value for the jetpack_sharing_enabled field. |
| 709 | * |
| 710 | * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing. |
| 711 | * When it is set to 1, we disable sharing on the post, regardless of the global setting. |
| 712 | * It is not possible to enable sharing on a post if it is disabled globally. |
| 713 | * |
| 714 | * @param array $post The post object. |
| 715 | * |
| 716 | * @return bool |
| 717 | */ |
| 718 | function jetpack_post_sharing_get_value( array $post ) { |
| 719 | // if sharing IS disabled on this post, enabled=false, so negate the meta |
| 720 | return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true ); |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * Callback to set sharing_disabled post_meta when the |
| 725 | * jetpack_sharing_enabled field is updated. |
| 726 | * |
| 727 | * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing. |
| 728 | * When it is set to 1, we disable sharing on the post, regardless of the global setting. |
| 729 | * It is not possible to enable sharing on a post if it is disabled globally. |
| 730 | * |
| 731 | * @param bool $enable_sharing Should sharing be enabled on this post. |
| 732 | * @param WP_Post $post_object The post object. |
| 733 | * |
| 734 | * @return int|bool |
| 735 | */ |
| 736 | function jetpack_post_sharing_update_value( $enable_sharing, $post_object ) { |
| 737 | if ( $enable_sharing ) { |
| 738 | // delete the override if we want to enable sharing |
| 739 | return delete_post_meta( $post_object->ID, 'sharing_disabled' ); |
| 740 | } else { |
| 741 | return update_post_meta( $post_object->ID, 'sharing_disabled', true ); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Add Sharing post_meta to the REST API Post response. |
| 747 | * |
| 748 | * @action rest_api_init |
| 749 | * @uses register_rest_field |
| 750 | * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/ |
| 751 | */ |
| 752 | function jetpack_post_sharing_register_rest_field() { |
| 753 | $post_types = get_post_types( array( 'public' => true ) ); |
| 754 | foreach ( $post_types as $post_type ) { |
| 755 | register_rest_field( |
| 756 | $post_type, |
| 757 | 'jetpack_sharing_enabled', |
| 758 | array( |
| 759 | 'get_callback' => 'jetpack_post_sharing_get_value', |
| 760 | 'update_callback' => 'jetpack_post_sharing_update_value', |
| 761 | 'schema' => array( |
| 762 | 'description' => __( 'Are sharing buttons enabled?', 'jetpack' ), |
| 763 | 'type' => 'boolean', |
| 764 | ), |
| 765 | ) |
| 766 | ); |
| 767 | |
| 768 | /** |
| 769 | * Ensures all public internal post-types support `sharing` |
| 770 | * This feature support flag is used by the REST API and Gutenberg. |
| 771 | */ |
| 772 | add_post_type_support( $post_type, 'jetpack-sharing-buttons' ); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | // Add Sharing post_meta to the REST API Post response. |
| 777 | add_action( 'rest_api_init', 'jetpack_post_sharing_register_rest_field' ); |
| 778 | |
| 779 | // Some CPTs (e.g. Jetpack portfolios and testimonials) get registered with |
| 780 | // restapi_theme_init because they depend on theme support, so let's also hook to that |
| 781 | add_action( 'restapi_theme_init', 'jetpack_post_likes_register_rest_field', 20 ); |
| 782 | |
| 783 | /** |
| 784 | * Initialize sharing settings in WP Admin. |
| 785 | * |
| 786 | * @return void |
| 787 | */ |
| 788 | function sharing_admin_init() { |
| 789 | global $sharing_admin; |
| 790 | |
| 791 | $sharing_admin = new Sharing_Admin(); |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * Set the Likes and Sharing Gutenberg extension as available |
| 796 | */ |
| 797 | function jetpack_sharing_set_extension_availability() { |
| 798 | Jetpack_Gutenberg::set_extension_available( 'sharing' ); |
| 799 | } |
| 800 | |
| 801 | add_action( 'jetpack_register_gutenberg_extensions', 'jetpack_sharing_set_extension_availability' ); |
| 802 | |
| 803 | add_action( 'init', 'sharing_admin_init' ); |
| 804 |