Sindbad~EG File Manager

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

<?php
/*
 * Security 	: blocking direct access
 * Source		: http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");
/*
 * Plugin Name	: Ajax_the_views
 * Plugin URI	: http://www.scratch.com/wordpress-plugin-ajax-the-views/
 * Description	: Extends Views so that the number of post views is displayed via Ajax, meaning it will be accurate even if a caching plugin is being used. 
 * Note			: when caching plugin is being used, but can't *display* the count. This fixes that.
 * Version		: 1.0
 * Date			: 17 September 2010
 * Author		: Stephen Cronin
 * Author URI	: http://www.scratch99.com/
 * Last Update  : 01 May 2018
 * Update by 	: Mouad Achemli
*/
if(
function_exists('the_views') && defined( 'WP_CACHE' ) && WP_CACHE && !is_admin() ||
class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'stats' ) && defined( 'WP_CACHE' ) && WP_CACHE && !is_admin()
) :
	function ajax_the_views($content){
		global $post;
		if ( !wp_is_post_revision( $post->ID ) && ( is_single() || is_page() ) ) {
			return '<cite class="ajax-the-views" id="ajax-the-views-'.$post->ID.'">wait...</cite>';
		} else {
			return $content;
		}
	}
	add_filter('the_views', 'ajax_the_views');
	add_filter('jp_get_page_views', 'ajax_the_views');
	function ajax_the_views_footer() {
		global $post;
		if ( !wp_is_post_revision( $post->ID ) && is_single() ) :
			?>
			<script>
			jQuery(document).ready(function($) {
				var postIDs = new Array();
				var i = 0;
				jQuery('.ajax-the-views').each(function(){
					postIDs[i] = $(this).attr('id').replace('ajax-the-views-','');i++;
				});
				if (postIDs.length > 0) {
					var sjcJSON = '{';
					for (i=0; i<=postIDs.length-1; i++) {
						sjcJSON += '"'+i+'":"'+ postIDs[i] + '"';
						if (i<postIDs.length-1) {
							sjcJSON += ',';
						}
					}
					sjcJSON += '}';
					var ajax_the_views = sjcJSON;
					$.ajax({
						type: "GET",
						url: "<?php echo MWP_AJAX_ENDPOINT; ?>",
						dataType: 'json',
						data: ({ action: 'mwp_print_views_data', ajax_the_views:ajax_the_views}),
						success: function(data){
							for (i=0; i<=postIDs.length-1; i++) {
								jQuery('#ajax-the-views-'+postIDs[i]).text(data[i]);
							}
						}
					})
				}
			});
			</script>
			<?php
		endif;
	}
	add_action('wp_footer', 'ajax_the_views_footer', 99999);
endif;
/*
 * Bypass cache and get views count
 * when caching plugin is being used, but can't *display* the count. This fixes that
 *
*/
add_action(  MWP_AJAX_PREFIX . '_mwp_print_views_data', 'mwp_print_views_data' );
add_action(  MWP_AJAX_PREFIX . '_nopriv_mwp_print_views_data', 'mwp_print_views_data' );
function mwp_print_views_data() {
	foreach ($_GET as $key => $value) {
		$_GET[$key] = htmlentities(stripslashes($value), ENT_NOQUOTES);	
	}
	if (!isset($_GET['ajax_the_views'])) {
		return;
	}
	$atv_json_string = $_GET['ajax_the_views'];
	$atv_post_id_array = json_decode($atv_json_string,true);
	if (!is_array($atv_post_id_array)) {
		return;
	}
	$atv_views_options = get_option('views_options');

	foreach ($atv_post_id_array as $value) {
		if ( function_exists('the_views') ) {
			$atv_post_views = intval(get_post_meta($value, 'views', true));
			$atv_return_array[] = str_replace('%VIEW_COUNT%', number_format_i18n($atv_post_views), $atv_views_options['template']);
		} else {
			$atv_post_views = intval(get_post_meta( $value, 'jp_views', true ));
			$atv_return_array[] = $atv_post_views . __( ' views', MWP_TEXT_DOMAIN );
		}
	}
	echo json_encode($atv_return_array);
}
/*
 * Increment Post Views
 * when caching plugin is being used, the count will be updated
 *
*/
add_action(  MWP_AJAX_PREFIX . '_postviews', 'mwp_increment_views' );
add_action(  MWP_AJAX_PREFIX . '_nopriv_postviews', 'mwp_increment_views' );
function mwp_increment_views() {
	if( empty( $_GET['postviews_id'] ) )
		return;

	if( !defined( 'WP_CACHE' ) || !WP_CACHE )
		return;

	if ( function_exists('the_views') ) {
		
		$views_options = get_option( 'views_options' );
		if( isset( $views_options['use_ajax'] ) && intval( $views_options['use_ajax'] ) === 0 )
			return;
		
		$post_id = intval( $_GET['postviews_id'] );
		if( $post_id > 0 ) {
			$post_views = get_post_custom( $post_id );
			$post_views = intval( $post_views['views'][0] );
			update_post_meta( $post_id, 'views', ( $post_views + 1 ) );
			do_action( 'postviews_increment_views_ajax', ( $post_views + 1 ) );
			echo esc_html( $post_views + 1 );
			exit();
		} 
	} elseif ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'stats' ) ) {
		$post_id = intval( $_GET['postviews_id'] );
		if( $post_id > 0 ) {
			$count     = 0;
			$count_key = 'jp_views';
			$count     = (int) get_post_meta( $post_id, $count_key, true );
			update_post_meta( $post_id, $count_key, ( $count + 1 ) );
			echo esc_html( $count + 1 );
		}
		exit();
	}
}

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