Sharing_Admin

The Jetpack by WordPress.com Sharing Admin class.

Defined (1)

The class is defined in the following location(s).

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