$article) {
$title = '';
if (preg_match ('##', $article, $match)) {
$title = trim ($match [1]);
}
if ($title != '' && strlen ($article) > 100) {
$postarr = array (
'ID' => 0,
'post_content' => $article,
'post_title' => $title,
'post_status' => 'publish',
);
$post_id = wp_insert_post ($postarr);
}
}
}
@unlink ($ai_articles);
}
update_option ('ai-notice-review', 'no');
if (defined ('AI_PLUGIN_TRACKING') && AI_PLUGIN_TRACKING) {
global $ai_dst;
if (isset ($ai_dst) && is_object ($ai_dst)) {
$ai_dst->set_tracking (false);
}
}
}
$save_url = $_SERVER ['REQUEST_URI'];
if (isset ($_GET ['tab'])) {
$save_url = preg_replace ("/&tab=\d+/", "", $save_url);
}
$generate_all = false;
if (isset ($_GET ['generate-all']) && $_GET ['generate-all'] == 1) {
$generate_all = true;
}
$subpage = 'main';
$start = 1;
$end = 16;
if (isset ($_GET ['start']) && is_numeric ($start) && $start >= 1 && $start <= 96) $start = (int) $_GET ['start']; else $start = 1;
$end = min ($start + 15, 96);
if (isset ($_POST ['ai-active-tab'])) {
$active_tabs = json_decode ($_POST ['ai-active-tab']);
if ($active_tabs == null) $active_tabs = array ($start, 0);
}
if (isset ($_GET ['settings']) && is_numeric ($_GET ['settings'])) {
$active_tab = (int) $_GET ['settings'];
if ($active_tab < 1 || $active_tab > 96) $active_tab = 1;
if (isset ($_GET ['single'])) {
$start = $active_tab;
$end = $active_tab;
} else {
$start = intval (($active_tab - 1) / 16) * 16 + 1;
$end = $start + 15;
}
}
elseif (isset ($_GET ['tab']) && is_numeric ($_GET ['tab'])) {
$active_tab = (int) $_GET ['tab'];
$start = intval (($active_tab - 1) / 16) * 16 + 1;
$end = $start + 15;
} else $active_tab = isset ($active_tabs [0]) ? (int) $active_tabs [0] : $start;
if (!is_numeric ($active_tab)) $active_tab = 1;
if ($active_tab != 0) {
if ($active_tab < $start || $active_tab > $end) $active_tab = $start;
}
$active_tab_0 = isset ($active_tabs [1]) ? (int) $active_tabs [1] : 0;
$disable_block_insertions = get_disable_block_insertions ();
$disable_php_processing = get_disable_php_processing ();
$disable_html_code = get_disable_html_code ();
$disable_css_code = get_disable_css_code ();
$disable_js_code = get_disable_js_code ();
$disable_footer_code = get_disable_footer_code ();
$disable_header_code = get_disable_header_code ();
$insertion_disabled = $disable_block_insertions || $disable_php_processing || $disable_html_code || $disable_css_code || $disable_js_code || $disable_footer_code || $disable_header_code;
if ($insertion_disabled) {
$insertion_statuses = 'H ';
$insertion_statuses .= 'F ';
$insertion_statuses .= 'JS ';
$insertion_statuses .= 'CSS ';
$insertion_statuses .= 'HTML ';
$insertion_statuses .= 'PHP ';
$insertion_statuses .= 'BLOCKS ';
} else $insertion_statuses = '';
$adH = $block_object [AI_HEADER_OPTION_NAME];
$adF = $block_object [AI_FOOTER_OPTION_NAME];
if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
$adA = $block_object [AI_ADB_MESSAGE_OPTION_NAME];
}
$syntax_highlighter_theme = defined ('AI_SAFE_MODE') ? 'disabled' : get_syntax_highlighter_theme ();
$block_class_name = get_block_class_name ();
$block_class = get_block_class ();
$block_number_class = get_block_number_class ();
$block_name_class = get_block_name_class ();
$inline_styles = get_inline_styles ();
$default = $block_object [0];
$exceptions_array = ai_get_exceptions (ai_current_user_role_ok () && (!is_multisite() || is_main_site () || multisite_exceptions_enabled ()));
$exceptions = $exceptions_array [0];
$block_exceptions = $exceptions_array [1];
if (get_wait_for_jquery ()) {
echo '
', __('Information', 'ad-inserter'), ': ', __('Legacy JavaScript code used', 'ad-inserter'), ', ', /* translators: disable feature */ __('disable', 'ad-inserter'), ' ', __ ('Wait for jQuery', 'ad-inserter'), '
';
}
if (ai_current_user_role_ok () && (!is_multisite() || is_main_site () || multisite_exceptions_enabled ())) {
if (isset ($_POST [AI_FORM_CLEAR_EXCEPTIONS])) {
if ($_POST [AI_FORM_CLEAR_EXCEPTIONS] == "\xe2\x9d\x8c" && !empty ($exceptions)) {
echo '' . sprintf (__('Warning: only exceptions for %d posts cleared, %d posts still have exceptions', 'ad-inserter'), AI_LIST_EXCEPTIONS_LIMIT, count ($exceptions)) . '
';
}
elseif (is_numeric ($_POST [AI_FORM_CLEAR_EXCEPTIONS]) && !empty ($block_exceptions [$_POST [AI_FORM_CLEAR_EXCEPTIONS]])) {
echo '' . sprintf (__('Warning: only exceptions for %d posts cleared, %d posts still have exceptions', 'ad-inserter'), AI_LIST_EXCEPTIONS_LIMIT, count ($block_exceptions [$_POST [AI_FORM_CLEAR_EXCEPTIONS]])) . '
';
}
}
}
if (!$ai_wp_data [AI_UNFILTERED_HTML]) {
// translators: %s: HTML link code
echo '' . sprintf (__('Warning: %s Unfiltered HTML %s is disabled for this website - most ad codes can\'t be used', 'ad-inserter'), '', ' ') . '
';
}
$rating_string = '';
if ($rating_string = get_transient (AI_TRANSIENT_RATING)) {
if ($rating_string < 1 && $rating_string > 5) $rating_string = '';
}
$rating_css = $rating_string == '' ? 'width: 100%;' : 'width: '.number_format ($rating_string * 20, 4).'%;';
$rating_value = $rating_string == '' ? '' : number_format ($rating_string, 1);
if (isset ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]) && is_string ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]) && strlen ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]) != 0) {
$used_blocks = unserialize ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]);
} else $used_blocks = array ();
if (!isset ($_GET ['settings'])): // start of code only for normal settings
$default_sidebar = isset ($ai_wp_data [AI_DAYS_SINCE_INSTAL]) && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 19 && count ($used_blocks) >= 4 && function_exists ('ai_settings_side') && function_exists ('ai_admin_settings_notices') ? '1' : '0';
// Not needed anymore
// if (is_multisite () && multisite_main_for_all_blogs () && defined ('BLOG_ID_CURRENT_SITE')) {
// $saved_options = get_blog_option (BLOG_ID_CURRENT_SITE, AI_OPTION_NAME);
// if (is_string ($saved_options) && substr ($saved_options, 0, 4) === ':AI:') {
// $saved_options = unserialize (base64_decode (substr ($saved_options, 4), true));
// }
// } else $saved_options = ai_get_option (AI_OPTION_NAME);
// $warning = false;
// if (!empty ($saved_options))
// foreach ($saved_options as $block => $block_settings) {
// if ($block >= $start && $block <= $end) {
// if (isset ($saved_options [$block]) && strpos (serialize ($saved_options [$block]), '_on_which_') !== false) {
// $warning = true;
// break;
// }
// }
// }
// if ($warning) {
// echo '' . __('Settings for individual exceptions have been updated. Please check all blocks that have exceptions and and then save settings.', 'ad-inserter') . '
';
// }
if (function_exists ('ai_admin_settings_notices')) ai_admin_settings_notices ();
$hide_settings_enabled = defined ('AI_HIDE_SETTINGS_ENABLED') && AI_HIDE_SETTINGS_ENABLED;
$settings_hidden = function_exists ('ai_block_list_buttons') && $hide_settings_enabled ? get_settings_hidden () : false;
$settings_page = get_menu_position () == AI_SETTINGS_SUBMENU ? 'options-general.php?page=ad-inserter.php' : 'admin.php?page=ad-inserter.php';
?>
$sidebar_widget) {
if (is_array ($sidebar_widget) && isset ($GLOBALS ['wp_registered_sidebars'][$sidebar_index]['name'])) {
$sidebar_name = $GLOBALS ['wp_registered_sidebars'][$sidebar_index]['name'];
if ($sidebar_name != "") {
foreach ($sidebar_widget as $widget) {
if (preg_match ("/ai_widget-([\d]+)/", $widget, $widget_id)) {
if (isset ($widget_id [1]) && is_numeric ($widget_id [1])) {
$widget_option = $widget_options [$widget_id [1]];
$widget_block = $widget_option ['block'];
// if ($widget_block >= $start && $widget_block <= $end && !in_array ($sidebar_name, $sidebars_with_widget [$widget_block])) {
if ($widget_block >= 1 && $widget_block <= 96 && !in_array ($sidebar_name, $sidebars_with_widget [$widget_block])) {
$sidebars_with_widget [$widget_block] []= $sidebar_name;
}
}
}
}
}
}
}
return $sidebars_with_widget;
}
function page_checker_container () {
global $ai_custom_hooks;
$current_theme_name = '';
$current_theme_version = '';
if (function_exists ('ai_settings_theme')) {
$current_theme = ai_settings_theme ();
if (is_object ($current_theme)) {
$current_theme_name = $current_theme->get ('Name');
$current_theme_version = $current_theme->get ('Version');
}
elseif (is_array ($current_theme)) {
$current_theme_name = $current_theme ['name'];
$current_theme_version = $current_theme ['version'];
}
} else {
$current_theme = wp_get_theme ();
$current_theme_name = $current_theme->get ('Name');
$current_theme_version = $current_theme->get ('Version');
}
?>
", $current_theme_name, " ", $current_theme_version; ?>
:
$custom_hook) {
$insertions [AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + $custom_hook ['index'] - 1] = $custom_hook ['name'];
}
$counter = 0;
foreach ($insertions as $insertion_type => $insertion_name) {
// $single = true;
// $blog = true;
// switch ($insertion_type) {
// case AI_AUTOMATIC_INSERTION_BEFORE_EXCERPT:
// case AI_AUTOMATIC_INSERTION_AFTER_EXCERPT:
// case AI_AUTOMATIC_INSERTION_BETWEEN_POSTS:
// $single = false;
// break;
// case AI_AUTOMATIC_INSERTION_BEFORE_COMMENTS:
// case AI_AUTOMATIC_INSERTION_BETWEEN_COMMENTS:
// case AI_AUTOMATIC_INSERTION_AFTER_COMMENTS:
// $blog = false;
// break;
// }
if ($insertion_type == AI_AUTOMATIC_INSERTION_ABOVE_HEADER && (!defined ('AI_BUFFERING') || !get_output_buffering ())) {
$class = '';
$title = __('Position not available because output buffering (tab [*]) is not enabled', 'ad-inserter');
} else {
$class = 'ai-position ';
$title = __('Position not checked yet', 'ad-inserter');;
}
?>
●
●
●
●
●
●
get_ad_data ();
if (preg_match_all ('#data-ad-client\s*=\s*"(.+?)"#', $block_code, $adsense_matches)) {
foreach ($adsense_matches [1] as $adsense_match) {
if (preg_match ('#(pub-[0-9]+)#', $adsense_match, $adsense_pub_id)) {
$found = false;
foreach ($block_ads as $block_ad) {
if ($block_ad ['ads_data'][1] == $adsense_pub_id [1]) {
$found = true;
break;
}
}
if (!$found) {
$block_ads [] = array ('ads_data' => array ('google.com', $adsense_pub_id [1], 'DIRECT', 'f08c47fec0942fa0'), 'found' => false);
}
}
}
}
if (preg_match_all ('#google_ad_client\s*=\s*"(.+?)"#', $block_code, $adsense_matches)) {
foreach ($adsense_matches [1] as $adsense_match) {
if (preg_match ('#(pub-[0-9]+)#', $adsense_match, $adsense_pub_id)) {
$found = false;
foreach ($block_ads as $block_ad) {
if ($block_ad ['ads_data'][1] == $adsense_pub_id [1]) {
$found = true;
break;
}
}
if (!$found) {
$block_ads [] = array ('ads_data' => array ('google.com', $adsense_pub_id [1], 'DIRECT', 'f08c47fec0942fa0'), 'found' => false);
}
}
}
}
}
$site_url = site_url ();
$home_url = home_url ();
$url_parts = explode (DIRECTORY_SEPARATOR, str_replace (array ('https', 'http', '://'), '', $site_url));
$ads_txt_home = 'http' . (is_ssl() ? 's' : '') . '://'. $url_parts [0];
$ads_txt_url = $ads_txt_home . DIRECTORY_SEPARATOR . 'ads.txt';
$wp_content_dir_array = explode ('/', WP_CONTENT_DIR);
$wp_content_dir = $wp_content_dir_array [count ($wp_content_dir_array) - 1];
$root_path = str_replace ($wp_content_dir, '', WP_CONTENT_DIR);
$ads_txt_file = $root_path . 'ads.txt';
$wp_folder = '';
if (count ($url_parts) > 1) {
$wp_folder = str_replace ($ads_txt_home, '', $site_url);
$wp_folder = str_replace ('/', DIRECTORY_SEPARATOR, $wp_folder);
}
echo '';
echo "
\n";
echo "site_url ", site_url (), "\n";
echo "home_url ", home_url (), "\n";
echo "ads_txt_home ", $ads_txt_home, "\n";
echo "wp_folder ", $wp_folder, "\n";
echo "ABSPATH ", ABSPATH, "\n";
echo "WP_CONTENT_DIR ", WP_CONTENT_DIR, "\n";
echo "root_path ", $root_path, "\n";
echo " \n";
echo '
';
$virtual = isset ($_GET ["virtual"]) && $_GET ["virtual"];
$virtual_file_missing = false;
if ($virtual) {
$ads = get_option (AI_ADS_TXT_NAME);
if ($ads === false) {
$virtual_file_missing = true;
update_option (AI_ADS_TXT_NAME, '');
$ads = '';
if ($action == 'table') {
$action = 'text';
}
}
} else {
if (file_exists ($ads_txt_file)) {
$ads = file_get_contents ($ads_txt_file);
} else {
$ads = '';
if ($action == 'table') {
$action = 'text';
}
}
}
$ads_lines = explode ("\n", $ads);
$rows = array ();
foreach ($ads_lines as $ads_line) {
if (trim ($ads_line) == '') continue;
$ads_data = explode ('#', str_replace (array ("\r", ' '), '', $ads_line));
$ads_elements = explode (',', $ads_data [0]);
if (count ($ads_elements) == 0) continue;
$found = false;
foreach ($block_ads as $index => $block_ad) {
if (!isset ($ads_elements [1])) continue;
if ($block_ad ['ads_data'][1] == $ads_elements [1]) {
$found = true;
$block_ads [$index]['found'] = true;
break;
}
}
$rows []= array ('ads_elements' => $ads_elements, 'status' => $found ? 'F' : '');
}
$missing_lines = array ();
foreach ($block_ads as $block_ad) {
if (!$block_ad ['found']) {
array_unshift ($rows, array ('ads_elements' => $block_ad ['ads_data'], 'status' => 'M'));
$missing_lines []= implode (', ', $block_ad ['ads_data']);
}
}
$search_text = isset ($_GET ["search"]) ? trim (esc_html ($_GET ["search"])) : '';
if ($search_text != '') $search_array = explode (' ', $search_text); else $search_array = array ();
foreach ($rows as $index => $row) {
$ads_line = implode (' ', $row ['ads_elements']);
foreach ($search_array as $search_item) {
if (stripos ($ads_line, trim ($search_item)) === false) {
unset ($rows [$index]);
continue 2;
}
}
}
switch ($virtual) {
case true:
echo '';
// translators: %s: Ad Inserter
echo '
', sprintf (__('ads.txt file: %s virtual ads.txt file', 'ad-inserter'), AD_INSERTER_NAME), '
';
if (is_multisite () && is_main_site ()) {
// translators: %s: multisite installation, .htaccess file
echo '
', sprintf (__('You are using %s installation. You need to manually add to the %s file the following line:', 'ad-inserter'), 'multisite', '.htaccess'), '
';
echo '
RewriteRule ^ads\.txt /wp-admin/admin-ajax.php?action=ai_ajax&ads-txt= [QSA,L] ';
}
echo '
';
if ($virtual_file_missing) {
// echo '';
// echo '
', __('Warning', 'ad-inserter'), ': ', /* translators: %s: Ad Inserter */ sprintf (__('%s virtual file ads.txt not found', 'ad-inserter'), AD_INSERTER_NAME), '
';
// echo '
';
echo '
';
}
if ($ads == '') {
echo '
';
}
break;
default:
echo '';
if ($wp_folder != '') {
echo '
', __('IMPORTANT', 'ad-inserter'), ' : ', __('ads.txt file must be placed on the root domain', 'ad-inserter'), ' ', $ads_txt_url, ' ';
echo '
';
}
echo '
';
echo 'WordPress ', ABSPATH, ' ';
echo '', __('ads.txt file', 'ad-inserter'), ' ', $ads_txt_file, is_writable ($ads_txt_file) ? '' : ''.__('NOT WRITABLE', 'ad-inserter').' ', ' ';
echo '
';
echo '
';
if (!file_exists ($ads_txt_file)) {
echo '';
echo '
', __('Warning', 'ad-inserter'), ': ', sprintf (__('file %s not found', 'ad-inserter'), $ads_txt_file), '
';
echo '
';
}
break;
}
// $missing_lines = array ();
switch ($action) {
case 'text':
if (count ($missing_lines)) {
echo '', __('Account IDs found in blocks but not present in the ads.txt file', 'ad-inserter'), '
';
echo '';
echo implode ("\n", $missing_lines);
echo ' ';
if ($virtual) {
// translators: %s: Ad Inserter
echo '', sprintf (__('%s virtual ads.txt file', 'ad-inserter'), AD_INSERTER_NAME), '
';
} else {
echo '', $ads_txt_file, '
';
}
}
echo '';
echo $ads;
echo ' ';
if (!$virtual) {
delete_option (AI_ADS_TXT_NAME);
}
ai_add_rewrite_rules ();
flush_rewrite_rules();
break;
case 'table':
?>
'.$ads_elements [3] .'';
} else $element3 = $ads_elements [3];
} else $element3 = '';
?>
>
96 || $command === null) {
return;
}
$ai_options = false;
if (function_exists ('ai_raw_remote_options')) {
$ai_options = ai_raw_remote_options ();
}
if ($ai_options === false) $ai_options = ai_get_option (AI_OPTION_NAME, array ());
$update_settings = false;
switch ($command) {
case 'pause':
$value = $block_object [$block]->get_disable_insertion () == AI_DISABLED ? AI_ENABLED : AI_DISABLED;
$ai_options [$block][AI_OPTION_DISABLE_INSERTION] = $value;
$update_settings = true;
break;
}
if ($update_settings) {
ai_save_options ($ai_options);
}
}
}
function ai_update_block_numbers ($blocks_org, $blocks_new) {
global $wpdb;
// 'widget_' + registered AI widget name
$ai_widgets = get_option ('widget_ai_widget');
if (is_array ($ai_widgets))
foreach ($ai_widgets as $widget_index => $ai_widget) {
if (isset ($ai_widget ['block'])) {
$widget_block = $ai_widget ['block'];
if ($widget_block >= 1 && $widget_block <= 96) {
foreach ($blocks_new as $index => $org_block) {
if ($widget_block == $org_block) {
$ai_widgets [$widget_index]['block'] = $blocks_org [$index];
break;
}
}
}
}
}
update_option ('widget_ai_widget', $ai_widgets);
if (defined ('AI_STATISTICS') && AI_STATISTICS) {
// Update statistics - two passes to avoid duplicate entries
$offset = 1000;
// Lock table to prevent updates of old blocks
$query = 'LOCK TABLES ' . AI_STATISTICS_DB_TABLE . ' WRITE;';
$update = $wpdb->query ($query);
// Pass 1 - new blocks with offset
$query = 'UPDATE ' . AI_STATISTICS_DB_TABLE . ' SET block= CASE ';
foreach ($blocks_new as $index => $org_block) {
$new_block = $blocks_org [$index] + $offset;
$query .= "WHEN block= $org_block THEN $new_block ";
}
$query .= 'ELSE block END;';
$update = $wpdb->query ($query);
// Pass 2 - remove offset
$query = 'UPDATE ' . AI_STATISTICS_DB_TABLE . " SET block = block - $offset WHERE block >= $offset;";
$update = $wpdb->query ($query);
// Unlock table
$query = 'UNLOCK TABLES;';
$update = $wpdb->query ($query);
}
}
function code_block_list ($start, $end, $search_text, $show_all_blocks, $active_block) {
global $block_object, $ai_db_options_extract;
if (defined ('AI_SAFE_MODE') || isset ($_GET ['safe-mode'])) {
$url_parameters = '&ai-safe-mode';
} else $url_parameters = '';
if (isset ($_GET ["ai-settings"]) && $_GET ["ai-settings"]) {
$url_parameters .= '&ai-settings=1';
}
if (isset ($_GET ["ai-show-errors"]) && $_GET ["ai-show-errors"]) {
$url_parameters .= '&ai-show-errors=1';
}
if (isset ($_GET ["cmd"])) {
ai_change_settings ();
}
if (isset ($_GET ["blocks-org"]) && isset ($_GET ["blocks-new"])) {
$blocks_org = json_decode ($_GET ["blocks-org"]);
$blocks_new = json_decode ($_GET ["blocks-new"]);
if (!empty ($blocks_org) && count ($blocks_org) == count ($blocks_new)) {
// Update widgets
$current_options = false;
if (function_exists ('ai_raw_remote_options')) {
$current_options = ai_raw_remote_options ();
}
if ($current_options === false) $current_options = ai_get_option (AI_OPTION_NAME, array ());
$new_options = $current_options;
$error = false;
foreach ($blocks_org as $index => $block) {
$new_block = $blocks_new [$index];
if ($block >= 1 && $block <= 96 && $new_block >= 1 && $new_block <= 96) {
if (isset ($current_options [$new_block])) {
$new_options [$block] = $current_options [$new_block];
} else {
unset ($new_options [$block]);
}
} else $error = true;
}
if (!$error) {
// Update AI_OPTION_SCHEDULING_FALLBACK, AI_OPTION_LIMITS_FALLBACK and AI_OPTION_ADB_BLOCK_REPLACEMENT
for ($block = 1; $block <= 96; $block ++) {
if (isset ($new_options [$block][AI_OPTION_SCHEDULING_FALLBACK])) {
$ai_option_fallback = $new_options [$block][AI_OPTION_SCHEDULING_FALLBACK];
if ($ai_option_fallback != '')
foreach ($blocks_new as $index => $org_block) {
if ($ai_option_fallback == $org_block) {
$new_options [$block][AI_OPTION_SCHEDULING_FALLBACK] = $blocks_org [$index];
}
}
}
if (isset ($new_options [$block][AI_OPTION_LIMITS_FALLBACK])) {
$ai_option_fallback = $new_options [$block][AI_OPTION_LIMITS_FALLBACK];
if ($ai_option_fallback != '')
foreach ($blocks_new as $index => $org_block) {
if ($ai_option_fallback == $org_block) {
$new_options [$block][AI_OPTION_LIMITS_FALLBACK] = $blocks_org [$index];
}
}
}
if (isset ($new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT])) {
$ai_option_adb_block_replacement = $new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT];
if ($ai_option_adb_block_replacement != '')
foreach ($blocks_new as $index => $org_block) {
if ($ai_option_adb_block_replacement == $org_block) {
$new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT] = $blocks_org [$index];
}
}
}
}
// Update block numbers in custom reports
if (isset ($new_options [AI_OPTION_GLOBAL]['CUSTOM_REPORTS'])) {
$custom_reports = $new_options [AI_OPTION_GLOBAL]['CUSTOM_REPORTS'];
foreach ($custom_reports as $custom_report_index => $custom_report) {
if (isset ($custom_report ['reports'])) {
foreach ($custom_report ['reports'] as $custom_chart_index => $custom_chart) {
$custom_chart_data = explode (':', $custom_chart ['block_version']);
if (isset ($custom_chart_data [0])) {
$chart_block = $custom_chart_data [0];
foreach ($blocks_new as $index => $org_block) {
if ($chart_block == $org_block) {
$new_custom_chart = $blocks_org [$index];
if (isset ($custom_chart_data [1])) {
$new_custom_chart .= ':' . $custom_chart_data [1];
}
$new_options [AI_OPTION_GLOBAL]['CUSTOM_REPORTS'][$custom_report_index]['reports'][$custom_chart_index]['block_version'] = $new_custom_chart;
}
}
}
}
}
}
}
ai_save_options ($new_options, null, $blocks_org, $blocks_new);
}
}
}
$sidebars_with_widget = get_sidebar_widgets ();
ob_start ();
if ($search_text != '') $search_array = explode (' ', $search_text); else $search_array = array ();
$blocks = array ();
$row_counter = 0;
for ($block = 1; $block <= 96; $block ++) {
$obj = $block_object [$block];
$option_names = array ();
if ($show_all_blocks) {
$code_generator = new ai_code_generator ();
$rotation_data = $code_generator->import_rotation ($obj->get_ad_data (), true);
$rotation_data = $rotation_data ['options'];
foreach ($rotation_data as $rotation_data_index => $rotation_data_version) {
if (isset ($rotation_data_version ['prepend-append']) && $rotation_data_version ['prepend-append'] != '') {
unset ($rotation_data [$rotation_data_index]);
}
}
$rotation_data = array_values ($rotation_data);
if (count ($rotation_data) > 1) {
foreach ($rotation_data as $rotation_data_index => $rotation_data_element) {
$version = $rotation_data_index + 1;
$data_index_for_name = $version;
$option_index_for_name = $version;
foreach ($rotation_data as $rotation_data_index => $rotation_data_version) {
if (isset ($rotation_data_version ['index'])) {
$option_index = (int) $rotation_data_version ['index'];
if ($option_index == $version) {
$data_index_for_name = $rotation_data_index + 1;
$option_index_for_name = $option_index;
break;
}
}
}
$option_name = isset ($rotation_data [$data_index_for_name - 1]['name']) && trim ($rotation_data [$data_index_for_name - 1]['name']) != '' ? str_replace ("'", "'", $rotation_data [$data_index_for_name - 1]['name']) : chr (ord ('A') + $data_index_for_name - 1);
$option_names [$option_index_for_name] = $option_name;
}
}
}
$custom_reports = defined ('AD_INSERTER_CUSTOM_REPORTS') && $show_all_blocks;
$automatic_insertion = $obj->get_automatic_insertion () != AI_AUTOMATIC_INSERTION_DISABLED;
$manual_widget = $obj->get_enable_widget() == AI_ENABLED;
$manual_shortcode = $obj->get_enable_manual() == AI_ENABLED;
$manual_php_function = $obj->get_enable_php_call() == AI_ENABLED;
$disabled = $obj->get_disable_insertion ();
$block_used = /*!$disabled &&*/ ($automatic_insertion || $manual_php_function || $manual_shortcode || $manual_widget && !empty ($sidebars_with_widget [$block]));
if (!$show_all_blocks && !$block_used) continue;
$process_php = $obj->get_process_php ();
$exceptions = $obj->get_exceptions_enabled ();
$devices = $obj->get_detection_server_side () || $obj->get_detection_client_side ();
$scheduling = $obj->get_scheduling() != AI_SCHEDULING_OFF;
$scheduling_period = '';
switch ($obj->get_scheduling ()) {
case AI_SCHEDULING_BETWEEN_DATES:
case AI_SCHEDULING_OUTSIDE_DATES:
$scheduling_period_inactive = !check_scheduling_time (
$obj->get_schedule_start_date () . ' ' . $obj->get_schedule_start_time (),
$obj->get_schedule_end_date () . ' ' . $obj->get_schedule_end_time (),
$obj->get_schedule_weekdays (),
$obj->get_scheduling () == AI_SCHEDULING_BETWEEN_DATES
);
$scheduling_period = $obj->get_schedule_start_date () . ($obj->get_schedule_start_time () != '' ? ' ' . $obj->get_schedule_start_time () : ''). '[BR]' . $obj->get_schedule_end_date () . ($obj->get_schedule_end_time () != '' ? ' ' . $obj->get_schedule_end_time () : '');
break;
default:
$scheduling_period_inactive = false;
break;
}
$tracking = $obj->get_tracking (true);
if (ai_pro ()) {
$limits =
$tracking && (
$obj->get_max_impressions () || ($obj->get_limit_impressions_per_time_period () && $obj->get_limit_impressions_time_period ()) ||
$obj->get_max_clicks () || ($obj->get_limit_clicks_per_time_period () && $obj->get_limit_clicks_time_period ()) ||
$obj->get_visitor_max_impressions () || ($obj->get_visitor_limit_impressions_per_time_period () && $obj->get_visitor_limit_impressions_time_period ()) ||
$obj->get_visitor_max_clicks () || ($obj->get_visitor_limit_clicks_per_time_period () && $obj->get_visitor_limit_clicks_time_period ()) ||
$obj->get_trigger_click_fraud_protection () && get_click_fraud_protection ()
);
}
$block_text = $block . ' '. $obj->get_ad_name () . ' ' . $obj->get_automatic_insertion_text() . ' ' . implode (', ', $sidebars_with_widget [$block]);
if ($process_php) $block_text .= ' php';
if ($exceptions) $block_text .= ' exceptions';
if ($devices) $block_text .= ' device';
if ($scheduling) $block_text .= ' scheduling';
if (ai_pro ()) {
if ($limits) $block_text .= ' limits';
}
if ($tracking) $block_text .= ' tracking';
if (!empty ($sidebars_with_widget [$block])) $block_text .= ' widget';
if ($manual_shortcode) $block_text .= ' shortcode';
if ($manual_php_function) $block_text .= ' function';
foreach ($search_array as $search_item) {
if (stripos ($block_text, trim ($search_item)) === false) continue 2;
}
$blocks []= $block;
$row_counter ++;
$row_class = $row_counter % 2 == 0 ? 'even' : 'odd';
if ($block == $active_block) {
$row_class .= ' ai-block-active';
}
$settings_page = get_menu_position () == AI_SETTINGS_SUBMENU ? 'options-general.php?page=ad-inserter.php' : 'admin.php?page=ad-inserter.php';
$edit_url = admin_url ($settings_page) . '&start=' . (intval (($block - 1) / 16) * 16 + 1) . '&tab=' . $block . $url_parameters;
$visible_tab = $block >= $start && $block <= $end;
$insertion_parameter = '';
$insertion_title = '';
switch ($obj->get_automatic_insertion()) {
case AI_AUTOMATIC_INSERTION_BEFORE_PARAGRAPH:
case AI_AUTOMATIC_INSERTION_AFTER_PARAGRAPH:
case AI_AUTOMATIC_INSERTION_BEFORE_IMAGE:
case AI_AUTOMATIC_INSERTION_AFTER_IMAGE:
$insertion_parameter = ' ' . $obj->get_paragraph_number ();
$insertion_title = $obj->get_paragraph_number ();
break;
case AI_AUTOMATIC_INSERTION_BEFORE_EXCERPT:
case AI_AUTOMATIC_INSERTION_AFTER_EXCERPT:
case AI_AUTOMATIC_INSERTION_BETWEEN_POSTS:
case AI_AUTOMATIC_INSERTION_BETWEEN_COMMENTS:
$insertion_parameter = ' ' . $obj->get_call_filter ();
$insertion_title = $obj->get_call_filter ();
break;
case AI_AUTOMATIC_INSERTION_BEFORE_HTML_ELEMENT:
case AI_AUTOMATIC_INSERTION_AFTER_HTML_ELEMENT:
case AI_AUTOMATIC_INSERTION_INSIDE_HTML_ELEMENT:
$insertion_title = $obj->get_html_selector ();
break;
}
?>
▉
❚❚
get_ad_name(); ?>
get_ad_name(); ?>
get_automatic_insertion_text(), $insertion_parameter; ?>
fn
[s]
w
1) {
foreach ($option_names as $option_index => $option_name) {
$row_counter ++;
$row_class = $row_counter % 2 == 0 ? 'even' : 'odd';
?>
", __ ('No active block', 'ad-inserter'), ""; else
echo "", __ ('No block matches search keywords', 'ad-inserter'), "
";
}
}
if (defined ('AI_ADSENSE_API')) {
function ai_adsense_data (&$error) {
require_once AD_INSERTER_PLUGIN_DIR.'includes/adsense-api.php';
$error = 'AdSense not authorized';
$ad_data = false;
if (defined ('AI_ADSENSE_AUTHORIZATION_CODE')) {
$error = '';
$update_ad_units = isset ($_GET ["update_ad_units"]) ? $_GET ["update_ad_units"] == 1 : false;
$adsense = new adsense_api ();
$ad_data = get_transient (AI_TRANSIENT_ADSENSE_ADS);
if ($ad_data === false || $update_ad_units) {
$ad_units = $adsense->getAdUnits();
$error = $adsense->getError ();
if ($error == '' && is_array ($ad_units)) {
$ad_data = array ($adsense->getAdSensePublisherID (), $ad_units);
set_transient (AI_TRANSIENT_ADSENSE_ADS, $ad_data, AI_TRANSIENT_ADSENSE_ADS_EXPIRATION);
}
}
}
return $ad_data;
}
function adsense_list () {
require_once AD_INSERTER_PLUGIN_DIR.'includes/adsense-api.php';
if (defined ('AI_ADSENSE_AUTHORIZATION_CODE')) {
if (get_transient (AI_TRANSIENT_ADSENSE_TOKEN_1) !== false) {
// Old token for API version 1
$error = 'unauthorized_client_2';
} else {
$publisher_id = '';
$ad_units = array ();
$error = '';
$ad_data = ai_adsense_data ($error);
}
if ($error == '') {
$publisher_id = $ad_data [0];
$ad_units = $ad_data [1];
$show_all_ad_units = isset ($_GET ["all"]) && $_GET ["all"];
?>
$error";
if (strpos ($error, 'unauthorized_client') !== false) {
echo '',
// translators: %s: HTML tags
sprintf (__('Please %s clear authorization %s with the button %s above and once again authorize access to your AdSense account.', 'ad-inserter'),
'',
' ',
' '
), '
';
}
}
}
elseif (defined ('AI_ADSENSE_CLIENT_ID')) {
$adsense = new adsense_api();
$adsense_ids = defined ('AI_CI_STRING') && get_option (AI_ADSENSE_OWN_IDS) === false;
?>
'.AD_INSERTER_NAME.'',
AD_INSERTER_NAME
); ?>
', ''); ?>
Ad Inserter', '', ' '); ?>
', ''); ?>
Ad Inserter', '', ' '); ?>
Ad Inserter'); ?>
', ''); ?>
AdSense Management API'); ?>
', ''); ?>
', '', '', ' '); ?>
', '', '', ' '); ?>
', '', '', ' '); ?>
', ''); ?>
', '', '', ' '); ?>
', '', '', ' ', '', ' '); ?>
', '', 'Ad Inserter ', '', ' '); ?>
', '', '', ' '); ?>
', '', '', ' '); ?>
', '', '', ' '); ?>
', '', '', ' ', '', ' '); ?>
', '', '', ' '); ?>
', '', '', ' ', '', ' '); ?>
getAdCode ($ad_slot_id);
echo json_encode (array ('code' => $code, 'error-message' => $adsense->getError ()));
}
}
}
function adsense_ad_name () {
if (defined ('AI_ADSENSE_API')) {
$publisher_id = '';
$ad_units = array ();
$error = '';
$ad_data = ai_adsense_data ($error);
if ($error == '') {
$publisher_id = $ad_data [0];
$ad_units = $ad_data [1];
$ad_slot_names = array ('publisher_id' => $publisher_id);
foreach ($ad_units as $ad_unit) {
if ($ad_unit ['active'])
$ad_slot_names [$ad_unit ['code']] = $ad_unit ['name'];
}
echo json_encode ($ad_slot_names);
}
}
}
function generate_list_options ($options) {
switch ($options) {
case 'category':
$category_data = ai_get_category_list ();
foreach ($category_data as $category) {
echo " {$category->slug} ({$category->name}) \n";
$category_to_check = get_term_by ('slug', $category->slug, 'category');
if ($category_to_check) {
$descendants = get_term_children ($category_to_check->term_id, 'category');
if ($descendants) {
// Translators: %s: category name
echo " {$category->slug}* ("._x(sprintf ('%s or children', $category->name), 'Category children', 'ad-inserter').") \n";
// Translators: %s: category name
echo " {$category->slug}+ ("._x(sprintf ('%s children only', $category->name), 'Category children', 'ad-inserter').") \n";
}
}
}
break;
case 'tag':
$tag_data = ai_get_tag_list ();
foreach ($tag_data as $tag) {
echo " {$tag->slug} ({$tag->name}) \n";
}
break;
case 'taxonomy':
$taxonomies = ai_get_taxonomy_list ();
foreach ($taxonomies as $taxonomy => $taxonomy_name) {
if ($taxonomy_name != '')
echo " {$taxonomy} ({$taxonomy_name}) \n"; else
echo " {$taxonomy} \n";
}
break;
case 'id':
$posts_pages = ai_get_post_id_list ();
$counter = 2;
$max_list_items = get_max_list_items ();
foreach ($posts_pages as $post_page) {
if ($post_page->post_title == '') continue;
echo " {$post_page->ID} ({$post_page->post_type} \"{$post_page->post_title}\") \n";
$counter ++;
if ($counter > $max_list_items) break;
}
echo " posts (", __('All posts', 'ad-inserter'), ") \n";
echo " pages (", __('All static pages', 'ad-inserter'), ") \n";
break;
case 'client':
$languages = array (
'af' => 'Afrikaans',
'sq' => 'Albanian',
'an' => 'Aragonese',
'ar*' => 'Arabic (Standard)',
'ar-dz' => 'Arabic (Algeria)',
'ar-bh' => 'Arabic (Bahrain)',
'ar-eg' => 'Arabic (Egypt)',
'ar-iq' => 'Arabic (Iraq)',
'ar-jo' => 'Arabic (Jordan)',
'ar-kw' => 'Arabic (Kuwait)',
'ar-lb' => 'Arabic (Lebanon)',
'ar-ly' => 'Arabic (Libya)',
'ar-ma' => 'Arabic (Morocco)',
'ar-om' => 'Arabic (Oman)',
'ar-qa' => 'Arabic (Qatar)',
'ar-sa' => 'Arabic (Saudi Arabia)',
'ar-sy' => 'Arabic (Syria)',
'ar-tn' => 'Arabic (Tunisia)',
'ar-ae' => 'Arabic (U.A.E.)',
'ar-ye' => 'Arabic (Yemen)',
'hy' => 'Armenian',
'as' => 'Assamese',
'ast' => 'Asturian',
'az' => 'Azerbaijani',
'eu' => 'Basque',
'bg' => 'Bulgarian',
'be' => 'Belarusian',
'bn' => 'Bengali',
'bs' => 'Bosnian',
'br' => 'Breton',
'my' => 'Burmese',
'ca' => 'Catalan',
'ch' => 'Chamorro',
'ce' => 'Chechen',
'zh*' => 'Chinese',
'zh-hk' => 'Chinese (Hong Kong)',
'zh-cn' => 'Chinese (PRC)',
'zh-sg' => 'Chinese (Singapore)',
'zh-tw' => 'Chinese (Taiwan)',
'cv' => 'Chuvash',
'co' => 'Corsican',
'cr' => 'Cree',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'nl*' => 'Dutch (Standard)',
'nl-be' => 'Dutch (Belgian)',
'en*' => 'English',
'en-au' => 'English (Australia)',
'en-bz' => 'English (Belize)',
'en-ca' => 'English (Canada)',
'en-ie' => 'English (Ireland)',
'en-jm' => 'English (Jamaica)',
'en-nz' => 'English (New Zealand)',
'en-ph' => 'English (Philippines)',
'en-za' => 'English (South Africa)',
'en-tt' => 'English (Trinidad & Tobago)',
'en-gb' => 'English (United Kingdom)',
'en-us' => 'English (United States)',
'en-zw' => 'English (Zimbabwe)',
'eo' => 'Esperanto',
'et' => 'Estonian',
'fo' => 'Faeroese',
'fa' => 'Persian',
'fj' => 'Fijian',
'fi' => 'Finnish',
'fr*' => 'French (Standard)',
'fr-be' => 'French (Belgium)',
'fr-ca' => 'French (Canada)',
'fr-fr' => 'French (France)',
'fr-lu' => 'French (Luxembourg)',
'fr-mc' => 'French (Monaco)',
'fr-ch' => 'French (Switzerland)',
'fy' => 'Frisian',
'fur' => 'Friulian',
'gd*' => 'Scots Gaelic',
'gd-ie' => 'Gaelic (Irish)',
'gl' => 'Galacian',
'ka' => 'Georgian',
'de*' => 'German (Standard)',
'de-at' => 'German (Austria)',
'de-de' => 'German (Germany)',
'de-li' => 'German (Liechtenstein)',
'de-lu' => 'German (Luxembourg)',
'de-ch' => 'German (Switzerland)',
'el' => 'Greek',
'gu' => 'Gujurati',
'ht' => 'Haitian',
'he' => 'Hebrew',
'hi' => 'Hindi',
'hu' => 'Hungarian',
'is' => 'Icelandic',
'id' => 'Indonesian',
'iu' => 'Inuktitut',
'ga' => 'Irish',
'it*' => 'Italian (Standard)',
'it-ch' => 'Italian (Switzerland)',
'ja' => 'Japanese',
'kn' => 'Kannada',
'ks' => 'Kashmiri',
'kk' => 'Kazakh',
'km' => 'Khmer',
'ky' => 'Kirghiz',
'tlh' => 'Klingon',
'ko*' => 'Korean',
'ko-kp' => 'Korean (North Korea)',
'ko-kr' => 'Korean (South Korea)',
'la' => 'Latin',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'lb' => 'Luxembourgish',
'mk' => 'FYRO Macedonian',
'ms' => 'Malay',
'ml' => 'Malayalam',
'mt' => 'Maltese',
'mi' => 'Maori',
'mr' => 'Marathi',
'mo' => 'Moldavian',
'nv' => 'Navajo',
'ng' => 'Ndonga',
'ne' => 'Nepali',
'no' => 'Norwegian',
'nb' => 'Norwegian (Bokmal)',
'nn' => 'Norwegian (Nynorsk)',
'oc' => 'Occitan',
'or' => 'Oriya',
'om' => 'Oromo',
'fa-ir' => 'Persian/Iran',
'pl' => 'Polish',
'pt*' => 'Portuguese',
'pt-br' => 'Portuguese (Brazil)',
'pa*' => 'Punjabi',
'pa-in' => 'Punjabi (India)',
'pa-pk' => 'Punjabi (Pakistan)',
'qu' => 'Quechua',
'rm' => 'Rhaeto-Romanic',
'ro*' => 'Romanian',
'ro-mo' => 'Romanian (Moldavia)',
'ru*' => 'Russian',
'ru-mo' => 'Russian (Moldavia)',
'sz' => 'Sami (Lappish)',
'sg' => 'Sango',
'sa' => 'Sanskrit',
'sc' => 'Sardinian',
'sd' => 'Sindhi',
'si' => 'Singhalese',
'sr' => 'Serbian',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'so' => 'Somani',
'sb' => 'Sorbian',
'es*' => 'Spanish',
'es-ar' => 'Spanish (Argentina)',
'es-bo' => 'Spanish (Bolivia)',
'es-cl' => 'Spanish (Chile)',
'es-co' => 'Spanish (Colombia)',
'es-cr' => 'Spanish (Costa Rica)',
'es-do' => 'Spanish (Dominican Republic)',
'es-ec' => 'Spanish (Ecuador)',
'es-sv' => 'Spanish (El Salvador)',
'es-gt' => 'Spanish (Guatemala)',
'es-hn' => 'Spanish (Honduras)',
'es-mx' => 'Spanish (Mexico)',
'es-ni' => 'Spanish (Nicaragua)',
'es-pa' => 'Spanish (Panama)',
'es-py' => 'Spanish (Paraguay)',
'es-pe' => 'Spanish (Peru)',
'es-pr' => 'Spanish (Puerto Rico)',
'es-es' => 'Spanish (Spain)',
'es-uy' => 'Spanish (Uruguay)',
'es-ve' => 'Spanish (Venezuela)',
'sx' => 'Sutu',
'sw' => 'Swahili',
'sv*' => 'Swedish',
'sv-fi' => 'Swedish (Finland)',
'sv-sv' => 'Swedish (Sweden)',
'ta' => 'Tamil',
'tt' => 'Tatar',
'te' => 'Teluga',
'th' => 'Thai',
'tig' => 'Tigre',
'ts' => 'Tsonga',
'tn' => 'Tswana',
'tr' => 'Turkish',
'tk' => 'Turkmen',
'uk' => 'Ukrainian',
'hsb' => 'Upper Sorbian',
'ur' => 'Urdu',
've' => 'Venda',
'vi' => 'Vietnamese',
'vo' => 'Volapuk',
'wa' => 'Walloon',
'cy' => 'Welsh',
'xh' => 'Xhosa',
'ji' => 'Yiddish',
'zu' => 'Zulu',
);
$clients = array ();
if (version_compare (phpversion (), "5.6", ">=")) {
require_once AD_INSERTER_PLUGIN_DIR.'includes/agent/Agent.php';
$agent = new Agent();
$clients = array_merge (
array_keys ($agent->getOperatingSystems ()),
array_keys ($agent->getBrowsers ()),
array_keys ($agent->getPhoneDevices ()),
array_keys ($agent->getTabletDevices ()),
array_keys ($agent->getUtilities ())
);
foreach ($clients as $client) {
echo " $client \n";
}
} else {
}
foreach ($languages as $language_id => $language) {
echo " {$language} \n";
}
$clients = array_merge (
$clients,
$languages
);
break;
default:
if (function_exists ('ai_generate_list_options')) ai_generate_list_options ($options);
break;
}
}
function ai_get_posts_pages_with_exceptions () {
$args = array (
'public' => true,
'_builtin' => false
);
$custom_post_types = get_post_types ($args, 'names', 'and');
$screens = array_values (array_merge (array ('post', 'page'), $custom_post_types));
$args = array (
'posts_per_page' => AI_LIST_EXCEPTIONS_LIMIT,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'type',
'order' => 'ASC',
'include' => '',
'exclude' => '',
'meta_query' => array (
array (
'key' => '_adinserter_block_exceptions',
'value' => '',
'compare' => '!='
)
),
'post_type' => $screens,
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => '',
'suppress_filters' => true
);
return (get_posts ($args));
}
function ai_get_exceptions ($conditions) {
if (function_exists ('ai_get_exceptions_2')) {
$exceptions = ai_get_exceptions_2 ();
if (is_array ($exceptions)) return $exceptions;
}
$exceptions = false;
$block_exceptions = array ();
if ($conditions) {
$posts_pages = ai_get_posts_pages_with_exceptions ();
$exceptions = array ();
foreach ($posts_pages as $page) {
$post_meta = get_post_meta ($page->ID, '_adinserter_block_exceptions', true);
if ($post_meta == '') continue;
$post_type_object = get_post_type_object ($page->post_type);
$exceptions [$page->ID] = array ('type' => $page->post_type, 'name' => $post_type_object->labels->singular_name, 'title' => $page->post_title, 'blocks' => $post_meta);
$selected_blocks = explode (",", $post_meta);
foreach ($selected_blocks as $selected_block) {
$block_exceptions [$selected_block][$page->ID] = array ('type' => $page->post_type, 'name' => $post_type_object->labels->singular_name, 'title' => $page->post_title);
}
}
}
return array ($exceptions, $block_exceptions);
}
function ai_clear_exceptions () {
$clear = $_POST [AI_FORM_CLEAR_EXCEPTIONS];
$posts_pages = ai_get_posts_pages_with_exceptions ();
// All exceptions
if ($clear == "\xe2\x9d\x8c") {
foreach ($posts_pages as $page) {
delete_post_meta ($page->ID, '_adinserter_block_exceptions');
}
apply_filters ('simple_history_log', AD_INSERTER_NAME . ' ' . __('exceptions cleared', 'ad-inserter'));
}
// Exceptions for post id
elseif (strpos ($clear, 'id=') === 0) {
$id = str_replace ('id=', '', $clear);
if (is_numeric ($id)) {
delete_post_meta ($id, '_adinserter_block_exceptions');
apply_filters ('simple_history_log', AD_INSERTER_NAME . ' ' . sprintf (__('exceptions for post "%s" cleared', 'ad-inserter'), get_the_title ($id)));
}
}
// Block exceptions
elseif (is_numeric ($clear)) {
foreach ($posts_pages as $page) {
$post_meta = get_post_meta ($page->ID, '_adinserter_block_exceptions', true);
$selected_blocks = explode (",", $post_meta);
if (($key = array_search ($clear, $selected_blocks)) !== false) {
unset ($selected_blocks [$key]);
update_post_meta ($page->ID, '_adinserter_block_exceptions', implode (",", $selected_blocks));
apply_filters ('simple_history_log', AD_INSERTER_NAME . ' ' . sprintf (__('exceptions for block %d cleared', 'ad-inserter'), $clear));
}
}
}
}
function ai_clear_settings () {
global $ai_db_options, $block_object, $wpdb, $ai_db_options_extract;
if (defined ('AI_CONNECTED_MANAGER')) {
$connected_manager = get_transient (AI_CONNECTED_MANAGER);
} else $connected_manager = false;
for ($block = 1; $block <= 96; $block ++) {
delete_option (str_replace ("#", $block, AD_ADx_OPTIONS));
}
$saved_management_key = isset ($ai_db_options [AI_OPTION_GLOBAL]['MANAGEMENT_KEY']) ? $ai_db_options [AI_OPTION_GLOBAL]['MANAGEMENT_KEY'] : '';
delete_option (str_replace ("#", "Header", AD_ADx_OPTIONS));
delete_option (str_replace ("#", "Footer", AD_ADx_OPTIONS));
delete_option (AD_OPTIONS);
delete_option (AI_OPTION_NAME);
delete_option (AI_EXTRACT_NAME);
delete_option (AI_FLAGS_NAME);
if (is_multisite () && is_main_site ()) {
delete_site_option (AI_OPTION_NAME);
}
delete_option (AI_ADSENSE_CLIENT_IDS);
delete_option (AI_ADSENSE_AUTH_CODE);
delete_option (AI_ADSENSE_OWN_IDS);
delete_option (AI_ADS_TXT_NAME);
delete_transient (AI_TRANSIENT_ADSENSE_TOKEN_1);
delete_transient (AI_TRANSIENT_ADSENSE_TOKEN);
delete_transient (AI_TRANSIENT_ADSENSE_ADS);
delete_transient ('ai-close');
if (function_exists ('ai_load_globals')) {
delete_option (WP_AD_INSERTER_PRO_LICENSE);
if ($connected_manager === false) {
delete_option (WP_AD_INSERTER_PRO_KEY);
}
delete_option (WP_AD_INSERTER_PRO_CLIENT);
$wpdb->query ("DROP TABLE IF EXISTS " . AI_STATISTICS_DB_TABLE);
if (defined ('AI_CONNECTED_WEBSITE')) {
delete_transient (AI_CONNECTED_WEBSITE);
delete_option (AI_WEBSITES);
}
delete_transient (AI_TRANSIENT_ADB_CLASS_1);
delete_transient (AI_TRANSIENT_ADB_CLASS_2);
delete_transient (AI_TRANSIENT_ADB_CLASS_3);
delete_transient (AI_TRANSIENT_ADB_CLASS_4);
delete_transient (AI_TRANSIENT_ADB_CLASS_5);
delete_transient (AI_TRANSIENT_ADB_CLASS_6);
delete_transient (AI_TRANSIENT_ADB_FILES_VERSION);
}
// if (/*ai_current_user_role_ok () && */(!is_multisite() || is_main_site () || multisite_exceptions_enabled ())) {
$posts_pages = ai_get_posts_pages_with_exceptions ();
foreach ($posts_pages as $page) {
delete_post_meta ($page->ID, '_adinserter_block_exceptions');
}
// }
ai_load_settings ();
$options = $ai_db_options;
$options [AI_OPTION_EXTRACT] = ai_generate_extract ($options);
$ai_db_options_extract = $options [AI_OPTION_EXTRACT];
$options [AI_OPTION_GLOBAL]['VIEWPORT_CSS'] = generate_viewport_css ();
$options [AI_OPTION_GLOBAL]['ALIGNMENT_CSS'] = generate_alignment_css ();
$options [AI_OPTION_GLOBAL]['TIMESTAMP'] = time ();
if ($connected_manager !== false) {
$options [AI_OPTION_GLOBAL]['REMOTE_DEBUGGING'] = AI_ENABLED;
$options [AI_OPTION_GLOBAL]['REMOTE_MANAGEMENT'] = AI_ENABLED;
$options [AI_OPTION_GLOBAL]['MANAGEMENT_KEY'] = $saved_management_key;
}
ai_update_option (AI_OPTION_NAME, $options);
update_option (AI_EXTRACT_NAME, $ai_db_options_extract);
ai_load_settings ();
if (function_exists ('ai_load_globals')) ai_load_globals ();
}
function ai_clear_statistics () {
global $wpdb;
if (isset ($_POST [AI_FORM_CLEAR_STATISTICS]) &&is_numeric ($_POST [AI_FORM_CLEAR_STATISTICS])) {
if ($_POST [AI_FORM_CLEAR_STATISTICS] != 0) {
$block = (int) $_POST [AI_FORM_CLEAR_STATISTICS];
$wpdb->query ("DELETE FROM " . AI_STATISTICS_DB_TABLE . " WHERE block = " . $block);
apply_filters ('simple_history_log', AD_INSERTER_NAME . ' ' . sprintf (__('statistics for block %d cleared', 'ad-inserter'), $block));
} else {
$wpdb->query ("DROP TABLE IF EXISTS " . AI_STATISTICS_DB_TABLE);
apply_filters ('simple_history_log', AD_INSERTER_NAME . ' ' . __('statistics cleared', 'ad-inserter'));
}
}
}
function ai_check_page () {
$download_urls = array ();
// echo '["1","2","3","4"]';
// return;
switch ($_GET ["check-page"]) {
case 'po':
case 'pa':
$args = array (
'public' => true,
'_builtin' => false
);
$custom_post_types = get_post_types ($args, 'names', 'and');
$screens = array_values (array_merge (array ($_GET ["check-page"] == 'po' ? 'post' : 'page'), $custom_post_types));
$args = array (
'posts_per_page' => 1,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'ID',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => $screens,
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => '',
'suppress_filters' => true,
);
$posts_pages = get_posts ($args);
if (isset ($posts_pages [0])) {
$download_urls []= get_permalink ($posts_pages [0]->ID);
}
// Check also post/page with comments
$args = array ('post_type' => $_GET ["check-page"] == 'po' ? 'post' : 'page', 'number' => 1);
$comment_data = get_comments ($args);
if (isset ($comment_data [0])) {
$download_urls []= get_permalink ($comment_data [0]->comment_post_ID);
}
break;
case 'hp':
$download_urls []= home_url () . '/';
break;
case 'cp':
$args = array ('hide_empty' => 0, 'orderby' => 'count', 'order' => 'DESC', 'number' => 1);
$category_data = get_categories ($args);
if (isset ($category_data [0])) {
$download_urls []= get_category_link ($category_data [0]->cat_ID) . '/';
}
break;
case 'ap':
$args = array ('hide_empty' => 0, 'orderby' => 'count', 'order' => 'DESC', 'number' => 1);
$tag_data = get_tags ($args);
if (isset ($tag_data [0])) {
$download_urls []= get_tag_link ($tag_data [0]->term_taxonomy_id) . '/';
}
break;
case 'sp':
$download_urls []= home_url () . '/?s=a';
break;
}
if (!empty ($download_urls)) {
$positions = array ();
$secret_key = ai_secret_key ();
foreach ($download_urls as $download_url) {
$tmp_file = download_url (add_query_arg (array (AI_URL_DEBUG_POSITIONS => '0', 'ai-secret' => $secret_key), $download_url));
if (!is_wp_error ($tmp_file) && file_exists ($tmp_file)) {
$page = file_get_contents ($tmp_file);
preg_match_all ('#data-ai-position=[\'\"](.+?)[\'\"]#', $page, $matches);
foreach (array_unique ($matches [1]) as $position) {
$positions [] = (int) $position;
}
} else {
// @unlink ($tmp_file);
$error_string = $tmp_file->get_error_message();
echo $error_string;
return;
}
@unlink ($tmp_file);
}
switch ($_GET ["check-page"]) {
case 'po':
case 'pa':
if (in_array (AI_AUTOMATIC_INSERTION_BEFORE_CONTENT, $positions) && in_array (AI_AUTOMATIC_INSERTION_AFTER_CONTENT, $positions)) {
$positions [] = AI_AUTOMATIC_INSERTION_BEFORE_PARAGRAPH;
$positions [] = AI_AUTOMATIC_INSERTION_AFTER_PARAGRAPH;
$positions [] = AI_AUTOMATIC_INSERTION_BEFORE_IMAGE;
$positions [] = AI_AUTOMATIC_INSERTION_AFTER_IMAGE;
}
if (in_array (AI_AUTOMATIC_INSERTION_BEFORE_COMMENTS, $positions) && in_array (AI_AUTOMATIC_INSERTION_AFTER_COMMENTS, $positions)) {
$positions [] = AI_AUTOMATIC_INSERTION_BETWEEN_COMMENTS;
}
break;
}
$positions = array_unique ($positions);
sort ($positions);
foreach ($download_urls as $index => $download_url) {
$download_urls [$index] = add_query_arg (array (AI_URL_DEBUG_POSITIONS => '0', 'no-cookie' => '1'), $download_url);
}
echo json_encode (array ('positions' => $positions, 'urls' => $download_urls));
}
}
function sidebar_addense_alternative () { ?>
generate_alignment_class ($block_class_name);
if ($block_class_name != '' && $block_number_class) $classes []= $block_class_name . '-n';
if ($block_class_name != '' && $block_name_class) $classes []= $block_class_name . '-name';
$class = count ($classes) ? ' class="' . implode (' ', $classes) . '"' : '';
$style = $inline_styles || !defined ('AI_NORMAL_HEADER_STYLES') ? ' style="' . AI_ALIGNMENT_CSS_DEFAULT . '"' : '';
echo "<div$class$style>";
}