Пример #1
0
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);
    }
}
Пример #2
0
     echo '<div class="error"><p>' . __('You did use %image% in your AdCode but did not select an image!', 'adrotate') . '</p></div>';
 }
 if ($edit_banner->imagetype != '' and $edit_banner->image == '' or $edit_banner->imagetype == '' and $edit_banner->image != '') {
     echo '<div class="error"><p>' . __('There is a problem saving the image. Please reset your image and re-save the ad!', 'adrotate') . '</p></div>';
 }
 if (!preg_match("/%image%/i", $edit_banner->bannercode) and $edit_banner->responsive == 'Y') {
     echo '<div class="error"><p>' . __(' You did not use %image% in your AdCode. The responsive checkbox will be ineffective.', 'adrotate') . '</p></div>';
 }
 if (strlen($edit_banner->image) > 0 and !preg_match("/full/", $edit_banner->image) and $edit_banner->responsive == 'Y') {
     echo '<div class="error"><p>' . __('Responsive is enabled but your banner image has the wrong name.', 'adrotate') . '</p></div>';
 }
 if (!preg_match_all('/<a[^>](.*?)>/i', stripslashes(htmlspecialchars_decode($edit_banner->bannercode, ENT_QUOTES)), $things) and $edit_banner->tracker == 'Y') {
     echo '<div class="error"><p>' . __("Clicktracking is enabled but no valid link was found in the adcode!", 'adrotate') . '</p></div>';
 }
 // Ad Notices
 $adstate = adrotate_evaluate_ad($edit_banner->id);
 if ($edit_banner->type == 'error' and $adstate == 'active') {
     echo '<div class="error"><p>' . __('AdRotate cannot find an error but the ad is marked erroneous, try re-saving the ad!', 'adrotate') . '</p></div>';
 }
 if ($adstate == 'expired') {
     echo '<div class="error"><p>' . __('This ad is expired and currently not shown on your website!', 'adrotate') . '</p></div>';
 }
 if ($adstate == '2days') {
     echo '<div class="updated"><p>' . __('The ad will expire in less than 2 days!', 'adrotate') . '</p></div>';
 }
 if ($adstate == '7days') {
     echo '<div class="updated"><p>' . __('This ad will expire in less than 7 days!', 'adrotate') . '</p></div>';
 }
 if ($edit_banner->type == 'disabled') {
     echo '<div class="updated"><p>' . __('This ad has been disabled and does not rotate on your site!', 'adrotate') . '</p></div>';
 }
function adrotate_active($id, $what)
{
    global $wpdb;
    if ($id > 0) {
        if ($what == 'deactivate') {
            $wpdb->update($wpdb->prefix . 'adrotate', array('type' => 'disabled'), array('id' => $id));
        }
        if ($what == 'activate') {
            // Determine status of ad
            $adstate = adrotate_evaluate_ad($id);
            if ($adstate == 'error' or $adstate == 'expired') {
                $adtype = 'error';
            } else {
                $adtype = 'active';
            }
            $wpdb->update($wpdb->prefix . 'adrotate', array('type' => $adtype), array('id' => $id));
        }
    }
}
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;
    }
}