";
}
return $output;
}
}
/*-------------------------------------------------------------
Name: adrotate_evaluate_ads
Purpose: Initiate evaluations for errors and determine the ad status
-------------------------------------------------------------*/
function adrotate_evaluate_ads() {
global $wpdb;
// Fetch ads
$ads = $wpdb->get_results("SELECT `id` FROM `{$wpdb->prefix}adrotate` WHERE `type` != 'disabled' AND `type` != 'generator' AND `type` != 'a_empty' AND `type` != 'a_error' AND `type` != 'queue' AND `type` != 'reject' AND `type` != 'archived' AND `type` != 'trash' AND `type` != 'empty' ORDER BY `id` ASC;");
// Determine error states
$error = $limit = $expired = $expiressoon = $expiresweek = $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 == 'limit') {
$limit++;
$wpdb->query("UPDATE `{$wpdb->prefix}adrotate` SET `type` = 'limit' 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') {
$expiresweek++;
$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++;
}
unset($ad);
}
$result = array('error' => $error, 'limit' => $limit, 'expired' => $expired, 'expiressoon' => $expiressoon, 'expiresweek' => $expiresweek, 'normal' => $normal, 'unknown' => $unknown);
update_option('adrotate_advert_status', $result);
unset($ads, $result);
}
/*-------------------------------------------------------------
Name: adrotate_evaluate_ad
Purpose: Evaluates ads for errors
-------------------------------------------------------------*/
function adrotate_evaluate_ad($ad_id) {
global $wpdb, $adrotate_config;
$now = current_time('timestamp');
$in2days = $now + 172800;
$in7days = $now + 604800;
// Fetch ad
$ad = $wpdb->get_row($wpdb->prepare("SELECT `id`, `bannercode`, `tracker`, `imagetype`, `image` FROM `{$wpdb->prefix}adrotate` WHERE `id` = %d;", $ad_id));
$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;");
$schedules = $wpdb->get_var("SELECT COUNT(`schedule`) FROM `{$wpdb->prefix}adrotate_linkmeta` WHERE `ad` = ".$ad->id." AND `group` = 0 AND `user` = 0;");
$bannercode = stripslashes(htmlspecialchars_decode($ad->bannercode, ENT_QUOTES));
// Determine error states
if(
strlen($bannercode) < 1 // AdCode empty
OR ((!preg_match_all('/<(a)[^>](.*?)>/i', stripslashes(htmlspecialchars_decode($ad->bannercode, ENT_QUOTES)), $things) OR preg_match_all('/<(ins|script|embed|iframe)[^>](.*?)>/i', stripslashes(htmlspecialchars_decode($ad->bannercode, ENT_QUOTES)), $things)) AND $ad->tracker == 'Y') // Stats active but no valid link/tag present
OR (preg_match_all('/(%asset%)/i', $bannercode, $things) AND $ad->image == '' AND $ad->imagetype == '') // Did use %image% but didn't select an image
OR (!preg_match_all('/(%asset%)/i', $bannercode, $things) AND $ad->image != '' AND $ad->imagetype != '') // Didn't use %image% but selected an image
OR (($ad->image == '' AND $ad->imagetype != '') OR ($ad->image != '' AND $ad->imagetype == '')) // Image and Imagetype mismatch
OR $schedules == 0 // No Schedules for this ad
) {
return 'error';
} else if(
$stoptime <= $now // Past the enddate
){
return 'expired';
} else if(
$stoptime <= $in2days AND $stoptime >= $now // Expires in 2 days
){
return '2days';
} else if(
$stoptime <= $in7days AND $stoptime >= $now // Expires in 7 days
){
return '7days';
} else {
return 'active';
}
}
/*-------------------------------------------------------------
Name: adrotate_prepare_color
Purpose: Check if ads are expired and set a color for its end date
-------------------------------------------------------------*/
function adrotate_prepare_color($enddate) {
$now = current_time('timestamp');
$in2days = $now + 172800;
$in7days = $now + 604800;
if($enddate <= $now) {
return '#CC2900'; // red
} else if($enddate <= $in2days AND $enddate >= $now) {
return '#F90'; // orange
} else if($enddate <= $in7days AND $enddate >= $now) {
return '#E6B800'; // yellow
} else {
return '#009900'; // green
}
}
/*-------------------------------------------------------------
Name: adrotate_ad_is_in_groups
Purpose: Build list of groups the advert is in (overview)
-------------------------------------------------------------*/
function adrotate_ad_is_in_groups($id) {
global $wpdb;
$output = '';
$groups = $wpdb->get_results("
SELECT
`{$wpdb->prefix}adrotate_groups`.`name`
FROM
`{$wpdb->prefix}adrotate_groups`,
`{$wpdb->prefix}adrotate_linkmeta`
WHERE
`{$wpdb->prefix}adrotate_linkmeta`.`ad` = ".$id."
AND `{$wpdb->prefix}adrotate_linkmeta`.`group` = `{$wpdb->prefix}adrotate_groups`.`id`
AND `{$wpdb->prefix}adrotate_linkmeta`.`user` = 0
;");
if($groups) {
foreach($groups as $group) {
$output .= $group->name.', ';
}
}
$output = rtrim($output, ', ');
return $output;
}
/*-------------------------------------------------------------
Name: adrotate_dropdown_roles
Purpose: Returns all roles that can be used
-------------------------------------------------------------*/
function adrotate_dropdown_roles($selected = '') {
$return = '';
$editable_roles = get_editable_roles();
unset($editable_roles['author'], $editable_roles['contributor'], $editable_roles['subscriber']);
foreach($editable_roles as $role => $details) {
$name = translate_user_role($details['name']);
// Preselect specified role.
if($selected === $role) {
$return .= "\n\t";
} else {
$return .= "\n\t";
}
}
echo $return;
}
/*-------------------------------------------------------------
Name: adrotate_get_sorted_roles
Purpose: Returns all roles and capabilities, sorted by user level. Lowest to highest.
-------------------------------------------------------------*/
function adrotate_get_sorted_roles() {
global $wp_roles;
$editable_roles = apply_filters('editable_roles', $wp_roles->roles);
$sorted = array();
foreach($editable_roles as $role => $details) {
$sorted[$details['name']] = get_role($role);
}
$sorted = array_reverse($sorted);
return $sorted;
}
/*-------------------------------------------------------------
Name: adrotate_set_capability
Purpose: Grant or revoke capabilities to a role and all higher roles
-------------------------------------------------------------*/
function adrotate_set_capability($lowest_role, $capability){
$check_order = adrotate_get_sorted_roles();
$add_capability = false;
foreach($check_order as $role) {
if($lowest_role == $role->name) $add_capability = true;
if(empty($role)) continue;
$add_capability ? $role->add_cap($capability) : $role->remove_cap($capability) ;
}
}
/*-------------------------------------------------------------
Name: adrotate_remove_capability
Purpose: Remove the $capability from the all roles
-------------------------------------------------------------*/
function adrotate_remove_capability($capability){
$check_order = adrotate_get_sorted_roles();
foreach($check_order as $role) {
$role = get_role($role->name);
$role->remove_cap($capability);
}
}
/*-------------------------------------------------------------
Name: adrotate_dashboard_scripts
Purpose: Load file uploaded popup
-------------------------------------------------------------*/
function adrotate_dashboard_scripts() {
$page = (isset($_GET['page'])) ? sanitize_key($_GET['page']) : '';
if(strpos($page, 'adrotate') !== false) {
wp_enqueue_style('jquery-ui-datepicker');
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('raphael', plugins_url('/library/raphael-min.js', __FILE__), array('jquery'));
wp_enqueue_script('elycharts', plugins_url('/library/elycharts.min.js', __FILE__), array('jquery', 'raphael'));
wp_enqueue_script('textatcursor', plugins_url('/library/textatcursor.js', __FILE__), ADROTATE_VERSION);
wp_enqueue_script('goosebox', plugins_url('/library/goosebox.js', __FILE__), ADROTATE_VERSION);
wp_enqueue_script('adrotate-datepicker', plugins_url('/library/jquery.datepicker.js', __FILE__), array('jquery'), ADROTATE_VERSION);
}
wp_enqueue_style('adrotate-admin-stylesheet', plugins_url('library/dashboard.css', __FILE__));
}
/*-------------------------------------------------------------
Name: adrotate_notifications_dashboard
Purpose: Notify user of expired banners in the dashboard
-------------------------------------------------------------*/
function adrotate_notifications_dashboard() {
global $current_user;
$displayname = (strlen($current_user->user_firstname) > 0) ? $current_user->user_firstname : $current_user->display_name;
if(current_user_can('adrotate_ad_manage')) {
$page = (isset($_GET['page'])) ? $_GET['page'] : '';
// These only show on AdRotate pages
if(strpos($page, 'adrotate') !== false) {
if(isset($_GET['hide']) AND $_GET['hide'] == 0) update_option('adrotate_hide_getpro', current_time('timestamp') + (31 * DAY_IN_SECONDS));
if(isset($_GET['hide']) AND $_GET['hide'] == 1) update_option('adrotate_hide_review', 1);
if(isset($_GET['hide']) AND $_GET['hide'] == 2) update_option('adrotate_hide_birthday', current_time('timestamp') + (10 * MONTH_IN_SECONDS));
// Get AdRotate Pro
$getpro_banner = get_option('adrotate_hide_getpro');
if($getpro_banner < current_time('timestamp')) {
echo "
";
echo "
";
echo "
Hello ".$displayname.". Have you considered upgrading to AdRotate Professional yet? Get extra features such as Geo Targeting, Scheduling, Mobile Adverts, More advanced Post Injection, access to premium ticket support and much more... ";
echo " Licenses start as low as € 49 and you can use coupon code GETADROTATEPRO to get a 10% discount on any AdRotate Professional license!
Hello ".$displayname."! You have been using AdRotate for a few days. If you like or found a use for AdRotate Banner Manager, please share your experience and write a review. Thanks for being awesome! If you have questions, complaints or something else that does not belong in a review, please use the support forum!
Hey ".$displayname."! Did you know it is Arnan his birtyday this month? February 9th to be exact. Wish him a happy birthday via Telegram! Who is Arnan? He made AdRotate for you - Check out his website.
AdRotate has detected "._n("one issue that requires", "several issues that require", count($adrotate_has_error), 'adrotate')." ".__("your attention:", 'adrotate')." ";
foreach($adrotate_has_error as $error => $message) {
echo "» ".$message." ";
}
echo "
";
echo "
";
}
}
if(current_user_can('update_plugins')) {
// Finish update
$adrotate_db_version = get_option('adrotate_db_version');
$adrotate_version = get_option('adrotate_version');
if($adrotate_db_version['current'] < ADROTATE_DB_VERSION OR $adrotate_version['current'] < ADROTATE_VERSION) {
$plugin_version = get_plugins();
$plugin_version = $plugin_version['adrotate/adrotate.php']['Version'];
// Do the update
adrotate_finish_upgrade();
// Thank user for updating
echo "
";
echo "
";
echo "
Hi there ".$displayname."! You have just updated AdRotate Professional to version ".$plugin_version."! Thanks for staying up-to-date! Your Database and settings have been updated to the latest version. For an overview of what has changed take a look at the development page and usually there is an article on the blog with more information as well.
".__("AdRotate Professional has a lot more to offer for even better advertising management and premium support. Enjoy features like Geo Targeting, Schedules, more advanced Post Injection and much more. Check out the feature comparison tab on any of the product pages to see what AdRotate Pro has to offer for you! When you upgrade to AdRotate Professional make sure you use coupon GETADROTATEPRO on checkout for 10 percent off on any license.", 'adrotate')." ".__("Compare Licenses", 'adrotate')." »
".__("If you need help, or have questions about AdRotate, the best and fastest way to get your answer is via the AdRotate support forum. Usually I answer questions the same day, often with a solution in the first answer.", 'adrotate')."
".__("Arnan needs your help. Please consider writing a review or sharing AdRotate in Social media if you find the plugin useful. Writing a review and sharing AdRotate on social media costs you nothing but doing so is super helpful.", 'adrotate')."
". __("Group including the Adverts in it deleted", 'adrotate') ."
";
break;
case '223' :
echo "
". __("Folder created", 'adrotate') ."
";
break;
case '226' :
echo "
". __("Advert HTML generated and placed in the AdCode field. Configure your advert below. Do not forget to check all settings and schedule the advert.", 'adrotate') ."
";
break;
// Settings
case '400' :
echo "
". __("Settings saved", 'adrotate') ."
";
break;
case '403' :
echo "
". __("Database optimized", 'adrotate') ."
";
break;
case '404' :
echo "
". __("Database repaired", 'adrotate') ."
";
break;
case '405' :
echo "
". __("Adverts evaluated and statuses have been corrected where required", 'adrotate') ."
";
break;
case '406' :
echo "
". __("Cleanup complete", 'adrotate') ."
";
break;
case '407' :
echo "
". __("Scheduled tasks reset", 'adrotate') ."
";
break;
case '408' :
echo "
". __("If there were any 3rd party plugins interfering with AdRotate they have been disabled", 'adrotate') ."
";
break;
case '409' :
echo "
". __("Database updated", 'adrotate') ."
";
break;
case '410' :
echo "
". __("Database and core settings updated", 'adrotate') ." ". __("Thanks for updating AdRotate Banner Manager!", 'adrotate') ." ". __("If you run into any issues with the new version please send a email through the support dashboard as soon as possible with any errors or symptoms you encounter.", 'adrotate') ."