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

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