Exemple #1
0
    protected function _publish_home()
    {
        global $bio;
        $v = $this->__(w('address key subject content playing f 0 p 0'));
        // TODO: Implement bio authorization
        $this->_bio_publish($v->address, $v->key);
        //
        if (!$v->forum && !$v->post) {
            $warning->now();
        }
        if ($v->forum) {
            if (empty($v->subject)) {
                $this->_error('NO_TOPIC_SUBJECT');
            }
            $sql = 'SELECT *
				FROM _board_forums
				WHERE forum_id = ?';
            if (!($forum = sql_fieldrow(sql_filter($sql, $v->forum)))) {
                $warning->now();
            }
            $v->subject = _subject($v->subject);
        } else {
            $sql = 'SELECT *
				FROM _board_posts
				WHERE post_id = ?';
            if (!($post = sql_fieldrow(sql_filter($sql, $v->post)))) {
                $warning->now();
            }
            $sql = 'SELECT *
				FROM _board_topics
				WHERE topic_id = ?';
            if (!($topic = sql_fieldrow(sql_filter($sql, $post->post_topic)))) {
                $warning->now();
            }
        }
        if ($v->forum) {
            if ($forum->forum_locked && !$this->auth_forum($forum, 'create')) {
                $warning->now();
            }
        }
        if (empty($v->content)) {
            $this->_error('NO_TOPIC_CONTENT');
        }
        $v->content = _prepare($v->content);
        // Start insert transaction
        sql_transaction();
        $sql_commit = false;
        if ($v->forum) {
            // Insert topic
            $sql_insert = array('forum' => $v->forum, 'subject' => $v->subject, 'author' => $bio->v('bio_id'), 'time' => time(), 'active' => $bio->v('bio_confirmed'));
            $v->topic_next = sql_put('_board_topics', prefix('topic', $sql_insert));
            // Insert post
            $sql_insert = array('forum' => $v->forum, 'topic' => $v->topic_next, 'parent' => 0, 'bio' => $bio->v('bio_id'), 'time' => time(), 'active' => $bio->v('bio_confirmed'), 'message' => $v->content, 'playing' => $v->playing);
            $v->post_next = sql_put('_board_posts', prefix('post', $sql_insert));
            if ($v->topic_next && $v->post_next) {
                $sql_commit = true;
            }
        } else {
            $sql_insert = array('forum' => $topic->topic_forum, 'topic' => $topic->topic_id, 'parent' => $v->post, 'bio' => $bio->v('bio_id'), 'time' => time(), 'active' => $bio->v('bio_confirmed'), 'message' => $v->content, 'playing' => $v->playing);
            $v->post_next = sql_put('_board_posts', prefix('post', $sql_insert));
            $sql_update = w();
            $sql = 'UPDATE _board_topics SET topic_replies = topic_replies + 1' . sql_build('UPDATE', $sql_update) . sql_filter('
				WHERE topic_id = ?', $topic->topic_id);
            $updated = sql_affected($sql);
            if ($v->post_next && $updated) {
                $sql_commit = true;
            }
        }
        if (!$sql_commit) {
            sql_transaction('rollback');
            $this->_error('ROLLBACK_MESSAGE');
        }
        sql_transaction('commit');
        if (is_ghost() && $v->post) {
            if ($bio->v('bio_confirmed')) {
                $response = array('show' => 1, 'parent' => $v->post, 'post' => $v->post_next, 'content' => _message($v->content), 'time' => _format_date(), 'profile' => array('link' => _link_bio($bio->v('bio_alias')), 'name' => $bio->v('bio_name')));
            } else {
                $response = array('show' => 0, 'legend' => _lang('PUBLISH_TOPIC_GUEST'));
            }
            $this->output(json_encode($response));
        }
        return redirect(_link('board', array('topic', $v->topic)));
    }
function replace_records($table, $conditions, $records)
{
    $queries[] = generate_delete_sql($table, $conditions);
    $queries[] = generate_insert_sql($table, $conditions, $records);
    return sql_transaction($queries);
}