예제 #1
0
function handle_claim($type, $from, $data, $res)
{
    global $connection;
    $from->need_level("member");
    validate_required($data, 'piece_index');
    $piece_index = $data['piece_index'];
    $piece_id = _find_piece_id($from, $piece_index);
    $result = pg_query($connection, 'SELECT COUNT(*) FROM claims WHERE author = ' . $from->user_id() . ' and piece = ' . $piece_id);
    $num = intval(pg_fetch_result($result, 0, 0));
    if ($num != 0) {
        throw new Exception("You have such claim already.");
    }
    // TODO: Protection from meaningless claims (for pieces without owner etc.)
    $result = pg_query($connection, 'INSERT INTO claims VALUES(DEFAULT,' . $from->user_id() . ',' . $piece_id . ',DEFAULT) RETURNING id');
    $claim_id = intval(pg_fetch_result($result, 0, 0));
    $msg = array('claim_add', array('claim_id' => $claim_id, 'vote_balance' => 0, 'piece_index' => $piece_index, 'owner' => $from->nick()));
    $res->to_pie($from, $msg);
}
예제 #2
0
function handle_piece_comment($type, $from, $data, $res)
{
    global $connection;
    $from->need_level('member');
    validate_required($data, 'piece_index', 'comment');
    $piece_index = $data['piece_index'];
    $piece_id = _find_piece_id($from, $piece_index);
    $comment = htmlspecialchars(trim(preg_replace('/\\s+/', ' ', $data['comment'])));
    $result = pg_query($connection, 'INSERT INTO pieces_comments VALUES(DEFAULT,' . $piece_id . ',' . $from->user_id() . ',\'' . pg_escape_string($comment) . '\',DEFAULT, \'comment\') RETURNING timestamp');
    $timestamp = pg_fetch_result($result, 0, 0);
    $res->to_sender(info_msg('Comment added to piece #' . $piece_id . '.', $from->nick()));
    $res->to_pie($from, array('piece_comment', array('piece_index' => $piece_index, 'author' => $from->nick(), 'message' => $comment, 'type' => 'comment', 'date' => $timestamp)));
    _update_pie_timestamp($from, $connection);
}