/** * Deactivates all of a user's affiliations: for use when a user deactivates. * This function assumes that $userid was active and is becoming deactivated. * * @param int $userid * @author moskov */ function deactivate_affiliations($userid) { $conn_w = id_get_conn($userid, 'w'); // unlink active affiliations $sql = 'SELECT `network_key` FROM `affiliations_data` ' . 'WHERE `id` = %d AND `status` != %d AND `confirmed` = %d'; $ret = queryf($conn_w, $sql, $userid, AffilNetworkStatusConst::REMOVED, AffilMiscConst::NETWORK_CONFIRMED_YES); while ($row = mysql_fetch_array($ret)) { list($network_key) = $row; remove_affiliation_link($userid, $network_key, $is_deactivate = true); } // mark id deactivated in affilitaions_data // (wisdom etc needs this data duplication from info.confirmed) $sql = 'UPDATE `affiliations_data` SET `id_is_active` = %d, ' . '`row_updated_time` = UNIX_TIMESTAMP() WHERE `id` = %d'; queryf($conn_w, $sql, false, $userid); }
/** * Fetches the user ids of all the friends of $user. * * @param $user user to fetch friends for * @return array of user ids that $user is friends with */ function user_get_all_friends($uid) { global $data_conn, $all_friend_sets; if (isset($all_friend_sets[$uid])) { return $all_friend_sets[$uid]; } $sql = "SELECT user2 FROM friend WHERE user1=%d"; $friend_arr = array(); if ($data_conn) { if ($ret = queryf($data_conn, $sql, $uid)) { while ($row = mysql_fetch_assoc($ret)) { $friend_arr[] = $row['user2']; } } } $all_friend_sets[$uid] = $friend_arr; return $friend_arr; }
/** * Fetch the members of a friend list * * @param $flid id of friend list * @return array of user ids that are members of the friend list */ function friend_list_get_members($flid) { global $data_conn, $friend_list_members; if (isset($friend_list_members[$flid])) { return $friend_list_members[$flid]; } $uids = array(); if ($data_conn) { $sql = 'SELECT uid from friend_list_member WHERE flid = %d'; if ($ret = queryf($data_conn, $sql, $flid)) { while ($row = mysql_fetch_assoc($ret)) { $uids[] = $row['uid']; } } $friend_list_members[$flid] = $uids; return $uids; } return null; }
/** * Get all the installed apps (of all types) for a user or page * * @param int $fbid id of user or page * @return array -- broken down by type of install * */ function id_get_installed_apps_all_types($uid) { global $data_conn, $installed_apps_types; if (isset($installed_apps_types[$uid])) { return $installed_apps_types[$uid]; } if ($data_conn) { $sql = "SELECT * FROM app_perms WHERE user_id=%d"; $app_arr = array(); if ($ret = queryf($data_conn, $sql, $uid)) { while ($row = mysql_fetch_assoc($ret)) { $app_arr[$row['application_id']] = $row; } } $profile_apps = array(); $installed_apps = array(); $authorized_apps = array(); foreach ($app_arr as $app_id => $app_data) { if ($app_data['installed']) { $installed[$app_id] = 1; } if ($app_data['authorized']) { $authorized[$app_id] = 1; } if ($app_data['installed_to_profile']) { $installed_to_profile[$app_id] = 1; } } // FBOPEN:NOTE - Feel free to add columns, e.g. // installed_to_minideed, installed_to_wap, etc. // Here for simplicity we will assume installed to profile and installed have some // other install applications. $installed_to_minifeed = $installed_to_feed = $installed; $installed_profile_actions = $installed_to_profile; return array('authorized' => $authorized, 'installed' => $installed, 'profile_apps' => $installed_to_profile, 'feed_apps' => $installed_to_feed, 'minifeed_apps' => $installed_to_minifeed, 'profile_actions_apps' => $installed_profile_actions); } return null; }
/** * removes an affiliation for a user or object in three places: the home db * for the id, and the home db for the network, the groups network editor * * @param int the user or object in question * @param int the network they are becoming un-affiliated with * @param bool if this is an account deactivation don't disable the * network assocs, they will get disabled on their own */ function remove_affiliation_link($userid, $network_key, $is_deactivate = false) { // 1. remove it from the user's db $conn_id_w = id_get_conn($userid, 'w'); $conn_network_w = network_get_conn($network_key, 'w'); $sql_remove = 'DELETE FROM affiliations WHERE id = %d AND network_key = %d'; $cachekeys = affiliation_get_cachekeys_for_add_remove($userid, $network_key); queryf_memcache($conn_id_w, $cachekeys, $sql_remove, $userid, $network_key); // 2. remove it from the network's db // unnecessary if a user's home db is the same as the network's if (id_to_db($userid) != network_to_db($network_key)) { queryf($conn_network_w, $sql_remove, $userid, $network_key); } hook_remove_affiliation($userid, $network_key); // 3. remove a group association as we transition over to groups // for deactivations we don't want to delete the group assocs as these // will be handled by the assoc deactivation code if (fbid_in_uid_range($userid) && !$is_deactivate) { if ($fbid = network_get_fbid($network_key)) { $viewer_context = ViewerContext::newAllPowerfulViewerContext(); $profile = fbobj_get_profile($fbid); if (group_is_managed_tribe($fbid, $profile)) { id(new EntTribeEditor($viewer_context, $fbid))->removeMember($userid); } else { if (group_is_network($fbid, $profile)) { id(new EntNetworkEditor($viewer_context, $network_key, $fbid))->removeMember($userid); } else { FBLogger('networks')->mustfix('Trying to add member to network with wrong version type'); } } } else { if (extract_network_type($network_key) != $GLOBALS['TYPE_GEO']) { FBLogger('networks')->mustfix('Failed to retrieve network FBID for key: %s', $network_key); } } } }
/** * Binds an auth_token with a session_key in the the database. Only * called for desktop apps. * * @param int $application_id object ID of application * @param string $auth_token Hex string of auth_token * @param string $session_key session_key with which to bind * @return true if successfully updated in db, false otherwise */ function _api_authtoken_update($application_id, $auth_token, $session_key) { global $data_conn; if ($data_conn) { // The only case where the given (app_id, auth_token) pair doesn't // exist in the DB is when two login requests with the same app_id // and auth_token (which apps shouldn't be doing anyway) arrive // simultaneously, *and* a getSession call comes in before one of // the login attempts completes. This is extremely rare (and we // probably want to know about it), so a login failure is okay. $sql = 'UPDATE auth_token SET session_key=%s WHERE application_id=%s AND auth_token=%s'; if (!($ret = queryf($data_conn, $sql, $session_key, $application_id, $auth_token))) { error_log("Failed to bind session_key: {$session_key} with auth_token : {$auth_token} for app" . " {$application}"); return null; } return true; } return null; }
function save() { $ret = queryf("INSERT INTO runs (username, date, miles, route) VALUES (%s, %s, %s, %s)", $this->username, $this->date, $this->miles, $this->route); return (bool) $ret; }
function getRuns() { if ($this->runs === null) { $ret = queryf('SELECT * FROM runs WHERE username = %s ORDER BY date DESC LIMIT %d', $this->username, MAX_DISPLAY_RUNS); if (!$ret) { return null; } $runs = array(); while ($row = mysql_fetch_assoc($ret)) { $run = new Run($this, $row); $runs[] = $run; } } $this->runs = $runs; return $this->runs; }
function profile_app_set_fbml($profile_id, $app_id, $fbml, $profile_action = null, $mobile_profile = null) { global $data_conn; if ($data_conn) { $sql = 'INSERT INTO profile_fbml ' . '(profile_id, app_id, fbml) ' . 'VALUES (%d, %d, %s)' . 'ON DUPLICATE KEY UPDATE fbml = %s'; if ($ret = queryf($data_conn, $sql, $profile_id, $app_id, $fbml, $fbml)) { return true; } } return false; }
function application_dbget_info($app_id) { global $data_conn; $sql = "SELECT * FROM application WHERE application_id=%d"; if ($data_conn) { if ($ret = queryf($data_conn, $sql, $app_id)) { if ($row = mysql_fetch_assoc($ret)) { return $row; } } } return null; //failure }