| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 4 | 8 | |
| 5 | -use Automattic\Jetpack\Image_CDN\Image_CDN_Core; | |
| 6 | - | |
| 7 | 9 | /** |
| 8 | 10 | * Jetpack_Internet_Defense_League_Widget main class. |
| 9 | 11 | */ |
| 10 | 12 | class Jetpack_Internet_Defense_League_Widget extends WP_Widget { |
| @@ -15,40 +17,8 @@ | ||
| 15 | 17 | */ |
| 16 | 18 | public $defaults = array(); |
| 17 | 19 | |
| 18 | 20 | /** |
| 19 | - * Selected display variant. | |
| 20 | - * | |
| 21 | - * @var string | |
| 22 | - */ | |
| 23 | - public $variant; | |
| 24 | - /** | |
| 25 | - * Display variants. | |
| 26 | - * | |
| 27 | - * @var array | |
| 28 | - */ | |
| 29 | - public $variants = array(); | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Selected campaign. | |
| 33 | - * | |
| 34 | - * @var string | |
| 35 | - */ | |
| 36 | - public $campaign; | |
| 37 | - /** | |
| 38 | - * Campaign options. | |
| 39 | - * | |
| 40 | - * @var array | |
| 41 | - */ | |
| 42 | - public $campaigns = array(); | |
| 43 | - /** | |
| 44 | - * False when enabling campaigns other than 'none' or empty. | |
| 45 | - * | |
| 46 | - * @var bool | |
| 47 | - */ | |
| 48 | - public $no_current = true; | |
| 49 | - | |
| 50 | - /** | |
| 51 | 21 | * Selected badge to display. |
| 52 | 22 | * |
| 53 | 23 | * @var string |
| 54 | 24 | */ |
| @@ -73,19 +43,8 @@ | ||
| 73 | 43 | 'customize_selective_refresh' => true, |
| 74 | 44 | ) |
| 75 | 45 | ); |
| 76 | 46 | |
| 77 | - // When enabling campaigns other than 'none' or empty, change $no_current to false above. | |
| 78 | - $this->campaigns = array( | |
| 79 | - '' => esc_html__( 'All current and future campaigns', 'jetpack' ), | |
| 80 | - 'none' => esc_html__( 'None, just display the badge please', 'jetpack' ), | |
| 81 | - ); | |
| 82 | - | |
| 83 | - $this->variants = array( | |
| 84 | - 'banner' => esc_html__( 'Banner at the top of my site', 'jetpack' ), | |
| 85 | - 'modal' => esc_html__( 'Modal (Overlay Box)', 'jetpack' ), | |
| 86 | - ); | |
| 87 | - | |
| 88 | 47 | $this->badges = array( |
| 89 | 48 | 'shield_badge' => esc_html__( 'Shield Badge', 'jetpack' ), |
| 90 | 49 | 'super_badge' => esc_html__( 'Super Badge', 'jetpack' ), |
| 91 | 50 | 'side_bar_badge' => esc_html__( 'Red Cat Badge', 'jetpack' ), |
| @@ -90,16 +49,10 @@ | ||
| 90 | 49 | 'super_badge' => esc_html__( 'Super Badge', 'jetpack' ), |
| 91 | 50 | 'side_bar_badge' => esc_html__( 'Red Cat Badge', 'jetpack' ), |
| 92 | 51 | ); |
| 93 | 52 | |
| 94 | - if ( false === $this->no_current ) { | |
| 95 | - $this->badges['none'] = esc_html__( 'Don\'t display a badge (just the campaign)', 'jetpack' ); | |
| 96 | - } | |
| 97 | - | |
| 98 | 53 | $this->defaults = array( |
| 99 | - 'campaign' => key( $this->campaigns ), | |
| 100 | - 'variant' => key( $this->variants ), | |
| 101 | - 'badge' => key( $this->badges ), | |
| 54 | + 'badge' => key( $this->badges ), | |
| 102 | 55 | ); |
| 103 | 56 | |
| 104 | 57 | add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); |
| 105 | 58 | } |
| @@ -129,22 +82,22 @@ | ||
| 129 | 82 | if ( 'none' !== $instance['badge'] ) { |
| 130 | 83 | if ( ! isset( $this->badges[ $instance['badge'] ] ) ) { |
| 131 | 84 | $instance['badge'] = $this->defaults['badge']; |
| 132 | 85 | } |
| 133 | - $badge_url = esc_url( 'https://www.internetdefenseleague.org/images/badges/final/' . $instance['badge'] . '.png' ); | |
| 134 | - $photon_badge_url = Image_CDN_Core::cdn_url( $badge_url ); | |
| 135 | - $alt_text = esc_html__( 'Member of The Internet Defense League', 'jetpack' ); | |
| 86 | + $badge_url = 'internet-defense-league/' . $instance['badge'] . '.png'; | |
| 87 | + | |
| 136 | 88 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 137 | - echo '<p><a href="https://www.internetdefenseleague.org/"><img src="' . esc_url( $photon_badge_url ) . '" alt="' . esc_attr( $alt_text ) . '" style="max-width: 100%; height: auto;" /></a></p>'; | |
| 89 | + | |
| 90 | + printf( | |
| 91 | + '<p><a href="%1$s" target="_blank" rel="noopener noreferrer"><img src="%2$s" alt="%3$s" style="max-width: 100%%; height: auto;" /></a></p>', | |
| 92 | + esc_url( 'https://www.fightforthefuture.org/' ), | |
| 93 | + esc_url( plugins_url( $badge_url, __FILE__ ) ), | |
| 94 | + esc_attr__( 'Member of The Internet Defense League', 'jetpack' ) | |
| 95 | + ); | |
| 96 | + | |
| 138 | 97 | echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 139 | 98 | } |
| 140 | 99 | |
| 141 | - if ( 'none' !== $instance['campaign'] ) { | |
| 142 | - $this->campaign = $instance['campaign']; | |
| 143 | - $this->variant = $instance['variant']; | |
| 144 | - add_action( 'wp_footer', array( $this, 'footer_script' ) ); | |
| 145 | - } | |
| 146 | - | |
| 147 | 100 | /** This action is already documented in modules/widgets/gravatar-profile.php */ |
| 148 | 101 | do_action( 'jetpack_stats_extra', 'widget_view', 'internet_defense_league' ); |
| 149 | 102 | } |
| 150 | 103 | |
| @@ -149,36 +102,13 @@ | ||
| 149 | 102 | } |
| 150 | 103 | |
| 151 | 104 | /** |
| 152 | 105 | * Inline footer script. |
| 106 | + * | |
| 107 | + * @deprecated 12.5 This widget does not enqueue scripts anymore. | |
| 153 | 108 | */ |
| 154 | 109 | public function footer_script() { |
| 155 | - if ( ! isset( $this->campaigns[ $this->campaign ] ) ) { | |
| 156 | - $this->campaign = $this->defaults['campaign']; | |
| 157 | - } | |
| 158 | - | |
| 159 | - if ( ! isset( $this->variants[ $this->variant ] ) ) { | |
| 160 | - $this->variant = $this->defaults['variant']; | |
| 161 | - } | |
| 162 | - | |
| 163 | - // On AMP endpoints, prevent a validation error from the inline script. | |
| 164 | - if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { | |
| 165 | - return; | |
| 166 | - } | |
| 167 | - | |
| 168 | - ?> | |
| 169 | - <script type="text/javascript"> | |
| 170 | - window._idl = {}; | |
| 171 | - _idl.campaign = "<?php echo esc_js( $this->campaign ); ?>"; | |
| 172 | - _idl.variant = "<?php echo esc_js( $this->variant ); ?>"; | |
| 173 | - (function() { | |
| 174 | - var idl = document.createElement('script'); | |
| 175 | - idl.async = true; | |
| 176 | - idl.src = 'https://members.internetdefenseleague.org/include/?url=' + (_idl.url || '') + '&campaign=' + (_idl.campaign || '') + '&variant=' + (_idl.variant || 'banner'); | |
| 177 | - document.getElementsByTagName('body')[0].appendChild(idl); | |
| 178 | - })(); | |
| 179 | - </script> | |
| 180 | - <?php | |
| 110 | + _deprecated_function( __METHOD__, 'jetpack-12.5' ); | |
| 181 | 111 | } |
| 182 | 112 | |
| 183 | 113 | /** |
| 184 | 114 | * Widget form in the dashboard. |
| @@ -185,28 +115,21 @@ | ||
| 185 | 115 | * |
| 186 | 116 | * @see WP_Widget::form() |
| 187 | 117 | * |
| 188 | 118 | * @param array $instance Previously saved values from database. |
| 119 | + * @return string|void | |
| 189 | 120 | */ |
| 190 | 121 | public function form( $instance ) { |
| 191 | 122 | $instance = wp_parse_args( $instance, $this->defaults ); |
| 192 | 123 | |
| 193 | - // Hide first two form fields if no current campaigns. | |
| 194 | - if ( false === $this->no_current ) { | |
| 195 | - echo '<p><label>'; | |
| 196 | - echo esc_html__( 'Which Internet Defense League campaign do you want to participate in?', 'jetpack' ) . '<br />'; | |
| 197 | - $this->select( 'campaign', $this->campaigns, $instance['campaign'] ); | |
| 198 | - echo '</label></p>'; | |
| 124 | + echo '<p><label>'; | |
| 125 | + echo esc_html__( 'Which badge would you like to display?', 'jetpack' ) . '<br />'; | |
| 199 | 126 | |
| 200 | - echo '<p><label>'; | |
| 201 | - echo esc_html__( 'How do you want to promote the campaign?', 'jetpack' ) . '<br />'; | |
| 202 | - $this->select( 'variant', $this->variants, $instance['variant'] ); | |
| 203 | - echo '</label></p>'; | |
| 127 | + echo '<select class="widefat" name="' . esc_attr( $this->get_field_name( 'badge' ) ) . '">'; | |
| 128 | + foreach ( $this->badges as $option_slug => $option_name ) { | |
| 129 | + echo '<option value="' . esc_attr( $option_slug ) . '"' . selected( $option_slug, $instance['badge'], false ) . '>' . esc_html( $option_name ) . '</option>'; | |
| 204 | 130 | } |
| 205 | - | |
| 206 | - echo '<p><label>'; | |
| 207 | - echo esc_html__( 'Which badge would you like to display?', 'jetpack' ) . '<br />'; | |
| 208 | - $this->select( 'badge', $this->badges, $instance['badge'] ); | |
| 131 | + echo '</select>'; | |
| 209 | 132 | echo '</label></p>'; |
| 210 | 133 | |
| 211 | 134 | echo '<p>' . wp_kses( |
| 212 | 135 | sprintf( |
| @@ -211,13 +134,15 @@ | ||
| 211 | 134 | echo '<p>' . wp_kses( |
| 212 | 135 | sprintf( |
| 213 | 136 | /* translators: %s is an HTML link to the website of an internet campaign called the "Internet Defense League" */ |
| 214 | 137 | _x( 'Learn more about the %s', 'the Internet Defense League', 'jetpack' ), |
| 215 | - '<a href="https://www.internetdefenseleague.org/">Internet Defense League</a>' | |
| 138 | + '<a href="https://www.fightforthefuture.org/" target="_blank" rel="noopener noreferrer">Internet Defense League</a>' | |
| 216 | 139 | ), |
| 217 | 140 | array( |
| 218 | 141 | 'a' => array( |
| 219 | - 'href' => array(), | |
| 142 | + 'href' => array(), | |
| 143 | + 'rel' => array(), | |
| 144 | + 'target' => array(), | |
| 220 | 145 | ), |
| 221 | 146 | ) |
| 222 | 147 | ) . '</p>'; |
| 223 | 148 | } |
| @@ -224,18 +149,16 @@ | ||
| 224 | 149 | |
| 225 | 150 | /** |
| 226 | 151 | * Display a select form field. |
| 227 | 152 | * |
| 153 | + * @deprecated 12.5 This widget only has one option now, no need for an extracted method. | |
| 154 | + * | |
| 228 | 155 | * @param string $field_name Name of the field. |
| 229 | 156 | * @param array $options Array of options. |
| 230 | 157 | * @param string $default Default option. |
| 231 | 158 | */ |
| 232 | - public function select( $field_name, $options, $default = null ) { | |
| 233 | - echo '<select class="widefat" name="' . esc_attr( $this->get_field_name( $field_name ) ) . '">'; | |
| 234 | - foreach ( $options as $option_slug => $option_name ) { | |
| 235 | - echo '<option value="' . esc_attr( $option_slug ) . '"' . selected( $option_slug, $default, false ) . '>' . esc_html( $option_name ) . '</option>'; | |
| 236 | - } | |
| 237 | - echo '</select>'; | |
| 159 | + public function select( $field_name, $options, $default = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 160 | + _deprecated_function( __METHOD__, 'jetpack-12.5' ); | |
| 238 | 161 | } |
| 239 | 162 | |
| 240 | 163 | /** |
| 241 | 164 | * Update widget. |
| @@ -247,11 +170,11 @@ | ||
| 247 | 170 | */ |
| 248 | 171 | public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 249 | 172 | $instance = array(); |
| 250 | 173 | |
| 251 | - $instance['campaign'] = ( isset( $new_instance['campaign'] ) && isset( $this->campaigns[ $new_instance['campaign'] ] ) ) ? $new_instance['campaign'] : $this->defaults['campaign']; | |
| 252 | - $instance['variant'] = ( isset( $new_instance['variant'] ) && isset( $this->variants[ $new_instance['variant'] ] ) ) ? $new_instance['variant'] : $this->defaults['variant']; | |
| 253 | - $instance['badge'] = ( isset( $new_instance['badge'] ) && isset( $this->badges[ $new_instance['badge'] ] ) ) ? $new_instance['badge'] : $this->defaults['badge']; | |
| 174 | + $instance['badge'] = ( isset( $new_instance['badge'] ) && isset( $this->badges[ $new_instance['badge'] ] ) ) | |
| 175 | + ? $new_instance['badge'] | |
| 176 | + : $this->defaults['badge']; | |
| 254 | 177 | |
| 255 | 178 | return $instance; |
| 256 | 179 | } |
| 257 | 180 | } |
| @@ -261,6 +184,5 @@ | ||
| 261 | 184 | */ |
| 262 | 185 | function jetpack_internet_defense_league_init() { |
| 263 | 186 | register_widget( 'Jetpack_Internet_Defense_League_Widget' ); |
| 264 | 187 | } |
| 265 | - | |
| 266 | 188 | add_action( 'widgets_init', 'jetpack_internet_defense_league_init' ); |