authors
8 years ago
contact-info
5 years ago
eu-cookie-law
4 years ago
facebook-likebox
11 years ago
flickr
4 years ago
gallery
4 years ago
goodreads
5 years ago
google-translate
4 years ago
image-widget
8 years ago
instagram
6 years ago
migrate-to-core
3 years ago
milestone
3 years ago
my-community
8 years ago
simple-payments
4 years ago
social-icons
4 years ago
social-media-icons
5 years ago
top-posts
8 years ago
wordpress-post-widget
3 years ago
authors.php
3 years ago
blog-stats.php
3 years ago
class-jetpack-eu-cookie-law-widget.php
3 years ago
class-jetpack-instagram-widget.php
3 years ago
contact-info.php
3 years ago
customizer-controls.css
9 years ago
customizer-utils.js
6 years ago
facebook-likebox.php
3 years ago
flickr.php
3 years ago
gallery.php
3 years ago
goodreads.php
3 years ago
google-translate.php
3 years ago
gravatar-profile.css
10 years ago
gravatar-profile.php
3 years ago
image-widget.php
3 years ago
internet-defense-league.php
3 years ago
mailchimp.php
3 years ago
milestone.php
5 years ago
my-community.php
3 years ago
rsslinks-widget.php
3 years ago
simple-payments.php
3 years ago
social-icons.php
3 years ago
social-media-icons.php
3 years ago
top-posts.php
3 years ago
twitter-timeline-admin.js
6 years ago
twitter-timeline.php
3 years ago
upcoming-events.php
3 years ago
wordpress-post-widget.php
4 years ago
social-media-icons.php
357 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName.php |
| 2 | /** |
| 3 | * Social Media Icons Widget |
| 4 | * |
| 5 | * This widget is now deprecated. |
| 6 | * Any new features should go into modules/widgets/social-icons.php instead. |
| 7 | * |
| 8 | * @see https://github.com/Automattic/jetpack/pull/8498 |
| 9 | * |
| 10 | * @package automattic/jetpack |
| 11 | */ |
| 12 | |
| 13 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 14 | |
| 15 | /** |
| 16 | * WPCOM_social_media_icons_widget class. |
| 17 | * |
| 18 | * @extends WP_Widget |
| 19 | * |
| 20 | * phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid |
| 21 | */ |
| 22 | class WPCOM_social_media_icons_widget extends WP_Widget { |
| 23 | // phpcs:enable PEAR.NamingConventions.ValidClassName.Invalid |
| 24 | /** |
| 25 | * Defaults |
| 26 | * |
| 27 | * @var mixed |
| 28 | * @access private |
| 29 | */ |
| 30 | private $defaults; |
| 31 | |
| 32 | /** |
| 33 | * Services |
| 34 | * |
| 35 | * @var mixed |
| 36 | * @access private |
| 37 | */ |
| 38 | private $services; |
| 39 | |
| 40 | /** |
| 41 | * __construct function. |
| 42 | * |
| 43 | * @access public |
| 44 | * @return void |
| 45 | */ |
| 46 | public function __construct() { |
| 47 | parent::__construct( |
| 48 | 'wpcom_social_media_icons_widget', |
| 49 | /** This filter is documented in modules/widgets/facebook-likebox.php */ |
| 50 | apply_filters( 'jetpack_widget_name', esc_html__( 'Social Media Icons (Deprecated)', 'jetpack' ) ), |
| 51 | array( |
| 52 | 'description' => __( 'A simple widget that displays social media icons.', 'jetpack' ), |
| 53 | 'customize_selective_refresh' => true, |
| 54 | ) |
| 55 | ); |
| 56 | $this->defaults = array( |
| 57 | 'title' => __( 'Social', 'jetpack' ), |
| 58 | 'facebook_username' => '', |
| 59 | 'twitter_username' => '', |
| 60 | 'instagram_username' => '', |
| 61 | 'pinterest_username' => '', |
| 62 | 'linkedin_username' => '', |
| 63 | 'github_username' => '', |
| 64 | 'youtube_username' => '', |
| 65 | 'vimeo_username' => '', |
| 66 | 'googleplus_username' => '', |
| 67 | 'flickr_username' => '', |
| 68 | 'wordpress_username' => '', |
| 69 | 'twitch_username' => '', |
| 70 | 'tumblr_username' => '', |
| 71 | ); |
| 72 | $this->services = array( |
| 73 | 'facebook' => array( 'Facebook', 'https://www.facebook.com/%s/' ), |
| 74 | 'twitter' => array( 'Twitter', 'https://twitter.com/%s/' ), |
| 75 | 'instagram' => array( 'Instagram', 'https://www.instagram.com/%s/' ), |
| 76 | 'pinterest' => array( 'Pinterest', 'https://www.pinterest.com/%s/' ), |
| 77 | 'linkedin' => array( 'LinkedIn', 'https://www.linkedin.com/in/%s/' ), |
| 78 | 'github' => array( 'GitHub', 'https://github.com/%s/' ), |
| 79 | 'youtube' => array( 'YouTube', 'https://www.youtube.com/%s/' ), |
| 80 | 'vimeo' => array( 'Vimeo', 'https://vimeo.com/%s/' ), |
| 81 | 'googleplus' => array( 'Google+', 'https://plus.google.com/u/0/%s/' ), |
| 82 | 'flickr' => array( 'Flickr', 'https://www.flickr.com/photos/%s/' ), |
| 83 | 'wordpress' => array( 'WordPress.org', 'https://profiles.wordpress.org/%s/' ), |
| 84 | 'twitch' => array( 'Twitch', 'https://www.twitch.tv/%s/' ), |
| 85 | 'tumblr' => array( 'Tumblr', 'https://%s.tumblr.com' ), |
| 86 | ); |
| 87 | if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) { |
| 88 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Enqueue Style. |
| 94 | * |
| 95 | * @access public |
| 96 | * @return void |
| 97 | */ |
| 98 | public function enqueue_style() { |
| 99 | wp_register_style( 'jetpack_social_media_icons_widget', plugins_url( 'social-media-icons/style.css', __FILE__ ), array(), '20150602' ); |
| 100 | wp_enqueue_style( 'jetpack_social_media_icons_widget' ); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Check Genericons. |
| 105 | * |
| 106 | * @access private |
| 107 | * @return Bool. |
| 108 | */ |
| 109 | private function check_genericons() { |
| 110 | global $wp_styles; |
| 111 | foreach ( $wp_styles->queue as $handle ) { |
| 112 | if ( false !== stristr( $handle, 'genericons' ) ) { |
| 113 | return $handle; |
| 114 | } |
| 115 | } |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Widget Front End. |
| 121 | * |
| 122 | * @access public |
| 123 | * @param mixed $args Arguments. |
| 124 | * @param mixed $instance Instance. |
| 125 | * @return void |
| 126 | */ |
| 127 | public function widget( $args, $instance ) { |
| 128 | $instance = wp_parse_args( (array) $instance, $this->defaults ); |
| 129 | /** This filter is documented in core/src/wp-includes/default-widgets.php */ |
| 130 | $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
| 131 | if ( ! $this->check_genericons() ) { |
| 132 | wp_enqueue_style( 'genericons' ); |
| 133 | } |
| 134 | $index = 10; |
| 135 | $html = array(); |
| 136 | /* Translators: 1. Username. 2. Service name. */ |
| 137 | $alt_text = esc_attr__( 'View %1$s’s profile on %2$s', 'jetpack' ); |
| 138 | foreach ( $this->services as $service => $data ) { |
| 139 | list( $service_name, $url ) = $data; |
| 140 | if ( ! isset( $instance[ $service . '_username' ] ) ) { |
| 141 | continue; |
| 142 | } |
| 143 | $link_username = $instance[ $service . '_username' ]; |
| 144 | $username = $link_username; |
| 145 | if ( empty( $username ) ) { |
| 146 | continue; |
| 147 | } |
| 148 | $index += 10; |
| 149 | $predefined_url = false; |
| 150 | |
| 151 | /** Check if full URL entered in configuration, use it instead of tinkering */ |
| 152 | if ( |
| 153 | in_array( |
| 154 | wp_parse_url( $username, PHP_URL_SCHEME ), |
| 155 | array( 'http', 'https' ), |
| 156 | true |
| 157 | ) |
| 158 | ) { |
| 159 | $predefined_url = $username; |
| 160 | |
| 161 | /* |
| 162 | * In case of a predefined link we only display the service name |
| 163 | * for screen readers |
| 164 | */ |
| 165 | $alt_text = '%2$s'; |
| 166 | } |
| 167 | |
| 168 | if ( 'googleplus' === $service |
| 169 | && ! is_numeric( $username ) |
| 170 | && substr( $username, 0, 1 ) !== '+' |
| 171 | ) { |
| 172 | $link_username = '+' . $username; |
| 173 | } |
| 174 | if ( 'youtube' === $service && 'UC' === substr( $username, 0, 2 ) ) { |
| 175 | $link_username = 'channel/' . $username; |
| 176 | } elseif ( 'youtube' === $service ) { |
| 177 | $link_username = 'user/' . $username; |
| 178 | } |
| 179 | |
| 180 | if ( ! $predefined_url ) { |
| 181 | $predefined_url = sprintf( $url, $link_username ); |
| 182 | } |
| 183 | /** |
| 184 | * Fires for each profile link in the social icons widget. Can be used |
| 185 | * to change the links for certain social networks if needed. All URLs |
| 186 | * will be passed through `esc_attr` on output. |
| 187 | * |
| 188 | * @module widgets |
| 189 | * |
| 190 | * @since 3.8.0 |
| 191 | * |
| 192 | * @param string $url the currently processed URL |
| 193 | * @param string $service the lowercase service slug, e.g. 'facebook', 'youtube', etc. |
| 194 | */ |
| 195 | $link = apply_filters( |
| 196 | 'jetpack_social_media_icons_widget_profile_link', |
| 197 | $predefined_url, |
| 198 | $service |
| 199 | ); |
| 200 | $html[ $index ] = sprintf( |
| 201 | '<a href="%1$s" class="genericon genericon-%2$s" target="_blank"><span class="screen-reader-text">%3$s</span></a>', |
| 202 | esc_attr( $link ), |
| 203 | esc_attr( $service ), |
| 204 | sprintf( $alt_text, esc_html( $username ), $service_name ) |
| 205 | ); |
| 206 | } |
| 207 | /** |
| 208 | * Fires at the end of the list of Social Media accounts. |
| 209 | * Can be used to add a new Social Media Site to the Social Media Icons Widget. |
| 210 | * The filter function passed the array of HTML entries that will be sorted |
| 211 | * by key, each wrapped in a list item element and output as an unsorted list. |
| 212 | * |
| 213 | * @module widgets |
| 214 | * |
| 215 | * @since 3.8.0 |
| 216 | * |
| 217 | * @param array $html Associative array of HTML snippets per each icon. |
| 218 | */ |
| 219 | $html = apply_filters( 'jetpack_social_media_icons_widget_array', $html ); |
| 220 | ksort( $html ); |
| 221 | $html = '<ul><li>' . implode( '</li><li>', $html ) . '</li></ul>'; |
| 222 | if ( ! empty( $instance['title'] ) ) { |
| 223 | $html = $args['before_title'] . $instance['title'] . $args['after_title'] . $html; |
| 224 | } |
| 225 | $html = $args['before_widget'] . $html . $args['after_widget']; |
| 226 | |
| 227 | /** This action is documented in modules/widgets/gravatar-profile.php */ |
| 228 | do_action( 'jetpack_stats_extra', 'widget_view', 'social_media_icons' ); |
| 229 | |
| 230 | /** |
| 231 | * Filters the Social Media Icons widget output. |
| 232 | * |
| 233 | * @module widgets |
| 234 | * |
| 235 | * @since 3.6.0 |
| 236 | * |
| 237 | * @param string $html Social Media Icons widget html output. |
| 238 | */ |
| 239 | echo apply_filters( 'jetpack_social_media_icons_widget_output', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Widget Settings. |
| 244 | * |
| 245 | * @access public |
| 246 | * @param mixed $instance Instance. |
| 247 | * @return void |
| 248 | */ |
| 249 | public function form( $instance ) { |
| 250 | $instance = wp_parse_args( (array) $instance, $this->defaults ); |
| 251 | ?> |
| 252 | <p> |
| 253 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'jetpack' ); ?></label> |
| 254 | <input |
| 255 | class="widefat" |
| 256 | id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" |
| 257 | name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
| 258 | type="text" |
| 259 | value="<?php echo esc_attr( $instance['title'] ); ?>" |
| 260 | /> |
| 261 | </p> |
| 262 | <?php |
| 263 | foreach ( $this->services as $service => $data ) { |
| 264 | list( $service_name, $url ) = $data; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 265 | ?> |
| 266 | <p> |
| 267 | <label for="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>"> |
| 268 | <?php |
| 269 | printf( |
| 270 | /* translators: %s is a social network name, e.g. Facebook. */ |
| 271 | esc_html__( '%s username:', 'jetpack' ), |
| 272 | esc_html( $service_name ) |
| 273 | ); |
| 274 | ?> |
| 275 | </label> |
| 276 | <input |
| 277 | class="widefat" |
| 278 | id="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>" |
| 279 | name="<?php echo esc_attr( $this->get_field_name( $service . '_username' ) ); ?>" |
| 280 | type="text" |
| 281 | value="<?php echo esc_attr( $instance[ $service . '_username' ] ); ?>" |
| 282 | /> |
| 283 | </p> |
| 284 | <?php |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Update Widget Settings. |
| 290 | * |
| 291 | * @access public |
| 292 | * @param mixed $new_instance New Instance. |
| 293 | * @param mixed $old_instance Old Instance. |
| 294 | * @return Instance. |
| 295 | */ |
| 296 | public function update( $new_instance, $old_instance ) { |
| 297 | $instance = (array) $old_instance; |
| 298 | foreach ( $new_instance as $field => $value ) { |
| 299 | $instance[ $field ] = sanitize_text_field( $new_instance[ $field ] ); |
| 300 | } |
| 301 | // Stats. |
| 302 | $stats = $instance; |
| 303 | unset( $stats['title'] ); |
| 304 | $stats = array_filter( $stats ); |
| 305 | $stats = array_keys( $stats ); |
| 306 | $stats = array_map( array( $this, 'remove_username' ), $stats ); |
| 307 | foreach ( $stats as $val ) { |
| 308 | /** |
| 309 | * Fires for each Social Media account being saved in the Social Media Widget settings. |
| 310 | * |
| 311 | * @module widgets |
| 312 | * |
| 313 | * @since 3.6.0 |
| 314 | * |
| 315 | * @param string social-media-links-widget-svcs Type of action to track. |
| 316 | * @param string $val Name of the Social Media account being saved. |
| 317 | */ |
| 318 | do_action( 'jetpack_bump_stats_extras', 'social-media-links-widget-svcs', $val ); |
| 319 | } |
| 320 | return $instance; |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Remove username from value before to save stats. |
| 325 | * |
| 326 | * @access public |
| 327 | * @param mixed $val Value. |
| 328 | * @return Value. |
| 329 | */ |
| 330 | public function remove_username( $val ) { |
| 331 | return str_replace( '_username', '', $val ); |
| 332 | } |
| 333 | } // End Class. |
| 334 | |
| 335 | /** |
| 336 | * Register and load the widget. |
| 337 | * |
| 338 | * @access public |
| 339 | * @return void |
| 340 | */ |
| 341 | function wpcom_social_media_icons_widget_load_widget() { |
| 342 | $transient = 'wpcom_social_media_icons_widget::is_active'; |
| 343 | $has_widget = get_transient( $transient ); |
| 344 | |
| 345 | if ( false === $has_widget ) { |
| 346 | $is_active_widget = is_active_widget( false, false, 'wpcom_social_media_icons_widget', false ); |
| 347 | $has_widget = (int) ! empty( $is_active_widget ); |
| 348 | set_transient( $transient, $has_widget, 1 * HOUR_IN_SECONDS ); |
| 349 | } |
| 350 | |
| 351 | // [DEPRECATION]: Only register widget if active widget exists already |
| 352 | if ( $has_widget ) { |
| 353 | register_widget( 'wpcom_social_media_icons_widget' ); |
| 354 | } |
| 355 | } |
| 356 | add_action( 'widgets_init', 'wpcom_social_media_icons_widget_load_widget' ); |
| 357 |