Sindbad~EG File Manager

Current Path : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt-mobile/functions/helper/
Upload File :
Current File : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt-mobile/functions/helper/related.php

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

/*
 * Read More inside Post Content
 *
 * remove all auto embeds : https://wordpress.stackexchange.com/q/214172#comment311729_214172
 *
*/
if (mwp_option('mobile_read_also') == 1) {
	add_filter( 'the_content', 'mwp_insert_post_related', 10, 1 );
}
function mwp_insert_post_related( $content ) {
    global $post;
	
	preg_match_all('<!-- /wp:(.*?) -->', $content, $blocks);
	
	$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  	= mwp_option('mobile_read_also');
	
	if ( function_exists('is_product') && is_product() ) return $content;
	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) return $content;
	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( has_shortcode($content, 'error') ) return $content;
	if( has_shortcode($content, 'notice') ) return $content;
	if( has_shortcode($content, 'information') ) return $content;
	if( has_shortcode($content, 'success') ) return $content;
	if( has_shortcode($content, 'proscons') ) return $content;
	if ( in_array( 'alert-info', $blocks[1] ) ) return $content;
	if ( in_array( 'alert-success', $blocks[1] ) ) return $content;
	if ( in_array( 'alert-danger', $blocks[1] ) ) return $content;
	if ( in_array( 'alert-warning', $blocks[1] ) ) return $content;
	if ( in_array( 'pros-cons', $blocks[1] ) ) return $content;
	
	if ( is_singular() && !is_page() && ! is_admin() && $related_check ==  1) {
		if (check_post_ads('related', get_the_ID()) == 1) {
			
			$related_code 		= require( get_template_directory() . '/includes/related/read-also.php' );
			$related_paragraph 	= get_post_meta($post->ID, 'paragraph_readalso' , true);
			
			if (!empty($related_paragraph)) {
				$default_related_paragraph = $related_paragraph;
			} else {
				$default_related_paragraph = 2;
			}
			if (!is_admin()) {
				remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
			}
			return prefix_insert_after_paragraph( $related_code, $default_related_paragraph, $content );
		}
	}
	
    return $content;
}

/*
 * Related Post
 *
 * Returns a new WP_Query with related posts.
 * https://wordpress.org/themes/expound/
 *
*/
function mwp_get_related_posts($postid) {
	
	$ebm_ids 		= mwp_option('category-ebookmagazine');
	$post_count 	= esc_attr(mwp_option('single-related-postcount'));
	$today 			= getdate();
	$post_count 	= esc_attr(mwp_option('single-related-postcount'));
	$post_by_date 	= esc_attr(mwp_option('single-related-postdate'));
	
	if (!empty($ebm_ids) && in_category($ebm_ids, $postid)) {
		$posts_number = 4;
	} else {
		if (!empty($post_count)) {
			$posts_number = $post_count;
		} else {
			$posts_number = 3;
		}
	}
	
	/*
	 * Related by CATEGORY
	*/
	if (mwp_option('related-post-type') == 1) :
		
		$posts_array = get_the_category($postid);
		$posts_ids = array();
		foreach($posts_array as $individual_posts)
			$posts_ids[] = $individual_posts->term_id;
		if ($post_by_date == 1) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'category__in'		  	=> $posts_ids,
				'post__not_in'		  	=> array($postid),
				'date_query' => array(
					array(
						'year' => date( 'Y' )
					)
				),
				'orderby' 			  	=> 'rand',
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		} elseif ($post_by_date == 2) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  => 'publish',
				'category__in'		  => $posts_ids,
				'post__not_in'		  => array($postid),
				'date_query' => array(
					array(
						'after' => '-1 month',
					),
				),
				'orderby' 			  	=> 'rand',
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		} elseif ($post_by_date == 3) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'category__in'		  	=> $posts_ids,
				'post__not_in'		  	=> array($postid),
				'year' 					=> strftime( '%Y' ),
				'week' 					=> strftime( '%U' ),
				'date_query' => array(
					array(
						'year' => date( 'Y' ),
						'week' => strftime( '%U' ),
					),
				),
				'orderby' 			  	=> 'rand',
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		} else {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'category__in'		  	=> $posts_ids,
				'post__not_in'		  	=> array($postid),
				'orderby' 			  	=> 'rand',
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		}
		return new WP_Query($param);
	/*
	 * Related by TAGS
	*/
	elseif (mwp_option('related-post-type') == 2) :
		
		$posts_array = wp_get_post_tags($postid);
		$posts_ids = array();
		foreach($posts_array as $individual_posts)
			$posts_ids[] = $individual_posts->term_id;
		if ($post_by_date == 1) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'tag__in' 			  	=> $posts_ids,
				'post__not_in' 		  	=> array($postid),
				'date_query' => array(
					array(
						'year' => date( 'Y' )
					),
				),
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		} elseif ($post_by_date == 2) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'tag__in' 			  	=> $posts_ids,
				'post__not_in' 		  	=> array($postid),
				'date_query' => array(
					array(
						'year' 	=> date( 'Y' ),
						'month' => $today['mon']
					),
				),				
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		} elseif ($post_by_date == 3) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'tag__in' 			  	=> $posts_ids,
				'post__not_in' 		  	=> array($postid),
				'year' 					=> strftime( '%Y' ),
				'week' 					=> strftime( '%U' ),
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		} else {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'tag__in' 			  	=> $posts_ids,
				'post__not_in' 		  	=> array($postid),
				'posts_per_page'	  	=> $posts_number,
				'no_found_rows'			=> true,
				'ignore_sticky_posts' 	=> 1
			);
		}
		return new WP_Query($param);
	/*
	 * YARPP Plugin
	*/
	elseif (mwp_option('related-post-type') == 3) :
		$limit = get_option('yarpp');
		// Support for the Yet Another Related Posts Plugin
		if ( function_exists( 'yarpp_get_related' ) ) {
			$related = yarpp_get_related( array( 'limit' => $posts_number ), $postid );
			return new WP_Query( array(
				'post__in' 				=> wp_list_pluck( $related, 'ID' ),
				'posts_per_page' 		=> $posts_number,
				'ignore_sticky_posts' 	=> true,
				'post__not_in' 			=> array( $postid ),
				'no_found_rows'			=> true,
			) );
		}
	endif;
}

/*
 * Desciption	: Display Related Posts in middle of posts
 * Author 		: Mouad Achemli
 * Source		: http://www.mwordpress.net
 *
*/
function related_inside_post($postid) {
	
	$today = getdate();
	$post_count 	= esc_attr(mwp_option('readalso-postcount'));
	$post_by_date 	= esc_attr(mwp_option('readalso-post-date'));
	
	if (!empty($post_count)) {
		$posts_number = $post_count;
	} else {
		$posts_number = 3;
	}

	/*
	 * Related by CATEGORY
	*/
	if (mwp_option('readalso-post-type') == 1) {
		
		$posts_array = get_the_category($postid);
		$posts_ids = array();
		foreach($posts_array as $individual_posts)
			$posts_ids[] = $individual_posts->term_id;
		if ($post_by_date == 1) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'category__in'		  	=> $posts_ids,
				'post__not_in'		  	=> array($postid),
				'date_query' => array(
					array(
						'year' => date( 'Y' )
					)
				),
				'orderby'				=> 'rand',
				'posts_per_page'	  	=> $posts_number,
				'ignore_sticky_posts' 	=> 1,
				'no_found_rows'			=> true
			);
		} elseif ($post_by_date == 2) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'post__not_in'		  	=> array($postid),
				'category__in'		  	=> $posts_ids,
				'date_query' => array(
					array(
						'year' 	=> date( 'Y' ),
						'month' => $today['mon']
					),
				),
				'orderby' 			 	=> 'rand',
				'posts_per_page'		=> $posts_number,
				'ignore_sticky_posts' 	=> 1,
				'no_found_rows' 		=> true
			);
		} elseif ($post_by_date == 3) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'post__not_in'		  	=> array($postid),
				'category__in'		  	=> $posts_ids,
				'year' 					=> strftime( '%Y' ),
				'week' 					=> strftime( '%U' ),
				'orderby' 			  	=> 'rand',
				'posts_per_page'	  	=> $posts_number,
				'ignore_sticky_posts' 	=> 1,
				'no_found_rows' 		=> true
			);
		} else {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		 	=> 'publish',
				'category__in'		  	=> $posts_ids,
				'post__not_in'		  	=> array($postid),
				'orderby' 			  	=> 'rand',
				'posts_per_page'	  	=> $posts_number,
				'ignore_sticky_posts'	=> 1,
				'no_found_rows' 		=> true
			);
		}
	}
	/*
	 * Related by TAGS
	*/
	elseif (mwp_option('readalso-post-type') == 2) {
		
		$posts_array = wp_get_post_tags($postid);
		$posts_ids = array();
		foreach($posts_array as $individual_posts)
			$posts_ids[] = $individual_posts->term_id;
		if ($post_by_date == 1) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'post__not_in' 		  	=> array($postid),
				'tag__in' 			 	=> $posts_ids,
				'date_query' => array(
					array(
						'year' => date( 'Y' )
					)
				),
				'posts_per_page' 	  	=> $posts_number,
				'ignore_sticky_posts' 	=> 1,
				'no_found_rows' 		=> true
			);
		} elseif ($post_by_date == 2) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'post__not_in' 		  	=> array($postid),
				'tag__in' 			  	=> $posts_ids,
				'date_query' => array(
					array(
						'year' 	=> date( 'Y' ),
						'month' => $today['mon']
					),
				),
				'posts_per_page' 	  	=> $posts_number,
				'ignore_sticky_posts' 	=> 1,
				'no_found_rows' 		=> true
			);
		} elseif ($post_by_date == 3) {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'post__not_in' 		  	=> array($postid),
				'tag__in' 			  	=> $posts_ids,
				'year' 					=> strftime( '%Y' ),
				'week' 					=> strftime( '%U' ),
				'posts_per_page' 	  	=> $posts_number,
				'ignore_sticky_posts' 	=> 1,
				'no_found_rows' 		=> true
			);
		} else {
			$param = array(
				'post_type'				=> 'post',
				'post_status' 		  	=> 'publish',
				'post__not_in' 		  	=> array($postid),
				'tag__in' 			  	=> $posts_ids,
				'posts_per_page' 	  	=> $posts_number,
				'ignore_sticky_posts' 	=> 1,
				'no_found_rows'			=> true
			);
		}	
	}
	/*
	 * YARPP Plugin
	*/
	elseif (mwp_option('readalso-post-type') == 3) {
		$limit = get_option('yarpp');
		// Support for the Yet Another Related Posts Plugin
		if ( function_exists( 'yarpp_get_related' ) ) {
			$related = yarpp_get_related( array( 'limit' => $posts_number ), $postid );
			$param = array(
				'post__in' 				=> wp_list_pluck( $related, 'ID' ),
				'posts_per_page' 		=> $posts_number,
				'ignore_sticky_posts' 	=> true,
				'post__not_in' 			=> array( $postid ),
				'no_found_rows'			=> true,
			);
		}
	}
	
	return new WP_Query($param);
}

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