function get_user_profile_field($userid, $field) { if (user_exists($userid)) { $query = "SELECT user_profile." . $field . " FROM " . cb_sql_table('user_profile'); start_where(); add_where(" user_profile.userid = '" . $userid . "' "); $query .= " WHERE " . get_where(); end_where(); $results = db_select($query); if ($results) { return $results[0][$field]; } else { return false; } } }
/** * Function used to get playlists */ function get_playlists($params = array()) { global $cb_columns, $db; $fields = array('playlists' => $cb_columns->object('playlists')->get_columns()); $order = $params['order']; $limit = $params['limit']; $main_query = $query = "SELECT " . table_fields($fields) . " FROM " . table('playlists'); $condition = "playlists.playlist_type = 'v'"; if (!has_access('admin_access')) { $condition .= $condition ? " AND " : ""; $condition .= "playlists.privacy = 'public'"; } else { if ($params['privacy']) { $condition .= $condition ? " AND " : ""; $condition .= " playlists.privacy = '" . mysql_clean($params['privacy']) . "' "; } } if ($params['category']) { $condition .= $condition ? " AND " : ""; $condition .= " playlists.category = '" . $params['category'] . "' "; } if ($params['include']) { $ids = is_array($params['include']) ? $params['include'] : explode(',', $params['include']); if (is_array($ids) and !empty($ids)) { $condition .= $condition ? " AND " : ""; $ids = implode(",", array_map('trim', $ids)); $condition .= " playlists.playlist_id IN ({$ids}) "; } } if ($params['exclude']) { $ids = is_array($params['exclude']) ? $params['exclude'] : explode(',', $params['exclude']); if (is_array($ids) and !empty($ids)) { $condition .= $condition ? " AND " : ""; $ids = implode(",", array_map('trim', $ids)); $condition .= " playlists.playlist_id NOT IN ({$ids}) "; } } if ($params['date_span']) { $condition .= $condition ? " AND " : ""; $column = $params['date_span_column'] ? trim($params['date_span_column']) : 'playlists.date_added'; $condition .= cbsearch::date_margin($column, $params['date_span']); } if ($params['last_update']) { $condition .= $condition ? " AND " : ""; $condition .= cbsearch::date_margin('playlists.last_update', $params['last_update']); } if ($params['user']) { $condition .= $condition ? " AND " : ""; $condition .= " playlists.userid = '" . $params['user'] . "' "; } if ($params['has_items']) { $condition .= $condition ? " AND " : ""; $condition .= " playlists.total_items > '0' "; } if ($params['count_only']) { $result = $db->count(cb_sql_table('playlists'), 'playlist_id'); return $result; } if ($condition) { $query .= " WHERE " . $condition; } $order = " ORDER BY " . ($order ? trim($order) : "playlists.date_added DESC"); $limit = $limit ? " LIMIT {$limit} " : ""; $query .= $order . $limit; $query_id = cb_query_id($query); $action_array = array('query_id' => $query_id); $data = cb_do_action('select_playlists', array_merge($action_array, $params)); if ($data) { return $data; } $results = select($query); if (!empty($results)) { cb_do_action('return_playlists', array('query_id' => $query_id, 'results' => $results)); return $results; } return false; }
/** * 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'); } }
function table($table, $as = null) { return cb_sql_table($table, $as); }
/** * This confirms that whether user was previously subscribed to * content or not. * * If user is subscribing for the first time, call <code>do_subscription_inital_actions</code> * * @author Fawaz Tahir <*****@*****.**> * @param int $sub_id * @param string $type * @return boolean */ function was_user_subscribed_to_content($sub_id, $type) { $query = " SELECT subscription_content_id FROM " . cb_sql_table('subscriptions_content'); start_where(); add_where(" subscriptions_content.subscription_id = '" . $sub_id . "' "); add_where(" subscriptions_content.content_type = '" . $type . "' "); $query .= " WHERE" . get_where(); end_where(); $query .= " ORDER BY subscriptions_content.date_added DESC LIMIT 1"; $result = db_select($query); if ($result) { return true; } else { return false; } }
/** * Function used to get user details using userid */ function get_user_details($id = NULL, $checksess = false) { global $db, $sess; /*if(!$id) $id = userid();*/ $is_email = strpos($id, '@') !== false ? true : false; $select_field = (!$is_email and !is_numeric($id)) ? 'username' : (!is_numeric($id) ? 'email' : 'userid'); $fields = tbl_fields(array('users' => array('*'))); $query = "SELECT {$fields} FROM " . cb_sql_table('users'); $query .= " WHERE users.{$select_field} = '{$id}'"; $result = select($query); if ($result) { $details = $result[0]; if (!$checksess) { return apply_filters($details, 'get_user'); } else { $session = $this->sessions['smart_sess']; $smart_sess = md5($details['user_session_key'] . $sess->get('sess_salt')); if ($smart_sess == $session['session_value']) { $this->is_login = true; return apply_filters($details, 'get_user'); } else { return false; } } } return false; }