예제 #1
0
 /**
  * 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)) {
         $params['admin_access'] = false;
         $superCond = $cond .= " " . "video.status" . "='Successful' AND \n\t\t\t" . "video.active" . "='yes' AND " . "video.broadcast" . " !='unlisted' ";
     } else {
         $params['admin_access'] = true;
         if ($params['active']) {
             $cond .= " " . "video.active" . "='" . $params['active'] . "'";
         }
         if ($params['status']) {
             if ($cond != '') {
                 $cond .= " AND ";
             }
             $cond .= " " . "video.status" . "='" . $params['status'] . "'";
         }
         if ($params['broadcast']) {
             if ($cond != '') {
                 $cond .= " AND ";
             }
             $cond .= " " . "video.broadcast" . "='" . $params['broadcast'] . "'";
         }
     }
     //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 .= " " . "video.category" . " LIKE '%#{$cat_params}#%' ";
         }
         $cond .= ")";
     }
     //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']);
     }
     //uid
     if ($params['user'] || $params['userid']) {
         if ($params['userid']) {
             $params['user'] = $params['userid'];
         }
         if (!is_array($params['user'])) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . "video.userid" . "='" . $params['user'] . "'";
         } else {
             if ($cond != '') {
                 $cond .= ' AND (';
             }
             $uQu = 0;
             foreach ($params['user'] as $user) {
                 if ($uQu > 0) {
                     $cond .= ' OR ';
                 }
                 $cond .= " " . "video.userid" . "='" . $user . "'";
                 $uQu++;
             }
             $cond .= " ) ";
         }
     }
     //non-uid to exclude user videos from related
     if ($params['nonuser']) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . "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 .= " " . 'video.tags' . " LIKE '%" . $tag . "%'";
                 if ($loop < $total) {
                     $tag_n_title .= " OR ";
                 }
                 $loop++;
             }
         } else {
             if ($tag_n_title != '') {
                 $tag_n_title .= ' OR ';
             }
             $tag_n_title .= " " . 'video.tags' . " LIKE '%" . $params['tags'] . "%'";
         }
     }
     //TITLE
     if ($params['title']) {
         if ($tag_n_title != '') {
             $tag_n_title .= ' OR ';
         }
         $tag_n_title .= " " . 'video.title' . " LIKE '%" . $params['title'] . "%'";
     }
     if ($tag_n_title) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " ({$tag_n_title}) ";
     }
     //FEATURED
     if ($params['featured']) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . "video.featured" . " = '" . $params['featured'] . "' ";
     }
     //VIDEO ID
     if ($params['videoid']) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . "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 .= " " . "video.videoid" . " = '" . $vid . "' ";
                 }
                 $curVid++;
             }
             $cond .= ' ) ';
         }
     }
     //VIDEO KEY
     if ($params['videokey']) {
         if (!is_array($params['videokey'])) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . "video.videokey" . " = '" . $params['videokey'] . "' ";
         } else {
             if ($cond != '') {
                 $cond .= ' AND (';
             }
             $vkeyQue = 0;
             foreach ($params['videokey'] as $videokey) {
                 if ($vkeyQue > 0) {
                     $cond .= ' OR ';
                 }
                 $cond .= " " . "video.videokey" . " = '" . $videokey . "' ";
                 $vkeyQue++;
             }
             $cond .= " ) ";
         }
     }
     //Exclude Vids
     if ($params['exclude']) {
         if (!is_array($params['exclude'])) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . 'video.videoid' . " <> '" . $params['exclude'] . "' ";
         } else {
             foreach ($params['exclude'] as $exclude) {
                 if ($cond != '') {
                     $cond .= ' AND ';
                 }
                 $cond .= " " . 'video.videoid' . " <> '" . $exclude . "' ";
             }
         }
     }
     //Duration
     if ($params['duration']) {
         $duration_op = $params['duration_op'];
         if (!$duration_op) {
             $duration_op = "=";
         }
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . 'video.duration' . " " . $duration_op . " '" . $params['duration'] . "' ";
     }
     if ($params['has_mobile']) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . 'video.has_mobile' . "='" . $params['has_mobile'] . "'";
     }
     //Filename
     if ($params['filename']) {
         if (!is_array($params['filename'])) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . 'video.file_name' . " <> '" . $params['filename'] . "' ";
         } else {
             if ($cond != '') {
                 $cond .= ' AND (';
             } else {
                 $cond .= " ( ";
             }
             $fileNameQue = 0;
             foreach ($params['filename'] as $filename) {
                 if ($fileNameQue > 0) {
                     $cond .= ' OR ';
                 }
                 $cond .= " " . "video.file_name" . " = '" . $filename . "' ";
                 $fileNameQue++;
             }
             $cond .= " ) ";
         }
     }
     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;
                 }
             }
         }
     }
     if (!$params['count_only'] && !$params['show_related']) {
         $userFields = array('userid', 'email', 'username');
         foreach ($userFields as $ufield) {
             $ufieldq .= ",users." . $ufield;
         }
         //$meta_query = $this->create_meta_query();
         $fields_arr = array('video' => get_video_fields(), 'users' => get_user_fields());
         $fields = tbl_fields($fields_arr);
         $query = " SELECT " . $fields . " FROM " . tbl('video') . " AS video ";
         $query .= " LEFT JOIN " . tbl('users') . " AS users ";
         $query .= " ON video.userid = users.userid ";
         $limit_query = "";
         $order_query = "";
         if ($limit) {
             $limit_query = " LIMIT " . $limit;
         }
         if ($order) {
             $order_query = " ORDER BY " . $order;
         }
         if ($cond) {
             $query .= " WHERE " . $cond;
         }
         $query .= $order_query;
         $query .= $limit_query;
         $start = microtime(true);
         $action_data = call_actions('get_videos', $query);
         if ($action_data) {
             $result = $action_data;
         } else {
             $result = db_select($query);
         }
         $end = microtime(true);
     }
     if ($params['show_related']) {
         $cond = "";
         if ($superCond) {
             $cond = $superCond . " AND ";
         }
         $cond .= "MATCH(" . "video.title,video.tags" . ") \n\t\t\tAGAINST ('" . cbsearch::set_the_key($params['title']) . "' IN BOOLEAN MODE) ";
         if ($params['exclude']) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . 'video.videoid' . " <> '" . $params['exclude'] . "' ";
         }
         $query = " SELECT " . $fields . " FROM " . tbl('video') . " AS video ";
         $query .= " LEFT JOIN " . tbl('users') . " AS users ";
         $query .= " ON video.userid = users.userid ";
         if ($cond) {
             $query .= " WHERE " . $cond;
         }
         if ($limit) {
             $limit_query = " LIMIT " . $limit;
         }
         if ($order) {
             $order_query = " ORDER BY " . $order;
         }
         $query .= $order_query;
         $query .= $limit_query;
         $action_data = call_actions('get_videos', $query);
         if ($action_data) {
             $result = $action_data;
         } else {
             $result = db_select($query);
         }
         if ($db->num_rows == 0) {
             $cond = "";
             if ($superCond) {
                 $cond = $superCond . " AND ";
             }
             //Try Finding videos via tags
             $cond .= "MATCH(" . "video.title,video.tags" . ") \n\t\t\t\tAGAINST ('" . cbsearch::set_the_key($params['tags']) . "' IN BOOLEAN MODE) ";
             if ($params['exclude']) {
                 if ($cond != '') {
                     $cond .= ' AND ';
                 }
                 $cond .= " " . 'video.videoid' . " <> '" . $params['exclude'] . "' ";
             }
             $query = " SELECT " . $fields . " FROM " . tbl('video') . " AS video ";
             $query .= " LEFT JOIN " . tbl('users') . " AS users ";
             $query .= " ON video.userid = users.userid ";
             if ($cond) {
                 $query .= " WHERE " . $cond;
             }
             if ($limit) {
                 $limit_query = " LIMIT " . $limit;
             }
             if ($order) {
                 $order_query = " ORDER BY " . $order;
             }
             $query .= $order_query;
             $query .= $limit_query;
             $action_data = call_actions('get_videos', $query);
             if ($action_data) {
                 $result = $action_data;
             } else {
                 $result = db_select($query);
             }
         }
     }
     $result = apply_filters($result, 'get_videos');
     if (!$action_data && $result) {
         call_actions('select_videos', array('query' => $query, 'results' => $result));
     }
     if ($params['pr']) {
         pr($result, true);
     }
     if ($params['count_only']) {
         return $result = $db->count(tbl('video') . " AS video ", 'videoid', $cond);
     }
     if ($params['assign']) {
         assign($params['assign'], $result);
     } else {
         return $result;
     }
 }
예제 #2
0
 /**
  * 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, $cb_columns;
     $limit = $params['limit'];
     $order = $params['order'];
     $cond = "";
     $superCond = "";
     if (!has_access('admin_access', TRUE)) {
         $superCond = " " . "video.status" . "='Successful' AND\r\n\t\t\t" . "video.active" . "='yes' AND " . "video.broadcast" . " !='unlisted' ";
     } else {
         if ($params['active']) {
             $cond .= " " . "video.active" . "='" . $params['active'] . "'";
         }
         if ($params['status']) {
             if ($cond != '') {
                 $cond .= " AND ";
             }
             $cond .= " " . "video.status" . "='" . $params['status'] . "'";
         }
         if ($params['broadcast']) {
             if ($cond != '') {
                 $cond .= " AND ";
             }
             $cond .= " " . "video.broadcast" . "='" . $params['broadcast'] . "'";
         }
     }
     //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 .= " " . "video.category" . " LIKE '%#{$cat_params}#%' ";
         }
         $cond .= ")";
     }
     //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']);
     }
     //uid
     if ($params['user']) {
         if (!is_array($params['user'])) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . "video.userid" . "='" . $params['user'] . "'";
         } else {
             if ($cond != '') {
                 $cond .= ' AND (';
             }
             $uQu = 0;
             foreach ($params['user'] as $user) {
                 if ($uQu > 0) {
                     $cond .= ' OR ';
                 }
                 $cond .= " " . "video.userid" . "='" . $user . "'";
                 $uQu++;
             }
             $cond .= " ) ";
         }
     }
     //non-uid to exclude user videos from related
     if ($params['nonuser']) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . "video.userid" . " <> '" . $params['nonuser'] . "' ";
     }
     //padding videos in mass_embed pllugin
     if ($params['mass_embed_status']) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . "video.mass_embed_status" . " = '" . $params['mass_embed_status'] . "' ";
     }
     $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 .= " " . 'video.tags' . " LIKE '%" . $tag . "%'";
                 if ($loop < $total) {
                     $tag_n_title .= " OR ";
                 }
                 $loop++;
             }
         } else {
             if ($tag_n_title != '') {
                 $tag_n_title .= ' OR ';
             }
             $tag_n_title .= " " . 'video.tags' . " LIKE '%" . $params['tags'] . "%'";
         }
     }
     //TITLE
     if ($params['title']) {
         if ($tag_n_title != '') {
             $tag_n_title .= ' OR ';
         }
         $tag_n_title .= " " . 'video.title' . " LIKE '%" . $params['title'] . "%'";
     }
     if ($tag_n_title) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " ({$tag_n_title}) ";
     }
     //FEATURED
     if ($params['featured']) {
         //exit($params['featured']);
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . "video.featured" . " = '" . $params['featured'] . "' ";
     }
     //VIDEO ID
     if ($params['videoid']) {
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . "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 .= " " . "video.videoid" . " = '" . $vid . "' ";
                 }
                 $curVid++;
             }
             $cond .= ' ) ';
         }
     }
     //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 .= " " . 'video.videoid' . " <> '" . $params['exclude'] . "' ";
         } else {
             foreach ($params['exclude'] as $exclude) {
                 if ($cond != '') {
                     $cond .= ' AND ';
                 }
                 $cond .= " " . 'video.videoid' . " <> '" . $exclude . "' ";
             }
         }
     }
     //Duration
     if ($params['duration']) {
         $duration_op = $params['duration_op'];
         if (!$duration_op) {
             $duration_op = "=";
         }
         if ($cond != '') {
             $cond .= ' AND ';
         }
         $cond .= " " . 'video.duration' . " " . $duration_op . " '" . $params['duration'] . "' ";
     }
     //Filename
     if ($params['filename']) {
         if (!is_array($params['filename'])) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . 'video.file_name' . " <> '" . $params['filename'] . "' ";
         } else {
             if ($cond != '') {
                 $cond .= ' AND (';
             }
             $fileNameQue = 0;
             foreach ($params['filename'] as $filename) {
                 if ($fileNameQue > 0) {
                     $cond .= ' OR ';
                 }
                 $cond .= " " . "video.file_name" . " = '" . $filename . "' ";
                 $fileNameQue++;
             }
             $cond .= " ) ";
         }
     }
     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;
                 }
             }
         }
     }
     $fields = array('video' => get_video_fields(), 'users' => $cb_columns->object('users')->temp_change('featured', 'user_featured')->get_columns());
     $fields = tbl_fields($fields);
     if (!$params['count_only'] && !$params['show_related']) {
         $query = "SELECT {$fields} FROM " . cb_sql_table('video');
         $query .= " LEFT JOIN " . cb_sql_table('users') . " ON video.userid = users.userid";
         if (!empty($superCond)) {
             if ($cond !== "") {
                 $cond .= " AND " . $superCond;
             } else {
                 $cond .= $superCond;
             }
         }
         if ($cond) {
             $query .= " WHERE " . $cond;
         }
         $query .= $order ? " ORDER BY " . $order : false;
         $query .= $limit ? " LIMIT " . $limit : false;
         #pr( $query, true );
         $result = select($query);
         #if(!empty($cond))
         #	$cond .= " AND ";
         #$result = $db->select(tbl('video,users'),tbl('video.*,users.userid,users.username'),$cond." ".tbl("video.userid")." = ".tbl("users.userid"),$limit,$order);
         //echo $db->db_query;
     }
     global $cbsearch;
     if ($params['show_related']) {
         $cond = "";
         if ($superCond) {
             $cond = $superCond . " AND ";
         }
         $cond .= "MATCH(" . "video.title,video.tags" . ")\r\n\t\t\tAGAINST ('" . $params['title'] . "' IN BOOLEAN MODE) ";
         if ($params['exclude']) {
             if ($cond != '') {
                 $cond .= ' AND ';
             }
             $cond .= " " . 'video.videoid' . " <> '" . $params['exclude'] . "' ";
         }
         $query = " SELECT " . $fields . " FROM " . cb_sql_table('video');
         $query .= " LEFT JOIN " . cb_sql_table('users');
         $query .= " ON video.userid = users.userid ";
         if ($cond) {
             $query .= " WHERE " . $cond;
         }
         $query .= $order ? " ORDER BY " . $order : false;
         $query .= $limit ? " LIMIT " . $limit : false;
         $result = select($query);
         #$result = $db->select(tbl('video,users'),tbl('video.*,users.userid,users.username'),
         #$cond." AND ".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(" . "video.title,video.tags" . ")\r\n\t\t\t\tAGAINST ('" . $params['tags'] . "' IN BOOLEAN MODE) ";
             if ($params['exclude']) {
                 if ($cond != '') {
                     $cond .= ' AND ';
                 }
                 $cond .= " " . 'video.videoid' . " <> '" . $params['exclude'] . "' ";
             }
             $query = " SELECT " . $fields . " FROM " . cb_sql_table('video');
             $query .= " LEFT JOIN " . cb_sql_table('users');
             $query .= " ON video.userid = users.userid ";
             if ($cond) {
                 $query .= " WHERE " . $cond;
             }
             $query .= $order ? " ORDER BY " . $order : false;
             $query .= $limit ? " LIMIT " . $limit : false;
             $result = select($query);
             #$result = $db->select(tbl('video,users'),tbl('video.*,users.userid,users.username'),
             #$cond." AND ".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(cb_sql_table('video'), 'videoid', $cond);
     }
     if ($params['assign']) {
         assign($params['assign'], apply_filters($result, 'get_video'));
     } else {
         return apply_filters($result, 'get_video');
     }
 }