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