function privatesquare_checkins_create($checkin)
{
    $user = users_get_by_id($checkin['user_id']);
    $cluster_id = $user['cluster_id'];
    $checkin['id'] = dbtickets_create(64);
    if (!isset($checkin['created'])) {
        $checkin['created'] = time();
    }
    $insert = array();
    foreach ($checkin as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'PrivatesquareCheckins', $insert);
    if ($rsp['ok']) {
        $rsp['checkin'] = $checkin;
    }
    return $rsp;
}
Esempio n. 2
0
function api_keys_create(&$user)
{
    $id = dbtickets_create(64);
    $key = api_keys_generate_key();
    $secret = random_string(64);
    $now = time();
    $key_row = array('id' => $id, 'user_id' => $user['id'], 'app_key' => $key, 'app_secret' => $secret, 'created' => $now);
    # TO DO: callbacks and other stuff (what?)
    $insert = array();
    foreach ($key_row as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert('ApiKeys', $insert);
    if ($rsp['ok']) {
        $rsp['key'] = $key_row;
    }
    return $rsp;
}
Esempio n. 3
0
function sheets_create_sheet(&$user, $more = array())
{
    $sheet_id = dbtickets_create(32);
    if (!$sheet_id) {
        return array('ok' => 0, 'error' => 'Ticket server failed');
    }
    $now = time();
    $sheet = array('user_id' => $user['id'], 'created' => $now, 'last_modified' => $now, 'id' => $sheet_id, 'simplified' => $more['simplified']);
    $optional = array('label', 'mime_type');
    foreach ($optional as $o) {
        if (isset($more[$o])) {
            $sheet[$o] = $more[$o];
        }
    }
    $insert = array();
    foreach ($sheet as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($user['cluster_id'], 'Sheets', $insert);
    if (!$rsp['ok']) {
        return null;
    }
    #
    # Store in the lookup table
    #
    $lookup = array('sheet_id' => AddSlashes($sheet_id), 'user_id' => AddSlashes($user['id']), 'created' => AddSlashes($now), 'fingerprint' => AddSlashes($more['fingerprint']));
    $lookup_rsp = sheets_lookup_create($lookup);
    if (!$lookup_rsp['ok']) {
        # What ?
    }
    #
    # Okay!
    #
    sheets_load_details($sheet, $user['id']);
    $rsp['sheet'] = $sheet;
    return $rsp;
}
Esempio n. 4
0
function api_keys_create($user_id, $title, $description, $callback = '')
{
    $user = users_get_by_id($user_id);
    $id = dbtickets_create(64);
    $role_map = api_keys_roles_map('string keys');
    $role_id = $role_map['general'];
    $key = api_keys_generate_key();
    $secret = random_string(64);
    $now = time();
    $key_row = array('id' => $id, 'user_id' => $user['id'], 'api_key' => $key, 'app_secret' => $secret, 'created' => $now, 'last_modified' => $now, 'app_title' => $title, 'app_description' => $description, 'app_callback' => $callback);
    # TO DO: callbacks and other stuff (what?)
    $insert = array();
    foreach ($key_row as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert('ApiKeys', $insert);
    if ($rsp['ok']) {
        $rsp['key'] = $key_row;
    }
    return $rsp;
}
function api_oauth2_access_tokens_create_site_token($user = null)
{
    $site_key = api_keys_fetch_site_key();
    $id = dbtickets_create(64);
    $user_id = $user ? $user['id'] : 0;
    $token = api_oauth2_access_tokens_generate_token();
    $ttl = $user ? $GLOBALS['cfg']['api_site_tokens_user_ttl'] : $GLOBALS['cfg']['api_site_tokens_ttl'];
    $now = time();
    $expires = $now + $ttl;
    $perms_map = api_oauth2_access_tokens_permissions_map('string keys');
    $perms = $user_id ? $perms_map['write'] : $perms_map['login'];
    $row = array('id' => $id, 'perms' => $perms, 'api_key_id' => $site_key['id'], 'api_key_role_id' => $site_key['role_id'], 'user_id' => $user_id, 'access_token' => $token, 'created' => $now, 'last_modified' => $now, 'expires' => $expires);
    $insert = array();
    foreach ($row as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert('OAuth2AccessTokens', $insert);
    if ($rsp['ok']) {
        $rsp['token'] = $row;
    }
    return $rsp;
}
function flickr_push_subscriptions_create_subscription($subscription)
{
    $user = users_get_by_id($subscription['user_id']);
    $cluster_id = $user['cluster_id'];
    $secret_url = flickr_push_subscriptions_generate_secret_url();
    if (!$secret_url) {
        return array('ok' => 0, 'error' => 'Failed to generate secret URL');
    }
    $token = random_string(32);
    $subscription['id'] = dbtickets_create();
    $subscription['secret_url'] = $secret_url;
    $subscription['verify_token'] = $token;
    $subscription['created'] = time();
    $insert = array();
    foreach ($subscription as $k => $v) {
        # quick and dirty hack... unsure
        if ($k == 'topic_args') {
            $v = json_encode($v);
        }
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'FlickrPushSubscriptions', $insert);
    if ($rsp['ok']) {
        $rsp['subscription'] = $subscription;
        $cache_key = "flickr_push_subscriptions_for_user_{$user['id']}";
        cache_unset($cache_key);
    }
    return $rsp;
}
Esempio n. 7
0
function dots_create_dot(&$user, &$sheet, &$data, $more = array())
{
    # if we've gotten here via lib_uploads then
    # we will have already done validation.
    if (!$more['skip_validation']) {
        $rsp = dots_ensure_valid_data($row);
        if (!$rsp['ok']) {
            return $rsp;
        }
    }
    #
    $id = dbtickets_create(64);
    if (!$id) {
        return array('ok' => 0, 'error' => 'Ticket server failed');
    }
    #
    # Assign basic geo bits - keep track of stuff that has
    # been derived so that we can flag them accordingly in
    # the DotsExtras table.
    #
    list($data, $derived) = dots_derive_location_data($data);
    # Note that we return $derived with the response below
    # (assuming everything else works) and check for any errors
    # out of band, read: the _import_dots function (20110311/straup)
    #
    # creation date for the point (different from import date)
    # should this be stored/flagged as an extra?
    #
    $now = time();
    if ($created = $data['created']) {
        #
        # Because intval("2010-09-23T00:18:55Z") returns '2010' ...
        # Because is_numeric(20101029154025.000) returns true ...
        # Because strtotime(time()) returns false ...
        # BECAUSE GOD HATES YOU ...
        #
        $created = preg_match("/^\\d+\$/", $created) ? $created : strtotime($created);
        # if ! $created then reassign $now ?
        # Now convert everything back in to a datetime string
        if ($created) {
            $data['created'] = gmdate('Y-m-d H:i:s', $created);
        }
    } else {
        $data['created'] = gmdate('Y-m-d H:i:s', $now);
    }
    #
    # permissions
    #
    $perms_map = dots_permissions_map('string keys');
    $perms = $perms_map['public'];
    if ($data['perms'] == 'private' || $more['mark_all_private']) {
        $perms = $perms_map['private'];
    }
    #
    # Go! Or rather... start!
    #
    $dot = array('id' => $id, 'user_id' => $user['id'], 'sheet_id' => $sheet['id'], 'perms' => $perms);
    # Always store created date in the user Sheets table; it's
    # not clear how this relates/works with the dots extras
    # stuff yet (20101210/straup)
    $to_denormalize = array('created');
    foreach ($to_denormalize as $key) {
        if (isset($data[$key]) && !empty($data[$key])) {
            $dot[$key] = $data[$key];
        }
    }
    # Please to write me: A discussion on the relationship between
    # details, extras, 'indexed' and search. (20101213/straup)
    #
    # Dots extras (as in: extra things you can search for)
    #
    $details = array();
    $extras = array();
    if ($GLOBALS['cfg']['enable_feature_dots_indexing']) {
        $index_on = array();
        if ($GLOBALS['cfg']['dots_indexing_index_all']) {
            $tmp = array();
            $skip = array('latitude', 'longitude', 'created', 'title_internal');
            foreach (array_keys($data) as $f) {
                if (!in_array($f, $skip)) {
                    $tmp[] = $f;
                }
            }
        } else {
            $tmp = explode(",", $more['dots_index_on'], $GLOBALS['cfg']['dots_indexing_max_cols']);
        }
        #
        foreach ($tmp as $field) {
            $field = trim($field);
            if (!isset($data[$field])) {
                continue;
            }
            $extras[] = array('dot_id' => $id, 'sheet_id' => $sheet['id'], 'user_id' => $user['id'], 'name' => $field, 'value' => $data[$field]);
            $index_on[] = AddSlashes($field);
        }
        $dot['index_on'] = implode(",", $index_on);
    }
    #
    # Store any remaining fields in a big old JSON blob
    #
    foreach (array_keys($data) as $label) {
        $label = filter_strict(trim($label));
        if (!$label) {
            continue;
        }
        $value = $data[$label];
        $value = filter_strict(trim($value));
        if (!$value) {
            continue;
        }
        $ns = null;
        $pred = $label;
        if (strpos($label, ':')) {
            list($ns, $pred) = explode(':', $label, 2);
        }
        $detail = array('namespace' => $ns, 'label' => $pred, 'value' => $data[$label]);
        if (isset($derived[$label])) {
            $extra['derived_from'] = $derived[$label];
        }
        if (!is_array($details[$label])) {
            $details[$label] = array();
        }
        $details[$label][] = $detail;
    }
    $dot['details_json'] = json_encode($details);
    #
    # Look, we are FINALLY NOW creating the dot
    #
    $insert = array();
    foreach ($dot as $key => $value) {
        $insert[$key] = AddSlashes($value);
    }
    $rsp = db_insert_users($user['cluster_id'], 'Dots', $insert);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $dot['details'] = $details;
    #
    # Update the DotsLookup table
    #
    $lookup = array('dot_id' => $id, 'sheet_id' => $sheet['id'], 'user_id' => $user['id'], 'imported' => $now, 'last_modified' => $now);
    if ($more['buffer_lookup_inserts']) {
        $rsp['lookup'] = $lookup;
    } else {
        $lookup_rsp = dots_lookup_create($lookup);
        if (!$lookup_rsp['ok']) {
            # What then...
        }
    }
    #
    # Now the searching (first the basics then any 'extras' specific to this dot)
    #
    $search = array('dot_id' => $id, 'sheet_id' => $sheet['id'], 'user_id' => $user['id'], 'imported' => $now, 'created' => $data['created'], 'perms' => $perms, 'geohash' => $data['geohash'], 'latitude' => $data['latitude'], 'longitude' => $data['longitude']);
    if ($more['buffer_search_inserts']) {
        $rsp['search'] =& $search;
    } else {
        $search_rsp = dots_search_add_dot($search);
        if (!$search_rsp['ok']) {
            # What then...
        }
    }
    # extras
    if ($more['buffer_extras_inserts']) {
        $rsp['extras'] = $extras;
    } else {
        $extras_rsp = dots_search_extras_add_lots_of_extras($extras);
        if (!$extras_rsp['ok']) {
            # What then...
        }
    }
    #
    # Happy happy
    #
    $rsp['dot'] =& $dot;
    $rsp['derived'] =& $derived;
    return $rsp;
}