class ZetaPlayer {
// Attributes
public $postmeta;
/**
* @since 1.0.0
* @version 1.0
*/
public function __construct() {
// Main postmeta
$this->postmeta = 'repeatable_fields';
// Actions
add_action('save_post', array($this, 'save'));
add_action('admin_init', array($this, 'add_metabox'), 1);
// Ajax Actions
add_action('wp_ajax_zeta_player_ajax', array($this, 'ajax'));
add_action('wp_ajax_nopriv_zeta_player_ajax', array($this, 'ajax'));
// Api Rest
add_action('rest_api_init', array($this, 'api_route'));
}
/**
* @since 1.0.0
* @version 1.0
*/
public function viewer($post, $type, $players, $trailer, $size, $views, $ads = false, $image = false, $tvid = '', $ssep = '') {
$players = apply_filters('player_videos', $players);
$nosplash = ' display-showvid';
$playvid = false;
// Set Ajax Player
$ajax_player = zeta_get_option('playajax');
$play_pager = zeta_compose_pagelink('jwpage');
$current_page = ($tvid) ? get_permalink($tvid) . "season/" . $ssep[0] . "/episode/" . $ssep[2] . "/" : get_permalink($post);
// Fetch IMDB ID and season/episode data if available
$imdb_id = get_post_meta($post->ID, 'imdb_id', true);
$season_id = isset($ssep[0]) ? $ssep[0] : '';
$episode_id = isset($ssep[2]) ? $ssep[2] : '';
// Define predefined servers for movies and TV shows
$predefined_servers = array(
array(
'name' => 'Server 1',
'url' => $type == 'movies' ? "https://vidsrc.xyz/embed/movie/$imdb_id" : "https://vidsrc.xyz/embed/tv/$imdb_id/$season_id-$episode_id"
),
array(
'name' => 'Server 2',
'url' => $type == 'movies' ? "https://vidsrc.xyz/embed/movie/$imdb_id" : "https://vidsrc.xyz/embed/tv/$imdb_id/$season_id-$episode_id"
),
array(
'name' => 'Server 3',
'url' => $type == 'movies' ? "https://vidsrc.xyz/embed/movie/$imdb_id" : "https://vidsrc.xyz/embed/tv/$imdb_id/$season_id-$episode_id"
),
array(
'name' => 'Server 4',
'url' => $type == 'movies' ? "https://vidsrc.xyz/embed/movie/$imdb_id" : "https://vidsrc.xyz/embed/tv/$imdb_id/$season_id-$episode_id"
),
);
$html = "
";
$num = 1;
// Loop through existing players (if any)
if (!empty($players) && is_array($players)) {
foreach ($players as $play) {
$source = zeta_isset($play, 'url');
$player_video = "
";
$player_video .= "
";
$player_video .= "
";
$html .= apply_filters('player_video_embed', $player_video, $play);
$num++;
}
}
// Add the predefined servers (Server 1, Server 2, etc.)
foreach ($predefined_servers as $server) {
$html .= "
";
$html .= "
";
$html .= "
";
$num++;
}
// Add the trailer player (if available)
if (!empty($trailer)) {
$html .= "
";
$html .= "
";
$html .= "
";
}
$html .= "
";
// Echo the final output
echo $html;
}
/**
* @since 1.0.0
* @version 1.0
*/
public function ajax() {
// Set URL IFRAME
$url_iframe = '';
$url_playselect = '';
$message = '';
$status = '';
// POST Data
$post_id = zeta_isset($_POST, 'post');
$post_ty = zeta_isset($_POST, 'type');
$play_nm = zeta_isset($_POST, 'nume');
// Verify data
if ($post_id && ($play_nm > 0 OR $play_nm == 'trailer')) {
// Get post meta
switch ($post_ty) {
case 'mv':
$postmeta = zeta_postmeta_movies($post_id);
break;
case 'tv':
case 'ss':
case 'ep':
$postmeta = zeta_postmeta_episodes($post_id);
break;
}
// Compose Player
$player = zeta_isset($postmeta, 'players');
$player = maybe_unserialize($player);
$player = apply_filters('ajax_videos', $player);
$pag = zeta_compose_pagelink('jwpage');
$url = ($play_nm != 'trailer') ? $this->ajax_isset($player, ($play_nm - 1), 'url') : false;
$typ = ($play_nm == 'trailer') ? 'trailer' : $this->ajax_isset($player, ($play_nm - 1), 'select');
$sub = ($play_nm != 'trailer') ? $this->ajax_isset($player, ($play_nm - 1), 'subt') : false;
$lng = ($play_nm != 'trailer') ? $this->ajax_isset($player, ($play_nm - 1), 'idioma') : false;
$cap = (isset($lng)) ? array_search($lng, $this->languages()) : '';
// Verify data
if ($typ) {
switch ($typ) {
case 'iframe':
$url_iframe = '';
break;
case 'mp4':
case 'gdrive':
$url_iframe = "{$pag}?source=" . urlencode($url) . "&sub=" . urlencode($sub) . "&lang=" . urlencode($cap) . "&capt=" . urlencode($lng) . "&id={$post_id}&type={$typ}";
break;
case 'ztshcode':
$url_iframe = do_shortcode($url);
break;
case 'trailer':
$url_iframe = zeta_trailer_iframe_url_embed(zeta_isset($postmeta, 'youtube_id'), 1);
break;
}
}
}
$url_iframe = apply_filters('ajax_video_url', $url_iframe, $player);
$message = apply_filters('ajax_video_message', $message);
$status = apply_filters('ajax_video_status', $status);
// End Action
wp_send_json(array('embed_url' => $url_iframe, 'type' => $typ, 'msg' => $message));
}
/**
* @since 1.0.0
* @version 1.0
*/
public function ajax_isset($data = array(), $n = '', $k = '') {
return (isset($data[$n][$k])) ? $data[$n][$k] : false;
}
}
Kim Sun-young – 123Movies