/**
  * 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 &laquo; %s &raquo;', 'wpmovielibrary'), $term->name), 'link' => get_term_link(sanitize_term($term, $taxonomy), $taxonomy), 'title' => esc_attr($term->name . ($count ? sprintf('&nbsp;(%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;
 }
 /**
  * Register a 'Genre' custom taxonomy to aggregate movies.
  * 
  * Genres are Tag-like taxonomies: not-hierarchical, tagcloud,
  * showing in admin columns.
  * 
  * @see wpmoly_movies_columns_head()
  * @see wpmoly_movies_columns_content()
  *
  * @since    1.0
  */
 public function register_genre_taxonomy()
 {
     $taxonomy = 'genre';
     $object_type = array('movie');
     $slug = 'genre';
     if ('1' == wpmoly_o('rewrite-enable')) {
         $rewrite = wpmoly_o('rewrite-genre');
         if ('' != $slug) {
             $slug = $rewrite;
         }
     }
     if (wpmoly_o('genre-posts')) {
         $object_type[] = 'post';
     }
     $args = array('labels' => array('name' => __('Genres', 'wpmovielibrary'), 'add_new_item' => __('New Genre', 'wpmovielibrary')), 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => false, 'query_var' => true, 'sort' => true, 'rewrite' => array('slug' => $slug));
     register_taxonomy($taxonomy, $object_type, $args);
 }
 /**
  * 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 &laquo; %s &raquo;', '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 . '&#9733;)';
                 } 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 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 Allocine styled Headbox.
  *
  * @since    2.1.4
  * 
  * @param    string    $content The original post content
  *
  * @return   string    Filtered content
  */
 public function render($content = null)
 {
     $this->init();
     $id = get_the_ID();
     $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';
     }
     $title = apply_filters('wpmoly_format_movie_title', self::get_movie_meta($id, 'title'));
     $menu = $this->render_menu();
     $tabs = $this->render_tabs();
     $attributes = compact('id', 'theme', 'title', 'menu', 'tabs');
     $content = self::render_template('movies/movie-allocine-headbox.php', $attributes, $require = 'always');
     return $content;
 }
 /**
  * Movie Rating shortcode.
  *
  * @since    2.1.4
  * 
  * @param    array     Shortcode attributes
  * @param    string    Shortcode content
  * 
  * @return   string    Shortcode display
  */
 public static function movie_rating_shortcode($atts = array(), $content = null)
 {
     $atts = self::filter_shortcode_atts('movie_rating', $atts);
     $movie_id = WPMOLY_Shortcodes::find_movie_id($atts['id'], $atts['title']);
     if (is_null($movie_id)) {
         return $content;
     }
     $atts['movie_id'] = $movie_id;
     // Caching
     $name = apply_filters('wpmoly_cache_name', 'movie_rating_shortcode', $atts);
     $content = WPMOLY_Cache::output($name, function () use($atts, $content) {
         extract($atts);
         $content = wpmoly_get_movie_rating($movie_id);
         if ($stars || $numbers) {
             $output = '';
             if ($stars) {
                 $output .= apply_filters('wpmoly_format_movie_rating', $content, $format = 'html');
             }
             if ($numbers) {
                 $output .= '&nbsp;−&nbsp;';
                 if (10 == wpmoly_o('format-rating')) {
                     $output .= sprintf('%d/10', $content * 2);
                 } else {
                     $output .= sprintf('%s/5', $content);
                 }
             }
         } else {
             $format = !$raw ? 'html' : 'raw';
             $output = apply_filters('wpmoly_format_movie_rating', $content, $format);
         }
         return $output;
     }, $echo = false);
     return $content;
 }
    print_r($debug['permalinks_args']);
    ?>
</pre>
				</div>
<?php 
}
?>

				<div id="wpmoly-movie-grid" class="wpmoly movies archives<?php 
echo $theme;
?>
">

<?php 
global $post;
$headbox_enable = wpmoly_o('headbox-enable');
if (!empty($movies)) {
    foreach ($movies as $post) {
        setup_postdata($post);
        if ('1' == $headbox_enable) {
            echo WPMOLY_Movies::movie_content();
        } else {
            ?>
					<div id="post-<?php 
            the_ID();
            ?>
" class="wpmoly movies archives movie">
						<h2><?php 
            the_title();
            ?>
</h2>
 /**
  * Retrieve all images for a particular movie
  * 
  * @since    1.0
  * 
  * @param    int       $id TMDb-id or IMDB-id
  * @param    string    $lang Filter the result with a language
  * 
  * @return   array    TMDb result
  */
 public function getMovieImages($id, $lang = null)
 {
     $params = array('language' => is_null($lang) ? wpmoly_o('api-language') : $lang);
     return self::_makeCall('movie/' . $id . '/images', $params);
 }
 /**
  * Get movie by ID. Load casts and images too.
  * 
  * Return a JSON string containing fetched data. Apply some filtering
  * to extract specific crew jobs like director or producer.
  *
  * @since    1.0
  * 
  * @param    string    $id Id to search in the TMDb database
  * @param    string    $lang Lang to use in the query
  * @param    int       $post_id Related Post ID
  *
  * @return   string    JSON formatted results.
  */
 public static function _get_movie_by_id($id, $lang, $post_id = null)
 {
     $tmdb = new TMDb();
     $data = array('movie' => $tmdb->getMovie($id, $lang), 'casts' => $tmdb->getMovieCast($id), 'images' => $tmdb->getMovieImages($id, ''), 'release' => $tmdb->getMovieRelease($id));
     foreach ($data as $d) {
         if (is_wp_error($d)) {
             return $d;
         }
     }
     extract($data, EXTR_SKIP);
     $poster_path = $movie['poster_path'];
     $movie = apply_filters('wpmoly_filter_meta_data', $movie);
     $casts = apply_filters('wpmoly_filter_crew_data', $casts);
     $meta = array_merge($movie, $casts);
     $meta['tmdb_id'] = $id;
     $meta['certification'] = '';
     if (isset($release['countries'])) {
         $certification_alt = '';
         foreach ($release['countries'] as $country) {
             if ($country['iso_3166_1'] == wpmoly_o('api-country')) {
                 $meta['certification'] = $country['certification'];
                 $meta['local_release_date'] = $country['release_date'];
             } else {
                 if ($country['iso_3166_1'] == wpmoly_o('api-country-alt')) {
                     $certification_alt = $country['certification'];
                 }
             }
         }
         if ('' == $meta['certification']) {
             $meta['certification'] = $certification_alt;
         }
         if ('' == $meta['local_release_date']) {
             $meta['local_release_date'] = '';
         }
     }
     if (is_null($poster_path)) {
         $poster_path = str_replace('{size}', '-medium', WPMOLY_DEFAULT_POSTER_URL);
     }
     if (is_null($poster_path)) {
         $poster = $poster_path;
     } else {
         $poster = self::get_image_url($poster_path, 'poster', 'small');
     }
     $_images = array('images' => $images['backdrops']);
     $_full = array_merge($movie, $casts, $images);
     $_movie = array('_id' => $post_id, '_tmdb_id' => $id, 'meta' => $meta, 'images' => $images, 'poster' => $poster, 'poster_path' => $poster_path, '_result' => 'movie', '_full' => $_full);
     $_movie['taxonomy'] = array();
     // Prepare Custom Taxonomy
     if (1 == wpmoly_o('actor-autocomplete')) {
         $_movie['taxonomy']['actors'] = array();
         if (!empty($casts['cast']) && 1 == wpmoly_o('enable-actor')) {
             foreach ($casts['cast'] as $actor) {
                 $_movie['taxonomy']['actors'][] = $actor;
             }
         }
     }
     // Prepare Custom Taxonomy
     if (1 == wpmoly_o('genre-autocomplete')) {
         $_movie['taxonomy']['genres'] = array();
         if (!empty($movie['genres']) && 1 == wpmoly_o('enable-genre')) {
             foreach ($movie['genres'] as $genre) {
                 $_movie['taxonomy']['genres'][] = $genre;
             }
         }
     }
     return $_movie;
 }
 /**
  * Initializes variables
  *
  * @since    2.1.4
  */
 public function init()
 {
     $this->metaboxes = array('movie' => array('wpmoly' => array('title' => __('WordPress Movie Library', 'wpmovielibrary'), 'callback' => 'WPMOLY_Edit_Movies::metabox', 'screen' => 'movie', 'context' => 'normal', 'priority' => 'high', 'callback_args' => array('panels' => array('preview' => array('title' => __('Preview', 'wpmovielibrary'), 'icon' => 'wpmolicon icon-video', 'callback' => 'WPMOLY_Edit_Movies::render_preview_panel'), 'meta' => array('title' => __('Metadata', 'wpmovielibrary'), 'icon' => 'wpmolicon icon-meta', 'callback' => 'WPMOLY_Edit_Movies::render_meta_panel'), 'details' => array('title' => __('Details', 'wpmovielibrary'), 'icon' => 'wpmolicon icon-details', 'callback' => 'WPMOLY_Edit_Movies::render_details_panel'), 'images' => array('title' => __('Images', 'wpmovielibrary'), 'icon' => 'wpmolicon icon-images-alt', 'callback' => 'WPMOLY_Edit_Movies::render_images_panel'), 'posters' => array('title' => __('Posters', 'wpmovielibrary'), 'icon' => 'wpmolicon icon-poster', 'callback' => 'WPMOLY_Edit_Movies::render_posters_panel'))), 'condition' => null)), 'default' => array('wpmoly' => array('title' => __('WordPress Movie Library', 'wpmovielibrary'), 'callback' => 'WPMOLY_Edit_Movies::metabox', 'screen' => wpmoly_o('convert-post-types', array()), 'context' => 'side', 'priority' => 'high', 'callback_args' => null, 'condition' => '1' == wpmoly_o('convert-enable'))));
 }
Esempio n. 11
0
" href="<?php 
echo get_edit_post_link();
?>
&amp;wpmovielibrary-empty-meta=1" onclick="wpmoly.editor.meta.empty_results(); return false;" class="button button-secondary button-empty button-icon hide-if-no-js"><span class="wpmolicon icon-erase"></span></a>
							</div>

							<div id="wpmoly_status"></div>

							<div id="meta_data"></div>

							<input type="hidden" id="wpmoly_actor_limit" class="hide-if-js hide-if-no-js" value="<?php 
echo wpmoly_o('actor-limit');
?>
" />
							<input type="hidden" id="wpmoly_poster_featured" class="hide-if-js hide-if-no-js" value="<?php 
echo 1 == wpmoly_o('poster-featured') ? '1' : '0';
?>
" />

						</div>

						<div id="wpmoly-movie-meta" class="wpmoly-movie-meta">
<?php 
foreach ($metas as $slug => $meta) {
    $value = '';
    if (!$empty && isset($metadata[$slug])) {
        $value = apply_filters('wpmoly_stringify_array', $metadata[$slug]);
    }
    ?>
							<div class="wpmoly-movie-meta-edit wpmoly-movie-meta-edit-<?php 
    echo $slug;
 /**
  * Convert a queued movie to regular movie.
  * 
  * Simply change the movie's post_status from 'import-queued' to
  * 'publish' and 
  *
  * @since    1.0
  * 
  * @param    int    $post_id Movie Post ID
  * 
  * @return   int|boolean        ID of the updated movie if everything worked, false else.
  */
 private static function import_queued_movie($post_id)
 {
     if (is_null($post_id) || !($post = get_post($post_id) || 'movie' != get_post_type($post_id))) {
         return new WP_Error('invalid_movie', sprintf(__('Error: submitted Post ID doesn\\t match any valid movie.', 'wpmovielibrary')));
     }
     $meta = wpmoly_get_movie_meta($post_id);
     if ('' == $meta || !is_array($meta) || !isset($meta['poster']) || !isset($meta['tmdb_id'])) {
         return new WP_Error('invalid_meta', sprintf(__('Error: cannot find submitted movie\'s metadata, try enqueuing it again.', 'wpmovielibrary')));
     }
     $_post = array('ID' => $post_id, 'post_status' => 'publish');
     if (wpmoly_o('poster-featured')) {
         $id = WPMOLY_Media::set_image_as_featured($meta['poster'], $post_id, $meta['tmdb_id'], $meta['title']);
         update_post_meta($post_id, '_thumbnail_id', $id);
     }
     $update = wp_update_post($_post, $wp_error = true);
     if (is_wp_error($update)) {
         return new WP_Error('error', sprintf(__('An error occured when trying to imported queued movie "%s": %s', 'wpmovielibrary'), get_the_title($post_id), $update->get_error_message()));
     }
     return $update;
 }
 /**
  * Add tiny flags before country names.
  * 
  * @since    2.0
  * 
  * @param    string    $code Country ISO code
  * @param    string    $name Country nam
  * 
  * @return   string    Formatted output
  */
 public static function movie_country_flag($code, $name)
 {
     if (!in_array('flag', wpmoly_o('countries-format'))) {
         return $name;
     }
     $flag = '<span class="flag flag-%s" title="%s"></span>';
     $flag = sprintf($flag, strtolower($code), $name);
     /**
      * Apply filter to the rendered country flag
      * 
      * @since    2.0
      * 
      * @param    string    $flag HTML markup
      * @param    string    $code Country ISO code
      * @param    string    $name Country name
      */
     $flag = apply_filters('wpmoly_filter_country_flag_html', $flag, $code, $name);
     return $flag;
 }
 /**
  * Format a Movie's misc actors/genres list depending on
  * existing terms.
  * 
  * This is used to provide links for actors and genres lists
  * by using the metadata lists instead of taxonomies. But since
  * actors and genres can be added to the metadata and not terms,
  * we rely on metadata to show a correct list.
  * 
  * @since    1.1
  * 
  * @param    string    $data field value
  * @param    string    $taxonomy taxonomy we're dealing with
  * 
  * @return   string    Formatted output
  */
 public static function format_movie_terms_list($data, $taxonomy)
 {
     $has_taxonomy = wpmoly_o("enable-{$taxonomy}");
     $_data = explode(',', $data);
     foreach ($_data as $key => $term) {
         $term = trim(str_replace(array('&#039;', "’"), "'", $term));
         if ($has_taxonomy) {
             $_term = get_term_by('name', $term, $taxonomy);
             if (!$_term) {
                 $_term = get_term_by('slug', sanitize_title($term), $taxonomy);
             }
         } else {
             $_term = $term;
         }
         if (!$_term) {
             $_term = $term;
         }
         if (is_object($_term) && '' != $_term->name) {
             $link = get_term_link($_term, $taxonomy);
             $_term = is_wp_error($link) ? $_term->name : sprintf('<a href="%s" title="%s">%s</a>', $link, sprintf(__('More movies from %s', 'wpmovielibrary'), $_term->name), $_term->name);
         }
         $_data[$key] = $_term;
     }
     $_data = !empty($_data) ? implode(', ', $_data) : '&mdash;';
     return $_data;
 }
<?php

/**
 * WPMovieLibrary Config Shortcodes definition
 *
 * @package   WPMovieLibrary
 * @author    Charlie MERLAND <*****@*****.**>
 * @license   GPL-3.0
 * @link      http://www.caercam.org/
 * @copyright 2014 Charlie MERLAND
 */
// If this file is called directly, abort.
if (!defined('WPINC')) {
    wp_die();
}
$wpmoly_shortcodes = array('movie_grid' => array('atts' => array('menu' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr'), 'order' => array('default' => wpmoly_o('movie-archives-movies-order'), 'values' => array('ASC', 'DESC'), 'filter' => 'esc_attr'), 'orderby' => array('default' => wpmoly_o('movie-archives-movies-orderby'), 'values' => array('title', 'date', 'localdate', 'rating'), 'filter' => 'esc_attr'), 'number' => array('default' => wpmoly_o('movie-archives-movies-per-page'), 'values' => null, 'filter' => 'intval'), 'columns' => array('default' => wpmoly_o('movie-archives-grid-columns'), 'values' => null, 'filter' => 'intval'), 'rows' => array('default' => wpmoly_o('movie-archives-grid-rows'), 'values' => null, 'filter' => 'intval'), 'view' => array('default' => null, 'values' => array('grid', 'archives', 'list'), 'filter' => 'esc_attr'), 'letter' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'category' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'tag' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'collection' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'genre' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'actor' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'meta' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'detail' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'value' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => false, 'values' => 'boolean', 'filter' => 'esc_attr'), 'genre' => array('default' => false, 'values' => 'boolean', 'filter' => 'esc_attr'), 'rating' => array('default' => false, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_grid', 'aliases' => null), 'movies' => array('atts' => array('collection' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'genre' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'actor' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'order' => array('default' => 'desc', 'values' => array('asc', 'desc'), 'filter' => 'esc_attr'), 'orderby' => array('default' => 'date', 'values' => array('date', 'title', 'rating'), 'filter' => 'esc_attr'), 'count' => array('default' => 4, 'values' => null, 'filter' => 'intval'), 'poster' => array('default' => 'medium', 'values' => array('none', 'thumb', 'thumbnail', 'medium', 'large', 'full'), 'filter' => 'esc_attr'), 'meta' => array('default' => null, 'values' => array('director', 'runtime', 'release_date', 'genres', 'actors', 'overview', 'title', 'original_title', 'production', 'country', 'language', 'producer', 'photography', 'composer', 'author', 'writer'), 'filter' => null), 'details' => array('default' => null, 'values' => array('media', 'status', 'rating'), 'filter' => null), 'paginate' => array('default' => false, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movies_shortcode', 'aliases' => null), 'movie' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'poster' => array('default' => 'medium', 'values' => array('none', 'thumb', 'thumbnail', 'medium', 'large', 'full'), 'filter' => 'esc_attr'), 'meta' => array('default' => array('director', 'runtime', 'release_date', 'genres', 'actors', 'overview'), 'values' => array('director', 'runtime', 'release_date', 'genres', 'actors', 'overview', 'title', 'original_title', 'production', 'country', 'language', 'producer', 'photography', 'composer', 'author', 'writer', 'cast'), 'filter' => null), 'details' => array('default' => array('media', 'status', 'rating'), 'values' => array('media', 'status', 'rating'), 'filter' => null)), 'content' => null, 'callback' => 'movie_shortcode', 'aliases' => null), 'movie_meta' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'key' => array('default' => null, 'values' => array('director', 'runtime', 'release_date', 'genres', 'actors', 'cast', 'overview', 'title', 'original_title', 'production', 'country', 'language', 'producer', 'photography', 'composer', 'author', 'writer'), 'filter' => 'esc_attr'), 'label' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_meta_shortcode', 'aliases' => array('movie_director', 'movie_overview', 'movie_title', 'movie_original_title', 'movie_production', 'movie_country', 'movie_language', 'movie_lang', 'movie_producer', 'movie_photography', 'movie_composer', 'movie_author', 'movie_writer', 'movie_tagline', 'movie_certification', 'movie_budget', 'movie_revenue', 'movie_imdb_id', 'movie_tmdb_id', 'movie_adult', 'movie_homepage')), 'movie_runtime' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'format' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'label' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_runtime_shortcode', 'aliases' => null), 'movie_release_date' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'format' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'label' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_release_date_shortcode', 'aliases' => array('movie_date')), 'movie_local_release_date' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'format' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'label' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_local_release_date_shortcode', 'aliases' => null), 'movie_actors' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'count' => array('default' => null, 'values' => null, 'filter' => 'intval'), 'label' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_actors_shortcode', 'aliases' => array('movie_cast', 'movie_casting')), 'movie_genres' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'count' => array('default' => null, 'values' => null, 'filter' => 'intval'), 'label' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_genres_shortcode', 'aliases' => null), 'movie_poster' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'size' => array('default' => 'medium', 'values' => array('none', 'thumb', 'thumbnail', 'medium', 'large', 'full'), 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_poster_shortcode', 'aliases' => null), 'movie_images' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'size' => array('default' => 'thumbnail', 'values' => array('none', 'thumb', 'thumbnail', 'medium', 'large', 'full'), 'filter' => 'esc_attr'), 'type' => array('default' => 'all', 'values' => array('all', 'images', 'backdrops', 'posters'), 'filter' => 'esc_attr'), 'count' => array('default' => -1, 'values' => null, 'filter' => 'intval'), 'label' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_images_shortcode', 'aliases' => array('movie_pictures', 'movie_photos', 'movie_posters')), 'movie_rating' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'stars' => array('default' => false, 'values' => 'boolean', 'filter' => 'esc_attr'), 'numbers' => array('default' => false, 'values' => 'boolean', 'filter' => 'esc_attr'), 'raw' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_rating_shortcode', 'aliases' => null), 'movie_detail' => array('atts' => array('id' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'title' => array('default' => null, 'values' => null, 'filter' => 'esc_attr'), 'key' => array('default' => null, 'values' => array('media', 'status', 'rating'), 'filter' => 'esc_attr'), 'raw' => array('default' => true, 'values' => 'boolean', 'filter' => 'esc_attr')), 'content' => null, 'callback' => 'movie_detail_shortcode', 'aliases' => array('movie_media', 'movie_status', 'movie_languages', 'movie_subtitles', 'movie_format')));
 /**
  * Parse taxonomy archives sorting parameters
  * 
  * @since    2.1.1
  * 
  * @param    array    $args Query parameters
  * 
  * @return   array    Parsed parameters
  */
 public static function parse_terms_query_vars($vars)
 {
     $defaults = array('letter' => '', 'paged' => '1', 'number' => wpmoly_o("tax-archives-terms-per-page", $default = true), 'order' => wpmoly_o("tax-archives-terms-order", $default = true), 'orderby' => wpmoly_o("tax-archives-terms-orderby", $default = true));
     $params = array();
     // I can haz sortingz!
     if (isset($vars['sorting']) && '' != $vars['sorting']) {
         $sorting = '/' . $vars['sorting'];
         $regex = array('letter' => '(\\/([0-9A-Za-z]{1}))\\/', 'number' => '([0-9]{1,})\\/?', 'order' => '(asc|desc|ASC|DESC)\\/?', 'orderby' => '(count|title)\\/?', 'paged' => '(page\\/([0-9]{1,}))\\/?');
         // Has letter?
         $preg = preg_match("/{$regex['letter']}/", $sorting, $matches);
         if ($preg && isset($matches[2]) && '' != $matches[2]) {
             $params['letter'] = $matches[2];
         }
         // Has number/columns?
         $preg = preg_match("/{$regex['number']}/", $sorting, $matches);
         if ($preg && isset($matches[1]) && '' != $matches[1]) {
             $params['number'] = $matches[1];
         }
         // Has sorting?
         $preg = preg_match("/{$regex['order']}/", $sorting, $matches);
         if ($preg && isset($matches[1]) && '' != $matches[1]) {
             $params['order'] = strtoupper($matches[1]);
         }
         // Has sorting?
         $preg = preg_match("/{$regex['orderby']}/", $sorting, $matches);
         if ($preg && isset($matches[1]) && '' != $matches[1]) {
             $params['orderby'] = strtolower($matches[1]);
         }
         // Has pagination?
         $preg = preg_match("/{$regex['paged']}/", $sorting, $matches);
         if ($preg) {
             $params['paged'] = $matches[2];
         }
         $params = wp_parse_args($params, $defaults);
     } else {
         $params = wp_parse_args($vars, $defaults);
     }
     return $params;
 }
 /**
  * Add movie post_type to archives WP_Query
  * 
  * @since    2.1
  * 
  * @param    object    $wp_query WP_Query object
  * 
  * @return   object    $wp_query WP_Query object
  */
 public static function filter_archives_query($wp_query)
 {
     if (!empty($query->query_vars['suppress_filters'])) {
         return $wp_query;
     }
     if ((!is_category() || is_category() && '0' == wpmoly_o('enable-categories')) && (!is_tag() || is_tag() && '0' == wpmoly_o('enable-tags'))) {
         return $wp_query;
     }
     $post_types = $wp_query->get('post_type');
     if ('' == $post_types) {
         $post_types = array('post', 'movie');
     } else {
         if (is_array($post_types)) {
             $post_types = array_merge($post_types, array('post', 'movie'));
         } else {
             $post_types = array_merge((array) $post_types, array('post', 'movie'));
         }
     }
     $wp_query->set('post_type', $post_types);
     return $wp_query;
 }
 /**
  * Modern headbox details tab content callback.
  * 
  * @since    2.0
  * 
  * @return   string    Tab content HTML markup
  */
 public function get_wpmoly_headbox_details_tab()
 {
     // TODO: better filtering/formatting
     $details = wpmoly_get_movie_details();
     $fields = wpmoly_o('sort-details');
     $default_fields = WPMOLY_Settings::get_supported_movie_details();
     if (empty($fields) || !isset($fields['used'])) {
         return null;
     }
     $fields = $fields['used'];
     if (isset($fields['placebo'])) {
         unset($fields['placebo']);
     }
     $post_id = get_the_ID();
     $items = array();
     foreach ($fields as $slug => $field) {
         if (isset($details[$slug])) {
             $detail = $details[$slug];
             if (!is_array($detail)) {
                 $detail = array($detail);
             }
             foreach ($detail as $i => $d) {
                 if ('' != $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);
             }
             if (empty($detail)) {
                 $detail[] = apply_filters("wpmoly_format_movie_field", '');
             }
             $title = '';
             if (isset($default_fields[$slug])) {
                 $title = __($default_fields[$slug]['title'], 'wpmovielibrary');
             }
             $items[] = array('slug' => $slug, 'title' => $title, 'value' => $detail);
         }
     }
     $attributes = array('details' => $items);
     $content = WPMovieLibrary::render_template('movies/headbox/tabs/details.php', $attributes, $require = 'always');
     return $content;
 }
 /**
  * Localization for scripts
  * 
  * Adds a translation object to the plugin's JavaScript object
  * containing localized texts.
  * 
  * @since    1.0
  * 
  * @return   array    Localization array
  */
 public static function localize_script()
 {
     $localize = array();
     $localize['language'] = wpmoly_o('api-language');
     $lang = array('available' => __('Available', 'wpmovielibrary'), 'deleted_movie' => __('One movie successfully deleted.', 'wpmovielibrary'), 'deleted_movies' => __('%s movies successfully deleted.', 'wpmovielibrary'), 'dequeued_movie' => __('One movie removed from the queue.', 'wpmovielibrary'), 'dequeued_movies' => __('%s movies removed from the queue.', 'wpmovielibrary'), 'done' => __('Done!', 'wpmovielibrary'), 'enqueued_movie' => __('One movie added to the queue.', 'wpmovielibrary'), 'enqueued_movies' => __('%s movies added to the queue.', 'wpmovielibrary'), 'images_added' => __('Images added!', 'wpmovielibrary'), 'image_from' => __('Image from', 'wpmovielibrary'), 'images_uploaded' => __('Images uploaded!', 'wpmovielibrary'), 'import_images' => __('Import Images', 'wpmovielibrary'), 'import_images_title' => __('Import Images for "%s"', 'wpmovielibrary'), 'import_images_wait' => __('Please wait while the images are uploaded...', 'wpmovielibrary'), 'import_poster' => __('Import Poster', 'wpmovielibrary'), 'import_poster_title' => __('Select a poster for "%s"', 'wpmovielibrary'), 'import_poster_wait' => __('Please wait while the poster is uploaded...', 'wpmovielibrary'), 'imported' => __('Imported', 'wpmovielibrary'), 'imported_movie' => __('One movie successfully imported!', 'wpmovielibrary'), 'imported_movies' => __('%s movies successfully imported!', 'wpmovielibrary'), 'in_progress' => __('Progressing', 'wpmovielibrary'), 'length_key' => __('Invalid key: it should be 32 characters long.', 'wpmovielibrary'), 'load_images' => __('Load Images', 'wpmovielibrary'), 'load_more' => __('Load More', 'wpmovielibrary'), 'loading_images' => __('Loading Images…', 'wpmovielibrary'), 'media_no_movie' => __('No movie could be found. You need to select a movie before importing images or posters.', 'wpmovielibrary'), 'metadata_saved' => __('Metadata saved!', 'wpmovielibrary'), 'missing_meta' => __('No metadata could be found, please import metadata before queuing.', 'wpmovielibrary'), 'movie' => __('Movie', 'wpmovielibrary'), 'movie_updated' => _n('movie updated', 'movies updated', 0, 'wpmovielibrary'), 'movies_updated' => _n('movie updated', 'movies updated', 2, 'wpmovielibrary'), 'not_updated' => __('not updated', 'wpmovielibrary'), 'oops' => __('Oops… Did something went wrong?', 'wpmovielibrary'), 'poster' => __('Poster', 'wpmovielibrary'), 'save_image' => __('Saving Images…', 'wpmovielibrary'), 'search_movie_title' => __('Searching movie', 'wpmovielibrary'), 'search_movie' => __('Fetching movie data', 'wpmovielibrary'), 'see_less' => __('see no more', 'wpmovielibrary'), 'see_more' => __('see more', 'wpmovielibrary'), 'selected' => _n('selected', 'selected', 0, 'wpmovielibrary'), 'set_featured' => __('Setting featured image…', 'wpmovielibrary'), 'updated' => __('updated successfully', 'wpmovielibrary'), 'used' => __('Used', 'wpmovielibrary'), 'updating' => __('updating movies...', 'wpmovielibrary'), 'x_selected' => _n('selected', 'selected', 2, 'wpmovielibrary'));
     $localize = array_merge($localize, $lang);
     return $localize;
 }
 /**
  * Update metas.
  * 
  * @since    2.0
  *
  * @param    int    $movie_id
  * 
  * @return   int|bool    False if update failed, true else
  */
 private static function update_meta($movie_id)
 {
     $meta = get_post_meta($movie_id, '_wpmoly_movie_data', $single = true);
     if ('' == $meta) {
         return false;
     }
     $update = WPMOLY_Edit_Movies::save_movie_meta($movie_id, $meta, $clean = false);
     if (!wpmoly_o('legacy-safety') && !is_wp_error($update) && $update == $movie_id) {
         delete_post_meta($movie_id, '_wpmoly_movie_data', $meta);
     }
     return $update;
 }
 /**
  * Format a Movie detail. If format is HTML, will return a
  * HTML formatted string; will return the value without change
  * if raw is asked.
  * 
  * @since    2.0
  * 
  * @param    string     $detail details slug
  * @param    string     $data detail value
  * @param    string     $format data format, raw or HTML
  * @param    boolean    $icon Show as icon or text
  * 
  * @return   string    Formatted output
  */
 public static function format_movie_detail($detail, $data, $format = 'html', $icon = false)
 {
     $format = 'raw' == $format ? 'raw' : 'html';
     if ('' == $data) {
         return $data;
     }
     if (true === $icon || wpmoly_o('details-icons') && 'html' == $format) {
         $view = 'shortcodes/detail-icon.php';
     } else {
         $view = 'shortcodes/detail.php';
     }
     $title = '';
     $default_fields = call_user_func("WPMOLY_Settings::get_available_movie_{$detail}");
     if (!is_array($data)) {
         $data = array($data);
     }
     $_data = '';
     foreach ($data as $d) {
         if (isset($default_fields[$d])) {
             $title = __($default_fields[$d], 'wpmovielibrary');
             $_data .= WPMovieLibrary::render_template($view, array('detail' => $detail, 'data' => $d, 'title' => $title), $require = 'always');
         }
     }
     return $_data;
 }
Esempio n. 22
0
<?php 
} else {
    ?>
		<?php 
    do_action('wpmoly_before_metabox_content');
    ?>
		<input type="hidden" id="wpmoly-autocomplete-collection" value="<?php 
    echo wpmoly_o('collection-autocomplete');
    ?>
" />
		<input type="hidden" id="wpmoly-autocomplete-genre" value="<?php 
    echo wpmoly_o('genre-autocomplete');
    ?>
" />
		<input type="hidden" id="wpmoly-autocomplete-actor" value="<?php 
    echo wpmoly_o('actor-autocomplete');
    ?>
" />

		<div id="wpmoly-meta" class="wpmoly-meta">

			<div id="wpmoly-meta-menu-bg"></div>
			<ul id="wpmoly-meta-menu" class="hide-if-no-js">

<?php 
    foreach ($tabs as $id => $tab) {
        ?>

				<li id="wpmoly-meta-<?php 
        echo $id;
        ?>
 /**
  * Save TMDb fetched data.
  * 
  * Uses the 'save_post_movie' action hook to save the movie metadata
  * as a postmeta. This method is used in regular post creation as
  * well as in movie import. If no $movie_meta is passed, we're 
  * most likely creating a new movie, use $_REQUEST to get the data.
  * 
  * Saves the movie details as well.
  *
  * @since    1.0
  * 
  * @param    int        $post_ID ID of the current Post
  * @param    object     $post Post Object of the current Post
  * @param    boolean    $queue Queued movie?
  * @param    array      $movie_meta Movie Metadata to save with the post
  * 
  * @return   int|WP_Error
  */
 public static function save_movie($post_ID, $post, $queue = false, $movie_meta = null)
 {
     if (!current_user_can('edit_post', $post_ID)) {
         return new WP_Error(__('You are not allowed to edit posts.', 'wpmovielibrary'));
     }
     if (!($post = get_post($post_ID) || 'movie' != get_post_type($post))) {
         return new WP_Error(sprintf(__('Posts with #%s is invalid or is not a movie.', 'wpmovielibrary'), $post_ID));
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_ID;
     }
     $errors = new WP_Error();
     if (!is_null($movie_meta) && count($movie_meta)) {
         // Save TMDb data
         self::save_movie_meta($post_ID, $movie_meta);
         // Set poster as featured image
         if (wpmoly_o('poster-featured') && !$queue) {
             $upload = WPMOLY_Media::set_image_as_featured($movie_meta['poster'], $post_ID, $movie_meta['tmdb_id'], $movie_meta['title']);
             if (is_wp_error($upload)) {
                 $errors->add($upload->get_error_code(), $upload->get_error_message());
             } else {
                 update_post_meta($post_ID, '_thumbnail_id', $upload);
             }
         }
         // Switch status from import draft to published
         if ('import-draft' == get_post_status($post_ID) && !$queue) {
             $update = wp_update_post(array('ID' => $post_ID, 'post_name' => sanitize_title_with_dashes($movie_meta['title']), 'post_status' => 'publish', 'post_title' => $movie_meta['title'], 'post_date' => current_time('mysql')), $wp_error = true);
             if (is_wp_error($update)) {
                 $errors->add($update->get_error_code(), $update->get_error_message());
             }
         }
         // Autofilling Actors
         if (wpmoly_o('enable-actor') && wpmoly_o('actor-autocomplete')) {
             $limit = intval(wpmoly_o('actor-limit'));
             $actors = explode(',', $movie_meta['cast']);
             if ($limit) {
                 $actors = array_slice($actors, 0, $limit);
             }
             $actors = wp_set_object_terms($post_ID, $actors, 'actor', false);
         }
         // Autofilling Genres
         if (wpmoly_o('enable-genre') && wpmoly_o('genre-autocomplete')) {
             $genres = explode(',', $movie_meta['genres']);
             $genres = wp_set_object_terms($post_ID, $genres, 'genre', false);
         }
         // Autofilling Collections
         if (wpmoly_o('enable-collection') && wpmoly_o('collection-autocomplete')) {
             $collections = explode(',', $movie_meta['director']);
             $collections = wp_set_object_terms($post_ID, $collections, 'collection', false);
         }
     } else {
         if (isset($_REQUEST['meta']) && '' != $_REQUEST['meta']) {
             self::save_movie_meta($post_ID, $_POST['meta']);
         }
     }
     if (isset($_REQUEST['wpmoly_details']) && !is_null($_REQUEST['wpmoly_details'])) {
         if (isset($_REQUEST['is_quickedit']) || isset($_REQUEST['is_bulkedit'])) {
             wpmoly_check_admin_referer('quickedit-movie-details');
         }
         $wpmoly_details = $_REQUEST['wpmoly_details'];
         if (true === $_REQUEST['is_bulkedit']) {
             foreach ($_REQUEST['post'] as $post_id) {
                 self::save_movie_details($post_id, $wpmoly_details);
             }
         } else {
             self::save_movie_details($post_ID, $wpmoly_details);
         }
     }
     WPMOLY_Cache::clean_transient('clean', $force = true);
     return !empty($errors->errors) ? $errors : $post_ID;
 }
 /**
  * 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;
 }
 private static function filter_value($value)
 {
     if ('1' == wpmoly_o('rewrite-enable')) {
         $value = WPMOLY_L10n::untranslate_rewrite($value);
     } else {
         $value = WPMOLY_L10n::translate_rewrite($value);
     }
     return $value;
 }
 /**
  * Update movie images/posters title, description, caption...
  * 
  * @since    2.0
  * 
  * @param    int       $attachment_id Current image Post ID
  * @param    int       $post_id Related Post ID
  * @param    string    $image_type Image type, 'backdrop' or 'poster'
  * @param    array     $data Image data
  */
 private static function update_attachment_meta($attachment_id, $post_id, $image_type, $data)
 {
     if (!get_post($attachment_id) || !get_post($post_id)) {
         return false;
     }
     if ('poster' != $image_type) {
         $image_type = 'image';
     }
     $tmdb_id = WPMOLY_Movies::get_movie_meta($post_id, 'tmdb_id');
     $title = WPMOLY_Movies::get_movie_meta($post_id, 'title');
     $production = WPMOLY_Movies::get_movie_meta($post_id, 'production_companies');
     $director = WPMOLY_Movies::get_movie_meta($post_id, 'director');
     $original_title = WPMOLY_Movies::get_movie_meta($post_id, 'original_title');
     $production = explode(',', $production);
     $production = trim(array_shift($production));
     $year = WPMOLY_Movies::get_movie_meta($post_id, 'release_date');
     $year = apply_filters('wpmoly_format_movie_date', $year, 'Y');
     $find = array('{title}', '{originaltitle}', '{year}', '{production}', '{director}');
     $replace = array($title, $original_title, $year, $production, $director);
     $_description = str_replace($find, $replace, wpmoly_o("{$image_type}-description"));
     $_title = str_replace($find, $replace, wpmoly_o("{$image_type}-title"));
     $attachment = array('ID' => $attachment_id, 'post_title' => $_title, 'post_content' => $_description, 'post_excerpt' => $_description);
     update_post_meta($attachment_id, '_wpmoly_' . $image_type . '_related_tmdb_id', $tmdb_id);
     update_post_meta($attachment_id, '_wpmoly_' . $image_type . '_related_meta_data', $data);
     update_post_meta($attachment_id, '_wp_attachment_image_alt', $_title);
     $update = wp_update_post($attachment);
 }
 /**
  * Cache outputs.
  * 
  * Uses an anonymous function to execute and get the result of the
  * code to cache; if $echo is set to true, just display the result.
  * If $echo is set to false, return the result.
  * 
  * @since    1.2
  * 
  * @param    string      the key to indicate the value
  * @param    function    anonymous function executing the code to cache
  * @param    boolean     should we echo the result of just return it?
  * 
  * @return   mixed
  */
 public static function output($name, $function, $echo = false)
 {
     // Cache is disabled, or user is logged in but user cache is disabled
     if (!wpmoly_o('enable-cache') || is_user_logged_in() && !wpmoly_o('cache-user')) {
         return self::output_callback($function, $echo);
     }
     $expire = wpmoly_o('cache-expire');
     if (!$expire) {
         return false;
     }
     $name = 'wpmoly_cache_' . $name;
     $output = get_transient($name);
     if (!empty($output)) {
         return $output;
     }
     $output = self::output_callback($function, $echo);
     set_transient($name, $output, $expire);
     return $output;
 }