Exemplo n.º 1
0
function vh_load_movies_list()
{
    $cat_id = sanitize_text_field($_POST['cat']);
    $theatre = sanitize_text_field($_POST['theatres']);
    $post_date = sanitize_text_field($_POST['date']);
    $sorting = sanitize_text_field($_POST['sorting']);
    $show_all = sanitize_text_field($_POST['list_all_events']);
    global $post;
    $output = '<script type="text/javascript">
	var $container = jQuery("#movies_list_content .event_container").isotope({
		layoutMode: "fitRows",
		transformsEnabled: true,
			getSortData: {
				popularity : function ( $elem ) {
					return parseInt($elem.find(".event_list_rating").text());
				},
				release : function ( $elem ) {
					
					var release_val = $elem.find(".info.event_release").text();
					if ( release_val == "" ) {
						release_val = "January 1, 1970";
					}
					return Date.parse(release_val);
				},
				comments : function ( $elem ) {
					return parseInt( $elem.find(".comments").text());
				}
			},
			sortBy: "' . $sorting . '",
			sortAscending: false,
			animationOptions: {
				duration: 250,
				easing: "swing",
				queue: true
			},
			animationEngine : "jquery"
	});
	jQuery(".wrapper-dropdown-6 .dropdown li").click(function(e) {
		var sortValue = jQuery(this).find("input[type=hidden]").attr("data-sort-value");
			$container.isotope({
				sortBy: sortValue,
				sortAscending: false
			});
	});

	jQuery( ".event_list.isotope-item .movie_list_image" ).mouseenter(function() {
		jQuery(this).find(".bottom_line").show().animate({
			width: "100%",
			left: "0%", 
		}, 300, function() {
			// Animation complete.
		 });
	});

	jQuery( ".event_list.isotope-item .movie_list_image" ).mouseleave(function() {
		jQuery(this).find(".bottom_line").show().animate({
			width: "0%",
			left: "50%", 
		}, 300, function() {
			// Animation complete.
		 });
	});

	jQuery(document).ajaxComplete(function() {
		var main = 0;
		var sidebar_height = 0;
		var sidebar = "";
		if ( jQuery(".page-wrapper").hasClass("page-sidebar-right") ) {
			sidebar_height = jQuery(".sidebar-right").height();
			sidebar = jQuery(".sidebar-right");
			main = jQuery(".sidebar-right-pull").height();
		} else {
			sidebar_height = jQuery(".sidebar-left").height();
			sidebar = jQuery(".sidebar-left");
			main = jQuery(".sidebar-left-pull").height();
		};

		if ( jQuery(window).width() > 750 && main > sidebar.height() ) {
			sidebar.height(main);
		} else {
			sidebar.height("auto");
		}
	});
	</script>';
    if ($post_date == '' || $post_date == 'NaN.NaN.NaN') {
        $post_date = date('m.d.Y');
    }
    $current_date = explode(".", $post_date);
    if ($show_all == '1') {
        $args = array('numberposts' => -1, 'post_type' => 'movies', 'event_categories' => $cat_id, 'posts_per_page' => -1);
    } else {
        $args = array('numberposts' => -1, 'posts_per_page' => -1, 'post_type' => 'movies', 'event_categories' => $cat_id, 'meta_query' => array(array('key' => 'movie_time_values', 'value' => $post_date, 'compare' => 'LIKE')));
    }
    $the_query = new WP_Query($args);
    if ($the_query->have_posts()) {
        $output .= '<ul class="event_container">';
        while ($the_query->have_posts()) {
            $the_query->the_post();
            try {
                $dt = new DateTime('', new DateTimeZone(get_option('timezone_string')));
            } catch (Exception $e) {
                if (strlen($e->getMessage()) > 1) {
                    $dt = new DateTime('', new DateTimeZone('UTC'));
                }
            }
            $now = strtotime($dt->format('H:00'));
            $now = date('H:00', $now);
            $values = trim(get_post_meta(get_post()->ID, 'movie_time_values', true), ',');
            $values_arr = json_decode('{"events":[' . $values . ']}', true);
            foreach ($values_arr as $value) {
                foreach ($value as $info) {
                    $movie_date = explode(".", $info['date']);
                    if ($post_date != '' && (strtotime($movie_date["2"] . "-" . $movie_date["0"] . "-" . $movie_date["1"]) == strtotime($current_date["2"] . "-" . $current_date["0"] . "-" . $current_date["1"]) && $show_all != '1' || strtotime($movie_date["2"] . "-" . $movie_date["0"] . "-" . $movie_date["1"]) >= strtotime($current_date["2"] . "-" . $current_date["0"] . "-" . $current_date["1"]) && $show_all == '1')) {
                        if ($theatre == '') {
                            $output .= '<li class="event_list vc_span12" id="post-' . get_the_ID() . '">';
                            $output .= '<div class="movie_list_image shadows">';
                            $output .= '<div class="bottom_line"></div>';
                            if (kd_mfi_get_featured_image_id('event-poster', 'movies') != '') {
                                $attachment_id = kd_mfi_get_featured_image_id('event-poster', 'movies');
                                $image = wp_get_attachment_image_src($attachment_id, 'movie_list');
                                $output .= '<a href="' . get_permalink(get_the_ID()) . '"><img src="' . $image[0] . '"></a>';
                            } elseif (has_post_thumbnail(get_post()->ID)) {
                                $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_post()->ID), 'movie_list');
                                $output .= '<a href="' . get_permalink(get_the_ID()) . '"><img src="' . $image[0] . '"></a>';
                            }
                            $output .= '</div>';
                            $output .= '<div class="movie_list_container">';
                            $output .= '<div class="movie_title"><a href="' . get_permalink(get_the_ID()) . '">' . get_the_title() . '</a></div>';
                            if (function_exists('the_ratings')) {
                                $rating_images = substr_replace(the_ratings_results($post->ID), '', strlen(the_ratings_results($post->ID)) - 5);
                                $rating_value = number_format(floatval(substr(the_ratings_results(get_the_ID()), strlen(the_ratings_results(get_the_ID())) - 5)), 1);
                                if ($rating_value < 10) {
                                    $rating_value = ' ' . $rating_value;
                                }
                                $output .= '<div class="event_list_rating">' . $rating_images . $rating_value . '</div>';
                            }
                            $tc = wp_count_comments(get_the_ID());
                            $output .= '<span class="comments icon-comment">' . $tc->total_comments . '</span>';
                            $output .= '<div class="overview-container">
															<div class="main_side_left">';
                            $categories = wp_get_post_terms(get_the_ID(), 'event_categories', array("fields" => "names"));
                            $categories_count = count($categories);
                            $categories_val = 1;
                            $categories_string = '';
                            foreach ($categories as $value) {
                                if ($categories_val == $categories_count) {
                                    $categories_string = $categories_string . $value;
                                } else {
                                    $categories_string = $categories_string . $value . ', ';
                                }
                                $categories_val++;
                            }
                            if ($categories_string != '') {
                                $output .= '<div class="event_list_item icon-tags"><div class="title left">' . __('Category:', 'vh') . '</div><div class="info event_category">' . $categories_string . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'event_release', true) != '') {
                                $output .= '<div class="event_list_item icon-calendar"><div class="title left">' . __('Release date:', 'vh') . '</div><div class="info event_release">' . get_post_meta(get_the_ID(), 'event_release', true) . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'movies_length', true) != '') {
                                $output .= '<div class="event_list_item icon-clock"><div class="title left">' . __('Duration:', 'vh') . '</div><div class="info movies_length">' . vh_convertToHoursMins(get_post_meta(get_the_ID(), 'movies_length', true), __('%2d hours %2d minutes', "vh")) . '</div><div class="clearfix"></div></div>';
                            }
                            $output .= '</div>
											<div class="main_side_right">';
                            if (get_post_meta(get_the_ID(), 'event_director', true) != '') {
                                $output .= '<div class="event_list_item icon-user"><div class="title right">' . __('Director:', 'vh') . '</div><div class="info event_director">' . get_post_meta(get_the_ID(), 'event_director', true) . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'event_actors', true) != '') {
                                $output .= '<div class="event_list_item icon-users"><div class="title right">' . __('Actors:', 'vh') . '</div><div class="info event_actors">' . get_post_meta(get_the_ID(), 'event_actors', true) . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'event_box_office', true) != '') {
                                $output .= '<div class="event_list_item icon-dollar"><div class="title right">' . __('Box Office:', 'vh') . '</div><div class="info event_box_office">' . get_post_meta(get_the_ID(), 'event_box_office', true) . '</div><div class="clearfix"></div></div>';
                            }
                            $output .= '</div>
											<div class="clearfix"></div>
											</div><!--end of overview-container-->';
                            $output .= '<div class="event_buttons">';
                            $output .= '<div class="button_red"><a href="' . get_permalink(get_the_ID()) . '#tickets' . '" class="vh_button red icon-ticket hover_right">' . __('Buy tickets', 'vh') . '</a></div>';
                            $youtube = explode('=', get_post_meta(get_the_ID(), 'event_trailer', true));
                            if ($youtube[0] != '') {
                                if ($youtube[0] != '') {
                                    $youtube_url = $youtube['1'];
                                } else {
                                    $youtube_url = '';
                                }
                                $output .= '<div class="button_yellow"><a href="#" class="vh_button yellow icon-play-1 hover_right">' . __('Watch trailer', 'vh') . '</a><input type="hidden" value="' . $youtube_url . '"></input></div>';
                            }
                            $output .= '</div>';
                            $output .= '</div>';
                            $output .= '</li>';
                            break;
                        } elseif ($info['theatre'] == $theatre) {
                            $output .= '<li class="vc_span12" id="post-' . get_the_ID() . '">';
                            $output .= '<div class="movie_list_image shadows">';
                            $output .= '<div class="bottom_line"></div>';
                            if (kd_mfi_get_featured_image_id('event-poster', 'movies') != '') {
                                $attachment_id = kd_mfi_get_featured_image_id('event-poster', 'movies');
                                $image = wp_get_attachment_image_src($attachment_id, 'movie_list');
                                $output .= '<a href="' . get_permalink(get_the_ID()) . '"><img src="' . $image[0] . '"></a>';
                            } elseif (has_post_thumbnail(get_post()->ID)) {
                                $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_post()->ID), 'movie_list');
                                $output .= '<a href="' . get_permalink(get_the_ID()) . '"><img src="' . $image[0] . '"></a>';
                            }
                            $output .= '</div>';
                            $output .= '<div class="movie_list_container">';
                            $output .= '<div class="movie_title"><a href="' . get_permalink(get_the_ID()) . '">' . get_the_title() . '</a></div>';
                            if (function_exists('the_ratings')) {
                                $rating_images = substr_replace(the_ratings_results($post->ID), '', strlen(the_ratings_results($post->ID)) - 5);
                                $rating_value = number_format(floatval(substr(the_ratings_results(get_the_ID()), strlen(the_ratings_results(get_the_ID())) - 5)), 1);
                                if ($rating_value < 10) {
                                    $rating_value = ' ' . $rating_value;
                                }
                                $output .= '<div class="event_list_rating">' . $rating_images . $rating_value . '</div>';
                            }
                            $tc = wp_count_comments(get_the_ID());
                            $output .= '<span class="comments icon-comment">' . $tc->total_comments . '</span>';
                            $output .= '<div class="overview-container">
															<div class="main_side_left">';
                            $categories = wp_get_post_terms(get_the_ID(), 'event_categories', array("fields" => "names"));
                            $categories_count = count($categories);
                            $categories_val = 1;
                            $categories_string = '';
                            foreach ($categories as $value) {
                                if ($categories_val == $categories_count) {
                                    $categories_string = $categories_string . $value;
                                } else {
                                    $categories_string = $categories_string . $value . ', ';
                                }
                                $categories_val++;
                            }
                            if ($categories_string != '') {
                                $output .= '<div class="event_list_item icon-tags"><div class="title left">' . __('Category:', 'vh') . '</div><div class="info event_category">' . $categories_string . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'event_release', true) != '') {
                                $output .= '<div class="event_list_item icon-calendar"><div class="title left">' . __('Release date:', 'vh') . '</div><div class="info event_release">' . get_post_meta(get_the_ID(), 'event_release', true) . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'movies_length', true) != '') {
                                $output .= '<div class="event_list_item icon-clock"><div class="title left">' . __('Duration:', 'vh') . '</div><div class="info movies_length">' . vh_convertToHoursMins(get_post_meta(get_the_ID(), 'movies_length', true), __('%2d hours %2d minutes', "vh")) . '</div><div class="clearfix"></div></div>';
                            }
                            $output .= '</div>
											<div class="main_side_right">';
                            if (get_post_meta(get_the_ID(), 'event_director', true) != '') {
                                $output .= '<div class="event_list_item icon-user"><div class="title right">' . __('Director:', 'vh') . '</div><div class="info event_director">' . get_post_meta(get_the_ID(), 'event_director', true) . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'event_actors', true) != '') {
                                $output .= '<div class="event_list_item icon-users"><div class="title right">' . __('Actors:', 'vh') . '</div><div class="info event_actors">' . get_post_meta(get_the_ID(), 'event_actors', true) . '</div><div class="clearfix"></div></div>';
                            }
                            if (get_post_meta(get_the_ID(), 'event_box_office', true) != '') {
                                $output .= '<div class="event_list_item icon-dollar"><div class="title right">' . __('Box Office:', 'vh') . '</div><div class="info event_box_office">' . get_post_meta(get_the_ID(), 'event_box_office', true) . '</div><div class="clearfix"></div></div>';
                            }
                            $output .= '</div>
											<div class="clearfix"></div>
											</div><!--end of overview-container-->';
                            $output .= '<div class="event_buttons">';
                            $output .= '<div class="button_red"><a href="' . get_permalink(get_the_ID()) . '#tickets' . '" class="vh_button red icon-ticket hover_right">' . __('Buy tickets', 'vh') . '</a></div>';
                            $youtube = explode('=', get_post_meta(get_the_ID(), 'event_trailer', true));
                            if ($youtube[0] != '') {
                                if ($youtube[0] != '') {
                                    $youtube_url = $youtube['1'];
                                } else {
                                    $youtube_url = '';
                                }
                                $output .= '<div class="button_yellow"><a href="#" class="vh_button yellow icon-play-1 hover_right">' . __('Watch trailer', 'vh') . '</a><input type="hidden" value="' . $youtube_url . '"></input></div>';
                            }
                            $output .= '</div>';
                            $output .= '</div>';
                            $output .= '</li>';
                            break;
                        }
                    }
                }
            }
        }
        $output .= '</ul>';
    }
    echo $output;
    wp_reset_query();
    die(1);
}
    ?>
</div><div class="info event_release"><?php 
    echo get_post_meta(get_the_ID(), 'event_release', true);
    ?>
</div><div class="clearfix"></div></div>
							<?php 
}
?>
							<?php 
if (get_post_meta(get_the_ID(), 'movies_length', true) != '') {
    ?>
								<div class="event_list_item icon-clock"><div class="title left"><?php 
    _e('Duration:', 'vh');
    ?>
</div><div class="info movies_length"><?php 
    echo vh_convertToHoursMins(get_post_meta(get_the_ID(), 'movies_length', true), __('%2d hours %2d minutes', "vh"));
    ?>
</div><div class="clearfix"></div></div>
							<?php 
}
?>
							<?php 
if (get_post_meta(get_the_ID(), 'event_writers', true) != '') {
    ?>
								<div class="event_list_item icon-pencil"><div class="title right"><?php 
    _e('Writers:', 'vh');
    ?>
</div><div class="info event_writers"><?php 
    echo get_post_meta(get_the_ID(), 'event_writers', true);
    ?>
</div><div class="clearfix"></div></div>