예제 #1
0
<?php

try {
    require_once "Sprinkles.php";
    $sprink = new Sprinkles();
    $topic_id = request_param('id');
    if (!$topic_id) {
        $topic_id = request_param('topic_id');
    }
    if (!$topic_id) {
        $sfn_id = request_param('sfn_id');
        $topic_id = $sprink->api_url("topics/" . $sfn_id);
    }
    if (!$topic_id) {
        die("Internal error: expected id parameter.");
    }
    $topic = $sprink->topic($topic_id);
    $topic_head = array_shift($topic['replies']);
    $reply_count = count($topic['replies']);
    $topic['replies'] = thread_items($topic['replies'], $topic_head['id']);
    $toplevel_reply_count = count($topic['replies']);
    $topic['replies'] = flatten_threads($topic['replies']);
    $sprink->resolve_author($topic_head);
    $sprink->resolve_authors($topic['replies']);
    $related_topics = $sprink->topics(array('related' => $topic_id));
    list($company_related_topics, $noncompany_related_topics) = $sprink->company_partition($related_topics['topics']);
    $noncompany_related_topics = take($related_topics_count, $noncompany_related_topics);
    resolve_companies($noncompany_related_topics);
    list($company_promoted, $star_promoted) = filter_promoted($topic['replies']);
    $smarty->assign('topic_head', $topic_head);
    $smarty->assign('replies', $topic['replies']);
예제 #2
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);
예제 #3
0
<?php

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);
예제 #4
0
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $type = request_param('type');
    if ($type != 'topic' && $type != 'reply') {
        die("unknown type '{$type}' while flagging");
    }
    $POST_URL = $type == 'topic' ? $sprink->api_url("flagged/topics") : ($type == 'reply' ? $sprink->api_url("flagged/replies") : '');
    $id = request_param('id');
    $params = $type == 'topic' ? array('topic_id' => $id) : ($type == 'reply' ? array('reply_id' => $id) : '');
    $creds = $sprink->current_user_session();
    if (!$creds) {
        die("Not logged in");
    }
    # FIXME
    $req = $sprink->oauthed_request('POST', $POST_URL, $creds, null, $params);
    if (201 != ($responseCode = $req->getResponseCode())) {
        die("API Error {$responseCode} flagging item {$type} {$id}.");
    }
    redirect('topic.php?id=' . request_param('topic_id') . ($type == 'topic' ? '&flagged_topic=' : ($type == 'reply' ? '&flagged_reply=' : '')) . $id);
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}