function topic($company_sfnid, $topic_id)
{
    $url = $topic_id;
    $feed_raw = get_url($url, false);
    if (!$feed_raw) {
        throw new Exception("Failed to load topic feed at {$url}.");
    }
    try {
        $topic_feed = new XML_Feed_Parser($feed_raw);
        if (!$topic_feed) {
            throw new Exception("Invalid feed at {$url}");
        }
    } catch (XML_Feed_Parser_Exception $e) {
        invalidate_http_cache($url);
        throw new Exception("Invalid feed at {$url}");
    }
    # Add stuff to the raw feed data using fix_atom_entry
    $items = array();
    foreach ($topic_feed as $entry) {
        $item = fix_atom_entry($entry, 'reply');
        array_push($items, $item);
    }
    # Collect information about the participants in this topic
    $authors = array();
    $employees = array();
    foreach ($items as $item) {
        $authors[$item['author']['uri']]++;
        list($role, $role_name) = get_person_role($company_sfnid, $item['author']['uri']);
        if ($role) {
            $employees[$item['author']['uri']] = $item['author'];
            $employees[$item['author']['uri']]['role'] = $role;
        }
    }
    $official_reps = array();
    foreach ($employees as $emp) {
        $emp_data = get_person($emp['uri']);
        $emp = superimpose($emp, $emp_data);
        if ($emp['role'] == 'company_rep' || $emp['role'] == 'company_admin') {
            array_push($official_reps, $emp);
        }
    }
    $particip = array('people' => count($authors), 'employees' => count($employees), 'official_reps' => $official_reps, 'count_official_reps' => count($official_reps));
    return array('replies' => $items, 'particip' => $particip, 'tags' => $tags);
}
Example #2
0
    $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());
    $smarty->display('error.t');
}