<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $company_sfnid = request_param('company_sfnid');
    $oauth_consumer_key = request_param('oauth_consumer_key');
    $oauth_consumer_secret = request_param('oauth_consumer_secret');
    $sprinkles_root_url = request_param('sprinkles_root_url');
    if (!$oauth_consumer_key || !$oauth_consumer_secret) {
        redirect('admin-findsite.php?msg=missing_oauth' . '&company_sfnid=' . $company_sfnid . '&oauth_consumer_key=' . $oauth_consumer_key . '&oauth_consumer_secret=' . $oauth_consumer_secret . '&sprinkles_root_url=' . $sprinkles_root_url);
        exit;
    }
    if (!$sprinkles_root_url) {
        redirect('admin-findsite.php?msg=missing_sprinkles_root_url' . '&company_sfnid=' . $company_sfnid . '&oauth_consumer_key=' . $oauth_consumer_key . '&oauth_consumer_secret=' . $oauth_consumer_secret . '&sprinkles_root_url=' . $sprinkles_root_url);
        exit;
    }
    if (!$company_sfnid) {
        redirect('admin-findsite.php?msg=missing_company_sfnid' . '&company_sfnid=' . $company_sfnid . '&oauth_consumer_key=' . $oauth_consumer_key . '&oauth_consumer_secret=' . $oauth_consumer_secret . '&sprinkles_root_url=' . $sprinkles_root_url);
        exit;
    }
    $sprinkles_root_url = preg_replace('|[^/]*.php$|', '', $sprinkles_root_url);
    # Note: the naive regex you'd usee below doesn't work; pcre is not in fact
    # Perl-compatible in this case
    $sprinkles_root_url = preg_replace('|([^/])/*$|', '\\1/', $sprinkles_root_url);
    $result = $sprink->set_site_settings(array('company_id' => $company_sfnid, 'oauth_consumer_key' => $oauth_consumer_key, 'oauth_consumer_secret' => $oauth_consumer_secret, 'sprinkles_root_url' => $sprinkles_root_url));
    if (!$result) {
        die(mysql_error());
    }
    message($sprink->site_configured());
    redirect($sprink->authorize_url('admin.php?hooked=true', true));
Example #2
0
<?php

require_once 'Sprinkles.php';
$sprink = new Sprinkles();
if ($sprink->site_configured()) {
    redirect('helpstart.php');
} else {
    redirect('admin-findsite.php');
}
exit(0);
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $from = request_param('email');
    $from = preg_replace('/\\n.*$/', ' ', $from);
    # Sanitizes $from; it'll go verbatim in the SMTP headers
    $message = request_param('name') . ' reported a problem in the Get Satisfaction Instant On Help Center at ' . date('H:i:s T, Y/m/d') . '.' . "\n\n" . 'Summary: ' . request_param('summary') . "\n\n" . 'Details: ' . request_param('observed') . "\n\n" . 'I\'m ' . request_param('feeling');
    $subject = request_param('summary');
    $contact = $sprink->site_contact_info();
    $to = $contact['contact_email'];
    mail($to, $subject, $message, "From: {$from}");
    $name = request_param('name');
    redirect('contactus-success.php?name=' . urlencode($name));
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Example #4
0
 # $email_regex = "/[A-Za-z0-9.-]+@[A-Za-z0-9.-]+/";
 $email_regex = "/{$nonspecial_or_dot_regex}*@{$word_regex}(\\.{$word_regex})*/";
 # c.f. RFC 821 p. 30. Doesn't handle quoted local-parts, #number domain
 # segments or dotted-quad domain segments.
 ## Validation  | FIXME: not finished
 $bad_fields = array();
 $contact_email = request_param('contact_email');
 if (preg_match($email_regex, $contact_email)) {
     $contact_email = trim($contact_email);
 } else {
     array_push($bad_fields, 'contact_email');
 }
 $contact_phone = request_param('contact_phone');
 $contact_address = request_param('contact_address');
 # TBD: additional links
 $sprink = new Sprinkles();
 # TBD: this is expensive; cheapen!
 $active_username = $sprink->current_username();
 if (!$active_username) {
     redirect($sprink->authorize_url('admin.php', false));
     exit(0);
 }
 $existing_admin_users = $sprink->get_users();
 if (!$sprink->user_is_admin()) {
     redirect('error.php');
     exit(0);
 }
 sort($existing_admin_users);
 $admin_users_str = request_param('admin_users_str');
 $admin_users = preg_split('/,\\s*|\\s+/', $admin_users_str);
 if (!member($active_username, $admin_users)) {
<?php

try {
    require_once 'Sprinkles.php';
    require_once 'HTTP_Request_Oauth.php';
    $sprink = new Sprinkles();
    $return = request_param('return');
    $consumer_data = $sprink->oauth_consumer_data();
    if (!$consumer_data['key'] || !$consumer_data['secret']) {
        die("The OAuth consumer data was missing from the Instant-On Help " . "Center database! Perhaps something went wrong during installation " . "and setup.");
    }
    list($token, $secret) = get_oauth_request_token($consumer_data);
    if (!$token || !$secret) {
        error("Failed to fetch OAuth request token " . "(Result token: '{$token}'; Token secret: '{$token_secret}')");
        die("Failed to fetch OAuth request token from getsatisfaction.com.");
    }
    $result = insert_into('sessions', array('token' => $token, 'token_secret' => $secret));
    if (!$result) {
        die("Error inserting OAuth tokens into database.");
    }
    $first_login = request_param('first_login');
    $callback_url = $sprink->sprinkles_root_url() . 'handle-oauth-return.php?' . ($first_login ? 'first_login=true&' : '') . 'return=' . urlencode($return);
    redirect(oauth_authorization_url($token, $callback_url));
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Example #6
0
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $subject = request_param('subject');
    $details = request_param('details');
    $tags = request_param('tags');
    $emoticon = request_param('emoticon');
    $emotion = request_param('emotion');
    $style = request_param('style');
    $selected_products = request_param('product');
    if (!$selected_products) {
        $selected_products = array();
    }
    $validation_errors = request_param('errs');
    $suggested = $sprink->topics(array('query' => $subject, "limit" => $submit_suggestions));
    $suggested = $suggested['topics'];
    $top_tags = take(8, $sprink->tags($api_root . 'companies/' . $sprink->company_sfnid . '/tags?on=topics&sort=usage&limit=8'));
    switch ($style) {
        case 'question':
            $friendly_style = 'question';
            break;
        case 'idea':
            $friendly_style = 'idea';
            break;
        case 'problem':
            $friendly_style = 'problem';
            break;
        case 'talk':
            $friendly_style = 'discussion';
Example #7
0
<?php

require_once "Sprinkles.php";
require_once 'admin-fields.php';
$sprink = new Sprinkles();
$user = $sprink->current_user();
$username = $sprink->current_username();
if (!$username) {
    redirect($sprink->authorize_url('admin.php', false));
    exit(0);
}
$admin_users = $sprink->get_users();
if (!$sprink->user_is_admin()) {
    $sprink->add_std_hash_elems($smarty);
    $smarty->display('not-admin.t');
}
$company_hcard = $sprink->company_hcard();
$company_name = $company_hcard["fn"];
# TBD: fetch the site_settings row just once per request.
$sql = "select background_color, contact_email, contact_phone, " . "contact_address, logo_link, map_url, faq_type from site_settings";
$result = mysql_query($sql);
if (!$result) {
    die("Failed to fetch site settings from database (" . mysql_error() . ").");
}
$settings = mysql_fetch_assoc($result);
$smarty->assign('admin_users', $admin_users);
foreach ($fields as $i => $field) {
    if (request_param($field)) {
        $settings[$field] = request_param($field);
    }
}
Example #8
0
<?php

require_once "Sprinkles.php";
$sprink = new Sprinkles();
$page_num = request_param('page');
if (!$page_num) {
    $page_num = 0;
}
$topic_filters = array("limit" => $discuss_page_size, "page" => $page_num);
$filter_style = request_param('style');
if ($filter_style) {
    $topic_filters['style'] = $filter_style;
    $smarty->assign('style', $filter_style);
}
$filter_query = request_param('query');
if ($filter_query) {
    $topic_filters['query'] = $filter_query;
    $smarty->assign('query', $filter_query);
}
$topics = $sprink->topics($topic_filters);
$topic_count = $topics['totals']['this'];
// $sprink->resolve_authors($topics['topics']);
$smarty->assign('page_num', $page_num);
$smarty->assign('num_pages', ceil($topic_count / $discuss_page_size));
$smarty->assign('topics', $topics['topics']);
$smarty->assign('topic_count', $topic_count);
$smarty->assign('totals', $topics['totals']);
$sprink->add_std_hash_elems($smarty);
$smarty->display('results.t');
finish_request('results');
Example #9
0
<?php

header('Content-type: image/png');
require_once 'Sprinkles.php';
$sprink = new Sprinkles();
print $sprink->site_logo();
 if (!$result) {
     throw new Exception("Couldn't look up token {$request_token}; database error: " . mysql_error());
 }
 $cols = mysql_fetch_array($result);
 $request_token_secret = $cols[0];
 $sprink = new Sprinkles();
 $consumer_data = $sprink->oauth_consumer_data();
 list($token, $token_secret) = get_oauth_access_token($consumer_data, $request_token, $request_token_secret);
 if (!$token || !$token_secret) {
     throw new Exception("Getting OAuth access token from Get Satisfaction failed.");
 }
 $result = mysql_query("update sessions set token = '" . mysql_real_escape_string($token) . "', token_secret = '" . mysql_real_escape_string($token_secret) . "' where token = '" . mysql_real_escape_string($request_token) . "'");
 if (!$result) {
     throw new Exception("Failed to store auth tokens on oauth response");
 }
 $sprink = new Sprinkles();
 $sprink->open_session($token);
 if (!$sprink->site_configured() && request_param('first_login')) {
     $user = $sprink->current_user();
     if (!$user) {
         throw new Exception("Internal error: No current user just after opening session.");
     }
     $sprink->set_admin_users(array($user['canonical_name']));
     $result = $sprink->set_site_settings(array('configured' => 'Y'));
     if (!$result) {
         die(mysql_error());
     }
 }
 $return = request_param('return');
 if (!$return) {
     $return = 'helpstart.php';
Example #11
0
<?php

try {
    require_once "Sprinkles.php";
    $sprink = new Sprinkles();
    $return = request_param('return');
    $smarty->assign('return', $return);
    # FIXME: check for nastiness?
    redirect($sprink->authorize_url($return, false));
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $sprink->close_session();
    $return = request_param('return');
    if (!$return) {
        $return = 'helpstart.php';
    }
    redirect($return);
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Example #13
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');
}
Example #14
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');
}
Example #15
0
<?php

require_once 'Sprinkles.php';
try {
    $sprink = new Sprinkles();
    $sprink->add_std_hash_elems($smarty);
    $smarty->assign('sprinkles_root_url', $sprink->sprinkles_root_url());
    $smarty->assign('error_msg', request_param('msg'));
} catch (Exception $e) {
    $smarty->assign('background_color', '#86fff6');
}
$smarty->display('error.t');
Example #16
0
<?php

try {
    require_once "Sprinkles.php";
    $sprink = new Sprinkles();
    $message = $_GET['wrong_password'] ? 'The username and password you entered did not match. Please try again.' : '';
    $smarty->assign('site_configured', $sprink->site_configured());
    $smarty->assign('message', $message);
    $smarty->assign('current_url', 'admin.php');
    $sprink->add_std_hash_elems($smarty);
    $smarty->display('admin-login.t');
    finish_request('admin-login');
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Example #17
0
<?php

try {
    require_once "Sprinkles.php";
    $sprink = new Sprinkles();
    $faqs = $sprink->topics(array('frequently_asked' => 1, 'style' => 'question'));
    $smarty->assign('entries', $entries);
    $smarty->assign('faqs', $faqs['topics']);
    $smarty->assign('current_url', 'faq.php');
    $sprink->add_std_hash_elems($smarty);
    $smarty->display('faq.t');
    finish_request('faq');
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Example #18
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);
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $smarty->assign('complainant_name', request_param('name'));
    $sprink->add_std_hash_elems($smarty);
    $smarty->display('contactus-success.t');
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Example #20
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']);
Example #21
0
<?php

try {
    require_once "Sprinkles.php";
    $sprink = new Sprinkles();
    $topic_id = request_param('id');
    if (!$topic_id) {
        die("Internal error: expected id parameter.");
    }
    $items = $sprink->topic($topic_id);
    if (!$items) {
        die("Internal error: Empty topic {$topic_id}.");
    }
    $topic_head = array_shift($items['replies']);
    $smarty->assign('topic_head', $topic_head);
    $smarty->assign('topic_id', $topic_id);
    $smarty->assign('body_css_id', 'share-topic');
    $smarty->assign('current_url', 'share-topic.php?id=' . $topic_id);
    $sprink->add_std_hash_elems($smarty);
    $smarty->display('share-topic.t');
    finish_request('share-topic');
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Example #22
0
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    if ($sprink->site_configured()) {
        redirect('helpstart.php');
        exit(0);
    }
    $defaults = $sprink->findsite_data();
    $sprinkles_root_url = request_param('sprinkles_root_url');
    if (!$sprinkles_root_url) {
        $sprinkles_root_url = $defaults[sprinkles_root_url];
    }
    if (!$sprinkles_root_url) {
        $uri = 'http' . ($_SERVER['HTTPS'] ? 's' : null) . '://' . $_SERVER['HTTP_HOST'];
        $uri .= $_SERVER['SERVER_PORT'] == '80' ? '' : ":" . $_SERVER['SERVER_PORT'];
        $uri .= $_SERVER['REQUEST_URI'];
        $sprinkles_root_url = $uri;
    }
    $smarty->assign('sprinkles_root_url', $sprinkles_root_url);
    $oauth_consumer_key = request_param('oauth_consumer_key');
    if (!$oauth_consumer_key) {
        $oauth_consumer_key = $defaults['oauth_consumer_key'];
    }
    $oauth_consumer_secret = request_param('oauth_consumer_secret');
    if (!$oauth_consumer_secret) {
        $oauth_consumer_secret = $defaults['oauth_consumer_secret'];
    }
    $company_sfnid = request_param('company_sfnid');
    if (!$company_sfnid) {
Example #23
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);
<?php

require_once 'Sprinkles.php';
$query = request_param('query');
$mode = request_param('mode');
if (!$mode) {
    $mode = 'simple';
}
$sprink = new Sprinkles();
$suggested = $sprink->topics(array('query' => $query, "limit" => 3));
$topics = $suggested['topics'];
if ($mode == 'fancy') {
    $sprink->resolve_authors($topics);
}
$smarty->assign('suggested_topics', $topics);
$smarty->assign('mode', $mode);
$smarty->display('topic-suggestions.t');
finish_request('topic-suggestions');
Example #25
0
 $emotion = request_param('emotion');
 $style = request_param('style');
 $products = request_param('products');
 $args = 'subject=' . urlencode($subject) . '&details=' . urlencode($details) . '&tags=' . urlencode($tags) . '&emoticon=' . urlencode($face) . '&emotion=' . urlencode($emotion) . '&style=' . urlencode($style);
 foreach ($products as $product) {
     $args .= '&product[]=' . urlencode($product);
 }
 if ($subject == '') {
     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);
 }
Example #26
0
<?php

try {
    require_once "Sprinkles.php";
    $sprink = new Sprinkles();
    $top_topic_tags = take(20, $sprink->tags($api_root . 'companies/' . $sprink->company_sfnid . '/tags?on=topics&sort=usage&limit=20'));
    $chunk = intval(ceil(sizeof($top_topic_tags) / 4));
    $top_topic_tags = array_chunk($top_topic_tags, $chunk);
    $entries = $sprink->topics(array("limit" => $helpstart_topic_count, "sort" => 'recently_active'));
    // $sprink->resolve_authors($entries['topics']);
    $smarty->assign('top_topic_tags', $top_topic_tags);
    $smarty->assign('entries', $entries['topics']);
    # Standard stash items
    $smarty->assign('products', $sprink->product_list());
    $smarty->assign('current_url', 'helpstart.php');
    $smarty->assign('totals', $entries['totals']);
    $smarty->assign('filter_style', 'question');
    $sprink->add_std_hash_elems($smarty);
    $smarty->display('helpstart.t');
    finish_request('helpstart');
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->assign('error_msg', $e->getMessage());
    $smarty->display('error.t');
}
<?php

try {
    require_once 'Sprinkles.php';
    $sprink = new Sprinkles();
    $id = request_param('id');
    $topic = $sprink->topic($id);
    $topic = $topic['replies'][0];
    $from = request_param('from_email');
    $from = preg_replace('/\\n.*$/', ' ', $from);
    # Sanitizes $from; it'll go verbatim in the SMTP headers
    $user_fn = request_param('sender_name');
    if (!$user_fn) {
        $user = $sprink->current_user();
        $user_fn = $user['fn'];
    }
    $personal_message = request_param('personal_message');
    $message = $user_fn . " thinks you might be interested in this discussion from Get Satisfaction:\n\n" . "\"" . $topic['title'] . "\n\n" . $topic['content'] . "\"\n\n" . $topic['author']['fn'] . " asked this on " . $topic['published_formatted'] . (!$personal_message ? '' : "\n\n" . $user_fn . " says: \n\n" . $personal_message);
    $subject = "'" . $topic['title'] . "' on Get Satisfaction!";
    $to = request_param('to_email');
    # TBD: handle more than one address
    if (preg_match('/,/', $to)) {
        die("Sharing with more than one recipient is not yet implemented. :-(");
    }
    # FIXME: not graceful.
    $result = mail($to, $subject, $message, "From: {$from}");
    if ($result) {
        redirect('topic.php?id=' . $id . '&shared_with=' . urlencode($to));
    } else {
        redirect('topic.php?id=' . $id . '&share_failed=true');
    }