Exemple #1
0
 /**
  * Function to validate video file
  *
  * @return string
  */
 public function validateFile()
 {
     $file_url = isset($_POST['file_url']) ? $_POST['file_url'] : '';
     $file_type = isset($_POST['file_type']) ? $_POST['file_type'] : '';
     if ($file_type == 'youtube') {
         $content = JSNPbVideoHelper::getYoutubeVideoInfo($file_url);
         $info = json_decode($content);
         if (count($info)) {
             $data = array();
             $content = '';
             $content .= 'Title' . ': <b>' . (string) $info->title . '</b><br>';
             $content .= 'Author Name' . ': <b>' . (string) $info->author_name . '</b><br>';
             $info->description = isset($info->description) ? JSNPagebuilderHelpersShortcode::pbTrimWords((string) $info->description, 20) : '';
             $content .= 'Description' . ': <b>' . (string) $info->description . '</b><br>';
             $data['content'] = $content;
             $data['type'] = 'video';
             // Check if url had this format "list=SJHkjhlKJHSA".
             $pattern = '#list=[A-Za-z0-9^/]*#i';
             if (preg_match($pattern, $file_url) && stripos($info->html, 'videoseries?') === false) {
                 $data['type'] = 'list';
             }
             exit(json_encode($data));
         }
     } else {
         if ($file_type == 'vimeo') {
             $content = JSNPbVideoHelper::getVimeoVideoInfo($file_url);
             $info = json_decode($content);
             if (count($info)) {
                 $data = array();
                 $content = '';
                 $content .= 'Title' . ': <b>' . (string) $info->title . '</b><br>';
                 $content .= 'Author Name' . ': <b>' . (string) $info->author_name . '</b><br>';
                 $info->description = isset($info->description) ? JSNPagebuilderHelpersShortcode::pbTrimWords((string) $info->description, 20) : '';
                 $content .= 'Description' . ': <b>' . (string) $info->description . '</b><br>';
                 $data['content'] = $content;
                 exit(json_encode($data));
             }
         }
     }
     exit('false');
 }
Exemple #2
0
 /**
  * Generate HTML for Youtube
  *
  * @return string
  */
 function generate_youtube($params)
 {
     $random_id = JSNPagebuilderHelpersShortcode::generateRandomString();
     $_w = ' width="' . $params['video_youtube_dimension_width'] . '" ';
     $_h = $params['video_youtube_dimension_height'] ? ' height="' . $params['video_youtube_dimension_height'] . '" ' : '';
     // Alignment
     $container_class = '';
     $object_style = '';
     if ($params['video_alignment'] === 'right') {
         $object_style .= 'float:right;';
         $container_class .= 'clearafter ';
     } else {
         if ($params['video_alignment'] === 'center') {
             $object_style .= 'margin: 0 auto;';
         } else {
             if ($params['video_alignment'] === 'left') {
                 $object_style .= 'float:left;';
                 $container_class .= 'clearafter ';
             }
         }
     }
     // Genarate Container class
     $container_class = $container_class ? 'class="' . $container_class . '" ' : '';
     // Margin.
     $container_style = '';
     $container_style .= isset($params['video_margin_left']) && $params['video_margin_left'] != '' ? 'margin-left:' . $params['video_margin_left'] . 'px;' : '';
     $container_style .= isset($params['video_margin_top']) && $params['video_margin_top'] != '' ? 'margin-top:' . $params['video_margin_top'] . 'px;' : '';
     $container_style .= isset($params['video_margin_right']) && $params['video_margin_right'] != '' ? 'margin-right:' . $params['video_margin_right'] . 'px;' : '';
     $container_style .= isset($params['video_margin_bottom']) && $params['video_margin_bottom'] != '' ? 'margin-bottom:' . $params['video_margin_bottom'] . 'px;' : '';
     $container_style = $container_style ? ' style=" ' . $container_style . ' " ' : '';
     $params['video_source_link_youtube'] = urldecode($params['video_source_link_youtube']);
     // Get video ID.
     $video_info = JSNPbVideoHelper::getYoutubeVideoInfo($params['video_source_link_youtube']);
     $video_info = json_decode($video_info);
     if (!$video_info) {
         return;
     }
     $video_info = $video_info->html;
     $_arr = array();
     $video_src = '';
     preg_match('/src\\s*\\n*=\\s*\\n*"([^"]*)"/i', $video_info, $_arr);
     if (count($_arr)) {
         // Check if video url included playlist id.
         $pattern = '#list=([A-Za-z0-9^/]*)#i';
         $matches = array();
         preg_match_all($pattern, $params['video_source_link_youtube'], $matches, PREG_SET_ORDER);
         if (count($matches)) {
             if (isset($params['video_youtube_show_list']) && $params['video_youtube_show_list'] == '1') {
                 $video_src = 'http://www.youtube.com/embed?listType=playlist&list=';
                 $_list_id = $matches[0][1];
                 $video_src .= $_list_id;
                 $video_src .= '&innerframe=true';
             } else {
                 $video_src = $_arr[1];
                 $video_src .= '&innerframe=true';
             }
         } else {
             $video_src = $_arr[1];
             $video_src .= '&innerframe=true';
         }
         $video_src .= isset($params['video_youtube_autoplay']) ? '&autoplay=' . (int) $params['video_youtube_autoplay'] : '';
         $video_src .= isset($params['video_youtube_autohide']) ? '&autohide=' . (int) $params['video_youtube_autohide'] : '';
         $video_src .= isset($params['video_youtube_controls']) ? '&controls=' . (int) $params['video_youtube_controls'] : '';
         // Specific playlist id for feature loop youtube video.
         $videoYoutubeLoop = isset($params['video_youtube_loop']) ? $params['video_youtube_loop'] == '1' ? true : false : false;
         if ($videoYoutubeLoop) {
             $video_src .= '&loop=1';
             $youtube_id = isset($params['video_source_link_youtube']) ? $this->getYoutubeID($params['video_source_link_youtube']) : '';
             $video_src .= $youtube_id ? '&playlist=' . $youtube_id : '';
         }
         $video_src .= isset($params['video_youtube_cc']) && (int) $params['video_youtube_cc'] == 1 ? '&cc_load_policy =1' : '';
     }
     $video_src .= '&showinfo=0';
     $embed = '<div ' . $container_class . $container_style . '>';
     $embed .= '<iframe style="display:block;' . $object_style . '" ' . $_w . $_h . 'src="' . $video_src . '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
     $embed .= '</div>';
     $embed .= '<div class="clear:both"></div>';
     return $embed;
 }