-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadrotate-widget.php
164 lines (137 loc) · 6.42 KB
/
adrotate-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/* ------------------------------------------------------------------------------------
* COPYRIGHT AND TRADEMARK NOTICE
* Copyright 2008-2025 Arnan de Gans. All Rights Reserved.
* ADROTATE is a registered trademark of Arnan de Gans.
* COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
* By using this code you agree to indemnify Arnan de Gans from any
* liability that might arise from its use.
------------------------------------------------------------------------------------ */
function adrotate_widget() {
register_widget('adrotate_widgets');
}
/*-------------------------------------------------------------
Name: adrotate_widget
Purpose: Unlimited widgets for the sidebar
Since: 0.8
-------------------------------------------------------------*/
class adrotate_widgets extends WP_Widget {
/*-------------------------------------------------------------
Purpose: Construct the widget
-------------------------------------------------------------*/
public function __construct() {
$widget_ops = array(
'classname' => 'adrotate_widgets',
'description' => 'Show a group of adverts or a single advert in any widget area.',
);
parent::__construct('adrotate_widgets', 'AdRotate', $widget_ops);
}
/*-------------------------------------------------------------
Purpose: Display the widget
-------------------------------------------------------------*/
public function widget($args, $instance) {
global $adrotate_config, $blog_id;
extract($args);
if(empty($instance['adid'])) $instance['adid'] = 0;
if(empty($instance['siteid'])) $instance['siteid'] = $blog_id;
if(empty($instance['title'])) $instance['title'] = '';
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if($title) {
echo $before_title . $title . $after_title;
}
if($adrotate_config['widgetalign'] == 'Y') echo '<ul><li>';
if($adrotate_config['w3caching'] == 'Y') {
echo "<!-- mfunc ".W3TC_DYNAMIC_SECURITY." -->";
if($instance['type'] == "single") {
echo "echo adrotate_ad(".$instance['adid'].", true);";
}
if($instance['type'] == "group") {
echo "echo adrotate_group(".$instance['adid'].");";
}
echo "<!-- /mfunc ".W3TC_DYNAMIC_SECURITY." -->";
} else if($adrotate_config['borlabscache'] == 'Y' AND function_exists('BorlabsCacheHelper') AND BorlabsCacheHelper()->willFragmentCachingPerform()) {
$borlabsphrase = BorlabsCacheHelper()->getFragmentCachingPhrase();
echo "<!--[borlabs cache start: ".$borlabsphrase."]-->";
if($instance['type'] == 'single') {
echo "echo adrotate_ad(".$instance['adid'].", true);";
}
if($instance['type'] == 'group') {
echo "echo adrotate_group(".$instance['adid'].");";
}
echo "<!--[borlabs cache end: ".$borlabsphrase."]-->";
unset($borlabsphrase);
} else {
if($instance['type'] == 'single') {
echo adrotate_ad($instance['adid'], true);
}
if($instance['type'] == 'group') {
echo adrotate_group($instance['adid']);
}
}
if($adrotate_config['widgetalign'] == 'Y') echo '</li></ul>';
echo $after_widget;
}
/*-------------------------------------------------------------
Purpose: Save the widget options per instance
-------------------------------------------------------------*/
public function update($new_instance, $old_instance) {
$new_instance['title'] = strip_tags($new_instance['title']);
$new_instance['description'] = strip_tags($new_instance['description']);
$new_instance['type'] = strip_tags($new_instance['type']);
//Try and preserve pre-fix widget IDs
if(isset($new_instance['id']) and $new_instance['adid'] < 1) {
$new_instance['adid'] = $new_instance['id'];
} else {
$new_instance['adid'] = strip_tags($new_instance['adid']);
}
$new_instance['siteid'] = strip_tags($new_instance['siteid']);
$instance = wp_parse_args($new_instance, $old_instance);
return $instance;
}
/*-------------------------------------------------------------
Purpose: Display the widget options for admins
-------------------------------------------------------------*/
public function form($instance) {
global $blog_id;
$defaults = array();
$instance = wp_parse_args( (array) $instance, $defaults );
$title = $description = $type = $adid = '';
extract($instance);
$title = sanitize_title($title);
$description = sanitize_text_field($description);
$type = sanitize_key($type);
$adid = sanitize_key($adid);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title (optional):', 'adrotate' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
<br />
<small><?php _e( 'HTML will be stripped out.', 'adrotate' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('description'); ?>"><?php _e( 'Description (optional):', 'adrotate' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" type="text" value="<?php echo $description; ?>" />
<br />
<small><?php _e( 'What is this widget used for? (Not parsed, HTML will be stripped out.)', 'adrotate' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('type'); ?>"><?php _e( 'Type:', 'adrotate' ); ?></label>
<select class="widefat" id="<?php echo $this->get_field_id('type'); ?>" name="<?php echo $this->get_field_name('type'); ?>" class="postform">
<option value="single" <?php if($type == "single") { echo 'selected'; } ?>><?php _e( 'Advert - Use Advert ID', 'adrotate' ); ?></option>
<option value="group" <?php if($type == "group") { echo 'selected'; } ?>><?php _e( 'Group - Use group ID', 'adrotate' ); ?></option>
</select>
<br />
<small><?php _e( 'Choose what you want to use this widget for', 'adrotate' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('adid'); ?>"><?php _e( 'ID:', 'adrotate' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('adid'); ?>" name="<?php echo $this->get_field_name('adid'); ?>" type="text" value="<?php echo $adid; ?>" />
<br />
<small><?php _e( 'Fill in the ID of the type you want to display!', 'adrotate' ); ?></small>
</p>
<input id="<?php echo $this->get_field_id('siteid'); ?>" name="<?php echo $this->get_field_name('siteid'); ?>" type="hidden" value="<?php echo $blog_id; ?>" />
<?php
}
}
?>