function flickr_faves_add_fave(&$viewer, &$photo, $date_faved = 0)
{
    if (!$date_faved) {
        $date_faved = time();
    }
    $cluster_id = $viewer['cluster_id'];
    $fave = array('user_id' => $viewer['id'], 'photo_id' => $photo['id'], 'owner_id' => $photo['user_id'], 'date_faved' => $date_faved);
    $insert = array();
    foreach ($fave as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'FlickrFaves', $insert);
    if (!$rsp['ok'] && $rsp['error_code'] != 1062) {
        return $rsp;
    }
    # now update the photo owner side of things
    $owner = users_get_by_id($photo['user_id']);
    $cluster_id = $owner['cluster_id'];
    $fave = array('user_id' => $owner['id'], 'photo_id' => $photo['id'], 'viewer_id' => $viewer['id']);
    $insert = array();
    foreach ($fave as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'FlickrFavesUsers', $insert);
    if (!$rsp['ok'] && $rsp['error_code'] != 1062) {
        return $rsp;
    }
    # TO DO: index/update the photo in solr and insert $viewer['id']
    # into the faved_by column (20111123/straup)
    return okay();
}
function flickr_geobookmarks_add($bookmark)
{
    $user = users_get_by_id($bookmark['user_id']);
    $cluster_id = $user['cluster_id'];
    $insert = array();
    foreach ($bookmark as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'FlickrGeoBookmarks', $insert);
    if ($rsp['ok']) {
        $rsp['bookmark'] = $bookmark;
    }
    return $rsp;
}
function flickr_push_photos_record(&$user, $photo_data)
{
    $cluster = $user['cluster_id'];
    $photo_data['created'] = time();
    $insert = array();
    foreach ($photo_data as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster, 'FlickrPushPhotos', $insert);
    if ($rsp['ok']) {
        $rsp['photo'] = $photo_data;
    }
    return $rsp;
}
function flickr_contacts_add_contact($contact)
{
    $user = users_get_by_id($contact['user_id']);
    $cluster_id = $user['cluster_id'];
    $insert = array();
    foreach ($contact as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'FlickrContacts', $insert);
    # check for duplicate insert here
    if (!$rsp['ok']) {
        return null;
    }
    return $contact;
}
function flickr_photos_geo_corrections_create($correction)
{
    $user = users_get_by_id($correction['user_id']);
    if (!$user['id']) {
        return not_okay("Invalid user ID");
    }
    $cluster_id = $user['cluster_id'];
    $correction['created'] = time();
    $insert = array();
    foreach ($correction as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'FlickrPhotosGeoCorrections', $insert);
    if ($rsp['ok']) {
        $rsp['correction'] = $correction;
    }
    return $rsp;
}
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;
}
Example #7
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;
}
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;
}
Example #9
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;
}
function flickr_photos_add_photo($photo)
{
    $user = users_get_by_id($photo['user_id']);
    $cluster_id = $user['cluster_id'];
    $insert = array();
    foreach ($photo as $k => $v) {
        $insert[$k] = AddSlashes($v);
    }
    $rsp = db_insert_users($cluster_id, 'FlickrPhotos', $insert);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $rsp['photo'] = $photo;
    return $rsp;
}