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 an ad unit 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
|
|
|
if ( ! isset( $instance['unit'] ) ) { |
31
|
|
|
$instance['unit'] = 'mrec'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$about = __( 'Advertisements', 'jetpack' ); |
35
|
|
|
$width = WordAds::$ad_tag_ids[$instance['unit']]['width']; |
36
|
|
|
$height = WordAds::$ad_tag_ids[$instance['unit']]['height']; |
37
|
|
|
|
38
|
|
|
$snippet = ''; |
|
|
|
|
39
|
|
|
if ( $wordads->option( 'wordads_house', true ) ) { |
40
|
|
|
$unit = 'mrec'; |
41
|
|
|
if ( 'leaderboard' == $instance['unit'] && ! $this->params->mobile_device ) { |
42
|
|
|
$unit = 'leaderboard'; |
43
|
|
|
} else if ( 'wideskyscraper' == $instance['unit'] ) { |
44
|
|
|
$unit = 'widesky'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$snippet = $wordads->get_house_ad( $unit ); |
48
|
|
|
} else { |
49
|
|
|
$section_id = 0 === $wordads->params->blog_id ? WORDADS_API_TEST_ID : $wordads->params->blog_id . '3'; |
50
|
|
|
$snippet = $wordads->get_ad_snippet( $section_id, $height, $width ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
echo <<< HTML |
54
|
|
|
<div class="wpcnt"> |
55
|
|
|
<div class="wpa"> |
56
|
|
|
<span class="wpa-about">$about</span> |
57
|
|
|
<div class="u {$instance['unit']}"> |
58
|
|
|
$snippet |
59
|
|
|
</div> |
60
|
|
|
</div> |
61
|
|
|
</div> |
62
|
|
|
HTML; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function form( $instance ) { |
66
|
|
|
// ad unit type |
67
|
|
|
if ( isset( $instance['unit'] ) ) { |
68
|
|
|
$unit = $instance['unit']; |
69
|
|
|
} else { |
70
|
|
|
$unit = 'mrec'; |
71
|
|
|
} |
72
|
|
|
?> |
73
|
|
|
<p> |
74
|
|
|
<label for="<?php echo esc_attr( $this->get_field_id( 'unit' ) ); ?>"><?php _e( 'Tag Dimensions:', 'jetpack' ); ?></label> |
75
|
|
|
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'unit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'unit' ) ); ?>"> |
76
|
|
|
<?php |
77
|
|
|
foreach ( WordAds::$ad_tag_ids as $ad_unit => $properties ) { |
78
|
|
|
if ( ! in_array( $ad_unit, self::$allowed_tags ) ) { |
79
|
|
|
continue; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$splits = explode( '_', $properties['tag'] ); |
83
|
|
|
$unit_pretty = "{$splits[0]} {$splits[1]}"; |
84
|
|
|
$selected = selected( $ad_unit, $unit, false ); |
85
|
|
|
echo "<option value='", esc_attr( $ad_unit ) ,"' ", $selected, '>', esc_html( $unit_pretty ) , '</option>'; |
86
|
|
|
} |
87
|
|
|
?> |
88
|
|
|
</select> |
89
|
|
|
</p> |
90
|
|
|
<?php |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function update( $new_instance, $old_instance ) { |
94
|
|
|
$instance = $old_instance; |
95
|
|
|
|
96
|
|
|
if ( in_array( $new_instance['unit'], self::$allowed_tags ) ) { |
97
|
|
|
$instance['unit'] = $new_instance['unit']; |
98
|
|
|
} else { |
99
|
|
|
$instance['unit'] = 'mrec'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $instance; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
add_action( |
107
|
|
|
'widgets_init', |
108
|
|
|
create_function( |
|
|
|
|
109
|
|
|
'', |
110
|
|
|
'return register_widget( "WordAds_Sidebar_Widget" );' |
111
|
|
|
) |
112
|
|
|
); |
113
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.