Location: PHPKode > projects > PhpMyForum > phpmyforum_4_1_1/newpost.php
<?php
define('PMF_INCLUDE', 1);
require('head.php');
require($_cfg['MAIN'].'/lib/bbcode.inc.php');
require($_cfg['MAIN'].'/lib/post.inc.php');
access('newpost');
access('topic');


#
#
### BB-Code Klasse
$_bbcode = new pmf_bbcode();


#
#
### Standard-Templates vorbereiten
$_style->prefill('goto', goto_list(array('board' => $forum['id'])), 0);
if (!empty($_config['FOOTER_RULES'])) $_style->prefill('footer_rules', footer_rulez(), 0);


#
#
### Navigation ...
$boardnav = makenavline($forum['id']);


#
#
### Thema geschlossen?
if (!empty($forum['closed']) && !user_mod()) {
    msg('error_access', 'back()');
}


#
#
### Thema nicht sichtbar && kein Mod || nicht vorhanden (show_topic)
if ((!$forum['show_topic'] && !user_mod()) || !isset($forum['show_topic'])) msg('error_topic_fault', 'back()');


#
#
### Flood Check
if ($_user['access']['newpost_flood'] > 0) {
    $last = $_db->fetch_first('SELECT COUNT(`id`) AS `anz`
                               FROM `'.$_cfg['DB_PREFIX'].'post`
                               WHERE `post_date` > '.(PMF_TIME-intval($_user['access']['newpost_flood'])).'
                                 AND `user_id` = '.$_user['id']);
    if ($last['anz'] > 0) msg('error_post_new_flood_fault', 'back()');
}



#
#
### keine Vorschau (normal)
if (!$_POST['view']) {
    $_style->del('newpost_preview');
    $_style->del('post_modul_sign');
    //Quote Beitrag ?
    if (is_numeric($_GET['quote'])) {
        $quote = $_db->fetch_first('SELECT p.text, u.name AS user_name, u.id AS user_id
                                    FROM `'.$_cfg['DB_PREFIX'].'post` AS p, `'.$_cfg['DB_PREFIX'].'user` AS u
                                    WHERE p.id = '.$_GET['quote'].'
                                      AND p.user_id = u.id');
        $quote['text'] = htmlentities( $_bbcode->remove_hidden($quote['text']), ENT_QUOTES);
        $message = eval('return ("'.$_style->get('newpost_quote').'");');
    }
    
    # Variablen anpassen
    $clickable = $_style->cfg['template_choice'];
    $bbcode = !empty($_user['bbcode']) ? $_style->cfg['template_choice'] : '';
    $html = !empty($_user['html']) ? $_style->cfg['template_choice'] : '';
    $smilie = !empty($_user['smilie']) ? $_style->cfg['template_choice'] : '';
    # Abo
    $abo = $_db->fetch_first('SELECT COUNT(*) AS anz FROM `'.$_cfg['DB_PREFIX'].'topic_abo` WHERE topic_id = '.$_GET['id'].' AND user_id = '.$_user['id']);
    $email = !empty($abo['anz']) ? $_style->cfg['template_choice'] : '';
    
### Vorschau anzeigen
} else {
    $_user['reg'] = pmf_date($_user['reg']);
    # Avatar
    $avatar = avatar($_user['avatar'], $_user['avatar_size']);
    # Benutzer-Titel
    $status = get_user_title($_user['group_id'], $_user['posts'], $_user['gender']);
    $_user['status_stars'] = $status['filename'];
    $_user['status_name'] = $status['name'];
    # Signatur
    if (!empty($_user['sign_active'])) {
        $sign = $_bbcode->parse($_user['sign'], $_config['SIGN_BBCODE'], $_config['SIGN_HTML'], $_config['SIGN_SMILIE'], 1, 1);
    } else {
        $_style->del('post_modul_sign');
    }
    $_POST['message'] = gpc_stripslashes($_POST['message']);
    $message = htmlentities($_POST['message'], ENT_QUOTES);
    $_POST['message'] = $_bbcode->parse($_POST['message'], $_POST['bbcode']*$_user['access']['topic_bbcode'], $_POST['html']*$_user['access']['topic_html'], $_POST['smilie']*$_user['access']['topic_smilie'], 1, 1, 0, $_POST['clickable']);
    
    # Variablen anpassen
    $clickable = !empty($_POST['clickable']) ? $_style->cfg['template_choice'] : '';
    $bbcode = !empty($_POST['bbcode']) ? $_style->cfg['template_choice'] : '';
    $html = !empty($_POST['html']) ? $_style->cfg['template_choice'] : '';
    $smilie = !empty($_POST['smilie']) ? $_style->cfg['template_choice'] : '';
    $email = !empty($_POST['email']) ? $_style->cfg['template_choice'] : '';
}


// html, bbcode, smilie
$can_use = array();
$can_use['html'] = !empty($_user['access']['topic_html']) ? true : false;
$can_use['bbcode'] = !empty($_user['access']['topic_bbcode']) ? true : false;
$can_use['smilie'] = !empty($_user['access']['topic_smilie']) ? true : false;
$default = array();
$default['html'] = $_user['html'];
$default['bbcode'] = $_user['bbcode'];
$default['smilie'] = $_user['smilie'];


#
#
### Formular anzeigen
if (!$_POST['message'] || $_POST['view']) {

    # Smilie Liste
    $smilie_list = smilie_list($_user['access']['topic_smilie']);

    # BB-Codes
    if (!$_user['access']['topic_bbcode']) $_style->del('post_modul_bbcodes');

    # Dateianh�nge
    if (!$_user['access']['attachment_upload']) {
        $_style->del('post_modul_files_newpost');
    } else {
        // Anzahl bereits hochgeladen
        $attachment_count = $_db->num_rows( $_db->query('SELECT id
                                                         FROM `'.$_cfg['DB_PREFIX'].'attachment`
                                                         WHERE `user_id` = '.$_user['id'].'
                                                           AND `post_id` = 0'));
        $aviable_extensions = get_aviable_attachment_types($_user['access']['groups']);
    }
    
    # letzte Themen
    $post_history_lines = topic_history($_GET['id']);
    
    eval ('echo "'.$_style->get('newpost').'";');



#
#
### Speichern
} else {
    include($_cfg['MAIN'].'/lib/search.inc.php');
    
    ### Post hinzuf�gen
    $_db->query('INSERT INTO `'.$_cfg['DB_PREFIX'].'post` (`user_id`,`post_date`,`text`,`topic_id`,`html`,`bbcode`,`smilie`,`ip`,`clickable`)
                 VALUES ('.$_user['id'].','.PMF_TIME.',\''.gpc_addslashes(prepare_post($_POST['message'])).'\','.intval($_POST['id']).','.intval($_POST['html']*$_user['access']['topic_html']).','.intval($_POST['bbcode']*$_user['access']['topic_bbcode']).','.intval($_POST['smilie']*$_user['access']['topic_smilie']).',\''.addslashes($_SERVER['REMOTE_ADDR']).'\','.intval($_POST['clickable']).')');
    $Post_id = $_db->insert_id();
    // Attachments
    if (!empty($_user['access']['attachment_upload'])) {
        $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'attachment`
                       SET `post_id` = '.intval($Post_id).'
                       WHERE `user_id` = '.$_user['id'].'
                         AND `post_id` = 0');
    }
    $attachments = $_db->fetch_first('SELECT COUNT(*) AS `anz`
                                      FROM `'.$_cfg['DB_PREFIX'].'post` AS p,
                                           `'.$_cfg['DB_PREFIX'].'attachment` AS a
                                      WHERE p.`topic_id` = '.intval($_POST['id']).'
                                        AND p.`id` = a.`post_id`');
    
    // Eintragen & Senden der Topic_abo�s
    topic_abo(intval($_POST['id']), 'send', $_POST['email']);
    if (!$_POST['email']) $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'topic_abo` WHERE topic_id = '.intval($_POST['id']).' AND user_id = '.$_user['id']);
    
    // Suche aktualisieren
    search_add( array($Post_id => search_filter(gpc_stripslashes($_POST['message'])) ) );

    // Punkt- hinzuf�gen / last_post hinzuf�gen
    $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'user` SET '.(($forum['count_posts']) ? 'posts = posts+1,' : '').' last_post = '.$Post_id.' WHERE id = '.$_user['id']);
    // Topic posts + last_post + attachments
    $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'topic` SET posts=posts+1, last_post = '.$Post_id.', attachments='.intval($attachments['anz']).' WHERE id = '.intval($_POST['id']));
    // Forums + posts + last_topic + last_post_date + last_user_id
    $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'board` SET posts=posts+1, last_topic = '.intval($_POST['id']).', last_post_date = '.PMF_TIME.', last_user_id='.$_user['id'].' WHERE id = '.$forum['id']);

    msg('error_post_new', 'topic.php?id='.$_POST['id'].'&goto=lastpost&'.$_sess['url']);
}
footer();
?>
Return current item: PhpMyForum