avpa_includes(); } public function avpa_includes() { if (is_admin()) { add_filter('plugin_action_links', 'avpa_action_links', 10, 2); } add_action('admin_menu', 'avpa_add_options_menu'); add_action('wp_enqueue_scripts', 'avpa_enqueue_scripts'); add_action('wp_head', 'avpa_header'); add_shortcode('avpa', 'avpa_embed_handler'); add_action('wp_ajax_avpa_video_tracking_action', 'avpa_video_tracking_action'); add_action('wp_ajax_nopriv_avpa_video_tracking_action', 'avpa_video_tracking_action'); add_action('init', 'avpa_custom_post_type'); add_filter('widget_text', 'do_shortcode'); add_filter('the_excerpt', 'do_shortcode', 11); add_filter('the_content', 'do_shortcode', 11); } } $GLOBALS['advancedVideoPlayerAnalytics'] = new advancedVideoPlayerAnalytics(); } function avpa_action_links($links, $file) { if ($file == plugin_basename(dirname(__FILE__) . '/videojs-html5-player.php')) { $links[] = '' . __('Settings', 'avpa') . ''; } return $links; } function avpa_add_options_menu() { if (is_admin()) { if (is_admin()) { add_options_page(__('Avpa Settings', 'avpa'), __('Advanced Video Player with Analytics', 'avpa'), 'manage_options', 'avpa', 'avpa_options_page'); /** * Creating Setting */ add_action('admin_init', 'avpa_settings_options'); /** * Enqueue Assets */ wp_enqueue_style("VideoAnalyticesStyle", plugins_url('', __FILE__) . "/assets/admin.css"); wp_enqueue_script('media-upload'); wp_enqueue_media(); wp_enqueue_script("VideoAnalyticesScript", plugins_url('', __FILE__) . "/assets/admin.js", '', '', true); /** * Creating Plugin Pgae */ add_menu_page( 'AVPA', 'AVPA', 'manage_options', 'video_analytices', 'avpa_adminMediaCPTIndex', 'dashicons-admin-media', 85 ); add_submenu_page( null, 'Video detail', 'Video detail', 'manage_options', 'video-detail-page', 'avpa_video_detail_callback' ); } } } function avpa_options_page() { echo 'homepage'; } function avpa_enqueue_scripts() { } function avpa_header() { if (!is_admin()) { $config = ' '; echo $config; } } function avpa_embed_handler($atts) { wp_enqueue_script('jquery'); wp_register_style('videoCSS', AVPA_PLUGIN_URL . '/videojs/video-js.min.css'); wp_enqueue_style('videoCSS'); wp_register_script('videojs', AVPA_PLUGIN_URL . '/videojs/video.min.js', array('jquery'), AVPA_VIDEOJS_VERSION, true); wp_enqueue_script('videojs'); wp_register_script('youtubejs', AVPA_PLUGIN_URL . '/videojs/youtube.min.js', array('jquery'), 1, true); wp_enqueue_script('youtubejs'); wp_register_script('avpa-ajax-script', AVPA_PLUGIN_URL . '/js/avpa-ajax-script.js', array('jquery'), 1, true); wp_localize_script( 'avpa-ajax-script', 'avpa_ajax', array( 'url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('avpa-ajax-nonce'), ) ); wp_enqueue_script('avpa-ajax-script'); extract(shortcode_atts(array( 'src' => '', 'webm' => '', 'ogv' => '', 'width' => '', 'height' => '', 'controls' => '', 'preload' => 'auto', 'autoplay' => '0', 'loop' => '', 'muted' => '', 'poster' => '', 'class' => '', 'theme' => '', ), $atts)); if (empty($src)) { return __('you need to specify the src of the video file', 'avpa'); } $src_raw = $src; //src $src = ''; if (!empty($webm)) { $webm_src = ''; $src = $src . $webm_src; } if (!empty($ogv)) { $ogv = ''; $src = $src . $ogv; } //controls $controls = $controls == true ? ' controls' : ''; if(empty($controls)){ $controls = (get_option('controls') == 0)?'': ' controls'; } //preload if ($preload == "metadata") { $preload = ' preload="metadata"'; } else if ($preload == "none") { $preload = ' preload="none"'; } else { $preload = ' preload="auto"'; } //autoplay $autoplay_option = ''; // if($autoplay == true){ // $autoplay_option == ' autoplay'; // } // if($autoplay == 0 && !$autoplay_option){ // $autoplay_option = (get_option('autoplay') == 1)?' autoplay': ' '; // } //loop $loop = $loop == true ? ' loop' : ''; if(empty($loop)){ $loop = (get_option('loop') == 1)?' loop': ''; } //muted $muted = $muted == true ? " muted" : ''; //poster $poster = $poster? $poster: ''; if (empty($poster)) { $poster = (get_option('poster') == '')?'': get_option('poster'); } // if(apva_checkRemoteFile($poster)){ // $poster = ' poster="' . $poster . '"'; // }else{ // $poster = ''; // } // Theme $themeClass = $theme != '' ? $theme : 'city'; //player id genration $resp = avpa_generate_video_id($src_raw); $post_id = $resp['post_id']; //playsinline $playsinline = ' playsinline'; $player = "avpa_" . $post_id; $session = $resp['session_id']; //custom style $style = ''; if (!empty($width)) { $style .=""; }else{ $style =""; } //width if ($width) { $width = ' width="' . $width . '"'; } else { $width = ""; } //height if ($height) { $height = ' height="' . $height . '"'; } else { $style .=""; } $script = ""; switch($webm){ case 'youtube': $output = <<<_HTML $script $style _HTML; break; case 'vimeo': $output = <<<_HTML $script $style _HTML; break; default: $output = <<<_HTML $script $style _HTML; } return $output; } function avpa_video_tracking_action() { // nonce check for an extra layer of security, the function will exit if it fails if (!wp_verify_nonce($_REQUEST['_ajax_nonce'], "avpa-ajax-nonce")) { exit("Woof Woof Woof"); } $lengthOfVideo = sanitize_text_field($_REQUEST["lengthOfVideo"]); $whereYouAt = sanitize_text_field($_REQUEST["whereYouAt"]); $session = sanitize_text_field($_REQUEST["session"]); $webm = esc_url_raw($_REQUEST["webm"]); $status = sanitize_text_field($_REQUEST["status"]); $resp = avpa_generate_video_id($webm, $whereYouAt, $lengthOfVideo, $status, $session); if (isset($resp['status'])) { echo json_encode(['status' => $resp['status'], 'session_id' => $resp['session_id']], true); die(); } echo 1; die(); } function avpa_custom_post_type() { register_post_type('avpa_vidoes', array( 'labels' => array( 'name' => __('Videos Analytics', 'textdomain'), 'singular_name' => __('Video Analytics', 'textdomain'), ), 'public' => false, 'has_archive' => true, //'show_ui' => false ) ); } function avpa_generate_video_id($video_url, $watching_at = '', $duration = '', $status = '', $session_id = '') { //0 if user not logged $watching_user = get_current_user_id(); $title = esc_html($video_url); $post_type = 'avpa_vidoes'; //check user watching status if (!$session_id) { $session_id = strtotime(date('Y-m-d H:i:s')); } //check video exists $post = get_page_by_title($title, 'ARRAY_A', $post_type); if (!isset($post['ID'])) { $post_arr = array( 'post_title' => $title, 'post_content' => 'Video Tracking', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_type' => $post_type, ); $post_id = wp_insert_post($post_arr); } else { $post_id = $post['ID']; } if ($watching_at) { //update or create meta //checking user watch session update_post_meta($post_id, 'avp_user_id__' . $watching_user . '__' . $session_id, $watching_user); update_post_meta($post_id, 'avp_watch_time__' . $watching_user . '__' . $session_id, $watching_at); update_post_meta($post_id, 'avp_duration__' . $watching_user . '__' . $session_id, $duration); update_post_meta($post_id, 'avp_watch_status__' . $watching_user . '__' . $session_id, $status); update_post_meta($post_id, 'avp_watching_time__' . $watching_user . '__' . $session_id, date('Y-m-d H:i:s')); } $return = ['session_id' => $session_id, 'post_id' => $post_id]; if ($status == 'completed') { $session_id = strtotime(date('Y-m-d H:i:s')); $return['session_id'] = $session_id; $return['status'] = 'completed'; } return $return; } function avpa_adminMediaCPTIndex() { return require_once(plugin_dir_path(__FILE__) . "/admin.php"); } function avpa_ManagerApi($input) { $output = get_option('videoFields'); if(isset($_POST['remove_post'])): unset($output[$_POST['remove_post']]); return $output; endif; if(count($output) == 0): $output[$input['meidaId']] = $input; return $output; endif; if($input['optionType'] === "add"): if(array_key_exists($input['meidaId'], $output)): $it = end($output); $input['meidaId'] = $it['meidaId'] + 1; endif; else: $input['optionType'] = 'add'; endif; if($output != ""): foreach($output as $key => $val): if($input['meidaId'] === $key): $output[$key] = $input; else: $output[$input['meidaId']] = $input; endif; endforeach; endif; return $output; } function avpa_SectionsApi() {} function avpaTheme($args) { $name = $args['label_for']; $optionName = $args['optionName']; ?>