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

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