/** * 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 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; } }
/** * 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; } }