AdRotate Banner Manager - Version 3.11

Version Description

FREE = * NOTE: Due to an earlier bugfix you may need to open/edit each AdRotate widget and click 'Save' * [tweak] Impression timer can be 10 again, default remains 60 * [tweak] Updated links for new ajdg.solutions website * [fix] Impression counting using the right timestamp

NOTE: Certain features are exclusive to AdRotate PRO. If you need these features please consider upgrading to AdRotate PRO.

Download this release

Release Info

Developer adegans
Plugin Icon 128x128 AdRotate Banner Manager
Version 3.11
Comparing to
See all releases

Version 3.11

Files changed (64) hide show
  1. adrotate-export.php +64 -0
  2. adrotate-functions.php +938 -0
  3. adrotate-manage-publisher.php +720 -0
  4. adrotate-output.php +1018 -0
  5. adrotate-setup.php +1024 -0
  6. adrotate-statistics.php +365 -0
  7. adrotate-widget.php +145 -0
  8. adrotate.php +984 -0
  9. dashboard/adrotate-info.php +209 -0
  10. dashboard/adrotate-pro.php +98 -0
  11. dashboard/index.php +3 -0
  12. dashboard/publisher/adrotate-ads-edit.php +489 -0
  13. dashboard/publisher/adrotate-ads-main-disabled.php +88 -0
  14. dashboard/publisher/adrotate-ads-main-error.php +81 -0
  15. dashboard/publisher/adrotate-ads-main.php +110 -0
  16. dashboard/publisher/adrotate-ads-report.php +58 -0
  17. dashboard/publisher/adrotate-groups-edit.php +407 -0
  18. dashboard/publisher/adrotate-groups-main.php +88 -0
  19. dashboard/publisher/adrotate-groups-report.php +64 -0
  20. dashboard/publisher/index.php +3 -0
  21. dashboard/server/adrotate-active.php +78 -0
  22. dashboard/server/adrotate-error.php +80 -0
  23. dashboard/server/adrotate-settings.php +67 -0
  24. dashboard/server/index.php +3 -0
  25. images/adrotate-logo-60x60.png +0 -0
  26. images/adrotate-product.png +0 -0
  27. images/ajdg-logo-100x60.png +0 -0
  28. images/close_icon.png +0 -0
  29. images/demo-advertisers.jpg +0 -0
  30. images/demo-geotargetting.jpg +0 -0
  31. images/demo-notifications.jpg +0 -0
  32. images/demo-schedules.jpg +0 -0
  33. images/icon.png +0 -0
  34. images/index.php +3 -0
  35. index.php +3 -0
  36. language/adrotate-bg_BG.mo +0 -0
  37. language/adrotate-bg_BG.po +3086 -0
  38. language/adrotate-el.mo +0 -0
  39. language/adrotate-el.po +3362 -0
  40. language/adrotate-en_US.mo +0 -0
  41. language/adrotate-en_US.po +3262 -0
  42. language/adrotate-es_ES.mo +0 -0
  43. language/adrotate-es_ES.po +3140 -0
  44. language/adrotate-fr_FR.mo +0 -0
  45. language/adrotate-fr_FR.po +2749 -0
  46. language/adrotate-ja.mo +0 -0
  47. language/adrotate-ja.po +4130 -0
  48. language/adrotate-pl_PL.mo +0 -0
  49. language/adrotate-pl_PL.po +3094 -0
  50. language/adrotate-sr_RS.mo +0 -0
  51. language/adrotate-sr_RS.po +3627 -0
  52. language/adrotate-sv_SV.mo +0 -0
  53. language/adrotate-sv_SV.po +3430 -0
  54. language/index.php +3 -0
  55. library/dashboard.css +29 -0
  56. library/elycharts.min.js +8 -0
  57. library/index.php +3 -0
  58. library/jquery.adrotate.clicktracker.js +30 -0
  59. library/jquery.adrotate.dyngroup.js +114 -0
  60. library/jquery.adrotate.responsive.js +72 -0
  61. library/raphael-min.js +11 -0
  62. library/textatcursor.js +48 -0
  63. library/uploader-hook.js +40 -0
  64. readme.txt +144 -0
adrotate-export.php ADDED
@@ -0,0 +1,64 @@
1
+ <?php
2
+ /* ------------------------------------------------------------------------------------
3
+ * COPYRIGHT AND TRADEMARK NOTICE
4
+ * Copyright 2008-2015 AJdG Solutions (Arnan de Gans). All Rights Reserved.
5
+ * ADROTATE is a trademark of Arnan de Gans.
6
+
7
+ * COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
8
+ * By using this code you agree to indemnify Arnan de Gans from any
9
+ * liability that might arise from it's use.
10
+ ------------------------------------------------------------------------------------ */
11
+
12
+ /*-------------------------------------------------------------
13
+ Name: adrotate_export_ads
14
+
15
+ Purpose: Export adverts in various formats
16
+ Receive: $ids, $format
17
+ Return: -- None --
18
+ Since: 3.11
19
+ -------------------------------------------------------------*/
20
+ function adrotate_export_ads($ids) {
21
+ global $wpdb;
22
+
23
+ $all_ads = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."adrotate` ORDER BY `id` ASC;", ARRAY_A);
24
+
25
+ $filename = "AdRotate_export_".date_i18n("mdYHi")."_".uniqid().".xml";
26
+ $fp = fopen(WP_CONTENT_DIR . '/reports/'.$filename, 'r');
27
+
28
+ $xml = new SimpleXMLElement('<adverts></adverts>');
29
+
30
+ foreach($all_ads as $single) {
31
+ if(in_array($single['id'], $ids)) {
32
+ $starttime = $stoptime = 0;
33
+ $starttime = $wpdb->get_var("SELECT `starttime` FROM `".$wpdb->prefix."adrotate_schedule`, `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = '".$single['id']."' AND `schedule` = `".$wpdb->prefix."adrotate_schedule`.`id` ORDER BY `starttime` ASC LIMIT 1;");
34
+ $stoptime = $wpdb->get_var("SELECT `stoptime` FROM `".$wpdb->prefix."adrotate_schedule`, `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = '".$single['id']."' AND `schedule` = `".$wpdb->prefix."adrotate_schedule`.`id` ORDER BY `stoptime` DESC LIMIT 1;");
35
+
36
+ if(!is_array($single['cities'])) $single['cities'] = array();
37
+ if(!is_array($single['countries'])) $single['countries'] = array();
38
+
39
+ $node = $xml->addChild('advert');
40
+ $node->addChild('title', $single['title']);
41
+ $node->addChild('bannercode', stripslashes($single['bannercode']));
42
+ $node->addChild('imagetype', $single['imagetype']);
43
+ $node->addChild('image', $single['image']);
44
+ $node->addChild('link', $single['link']);
45
+ $node->addChild('tracker', $single['tracker']);
46
+ $node->addChild('responsive', $single['responsive']);
47
+ $node->addChild('weight', $single['weight']);
48
+ $node->addChild('cbudget', $single['cbudget']);
49
+ $node->addChild('ibudget', $single['ibudget']);
50
+ $node->addChild('crate', $single['crate']);
51
+ $node->addChild('irate', $single['irate']);
52
+ $node->addChild('cities', implode(',', unserialize($single['cities'])));
53
+ $node->addChild('countries', implode(',', unserialize($single['countries'])));
54
+ $node->addChild('start', $starttime);
55
+ $node->addChild('end', $stoptime);
56
+ }
57
+ }
58
+
59
+ file_put_contents(WP_CONTENT_DIR . '/reports/'.$filename, $xml->saveXML());
60
+
61
+ adrotate_return('exported', array($filename));
62
+ exit;
63
+ }
64
+ ?>
adrotate-functions.php ADDED
@@ -0,0 +1,938 @@
1
+ <?php
2
+ /* ------------------------------------------------------------------------------------
3
+ * COPYRIGHT AND TRADEMARK NOTICE
4
+ * Copyright 2008-2015 AJdG Solutions (Arnan de Gans). All Rights Reserved.
5
+ * ADROTATE is a trademark of Arnan de Gans.
6
+
7
+ * COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
8
+ * By using this code you agree to indemnify Arnan de Gans from any
9
+ * liability that might arise from it's use.
10
+ ------------------------------------------------------------------------------------ */
11
+
12
+ /*-------------------------------------------------------------
13
+ Name: adrotate_shortcode
14
+
15
+ Purpose: Prepare function requests for calls on shortcodes
16
+ Receive: $atts, $content
17
+ Return: Function()
18
+ Since: 0.7
19
+ -------------------------------------------------------------*/
20
+ function adrotate_shortcode($atts, $content = null) {
21
+ global $adrotate_config;
22
+
23
+ $banner_id = $group_ids = $block_id = $fallback = $weight = $site = 0;
24
+ if(!empty($atts['banner'])) $banner_id = trim($atts['banner'], "\r\t ");
25
+ if(!empty($atts['group'])) $group_ids = trim($atts['group'], "\r\t ");
26
+ if(!empty($atts['block'])) $block_id = trim($atts['block'], "\r\t ");
27
+ if(!empty($atts['fallback'])) $fallback = trim($atts['fallback'], "\r\t "); // Optional for groups (override)
28
+ if(!empty($atts['weight'])) $weight = trim($atts['weight'], "\r\t "); // Optional for groups (override)
29
+ if(!empty($atts['site'])) $site = 0; // Not supported in free version
30
+
31
+ $output = '';
32
+
33
+ if($adrotate_config['w3caching'] == "Y") $output .= '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
34
+
35
+ if($banner_id > 0 AND ($group_ids == 0 OR $group_ids > 0) AND $block_id == 0) { // Show one Ad
36
+ if($adrotate_config['supercache'] == "Y") $output .= '<!--mfunc echo adrotate_ad('.$banner_id.', true, 0, 0) -->';
37
+ $output .= adrotate_ad($banner_id, true, 0, 0);
38
+ if($adrotate_config['supercache'] == "Y") $output .= '<!--/mfunc-->';
39
+ }
40
+
41
+ if($banner_id == 0 AND $group_ids > 0 AND $block_id == 0) { // Show group
42
+ if($adrotate_config['supercache'] == "Y") $output .= '<!--mfunc echo adrotate_group('.$group_ids.', '.$fallback.', '.$weight.') -->';
43
+ $output .= adrotate_group($group_ids, $fallback, $weight);
44
+ if($adrotate_config['supercache'] == "Y") $output .= '<!--/mfunc-->';
45
+ }
46
+
47
+ if($banner_id == 0 AND $group_ids == 0 AND $block_id > 0) { // Show block
48
+ if($adrotate_config['supercache'] == "Y") $output .= '<!--mfunc echo adrotate_block( $block_id, $weight ) -->';
49
+ $output .= adrotate_block($block_id, $weight);
50
+ if($adrotate_config['supercache'] == "Y") $output .= '<!--/mfunc-->';
51
+ }
52
+
53
+ if($adrotate_config['w3caching'] == "Y") $output .= '<!-- /mfunc -->';
54
+
55
+ return $output;
56
+ }
57
+
58
+ /*-------------------------------------------------------------
59
+ Name: adrotate_is_networked
60
+
61
+ Purpose: Determine if AdRotate is network activated
62
+ Receive: -None-
63
+ Return: Boolean
64
+ Since: 3.9.8
65
+ -------------------------------------------------------------*/
66
+ function adrotate_is_networked() {
67
+ if(!function_exists( 'is_plugin_active_for_network')) require_once(ABSPATH.'/wp-admin/includes/plugin.php');
68
+
69
+ if(is_plugin_active_for_network(ADROTATE_FOLDER.'/adrotate.php')) {
70
+ return true;
71
+ }
72
+ return false;
73
+ }
74
+
75
+ /*-------------------------------------------------------------
76
+ Name: adrotate_is_bot
77
+
78
+ Purpose: Check if visitor is a bot
79
+ Receive: -None-
80
+ Return: Boolean
81
+ Since: 3.11.10
82
+ -------------------------------------------------------------*/
83
+ function adrotate_is_bot() {
84
+ global $adrotate_crawlers;
85
+
86
+ if(is_array($adrotate_crawlers)) {
87
+ $crawlers = $adrotate_crawlers;
88
+ } else {
89
+ $crawlers = array();
90
+ }
91
+
92
+ if(isset($_SERVER['HTTP_USER_AGENT'])) {
93
+ $useragent = $_SERVER['HTTP_USER_AGENT'];
94
+ $useragent = trim($useragent, ' \t\r\n\0\x0B');
95
+ } else {
96
+ $useragent = '';
97
+ }
98
+
99
+ if(strlen($useragent) > 0) {
100
+ $nocrawler = true;
101
+ foreach($crawlers as $crawler) {
102
+ if(preg_match("/$crawler/i", $useragent)) $nocrawler = false;
103
+ }
104
+ } else {
105
+ $nocrawler = false;
106
+ }
107
+
108
+ // Returns true if no bot.
109
+ return $nocrawler;
110
+ }
111
+
112
+ /*-------------------------------------------------------------
113
+ Name: adrotate_count_impression
114
+
115
+ Purpose: Count Impressions where needed
116
+ Receive: $ad, $group
117
+ Return: -None-
118
+ Since: 3.10.12
119
+ -------------------------------------------------------------*/
120
+ function adrotate_count_impression($ad, $group = 0, $blog_id = 0, $impression_timer = 0) {
121
+ global $wpdb, $adrotate_config, $adrotate_debug;
122
+
123
+ if(($adrotate_config['enable_loggedin_impressions'] == 'Y' AND is_user_logged_in()) OR !is_user_logged_in()) {
124
+ $now = adrotate_now();
125
+ $today = adrotate_date_start('day');
126
+ $remote_ip = adrotate_get_remote_ip();
127
+
128
+ if($adrotate_debug['timers'] == true) {
129
+ $impression_timer = $now;
130
+ } else {
131
+ $impression_timer = $now - $impression_timer;
132
+ }
133
+
134
+ $saved_timer = $wpdb->get_var($wpdb->prepare("SELECT `timer` FROM `".$wpdb->prefix."adrotate_tracker` WHERE `ipaddress` = '%s' AND `stat` = 'i' AND `bannerid` = %d ORDER BY `timer` DESC LIMIT 1;", $remote_ip, $ad));
135
+ if($saved_timer < $impression_timer AND adrotate_is_bot()) {
136
+ $stats = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `".$wpdb->prefix."adrotate_stats` WHERE `ad` = %d AND `group` = %d AND `thetime` = $today;", $ad, $group));
137
+ if($stats > 0) {
138
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate_stats` SET `impressions` = `impressions` + 1 WHERE `id` = $stats;");
139
+ } else {
140
+ $wpdb->insert($wpdb->prefix.'adrotate_stats', array('ad' => $ad, 'group' => $group, 'block' => 0, 'thetime' => $today, 'clicks' => 0, 'impressions' => 1));
141
+ }
142
+
143
+ $wpdb->insert($wpdb->prefix."adrotate_tracker", array('ipaddress' => $remote_ip, 'timer' => $now, 'bannerid' => $ad, 'stat' => 'i', 'useragent' => '', 'country' => '', 'city' => ''));
144
+ }
145
+ }
146
+ }
147
+
148
+ /*-------------------------------------------------------------
149
+ Name: adrotate_impression_callback
150
+
151
+ Purpose: Register a impression for dynamic groups
152
+ Receive: $_POST
153
+ Return: -None-
154
+ Since: 3.10.14
155
+ -------------------------------------------------------------*/
156
+ function adrotate_impression_callback() {
157
+ global $adrotate_debug;
158
+
159
+ $meta = $_POST['track'];
160
+ if($adrotate_debug['track'] != true) {
161
+ $meta = base64_decode($meta);
162
+ }
163
+
164
+ $meta = esc_attr($meta);
165
+ list($ad, $group, $blog_id, $impression_timer) = explode(",", $meta, 4);
166
+ adrotate_count_impression($ad, $group, $blog_id, $impression_timer);
167
+
168
+ die();
169
+ }
170
+
171
+
172
+ /*-------------------------------------------------------------
173
+ Name: adrotate_click_callback
174
+
175
+ Purpose: Register clicks for clicktracking
176
+ Receive: $_POST
177
+ Return: -None-
178
+ Since: 3.10.14
179
+ -------------------------------------------------------------*/
180
+ function adrotate_click_callback() {
181
+ global $wpdb, $adrotate_config, $adrotate_debug;
182
+
183
+ $meta = $_POST['track'];
184
+
185
+ if($adrotate_debug['track'] != true) {
186
+ $meta = base64_decode($meta);
187
+ }
188
+
189
+ $meta = esc_attr($meta);
190
+ list($ad, $group, $blog_id, $impression_timer) = explode(",", $meta, 4);
191
+
192
+ if(is_numeric($ad) AND is_numeric($group) AND is_numeric($blog_id)) {
193
+ if(($adrotate_config['enable_loggedin_clicks'] == 'Y' AND is_user_logged_in()) OR !is_user_logged_in()) {
194
+ $remote_ip = adrotate_get_remote_ip();
195
+
196
+ if(adrotate_is_bot() AND $remote_ip != "unknown" AND !empty($remote_ip)) {
197
+ $now = adrotate_now();
198
+ $today = adrotate_date_start('day');
199
+
200
+ if($adrotate_debug['timers'] == true) {
201
+ $click_timer = $now;
202
+ } else {
203
+ $click_timer = $now - $adrotate_config['click_timer'];
204
+ }
205
+
206
+ $saved_timer = $wpdb->get_var($wpdb->prepare("SELECT `timer` FROM `".$wpdb->prefix."adrotate_tracker` WHERE `ipaddress` = '%s' AND `stat` = 'c' AND `bannerid` = %d ORDER BY `timer` DESC LIMIT 1;", $remote_ip, $ad));
207
+ if($saved_timer < $click_timer) {
208
+ $stats = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `".$wpdb->prefix."adrotate_stats` WHERE `ad` = %d AND `group` = %d AND `thetime` = $today;", $ad, $group));
209
+ if($stats > 0) {
210
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate_stats` SET `clicks` = `clicks` + 1 WHERE `id` = $stats;");
211
+ } else {
212
+ $wpdb->insert($wpdb->prefix.'adrotate_stats', array('ad' => $ad, 'group' => $group, 'block' => 0, 'thetime' => $today, 'clicks' => 1, 'impressions' => 1));
213
+ }
214
+
215
+ $wpdb->insert($wpdb->prefix.'adrotate_tracker', array('ipaddress' => $remote_ip, 'timer' => $now, 'bannerid' => $ad, 'stat' => 'c', 'useragent' => $useragent, 'country' => '', 'city' => ''));
216
+ }
217
+ }
218
+ }
219
+
220
+ unset($remote_ip, $track, $meta, $ad, $group, $remote, $banner);
221
+ }
222
+
223
+ die();
224
+ }
225
+ /*-------------------------------------------------------------
226
+ Name: adrotate_filter_schedule
227
+
228
+ Purpose: Weed out ads that are over the limit of their schedule
229
+ Receive: $selected, $banner
230
+ Return: $selected
231
+ Since: 3.6.11
232
+ -------------------------------------------------------------*/
233
+ function adrotate_filter_schedule($selected, $banner) {
234
+ global $wpdb, $adrotate_config, $adrotate_debug;
235
+
236
+ $now = adrotate_now();
237
+
238
+ if($adrotate_debug['general'] == true) {
239
+ echo "<p><strong>[DEBUG][adrotate_filter_schedule()] Filtering banner</strong><pre>";
240
+ print_r($banner->id);
241
+ echo "</pre></p>";
242
+ }
243
+
244
+ // Get schedules for advert
245
+ $schedules = $wpdb->get_results("SELECT `".$wpdb->prefix."adrotate_schedule`.`id`, `starttime`, `stoptime`, `maxclicks`, `maximpressions` FROM `".$wpdb->prefix."adrotate_schedule`, `".$wpdb->prefix."adrotate_linkmeta` WHERE `schedule` = `".$wpdb->prefix."adrotate_schedule`.`id` AND `ad` = '".$banner->id."' ORDER BY `starttime` ASC LIMIT 1;");
246
+
247
+ $schedule = $schedules[0];
248
+
249
+ $current = array();
250
+ if($schedule->starttime > $now OR $schedule->stoptime < $now) {
251
+ $current[] = 0;
252
+ } else {
253
+ $current[] = 1;
254
+ if($adrotate_config['enable_stats'] == 'Y') {
255
+ $stat = adrotate_stats($banner->id, $schedule->starttime, $schedule->stoptime);
256
+
257
+ if($adrotate_debug['general'] == true) {
258
+ echo "<p><strong>[DEBUG][adrotate_filter_schedule] Ad ".$banner->id." - Has schedule (id: ".$schedule->id.")</strong><pre>";
259
+ echo "<br />Start: ".$schedule->starttime." (".date("F j, Y, g:i a", $schedule->starttime).")";
260
+ echo "<br />End: ".$schedule->stoptime." (".date("F j, Y, g:i a", $schedule->stoptime).")";
261
+ echo "<br />Clicks this period: ".$stat['clicks'];
262
+ echo "<br />Impressions this period: ".$stat['impressions'];
263
+ echo "</pre></p>";
264
+ }
265
+
266
+ if($stat['clicks'] >= $schedule->maxclicks AND $schedule->maxclicks > 0 AND $banner->tracker == "Y") {
267
+ unset($selected[$banner->id]);
268
+ }
269
+
270
+ if($stat['impressions'] >= $schedule->maximpressions AND $schedule->maximpressions > 0) {
271
+ unset($selected[$banner->id]);
272
+ }
273
+ }
274
+ }
275
+
276
+ // Remove advert from array if all schedules are false (0)
277
+ if(!in_array(1, $current)) {
278
+ unset($selected[$banner->id]);
279
+ }
280
+ unset($current, $schedules);
281
+
282
+ return $selected;
283
+ }
284
+
285
+ /*-------------------------------------------------------------
286
+ Name: adrotate_array_unique
287
+
288
+ Purpose: Filter out duplicate records in multidimensional arrays
289
+ Receive: $array
290
+ Return: $array|$return
291
+ Since: 3.0
292
+ -------------------------------------------------------------*/
293
+ function adrotate_array_unique($array) {
294
+ if(count($array) > 0) {
295
+ if(is_array($array[0])) {
296
+ $return = array();
297
+ // multidimensional
298
+ foreach($array as $row) {
299
+ if(!in_array($row, $return)) {
300
+ $return[] = $row;
301
+ }
302
+ }
303
+ return $return;
304
+ } else {
305
+ // not multidimensional
306
+ return array_unique($array);
307
+ }
308
+ } else {
309
+ return $array;
310
+ }
311
+ }
312
+
313
+ /*-------------------------------------------------------------
314
+ Name: adrotate_rand
315
+
316
+ Purpose: Generate a random string
317
+ Receive: $length
318
+ Return: $result
319
+ Since: 3.8
320
+ -------------------------------------------------------------*/
321
+ function adrotate_rand($length = 8) {
322
+ $available_chars = "abcdefghijklmnopqrstuvwxyz";
323
+
324
+ $result = '';
325
+ $size = strlen($available_chars);
326
+ for($i = 0; $i < $length; $i++) {
327
+ $result .= $available_chars[rand(0, $size - 1)];
328
+ }
329
+
330
+ return $result;
331
+ }
332
+
333
+ /*-------------------------------------------------------------
334
+ Name: adrotate_shuffle
335
+
336
+ Purpose: Randomize an array but keep keys intact
337
+ Receive: $length
338
+ Return: $result
339
+ Since: 3.8.8.3
340
+ -------------------------------------------------------------*/
341
+ function adrotate_shuffle($array) {
342
+ if(!is_array($array)) return $array;
343
+ $keys = array_keys($array);
344
+ shuffle($keys);
345
+ $shuffle = array();
346
+ foreach($keys as $key) {
347
+ $shuffle[$key] = $array[$key];
348
+ }
349
+ return $shuffle;
350
+ }
351
+
352
+ /*-------------------------------------------------------------
353
+ Name: adrotate_select_categories
354
+
355
+ Purpose: Create scrolling menu of all categories.
356
+ Receive: $savedcats, $count, $child_of, $parent
357
+ Return: $output
358
+ Since: 3.8.4
359
+ -------------------------------------------------------------*/
360
+ function adrotate_select_categories($savedcats, $count = 2, $child_of = 0, $parent = 0) {
361
+ if(!is_array($savedcats)) $savedcats = explode(',', $savedcats);
362
+ $categories = get_categories(array('child_of' => $parent, 'parent' => $parent, 'orderby' => 'id', 'order' => 'asc', 'hide_empty' => 0));
363
+
364
+ if(!empty($categories)) {
365
+ $output = '';
366
+ if($parent == 0) {
367
+ $output = '<table width="100%">';
368
+ if(count($categories) > 5) {
369
+ $output .= '<thead><tr><td scope="col" class="manage-column check-column" style="padding: 0px;"><input type="checkbox" /></td><td style="padding: 0px;">Select All</td></tr></thead>';
370
+ }
371
+ $output .= '<tbody>';
372
+ }
373
+ foreach($categories as $category) {
374
+ if($category->parent > 0) {
375
+ if($category->parent != $child_of) {
376
+ $count = $count + 1;
377
+ }
378
+ $indent = '&nbsp;'.str_repeat('-', $count * 2).'&nbsp;';
379
+ } else {
380
+ $indent = '';
381
+ }
382
+ $output .= '<tr>';
383
+ $output .= '<td class="check-column" style="padding: 0px;"><input type="checkbox" name="adrotate_categories[]" value="'.$category->cat_ID.'"';
384
+ if(in_array($category->cat_ID, $savedcats)) {
385
+ $output .= ' checked';
386
+ }
387
+ $output .= '></td><td style="padding: 0px;">'.$indent.$category->name.' ('.$category->category_count.')</td>';
388
+ $output .= '</tr>';
389
+ $output .= adrotate_select_categories($savedcats, $count, $category->parent, $category->cat_ID);
390
+ $child_of = $parent;
391
+ }
392
+ if($parent == 0) {
393
+ $output .= '</tbody></table>';
394
+ }
395
+ return $output;
396
+ }
397
+ }
398
+
399
+ /*-------------------------------------------------------------
400
+ Name: adrotate_select_pages
401
+
402
+ Purpose: Create scrolling menu of all pages.
403
+ Receive: $savedpages, $count, $child_of, $parent
404
+ Return: $output
405
+ Since: 3.8.4
406
+ -------------------------------------------------------------*/
407
+ function adrotate_select_pages($savedpages, $count = 2, $child_of = 0, $parent = 0) {
408
+ if(!is_array($savedpages)) $savedpages = explode(',', $savedpages);
409
+ $pages = get_pages(array('child_of' => $parent, 'parent' => $parent, 'sort_column' => 'ID', 'sort_order' => 'asc'));
410
+
411
+ if(!empty($pages)) {
412
+ $output = '';
413
+ if($parent == 0) {
414
+ $output = '<table width="100%">';
415
+ if(count($pages) > 5) {
416
+ $output .= '<thead><tr><td scope="col" class="manage-column check-column" style="padding: 0px;"><input type="checkbox" /></td><td style="padding: 0px;">Select All</td></tr></thead>';
417
+ }
418
+ $output .= '<tbody>';
419
+ }
420
+ foreach($pages as $page) {
421
+ if($page->post_parent > 0) {
422
+ if($page->post_parent != $child_of) {
423
+ $count = $count + 1;
424
+ }
425
+ $indent = '&nbsp;'.str_repeat('-', $count * 2).'&nbsp;';
426
+ } else {
427
+ $indent = '';
428
+ }
429
+ $output .= '<tr>';
430
+ $output .= '<td class="check-column" style="padding: 0px;"><input type="checkbox" name="adrotate_pages[]" value="'.$page->ID.'"';
431
+ if(in_array($page->ID, $savedpages)) {
432
+ $output .= ' checked';
433
+ }
434
+ $output .= '></td><td style="padding: 0px;">'.$indent.$page->post_title.'</td>';
435
+ $output .= '</tr>';
436
+ $output .= adrotate_select_pages($savedpages, $count, $page->post_parent, $page->ID);
437
+ $child_of = $parent;
438
+ }
439
+ if($parent == 0) {
440
+ $output .= '</tbody></table>';
441
+ }
442
+ return $output;
443
+ }
444
+ }
445
+
446
+ /*-------------------------------------------------------------
447
+ Name: adrotate_prepare_evaluate_ads
448
+
449
+ Purpose: Initiate evaluations for errors and determine the ad status
450
+ Receive: -None-
451
+ Return: -None-
452
+ Since: 3.6.5
453
+ -------------------------------------------------------------*/
454
+ function adrotate_prepare_evaluate_ads($return = true) {
455
+ global $wpdb;
456
+
457
+ // Fetch ads
458
+ $ads = $wpdb->get_results("SELECT `id`, `type` FROM `".$wpdb->prefix."adrotate` WHERE `type` != 'disabled' AND `type` != 'empty' ORDER BY `id` ASC;");
459
+
460
+ // Determine error states
461
+ $error = $expired = $expiressoon = $normal = $unknown = 0;
462
+ foreach($ads as $ad) {
463
+ $result = adrotate_evaluate_ad($ad->id);
464
+ if($result == 'error') {
465
+ $error++;
466
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate` SET `type` = 'error' WHERE `id` = '".$ad->id."';");
467
+ }
468
+
469
+ if($result == 'expired') {
470
+ $expired++;
471
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate` SET `type` = 'expired' WHERE `id` = '".$ad->id."';");
472
+ }
473
+
474
+ if($result == '2days') {
475
+ $expiressoon++;
476
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate` SET `type` = '2days' WHERE `id` = '".$ad->id."';");
477
+ }
478
+
479
+ if($result == '7days') {
480
+ $normal++;
481
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate` SET `type` = '7days' WHERE `id` = '".$ad->id."';");
482
+ }
483
+
484
+ if($result == 'active') {
485
+ $normal++;
486
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate` SET `type` = 'active' WHERE `id` = '".$ad->id."';");
487
+ }
488
+
489
+ if($result == 'unknown') {
490
+ $unknown++;
491
+ }
492
+ }
493
+
494
+ $count = $expired + $expiressoon + $error;
495
+ $result = array('error' => $error,
496
+ 'expired' => $expired,
497
+ 'expiressoon' => $expiressoon,
498
+ 'normal' => $normal,
499
+ 'total' => $count,
500
+ 'unknown' => $unknown
501
+ );
502
+
503
+ update_option('adrotate_advert_status', $result);
504
+ if($return) adrotate_return('db_evaluated');
505
+ }
506
+
507
+ /*-------------------------------------------------------------
508
+ Name: adrotate_evaluate_ads
509
+
510
+ Purpose: Initiate automated evaluations for errors and determine the ad status
511
+ Receive: -None-
512
+ Return: -None-
513
+ Since: 3.8.5.1
514
+ -------------------------------------------------------------*/
515
+ function adrotate_evaluate_ads() {
516
+ adrotate_prepare_evaluate_ads(false);
517
+ }
518
+
519
+ /*-------------------------------------------------------------
520
+ Name: adrotate_evaluate_ad
521
+
522
+ Purpose: Evaluates ads for errors
523
+ Receive: $ad_id
524
+ Return: boolean
525
+ Since: 3.6.5
526
+ -------------------------------------------------------------*/
527
+ function adrotate_evaluate_ad($ad_id) {
528
+ global $wpdb, $adrotate_config;
529
+
530
+ $now = adrotate_now();
531
+ $in2days = $now + 172800;
532
+ $in7days = $now + 604800;
533
+
534
+ // Fetch ad
535
+ $ad = $wpdb->get_row($wpdb->prepare("SELECT `id`, `bannercode`, `tracker`, `link`, `imagetype`, `image`, `cbudget`, `ibudget`, `crate`, `irate` FROM `".$wpdb->prefix."adrotate` WHERE `id` = %d;", $ad_id));
536
+ $advertiser = $wpdb->get_var("SELECT `user` FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = '".$ad->id."' AND `group` = 0 AND `block` = 0 AND `user` > 0 AND `schedule` = 0;");
537
+ $stoptime = $wpdb->get_var("SELECT `stoptime` FROM `".$wpdb->prefix."adrotate_schedule`, `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = '".$ad->id."' AND `schedule` = `".$wpdb->prefix."adrotate_schedule`.`id` ORDER BY `stoptime` DESC LIMIT 1;");
538
+
539
+ $bannercode = stripslashes(htmlspecialchars_decode($ad->bannercode, ENT_QUOTES));
540
+ // Determine error states
541
+ if(
542
+ strlen($bannercode) < 1 // AdCode empty
543
+ OR ($ad->tracker == 'N' AND $advertiser > 0) // Didn't enable click-tracking, didn't provide a link, DID set a advertiser
544
+ OR (!preg_match_all('/<a[^>](.*?)>/i', $bannercode, $things) AND $ad->tracker == 'Y') // Clicktracking active but no valid link present
545
+ OR (!preg_match("/%image%/i", $bannercode) AND $ad->image != '' AND $ad->imagetype != '') // Didn't use %image% but selected an image
546
+ OR (preg_match("/%image%/i", $bannercode) AND $ad->image == '' AND $ad->imagetype == '') // Did use %image% but didn't select an image
547
+ OR ($ad->image == '' AND $ad->imagetype != '') // Image and Imagetype mismatch
548
+ ) {
549
+ return 'error';
550
+ } else if(
551
+ $stoptime <= $now // Past the enddate
552
+ ){
553
+ return 'expired';
554
+ } else if(
555
+ $stoptime <= $in2days AND $stoptime >= $now // Expires in 2 days
556
+ ){
557
+ return '2days';
558
+ } else if(
559
+ $stoptime <= $in7days AND $stoptime >= $now // Expires in 7 days
560
+ ){
561
+ return '7days';
562
+ } else {
563
+ return 'active';
564
+ }
565
+ }
566
+
567
+ /*-------------------------------------------------------------
568
+ Name: adrotate_prepare_color
569
+
570
+ Purpose: Check if ads are expired and set a color for its end date
571
+ Receive: $banner_id
572
+ Return: $result
573
+ Since: 3.0
574
+ -------------------------------------------------------------*/
575
+ function adrotate_prepare_color($enddate) {
576
+ $now = adrotate_now();
577
+ $in2days = $now + 172800;
578
+ $in7days = $now + 604800;
579
+
580
+ if($enddate <= $now) {
581
+ return '#CC2900'; // red
582
+ } else if($enddate <= $in2days AND $enddate >= $now) {
583
+ return '#F90'; // orange
584
+ } else if($enddate <= $in7days AND $enddate >= $now) {
585
+ return '#E6B800'; // yellow
586
+ } else {
587
+ return '#009900'; // green
588
+ }
589
+ }
590
+
591
+ /*-------------------------------------------------------------
592
+ Name: adrotate_ad_is_in_groups
593
+
594
+ Purpose: Build list of groups the ad is in (overview)
595
+ Receive: $id
596
+ Return: $output
597
+ Since: 3.8
598
+ -------------------------------------------------------------*/
599
+ function adrotate_ad_is_in_groups($id) {
600
+ global $wpdb;
601
+
602
+ $output = '';
603
+ $groups = $wpdb->get_results("
604
+ SELECT
605
+ `".$wpdb->prefix."adrotate_groups`.`name`
606
+ FROM
607
+ `".$wpdb->prefix."adrotate_groups`,
608
+ `".$wpdb->prefix."adrotate_linkmeta`
609
+ WHERE
610
+ `".$wpdb->prefix."adrotate_linkmeta`.`ad` = '".$id."'
611
+ AND `".$wpdb->prefix."adrotate_linkmeta`.`group` = `".$wpdb->prefix."adrotate_groups`.`id`
612
+ AND `".$wpdb->prefix."adrotate_linkmeta`.`block` = 0
613
+ AND `".$wpdb->prefix."adrotate_linkmeta`.`user` = 0
614
+ ;");
615
+ if($groups) {
616
+ foreach($groups as $group) {
617
+ $output .= $group->name.", ";
618
+ }
619
+ }
620
+ $output = rtrim($output, ", ");
621
+
622
+ return $output;
623
+ }
624
+
625
+ /*-------------------------------------------------------------
626
+ Name: adrotate_hash
627
+
628
+ Purpose: Generate the adverts clicktracking hash
629
+ Receive: $ad, $group, $remote, $blog_id
630
+ Return: $result
631
+ Since: 3.9.12
632
+ -------------------------------------------------------------*/
633
+ function adrotate_hash($ad, $group = 0, $blog_id = 0) {
634
+ global $adrotate_debug, $adrotate_config;
635
+
636
+ if($adrotate_debug['timers'] == true) {
637
+ $timer = 0;
638
+ } else {
639
+ $timer = $adrotate_config['impression_timer'];
640
+ }
641
+
642
+ if($adrotate_debug['track'] == true) {
643
+ return "$ad,$group,$blog_id,$timer";
644
+ } else {
645
+ return base64_encode("$ad,$group,$blog_id,$timer");
646
+ }
647
+ }
648
+
649
+ /*-------------------------------------------------------------
650
+ Name: adrotate_get_remote_ip
651
+
652
+ Purpose: Get the remote IP from the visitor
653
+ Receive: -None-
654
+ Return: $buffer[0]
655
+ Since: 3.6.2
656
+ -------------------------------------------------------------*/
657
+ function adrotate_get_remote_ip(){
658
+ if(empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
659
+ $remote_ip = $_SERVER["REMOTE_ADDR"];
660
+ } else {
661
+ $remote_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
662
+ }
663
+ $buffer = explode(',', $remote_ip, 2);
664
+
665
+ return $buffer[0];
666
+ }
667
+
668
+ /*-------------------------------------------------------------
669
+ Name: adrotate_get_sorted_roles
670
+
671
+ Purpose: Returns all roles and capabilities, sorted by user level. Lowest to highest.
672
+ Receive: -none-
673
+ Return: $sorted
674
+ Since: 3.2
675
+ -------------------------------------------------------------*/
676
+ function adrotate_get_sorted_roles() {
677
+ global $wp_roles;
678
+
679
+ $editable_roles = apply_filters('editable_roles', $wp_roles->roles);
680
+ $sorted = array();
681
+
682
+ foreach($editable_roles as $role => $details) {
683
+ $sorted[$details['name']] = get_role($role);
684
+ }
685
+
686
+ $sorted = array_reverse($sorted);
687
+
688
+ return $sorted;
689
+ }
690
+
691
+ /*-------------------------------------------------------------
692
+ Name: adrotate_set_capability
693
+
694
+ Purpose: Grant or revoke capabilities to a role and all higher roles
695
+ Receive: $lowest_role, $capability
696
+ Return: -None-
697
+ Since: 3.2
698
+ -------------------------------------------------------------*/
699
+ function adrotate_set_capability($lowest_role, $capability){
700
+ $check_order = adrotate_get_sorted_roles();
701
+ $add_capability = false;
702
+
703
+ foreach($check_order as $role) {
704
+ if($lowest_role == $role->name) $add_capability = true;
705
+ if(empty($role)) continue;
706
+ $add_capability ? $role->add_cap($capability) : $role->remove_cap($capability) ;
707
+ }
708
+ }
709
+
710
+ /*-------------------------------------------------------------
711
+ Name: adrotate_remove_capability
712
+
713
+ Purpose: Remove the $capability from the all roles
714
+ Receive: $capability
715
+ Return: -None-
716
+ Since: 3.2
717
+ -------------------------------------------------------------*/
718
+ function adrotate_remove_capability($capability){
719
+ $check_order = adrotate_get_sorted_roles();
720
+
721
+ foreach($check_order as $role) {
722
+ $role = get_role($role->name);
723
+ $role->remove_cap($capability);
724
+ }
725
+ }
726
+
727
+ /*-------------------------------------------------------------
728
+ Name: adrotate_dashboard_scripts
729
+
730
+ Purpose: Load file uploaded popup
731
+ Receive: -None-
732
+ Return: -None-
733
+ Since: 3.6
734
+ -------------------------------------------------------------*/
735
+ function adrotate_dashboard_scripts() {
736
+ wp_enqueue_script('jquery');
737
+ wp_enqueue_script('raphael', plugins_url('/library/raphael-min.js', __FILE__), array('jquery'));
738
+ wp_enqueue_script('elycharts', plugins_url('/library/elycharts.min.js', __FILE__), array('jquery', 'raphael'));
739
+ wp_enqueue_script('textatcursor', plugins_url('/library/textatcursor.js', __FILE__));
740
+
741
+ // WP Pointers
742
+ $seen_it = explode(',', get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true));
743
+ $do_add_script = false;
744
+ if(!in_array('adrotate_free_'.ADROTATE_VERSION.ADROTATE_DB_VERSION, $seen_it)) {
745
+ $do_add_script = true;
746
+ add_action('admin_print_footer_scripts', 'adrotate_welcome_pointer');
747
+ }
748
+
749
+ if($do_add_script) {
750
+ wp_enqueue_script('wp-pointer');
751
+ wp_enqueue_style('wp-pointer');
752
+ }
753
+ }
754
+
755
+ /*-------------------------------------------------------------
756
+ Name: adrotate_dashboard_styles
757
+
758
+ Purpose: Load file uploaded popup
759
+ Receive: -None-
760
+ Return: -None-
761
+ Since: 3.6
762
+ -------------------------------------------------------------*/
763
+ function adrotate_dashboard_styles() {
764
+ wp_enqueue_style( 'adrotate-admin-stylesheet', plugins_url( 'library/dashboard.css', __FILE__ ) );
765
+ }
766
+
767
+ /*-------------------------------------------------------------
768
+ Name: adrotate_folder_contents
769
+
770
+ Purpose: List folder contents of /wp-content/banners and /wp-content/uploads
771
+ Receive: $current
772
+ Return: $output
773
+ Since: 0.4
774
+ -------------------------------------------------------------*/
775
+ function adrotate_folder_contents($current) {
776
+ global $wpdb, $adrotate_config;
777
+
778
+ $output = '';
779
+ $siteurl = get_option('siteurl');
780
+
781
+ // Read Banner folder
782
+ $files = array();
783
+ $i = 0;
784
+ if($handle = opendir(ABSPATH.$adrotate_config['banner_folder'])) {
785
+ while (false !== ($file = readdir($handle))) {
786
+ if ($file != "." AND $file != ".." AND $file != "index.php") {
787
+ $files[] = $file;
788
+ $i++;
789
+ }
790
+ }
791
+ closedir($handle);
792
+
793
+ if($i > 0) {
794
+ sort($files);
795
+ foreach($files as $file) {
796
+ $fileinfo = pathinfo($file);
797
+
798
+ if((strtolower($fileinfo['extension']) == "jpg" OR strtolower($fileinfo['extension']) == "gif" OR strtolower($fileinfo['extension']) == "png"
799
+ OR strtolower($fileinfo['extension']) == "jpeg" OR strtolower($fileinfo['extension']) == "swf" OR strtolower($fileinfo['extension']) == "flv")) {
800
+ $output .= "<option value='".$file."'";
801
+ if(($current == $siteurl.'/wp-content/banners/'.$file) OR ($current == $siteurl."/%folder%".$file)) { $output .= "selected"; }
802
+ $output .= ">".$file."</option>";
803
+ }
804
+ }
805
+ } else {
806
+ $output .= "<option disabled>&nbsp;&nbsp;&nbsp;".__('No files found', 'adrotate')."</option>";
807
+ }
808
+ } else {
809
+ $output .= "<option disabled>&nbsp;&nbsp;&nbsp;".__('Folder not found or not accessible', 'adrotate')."</option>";
810
+ }
811
+
812
+ return $output;
813
+ }
814
+
815
+ /*-------------------------------------------------------------
816
+ Name: adrotate_return
817
+
818
+ Purpose: Internal redirects
819
+ Receive: $action, $arg (array)
820
+ Return: -none-
821
+ Since: 0.2
822
+ Usage: array('wp_page', 'message', 'arguments', 'id')
823
+ -------------------------------------------------------------*/
824
+ function adrotate_return($action, $arg = null) {
825
+
826
+ switch($action) {
827
+ // Manage Ads
828
+ case "new" :
829
+ wp_redirect('admin.php?page=adrotate-ads&message=new');
830
+ break;
831
+
832
+ case "update" :
833
+ wp_redirect('admin.php?page=adrotate-ads&view=edit&message=updated&ad='.$arg[0]);
834
+ break;
835
+
836
+ case "update_manage" :
837
+ wp_redirect('admin.php?page=adrotate-ads&message=updated');
838
+ break;
839
+
840
+ case "delete" :
841
+ wp_redirect('admin.php?page=adrotate-ads&message=deleted');
842
+ break;
843
+
844
+ case "reset" :
845
+ wp_redirect('admin.php?page=adrotate-ads&message=reset');
846
+ break;
847
+
848
+ case "renew" :
849
+ wp_redirect('admin.php?page=adrotate-ads&message=renew');
850
+ break;
851
+
852
+ case "deactivate" :
853
+ wp_redirect('admin.php?page=adrotate-ads&message=deactivate');
854
+ break;
855
+
856
+ case "activate" :
857
+ wp_redirect('admin.php?page=adrotate-ads&message=activate');
858
+ break;
859
+
860
+ case "exported" :
861
+ wp_redirect('admin.php?page=adrotate-ads&message=exported&file='.$arg[0]);
862
+ break;
863
+
864
+ case "field_error" :
865
+ wp_redirect('admin.php?page=adrotate-ads&message=field_error');
866
+ break;
867
+
868
+ // Groups
869
+ case "group_new" :
870
+ wp_redirect('admin.php?page=adrotate-groups&message=created');
871
+ break;
872
+
873
+ case "group_edit" :
874
+ wp_redirect('admin.php?page=adrotate-groups&view=edit&message=updated&group='.$arg[0]);
875
+ break;
876
+
877
+ case "group_delete" :
878
+ wp_redirect('admin.php?page=adrotate-groups&message=deleted');
879
+ break;
880
+
881
+ case "group_delete_banners" :
882
+ wp_redirect('admin.php?page=adrotate-groups&message=deleted_banners');
883
+ break;
884
+
885
+ // Settings
886
+ case "settings_saved" :
887
+ wp_redirect('admin.php?page=adrotate-settings&message=updated');
888
+ break;
889
+
890
+ // Maintenance
891
+ case "db_optimized" :
892
+ wp_redirect('admin.php?page=adrotate-settings&message=db_optimized');
893
+ break;
894
+
895
+ case "db_evaluated" :
896
+ wp_redirect('admin.php?page=adrotate-settings&message=db_evaluated');
897
+ break;
898
+
899
+ case "db_repaired" :
900
+ wp_redirect('admin.php?page=adrotate-settings&message=db_optimized');
901
+ break;
902
+
903
+ case "db_cleaned" :
904
+ wp_redirect('admin.php?page=adrotate-settings&message=db_cleaned');
905
+ break;
906
+
907
+ case "db_timer" :
908
+ wp_redirect('admin.php?page=adrotate-settings&message=db_timer');
909
+ break;
910
+
911
+ // Misc plugin events
912
+ case "mail_sent" :
913
+ wp_redirect('admin.php?page=adrotate-advertiser&message=mail_sent');
914
+ break;
915
+
916
+ case "beta_mail_sent" :
917
+ wp_redirect('admin.php?page=adrotate-beta&message=sent');
918
+ break;
919
+
920
+ case "beta_mail_empty" :
921
+ wp_redirect('admin.php?page=adrotate-beta&message=empty');
922
+ break;
923
+
924
+ case "no_access" :
925
+ wp_redirect('admin.php?page=adrotate&message=no_access');
926
+ break;
927
+
928
+ case "error" :
929
+ wp_redirect('admin.php?page=adrotate&message=error');
930
+ break;
931
+
932
+ default:
933
+ wp_redirect('admin.php?page=adrotate');
934
+ break;
935
+
936
+ }
937
+ }
938
+ ?>
adrotate-manage-publisher.php ADDED
@@ -0,0 +1,720 @@
1
+ <?php
2
+ /* ------------------------------------------------------------------------------------
3
+ * COPYRIGHT AND TRADEMARK NOTICE
4
+ * Copyright 2008-2015 AJdG Solutions (Arnan de Gans). All Rights Reserved.
5
+ * ADROTATE is a trademark of Arnan de Gans.
6
+
7
+ * COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
8
+ * By using this code you agree to indemnify Arnan de Gans from any
9
+ * liability that might arise from it's use.
10
+ ------------------------------------------------------------------------------------ */
11
+
12
+ /*-------------------------------------------------------------
13
+ Name: adrotate_insert_input
14
+
15
+ Purpose: Prepare input form on saving new or updated banners
16
+ Receive: -None-
17
+ Return: -None-
18
+ Since: 0.1
19
+ -------------------------------------------------------------*/
20
+ function adrotate_insert_input() {
21
+ global $wpdb, $adrotate_config;
22
+
23
+ if(wp_verify_nonce($_POST['adrotate_nonce'], 'adrotate_save_ad')) {
24
+ // Mandatory
25
+ $id = $schedule_id = $author = $title = $bannercode = $active = $sortorder = '';
26
+ if(isset($_POST['adrotate_id'])) $id = $_POST['adrotate_id'];
27
+ if(isset($_POST['adrotate_schedule'])) $schedule_id = $_POST['adrotate_schedule'];
28
+ if(isset($_POST['adrotate_username'])) $author = $_POST['adrotate_username'];
29
+ if(isset($_POST['adrotate_title'])) $title = strip_tags(htmlspecialchars(trim($_POST['adrotate_title'], "\t\n "), ENT_QUOTES));
30
+ if(isset($_POST['adrotate_bannercode'])) $bannercode = htmlspecialchars(trim($_POST['adrotate_bannercode'], "\t\n "), ENT_QUOTES);
31
+ $thetime = adrotate_now();
32
+ if(isset($_POST['adrotate_active'])) $active = strip_tags(htmlspecialchars(trim($_POST['adrotate_active'], "\t\n "), ENT_QUOTES));
33
+ if(isset($_POST['adrotate_sortorder'])) $sortorder = strip_tags(htmlspecialchars(trim($_POST['adrotate_sortorder'], "\t\n "), ENT_QUOTES));
34
+
35
+ // Schedules
36
+ $sday = $smonth = $syear = $shour = $sminute = '';
37
+ if(isset($_POST['adrotate_sday'])) $sday = strip_tags(trim($_POST['adrotate_sday'], "\t\n "));
38
+ if(isset($_POST['adrotate_smonth'])) $smonth = strip_tags(trim($_POST['adrotate_smonth'], "\t\n "));
39
+ if(isset($_POST['adrotate_syear'])) $syear = strip_tags(trim($_POST['adrotate_syear'], "\t\n "));
40
+ if(isset($_POST['adrotate_shour'])) $shour = strip_tags(trim($_POST['adrotate_shour'], "\t\n "));
41
+ if(isset($_POST['adrotate_sminute'])) $sminute = strip_tags(trim($_POST['adrotate_sminute'], "\t\n "));
42
+
43
+ $eday = $emonth = $eyear = $ehour = $eminute = '';
44
+ if(isset($_POST['adrotate_eday'])) $eday = strip_tags(trim($_POST['adrotate_eday'], "\t\n "));
45
+ if(isset($_POST['adrotate_emonth'])) $emonth = strip_tags(trim($_POST['adrotate_emonth'], "\t\n "));
46
+ if(isset($_POST['adrotate_eyear'])) $eyear = strip_tags(trim($_POST['adrotate_eyear'], "\t\n "));
47
+ if(isset($_POST['adrotate_ehour'])) $ehour = strip_tags(trim($_POST['adrotate_ehour'], "\t\n "));
48
+ if(isset($_POST['adrotate_eminute'])) $eminute = strip_tags(trim($_POST['adrotate_eminute'], "\t\n "));
49
+
50
+ $maxclicks = $maxshown = '';
51
+ if(isset($_POST['adrotate_maxclicks'])) $maxclicks = strip_tags(trim($_POST['adrotate_maxclicks'], "\t\n "));
52
+ if(isset($_POST['adrotate_maxshown'])) $maxshown = strip_tags(trim($_POST['adrotate_maxshown'], "\t\n "));
53
+
54
+ // Advanced options
55
+ $advertiser = $image_field = $image_dropdown = $link = $tracker = '';
56
+ if(isset($_POST['adrotate_advertiser'])) $advertiser = 0;
57
+ if(isset($_POST['adrotate_image'])) $image_field = strip_tags(trim($_POST['adrotate_image'], "\t\n "));
58
+ if(isset($_POST['adrotate_image_dropdown'])) $image_dropdown = strip_tags(trim($_POST['adrotate_image_dropdown'], "\t\n "));
59
+ if(isset($_POST['adrotate_link'])) $link = strip_tags(trim($_POST['adrotate_link'], "\t\n "));
60
+ if(isset($_POST['adrotate_tracker'])) $tracker = strip_tags(trim($_POST['adrotate_tracker'], "\t\n "));
61
+ if(isset($_POST['adrotate_responsive'])) $responsive = strip_tags(trim($_POST['adrotate_responsive'], "\t\n "));
62
+
63
+ // Misc variabled
64
+ $groups = $type = $group_array = '';
65
+ if(isset($_POST['groupselect'])) $groups = $_POST['groupselect'];
66
+ if(isset($_POST['adrotate_type'])) $type = strip_tags(trim($_POST['adrotate_type'], "\t\n "));
67
+
68
+
69
+ if(current_user_can('adrotate_ad_manage')) {
70
+ if(strlen($title) < 1) {
71
+ $title = 'Ad '.$id;
72
+ }
73
+
74
+ // Sort out start dates
75
+ if(strlen($smonth) > 0 AND !is_numeric($smonth)) $smonth = date_i18n('m');
76
+ if(strlen($sday) > 0 AND !is_numeric($sday)) $sday = date_i18n('d');
77
+ if(strlen($syear) > 0 AND !is_numeric($syear)) $syear = date_i18n('Y');
78
+ if(strlen($shour) > 0 AND !is_numeric($shour)) $shour = date_i18n('H');
79
+ if(strlen($sminute) > 0 AND !is_numeric($sminute)) $sminute = date_i18n('i');
80
+ if(($smonth > 0 AND $sday > 0 AND $syear > 0) AND strlen($shour) == 0) $shour = '00';
81
+ if(($smonth > 0 AND $sday > 0 AND $syear > 0) AND strlen($sminute) == 0) $sminute = '00';
82
+
83
+ if($smonth > 0 AND $sday > 0 AND $syear > 0) {
84
+ $startdate = mktime($shour, $sminute, 0, $smonth, $sday, $syear);
85
+ } else {
86
+ $startdate = 0;
87
+ }
88
+
89
+ // Sort out end dates
90
+ if(strlen($emonth) > 0 AND !is_numeric($emonth)) $emonth = $smonth;
91
+ if(strlen($eday) > 0 AND !is_numeric($eday)) $eday = $sday;
92
+ if(strlen($eyear) > 0 AND !is_numeric($eyear)) $eyear = $syear+1;
93
+ if(strlen($ehour) > 0 AND !is_numeric($ehour)) $ehour = $shour;
94
+ if(strlen($eminute) > 0 AND !is_numeric($eminute)) $eminute = $sminute;
95
+ if(($emonth > 0 AND $eday > 0 AND $eyear > 0) AND strlen($ehour) == 0) $ehour = '00';
96
+ if(($emonth > 0 AND $eday > 0 AND $eyear > 0) AND strlen($eminute) == 0) $eminute = '00';
97
+
98
+ if($emonth > 0 AND $eday > 0 AND $eyear > 0) {
99
+ $enddate = mktime($ehour, $eminute, 0, $emonth, $eday, $eyear);
100
+ } else {
101
+ $enddate = 0;
102
+ }
103
+
104
+ // Enddate is too early, reset to default
105
+ if($enddate <= $startdate) $enddate = $startdate + 7257600; // 84 days (12 weeks)
106
+
107
+ // Validate sort order
108
+ if(strlen($sortorder) < 1 OR !is_numeric($sortorder) AND ($sortorder < 1 OR $sortorder > 99999)) $sortorder = 0;
109
+
110
+ // Sort out click and impressions restrictions
111
+ if(strlen($maxclicks) < 1 OR !is_numeric($maxclicks)) $maxclicks = 0;
112
+ if(strlen($maxshown) < 1 OR !is_numeric($maxshown)) $maxshown = 0;
113
+
114
+ // Set tracker value
115
+ if(isset($tracker) AND strlen($tracker) != 0) $tracker = 'Y';
116
+ else $tracker = 'N';
117
+
118
+ // Set responsive value
119
+ if(isset($responsive) AND strlen($responsive) != 0) $responsive = 'Y';
120
+ else $responsive = 'N';
121
+
122
+ // Format the URL (assume agnostic)
123
+ if((strlen($link) > 0 OR $link != "") AND preg_match("/%link%/i", $bannercode) AND strlen($link) > 0) $bannercode = str_replace('%link%', $link, $bannercode);
124
+
125
+ // Determine image settings ($image_field has priority!)
126
+ if(strlen($image_field) > 1) {
127
+ $imagetype = "field";
128
+ $image = $image_field;
129
+ } else if(strlen($image_dropdown) > 1) {
130
+ $imagetype = "dropdown";
131
+ $image = home_url()."/wp-content/banners/".$image_dropdown;
132
+ } else {
133
+ $imagetype = "";
134
+ $image = "";
135
+ }
136
+
137
+ // Save schedule for new ads or update the existing one
138
+ if($type != 'empty') {
139
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_schedule` WHERE `id` IN (SELECT `schedule` FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `schedule` != %d AND `schedule` > 0 AND `ad` = %d AND `group` = 0 AND `block` = 0 AND `user` = 0);", $schedule_id, $id));
140
+ }
141
+ $wpdb->update($wpdb->prefix.'adrotate_schedule', array('starttime' => $startdate, 'stoptime' => $enddate, 'maxclicks' => $maxclicks, 'maximpressions' => $maxshown), array('id' => $schedule_id));
142
+
143
+ // Save the ad to the DB
144
+ $wpdb->update($wpdb->prefix.'adrotate', array('title' => $title, 'bannercode' => $bannercode, 'updated' => $thetime, 'author' => $author, 'imagetype' => $imagetype, 'image' => $image, 'link' => $link, 'tracker' => $tracker, 'responsive' => $responsive, 'sortorder' => $sortorder), array('id' => $id));
145
+
146
+ // Determine Responsive requirement
147
+ $responsive_count = $wpdb->get_var("SELECT COUNT(*) as `total` FROM `".$wpdb->prefix."adrotate` WHERE `responsive` = 'Y';");
148
+ update_option('adrotate_responsive_required', $responsive_count);
149
+
150
+ // Fetch group records for the ad
151
+ $groupmeta = $wpdb->get_results($wpdb->prepare("SELECT `group` FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = %d AND `block` = 0 AND `user` = 0 AND `schedule` = 0;", $id));
152
+ foreach($groupmeta as $meta) {
153
+ $group_array[] = $meta->group;
154
+ }
155
+
156
+ if(empty($group_array)) $group_array = array();
157
+ if(empty($groups)) $groups = array();
158
+
159
+ // Add new groups to this ad
160
+ $insert = array_diff($groups, $group_array);
161
+ foreach($insert as &$value) {
162
+ $wpdb->insert($wpdb->prefix.'adrotate_linkmeta', array('ad' => $id, 'group' => $value, 'block' => 0, 'user' => 0, 'schedule' => 0));
163
+ }
164
+ unset($value);
165
+
166
+ // Remove groups from this ad
167
+ $delete = array_diff($group_array, $groups);
168
+ foreach($delete as &$value) {
169
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = %d AND `group` = %d AND `block` = 0 AND `user` = 0 AND `schedule` = 0;", $id, $value));
170
+ }
171
+ unset($value);
172
+
173
+ // Verify ad
174
+ if($type == "empty") {
175
+ $action = 'new';
176
+ } else {
177
+ $action = 'update';
178
+ }
179
+
180
+ if($active == "active") {
181
+ // Determine status of ad
182
+ $adstate = adrotate_evaluate_ad($id);
183
+ if($adstate == 'error' OR $adstate == 'expired' OR $adstate == 'expiring') {
184
+ $action = 'field_error';
185
+ }
186
+ $active = $adstate;
187
+ }
188
+ $wpdb->update($wpdb->prefix."adrotate", array('type' => $active), array('id' => $id));
189
+
190
+ adrotate_return($action, array($id));
191
+ exit;
192
+ } else {
193
+ adrotate_return('no_access');
194
+ }
195
+ } else {
196
+ adrotate_nonce_error();
197
+ exit;
198
+ }
199
+ }
200
+
201
+ /*-------------------------------------------------------------
202
+ Name: adrotate_insert_group
203
+
204
+ Purpose: Save provided data for groups, update linkmeta where required
205
+ Receive: -None-
206
+ Return: -None-
207
+ Since: 0.4
208
+ -------------------------------------------------------------*/
209
+ function adrotate_insert_group() {
210
+ global $wpdb, $adrotate_config;
211
+
212
+ if(wp_verify_nonce($_POST['adrotate_nonce'], 'adrotate_save_group')) {
213
+ $action = $id = $name = $modus = '';
214
+ if(isset($_POST['adrotate_action'])) $action = $_POST['adrotate_action'];
215
+ if(isset($_POST['adrotate_id'])) $id = $_POST['adrotate_id'];
216
+ if(isset($_POST['adrotate_groupname'])) $name = strip_tags(trim($_POST['adrotate_groupname'], "\t\n "));
217
+ if(isset($_POST['adrotate_modus'])) $modus = strip_tags(trim($_POST['adrotate_modus'], "\t\n "));
218
+
219
+ $rows = $columns = $adwidth = $adheight = $adspeed = '';
220
+ if(isset($_POST['adrotate_gridrows'])) $rows = strip_tags(trim($_POST['adrotate_gridrows'], "\t\n "));
221
+ if(isset($_POST['adrotate_gridcolumns'])) $columns = strip_tags(trim($_POST['adrotate_gridcolumns'], "\t\n "));
222
+ if(isset($_POST['adrotate_adwidth'])) $adwidth = strip_tags(trim($_POST['adrotate_adwidth'], "\t\n "));
223
+ if(isset($_POST['adrotate_adheight'])) $adheight = strip_tags(trim($_POST['adrotate_adheight'], "\t\n "));
224
+ if(isset($_POST['adrotate_adspeed'])) $adspeed = strip_tags(trim($_POST['adrotate_adspeed'], "\t\n "));
225
+
226
+ $ads = $admargin = $align = $sortorder = '';
227
+ if(isset($_POST['adselect'])) $ads = $_POST['adselect'];
228
+ if(isset($_POST['adrotate_admargin'])) $admargin = strip_tags(trim($_POST['adrotate_admargin'], "\t\n "));
229
+ if(isset($_POST['adrotate_align'])) $align = strip_tags(trim($_POST['adrotate_align'], "\t\n "));
230
+ if(isset($_POST['adrotate_sortorder'])) $sortorder = strip_tags(htmlspecialchars(trim($_POST['adrotate_sortorder'], "\t\n "), ENT_QUOTES));
231
+
232
+ $categories = $category_loc = $category_par = $pages = $page_loc = $page_par = '';
233
+ if(isset($_POST['adrotate_categories'])) $categories = $_POST['adrotate_categories'];
234
+ if(isset($_POST['adrotate_cat_location'])) $category_loc = $_POST['adrotate_cat_location'];
235
+ if(isset($_POST['adrotate_cat_paragraph'])) $category_par = $_POST['adrotate_cat_paragraph'];
236
+ if(isset($_POST['adrotate_pages'])) $pages = $_POST['adrotate_pages'];
237
+ if(isset($_POST['adrotate_page_location'])) $page_loc = $_POST['adrotate_page_location'];
238
+ if(isset($_POST['adrotate_page_paragraph'])) $page_par = $_POST['adrotate_page_paragraph'];
239
+
240
+ $wrapper_before = $wrapper_after = '';
241
+ if(isset($_POST['adrotate_wrapper_before'])) $wrapper_before = trim($_POST['adrotate_wrapper_before'], "\t\n ");
242
+ if(isset($_POST['adrotate_wrapper_after'])) $wrapper_after = trim($_POST['adrotate_wrapper_after'], "\t\n ");
243
+
244
+ if(current_user_can('adrotate_group_manage')) {
245
+ if(strlen($name) < 1) $name = 'Group '.$id;
246
+
247
+ if($modus < 0 OR $modus > 2) $modus = 0;
248
+ if($adspeed < 0 OR $adspeed > 99999) $adspeed = 6000;
249
+ if($align < 0 OR $align > 3) $align = 0;
250
+
251
+ // Sort out block shape
252
+ if($rows < 1 OR $rows == '' OR !is_numeric($rows)) $rows = 2;
253
+ if($columns < 1 OR $columns == '' OR !is_numeric($columns)) $columns = 2;
254
+ if((is_numeric($adwidth) AND $adwidth < 1 OR $adwidth > 9999) OR $adwidth == '' OR (!is_numeric($adwidth) AND $adwidth != 'auto')) $adheight = '125';
255
+ if((is_numeric($adheight) AND $adheight < 1 OR $adheight > 9999) OR $adheight == '' OR (!is_numeric($adheight) AND $adheight != 'auto')) $adheight = '125';
256
+ if($admargin < 0 OR $admargin > 99 OR $admargin == '' OR !is_numeric($admargin)) $admargin = 0;
257
+
258
+ // Validate sort order
259
+ if(strlen($sortorder) < 1 OR !is_numeric($sortorder) AND ($sortorder < 1 OR $sortorder > 99999)) $sortorder = $id;
260
+
261
+ // Categories
262
+ if(!is_array($categories)) $categories = array();
263
+ $category = '';
264
+ foreach($categories as $key => $value) {
265
+ $category = $category.','.$value;
266
+ }
267
+ $category = trim($category, ', ');
268
+ if(strlen($category) < 1) $category = '';
269
+
270
+ if($category_par > 0) $category_loc = 4;
271
+ if($category_loc != 4) $category_par = 0;
272
+
273
+ // Pages
274
+ if(!is_array($pages)) $pages = array();
275
+ $page = '';
276
+ foreach($pages as $key => $value) {
277
+ $page = $page.','.$value;
278
+ }
279
+ $page = trim($page, ',');
280
+ if(strlen($page) < 1) $page = '';
281
+
282
+ if($page_par > 0) $page_loc = 4;
283
+ if($page_loc != 4) $page_par = 0;
284
+
285
+ // Fetch records for the group
286
+ $linkmeta = $wpdb->get_results($wpdb->prepare("SELECT `ad` FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `group` = %d AND `block` = 0 AND `user` = 0;", $id));
287
+ foreach($linkmeta as $meta) {
288
+ $meta_array[] = $meta->ad;
289
+ }
290
+
291
+ if(empty($meta_array)) $meta_array = array();
292
+ if(empty($ads)) $ads = array();
293
+
294
+ // Add new ads to this group
295
+ $insert = array_diff($ads,$meta_array);
296
+ foreach($insert as &$value) {
297
+ $wpdb->insert($wpdb->prefix.'adrotate_linkmeta', array('ad' => $value, 'group' => $id, 'block' => 0, 'user' => 0));
298
+ }
299
+ unset($value);
300
+
301
+ // Remove ads from this group
302
+ $delete = array_diff($meta_array,$ads);
303
+ foreach($delete as &$value) {
304
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = %d AND `group` = %d AND `block` = 0 AND `user` = 0;", $value, $id));
305
+ }
306
+ unset($value);
307
+
308
+ // Update the group itself
309
+ $wpdb->update($wpdb->prefix.'adrotate_groups', array('name' => $name, 'modus' => $modus, 'fallback' => 0, 'sortorder' => $sortorder, 'cat' => $category, 'cat_loc' => $category_loc, 'cat_par' => $category_par, 'page' => $page, 'page_loc' => $page_loc, 'page_par' => $page_par, 'wrapper_before' => $wrapper_before, 'wrapper_after' => $wrapper_after, 'align' => $align, 'gridrows' => $rows, 'gridcolumns' => $columns, 'admargin' => $admargin, 'adwidth' => $adwidth, 'adheight' => $adheight, 'adspeed' => $adspeed), array('id' => $id));
310
+
311
+ // Determine Dynamic Library requirement
312
+ $dynamic_count = $wpdb->get_var("SELECT COUNT(*) as `total` FROM `".$wpdb->prefix."adrotate_groups` WHERE `name` != '' AND `modus` = 1;");
313
+ update_option('adrotate_dynamic_required', $dynamic_count);
314
+
315
+ adrotate_return($action, array($id));
316
+ exit;
317
+ } else {
318
+ adrotate_return('no_access');
319
+ }
320
+ } else {
321
+ adrotate_nonce_error();
322
+ exit;
323
+ }
324
+ }
325
+
326
+ /*-------------------------------------------------------------
327
+ Name: adrotate_request_action
328
+
329
+ Purpose: Prepare action for banner or group from database
330
+ Receive: -none-
331
+ Return: -none-
332
+ Since: 2.2
333
+ -------------------------------------------------------------*/
334
+ function adrotate_request_action() {
335
+ global $wpdb, $adrotate_config;
336
+
337
+ if(wp_verify_nonce($_POST['adrotate_nonce'],'adrotate_bulk_ads_active') OR wp_verify_nonce($_POST['adrotate_nonce'],'adrotate_bulk_ads_disable')
338
+ OR wp_verify_nonce($_POST['adrotate_nonce'],'adrotate_bulk_ads_error') OR wp_verify_nonce($_POST['adrotate_nonce'],'adrotate_bulk_ads_queue')
339
+ OR wp_verify_nonce($_POST['adrotate_nonce'],'adrotate_bulk_groups')) {
340
+ if(isset($_POST['bannercheck'])) $banner_ids = $_POST['bannercheck'];
341
+ if(isset($_POST['disabledbannercheck'])) $banner_ids = $_POST['disabledbannercheck'];
342
+ if(isset($_POST['errorbannercheck'])) $banner_ids = $_POST['errorbannercheck'];
343
+ if(isset($_POST['groupcheck'])) $group_ids = $_POST['groupcheck'];
344
+ if(isset($_POST['adrotate_id'])) $banner_ids = array($_POST['adrotate_id']);
345
+
346
+ // Determine which kind of action to use
347
+ if(isset($_POST['adrotate_action'])) {
348
+ // Default action call
349
+ $actions = $_POST['adrotate_action'];
350
+ } else if(isset($_POST['adrotate_disabled_action'])) {
351
+ // Disabled ads listing call
352
+ $actions = $_POST['adrotate_disabled_action'];
353
+ } else if(isset($_POST['adrotate_error_action'])) {
354
+ // Erroneous ads listing call
355
+ $actions = $_POST['adrotate_error_action'];
356
+ } else {
357
+ // If neither, protect user with invalid ID
358
+ $banner_ids = $group_ids = '';
359
+ }
360
+ list($action, $specific) = explode("-", $actions);
361
+
362
+ if($banner_ids != '') {
363
+ if($action == 'export') {
364
+ if(current_user_can('adrotate_moderate')) {
365
+ adrotate_export($banner_ids);
366
+ $result_id = 215;
367
+ } else {
368
+ adrotate_return($return, 500);
369
+ }
370
+ }
371
+ foreach($banner_ids as $banner_id) {
372
+ if($action == 'deactivate') {
373
+ if(current_user_can('adrotate_ad_manage')) {
374
+ adrotate_active($banner_id, 'deactivate');
375
+ $result_id = $banner_id;
376
+ } else {
377
+ adrotate_return('no_access');
378
+ }
379
+ }
380
+ if($action == 'activate') {
381
+ if(current_user_can('adrotate_ad_manage')) {
382
+ adrotate_active($banner_id, 'activate');
383
+ $result_id = $banner_id;
384
+ } else {
385
+ adrotate_return('no_access');
386
+ }
387
+ }
388
+ if($action == 'delete') {
389
+ if(current_user_can('adrotate_ad_delete')) {
390
+ adrotate_delete($banner_id, 'banner');
391
+ $result_id = $banner_id;
392
+ } else {
393
+ adrotate_return('no_access');
394
+ }
395
+ }
396
+ if($action == 'reset') {
397
+ if(current_user_can('adrotate_ad_delete')) {
398
+ adrotate_reset($banner_id);
399
+ $result_id = $banner_id;
400
+ } else {
401
+ adrotate_return('no_access');
402
+ }
403
+ }
404
+ if($action == 'renew') {
405
+ if(current_user_can('adrotate_ad_manage')) {
406
+ adrotate_renew($banner_id, $specific);
407
+ $result_id = $banner_id;
408
+ } else {
409
+ adrotate_return('no_access');
410
+ }
411
+ }
412
+ if($action == 'weight') {
413
+ if(current_user_can('adrotate_ad_manage')) {
414
+ adrotate_weight($banner_id, $specific);
415
+ $result_id = $banner_id;
416
+ } else {
417
+ adrotate_return('no_access');
418
+ }
419
+ }
420
+ }
421
+ adrotate_prepare_evaluate_ads(false);
422
+ }
423
+
424
+ if($group_ids != '') {
425
+ foreach($group_ids as $group_id) {
426
+ if($action == 'group_delete') {
427
+ if(current_user_can('adrotate_group_delete')) {
428
+ adrotate_delete($group_id, 'group');
429
+ $result_id = $group_id;
430
+ } else {
431
+ adrotate_return('no_access');
432
+ }
433
+ }
434
+ if($action == 'group_delete_banners') {
435
+ if(current_user_can('adrotate_group_delete')) {
436
+ adrotate_delete($group_id, 'bannergroup');
437
+ $result_id = $group_id;
438
+ } else {
439
+ adrotate_return('no_access');
440
+ }
441
+ }
442
+ }
443
+ }
444
+
445
+ adrotate_return($action, array($result_id));
446
+ } else {
447
+ adrotate_nonce_error();
448
+ exit;
449
+ }
450
+ }
451
+
452
+ /*-------------------------------------------------------------
453
+ Name: adrotate_delete
454
+
455
+ Purpose: Remove banner or group from database
456
+ Receive: $id, $what
457
+ Return: -none-
458
+ Since: 0.1
459
+ -------------------------------------------------------------*/
460
+ function adrotate_delete($id, $what) {
461
+ global $wpdb;
462
+
463
+ if($id > 0) {
464
+ if($what == 'banner') {
465
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate` WHERE `id` = %d;", $id));
466
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = %d;", $id));
467
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_stats` WHERE `ad` = %d;", $id));
468
+ adrotate_prepare_evaluate_ads(false);
469
+ } else if ($what == 'group') {
470
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_groups` WHERE `id` = %d;", $id));
471
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `group` = %d;", $id));
472
+ adrotate_prepare_evaluate_ads(false);
473
+ } else if ($what == 'bannergroup') {
474
+ $linkmeta = $wpdb->get_results($wpdb->prepare("SELECT `ad` FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `group` = %d AND `block` = '0';", $id));
475
+ foreach($linkmeta as $meta) {
476
+ $wpdb->query("DELETE FROM `".$wpdb->prefix."adrotate` WHERE `id` = ".$meta->ad.";");
477
+ $wpdb->query("DELETE FROM `".$wpdb->prefix."adrotate_stats` WHERE `ad` = ".$meta->ad.";");
478
+ $wpdb->query("DELETE FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = ".$meta->ad.";");
479
+ }
480
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_groups` WHERE `id` = %d;", $id));
481
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `group` = %d;", $id));
482
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_stats` WHERE `group` = %d;", $id)); // Perhaps unnessesary
483
+ adrotate_prepare_evaluate_ads(false);
484
+ } else {
485
+ adrotate_return('error');
486
+ exit;
487
+ }
488
+ }
489
+ }
490
+
491
+ /*-------------------------------------------------------------
492
+ Name: adrotate_active
493
+
494
+ Purpose: Activate or Deactivate a banner
495
+ Receive: $id, $what
496
+ Return: -none-
497
+ Since: 0.1
498
+ -------------------------------------------------------------*/
499
+ function adrotate_active($id, $what) {
500
+ global $wpdb;
501
+
502
+ if($id > 0) {
503
+ if($what == 'deactivate') {
504
+ $wpdb->update($wpdb->prefix.'adrotate', array('type' => 'disabled'), array('id' => $id));
505
+ }
506
+ if ($what == 'activate') {
507
+ // Determine status of ad
508
+ $adstate = adrotate_evaluate_ad($id);
509
+ if($adstate == 'error' OR $adstate == 'expired') $adtype = 'error';
510
+ else $adtype = 'active';
511
+ $wpdb->update($wpdb->prefix.'adrotate', array('type' => $adtype), array('id' => $id));
512
+ }
513
+ }
514
+ }
515
+
516
+ /*-------------------------------------------------------------
517
+ Name: adrotate_reset
518
+
519
+ Purpose: Reset statistics for a banner
520
+ Receive: $id
521
+ Return: -none-
522
+ Since: 2.2
523
+ -------------------------------------------------------------*/
524
+ function adrotate_reset($id) {
525
+ global $wpdb;
526
+
527
+ if($id > 0) {
528
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_stats` WHERE `ad` = %d", $id));
529
+ $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."adrotate_tracker` WHERE `bannerid` = %d", $id));
530
+ }
531
+ }
532
+
533
+ /*-------------------------------------------------------------
534
+ Name: adrotate_renew
535
+
536
+ Purpose: Renew the end date of a banner with a new schedule starting where the last ended
537
+ Receive: $id, $howlong
538
+ Return: -none-
539
+ Since: 2.2
540
+ -------------------------------------------------------------*/
541
+ function adrotate_renew($id, $howlong = 2592000) {
542
+ global $wpdb;
543
+
544
+ if($id > 0) {
545
+ $schedule_id = $wpdb->get_var($wpdb->prepare("SELECT `schedule` FROM `".$wpdb->prefix."adrotate_linkmeta` WHERE `ad` = %d AND `group` = 0 AND `block` = 0 AND `user` = 0 ORDER BY `id` DESC LIMIT 1;", $id));
546
+ if($schedule_id > 0) {
547
+ $wpdb->query("UPDATE `".$wpdb->prefix."adrotate_schedule` SET `stoptime` = `stoptime` + $howlong WHERE `id` = $schedule_id;");
548
+ } else {
549
+ $now = adrotate_now();
550
+ $stoptime = $now + $howlong;
551
+ $wpdb->insert($wpdb->prefix.'adrotate_schedule', array('name' => 'Schedule for ad '.$id, 'starttime' => $now, 'stoptime' => $stoptime, 'maxclicks' => 0, 'maximpressions' => 0));
552
+ $wpdb->insert($wpdb->prefix.'adrotate_linkmeta', array('ad' => $id, 'group' => 0, 'block' => 0, 'user' => 0, 'schedule' => $wpdb->insert_id));
553
+ }
554
+ }
555
+ }
556
+
557
+ /*-------------------------------------------------------------
558
+ Name: adrotate_export
559
+
560
+ Purpose: Export selected banners
561
+ Receive: $id
562
+ Return: -none-
563
+ Since: 3.8.5
564
+ -------------------------------------------------------------*/
565
+ function adrotate_export($ids) {
566
+ if(is_array($ids)) {
567
+ adrotate_export_ads($ids);
568
+ }
569
+ }
570
+
571
+ /*-------------------------------------------------------------
572
+ Name: adrotate_options_submit
573
+
574
+ Purpose: Save options from dashboard
575
+ Receive: $_POST
576
+ Return: -none-
577
+ Since: 0.1
578
+ -------------------------------------------------------------*/
579
+ function adrotate_options_submit() {
580
+
581
+ if(wp_verify_nonce($_POST['adrotate_nonce_settings'],'adrotate_settings')) {
582
+ // Set and save user roles
583
+ adrotate_set_capability($_POST['adrotate_ad_manage'], "adrotate_ad_manage");
584
+ adrotate_set_capability($_POST['adrotate_ad_delete'], "adrotate_ad_delete");
585
+ adrotate_set_capability($_POST['adrotate_group_manage'], "adrotate_group_manage");
586
+ adrotate_set_capability($_POST['adrotate_group_delete'], "adrotate_group_delete");
587
+ $config['ad_manage'] = $_POST['adrotate_ad_manage'];
588
+ $config['ad_delete'] = $_POST['adrotate_ad_delete'];
589
+ $config['group_manage'] = $_POST['adrotate_group_manage'];
590
+ $config['group_delete'] = $_POST['adrotate_group_delete'];
591
+
592
+ //Advertisers
593
+ if(isset($_POST['adrotate_enable_stats'])) $config['enable_stats'] = 'Y';
594
+ else $config['enable_stats'] = 'N';
595
+
596
+ // Set the banner folder, reset if empty
597
+ $config['banner_folder'] = "/wp-content/banners/";
598
+
599
+ // Turn option off.
600
+ $config['notification_email_switch'] = 'N';
601
+ $config['notification_email'] = array();
602
+ $config['advertiser_email'] = array();
603
+
604
+ // Set up impression tracker timer
605
+ $impression_timer = trim($_POST['adrotate_impression_timer']);
606
+ if(is_numeric($impression_timer) AND $impression_timer >= 10 AND $impression_timer <= 3600) {
607
+ $config['impression_timer'] = $impression_timer;
608
+ } else {
609
+ $config['impression_timer'] = 60;
610
+ }
611
+
612
+ // Set up click timer
613
+ $click_timer = trim($_POST['adrotate_click_timer']);
614
+ if(is_numeric($click_timer) AND $click_timer >= 60 AND $click_timer <= 86400) {
615
+ $config['click_timer'] = $click_timer;
616
+ } else {
617
+ $config['click_timer'] = 86400;
618
+ }
619
+
620
+ // Miscellaneous Options
621
+ if(isset($_POST['adrotate_widgetalign'])) $config['widgetalign'] = 'Y';
622
+ else $config['widgetalign'] = 'N';
623
+ if(isset($_POST['adrotate_widgetpadding'])) $config['widgetpadding'] = 'Y';
624
+ else $config['widgetpadding'] = 'N';
625
+ if(isset($_POST['adrotate_w3caching'])) $config['w3caching'] = 'Y';
626
+ else $config['w3caching'] = 'N';
627
+ if(isset($_POST['adrotate_supercache'])) $config['supercache'] = 'Y';
628
+ else $config['supercache'] = 'N';
629
+ if(isset($_POST['adrotate_jquery'])) $config['jquery'] = 'Y';
630
+ else $config['jquery'] = 'N';
631
+ if(isset($_POST['adrotate_jsfooter'])) $config['jsfooter'] = 'Y';
632
+ else $config['jsfooter'] = 'N';
633
+ $config['adblock'] = 'N'; // Pro only
634
+ $config['adblock_timer'] = 0; // Pro only
635
+ $config['adblock_message'] = ''; // Pro only
636
+
637
+ update_option('adrotate_config', $config);
638
+
639
+ // Sort out crawlers
640
+ $crawlers = explode(',', trim($_POST['adrotate_crawlers']));
641
+ $clean_crawler = array();
642
+ foreach($crawlers as $crawler) {
643
+ $crawler = preg_replace('/[^a-zA-Z0-9\[\]\-_:; ]/i', '', trim($crawler));
644
+ if(strlen($crawler) > 0) $clean_crawler[] = $crawler;
645
+ }
646
+ update_option('adrotate_crawlers', $clean_crawler);
647
+
648
+ // Debug option
649
+ if(isset($_POST['adrotate_debug'])) $debug['general'] = true;
650
+ else $debug['general'] = false;
651
+ if(isset($_POST['adrotate_debug_dashboard'])) $debug['dashboard'] = true;
652
+ else $debug['dashboard'] = false;
653
+ if(isset($_POST['adrotate_debug_userroles'])) $debug['userroles'] = true;
654
+ else $debug['userroles'] = false;
655
+ if(isset($_POST['adrotate_debug_userstats'])) $debug['userstats'] = true;
656
+ else $debug['userstats'] = false;
657
+ if(isset($_POST['adrotate_debug_stats'])) $debug['stats'] = true;
658
+ else $debug['stats'] = false;
659
+ if(isset($_POST['adrotate_debug_timers'])) $debug['timers'] = true;
660
+ else $debug['timers'] = false;
661
+ if(isset($_POST['adrotate_debug_track'])) $debug['track'] = true;
662
+ else $debug['track'] = false;
663
+ update_option('adrotate_debug', $debug);
664
+
665
+ // Return to dashboard
666
+ adrotate_return('settings_saved');
667
+ } else {
668
+ adrotate_nonce_error();
669
+ exit;
670
+ }
671
+ }
672
+
673
+ /*-------------------------------------------------------------
674
+ Name: adrotate_prepare_roles
675
+
676
+ Purpose: Prepare user roles for WordPress
677
+ Receive: -None-
678
+ Return: $action
679
+ Since: 3.0
680
+ -------------------------------------------------------------*/
681
+ function adrotate_prepare_roles() {
682
+
683
+ if(isset($_POST['adrotate_role_add_submit'])) {
684
+ $action = "role_add";
685
+ adrotate_add_roles();
686
+ update_option('adrotate_roles', '1');
687
+ }
688
+ if(isset($_POST['adrotate_role_remove_submit'])) {
689
+ $action = "role_remove";
690
+ adrotate_remove_roles();
691
+ update_option('adrotate_roles', '0');
692
+ }
693
+
694
+ adrotate_return($action);
695
+ }
696
+
697
+ /*-------------------------------------------------------------
698
+ Name: adrotate_add_roles
699
+
700
+ Purpose: Add User roles and capabilities
701
+ Receive: -None-
702
+ Return: -None-
703
+ Since: 3.0
704
+ -------------------------------------------------------------*/
705
+ function adrotate_add_roles() {
706
+ add_role('adrotate_advertiser', 'AdRotate Advertiser', array('read' => 1));
707
+ }
708
+
709
+ /*-------------------------------------------------------------
710
+ Name: adrotate_remove_roles
711
+
712
+ Purpose: Remove User roles and capabilities
713
+ Receive: -None-
714
+ Return: -None-
715
+ Since: 3.0
716
+ -------------------------------------------------------------*/
717
+ function adrotate_remove_roles() {
718
+ remove_role('adrotate_advertiser');
719
+ }
720
+ ?>
adrotate-output.php ADDED
@@ -0,0 +1,1018 @@