Sindbad~EG File Manager

Current Path : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt/amp/helper/
Upload File :
Current File : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt/amp/helper/ads.php

<?php 
/*
 * Security 	: blocking direct access
 * Source		: http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");

/*
 * Desciption	: Display Ads based on MWP Panel
 * Author 		: Mouad Achemli
 * Source		: http://www.mwordpress.net
 *
*/
function mwp_ads_display_amp($type, $ad_client, $ad_slot) {
	switch ($type) {
		case 'amp-fixed':
			return  '<amp-ad layout="fixed-height" height=100 type="adsense" data-ad-client="'.$ad_client.'" data-ad-slot="'.$ad_slot.'"></amp-ad>';
		break;
		case 'amp-responsive':
			return  '<amp-ad width="100vw" height=320 type="adsense" data-ad-client="'.$ad_client.'" data-ad-slot="'.$ad_slot.'" data-auto-format="rspv" data-full-width> <div overflow></div></amp-ad>';
		break;
	}
}

/*
 * Adsense - Revenu Share
 *
 * randomize the admin/author accordingly 
 *
*/
function mwp_ads_revenu_share_amp($type) {
	
	global $post;
	$author_id 			= $post->post_author;
	$get_percent 		= mwp_option('ars-admin-ad-percentage');
	$admin_ad_client	= mwp_option('ars-admin-ad-client');
	$admin_ad_slot		= mwp_option('ars-admin-ad-slot');
	$author_ad_client	= get_the_author_meta( 'mwp_ars_ad_client', $author_id );
	$author_ad_slot		= get_the_author_meta( 'mwp_ars_ad_slot', $author_id );
	$check_authors_list = mwp_option('ars-select-author');
	
	if (!empty($get_percent)) {
		$percent 		= $get_percent;
	} else {
		$percent 		= 50;
	}
	$ray_state = array_filter($check_authors_list);
	
	// Here Only Select Authors Will Use Adsense Revenu Share
	if (!empty($ray_state) && in_array($author_id, $check_authors_list)) {
		// Ad Client check
		if($author_ad_client != ""){
			$input1 = $admin_ad_client;
			$input2 = $author_ad_client;
		} else {
			$input1 = $admin_ad_client;
			$input2 = $input1;
		}
		// Ad Slot check
		if($author_ad_slot != ""){
			$input3 = $admin_ad_slot;
			$input4 = $author_ad_slot;
		} else {
			$input3 = $admin_ad_slot;
			$input4 = $input3;
		}
	} 
	// Here will Skip Authors Not Select In Adsense Revenu Share
	elseif (!empty($ray_state) && !in_array($author_id, $check_authors_list)) {
		// Ad Client check
		if($author_ad_client != ""){
			$input1 = $admin_ad_client;
			$input2 = $input1;
		} else {
			$input1 = $admin_ad_client;
			$input2 = $input1;
		}
		// Ad Slot check
		if($author_ad_slot != ""){
			$input3 = $admin_ad_slot;
			$input4 = $input3;
		} else {
			$input3 = $admin_ad_slot;
			$input4 = $input3;
		}
	} 
	// Here All Authors Can Use Adsense Revenu Share
	else {
		// Ad Client check
		if($author_ad_client != ""){
			$input1 = $admin_ad_client;
			$input2 = $author_ad_client;
		} else {
			$input1 = $admin_ad_client;
			$input2 = $input1;
		}
		// Ad Slot Check
		if($author_ad_slot != ""){
			$input3 = $admin_ad_slot;
			$input4 = $author_ad_slot;
		} else {
			$input3 = $admin_ad_slot;
			$input4 = $input3;
		}
	}
	//randomize the admin/author accordingly
	srand(time());
	$random = (rand()%101);
	if ($random <= $percent) {
		$ad_client 	= $input1;
		$ad_slot 	= $input3;
	} else {
		$ad_client 	= $input2;
		$ad_slot 	= $input4;
	}
	
	switch ($type) {
		case 'amp-fixed':
			return '<amp-ad layout="fixed-height" height=100 type="adsense" data-ad-client="'.$ad_client.'" data-ad-slot="'.$ad_slot.'"></amp-ad>';
		break;
		
		case 'amp-responsive':
			return '<amp-ad class="amp-ad-3" width="100vw" height=320 type="adsense" data-ad-client="'.$ad_client.'" data-ad-slot="'.$ad_slot.'" data-auto-format="rspv" data-full-width><div overflow></div></amp-ad>';
		break;
		
		case 'amp-auto':
			return  '<amp-auto-ads type="adsense" data-ad-client="'.$ad_client.'"></amp-auto-ads>';
		break;
		
	}
}

/*
 * POSTQUARE - Revenu Share
 *
 * randomize the admin/author accordingly 
 *
*/
function mwp_ads_rs_postquare_amp() {
	
	global $post;
	$author_id 				= $post->post_author;
	$get_percent 			= mwp_option('ars-admin-ad-percentage');
	$admin_ad_prs_wid		= mwp_option('mwp_admin_prs_wid');
	$admin_ad_prs_pubid		= mwp_option('mwp_admin_prs_pubid');
	$admin_ad_prs_webid		= mwp_option('mwp_admin_prs_webid');
	$author_ad_prs_wid		= get_the_author_meta( 'mwp_prs_wid', $author_id );
	$author_ad_prs_pubid	= get_the_author_meta( 'mwp_prs_pubid', $author_id );
	$author_ad_prs_webid	= get_the_author_meta( 'mwp_prs_webid', $author_id );
	$check_authors_list 	= mwp_option('ars-select-author');
	
	if (!empty($get_percent)) {
		$percent 		= $get_percent;
	} else {
		$percent 		= 50;
	}
	
	$ray_state = array_filter($check_authors_list);
	
	// Here Only Select Authors Will Use Adsense Revenu Share
	if (!empty($ray_state) && in_array($author_id, $check_authors_list)) {
		
		// wid check
		if($author_ad_prs_wid != ""){
			$input1 = $admin_ad_prs_wid;
			$input2 = $author_ad_prs_wid;
		} else {
			$input1 = $admin_ad_prs_wid;
			$input2 = $input1;
		}
		
		// pubid check
		if($author_ad_prs_pubid != ""){
			$input3 = $admin_ad_prs_pubid;
			$input4 = $author_ad_prs_pubid;
		} else {
			$input3 = $admin_ad_prs_pubid;
			$input4 = $input3;
		}
		
		// webid check
		if($author_ad_prs_webid != ""){
			$input5 = $admin_ad_prs_webid;
			$input6 = $author_ad_prs_webid;
		} else {
			$input5 = $admin_ad_prs_webid;
			$input6 = $input5;
		}
		
	} 
	// Here will Skip Authors Not Select In Adsense Revenu Share
	elseif (!empty($ray_state) && !in_array($author_id, $check_authors_list)) {
		// wid check
		if($author_ad_prs_wid != ""){
			$input1 = $admin_ad_prs_wid;
			$input2 = $input1;
		} else {
			$input1 = $admin_ad_prs_wid;
			$input2 = $input1;
		}
		
		// pubid check
		if($author_ad_prs_pubid != ""){
			$input3 = $admin_ad_prs_pubid;
			$input4 = $input3;
		} else {
			$input3 = $admin_ad_prs_pubid;
			$input4 = $input3;
		}
		
		// webid check
		if($author_ad_prs_webid != ""){
			$input5 = $admin_ad_prs_webid;
			$input6 = $input5;
		} else {
			$input5 = $admin_ad_prs_webid;
			$input6 = $input5;
		}
	
	} 
	// Here All Authors Can Use Adsense Revenu Share
	else {
		
		// wid check
		if($author_ad_prs_wid != ""){
			$input1 = $admin_ad_prs_wid;
			$input2 = $author_ad_prs_wid;
		} else {
			$input1 = $admin_ad_prs_wid;
			$input2 = $input1;
		}
		
		// pubid check
		if($author_ad_prs_pubid != ""){
			$input3 = $admin_ad_prs_pubid;
			$input4 = $author_ad_prs_pubid;
		} else {
			$input3 = $admin_ad_prs_pubid;
			$input4 = $input3;
		}
		
		// webid check
		if($author_ad_prs_webid != ""){
			$input5 = $admin_ad_prs_webid;
			$input6 = $author_ad_prs_webid;
		} else {
			$input5 = $admin_ad_prs_webid;
			$input6 = $input5;
		}
		
	}
	
	srand(time());
	$random = (rand()%101);
	if ($random <= $percent) {
		$ad_wid 	= $input1;
		$ad_pubid 	= $input3;
		$ad_webid 	= $input5;
	} else {
		$ad_wid 	= $input2;
		$ad_pubid 	= $input4;
		$ad_webid 	= $input6;
	}
	
	return '<amp-embed width="200" height="200" type="postquare" layout="responsive" data-widgetIds="'.$ad_wid.'" data-websiteId="'.$ad_pubid.'" data-publisherId="'.$ad_webid.'"><div overflow>Click to resize</div></amp-embed>';
	
}


/*
 * Ads Above Content
 *
*/
function mwp_amp_ads_top_content() {
	$output = '';
	$amp_fixed_skip 	= mwp_option('amp-fixed-skip-categories');
	$amp_ad_client 		= mwp_option('amp-fixed-ad-client');
	$amp_ad_slot 		= mwp_option('amp-fixed-ad-slot');
	$amp_ad_share 		= mwp_option('amp-fixed-revenu-share');
	if ( mwp_option('amp-fixed-ad-enable') == 1 && !in_category($amp_fixed_skip) ) : 
		if ( mwp_option('amp-fixed-type') == 1 ) {
			$ad_type = 'amp-fixed';
		} else {
			$ad_type = 'amp-responsive';
		}
		$output .= '<div class="amp-ad-wrapper">';
			if ($amp_ad_share == 1) {
				$output .= mwp_ads_revenu_share_amp($ad_type);
			} else {
				if(!empty($amp_ad_client) && !empty($amp_ad_slot)):
					$output .= mwp_ads_display_amp($ad_type, $amp_ad_client, $amp_ad_slot);
				endif;
			}
		$output .= '</div>';
	endif;
	return $output;
}
function mwp_amp_ads_top($content) {
	
	if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
		$ads = mwp_amp_ads_top_content();
		$content = $ads.$content;
		return $content;
	} else {
		return $content;
	}
}
add_filter('the_content','mwp_amp_ads_top', 10, 1);
/*
 * Ads Below Content
 *
*/
function mwp_amp_ads_bottom_content() {
	$output = '';
	$amp_res2_skip 	= mwp_option('amp-responsive2-skip-categories');
	$amp_ad_client 	= mwp_option('amp-responsive2-ad-client');
	$amp_ad_slot 	= mwp_option('amp-responsive2-ad-slot');
	$amp_ad_share 	= mwp_option('amp-responsive2-revenu-share');
	if ( mwp_option('amp-responsive2-ad-enable') == 1 && !in_category($amp_res2_skip) ) : 
		$output .= '<div class="amp-ad-wrapper">';
			if ($amp_ad_share == 1) {
				$output .= mwp_ads_revenu_share_amp('amp-responsive');
			} else {
				if(!empty($amp_ad_client) && !empty($amp_ad_slot)):
					$output .= mwp_ads_display_amp('amp-responsive', $amp_ad_client, $amp_ad_slot);
				endif;
			}
		$output .= '</div>';
	endif;
	return $output;
}
function mwp_amp_ads_bottom($content) {
	
	if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
		$ads = mwp_amp_ads_bottom_content();
		$content = $content.$ads;
		return $content;
	} else {
		return $content;
	}
}
add_filter('the_content','mwp_amp_ads_bottom', 11, 1);


/*
 * Ads Inside Content
 *
*/
function mwp_amp_ads_inside_content() {
	$output = '';
	$amp_res_skip 	= mwp_option('amp-responsive-skip-categories');
	$amp_ad_client 	= mwp_option('amp-responsive-ad-client');
	$amp_ad_slot 	= mwp_option('amp-responsive-ad-slot');
	$amp_ad_share 	= mwp_option('amp-responsive-revenu-share');
	if ( mwp_option('amp-responsive-ad-enable') == 1 && !in_category($amp_res_skip) ) : 
		$output .= '<div class="amp-ad-wrapper">';
			if ($amp_ad_share == 1) {
				$output .= mwp_ads_revenu_share_amp('amp-responsive');
			} else {
				if(!empty($amp_ad_client) && !empty($amp_ad_slot)):
					$output .= mwp_ads_display_amp('amp-responsive', $amp_ad_client, $amp_ad_slot);
				endif;
			}
		$output .= '</div>';
	endif;
	echo $output;
}

/*
 * ADS inside Post Content
 *
*/
if (mwp_option('amp-responsive-ad-enable') == 1) {
	add_filter( 'the_content', 'mwp_amp_insert_post_ads', 10, 1  );
}
function mwp_amp_insert_post_ads( $content ) {
    
	global $post;
	
	$videos_ids 		= mwp_option('category-videos');
	$gallery_ids 		= mwp_option('category-gallery');
	$caricature_ids 	= mwp_option('category-caricature');
	$ebookmagazine_ids 	= mwp_option('category-ebookmagazine');
	$article_ids 		= mwp_option('category-article');
	$related_check 		= 0;
	$ads_check  		= mwp_option('amp-responsive-ad-enable');

	if (!empty($videos_ids) && in_category($videos_ids) ) return $content;
	if (!empty($gallery_ids) && in_category($gallery_ids) ) return $content;
	if (!empty($caricature_ids) && in_category($caricature_ids) ) return $content;
	if ( !empty($ebookmagazine_ids) && in_category($ebookmagazine_ids) ) return $content;
	if ( !empty($article_ids) && in_category($article_ids) ) return $content;
	
	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
		if ( is_singular() && !is_admin() && $ads_check == 1) {
			if (check_post_ads('inside', get_the_ID()) == 1) {				
				ob_start();
				mwp_amp_ads_inside_content();
				$html_ad_code = ob_get_contents();
				ob_end_clean();
				$ads_code 		= $html_ad_code;
				$ads_paragraph 	= get_post_meta($post->ID, 'paragraph_ads' , true);
				if (!empty($ads_paragraph)) {
					$default_ads_paragraph = $ads_paragraph;
				} elseif ($related_check ==  1) {
					$default_ads_paragraph = 3;
				} else {
					$default_ads_paragraph = 2;
				}
				return prefix_insert_after_paragraph( $ads_code, $default_ads_paragraph, $content );
			}
		}
		return $content;
	} else {
		return $content;
	}
}
/*
 * AMP Auto Ads By Adsense
 *
*/
function mwp_amp_insert_auto_ads_content() {
	$output = '';
	$auto_ads = mwp_option('amp-auto-ad-client');
	if ( mwp_option('amp-auto-revenu-share') == 1 ) {
		$output .= mwp_ads_revenu_share_amp('amp-auto');
	} else {
		$output .= '<amp-auto-ads type="adsense" data-ad-client="'.$auto_ads.'"></amp-auto-ads>';
	}
	return $output;
}
if (mwp_option('amp-auto-ad-enable') == 1) {
	add_filter( 'the_content', 'mwp_amp_insert_auto_ads', 999999, 1  );
}
function mwp_amp_insert_auto_ads( $content ) {
	if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
		$ads = mwp_amp_insert_auto_ads_content();
		$content = $content.$ads;
		return $content;
	} else {
		return $content;
	}
}


/*
 * POSTQUARE ADS
 *
*/
function mwp_amp_pq_ads_content() {
	$output = '';
	
	$postquare_wid 		= mwp_option('amp-pq-ad-wid');
	$postquare_pubid 	= mwp_option('amp-pq-ad-pubid');
	$postquare_webid 	= mwp_option('amp-pq-ad-webid');
			
	if ( mwp_option('amp-pq-revenu-share') == 1 ) {
		$output .= mwp_ads_rs_postquare_amp();
	} else {
		$output .= '<amp-embed width="200" height="200" type="postquare" layout="responsive" data-widgetIds="'.$postquare_wid.'" data-websiteId="'.$postquare_webid.'" data-publisherId="'.$postquare_pubid.'"><div overflow>Click to resize</div></amp-embed>';
	}
	return $output;
}
if (mwp_option('amp-pq-ad-enable') == 1) {
	add_filter( 'the_content', 'mwp_amp_pq_ads', 9999999, 1  );
}
function mwp_amp_pq_ads( $content ) {
	if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
		$ads = mwp_amp_pq_ads_content();
		$content = $content.$ads;
		return $content;
	} else {
		return $content;
	}
}




Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists