/** * 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) { extract($args, EXTR_SKIP); extract($instance); $count = (array) wp_count_posts('movie'); $count = array('movies' => $count['publish'], 'imported' => $count['import-draft'], 'queued' => $count['import-queued'], 'draft' => $count['draft'], 'total' => 0); $count['total'] = array_sum($count); $count['collections'] = wp_count_terms('collection'); $count['genres'] = wp_count_terms('genre'); $count['actors'] = wp_count_terms('actor'); $count = array_map('intval', $count); extract($count); $links = array(); $links['%total%'] = sprintf('<a href="%s">%s</a>', get_post_type_archive_link('movie'), sprintf(_n('<strong>1</strong> movie', '<strong>%d</strong> movies', $movies, 'wpmovielibrary'), $movies)); $links['%collections%'] = WPMOLY_Utils::get_taxonomy_permalink('collection', sprintf(_n('<strong>1</strong> collection', '<strong>%d</strong> collections', $collections, 'wpmovielibrary'), $collections)); $links['%genres%'] = WPMOLY_Utils::get_taxonomy_permalink('genre', sprintf(_n('<strong>1</strong> genre', '<strong>%d</strong> genres', $genres, 'wpmovielibrary'), $genres)); $links['%actors%'] = WPMOLY_Utils::get_taxonomy_permalink('actor', sprintf(_n('<strong>1</strong> actor', '<strong>%d</strong> actors', $actors, 'wpmovielibrary'), $actors)); $title = $before_title . apply_filters('widget_title', $title) . $after_title; $description = esc_attr($description); $format = wpautop(wp_kses($format, array('ul', 'ol', 'li', 'p', 'span', 'em', 'i', 'p', 'strong', 'b', 'br'))); $content = str_replace(array_keys($links), array_values($links), $format); $style = 'wpmoly-widget wpmoly-statistics'; $attributes = array('content' => $content, 'description' => $description, 'style' => $style); $html = WPMovieLibrary::render_template('statistics-widget/statistics.php', $attributes, $require = 'always'); return $before_widget . $title . $html . $after_widget; }
/** * Specifies the classname and description, instantiates the widget. No * stylesheets or JavaScript needed, localization loaded in public class. */ public function __construct() { $this->widget_name = __('WPMovieLibrary Movies', 'wpmovielibrary'); $this->widget_description = __('Display a list of movies from a specific taxonomy, media, status, rating…', 'wpmovielibrary'); $this->widget_css = 'wpmoly movies'; $this->widget_id = 'wpmovielibrary-movies-widget'; $this->widget_form = 'movies-widget/movies-admin.php'; $this->widget_params = array('title' => array('type' => 'text', 'std' => __('Movies', 'wpmovielibrary')), 'description' => array('type' => 'text', 'std' => ''), 'select' => array('type' => 'select', 'std' => 'date'), 'select_status' => array('type' => 'select', 'std' => 'all'), 'select_media' => array('type' => 'select', 'std' => 'all'), 'select_rating' => array('type' => 'select', 'std' => 'all'), 'select_meta' => array('type' => 'select', 'std' => 'all'), 'release_date' => array('type' => 'text', 'std' => ''), 'spoken_languages' => array('type' => 'text', 'std' => ''), 'production_companies' => array('type' => 'text', 'std' => ''), 'production_countries' => array('type' => 'text', 'std' => ''), 'certification' => array('type' => 'text', 'std' => ''), 'sort' => array('type' => 'select', 'std' => 'DESC'), 'limit' => array('type' => 'number', 'std' => 4), 'show_poster' => array('type' => 'select', 'std' => 'normal'), 'show_title' => array('type' => 'select', 'std' => 'no'), 'show_rating' => array('type' => 'select', 'std' => 'starsntext'), 'exclude_current' => array('type' => 'select', 'std' => 'no')); $this->movies_by = array('status' => __('Status', 'wpmovielibrary'), 'media' => __('Media', 'wpmovielibrary'), 'rating' => __('Rating', 'wpmovielibrary'), 'title' => __('Title', 'wpmovielibrary'), 'date' => __('Date', 'wpmovielibrary'), 'meta' => __('Metadata', 'wpmovielibrary'), 'random' => __('Random', 'wpmovielibrary')); $this->status = WPMOLY_Settings::get_available_movie_status(); $this->media = WPMOLY_Settings::get_available_movie_media(); $this->rating = WPMOLY_Settings::get_available_movie_rating(); $this->meta = array('release_date' => __('Release Date', 'wpmovielibrary'), 'production_companies' => __('Production', 'wpmovielibrary'), 'production_countries' => __('Country', 'wpmovielibrary'), 'spoken_languages' => __('Languages', 'wpmovielibrary'), 'certification' => __('Certification', 'wpmovielibrary')); $this->years = WPMOLY_Utils::get_used_years($count = true); $this->languages = WPMOLY_Utils::get_used_languages($count = true); $this->companies = WPMOLY_Utils::get_used_companies($count = true); $this->countries = WPMOLY_Utils::get_used_countries($count = true); $this->certifications = WPMOLY_Utils::get_used_certifications($count = true); parent::__construct(); }
/** * Render IMDb styled Headbox. * * @since 2.1.4 * * @param string $content The original post content * * @return string Filtered content */ public function render($content = null) { $theme = wp_get_theme(); if (!is_null($theme->stylesheet)) { $theme = 'theme-' . $theme->stylesheet; } else { $theme = ''; } if ('bottom' == wpmoly_o('headbox-position')) { $theme .= ' position-bottom'; } else { $theme .= ' position-top'; } $id = get_the_ID(); $meta = self::get_movie_meta($id, 'meta'); $details = self::get_movie_meta($id, 'details'); $poster = get_the_post_thumbnail($id, 'medium'); $images = $this->get_imdb_headbox_images($id); $collections = get_the_terms($id, 'collection'); if ($collections && !is_wp_error($collections)) { foreach ($collections as $i => $c) { $collections[$i] = $c->name; } } if (is_array($collections)) { $collections = implode(',', $collections); } $meta['collections'] = WPMOLY_Utils::format_movie_terms_list($collections, 'collection'); $meta['year'] = apply_filters('wpmoly_format_movie_year', $meta['release_date'], 'Y'); $meta['_year'] = date_i18n('Y', strtotime($meta['release_date'])); $meta['_runtime'] = $meta['runtime']; $_meta = array('title', 'director', 'writer', 'certification', 'runtime', 'genres', 'cast', 'release_date', 'overview', 'tagline', 'genres', 'homepage', 'production_countries', 'spoken_languages', 'budget', 'revenue', 'production_companies'); foreach ($_meta as $m) { $meta[$m] = apply_filters("wpmoly_format_movie_{$m}", $meta[$m]); } $details['rating_stars'] = apply_filters('wpmoly_movie_rating_stars', $details['rating'], $id, $base = 10); $attributes = compact('id', 'meta', 'details', 'poster', 'images', 'theme'); $content = WPMovieLibrary::render_template('movies/movie-imdb-headbox.php', $attributes, $require = 'always'); return $content; }
/** * Render WPMOLY Dashboard Page. * * Create a nice landing page for the plugin, displaying recent * movies and other stuff like a simple shortcut menu. * * @since 1.0 */ public static function dashboard() { $hidden = self::save_screen_options(); if (isset($_GET['hide_wpmoly_api_key_notice']) && (isset($_GET['_nonce']) || !wp_verify_nonce($_GET['_nonce'], 'hide-wpmoly-api-key-notice'))) { WPMovieLibrary_Admin::show_api_key_notice(); } if (isset($_GET['wpmoly_set_archive_page']) && (isset($_GET['_nonce']) || !wp_verify_nonce($_GET['_nonce'], 'wpmoly-set-archive-page'))) { WPMOLY_Utils::set_archive_page(); } global $wpmoly_dashboard_widgets; foreach ($wpmoly_dashboard_widgets as $widget) { self::add_dashboard_widget($widget); } echo self::render_admin_template('/dashboard/dashboard.php', array('screen' => get_current_screen(), 'hidden' => $hidden)); echo self::render_admin_template('/dashboard/movie-modal.php'); }
/** * Generate Movie Grid * * If a current letter is passed to the query use it to narrow * the list of movies. * * @since 2.0 * * @param array Shortcode arguments to use as parameters * @param boolean Are we actually doing a Shortcode? * * @return string HTML content */ public static function get_content($args = array(), $shortcode = false) { global $wpdb, $wp_query; $defaults = array('columns' => wpmoly_o('movie-archives-grid-columns', $default = true), 'rows' => wpmoly_o('movie-archives-grid-rows', $default = true), 'paged' => 1, 'category' => null, 'tag' => null, 'collection' => null, 'actor' => null, 'genre' => null, 'meta' => null, 'detail' => null, 'value' => null, 'title' => false, 'year' => false, 'rating' => false, 'letter' => null, 'order' => wpmoly_o('movie-archives-movies-order', $default = true), 'orderby' => 'post_title', 'view' => 'grid'); $args = wp_parse_args($args, $defaults); // Allow URL params to override Shortcode settings $_args = WPMOLY_Archives::parse_query_vars($wp_query->query); $args = wp_parse_args($_args, $args); // debug $main_args = $args; extract($args, EXTR_SKIP); $total = 0; $grid_meta = (array) wpmoly_o('movie-archives-movies-meta', $default = true); $grid_meta = array_keys($grid_meta['used']); $title = $title || in_array('title', $grid_meta); $rating = $rating || in_array('rating', $grid_meta); $year = $year || in_array('year', $grid_meta); $views = array('grid', 'archives', 'list'); if ('1' == wpmoly_o('rewrite-enable')) { $views = array('grid' => __('grid', 'wpmovielibrary'), 'archives' => __('archives', 'wpmovielibrary'), 'list' => __('list', 'wpmovielibrary')); } if (!isset($views[$view])) { $_view = array_search($view, $views); if (false != $_view) { $view = $_view; } else { $view = 'grid'; } } $movies = array(); $total = wp_count_posts('movie'); $total = $total->publish; $select = array('SQL_CALC_FOUND_ROWS DISTINCT ID'); // Limit the maximum number of terms to get $number = $columns * $rows; $limit = wpmoly_o('movie-archives-movies-limit', $default = true); if (-1 == $number) { $number = $limit; } $columns = min($columns, 8); if (0 > $columns) { $columns = wpmoly_o('movie-archives-grid-columns', $default = true); } $rows = min($rows, 12); if (0 > $rows) { $rows = wpmoly_o('movie-archives-grid-rows', $default = true); } // Calculate offset $offset = 0; if ($paged) { $offset = max(0, $number * ($paged - 1)); } if ('' == $meta && '' != $detail) { $meta = $detail; $type = 'detail'; } else { $type = 'meta'; } // Don't use LIMIT with weird values $limit = "LIMIT 0,{$number}"; if ($offset >= $number) { $limit = sprintf('LIMIT %d,%d', $offset, $number); } $where = array("post_type='movie'", " AND post_status='publish'"); if ('' != $letter) { $where[] = " AND post_title LIKE '" . wpmoly_esc_like($letter) . "%'"; } $join = array(); $meta_query = array('join' => array(), 'where' => array()); if ('' != $value && '' != $meta) { $meta_query = call_user_func("WPMOLY_Search::by_{$meta}", $value, 'sql'); $join[] = $meta_query['join']; $where[] = $meta_query['where']; } $tax_query = array(); if (!is_null($collection) && !empty($collection)) { $tax_query = array('taxonomy' => 'collection', 'terms' => $collection); } elseif (!is_null($genre) && !empty($genre)) { $tax_query = array('taxonomy' => 'genre', 'terms' => $genre); } elseif (!is_null($actor) && !empty($actor)) { $tax_query = array('taxonomy' => 'actor', 'terms' => $actor); } elseif (!is_null($category) && !empty($category)) { $tax_query = array('taxonomy' => 'category', 'terms' => $category); } elseif (!is_null($tag) && !empty($tag)) { $tax_query = array('taxonomy' => 'post_tag', 'terms' => $tag); } if (!empty($tax_query)) { $tax_query = array('relation' => 'OR', array('taxonomy' => $tax_query['taxonomy'], 'field' => 'slug', 'terms' => $tax_query['terms']), array('taxonomy' => $tax_query['taxonomy'], 'field' => 'name', 'terms' => $tax_query['terms'])); $tax_query = get_tax_sql($tax_query, $wpdb->posts, 'ID'); $join[] = $tax_query['join']; $where[] = $tax_query['where']; } $_orderby = array('year' => 'release_date', 'date' => 'release_date', 'localdate' => 'local_release_date', 'rating' => 'rating'); if (in_array($orderby, array_keys($_orderby))) { $select[] = ' pm.meta_value AS value'; $join[] = ' INNER JOIN wp_postmeta AS pm ON ( wp_posts.ID = pm.post_id )'; $where[] = ' AND pm.meta_key = "_wpmoly_movie_' . $_orderby[$orderby] . '"'; $orderby = 'value'; } elseif ('post_date' == $orderby) { $orderby = 'post_date'; } else { $orderby = 'post_title'; } $where = implode('', $where); $join = implode('', $join); $select = implode(',', $select); $query = "SELECT {$select} FROM {$wpdb->posts} {$join} WHERE {$where} ORDER BY {$orderby} {$order} {$limit}"; $movies = $wpdb->get_col($query); $total = $wpdb->get_var('SELECT FOUND_ROWS() AS total'); $movies = array_map('get_post', $movies); if ('list' == $view) { $movies = self::prepare_list_view($movies); } $baseurl = get_permalink(); /*if ( true === $shortcode ) { $baseurl = get_permalink(); } else { $baseurl = get_post_type_archive_link( 'movie' ); }*/ $args = array('order' => $order, 'columns' => $columns, 'rows' => $rows, 'letter' => $letter, 'value' => $value, $type => $meta, 'l10n' => false, 'view' => $view, 'baseurl' => $baseurl); $url = WPMOLY_Utils::build_meta_permalink($args); // debug $permalinks_args = $args; global $wp_rewrite; $format = '/page/%#%'; if ('' == $wp_rewrite->permalink_structure) { $format = '&paged=%#%'; } $args = array('type' => 'list', 'total' => ceil($total / $number), 'current' => max(1, $paged), 'format' => $url . $format); $paginate = WPMOLY_Utils::paginate_links($args); $paginate = '<div id="wpmoly-movies-pagination">' . $paginate . '</div>'; $theme = wp_get_theme(); if (!is_null($theme->stylesheet)) { $theme = ' theme-' . $theme->stylesheet; } else { $theme = ''; } // debug $debug = null; if (current_user_can('manage_options') && '1' == wpmoly_o('debug-mode')) { $debug = compact('main_args', 'permalinks_args'); } $attributes = compact('movies', 'columns', 'title', 'year', 'rating', 'theme', 'debug'); $content = self::render_template("movies/grid/{$view}-loop.php", $attributes, $require = 'always'); $content = $content . $paginate; return $content; }
/** * Update Widget settings when config form is posted. * * @since 1.0 */ private function update_settings() { wpmoly_check_admin_referer("save-{$this->widget_id}"); $settings = get_user_option($this->widget_id . '_settings'); $_settings = array(); foreach ($this->default_settings as $key => $value) { if (!isset($_POST[$this->widget_id][$key])) { $_settings[$key] = 0; } else { $_settings[$key] = $_POST[$this->widget_id][$key]; } } $settings = wp_parse_args($_settings, $settings); $update = update_user_option(get_current_user_id(), $this->widget_id . '_settings', $settings); if ($update) { WPMOLY_Utils::admin_notice(__('Settings saved.'), $type = 'update'); $this->settings = $settings; } }
/** * Generate the content of the widget. * * @since 1.2 * * @param array $args The array of form elements * @param array $instance The current instance of the widget * * @return string The Widget Content */ public function widget_content($args, $instance) { if (!in_array($instance['taxonomy'], array('collection', 'genre', 'actor'))) { return false; } $defaults = array('title' => __('Movie Taxonomies', 'wpmovielibrary'), 'description' => '', 'taxonomy' => '', 'list' => 0, 'count' => 0, 'orderby' => 'count', 'order' => 'DESC', 'css' => 0, 'limit' => WPMOLY_MAX_TAXONOMY_LIST); $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); extract($instance); $title = apply_filters('widget_title', $title); $archive = wpmoly_o("rewrite-{$taxonomy}"); if ('ASC' != $order) { $order = 'DESC'; } if ('name' != $orderby) { $orderby = 'count'; } $args = array("order={$order}", "orderby={$orderby}"); if (0 < $limit) { $args[] = "number={$limit}"; } $args = implode('&', $args); $taxonomies = get_terms(array($taxonomy), $args); if ($taxonomies && !is_wp_error($taxonomies)) { $items = array(); $this->widget_css .= " {$taxonomy} list"; if ($css) { $this->widget_css .= ' custom'; } foreach ($taxonomies as $term) { $items[] = array('attr_title' => sprintf(__('Permalink for « %s »', 'wpmovielibrary'), $term->name), 'link' => get_term_link(sanitize_term($term, $taxonomy), $taxonomy), 'title' => esc_attr($term->name . ($count ? sprintf(' (%d)', $term->count) : ''))); } if ($limit) { $url = WPMOLY_Utils::get_taxonomy_permalink($archive, $value = false); if ('' != $url) { $items[] = array('attr_title' => $this->taxonomies[$taxonomy]['view_all'], 'link' => $url, 'title' => __('View the complete list', 'wpmovielibrary')); } } $items = apply_filters('wpmoly_widget_collection_list', $items, $list, $css); $attributes = array('items' => $items, 'description' => $description, 'default_option' => $this->taxonomies[$taxonomy]['default'], 'style' => $this->widget_css); if ($list) { $html = WPMovieLibrary::render_template('taxonomies-widget/taxonomies-dropdown-list.php', $attributes, $require = 'always'); } else { $html = WPMovieLibrary::render_template('taxonomies-widget/taxonomies-list.php', $attributes, $require = 'always'); } } else { $html = WPMovieLibrary::render_template('empty.php', array('message' => $this->taxonomies[$taxonomy]['empty']), $require = 'always'); } return $before_widget . $before_title . $title . $after_title . $html . $after_widget; }
/** * Initializes variables * * @since 1.0 */ public function init() { $this->modules = array('WPMOLY_Dashboard' => WPMOLY_Dashboard::get_instance(), 'WPMOLY_Settings' => WPMOLY_Settings::get_instance(), 'WPMOLY_TMDb' => WPMOLY_TMDb::get_instance(), 'WPMOLY_Utils' => WPMOLY_Utils::get_instance(), 'WPMOLY_Metaboxes' => WPMOLY_Metaboxes::get_instance(), 'WPMOLY_Edit_Movies' => WPMOLY_Edit_Movies::get_instance(), 'WPMOLY_Media' => WPMOLY_Media::get_instance(), 'WPMOLY_Import' => WPMOLY_Import::get_instance(), 'WPMOLY_Queue' => WPMOLY_Queue::get_instance()); $this->screen_hooks = array('edit' => 'post.php', 'new' => 'post-new.php', 'movie' => 'movie', 'movies' => 'edit.php', 'widgets' => 'widgets.php', 'settings' => sprintf('%s_page_wpmovielibrary-settings', strtolower(__('Movies', 'wpmovielibrary')))); $this->hidden_pages = array(); }
/** * Format a Movie's casting for display * * Match each actor against the actor taxonomy to detect missing * terms. If term actor exists, provide a link, raw text value * if no matching term could be found. * * @since 1.1 * * @param string $data field value * * @return string Formatted output */ public static function format_movie_cast($data) { $output = WPMOLY_Utils::format_movie_terms_list($data, 'actor'); $output = self::format_movie_field($output); return $output; }
/** * Get configuration from TMDb * * @since 1.0 * * @return array TMDb result */ public function getConfiguration() { $config = WPMOLY_Cache::get('tmdb_api_config'); if (!$config) { $config = $this->_makeCall('configuration'); if (is_wp_error($config)) { if (defined('DOING_AJAX') && DOING_AJAX) { return $config; } WPMOLY_Utils::admin_notice($config->get_error_message(), 'error'); return array(); } if (!empty($config)) { $this->_config = $config; } WPMOLY_Cache::set('tmdb_api_config', $config); } return $config; }
/** * Generate the content of the widget. * * @since 1.2 * * @param array $args The array of form elements * @param array $instance The current instance of the widget * * @return string The Widget Content */ public function widget_content($args, $instance) { $defaults = array('title' => __('Movie Details', 'wpmovielibrary'), 'description' => '', 'detail' => '', 'list' => 0, 'css' => 0); $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); extract($instance); $title = apply_filters('widget_title', $title); $details = call_user_func("WPMOLY_Settings::get_available_movie_{$detail}"); $rewrite = wpmoly_o('rewrite-details'); $movies = wpmoly_o('rewrite-movie'); if (!empty($details)) { $baseurl = trailingslashit(get_post_type_archive_link('movie')); $this->widget_css .= " wpmoly {$detail}"; if ($css) { $this->widget_css .= ' list custom'; } $items = array(); foreach ($details as $slug => $_title) { $item = array('attr_title' => sprintf(__('Permalink for « %s »', 'wpmovielibrary'), __($_title, 'wpmovielibrary')), 'link' => WPMOLY_Utils::get_meta_permalink(array('key' => $detail, 'value' => $slug, 'type' => 'detail', 'format' => 'raw', 'baseurl' => $baseurl))); if ('rating' != $detail) { $item['title'] = __($_title, 'wpmovielibrary'); } else { if ('rating' == $detail && $list) { $item['title'] = esc_attr__($_title, 'wpmovielibrary') . ' (' . $slug . '★)'; } else { $item['title'] = '<div class="movie-rating-display">' . apply_filters('wpmoly_movie_rating_stars', $slug, null, null, true) . '<span class="rating-label">' . esc_attr__($_title, 'wpmovielibrary') . '</span></div>'; } } $items[] = $item; } $attributes = array('items' => $items, 'description' => $description, 'default_option' => $this->details[$detail]['default'], 'style' => $this->widget_css); if ($list) { $html = WPMovieLibrary::render_template('details-widget/details-dropdown-list.php', $attributes, $require = 'always'); } else { $html = WPMovieLibrary::render_template('details-widget/details-list.php', $attributes, $require = 'always'); } } else { $html = WPMovieLibrary::render_template('empty.php', array('message' => __('No detail no show', 'wpmovielibrary')), $require = 'always'); } return $before_widget . $before_title . $title . $after_title . $html . $after_widget; }
/** * Render Allocine styled Headbox 'Overview' Tab. * * @since 2.1.4 * * @return string Headbox Tab HTML content */ private function render_main_tab() { $id = get_the_ID(); $poster = get_the_post_thumbnail($id, 'medium'); $images = get_posts(array('post_type' => 'attachment', 'orderby' => 'title', 'numberposts' => 5, 'post_status' => null, 'post_parent' => $id, 'meta_key' => '_wpmoly_image_related_tmdb_id', 'exclude' => get_post_thumbnail_id($id))); if ($images) { foreach ($images as $i => $image) { $images[$i] = array('thumbnail' => wp_get_attachment_image_src($image->ID, 'thumbnail'), 'full' => wp_get_attachment_image_src($image->ID, 'full')); } $images = WPMovieLibrary::render_template('shortcodes/images.php', array('size' => 'thumbnail', 'movie_id' => $id, 'images' => $images), $require = 'always'); } $collections = get_the_terms($id, 'collection'); if ($collections && !is_wp_error($collections)) { foreach ($collections as $i => $c) { $collections[$i] = $c->name; } } if (is_array($collections)) { $collections = implode(',', $collections); } $meta = array(); $_meta = array('title', 'director', 'composer', 'writer', 'local_release_date', 'runtime', 'genres', 'overview', 'production_countries', 'spoken_languages', 'budget', 'revenue'); foreach ($_meta as $m) { $meta[$m] = apply_filters("wpmoly_format_movie_{$m}", self::get_movie_meta($id, $m)); } $meta['collections'] = WPMOLY_Utils::format_movie_terms_list($collections, 'collection'); $meta['release_date'] = self::get_movie_meta($id, 'release_date'); $meta['year'] = apply_filters('wpmoly_format_movie_year', $meta['release_date'], 'Y'); $meta['release_date'] = apply_filters('wpmoly_format_movie_release_date', $meta['release_date']); $meta = array_map('WPMOLY_Formatting_Meta::format_movie_field', $meta); $meta['cast'] = self::get_movie_meta($id, 'cast'); $casting = $meta['cast']; $meta['cast'] = array_slice(explode(', ', $meta['cast']), 0, 3); $meta['cast'] = implode(', ', $meta['cast']); $meta['cast'] = apply_filters('wpmoly_format_movie_cast', $meta['cast']); $casting = apply_filters('wpmoly_format_movie_cast', $casting); $casting = array_slice(explode(', ', $casting), 0, 4); $rating = apply_filters('wpmoly_movie_rating_stars', self::get_movie_meta($id, 'rating'), $id, $base = 10); if (empty($images)) { $images = sprintf(__('No image to show for %s', 'wpmovielibrary'), '<em>' . $meta['title'] . '</em>'); } $attributes = compact('id', 'meta', 'rating', 'casting', 'poster', 'images'); $content = self::render_template('movies/headbox-allocine/tabs/overview.php', $attributes, $require = 'always'); return $content; }
/** * Generate Custom Taxonome Archives pages menu. * * Similar to the version 2.0 grid shortcode, this generated a * double menu: alphabetical selection of taxonomies, and basic * sorting menu including asc/descending alphabetical/numeric * sorting, number limitation and pagination. * * @since 2.1 * * @param string $taxonomy Taxonomy type: collection, genre or actor * @param array $args Taxonomy Menu arguments * * @return string HTML content */ public static function taxonomy_archive_menu($taxonomy, $args) { global $wpdb; $defaults = array('letter' => '', 'order' => wpmoly_o('tax-archives-terms-order', $default = true), 'orderby' => wpmoly_o('tax-archives-terms-orderby', $default = true), 'number' => wpmoly_o('tax-archives-terms-per-page', $default = true), 'editable' => wpmoly_o('tax-archives-frontend-edit', $default = true)); $args = wp_parse_args($args, $defaults); extract($args); $default = str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $letters = array(); $result = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT LEFT(t.name, 1) as letter\n\t\t\t\t\t FROM {$wpdb->terms} AS t\n\t\t\t\t\t INNER JOIN {$wpdb->term_taxonomy} AS tt\n\t\t\t\t\t ON t.term_id = tt.term_id\n\t\t\t\t\t WHERE tt.taxonomy = %s\n\t\t\t\t\t ORDER BY t.name ASC", $taxonomy)); foreach ($result as $r) { $letters[] = $r->letter; } $baseurl = get_permalink(); $is_tax = $taxonomy; $args = compact('order', 'orderby', 'number', 'baseurl', 'is_tax'); $attributes = compact('letters', 'default', 'letter', 'order', 'orderby', 'number', 'letter_url', 'default_url', 'editable'); $urls = array(); $urls['all'] = WPMOLY_Utils::build_meta_permalink($args); $args['order'] = $order; $args['letter'] = '{letter}'; $urls['letter'] = WPMOLY_Utils::build_meta_permalink($args); $args['letter'] = $letter; $args['order'] = 'ASC'; $args['orderby'] = 'count'; $urls['count_asc'] = WPMOLY_Utils::build_meta_permalink($args); $args['orderby'] = 'title'; $urls['title_asc'] = WPMOLY_Utils::build_meta_permalink($args); $args['order'] = 'DESC'; $args['orderby'] = 'count'; $urls['count_desc'] = WPMOLY_Utils::build_meta_permalink($args); $args['orderby'] = 'title'; $urls['title_desc'] = WPMOLY_Utils::build_meta_permalink($args); $attributes['urls'] = $urls; $content = self::render_template('archives/menu.php', $attributes, $require = 'always'); return $content; }
/** * Render movie import page * * @since 1.0 */ public static function import_page() { $errors = new WP_Error(); $imported = array(); $_section = ''; $movies = (array) wp_count_posts('movie'); $_imported = $movies['import-draft']; $_queued = $movies['import-queued']; if (isset($_POST['wpmoly_save_imported']) && '' != $_POST['wpmoly_save_imported'] && isset($_POST['wpmoly_imported_ids']) && '' != $_POST['wpmoly_imported_ids'] && isset($_POST['movies']) && count($_POST['movies'])) { wpmoly_check_admin_referer('save-imported-movies'); $post_ids = explode(',', $_POST['wpmoly_imported_ids']); foreach ($_POST['movies'] as $movie) { if (0 != $movie['tmdb_id'] && in_array($movie['post_id'], $post_ids)) { $update = WPMOLY_Edit_Movies::save_movie($movie['post_id'], $post = null, $queue = false, $movie); if (is_wp_error($update)) { $errors->add($update->get_error_code(), $update->get_error_message()); } else { $imported[] = $update; } } } if (!empty($errors->errors)) { $_errors = array(); foreach ($errors->errors as $error) { if (is_array($error)) { foreach ($error as $e) { $_errors[] = '<li>' . $e . '</li>'; } } else { $_errors[] = '<li>' . $error . '</li>'; } } WPMOLY_Utils::admin_notice(sprintf(__('The following errors occured: <ul>%s</ul>', 'wpmovielibrary'), implode('', $_errors)), 'error'); } if (!empty($imported)) { WPMOLY_Utils::admin_notice(sprintf(_n('One movie imported successfully!', '%d movies imported successfully!', count($imported), 'wpmovielibrary'), count($imported)), 'updated'); } } else { if (isset($_POST['wpmoly_importer']) && '' != $_POST['wpmoly_importer']) { } } if (isset($_GET['wpmoly_section']) && in_array($_GET['wpmoly_section'], array('wpmoly_import', 'wpmoly_import_queue', 'wpmoly_imported'))) { $_section = $_GET['wpmoly_section']; } $attributes = array('_section' => $_section, '_queued' => $_queued, '_imported' => $_imported); echo self::render_admin_template('/import/import.php', $attributes); }
/** * Set the uninstallation instructions * * @since 1.0 */ private static function _uninstall() { WPMOLY_Utils::uninstall(); WPMOLY_Movies::uninstall(); WPMOLY_Collections::uninstall(); WPMOLY_Genres::uninstall(); WPMOLY_Actors::uninstall(); WPMOLY_Settings::uninstall(); }
/** * Movies shortcode. Display a list of movies with various sorting * and display options. * * @since 1.1 * * @param array Shortcode attributes * @param string Shortcode content * * @return string Shortcode display */ public static function movies_shortcode($atts = array(), $content = null) { $default_fields = WPMOLY_Settings::get_supported_movie_meta(); $atts = self::filter_shortcode_atts('movies', $atts); // Caching $name = apply_filters('wpmoly_cache_name', 'movies_shortcode', $atts); $content = WPMOLY_Cache::output($name, function () use($atts, $content) { extract($atts); $query = array('post_type=movie', 'post_status=publish', 'posts_per_page=' . $count); $_page = intval(get_query_var('_page')); if ($paginate && $_page) { $query[] = 'paged=' . $_page; } else { $query[] = 'paged=0'; } if (!is_null($order)) { $query[] = 'order=' . $order; } if (!is_null($orderby)) { if ('rating' == $orderby) { $query[] = 'orderby=meta_value_num'; $query[] = 'meta_key=_wpmoly_movie_rating'; } else { $query[] = 'orderby=' . $orderby; } } if (!is_null($collection)) { $query[] = 'collection=' . $collection; } elseif (!is_null($genre)) { $query[] = 'genre=' . $genre; } elseif (!is_null($actor)) { $query[] = 'actor=' . $actor; } $query = implode('&', $query); $query = new WP_Query($query); if ('none' == $atts['poster']) { $atts['poster'] = null; } $movies = WPMOLY_Shortcodes::prepare_movies($query, $atts); $attributes = array('movies' => $movies); $format[] = '_page=%#%'; $args = array('type' => 'list', 'total' => ceil($query->found_posts / $count), 'current' => max(1, $_page), 'format' => sprintf('%s?%s', get_permalink(), implode('&', $format))); $paginate = WPMOLY_Utils::paginate_links($args); $paginate = '<div id="wpmoly-movies-pagination">' . $paginate . '</div>'; $content = WPMovieLibrary::render_template('shortcodes/movies.php', $attributes, $require = 'always'); $content = $content . $paginate; return $content; }, $echo = false); return $content; }