Revenue Sharing to edit the options. Please make sure you read Google's TOS before using this plugin! Author: MaiQ Author URI: http://www.maiq.info/ */ add_action('admin_head', 'cssjs'); add_action('admin_menu', 'maiq_add_pages'); add_filter('the_content', 'add_adsense'); add_filter('admin_footer', 'adsense_quicktag'); add_action('activate_adsense-revenue-sharing/adsense.php', 'install'); add_action('deactivate_adsense-revenue-sharing/adsense.php', 'uninstall'); $table_one = $wpdb->prefix . "adsense_id"; $table_two = $wpdb->prefix . "adsense_settings"; $pub = $wpdb->get_var("SELECT aid FROM $table_one order by hits ASC limit 1"); $settings = $wpdb->get_row("SELECT * FROM $table_two WHERE id='1'"); $posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_status='publish' ORDER BY ID DESC LIMIT 1"); function cssjs() { global $pub; echo " "; } function add_adsense($data) { global $wpdb, $table_one, $table_two, $settings, $pub, $posts, $post; $tag = ""; $wh = str_replace ('_as','',$settings->google_ad_format); $wh = explode("x", $wh); $adsense_code = ' '; if ($settings->all_pages == 'no'){ $matchCount = preg_match_all ( "//", $data, $matches , PREG_PATTERN_ORDER ); if (is_home()){ foreach ($posts as $pos) { if ($post->ID == $pos->ID){ if( $matchCount != 0 ){ $wpdb->query("UPDATE $table_one SET hits = hits+1 WHERE aid = '$pub'"); } if( $matchCount <= 3 ){ return str_replace( $tag, $adsense_code, $data );}elseif( $matchCount > 3 ){ return $data .$adsense_code; } }else{ return $data; } } } elseif (is_archive()){ foreach ($posts as $pos) { if ($post->ID == $pos->ID){ if( $matchCount != 0 ){ $wpdb->query("UPDATE $table_one SET hits = hits+1 WHERE aid = '$pub'"); } if( $matchCount <= 3 ){ return str_replace( $tag, $adsense_code, $data );}elseif( $matchCount > 3 ){ return $data .$adsense_code; } }else{ return $data; } } } elseif (is_search()){ return $data; } elseif (is_feed()){ return $data; }else{ if( $matchCount != 0 ){ $wpdb->query("UPDATE $table_one SET hits = hits+1 WHERE aid = '$pub'"); } if( $matchCount <= 3 ){return str_replace( $tag, $adsense_code, $data ); }elseif( $matchCount > 3 ){ return $data .$adsense_code; } } }else{ if (is_home()){ foreach ($posts as $pos) { if ($post->ID == $pos->ID){ $wpdb->query("UPDATE $table_one SET hits = hits+1 WHERE aid = '$pub'"); return $data .$adsense_code; }else{ return $data; } } } elseif (is_archive()){ foreach ($posts as $pos) { if ($post->ID == $pos->ID){ $wpdb->query("UPDATE $table_one SET hits = hits+1 WHERE aid = '$pub'"); return $data .$adsense_code; }else{ return $data; } } } elseif (is_search()){ return $data; } elseif (is_feed()){ return $data; }else{ $wpdb->query("UPDATE $table_one SET hits = hits+1 WHERE aid = '$pub'"); return $data .$adsense_code; } } } function adsense_quicktag() { if(strpos($_SERVER['REQUEST_URI'], 'post.php') || strpos($_SERVER['REQUEST_URI'], 'page.php') || strpos($_SERVER['REQUEST_URI'], 'post-new.php') || strpos($_SERVER['REQUEST_URI'], 'page-new.php') || strpos($_SERVER['REQUEST_URI'], 'bookmarklet.php')) { ?> if(toolbar) { var theButton = document.createElement('input'); theButton.type = 'button'; theButton.value = ''; theButton.onclick = ; theButton.className = 'ed_button'; theButton.title = ""; theButton.id = ""; toolbar.appendChild(theButton); } get_var("show tables like '$table_one'") != $table_one) && ($wpdb->get_var("show tables like '$table_two'") != $table_two)){ $sql = "CREATE TABLE " . $table_one . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, aid text NOT NULL, name tinytext NOT NULL, hits mediumint(9) NOT NULL, UNIQUE KEY id (id) );"; $sqla = "CREATE TABLE " . $table_two . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, google_ad_format text NOT NULL, google_ad_channel text NOT NULL, google_color_border text NOT NULL, google_color_bg text NOT NULL, google_color_link text NOT NULL, google_color_text text NOT NULL, google_color_url text NOT NULL, google_ui_features text NOT NULL, all_pages text NOT NULL, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); dbDelta($sqla); $wpdb->query("INSERT INTO ".$table_two."(google_ad_format, google_color_border, google_color_bg, google_color_link, google_color_text, google_color_url, google_ui_features, all_pages)"."VALUES('468x60_as','FFFFFF','FFFFFF','B33C01','4d4d4d','B33C01','rc:0', 'no')"); $wpdb->query("INSERT INTO ".$table_one."(aid, name)"."VALUES('pub-1546082867930106','maiq')"); add_option("maiq_db_version", $maiq_db_version); } } function uninstall() { global $wpdb, $table_one, $table_two; $tbl = array($table_one, $table_two); foreach($tbl as $table) $wpdb->query("DROP TABLE `{$table}` "); } function brag(){ $bragg='
Thanks for using my plugin.
If you find yourself using it a lot you might want to "Buy me a coffee :)"
Also you will find some good information about your blog here.
For updates visit the plugin page here
'; return $bragg; } function maiq_add_pages() { add_options_page('Revenue Sharing', 'Revenue Sharing', 8, 'revenueoptions', 'maiq_options_page'); } function user_update() { global $wpdb, $table_one; $id= $_REQUEST["id"]; $name= $_REQUEST["name"]; $hits= $_REQUEST["hits"]; $pub= $_REQUEST["pub"]; $wpdb->query("UPDATE $table_one SET name='$name', hits='$hits', aid='$pub' WHERE id = '$id'"); } function hit_reset() { global $wpdb, $table_one; $id= $_REQUEST["id"]; $wpdb->query("UPDATE $table_one SET hits='0' WHERE id = '$id'"); } function delete() { global $wpdb, $table_one; $wpdb->query("DELETE FROM $table_one WHERE id = '$_POST[id]'"); } function add_new() { global $wpdb, $table_one; $pub= $_REQUEST["pub"]; $name= $_REQUEST["name"]; $hits= $_REQUEST["hits"]; if((!empty($pub)) && (!empty($name))){ $wpdb->query("INSERT INTO $table_one (aid, name, hits) VALUES ('$pub', '$name', '$hits')"); } } function settings_update() { global $wpdb, $table_two; $google_ad_format= $_REQUEST["google_ad_format"]."_as"; $google_ad_channel= $_REQUEST["google_ad_channel"]; $google_color_border= $_REQUEST["google_color_border"]; $google_color_bg= $_REQUEST["google_color_bg"]; $google_color_link= $_REQUEST["google_color_link"]; $google_color_text= $_REQUEST["google_color_text"]; $google_color_url= $_REQUEST["google_color_url"]; $google_ui_features= $_REQUEST["google_ui_features"]; $all_pages= $_REQUEST["all_pages"]; $wpdb->query("UPDATE $table_two SET google_ad_format='$google_ad_format', google_ad_channel ='$google_ad_channel', google_color_border = '$google_color_border', google_color_bg = '$google_color_bg', google_color_link = '$google_color_link', google_color_text = '$google_color_text', google_color_url = '$google_color_url', google_ui_features = '$google_ui_features', all_pages = '$all_pages' WHERE id = '1'"); header('Location: '.$_SERVER["REQUEST_URI"]); } if(isset($_POST['add_client'])){ add_new(); } if(isset($_POST['client_update'])){ user_update(); } if ((isset($_POST['delete'])) || (isset($_POST['delete_x']))) { delete(); } if ((isset($_POST['hit_reset'])) || (isset($_POST['hit_reset_x']))) { hit_reset(); } if(isset($_POST['settings_update'])){ settings_update(); } function maiq_options_page() { global $wpdb, $table_one, $table_two, $settings, $pub; echo '
'; echo '

AdSense Revenue Sharing Options

'; $publishers = $wpdb->get_results("SELECT * FROM $table_one order by id asc"); echo''; foreach ($publishers as $val){ echo''; } echo'
IDNameHitspubMisc
'.$val->id.''.$val->name.''.$val->hits.''.$val->aid.'
Name: PUB: Hits:

AdSense ad settings
Channel
Border
Background
Title
Text
URL
Corners
Ad format
All pages Yes all_pages == 'yes'){echo'checked';} ?>> No all_pages == 'no'){echo'checked';} ?>>

If you select yes all the <!--adsense--> tags will be ignored and one ad will be inserted at the end of every post and page.

'; } ?>