/**
 * Simple function to check for deprecated movie metadata. Prior to version 1.3
 * metadata are stored in a unique meta field and must be converted to be used
 * in latest versions.
 *
 * @since    2.0
 *
 * @return   boolean    Deprecated meta?
 */
function wpmoly_has_deprecated_meta($post_id = null)
{
    if (!is_null($post_id) && class_exists('WPMOLY_Legacy')) {
        return WPMOLY_Legacy::has_deprecated_meta($post_id);
    }
    // Option not set, simultate deprecated to update counter
    $deprecated = get_option('wpmoly_has_deprecated_meta');
    if (false === $deprecated) {
        return true;
    }
    // transient set but count to 0 means we don't do anything
    $deprecated = '0' == $deprecated ? false : true;
    return $deprecated;
}
 /**
  * Return various Movie's Post Meta. Possible meta: status, media, rating
  * and data.
  *
  * @since    1.0
  * 
  * @param    int       Movie Post ID
  * @param    string    Meta type to return: data, status, media or rating
  *
  * @return   array|string    WPMOLY Movie Meta if available, empty string else.
  */
 public static function get_movie_meta($post_id = null, $meta = null)
 {
     if (is_null($post_id)) {
         $post_id = get_the_ID();
     }
     if (!($post = get_post($post_id) || 'movie' != get_post_type($post_id))) {
         return false;
     }
     if (is_admin() && 'data' == $meta && wpmoly_has_deprecated_meta($post_id) && wpmoly_o('legacy-mode')) {
         WPMOLY_Legacy::update_movie($post_id);
     }
     if ('data' == $meta || 'meta' == $meta) {
         $_meta = WPMOLY_Settings::get_supported_movie_meta();
         $value = array();
         $value['tmdb_id'] = get_post_meta($post_id, "_wpmoly_movie_tmdb_id", true);
         $value['poster'] = get_post_meta($post_id, "_wpmoly_movie_poster", true);
         foreach (array_keys($_meta) as $slug) {
             $value[$slug] = get_post_meta($post_id, "_wpmoly_movie_{$slug}", true);
         }
         return $value;
     } else {
         if ('details' == $meta) {
             $details = WPMOLY_Settings::get_supported_movie_details();
             $value = array();
             foreach (array_keys($details) as $slug) {
                 $value[$slug] = get_post_meta($post_id, "_wpmoly_movie_{$slug}", true);
             }
             return $value;
         }
     }
     $value = get_post_meta($post_id, "_wpmoly_movie_{$meta}", true);
     if ('rating' == $meta) {
         $value = number_format(floatval($value), 1);
     }
     return $value;
 }
 /**
  * Initialize the plugin by setting localization and loading public scripts
  * and styles.
  *
  * @since    1.0
  */
 protected function __construct()
 {
     $this->register_hook_callbacks();
     $this->modules = array('WPMOLY_Settings' => WPMOLY_Settings::get_instance(), 'WPMOLY_Cache' => WPMOLY_Cache::get_instance(), 'WPMOLY_L10n' => WPMOLY_L10n::get_instance(), 'WPMOLY_Utils' => WPMOLY_Utils::get_instance(), 'WPMOLY_Movies' => WPMOLY_Movies::get_instance(), 'WPMOLY_Headbox' => WPMOLY_Headbox::get_instance(), 'WPMOLY_Search' => WPMOLY_Search::get_instance(), 'WPMOLY_Collections' => WPMOLY_Collections::get_instance(), 'WPMOLY_Genres' => WPMOLY_Genres::get_instance(), 'WPMOLY_Actors' => WPMOLY_Actors::get_instance(), 'WPMOLY_Archives' => WPMOLY_Archives::get_instance(), 'WPMOLY_Shortcodes' => WPMOLY_Shortcodes::get_instance(), 'WPMOLY_Legacy' => WPMOLY_Legacy::get_instance());
     $this->widgets = array('WPMOLY_Statistics_Widget', 'WPMOLY_Taxonomies_Widget', 'WPMOLY_Details_Widget', 'WPMOLY_Movies_Widget');
 }