/** * Generate a list of all countries used in movies * * @since 2.0 * * @param boolean $count Shall we add count? * * @return array */ public static function get_used_countries($count = false) { $used_countries = array(); if (true !== $count) { $count = false; } $countries = self::get_used_meta('production_countries', $count); foreach ($countries as $i => $country) { $_country = WPMOLY_L10n::get_country_standard_name($country['name']); if ($_country != $country['name']) { if (!$count) { $used_countries[$country['name']] = __($_country, 'wpmovielibrary-iso'); } else { $used_countries[$country['name']] = sprintf('%s (%s)', __($_country, 'wpmovielibrary-iso'), sprintf(_n('%d movie', '%d movies', $country['count'], 'wpmovielibrary'), $country['count'])); } } } return $used_countries; }
public static function by_production_countries($country, $format = 'array') { $value = self::filter_value($country); $value = WPMOLY_L10n::get_country_standard_name($value); $meta_query = self::by_interval('production_countries', $value, $strict = false, $filter = false); if ('sql' === $format) { $meta_query = self::get_sql($meta_query); } return $meta_query; }
/** * Format a Movie's countries for display * * @since 2.0 * * @param string $data field value * * @return string Formatted output */ public static function format_movie_production_countries($data) { if (is_null($data) || '' == $data) { return $data; } if ('1' == wpmoly_o('translate-countries')) { $format = wpmoly_o('countries-format', array()); } else { $format = array('flag', 'original'); } $data = explode(',', $data); foreach ($data as $i => $country) { $country = trim($country); $value = $country; $_value = array(); foreach ($format as $c => $f) { switch ($f) { case 'flag': $country = WPMOLY_L10n::get_country_standard_name($country); $code = WPMOLY_L10n::get_country_code($country); $text = self::movie_country_flag($code, $country); break; case 'original': $text = $country; break; case 'translated': $country = WPMOLY_L10n::get_country_standard_name($country); $country = __($country, 'wpmovielibrary-iso'); $text = $country; break; case 'ptranslated': $country = __($country, 'wpmovielibrary-iso'); $text = sprintf('(%s)', $country); break; case 'poriginal': $country = WPMOLY_L10n::get_country_standard_name($country); $text = sprintf('(%s)', $country); break; default: $text = ''; break; } if ('flag' != $f && '' != $text) { $text = apply_filters('wpmoly_movie_meta_link', array('key' => 'production_countries', 'value' => $value, 'type' => 'meta', 'text' => $text, 'title' => sprintf(__('More movies from country %s', 'wpmovielibrary'), $text))); } $_value[] = $text; } $data[$i] = implode(' ', $_value); } $data = implode(', ', $data); $output = self::format_movie_field($data); return $output; }
/** * Filter page's title to feature letters, meta, value in archives * pages' titles. Hooked to 'the_title' and 'wp_title' filters. * * @since 2.1.1 * * @param string $title Current title * @param int|string $id Current page ID if current filter if 'the_title', separator if filter is 'wp_title' * * @return string */ public function movie_archives_title($title, $id = null) { // Exclude admin if (is_admin()) { return $title; } // 'wp_title' filter second parameter is separator, not id $filter = current_filter(); $sep = ' | '; if ('wp_title' == $filter) { $id = get_the_ID(); } // Exclude not-archive pages if (!in_array($id, $this->pages)) { return $title; } $is_movie = $id == $this->pages['movie']; $translate = '1' == wpmoly_o('rewrite-enable'); $rewrite_movie = '1' == wpmoly_o('movie-archives-title-rewrite'); $rewrite_taxonomy = '1' == wpmoly_o('tax-archives-title-rewrite'); if ($is_movie && !$rewrite_movie || !$is_movie && !$rewrite_taxonomy) { return $title; } $page = array_search($id, $this->pages); $titles = array('movie' => __('Movies', 'wpmovielibrary'), 'collection' => __('Collections', 'wpmovielibrary'), 'genre' => __('Genres', 'wpmovielibrary'), 'actor' => __('Actors', 'wpmovielibrary')); /** * Filter Archive Pages Titles * * @since 2.1.1 * * @param array $titles Default Archive Pages titles * * @return array Filtered titles */ $titles = apply_filters('wpmoly_filter_archive_pages_titles', $titles); /** * Filter Archive Page's default title * * @since 2.1.1 * * @param string $title Current Archive Page title * @param int $id Current Archive Page Post ID * * @return string Filtered title */ $title = apply_filters("wpmoly_filter_{$page}_archive_page_default_title", $titles[$page], $id); if (!is_single($id) && !is_page($id) || 'the_title' == $filter && !in_the_loop()) { return $title; } $meta = get_query_var('meta'); $detail = get_query_var('detail'); $value = get_query_var('value'); $sorting = get_query_var('sorting'); $_detail = ''; $_meta = ''; if ($is_movie && $rewrite_movie) { if ('' != $meta) { if ($translate) { $meta = WPMOLY_L10n::untranslate_rewrite($meta); } $supported = WPMOLY_Settings::get_supported_movie_meta(); if (isset($supported[$meta])) { $_meta = $supported[$meta]['title']; } if ('' != $value) { $value = WPMOLY_L10n::untranslate_rewrite($value); } } elseif ('' != $detail) { if ($translate) { $detail = WPMOLY_L10n::untranslate_rewrite($detail); } $supported = WPMOLY_Settings::get_supported_movie_detail(); if (isset($supported[$detail])) { $_detail = $supported[$detail]['title']; } if ('' != $value) { $value = WPMOLY_L10n::untranslate_rewrite($value); } } if ('production_countries' == $meta) { $value = WPMOLY_L10n::get_country_standard_name($value); $value = __($value, 'wpmovielibrary-iso'); } else { if ('spoken_languages' == $meta) { $value = WPMOLY_L10n::get_language_standard_name($value); $value = __($value, 'wpmovielibrary-iso'); } else { $value = __($value, 'wpmovielibrary'); } } if ('' == $_meta && '' != $_detail) { $_meta = $_detail; } if ('' != $_meta && '' == $value) { $title = sprintf(__('Movies by %s', 'wpmovielibrary'), $_meta); } elseif ('' != $_meta && '' != $value) { $title = sprintf(__('Movies by %s: %s', 'wpmovielibrary'), ucwords($_meta), $value); } else { $title = __('Movies', 'wpmovielibrary'); } } if ('' != $sorting) { $sorting = self::parse_query_vars(compact('sorting')); if (isset($sorting['letter']) && '' != $sorting['letter']) { $title .= sprintf(' − %s ', sprintf(__('Letter %s', 'wpmovielibrary'), $sorting['letter'])); } if (isset($sorting['paged']) && '' != $sorting['paged'] && 'wp_title' == $filter) { $title .= sprintf(__(' %s Page %d ', 'wpmovielibrary'), $sep, $sorting['paged']); } } /** * Filter Page's Post title as used in (get_)the_title() * * @since 2.1.1 * * @param string $title Current Archive Page title * @param int $id Current Archive Page Post ID * * @return string Filtered title */ $title = apply_filters("wpmoly_filter_{$page}_archive_page_title", $title, $id); if ('wp_title' == $filter) { $title = str_replace(array(' : ', ' − '), $sep, $title) . $sep; /** * Filter Page's main title as used in wp_title() * * @since 2.1.1 * * @param string $title Current Archive Page title * @param int $id Current Archive Page Post ID * * @return string Filtered title */ $title = apply_filters("wpmoly_filter_{$page}_archive_page_wp_title", $title, $id); } return $title; }