post_id = $post_id; $this->args = $args; $this->reference_id = $reference_id; if ( $this->post_id > 0 ) { $this->post_type = get_post_type( $this->post_id ); $this->post_title = get_the_title( $this->post_id ); } } /** * Get the options that can be passed through the WP filter hooks. * * @since 3.5.0 * @return array Player options. */ public function get_params() { $params = array( 'uid' => $this->reference_id, 'post_id' => $this->post_id, 'post_type' => $this->post_type, 'post_title' => $this->post_title, 'embed_url' => $this->embed_url ); // Output return array_merge( $params, $this->args ); } /** * Get the videos. * * @since 3.5.0 * @return array $videos Array of videos. */ public function get_videos() { if ( isset( $this->cache['videos'] ) ) { return $this->cache['videos']; } $defaults = array( 'mp4' => '', 'webm' => '', 'ogv' => '', 'hls' => '', 'dash' => '', 'youtube' => '', 'vimeo' => '', 'dailymotion' => '', 'rumble' => '', 'facebook' => '' ); $videos = shortcode_atts( $defaults, $this->args ); // Is a video post? if ( $this->post_id > 0 && 'aiovg_videos' == $this->post_type ) { $source_type = get_post_meta( $this->post_id, 'type', true ); switch ( $source_type ) { case 'adaptive': $hls = get_post_meta( $this->post_id, 'hls', true ); if ( ! empty( $hls ) ) { $videos['hls'] = $hls; } $dash = get_post_meta( $this->post_id, 'dash', true ); if ( ! empty( $dash ) ) { $videos['dash'] = $dash; } break; case 'youtube': case 'vimeo': case 'dailymotion': case 'rumble': case 'facebook': $src = get_post_meta( $this->post_id, $source_type, true ); if ( ! empty( $src ) ) { $videos[ $source_type ] = $src; } break; case 'embedcode': $embedcode = get_post_meta( $this->post_id, 'embedcode', true ); if ( ! empty( $embedcode ) ) { $iframe_src = aiovg_extract_iframe_src( $embedcode ); if ( $iframe_src ) { $videos['iframe'] = $iframe_src; } else { $videos['embedcode'] = $embedcode; } } break; default: $mp4 = get_post_meta( $this->post_id, 'mp4', true ); if ( ! empty( $mp4 ) ) { $videos['mp4'] = $mp4; } $webm = get_post_meta( $this->post_id, 'webm', true ); if ( ! empty( $webm ) ) { $videos['webm'] = $webm; } $ogv = get_post_meta( $this->post_id, 'ogv', true ); if ( ! empty( $ogv ) ) { $videos['ogv'] = $ogv; } $quality_level = get_post_meta( $this->post_id, 'quality_level', true ); if ( ! empty( $quality_level ) ) { $videos['quality_level'] = $quality_level; } $sources = get_post_meta( $this->post_id, 'sources', true ); if ( ! empty( $sources ) && is_array( $sources ) ) { foreach ( $sources as $index => $source ) { $sources[ $index ]['src'] = aiovg_resolve_url( $source['src'] ); } $videos['sources'] = $sources; } break; } } // Resolve relative file paths as absolute URLs if ( ! empty( $videos['mp4'] ) ) { $videos['mp4'] = aiovg_resolve_url( $videos['mp4'] ); } if ( ! empty( $videos['webm'] ) ) { $videos['webm'] = aiovg_resolve_url( $videos['webm'] ); } if ( ! empty( $videos['ogv'] ) ) { $videos['ogv'] = aiovg_resolve_url( $videos['ogv'] ); } // Set embed URL if available if ( isset( $videos['iframe'] ) ) { $this->embed_url = $videos['iframe']; } // Output $this->cache['videos'] = $videos; return $videos; } /** * Get the video tracks. * * @since 3.5.0 * @return array $tracks Array of video tracks. */ public function get_tracks() { if ( isset( $this->cache['tracks'] ) ) { return $this->cache['tracks']; } $tracks = array(); if ( $this->post_id > 0 && 'aiovg_videos' == $this->post_type ) { $tracks = get_post_meta( $this->post_id, 'track' ); foreach ( $tracks as $index => $track ) { $tracks[ $index ]['src'] = aiovg_resolve_url( $track['src'] ); } } // Output $this->cache['tracks'] = $tracks; return $tracks; } /** * Get the video chapters. * * @since 3.6.0 * @return array $chapters Array of video chapters. */ public function get_chapters() { if ( isset( $this->cache['chapters'] ) ) { return $this->cache['chapters']; } $chapters = array(); if ( $this->post_id > 0 && 'aiovg_videos' == $this->post_type ) { $chapters = get_post_meta( $this->post_id, 'chapter' ); foreach ( $chapters as $index => $chapter ) { $chapters[ $index ]['label'] = sanitize_text_field( $chapter['label'] ); $chapters[ $index ]['time'] = (float) $chapter['time']; } } // Output $this->cache['chapters'] = $chapters; return $chapters; } /** * Get the poster image. * * @since 3.5.0 * @return array $poster Poster image URL. */ public function get_poster() { if ( isset( $this->cache['poster'] ) ) { return $this->cache['poster']; } $poster = ''; if ( ! empty( $this->args['poster'] ) ) { $poster = aiovg_resolve_url( $this->args['poster'] ); } else { // Is a video post? if ( $this->post_id > 0 && 'aiovg_videos' == $this->post_type ) { $image_data = aiovg_get_image( $this->post_id, 'large' ); if ( ! empty( $image_data['src'] ) ) { $poster = aiovg_resolve_url( $image_data['src'] ); } } } if ( empty( $poster ) ) { $videos = $this->get_videos(); // YouTube if ( ! empty( $videos['youtube'] ) ) { $poster = aiovg_get_youtube_image_url( $videos['youtube'] ); } // Vimeo if ( ! empty( $videos['vimeo'] ) ) { $poster = aiovg_get_vimeo_image_url( $videos['vimeo'] ); } // Dailymotion if ( ! empty( $videos['dailymotion'] ) ) { $poster = aiovg_get_dailymotion_image_url( $videos['dailymotion'] ); } // Rumble if ( ! empty( $videos['rumble'] ) ) { $oembed = aiovg_get_rumble_oembed_data( $videos['rumble'] ); $poster = $oembed['thumbnail_url']; } } // Output $this->cache['poster'] = $poster; return $poster; } /** * Get the player settings. * * @since 3.5.0 * @return array $settings Player settings. */ public function get_player_settings() { if ( isset( $this->cache['player_settings'] ) ) { return $this->cache['player_settings']; } $player_settings = get_option( 'aiovg_player_settings' ); $defaults = array( 'width' => $player_settings['width'], 'ratio' => $player_settings['ratio'], 'preload' => $player_settings['preload'], 'playsinline' => isset( $player_settings['playsinline'] ) ? $player_settings['playsinline'] : 0, 'autoplay' => $player_settings['autoplay'], 'loop' => $player_settings['loop'], 'muted' => $player_settings['muted'], 'controls' => $player_settings['controls'], 'playpause' => isset( $player_settings['controls']['playpause'] ), 'current' => isset( $player_settings['controls']['current'] ), 'progress' => isset( $player_settings['controls']['progress'] ), 'duration' => isset( $player_settings['controls']['duration'] ), 'tracks' => isset( $player_settings['controls']['tracks'] ), 'chapters' => isset( $player_settings['controls']['chapters'] ), 'speed' => isset( $player_settings['controls']['speed'] ), 'quality' => isset( $player_settings['controls']['quality'] ), 'volume' => isset( $player_settings['controls']['volume'] ), 'fullscreen' => isset( $player_settings['controls']['fullscreen'] ), 'share' => isset( $player_settings['controls']['share'] ), 'embed' => isset( $player_settings['controls']['embed'] ), 'download' => isset( $player_settings['controls']['download'] ), 'hotkeys' => isset( $player_settings['hotkeys'] ) ? $player_settings['hotkeys'] : 0, 'cc_load_policy' => $player_settings['cc_load_policy'], 'use_native_controls' => $player_settings['use_native_controls'], 'lazyloading' => isset( $player_settings['lazyloading'] ) ? $player_settings['lazyloading'] : 0 ); $settings = shortcode_atts( $defaults, $this->args ); if ( empty( $settings['ratio'] ) ) { $settings['ratio'] = 56.25; } // Output $this->cache['player_settings'] = $settings; return $settings; } /** * Get the privacy settings. * * @since 3.5.0 * @return array $settings Privacy settings. */ public function get_privacy_settings() { if ( isset( $this->cache['privacy_settings'] ) ) { return $this->cache['privacy_settings']; } if ( isset( $_COOKIE['aiovg_gdpr_consent'] ) ) { $settings = array( 'show_consent' => false ); } else { $privacy_settings = get_option( 'aiovg_privacy_settings' ); $settings = shortcode_atts( $privacy_settings, $this->args ); if ( $settings['show_consent'] ) { $settings['consent_message'] = apply_filters( 'aiovg_translate_strings', $settings['consent_message'], 'consent_message' ); $settings['consent_button_label'] = apply_filters( 'aiovg_translate_strings', $settings['consent_button_label'], 'consent_button_label' ); } if ( empty( $settings['consent_message'] ) || empty( $settings['consent_button_label'] ) ) { $settings['show_consent'] = false; } } // Output $this->cache['privacy_settings'] = $settings; return $settings; } /** * Get the logo settings. * * @since 3.5.0 * @return array $settings Logo settings. */ public function get_logo_settings() { if ( isset( $this->cache['logo_settings'] ) ) { return $this->cache['logo_settings']; } $brand_settings = get_option( 'aiovg_brand_settings', array() ); $settings = shortcode_atts( $brand_settings, $this->args ); if ( ! empty( $settings['logo_image'] ) ) { $settings['logo_image'] = aiovg_resolve_url( $settings['logo_image'] ); } else { $settings['show_logo'] = false; } if ( ! empty( $settings['copyright_text'] ) ) { $settings['copyright_text'] = apply_filters( 'aiovg_translate_strings', $settings['copyright_text'], 'copyright_text' ); } // Output $this->cache['logo_settings'] = $settings; return $settings; } /** * Get the share buttons. * * @since 3.5.0 * @return array Share buttons. */ public function get_share_buttons() { if ( isset( $this->cache['share_buttons'] ) ) { return $this->cache['share_buttons']; } $socialshare_settings = get_option( 'aiovg_socialshare_settings' ); $share_url = get_permalink( $this->post_id ); $share_title = $this->post_title; $share_title = str_replace( ' ', '%20', $share_title ); $share_title = str_replace( '|', '%7C', $share_title ); $share_title = str_replace( '@', '%40', $share_title ); $share_image = $this->get_poster(); $share_buttons = array(); if ( isset( $socialshare_settings['services']['facebook'] ) ) { $share_buttons[] = array( 'service' => 'facebook', 'url' => "https://www.facebook.com/sharer/sharer.php?u={$share_url}", 'icon' => 'aiovg-icon-facebook', 'text' => __( 'Facebook', 'all-in-one-video-gallery' ) ); } if ( isset( $socialshare_settings['services']['twitter'] ) ) { $share_buttons[] = array( 'service' => 'twitter', 'url' => "https://twitter.com/intent/tweet?text={$share_title}&url={$share_url}", 'icon' => 'aiovg-icon-twitter', 'text' => __( 'Twitter', 'all-in-one-video-gallery' ) ); } if ( isset( $socialshare_settings['services']['linkedin'] ) ) { $share_buttons[] = array( 'service' => 'linkedin', 'url' => "https://www.linkedin.com/shareArticle?url={$share_url}&title={$share_title}", 'icon' => 'aiovg-icon-linkedin', 'text' => __( 'Linkedin', 'all-in-one-video-gallery' ) ); } if ( isset( $socialshare_settings['services']['pinterest'] ) ) { $pinterest_url = "https://pinterest.com/pin/create/button/?url={$share_url}&description={$share_title}"; if ( ! empty( $share_image ) ) { $pinterest_url .= "&media={$share_image}"; } $share_buttons[] = array( 'service' => 'pinterest', 'url' => $pinterest_url, 'icon' => 'aiovg-icon-pinterest', 'text' => __( 'Pinterest', 'all-in-one-video-gallery' ) ); } if ( isset( $socialshare_settings['services']['tumblr'] ) ) { $tumblr_url = "https://www.tumblr.com/share/link?url={$share_url}&name={$share_title}"; $share_description = aiovg_get_excerpt( $this->post_id, 160, '', false ); if ( ! empty( $share_description ) ) { $share_description = str_replace( ' ', '%20', $share_description ); $share_description = str_replace( '|', '%7C', $share_description ); $share_description = str_replace( '@', '%40', $share_description ); $tumblr_url .= "&description={$share_description}"; } $share_buttons[] = array( 'service' => 'tumblr', 'url' => $tumblr_url, 'icon' => 'aiovg-icon-tumblr', 'text' => __( 'Tumblr', 'all-in-one-video-gallery' ) ); } if ( isset( $socialshare_settings['services']['whatsapp'] ) ) { if ( wp_is_mobile() ) { $whatsapp_url = "whatsapp://send?text={$share_title} " . rawurlencode( $share_url ); } else { $whatsapp_url = "https://api.whatsapp.com/send?text={$share_title} {$share_url}"; } $share_buttons[] = array( 'service' => 'whatsapp', 'url' => $whatsapp_url, 'icon' => 'aiovg-icon-whatsapp', 'text' => __( 'WhatsApp', 'all-in-one-video-gallery' ) ); } $share_buttons = apply_filters( 'aiovg_player_socialshare_buttons', $share_buttons ); // Output $this->cache['share_buttons'] = $share_buttons; return $share_buttons; } /** * Get the video embedcode. * * @since 3.5.0 * @return string $embedcode Video embedcode. */ public function get_embedcode() { if ( isset( $this->cache['embedcode'] ) ) { return $this->cache['embedcode']; } $player_settings = $this->get_player_settings(); $embedcode = sprintf( '
', (float) $player_settings['ratio'], esc_url( aiovg_get_player_page_url( $this->post_id, $this->args ) ), esc_attr( $this->post_title ) ); // Output $this->cache['embedcode'] = $embedcode; return $embedcode; } /** * Get the video file download URL. * * @since 3.5.0 * @return string Video file download URL. */ public function get_download_url() { if ( isset( $this->cache['download_url'] ) ) { return $this->cache['download_url']; } $videos = $this->get_videos(); $download_url = ''; if ( ! empty( $videos['mp4'] ) ) { $can_download = 1; // Is a video post? if ( $this->post_id > 0 && 'aiovg_videos' == $this->post_type ) { if ( metadata_exists( 'post', $this->post_id, 'download' ) ) { $can_download = (int) get_post_meta( $this->post_id, 'download', true ); } if ( $can_download ) { $download_url = home_url( '?vdl=' . $this->post_id ); } } if ( empty( $download_url ) && $can_download ) { $download_url = home_url( '?vdl=' . aiovg_get_temporary_file_download_id( $videos['mp4'] ) ); } } // Output $this->cache['download_url'] = $download_url; return $download_url; } /** * Get the raw player embedcode. * * @since 3.5.0 * @return string $html Player HTML. */ public function get_player_raw_embed() { $videos = $this->get_videos(); wp_enqueue_script( AIOVG_PLUGIN_SLUG . '-player' ); $settings = array( 'post_id' => $this->post_id, 'post_type' => 'aiovg_videos' ); $html = sprintf( '