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

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