function api_oauth2_access_tokens_for_key(&$key, $more = array()) { $enc_key = AddSlashes($key['id']); $sql = "SELECT * FROM OAuth2AccessTokens WHERE api_key_id='{$enc_key}' AND (expires=0 OR expires > UNIX_TIMESTAMP(NOW()))"; if (features_is_enabled(array("api_site_keys", "api_site_tokens"))) { # pretty sure we don't want to filter on this # but just in case... (20130711/straup) # $sql .= " AND api_key_role_id=0"; } $sql .= " ORDER BY created DESC"; $rsp = db_fetch_paginated($sql, $more); return $rsp; }
function api_keys_for_user(&$user, $more = array()) { $enc_user = AddSlashes($user['id']); $sql = "SELECT * FROM ApiKeys WHERE user_id='{$enc_user}' AND deleted=0 ORDER BY created DESC"; $rsp = db_fetch_paginated($sql, $more); return $rsp; }
function _search_sheets_all($where, $viewer_id, $more = array()) { $sql = "SELECT DISTINCT(d.sheet_id) FROM DotsSearch d WHERE "; if ($more['has_extras']) { $sql = "SELECT DISTINCT(d.sheet_id) FROM DotsSearch d, DotsSearchExtras e WHERE d.dot_id=e.dot_id AND "; } # $sql .= implode(" AND ", $where); $rsp = db_fetch_paginated($sql, $more); if (!$rsp['ok']) { return $rsp; } $sheets = array(); $sheet_more = array('load_user' => 1, 'load_extent' => 1); foreach ($rsp['rows'] as $row) { if (!$row['sheet_id']) { continue; } $sheet_more['sheet_user_id'] = $row['user_id']; $sheets[] = sheets_get_sheet($row['sheet_id'], $viewer_id, $sheet_more); } return array('ok' => 1, 'sheets' => &$sheets); }
function flickr_push_subscriptions_get_subscriptions_for_user(&$user, $more = array()) { $enc_user = AddSlashes($user['id']); $sql = "SELECT * FROM FlickrPushSubscriptions WHERE user_id='{$enc_user}' ORDER BY id"; $rsp = db_fetch_paginated($sql, $args); return $rsp; }
function users_get_users($args = array()) { $sql = "SELECT * FROM Users ORDER BY created DESC"; return db_fetch_paginated($sql, $args); }
function sheets_recently_created($viewer_id = 0, $more = array()) { $defaults = array('per_page' => 50); $args = array_merge($defaults, $more); $sql = "SELECT * FROM SheetsLookup WHERE deleted=0 AND count_dots_public > 0 ORDER BY created DESC"; $rsp = db_fetch_paginated($sql, $args); if (!$rsp['ok']) { return $rsp; } $sheets = array(); foreach ($rsp['rows'] as $row) { $more = array('sheet_user_id' => $row['user_id'], 'load_extent' => 1, 'load_user' => 1); if ($sheet = sheets_get_sheet($row['sheet_id'], $viewer_id, $more)) { $sheets[] = $sheet; } } $ok = count($sheets) ? 1 : 0; return array('ok' => $ok, 'sheets' => &$sheets); }
function dots_get_dots_recently_imported($to_fetch = 15) { # CACHING: This doesn't really lend itself to caching. # That may become an issue (20110301/straup) $recent = array(); $sheet_sql = "SELECT * FROM SheetsLookup WHERE deleted=0 ORDER BY created DESC"; $sheet_args = array('page' => 1); $page_count = null; $total_count = null; $iters = 0; $max_iters = 15; while (!isset($page_count) || $page_count >= $sheet_args['page']) { $sheet_rsp = db_fetch_paginated($sheet_sql, $sheet_args); if (!$sheet_rsp['ok']) { break; } if (!isset($page_count)) { $page_count = $sheet_rsp['pagination']['page_count']; $total_count = $sheet_rsp['pagination']['total_count']; } foreach ($sheet_rsp['rows'] as $sheet) { $enc_sheet = AddSlashes($sheet['sheet_id']); $dot_sql = "SELECT * FROM DotsSearch WHERE sheet_id='{$enc_sheet}' AND perms=0 ORDER BY imported DESC"; $dot_args = array('per_page' => 15); $dot_rsp = db_fetch_paginated($dot_sql, $dot_args); if (!$dot_rsp['ok']) { break; } $default_limit = 3; # sudo, make me smarter $limit = min($default_limit, count($dot_rsp['rows'])); if ($limit) { shuffle($dot_rsp['rows']); foreach (array_slice($dot_rsp['rows'], 0, $limit) as $row) { $viewer_id = 0; $more = array('load_user' => 1); $recent[] = dots_get_dot($row['dot_id'], $viewer_id, $more); } if (count($recent) == $to_fetch) { break; } } } if (count($recent) == $to_fetch) { break; } $sheet_args['page']++; $iters++; if ($iters == $max_iters) { break; } } shuffle($recent); return $recent; }
function invite_codes_get_all(&$args) { $sql = "SELECT * FROM InviteCodes"; $sql .= " ORDER BY created DESC"; return db_fetch_paginated($sql, $args); }