';
} //end color_selector
function kd_admin_googleads_prepare_new() {
//prepare a new id into ads table
//and redirect to manage page passing the new id
}
function kd_admin_googleads() {
//check if Plugin need to install his db table.
$kd_need_install = kd_check_install();
//check if Plugin need to update db table column for a new version.
$kd_need_update = kd_check_update();
if ($kd_need_install) {
kd_installer();
} elseif ($kd_need_update) {
kd_updater();
} else {
echo kd_G_icon();
echo "
", _e('Author Advertising Pro - Gestione Annunci Google', 'author-advertising-pro'), "
";
echo "
";
echo kd_menu_application();
echo "
", kd_help_icon(), "
";
echo "
", _e('In questa sezione potrai gestire, creare o eliminare i tuoi annunci Adsense', 'author-advertising-pro'), "
";
echo "
", _e('Scegli il tipo di annuncio che desideri, poi compila tutti i campi necessari a farlo funzionare correttamente sul sito; In questa nuova versione di Author Advertising Pro, potrai decidere direttamente dove posizionare gli annunci all\'interno delle pagine senza dover mettere mano al codice del tuo template.', 'author-advertising-pro'), "
";
echo "
";
//GET VALUES
global $wpdb;
$base_prefix = $wpdb->base_prefix;
$table_name_ad_google = $base_prefix . "author_advertising_ad_google";
//IMPORT OLD ADS
if (isset($_POST['show_old_ads'])) {
$old_values = get_option("kd_old_values");
if (!empty($old_values[14])) {
if (!empty($old_values[22])) {
$ads_1['code'] = $old_values[14];
$ads_1['tag'] = $old_values[22];
}
}
if (!empty($old_values[16])) {
if (!empty($old_values[23])) {
$ads_2['code'] = $old_values[16];
$ads_2['tag'] = $old_values[23];
}
}
if (!empty($old_values[18])) {
if (!empty($old_values[24])) {
$ads_3['code'] = $old_values[18];
$ads_3['tag'] = $old_values[24];
}
}
//Widget
if (!empty($old_values[20])) {
if (!empty($old_values[19])) {
$ads_4['code'] = $old_values[20];
}
}
//SHOW CODES
echo "
Codice Annuncio 1
TAG: ", $ads_1['tag'], "
Codice Annuncio 2
TAG: ", $ads_2['tag'], "
Codice Annuncio 3
TAG: ", $ads_3['tag'], "
Codice Annuncio 4 (Widget)
";
}
//DELETE ADS ID FUNCTION
if (isset($_POST['delete_ads'])) {
$delete_id = $_POST['delete_id'];
$sql= "DELETE FROM `$table_name_ad_google` WHERE `id` = $delete_id";
$delete = $wpdb->query($sql);
if ($delete) {
echo "
", _e('Errore durante l\'eliminazione dell\'annuncio.', 'author-advertising-pro'), "
";
}
//Conto il numero di ads presenti nella tabella
$ads_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM $table_name_ad_google" ) );
if ($ads_count == 0) {
$wpdb->query("ALTER TABLE $table_name_ad_google AUTO_INCREMENT = 1");
echo "
", _e('Tutti gli annunci sono stati eliminati, il contatore degli ID è stato quindi resettato e ripartirà da 1', 'author-advertising-pro'), " :)
";
}
}
//CREATE NEW ADS FUNCTION
if (isset($_POST['new_ads'])) {
$query = $wpdb->insert(
$table_name_ad_google,
array(
'ad_active' => 'on',
'ad_type' => 1,
'ad_type2' => 2,
'ad_format' => 2,
) );
if ($query) {
echo "
", _e('E\' stato creato un nuovo ID annuncio! Ora puoi modificarlo impostando i campi sottostanti!', 'author-advertising-pro'), "
", _e('Errore durante la creazione del nuovo ID annuncio', 'author-advertising-pro'), "
";
}
}
//Conto il numero di ads presenti nella tabella
$ads_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM $table_name_ad_google" ) );
echo "
";
if ($ads_count == 0) {
echo "
", _e('Non ci sono annunci salvati nel database', 'author-advertising-pro'), "
";
echo "";
echo "";
echo "
";
} else {
echo "";
echo "
";
//Conto il numero di ads presenti nella tabella
$ads_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM $table_name_ad_google" ) );
//Seleziona il primo id salvato nella tabella
$first_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $table_name_ad_google LIMIT 1" ) );
//GET VALUES FROM ID
if (isset($new_ad_created)) {
$selected_id = $new_ad_created;
} elseif (isset($_POST['ads_id'])) {
$selected_id = $_POST['ads_id'];
} else {
$selected_id = $first_id;
}
if (isset($_POST['save_ad_values'])) {
//GET POST VALUES
$ad_type = $_POST['ad_type'];
$ad_type2 = $_POST['ad_type2'];
$ad_format = $_POST['ad_format'];
//FIX AD_CLIENT
$ad_client = ltrim($_POST['ad_client']);
$ad_client = rtrim($ad_client);
if (!empty($ad_client)) {
$ad_pub_id = $ad_client;
$ad_client = $ad_client;
} else {
$ad_pub_id = "%pubid%";
$ad_client = "";
}
//END FIX
$personal_ad_slot = $_POST['personal_ad_slot'];
$ad_slot = $_POST['ad_slot'];
$ad_channel = $_POST['ad_channel'];
//FIX COLOR VALUES
if (isset($_POST['ad_color_border'])) { $ad_color_border = $_POST['ad_color_border']; } else { $ad_color_border = "FFFFFF"; }
if (isset($_POST['ad_color_bg'])) { $ad_color_bg = $_POST['ad_color_bg']; } else { $ad_color_bg = "FFFFFF"; }
if (isset($_POST['ad_color_link'])) { $ad_color_link = $_POST['ad_color_link']; } else { $ad_color_link = "FFFFFF"; }
if (isset($_POST['ad_color_text'])) { $ad_color_text = $_POST['ad_color_text']; } else { $ad_color_text = "FFFFFF"; }
if (isset($_POST['ad_color_url'])) { $ad_color_url = $_POST['ad_color_url']; } else { $ad_color_url = "FFFFFF"; }
//END FIX
$ad_ui_features = $_POST['ad_ui_features'];
//$ad_generated_code = $_POST[''];
$ad_excluded_categories = $_POST['ad_excluded_categories'];
$ad_included_categories = $_POST['ad_included_categories'];
$ad_css = $_POST['ad_css'];
$ad_active = $_POST['ad_active'];
$ad_links = $_POST['ad_links'];
$ad_style = $_POST['ad_style'];
$ad_position_begin = $_POST['ad_position_begin'];
$ad_position_end = $_POST['ad_position_end'];
$ad_tag = $_POST['ad_tag'];
$ad_comment = $_POST['ad_comment'];
///PREPARE THE FORMAT VALUES TO GENERATE THE FINAL CODE
$ad_format_values = kd_admin_google_ads_size_values($ad_format, $ad_type, $ad_links);
$ad_width = $ad_format_values['width'];
$ad_height = $ad_format_values['height'];
$ad_format_text = $ad_format_values['format_text'];
//CHECK AD STYLE (TEXT/IMAGE)
Switch ($ad_style) {
case 0:
//image
$ad_style_format = "image";
break;
case 1:
//text
$ad_style_format = "text";
break;
case 2:
//text_image
$ad_style_format = "text_image";
break;
}
//CHECK UI FEATURES
Switch ($ad_ui_features) {
case 0:
$ad_ui_value = "rc:0";
break;
case 6:
$ad_ui_value = "rc:6";
break;
case 10:
$ad_ui_value = "rc:10";
break;
}
//NOW GENERATE THE FINAL CODE
if ($ad_type2 == 2) { //IF OLD CODE
if ($ad_type == 2) { //IF ADS
$code = "
";
} elseif ($ad_type == 1) { //IF LINK_UNIT
$code = "
";
}
} elseif ($ad_type2 == 1 && $personal_ad_slot == 0) {
switch ($ad_slot) {
case 1:
$ad_slot = "%ad_slot1%";
break;
case 2:
$ad_slot = "%ad_slot2%";
break;
case 3:
$ad_slot = "%ad_slot3%";
break;
case 4:
$ad_slot = "%ad_slot4%";
break;
case 5:
$ad_slot = "%ad_slot5%";
break;
case 6:
$ad_slot = "%ad_slot6%";
break;
}
$code = "
";
} elseif ($ad_type2 == 1 && $personal_ad_slot == 1) {
$code = "
";
}
//NOW SAVE THE VALUES
$data = array('ad_type' => $ad_type,
'ad_type2' => $ad_type2,
'ad_format' => $ad_format,
'ad_client' => $ad_client,
'personal_ad_slot' => $personal_ad_slot,
'ad_slot' => $ad_slot,
'ad_channel' => $ad_channel,
'ad_width' => $ad_width,
'ad_height' => $ad_height,
'ad_color_border' => $ad_color_border,
'ad_color_bg' => $ad_color_bg,
'ad_color_link' => $ad_color_link,
'ad_color_text' => $ad_color_text,
'ad_color_url' => $ad_color_url,
'ad_ui_features' => $ad_ui_features,
'ad_excluded_categories' => $ad_excluded_categories,
'ad_included_categories' => $ad_included_categories,
'ad_css' => $ad_css,
'ad_active' => $ad_active,
'ad_links' => $ad_links,
'ad_style' => $ad_style,
'ad_generated_code' => $code,
'ad_position_begin' => $ad_position_begin,
'ad_position_end' => $ad_position_end,
'ad_tag' => $ad_tag,
'ad_comment' => $ad_comment);
$where = array('id' => $selected_id);
$wpdb->update( $table_name_ad_google, $data, $where );
}
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//GETTING SETTING VALUES BY SAVED ADS
$ad_active = $wpdb->get_var( $wpdb->prepare( "SELECT ad_active FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_type = $wpdb->get_var( $wpdb->prepare( "SELECT ad_type FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_type2 = $wpdb->get_var( $wpdb->prepare( "SELECT ad_type2 FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_format = $wpdb->get_var( $wpdb->prepare( "SELECT ad_format FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_client = $wpdb->get_var( $wpdb->prepare( "SELECT ad_client FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$personal_ad_slot = $wpdb->get_var( $wpdb->prepare( "SELECT personal_ad_slot FROM $table_name_ad_google WHERE id='$selected_id'") );
$ad_slot = $wpdb->get_var( $wpdb->prepare( "SELECT ad_slot FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_width = $wpdb->get_var( $wpdb->prepare( "SELECT ad_width FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_height = $wpdb->get_var( $wpdb->prepare( "SELECT ad_height FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_channel = $wpdb->get_var( $wpdb->prepare( "SELECT ad_channel FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_color_border = $wpdb->get_var( $wpdb->prepare( "SELECT ad_color_border FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_color_bg = $wpdb->get_var( $wpdb->prepare( "SELECT ad_color_bg FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_color_link = $wpdb->get_var( $wpdb->prepare( "SELECT ad_color_link FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_color_text = $wpdb->get_var( $wpdb->prepare( "SELECT ad_color_text FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_color_url = $wpdb->get_var( $wpdb->prepare( "SELECT ad_color_url FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_ui_features = $wpdb->get_var( $wpdb->prepare( "SELECT ad_ui_features FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_generated_code = $wpdb->get_var( $wpdb->prepare( "SELECT ad_generated_code FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_excluded_categories = $wpdb->get_var( $wpdb->prepare( "SELECT ad_excluded_categories FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_included_categories = $wpdb->get_var( $wpdb->prepare( "SELECT ad_included_categories FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_css = $wpdb->get_var( $wpdb->prepare( "SELECT ad_css FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_links = $wpdb->get_var( $wpdb->prepare( "SELECT ad_links FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_style = $wpdb->get_var( $wpdb->prepare( "SELECT ad_style FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_position_begin = $wpdb->get_var( $wpdb->prepare( "SELECT ad_position_begin FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_position_end = $wpdb->get_var( $wpdb->prepare( "SELECT ad_position_end FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_tag = $wpdb->get_var( $wpdb->prepare( "SELECT ad_tag FROM $table_name_ad_google WHERE id='$selected_id'" ) );
$ad_comment = $wpdb->get_var( $wpdb->prepare( "SELECT ad_comment FROM $table_name_ad_google WHERE id='$selected_id'" ) );
//END GETTING VALUES
echo "
";
echo "
";
echo "";
echo "
";
//FINE BLOCCO SELECT ID
//INIZIO BLOCCO FORM VALUES ADS
echo "