96) $start = 1;
$end = $start + 15;
if ($end > 96) $end = 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'])) {
$active_tab = $_GET ['settings'];
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'])) $active_tab = $_GET ['tab']; else
$active_tab = isset ($active_tabs [0]) ? $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]) ? $active_tabs [1] : 0;
$disable_block_insertions = get_disable_block_insertions ();
$disable_php_processing = get_disable_php_processing ();
$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_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 .= '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 = get_syntax_highlighter_theme ();
$block_class_name = get_block_class_name ();
$block_class = get_block_class ();
$block_number_class = get_block_number_class ();
$inline_styles = get_inline_styles ();
$default = $block_object [0];
$exceptions = false;
$block_exceptions = array ();
if (ai_current_user_role_ok () && (!is_multisite() || is_main_site () || multisite_exceptions_enabled ())) {
$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' => 100,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'type',
'order' => 'ASC',
'include' => '',
'exclude' => '',
'meta_key' => '_adinserter_block_exceptions',
'meta_value' => '',
'post_type' => $screens,
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => '',
'suppress_filters' => true
);
$posts_pages = get_posts ($args);
$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);
}
}
}
$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])) $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
if (function_exists ('ai_admin_settings_notices')) ai_admin_settings_notices ();
?>
$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 = wp_get_theme();
?>
", $current_theme->get ('Name'), " ", $current_theme->get ('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 ();
// data-ad-client="ca-pub-3118622027477755"
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);
}
}
}
}
// google_ad_client = "ca-pub-3118622027477755";
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);
}
}
}
}
}
$ads_txt_file = ABSPATH . 'ads.txt';
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 ($_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;
}
}
}
if (site_url ('', 'relative') != '') {
$right_ads_txt_url = str_replace (site_url ('', 'relative'), '', home_url ('/')) . 'ads.txt';
echo '';
echo '
', __('Warning', 'ad-inserter'), ': ', __('ads.txt file must be placed on the root domain', 'ad-inserter'), ' ', $right_ads_txt_url, ' ';
echo '
', /* translators: %s: file path */ sprintf (__('WordPress is installed in %s', 'ad-inserter'), '' . ABSPATH . ' '), '
';
echo '
', __('Showing file', 'ad-inserter'), ' ', $ads_txt_file, '
';
echo '
';
}
if (!file_exists ($ads_txt_file)) {
echo '';
echo '
', __('Warning', 'ad-inserter'), ': ', sprintf (__('File %s not found', 'ad-inserter'), $ads_txt_file), '
';
echo '
';
}
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 ' ';
echo '', $ads_txt_file, '
';
}
echo '';
echo $ads;
echo ' ';
break;
case 'table':
?>
'.$ads_elements [3] .'';
} else $element3 = $ads_elements [3];
} else $element3 = '';
?>
>
$block) {
$new_block = $blocks_new [$index];
if ($block >= 1 && $block <= 96 && $new_block >= 1 && $new_block <= 96) {
$new_options [$block] = $current_options [$new_block];
} else $error = true;
}
if (!$error) {
// Update AI_OPTION_FALLBACK and AI_OPTION_ADB_BLOCK_REPLACEMENT
for ($block = 1; $block <= 96; $block ++) {
if (isset ($new_options [$block][AI_OPTION_FALLBACK])) {
$ai_option_fallback = $new_options [$block][AI_OPTION_FALLBACK];
if ($ai_option_fallback != '')
foreach ($blocks_new as $index => $org_block) {
if ($ai_option_fallback == $org_block) {
$new_options [$block][AI_OPTION_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_option (AI_OPTION_NAME, $new_options);
ai_load_settings ();
$new_options [AI_OPTION_EXTRACT] = ai_generate_extract ($new_options);
$ai_db_options_extract = $new_options [AI_OPTION_EXTRACT];
$new_options [AI_OPTION_GLOBAL]['VIEWPORT_CSS'] = generate_viewport_css ();
$new_options [AI_OPTION_GLOBAL]['ALIGNMENT_CSS'] = generate_alignment_css ();
$new_options [AI_OPTION_GLOBAL]['TIMESTAMP'] = time ();
update_option (AI_OPTION_NAME, $new_options);
update_option (AI_EXTRACT_NAME, $ai_db_options_extract);
ai_load_settings ();
$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);
}
}
}
}
$sidebars_with_widget = get_sidebar_widgets ();
ob_start ();
$search_text = trim ($_GET ["list"]);
$show_all_blocks = isset ($_GET ["all"]) && $_GET ["all"];
$start = trim ($_GET ["start"]);
$end = trim ($_GET ["end"]);
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];
$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;
$block_text = $block . ' '. $obj->get_ad_name () . ' ' . $obj->get_automatic_insertion_text() . ' ' . $obj->get_alignment_type_text () . ' ' . implode (', ', $sidebars_with_widget [$block]);
if (!empty ($sidebars_with_widget [$block])) $block_text .= ' widget';
if ($manual_shortcode) $block_text .= ' shortcode';
if ($manual_php_function) $block_text .= ' php';
foreach ($search_array as $search_item) {
if (stripos ($block_text, trim ($search_item)) === false) continue 2;
}
$blocks []= $block;
$row_counter ++;
$row_color = $row_counter % 2 == 0 ? '#eee' : '#fff';
if (function_exists ('ai_settings_url_parameters')) $url_parameters = ai_settings_url_parameters ($block); else $url_parameters = "";
$edit_url = admin_url ('options-general.php?page=ad-inserter.php') . $url_parameters . '&tab=' . $block;
$visible_tab = $block >= $start && $block <= $end;
?>
get_ad_name(); ?>
get_ad_name(); ?>
get_automatic_insertion_text(); ?>
get_alignment_type_text (); ?>
●
●
●
"; else
echo "
";
}
}
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')) {
$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 ($adsense_data) {
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) {
$max_items = 2000;
switch ($options) {
case 'category':
// $args = array("hide_empty" => 0);
$args = array("hide_empty" => 0, 'number' => $max_items);
$category_data = get_categories ($args);
// $category_data = array_slice ($category_data, 0, $max_items);
foreach ($category_data as $category) {
echo " {$category->slug} ({$category->name}) \n";
}
break;
case 'tag':
$args = array ('number' => $max_items);
// $tag_data = get_tags ();
$tag_data = get_tags ($args);
// $tag_data = array_slice ($tag_data, 0, $max_items);
foreach ($tag_data as $tag) {
echo " {$tag->slug} ({$tag->name}) \n";
}
break;
case 'taxonomy':
$term_data = get_terms ();
$taxonomies = array ();
foreach ($term_data as $term) {
if ($term->taxonomy == 'category') continue;
if ($term->taxonomy == 'post_tag') continue;
$taxonomies [strtolower ($term->taxonomy) . ':' . strtolower ($term->slug)] = $term->name;
if (count ($taxonomies) >= $max_items) break;
}
$args = array (
'public' => true,
// '_builtin' => false,
);
$custom_post_types = get_post_types ($args, 'objects', 'and');
foreach ($custom_post_types as $custom_post_type => $custom_post_data) {
$taxonomies ['post-type:' . strtolower ($custom_post_type)] = $custom_post_data->labels->singular_name;
}
$editable_roles = get_editable_roles ();
foreach ($editable_roles as $editable_role_slug => $editable_role) {
$taxonomies ['user-role:' . strtolower ($editable_role_slug)] = $editable_role ['name'];
}
$users = get_users ();
foreach ($users as $user) {
$taxonomies ['user:' . strtolower ($user->data->user_login)] = $user->data->display_name;
$taxonomies ['author:' . strtolower ($user->data->user_login)] = $user->data->display_name;
if (count ($taxonomies) >= $max_items) break;
}
ksort ($taxonomies);
foreach ($taxonomies as $taxonomy => $taxonomy_name) {
if ($taxonomy_name != '')
echo " {$taxonomy} ({$taxonomy_name}) \n"; else
echo " {$taxonomy} \n";
}
break;
case 'id':
$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' => 3 * $max_items,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'ID',
'order' => 'ASC',
'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);
$counter = 0;
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_items) break;
}
break;
default:
if (function_exists ('ai_generate_list_options')) ai_generate_list_options ($options);
break;
}
}
function ai_check_page ($options) {
$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;
}
}
@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';
$class = count ($classes) ? ' class="' . implode (' ', $classes) . '"' : '';
$style = $inline_styles || !defined ('AI_NORMAL_HEADER_STYLES') ? ' style="' . AI_ALIGNMENT_CSS_DEFAULT . '"' : '';
echo "<div$class$style>";
}