/** * Retrieve and prepare the movies to display in the Widget. * * @since 1.0 * * @param int $limit How many movies to get * @param int $limit Offset to select movies * * @return array Requested Movies. */ private function widget_content($limit = null, $offset = 0) { global $wpdb; if (is_null($limit)) { $limit = $this->settings['movies_per_page']; } $args = array('posts_per_page' => $limit, 'offset' => $offset, 'post_type' => 'movie', 'order' => 'DESC', 'orderby' => 'post_date'); $movies = new WP_Query($args); if (!$movies->have_posts()) { return false; } foreach ($movies->posts as $movie) { $movie->meta = array('title' => apply_filters('the_title', wpmoly_get_movie_meta($movie->ID, 'title')), 'runtime' => apply_filters('wpmoly_format_movie_runtime', wpmoly_get_movie_meta($movie->ID, 'runtime')), 'release_date' => apply_filters('wpmoly_format_movie_release_date', wpmoly_get_movie_meta($movie->ID, 'release_date'), 'Y'), 'overview' => apply_filters('the_content', wpmoly_get_movie_meta($movie->ID, 'overview'))); $movie->rating = wpmoly_get_movie_meta($movie->ID, 'rating'); $movie->_rating = apply_filters('wpmoly_movie_rating_stars', $movie->rating); $movie->year = $movie->meta['release_date']; $movie->meta = json_encode($movie->meta); if (has_post_thumbnail($movie->ID)) { $movie->poster = wp_get_attachment_image_src(get_post_thumbnail_id($movie->ID), 'large'); $movie->poster = $movie->poster[0]; } else { $movie->poster = WPMOLY_DEFAULT_POSTER_URL; } $attachments = get_children($args = array('post_parent' => $movie->ID, 'post_type' => 'attachment')); if (!empty($attachments)) { shuffle($attachments); $movie->backdrop = wp_get_attachment_image_src($attachments[0]->ID, 'full'); $movie->backdrop = $movie->backdrop[0]; } else { $movie->backdrop = $movie->poster; } } return $movies->posts; }
/** * Get queued imported movies. * * Fetch all posts with 'import-queued' status and 'movie' post type * * @since 1.0 * * @return array Default movie values */ public static function get_queued_movies() { $columns = array(); $args = array('posts_per_page' => -1, 'post_type' => 'movie', 'post_status' => 'import-queued'); query_posts($args); if (have_posts()) { while (have_posts()) { the_post(); if ('import-queued' == get_post_status()) { $columns[get_the_ID()] = array('ID' => get_the_ID(), 'title' => get_the_title(), 'director' => wpmoly_get_movie_meta(get_the_ID(), 'director'), 'tmdb_id' => wpmoly_get_movie_meta(get_the_ID(), 'tmdb_id', true)); } } } return $columns; }
<?php if (has_post_thumbnail()) { the_post_thumbnail($size, array('class' => 'wpmoly grid movie poster')); } if ($title) { ?> <h4 class="wpmoly grid movie title"><?php the_title(); ?> </h4> <?php } if ($year) { ?> <span class="wpmoly grid movie year"><?php echo apply_filters('wpmoly_format_movie_release_date', wpmoly_get_movie_meta(get_the_ID(), 'release_date'), 'Y'); ?> </span> <?php } if ($rating) { ?> <span class="wpmoly grid movie rating"><?php echo apply_filters('wpmoly_movie_rating_stars', wpmoly_get_movie_rating(get_the_ID())); ?> </span> <?php } ?> </a> </div>
/** * Movie Metabox Meta Panel. * * Display a Metabox panel to download movie metadata. * * @since 2.0 * * @param int Current Post ID * * @return string Panel HTML Markup */ private static function render_meta_panel($post_id) { $metas = WPMOLY_Settings::get_supported_movie_meta(); $languages = WPMOLY_Settings::get_supported_languages(); $metadata = wpmoly_get_movie_meta($post_id); $metadata = wpmoly_filter_empty_array($metadata); $attributes = array('languages' => $languages, 'metas' => $metas, 'metadata' => $metadata); $panel = self::render_admin_template('metabox/panels/panel-meta.php', $attributes); return $panel; }
/** * Generate the content of the widget. * * @param array args The array of form elements * @param array instance The current instance of the widget */ public function widget_content($args, $instance) { $defaults = array('title' => __('Movies', 'wpmovielibrary'), 'description' => '', 'select' => 'date', 'select_status' => 'all', 'select_media' => 'all', 'select_rating' => 'all', 'select_meta' => 'all', 'release_date' => '', 'spoken_languages' => '', 'production_companies' => '', 'production_countries' => '', 'certification' => '', 'sort' => 'DESC', 'limit' => 4, 'show_poster' => 'normal', 'show_title' => 'no', 'show_rating' => 'starsntext', 'exclude_current' => 'no'); $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); extract($instance); $title = apply_filters('widget_title', $title); if ('no' != $show_poster) { $this->widget_css .= ' wpmoly-movies-with-thumbnail'; } if ('normal' == $show_poster) { $thumbnail = 'medium'; } else { $thumbnail = 'thumbnail'; } switch ($select) { case 'status': $_select = $instance["select_{$select}"]; $args = array('orderby' => 'post_date', 'meta_query' => array()); if ('all' != $_select) { $args['meta_query'][] = array('key' => "_wpmoly_movie_{$select}", 'value' => $_select, 'compare' => '='); } else { $args['meta_query'][] = array('key' => "_wpmoly_movie_{$select}", 'value' => '', 'compare' => '!='); } break; case 'media': $_select = $instance["select_{$select}"]; $args = array('orderby' => 'post_date', 'meta_query' => array()); if ('all' != $_select) { $args['meta_query'][] = array('key' => "_wpmoly_movie_{$select}", 'value' => $_select, 'compare' => 'LIKE'); } else { $args['meta_query'][] = array('key' => "_wpmoly_movie_{$select}", 'value' => '', 'compare' => 'NOT LIKE'); } break; case 'rating': $args = array('orderby' => 'meta_value_num', 'meta_key' => '_wpmoly_movie_rating'); if ('all' != $select_rating) { $args['meta_value'] = $select_rating; } break; case 'title': $args = array('orderby' => 'title'); break; case 'random': $args = array('orderby' => 'rand'); if (is_single() && $exclude_current) { global $post; $args['post__not_in'] = array($post->ID); } break; case 'meta': switch ($select_meta) { case 'release_date': case 'production_companies': case 'production_countries': case 'spoken_languages': case 'certification': $args = array('meta_query' => array(array('key' => "_wpmoly_movie_{$select_meta}", 'value' => $instance[$select_meta], 'compare' => 'LIKE'))); break; default: break; } break; case 'date': default: $args = array('orderby' => 'date'); break; } $args = array_merge(array('posts_per_page' => $limit, 'post_type' => 'movie', 'order' => $sort), $args); $movies = new WP_Query($args); if (empty($movies->posts)) { $html = WPMovieLibrary::render_template('empty.php', array('message' => __('Nothing to display.', 'wpmovielibrary')), $require = 'always'); return $before_widget . $before_title . $title . $after_title . $html . $after_widget; } $items = array(); foreach ($movies->posts as $movie) { $item = array('ID' => $movie->ID, 'attr_title' => sprintf(__('Permalink for « %s »', 'wpmovielibrary'), $movie->post_title), 'title' => $movie->post_title, 'link' => get_permalink($movie->ID), 'rating' => wpmoly_get_movie_meta($movie->ID, 'rating'), 'thumbnail' => get_the_post_thumbnail($movie->ID, $thumbnail)); $item['_rating'] = apply_filters('wpmoly_movie_rating_stars', $item['rating'], $movie->ID, $base = 5); $items[] = $item; } $attributes = array('items' => $items, 'description' => $description, 'show_rating' => $show_rating, 'show_title' => $show_title, 'show_poster' => $show_poster, 'style' => $this->widget_css); $html = WPMovieLibrary::render_template('movies-widget/movies.php', $attributes, $require = 'always'); return $before_widget . $before_title . $title . $after_title . $html . $after_widget; }
/** * Render Allocine styled Headbox 'Details' Tab. * * @since 2.1.4 * * @return string Headbox Tab HTML content */ private function render_details_tab() { $id = get_the_ID(); $overview = self::get_movie_meta($id, 'overview'); $tagline = self::get_movie_meta($id, 'tagline'); $details = wpmoly_get_movie_details(); $default_fields = WPMOLY_Settings::get_supported_movie_details(); foreach ($details as $slug => $detail) { if (!is_array($detail)) { $detail = array($detail); } if (isset($default_fields[$slug]['panel']) && 'custom' == $default_fields[$slug]['panel']) { unset($details[$slug]); } else { foreach ($detail as $i => $d) { if (!empty($d)) { if (isset($default_fields[$slug]['options'])) { $value = $default_fields[$slug]['options'][$d]; } else { $value = $d; } if ('rating' == $slug) { $d = apply_filters("wpmoly_movie_meta_link", array('key' => 'rating', 'value' => array_search($value, $default_fields[$slug]['options']), 'type' => 'detail', 'text' => $value)); } else { $d = apply_filters("wpmoly_movie_meta_link", array('key' => $slug, 'value' => $value, 'meta' => 'detail', 'text' => $value)); } $detail[$i] = apply_filters("wpmoly_format_movie_field", $d); } } $detail = implode(', ', $detail); if (empty($detail)) { $detail = apply_filters("wpmoly_format_movie_field", ''); } $title = ''; if (isset($default_fields[$slug])) { $title = __($default_fields[$slug]['title'], 'wpmovielibrary'); } $details[$slug] = array('slug' => $slug, 'title' => $title, 'value' => $detail); } } $metas = wpmoly_get_movie_meta(); $metas = wpmoly_filter_undimension_array($metas); $default_fields = WPMOLY_Settings::get_supported_movie_meta(); if (!empty($metas)) { unset($metas['title'], $metas['cast'], $metas['overview'], $metas['tagline']); foreach ($metas as $slug => $field) { if (isset($default_fields[$slug])) { // Custom filter if available if (has_filter("wpmoly_format_movie_{$slug}")) { $field = apply_filters("wpmoly_format_movie_{$slug}", $field); } // Filter empty field $field = apply_filters("wpmoly_format_movie_field", $field); $metas[$slug] = array('slug' => $slug, 'title' => __($default_fields[$slug]['title'], 'wpmovielibrary'), 'value' => $field); } else { unset($metas[$slug]); } } } $attributes = compact('id', 'overview', 'tagline', 'details', 'metas'); $content = self::render_template('movies/headbox-allocine/tabs/details.php', $attributes, $require = 'always'); return $content; }
/** * Generate current movie's metadata list. * * @since 1.0 * * @return null|string The current movie's metadata list */ public static function movie_metadata() { if ('nowhere' == wpmoly_o('show-meta') || 'posts_only' == wpmoly_o('show-meta') && !is_singular()) { return null; } $metadata = wpmoly_get_movie_meta(); $metadata = wpmoly_filter_undimension_array($metadata); $fields = wpmoly_o('sort-meta'); $default_fields = WPMOLY_Settings::get_supported_movie_meta(); if ('' == $metadata || empty($fields) || !isset($fields['used'])) { return null; } $fields = $fields['used']; if (isset($fields['placebo'])) { unset($fields['placebo']); } $items = array(); foreach ($fields as $slug => $field) { $_field = $metadata[$slug]; // Custom filter if available if (has_filter("wpmoly_format_movie_{$slug}")) { $_field = apply_filters("wpmoly_format_movie_{$slug}", $_field); } // Filter empty field $_field = apply_filters("wpmoly_format_movie_field", $_field); $fields[$slug] = $_field; $items[] = array('slug' => $slug, 'title' => __($default_fields[$slug]['title'], 'wpmovielibrary'), 'value' => $_field); } $html = WPMovieLibrary::render_template('movies/movie-metadata.php', array('items' => $items), $require = 'always'); return $html; }
/** * Modern headbox actors tab content callback. * * @since 2.0 * * @return string Tab content HTML markup */ public function get_wpmoly_headbox_actors_tab() { $actors = wpmoly_get_movie_meta(get_the_ID(), 'cast'); $actors = apply_filters('wpmoly_format_movie_actors', $actors); $attributes = array('actors' => $actors); $content = WPMovieLibrary::render_template('movies/headbox/tabs/actors.php', $attributes, $require = 'always'); return $content; }
/** * Prepare movies for Movies and Movie shortcodes. * * @since 1.1 * * @param object WP_Query object * @param acrray Shortcode attributes * * @return array Usable data for Shortcodes */ private static function prepare_movies($query, $atts) { if (!$query->have_posts()) { return array(); } extract($atts); $movies = array(); $default_fields = WPMOLY_Settings::get_supported_movie_meta(); while ($query->have_posts()) { $query->the_post(); $movies[$query->current_post] = array('id' => get_the_ID(), 'title' => get_the_title(), 'url' => get_permalink(), 'poster' => null, 'meta' => null, 'details' => null); if (!is_null($poster) && has_post_thumbnail(get_the_ID())) { $movies[$query->current_post]['poster'] = get_the_post_thumbnail(get_the_ID(), $poster); } /* * Meta are passed to the template as an array of values and titles * This gives more freedom to adapt the template */ if (!is_null($meta)) { if (!is_array($meta)) { $meta = array($meta); } $_meta = wpmoly_get_movie_meta(get_the_ID(), 'data'); $_meta = wpmoly_filter_undimension_array($_meta); $metadata = array(); foreach ($_meta as $slug => $m) { if (in_array($slug, $meta)) { $title = __($default_fields[$slug]['title'], 'wpmovielibrary'); $value = $_meta[$slug]; if (has_filter("wpmoly_format_movie_{$slug}")) { $value = apply_filters("wpmoly_format_movie_{$slug}", $value); } $value = apply_filters('wpmoly_format_movie_field', $value); $metadata[array_search($slug, $meta)] = array('title' => $title, 'value' => $value); } } ksort($metadata); $movies[$query->current_post]['meta'] = $metadata; } /* * Details are passed to the template as a string * This is simpler because formatting is already * done via filters */ if (!is_null($details)) { $movies[$query->current_post]['details'] = ''; if (!is_array($details)) { $details = array($details); } foreach ($details as $detail) { $value = call_user_func("wpmoly_get_movie_{$detail}", get_the_ID()); $movies[$query->current_post]['details'] .= apply_filters("wpmoly_format_movie_{$detail}", $value); } } } wp_reset_postdata(); return $movies; }