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', 'mq_rs_cssjs');
add_action('admin_menu', 'mq_rs_maiq_add_pages');
add_filter('the_content', 'mq_rs_add_adsense');
add_filter('admin_footer', 'mq_rs_adsense_quicktag');
add_action('activate_adsense-revenue-sharing/adsense.php', 'mq_rs_install');
add_action('deactivate_adsense-revenue-sharing/adsense.php', 'mq_rs_uninstall');
global $wpdb, $mq_rs_table_one, $mq_rs_table_two, $mq_rs_pub, $mq_rs_settings, $mq_rs_posts, $post, $mq_rs_db_version;
$mq_rs_table_one = $wpdb->prefix . "adsense_id";
$mq_rs_table_two = $wpdb->prefix . "adsense_settings";
$mq_rs_pub = $wpdb->get_var("SELECT aid FROM $mq_rs_table_one order by hits ASC limit 1");
$mq_rs_settings = $wpdb->get_row("SELECT * FROM $mq_rs_table_two WHERE id='1'");
$mq_rs_posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_status='publish' ORDER BY post_date DESC LIMIT 1");
function mq_rs_cssjs() {
global $mq_rs_pub;
echo "
";
}
function mq_rs_ad($float) {
global $wpdb, $mq_rs_settings, $mq_rs_pub;
$wh = str_replace ('_as','',$mq_rs_settings->google_ad_format);
$wh = explode("x", $wh);
$adsense_code = '
';
return $adsense_code;
}
function mq_rs_add_adsense($data) {
global $wpdb, $mq_rs_table_one, $mq_rs_table_two, $mq_rs_settings, $mq_rs_pub, $mq_rs_posts, $post;
$tag = "";
if ($mq_rs_settings->all_pages == 'no'){
$matchCount = preg_match_all ( "//", $data, $matches , PREG_PATTERN_ORDER );
if (is_home()){
foreach ($mq_rs_posts as $pos) {
if ($post->ID == $pos->ID){
if( $matchCount != 0 ){ $wpdb->query("UPDATE $mq_rs_table_one SET hits = hits+1 WHERE aid = '$mq_rs_pub'"); }
if( $matchCount <= 3 ){ return str_replace( $tag, mq_rs_ad('none'), $data );}elseif( $matchCount > 3 ){ return $data .$adsense_code; }
}else{ return $data; }
}
}elseif (is_archive()){
foreach ($mq_rs_posts as $pos) {
if ($post->ID == $pos->ID){
if( $matchCount != 0 ){ $wpdb->query("UPDATE $mq_rs_table_one SET hits = hits+1 WHERE aid = '$mq_rs_pub'"); }
if( $matchCount <= 3 ){ return str_replace( $tag, mq_rs_ad('none'), $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 $mq_rs_table_one SET hits = hits+1 WHERE aid = '$mq_rs_pub'"); }
if( $matchCount <= 3 ){return str_replace( $tag, mq_rs_ad('none'), $data );
}elseif( $matchCount > 3 ){
return $data .mq_rs_ad('none');
}
}
}else{
if ($mq_rs_settings->position == 'top'){
$cdata = mq_rs_ad('none'). $data;
}elseif($mq_rs_settings->position == 'top-left'){
$cdata = mq_rs_ad('left'). $data;
}elseif($mq_rs_settings->position == 'top-right'){
$cdata = mq_rs_ad('right'). $data;
}elseif($mq_rs_settings->position == 'bottom'){
$cdata = $data .mq_rs_ad('none');
}elseif($mq_rs_settings->position == 'bottom-left'){
$cdata = $data .mq_rs_ad('left');
}elseif($mq_rs_settings->position == 'bottom-right'){
$cdata = $data .mq_rs_ad('right');
}else{$cdata=$data;}
if (is_home()){
foreach ($mq_rs_posts as $pos) {
if ($post->ID == $pos->ID){
$wpdb->query("UPDATE $mq_rs_table_one SET hits = hits+1 WHERE aid = '$mq_rs_pub'");
return $cdata;
}else{ return $data; }
}
}elseif (is_archive()){
foreach ($mq_rs_posts as $pos) {
if ($post->ID == $pos->ID){
$wpdb->query("UPDATE $mq_rs_table_one SET hits = hits+1 WHERE aid = '$mq_rs_pub'");
return $cdata ;
}else{ return $data; }
}
}elseif (is_search()){ return $data;
}elseif (is_feed()){ return $data;
}else{
$wpdb->query("UPDATE $mq_rs_table_one SET hits = hits+1 WHERE aid = '$mq_rs_pub'");
return $cdata;
}
}
}
function mq_rs_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 '$mq_rs_table_one'") != $mq_rs_table_one) && ($wpdb->get_var("show tables like '$mq_rs_table_two'") != $mq_rs_table_two)){
$sql = "CREATE TABLE " . $mq_rs_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 " . $mq_rs_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,
position text NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($sql);
dbDelta($sqla);
$wpdb->query("INSERT INTO ".$mq_rs_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, position)"."VALUES('468x60_as','FFFFFF','FFFFFF','B33C01','4d4d4d','B33C01','rc:0', 'no', 'top')");
$wpdb->query("INSERT INTO ".$mq_rs_table_one."(aid, name)"."VALUES('pub-8227551131685831','maiq')");
add_option("$mq_rs_db_version", $mq_rs_db_version);
}
}
function mq_rs_uninstall() {
global $wpdb, $mq_rs_table_one, $mq_rs_table_two;
$tbl = array($mq_rs_table_one, $mq_rs_table_two);
foreach($tbl as $table)
$wpdb->query("DROP TABLE `{$table}` ");
}
function mq_rs_brag(){
$mq_rs_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 $mq_rs_bragg;
}
function mq_rs_maiq_add_pages() {
add_options_page('Revenue Sharing', 'Revenue Sharing', 8, 'revenueoptions', 'maiq_options_page');
}
function mq_rs_user_update() {
global $wpdb, $mq_rs_table_one;
$id= $_REQUEST["id"]; $name= $_REQUEST["name"]; $hits= $_REQUEST["hits"]; $mq_rs_pub= $_REQUEST["pub"];
$wpdb->query("UPDATE $mq_rs_table_one SET name='$name', hits='$hits', aid='$mq_rs_pub' WHERE id = '$id'");
}
function mq_rs_hit_reset() {
global $wpdb, $mq_rs_table_one;
$id= $_REQUEST["id"];
$wpdb->query("UPDATE $mq_rs_table_one SET hits='0' WHERE id = '$id'");
}
function mq_rs_delete() {
global $wpdb, $mq_rs_table_one;
$wpdb->query("DELETE FROM $mq_rs_table_one WHERE id = '$_POST[id]'");
}
function mq_rs_add_new() {
global $wpdb, $mq_rs_table_one;
$mq_rs_pub= $_REQUEST["pub"]; $name= $_REQUEST["name"]; $hits= $_REQUEST["hits"];
if((!empty($mq_rs_pub)) && (!empty($name))){
$wpdb->query("INSERT INTO $mq_rs_table_one (aid, name, hits) VALUES ('$mq_rs_pub', '$name', '$hits')");
}
}
function mq_rs_settings_update() {
global $wpdb, $mq_rs_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"];
$position= $_REQUEST["ad_align"];
$wpdb->query("UPDATE $mq_rs_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', position = '$position' WHERE id = '1'");
header('Location: '.$_SERVER["REQUEST_URI"]);
}
if(isset($_POST['add_client'])){ mq_rs_add_new(); }
if(isset($_POST['client_update'])){ mq_rs_user_update(); }
if ((isset($_POST['delete'])) || (isset($_POST['delete_x']))) { mq_rs_delete(); }
if ((isset($_POST['hit_reset'])) || (isset($_POST['hit_reset_x']))) { mq_rs_hit_reset(); }
if(isset($_POST['settings_update'])){ mq_rs_settings_update(); }
function maiq_options_page() {
global $wpdb, $mq_rs_table_one, $mq_rs_table_two, $mq_rs_settings, $mq_rs_pub;
echo '
';
echo '
AdSense Revenue Sharing Options
';
$mq_rs_publishers = $wpdb->get_results("SELECT * FROM $mq_rs_table_one order by id asc");
echo'