/modules/sharedaddy/sharing-service.php

  1. <?php 
  2.  
  3. include_once dirname( __FILE__ ).'/sharing-sources.php'; 
  4.  
  5. define( 'WP_SHARING_PLUGIN_VERSION', JETPACK__VERSION ); 
  6.  
  7. class Sharing_Service { 
  8. private $global = false; 
  9. public $default_sharing_label = ''; 
  10.  
  11. public function __construct() { 
  12. $this->default_sharing_label = __( 'Share this:', 'jetpack' ); 
  13.  
  14. /** 
  15. * Gets a generic list of all services, without any config 
  16. */ 
  17. public function get_all_services_blog() { 
  18. $options = get_option( 'sharing-options' ); 
  19.  
  20. $all = $this->get_all_services(); 
  21. $services = array(); 
  22.  
  23. foreach ( $all AS $id => $name ) { 
  24. if ( isset( $all[$id] ) ) { 
  25. $config = array(); 
  26.  
  27. // Pre-load custom modules otherwise they won't know who they are 
  28. if ( substr( $id, 0, 7 ) == 'custom-' && is_array( $options[$id] ) ) 
  29. $config = $options[$id]; 
  30.  
  31. $services[$id] = new $all[$id]( $id, $config ); 
  32.  
  33. return $services; 
  34.  
  35. /** 
  36. * Gets a list of all available service names and classes 
  37. */ 
  38. public function get_all_services( $include_custom = true ) { 
  39. // Default services 
  40. // if you update this list, please update the REST API tests 
  41. // in bin/tests/api/suites/SharingTest.php 
  42. $services = array( 
  43. 'email' => 'Share_Email',  
  44. 'print' => 'Share_Print',  
  45. 'facebook' => 'Share_Facebook',  
  46. 'linkedin' => 'Share_LinkedIn',  
  47. 'reddit' => 'Share_Reddit',  
  48. 'twitter' => 'Share_Twitter',  
  49. 'press-this' => 'Share_PressThis',  
  50. 'google-plus-1' => 'Share_GooglePlus1',  
  51. 'tumblr' => 'Share_Tumblr',  
  52. 'pinterest' => 'Share_Pinterest',  
  53. 'pocket' => 'Share_Pocket',  
  54. ); 
  55.  
  56. if ( $include_custom ) { 
  57. // Add any custom services in 
  58. $options = $this->get_global_options(); 
  59. foreach ( (array) $options['custom'] AS $custom_id ) { 
  60. $services[$custom_id] = 'Share_Custom'; 
  61.  
  62. /** 
  63. * Filters the list of available Sharing Services. 
  64. * 
  65. * @module sharedaddy 
  66. * 
  67. * @since 1.1.0 
  68. * 
  69. * @param array $services Array of all available Sharing Services. 
  70. */ 
  71. return apply_filters( 'sharing_services', $services ); 
  72.  
  73. public function new_service( $label, $url, $icon ) { 
  74. // Validate 
  75. $label = trim( wp_html_excerpt( wp_kses( $label, array() ), 30 ) ); 
  76. $url = trim( esc_url_raw( $url ) ); 
  77. $icon = trim( esc_url_raw( $icon ) ); 
  78.  
  79. if ( $label && $url && $icon ) { 
  80. $options = get_option( 'sharing-options' ); 
  81. if ( !is_array( $options ) ) 
  82. $options = array(); 
  83.  
  84. $service_id = 'custom-'.time(); 
  85.  
  86. // Add a new custom service 
  87. $options['global']['custom'][] = $service_id; 
  88. if ( false !== $this->global ) { 
  89. $this->global['custom'][] = $service_id; 
  90.  
  91. update_option( 'sharing-options', $options ); 
  92.  
  93. // Create a custom service and set the options for it 
  94. $service = new Share_Custom( $service_id, array( 'name' => $label, 'url' => $url, 'icon' => $icon ) ); 
  95. $this->set_service( $service_id, $service ); 
  96.  
  97. // Return the service 
  98. return $service; 
  99.  
  100. return false; 
  101.  
  102. public function delete_service( $service_id ) { 
  103. $options = get_option( 'sharing-options' ); 
  104. if ( isset( $options[$service_id] ) ) 
  105. unset( $options[$service_id] ); 
  106.  
  107. $key = array_search( $service_id, $options['global']['custom'] ); 
  108. if ( $key !== false ) 
  109. unset( $options['global']['custom'][$key] ); 
  110.  
  111. update_option( 'sharing-options', $options ); 
  112. return true; 
  113.  
  114. public function set_blog_services( array $visible, array $hidden ) { 
  115. $services = $this->get_all_services(); 
  116. // Validate the services 
  117. $available = array_keys( $services ); 
  118.  
  119. // Only allow services that we have defined 
  120. $hidden = array_intersect( $hidden, $available ); 
  121. $visible = array_intersect( $visible, $available ); 
  122.  
  123. // Ensure we don't have the same ones in hidden and visible 
  124. $hidden = array_diff( $hidden, $visible ); 
  125.  
  126. /** 
  127. * Control the state of the list of sharing services. 
  128. * 
  129. * @module sharedaddy 
  130. * 
  131. * @since 1.1.0 
  132. * 
  133. * @param array $args { 
  134. * Array of options describing the state of the sharing services. 
  135. * 
  136. * @type array $services List of all available service names and classes. 
  137. * @type array $available Validated list of all available service names and classes. 
  138. * @type array $hidden List of services hidden behind a "More" button. 
  139. * @type array $visible List of visible services. 
  140. * @type array $this->get_blog_services() Array of Sharing Services currently enabled. 
  141. * } 
  142. */ 
  143. do_action( 'sharing_get_services_state', array( 
  144. 'services' => $services,  
  145. 'available' => $available,  
  146. 'hidden' => $hidden,  
  147. 'visible' => $visible,  
  148. 'currently_enabled' => $this->get_blog_services() 
  149. ) ); 
  150.  
  151. update_option( 'sharing-services', array( 'visible' => $visible, 'hidden' => $hidden ) ); 
  152.  
  153. public function get_blog_services() { 
  154. $options = get_option( 'sharing-options' ); 
  155. $enabled = get_option( 'sharing-services' ); 
  156. $services = $this->get_all_services(); 
  157.  
  158. if ( !is_array( $options ) ) 
  159. $options = array( 'global' => $this->get_global_options() ); 
  160.  
  161. $global = $options['global']; 
  162.  
  163. // Default services 
  164. if ( ! is_array( $enabled ) ) { 
  165. $enabled = array( 
  166. 'visible' => array(),  
  167. 'hidden' => array() 
  168. ); 
  169.  
  170. /** 
  171. * Filters the list of default Sharing Services. 
  172. * 
  173. * @module sharedaddy 
  174. * 
  175. * @since 1.1.0 
  176. * 
  177. * @param array $enabled Array of default Sharing Services. 
  178. */ 
  179. $enabled = apply_filters( 'sharing_default_services', $enabled ); 
  180.  
  181. // Cleanup after any filters that may have produced duplicate services 
  182. $enabled['visible'] = array_unique( $enabled['visible'] ); 
  183. $enabled['hidden'] = array_unique( $enabled['hidden'] ); 
  184.  
  185. // Form the enabled services 
  186. $blog = array( 'visible' => array(), 'hidden' => array() ); 
  187.  
  188. foreach ( $blog AS $area => $stuff ) { 
  189. foreach ( (array)$enabled[$area] AS $service ) { 
  190. if ( isset( $services[$service] ) ) { 
  191. $blog[$area][$service] = new $services[$service]( $service, array_merge( $global, isset( $options[$service] ) ? $options[$service] : array() ) ); 
  192.  
  193. /** 
  194. * Filters the list of enabled Sharing Services. 
  195. * 
  196. * @module sharedaddy 
  197. * 
  198. * @since 1.1.0 
  199. * 
  200. * @param array $blog Array of enabled Sharing Services. 
  201. */ 
  202. $blog = apply_filters( 'sharing_services_enabled', $blog ); 
  203.  
  204. // Add CSS for NASCAR 
  205. if ( count( $blog['visible'] ) || count( $blog['hidden'] ) ) 
  206. add_filter( 'post_flair_block_css', 'post_flair_service_enabled_sharing' ); 
  207.  
  208. // Convenience for checking if a service is present 
  209. $blog['all'] = array_flip( array_merge( array_keys( $blog['visible'] ), array_keys( $blog['hidden'] ) ) ); 
  210. return $blog; 
  211.  
  212. public function get_service( $service_name ) { 
  213. $services = $this->get_blog_services(); 
  214.  
  215. if ( isset( $services['visible'][$service_name] ) ) 
  216. return $services['visible'][$service_name]; 
  217.  
  218. if ( isset( $services['hidden'][$service_name] ) ) 
  219. return $services['hidden'][$service_name]; 
  220.  
  221. return false; 
  222.  
  223. public function set_global_options( $data ) { 
  224. $options = get_option( 'sharing-options' ); 
  225.  
  226. // No options yet 
  227. if ( !is_array( $options ) ) 
  228. $options = array(); 
  229.  
  230. // Defaults 
  231. $options['global'] = array( 
  232. 'button_style' => 'icon-text',  
  233. 'sharing_label' => $this->default_sharing_label,  
  234. 'open_links' => 'same',  
  235. 'show' => array(),  
  236. 'custom' => isset( $options['global']['custom'] ) ? $options['global']['custom'] : array() 
  237. ); 
  238.  
  239. /** 
  240. * Filters global sharing settings. 
  241. * 
  242. * @module sharedaddy 
  243. * 
  244. * @since 1.1.0 
  245. * 
  246. * @param array $options['global'] Array of global sharing settings. 
  247. */ 
  248. $options['global'] = apply_filters( 'sharing_default_global', $options['global'] ); 
  249.  
  250. // Validate options and set from our data 
  251. if ( isset( $data['button_style'] ) && in_array( $data['button_style'], array( 'icon-text', 'icon', 'text', 'official' ) ) ) 
  252. $options['global']['button_style'] = $data['button_style']; 
  253.  
  254. if ( isset( $data['sharing_label'] ) ) { 
  255. if ( $this->default_sharing_label === $data['sharing_label'] ) { 
  256. $options['global']['sharing_label'] = false; 
  257. } else { 
  258. $options['global']['sharing_label'] = trim( wp_kses( stripslashes( $data['sharing_label'] ), array() ) ); 
  259.  
  260. if ( isset( $data['open_links'] ) && in_array( $data['open_links'], array( 'new', 'same' ) ) ) 
  261. $options['global']['open_links'] = $data['open_links']; 
  262.  
  263. $shows = array_values( get_post_types( array( 'public' => true ) ) ); 
  264. $shows[] = 'index'; 
  265. if ( isset( $data['show'] ) ) { 
  266. if ( is_scalar( $data['show'] ) ) { 
  267. switch ( $data['show'] ) { 
  268. case 'posts' : 
  269. $data['show'] = array( 'post', 'page' ); 
  270. break; 
  271. case 'index' : 
  272. $data['show'] = array( 'index' ); 
  273. break; 
  274. case 'posts-index' : 
  275. $data['show'] = array( 'post', 'page', 'index' ); 
  276. break; 
  277.  
  278. if ( $data['show'] = array_intersect( $data['show'], $shows ) ) { 
  279. $options['global']['show'] = $data['show']; 
  280.  
  281. update_option( 'sharing-options', $options ); 
  282. return $options['global']; 
  283.  
  284. public function get_global_options() { 
  285. if ( $this->global === false ) { 
  286. $options = get_option( 'sharing-options' ); 
  287.  
  288. if ( is_array( $options ) && isset( $options['global'] ) ) 
  289. $this->global = $options['global']; 
  290. else 
  291. $this->global = $this->set_global_options( $options['global'] ); 
  292.  
  293. if ( ! isset( $this->global['show'] ) ) { 
  294. $this->global['show'] = array( 'post', 'page' ); 
  295. } elseif ( is_scalar( $this->global['show'] ) ) { 
  296. switch ( $this->global['show'] ) { 
  297. case 'posts' : 
  298. $this->global['show'] = array( 'post', 'page' ); 
  299. break; 
  300. case 'index' : 
  301. $this->global['show'] = array( 'index' ); 
  302. break; 
  303. case 'posts-index' : 
  304. $this->global['show'] = array( 'post', 'page', 'index' ); 
  305. break; 
  306.  
  307. if ( false === $this->global['sharing_label'] ) { 
  308. $this->global['sharing_label'] = $this->default_sharing_label; 
  309.  
  310. return $this->global; 
  311.  
  312. public function set_service( $id, Sharing_Source $service ) { 
  313. // Update the options for this service 
  314. $options = get_option( 'sharing-options' ); 
  315.  
  316. // No options yet 
  317. if ( ! is_array( $options ) ) { 
  318. $options = array(); 
  319.  
  320. /** 
  321. * Get the state of a sharing button. 
  322. * 
  323. * @module sharedaddy 
  324. * 
  325. * @since 1.1.0 
  326. * 
  327. * @param array $args { 
  328. * State of a sharing button. 
  329. * 
  330. * @type string $id Service ID. 
  331. * @type array $options Array of all sharing options. 
  332. * @type array $service Details about a service. 
  333. * } 
  334. */ 
  335. do_action( 'sharing_get_button_state', array( 'id' => $id, 'options' => $options, 'service' => $service ) ); 
  336.  
  337. $options[$id] = $service->get_options(); 
  338.  
  339. update_option( 'sharing-options', array_filter( $options ) ); 
  340.  
  341. // Soon to come to a .org plugin near you! 
  342. public function get_total( $service_name = false, $post_id = false, $_blog_id = false ) { 
  343. global $wpdb, $blog_id; 
  344. if ( !$_blog_id ) { 
  345. $_blog_id = $blog_id; 
  346. if ( $service_name == false ) { 
  347. if ( $post_id > 0 ) { 
  348. // total number of shares for this post 
  349. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND post_id = %d", $_blog_id, $post_id ) ); 
  350. } else { 
  351. // total number of shares for this blog 
  352. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d", $_blog_id ) ); 
  353.  
  354. if ( $post_id > 0 ) 
  355. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s", $_blog_id, $post_id, $service_name ) ); 
  356. else 
  357. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s", $_blog_id, $service_name ) ); 
  358.  
  359. public function get_services_total( $post_id = false ) { 
  360. $totals = array(); 
  361. $services = $this->get_blog_services(); 
  362.  
  363. if ( !empty( $services ) && isset( $services[ 'all' ] ) ) 
  364. foreach( $services[ 'all' ] as $key => $value ) { 
  365. $totals[$key] = new Sharing_Service_Total( $key, $this->get_total( $key, $post_id ) ); 
  366. usort( $totals, array( 'Sharing_Service_Total', 'cmp' ) ); 
  367.  
  368. return $totals; 
  369.  
  370. public function get_posts_total() { 
  371. $totals = array(); 
  372. global $wpdb, $blog_id; 
  373.  
  374. $my_data = $wpdb->get_results( $wpdb->prepare( "SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d GROUP BY post_id ORDER BY count DESC ", $blog_id ) ); 
  375.  
  376. if ( !empty( $my_data ) ) 
  377. foreach( $my_data as $row ) 
  378. $totals[] = new Sharing_Post_Total( $row->id, $row->total ); 
  379.  
  380. usort( $totals, array( 'Sharing_Post_Total', 'cmp' ) ); 
  381.  
  382. return $totals; 
  383.  
  384. class Sharing_Service_Total { 
  385. public $id = ''; 
  386. public $name = ''; 
  387. public $service = ''; 
  388. public $total = 0; 
  389.  
  390. public function __construct( $id, $total ) { 
  391. $services = new Sharing_Service(); 
  392. $this->id = esc_html( $id ); 
  393. $this->service = $services->get_service( $id ); 
  394. $this->total = (int) $total; 
  395.  
  396. $this->name = $this->service->get_name(); 
  397.  
  398. static function cmp( $a, $b ) { 
  399. if ( $a->total == $b->total ) 
  400. return $a->name < $b->name; 
  401. return $a->total < $b->total; 
  402.  
  403. class Sharing_Post_Total { 
  404. public $id = 0; 
  405. public $total = 0; 
  406. public $title = ''; 
  407. public $url = ''; 
  408.  
  409. public function __construct( $id, $total ) { 
  410. $this->id = (int) $id; 
  411. $this->total = (int) $total; 
  412. $this->title = get_the_title( $this->id ); 
  413. $this->url = get_permalink( $this->id ); 
  414.  
  415. static function cmp( $a, $b ) { 
  416. if ( $a->total == $b->total ) 
  417. return $a->id < $b->id; 
  418. return $a->total < $b->total; 
  419.  
  420. function sharing_register_post_for_share_counts( $post_id ) { 
  421. global $jetpack_sharing_counts; 
  422.  
  423. if ( ! isset( $jetpack_sharing_counts ) || ! is_array( $jetpack_sharing_counts ) ) 
  424. $jetpack_sharing_counts = array(); 
  425.  
  426. $jetpack_sharing_counts[ (int) $post_id ] = get_permalink( $post_id ); 
  427.  
  428. function sharing_maybe_enqueue_scripts() { 
  429. $sharer = new Sharing_Service(); 
  430. $global_options = $sharer->get_global_options(); 
  431.  
  432. $enqueue = false; 
  433. if ( is_singular() && in_array( get_post_type(), $global_options['show'] ) ) { 
  434. $enqueue = true; 
  435. } elseif ( in_array( 'index', $global_options['show'] ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global_options['show'] ) ) ) { 
  436. $enqueue = true; 
  437.  
  438. /** 
  439. * Filter to decide when sharing scripts should be enqueued. 
  440. * 
  441. * @module sharedaddy 
  442. * 
  443. * @since 3.2.0 
  444. * 
  445. * @param bool $enqueue Decide if the sharing scripts should be enqueued. 
  446. */ 
  447. return (bool) apply_filters( 'sharing_enqueue_scripts', $enqueue ); 
  448.  
  449. function sharing_add_footer() { 
  450. global $jetpack_sharing_counts; 
  451.  
  452. /** 
  453. * Filter all Javascript output by the sharing module. 
  454. * 
  455. * @module sharedaddy 
  456. * 
  457. * @since 1.1.0 
  458. * 
  459. * @param bool true Control whether the sharing module should add any Javascript to the site. Default to true. 
  460. */ 
  461. if ( apply_filters( 'sharing_js', true ) && sharing_maybe_enqueue_scripts() ) { 
  462.  
  463. /** 
  464. * Filter the display of sharing counts next to the sharing buttons. 
  465. * 
  466. * @module sharedaddy 
  467. * 
  468. * @since 3.2.0 
  469. * 
  470. * @param bool true Control the display of counters next to the sharing buttons. Default to true. 
  471. */ 
  472. if ( apply_filters( 'jetpack_sharing_counts', true ) && is_array( $jetpack_sharing_counts ) && count( $jetpack_sharing_counts ) ) : 
  473. $sharing_post_urls = array_filter( $jetpack_sharing_counts ); 
  474. if ( $sharing_post_urls ) : 
  475. ?> 
  476.  
  477. <script type="text/javascript"> 
  478. window.WPCOM_sharing_counts = <?php echo json_encode( array_flip( $sharing_post_urls ) ); ?>; 
  479. </script> 
  480. <?php 
  481. endif; 
  482. endif; 
  483.  
  484. wp_enqueue_script( 'sharing-js' ); 
  485. $sharing_js_options = array( 
  486. 'lang' => get_base_recaptcha_lang_code(),  
  487. /** This filter is documented in modules/sharedaddy/sharing-service.php */ 
  488. 'counts' => apply_filters( 'jetpack_sharing_counts', true ) 
  489. ); 
  490. wp_localize_script( 'sharing-js', 'sharing_js_options', $sharing_js_options); 
  491.  
  492. $sharer = new Sharing_Service(); 
  493. $enabled = $sharer->get_blog_services(); 
  494. foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) AS $service ) { 
  495. $service->display_footer(); 
  496.  
  497. function sharing_add_header() { 
  498. $sharer = new Sharing_Service(); 
  499. $enabled = $sharer->get_blog_services(); 
  500.  
  501. foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) AS $service ) { 
  502. $service->display_header(); 
  503.  
  504. if ( count( $enabled['all'] ) > 0 && sharing_maybe_enqueue_scripts() ) { 
  505. wp_enqueue_style( 'sharedaddy', plugin_dir_url( __FILE__ ) .'sharing.css', array(), JETPACK__VERSION ); 
  506. wp_enqueue_style( 'genericons' ); 
  507.  
  508. add_action( 'wp_head', 'sharing_add_header', 1 ); 
  509.  
  510. function sharing_process_requests() { 
  511. global $post; 
  512.  
  513. // Only process if: single post and share=X defined 
  514. if ( ( is_page() || is_single() ) && isset( $_GET['share'] ) ) { 
  515. $sharer = new Sharing_Service(); 
  516.  
  517. $service = $sharer->get_service( $_GET['share'] ); 
  518. if ( $service ) { 
  519. $service->process_request( $post, $_POST ); 
  520. add_action( 'template_redirect', 'sharing_process_requests', 9 ); 
  521.  
  522. function sharing_display( $text = '', $echo = false ) { 
  523. global $post, $wp_current_filter; 
  524.  
  525. if ( empty( $post ) ) 
  526. return $text; 
  527.  
  528. if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 
  529. return $text; 
  530.  
  531. // Don't output flair on excerpts 
  532. if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) { 
  533. return $text; 
  534.  
  535. // Don't allow flair to be added to the_content more than once (prevent infinite loops) 
  536. $done = false; 
  537. foreach ( $wp_current_filter as $filter ) { 
  538. if ( 'the_content' == $filter ) { 
  539. if ( $done ) 
  540. return $text; 
  541. else 
  542. $done = true; 
  543.  
  544. // check whether we are viewing the front page and whether the front page option is checked 
  545. $options = get_option( 'sharing-options' ); 
  546. $display_options = $options['global']['show']; 
  547.  
  548. if ( is_front_page() && ( is_array( $display_options ) && ! in_array( 'index', $display_options ) ) ) 
  549. return $text; 
  550.  
  551. if ( is_attachment() && in_array( 'the_excerpt', (array) $wp_current_filter ) ) { 
  552. // Many themes run the_excerpt() conditionally on an attachment page, then run the_content(). 
  553. // We only want to output the sharing buttons once. Let's stick with the_content(). 
  554. return $text; 
  555.  
  556. $sharer = new Sharing_Service(); 
  557. $global = $sharer->get_global_options(); 
  558.  
  559. $show = false; 
  560. if ( !is_feed() ) { 
  561. if ( is_singular() && in_array( get_post_type(), $global['show'] ) ) { 
  562. $show = true; 
  563. } elseif ( in_array( 'index', $global['show'] ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global['show'] ) ) ) { 
  564. $show = true; 
  565.  
  566. /** 
  567. * Filter to decide if sharing buttons should be displayed. 
  568. * 
  569. * @module sharedaddy 
  570. * 
  571. * @since 1.1.0 
  572. * 
  573. * @param bool $show Should the sharing buttons be displayed. 
  574. * @param WP_Post $post The post to share. 
  575. */ 
  576. $show = apply_filters( 'sharing_show', $show, $post ); 
  577.  
  578. // Disabled for this post? 
  579. $switched_status = get_post_meta( $post->ID, 'sharing_disabled', false ); 
  580.  
  581. if ( !empty( $switched_status ) ) 
  582. $show = false; 
  583.  
  584. // Private post? 
  585. $post_status = get_post_status( $post->ID ); 
  586.  
  587. if ( 'private' === $post_status ) { 
  588. $show = false; 
  589.  
  590. // Allow to be used on P2 ajax requests for latest posts. 
  591. if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'get_latest_posts' == $_REQUEST['action'] ) 
  592. $show = true; 
  593.  
  594. $sharing_content = ''; 
  595.  
  596. if ( $show ) { 
  597. /** 
  598. * Filters the list of enabled Sharing Services. 
  599. * 
  600. * @module sharedaddy 
  601. * 
  602. * @since 2.2.3 
  603. * 
  604. * @param array $sharer->get_blog_services() Array of Sharing Services currently enabled. 
  605. */ 
  606. $enabled = apply_filters( 'sharing_enabled', $sharer->get_blog_services() ); 
  607.  
  608. if ( count( $enabled['all'] ) > 0 ) { 
  609. global $post; 
  610.  
  611. $dir = get_option( 'text_direction' ); 
  612.  
  613. // Wrapper 
  614. $sharing_content .= '<div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-' . $global['button_style'] . ' sd-sharing">'; 
  615. if ( $global['sharing_label'] != '' ) 
  616. $sharing_content .= '<h3 class="sd-title">' . $global['sharing_label'] . '</h3>'; 
  617. $sharing_content .= '<div class="sd-content"><ul>'; 
  618.  
  619. // Visible items 
  620. $visible = ''; 
  621. foreach ( $enabled['visible'] as $id => $service ) { 
  622. // Individual HTML for sharing service 
  623. $visible .= '<li class="share-' . $service->get_class() . '">' . $service->get_display( $post ) . '</li>'; 
  624.  
  625. $parts = array(); 
  626. $parts[] = $visible; 
  627. if ( count( $enabled['hidden'] ) > 0 ) { 
  628. if ( count( $enabled['visible'] ) > 0 ) 
  629. $expand = __( 'More', 'jetpack' ); 
  630. else 
  631. $expand = __( 'Share', 'jetpack' ); 
  632. $parts[] = '<li><a href="#" class="sharing-anchor sd-button share-more"><span>'.$expand.'</span></a></li>'; 
  633.  
  634. if ( $dir == 'rtl' ) 
  635. $parts = array_reverse( $parts ); 
  636.  
  637. $sharing_content .= implode( '', $parts ); 
  638. $sharing_content .= '<li class="share-end"></li></ul>'; 
  639.  
  640. if ( count( $enabled['hidden'] ) > 0 ) { 
  641. $sharing_content .= '<div class="sharing-hidden"><div class="inner" style="display: none;'; 
  642.  
  643. if ( count( $enabled['hidden'] ) == 1 ) 
  644. $sharing_content .= 'width:150px;'; 
  645.  
  646. $sharing_content .= '">'; 
  647.  
  648. if ( count( $enabled['hidden'] ) == 1 ) 
  649. $sharing_content .= '<ul style="background-image:none;">'; 
  650. else 
  651. $sharing_content .= '<ul>'; 
  652.  
  653. $count = 1; 
  654. foreach ( $enabled['hidden'] as $id => $service ) { 
  655. // Individual HTML for sharing service 
  656. $sharing_content .= '<li class="share-'.$service->get_class().'">'; 
  657. $sharing_content .= $service->get_display( $post ); 
  658. $sharing_content .= '</li>'; 
  659.  
  660. if ( ( $count % 2 ) == 0 ) 
  661. $sharing_content .= '<li class="share-end"></li>'; 
  662.  
  663. $count ++; 
  664.  
  665. // End of wrapper 
  666. $sharing_content .= '<li class="share-end"></li></ul></div></div>'; 
  667.  
  668. $sharing_content .= '</div></div></div>'; 
  669.  
  670. // Register our JS 
  671. if ( defined( 'JETPACK__VERSION' ) ) { 
  672. $ver = JETPACK__VERSION; 
  673. } else { 
  674. $ver = '20141212'; 
  675. wp_register_script( 'sharing-js', plugin_dir_url( __FILE__ ).'sharing.js', array( 'jquery' ), $ver ); 
  676. add_action( 'wp_footer', 'sharing_add_footer' ); 
  677.  
  678. /** 
  679. * Filters the content markup of the Jetpack sharing links 
  680. * 
  681. * @module sharedaddy 
  682. * 
  683. * @since 3.8.0 
  684. * 
  685. * @param string $sharing_content Content markup of the Jetpack sharing links 
  686. */ 
  687. $sharing_markup = apply_filters( 'jetpack_sharing_display_markup', $sharing_content ); 
  688.  
  689. if ( $echo ) 
  690. echo $text . $sharing_markup; 
  691. else 
  692. return $text . $sharing_markup; 
  693.  
  694. add_filter( 'the_content', 'sharing_display', 19 ); 
  695. add_filter( 'the_excerpt', 'sharing_display', 19 ); 
  696. function get_base_recaptcha_lang_code() { 
  697.  
  698. $base_recaptcha_lang_code_mapping = array( 
  699. 'en' => 'en',  
  700. 'nl' => 'nl',  
  701. 'fr' => 'fr',  
  702. 'fr-be' => 'fr',  
  703. 'fr-ca' => 'fr',  
  704. 'fr-ch' => 'fr',  
  705. 'de' => 'de',  
  706. 'pt' => 'pt',  
  707. 'pt-br' => 'pt',  
  708. 'ru' => 'ru',  
  709. 'es' => 'es',  
  710. 'tr' => 'tr' 
  711. ); 
  712.  
  713. $blog_lang_code = function_exists( 'get_blog_lang_code' ) ? get_blog_lang_code() : get_bloginfo( 'language' ); 
  714. if( isset( $base_recaptcha_lang_code_mapping[ $blog_lang_code ] ) ) 
  715. return $base_recaptcha_lang_code_mapping[ $blog_lang_code ]; 
  716.  
  717. // if no base mapping is found return default 'en' 
  718. return 'en'; 
.