2009-09-01 20:57:38 +00:00
< ? php
/**
* Author : Arslan Hassan
* Script : ClipBucket v2
2010-03-16 18:56:41 +00:00
* License : Attribution Assurance License -- http :// www . opensource . org / licenses / attribution . php
2009-09-01 20:57:38 +00:00
*
*
* Class : Video
* Used to perform function swith videos
* -- history
* all function that were in my_query
* has been transfered here
* however thhey will still work from there
* too
*/
2009-12-04 21:03:27 +00:00
define ( " QUICK_LIST_SESS " , " quick_list " );
2009-09-01 20:57:38 +00:00
class CBvideo extends CBCategory
{
2009-10-03 10:38:28 +00:00
var $embed_func_list = array (); //Function list that are applied while asking for video embed code
2010-07-19 22:19:57 +00:00
var $embed_src_func_list = array (); //Function list that are applied while asking for video embed src
2009-10-10 14:25:07 +00:00
var $action = '' ; // variable used to call action class
2010-11-01 11:01:15 +00:00
var $collection = '' ;
2009-10-10 14:25:07 +00:00
var $email_template_vars = array ();
2009-10-03 10:38:28 +00:00
2009-11-04 10:27:40 +00:00
var $dbtbl = array ( 'video' => 'video' );
2009-11-05 21:50:39 +00:00
var $video_manager_links = array ();
var $video_manager_funcs = array ();
2010-04-26 10:18:23 +00:00
var $video_delete_functions = array (); //Holds all delete functions of video
2009-09-01 20:57:38 +00:00
/**
* __Constructor of CBVideo
*/
2010-03-24 08:31:16 +00:00
function init ()
2009-09-01 20:57:38 +00:00
{
2011-01-03 11:02:54 +00:00
global $Cbucket ;
2009-09-01 20:57:38 +00:00
$this -> cat_tbl = 'video_categories' ;
$this -> section_tbl = 'video' ;
2010-08-19 09:56:41 +00:00
$this -> use_sub_cats = TRUE ;
2009-10-10 14:25:07 +00:00
$this -> init_actions ();
2010-11-01 11:01:15 +00:00
$this -> init_collections ();
2011-01-03 11:02:54 +00:00
if ( isSectionEnabled ( 'videos' ))
$Cbucket -> search_types [ 'videos' ] = " cbvid " ;
2010-11-01 11:01:15 +00:00
}
/**
* Initiating Collections
*/
function init_collections ()
{
$this -> collection = new Collections ();
$this -> collection -> objType = " v " ;
$this -> collection -> objClass = " cbvideo " ;
$this -> collection -> objTable = " video " ;
$this -> collection -> objName = " Video " ;
$this -> collection -> objFunction = " video_exists " ;
$this -> collection -> objFieldID = " videoid " ;
2009-09-01 20:57:38 +00:00
}
/**
* Function used to check weather video exists or not
* @ param VID or VKEY
*/
function video_exists ( $vid )
{
2010-02-02 16:19:41 +00:00
global $db ;
2010-07-26 08:51:34 +00:00
if ( is_numeric ( $vid ))
2010-02-06 07:51:48 +00:00
return $db -> count ( tbl ( " video " ), " videoid " , " videoid=' $vid ' " );
2010-07-26 08:51:34 +00:00
else
return $db -> count ( tbl ( " video " ), " videoid " , " videokey=' $vid ' " );
2010-02-02 16:19:41 +00:00
//return $this->get_video($vid);
2009-09-01 20:57:38 +00:00
}
function exists ( $vid ){ return $this -> video_exists ( $vid );}
function videoexists ( $vid ){ return $this -> video_exists ( $vid );}
/**
* Function used to get video data
*/
function get_video ( $vid )
{
global $db ;
2010-01-28 15:18:54 +00:00
if ( is_numeric ( $vid ))
2011-02-03 17:03:48 +00:00
$results = $db -> select ( tbl ( " video,users " ), tbl ( " video.*,users.userid,users.username " ), tbl ( " video.videoid=' $vid ' " ) . " AND " . tbl ( " video.userid= " ) . tbl ( " users.userid " ));
2010-01-28 15:18:54 +00:00
else
2011-02-03 17:03:48 +00:00
$results = $db -> select ( tbl ( " video,users " ), tbl ( " video.*,users.userid,users.username " ), tbl ( " video.videokey=' $vid ' " ) . " AND " . tbl ( " video.userid= " ) . tbl ( " users.userid " ));
2009-09-01 20:57:38 +00:00
if ( $db -> num_rows > 0 )
{
return $results [ 0 ];
} else {
return false ;
}
}
function getvideo ( $vid ){ return $this -> get_video ( $vid );}
function get_video_data ( $vid ){ return $this -> get_video ( $vid );}
function getvideodata ( $vid ){ return $this -> get_video ( $vid );}
function get_video_details ( $vid ){ return $this -> get_video ( $vid );}
function getvideodetails ( $vid ){ return $this -> get_video ( $vid );}
/**
* Function used to perform several actions with a video
*/
function action ( $case , $vid )
{
global $db ;
2010-03-01 14:33:21 +00:00
$video = $this -> get_video_details ( $vid );
if ( ! $video )
2009-09-01 20:57:38 +00:00
return false ;
//Lets just check weathter video exists or not
switch ( $case )
{
//Activating a video
case 'activate' :
case 'av' :
case 'a' :
{
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( " video " ), array ( 'active' ), array ( 'yes' ), " videoid=' $vid ' OR videokey = ' $vid ' " );
2010-03-30 07:46:02 +00:00
e ( lang ( " class_vdo_act_msg " ), 'm' );
2010-03-01 14:33:21 +00:00
if ( SEND_VID_APPROVE_EMAIL == 'yes' )
{
//Sending Email
global $cbemail , $userquery ;
$tpl = $cbemail -> get_template ( 'video_activation_email' );
$user_fields = $userquery -> get_user_field ( $video [ 'userid' ], " username,email " );
$more_var = array
( '{username}' => $user_fields [ 'username' ],
'{video_link}' => videoLink ( $video )
);
if ( ! is_array ( $var ))
$var = array ();
$var = array_merge ( $more_var , $var );
$subj = $cbemail -> replace ( $tpl [ 'email_template_subject' ], $var );
$msg = nl2br ( $cbemail -> replace ( $tpl [ 'email_template' ], $var ));
//Now Finally Sending Email
cbmail ( array ( 'to' => $user_fields [ 'email' ], 'from' => WEBSITE_EMAIL , 'subject' => $subj , 'content' => $msg ));
}
2009-09-01 20:57:38 +00:00
}
break ;
//Deactivating a video
case " deactivate " :
case " dav " :
case " d " :
{
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( " video " ), array ( 'active' ), array ( 'no' ), " videoid=' $vid ' OR videokey = ' $vid ' " );
2010-03-30 07:46:02 +00:00
e ( lang ( " class_vdo_act_msg1 " ), 'm' );
2009-09-01 20:57:38 +00:00
}
break ;
//Featuring Video
case " feature " :
case " featured " :
case " f " :
{
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( " video " ), array ( 'featured' , 'featured_date' ), array ( 'yes' , now ()), " videoid=' $vid ' OR videokey = ' $vid ' " );
2010-03-30 07:46:02 +00:00
e ( lang ( " class_vdo_fr_msg " ), 'm' );
2009-09-01 20:57:38 +00:00
}
break ;
//Unfeatured video
case " unfeature " :
case " unfeatured " :
case " uf " :
{
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( " video " ), array ( 'featured' ), array ( 'no' ), " videoid=' $vid ' OR videokey = ' $vid ' " );
2010-03-30 07:46:02 +00:00
e ( lang ( " class_fr_msg1 " ), 'm' );
2009-09-01 20:57:38 +00:00
}
break ;
}
}
/**
* Function used to update video
*/
2009-11-04 10:27:40 +00:00
function update_video ( $array = NULL )
2009-09-01 20:57:38 +00:00
{
2010-02-13 12:03:01 +00:00
global $eh , $Cbucket , $db , $Upload ;
2009-11-04 10:27:40 +00:00
2009-09-01 20:57:38 +00:00
$Upload -> validate_video_upload_form ( NULL , TRUE );
if ( empty ( $eh -> error_list ))
{
$required_fields = $Upload -> loadRequiredFields ( $array );
$location_fields = $Upload -> loadLocationFields ( $array );
$option_fields = $Upload -> loadOptionFields ( $array );
$upload_fields = array_merge ( $required_fields , $location_fields , $option_fields );
//Adding Custom Upload Fields
2011-01-26 11:54:48 +00:00
if ( count ( $Upload -> custom_upload_fields ) > 0 )
$upload_fields = array_merge ( $upload_fields , $Upload -> custom_upload_fields );
2010-10-06 08:22:31 +00:00
2009-09-01 20:57:38 +00:00
//Adding Custom Form Fields
if ( count ( $Upload -> custom_form_fields ) > 0 )
$upload_fields = array_merge ( $upload_fields , $Upload -> custom_form_fields );
2009-11-04 10:27:40 +00:00
if ( ! $array )
$array = $_POST ;
2009-09-01 20:57:38 +00:00
$vid = $array [ 'videoid' ];
if ( is_array ( $_FILES ))
$array = array_merge ( $array , $_FILES );
2011-01-26 11:54:48 +00:00
2009-09-01 20:57:38 +00:00
foreach ( $upload_fields as $field )
{
$name = formObj :: rmBrackets ( $field [ 'name' ]);
$val = $array [ $name ];
2010-02-13 12:03:01 +00:00
if ( empty ( $val ) && $field [ 'use_if_value' ])
2009-09-01 20:57:38 +00:00
{
2010-02-13 12:03:01 +00:00
} else
{
if ( $field [ 'use_func_val' ])
$val = $field [ 'validate_function' ]( $val );
if ( ! empty ( $field [ 'db_field' ]))
$query_field [] = $field [ 'db_field' ];
if ( is_array ( $val ))
2009-09-01 20:57:38 +00:00
{
2010-02-13 12:03:01 +00:00
$new_val = '' ;
foreach ( $val as $v )
{
$new_val .= " # " . $v . " # " ;
}
$val = $new_val ;
2009-09-01 20:57:38 +00:00
}
2010-02-13 12:03:01 +00:00
if ( ! $field [ 'clean_func' ] || ( ! apply_func ( $field [ 'clean_func' ], $val ) && ! is_array ( $field [ 'clean_func' ])))
2010-06-24 07:05:52 +00:00
$val = ( $val );
2010-02-13 12:03:01 +00:00
else
2010-03-25 12:14:58 +00:00
$val = apply_func ( $field [ 'clean_func' ], sql_free ( '|no_mc|' . $val ));
2010-02-13 12:03:01 +00:00
if ( ! empty ( $field [ 'db_field' ]))
$query_val [] = $val ;
2010-04-27 15:27:48 +00:00
2009-09-01 20:57:38 +00:00
}
}
#$query = "INSERT INTO video (";
$total_fields = count ( $query_field );
/* for ( $key = 0 ; $key < $total_fields ; $key ++ )
{
$query .= query_field [ $key ] . " = ' " . $query_val [ $key ] . " ' " ;
if ( $key < $total_fields - 1 )
$query .= ',' ;
} */
2009-12-25 17:13:06 +00:00
if ( has_access ( 'admin_access' , TRUE ))
2009-09-14 02:57:19 +00:00
{
2009-12-25 17:13:06 +00:00
if ( ! empty ( $array [ 'status' ]))
{
$query_field [] = 'status' ;
$query_val [] = $array [ 'status' ];
}
if ( ! empty ( $array [ 'duration' ]))
{
$query_field [] = 'duration' ;
$query_val [] = $array [ 'duration' ];
}
if ( ! empty ( $array [ 'views' ]))
{
$query_field [] = 'views' ;
$query_val [] = $array [ 'views' ];
}
if ( ! empty ( $array [ 'rating' ]))
{
$query_field [] = 'rating' ;
$rating = $array [ 'rating' ];
if ( ! is_numeric ( $rating ) || $rating < 0 || $rating > 10 )
$rating = 1 ;
$query_val [] = $rating ;
}
if ( ! empty ( $array [ 'rated_by' ]))
{
$query_field [] = 'rated_by' ;
$query_val [] = $array [ 'rated_by' ];
}
2009-09-14 02:57:19 +00:00
}
2009-09-01 20:57:38 +00:00
if ( ! userid ())
{
2010-02-09 11:47:08 +00:00
e ( lang ( " you_not_logged_in " ));
2009-09-01 20:57:38 +00:00
} elseif ( ! $this -> video_exists ( $vid )){
2010-02-09 13:00:29 +00:00
e ( lang ( " class_vdo_del_err " ));
2009-12-09 13:43:19 +00:00
} elseif ( ! $this -> is_video_owner ( $vid , userid ()) && ! has_access ( 'admin_access' , TRUE ))
2009-11-04 10:27:40 +00:00
{
2010-02-09 13:00:29 +00:00
e ( lang ( " no_edit_video " ));
2009-09-01 20:57:38 +00:00
} else {
2010-10-06 08:22:31 +00:00
//pr($upload_fields);
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( 'video' ), $query_field , $query_val , " videoid=' $vid ' " );
2010-06-24 07:05:52 +00:00
//echo $db->db_query;
2010-03-30 07:46:02 +00:00
e ( lang ( " class_vdo_update_msg " ), 'm' );
2009-09-01 20:57:38 +00:00
}
}
}
2009-09-14 02:57:19 +00:00
/**
* Function used to delete a video
*/
function delete_video ( $vid )
{
global $db ;
if ( $this -> video_exists ( $vid ))
{
2009-11-04 10:27:40 +00:00
2009-09-14 02:57:19 +00:00
$vdetails = $this -> get_video ( $vid );
2009-11-04 10:27:40 +00:00
2009-12-09 13:43:19 +00:00
if ( $this -> is_video_owner ( $vid , userid ()) || has_access ( 'admin_access' , TRUE ))
2009-09-14 02:57:19 +00:00
{
2010-04-26 10:18:23 +00:00
#THIS SHOULD NOT BE REMOVED :O
//list of functions to perform while deleting a video
$del_vid_funcs = $this -> video_delete_functions ;
if ( is_array ( $del_vid_funcs ))
{
foreach ( $del_vid_funcs as $func )
{
if ( function_exists ( $func ))
{
$func ( $vdetails );
}
}
}
2009-11-04 10:27:40 +00:00
//Finally Removing Database entry of video
2010-02-06 07:51:48 +00:00
$db -> execute ( " DELETE FROM " . tbl ( " video " ) . " WHERE videoid=' $vid ' " );
2010-02-13 12:03:01 +00:00
//Removing Video From Playlist
$db -> execute ( " DELETE FROM " . tbl ( " playlist_items " ) . " WHERE object_id=' $vid ' AND playlist_item_type='v' " );
2010-04-27 15:27:48 +00:00
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( " users " ), array ( " total_videos " ), array ( " |f|total_videos-1 " ), " userid=' " . $vdetails [ 'userid' ] . " ' " );
2011-01-25 12:05:11 +00:00
//Removing video Comments
$db -> delete ( tbl ( " comments " ), array ( " type " , " type_id " ), array ( " v " , $vdetails [ 'videoid' ]));
//Removing video From Favortes
$db -> delete ( tbl ( " favorites " ), array ( " type " , " id " ), array ( " v " , $vdetails [ 'videoid' ]));
2010-03-30 07:46:02 +00:00
e ( lang ( " class_vdo_del_msg " ), 'm' );
2009-11-04 10:27:40 +00:00
} else {
e ( lang ( " You cannot delete this video " ));
2009-09-14 02:57:19 +00:00
}
} else {
e ( lang ( " class_vdo_del_err " ));
}
}
/**
* Function used to remove video thumbs
*/
function remove_thumbs ( $vdetails )
{
//First lets get list of all thumbs
$thumbs = get_thumb ( $vdetails , 1 , true , false , false );
if ( ! is_default_thumb ( $thumbs ))
{
if ( is_array ( $thumbs ))
{
foreach ( $thumbs as $thumb )
{
$file = THUMBS_DIR . '/' . $thumb ;
if ( file_exists ( $file ) && is_file ( $file ))
unlink ( $file );
}
} else {
$file = THUMBS_DIR . '/' . $thumbs ;
if ( file_exists ( $file ) && is_file ( $file ))
unlink ( $file );
}
2010-03-30 07:46:02 +00:00
e ( lang ( " vid_thumb_removed_msg " ), 'm' );
2009-09-14 02:57:19 +00:00
}
}
/**
* Function used to remove video log
*/
function remove_log ( $vdetails )
{
global $db ;
$src = $vdetails [ 'videoid' ];
2009-12-09 13:43:19 +00:00
$file = LOGS_DIR . '/' . $vdetails [ 'file_name' ] . '.log' ;
2010-02-06 07:51:48 +00:00
$db -> execute ( " DELETE FROM " . tbl ( " video_file " ) . " WHERE src_name = ' $src ' " );
2009-12-09 13:43:19 +00:00
if ( file_exists ( $file ))
unlink ( $file );
2010-03-30 07:46:02 +00:00
e ( lang ( " vid_log_delete_msg " ), 'm' );
2009-09-14 02:57:19 +00:00
}
/**
* Function used to remove video files
*/
function remove_files ( $vdetails )
{
2010-04-26 10:18:23 +00:00
//Return nothing incase there is no input
if ( ! $vdetails )
{
e ( " No input details specified " );
return false ;
}
//Callign Video Delete Functions
2010-03-30 05:53:27 +00:00
call_delete_video_function ( $vdetails );
2009-09-14 02:57:19 +00:00
//Getting list of files
$files = get_video_file ( $vdetails , false , false , true );
if ( is_array ( $files ))
{
foreach ( $files as $file )
{
if ( file_exists ( VIDEOS_DIR . '/' . $file ) && is_file ( VIDEOS_DIR . '/' . $file ))
unlink ( VIDEOS_DIR . '/' . $file );
}
} else {
if ( file_exists ( VIDEOS_DIR . '/' . $files ) && is_file ( VIDEOS_DIR . '/' . $files ))
unlink ( VIDEOS_DIR . '/' . $files );
}
2010-03-30 07:46:02 +00:00
e ( lang ( " vid_files_removed_msg " ), 'm' );
2009-09-14 02:57:19 +00:00
}
2009-09-28 05:23:50 +00:00
/**
* Function used to get videos
* this function has all options
* that you need to fetch videos
* please see docs . clip - bucket . com for more details
*/
2010-01-27 12:18:17 +00:00
function get_videos ( $params )
2009-09-28 05:23:50 +00:00
{
2009-11-04 10:27:40 +00:00
global $db ;
2009-11-30 19:46:45 +00:00
2009-11-04 10:27:40 +00:00
$limit = $params [ 'limit' ];
$order = $params [ 'order' ];
2010-01-05 09:47:10 +00:00
$cond = " " ;
2011-02-07 15:42:02 +00:00
$superCond = " " ;
2010-01-27 12:18:17 +00:00
if ( ! has_access ( 'admin_access' , TRUE ))
2011-02-07 15:42:02 +00:00
$superCond = $cond .= " " . tbl ( " video.status " ) . " ='Successful' AND
" .tbl( " video . active " ). " = 'yes' AND " .tbl( " video . broadcast " ). " != 'unlisted' " ;
2009-12-25 17:13:06 +00:00
else
{
2010-01-05 09:47:10 +00:00
if ( $params [ 'active' ])
2010-02-06 14:27:00 +00:00
$cond .= " " . tbl ( " video.active " ) . " =' " . $params [ 'active' ] . " ' " ;
2010-01-06 11:59:41 +00:00
2010-01-05 09:47:10 +00:00
if ( $params [ 'status' ])
{
if ( $cond != '' )
$cond .= " AND " ;
2010-02-06 14:27:00 +00:00
$cond .= " " . tbl ( " video.status " ) . " =' " . $params [ 'status' ] . " ' " ;
2010-01-05 09:47:10 +00:00
}
2010-02-25 13:18:33 +00:00
if ( $params [ 'broadcast' ])
{
if ( $cond != '' )
$cond .= " AND " ;
2010-09-22 06:49:12 +00:00
$cond .= " " . tbl ( " video.broadcast " ) . " =' " . $params [ 'broadcast' ] . " ' " ;
2010-02-25 13:18:33 +00:00
}
2009-12-25 17:13:06 +00:00
}
2009-09-28 05:23:50 +00:00
//Setting Category Condition
2009-12-25 17:13:06 +00:00
$all = false ;
if ( ! is_array ( $params [ 'category' ]))
if ( strtolower ( $params [ 'category' ]) == 'all' )
$all = true ;
if ( $params [ 'category' ] && ! $all )
2009-09-28 05:23:50 +00:00
{
2009-11-04 10:27:40 +00:00
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " ( " ;
2009-11-30 19:46:45 +00:00
2009-11-04 10:27:40 +00:00
if ( ! is_array ( $params [ 'category' ]))
2009-09-28 05:23:50 +00:00
{
2009-11-30 19:46:45 +00:00
$cats = explode ( ',' , $params [ 'category' ]);
2009-11-04 10:27:40 +00:00
} else
$cats = $params [ 'category' ];
2009-11-30 19:46:45 +00:00
2009-11-04 10:27:40 +00:00
$count = 0 ;
2009-11-30 19:46:45 +00:00
2009-11-04 10:27:40 +00:00
foreach ( $cats as $cat_params )
{
$count ++ ;
if ( $count > 1 )
$cond .= " OR " ;
2010-02-06 14:47:17 +00:00
$cond .= " " . tbl ( " video.category " ) . " LIKE '%# $cat_params #%' " ;
2009-09-28 05:23:50 +00:00
}
2009-11-04 10:27:40 +00:00
$cond .= " ) " ;
2009-09-28 05:23:50 +00:00
}
//date span
2009-11-04 10:27:40 +00:00
if ( $params [ 'date_span' ])
2009-09-28 05:23:50 +00:00
{
2009-11-04 10:27:40 +00:00
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " " . cbsearch :: date_margin ( " date_added " , $params [ 'date_span' ]);
}
//uid
if ( $params [ 'user' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
2010-02-08 18:04:07 +00:00
$cond .= " " . tbl ( " video.userid " ) . " =' " . $params [ 'user' ] . " ' " ;
2009-11-04 10:27:40 +00:00
}
2010-07-24 14:39:42 +00:00
//non-uid to exclude user videos from related
if ( $params [ 'nonuser' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " " . tbl ( " video.userid " ) . " <> ' " . $params [ 'nonuser' ] . " ' " ;
}
2009-11-04 10:27:40 +00:00
$tag_n_title = '' ;
//Tags
if ( $params [ 'tags' ])
{
2009-11-30 19:46:45 +00:00
//checking for commas ;)
$tags = explode ( " , " , $params [ 'tags' ]);
if ( count ( $tags ) > 0 )
{
if ( $tag_n_title != '' )
$tag_n_title .= ' OR ' ;
$total = count ( $tags );
$loop = 1 ;
foreach ( $tags as $tag )
{
2010-02-06 16:00:33 +00:00
$tag_n_title .= " " . tbl ( 'video.tags' ) . " LIKE '% " . $tag . " %' " ;
2009-11-30 19:46:45 +00:00
if ( $loop < $total )
$tag_n_title .= " OR " ;
$loop ++ ;
}
} else
{
if ( $tag_n_title != '' )
$tag_n_title .= ' OR ' ;
2010-02-06 16:00:33 +00:00
$tag_n_title .= " " . tbl ( 'video.tags' ) . " LIKE '% " . $params [ 'tags' ] . " %' " ;
2009-11-30 19:46:45 +00:00
}
2009-11-04 10:27:40 +00:00
}
//TITLE
if ( $params [ 'title' ])
{
if ( $tag_n_title != '' )
$tag_n_title .= ' OR ' ;
2010-03-16 16:47:05 +00:00
$tag_n_title .= " " . tbl ( 'video.title' ) . " LIKE '% " . $params [ 'title' ] . " %' " ;
2009-09-28 05:23:50 +00:00
}
2009-11-04 10:27:40 +00:00
if ( $tag_n_title )
{
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " ( $tag_n_title ) " ;
}
2009-11-05 21:50:39 +00:00
//FEATURED
if ( $params [ 'featured' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
2010-12-21 11:31:21 +00:00
$cond .= " " . tbl ( " video.featured " ) . " = ' " . $params [ 'featured' ] . " ' " ;
2009-11-05 21:50:39 +00:00
}
2010-03-19 12:32:36 +00:00
//VIDEO ID
if ( $params [ 'videoid' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " " . tbl ( " video.videoid " ) . " = ' " . $params [ 'videoid' ] . " ' " ;
2010-07-26 13:20:47 +00:00
}
2011-01-08 11:11:20 +00:00
//VIDEO ID
if ( $params [ 'videoids' ])
{
if ( is_array ( $params [ 'videoids' ]))
{
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= ' ( ' ;
$curVid = 0 ;
foreach ( $params [ 'videoids' ] as $vid )
{
if ( is_numeric ( $vid ))
{
if ( $curVid > 0 )
$cond .= " OR " ;
$cond .= " " . tbl ( " video.videoid " ) . " = ' " . $vid . " ' " ;
}
$curVid ++ ;
}
$cond .= ' ) ' ;
}
}
2010-07-28 13:04:34 +00:00
//VIDEO KEY
2010-07-26 13:20:47 +00:00
if ( $params [ 'videokey' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " " . tbl ( " video.videokey " ) . " = ' " . $params [ 'videokey' ] . " ' " ;
2010-03-19 12:32:36 +00:00
}
2009-11-30 19:46:45 +00:00
//Exclude Vids
if ( $params [ 'exclude' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
2010-02-06 16:00:33 +00:00
$cond .= " " . tbl ( 'video.videoid' ) . " <> ' " . $params [ 'exclude' ] . " ' " ;
2009-11-30 19:46:45 +00:00
}
2009-11-04 10:27:40 +00:00
2010-03-20 07:24:24 +00:00
if ( $params [ 'cond' ])
$cond .= " " . $params [ 'cond' ];
2010-02-06 14:27:00 +00:00
2010-03-20 07:24:24 +00:00
2010-06-24 07:05:52 +00:00
if ( ! $params [ 'count_only' ] && ! $params [ 'show_related' ])
2010-01-18 07:29:28 +00:00
{
if ( ! empty ( $cond ))
$cond .= " AND " ;
2010-02-06 07:51:48 +00:00
$result = $db -> select ( tbl ( 'video,users' ), tbl ( 'video.*,users.userid,users.username' ), $cond . " " . tbl ( " video.userid " ) . " = " . tbl ( " users.userid " ), $limit , $order );
2010-08-07 11:39:39 +00:00
//echo $db->db_query;
2010-01-18 07:29:28 +00:00
}
2010-08-07 11:39:39 +00:00
2010-03-20 07:24:24 +00:00
2010-06-24 07:05:52 +00:00
if ( $params [ 'show_related' ])
{
2011-02-07 15:42:02 +00:00
$cond = " " ;
if ( $superCond )
$cond = $superCond . " AND " ;
$cond .= " MATCH( " . tbl ( " video.title,video.tags " ) . " )
2010-06-24 07:05:52 +00:00
AGAINST ( '".cbsearch::set_the_key($params[' title '])."' IN BOOLEAN MODE ) " ;
if ( $params [ 'exclude' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " " . tbl ( 'video.videoid' ) . " <> ' " . $params [ 'exclude' ] . " ' " ;
}
2011-02-07 15:42:02 +00:00
2010-06-24 07:05:52 +00:00
$result = $db -> select ( tbl ( 'video,users' ), tbl ( 'video.*,users.userid,users.username' ),
$cond . " AND " . tbl ( " video.userid " ) . " = " . tbl ( " users.userid " ), $limit , $order );
2010-03-20 07:24:24 +00:00
2010-08-07 13:26:24 +00:00
if ( $db -> num_rows == 0 )
{
2011-02-07 15:42:02 +00:00
$cond = " " ;
if ( $superCond )
$cond = $superCond . " AND " ;
2010-08-07 13:26:24 +00:00
//Try Finding videos via tags
2011-02-07 15:42:02 +00:00
$cond .= " MATCH( " . tbl ( " video.title,video.tags " ) . " )
2010-08-07 13:26:24 +00:00
AGAINST ( '".cbsearch::set_the_key($params[' tags '])."' IN BOOLEAN MODE ) " ;
if ( $params [ 'exclude' ])
{
if ( $cond != '' )
$cond .= ' AND ' ;
$cond .= " " . tbl ( 'video.videoid' ) . " <> ' " . $params [ 'exclude' ] . " ' " ;
}
$result = $db -> select ( tbl ( 'video,users' ), tbl ( 'video.*,users.userid,users.username' ),
$cond . " AND " . tbl ( " video.userid " ) . " = " . tbl ( " users.userid " ), $limit , $order );
}
2010-06-24 07:05:52 +00:00
assign ( $params [ 'assign' ], $result );
}
2011-01-25 13:23:03 +00:00
if ( $params [ 'pr' ]) pr ( $result , true );
2009-11-04 10:27:40 +00:00
if ( $params [ 'count_only' ])
2010-02-06 07:51:48 +00:00
return $result = $db -> count ( tbl ( 'video' ), '*' , $cond );
2009-11-04 10:27:40 +00:00
if ( $params [ 'assign' ])
assign ( $params [ 'assign' ], $result );
else
return $result ;
2009-09-28 05:23:50 +00:00
}
2009-11-30 19:46:45 +00:00
/**
* Function used to count total video comments
*/
function count_video_comments ( $id )
{
global $db ;
2010-02-06 07:51:48 +00:00
$total_comments = $db -> count ( tbl ( 'comments' ), " comment_id " , " type='v' AND type_id=' $id ' " );
2009-11-30 19:46:45 +00:00
return $total_comments ;
}
/**
* Function used to update video comments count
*/
function update_comments_count ( $id )
{
global $db ;
$total_comments = $this -> count_video_comments ( $id );
2011-02-07 13:09:51 +00:00
$db -> update ( tbl ( " video " ), array ( " comments_count " , " last_commented " ), array ( $total_comments , now ()), " videoid=' $id ' " );
2009-11-30 19:46:45 +00:00
}
2009-09-28 05:23:50 +00:00
/**
* Function used to add video comment
*/
2010-03-17 08:45:57 +00:00
function add_comment ( $comment , $obj_id , $reply_to = NULL , $force_name_email = false )
2009-09-28 05:23:50 +00:00
{
2009-11-30 19:46:45 +00:00
global $myquery , $db ;
2010-02-02 16:19:41 +00:00
2010-03-01 14:33:21 +00:00
$video = $this -> get_video_details ( $obj_id );
if ( ! $video )
2010-02-09 13:00:29 +00:00
e ( lang ( " class_vdo_del_err " ));
2010-02-02 16:19:41 +00:00
else
2009-11-30 19:46:45 +00:00
{
2010-02-02 16:19:41 +00:00
//Getting Owner Id
$owner_id = $this -> get_video_owner ( $obj_id , true );
2010-03-17 08:45:57 +00:00
$add_comment = $myquery -> add_comment ( $comment , $obj_id , $reply_to , 'v' , $owner_id , videoLink ( $video ), $force_name_email );
2010-02-02 16:19:41 +00:00
if ( $add_comment )
{
//Loggin Comment
$log_array = array
(
'success' => 'yes' ,
'details' => " comment on a video " ,
'action_obj_id' => $obj_id ,
'action_done_id' => $add_comment ,
);
insert_log ( 'video_comment' , $log_array );
//Updating Number of comments of video
$this -> update_comments_count ( $obj_id );
}
return $add_comment ;
2009-11-30 19:46:45 +00:00
}
2009-09-28 05:23:50 +00:00
}
2009-10-03 10:38:28 +00:00
2009-12-04 21:03:27 +00:00
/**
* Function used to remove video comment
*/
function delete_comment ( $cid , $is_reply = FALSE )
{
global $myquery , $db ;
$remove_comment = $myquery -> delete_comment ( $cid , 'v' , $is_reply );
if ( $remove_comment )
{
//Updating Number of comments of video
$this -> update_comments_count ( $obj_id );
}
return $remove_comment ;
}
2009-10-03 10:38:28 +00:00
/**
* Function used to generate Embed Code
*/
function embed_code ( $vdetails )
{
//Checking for video details
if ( ! is_array ( $vdetails ))
{
$vdetails = $this -> get_video ( $vdetails );
}
$embed_code = false ;
2010-04-29 13:46:06 +00:00
$funcs = $this -> embed_func_list ;
2009-10-03 10:38:28 +00:00
if ( is_array ( $funcs ))
{
foreach ( $funcs as $func )
{
if ( @ function_exists ( $func ))
$embed_code = $func ( $vdetails );
}
}
if ( ! $embed_code )
{
//Default ClipBucket Embed Code
if ( function_exists ( 'default_embed_code' ))
{
$embed_code = default_embed_code ( $vdetails );
2010-07-19 22:19:57 +00:00
} else
{
//return new Embed Code
$vid_file = get_video_file ( $vdetails , false , false );
if ( $vid_file )
{
$code = '' ;
$code .= '<object width="' . EMBED_VDO_WIDTH . '" height="' . EMBED_VDO_HEIGHT . '">' ;
$code .= '<param name="movie" value="' . PLAYER_URL . '/embed_player.php?vid=' . $vdetails [ 'videoid' ] . '"></param>' ;
$code .= '<param name="allowFullScreen" value="true"></param>' ;
$code .= '<param name="allowscriptaccess" value="always"></param>' ;
$code .= '<embed src="' . PLAYER_URL . '/embed_player.php?vid=' . $vdetails [ 'videoid' ] . '"' ;
$code .= 'type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="250"></embed>' ;
return $code .= '</object>' ;
} else
{
return embeded_code ( $vdetails );
}
2009-10-03 10:38:28 +00:00
}
}
return $embed_code ;
}
2009-10-10 14:25:07 +00:00
/**
* Function used to initialize action class
* in order to call actions . class . php to
* work with Video section , this function will be called first
*/
function init_actions ()
{
$this -> action = new cbactions ();
2010-03-24 08:31:16 +00:00
$this -> action -> init ();
2009-10-10 14:25:07 +00:00
$this -> action -> type = 'v' ;
$this -> action -> name = 'video' ;
$this -> action -> obj_class = 'cbvideo' ;
2009-10-14 21:09:54 +00:00
$this -> action -> check_func = 'video_exists' ;
2009-11-04 10:27:40 +00:00
$this -> action -> type_tbl = $this -> dbtbl [ 'video' ];
$this -> action -> type_id_field = 'videoid' ;
2009-10-10 14:25:07 +00:00
}
/**
* Function used to create value array for email templates
* @ param video_details ARRAY
*/
function set_share_email ( $details )
{
$this -> email_template_vars = array
( '{video_title}' => $details [ 'title' ],
2010-06-24 07:05:52 +00:00
'{video_description}' => $details [ 'description' ],
'{video_tags}' => $details [ 'tags' ],
2009-10-10 14:25:07 +00:00
'{video_date}' => cbdate ( DATE_FORMAT , strtotime ( $details [ 'date_added' ])),
'{video_link}' => video_link ( $details ),
'{video_thumb}' => GetThumb ( $details )
);
$this -> action -> share_template_name = 'share_video_template' ;
$this -> action -> val_array = $this -> email_template_vars ;
}
2009-09-14 02:57:19 +00:00
2009-10-14 21:09:54 +00:00
/**
* Function used to use to initialize search object for video section
* op => operator ( AND OR )
*/
function init_search ()
{
2011-01-03 11:02:54 +00:00
$this -> search = new cbsearch ;
2010-01-15 15:38:47 +00:00
$this -> search -> db_tbl = " video " ;
2009-10-14 21:09:54 +00:00
$this -> search -> columns = array (
array ( 'field' => 'title' , 'type' => 'LIKE' , 'var' => '%{KEY}%' ),
2011-02-07 15:58:40 +00:00
array ( 'field' => 'tags' , 'type' => 'LIKE' , 'var' => '%{KEY}%' , 'op' => 'OR' ),
array ( 'field' => 'broadcast' , 'type' => '!=' , 'var' => 'unlisted' , 'op' => 'AND' , 'value' => 'static' )
2009-10-14 21:09:54 +00:00
);
2010-06-24 07:05:52 +00:00
$this -> search -> use_match_method = true ;
$this -> search -> match_fields = array ( " title " , " tags " );
2009-10-14 21:09:54 +00:00
$this -> search -> cat_tbl = $this -> cat_tbl ;
2009-12-25 17:13:06 +00:00
2009-12-23 13:06:42 +00:00
$this -> search -> display_template = LAYOUT . '/blocks/video.html' ;
$this -> search -> template_var = 'video' ;
2010-01-15 15:38:47 +00:00
$this -> search -> has_user_id = true ;
2009-10-14 21:09:54 +00:00
/**
* Setting up the sorting thing
*/
$sorting = array (
'date_added' => lang ( " date_added " ),
'views' => lang ( " views " ),
'comments' => lang ( " comments " ),
'rating' => lang ( " rating " ),
'favorites' => lang ( " favorites " )
);
$this -> search -> sorting = array (
'date_added' => " date_added DESC " ,
'views' => " views DESC " ,
'comments' => " comments_count DESC " ,
'rating' => " rating DESC " ,
'favorites' => " favorites DeSC "
);
/**
* Setting Up The Search Fields
*/
$default = $_GET ;
if ( is_array ( $default [ 'category' ]))
$cat_array = array ( $default [ 'category' ]);
$uploaded = $default [ 'datemargin' ];
$sort = $default [ 'sort' ];
2010-01-05 09:47:10 +00:00
$this -> search -> search_type [ 'videos' ] = array ( 'title' => lang ( 'videos' ));
2010-03-03 11:40:20 +00:00
$this -> search -> results_per_page = config ( 'videos_items_search_page' );
2009-12-23 13:06:42 +00:00
2009-10-14 21:09:54 +00:00
$fields = array (
2009-12-25 17:13:06 +00:00
'query' => array (
2009-10-14 21:09:54 +00:00
'title' => lang ( 'keywords' ),
'type' => 'textfield' ,
2009-12-25 17:13:06 +00:00
'name' => 'query' ,
'id' => 'query' ,
'value' => cleanForm ( $default [ 'query' ])
2009-10-14 21:09:54 +00:00
),
'category' => array (
'title' => lang ( 'vdo_cat' ),
'type' => 'checkbox' ,
'name' => 'category[]' ,
'id' => 'category' ,
'value' => array ( 'category' , $cat_array ),
),
'uploaded' => array (
'title' => lang ( 'uploaded' ),
'type' => 'dropdown' ,
'name' => 'datemargin' ,
'id' => 'datemargin' ,
'value' => $this -> search -> date_margins (),
'checked' => $uploaded ,
),
'sort' => array (
'title' => lang ( 'sort_by' ),
'type' => 'dropdown' ,
'name' => 'sort' ,
'value' => $sorting ,
'checked' => $sort
)
);
2009-12-23 13:06:42 +00:00
$this -> search -> search_type [ 'videos' ][ 'fields' ] = $fields ;
2009-10-14 21:09:54 +00:00
}
2009-11-04 10:27:40 +00:00
2009-11-05 21:50:39 +00:00
/*
2009-11-04 10:27:40 +00:00
* Function used to update video and set a thumb as default
* @ param VID
* @ param THUMB NUM
*/
function set_default_thumb ( $vid , $thumb )
{
global $db , $LANG ;
$num = get_thumb_num ( $thumb );
$file = THUMBS_DIR . '/' . $thumb ;
2011-01-19 11:45:34 +00:00
//if(file_exists($file))
//{
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( " video " ), array ( " default_thumb " ), array ( $num ), " videoid=' $vid ' " );
2010-03-30 07:46:02 +00:00
e ( lang ( 'vid_thumb_changed' ), 'm' );
2011-01-19 11:45:34 +00:00
//}else{
// e(lang('vid_thumb_change_err'));
//}
2009-11-04 10:27:40 +00:00
}
2010-02-02 16:19:41 +00:00
/**
* Function used to get video owner
*/
function get_video_owner ( $vid , $idonly = false )
{
global $db ;
if ( $idonly )
{
2010-02-06 07:51:48 +00:00
$results = $db -> select ( tbl ( " video " ), " userid " , " videoid=' $vid ' " , 1 );
2010-02-02 16:19:41 +00:00
if ( $db -> num_rows > 0 )
return $results [ 0 ][ 'userid' ];
else
return false ;
} else {
2010-02-06 07:51:48 +00:00
$results = $db -> select ( tbl ( " video " ), " * " , " videoid=' $vid ' " , 1 );
2010-02-02 16:19:41 +00:00
if ( $db -> num_rows > 0 )
return $results [ 0 ];
else
return false ;
}
}
2009-11-04 10:27:40 +00:00
/**
* Function used to check weather current user is video owner or not
*/
function is_video_owner ( $vid , $uid )
{
global $db ;
2010-02-06 07:51:48 +00:00
$result = $db -> count ( tbl ( $this -> dbtbl [ 'video' ]), 'videoid' , " videoid=' $vid ' AND userid=' $uid ' " );
2009-11-04 10:27:40 +00:00
if ( $result > 0 )
return true ;
else
return false ;
}
2009-11-05 21:50:39 +00:00
/**
* Function used to display video manger link
*/
function video_manager_link ( $link , $vid )
{
if ( function_exists ( $link ) && ! is_array ( $link ))
{
return $link ( $vid );
} else
{
if ( ! empty ( $link [ 'title' ]) && ! empty ( $link [ 'link' ]))
{
return ' | <a href="' . $link [ 'link' ] . '">' . $link [ 'title' ] . '</a>' ;
}
}
}
2009-11-04 10:27:40 +00:00
2009-11-30 19:46:45 +00:00
/**
* Function used to get video rating details
*/
function get_video_rating ( $id )
{
global $db ;
2010-03-03 09:44:32 +00:00
if ( is_numeric ( $id ))
2010-01-27 12:18:17 +00:00
{
2010-03-03 09:44:32 +00:00
$results = $db -> select ( tbl ( " video " ), " allow_rating,rating,rated_by,voter_ids " , " videoid=' $id ' " );
2010-01-27 12:18:17 +00:00
} else
2010-03-03 09:44:32 +00:00
$results = $db -> select ( tbl ( " video " ), " allow_rating,rating,rated_by,voter_ids " , " videokey=' $id ' " );
2009-11-30 19:46:45 +00:00
if ( $db -> num_rows > 0 )
2010-03-03 09:44:32 +00:00
return $results [ 0 ];
2009-11-30 19:46:45 +00:00
else
return false ;
}
/**
* Function used to display rating option for videos
* this is an OLD TYPICAL RATING SYSTEM
* and yes , still with AJAX
*/
function show_video_rating ( $params )
{
$rating = $params [ 'rating' ];
$ratings = $params [ 'ratings' ];
$total = $params [ 'total' ];
$id = $params [ 'id' ];
$type = $params [ 'type' ];
//Checking Percent
if ( $rating <= 0 )
$perc = '0' ;
else
{
if ( $total <= 1 )
$total = 1 ;
$perc = $rating * 100 / $total ;
}
$perc = $perc . '%' ;
if ( $params [ 'is_rating' ])
{
if ( error ())
{
$rating_msg = error ();
$rating_msg = '<span class="error">' . $rating_msg [ 0 ] . '</span>' ;
}
if ( msg ())
{
$rating_msg = msg ();
$rating_msg = '<span class="msg">' . $rating_msg [ 0 ] . '</span>' ;
}
}
assign ( 'perc' , $perc );
assign ( 'id' , $id );
assign ( 'type' , $type );
assign ( 'id' , $id );
assign ( 'rating_msg' , $rating_msg );
assign ( 'disable' , $params [ 'disable' ]);
Template ( 'blocks/rating.html' );
}
/**
* Function used to rate video
*/
function rate_video ( $id , $rating )
{
global $db ;
if ( ! is_numeric ( $rating ) || $rating < 1 )
$rating = 1 ;
if ( $rating > 10 )
$rating = 10 ;
$rating_details = $this -> get_video_rating ( $id );
$voter_id = $rating_details [ 'voter_ids' ];
$new_by = $rating_details [ 'rated_by' ];
$newrate = $rating_details [ 'rating' ];
$niddle = " | " ;
$niddle .= userid ();
$niddle .= " | " ;
$flag = strstr ( $voter_id , $niddle );
2010-03-03 08:51:43 +00:00
//checking if raings are allowed or not
$vid_rating = config ( 'video_rating' );
2009-11-30 19:46:45 +00:00
if ( ! empty ( $flag ))
2010-02-09 13:00:29 +00:00
e ( lang ( " you_hv_already_rated_vdo " ));
2009-11-30 19:46:45 +00:00
elseif ( ! userid ())
2010-02-09 13:00:29 +00:00
e ( lang ( " please_login_to_rate " ));
2010-03-03 09:44:32 +00:00
elseif ( $vid_rating != 1 || $rating_details [ 'allow_rating' ] != 'yes' )
2010-03-03 08:58:29 +00:00
e ( lang ( " vid_rate_disabled " ));
2009-11-30 19:46:45 +00:00
else
{
if ( empty ( $voter_id ))
$voter_id .= " | " ;
$voter_id .= userid ();
$voter_id .= " | " ;
$t = $rating_details [ 'rated_by' ] * $rating_details [ 'rating' ];
$new_by = $rating_details [ 'rated_by' ] + 1 ;
$newrate = ( $t + $rating ) / $new_by ;
2010-02-06 07:51:48 +00:00
$db -> update ( tbl ( $this -> dbtbl [ 'video' ]), array ( " rating " , " rated_by " , " voter_ids " ), array ( $newrate , $new_by , $voter_id ), " videoid=' $id ' " );
2010-02-09 13:00:29 +00:00
e ( lang ( " thnx_for_voting " ), " m " );
2009-11-30 19:46:45 +00:00
}
$result = array ( 'rating' => $newrate , 'ratings' => $new_by , 'total' => 10 , 'id' => $id , 'type' => 'video' , 'disable' => 'disabled' );
return $result ;
}
/**
* Function used to get playlist items
*/
function get_playlist_items ( $pid )
{
global $db ;
2010-02-06 07:51:48 +00:00
$ptbl = tbl ( $this -> action -> playlist_items_tbl );
$vtbl = tbl ( $this -> dbtbl [ 'video' ]);
2009-11-30 19:46:45 +00:00
$tbls = $ptbl . ',' . $vtbl ;
$fields = $ptbl . " .*, $vtbl .title, $vtbl .comments_count, $vtbl .views, $vtbl .userid, $vtbl .date_added,
2010-02-13 12:05:32 +00:00
$vtbl . file_name , $vtbl . category , $vtbl . description , $vtbl . videokey , $vtbl . tags , $vtbl . videoid , $vtbl . duration " ;
2009-11-30 19:46:45 +00:00
$result = $db -> select ( $tbls , $fields , " playlist_id=' $pid ' AND " . $vtbl . " .videoid= " . $ptbl . " .object_id " );
if ( $db -> num_rows > 0 )
return $result ;
else
return false ;
2009-12-04 21:03:27 +00:00
}
/**
* Function used to add video in quicklist
*/
function add_to_quicklist ( $id )
{
2011-01-08 11:11:20 +00:00
global $json , $sess , $userquery ;
2009-12-04 21:03:27 +00:00
if ( $this -> exists ( $id ))
{
2010-04-01 00:09:39 +00:00
if ( phpversion () < '5.2.0' )
{
2011-01-08 11:11:20 +00:00
$list = $json -> decode ( $sess -> get_cookie ( QUICK_LIST_SESS ), true );
2010-04-01 00:09:39 +00:00
}
else
{
2011-01-08 11:11:20 +00:00
$list = json_decode ( $sess -> get_cookie ( QUICK_LIST_SESS ), true );
2010-04-01 00:09:39 +00:00
}
2011-01-08 11:11:20 +00:00
2009-12-04 21:03:27 +00:00
$list [] = $id ;
$new_list = array_unique ( $list );
2011-01-08 11:11:20 +00:00
/*// Getting list of videos
$vids = $this -> get_videos ( array ( 'videoids' => $new_list ));
$newlist = array ();
//setting up the list
if ( $vids )
foreach ( $vids as $vid )
{
$newlist [ $vid [ 'videoid' ]] =
array (
'title' => $vid [ 'title' ],
'description' => $vid [ 'description' ],
'duration' => SetTime ( $vid [ 'duration' ]),
'thumb' => get_thumb ( $vid ),
'url' => video_link ( $video ),
'owner' => $vid [ 'username' ],
'ownner_url' => $userquery -> profile_link ( $vid ),
'date_added' => $vid [ 'date_added' ],
'views' => $vid [ 'views' ],
);
} */
2010-04-01 00:09:39 +00:00
if ( phpversion () < '5.2.0' )
{
2011-01-11 13:56:34 +00:00
$sess -> set_cookie ( QUICK_LIST_SESS , $json -> encode ( $new_list ));
2010-04-01 00:09:39 +00:00
}
else
{
2011-01-11 13:56:34 +00:00
$sess -> set_cookie ( QUICK_LIST_SESS , json_encode ( $new_list ));
2010-04-01 00:09:39 +00:00
}
2009-12-04 21:03:27 +00:00
return true ;
} else
return false ;
}
/**
* Removing video from quicklist
*/
function remove_from_quicklist ( $id )
{
2010-04-01 00:09:39 +00:00
global $json , $sess ;
if ( phpversion () < '5.2.0' )
{
2011-01-08 11:11:20 +00:00
$list = $json -> decode ( $sess -> get_cookie ( QUICK_LIST_SESS ), true );
2010-04-01 00:09:39 +00:00
}
else
{
2011-01-08 11:11:20 +00:00
$list = json_decode ( $sess -> get_cookie ( QUICK_LIST_SESS ), true );
2010-04-01 00:09:39 +00:00
}
2009-12-04 21:03:27 +00:00
$key = array_search ( $id , $list );
unset ( $list [ $key ]);
2010-04-01 00:09:39 +00:00
if ( phpversion () < '5.2.0' )
{
2011-01-08 11:11:20 +00:00
$sess -> set_cookie ( QUICK_LIST_SESS , $json -> encode ( $list ));
2010-04-01 00:09:39 +00:00
}
else
{
2011-01-08 11:11:20 +00:00
$sess -> set_cookie ( QUICK_LIST_SESS , json_encode ( $list ));
2010-04-01 00:09:39 +00:00
}
2009-12-04 21:03:27 +00:00
return true ;
}
/**
* function used to count num of quicklist
*/
function total_quicklist ()
{
2010-04-01 00:09:39 +00:00
global $json , $sess ;
2011-01-08 11:11:20 +00:00
$total = $sess -> get_cookie ( QUICK_LIST_SESS );
2010-04-01 00:09:39 +00:00
if ( phpversion () < '5.2.0' )
{
$total = $json -> decode ( $total , true );
}
else
{
$total = json_decode ( $total , true );
}
2011-01-08 11:11:20 +00:00
2009-12-04 21:03:27 +00:00
return count ( $total );
}
/**
* Function used to get quicklist
*/
function get_quicklist ()
{
2010-04-01 00:09:39 +00:00
global $json , $sess ;
if ( phpversion () < '5.2.0' )
{
2011-01-08 11:11:20 +00:00
return $json -> decode ( $sess -> get_cookie ( QUICK_LIST_SESS ), true );
2010-04-01 00:09:39 +00:00
}
else
{
2011-01-08 11:11:20 +00:00
return json_decode ( $sess -> get_cookie ( QUICK_LIST_SESS ), true );
2010-04-01 00:09:39 +00:00
}
2009-12-04 21:03:27 +00:00
}
/**
* Function used to remove all items of quicklist
*/
function clear_quicklist ()
{
global $sess ;
2011-01-08 11:11:20 +00:00
$sess -> set_cookie ( QUICK_LIST_SESS , '' );
2009-12-04 21:03:27 +00:00
}
2010-03-02 14:50:54 +00:00
/**
* Function used to check weather video is downloadable or not
*/
function downloadable ( $vdo )
{
$file = get_video_file ( $vdo , false );
if ( $file )
return true ;
else
return false ;
}
2010-03-16 16:47:05 +00:00
/**
* Function used get comments of videos
*/
2010-03-19 11:39:18 +00:00
function get_comments ( $params = NULL )
2010-03-16 16:47:05 +00:00
{
global $db ;
2010-03-19 11:39:18 +00:00
$comtbl = tbl ( " comments " );
$limit = $params [ 'limit' ];
$order = $params [ 'order' ];
$type = $params [ 'type' ];
2010-03-16 16:47:05 +00:00
2010-03-19 11:39:18 +00:00
if ( $type )
$cond = " $comtbl .type = ' $type ' " ;
else
$cond = '' ;
switch ( $type ) {
case 'v' :
{
$sectbl = tbl ( 'video' );
$sectblName = 'video' ;
$secfields = $sectbl . " .videokey, " . $sectbl . " .videoid, " . $sectbl . " .file_name, " . $sectbl . " .title " ;
if ( $cond ) {
$cond .= " AND " ;
}
$cond .= " $comtbl .type_id = $sectbl .videoid " ;
}
break ;
case 't' :
{
$sectbl = tbl ( 'group_topics' );
$sectblName = 'group_topics' ;
$secfields = $sectbl . " .topic_title, " . $sectbl . " .topic_id, " . $sectbl . " .topic_title " ;
if ( $cond ) {
$cond .= " AND " ;
}
$cond .= " $comtbl .type_id = $sectbl .topic_id " ;
}
break ;
case 'c' :
{
$sectbl = tbl ( 'users' );
$sectblName = 'users' ;
$secfields = $sectbl . " .username, " . $sectbl . " .userid " ;
if ( $cond ) {
$cond .= " AND " ;
}
$cond .= " $comtbl .type_id = $sectbl .userid " ;
}
2010-03-20 07:24:24 +00:00
break ;
2010-03-19 11:39:18 +00:00
default :
{
$sectbl = tbl ( 'video' );
$sectblName = 'video' ;
$secfields = $sectbl . " .videokey, " . $sectbl . " .videoid, " . $sectbl . " .file_name, " . $sectbl . " .title " ;
if ( $cond ) {
$cond .= " AND " ;
}
$cond .= " $comtbl .type_id = $sectbl .videoid " ;
}
}
2010-03-20 07:24:24 +00:00
if ( $params [ 'cond' ])
$cond .= " " . $params [ 'cond' ];
2010-03-19 11:39:18 +00:00
if ( ! $params [ 'count_only' ]) {
$result = $db -> select ( tbl ( " comments, " . $sectblName . " " ),
" $comtbl .*, $secfields " ,
$cond , $limit , $order );
2010-03-19 13:26:16 +00:00
// echo $db->db_query;
2010-03-16 16:47:05 +00:00
}
2010-03-19 11:39:18 +00:00
if ( $params [ 'count_only' ])
return $result = $db -> count ( tbl ( " comments,video " ), " * " , $cond );
else
2010-03-16 16:47:05 +00:00
return $result ;
2010-03-19 11:39:18 +00:00
}
/**
* Function used get single comment
*/
2010-03-02 14:50:54 +00:00
2010-03-19 11:39:18 +00:00
function get_comment ( $cid ) {
global $db ;
$result = $db -> select ( tbl ( " comments " ), " * " , " comment_id = $cid " );
if ( $result )
return $result [ 0 ];
else
return false ;
}
/**
* Function used update comment
*/
2010-03-20 08:39:04 +00:00
// function update_comment($cid,$comment) {
// global $db;
// if(!$comment) {
// e(lang('usr_cmt_err1'),e);
// } else {
// $db->update(tbl("comments"),array("comment"),array($comment)," comment_id = $cid");
// e(lang("Comment Updated"),m);
// }
// }
2010-03-02 14:50:54 +00:00
2009-09-14 02:57:19 +00:00
}
2009-09-01 20:57:38 +00:00
?>