/** * 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; } }
/** * Function used to get collections */ function get_collections($p = NULL) { global $db; $limit = $p['limit']; $order = $p['order']; $cond = ""; if (!has_access('admin_access', TRUE) && $p['user'] != userid()) { $cond .= " " . tbl('collections.active') . " = 'yes' AND " . tbl('collections.broadcast') . " = 'public' "; } elseif ($p['user'] == userid()) { $cond .= " " . tbl('collections.active') . " = 'yes'"; } else { if ($p['active']) { $cond .= " " . tbl('collections.active') . " = '" . $p['active'] . "'"; } if ($p['broadcast']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.broadcast') . " = '" . $p['broadcast'] . "'"; } } if ($p['category']) { $get_all = false; if (!is_array($p['category'])) { if (strtolower($p['category']) == 'all') { $get_all = true; } } if (!$get_all) { if ($cond != '') { $cond .= " AND "; } $cond .= "("; if (!is_array($p['category'])) { $cats = explode(',', $p['category']); } else { $cats = $p['category']; } $count = 0; foreach ($cats as $cat) { $count++; if ($count > 1) { $cond .= " OR "; } $cond .= " " . tbl('collections.category') . " LIKE '%#{$cat}#%'"; } $cond .= ")"; } } if ($p['date_span']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . cbsearch::date_margin("date_added", $p['date_span']); } if ($p['user']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.userid') . " = '" . $p['user'] . "'"; } if ($p['type']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.type') . " = '" . $p['type'] . "'"; } if ($p['featured']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.featured') . " = '" . $p['featured'] . "'"; } if ($p['public_upload']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.public_upload') . " = '" . $p['public_upload'] . "'"; } if ($p['exclude']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.collection_id') . " <> '" . $p['exclude'] . "'"; } if ($p['cid']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.collection_id') . " = '" . $p['cid'] . "'"; } /** Get only with those who have items **/ if ($p['has_items']) { if ($cond != '') { $cond .= " AND "; } $cond .= " " . tbl('collections.total_objects') . " >= '1'"; } $title_tag = ''; if ($p['name']) { $title_tag .= " " . tbl('collections.collection_name') . " LIKE '%" . $p['name'] . "%'"; } if ($p['tags']) { $tags = explode(",", $p['tags']); if (count($tags) > 0) { if ($title_tag != '') { $title_tag .= " OR "; } $total = count($tags); $loop = 1; foreach ($tags as $tag) { $title_tag .= " " . tbl('collections.collection_tags') . " LIKE '%{$tag}%'"; if ($loop < $total) { $title_tag .= " OR "; } $loop++; } } else { if ($title_tag != '') { $title_tag .= " OR "; } $title_tag .= " " . tbl('collections.collection_tags') . " LIKE '%" . $p['tags'] . "%'"; } } if ($title_tag != "") { if ($cond != '') { $cond .= " AND "; } $cond .= " ({$title_tag}) "; } // Remove avatar collections if (has_access('admin_access')) { if (!$p['avatar_collection']) { $p['avatar_collection'] = 'no'; } if ($cond != '') { $cond .= ' AND '; } $cond .= " " . tbl('collections.is_avatar_collection') . " = '" . $p['avatar_collection'] . "'"; } else { if ($cond != '') { $cond .= ' AND '; } $cond .= ' ' . tbl('collections.is_avatar_collection') . ' = "no" '; } if (!$p['count_only']) { if ($cond != "") { $cond .= " AND "; } $result = $db->select(tbl("collections") . ' LEFT JOIN ' . tbl('users') . ' ON ' . tbl('collections.userid') . ' = ' . tbl('users.userid'), tbl("collections.*,users.userid,users.username"), $cond . tbl("collections.userid") . " = " . tbl("users.userid"), $limit, $order); //echo $db->db_query; } if ($p['count_only']) { return $result = $db->count(tbl("collections"), "collection_id", $cond); //echo $db->db_query; } if ($p['assign']) { assign($p['assign'], $result); } else { return $result; } }
/** * Function used to get groups * @parma ARRAY * group_id => {id of group} INT * user => {all groups of the user INT * category => {all groups in specified category INT,INT,INT * featured => {get featured groups only} yes,no * limit => {number of results including offset} * order => {soring by} * date_margin => {date span} */ function get_groups($params = NULL, $force_admin = FALSE) { global $db; $limit = $params['limit']; $order = $params['order']; $cond = ""; if (!has_access('admin_access', TRUE) && !$force_admin) { $cond .= " " . tbl("groups.active") . "='yes' "; } else { if ($params['active']) { $cond .= " " . tbl("groups.active") . "='" . $params['active'] . "'"; } } //Setting Category Condition if (!is_array($params['category'])) { $is_all = strtolower($params['category']); } if ($params['category'] && $is_all != '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("groups.category") . " LIKE '%#{$cat_params}#%' "; } $cond .= ")"; } //date span if ($params['date_span']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . cbsearch::date_margin("date_added", $params['date_span']); } //uid if ($params['user']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . tbl("groups.userid") . "='" . $params['user'] . "'"; } $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("groups.group_tags") . " LIKE '%" . $tag . "%'"; if ($loop < $total) { $tag_n_title .= " OR "; } $loop++; } } else { if ($tag_n_title != '') { $tag_n_title .= ' OR '; } $tag_n_title .= " " . tbl("groups.group_tags") . " LIKE '%" . $params['tags'] . "%'"; } } //TITLE if ($params['title']) { if ($tag_n_title != '') { $tag_n_title .= ' OR '; } $tag_n_title .= " " . tbl("groups.group_name") . " LIKE '%" . $params['title'] . "%'"; } if ($tag_n_title) { if ($cond != '') { $cond .= ' AND '; } $cond .= " ({$tag_n_title}) "; } //FEATURED if ($params['featured']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . tbl("groups.featured") . " = '" . $params['featured'] . "' "; } //GROUP ID if ($params['group_id']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " group_id = '" . $params['group_id'] . "' "; } //Exclude Vids if ($params['exclude']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . tbl("groups.group_id") . " <> '" . $params['exclude'] . "' "; } if (!$params['count_only']) { if (!empty($cond)) { $cond .= " AND "; } $result = $db->select(tbl($this->gp_tbl . ",users"), '' . tbl($this->gp_tbl) . '.*, ' . tbl("users") . '.username, ' . tbl("users") . '.userid', $cond . " " . tbl("groups.userid") . " = " . tbl("users.userid") . " ", $limit, $order); } // echo $db->db_query; if ($params['count_only']) { return $result = $db->count(tbl($this->gp_tbl), '*', $cond); } if ($params['assign']) { assign($params['assign'], $result); } else { return $result; } }
/** * Get Photos */ function get_photos($p) { global $db; $tables = "users,photos"; $order = $p['order']; if (!$order) { $order = 'date_added DESC'; } if (strpos($order, ',') > 0) { $order = explode(',', $order); $order = array_map('trim', $order); foreach ($order as $o) { $newo[] = tbl('photos.' . $o); } $order = $newo; $order = implode(',', $order); } $limit = $p['limit']; $cond = ""; if (!has_access('admin_access', TRUE)) { $cond = " " . tbl('photos.broadcast') . " = 'public' AND " . tbl('photos.active') . " = 'yes'"; } else { if ($p['active']) { $cond .= " " . tbl('photos.active') . " = '" . $p['active'] . "'"; } if ($p['broadcast']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . tbl('photos.broadcast') . " = '" . $p['broadcast'] . "'"; } } if ($p['pid']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['pid'], "sign" => "=", "operator" => "OR")); } if ($p['key']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . tbl('photos.photo_key') . " = '" . $p['key'] . "'"; } if ($p['filename']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . tbl('photos.filename') . " = '" . $p['filename'] . "'"; } if ($p['extension']) { foreach ($this->exts as $ext) { if (in_array($ext, $this->exts)) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . tbl('photos.ext') . " = '" . $p['extension'] . "'"; } } } if ($p['date_span']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . cbsearch::date_margin(tbl("photos.date_added"), $p['date_span']); } if ($p['featured']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . tbl('photos.featured') . " = '" . $p['featured'] . "'"; } if ($p['user']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['user'], "sign" => "=", "operator" => "AND", "column" => "userid")); } if ($p['exclude']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>")); } $title_tag = ''; if ($p['title']) { $title_tag = " " . tbl('photos.photo_title') . " LIKE '%" . $p['title'] . "%'"; } if ($p['tags']) { $tags = explode(",", $p['tags']); if (count($tags) > 0) { if ($title_tag != '') { $title_tag .= " OR "; } $total = count($tags); $loop = 1; foreach ($tags as $tag) { $title_tag .= " " . tbl('photos.photo_tags') . " LIKE '%{$tag}%'"; if ($loop < $total) { $title_tag .= " OR "; } $loop++; } } else { if ($title_tag != '') { $title_tag .= " OR "; } $title_tag .= " " . tbl('photos.photo_tags') . " LIKE '%" . $p['tags'] . "%'"; } } if ($title_tag != "") { if ($cond != '') { $cond .= " AND "; } $cond .= " ({$title_tag}) "; } if ($p['ex_user']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['ex_user'], "sign" => "<>", "operator" => "AND", "column" => "userid")); } if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } if ($p['get_orphans']) { $p['collection'] = ""; } if ($p['collection']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "=", "operator" => "OR", "column" => "collection_id")); } else { if ($cond != "") { $cond .= " AND "; } $cond .= " " . tbl('photos.collection_id') . " <> '0'"; } if ($p['mature']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . tbl('photos.is_mature') . " = '" . $p['mature'] . "'"; } if (has_access('admin_access')) { if (!$p['is_avatar']) { $p['is_avatar'] = 'no'; } if ($cond != '') { $cond .= ' AND '; } $cond .= " " . tbl('photos.is_avatar') . " = '" . $p['is_avatar'] . "'"; } else { if ($cond != '') { $cond .= ' AND '; } $cond .= ' ' . tbl('photos.is_avatar') . ' = "no" '; } list($join, $alias) = join_collection_table(); if (!$p['count_only'] && !$p['show_related']) { if ($cond != "") { $cond .= " AND "; } $result = $db->select(tbl($tables) . $join, tbl("photos.*,users.userid,users.username") . $alias, $cond . tbl("photos.userid") . " = " . tbl("users.userid"), $limit, trim($order)); //echo $db->db_query; } if ($p['show_related']) { $cond = "MATCH(" . tbl('photos.photo_title,photos.photo_tags') . ")"; $cond .= " AGAINST ('" . cbsearch::set_the_key($p['title']) . "' IN BOOLEAN MODE)"; if ($p['exclude']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>")); } if ($p['collection']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id")); } if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } // Remove avatar photos if (has_access('admin_access')) { if (!$p['is_avatar']) { $p['is_avatar'] = 'no'; } if ($cond != '') { $cond .= ' AND '; } $cond .= " " . tbl('photos.is_avatar') . " = '" . $p['is_avatar'] . "'"; } else { if ($cond != '') { $cond .= ' AND '; } $cond .= ' ' . tbl('photos.is_avatar') . ' = "no" '; } $result = $db->select(tbl($tables) . $join, tbl("photos.*,users.userid,users.username") . $alias, $cond . " AND " . tbl('photos.collection_id') . " <> '0' AND " . tbl("photos.userid") . " = " . tbl("users.userid"), $limit, tbl('photos.' . trim($order))); //echo $db->db_query; // We found nothing from TITLE of Photos, let's try TAGS if ($db->num_rows == 0) { $tags = cbsearch::set_the_key($p['tags']); $tags = str_replace('+', '', $tags); $cond = "MATCH(" . tbl('photos.photo_title,photos.photo_tags') . ")"; $cond .= " AGAINST ('" . $tags . "' IN BOOLEAN MODE)"; if ($p['exclude']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>")); } if ($p['collection']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id")); } if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } if (has_access('admin_access')) { if (!$p['is_avatar']) { $p['is_avatar'] = 'no'; } if ($cond != '') { $cond .= ' AND '; } $cond .= " " . tbl('photos.is_avatar') . " = '" . $p['is_avatar'] . "'"; } else { if ($cond != '') { $cond .= ' AND '; } $cond .= ' ' . tbl('photos.is_avatar') . ' = "no" '; } $result = $db->select(tbl($tables) . $join, tbl("photos.*,users.userid,users.username") . $alias, $cond . " AND " . tbl('photos.collection_id') . " <> '0' AND " . tbl("photos.userid") . " = " . tbl("users.userid"), $limit, tbl('photos.' . trim($order))); //echo $db->db_query; } } if ($p['count_only']) { if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } $result = $db->count(tbl("photos"), "photo_id", $cond); } if ($p['assign']) { assign($p['assign'], $result); } else { return $result; } }
/** * 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 used to get users */ function get_users($params = NULL, $force_admin = FALSE) { global $db; $limit = $params['limit']; $order = $params['order']; $cond = ""; if (!has_access('admin_access', TRUE) && !$force_admin) { $cond .= " \tstatus='verified' AND ban_status ='no' "; } else { if ($params['ban']) { $cond .= " ban_status ='" . $params['ban'] . "'"; } if ($params['status']) { if ($cond != '') { $cond .= " AND "; } $cond .= " \tstatus='" . $params['status'] . "'"; } } //Setting Category Condition if (!is_array($params['category'])) { $is_all = strtolower($params['category']); } if ($params['category'] && $is_all != '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 .= " category LIKE '%{$cat_params}%' "; } $cond .= ")"; } //date span if ($params['date_span']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . cbsearch::date_margin("doj", $params['date_span']); } /* //uid if($params['user']) { if($cond!='') $cond .= ' AND '; $cond .= " userid='".$params['user']."'"; } $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 .= " tags LIKE '%".$tag."%'"; if($loop<$total) $tag_n_title .= " OR "; $loop++; } }else { if($tag_n_title!='') $tag_n_title .= ' OR '; $tag_n_title .= " tags LIKE '%".$params['tags']."%'"; } } //TITLE if($params['title']) { if($tag_n_title!='') $tag_n_title .= ' OR '; $tag_n_title .= " title LIKE '%".$params['tags']."%'"; } if($tag_n_title) { if($cond!='') $cond .= ' AND '; $cond .= " ($tag_n_title) "; } */ //FEATURED if ($params['featured']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " featured = '" . $params['featured'] . "' "; } //Email if ($params['username']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " username = '******'username'] . "' "; } //Email if ($params['email']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " email = '" . $params['email'] . "' "; } //Exclude Users if ($params['exclude']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " userid <> '" . $params['exclude'] . "' "; } //Getting specific User if ($params['userid']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " userid = '" . $params['userid'] . "' "; } //Sex if ($params['gender']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " sex = '" . $params['gender'] . "' "; } //Level if ($params['level']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " level = '" . $params['level'] . "' "; } if ($params['cond']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . $params['cond'] . " "; } if ($params['join_profile'] != "no") { @($join_profile = " LEFT JOIN " . tbl("user_profile") . " ON " . tbl("users.userid") . " = " . tbl("user_profile.userid")); } $join_profile = ""; if (!$params['count_only']) { $result = $db->select(tbl('users') . $join_profile, '*', $cond, $limit, $order); } if ($params['count_only']) { return $result = $db->count(tbl('users'), 'userid', $cond); } if ($params['assign']) { assign($params['assign'], $result); } else { return $result; } }
/** * Get Photos */ function get_photos($p) { global $db, $cb_columns; $tables = "photos,users"; $order = $p['order']; $limit = $p['limit']; $cond = ""; if (!has_access('admin_access', TRUE)) { $cond = " " . 'photos.broadcast' . " = 'public' AND " . 'photos.active' . " = 'yes'"; } else { if ($p['active']) { $cond .= " " . 'photos.active' . " = '" . $p['active'] . "'"; } if ($p['broadcast']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . 'photos.broadcast' . " = '" . $p['broadcast'] . "'"; } } if ($p['pid']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['pid'], "sign" => "=", "operator" => "OR")); } if ($p['key']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . 'photos.photo_key' . " = '" . $p['key'] . "'"; } if ($p['filename']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . 'photos.filename' . " = '" . $p['filename'] . "'"; } if ($p['extension']) { foreach ($this->exts as $ext) { if (in_array($ext, $this->exts)) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . 'photos.ext' . " = '" . $p['extension'] . "'"; } } } if ($p['date_span']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . cbsearch::date_margin("photos.date_added", $p['date_span']); } if ($p['featured']) { if ($cond != "") { $cond .= " AND "; } $cond .= " " . 'photos.featured' . " = '" . $p['featured'] . "'"; } if ($p['user']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['user'], "sign" => "=", "operator" => "AND", "column" => "userid")); } if ($p['exclude']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>")); } $title_tag = ''; if ($p['title']) { $title_tag = " " . 'photos.photo_title' . " LIKE '%" . $p['title'] . "%'"; } if ($p['tags']) { $tags = explode(",", $p['tags']); if (count($tags) > 0) { if ($title_tag != '') { $title_tag .= " OR "; } $total = count($tags); $loop = 1; foreach ($tags as $tag) { $title_tag .= " " . 'photos.photo_tags' . " LIKE '%{$tag}%'"; if ($loop < $total) { $title_tag .= " OR "; } $loop++; } } else { if ($title_tag != '') { $title_tag .= " OR "; } $title_tag .= " " . 'photos.photo_tags' . " LIKE '%" . $p['tags'] . "%'"; } } if ($title_tag != "") { if ($cond != '') { $cond .= " AND "; } $cond .= " ({$title_tag}) "; } if ($p['ex_user']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['ex_user'], "sign" => "<>", "operator" => "AND", "column" => "userid")); } if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } if ($p['get_orphans']) { $p['collection'] = (string) "0"; } if ($p['collection'] || $p['get_orphans']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "=", "operator" => "OR", "column" => "collection_id")); } else { if ($cond != "") { $cond .= " AND "; } $cond .= " " . 'photos.collection_id' . " <> '0'"; } $fields = array('photos' => get_photo_fields(), 'users' => get_user_fields(), 'collections' => array('collection_name', 'type', 'category', 'views as collection_views', 'date_added as collection_added')); $string = tbl_fields($fields); $main_query = "SELECT {$string} FROM " . table('photos'); $main_query .= " LEFT JOIN " . table('collections') . " ON photos.collection_id = collections.collection_id"; $main_query .= " LEFT JOIN " . table('users') . " ON collections.userid = users.userid"; $order = $order ? " ORDER BY " . $order : false; $limit = $limit ? " LIMIT " . $limit : false; if (!$p['count_only'] && !$p['show_related']) { $query = $main_query; if ($cond) { $query .= " WHERE " . $cond; } $query .= $order; $query .= $limit; $result = select($query); } if ($p['show_related']) { $query = $main_query; $cond = "MATCH(" . 'photos.photo_title,photos.photo_tags' . ")"; $cond .= " AGAINST ('" . cbsearch::set_the_key($p['title']) . "' IN BOOLEAN MODE)"; if ($p['exclude']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>")); } if ($p['collection']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id")); } if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } $where = " WHERE " . $cond . " AND photos.collection_id <> 0"; $query .= $where; $query .= $order; $query .= $limit; $result = select($query); // We found nothing from TITLE of Photos, let's try TAGS if ($db->num_rows == 0) { $query = $main_query; $tags = cbsearch::set_the_key($p['tags']); $tags = str_replace('+', '', $tags); $cond = "MATCH(" . 'photos.photo_title,photos.photo_tags' . ")"; $cond .= " AGAINST ('" . $tags . "' IN BOOLEAN MODE)"; if ($p['exclude']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>")); } if ($p['collection']) { if ($cond != "") { $cond .= " AND "; } $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id")); } if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } $where = " WHERE " . $cond . " AND photos.collection_id <> 0"; $query .= $where; $query .= $order; $query .= $limit; $result = select($query); } } if ($p['count_only']) { if ($p['extra_cond']) { if ($cond != "") { $cond .= " AND "; } $cond .= $p['extra_cond']; } $result = $db->count(table("photos"), "photo_id", $cond); } ##pr( $query, true ); if ($p['assign']) { assign($p['assign'], $result); } else { return $result; } }
/** * Function used to get users */ function get_users($params = NULL, $force_admin = FALSE) { global $db; $limit = $params['limit']; $order = $params['order']; $cond = ""; if (!has_access('admin_access', TRUE) && !$force_admin) { $cond .= " \tusers.usr_status='Ok' AND users.ban_status ='no' "; } else { if ($params['ban']) { $cond .= " users.ban_status ='" . $params['ban'] . "'"; } if ($params['status']) { if ($cond != '') { $cond .= " AND "; } $cond .= " \tusers.usr_status='" . $params['status'] . "'"; } } //Setting Category Condition if (!is_array($params['category'])) { $is_all = strtolower($params['category']); } if ($params['category'] && $is_all != '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 .= " users.category LIKE '%{$cat_params}%' "; } $cond .= ")"; } //date span if ($params['date_span']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . cbsearch::date_margin("users.doj", $params['date_span']); } /*//uid if($params['user']) { if($cond!='') $cond .= ' AND '; $cond .= " userid='".$params['user']."'"; } $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 .= " tags LIKE '%".$tag."%'"; if($loop<$total) $tag_n_title .= " OR "; $loop++; } }else { if($tag_n_title!='') $tag_n_title .= ' OR '; $tag_n_title .= " tags LIKE '%".$params['tags']."%'"; } } //TITLE if($params['title']) { if($tag_n_title!='') $tag_n_title .= ' OR '; $tag_n_title .= " title LIKE '%".$params['tags']."%'"; } if($tag_n_title) { if($cond!='') $cond .= ' AND '; $cond .= " ($tag_n_title) "; }*/ //FEATURED if ($params['featured']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " users.featured = '" . $params['featured'] . "' "; } //Email if ($params['username']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " users.username = '******'username'] . "' "; } //Email if ($params['email']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " users.email = '" . $params['email'] . "' "; } //Exclude Users if ($params['exclude']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " users.userid <> '" . $params['exclude'] . "' "; } //Getting specific User if ($params['userid']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " users.userid = '" . $params['userid'] . "' "; } //Sex if ($params['gender']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " users.sex = '" . $params['gender'] . "' "; } //Level if ($params['level']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " users.level = '" . $params['level'] . "' "; } if ($params['cond']) { if ($cond != '') { $cond .= ' AND '; } $cond .= " " . $params['cond'] . " "; } if (!$params['count_only']) { $fields = array('users' => get_user_fields(), 'profile' => array('rating', 'rated_by', 'voters', 'first_name', 'last_name')); $fields['users'][] = 'last_active'; $query = " SELECT " . tbl_fields($fields) . " FROM " . tbl('users') . " AS users "; $query .= " LEFT JOIN " . table('user_profile', 'profile ') . " ON users.userid = profile.userid "; if ($cond) { $query .= " WHERE " . $cond; } if ($order) { $query .= " ORDER BY " . $order; } if ($limit) { $query .= " LIMIT " . $limit; } //$result = $db->select(tbl('users'),'*',$cond,$limit,$order); $result = select($query); } if ($params['count_only']) { //$cond= substr($cond,8); $result = $db->count(tbl('users') . " AS users ", 'userid', $cond); //echo $cond; //return $result; } if ($params['assign']) { assign($params['assign'], $result); } else { return $result; } }