/** * 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; } }
/** * This function return all photos that are avatars * * @global object $db * @global OBJECT $cbphoto * @param boolean $join * @param string $cond * @param string $order * @param int $limit * @return array */ function get_avatar_photos($join = true, $cond = null, $order = null, $limit = null) { global $db, $cbphoto; if (!is_null($cond)) { $cond .= ' AND ' . $cond; } if ($join) { list($join, $alias) = join_collection_table(); } $results = $db->select(tbl('photos') . $join, '*' . $alias, " is_avatar='yes' {$cond} ", $limit, $order); if ($results) { return $results; } else { return false; } }