$end) $active_tab = $start;
$active_tab_0 = isset ($active_tabs [1]) ? $active_tabs [1] : 0;
$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 <= AD_INSERTER_BLOCKS && !in_array ($sidebar_name, $sidebars_with_widget [$widget_block])) {
$sidebars_with_widget [$widget_block] []= $sidebar_name;
}
}
}
}
}
}
}
return $sidebars_with_widget;
}
function code_block_list_container () {
?>
$block) {
$new_block = $blocks_new [$index];
if ($block >= 1 && $block <= AD_INSERTER_BLOCKS && $new_block >= 1 && $new_block <= AD_INSERTER_BLOCKS) {
$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 <= AD_INSERTER_BLOCKS; $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 <= AD_INSERTER_BLOCKS) {
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 <= AD_INSERTER_BLOCKS; $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->wp_options [AI_OPTION_BLOCK_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;
?>
wp_options [AI_OPTION_BLOCK_NAME]; ?>
wp_options [AI_OPTION_BLOCK_NAME]; ?>
get_automatic_insertion_text(); ?>
get_alignment_type_text (); ?>
●
●
●
Block
Name
Automatic Insertion
Alignment
P
S
W
Widget Positions
No active code block"; else
echo "No code block matches search keywords
";
}
}
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"];
?>
Ad unit
Name
Slot ID
Type
Size
$error";
if (strpos ($error, 'unauthorized_client') !== false) {
echo "Please clear authorization with the button ",
' ',
" above and once again authorize access to your AdSense account.
";
}
}
}
elseif (defined ('AI_ADSENSE_CLIENT_ID')) {
$adsense = new adsense_api();
$adsense_ids = defined ('AI_CI_STRING') && get_option (AI_ADSENSE_OWN_IDS) === false;
?>
AdSense Integration
AdSense Integration - Step 2
Authorize to access your AdSense account. Click on the Get Authorization Code button to open a new window where you can allow access.
When you get the code copy it to the field below and click on the button Authorize .
If you get error, can't access ad units or would like to use own Google API IDs click on the button Use own API IDs to enter Client ID and Client Secret.
Now you can authorize to access your AdSense account. Click on the Get Authorization Code button to open a new window where you can allow access.
When you get the code copy it to the field below and click on the button Authorize .
If you get error invalid client click on the button Clear and return to Step 1 to re-enter Client ID and Client Secret.
Get Authorization Code
Use own API IDs
Clear and return to Step 1
Authorize
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);
$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':
$tag_data = get_tags ();
$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 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>";
}