Example #1
0
    public function __construct($page, $account)
    {
        $this->id = $page;
        $this->valid = false;
        $sql = GetSQL();
        $result = $sql->safequery('SELECT Topics.account, state, goods, bads, time, content, vote FROM Topics 
			LEFT JOIN TopicVotes ON (topicid=id AND TopicVotes.account=' . $account->id . ') 
			WHERE id=' . $page);
        $row = $result->fetch_assoc();
        if ($row === NULL) {
            return;
        }
        $state = $row['state'];
        if ($state == TopicStates::Live || $state == TopicStates::Composing) {
            if ($page != $account->page) {
                return;
            }
        }
        $this->state = $state;
        $this->accountid = $row['account'];
        $this->content = $row['content'];
        $this->goods = $row['goods'];
        $this->bads = $row['bads'];
        $this->vote = is_null($row['vote']) ? null : ($row['vote'] == 1 ? TRUE : FALSE);
        $this->time = $row['time'];
        $this->valid = true;
    }
Example #2
0
    $text = $_POST['text'];
    $text = str_replace('[[br]]', "\n", $text);
    // convert marked newlines to real newlines
    $text = trim($text);
    // trim whitespace
    if ($text == "") {
        exit('empty');
    }
    // error if empty
    $text = htmlspecialchars($text);
    // escape html chars
    $text = nl2br($text, false);
    // convert newlines to html
    if (strlen($text) > $MAXCHARS || substr_count($text, "<br>") > $MAXLINES) {
        // too many lines or too many characters.
        exit('toolong');
    }
    $sql = GetSQL();
    $text = $sql->real_escape_string($text);
    $sql->safequery("\n\t\t\tUPDATE Topics SET state=" . TopicStates::Live . ",\n\t\t\tcontent='{$text}', time=" . time() . " WHERE id=" . $g_account->page . "\n\t\t\tAND state=" . TopicStates::Composing);
    //$sql->safequery( "UPDATE Accounts SET serial=serial+1 WHERE id=". $g_account->id );
    if ($sql->affected_rows == 0) {
        // their composition slot was deleted because
        // they took too long.
        exit('expired');
    }
    exit('okay.');
} catch (Exception $e) {
    LogException("compose", $e);
}
exit('error');
Example #3
0
function CheckTopicExpired($id)
{
    $sql = GetSQL();
    $result = $sql->safequery("SELECT state,goods,bads,time FROM Topics WHERE id={$id}");
    $row = $result->fetch_row();
    if ($row === NULL) {
        throw new Exception('Invalid page.');
    }
    if ($row[0] == TopicStates::Old) {
        return 2;
    }
    if ($row[0] == TopicStates::Deleted) {
        return 1;
    }
    if ($row[0] != TopicStates::Live) {
        throw new Exception('Invalid page.');
    }
    return CheckTopicExpired2($id, $row[1], $row[2], $row[3]);
}