clipbucket/upload/includes/classes/video.class.php

2375 lines
78 KiB
PHP
Raw Normal View History

2009-09-01 20:57:38 +00:00
<?php
2012-09-04 10:38:50 +00:00
2009-09-01 20:57:38 +00:00
/**
* Author : Arslan Hassan
* Script : ClipBucket v2
* 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
*/
2012-09-04 10:38:50 +00:00
define("QUICK_LIST_SESS", "quick_list");
class CBvideo extends CBCategory {
var $embed_func_list = array(); //Function list that are applied while asking for video embed code
var $embed_src_func_list = array(); //Function list that are applied while asking for video embed src
var $action = ''; // variable used to call action class
var $collection = '';
var $email_template_vars = array();
var $dbtbl = array('video' => 'video');
var $video_manager_links = array();
var $video_manager_funcs = array();
var $video_delete_functions = array(); //Holds all delete functions of video
/**
* __Constructor of CBVideo
*/
function init() {
global $Cbucket;
$this->cat_tbl = 'video_categories';
$this->section_tbl = 'video';
$this->use_sub_cats = TRUE;
$this->init_actions();
$this->init_collections();
if (config('vid_cat_height'))
;
$this->cat_thumb_height = config('vid_cat_height');
if (config('vid_cat_width'))
;
$this->cat_thumb_width = config('vid_cat_width');
if (isSectionEnabled('videos'))
$Cbucket->search_types['videos'] = "cbvid";
$Cbucket->clipbucket_footer[] = 'check_cbvideo';
$this->video_delete_functions[] = 'delete_video_from_collection';
}
/**
* 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";
}
/**
* Function used to check weather video exists or not
* @param VID or VKEY
*/
function video_exists($vid) {
global $db;
if (is_numeric($vid))
return $db->count(tbl("video"), "videoid", " videoid='$vid' ");
else
return $db->count(tbl("video"), "videoid", " videokey='$vid' ");
//return $this->get_video($vid);
}
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, $file = false) {
global $db;
$userFields = array('userid', 'username', 'avatar', 'avatar_url',
'email', 'total_videos');
$ufieldsQuery = "";
foreach ($userFields as $ufield)
$ufieldsQuery .= ',users.' . $ufield;
if (!$file) {
if (is_numeric($vid))
$cond = tbl("video.videoid='$vid'");
else
$cond = tbl("video.videokey='$vid'");
}else
$cond = tbl("video.file_name='$vid'");
2012-09-12 10:00:57 +00:00
$meta_query = $this->create_meta_query();
2012-09-04 10:38:50 +00:00
$results = $db->select(
//Joining Slugs and User table
tbl("video")
2012-09-04 10:38:50 +00:00
. ' LEFT JOIN ' . tbl('users') . ' ON '
. tbl('video.userid') . ' = ' . tbl('users.userid')
. ' LEFT JOIN ' . tbl('slugs') . ' ON '
2012-09-12 10:00:57 +00:00
. tbl('video.slug_id') . ' = ' . tbl('slugs.slug_id')
.' LEFT JOIN ' . tbl('video_meta') . ' ON '
. tbl('video.videoid') . ' = ' . tbl('video_meta.videoid'),
//Selecting fields
2012-09-12 10:00:57 +00:00
tbl("video.*" . $ufieldsQuery . ",slugs.*").','.$meta_query,
//Addind Condition
$cond);
//echo $db->db_query;
2012-09-04 10:38:50 +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, $eh;
$video = $this->get_video_details($vid);
if (!$video)
return false;
//Lets just check weathter video exists or not
switch ($case) {
//Activating a video
case 'activate':
case 'av':
case 'a': {
$db->update(tbl("video"), array('active'), array('yes'), " videoid='$vid' OR videokey = '$vid' ");
e(lang("class_vdo_act_msg"), 'm');
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));
}
if (($video['broadcast'] == 'public' || $video['broadcast'] == "logged")
&& $video['subscription_email'] == 'pending') {
//Sending Subscription email in background
if (stristr(PHP_OS, 'WIN')) {
exec(php_path() . " -q " . BASEDIR . "/actions/send_subscription_email.php $vid ");
} else {
exec(php_path() . " -q " . BASEDIR . "/actions/send_subscription_email.php $vid &> /dev/null &");
}
2012-09-04 10:38:50 +00:00
}
}
break;
//Deactivating a video
case "deactivate":
case "dav":
case "d": {
$db->update(tbl("video"), array('active'), array('no'), " videoid='$vid' OR videokey = '$vid' ");
e(lang("class_vdo_act_msg1"), 'm');
}
break;
//Featuring Video
case "feature":
case "featured":
case "f": {
$db->update(tbl("video"), array('featured', 'featured_date'), array('yes', now()), " videoid='$vid' OR videokey = '$vid' ");
e(lang("class_vdo_fr_msg"), 'm');
}
break;
//Unfeatured video
case "unfeature":
case "unfeatured":
case "uf": {
$db->update(tbl("video"), array('featured'), array('no'), " videoid='$vid' OR videokey = '$vid' ");
e(lang("class_fr_msg1"), 'm');
}
break;
}
}
/**
* Function used to update video
*/
function update_video($array = NULL) {
global $eh, $Cbucket, $db, $Upload;
$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
if (count($Upload->custom_upload_fields) > 0)
$upload_fields = array_merge($upload_fields, $Upload->custom_upload_fields);
//Adding Custom Form Fields
if (count($Upload->custom_form_fields) > 0)
$upload_fields = array_merge($upload_fields, $Upload->custom_form_fields);
//Adding custom fields from group
if (count($Upload->custom_form_fields_groups) > 0) {
$custom_fields_from_group_fields = array();
$custom_fields_from_group = $Upload->custom_form_fields_groups;
foreach ($custom_fields_from_group as $cffg) {
$custom_fields_from_group_fields = array_merge($custom_fields_from_group_fields, $cffg['fields']);
}
$upload_fields = array_merge($upload_fields, $custom_fields_from_group_fields);
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
if (!$array)
$array = $_POST;
$vid = $array['videoid'];
$the_video = get_video_details($vid);
if (is_array($_FILES))
$array = array_merge($array, $_FILES);
foreach ($upload_fields as $field) {
$name = formObj::rmBrackets($field['name']);
$val = $array[$name];
if (empty($val) && $field['use_if_value']) {
} 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)) {
$new_val = '';
foreach ($val as $v) {
$new_val .= "#" . $v . "# ";
}
$val = $new_val;
}
if (!$field['clean_func'] || (!apply_func($field['clean_func'], $val) && !is_array($field['clean_func'])))
$val = ($val);
else
$val = apply_func($field['clean_func'], sql_free('|no_mc|' . $val));
if (!empty($field['db_field']))
$query_val[] = $val;
}
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +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 .= ',';
} */
if (has_access('admin_access', TRUE)) {
if (!empty($array['status'])) {
$query_field[] = 'status';
$query_val[] = $array['status'];
}
if (!empty($array['duration']) && is_numeric($array['duration']) && $array['duration'] > 0) {
$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'];
}
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
if (!userid()) {
e(lang("you_dont_have_permission_to_update_this_video"));
} elseif (!$this->video_exists($vid)) {
e(lang("class_vdo_del_err"));
} elseif (!$this->is_video_owner($vid, userid()) && !has_access('admin_access', TRUE)) {
e(lang("no_edit_video"));
} else {
//pr($upload_fields);
//Updating Slug
if (config('auto_update_slug') != 'no' || !$the_video['slug']) {
if ($the_video['title'] != $array['title']) {
$slug = slug($array['title']);
if ($the_video['slug'] != $slug) {
$db->update(tbl('slugs'), array('in_use')
, array('no'), "object_id='$vid' AND object_type='v' ");
$slug_arr = add_slug($slug, $vid, 'v');
$query_field[] = 'slug_id';
$query_val[] = $slug_arr['id'];
}
}
}
$db->update(tbl('video'), $query_field, $query_val, " videoid='$vid'");
//echo $db->db_query;
e(lang("class_vdo_update_msg"), 'm');
2010-04-01 00:09:39 +00:00
}
}
2012-09-04 10:38:50 +00:00
}
/**
* Function used to delete a video
*/
function delete_video($vid) {
global $db;
if ($this->video_exists($vid)) {
$vdetails = $this->get_video($vid);
if ($this->is_video_owner($vid, userid()) || has_access('admin_access', TRUE)) {
#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);
}
}
}
//Finally Removing Database entry of video
$db->execute("DELETE FROM " . tbl("video") . " WHERE videoid='$vid'");
//Removing Video From Playlist
$db->execute("DELETE FROM " . tbl("playlist_items") . " WHERE object_id='$vid' AND playlist_item_type='v'");
$db->update(tbl("users"), array("total_videos"), array("|f|total_videos-1"), " userid='" . $vdetails['userid'] . "'");
//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']));
e(lang("class_vdo_del_msg"), 'm');
} else {
e(lang("You cannot delete this video"));
}
} else {
e(lang("class_vdo_del_err"));
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
}
/**
* 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);
}
e(lang("vid_thumb_removed_msg"), 'm');
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
}
/**
* Function used to remove video log
*/
function remove_log($vdetails) {
global $db;
$src = $vdetails['videoid'];
$file = LOGS_DIR . '/' . $vdetails['file_name'] . '.log';
$db->execute("DELETE FROM " . tbl("video_file") . " WHERE src_name = '$src'");
if (file_exists($file))
unlink($file);
e(lang("vid_log_delete_msg"), 'm');
}
/**
* Function used to remove video files
*/
function remove_files($vdetails) {
//Return nothing incase there is no input
if (!$vdetails) {
e("No input details specified");
return false;
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
//Callign Video Delete Functions
call_delete_video_function($vdetails);
//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-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
e(lang("vid_files_removed_msg"), 'm');
}
/**
* 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
*/
function get_videos($params) {
global $db;
$limit = $params['limit'];
$order = $params['order'];
$cond = "";
$superCond = "";
if (!has_access('admin_access', TRUE)) {
$superCond = $cond .= " " . tbl("video.status") . "='Successful' AND
" . tbl("video.active") . "='yes' AND " . tbl("video.broadcast") . " !='unlisted' ";
} else {
if ($params['active'])
$cond .= " " . tbl("video.active") . "='" . $params['active'] . "'";
if ($params['status']) {
if ($cond != '')
$cond .=" AND ";
$cond .= " " . tbl("video.status") . "='" . $params['status'] . "'";
}
if ($params['broadcast']) {
if ($cond != '')
$cond .=" AND ";
$cond .= " " . tbl("video.broadcast") . "='" . $params['broadcast'] . "'";
}
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
//Setting Category Condition
$all = false;
if (!is_array($params['category']))
if (strtolower($params['category']) == 'all')
$all = true;
if ($params['category'] && !$all) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " (";
if (!is_array($params['category'])) {
$cats = explode(',', $params['category']);
}else
$cats = $params['category'];
$count = 0;
foreach ($cats as $cat_params) {
$count++;
if ($count > 1)
$cond .=" OR ";
$cond .= " " . tbl("video.category") . " LIKE '%#$cat_params#%' ";
}
$cond .= ")";
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
//date span
if ($params['date_span']) {
if ($cond != '')
$cond .= ' AND ';
if ($params['date_span_column'])
$column = $params['date_span_column'];
else
$column = 'date_added';
$cond .= " " . cbsearch::date_margin($column, $params['date_span']);
2010-04-01 00:09:39 +00:00
}
2012-09-04 10:38:50 +00:00
//uid
if ($params['user'] || $params['userid']) {
if ($params['userid'])
$params['user'] = $params['userid'];
if (!is_array($params['user'])) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl("video.userid") . "='" . $params['user'] . "'";
}else {
if ($cond != '')
$cond .= ' AND (';
$uQu = 0;
foreach ($params['user'] as $user) {
if ($uQu > 0)
$cond .= ' OR ';
$cond .= " " . tbl("video.userid") . "='" . $user . "'";
$uQu++;
2012-07-10 20:25:48 +00:00
}
2012-09-04 10:38:50 +00:00
$cond .=" ) ";
2012-07-10 20:25:48 +00:00
}
}
2012-09-04 10:38:50 +00:00
//non-uid to exclude user videos from related
if ($params['nonuser']) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl("video.userid") . " <> '" . $params['nonuser'] . "' ";
}
$tag_n_title = '';
//Tags
if ($params['tags']) {
//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) {
$tag_n_title .= " " . tbl('video.tags') . " LIKE '%" . $tag . "%'";
if ($loop < $total)
$tag_n_title .= " OR ";
$loop++;
}
}else {
if ($tag_n_title != '')
$tag_n_title .= ' OR ';
$tag_n_title .= " " . tbl('video.tags') . " LIKE '%" . $params['tags'] . "%'";
2012-07-10 20:25:48 +00:00
}
}
2012-09-04 10:38:50 +00:00
//TITLE
if ($params['title']) {
if ($tag_n_title != '')
$tag_n_title .= ' OR ';
$tag_n_title .= " " . tbl('video.title') . " LIKE '%" . $params['title'] . "%'";
}
2012-09-04 10:38:50 +00:00
if ($tag_n_title) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " ($tag_n_title) ";
2012-07-10 20:25:48 +00:00
}
2012-09-04 10:38:50 +00:00
//FEATURED
if ($params['featured']) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl("video.featured") . " = '" . $params['featured'] . "' ";
}
//VIDEO ID
if ($params['videoid']) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl("video.videoid") . " = '" . $params['videoid'] . "' ";
}
//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 .= ' ) ';
2012-07-10 20:25:48 +00:00
}
}
2012-09-04 10:38:50 +00:00
//VIDEO KEY
if ($params['videokey']) {
if (!is_array($params['videokey'])) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl("video.videokey") . " = '" . $params['videokey'] . "' ";
}else {
if ($cond != '')
$cond .= ' AND (';
$vkeyQue = 0;
foreach ($params['videokey'] as $videokey) {
if ($vkeyQue > 0)
$cond .= ' OR ';
$cond .= " " . tbl("video.videokey") . " = '" . $videokey . "' ";
$vkeyQue++;
}
$cond .=" ) ";
}
}
//Exclude Vids
if ($params['exclude']) {
if (!is_array($params['exclude'])) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl('video.videoid') . " <> '" . $params['exclude'] . "' ";
}else {
foreach ($params['exclude'] as $exclude) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl('video.videoid') . " <> '" . $exclude . "' ";
}
}
}
//Duration
if ($params['duration']) {
$duration_op = $params['duration_op'];
if (!$duration_op)
$duration_op = "=";
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl('video.duration') . " " . $duration_op . " '" . $params['duration'] . "' ";
}
//Filename
if ($params['filename']) {
if (!is_array($params['filename'])) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl('video.file_name') . " <> '" . $params['filename'] . "' ";
}else {
if ($cond != '')
$cond .= ' AND (';
2012-07-10 20:25:48 +00:00
else
2012-09-04 10:38:50 +00:00
$cond .=" ( ";
$fileNameQue = 0;
foreach ($params['filename'] as $filename) {
if ($fileNameQue > 0)
$cond .= ' OR ';
$cond .= " " . tbl("video.file_name") . " = '" . $filename . "' ";
$fileNameQue++;
}
$cond .=" ) ";
2012-07-10 20:25:48 +00:00
}
2012-09-04 10:38:50 +00:00
}
if ($params['cond']) {
if ($params['cond_and'])
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . $params['cond'];
}
$functions = cb_get_functions('get_videos');
if ($functions) {
foreach ($functions as $func) {
$array = array('params' => $params, 'cond' => $cond);
if (function_exists($func['func'])) {
$returned = $func['func']($array);
if ($returned)
$cond = $returned;
2012-07-10 20:25:48 +00:00
}
}
}
2012-09-04 10:38:50 +00:00
if (!$params['count_only'] && !$params['show_related']) {
$userFields = array('userid', 'email', 'username');
foreach ($userFields as $ufield) {
$ufieldq .= ",users." . $ufield;
}
if (!empty($cond))
$cond .= " AND ";
2012-09-12 10:00:57 +00:00
2012-09-04 16:28:33 +00:00
$meta_query = $this->create_meta_query();
2012-09-12 10:00:57 +00:00
2012-09-04 10:38:50 +00:00
$result = $db->select(tbl('video')
. ' LEFT JOIN ' . tbl('users') . ' ON '
. tbl('video.userid') . ' = ' . tbl('users.userid')
. ' LEFT JOIN ' . tbl('slugs') . ' ON '
. tbl('video.slug_id') . ' = ' . tbl('slugs.slug_id')
2012-09-04 16:28:33 +00:00
. ' LEFT JOIN ' . tbl('video_meta') . ' ON '
. tbl('video.videoid') . ' = ' . tbl('video_meta.videoid')
2012-09-12 10:00:57 +00:00
, tbl('video.*' . $ufieldq . ',slugs.*') . ',' . $meta_query, $cond . " " . tbl("video.userid") . " = " . tbl("users.userid") . " GROUP BY " . tbl('video.videoid'), $limit, $order);
2012-09-04 10:38:50 +00:00
2012-09-05 10:17:07 +00:00
$db->db_query;
2012-09-04 10:38:50 +00:00
}
if ($params['show_related']) {
$cond = "";
if ($superCond)
$cond = $superCond . " AND ";
$cond .= "MATCH(" . tbl("video.title,video.tags") . ")
AGAINST ('" . cbsearch::set_the_key($params['title']) . "' IN BOOLEAN MODE) ";
if ($params['exclude']) {
if ($cond != '')
$cond .= ' AND ';
$cond .= " " . tbl('video.videoid') . " <> '" . $params['exclude'] . "' ";
}
$result = $db->select(tbl('video')
. ' LEFT JOIN ' . tbl('users') . ' ON '
. tbl('video.userid') . ' = ' . tbl('users.userid')
. ' LEFT JOIN ' . tbl('slugs') . ' ON '
. tbl('video.slug_id') . ' = ' . tbl('slugs.slug_id')
, tbl('video.*' . $ufieldq . ',slugs.*'), $cond . " " . tbl("video.userid") . " = " . tbl("users.userid"), $limit, $order);
if ($db->num_rows == 0) {
$cond = "";
if ($superCond)
$cond = $superCond . " AND ";
//Try Finding videos via tags
$cond .= "MATCH(" . tbl("video.title,video.tags") . ")
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')
. ' LEFT JOIN ' . tbl('users') . ' ON '
. tbl('video.userid') . ' = ' . tbl('users.userid')
. ' LEFT JOIN ' . tbl('slugs') . ' ON '
. tbl('video.slug_id') . ' = ' . tbl('slugs.slug_id')
, tbl('video.*' . $ufieldq . ',slugs.*'), $cond . " " . tbl("video.userid") . " = " . tbl("users.userid"), $limit, $order);
}
assign($params['assign'], $result);
}
if ($params['pr'])
pr($result, true);
if ($params['count_only'])
return $result = $db->count(tbl('video'), '*', $cond);
if ($params['assign'])
assign($params['assign'], $result);
else
return $result;
}
/**
* Function used to count total video comments
*/
function count_video_comments($id) {
global $db;
$total_comments = $db->count(tbl('comments'), "comment_id", "type='v' AND type_id='$id'");
return $total_comments;
}
/**
* Function used to update video comments count
*/
function update_comments_count($id) {
global $db;
$total_comments = $this->count_video_comments($id);
$db->update(tbl("video"), array("comments_count", "last_commented"), array($total_comments, now()), " videoid='$id'");
}
/**
* Function used to add video comment
*/
function add_comment($comment, $obj_id, $reply_to = NULL, $force_name_email = false) {
global $myquery, $db;
$video = $this->get_video_details($obj_id);
if (!$video)
e(lang("class_vdo_del_err"));
else {
//Getting Owner Id
$owner_id = $this->get_video_owner($obj_id, true);
$add_comment = $myquery->add_comment($comment, $obj_id, $reply_to, 'v', $owner_id, videoLink($video), $force_name_email);
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;
}
}
/**
* 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;
}
/**
2012-09-08 10:15:54 +00:00
* Generates embed code properties
*
* @param ARRAY vdetails
* @return ARRAY emebd_code_detailss
2012-09-04 10:38:50 +00:00
*/
2012-09-08 10:15:54 +00:00
function embed_code_props($vdetails, $type = 'embed_object') {
2012-09-04 10:38:50 +00:00
//Checking for video details
if (!is_array($vdetails)) {
$vdetails = $this->get_video($vdetails);
}
$embed_code = false;
$funcs = $this->embed_func_list;
if (is_array($funcs)) {
foreach ($funcs as $func) {
if (@function_exists($func))
$embed_code = $func($vdetails);
if ($embed_code)
break;
}
}
if ($type == 'iframe') {
2012-09-08 10:15:54 +00:00
//Setting up an array in case we dont want an echo
//we can give array-output to re-use code even with jS
2012-09-12 10:00:57 +00:00
2012-09-08 10:15:54 +00:00
$code_props = array();
$code_props['type'] = 'iframe';
2012-09-12 10:00:57 +00:00
$code_props['configs']['width'] = config('embed_player_width');
$code_props['configs']['height'] = config('embed_player_height');
$code_props['src']['url'] = BASEURL . '/player/embed_player.php';
2012-09-08 10:15:54 +00:00
$code_props['src']['params'] = array(
2012-09-12 10:00:57 +00:00
'vid' => $vdetails['videoid'],
'height' => config('embed_player_height'),
'width' => config('embed_player_width'),
'autoplay' => config('autoplay_embed')
2012-09-08 10:15:54 +00:00
);
$code_props['params'] = array(
2012-09-12 10:00:57 +00:00
'height' => config('embed_player_height'),
'width' => config('embed_player_width'),
2012-09-08 10:15:54 +00:00
'frameborder' => 0,
'allowfullscreen' => true
);
2012-09-12 10:00:57 +00:00
2012-09-10 12:48:37 +00:00
return $code_props;
2012-09-04 10:38:50 +00:00
}
2012-09-08 10:15:54 +00:00
//Default ClipBucket Embed Code
if (function_exists('default_embed_code')) {
2012-09-12 10:00:57 +00:00
$code_props = default_embed_code($vdetails);
2012-09-08 10:15:54 +00:00
} else {
//return new Embed Code
$embed_code = $vdetails['embed_code'];
2012-09-12 10:00:57 +00:00
if (!$embed_code || $embed_code == 'none') {
2012-09-08 10:15:54 +00:00
$code_props = array();
$code_props['type'] = 'embed_object';
$code_props['src']['url'] = PLAYER_URL . '/embed_player.php';
$code_props['src']['params'] = array(
2012-09-12 10:00:57 +00:00
'vid' => $vdetails['videoid'],
2012-09-08 10:15:54 +00:00
);
$code_props['params'] = array(
2012-09-12 10:00:57 +00:00
'width' => EMBED_VDO_WIDTH,
'height' => EMBED_VDO_HEIGHT,
2012-09-08 10:15:54 +00:00
'allowfullscreen' => true,
'allowscriptaccess' => 'always'
);
2012-09-04 10:38:50 +00:00
} else {
2012-09-08 10:15:54 +00:00
$code_props['type'] = 'embeded';
2012-09-12 10:00:57 +00:00
$code_props['src'] = embeded_code($vdetails);
2012-09-04 10:38:50 +00:00
}
}
2012-09-08 10:15:54 +00:00
return $code_props;
}
2012-09-12 10:00:57 +00:00
2012-09-08 10:15:54 +00:00
/**
* returns the embed code for the video...
*
* @param ARRAY $code_props
* @return STRING embed_code
*/
2012-09-12 10:00:57 +00:00
function embed_code($code_props) {
2012-09-08 10:15:54 +00:00
$type = $code_props['type'];
2012-09-12 10:00:57 +00:00
switch ($type) {
case "iframe": {
$code = '<iframe ';
$code .= 'src="'; //opening src attr
$code .= $code_props['src']['url'] . '?embed=true';
if ($code_props['src']['params']) {
foreach ($code_props['src']['params'] as $attr => $val)
$code .= '&' . $attr . '=' . urlencode($val);
}
$code .= '" '; //ending src attr
if ($code_props['params']) {
foreach ($code_props['params'] as $attr => $val)
$code .= $attr . '="' . $val . '" ';
}
$code .= '>';
$code .= '</frame>';
2012-09-08 10:15:54 +00:00
}
2012-09-12 10:00:57 +00:00
break;
case "embed_object": {
$code = '<object ';
$code .= 'height="' . $code_props['params']['height'] . "' "; //setting object height
$code .= 'width="' . $code_props['params']['width'] . "' >"; //setting object width
//adding src
$code .= '<param name="movie" value="';
$code .= $code_props['src']['url'] . '?embed=true';
if ($code_props['src']['params']) {
foreach ($code_props['src']['params'] as $attr => $val)
$code .= '&' . $attr . '=' . urlencode($val);
}
$code .= '"></param>'; //ending src attr
if ($code_props['params']) {
foreach ($code_props['params'] as $attr => $val)
$code .= '<param name="' . $attr . '" value="' . $val . '"></param>';
}
$code .= '<embed ';
$code .= 'src="'; //opening src attr
$code .= $code_props['src']['url'] . '?embed=true';
if ($code_props['src']['params']) {
foreach ($code_props['src']['params'] as $attr => $val)
$code .= '&' . $attr . '=' . urlencode($val);
}
$code .= '" '; //ending src attr
if ($code_props['params']) {
foreach ($code_props['params'] as $attr => $val)
$code .= $attr . '="' . $val . '" ';
}
$code .= '>';
$code .= '</embed>';
$code .= '</object>';
2012-09-08 10:15:54 +00:00
}
2012-09-12 10:00:57 +00:00
break;
case "embeded": {
return $code_props['src'];
2012-09-08 10:15:54 +00:00
}
2012-09-12 10:00:57 +00:00
break;
2012-09-08 10:15:54 +00:00
}
2012-09-04 10:38:50 +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();
$this->action->init();
$this->action->type = 'v';
$this->action->name = 'video';
$this->action->obj_class = 'cbvideo';
$this->action->check_func = 'video_exists';
$this->action->type_tbl = $this->dbtbl['video'];
$this->action->type_id_field = 'videoid';
}
/**
* 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'],
'{video_description}' => $details['description'],
'{video_tags}' => $details['tags'],
'{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;
}
/**
* Function used to use to initialize search object for video section
* op=>operator (AND OR)
*/
function init_search() {
$this->search = new cbsearch;
$this->search->db_tbl = "video";
$this->search->columns = array(
array('field' => 'title', 'type' => 'LIKE', 'var' => '%{KEY}%'),
array('field' => 'tags', 'type' => 'LIKE', 'var' => '%{KEY}%', 'op' => 'OR'),
array('field' => 'broadcast', 'type' => '!=', 'var' => 'unlisted', 'op' => 'AND', 'value' => 'static'),
array('field' => 'status', 'type' => '=', 'var' => 'Successful', 'op' => 'AND', 'value' => 'static')
);
$this->search->use_match_method = true;
$this->search->match_fields = array("title", "tags");
$this->search->cat_tbl = $this->cat_tbl;
$this->search->display_template = LAYOUT . '/blocks/video.html';
$this->search->template_var = 'video';
$this->search->has_user_id = true;
2012-07-10 20:25:48 +00:00
/**
2012-09-04 10:38:50 +00:00
* Setting up the sorting thing
2012-07-10 20:25:48 +00:00
*/
2012-09-04 10:38:50 +00:00
$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'];
2012-07-10 20:25:48 +00:00
2012-09-04 10:38:50 +00:00
$this->search->search_type['videos'] = array('title' => lang('videos'));
$this->search->results_per_page = config('videos_items_search_page');
2012-07-10 20:25:48 +00:00
2012-09-04 10:38:50 +00:00
$fields = array(
'query' => array(
'title' => lang('keywords'),
'type' => 'textfield',
'name' => 'query',
'id' => 'query',
'value' => cleanForm($default['query'])
),
'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
)
);
$this->search->search_type['videos']['fields'] = $fields;
}
/*
* 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;
//if(file_exists($file))
//{
$db->update(tbl("video"), array("default_thumb"), array($num), " videoid='$vid'");
e(lang('vid_thumb_changed'), 'm');
//}else{
// e(lang('vid_thumb_change_err'));
//}
}
/**
* Function used to get video owner
*/
function get_video_owner($vid, $idonly = false) {
global $db;
if ($idonly) {
$results = $db->select(tbl("video"), "userid", " videoid='$vid' ", 1);
if ($db->num_rows > 0)
return $results[0]['userid'];
else
return false;
}else {
$results = $db->select(tbl("video"), "*", " videoid='$vid' ", 1);
if ($db->num_rows > 0)
return $results[0];
else
return false;
}
}
/**
* Function used to check weather current user is video owner or not
*/
function is_video_owner($vid, $uid) {
global $db;
$result = $db->count(tbl($this->dbtbl['video']), 'videoid', "videoid='$vid' AND userid='$uid' ");
if ($result > 0)
2012-07-10 20:25:48 +00:00
return true;
2012-09-04 10:38:50 +00:00
else
return false;
}
2012-07-10 20:25:48 +00:00
2012-09-04 10:38:50 +00:00
/**
* Function used to display video manger link
*
* @todo : IMprove this function and add filters
*/
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 '<li><a href="' . $link['link'] . '">' . $link['title'] . '</a></li>';
}
2012-07-10 20:25:48 +00:00
}
2012-09-04 10:38:50 +00:00
}
/**
* Function used to get video rating details
*/
function get_video_rating($id) {
global $db;
if (is_numeric($id)) {
$results = $db->select(tbl("video"), "userid,allow_rating,rating,rated_by,voter_ids", " videoid='$id'");
}else
$results = $db->select(tbl("video"), "userid,allow_rating,rating,rated_by,voter_ids", " videokey='$id'");
if ($db->num_rows > 0)
return $results[0];
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 ($total <= 10)
$total = 10;
$perc = $rating * 100 / $total;
$disperc = 100 - $perc;
if ($ratings <= 0 && $disperc == 100)
$disperc = 0;
$perc = $perc . '%';
$disperc = $disperc . '%';
$likes = round($ratings * $perc / 100); // get lowest integer
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('disperc', $disperc);
assign('id', $id);
assign('type', $type);
assign('id', $id);
assign('rating_msg', $rating_msg);
assign("likes", $likes);
assign('rating', $rating);
assign('ratings', $ratings);
assign("dislikes", ($ratings - $likes));
assign('disable', $params['disable']);
Template('blocks/rating.html');
}
/**
* Function used to rate video
*/
function rate_video($id, $rating) {
global $db,$myquery,$userquery;
2012-09-04 10:38:50 +00:00
if (!is_numeric($rating) || $rating <= 9)
$rating = 0;
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'];
if (phpversion < '5.2.0')
global $json; $js = $json;
$Oldvoters = explode('|', $voter_id);
if (is_array($Oldvoters) && count($Oldvoters) > 2) {
foreach ($Oldvoters as $voter) {
if ($voter) {
$voters[$voter] = array(
"userid" => $voter,
"time" => now(),
"method" => 'old',
);
}
}
} else {
if (!empty($js))
$voters = $js->json_decode($voter_id, TRUE);
else
$voters = json_decode($voter_id, TRUE);
}
if (!empty($voters))
$already_voted = array_key_exists(userid(), $voters);
if (!userid())
e(lang("please_login_to_rate"));
elseif (userid() == $rating_details['userid'] && !config('own_video_rating'))
e(lang("you_cant_rate_own_video"));
elseif (!empty($already_voted) && !1)
2012-09-04 10:38:50 +00:00
e(lang("you_hv_already_rated_vdo"));
elseif (!config('video_rating') || $rating_details['allow_rating'] != 'yes')
e(lang("vid_rate_disabled"));
else {
$voters[userid()] = array(
"userid" => userid(),
"username" => username(),
"time" => now(),
"rating" => $rating
);
$total_voters = count($voters);
if (!empty($js))
$voters = $js->json_encode($voters);
else
$voters = json_encode($voters);
$t = $rating_details['rated_by'] * $rating_details['rating'];
//$new_by = $rating_details['rated_by'] + 1;
$new_by = $total_voters;
$newrate = ($t + $rating) / $new_by;
if ($newrate > 10)
$newrate = 10;
$newrate = round($newrate+0.49,0);
2012-09-04 10:38:50 +00:00
$db->update(tbl($this->dbtbl['video']), array("rating", "rated_by", "voter_ids"), array($newrate, $new_by, "|no_mc|$voters"), " videoid='$id'");
2012-09-04 10:38:50 +00:00
$userDetails = array(
"object_id" => $id,
"type" => "video",
"time" => now(),
"rating" => $rating,
"userid" => userid(),
"username" => username()
);
/* Updating user details */
update_user_voted($userDetails);
$like_array = array(
'userid' => userid(),
'type' => 'v',
'object_id' => $id,
);
if($rating>1)
{
$myquery->add_like($like_array);
}else
{
$myquery->add_dislike($like_array);
}
if(isSectionEnabled('feeds'))
{
//ADding feed
global $cbfeeds;
if($rating>1)
{
$object = $this->get_content($id);
$user = $userquery->udetails;
$feed_array = array(
'userid' => userid(),
'user' => $user,
'object' => $object,
'object_id' => $id,
'object_type' => 'video',
'is_activity' => 'yes',
'action' => 'like_video',
);
$cbfeeds->add_feed($feed_array);
}else
{
$feed_array = array(
'userid' => userid(),
'object_id' => $id,
'object_type' => 'video',
'is_activity' => 'yes',
'action' => 'like_video',
);
$cbfeeds->delete_feed($feed_array);
}
}
2012-09-04 10:38:50 +00:00
e(lang("thnx_for_voting"), "m");
}
$result = array('rating' => $newrate, 'ratings' => $new_by, 'total' => 10, 'id' => $id, 'type' => 'video', 'disable' => 'disabled');
return $result;
/*
Following code is unused
$niddle = "|";
$niddle .= userid();
$niddle .= "|";
$flag = strstr($voter_id, $niddle);
//checking if raings are allowed or not
$vid_rating = config('video_rating');
if(!userid())
e(lang("please_login_to_rate"));
elseif(userid()==$rating_details['userid'] && !config('own_video_rating'))
e(lang("you_cant_rate_own_video"));
elseif(!empty($flag))
e(lang("you_hv_already_rated_vdo"));
elseif(!config('video_rating') || $rating_details['allow_rating'] !='yes' )
e(lang("vid_rate_disabled"));
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;
$db->update(tbl($this->dbtbl['video']),array("rating","rated_by","voter_ids"),array($newrate,$new_by,$voter_id)," videoid='$id'");
e(lang("thnx_for_voting"),"m");
}
$result = array('rating'=>$newrate,'ratings'=>$new_by,'total'=>10,'id'=>$id,'type'=>'video','disable'=>'disabled');
return $result;
2012-07-10 20:25:48 +00:00
*/
2012-09-04 10:38:50 +00:00
}
/**
* Function used to get playlist items
*/
2012-09-12 10:00:57 +00:00
function get_playlist_items($pid,$order=NULL,$limit=NULL) {
2012-09-04 10:38:50 +00:00
global $db;
$ptbl = tbl($this->action->playlist_items_tbl);
$vtbl = tbl($this->dbtbl['video']);
2012-09-12 10:00:57 +00:00
$fields = array(
'title',
'comments_count',
'views',
'userid',
'date_added',
'file_name',
'category',
'description',
'videokey',
'tags',
'videoid',
'duration',
'file_directory'
);
$query_fields = '';
foreach($fields as $field)
{
if($query_fields)
$query_fields .= ',';
$query_fields .= $vtbl.'.'.$field;
}
$query_fields = $ptbl . ".*,$query_fields";
$meta_query = $this->create_meta_query();
2012-09-04 10:38:50 +00:00
$result = $db->select(tbl('playlist_items')
. ' LEFT JOIN ' . tbl('video') . ' ON '
. $ptbl . '.object_id' . ' = ' . tbl('video.videoid')
2012-09-12 10:00:57 +00:00
, $query_fields, $ptbl . '.object_id=' . $vtbl . '.videoid AND ' . $ptbl
. ".playlist_id='$pid'", $limit, $ptbl . '.item_order ASC');
2012-09-04 10:38:50 +00:00
if ($db->num_rows > 0)
return $result;
else
return false;
}
/**
* Function used to add video in quicklist
*/
function add_to_quicklist($id) {
global $json, $sess, $userquery;
if ($this->exists($id)) {
if (phpversion() < '5.2.0') {
$list = $json->decode($sess->get_cookie(QUICK_LIST_SESS), true);
} else {
$list = json_decode($sess->get_cookie(QUICK_LIST_SESS), true);
}
$list[] = $id;
$new_list = array_unique($list);
/* //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'],
);
} */
if (phpversion() < '5.2.0') {
$sess->set_cookie(QUICK_LIST_SESS, $json->encode($new_list));
} else {
$sess->set_cookie(QUICK_LIST_SESS, json_encode($new_list));
}
return true;
}else
return false;
}
/**
* Removing video from quicklist
*/
function remove_from_quicklist($id) {
global $json, $sess;
if (phpversion() < '5.2.0') {
$list = $json->decode($sess->get_cookie(QUICK_LIST_SESS), true);
} else {
$list = json_decode($sess->get_cookie(QUICK_LIST_SESS), true);
}
$key = array_search($id, $list);
unset($list[$key]);
if (phpversion() < '5.2.0') {
$sess->set_cookie(QUICK_LIST_SESS, $json->encode($list));
} else {
$sess->set_cookie(QUICK_LIST_SESS, json_encode($list));
}
return true;
}
/**
* function used to count num of quicklist
*/
function total_quicklist() {
global $json, $sess;
$total = $sess->get_cookie(QUICK_LIST_SESS);
if (phpversion() < '5.2.0') {
$total = $json->decode($total, true);
} else {
$total = json_decode($total, true);
}
return count($total);
}
/**
* Function used to get quicklist
*/
function get_quicklist() {
global $json, $sess;
if (phpversion() < '5.2.0') {
return $json->decode($sess->get_cookie(QUICK_LIST_SESS), true);
} else {
return json_decode($sess->get_cookie(QUICK_LIST_SESS), true);
}
}
/**
* Function used to remove all items of quicklist
*/
function clear_quicklist() {
global $sess;
$sess->set_cookie(QUICK_LIST_SESS, '');
}
/**
* 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;
}
/**
* Function used get comments of videos
*/
function get_comments($params = NULL) {
global $db;
$comtbl = tbl("comments");
$limit = $params['limit'];
$order = $params['order'];
$type = $params['type'];
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";
}
break;
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";
}
}
if ($params['cond'])
$cond .= " " . $params['cond'];
if (!$params['count_only']) {
$result = $db->select(tbl("comments," . $sectblName . ""), "$comtbl.*,$secfields", $cond, $limit, $order);
// echo $db->db_query;
}
if ($params['count_only'])
return $result = $db->count(tbl("comments,video"), "*", $cond);
else
return $result;
}
/**
* Function used get single comment
*/
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
*/
// 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);
// }
// }
/**
* Add video profile that will be used when converting a video
*
* @param ARRAY a list of options for a profile
* @return INT added profile ID
* @link http://docs.clip-bucket.com/user-manual/developers-guide/objects/videos/add_video_profile
*/
function add_video_profile($array) {
global $db;
$fields = array(
'name',
'format',
'ext',
'suffix',
'height',
'width',
'verify_dimension',
'video_codec',
'audio_codec',
'audio_bitrate',
'video_bitrate',
'audio_rate',
'video_rate',
'resize',
'preset',
'2pass',
'apply_watermark',
'ffmpeg_cmd',
);
if ($array['height'] < 100)
e(lang("Video height is too small, it must be atleast 100"));
if ($array['width'] < 100)
e(lang('Video width is too small, please make sure its atleast 100'));
$valid_exts = array('flv', 'mp4', 'm4v', 'f4v', 'webm', '3gp');
$valid_exts = apply_filters($valid_exts, 'valid_exts');
$valid_formats = array('flv', 'mp4', 'webm', 'mobile', '3gp');
$valid_formats = apply_filters($valid_formats, 'valid_formats');
$valid_presets = array('', 'low', 'normal', 'hq', 'max');
$valid_presets = apply_filters($valid_presets, 'valid_presets');
$valid_resizes = array('none', 'max', 'fit', 'wxh');
$valid_resizes = apply_filters($valid_resizes, 'valid_resizes');
if (!in_array($array['ext'], $valid_exts))
e(lang('Invalid extension, please set valid streamable extension'), 'e', 'ext');
if (!in_array($array['format'], $valid_formats))
e(lang('Invalid video format, please select a valid video format'), 'e', 'format');
if (!$array['name'])
e(lang("Please enter a suitable name for this profile"), 'e', 'name');
if (!in_array($array['preset'], $valid_presets)) {
if ($array['preset'])
e(sprintf(lang("%s is not a valid preset"), $array['preset']), 'e', 'preset');
else
e(lang("Please choose a preset for your profile"), 'e', 'preset');
}
if (!in_array($array['resize'], $valid_resizes))
$array['resize'] = 'none';
/* Finally adding our preset */
if (!error()) {
$values = array();
foreach ($fields as $field) {
$values[] = $array[$field];
}
$fields = apply_filters($fields, 'video_profile_fields');
$values = apply_filters($values, 'video_profile_values');
//Adding order
$order = $this->get_latest_profile_order();
$order = $order + 1;
$fields[] = 'profile_order';
$values[] = $order;
$db->insert(tbl('video_profiles'), $fields, $values);
if ($db->insert_id())
return $db->insert_id();
else
return false;
}
return false;
}
/**
* Get list of video profiles
*
* @param ARRAY for restrictions
*/
function get_video_profiles($array = null) {
global $db;
$cond = "";
$cond = apply_filters($cond, 'get_video_profiles_cond');
if ($array['order'])
$order = $array['order'];
else
$order = ' profile_order ASC ';
if ($array['limit'])
$limit = $array['limit'];
else
$limit = NULL;
if ($array['count_only']) {
return $results = $db->count(tbl('video_profiles'), 'profile_id', $cond);
}
$results = $db->select(tbl('video_profiles'), '*', $cond, $limit, $order);
if ($db->num_rows > 0)
return $results;
else
return false;
}
/**
* Get video profile
*
* @param INT profile_id
* @return ARRAY profile details
*/
function get_video_profile($pid) {
global $db;
$profile = $db->select(tbl('video_profiles'), '*', "profile_id='$pid'");
if ($db->num_rows > 0)
return $profile[0];
else
return false;
}
/**
* get latest profile order..
*
* @return INT
*/
function get_latest_profile_order() {
global $db;
$results = $db->select(tbl('video_profiles'), 'profile_order', NULL, 1, ' profile_order DESC ');
if ($db->num_rows > 0) {
return $results[0]['profile_order'];
} else {
return 0;
}
}
/**
* delete video profile..
*
* @param INT
* @return BOOLEAN
*/
function delete_video_profile($in) {
global $db;
if ($in) {
$in = mysql_clean($in);
$db->Execute("DELETE FROM " . tbl('video_profiles')
. " WHERE profile_id='$in' ");
return true;
}
}
/**
* Update video profile...
*
* @param ARRAY
* @return BOOLEAN
*/
function update_video_profile($array) {
global $db;
$fields = array(
'name',
'format',
'ext',
'suffix',
'height',
'width',
'verify_dimension',
'video_codec',
'audio_codec',
'audio_bitrate',
'video_bitrate',
'audio_rate',
'video_rate',
'resize',
'preset',
'2pass',
'apply_watermark',
'ffmpeg_cmd',
);
if ($array['height'] < 100)
e(lang("Video height is too small, it must be atleast 100"));
if ($array['width'] < 100)
e(lang('Video width is too small, please make sure its atleast 100'));
$valid_exts = array('flv', 'mp4', 'm4v', 'f4v', 'webm', '3gp');
$valid_exts = apply_filters($valid_exts, 'valid_exts');
$valid_formats = array('flv', 'mp4', 'webm', 'mobile', '3gp');
$valid_formats = apply_filters($valid_formats, 'valid_formats');
$valid_presets = array('', 'low', 'normal', 'hq', 'max');
$valid_presets = apply_filters($valid_presets, 'valid_presets');
$valid_resizes = array('none', 'max', 'fit', 'wxh');
$valid_resizes = apply_filters($valid_resizes, 'valid_resizes');
if (!in_array($array['ext'], $valid_exts))
e(lang('Invalid extension, please set valid streamable extension'), 'e', 'ext');
if (!in_array($array['format'], $valid_formats))
e(lang('Invalid video format, please select a valid video format'), 'e', 'format');
if (!$array['name'])
e(lang("Please enter a suitable name for this profile"), 'e', 'name');
if (!in_array($array['preset'], $valid_presets)) {
if ($array['preset'])
e(sprintf(lang("%s is not a valid preset"), $array['preset']), 'e', 'preset');
else
e(lang("Please choose a preset for your profile"), 'e', 'preset');
}
if (!in_array($array['resize'], $valid_resizes))
$array['resize'] = 'none';
/* Finally adding our preset */
if (!error()) {
$values = array();
foreach ($fields as $field) {
$values[] = $array[$field];
}
$fields = apply_filters($fields, 'video_profile_fields');
$values = apply_filters($values, 'video_profile_values');
//Adding order
$order = $this->get_latest_profile_order();
$order = $order + 1;
$profile_id = $array['profile_id'];
$fields[] = 'profile_order';
$values[] = $order;
$db->update(tbl('video_profiles'), $fields, $values, " profile_id='$profile_id' ");
return $profile_id;
}
return false;
}
/**
* Update playist order
*
* @param INT pid
* @param ARRAY playlist_items array
* @return BOOLEAN
*/
function update_video_profile_order($items, $uid = NULL) {
global $db;
$itemsNew = array();
$count = 0;
//Setting up the query...
$query = "UPDATE " . tbl('video_profiles');
$query .= " SET profile_order = CASE profile_id ";
foreach ($items as $item => $order) {
$ids[] = $item;
$query .= sprintf("WHEN '%s' THEN '%s' ", $item, $order);
$query .= " ";
}
$query .= " END ";
$query .= " WHERE profile_id in(" . implode($ids, ',') . ")";
$db->Execute($query);
if (mysql_error())
die($db->db_query . '<br>' . mysql_error());
return true;
}
/**
* Activate deactivate video profile
*
* @param INT pid
* @param STRING mode
*/
function profile_action($pid, $mode) {
global $db;
switch ($mode) {
case "activate": {
$db->update(tbl('video_profiles'), array('active'), array('yes'), " profile_id='$pid' ");
2012-07-10 20:25:48 +00:00
return true;
}
break;
2012-09-04 10:38:50 +00:00
case "deactivate": {
$db->update(tbl('video_profiles'), array('active'), array('no'), " profile_id='$pid' ");
2012-07-10 20:25:48 +00:00
return true;
}
break;
}
2012-09-04 10:38:50 +00:00
}
/**
* Index video thumbs...
* will search for video thumbs in its folder and sort them in an array
* and can be retrieved later for use in easy format
*
* @param INT videoid | ARRAY videoarray
*/
function index_video_thumbs($arr, $update_db = true) {
$video = $arr;
if (!is_array($video))
2012-09-12 10:00:57 +00:00
$video = $this->get_video($video, true);
2012-09-04 10:38:50 +00:00
if (!$video)
return false;
/** @todo : this function must be callable and work when multi-server
* is installed
*/
$folder = '';
if ($video['file_directory'])
$folder = '/' . $video['file_directory'];
$dir = THUMBS_DIR . $folder . '/' . $video['file_name'];
$thumbs = glob($dir . '*.jpg');
$new_thumbs = array();
foreach ($thumbs as $thumb) {
$name = getName($thumb);
$name_arr = explode('-', $name);
2012-09-05 10:17:07 +00:00
$new_thumbs[$name_arr[1]][] = getname($thumb) . '.jpg';
2012-09-04 10:38:50 +00:00
}
if ($update_db)
2012-09-12 10:00:57 +00:00
$this->update_meta($video['videoid'], 'thumbs', '|no_mc|' . json_encode($new_thumbs));
2012-09-04 10:38:50 +00:00
return $new_thumbs;
}
/**
* Function used to update video metas for extended data
*
* read more about metas in our docs
*
* @todo : write docs for metas
* @author : Arslan
* @param INT videoid
* @param STRING meta_name
* @param STRING meta_value
*/
function update_meta($vid, $name, $val) {
global $db;
if (!$this->meta_exists($vid, $name))
$this->add_meta($vid, $name, $val);
else {
$db->update(tbl('video_meta'), array('meta_value'), array($val), "meta_name='$name' AND videoid='$vid' ");
}
}
2012-07-10 20:25:48 +00:00
2012-09-04 10:38:50 +00:00
/**
* Function used to check video meta exists or not...
*
* @author Arslan
* @param INT videoid
* @param STRING meta_name
* @return BOOLEAN
*/
function meta_exists($vid, $name) {
global $db;
$count = $db->count(tbl('video_meta'), 'meta_id', " meta_name='$name' AND videoid='$vbid' ");
if ($count > 0)
return true;
else
return false;
}
2012-07-10 20:25:48 +00:00
2012-09-04 10:38:50 +00:00
/**
* Add meta for videos
*
* @author Arslan
* @param INT videoid
* @param STRING name
* @param STRING value
* @param STRING extras, some extra valuews for metas..
*/
2012-09-12 10:00:57 +00:00
function add_meta($vid, $name, $val, $extras = NULL) {
2012-09-04 10:38:50 +00:00
global $db;
if (!$this->meta_exists($vid, $name)) {
2012-09-12 10:00:57 +00:00
$db->insert(tbl('video_meta'), array('meta_name', 'meta_value', 'videoid', 'extras'), array($name, $val, $vid, $extras));
2012-09-04 10:38:50 +00:00
}
}
2012-09-12 10:00:57 +00:00
2012-09-04 10:38:50 +00:00
/**
* Function remove video metas
*
* @param INT videoid
* @param STRING default: ALL, othere keys sperated by comma
*/
2012-09-12 10:00:57 +00:00
function remove_metas($video, $meta_names = NULL) {
2012-09-04 10:38:50 +00:00
$meta_cond = "";
2012-09-12 10:00:57 +00:00
if ($meta_names && strtolower($meta_namess) != 'all') {
2012-09-04 10:38:50 +00:00
$meta_cond = ' AND ( ';
2012-09-12 10:00:57 +00:00
$metas = explode(',', $meta_names);
if ($metas) {
2012-09-04 10:38:50 +00:00
$count = 0;
2012-09-12 10:00:57 +00:00
foreach ($metas as $meta) {
2012-09-04 10:38:50 +00:00
$count++;
2012-09-12 10:00:57 +00:00
if ($count > 1)
2012-09-04 10:38:50 +00:00
$meta_cond .= " OR ";
$meta_cond .= " meta_name='$meta' ";
}
}
2012-09-12 10:00:57 +00:00
2012-09-04 10:38:50 +00:00
$meta_cond .= ' ) ';
}
2012-09-12 10:00:57 +00:00
$cond = " videoid='$video' " . $meta_cond;
$db->execute("DELETE FROM " . tbl('video_meta') . " WHERE " . $cond);
2012-09-04 10:38:50 +00:00
return true;
}
2012-09-12 10:00:57 +00:00
2012-09-04 16:28:33 +00:00
/**
* Register metas and can be used when retrieved/updating data
*
* metas are extra fields of any video for extended data. This function
* will register metas and tells ClipBucket to use them when performing
* an action on a video
*
* @param STRING meta_name
*/
2012-09-12 10:00:57 +00:00
function register_meta($name) {
2012-09-04 16:28:33 +00:00
$this->metas[] = $name;
}
2012-09-12 10:00:57 +00:00
2012-09-04 16:28:33 +00:00
/**
* create meta concat query
*
*/
2012-09-12 10:00:57 +00:00
function create_meta_query() {
2012-09-04 16:28:33 +00:00
$metas = $this->metas;
2012-09-12 10:00:57 +00:00
2012-09-04 16:28:33 +00:00
$query = '';
2012-09-12 10:00:57 +00:00
if ($metas) {
foreach ($metas as $meta) {
if ($query) {
2012-09-04 16:28:33 +00:00
$query .=',';
}
2012-09-12 10:00:57 +00:00
2012-09-04 16:28:33 +00:00
$query .= " CONCAT (if(meta_name='$meta',meta_value,meta_value)) AS '$meta' ";
}
}
2012-09-12 10:00:57 +00:00
2012-09-04 16:28:33 +00:00
return $query;
}
2012-09-12 10:00:57 +00:00
2012-09-05 11:28:09 +00:00
/**
* Function used to get list of video files
*
* @param STRING $file_name
*/
2012-09-12 10:00:57 +00:00
function get_video_files($video) {
2012-09-05 11:28:09 +00:00
global $db;
2012-09-12 10:00:57 +00:00
$file = $video['file_name'];
2012-09-12 10:00:57 +00:00
//Checking if the system is old..
2012-09-12 10:00:57 +00:00
$folder = "";
2012-09-12 10:00:57 +00:00
if ($video['file_directory']) {
$folder = '/' . $video['file_directory'];
}
2012-09-12 10:00:57 +00:00
if (file_exists(VIDEOS_DIR . $folder . '/' . $file . '.flv') ||
file_exists(VIDEOS_DIR . $folder . '/' . $file . '.mp4')) {
$files = array();
2012-09-12 10:00:57 +00:00
if (file_exists(VIDEOS_DIR . $folder . '/' . $file . '.flv'))
$files['flv'] = VIDEOS_URL . $folder . '/' . $file . '.flv';
if (file_exists(VIDEOS_DIR . $folder . '/' . $file . '.mp4'))
$files['mp4'] = VIDEOS_URL . $folder . '/' . $file . '.mp4';
//For mobile now..
2012-09-12 10:00:57 +00:00
if (file_exists(VIDEOS_DIR . $folder . '/' . $file . '-m.mp4'))
$files['mobile'] = VIDEOS_URL . $folder . '/' . $file . '-m.mp4';
return $files;
}
2012-09-12 10:00:57 +00:00
$query = "SELECT * FROM " .
$query .= tbl('video_files');
$query .= " LEFT JOIN " . tbl('video_profiles');
$query .= " ON " . tbl('video_files.profile_id') . " = " . tbl('video_profiles.profile_id');
$query .= " WHERE " . tbl('video_files.file_name') . "='$file'";
2012-09-05 11:28:09 +00:00
$data = $db->execute($query);
$db->num_rows = $data->_numOfRows;
$db->total_queries++;
$db->total_queries_sql[] = $query;
//Now Get Rows and return that data
2012-09-12 10:00:57 +00:00
if ($db->num_rows > 0) {
$files = $data->getrows();
return $files;
2012-09-05 11:28:09 +00:00
}
else
return false;
2012-09-12 10:00:57 +00:00
}
/**
* get playlist url...
*
* @param INT playlist_id
* @return STRING playlist url
*/
function playPlaylist($id) {
$items = $this->get_playlist_items($id, NULL, 1);
if ($items) {
$item = $items[0];
return videoLink($item);
}
2012-09-05 11:28:09 +00:00
}
/**
* get video content for feed
*
* @param INT $id
* @param ARRAY $content
*/
function get_content($id,$content=NULL)
{
if($content)
{
if($content['title'] && $content['videoid'])
$the_content = $content;
}
if(!$the_content)
$the_content = $this->get_video($id);
if(!$the_content)
return false;
$video_feed_fields = array(
'title','description','duration','videoid','date_added',
'file_server_path','files_thumbs_path','file_directory','file_thumbs_count',
'tags','category','privacy','userid','username','email','fullname'
);
$video_feed_fields = apply_filters($video_feed_fields, 'video_content_fields_unsorted');
$video_fields = array();
foreach($video_feed_fields as $vid_field)
$video_fields[$vid_field] = $the_content[$vid_field];
$video_fields['link'] = VideoLink($the_content);
$video_fields['thumb'] = get_thumb($the_content);
$video_fields['sub_title'] = setTime($the_content['duration']);
return $video_fields;
}
2012-09-04 10:38:50 +00:00
}
2012-07-10 20:25:48 +00:00
2009-09-01 20:57:38 +00:00
?>