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

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