PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2
Jetpack – WP Security, Backup, Speed, & Growth v6.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / sharedaddy / sharing.php

sharing.php in Jetpack – WP Security, Backup, Speed, & Growth 6.2, at modules/sharedaddy/sharing.php

535 lines 19.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) {
3 define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
4 define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
5 }
6
7 class Sharing_Admin {
8 public function __construct() {
9 require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php';
10
11 add_action( 'admin_init', array( &$this, 'admin_init' ) );
12 add_action( 'admin_menu', array( &$this, 'subscription_menu' ) );
13
14 // Insert our CSS and JS
15 add_action( 'load-settings_page_sharing', array( &$this, 'sharing_head' ) );
16
17 // Catch AJAX
18 add_action( 'wp_ajax_sharing_save_services', array( &$this, 'ajax_save_services' ) );
19 add_action( 'wp_ajax_sharing_save_options', array( &$this, 'ajax_save_options' ) );
20 add_action( 'wp_ajax_sharing_new_service', array( &$this, 'ajax_new_service' ) );
21 add_action( 'wp_ajax_sharing_delete_service', array( &$this, 'ajax_delete_service' ) );
22 }
23
24 public function sharing_head() {
25 wp_enqueue_script(
26 'sharing-js',
27 Jetpack::get_file_url_for_environment(
28 '_inc/build/sharedaddy/admin-sharing.min.js',
29 'modules/sharedaddy/admin-sharing.js'
30 ),
31 array( 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-form' ),
32 2
33 );
34
35 /**
36 * Filters the switch that if set to true allows Jetpack to use minified assets. Defaults to true
37 * if the SCRIPT_DEBUG constant is not set or set to false. The filter overrides it.
38 *
39 * @since 6.2.0
40 *
41 * @param boolean $var should Jetpack use minified assets.
42 */
43 $postfix = apply_filters( 'jetpack_should_use_minified_assets', true ) ? '.min' : '';
44 if ( is_rtl() ) {
45 wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing-rtl' . $postfix . '.css', false, JETPACK__VERSION );
46 } else {
47 wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing' . $postfix . '.css', false, JETPACK__VERSION );
48 }
49 wp_enqueue_style( 'sharing', WP_SHARING_PLUGIN_URL . 'sharing.css', false, JETPACK__VERSION );
50
51 wp_enqueue_style( 'social-logos' );
52 wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array(), 4 );
53 add_thickbox();
54 }
55
56 public function admin_init() {
57 if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'sharing.php' || $_GET['page'] == 'sharing' ) ) {
58 $this->process_requests();
59 }
60 }
61
62 public function process_requests() {
63 if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) {
64 $sharer = new Sharing_Service();
65 $sharer->set_global_options( $_POST );
66 /**
67 * Fires when updating sharing settings.
68 *
69 * @module sharedaddy
70 *
71 * @since 1.1.0
72 */
73 do_action( 'sharing_admin_update' );
74
75 wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
76 die();
77 }
78 }
79
80 public function subscription_menu( $user ) {
81 if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
82 $active = Jetpack::get_active_modules();
83 if ( ! in_array( 'publicize', $active ) && ! current_user_can( 'manage_options' ) ) {
84 return;
85 }
86 }
87
88 add_submenu_page( 'options-general.php', __( 'Sharing Settings', 'jetpack' ), __( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', array( &$this, 'management_page' ) );
89 }
90
91 public function ajax_save_services() {
92 if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) && isset( $_POST['hidden'] ) && isset( $_POST['visible'] ) ) {
93 $sharer = new Sharing_Service();
94
95 $sharer->set_blog_services( explode( ',', $_POST['visible'] ), explode( ',', $_POST['hidden'] ) );
96 die();
97 }
98 }
99
100 public function ajax_new_service() {
101 if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['sharing_name'] ) && isset( $_POST['sharing_url'] ) && isset( $_POST['sharing_icon'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-new_service' ) ) {
102 $sharer = new Sharing_Service();
103 if ( $service = $sharer->new_service( stripslashes( $_POST['sharing_name'] ), stripslashes( $_POST['sharing_url'] ), stripslashes( $_POST['sharing_icon'] ) ) ) {
104 $this->output_service( $service->get_id(), $service );
105 echo '<!--->';
106 $service->button_style = 'icon-text';
107 $this->output_preview( $service );
108
109 die();
110 }
111 }
112
113 // Fail
114 die( '1' );
115 }
116
117 public function ajax_delete_service() {
118 if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_' . $_POST['service'] ) ) {
119 $sharer = new Sharing_Service();
120 $sharer->delete_service( $_POST['service'] );
121 }
122 }
123
124 public function ajax_save_options() {
125 if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_' . $_POST['service'] ) ) {
126 $sharer = new Sharing_Service();
127 $service = $sharer->get_service( $_POST['service'] );
128
129 if ( $service && $service instanceof Sharing_Advanced_Source ) {
130 $service->update_options( $_POST );
131
132 $sharer->set_service( $_POST['service'], $service );
133 }
134
135 $this->output_service( $service->get_id(), $service, true );
136 echo '<!--->';
137 $service->button_style = 'icon-text';
138 $this->output_preview( $service );
139 die();
140 }
141 }
142
143 public function output_preview( $service ) {
144 $klasses = array( 'advanced', 'preview-item' );
145
146 if ( $service->button_style != 'text' || $service->has_custom_button_style() ) {
147 $klasses[] = 'preview-' . $service->get_class();
148 $klasses[] = 'share-' . $service->get_class();
149
150 if ( $service->get_class() != $service->get_id() ) {
151 $klasses[] = 'preview-' . $service->get_id();
152 }
153 }
154
155 echo '<li class="' . implode( ' ', $klasses ) . '">';
156 $service->display_preview();
157 echo '</li>';
158 }
159
160 public function output_service( $id, $service, $show_dropdown = false ) {
161 ?>
162 <li class="service advanced share-<?php echo $service->get_class(); ?>" id="<?php echo $service->get_id(); ?>" tabindex="0">
163 <span class="options-left"><?php echo esc_html( $service->get_name() ); ?></span>
164 <?php if ( 0 === strpos( $service->get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?>
165 <span class="close"><a href="#" class="remove">&times;</a></span>
166 <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>">
167 <input type="hidden" name="action" value="sharing_delete_service" />
168 <input type="hidden" name="service" value="<?php echo esc_attr( $id ); ?>" />
169 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options_' . $id );?>" />
170 </form>
171 <?php endif; ?>
172 </li>
173 <?php
174 }
175
176 public function management_page() {
177 $sharer = new Sharing_Service();
178 $enabled = $sharer->get_blog_services();
179 $global = $sharer->get_global_options();
180
181 $shows = array_values( get_post_types( array( 'public' => true ) ) );
182 array_unshift( $shows, 'index' );
183
184 if ( false == function_exists( 'mb_stripos' ) ) {
185 echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>';
186 echo '<p>' . sprintf( __( 'This plugin will work without it, but multibyte support is used <a href="%s" target="_blank">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack' ), 'http://www.php.net/manual/en/mbstring.installation.php' ) . '</p></div>';
187 }
188
189 if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ) {
190 echo '<div class="updated"><p>' . __( 'Settings have been saved', 'jetpack' ) . '</p></div>';
191 }
192
193 if ( ! isset( $global['sharing_label'] ) ) {
194 $global['sharing_label'] = __( 'Share this:', 'jetpack' );
195 }
196 ?>
197
198 <div class="wrap">
199 <div class="icon32" id="icon-options-general"><br /></div>
200 <h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1>
201
202 <?php
203 /**
204 * Fires at the top of the admin sharing settings screen.
205 *
206 * @module sharedaddy
207 *
208 * @since 1.6.0
209 */
210 do_action( 'pre_admin_screen_sharing' );
211 ?>
212
213 <?php if ( current_user_can( 'manage_options' ) ) : ?>
214
215 <div class="share_manage_options">
216 <h2><?php _e( 'Sharing Buttons', 'jetpack' ) ?></h2>
217 <p><?php _e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ) ?></p>
218
219 <div id="services-config">
220 <table id="available-services">
221 <tr>
222 <td class="description">
223 <h3><?php _e( 'Available Services', 'jetpack' ); ?></h3>
224 <p><?php _e( "Drag and drop the services you'd like to enable into the box below.", 'jetpack' ); ?></p>
225 <p><a href="#TB_inline?height=395&amp;width=600&amp;inlineId=new-service" class="thickbox" id="add-a-new-service"><?php _e( 'Add a new service', 'jetpack' ); ?></a></p>
226 </td>
227 <td class="services">
228 <ul class="services-available" style="height: 100px;">
229 <?php foreach ( $sharer->get_all_services_blog() as $id => $service ) : ?>
230 <?php
231 if ( ! isset( $enabled['all'][ $id ] ) ) {
232 $this->output_service( $id, $service );
233 }
234 ?>
235 <?php endforeach; ?>
236 </ul>
237 <?php
238 if ( -1 == get_option( 'blog_public' ) ) {
239 echo '<p><strong>' . __( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . '</strong></p>';
240 }
241 ?>
242 <br class="clearing" />
243 </td>
244 </tr>
245 </table>
246
247 <table id="enabled-services">
248 <tr>
249 <td class="description">
250 <h3>
251 <?php _e( 'Enabled Services', 'jetpack' ); ?>
252 <img src="<?php echo admin_url( 'images/loading.gif' ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
253 </h3>
254 <p><?php _e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p>
255 </td>
256 <td class="services" id="share-drop-target">
257 <h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
258
259 <ul class="services-enabled">
260 <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
261 <?php $this->output_service( $id, $service, true ); ?>
262 <?php endforeach; ?>
263
264 <li class="end-fix"></li>
265 </ul>
266 </td>
267 <td id="hidden-drop-target" class="services">
268 <p><?php _e( 'Services dragged here will be hidden behind a share button.', 'jetpack' ); ?></p>
269
270 <ul class="services-hidden">
271 <?php foreach ( $enabled['hidden'] as $id => $service ) : ?>
272 <?php $this->output_service( $id, $service, true ); ?>
273 <?php endforeach; ?>
274 <li class="end-fix"></li>
275 </ul>
276 </td>
277 </tr>
278 </table>
279
280 <table id="live-preview">
281 <tr>
282 <td class="description">
283 <h3><?php _e( 'Live Preview', 'jetpack' ); ?></h3>
284 </td>
285 <td class="services">
286 <h2 <?php echo ( count( $enabled['all'] ) > 0 ) ? ' style="display: none"' : ''; ?>><?php _e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2>
287 <div class="sharedaddy sd-sharing-enabled">
288 <?php if ( count( $enabled['all'] ) > 0 ) : ?>
289 <h3 class="sd-title"><?php echo esc_html( $global['sharing_label'] ); ?></h3>
290 <?php endif; ?>
291 <div class="sd-content">
292 <ul class="preview">
293 <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
294 <?php $this->output_preview( $service ); ?>
295 <?php endforeach; ?>
296
297 <?php if ( count( $enabled['hidden'] ) > 0 ) : ?>
298 <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e( 'More', 'jetpack' ); ?></span></a></li>
299 <?php endif; ?>
300 </ul>
301
302 <?php if ( count( $enabled['hidden'] ) > 0 ) : ?>
303 <div class="sharing-hidden">
304 <div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) == 1 ? 'width:150px;' : ''; ?>">
305 <?php if ( count( $enabled['hidden'] ) == 1 ) : ?>
306 <ul style="background-image:none;">
307 <?php else : ?>
308 <ul>
309 <?php endif; ?>
310
311 <?php
312 foreach ( $enabled['hidden'] as $id => $service ) {
313 $this->output_preview( $service );
314 }
315 ?>
316 </ul>
317 </div>
318 </div>
319 <?php endif; ?>
320
321 <ul class="archive" style="display:none;">
322 <?php
323 foreach ( $sharer->get_all_services_blog() as $id => $service ) :
324 if ( isset( $enabled['visible'][ $id ] ) ) {
325 $service = $enabled['visible'][ $id ];
326 } elseif ( isset( $enabled['hidden'][ $id ] ) ) {
327 $service = $enabled['hidden'][ $id ];
328 }
329
330 $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later
331 $service->smart = false;
332 $this->output_preview( $service );
333 endforeach; ?>
334 <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e( 'More', 'jetpack' ); ?></span></a></li>
335 </ul>
336 </div>
337 </div>
338 <br class="clearing" />
339 </td>
340 </tr>
341 </table>
342
343 <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" id="save-enabled-shares">
344 <input type="hidden" name="action" value="sharing_save_services" />
345 <input type="hidden" name="visible" value="<?php echo implode( ',', array_keys( $enabled['visible'] ) ); ?>" />
346 <input type="hidden" name="hidden" value="<?php echo implode( ',', array_keys( $enabled['hidden'] ) ); ?>" />
347 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" />
348 </form>
349 </div>
350
351 <form method="post" action="">
352 <table class="form-table">
353 <tbody>
354 <tr valign="top">
355 <th scope="row"><label><?php _e( 'Button style', 'jetpack' ); ?></label></th>
356 <td>
357 <select name="button_style" id="button_style">
358 <option<?php echo ( $global['button_style'] == 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php _e( 'Icon + text', 'jetpack' ); ?></option>
359 <option<?php echo ( $global['button_style'] == 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php _e( 'Icon only', 'jetpack' ); ?></option>
360 <option<?php echo ( $global['button_style'] == 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php _e( 'Text only', 'jetpack' ); ?></option>
361 <option<?php echo ( $global['button_style'] == 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php _e( 'Official buttons', 'jetpack' ); ?></option>
362 </select>
363 </td>
364 </tr>
365 <tr valign="top">
366 <th scope="row"><label><?php _e( 'Sharing label', 'jetpack' ); ?></label></th>
367 <td>
368 <input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" />
369 </td>
370 </tr>
371 <?php
372 /**
373 * Filters the HTML at the beginning of the "Show button on" row.
374 *
375 * @module sharedaddy
376 *
377 * @since 2.1.0
378 *
379 * @param string $var Opening HTML tag at the beginning of the "Show button on" row.
380 */
381 echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' );
382 ?>
383 <th scope="row"><label><?php _e( 'Show buttons on', 'jetpack' ); ?></label></th>
384 <td>
385 <?php
386 $br = false;
387 foreach ( $shows as $show ) :
388 if ( 'index' == $show ) {
389 $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' );
390 } else {
391 $post_type_object = get_post_type_object( $show );
392 $label = $post_type_object->labels->name;
393 }
394 ?>
395 <?php
396 if ( $br ) {
397 echo '<br />';
398 }
399 ?>
400 <label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label>
401 <?php
402 $br = true;
403 endforeach;
404 ?>
405 </td>
406 <?php
407 /**
408 * Filters the HTML at the end of the "Show button on" row.
409 *
410 * @module sharedaddy
411 *
412 * @since 2.1.0
413 *
414 * @param string $var Closing HTML tag at the end of the "Show button on" row.
415 */
416 echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' );
417 ?>
418
419 <?php
420 /**
421 * Fires at the end of the sharing global options settings table.
422 *
423 * @module sharedaddy
424 *
425 * @since 1.1.0
426 */
427 do_action( 'sharing_global_options' );
428 ?>
429 </tbody>
430 </table>
431
432 <p class="submit">
433 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
434 </p>
435
436 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" />
437 </form>
438
439 <div id="new-service" style="display: none">
440 <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" id="new-service-form">
441 <table class="form-table">
442 <tbody>
443 <tr valign="top">
444 <th scope="row" width="100"><label><?php _e( 'Service name', 'jetpack' ); ?></label></th>
445 <td>
446 <input type="text" name="sharing_name" id="new_sharing_name" size="40" />
447 </td>
448 </tr>
449 <tr valign="top">
450 <th scope="row" width="100"><label><?php _e( 'Sharing URL', 'jetpack' ); ?></label></th>
451 <td>
452 <input type="text" name="sharing_url" id="new_sharing_url" size="40" />
453
454 <p><?php _e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/>
455 <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>
456 </td>
457 </tr>
458 <tr valign="top">
459 <th scope="row" width="100"><label><?php _e( 'Icon URL', 'jetpack' ); ?></label></th>
460 <td>
461 <input type="text" name="sharing_icon" id="new_sharing_icon" size="40" />
462 <p><?php _e( 'Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack' ); ?></p>
463 </td>
464 </tr>
465 <tr valign="top" width="100">
466 <th scope="row"></th>
467 <td>
468 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" />
469 <img src="<?php echo admin_url( 'images/loading.gif' ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
470 </td>
471 </tr>
472
473 <?php
474 /**
475 * Fires after the custom sharing service form
476 *
477 * @module sharedaddy
478 *
479 * @since 1.1.0
480 */
481 do_action( 'sharing_new_service_form' );
482 ?>
483 </tbody>
484 </table>
485
486 <?php
487 /**
488 * Fires at the bottom of the admin sharing settings screen.
489 *
490 * @module sharedaddy
491 *
492 * @since 1.6.0
493 */
494 do_action( 'post_admin_screen_sharing' );
495 ?>
496
497 <div class="inerror" style="display: none; margin-top: 15px">
498 <p><?php _e( 'An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack' ); ?></p>
499 </div>
500
501 <input type="hidden" name="action" value="sharing_new_service" />
502 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-new_service' );?>" />
503 </form>
504 </div>
505 </div>
506
507 <?php endif; ?>
508
509
510 </div>
511
512 <script type="text/javascript">
513 var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>';
514 <?php if ( isset( $_GET['create_new_service'] ) && 'true' == $_GET['create_new_service'] ) : ?>
515 jQuery(document).ready(function() {
516 // Prefill new service box and then open it
517 jQuery( '#new_sharing_name' ).val( '<?php echo esc_js( $_GET['name'] ); ?>' );
518 jQuery( '#new_sharing_url' ).val( '<?php echo esc_js( $_GET['url'] ); ?>' );
519 jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js( $_GET['icon'] ); ?>' );
520 jQuery( '#add-a-new-service' ).click();
521 });
522 <?php endif; ?>
523 </script>
524 <?php
525 }
526 }
527
528 function sharing_admin_init() {
529 global $sharing_admin;
530
531 $sharing_admin = new Sharing_Admin();
532 }
533
534 add_action( 'init', 'sharing_admin_init' );
535