Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Widget for inserting an ad into your sidebar |
||
| 5 | * |
||
| 6 | * @since 4.5.0 |
||
| 7 | */ |
||
| 8 | class WordAds_Sidebar_Widget extends WP_Widget { |
||
| 9 | |||
| 10 | private static $allowed_tags = array( 'mrec', 'wideskyscraper' ); |
||
| 11 | |||
| 12 | View Code Duplication | function __construct() { |
|
| 13 | parent::__construct( |
||
| 14 | 'wordads_sidebar_widget', |
||
| 15 | /** This filter is documented in modules/widgets/facebook-likebox.php */ |
||
| 16 | apply_filters( 'jetpack_widget_name', 'Ads' ), |
||
| 17 | array( |
||
| 18 | 'description' => __( 'Insert a WordAd wherever you can place a widget.', 'jetpack' ), |
||
| 19 | 'customize_selective_refresh' => true |
||
| 20 | ) |
||
| 21 | ); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function widget( $args, $instance ) { |
||
| 25 | global $wordads; |
||
| 26 | if ( $wordads->should_bail() ) { |
||
| 27 | return false; |
||
| 28 | } |
||
| 29 | |||
| 30 | $about = __( 'About these ads', 'jetpack' ); |
||
| 31 | $width = WordAds::$ad_tag_ids[$instance['unit']]['width']; |
||
| 32 | $height = WordAds::$ad_tag_ids[$instance['unit']]['height']; |
||
| 33 | $snippet = ''; |
||
|
0 ignored issues
–
show
|
|||
| 34 | if ( $wordads->option( 'wordads_house', true ) ) { |
||
| 35 | $ad_url = 'https://s0.wp.com/wp-content/blog-plugins/wordads/house/'; |
||
| 36 | if ( 'leaderboard' == $instance['unit'] && ! $this->params->mobile_device ) { |
||
| 37 | $ad_url .= 'leaderboard.png'; |
||
| 38 | } else if ( 'wideskyscraper' == $instance['unit'] ) { |
||
| 39 | $ad_url .= 'widesky.png'; |
||
| 40 | } else { |
||
| 41 | $ad_url .= 'mrec.png'; |
||
| 42 | } |
||
| 43 | |||
| 44 | $snippet = <<<HTML |
||
| 45 | <a href="https://wordpress.com/create/" target="_blank"> |
||
| 46 | <img src="$ad_url" alt="WordPress.com: Grow Your Business" width="$width" height="$height" /> |
||
| 47 | </a> |
||
| 48 | HTML; |
||
| 49 | } else { |
||
| 50 | $section_id = 0 === $wordads->params->blog_id ? WORDADS_API_TEST_ID : $wordads->params->blog_id . '3'; |
||
| 51 | $data_tags = ( $wordads->params->cloudflare ) ? ' data-cfasync="false"' : ''; |
||
| 52 | $snippet = <<<HTML |
||
| 53 | <script$data_tags type='text/javascript'> |
||
| 54 | (function(g){g.__ATA.initAd({sectionId:$section_id, width:$width, height:$height});})(window); |
||
| 55 | </script> |
||
| 56 | HTML; |
||
| 57 | } |
||
| 58 | |||
| 59 | echo <<< HTML |
||
| 60 | <div class="wpcnt"> |
||
| 61 | <div class="wpa"> |
||
| 62 | <a class="wpa-about" href="https://en.wordpress.com/about-these-ads/" rel="nofollow">$about</a> |
||
| 63 | <div class="u {$instance['unit']}"> |
||
| 64 | $snippet |
||
| 65 | </div> |
||
| 66 | </div> |
||
| 67 | </div> |
||
| 68 | HTML; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function form( $instance ) { |
||
| 72 | // ad unit type |
||
| 73 | if ( isset( $instance['unit'] ) ) { |
||
| 74 | $unit = $instance['unit']; |
||
| 75 | } else { |
||
| 76 | $unit = 'mrec'; |
||
| 77 | } |
||
| 78 | ?> |
||
| 79 | <p> |
||
| 80 | <label for="<?php echo esc_attr( $this->get_field_id( 'unit' ) ); ?>"><?php _e( 'Tag Dimensions:', 'jetpack' ); ?></label> |
||
| 81 | <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'unit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'unit' ) ); ?>"> |
||
| 82 | <?php |
||
| 83 | foreach ( WordAds::$ad_tag_ids as $ad_unit => $properties ) { |
||
| 84 | if ( ! in_array( $ad_unit, self::$allowed_tags ) ) { |
||
| 85 | continue; |
||
| 86 | } |
||
| 87 | |||
| 88 | $splits = explode( '_', $properties['tag'] ); |
||
| 89 | $unit_pretty = "{$splits[0]} {$splits[1]}"; |
||
| 90 | $selected = selected( $ad_unit, $unit, false ); |
||
| 91 | echo "<option value='", esc_attr( $ad_unit ) ,"' ", $selected, '>', esc_html( $unit_pretty ) , '</option>'; |
||
| 92 | } |
||
| 93 | ?> |
||
| 94 | </select> |
||
| 95 | </p> |
||
| 96 | <?php |
||
| 97 | } |
||
| 98 | |||
| 99 | public function update( $new_instance, $old_instance ) { |
||
| 100 | $instance = $old_instance; |
||
| 101 | |||
| 102 | if ( in_array( $new_instance['unit'], self::$allowed_tags ) ) { |
||
| 103 | $instance['unit'] = $new_instance['unit']; |
||
| 104 | } else { |
||
| 105 | $instance['unit'] = 'mrec'; |
||
| 106 | } |
||
| 107 | |||
| 108 | return $instance; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | add_action( |
||
| 113 | 'widgets_init', |
||
| 114 | create_function( |
||
|
0 ignored issues
–
show
The use of
create_function is highly discouraged, better use a closure.
// Instead of
$function = create_function('$a, $b', 'return $a + $b');
// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
|
|||
| 115 | '', |
||
| 116 | 'return register_widget( "WordAds_Sidebar_Widget" );' |
||
| 117 | ) |
||
| 118 | ); |
||
| 119 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.