function adrotate_import_ads()
{
    global $wpdb, $current_user, $userdata;
    if (wp_verify_nonce($_POST['adrotate_nonce'], 'adrotate_import')) {
        if (current_user_can('adrotate_ad_manage')) {
            if ($_FILES["adrotate_file"]["error"] == 4) {
                adrotate_return('adrotate-ads', 506, array('view' => 'import'));
                exit;
            } else {
                if ($_FILES["adrotate_file"]["error"] > 0) {
                    adrotate_return('adrotate-ads', 507, array('view' => 'import'));
                    exit;
                } else {
                    if ($_FILES["adrotate_file"]["size"] > 4096000) {
                        adrotate_return('adrotate-ads', 511, array('view' => 'import'));
                        exit;
                    } else {
                        $now = adrotate_now();
                        $ad_fields = array('title', 'bannercode', 'thetime', 'updated', 'author', 'imagetype', 'image', 'tracker', 'responsive', 'type', 'weight', 'sortorder', 'budget', 'crate', 'irate', 'cities', 'countries');
                        if ($_FILES["adrotate_file"]["type"] == "text/xml" or $_FILES["adrotate_file"]["type"] == "application/xml" or $_FILES["adrotate_file"]["type"] == "application/x-xml") {
                            $xml_name = "adrotate_import_" . date_i18n("mdYHi", $now) . ".xml";
                            move_uploaded_file($_FILES["adrotate_file"]["tmp_name"], WP_CONTENT_DIR . "/reports/" . $xml_name);
                            $file = WP_CONTENT_URL . "/reports/" . $xml_name;
                            $xml = simplexml_load_file($file);
                            foreach ($xml->xpath('advert') as $advert) {
                                $ad = array('title' => strip_tags(htmlspecialchars(trim($advert->title, "\t\n "), ENT_QUOTES)), 'bannercode' => htmlspecialchars(trim($advert->bannercode, "\t\n "), ENT_QUOTES), 'thetime' => $now, 'updated' => $now, 'author' => $current_user->user_login, 'imagetype' => strip_tags(trim($advert->imagetype, "\t\n ")), 'image' => strip_tags(trim($advert->image, "\t\n ")), 'tracker' => strip_tags(trim($advert->tracker, "\t\n ")), 'mobile' => strip_tags(trim($advert->mobile, "\t\n ")), 'tablet' => strip_tags(trim($advert->tablet, "\t\n ")), 'responsive' => strip_tags(trim($advert->responsive, "\t\n ")), 'type' => 'import', 'weight' => strip_tags(trim($advert->weight, "\t\n ")), 'sortorder' => 0, 'budget' => strip_tags(trim($advert->budget, "\t\n ")), 'crate' => strip_tags(trim($advert->crate, "\t\n ")), 'irate' => strip_tags(trim($advert->irate, "\t\n ")), 'cities' => serialize(explode(',', strip_tags(trim($advert->cities, "\t\n ")))), 'countries' => serialize(explode(',', strip_tags(trim($advert->countries, "\t\n ")))));
                                $wpdb->insert($wpdb->prefix . "adrotate", $ad);
                                $ad_id = $wpdb->insert_id;
                                $schedule = array('name' => 'Schedule for advert ' . $ad_id, 'starttime' => strip_tags(trim($advert->start, "\t\n ")), 'stoptime' => strip_tags(trim($advert->end, "\t\n ")), 'maxclicks' => 0, 'maximpressions' => 0, 'spread' => 'N', 'dayimpressions' => 0);
                                $wpdb->insert($wpdb->prefix . "adrotate_schedule", $schedule);
                                $schedule_id = $wpdb->insert_id;
                                $linkmeta = array('ad' => $ad_id, 'group' => 0, 'user' => 0, 'schedule' => $schedule_id);
                                $wpdb->insert($wpdb->prefix . "adrotate_linkmeta", $linkmeta);
                                unset($advert, $ad, $ad_id, $schedule, $schedule_id, $linkmeta);
                            }
                        }
                        adrotate_prepare_evaluate_ads(false);
                        // return to dashboard
                        adrotate_return('adrotate-ads', 216);
                        exit;
                    }
                }
            }
        } else {
            adrotate_return('adrotate-ads', 500);
        }
    } else {
        adrotate_nonce_error();
        exit;
    }
}
Beispiel #2
0
function adrotate_export_ads($ids, $format)
{
    global $wpdb;
    $all_ads = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}adrotate` ORDER BY `id` ASC;", ARRAY_A);
    $ads = array();
    foreach ($all_ads as $single) {
        if (in_array($single['id'], $ids)) {
            $starttime = $stoptime = 0;
            $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;");
            $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;");
            if (!is_array($single['cities'])) {
                $single['cities'] = array();
            }
            if (!is_array($single['countries'])) {
                $single['countries'] = array();
            }
            $ads[$single['id']] = array('title' => $single['title'], 'bannercode' => stripslashes($single['bannercode']), 'imagetype' => $single['imagetype'], 'image' => $single['image'], 'tracker' => $single['tracker'], 'mobile' => $single['mobile'], 'tablet' => $single['tablet'], 'responsive' => $single['responsive'], 'weight' => $single['weight'], 'budget' => $single['budget'], 'crate' => $single['crate'], 'irate' => $single['irate'], 'cities' => implode(',', maybe_unserialize($single['cities'])), 'countries' => implode(',', maybe_unserialize($single['countries'])), 'start' => $starttime, 'end' => $stoptime);
        }
    }
    if ($ads) {
        $filename = "AdRotate_export_" . date_i18n("mdYHi") . "_" . uniqid() . ".xml";
        $xml = new SimpleXMLElement('<adverts></adverts>');
        foreach ($ads as $ad) {
            $node = $xml->addChild('advert');
            $node->addChild('title', $ad['title']);
            $node->addChild('bannercode', $ad['bannercode']);
            $node->addChild('imagetype', $ad['imagetype']);
            $node->addChild('image', $ad['image']);
            $node->addChild('tracker', $ad['tracker']);
            $node->addChild('mobile', $ad['mobile']);
            $node->addChild('tablet', $ad['tablet']);
            $node->addChild('responsive', $ad['responsive']);
            $node->addChild('weight', $ad['weight']);
            $node->addChild('budget', $ad['budget']);
            $node->addChild('crate', $ad['crate']);
            $node->addChild('irate', $ad['irate']);
            $node->addChild('cities', $ad['cities']);
            $node->addChild('countries', $ad['countries']);
            $node->addChild('start', $ad['start']);
            $node->addChild('end', $ad['end']);
        }
        file_put_contents(WP_CONTENT_DIR . '/reports/' . $filename, $xml->saveXML());
        unset($all_ads, $ads);
        adrotate_return('adrotate-ads', 215, array('file' => $filename));
        exit;
    } else {
        adrotate_return('adrotate-ads', 509);
    }
}
function adrotate_export_ads($ids)
{
    global $wpdb;
    $all_ads = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "adrotate` ORDER BY `id` ASC;", ARRAY_A);
    $filename = "AdRotate_export_" . date_i18n("mdYHi") . "_" . uniqid() . ".xml";
    $fp = fopen(WP_CONTENT_DIR . '/reports/' . $filename, 'r');
    $xml = new SimpleXMLElement('<adverts></adverts>');
    foreach ($all_ads as $single) {
        if (in_array($single['id'], $ids)) {
            $starttime = $stoptime = 0;
            $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;");
            $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;");
            if (!is_array($single['cities'])) {
                $single['cities'] = array();
            }
            if (!is_array($single['countries'])) {
                $single['countries'] = array();
            }
            $node = $xml->addChild('advert');
            $node->addChild('title', $single['title']);
            $node->addChild('bannercode', stripslashes($single['bannercode']));
            $node->addChild('imagetype', $single['imagetype']);
            $node->addChild('image', $single['image']);
            $node->addChild('link', $single['link']);
            $node->addChild('tracker', $single['tracker']);
            $node->addChild('responsive', $single['responsive']);
            $node->addChild('weight', $single['weight']);
            $node->addChild('budget', $single['budget']);
            $node->addChild('crate', $single['crate']);
            $node->addChild('irate', $single['irate']);
            $node->addChild('cities', implode(',', unserialize($single['cities'])));
            $node->addChild('countries', implode(',', unserialize($single['countries'])));
            $node->addChild('start', $starttime);
            $node->addChild('end', $stoptime);
        }
    }
    file_put_contents(WP_CONTENT_DIR . '/reports/' . $filename, $xml->saveXML());
    adrotate_return('exported', array($filename));
    exit;
}
function adrotate_prepare_evaluate_ads($return = true, $id = 0)
{
    global $wpdb;
    $getid = '';
    if ($id > 0) {
        $getid = " AND `id` = {$id}";
    } else {
        $getid = " AND `type` != 'empty'";
    }
    // Fetch ads
    $ads = $wpdb->get_results("SELECT `id` FROM `" . $wpdb->prefix . "adrotate` WHERE `type` != 'disabled'{$getid} ORDER BY `id` ASC;");
    // Determine error states
    $error = $expired = $expiressoon = $normal = $unknown = 0;
    foreach ($ads as $ad) {
        $result = adrotate_evaluate_ad($ad->id);
        if ($result == 'error') {
            $error++;
            $wpdb->query("UPDATE `" . $wpdb->prefix . "adrotate` SET `type` = 'error' WHERE `id` = '" . $ad->id . "';");
        }
        if ($result == 'expired') {
            $expired++;
            $wpdb->query("UPDATE `" . $wpdb->prefix . "adrotate` SET `type` = 'expired' WHERE `id` = '" . $ad->id . "';");
        }
        if ($result == '2days') {
            $expiressoon++;
            $wpdb->query("UPDATE `" . $wpdb->prefix . "adrotate` SET `type` = '2days' WHERE `id` = '" . $ad->id . "';");
        }
        if ($result == '7days') {
            $normal++;
            $wpdb->query("UPDATE `" . $wpdb->prefix . "adrotate` SET `type` = '7days' WHERE `id` = '" . $ad->id . "';");
        }
        if ($result == 'active') {
            $normal++;
            $wpdb->query("UPDATE `" . $wpdb->prefix . "adrotate` SET `type` = 'active' WHERE `id` = '" . $ad->id . "';");
        }
        if ($result == 'unknown') {
            $unknown++;
        }
    }
    $count = $expired + $expiressoon + $error;
    $result = array('error' => $error, 'expired' => $expired, 'expiressoon' => $expiressoon, 'normal' => $normal, 'total' => $count, 'unknown' => $unknown);
    update_option('adrotate_advert_status', $result);
    if ($return) {
        adrotate_return('adrotate-settings', 405);
    }
}
Beispiel #5
0
function adrotate_license_response($request = '', $a = array(), $uninstall = false, $network = false, $hide = 0, $force = 0)
{
    global $ajdg_solutions_domain;
    $args = $license = array();
    if ($request == 'activation') {
        $args = array('request' => 'activation', 'email' => $a['email'], 'license_key' => $a['key'], 'product_id' => $a['type'], 'instance' => $a['instance'], 'platform' => $a['platform']);
    }
    if ($request == 'deactivation') {
        $args = array('request' => 'deactivation', 'email' => $a['email'], 'license_key' => $a['key'], 'product_id' => $a['type'], 'instance' => $a['instance']);
    }
    $http_args = array('timeout' => 15, 'sslverify' => false, 'headers' => array('user-agent' => 'AdRotate Pro;'));
    if ($a['version'] == '101') {
        // Old licenses from adrotateplugin.com
        $response = wp_remote_get($ajdg_solutions_domain . 'api/license/?' . http_build_query($args, '', '&'), $http_args);
    } else {
        // Licenses from ajdg.solutions
        $response = wp_remote_get(add_query_arg('wc-api', 'software-api', $ajdg_solutions_domain) . '&' . http_build_query($args, '', '&'), $http_args);
    }
    if ($network) {
        $redirect = 'adrotate';
    } else {
        $redirect = 'adrotate-settings';
    }
    if ($uninstall) {
        return;
    }
    if (!is_wp_error($response) || wp_remote_retrieve_response_code($response) === 200) {
        $data = json_decode($response['body'], 1);
        if (empty($data['code'])) {
            $data['code'] = 0;
        }
        if (empty($data['activated'])) {
            $data['activated'] = 0;
        }
        if (empty($data['reset'])) {
            $data['reset'] = 0;
        }
        if ($data['code'] == 100) {
            // Invalid Request
            adrotate_return($redirect, 600, array('tab' => 'license'));
            exit;
        } else {
            if ($data['code'] == 101) {
                // Invalid License
                adrotate_return($redirect, 604, array('tab' => 'license'));
                exit;
            } else {
                if ($data['code'] == 102) {
                    // Order is not complete
                    adrotate_return($redirect, 605, array('tab' => 'license'));
                    exit;
                } else {
                    if ($data['code'] == 103) {
                        // No activations remaining
                        adrotate_return($redirect, 606, array('tab' => 'license'));
                        exit;
                    } else {
                        if ($data['code'] == 104) {
                            // Could not (de)activate
                            adrotate_return($redirect, 607, array('tab' => 'license'));
                            exit;
                        } else {
                            if ($data['code'] == 0 && $data['activated'] == 1) {
                                // Activated
                                update_option('adrotate_hide_license', $hide);
                                if ($network) {
                                    update_site_option('adrotate_activate', array('status' => 1, 'instance' => $a['instance'], 'activated' => current_time('timestamp'), 'deactivated' => '', 'type' => $a['type'], 'key' => $a['key'], 'email' => $a['email'], 'version' => $a['version'], 'firstrun' => 0));
                                } else {
                                    update_option('adrotate_activate', array('status' => 1, 'instance' => $a['instance'], 'activated' => current_time('timestamp'), 'deactivated' => '', 'type' => $a['type'], 'key' => $a['key'], 'email' => $a['email'], 'version' => $a['version'], 'firstrun' => 0));
                                }
                                unset($a, $args, $response, $data);
                                if ($request == 'activation') {
                                    adrotate_return($redirect, 608, array('tab' => 'license'));
                                }
                                exit;
                            } else {
                                if ($data['code'] == 0 && $data['reset'] == 1 or $force == 1) {
                                    // Deactivated
                                    update_option('adrotate_hide_license', 0);
                                    if ($network) {
                                        update_site_option('adrotate_activate', array('status' => 0, 'instance' => '', 'activated' => $a['activated'], 'deactivated' => current_time('timestamp'), 'type' => '', 'key' => '', 'email' => '', 'version' => '', 'firstrun' => 1));
                                    } else {
                                        update_option('adrotate_activate', array('status' => 0, 'instance' => '', 'activated' => $a['activated'], 'deactivated' => current_time('timestamp'), 'type' => '', 'key' => '', 'email' => '', 'version' => '', 'firstrun' => 1));
                                    }
                                    unset($a, $args, $response, $data);
                                    if ($request == 'deactivation') {
                                        adrotate_return($redirect, 609, array('tab' => 'license'));
                                    }
                                    exit;
                                } else {
                                    adrotate_return($redirect, 600, array('tab' => 'license'));
                                    exit;
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        adrotate_return($redirect, 602, array('tab' => 'license'));
        exit;
    }
}
Beispiel #6
0
function adrotate_cleanup_database() {
	global $wpdb;

	$now = adrotate_now();
	
	// Delete expired schedules
	if(isset($_POST['adrotate_db_cleanup_schedules'])) {
		$wpdb->query("DELETE FROM `{$wpdb->prefix}adrotate_schedule` WHERE `stoptime` < $now;");
	}

	// Delete old stats
	if(isset($_POST['adrotate_db_cleanup_statistics'])) {
		$lastyear = $now - 30758400;
		$wpdb->query("DELETE FROM `{$wpdb->prefix}adrotate_stats` WHERE `thetime` < $lastyear;");
	}

	// Clean up Tracker data
	$yesterday = $now - 2073600;
	$wpdb->query("DELETE FROM `{$wpdb->prefix}adrotate_tracker` WHERE `timer` < $yesterday;");

	// Delete empty ads, groups and schedules
	$wpdb->query("DELETE FROM `{$wpdb->prefix}adrotate` WHERE `type` = 'empty' OR `type` = 'a_empty';");
	$wpdb->query("DELETE FROM `{$wpdb->prefix}adrotate_groups` WHERE `name` = '';");
	
	// Clean up meta data
	$ads = $wpdb->get_results("SELECT `id` FROM `{$wpdb->prefix}adrotate` ORDER BY `id`;");
	$metas = $wpdb->get_results("SELECT `id`, `ad` FROM `{$wpdb->prefix}adrotate_linkmeta` WHERE `ad` != '0' ORDER BY `id`;");
	
	$adverts = $linkmeta = array();
	foreach($ads as $ad) {
		$adverts[$ad->id] = $ad->id;
	}
	foreach($metas as $meta) {
		$linkmeta[$meta->id] = $meta->ad;
	}

	$result = array_diff($linkmeta, $adverts);
	foreach($result as $key => $value) {
		$wpdb->query("DELETE FROM `{$wpdb->prefix}adrotate_linkmeta` WHERE `id` = $key;");
		unset($result[$key]);
	}
	unset($ads, $metas, $adverts, $linkmeta, $result);

	// Clean up stray linkmeta
	$wpdb->query("DELETE FROM `{$wpdb->prefix}adrotate_linkmeta` WHERE `ad` = 0 OR `ad` = '';");

	adrotate_return('adrotate-settings', 406);
}
function adrotate_options_submit()
{
    if (wp_verify_nonce($_POST['adrotate_nonce_settings'], 'adrotate_settings')) {
        $settings_tab = esc_attr($_POST['adrotate_settings_tab']);
        if ($settings_tab == 'general') {
            $config = get_option('adrotate_config');
            $config['jquery'] = isset($_POST['adrotate_jquery']) ? 'Y' : 'N';
            $config['jsfooter'] = isset($_POST['adrotate_jsfooter']) ? 'Y' : 'N';
            // Turn options off. Available in AdRotate Pro only
            $config['banner_folder'] = "wp-content/banners/";
            $config['notification_email'] = array();
            $config['advertiser_email'] = array();
            $config['adblock'] = 'N';
            $config['adblock_timer'] = 0;
            $config['adblock_message'] = '';
            $config['enable_geo'] = 0;
            $config['geo_cookie_life'] = 86400;
            $config['geo_email'] = '';
            $config['geo_pass'] = '';
            $config['enable_advertisers'] = 'N';
            $config['enable_editing'] = 'N';
            $config['enable_geo_advertisers'] = 0;
            $config['adblock'] = 'N';
            $config['adblock_loggedin'] = 'N';
            $config['adblock_timer'] = 5;
            $config['adblock_message'] = "Ad blocker detected! Please wait %time% seconds or disable your ad blocker!";
            update_option('adrotate_config', $config);
            // Sort out crawlers
            $crawlers = explode(',', trim($_POST['adrotate_crawlers']));
            $new_crawlers = array();
            foreach ($crawlers as $crawler) {
                $crawler = preg_replace('/[^a-zA-Z0-9\\[\\]\\-_:; ]/i', '', trim($crawler));
                if (strlen($crawler) > 0) {
                    $new_crawlers[] = $crawler;
                }
            }
            update_option('adrotate_crawlers', $new_crawlers);
            $notifications = get_option('adrotate_notifications');
            // Turn options off. Available in AdRotate Pro only
            $notifications['notification_email'] = 'N';
            $notifications['notification_push'] = 'N';
            $notifications['notification_dashboard'] = 'Y';
            $notifications['notification_email_publisher'] = array();
            $notifications['notification_email_advertiser'] = array(get_option('admin_email'));
            $notifications['notification_push_geo'] = 'N';
            $notifications['notification_push_status'] = 'N';
            $notifications['notification_push_queue'] = 'N';
            $notifications['notification_push_approved'] = 'N';
            $notifications['notification_push_rejected'] = 'N';
            $notifications['notification_push_user'] = '';
            $notifications['notification_push_api'] = '';
            update_option('adrotate_notifications', $notifications);
        }
        if ($settings_tab == 'stats') {
            $config = get_option('adrotate_config');
            $stats = trim($_POST['adrotate_stats']);
            $config['stats'] = (is_numeric($stats) and $stats >= 0 and $stats <= 3) ? $stats : 1;
            $config['enable_loggedin_impressions'] = 'Y';
            $config['enable_loggedin_clicks'] = 'Y';
            $impression_timer = trim($_POST['adrotate_impression_timer']);
            $config['impression_timer'] = (is_numeric($impression_timer) and $impression_timer >= 10 and $impression_timer <= 3600) ? $impression_timer : 60;
            $click_timer = trim($_POST['adrotate_click_timer']);
            $config['click_timer'] = (is_numeric($click_timer) and $click_timer >= 60 and $click_timer <= 86400) ? $click_timer : 86400;
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'roles') {
            $config = get_option('adrotate_config');
            adrotate_set_capability($_POST['adrotate_ad_manage'], "adrotate_ad_manage");
            adrotate_set_capability($_POST['adrotate_ad_delete'], "adrotate_ad_delete");
            adrotate_set_capability($_POST['adrotate_group_manage'], "adrotate_group_manage");
            adrotate_set_capability($_POST['adrotate_group_delete'], "adrotate_group_delete");
            $config['ad_manage'] = $_POST['adrotate_ad_manage'];
            $config['ad_delete'] = $_POST['adrotate_ad_delete'];
            $config['group_manage'] = $_POST['adrotate_group_manage'];
            $config['group_delete'] = $_POST['adrotate_group_delete'];
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'misc') {
            $config = get_option('adrotate_config');
            $config['widgetalign'] = isset($_POST['adrotate_widgetalign']) ? 'Y' : 'N';
            $config['widgetpadding'] = isset($_POST['adrotate_widgetpadding']) ? 'Y' : 'N';
            $config['adminbar'] = isset($_POST['adrotate_adminbar']) ? 'Y' : 'N';
            $config['hide_schedules'] = isset($_POST['adrotate_hide_schedules']) ? 'Y' : 'N';
            $config['w3caching'] = isset($_POST['adrotate_w3caching']) ? 'Y' : 'N';
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'maintenance') {
            $debug = get_option('adrotate_debug');
            $debug['general'] = isset($_POST['adrotate_debug']) ? true : false;
            $debug['publisher'] = isset($_POST['adrotate_debug_publisher']) ? true : false;
            $debug['timers'] = isset($_POST['adrotate_debug_timers']) ? true : false;
            $debug['track'] = isset($_POST['adrotate_debug_track']) ? true : false;
            update_option('adrotate_debug', $debug);
        }
        // Return to dashboard
        adrotate_return('adrotate-settings', 400, array('tab' => $settings_tab));
    } else {
        adrotate_nonce_error();
        exit;
    }
}
function adrotate_mail_message()
{
    if (wp_verify_nonce($_POST['adrotate_nonce'], 'adrotate_email_advertiser') or wp_verify_nonce($_POST['adrotate_nonce'], 'adrotate_email_moderator')) {
        $notifications = get_option("adrotate_notifications");
        $id = $_POST['adrotate_id'];
        $request = $_POST['adrotate_request'];
        $author = $_POST['adrotate_username'];
        $useremail = $_POST['adrotate_email'];
        $text = strip_tags(stripslashes(trim($_POST['adrotate_message'], "\t\n ")));
        if (strlen($text) < 1) {
            $text = "";
        }
        $emails = $notifications['notification_email_advertiser'];
        $x = count($emails);
        if ($x == 0) {
            $emails = array(get_option('admin_email'));
        }
        $siteurl = get_option('siteurl');
        $adurl = $siteurl . "/wp-admin/admin.php?page=adrotate-ads&view=edit&ad=" . $id;
        $pluginurl = "https://ajdg.solutions/products/adrotate-for-wordpress/";
        $now = adrotate_now();
        if ($request == "renew") {
            $subject = __('[AdRotate] An advertiser has put in a request for renewal!', 'adrotate-pro');
        }
        if ($request == "remove") {
            $subject = __('[AdRotate] An advertiser wants his ad removed.', 'adrotate-pro');
        }
        if ($request == "other") {
            $subject = __('[AdRotate] An advertiser wrote a comment on his ad!', 'adrotate-pro');
        }
        if ($request == "issue") {
            $subject = __('[AdRotate] An advertiser has a problem!', 'adrotate-pro');
        }
        $message = "<p>Hello,</p>";
        if ($request == "renew") {
            $message .= "<p>{$author} " . __('requests ad', 'adrotate-pro') . " <strong>{$id}</strong> " . __('renewed!', 'adrotate-pro') . "</p>";
        }
        if ($request == "remove") {
            $message .= "<p>{$author} " . __('requests ad', 'adrotate-pro') . " <strong>{$id}</strong> " . __('removed.', 'adrotate-pro') . "</p>";
        }
        if ($request == "other") {
            $message .= "<p>{$author} " . __('has something to say about ad', 'adrotate-pro') . " <strong>{$id}</strong>.</p>";
        }
        if ($request == "issue") {
            $message .= "<p>{$author} " . __('has a problem with AdRotate.', 'adrotate-pro') . "</p>";
        }
        $message .= "<p>" . __('Attached message:', 'adrotate-pro') . " {$text}</p>";
        $message .= "<p>" . __('You can reply to this message to contact', 'adrotate-pro') . " {$author}.<br />";
        if ($request != "issue") {
            $message .= __('Review the ad here:', 'adrotate-pro') . " {$adurl}";
        }
        $message .= "</p>";
        $message .= "<p>" . __('Have a nice day!', 'adrotate-pro') . "<br />";
        $message .= __('Your AdRotate Notifier', 'adrotate-pro') . "<br />";
        $message .= "{$pluginurl}</p>";
        for ($i = 0; $i < $x; $i++) {
            $headers = "Content-Type: text/html; charset=UTF-8" . "\r\n" . "From: {$author} <{$useremail}>" . "\r\n";
            wp_mail($emails[$i], $subject, $message, $headers);
        }
        adrotate_return('adrotate-advertiser', 300);
    } else {
        adrotate_nonce_error();
        exit;
    }
}
function adrotate_advertiser_insert_input()
{
    global $wpdb, $adrotate_config;
    if (wp_verify_nonce($_POST['adrotate_nonce'], 'adrotate_save_ad')) {
        // Mandatory
        $id = $author = $title = $bannercode = '';
        if (isset($_POST['adrotate_id'])) {
            $id = $_POST['adrotate_id'];
        }
        if (isset($_POST['adrotate_username'])) {
            $author = $_POST['adrotate_username'];
        }
        if (isset($_POST['adrotate_title'])) {
            $title = strip_tags(htmlspecialchars(trim($_POST['adrotate_title'], "\t\n "), ENT_QUOTES));
        }
        if (isset($_POST['adrotate_bannercode'])) {
            $bannercode = htmlspecialchars(trim($_POST['adrotate_bannercode'], "\t\n "), ENT_QUOTES);
        }
        $thetime = adrotate_now();
        // Schedule and timeframe variables
        $schedules = $groups = $group_array = '';
        if (isset($_POST['scheduleselect'])) {
            $schedules = $_POST['scheduleselect'];
        }
        if (isset($_POST['groupselect'])) {
            $groups = $_POST['groupselect'];
        }
        // GeoTargeting
        $cities = '';
        $countries = array();
        if (isset($_POST['adrotate_geo_cities'])) {
            $cities = trim($_POST['adrotate_geo_cities'], "\t\n ");
        }
        if (isset($_POST['adrotate_geo_countries'])) {
            $countries = $_POST['adrotate_geo_countries'];
        }
        if (isset($_POST['adrotate_geo_westeurope'])) {
            $countries_westeurope = array('AD', 'AT', 'BE', 'DK', 'FR', 'DE', 'GR', 'IS', 'IE', 'IT', 'LI', 'LU', 'MT', 'MC', 'NL', 'NO', 'PT', 'SM', 'ES', 'SE', 'CH', 'VA', 'GB');
        }
        if (isset($_POST['adrotate_geo_easteurope'])) {
            $countries_easteurope = array('AL', 'AM', 'AZ', 'BY', 'BA', 'BG', 'HR', 'CY', 'CZ', 'EE', 'FI', 'GE', 'HU', 'LV', 'LT', 'MK', 'MD', 'PL', 'RO', 'RS', 'SK', 'SI', 'TR', 'UA');
        }
        if (isset($_POST['adrotate_geo_northamerica'])) {
            $countries_northamerica = array('AG', 'BS', 'BB', 'BZ', 'CA', 'CR', 'CU', 'DM', 'DO', 'SV', 'GD', 'GT', 'HT', 'HN', 'JM', 'MX', 'NI', 'PA', 'KN', 'LC', 'VC', 'TT', 'US');
        }
        if (isset($_POST['adrotate_geo_southamerica'])) {
            $countries_southamerica = array('AR', 'BO', 'BR', 'CL', 'CO', 'EC', 'GY', 'PY', 'PE', 'SR', 'UY', 'VE');
        }
        if (isset($_POST['adrotate_geo_southeastasia'])) {
            $countries_southeastasia = array('AU', 'BN', 'KH', 'TL', 'ID', 'LA', 'MY', 'MM', 'NZ', 'PH', 'SG', 'TH', 'VN');
        }
        // Ad options
        $adrotate_image_current = $type = $weight = '';
        if (isset($_POST['adrotate_image_current'])) {
            $adrotate_image_current = strip_tags(htmlspecialchars(trim($_POST['adrotate_image_current'], "\t\n "), ENT_QUOTES));
        }
        if (isset($_POST['adrotate_type'])) {
            $type = strip_tags(htmlspecialchars(trim($_POST['adrotate_type'], "\t\n "), ENT_QUOTES));
        }
        if (isset($_POST['adrotate_desktop'])) {
            $desktop = strip_tags(trim($_POST['adrotate_desktop'], "\t\n "));
        }
        if (isset($_POST['adrotate_mobile'])) {
            $mobile = strip_tags(trim($_POST['adrotate_mobile'], "\t\n "));
        }
        if (isset($_POST['adrotate_tablet'])) {
            $tablet = strip_tags(trim($_POST['adrotate_tablet'], "\t\n "));
        }
        if (isset($_POST['adrotate_weight'])) {
            $weight = $_POST['adrotate_weight'];
        }
        if (current_user_can('adrotate_advertiser')) {
            if (strlen($title) < 1) {
                $title = 'Ad ' . $id;
            }
            if ($_FILES["adrotate_image"]["size"] > 0) {
                $allowedExts = array("jpg", "jpeg", "gif", "png", "flv", "swf");
                $filename = sanitize_file_name(strtolower($_FILES["adrotate_image"]["name"]));
                $extension = explode(".", $_FILES["adrotate_image"]["name"]);
                $extension = end($extension);
                $image_path = ABSPATH . $adrotate_config['banner_folder'];
                if (($_FILES["adrotate_image"]["type"] == "image/gif" or $_FILES["adrotate_image"]["type"] == "image/jpeg" or $_FILES["adrotate_image"]["type"] == "image/pjpeg" or $_FILES["adrotate_image"]["type"] == "image/jpg" or $_FILES["adrotate_image"]["type"] == "image/png" or $_FILES["adrotate_image"]["type"] == "application/x-shockwave-flash" or $_FILES["adrotate_image"]["type"] == "video/x-flv" or $_FILES["adrotate_image"]["size"] <= 512000) and in_array($extension, $allowedExts)) {
                    if ($_FILES["adrotate_image"]["error"] > 0) {
                        if ($_FILES["adrotate_image"]["error"] == 1 or $_FILES["adrotate_image"]["error"] == 2) {
                            $errorcode = __("File size exceeded.", "adrotate");
                        } else {
                            if ($_FILES["adrotate_image"]["error"] == 3) {
                                $errorcode = __("Upload incomplete.", "adrotate");
                            } else {
                                if ($_FILES["adrotate_image"]["error"] == 4) {
                                    $errorcode = __("No file uploaded.", "adrotate");
                                } else {
                                    if ($_FILES["adrotate_image"]["error"] == 6 or $_FILES["adrotate_image"]["error"] == 7) {
                                        $errorcode = __("Could not write file to server.", "adrotate");
                                    } else {
                                        $errorcode = __("An unknown error occured, contact staff.", "adrotate");
                                    }
                                }
                            }
                        }
                        wp_die("<h3>" . __("Something went wrong!", "adrotate") . "</h3><p>" . __("Go back and try again. If the error persists, contact staff.", "adrotate") . "</p><p style='color: #f00;'>" . $errorcode . "</p>");
                    } else {
                        $image_name = $id . "-" . $author . "-" . $thetime . "-" . $filename;
                        move_uploaded_file($_FILES["adrotate_image"]["tmp_name"], $image_path . $image_name);
                    }
                } else {
                    wp_die("<h3>" . __("Something went wrong!", "adrotate") . "</h3><p>" . __("Go back and try again. If the error persists, contact staff.", "adrotate") . "</p><p style='color: #f00;'>" . __("The file was either too large or not in the right format.", "adrotate") . "</p>");
                }
            } else {
                $image_name = $adrotate_image_current;
            }
            // Force image location
            $image = site_url() . "/%folder%" . $image_name;
            // Determine image settings ($image_field has priority!)
            if (strlen($image_name) > 0) {
                $imagetype = "dropdown";
                $image = site_url() . "/%folder%" . $image_name;
            } else {
                $imagetype = "";
                $image = "";
            }
            // Set desktop value
            if (isset($desktop) and strlen($desktop) != 0) {
                $desktop = 'Y';
            } else {
                $desktop = 'N';
            }
            // Set mobile value
            if (isset($mobile) and strlen($mobile) != 0) {
                $mobile = 'Y';
            } else {
                $mobile = 'N';
            }
            // Set tablet value
            if (isset($tablet) and strlen($tablet) != 0) {
                $tablet = 'Y';
            } else {
                $tablet = 'N';
            }
            // Geo Targeting
            if (strlen($cities) > 0) {
                $cities = explode(",", strtolower($cities));
                foreach ($cities as $key => $value) {
                    $cities_clean[] = trim($value);
                    unset($value);
                }
                unset($cities);
                $cities = serialize($cities_clean);
            }
            $countries = array_merge($countries, $countries_westeurope, $countries_easteurope, $countries_northamerica, $countries_southamerica, $countries_southeastasia);
            $countries = array_unique($countries);
            if (count($countries) == 0) {
                $countries = serialize(array());
            } else {
                foreach ($countries as $key => $value) {
                    $countries_clean[] = trim($value);
                    unset($value);
                }
                unset($countries);
                $countries = serialize($countries_clean);
            }
            // Fetch schedules for the ad
            $schedulemeta = $wpdb->get_results($wpdb->prepare("SELECT `schedule` FROM `" . $wpdb->prefix . "adrotate_linkmeta` WHERE `ad` = %d AND `group` = 0 AND `user` = 0;", $id));
            $schedule_array = array();
            foreach ($schedulemeta as $meta) {
                $schedule_array[] = $meta->schedule;
                unset($meta);
            }
            // Add new schedules to this ad
            if (!is_array($schedules)) {
                $schedules = array();
            }
            $insert = array_diff($schedules, $schedule_array);
            foreach ($insert as &$value) {
                $wpdb->insert($wpdb->prefix . 'adrotate_linkmeta', array('ad' => $id, 'group' => 0, 'user' => 0, 'schedule' => $value));
            }
            unset($insert, $value);
            // Remove schedules from this ad
            $delete = array_diff($schedule_array, $schedules);
            foreach ($delete as &$value) {
                $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->prefix . "adrotate_linkmeta` WHERE `ad` = %d AND `group` = 0 AND `user` = 0 AND `schedule` = %d;", $id, $value));
            }
            unset($delete, $value, $schedulemeta, $schedule_array);
            // Fetch group records for the ad
            $groupmeta = $wpdb->get_results($wpdb->prepare("SELECT `group` FROM `" . $wpdb->prefix . "adrotate_linkmeta` WHERE `ad` = %d AND `user` = 0 AND `schedule` = 0;", $id));
            $group_array = array();
            foreach ($groupmeta as $meta) {
                $group_array[] = $meta->group;
                unset($meta);
            }
            // Add new groups to this ad
            if (!is_array($groups)) {
                $groups = array();
            }
            $insert = array_diff($groups, $group_array);
            foreach ($insert as &$value) {
                $wpdb->insert($wpdb->prefix . 'adrotate_linkmeta', array('ad' => $id, 'group' => $value, 'user' => 0, 'schedule' => 0));
            }
            unset($insert, $value);
            // Remove groups from this ad
            $delete = array_diff($group_array, $groups);
            foreach ($delete as &$value) {
                $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->prefix . "adrotate_linkmeta` WHERE `ad` = %d AND `group` = %d AND `user` = 0 AND `schedule` = 0;", $id, $value));
            }
            unset($delete, $value, $groupmeta, $group_array);
            // Save the ad to the DB
            $wpdb->update($wpdb->prefix . 'adrotate', array('title' => $title, 'bannercode' => $bannercode, 'updated' => $thetime, 'author' => $author, 'imagetype' => $imagetype, 'image' => $image, 'desktop' => $desktop, 'mobile' => $mobile, 'tablet' => $tablet, 'weight' => $weight, 'cities' => $cities, 'countries' => $countries), array('id' => $id));
            // Determine status of ad
            $adstate = adrotate_evaluate_ad($id);
            if ($adstate == 'error' or $adstate == 'expired') {
                $action = 502;
                $active = 'a_error';
            } else {
                $action = 306;
                $active = 'queue';
            }
            $wpdb->update($wpdb->prefix . 'adrotate', array('type' => $active), array('id' => $id));
            if ($action == 306) {
                adrotate_push_notifications('queued', $id);
            }
            // Fetch records for the ad, see if a publisher is set
            $linkmeta = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->prefix . "adrotate_linkmeta` WHERE `ad` = %d AND `group` = 0 AND `user` > 0;", $id));
            $advertiser = wp_get_current_user();
            // Add/update publisher on this ad
            if ($linkmeta == 0 and $advertiser->ID > 0) {
                $wpdb->insert($wpdb->prefix . 'adrotate_linkmeta', array('ad' => $id, 'group' => 0, 'user' => $advertiser->ID, 'schedule' => 0));
            }
            if ($linkmeta == 1 and $advertiser->ID > 0) {
                $wpdb->query($wpdb->prepare("UPDATE `" . $wpdb->prefix . "adrotate_linkmeta` SET `user` = {$advertiser->ID} WHERE `ad` = %d AND `group` = 0 AND `schedule` = 0;", $id));
            }
            adrotate_return('adrotate-advertiser', $action);
            exit;
        } else {
            adrotate_return('adrotate-advertiser', 500);
        }
    } else {
        adrotate_nonce_error();
        exit;
    }
}
function adrotate_options_submit()
{
    if (wp_verify_nonce($_POST['adrotate_nonce_settings'], 'adrotate_settings')) {
        $settings_tab = esc_attr($_POST['adrotate_settings_tab']);
        if ($settings_tab == 'general') {
            $config = get_option('adrotate_config');
            $config['textwidget_shortcodes'] = isset($_POST['adrotate_textwidget_shortcodes']) ? 'Y' : 'N';
            $config['live_preview'] = isset($_POST['adrotate_live_preview']) ? 'Y' : 'N';
            $config['mobile_dynamic_mode'] = isset($_POST['adrotate_mobile_dynamic_mode']) ? 'Y' : 'N';
            $config['jquery'] = isset($_POST['adrotate_jquery']) ? 'Y' : 'N';
            $config['jsfooter'] = isset($_POST['adrotate_jsfooter']) ? 'Y' : 'N';
            $adblock_disguise = strtolower(trim($_POST['adrotate_adblock_disguise']));
            $config['adblock_disguise'] = strlen($adblock_disguise) > 0 ? preg_replace('/[^a-z]/', '', strtolower(substr($adblock_disguise, 0, 6))) : "";
            $banner_folder = strtolower(trim($_POST['adrotate_banner_folder']));
            $config['banner_folder'] = strlen($banner_folder) > 0 ? preg_replace('/[^a-zA-Z0-9\\/\\-_]/', '', $banner_folder) : "wp-content/banners/";
            $config['adblock'] = isset($_POST['adrotate_adblock']) ? 'Y' : 'N';
            $config['adblock_loggedin'] = isset($_POST['adrotate_adblock_loggedin']) ? 'Y' : 'N';
            $adblock_timer = trim($_POST['adrotate_adblock_timer']);
            $config['adblock_timer'] = (strlen($adblock_timer) > 0 and (is_numeric($adblock_timer) and $adblock_timer >= 1 and $adblock_timer <= 20)) ? $adblock_timer : 5;
            $adblock_message = trim($_POST['adrotate_adblock_message']);
            $config['adblock_message'] = strlen($adblock_message) > 0 ? strip_tags(htmlspecialchars(trim($adblock_message, "\t\n "), ENT_QUOTES)) : "Ad blocker detected! Please wait %time% seconds or disable your ad blocker!";
            update_option('adrotate_config', $config);
            // Sort out crawlers
            $crawlers = explode(',', trim($_POST['adrotate_crawlers']));
            $new_crawlers = array();
            foreach ($crawlers as $crawler) {
                $crawler = preg_replace('/[^a-zA-Z0-9\\[\\]\\-_:; ]/i', '', trim($crawler));
                if (strlen($crawler) > 0) {
                    $new_crawlers[] = $crawler;
                }
            }
            update_option('adrotate_crawlers', $new_crawlers);
        }
        if ($settings_tab == 'notifications') {
            $notifications = get_option('adrotate_notifications');
            // Notifications
            $notifications['notification_email'] = isset($_POST['adrotate_notification_email']) ? 'Y' : 'N';
            $notifications['notification_push'] = isset($_POST['adrotate_notification_push']) ? 'Y' : 'N';
            $notifications['notification_dashboard'] = isset($_POST['adrotate_notification_dashboard']) ? 'N' : 'Y';
            // Filter and validate notification addresses, if not set, turn option off.
            $notification_emails = $_POST['adrotate_notification_email_publisher'];
            if (strlen($notification_emails) > 0) {
                $notification_emails = explode(',', trim($notification_emails));
                foreach ($notification_emails as $notification_email) {
                    $notification_email = trim($notification_email);
                    if (strlen($notification_email) > 0) {
                        if (is_email($notification_email)) {
                            $clean_notification_email[] = $notification_email;
                        }
                    }
                }
                $notifications['notification_email_publisher'] = array_unique(array_slice($clean_notification_email, 0, 5));
            } else {
                $notifications['notification_email_publisher'] = array();
            }
            // Filter and validate advertiser addresses
            $advertiser_emails = $_POST['adrotate_notification_email_advertiser'];
            if (strlen($advertiser_emails) > 0) {
                $advertiser_emails = explode(',', trim($advertiser_emails));
                foreach ($advertiser_emails as $advertiser_email) {
                    $advertiser_email = trim($advertiser_email);
                    if (strlen($advertiser_email) > 0) {
                        if (is_email($advertiser_email)) {
                            $clean_advertiser_email[] = $advertiser_email;
                        }
                    }
                }
                $notifications['notification_email_advertiser'] = array_unique(array_slice($clean_advertiser_email, 0, 2));
            } else {
                $notifications['notification_email_advertiser'] = array(get_option('admin_email'));
            }
            // Push Notifications
            $notifications['notification_push_geo'] = isset($_POST['adrotate_notification_push_geo']) ? 'Y' : 'N';
            $notifications['notification_push_status'] = isset($_POST['adrotate_notification_push_status']) ? 'Y' : 'N';
            $notifications['notification_push_queue'] = isset($_POST['adrotate_notification_push_queue']) ? 'Y' : 'N';
            $notifications['notification_push_approved'] = isset($_POST['adrotate_notification_push_approved']) ? 'Y' : 'N';
            $notifications['notification_push_rejected'] = isset($_POST['adrotate_notification_push_rejected']) ? 'Y' : 'N';
            $notifications['notification_push_user'] = strlen($_POST['adrotate_notification_push_user']) > 0 ? preg_replace('/[^a-z0-9.]+/i', '', trim(esc_attr($_POST['adrotate_notification_push_user']))) : '';
            $notifications['notification_push_api'] = strlen($_POST['adrotate_notification_push_api']) > 0 ? preg_replace('/[^a-z0-9.]+/i', '', trim(esc_attr($_POST['adrotate_notification_push_api']))) : '';
            update_option('adrotate_notifications', $notifications);
        }
        if ($settings_tab == 'stats') {
            $config = get_option('adrotate_config');
            $stats = trim($_POST['adrotate_stats']);
            $config['stats'] = (is_numeric($stats) and $stats >= 0 and $stats <= 3) ? $stats : 1;
            $config['enable_loggedin_impressions'] = isset($_POST['adrotate_enable_loggedin_impressions']) ? 'Y' : 'N';
            $config['enable_loggedin_clicks'] = isset($_POST['adrotate_enable_loggedin_clicks']) ? 'Y' : 'N';
            $impression_timer = trim($_POST['adrotate_impression_timer']);
            $config['impression_timer'] = (is_numeric($impression_timer) and $impression_timer >= 10 and $impression_timer <= 3600) ? $impression_timer : 60;
            $click_timer = trim($_POST['adrotate_click_timer']);
            $config['click_timer'] = (is_numeric($click_timer) and $click_timer >= 60 and $click_timer <= 86400) ? $click_timer : 86400;
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'geo') {
            $config = get_option('adrotate_config');
            $geo = trim($_POST['adrotate_enable_geo']);
            $config['enable_geo'] = (is_numeric($geo) and $geo >= 0 and $geo <= 5) ? $geo : 0;
            $geo_cookie = trim($_POST['adrotate_geo_cookie_life']);
            $config['geo_cookie_life'] = is_numeric($geo_cookie) ? $geo_cookie : 86400;
            $geo_email = trim($_POST['adrotate_geo_email']);
            $config['geo_email'] = strlen($geo_email) > 0 ? $geo_email : '';
            $geo_pass = trim($_POST['adrotate_geo_pass']);
            $config['geo_pass'] = strlen($geo_pass) > 0 ? $geo_pass : '';
            // Try to update the Geo Cookie for Admin
            if ($config['enable_geo'] > 0) {
                adrotate_geolocation();
            }
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'advertisers') {
            $config = get_option('adrotate_config');
            $config['enable_advertisers'] = isset($_POST['adrotate_enable_advertisers']) ? 'Y' : 'N';
            $config['enable_editing'] = isset($_POST['adrotate_enable_editing']) ? 'Y' : 'N';
            $config['enable_mobile_advertisers'] = isset($_POST['adrotate_enable_mobile_advertisers']) ? 1 : 0;
            $config['enable_geo_advertisers'] = isset($_POST['adrotate_enable_geo_advertisers']) ? 1 : 0;
            if (isset($_POST['adrotate_role'])) {
                adrotate_prepare_roles('add');
            } else {
                adrotate_prepare_roles('remove');
            }
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'roles') {
            $config = get_option('adrotate_config');
            adrotate_set_capability($_POST['adrotate_advertiser'], "adrotate_advertiser");
            adrotate_set_capability($_POST['adrotate_global_report'], "adrotate_global_report");
            adrotate_set_capability($_POST['adrotate_ad_manage'], "adrotate_ad_manage");
            adrotate_set_capability($_POST['adrotate_ad_delete'], "adrotate_ad_delete");
            adrotate_set_capability($_POST['adrotate_group_manage'], "adrotate_group_manage");
            adrotate_set_capability($_POST['adrotate_group_delete'], "adrotate_group_delete");
            adrotate_set_capability($_POST['adrotate_schedule_manage'], "adrotate_schedule_manage");
            adrotate_set_capability($_POST['adrotate_schedule_delete'], "adrotate_schedule_delete");
            adrotate_set_capability($_POST['adrotate_moderate'], "adrotate_moderate");
            adrotate_set_capability($_POST['adrotate_moderate_approve'], "adrotate_moderate_approve");
            $config['advertiser'] = $_POST['adrotate_advertiser'];
            $config['global_report'] = $_POST['adrotate_global_report'];
            $config['ad_manage'] = $_POST['adrotate_ad_manage'];
            $config['ad_delete'] = $_POST['adrotate_ad_delete'];
            $config['group_manage'] = $_POST['adrotate_group_manage'];
            $config['group_delete'] = $_POST['adrotate_group_delete'];
            $config['schedule_manage'] = $_POST['adrotate_schedule_manage'];
            $config['schedule_delete'] = $_POST['adrotate_schedule_delete'];
            $config['moderate'] = $_POST['adrotate_moderate'];
            $config['moderate_approve'] = $_POST['adrotate_moderate_approve'];
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'misc') {
            $config = get_option('adrotate_config');
            $config['widgetalign'] = isset($_POST['adrotate_widgetalign']) ? 'Y' : 'N';
            $config['widgetpadding'] = isset($_POST['adrotate_widgetpadding']) ? 'Y' : 'N';
            $config['adminbar'] = isset($_POST['adrotate_adminbar']) ? 'Y' : 'N';
            $config['hide_schedules'] = isset($_POST['adrotate_hide_schedules']) ? 'Y' : 'N';
            $config['w3caching'] = isset($_POST['adrotate_w3caching']) ? 'Y' : 'N';
            update_option('adrotate_config', $config);
        }
        if ($settings_tab == 'maintenance') {
            $debug = get_option('adrotate_debug');
            $debug['general'] = isset($_POST['adrotate_debug']) ? true : false;
            $debug['publisher'] = isset($_POST['adrotate_debug_publisher']) ? true : false;
            $debug['advertiser'] = isset($_POST['adrotate_debug_advertiser']) ? true : false;
            $debug['geo'] = isset($_POST['adrotate_debug_geo']) ? true : false;
            $debug['timers'] = isset($_POST['adrotate_debug_timers']) ? true : false;
            $debug['track'] = isset($_POST['adrotate_debug_track']) ? true : false;
            update_option('adrotate_debug', $debug);
        }
        // Return to dashboard
        adrotate_return('adrotate-settings', 400, array('tab' => $settings_tab));
    } else {
        adrotate_nonce_error();
        exit;
    }
}
Beispiel #11
0
function adrotate_support_request()
{
    if (wp_verify_nonce($_POST['ajdg_nonce_support'], 'ajdg_nonce_support_request')) {
        $author = sanitize_text_field($_POST['ajdg_support_username']);
        $useremail = sanitize_email($_POST['ajdg_support_email']);
        $subject = sanitize_text_field($_POST['ajdg_support_subject']);
        $text = esc_attr($_POST['ajdg_support_message']);
        if (adrotate_is_networked()) {
            $a = get_site_option('adrotate_activate');
            $networked = 'Yes';
        } else {
            $a = get_option('adrotate_activate');
            $networked = 'No';
        }
        if (strlen($text) < 1 or strlen($subject) < 1 or strlen($author) < 1 or strlen($useremail) < 1) {
            adrotate_return('adrotate', 505);
        } else {
            $website = get_bloginfo('wpurl');
            $pluginversion = ADROTATE_DISPLAY;
            $wpversion = get_bloginfo('version');
            $wpmultisite = is_multisite() ? 'Yes' : 'No';
            $pluginnetwork = $networked;
            $wplanguage = get_bloginfo('language');
            $wpcharset = get_bloginfo('charset');
            $subject = "[AdRotate Pro Support] {$subject}";
            $message = "<p>Hello,</p>";
            $message .= "<p>{$author} has a question about AdRotate</p>";
            $message .= "<p>{$text}</p>";
            $message .= "<p><strong>Additional information:</strong><br />";
            $message .= "Website: {$website}<br />";
            $message .= "Plugin version: {$pluginversion}<br />";
            $message .= "WordPress version: {$wpversion}<br />";
            $message .= "Is multisite? {$wpmultisite}<br />";
            $message .= "Is networked? {$pluginnetwork}<br />";
            $message .= "Language: {$wplanguage}<br />";
            $message .= "Charset: {$wpcharset}";
            $message .= "</p>";
            $message .= "<p>You can reply to this message to contact {$author}.</p>";
            $message .= "<p>Have a nice day!<br />AdRotate Support</p>";
            $headers[] = "Content-Type: text/html; charset=UTF-8";
            $headers[] = "Reply-To: {$useremail}";
            wp_mail('*****@*****.**', $subject, $message, $headers);
            adrotate_return('adrotate', 701);
            exit;
        }
    } else {
        adrotate_nonce_error();
        exit;
    }
}
function adrotate_prepare_roles()
{
    if (isset($_POST['adrotate_role_add_submit'])) {
        $action = "role_add";
        adrotate_add_roles();
        update_option('adrotate_roles', '1');
    }
    if (isset($_POST['adrotate_role_remove_submit'])) {
        $action = "role_remove";
        adrotate_remove_roles();
        update_option('adrotate_roles', '0');
    }
    adrotate_return($action);
}
function adrotate_delete($id, $what)
{
    global $wpdb;
    if ($id > 0) {
        if ($what == 'banner') {
            if ($wpdb->query("DELETE FROM `" . $wpdb->prefix . "adrotate` WHERE `id` = {$id}") == FALSE) {
                die(mysql_error());
            }
        } else {
            if ($what == 'group') {
                if ($wpdb->query("DELETE FROM `" . $wpdb->prefix . "adrotate_groups` WHERE `id` = {$id}") == FALSE) {
                    die(mysql_error());
                }
            } else {
                if ($what == 'bannergroup') {
                    if ($wpdb->query("DELETE FROM `" . $wpdb->prefix . "adrotate_groups` WHERE `id` = {$id}") == FALSE) {
                        die(mysql_error());
                    }
                    if ($wpdb->query("DELETE FROM `" . $wpdb->prefix . "adrotate` WHERE `group` = {$id}") == FALSE) {
                        die(mysql_error());
                    }
                } else {
                    adrotate_return('error');
                    exit;
                }
            }
        }
    }
}