Exemplo n.º 1
0
try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $reply_id = request_param('reply_id');
    $topic_id = request_param('topic_id');
    $creds = $sprink->current_user_session();
    if (!$creds) {
        $target_page = $preview_after_login ? 'topic.php' : 'handle-star.php';
        $args = 'reply_id=' . urlencode($reply_id) . '&topic_id=' . urlencode($topic_id);
        redirect('user-login.php?return=' . urlencode($target_page . '?' . $args));
        exit(0);
    }
    $POST_URL = $sprink->api_url($reply_id . "/stars");
    # FIXME use @rel=stars link from feed
    $params = array('reply_id' => $reply_id);
    $req = $sprink->oauthed_request('POST', $POST_URL, $creds, null, $params);
    if (400 == ($responseCode = $req->getResponseCode())) {
        # TBD: refine this to read HTTP reason
        redirect('topic.php?no_self_star=1&id=' . $topic_id);
        exit(0);
    }
    if (201 != $responseCode) {
        error("Failed starring with POST to {$POST_URL}: " . $req->getResponseBody());
        die("API Error {$responseCode} starring reply {$reply_id}.");
    }
    $topic_url = request_param('topic_id');
    invalidate_http_cache($topic_url);
    redirect('topic.php?id=' . urlencode($topic_url));
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
Exemplo n.º 2
0
        redirect('submit.php?' . $args . '&errs[]=subject');
        exit(0);
    }
    if (!$products) {
        $products = array();
    }
    $products_commasep = join(',', $products);
    $sprink = new Sprinkles();
    $creds = $sprink->current_user_session();
    if (!$creds) {
        $target_page = $preview_after_login ? 'submit.php' : 'handle-submit.php';
        redirect('user-login.php?return=' . urlencode($target_page . '?' . $args));
        exit(0);
    }
    $POST_URL = $api_root . 'companies/' . $sprink->company_sfnid . '/topics';
    $req = $sprink->oauthed_request('POST', $POST_URL, $creds, null, array('topic[subject]' => $subject, 'topic[additional_detail]' => $details, 'topic[style]' => $style, 'topic[keywords]' => $tags, 'topic[products]' => $products_commasep, 'topic[emotitag][face]' => $face, 'topic[emotitag][feeling]' => $emotion));
    $response_body = $req->getResponseBody();
    try {
        $topic_feed = new XML_Feed_Parser($response_body);
    } catch (Exception $e) {
        error("Failed to post new topic; response was: " . $req->getResponseCode() . ", body: " . $response_body);
        throw new Exception($response_body);
    }
    if ($topic_feed->id()) {
        # FIXME: better error checking here.
        redirect('topic.php?id=' . $topic_feed->id());
        exit(0);
    } else {
        print "An error occured";
    }
} catch (Exception $e) {
Exemplo n.º 3
0
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $topic_id = request_param('topic_id');
    $reply_url = request_param('replies_url');
    if (!($content = request_param('content'))) {
        redirect('topic.php?blank_reply=1&id=' . urlencode($topic_id));
        exit(0);
    }
    $params = array('reply[content]' => $content);
    if ($parent_id = request_param('parent_id')) {
        $params['reply[parent_id]'] = $parent_id;
    }
    $creds = $sprink->current_user_session();
    if (!$creds) {
        die("Not logged in! (FIXME)");
    }
    $req = $sprink->oauthed_request('POST', $reply_url, $creds, null, $params);
    if (201 != ($responseCode = $req->getResponseCode())) {
        die("API Error {$responseCode} replying to {$topic_id}.");
    }
    $topic_url = $topic_id;
    invalidate_http_cache($topic_url);
    redirect('topic.php?id=' . urlencode($topic_id));
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Exemplo n.º 4
0
<?php

try {
    # POST to /topics/$sfn_id/me_toos
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $sfn_id = request_param('sfn_id');
    $creds = $sprink->current_user_session();
    if (!$creds) {
        $target_page = $preview_after_login ? 'topic.php' : 'handle-me-too.php';
        $args = 'sfn_id=' . urlencode($sfn_id);
        redirect('user-login.php?return=' . urlencode($target_page . '?' . $args));
        exit(0);
    }
    $POST_URL = $sprink->api_url("topics/" . $sfn_id . "/me_toos");
    $req = $sprink->oauthed_request('POST', $POST_URL, $creds, null, array("askdjnaksjdbas" => "aksjhdaksjdnaksjdnka"));
    $responseCode = $req->getResponseCode();
    if (0 == $responseCode) {
        die("Timeout accessing the API, while posting to {$POST_URL}.");
        # FIXME: recover for user
    } else {
        if (400 == $responseCode) {
            redirect('topic.php?sfn_id=' . $sfn_id . '&me_too_failed=true');
            exit(0);
        } else {
            if (201 != $responseCode) {
                die("API Error {$responseCode} me-tooing topic {$sfn_id}.");
            }
        }
    }
    $topic_url = $sprink->api_url("topics/" . $sfn_id);