2013-10-08 12:24:07 +00:00
< ? php
2016-03-11 05:44:44 -08:00
/**
* File : Video Functions
* Description : Various functions to perform operations on VIDEOS section
* @ license : Attribution Assurance License
* @ since : ClipBucket 1.0
* @ author [ s ] : Arslan Hassan , Fawaz Tahir , Fahad Abbass , Saqib Razzaq
2017-01-10 12:49:44 +05:00
* @ copyright : ( c ) 2008 - 2017 ClipBucket / PHPBucket
2016-03-11 05:44:44 -08:00
* @ notice : Please maintain this section
2017-01-10 12:49:44 +05:00
* @ modified : { January 10 th , 2017 } { Saqib Razzaq } { Updated copyright date }
2016-03-11 05:44:44 -08:00
*/
function get_video_fields ( $extra = null ) {
global $cb_columns ;
return $cb_columns -> set_object ( 'videos' ) -> get_columns ( $extra );
}
/**
* Function used to check video is playlable or not
2016-03-11 05:46:08 -08:00
* @ param : { string / id } { $id } { id of key of video }
* @ return : { boolean } { true if playable , else false }
2016-03-11 05:44:44 -08:00
*/
2016-03-11 05:46:08 -08:00
function video_playable ( $id ) {
2016-03-11 05:44:44 -08:00
global $cbvideo , $userquery ;
2016-03-11 05:46:08 -08:00
if ( isset ( $_POST [ 'watch_protected_video' ])) {
2016-03-11 05:44:44 -08:00
$video_password = mysql_clean ( post ( 'video_password' ));
2016-03-11 05:46:08 -08:00
} else {
2016-03-11 05:44:44 -08:00
$video_password = '' ;
2016-03-11 05:46:08 -08:00
}
2016-03-11 05:44:44 -08:00
2016-03-11 05:46:08 -08:00
if ( ! is_array ( $id )) {
2016-03-11 05:44:44 -08:00
$vdo = $cbvideo -> get_video ( $id );
2016-03-11 05:46:08 -08:00
} else {
2016-03-11 05:44:44 -08:00
$vdo = $id ;
2016-03-11 05:46:08 -08:00
}
2016-03-11 05:44:44 -08:00
$uid = userid ();
2016-03-11 05:46:08 -08:00
if ( ! $vdo ) {
2016-03-11 05:44:44 -08:00
e ( lang ( " class_vdo_del_err " ));
2013-10-08 12:24:07 +00:00
return false ;
2016-03-11 05:46:08 -08:00
} elseif ( $vdo [ 'status' ] != 'Successful' ) {
2016-03-11 05:44:44 -08:00
e ( lang ( " this_vdo_not_working " ));
2016-03-11 05:46:08 -08:00
if ( ! has_access ( 'admin_access' , TRUE )) {
2016-03-11 05:44:44 -08:00
return false ;
2016-03-11 05:46:08 -08:00
} else {
2016-03-11 05:44:44 -08:00
return true ;
2016-03-11 05:46:08 -08:00
}
} elseif ( $vdo [ 'broadcast' ] == 'private'
2016-03-11 05:44:44 -08:00
&& ! $userquery -> is_confirmed_friend ( $vdo [ 'userid' ], userid ())
&& ! is_video_user ( $vdo )
&& ! has_access ( 'video_moderation' , true )
&& $vdo [ 'userid' ] != $uid ){
e ( lang ( 'private_video_error' ));
2013-10-08 12:24:07 +00:00
return false ;
2016-03-11 05:46:08 -08:00
} elseif ( $vdo [ 'active' ] == 'pen' ) {
2016-03-11 05:44:44 -08:00
e ( lang ( " video_in_pending_list " ));
2016-03-11 05:46:08 -08:00
if ( has_access ( 'admin_access' , TRUE ) || $vdo [ 'userid' ] == userid ()) {
2016-03-11 05:44:44 -08:00
return true ;
2016-03-11 05:46:08 -08:00
} else {
2016-03-11 05:44:44 -08:00
return false ;
2016-03-11 05:46:08 -08:00
}
} elseif ( $vdo [ 'broadcast' ] == 'logged'
2016-03-11 05:44:44 -08:00
&& ! userid ()
&& ! has_access ( 'video_moderation' , true )
2016-03-11 05:46:08 -08:00
&& $vdo [ 'userid' ] != $uid ) {
2016-03-11 05:44:44 -08:00
e ( lang ( 'not_logged_video_error' ));
return false ;
2016-09-16 16:20:26 +05:00
} elseif ( $vdo [ 'active' ] == 'no' && $vdo [ 'userid' ] != userid () ) {
2016-03-11 05:44:44 -08:00
e ( lang ( " vdo_iac_msg " ));
2016-03-11 05:46:08 -08:00
if ( ! has_access ( 'admin_access' , TRUE )) {
2016-03-11 05:44:44 -08:00
return false ;
2016-03-11 05:46:08 -08:00
} else {
2016-03-11 05:44:44 -08:00
return true ;
2016-03-11 05:46:08 -08:00
}
} elseif ( $vdo [ 'video_password' ]
2016-03-11 05:44:44 -08:00
&& $vdo [ 'broadcast' ] == 'unlisted'
&& $vdo [ 'video_password' ] != $video_password
&& ! has_access ( 'video_moderation' , true )
2016-03-11 05:46:08 -08:00
&& $vdo [ 'userid' ] != $uid ) {
if ( ! $video_password ) {
2016-03-11 05:44:44 -08:00
e ( lang ( " video_pass_protected " ));
2016-03-11 05:46:08 -08:00
} else {
2016-03-11 05:44:44 -08:00
e ( lang ( " invalid_video_password " ));
2016-03-11 05:46:08 -08:00
}
2016-03-11 05:44:44 -08:00
template_files ( " blocks/watch_video/video_password.html " , false , false );
2016-03-11 05:46:08 -08:00
} else {
2016-03-11 05:44:44 -08:00
$funcs = cb_get_functions ( 'watch_video' );
2013-10-08 12:24:07 +00:00
2016-03-11 05:46:08 -08:00
if ( $funcs ) {
foreach ( $funcs as $func ) {
2016-03-11 05:44:44 -08:00
$data = $func [ 'func' ]( $vdo );
2016-03-11 05:46:08 -08:00
if ( $data ) {
2016-03-11 05:44:44 -08:00
return $data ;
2016-03-11 05:46:08 -08:00
}
2016-03-11 05:44:44 -08:00
}
2016-03-11 05:46:08 -08:00
}
2016-03-11 05:44:44 -08:00
return true ;
}
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:46:08 -08:00
2016-03-11 05:44:44 -08:00
/**
2016-03-11 05:46:08 -08:00
* FUNCTION USED TO GET THUMBNAIL
* @ param ARRAY video_details , or videoid will also work
*/
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
function get_thumb ( $vdetails , $num = 'default' , $multi = false , $count = false , $return_full_path = true , $return_big = true , $size = false ){
//echo $size;
global $db , $Cbucket , $myquery ;
$num = $num ? $num : 'default' ;
#checking what kind of input we have
if ( is_array ( $vdetails ))
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( empty ( $vdetails [ 'title' ]))
2014-09-19 06:32:00 +00:00
{
2016-03-11 05:44:44 -08:00
#check for videoid
if ( empty ( $vdetails [ 'videoid' ]) && empty ( $vdetails [ 'vid' ]) && empty ( $vdetails [ 'videokey' ]))
2013-10-08 12:24:07 +00:00
{
if ( $multi )
return $dthumb [ 0 ] = default_thumb ();
return default_thumb ();
}
2016-03-11 05:44:44 -08:00
else
{
if ( ! empty ( $vdetails [ 'videoid' ]))
$vid = $vdetails [ 'videoid' ];
elseif ( ! empty ( $vdetails [ 'vid' ]))
$vid = $vdetails [ 'vid' ];
elseif ( ! empty ( $vdetails [ 'videokey' ]))
$vid = $vdetails [ 'videokey' ];
else
{
if ( $multi )
return $dthumb [ 0 ] = default_thumb ();
return default_thumb ();
}
}
}
} else {
if ( is_numeric ( $vdetails ))
$vid = $vdetails ;
else
{
if ( $multi )
return $dthumb [ 0 ] = default_thumb ();
return default_thumb ();
2013-10-08 12:24:07 +00:00
}
}
2014-04-07 06:54:45 +00:00
2016-03-11 05:44:44 -08:00
#checking if we have vid , so fetch the details
if ( ! empty ( $vid ))
$vdetails = get_video_details ( $vid );
2013-10-08 12:24:07 +00:00
2014-09-19 06:32:00 +00:00
2016-03-11 05:44:44 -08:00
if ( empty ( $vdetails [ 'title' ]))
{
if ( $multi )
return default_thumb ();
2013-10-08 12:24:07 +00:00
return default_thumb ();
2016-03-11 05:44:44 -08:00
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
#Checking if there is any custom function for
if ( count ( $Cbucket -> custom_get_thumb_funcs ) > 0 )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
foreach ( $Cbucket -> custom_get_thumb_funcs as $funcs )
2013-10-08 12:24:07 +00:00
{
2015-08-24 11:05:09 +00:00
2016-03-11 05:44:44 -08:00
//Merging inputs
$in_array = array (
'num' => $num ,
'multi' => $multi ,
'count' => $count ,
'return_full_path' => $return_full_path ,
'return_big' => $return_big ,
'size' => $size
);
if ( ! empty ( $vdetails [ 'files_thumbs_path' ]) && $funcs == 'server_thumb' )
{
$funcs = " ms_server_thumb " ;
}
2015-08-24 11:05:09 +00:00
2016-03-11 05:44:44 -08:00
if ( function_exists ( $funcs ))
{
$func_returned = $funcs ( $vdetails , $in_array );
if ( $func_returned )
return $func_returned ;
}
2013-10-08 12:24:07 +00:00
}
}
2016-03-11 05:44:44 -08:00
// echo "hooooo";
#get all possible thumbs of video
$thumbDir = ( isset ( $vdetails [ 'file_directory' ]) && $vdetails [ 'file_directory' ]) ? $vdetails [ 'file_directory' ] : " " ;
if ( ! isset ( $vdetails [ 'file_directory' ])){
$justDate = explode ( " " , $vdetails [ 'date_added' ]);
$thumbDir = implode ( " / " , explode ( " - " , array_shift ( $justDate )));
}
if ( substr ( $thumbDir , ( strlen ( $thumbDir ) - 1 )) !== " / " ){
$thumbDir .= " / " ;
}
2014-04-07 06:43:12 +00:00
2016-03-11 05:44:44 -08:00
//$justDate = explode(" ", $vdetails['date_added']);
//$dateAdded = implode("/", explode("-", array_shift($justDate)));
$file_dir = " " ;
if ( isset ( $vdetails [ 'file_name' ]) && $thumbDir )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
$file_dir = " / " . $thumbDir ;
}
$vid_thumbs = glob ( THUMBS_DIR . " / " . $file_dir . $vdetails [ 'file_name' ] . " * " );
#replace Dir with URL
if ( is_array ( $vid_thumbs ))
foreach ( $vid_thumbs as $thumb )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( file_exists ( $thumb ) && filesize ( $thumb ) > 0 )
{
$thumb_parts = explode ( '/' , $thumb );
$thumb_file = $thumb_parts [ count ( $thumb_parts ) - 1 ];
//Saving All Thumbs
if ( ! is_big ( $thumb_file ) || $return_big ){
if ( $return_full_path )
$thumbs [] = THUMBS_URL . '/' . $thumbDir . $thumb_file ;
else
$thumbs [] = $thumb_file ;
}
//Saving Original Thumbs
if ( is_original ( $thumb_file )){
if ( $return_full_path )
$original_thumbs [] = THUMBS_URL . '/' . $thumbDir . $thumb_file ;
else
$original_thumbs [] = $thumb_file ;
}
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
} elseif ( file_exists ( $thumb ))
unlink ( $thumb );
}
#pr($thumbs,true);
if ( count ( $thumbs ) == 0 )
{
if ( $count )
return count ( $thumbs );
if ( $multi )
return $dthumb [ 0 ] = default_thumb ();
return default_thumb ();
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
else
{
//Initializing thumbs settings
$thumbs_res_settings = thumbs_res_settings_28 ();
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
if ( $multi ){
if ( ! empty ( $original_thumbs ) && $size == 'original' ){
return $original_thumbs ;
} else {
return $thumbs ;
}
2016-03-07 14:33:42 +05:00
}
2016-03-11 05:44:44 -08:00
if ( $count )
return count ( $thumbs );
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
//Now checking for thumb
if ( $num == 'default' )
{
$num = $vdetails [ 'default_thumb' ];
}
if ( $num == 'big' || $size == 'big' )
{
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$num = 'big-' . $vdetails [ 'default_thumb' ];
$num_big_28 = implode ( 'x' , $thumbs_res_settings [ '320' ]) . '-' . $vdetails [ 'default_thumb' ];
$big_thumb_cb26 = THUMBS_DIR . '/' . $vdetails [ 'file_name' ] . '-' . $num . '.jpg' ;
$big_thumb_cb27 = THUMBS_DIR . '/' . $thumbDir . $vdetails [ 'file_name' ] . '-' . $num . '.jpg' ;
$big_thumb_cb28 = THUMBS_DIR . '/' . $thumbDir . $vdetails [ 'file_name' ] . '-' . $num_big_28 . '.jpg' ;
if ( file_exists ( $big_thumb_cb26 )){
return THUMBS_URL . '/' . $vdetails [ 'file_name' ] . '-' . $num . '.jpg' ;
} elseif ( file_exists ( $big_thumb_cb27 )){
return THUMBS_URL . '/' . $thumbDir . $vdetails [ 'file_name' ] . '-' . $num . '.jpg' ;
} elseif ( file_exists ( $big_thumb_cb28 )){
return THUMBS_URL . '/' . $thumbDir . $vdetails [ 'file_name' ] . '-' . $num_big_28 . '.jpg' ;
}
2016-03-07 14:33:42 +05:00
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$default_thumb = array_find ( $vdetails [ 'file_name' ] . '-' . $size . '-' . $num , $thumbs );
if ( ! empty ( $default_thumb )){
2016-03-07 14:33:42 +05:00
return $default_thumb ;
}
2016-03-11 05:44:44 -08:00
elseif ( empty ( $default_thumb )){
$default_thumb = array_find ( $vdetails [ 'file_name' ] . '-' . $num , $thumbs );
if ( ! empty ( $default_thumb )){
return $default_thumb ;
} else {
return $thumbs [ 0 ];
}
}
2016-03-07 14:33:42 +05:00
}
2016-03-11 05:44:44 -08:00
2013-10-08 12:24:07 +00:00
}
2014-09-19 06:32:00 +00:00
2016-03-11 05:44:44 -08:00
/**
2016-03-18 18:05:42 +05:00
* Function used to check weaether given thumb is big or not
* @ param : { string } { $thumb_file } { the file to be checked for size }
* @ return : { boolean } { true if thumb is big , false }
*/
function is_big ( $thumb_file ) {
if ( strstr ( $thumb_file , 'big' )) {
2016-03-11 05:44:44 -08:00
return true ;
2016-03-18 18:05:42 +05:00
} else {
2016-03-11 05:44:44 -08:00
return false ;
2016-03-18 18:05:42 +05:00
}
2016-03-11 05:44:44 -08:00
}
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
/**
* Function used to check weaether given thumb is original or not
*/
function is_original ( $thumb_file )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( strstr ( $thumb_file , 'original' ))
return true ;
else
return false ;
}
function GetThumb ( $vdetails , $num = 'default' , $multi = false , $count = false )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
return get_thumb ( $vdetails , $num , $multi , $count );
}
/**
* function used to get detaulf thumb of ClipBucket
*/
function default_thumb ()
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( file_exists ( TEMPLATEDIR . '/images/thumbs/processing.png' ))
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
return TEMPLATEURL . '/images/thumbs/processing.png' ;
} elseif ( file_exists ( TEMPLATEDIR . '/images/thumbs/processing.jpg' ))
{
return TEMPLATEURL . '/images/thumbs/processing.jpg' ;
} else
return BASEURL . '/files/thumbs/processing.jpg' ;
}
/**
* Function used to check weather give thumb is deafult or not
*/
function is_default_thumb ( $i )
{
if ( getname ( $i ) == 'processing.jpg' )
return true ;
2013-10-08 12:24:07 +00:00
else
2016-03-11 05:44:44 -08:00
return false ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Function used to get video link
* @ param ARRAY video details
*/
function video_link ( $vdetails , $type = NULL )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $myquery ;
#checking what kind of input we have
if ( is_array ( $vdetails ))
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( empty ( $vdetails [ 'title' ]))
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
#check for videoid
if ( empty ( $vdetails [ 'videoid' ]) && empty ( $vdetails [ 'vid' ]) && empty ( $vdetails [ 'videokey' ]))
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
return BASEURL ;
} else {
if ( ! empty ( $vdetails [ 'videoid' ]))
$vid = $vdetails [ 'videoid' ];
elseif ( ! empty ( $vdetails [ 'vid' ]))
$vid = $vdetails [ 'vid' ];
elseif ( ! empty ( $vdetails [ 'videokey' ]))
$vid = $vdetails [ 'videokey' ];
else
return BASEURL ;
2013-10-08 12:24:07 +00:00
}
}
2016-03-11 05:44:44 -08:00
} else {
if ( is_numeric ( $vdetails ))
$vid = $vdetails ;
else
return BASEURL ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
#checking if we have vid , so fetch the details
if ( ! empty ( $vid ))
$vdetails = get_video_details ( $vid );
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
//calling for custom video link functions
$functions = cb_get_functions ( 'video_link' );
if ( $functions )
{
foreach ( $functions as $func )
{
$array = array ( 'vdetails' => $vdetails , 'type' => $type );
if ( function_exists ( $func [ 'func' ]))
{
$returned = $func [ 'func' ]( $array );
if ( $returned )
{
$link = $returned ;
return $link ;
break ;
}
}
}
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$plist = " " ;
if ( SEO == 'yes' ){
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
if ( $vdetails [ 'playlist_id' ])
2016-07-12 12:03:53 +05:00
$plist = '?play_list=' . $vdetails [ 'playlist_id' ];
2015-09-28 13:38:23 +00:00
2016-03-11 05:44:44 -08:00
$vdetails [ 'title' ] = strtolower ( $vdetails [ 'title' ]);
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
switch ( config ( 'seo_vido_url' ))
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
default :
$link = BASEURL . '/video/' . $vdetails [ 'videokey' ] . '/' . SEO ( clean ( str_replace ( ' ' , '-' , $vdetails [ 'title' ]))) . $plist ;
break ;
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
case 1 :
{
$link = BASEURL . '/' . SEO ( clean ( str_replace ( ' ' , '-' , $vdetails [ 'title' ]))) . '_v' . $vdetails [ 'videoid' ] . $plist ;
}
break ;
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
case 2 :
{
$link = BASEURL . '/video/' . $vdetails [ 'videoid' ] . '/' . SEO ( clean ( str_replace ( ' ' , '-' , $vdetails [ 'title' ]))) . $plist ;
}
break ;
case 3 :
{
$link = BASEURL . '/video/' . $vdetails [ 'videoid' ] . '_' . SEO ( clean ( str_replace ( ' ' , '-' , $vdetails [ 'title' ]))) . $plist ;
}
break ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
} else {
if ( $vdetails [ 'playlist_id' ])
$plist = '&play_list=' . $vdetails [ 'playlist_id' ];
$link = BASEURL . '/watch_video.php?v=' . $vdetails [ 'videokey' ] . $plist ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
if ( ! $type || $type == 'link' )
return $link ;
elseif ( $type == 'download' )
return BASEURL . '/download.php?v=' . $vdetails [ 'videokey' ];
}
//Function That will use in creating SEO urls
function VideoLink ( $vdetails , $type = NULL )
{
return video_link ( $vdetails , $type );
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* Function Used to format video duration
* @ param : array ( videoKey or ID , videok TITLE )
*/
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
function videoSmartyLink ( $params )
{
$link = VideoLink ( $params [ 'vdetails' ], $params [ 'type' ]);
if ( ! $params [ 'assign' ])
return $link ;
else
assign ( $params [ 'assign' ], $link );
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Function used to validate category
* INPUT $cat array
*/
function validate_vid_category ( $array = NULL )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $myquery , $LANG , $cbvid ;
if ( $array == NULL )
$array = $_POST [ 'category' ];
if ( count ( $array ) == 0 )
return false ;
else
{
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
foreach ( $array as $arr )
{
if ( $cbvid -> category_exists ( $arr ))
$new_array [] = $arr ;
}
}
if ( count ( $new_array ) == 0 )
{
e ( lang ( 'vdo_cat_err3' ));
return false ;
} elseif ( count ( $new_array ) > ALLOWED_VDO_CATS )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
e ( sprintf ( lang ( 'vdo_cat_err2' ), ALLOWED_VDO_CATS ));
return false ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
return true ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Function used to check videokey exists or not
* key_exists
*/
function vkey_exists ( $key )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
$db -> select ( tbl ( " video " ), " videokey " , " videokey=' $key ' " );
if ( $db -> num_rows > 0 )
return true ;
else
return false ;
}
/**
* Function used to check file_name exists or not
* as its a unique name so it will not let repost the data
*/
function file_name_exists ( $name )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
$results = $db -> select ( tbl ( " video " ), " videoid,file_name " , " file_name=' $name ' " );
if ( $db -> num_rows > 0 )
return $results [ 0 ][ 'videoid' ];
else
return false ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Function used to get video from conversion queue
*/
function get_queued_video ( $update = TRUE , $fileName = NULL )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
$max_conversion = config ( 'max_conversion' );
$max_conversion = $max_conversion ? $max_conversion : 2 ;
$max_time_wait = config ( 'max_time_wait' ); //Maximum Time Wait to make PRocessing Video Automatcially OK
$max_time_wait = $max_time_wait ? $max_time_wait : 7200 ;
//First Check How Many Videos Are In Queu Already
$processing = $db -> count ( tbl ( " conversion_queue " ), " cqueue_id " , " cqueue_conversion='p' " );
if ( true )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( $fileName )
{
$queueName = getName ( $fileName );
$ext = getExt ( $fileName );
$fileNameQuery = " AND cqueue_name =' $queueName ' AND cqueue_ext =' $ext ' " ;
}
$results = $db -> select ( tbl ( " conversion_queue " ), " * " , " cqueue_conversion='no' $fileNameQuery " , 1 );
$result = $results [ 0 ];
if ( $update )
$db -> update ( tbl ( " conversion_queue " ), array ( " cqueue_conversion " , " time_started " ), array ( " p " , time ()), " cqueue_id = ' " . $result [ 'cqueue_id' ] . " ' " );
return $result ;
} else
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
//Checking if video is taking more than $max_time_wait to convert so we can change its time to
//OK Automatically
//Getting All Videos That are being processed
$results = $db -> select ( tbl ( " conversion_queue " ), " * " , " cqueue_conversion='p' " );
foreach ( $results as $vid )
2013-10-08 12:24:07 +00:00
{
if ( $vid [ 'time_started' ])
2016-03-11 05:44:44 -08:00
{
if ( $vid [ 'time_started' ])
$time_started = $vid [ 'time_started' ];
else
$time_started = strtotime ( $vid [ 'date_added' ]);
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$elapsed_time = time () - $time_started ;
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
if ( $elapsed_time > $max_time_wait )
{
//CHanging Status TO OK
$db -> update ( tbl ( " conversion_queue " ), array ( " cqueue_conversion " ),
array ( " yes " ), " cqueue_id = ' " . $result [ 'cqueue_id' ] . " ' " );
}
2013-10-08 12:24:07 +00:00
}
}
2016-03-11 05:44:44 -08:00
return false ;
2013-10-08 12:24:07 +00:00
}
}
2016-03-11 05:44:44 -08:00
/**
* Function used to get video being processed
*/
function get_video_being_processed ( $fileName = NULL )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
if ( $fileName )
{
$queueName = getName ( $fileName );
$ext = getExt ( $fileName );
$fileNameQuery = " AND cqueue_name =' $queueName ' AND cqueue_ext =' $ext ' " ;
}
//$results = $db->select(tbl("conversion_queue"),"*","cqueue_conversion='p' $fileNameQuery");
$query = " SELECT * FROM " . tbl ( " conversion_queue " );
$query .= " WHERE cqueue_conversion='p' " ;
if ( isset ( $fileNameQuery ))
$query .= $fileNameQuery ;
$results = db_select ( $query );
if ( $results )
return $results ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
function get_video_details ( $vid = null , $basic = false ) {
global $cbvid ;
2014-09-29 11:02:53 +00:00
2016-03-11 05:44:44 -08:00
if ( $vid === null ) {
return false ;
}
2014-09-29 11:02:53 +00:00
2016-03-11 05:44:44 -08:00
return $cbvid -> get_video ( $vid , false , $basic );
}
2014-09-29 11:02:53 +00:00
2016-03-11 05:44:44 -08:00
function get_video_basic_details ( $vid ) {
global $cbvid ;
return $cbvid -> get_video ( $vid , false , true );
}
2014-09-29 11:02:53 +00:00
2016-03-11 05:44:44 -08:00
function get_video_details_from_filename ( $filename , $basic = false ) {
global $cbvid ;
return $cbvid -> get_video ( $filename , true , $basic );
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
function get_basic_video_details_from_filename ( $filename ) {
global $cbvid ;
return $cbvid -> get_video ( $filename , true , true );
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* Function used to get all video files
* @ param Vdetails
* @ param $count_only
* @ param $with_path
*/
function get_all_video_files ( $vdetails , $count_only = false , $with_path = false )
{
$details = get_video_file ( $vdetails , true , $with_path , true , $count_only );
if ( $count_only )
return count ( $details );
return $details ;
}
function get_all_video_files_smarty ( $params )
{
$vdetails = $params [ 'vdetails' ];
$count_only = $params [ 'count_only' ];
$with_path = $params [ 'with_path' ];
return get_all_video_files ( $vdetails , $count_only , $with_path );
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Function use to get video files
*/
function get_video_file ( $vdetails , $return_default = true , $with_path = true , $multi = false , $count_only = false , $hq = false )
{
global $Cbucket ;
# checking if there is any other functions
# available
if ( is_array ( $Cbucket -> custom_video_file_funcs ))
foreach ( $Cbucket -> custom_video_file_funcs as $func )
if ( function_exists ( $func ))
{
$func_returned = $func ( $vdetails , $hq );
if ( $func_returned )
return $func_returned ;
}
$fileDirectory = " " ;
if ( isset ( $vdetails [ 'file_directory' ]) && ! empty ( $vdetails [ 'file_directory' ])){
$fileDirectory = " { $vdetails [ 'file_directory' ] } / " ;
}
//dump($vdetails['file_name']);
#Now there is no function so lets continue as
if ( isset ( $vdetails [ 'file_name' ]))
$vid_files = glob ( VIDEOS_DIR . " / " . $fileDirectory . $vdetails [ 'file_name' ] . " * " );
// if($hq){
// var_dump(glob(VIDEOS_DIR."/".$fileDirectory . $vdetails['file_name']."*"));
// }
#replace Dir with URL
if ( is_array ( $vid_files ))
foreach ( $vid_files as $file )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
// if($hq){
// echo "filesize = " . filesize($file);
// }
if ( filesize ( $file ) < 100 ) continue ;
$files_part = explode ( '/' , $file );
$video_file = $files_part [ count ( $files_part ) - 1 ];
if ( $with_path )
$files [] = VIDEOS_URL . '/' . $fileDirectory . $video_file ;
else
$files [] = $video_file ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
if ( count ( $files ) == 0 && ! $multi && ! $count_only )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( $return_default )
{
if ( $with_path )
return VIDEOS_URL . '/no_video.flv' ;
else
return 'no_video.flv' ;
} else {
return false ;
}
} else {
if ( $multi )
return $files ;
if ( $count_only )
return count ( $files );
foreach ( $files as $file )
{
if ( $hq )
{
if ( getext ( $file ) == 'mp4' )
{
return $file ;
break ;
}
} else {
return $file ;
break ;
}
}
return $files [ 0 ];
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* FUnction used to get HQ ie mp4 video
*/
function get_hq_video_file ( $vdetails , $return_default = true )
{
return get_video_file ( $vdetails , $return_default , true , false , false , true );
}
2014-02-25 13:27:29 +00:00
2016-03-11 05:44:44 -08:00
/**
* Function used to update processed video
* @ param Files details
*/
function update_processed_video ( $file_array , $status = 'Successful' , $ingore_file_status = false , $failed_status = '' )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
$file = $file_array [ 'cqueue_name' ];
$array = explode ( '-' , $file );
if ( ! empty ( $array [ 0 ]))
$file_name = $array [ 0 ];
$file_name = $file ;
$file_path = VIDEOS_DIR . '/' . $file_array [ 'cqueue_name' ] . '.flv' ;
$file_size = @ filesize ( $file_path );
if ( file_exists ( $file_path ) && $file_size > 0 && ! $ingore_file_status )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
$stats = get_file_details ( $file_name );
2014-02-25 13:27:29 +00:00
2016-03-11 05:44:44 -08:00
//$duration = $stats['output_duration'];
//if(!$duration)
// $duration = $stats['duration'];
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$duration = parse_duration ( LOGS_DIR . '/' . $file_array [ 'cqueue_name' ] . '.log' );
2014-04-15 08:09:21 +00:00
2016-03-11 05:44:44 -08:00
$db -> update ( tbl ( " video " ), array ( " status " , " duration " , " failed_reason " ),
array ( $status , $duration , $failed_status ), " file_name=' " . $file_name . " ' " );
} else
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
//$duration = $stats['output_duration'];
//if(!$duration)
// $duration = $stats['duration'];
$result = db_select ( " SELECT * FROM " . tbl ( " video " ) . " WHERE file_name = ' $file_name ' " );
if ( $result )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
foreach ( $result as $result1 )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
$str = '/' . $result1 [ 'file_directory' ] . '/' ;
$duration = parse_duration ( LOGS_DIR . $str . $file_array [ 'cqueue_name' ] . '.log' );
2013-10-08 12:24:07 +00:00
}
}
2016-03-11 05:44:44 -08:00
$db -> update ( tbl ( " video " ), array ( " status " , " duration " , " failed_reason " ),
array ( $status , $duration , $failed_status ), " file_name=' " . $file_name . " ' " );
2013-10-08 12:24:07 +00:00
}
}
2016-03-11 05:44:44 -08:00
/**
* This function will activate the video if file exists
*/
function activate_video_with_file ( $vid )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
$vdetails = get_video_basic_details ( $vid );
$file_name = $vdetails [ 'file_name' ];
$results = $db -> select ( tbl ( " conversion_queue " ), " * " , " cqueue_name=' $file_name ' AND cqueue_conversion='yes' " );
$result = $results [ 0 ];
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
update_processed_video ( $result );
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* Function Used to get video file stats from database
* @ param FILE_NAME
*/
function get_file_details ( $file_name , $get_jsoned = false )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
//$result = $db->select(tbl("video_files"),"*"," id ='$file_name' OR src_name = '$file_name' ");
//Reading Log File
2014-09-30 09:01:06 +00:00
$result = db_select ( " SELECT * FROM " . tbl ( " video " ) . " WHERE file_name = ' $file_name ' " );
2016-03-11 05:44:44 -08:00
2014-09-30 09:01:06 +00:00
if ( $result )
{
2016-03-11 05:44:44 -08:00
$video = $result [ 0 ];
if ( $video [ 'file_server_path' ]){
$file = $video [ 'file_server_path' ] . '/logs/' . $video [ 'file_directory' ] . $file_name . '.log' ;
}
else {
$str = '/' . $video [ 'file_directory' ] . '/' ;
$file = LOGS_DIR . $str . $file_name . '.log' ;
2014-09-30 09:01:06 +00:00
}
}
2016-03-11 05:44:44 -08:00
//saving log in a variable
$data = file_get_contents ( $file );
if ( empty ( $data ))
$file = $file_name ;
if ( ! empty ( $data ))
{
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$data = file_get_contents ( $file );
2014-09-29 11:02:53 +00:00
2016-03-11 05:44:44 -08:00
if ( ! $get_jsoned )
return $data ;
//$file = file_get_contents('1260270267.log');
preg_match_all ( '/(.*) : (.*)/' , trim ( $data ), $matches );
$matches_1 = ( $matches [ 1 ]);
$matches_2 = ( $matches [ 2 ]);
for ( $i = 0 ; $i < count ( $matches_1 ); $i ++ )
{
$statistics [ trim ( $matches_1 [ $i ])] = trim ( $matches_2 [ $i ]);
}
if ( count ( $matches_1 ) == 0 )
{
return false ;
}
$statistics [ 'conversion_log' ] = $data ;
return $statistics ;
} else
return false ;
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
function parse_duration ( $log )
2014-09-30 09:01:06 +00:00
{
2016-03-11 05:44:44 -08:00
$duration = false ;
$log_details = get_file_details ( $log );
if ( isset ( $log [ 'output_duration' ]))
$duration = $log [ 'output_duration' ];
if (( ! $duration || ! is_numeric ( $duration )) && isset ( $log [ 'duration' ]))
$duration = $log [ 'duration' ];
if ( ! $duration || ! is_numeric ( $duration ))
{
if ( file_exists ( $log ))
$log_content = file_get_contents ( $log );
//Parse duration..
preg_match_all ( '/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9.]{1,5})/i' , $log_content , $matches );
unset ( $log_content );
//Now we will multiple hours, minutes accordingly and then add up with seconds to
//make a single variable of duration
$hours = $matches [ 1 ][ 0 ];
$minutes = $matches [ 2 ][ 0 ];
$seconds = $matches [ 3 ][ 0 ];
$hours = $hours * 60 * 60 ;
$minutes = $minutes * 60 ;
$duration = $hours + $minutes + $seconds ;
$duration ;
2014-09-30 09:01:06 +00:00
}
2016-03-11 05:44:44 -08:00
return $duration ;
2014-09-30 09:01:06 +00:00
}
2015-12-29 10:30:08 +00:00
2016-03-11 05:44:44 -08:00
/**
* Function used to get thumbnail number from its name
* Updated : If we provide full path for some reason and
* web - address has '-' in it , this means our result is messed .
* But we know our number will always be in last index
* So wrap it with end () and problem solved .
*/
function get_thumb_num ( $name )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
$list = explode ( '-' , $name );
$list = end ( $list );
$list = explode ( '.' , $list );
return $list [ 0 ];
}
2014-09-29 11:02:53 +00:00
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* Function used to remove specific thumbs number
*/
function delete_video_thumb ( $file_dir , $file_name , $num )
{
global $LANG ;
if ( ! empty ( $file_dir )){
$files = glob ( THUMBS_DIR . '/' . $file_dir . '/' . $file_name . '*' . $num . '.*' );
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
else {
$files = glob ( THUMBS_DIR . '/' . $file_name . '*' . $num . '.*' );
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
//pr($files,true);
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
if ( $files ){
foreach ( $files as $key => $file ){
if ( file_exists ( $file )){
unlink ( $file );
}
}
e ( lang ( 'video_thumb_delete_msg' ), 'm' );
} else {
e ( lang ( 'video_thumb_delete_err' ));
}
}
2014-11-22 15:22:41 +00:00
2016-03-11 05:44:44 -08:00
/**
* function used to remove video thumbs
*/
function remove_video_thumbs ( $vdetails )
{
global $cbvid ;
return $cbvid -> remove_thumbs ( $vdetails );
}
2014-11-22 15:22:41 +00:00
2016-03-11 05:44:44 -08:00
/**
* function used to remove video log
*/
function remove_video_log ( $vdetails )
{
global $cbvid ;
return $cbvid -> remove_log ( $vdetails );
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* function used to remove video files
*/
function remove_video_files ( $vdetails )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $cbvid ;
return $cbvid -> remove_files ( $vdetails );
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* Function used to check weather video has Mp4 file or not
*/
function has_hq ( $vdetails , $is_file = false )
{
if ( ! $is_file )
$file = get_hq_video_file ( $vdetails );
else
$file = $vdetails ;
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
if ( getext ( $file ) == 'mp4' )
return $file ;
else
return false ;
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* Funcion used to call functions
* when video is going to watched
* ie in watch_video . php
*/
function call_watch_video_function ( $vdo )
{
global $userquery ;
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$funcs = get_functions ( 'watch_video_functions' );
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 )
{
foreach ( $funcs as $func )
{
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
if ( function_exists ( $func ))
{
$func ( $vdo );
}
2016-03-07 14:33:42 +05:00
}
}
2016-03-11 05:44:44 -08:00
increment_views_new ( $vdo [ 'videoid' ], 'video' );
if ( userid ())
$userquery -> increment_watched_vides ( userid ());
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Funcion used to call functions
* when video is going
* on CBvideo :: remove_files
*/
function call_delete_video_function ( $vdo )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
$funcs = get_functions ( 'on_delete_video' );
if ( is_array ( $funcs ) && count ( $funcs ) > 0 )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
foreach ( $funcs as $func )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( function_exists ( $func ))
{
$func ( $vdo );
}
2013-10-08 12:24:07 +00:00
}
}
}
2016-03-11 05:44:44 -08:00
/**
* Funcion used to call functions
* when video is going to dwnload
* ie in download . php
*/
function call_download_video_function ( $vdo )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $db ;
$funcs = get_functions ( 'download_video_functions' );
if ( is_array ( $funcs ) && count ( $funcs ) > 0 )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
foreach ( $funcs as $func )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( function_exists ( $func ))
{
$func ( $vdo );
}
2013-10-08 12:24:07 +00:00
}
}
2016-03-11 05:44:44 -08:00
//Updating Video Downloads
$db -> update ( tbl ( " video " ), array ( " downloads " ), array ( " |f|downloads+1 " ), " videoid = ' " . $vdo [ 'videoid' ] . " ' " );
//Updating User Download
if ( userid ())
$db -> update ( tbl ( " users " ), array ( " total_downloads " ), array ( " |f|total_downloads+1 " ), " userid = ' " . userid () . " ' " );
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* function used to get vidos
*/
function get_videos ( $param )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $cbvideo ;
return $cbvideo -> get_videos ( $param );
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Function used to check
* input users are valid or not
* so that only registere usernames can be set
*/
function video_users ( $users )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
global $userquery ;
2017-07-03 16:28:41 +05:00
if ( ! empty ( $users )){
$users_array = explode ( ',' , $users );
}
2016-03-11 05:44:44 -08:00
$new_users = array ();
foreach ( $users_array as $user )
2013-10-08 12:24:07 +00:00
{
2016-03-11 05:44:44 -08:00
if ( $user != username () && ! is_numeric ( $user ) && $userquery -> user_exists ( $user ))
{
$new_users [] = $user ;
}
2013-10-08 12:24:07 +00:00
}
2016-03-11 05:44:44 -08:00
$new_users = array_unique ( $new_users );
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
if ( count ( $new_users ) > 0 )
return implode ( ',' , $new_users );
else
return " " ;
}
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
/**
* function used to check weather logged in user is
* is in video users or not
*/
function is_video_user ( $vdo , $user = NULL )
{
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
if ( ! $user )
$user = username ();
2016-05-26 16:36:05 +05:00
2016-03-11 05:44:44 -08:00
if ( is_array ( $vdo ))
$video_users = $vdo [ 'video_users' ];
else
$video_users = $vdo ;
2013-10-08 12:24:07 +00:00
2016-03-11 05:44:44 -08:00
$users_array = explode ( ',' , $video_users );
2016-05-26 16:36:05 +05:00
$users_array = array_filter ( array_map ( 'trim' , $users_array ));
if ( in_array ( $user , $users_array )){
2016-03-11 05:44:44 -08:00
return true ;
2016-05-26 16:36:05 +05:00
}
else {
2016-03-11 05:44:44 -08:00
return false ;
2016-05-26 16:36:05 +05:00
}
2016-03-11 05:44:44 -08:00
}
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
/**
* function used to get allowed extension as in array
*/
function get_vid_extensions ()
{
$exts = config ( 'allowed_types' );
$exts = preg_replace ( " / / " , " " , $exts );
$exts = explode ( " , " , $exts );
return $exts ;
}
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
//this function is written for temporary purposes for html5 player
function get_normal_vid ( $vdetails , $return_default = true , $with_path = true , $multi = false , $count_only = false , $hq = false ){
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
global $Cbucket ;
# checking if there is any other functions
# available
if ( is_array ( $Cbucket -> custom_video_file_funcs ))
foreach ( $Cbucket -> custom_video_file_funcs as $func )
if ( function_exists ( $func ))
{
$func_returned = $func ( $vdetails , $hq );
if ( $func_returned )
return $func_returned ;
}
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
$fileDirectory = " " ;
if ( isset ( $vdetails [ 'file_directory' ]) && ! empty ( $vdetails [ 'file_directory' ])){
$fileDirectory = " { $vdetails [ 'file_directory' ] } / " ;
}
//dump($vdetails['file_name']);
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
#Now there is no function so lets continue as
if ( isset ( $vdetails [ 'file_name' ]))
$vid_files = glob ( VIDEOS_DIR . " / " . $fileDirectory . $vdetails [ 'file_name' ] . " * " );
// if($hq){
// var_dump(glob(VIDEOS_DIR."/".$fileDirectory . $vdetails['file_name']."*"));
// }
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
#replace Dir with URL
if ( is_array ( $vid_files ))
foreach ( $vid_files as $file )
2014-06-05 10:52:55 +00:00
{
2016-03-11 05:44:44 -08:00
// if($hq){
// echo "filesize = " . filesize($file);
// }
if ( filesize ( $file ) < 100 ) continue ;
$files_part = explode ( '/' , $file );
$video_file = $files_part [ count ( $files_part ) - 1 ];
if ( $with_path )
$files [] = VIDEOS_URL . '/' . $fileDirectory . $vdetails [ 'file_name' ] ;
else
$files [] = $video_file ;
2014-06-05 10:52:55 +00:00
}
2016-03-11 05:44:44 -08:00
//pr($files,true);
return $files [ 0 ];
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
}
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
//this function is written for temporary purposes for html5 player
function get_hq_vid ( $vdetails , $return_default = true , $with_path = true , $multi = false , $count_only = false , $hq = false ){
2014-06-05 10:52:55 +00:00
2016-03-11 05:44:44 -08:00
global $Cbucket ;
# checking if there is any other functions
# available
if ( is_array ( $Cbucket -> custom_video_file_funcs ))
foreach ( $Cbucket -> custom_video_file_funcs as $func )
if ( function_exists ( $func ))
{
$func_returned = $func ( $vdetails , $hq );
if ( $func_returned )
return $func_returned ;
}
2014-12-08 14:51:09 +00:00
2016-03-11 05:44:44 -08:00
$fileDirectory = " " ;
if ( isset ( $vdetails [ 'file_directory' ]) && ! empty ( $vdetails [ 'file_directory' ])){
$fileDirectory = " { $vdetails [ 'file_directory' ] } / " ;
}
//dump($vdetails['file_name']);
2014-12-08 14:51:09 +00:00
2016-03-11 05:44:44 -08:00
#Now there is no function so lets continue as
if ( isset ( $vdetails [ 'file_name' ]))
$vid_files = glob ( VIDEOS_DIR . " / " . $fileDirectory . $vdetails [ 'file_name' ] . " * " );
// if($hq){
// var_dump(glob(VIDEOS_DIR."/".$fileDirectory . $vdetails['file_name']."*"));
// }
2014-12-18 10:26:29 +00:00
2016-03-11 05:44:44 -08:00
#replace Dir with URL
if ( is_array ( $vid_files ))
foreach ( $vid_files as $file )
2014-12-08 14:51:09 +00:00
{
2016-03-11 05:44:44 -08:00
// if($hq){
// echo "filesize = " . filesize($file);
// }
if ( filesize ( $file ) < 100 ) continue ;
$files_part = explode ( '/' , $file );
$video_file = $files_part [ count ( $files_part ) - 1 ];
if ( $with_path )
$files [] = VIDEOS_URL . '/' . $fileDirectory . $vdetails [ 'file_name' ] ;
else
$files [] = $video_file ;
2014-12-08 14:51:09 +00:00
}
2016-03-11 05:44:44 -08:00
//pr($files,true);
//echo $files;
return $files [ 1 ];
}
/**
* Function used to get list of videos files
* ..
* ..
* @ since 2.7 */
function get_video_files ( $vdetails , $return_default = true , $with_path = true , $multi = false , $count_only = false , $hq = false ){
global $Cbucket ;
# checking if there is any other functions
# available
define ( 'VIDEO_VERSION' , $vdetails [ 'video_version' ]);
if ( is_array ( $Cbucket -> custom_video_file_funcs ))
foreach ( $Cbucket -> custom_video_file_funcs as $func )
if ( function_exists ( $func ))
{
$func_returned = $func ( $vdetails , $hq );
if ( $func_returned )
return $func_returned ;
}
2014-12-18 10:26:29 +00:00
2016-03-11 05:44:44 -08:00
$fileDirectory = " " ;
if ( isset ( $vdetails [ 'file_directory' ]) && ! empty ( $vdetails [ 'file_directory' ])){
$fileDirectory = " { $vdetails [ 'file_directory' ] } / " ;
}
//dump($vdetails['file_name']);
2014-12-08 14:51:09 +00:00
2016-03-11 05:44:44 -08:00
#Now there is no function so lets continue as
2014-12-18 10:26:29 +00:00
2016-03-11 05:44:44 -08:00
if ( isset ( $vdetails [ 'file_name' ])){
if ( VIDEO_VERSION == '2.7' ){
$vid_files = glob ( VIDEOS_DIR . " / " . $fileDirectory . $vdetails [ 'file_name' ] . " * " );
}
else {
$vid_files = glob ( VIDEOS_DIR . " / " . $vdetails [ 'file_name' ] . " * " );
}
}
// if($hq){
// var_dump(glob(VIDEOS_DIR."/".$fileDirectory . $vdetails['file_name']."*"));
// }
#replace Dir with URL
if ( is_array ( $vid_files ))
foreach ( $vid_files as $file )
{
// if($hq){
// echo "filesize = " . filesize($file);
// }
if ( filesize ( $file ) < 100 ) continue ;
$files_part = explode ( '/' , $file );
$video_file = $files_part [ count ( $files_part ) - 1 ];
if ( $with_path ){
if ( VIDEO_VERSION == '2.7' )
$files [] = VIDEOS_URL . '/' . $fileDirectory . $video_file ;
else if ( VIDEO_VERSION == '2.6' )
$files [] = VIDEOS_URL . '/' . $video_file ;
}
else
$files [] = $video_file ;
2014-12-18 10:26:29 +00:00
}
2014-12-23 05:30:23 +00:00
2016-03-11 05:44:44 -08:00
if ( count ( $files ) == 0 && ! $multi && ! $count_only )
2014-12-23 05:30:23 +00:00
{
2016-03-11 05:44:44 -08:00
if ( $return_default )
{
2014-12-23 05:30:23 +00:00
2016-03-11 05:44:44 -08:00
if ( $with_path )
return VIDEOS_URL . '/no_video.mp4' ;
else
return 'no_video.mp4' ;
}
2014-12-23 05:30:23 +00:00
else
2016-03-11 05:44:44 -08:00
{
return false ;
}
2014-12-23 05:30:23 +00:00
}
else
{
2016-03-11 05:44:44 -08:00
return $files ;
2014-12-23 05:30:23 +00:00
}
2014-12-08 14:51:09 +00:00
2015-01-22 13:53:20 +00:00
2016-03-11 05:44:44 -08:00
}
2015-01-22 13:53:20 +00:00
2016-03-11 05:44:44 -08:00
function upload_thumb ( $array )
2015-01-22 13:53:20 +00:00
{
2016-03-11 05:44:44 -08:00
global $file_name , $LANG , $Upload ;
//Get File Name
$file = $array [ 'name' ];
$ext = getExt ( $file );
$image = new ResizeImage ();
if ( ! empty ( $file ) && file_exists ( $array [ 'tmp_name' ]) && ! error ())
2015-01-22 13:53:20 +00:00
{
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
$file_directory = " " ;
if ( isset ( $_REQUEST [ 'time_stamp' ]))
{
$file_directory = create_dated_folder ( NULL , $_REQUEST [ 'time_stamp' ]);
$file_directory .= '/' ;
//exit($file_directory);
}
if ( $image -> ValidateImage ( $array [ 'tmp_name' ], $ext )){
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
$imageDetails = getimagesize ( $array [ 'tmp_name' ]);
$file_num = $Upload -> get_available_file_num ( $_POST [ 'file_name' ]);
$temp_file = THUMBS_DIR . '/' . $file_directory . '/' . $_POST [ 'file_name' ] . '-' . $file_num . '.' . $ext ;
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
move_uploaded_file ( $array [ 'tmp_name' ], $temp_file );
$thumbs_settings_28 = thumbs_res_settings_28 ();
foreach ( $thumbs_settings_28 as $key => $thumbs_size ) {
$height_setting = $thumbs_size [ 1 ];
$width_setting = $thumbs_size [ 0 ];
if ( $key != 'original' ){
$dimensions = implode ( 'x' , $thumbs_size );
} else {
$dimensions = 'original' ;
$width_setting = $imageDetails [ 0 ];
$height_setting = $imageDetails [ 1 ];
}
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
$outputFilePath = THUMBS_DIR . '/' . $file_directory . '/' . $_POST [ 'file_name' ] . '-' . $dimensions . '-' . $file_num . '.' . $ext ;
//echo $outputFilePath.'<br>';
$image -> CreateThumb ( $temp_file , $outputFilePath , $width_setting , $ext , $height_setting , false );
}
unlink ( $temp_file );
} else {
e ( lang ( 'vdo_thumb_up_err' ));
2015-01-22 13:53:20 +00:00
}
} else {
2016-03-11 05:44:44 -08:00
return true ;
2015-01-22 13:53:20 +00:00
}
}
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
/**
* Assigns videos array to video player ' s HTML in VideoJS and HTML5 Player
* @ param : { array } { $array } { array of all sources for video }
* @ param : { boolean } { $test_msg } { show all notifications during testing }
* @ author : Saqib Razzaq
*/
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
function vids_assign ( $array , $test_msg = false )
2015-12-23 10:19:10 +00:00
{
2016-04-27 17:10:54 +05:00
if ( ! is_array ( $array )){
assign ( 'video_files' , array ( $array ));
return false ;
}
2016-03-11 05:44:44 -08:00
$data = get_browser_details ();
$vids_array = array ();
foreach ( $array as $key => $value )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
if ( is_mob_vid ( $value ) )
{
if ( is_phone_user ( $data ))
{
if ( $test_msg )
{
echo 'Mobile video on mobile ' ;
}
$new_array = array ();
$new_array [] = $value ;
assign ( " mobile_vid " , " true " );
assign ( " video_files " , $new_array );
break ;
}
}
elseif ( is_extension ( $value , 'flv' ) && ! is_phone_user ( $data ) )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
if ( $test_msg )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
echo 'FLV video on PC' ;
2015-12-23 10:19:10 +00:00
}
$new_array = array ();
$new_array [] = $value ;
2016-03-11 05:44:44 -08:00
assign ( " flv_vid " , " true " );
2015-12-23 10:19:10 +00:00
assign ( " video_files " , $new_array );
break ;
}
2016-03-11 05:44:44 -08:00
else
{
if ( $test_msg )
{
echo 'Regular vids array' ;
}
assign ( " video_files " , $array );
break ;
}
2015-12-23 10:19:10 +00:00
}
2016-03-11 05:44:44 -08:00
}
/**
* Checks if a provided file matches provided extension
* @ param : { string } { $filepath } { path or link to file }
* @ param : { string } { $ext } { file extension to match against }
* @ return : { boolean } { true or false }
* @ author : Saqib Razzaq
*/
function is_extension ( $filepath , $ext , $err_msg = false )
{
# extract file extension
$file_format = pathinfo ( $filepath , PATHINFO_EXTENSION );
# check if extesnon is empty
if ( empty ( $filepath ) )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
if ( $err_msg )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
echo " Invalid URL given for checking " ;
2015-12-23 10:19:10 +00:00
}
2016-03-11 05:44:44 -08:00
# extension is empty so return false
return false ;
# check extension == extension given by user
}
elseif ( strtolower ( $file_format ) == strtolower ( $ext ) )
{
# extensions match so return true
return $ext ;
}
2015-12-23 10:19:10 +00:00
else
{
2016-03-11 05:44:44 -08:00
if ( $err_msg )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
echo " Invalid extension " . $ext ;
2015-12-23 10:19:10 +00:00
}
2016-03-11 05:44:44 -08:00
# extesnions don't match or something else went wrong so return false
return false ;
2015-12-23 10:19:10 +00:00
}
}
2016-03-11 05:44:44 -08:00
/**
* Checks if video was converted using CB Mobile Mod ( for 2.6 users )
* @ param : { string } { $url } { url of the video to check }
* @ param : { boolean } { $err_msg } { show or hide error messages }
* @ return : { boolean } { true of false }
* @ author : Saqib Razzaq
*/
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
function is_mob_vid ( $url , $err_msg = false )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
if ( ! empty ( $url ))
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
if ( is_extension ( $url , 'mp4' ) )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
$check = substr ( $url , - 6 );
if ( $check == '-m.mp4' )
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
return true ;
2015-12-23 10:19:10 +00:00
}
2016-03-11 05:44:44 -08:00
else
{
if ( $err_msg )
{
echo 'Not a mobile mod video' ;
}
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
return false ;
}
2015-12-23 10:19:10 +00:00
}
}
2016-03-11 05:44:44 -08:00
else
2015-12-23 10:19:10 +00:00
{
2016-03-11 05:44:44 -08:00
if ( $err_msg )
{
echo " Invalid URL given for checking " ;
}
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
return false ;
}
2015-12-23 10:19:10 +00:00
}
2016-03-11 05:44:44 -08:00
/**
* Checks if current website user is using mobile / smart phone
* @ param : { array } { array of data ( useragent etc ) }
* @ return : { string } { platform of user }
* @ author : Saqib Razzaq
*/
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
function is_phone_user ( $data )
{
$platform = $data [ 'platform' ];
$useragent = $data [ 'userAgent' ];
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
$mob_array = array ( 'Unknown' , 'iphone' , 'ipad' , 'ipod' , 'android' );
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
if ( in_array ( $platform , $mob_array ) )
{
return $platform ;
}
else
{
$data = explode ( " " , $useragent );
foreach ( $data as $key ) {
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
$key = strtolower ( $key );
2015-12-23 10:19:10 +00:00
2016-03-11 05:44:44 -08:00
if ( in_array ( $key , $mob_array ) )
{
return $key ;
}
else
{
#echo "na kar";
}
2015-12-23 10:19:10 +00:00
}
}
}
2016-03-11 05:44:44 -08:00
/**
* @ author : Fahad Abbas
* @ param : { Null }
* @ return : { Array } { Clipbucket version 2.8 thumbs default settings }
* @ since : 02 - 03 - 2016
*/
function thumbs_res_settings_28 (){
$thumbs_res_settings = array (
" original " => " original " ,
2016-04-11 18:47:52 +05:00
'105' => array ( '168' , '105' ),
'260' => array ( '416' , '260' ),
'320' => array ( '632' , '395' ),
'480' => array ( '768' , '432' )
2016-03-11 05:44:44 -08:00
);
return $thumbs_res_settings ;
2016-03-07 14:33:42 +05:00
}
2016-03-11 05:44:44 -08:00
/**
* @ author : Fahad Abbas
* @ param : { Array } { Video Details }
* @ return : { Variable or boolean } { Max resolution file }
* @ since : 03 - 03 - 2016
*/
function get_high_res_file ( $vdetails , $dir = false ){
//Getting video Files array
$video_files = $vdetails [ 'video_files' ];
$video_files = json_decode ( $video_files , true );
//Getting video actual files source
$v_files = get_video_files ( $vdetails , true , true );
if ( empty ( $v_files )){
e ( lang ( 'Video file doesn\'t exists' ), 'e' );
}
//Checking if video_files field is not empty (greater versions than CB 2.8)
if ( ! empty ( $video_files )){
$pre_check_file = $video_files [ 0 ];
if ( is_int ( $pre_check_file )){
$max_file_res = max ( $video_files );
2016-03-07 14:33:42 +05:00
} else {
2016-03-11 05:44:44 -08:00
if ( in_array ( " hd " , $video_files )) {
$max_file_res = " hd " ;
} else {
$max_file_res = " sd " ;
}
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
}
2016-03-07 14:33:42 +05:00
} else {
2016-03-11 05:44:44 -08:00
//Checking if video_files field is empty (lower versions than CB 2.8.1)
foreach ( $v_files as $key => $file ) {
$video_files [] = get_video_file_quality ( $file );
}
$pre_check_file = $video_files [ 0 ];
if ( is_numeric ( $pre_check_file )){
$max_file_res = max ( $video_files );
2016-03-07 14:33:42 +05:00
} else {
2016-03-11 05:44:44 -08:00
if ( in_array ( " hd " , $video_files )) {
$max_file_res = " hd " ;
} else {
$max_file_res = " sd " ;
}
2016-03-07 14:33:42 +05:00
}
2016-03-11 05:44:44 -08:00
}
// now saving the max resolution file in a variable
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
if ( $dir ){
$Ext = GetExt ( $v_files [ 0 ]);
$max_res_file = VIDEOS_DIR . '/' . $vdetails [ 'file_directory' ] . '/' . $vdetails [ 'file_name' ] . '-' . $max_file_res . '.' . $Ext ;
2016-03-07 14:33:42 +05:00
2016-03-11 05:44:44 -08:00
} else {
foreach ( $v_files as $key => $file ) {
$video_quality = get_video_file_quality ( $file );
if ( $max_file_res == $video_quality ){
$max_res_file = $file ;
}
2016-03-07 14:33:42 +05:00
}
}
2016-03-11 05:44:44 -08:00
if ( ! empty ( $max_res_file )){
return $max_res_file ;
} else {
return false ;
2016-03-10 00:38:24 -08:00
}
2016-03-11 05:44:44 -08:00
2016-03-10 00:38:24 -08:00
}
2016-03-11 05:44:44 -08:00
/**
* @ author : Fahad Abbas
* @ param : { Var } { quality of input file }
* @ return : { Variable } { resolution of a file }
* @ since : 03 - 03 - 2016
*/
function get_video_file_quality ( $file ){
$quality = explode ( '-' , $file );
$quality = end ( $quality );
$quality = explode ( '.' , $quality );
$quality = $quality [ 0 ];
return $quality ;
2016-03-10 00:03:18 -08:00
}
2016-03-11 05:44:44 -08:00
/**
* Checks ram of a Linux server e . g Ubutnu , CentOS
* @ param : { none }
* @ since : 10 th March , 2016 ClipBucket 2.8 . 1
* @ author : Saqib Razzaq
* @ return : { integer } { $total_ram } { total RAM in GB ' s }
*/
function check_server_ram () {
$fh = fopen ( '/proc/meminfo' , 'r' );
$mem = 0 ;
while ( $line = fgets ( $fh )) {
$pieces = array ();
if ( preg_match ( '/^MemTotal:\s+(\d+)\skB$/' , $line , $pieces )) {
$mem = $pieces [ 1 ];
break ;
2016-03-10 00:38:24 -08:00
}
2016-03-10 00:14:27 -08:00
}
2016-03-11 05:44:44 -08:00
fclose ( $fh );
$total_ram = $mem / 1024 / 1024 ;
return $total_ram ;
2016-03-10 00:14:27 -08:00
}
2016-03-11 05:44:44 -08:00
/**
* Checks different sections to make sure video uploading is good to go
*
* @ param : { none } { everything handled inside function }
* @ checks : { server ram , directory permissions , PHP path , module installations , versions }
* @ action : { string } { error messages depending on situation }
* @ author : Saqib Razzaq
* @ since : 10 th March , 2016 ClipBucket 2.8 . 1
*/
function pre_upload () {
if ( isset ( $_GET [ 'alliswell' ])) {
2016-03-10 00:14:27 -08:00
if ( has_access ( " admin_access " )) {
2016-03-11 05:44:44 -08:00
$alliswell = $_GET [ 'alliswell' ];
}
}
if ( PHP_OS == 'Linux' ) {
$ramsize = check_server_ram ();
if ( $ramsize < 5 ) {
if ( $ramsize < 1 ) {
$mode = 'MB' ;
} else {
$mode = 'GB' ;
2016-03-10 00:03:18 -08:00
}
2016-05-19 11:32:36 +05:00
if ( has_access ( 'admin_access' )) {
e ( " Current Memory Size (RAM) of server is <strong> " . round ( $ramsize , 2 ) . " " . $mode . " </strong> but recomended RAM is atleast 5 GB " );
}
2016-03-10 00:03:18 -08:00
}
}
2016-03-11 05:44:44 -08:00
$directories = array ( 'files' , 'cache' , 'includes' );
foreach ( $directories as $dir ) {
$full_path = BASEDIR . '/' . $dir ;
if ( ! is_writable ( $full_path )) {
e ( " <strong> " . $full_path . " </strong> is not writeable, video upload might not work " );
}
}
$ffmpeg = check_ffmpeg ( " ffmpeg " );
$phpVersion = check_php_cli ( " php " );
$MP4BoxVersion = check_mp4box ( " MP4Box " );
$imagick_version = check_imagick ( " i_magick " );
$media_info = check_media_info ( 'media_info' );
$ffprobe_path = check_ffprobe_path ( 'ffprobe_path' );
$errs = array ();
$alltools = array (
" ffmpeg " => $ffmpeg ,
" php " => $phpVersion ,
" mp4box " => $MP4BoxVersion ,
" imagick " => $imagick_version ,
" mediainfo " => $media_info ,
" ffprobe " => $ffprobe_path
);
2016-03-10 00:03:18 -08:00
2016-03-11 05:44:44 -08:00
foreach ( $alltools as $name => $tool ) {
if ( ! $tool ) {
$errs [ $name ] = " not found " ;
2016-03-10 00:03:18 -08:00
} else {
2016-03-11 05:44:44 -08:00
if ( has_access ( " admin_access " )) {
if ( $name == 'php' ) {
if ( $phpVersion > " 5.4.45 " || $phpVersion < " 5.4 " ) {
e ( " [Admin only message] Installed PHP Version is <strong> " . $phpVersion . " </strong> but recomended version is 5.4.x " , " w " );
}
}
}
}
if ( $alliswell ) {
if ( $alliswell == 'all' ) {
e ( $name . " [Admin only message] seems good to go " , " m " );
} else {
if ( strtolower ( $name ) == $alliswell ) {
e ( strtoupper ( $name ) . " [Admin only message] seems good to go " , " m " );
}
2016-03-10 00:03:18 -08:00
}
}
}
2016-03-11 05:44:44 -08:00
if ( ! empty ( $errs )) {
if ( has_access ( " admin_access " )) {
foreach ( $errs as $name => $issue ) {
2016-05-16 12:49:07 +05:00
e ( strtoupper ( " [Admin only message] <strong> " . $name . " </strong> " ) . " couldn't be found or isn't installed properly hence video might not work, check <a href= " . BASEURL . " /admin_area/cb_mod_check.php>Server Modules</a> page to know more " );
2016-03-11 05:44:44 -08:00
}
} else {
e ( " Video upload might not work properly, kindly contact website admin " );
2016-03-10 00:03:18 -08:00
}
} else {
2016-03-11 05:44:44 -08:00
return true ;
2016-03-10 00:03:18 -08:00
}
2016-03-10 18:06:36 +05:00
2016-03-11 05:44:44 -08:00
}
2016-03-10 18:06:36 +05:00
2016-03-11 05:44:44 -08:00
/**
* This Function is used to log the input video File procession
*
* @ param : { Array } { filename } { file directory } { content }
* @ return : { boolean } { Null }
* @ since : 8 th March , 2016 ClipBucket 2.8 . 1
* @ author : Fahad Abbas
* @ email : < fahad . dev @ iu . com . pk >
*/
2016-03-10 18:06:36 +05:00
2016-03-11 05:44:44 -08:00
function log_file_procession ( $input ){
$File_name = $input [ 'file_name' ];
$File_dir = $input [ 'file_dir' ];
$data = $input [ 'data' ];
2016-03-10 18:06:36 +05:00
2016-06-29 00:52:30 -07:00
$PlogFilePath = FILES_DIR . " /logs/ " . $File_dir . " / " . $File_name . " .plog " ;
2016-03-10 18:06:36 +05:00
2016-03-11 05:44:44 -08:00
if ( file_exists ( $PlogFilePath )) {
$text = file_get_contents ( $PlogFilePath );
}
logData ( $PlogFilePath , 'plogs_tester' );
$text .= " \n \n <br><br> > { $data } " ;
file_put_contents ( $PlogFilePath , $text );
2016-03-10 18:06:36 +05:00
}
2016-03-11 05:44:44 -08:00
/**
* This Function is used to get video file procession log
*
* @ param : { Array } { video Details }
* @ return : { File } { }
* @ since : 9 th March , 2016 ClipBucket 2.8 . 1
* @ author : Fahad Abbas
* @ email : < fahad . dev @ iu . com . pk >
*/
function get_file_procession_log ( $vdetails ){
$file_dir = $vdetails [ 'file_directory' ];
$file_name = $vdetails [ 'file_name' ];
$multiserver_file = $vdetails [ 'file_server_path' ];
if ( empty ( $multiserver_file )){
$plog_file = LOGS_DIR . '/' . $file_dir . '/' . $file_name . '.plog' ;
} else {
$plog_file = $multiserver_file . '/logs/' . $file_dir . '/' . $filename . '.plog' ;
}
if ( file_exists ( $plog_file )){
$data = file_get_contents ( $plog_file );
return $data ;
} else {
return false ;
}
2016-03-18 18:05:42 +05:00
}
2016-03-21 11:16:34 +05:00
/**
* Fetches quicklists stored in cookies
* @ param : { string } { $cookie_name } { false by default , read from certain cookie }
* @ return : { array } { $vid_dets } { an array with all details of videos in quicklists }
* @ since : 18 th March , 2016 ClipBucket 2.8 . 1
* @ author : Saqib Razzaq < saqi . cb @ gmail . com >
*/
2016-03-18 18:05:42 +05:00
function get_fast_qlist ( $cookie_name = false ) {
global $cbvid ;
if ( $cookie_name ) {
$cookie = $cookie_name ;
} else {
$cookie = 'fast_qlist' ;
}
2017-01-06 12:40:43 +05:00
$raw_cookies = isset ( $_COOKIE [ $cookie ]) ? $_COOKIE [ $cookie ] : false ;
2016-03-18 18:05:42 +05:00
$clean_cookies = str_replace ( array ( " [ " , " ] " ), " " , $raw_cookies );
$vids = explode ( " , " , $clean_cookies );
2016-03-21 19:36:41 +05:00
assign ( " qlist_vids " , $vids );
2016-03-18 18:05:42 +05:00
$vid_dets = array ();
foreach ( $vids as $key => $vid ) {
$vid_dets [] = $cbvid -> get_video_details ( $vid );
}
return array_filter ( $vid_dets );
2016-06-30 05:36:31 -07:00
}
2016-06-30 05:45:06 -07:00
/**
* Fetches the oldest video from still - waiting - to - convert list of videos when user by cron is active
* @ param : { none }
* @ author : { Saqib Razzaq }
* @ return : { array } { $returnData } { an array with required parameters for video convert }
*/
2016-06-30 05:36:31 -07:00
function convertWithCron () {
global $db ;
$toConvert = $db -> select ( tbl ( " conversion_queue " ), " * " , " cqueue_conversion ='no' ORDER BY cqueue_id ASC LIMIT 0,1 " );
$filedata = $toConvert [ 0 ];
2016-06-30 05:45:06 -07:00
if ( empty ( $filedata )) {
return false ;
}
2016-06-30 05:36:31 -07:00
$dateDir = str_replace ( '-' , '/' , $filedata [ 'date_added' ]);
$dateDir = substr ( $dateDir , 0 , strpos ( $dateDir , ' ' ));
$returnData = array ();
$returnData [ 1 ] = $filedata [ 'cqueue_name' ] . '.' . $filedata [ 'cqueue_ext' ];
$returnData [ 2 ] = $filedata [ 'cqueue_name' ];
$returnData [ 3 ] = $dateDir ;
$returnData [ 4 ] = FILES_DIR . '/logs/' . $dateDir . '/' . $filedata [ 'cqueue_name' ] . '.log' ;
return $returnData ;
2016-09-17 18:22:00 +05:00
}
function dateNow () {
return date ( " Y-m-d H:i:s " );
}
2016-11-03 13:48:39 +05:00
/**
* Set status or reconversion status for any given video
* @ param : { mixed } { $video } { videoid , videokey or filename }
* @ param : { string } { $status } { new status to be set }
* @ param : { boolean } { $reconv } { if you are setting reconversion status , pass this true }
* @ param : { boolean } { $byFileName } { if you passed file_name in first paramter , you will need to pass this true as well }
* @ since : 31 st October , 2016
* @ author : Saqib Razzaq
*
* @ action : Updates database
*/
2016-11-01 19:26:50 +05:00
// Processing
// Successful
// Failed
#
# For video reconverting
#
// pending
// started
// success
// failed
2016-10-28 17:46:19 +05:00
2016-11-01 18:32:02 +05:00
function setVideoStatus ( $video , $status , $reconv = false , $byFilename = false ) {
2016-10-28 17:46:19 +05:00
global $db ;
2016-11-01 18:32:02 +05:00
if ( $byFilename ) {
$type = 'file_name' ;
2016-10-28 17:46:19 +05:00
} else {
2016-11-01 18:32:02 +05:00
if ( is_numeric ( $video )) {
$type = 'videoid' ;
} else {
$type = 'videokey' ;
}
2016-10-28 17:46:19 +05:00
}
if ( $reconv ) {
$field = 're_conv_status' ;
} else {
$field = 'status' ;
}
2016-11-01 18:32:02 +05:00
$db -> update ( tbl ( 'video' ), array ( $field ), array ( $status ), " $type =' $video ' " );
2016-10-28 17:46:19 +05:00
}
2016-11-03 13:48:39 +05:00
/**
* Checks current reconversion status of any given video : default is empty
* @ param : { integer } { $vid } { id of video that we need to check sstatus for }
* @ return : { string } { reconversion status of video }
*/
2016-11-01 19:26:50 +05:00
function checkReConvStatus ( $vid ) {
global $db ;
$data = $db -> select ( tbl ( 'video' ), 're_conv_status' , 'videoid=' . $vid );
if ( isset ( $data [ 0 ][ 're_conv_status' ])) {
return $data [ 0 ][ 're_conv_status' ];
}
}
2016-11-03 13:42:56 +05:00
/**
* Checks if given video is reconvertable or not
* @ param : { array } { $vdetails } { an array with all details regarding video }
2016-11-15 14:50:16 +05:00
* @ since : 14 th November October , 2016
* @ author : Fahad Abbas
2016-11-03 13:42:56 +05:00
*
* @ return : { boolean } { returns true or false depending on matched case }
*/
2016-10-28 17:46:19 +05:00
function isReconvertAble ( $vdetails ) {
2016-11-15 14:50:16 +05:00
try {
global $cbvid ;
if ( is_array ( $vdetails ) && ! empty ( $vdetails )) {
$fileName = $vdetails [ 'file_name' ];
$fileDirectory = $vdetails [ 'file_directory' ];
$serverPath = $vdetails [ 'file_server_path' ];
if ( empty ( $vdetails [ 'file_server_path' ])){
if ( ! empty ( $fileDirectory ) ){
$path = VIDEOS_DIR . " / " . $fileDirectory . '/' . $fileName . " * " ;
$vid_files = glob ( $path );
2016-10-28 17:46:19 +05:00
}
2016-11-15 14:50:16 +05:00
else {
$path = VIDEOS_DIR . '/' . $fileName . " * " ;
$vid_files = glob ( $path );
}
if ( ! empty ( $vid_files ) && is_array ( $vid_files )){
$is_convertable = true ;
}
} else {
$is_convertable = true ;
2016-10-28 17:46:19 +05:00
}
2016-11-15 14:50:16 +05:00
if ( $is_convertable ){
return true ;
} else {
return false ;
}
} else {
return false ;
2016-10-28 17:46:19 +05:00
}
2016-11-15 14:50:16 +05:00
} catch ( Exception $e ) {
echo 'Caught exception: ' , $e -> getMessage (), " \n " ;
2016-10-28 17:46:19 +05:00
}
2016-11-15 14:50:16 +05:00
2016-10-28 17:46:19 +05:00
}
/**
* Reconvert any given video in ClipBucket . It will work fine with flv as well as other older files
* as well . You must have at least one video quality available in system for this to work
* @ param : { array } { $data } { $_POST data to read video ids to run re converter against }
* @ since : October 28 th , 2016
* @ author : { Saqib Razzaq }
*/
function reConvertVideos ( $data ) {
global $cbvid , $db , $Upload ;
2016-11-01 15:57:06 +05:00
$toConvert = 0 ;
2016-10-28 17:46:19 +05:00
// if nothing is passed in data array, read from $_POST
if ( ! is_array ( $data )) {
$data = $_POST ;
}
// a list of videos to be reconverted
$videos = $data [ 'check_video' ];
2016-11-01 15:57:06 +05:00
if ( isset ( $_GET [ 'reconvert_video' ])) {
$videos [] = $_GET [ 'reconvert_video' ];
}
2016-10-28 17:46:19 +05:00
// Loop through all video ids
foreach ( $videos as $id => $daVideo ) {
// get details of single video
$vdetails = $cbvid -> get_video ( $daVideo );
2016-11-15 14:50:16 +05:00
if ( ! empty ( $vdetails [ 'file_server_path' ])){
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
if ( empty ( $vdetails [ 'file_directory' ])){
$vdetails [ 'file_directory' ] = str_replace ( '-' , '/' , $vdetails [ 'datecreated' ]);
}
setVideoStatus ( $daVideo , 'Processing' );
$encoded [ 'file_directory' ] = $vdetails [ 'file_directory' ];
$encoded [ 'file_name' ] = $vdetails [ 'file_name' ];
$encoded [ 're-encode' ] = true ;
$api_path = str_replace ( '/files' , '' , $vdetails [ 'file_server_path' ]);
$api_path .= " /actions/re_encode.php " ;
$request = curl_init ( $api_path );
curl_setopt ( $request , CURLOPT_POST , true );
curl_setopt ( $request , CURLOPT_POSTFIELDS , $encoded );
// output the response
curl_setopt ( $request , CURLOPT_SSL_VERIFYPEER , FALSE );
curl_setopt ( $request , CURLOPT_RETURNTRANSFER , true );
$results_curl = curl_exec ( $request );
// pr($results_curl,true);
$results_curl_arr = json_decode ( $results_curl , true );
$returnCode = ( int ) curl_getinfo ( $request , CURLINFO_HTTP_CODE );
curl_close ( $request );
if ( isset ( $results_curl_arr [ 'success' ]) && $results_curl_arr [ 'success' ] == " yes " ){
e ( lang ( 'Your request for re-encoding ' . $vdetails [ 'title' ] . ' has been queued.' ), 'm' );
}
if ( isset ( $results_curl_arr [ 'error' ]) && $results_curl_arr [ 'error' ] == " yes " ){
e ( lang ( $results_curl_arr [ 'msg' ] ) );
}
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
} else {
#pr($vdetails,true);
if ( ! isReconvertAble ( $vdetails )) {
e ( " Video with id " . $vdetails [ 'videoid' ] . " is not re-convertable " );
continue ;
} elseif ( checkReConvStatus ( $vdetails [ 'videoid' ]) == 'started' ) {
e ( " Video with id : " . $vdetails [ 'videoid' ] . " is already processing " );
continue ;
} else {
$toConvert ++ ;
e ( " Started re-conversion process for id " . $vdetails [ 'videoid' ], " m " );
}
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// grab all video files against single video
$video_files = get_video_files ( $vdetails );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// possible array of video qualities
$qualities = array ( '1080' , '720' , '480' , '360' , '240' , 'hd' , 'sd' );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// loop though possible qualities, from high res to low
foreach ( $qualities as $qualNow ) {
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// loop through all video files of current video
// and match theme with current possible quality
foreach ( $video_files as $key => $file ) {
2016-11-01 19:26:50 +05:00
2016-11-15 14:50:16 +05:00
// get quality of current url
$currentQuality = get_video_file_quality ( $file , '-' , '.' );
// pex($currentQuality,true);
// get extension of file
$currentExt = pathinfo ( $file , PATHINFO_EXTENSION );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// if current video file matches with possible quality,
// we have found best quality video
if ( $qualNow === $currentQuality || $currentExt == 'flv' ) {
// You got best quality here, perform action on video
$subPath = str_replace ( BASEURL , '' , $video_files [ $key ]);
$fullPath = BASEDIR . $subPath ;
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// change video status to processing
setVideoStatus ( $daVideo , 'Processing' );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
$file_name = $vdetails [ 'file_name' ]; // e.g : 147765247515e0e
$targetFileName = $file_name . '.mp4' ; // e.g : 147765247515e0e.mp4
$file_directory = $vdetails [ 'file_directory' ]; // e.g : 2016/10/28
$logFile = LOGS_DIR . '/' . $file_directory . '/' . $file_name . '.log' ; // e.g : /var/www/html/cb_root/files/logs/2016/10/28/147765247515e0e.log
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// remove old log file
unlink ( $logFile );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// path of file in temp dir
$newDest = TEMP_DIR . '/' . $targetFileName ;
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// move file from original source to temp
$toTemp = copy ( $fullPath , $newDest );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// add video in conversion qeue
$Upload -> add_conversion_queue ( $targetFileName );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// begin the process of brining back from dead
exec ( php_path () . " -q " . BASEDIR . " /actions/video_convert.php { $targetFileName } { $file_name } { $file_directory } { $logFile } > /dev/null & " );
2016-10-28 17:46:19 +05:00
2016-11-15 14:50:16 +05:00
// set reconversion status
setVideoStatus ( $daVideo , 'started' , true );
break 2 ;
}
2016-10-28 17:46:19 +05:00
}
}
}
2016-11-15 14:50:16 +05:00
2016-10-28 17:46:19 +05:00
}
2016-11-01 15:57:06 +05:00
if ( $toConvert >= 1 ) {
e ( " Reconversion is underway. Kindly don't run reconversion on videos that are already reconverting. Doing so may cause things to become lunatic fringes :P " , " w " );
}
2016-10-28 17:46:19 +05:00
}
2016-12-02 10:50:07 +05:00
/**
* Returns cleaned string containing video qualities
* @ since : 2 nd December , 2016
*/
function resString ( $res ) {
2016-12-02 10:51:03 +05:00
$qual = preg_replace ( " /[^a-zA-Z0-9-,]+/ " , " " , html_entity_decode ( $res , ENT_QUOTES ));
2016-12-02 10:50:07 +05:00
if ( ! empty ( $qual )) {
return $qual ;
}
}
2017-03-22 13:11:00 +05:00
/**
* Used to get Sprite file against video
* @ since : 21 March , 2017
*/
function get_video_sprite ( $video ) {
try {
$filename = $video [ 'file_name' ];
$videoid = $video [ 'videoid' ];
$file_directory = $video [ 'file_directory' ];
$file = SPRITES_DIR . '/' . $file_directory . '/' . $filename . '-sprite.png' ;
if ( file_exists ( $file )){
$file = SPRITES_URL . '/' . $file_directory . '/' . $filename . '-sprite.png' ;
$response [ 'file' ] = $file ;
} else {
$response [ 'file' ] = false ;
}
$sprite_count = get_video_sprite_count ( $videoid );
$response [ 'count' ] = $sprite_count ;
return $response ;
} catch ( Exception $e ){
echo " Caught Exception " . $e -> getMessage ();
}
}
/**
* Used to get Sprite count against video
* @ since : 21 March , 2017
*/
function get_video_sprite_count ( $videoid ){
try {
$videoid = ( int ) $videoid ;
if ( $videoid ){
$query = " SELECT sprite_count FROM " . tbl ( " video " );
$query .= " WHERE videoid=' " . $videoid . " ' " ;
$sprite_count = db_select ( $query );
if ( is_array ( $sprite_count )){
$sprite_count = $sprite_count [ 0 ][ 'sprite_count' ];
} else {
$sprite_count = 0 ;
}
return $sprite_count ;
}
} catch ( Exception $e ){
echo " Caught Exception " . $e -> getMessage ();
}
}