PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.1
Jetpack – WP Security, Backup, Speed, & Growth v6.1
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.1, at modules/sharedaddy/sharing.php

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