Example #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');
 }
Example #2
0
    /**
     * Generate HTML for Vimeo
     *
     * @return string
     */
    function generate_vimeo($params)
    {
        $random_id = JSNPagebuilderHelpersShortcode::generateRandomString();
        $_w = ' width="' . $params['video_vimeo_dimension_width'] . '" ';
        $_h = $params['video_vimeo_dimension_height'] ? ' height="' . $params['video_vimeo_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 . ' " ' : '';
        // Get video ID.
        $params['video_source_link_vimeo'] = urldecode($params['video_source_link_vimeo']);
        $video_info = JSNPbVideoHelper::getVimeoVideoInfo($params['video_source_link_vimeo']);
        $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)) {
            $video_src = $_arr[1];
            $video_src .= '?innerframe=true';
            $video_src .= isset($params['video_vimeo_autoplay']) ? '&autoplay=' . (string) $params['video_vimeo_autoplay'] : '';
            $video_src .= isset($params['video_vimeo_loop']) ? '&loop=' . (string) $params['video_vimeo_loop'] : '';
            $video_src .= isset($params['video_vimeo_title']) ? '&title=' . (string) $params['video_vimeo_title'] : '';
            $video_src .= isset($params['video_vimeo_color']) ? '&color=' . str_replace('#', '', (string) $params['video_vimeo_color']) : '';
        }
        $embed = '<div ' . $container_class . $container_style . '>';
        $embed .= '<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen style="display:block;' . $object_style . '" ' . $_w . $_h . '"
src="' . $video_src . '" frameborder="0"></iframe>';
        $embed .= '</div>';
        $embed .= '<div class="clear:both"></div>';
        return $embed;
    }