function execute(&$request) { global $_QUERYPARAMS, $_DATASTORE, $_SETTINGS; $this->dba = $request['dba']; /* set the breadcrumbs bit */ k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION'); /* Check the request ID */ if (!isset($_REQUEST['forum_id']) || !$_REQUEST['forum_id'] || intval($_REQUEST['forum_id']) == 0) { $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_FORUMDOESNTEXIST'); } /* Check the request ID */ if (!isset($_REQUEST['forum_id']) || !$_REQUEST['forum_id'] || intval($_REQUEST['forum_id']) == 0) { $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_FORUMDOESNTEXIST'); } $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($_REQUEST['forum_id'])); /* Check the forum data given */ if (!$forum || !is_array($forum) || empty($forum)) { $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_FORUMDOESNTEXIST'); } /* Make sure the we are trying to post into a forum */ if (!($forum['row_type'] & FORUM) || $forum['forum_id'] == GARBAGE_BIN) { $action = new K4InformationAction(new K4LanguageElement('L_CANTPOSTTONONFORUM'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_CANTPOSTTONONFORUM'); } /* Do we have permission to post to this forum? */ if ($request['user']->get('perms') < get_map('topics', 'can_add', array('forum_id' => $forum['forum_id']))) { $action = new K4InformationAction(new K4LanguageElement('L_PERMCANTPOST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_PERMCANTPOST'); } /* General error checking */ if (!isset($_REQUEST['name']) || $_REQUEST['name'] == '') { $action = new K4InformationAction(new K4LanguageElement('L_INSERTTOPICNAME'), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTTOPICNAME'); } if (!$this->runPostFilter('name', new FALengthFilter(intval($_SETTINGS['topicmaxchars'])))) { $action = new K4InformationAction(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars']))); } if (!$this->runPostFilter('name', new FALengthFilter(intval($_SETTINGS['topicmaxchars']), intval($_SETTINGS['topicminchars'])))) { $action = new K4InformationAction(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars']))); } if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') { $action = new K4InformationAction(new K4LanguageElement('L_INSERTTOPICMESSAGE'), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTTOPICMESSAGE'); } /* Get our topic */ $draft = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['post_id']) . " AND is_draft = 1 AND poster_id = " . intval($request['user']->get('id'))); if (!$draft || !is_array($draft) || empty($draft)) { $action = new K4InformationAction(new K4LanguageElement('L_DRAFTDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_DRAFTDOESNTEXIST'); } /* set the breadcrumbs bit */ k4_bread_crumbs($request['template'], $request['dba'], 'L_POSTTOPIC', $forum); $created = time(); /* Initialize the bbcode parser with the topic message */ $_REQUEST['message'] = substr($_REQUEST['message'], 0, $_SETTINGS['postmaxchars']); /* Parse the bbcode */ $body_text = $_REQUEST['message']; $submit_type = isset($_REQUEST['submit_type']) ? $_REQUEST['submit_type'] : 'post'; if (!isset($_REQUEST['disable_bbcode']) || !$_REQUEST['disable_bbcode']) { $parser =& new BBParser(); Globals::setGlobal('forum_id', $forum['forum_id']); Globals::setGlobal('maxpolloptions', $request['template']->getVar('maxpolloptions') > $forum['maxpolloptions'] ? $forum['maxpolloptions'] : $request['template']->getVar('maxpolloptions')); Globals::setGlobal('maxpollquestions', $request['template']->getVar('maxpollquestions') > $forum['maxpollquestions'] ? $forum['maxpollquestions'] : $request['template']->getVar('maxpollquestions')); if ($submit_type == 'post' || $submit_type == 'draft' || isset($_REQUEST['post'])) { $parser->register('BBPollNode'); } $body_text = $parser->parse($body_text); $is_poll = Globals::getGlobal('is_poll'); } // permissions are taken into account inside the poller //$poller = &new K4BBPolls($body_text, $draft['body_text'], $forum, $draft['post_id']); /** * Figure out what type of topic type this is */ $post_type = isset($_REQUEST['post_type']) && intval($_REQUEST['post_type']) != 0 ? $_REQUEST['post_type'] : TOPIC_NORMAL; if ($post_type == TOPIC_STICKY && $request['user']->get('perms') < get_map('sticky', 'can_add', array('forum_id' => $forum['forum_id']))) { $post_type = TOPIC_NORMAL; } else { if ($post_type == TOPIC_ANNOUNCE && $request['user']->get('perms') < get_map('announce', 'can_add', array('forum_id' => $forum['forum_id']))) { $post_type = TOPIC_NORMAL; } } $is_feature = isset($_REQUEST['is_feature']) && $_REQUEST['is_feature'] == 'yes' ? 1 : 0; if ($is_feature == 1 && $request['user']->get('perms') < get_map('feature', 'can_add', array('forum_id' => $forum['forum_id']))) { $is_feature = 0; } /* If we are submitting or saving a draft */ if ($submit_type == 'post' || $submit_type == 'draft' || (isset($_REQUEST['post']) || isset($_REQUEST['draft']))) { /** * Build the queries to add the draft */ $poster_name = $request['user']->get('id') <= 0 ? k4_htmlentities(isset($_REQUEST['poster_name']) ? $_REQUEST['poster_name'] : '', ENT_QUOTES) : $request['user']->get('name'); $update_a = $request['dba']->prepareStatement("UPDATE " . K4POSTS . " SET name=?,body_text=?,posticon=?,disable_html=?,disable_bbcode=?,disable_emoticons=?,disable_sig=?,disable_areply=?,disable_aurls=?,is_draft=?,post_type=?,is_feature=?,is_poll=?,created=? WHERE post_id=?"); /* Set the informtion */ $update_a->setInt(1, $created); $update_a->setInt(2, $draft['post_id']); /* Set the topic information */ $update_a->setString(1, k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES)); $update_a->setString(2, $body_text); $update_a->setString(3, $request['user']->get('perms') >= get_map('posticons', 'can_add', array('forum_id' => $forum['forum_id'])) ? isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif' : 'clear.gif'); $update_a->setInt(4, isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'] ? 1 : 0); $update_a->setInt(5, isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'] ? 1 : 0); $update_a->setInt(6, isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'] ? 1 : 0); $update_a->setInt(7, isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'] ? 0 : 1); $update_a->setInt(8, isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'] ? 1 : 0); $update_a->setInt(9, isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'] ? 1 : 0); $update_a->setInt(10, 0); $update_a->setInt(11, $post_type); $update_a->setInt(12, $is_feature); $update_a->setInt(13, $is_poll); $update_a->setInt(14, $created); $update_a->setInt(15, $draft['post_id']); /** * Do the queries */ $update_a->executeUpdate(); $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET topics=topics+1,posts=posts+1,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? WHERE forum_id=?"); $datastore_update = $request['dba']->prepareStatement("UPDATE " . K4DATASTORE . " SET data=? WHERE varname=?"); if (isset($_REQUEST['submit_type']) && $_REQUEST['submit_type'] == 'post' || isset($_REQUEST['post'])) { $request['dba']->executeUpdate("UPDATE " . K4USERINFO . " SET num_posts=num_posts+1,total_posts=total_posts+1 WHERE user_id=" . intval($request['user']->get('id'))); } /* Set the forum values */ $forum_update->setInt(1, $created); $forum_update->setString(2, k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES)); $forum_update->setString(3, $poster_name); $forum_update->setInt(4, $draft['post_id']); $forum_update->setInt(5, $request['user']->get('id')); $forum_update->setString(6, iif($request['user']->get('perms') >= get_map('posticons', 'can_add', array('forum_id' => $forum['forum_id'])), isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif', 'clear.gif')); $forum_update->setInt(7, $forum['forum_id']); /* Set the datastore values */ $datastore = $_DATASTORE['forumstats']; $datastore['num_topics'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE is_draft=0"); $datastore_update->setString(1, serialize($datastore)); $datastore_update->setString(2, 'forumstats'); /** * Update the forums table and datastore table */ $forum_update->executeUpdate(); $datastore_update->executeUpdate(); reset_cache('datastore'); /** * Subscribe this user to the topic */ if (isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply']) { $subscribe = $request['dba']->prepareStatement("INSERT INTO " . K4SUBSCRIPTIONS . " (user_id,post_id,forum_id,email) VALUES (?,?,?,?)"); $subscribe->setInt(1, $request['user']->get('id')); $subscribe->setInt(2, $draft['id']); $subscribe->setInt(3, $forum['forum_id']); $subscribe->setString(4, $request['user']->get('email')); $subscribe->executeUpdate(); } // deal with attachments if ($request['template']->getVar('nojs') == 0) { attach_files($request, $forum, $draft['post_id']); } // set up the topic queue set_send_topic_mail($forum['forum_id'], $poster_name == '' ? $request['template']->getVar('L_GUEST') : $poster_name); /* Redirect the user */ $action = new K4InformationAction(new K4LanguageElement('L_ADDEDTOPIC', k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES), $forum['name']), 'content', FALSE, 'viewtopic.php?id=' . $draft['post_id'], 3); return $action->execute($request); /* If we are previewing */ } else { /** * Post Previewing */ if (!USE_XMLHTTP) { $request['template']->setVar('L_TITLETOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars'))); /* Get and set the emoticons and post icons to the template */ $emoticons = $request['dba']->executeQuery("SELECT * FROM " . K4EMOTICONS . " WHERE clickable=1"); $posticons = $request['dba']->executeQuery("SELECT * FROM " . K4POSTICONS); /* Add the emoticons and posticons */ $request['template']->setList('emoticons', $emoticons); $request['template']->setList('posticons', $posticons); /* Set some emoticon information */ $request['template']->setVar('emoticons_per_row', $request['template']->getVar('smcolumns')); $request['template']->setVar('emoticons_per_row_remainder', $request['template']->getVar('smcolumns') - 1); $request['template']->setVar('newtopic_action', 'newtopic.php?act=postdraft'); $request['template']->setVisibility('post_topic', TRUE); post_attachment_options($request, $forum, $draft); topic_post_options($request['template'], $request['user'], $forum); /* Create our editor */ create_editor($request, $_REQUEST['message'], 'post', $forum); } /* Set topic iterator array elements to be passed to the template */ $topic_preview = array('post_id' => @$draft['post_id'], 'name' => k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES), 'posticon' => isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif', 'body_text' => $body_text, 'poster_name' => html_entity_decode($draft['poster_name'], ENT_QUOTES), 'poster_id' => $request['user']->get('id'), 'is_poll' => $draft['is_poll'], 'row_left' => 0, 'row_right' => 0, 'post_type' => $post_type, 'is_feature' => $is_feature, 'posticon' => $request['user']->get('perms') >= get_map('posticons', 'can_add', array('forum_id' => $forum['forum_id'])) ? isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif' : 'clear.gif', 'disable_html' => isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'] ? 1 : 0, 'disable_sig' => isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'] ? 0 : 1, 'disable_bbcode' => isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'] ? 1 : 0, 'disable_emoticons' => isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'] ? 1 : 0, 'disable_areply' => isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'] ? 1 : 0, 'disable_aurls' => isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'] ? 1 : 0); /* Add the topic information to the template */ $topic_iterator = new TopicIterator($request['dba'], $request['user'], $topic_preview, FALSE); $request['template']->setList('topic', $topic_iterator); /* Assign the topic preview values to the template */ $topic_preview['body_text'] = $_REQUEST['message']; foreach ($topic_preview as $key => $val) { $request['template']->setVar('topic_' . $key, $val); } /* Assign the forum information to the template */ foreach ($forum as $key => $val) { $request['template']->setVar('forum_' . $key, $val); } $request['template']->setVar('is_topic', 1); if (!USE_XMLHTTP) { /* Set the the button display options */ $request['template']->setVisibility('save_draft', FALSE); $request['template']->setVisibility('load_button', FALSE); $request['template']->setVisibility('edit_topic', TRUE); $request['template']->setVisibility('post_id', TRUE); /* set the breadcrumbs bit */ k4_bread_crumbs($request['template'], $request['dba'], 'L_POSTTOPIC', $forum); /* Set the post topic form */ $request['template']->setVar('forum_forum_id', $forum['forum_id']); $request['template']->setFile('preview', 'post_preview.html'); $request['template']->setFile('content', 'newtopic.html'); } else { $templateset = $request['user']->isMember() ? $request['user']->get('templateset') : $forum['defaultstyle']; $html = $request['template']->run(BB_BASE_DIR . '/templates/' . $templateset . '/post_preview.html'); xmlhttp_header(); echo $html; xmlhttp_footer(); } } return TRUE; }
function Execute(&$template, $request, &$dba, &$session, &$user) { global $_QUERYPARAMS, $_DATASTORE, $_SETTINGS; $this->dba =& $dba; /* Check the request ID */ if (!isset($request['forum_id']) || !$request['forum_id'] || intval($request['forum_id']) == 0) { /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM')); $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE); return TRUE; } $forum = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'] . " FROM " . FORUMS . " f LEFT JOIN " . INFO . " i ON f.forum_id = i.id WHERE i.id = " . intval($request['forum_id'])); /* Check the forum data given */ if (!$forum || !is_array($forum) || empty($forum)) { /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM')); $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE); return TRUE; } /* Make sure the we are trying to post into a forum */ if (!($forum['row_type'] & FORUM)) { /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_INFORMATION')); $template->setInfo('content', $template->getVar('L_CANTPOSTTONONFORUM'), FALSE); return TRUE; } /* Do we have permission to post to this forum? */ if ($user['perms'] < get_map($user, 'topics', 'can_add', array('forum_id' => $forum['id']))) { /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_INFORMATION')); $template->setInfo('content', $template->getVar('L_PERMCANTPOST'), FALSE); return TRUE; } /* General error checking */ if (!isset($request['name']) || $request['name'] == '') { /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']); $template->setInfo('content', $template->getVar('L_INSERTTOPICNAME'), TRUE); return TRUE; } if (!isset($request['message']) || $request['message'] == '') { /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']); $template->setInfo('content', $template->getVar('L_INSERTTOPICMESSAGE'), TRUE); return TRUE; } /* Get our topic */ $draft = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE i.id = " . intval($request['topic_id']) . " AND t.is_draft = 1 AND t.poster_id = " . intval($user['id'])); if (!$draft || !is_array($draft) || empty($draft)) { /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_INVALIDDRAFT')); $template->setInfo('content', $template->getVar('L_DRAFTDOESNTEXIST'), FALSE); return TRUE; } /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_POSTTOPIC'), $forum['row_left'], $forum['row_right']); $created = time(); /* Initialize the bbcode parser with the topic message */ $request['message'] = substr($request['message'], 0, $_SETTINGS['postmaxchars']); $bbcode =& new BBCodex(&$user, $request['message'], $forum['id'], iif(isset($request['disable_html']) && $request['disable_html'] == 'on', FALSE, TRUE), iif(isset($request['disable_bbcode']) && $request['disable_bbcode'] == 'on', FALSE, TRUE), iif(isset($request['disable_emoticons']) && $request['disable_emoticons'] == 'on', FALSE, TRUE), iif(isset($request['disable_aurls']) && $request['disable_aurls'] == 'on', FALSE, TRUE)); /* Parse the bbcode */ $body_text = $bbcode->parse(); /** * Figure out what type of topic type this is */ $topic_type = isset($request['topic_type']) && intval($request['topic_type']) != 0 ? $request['topic_type'] : TOPIC_NORMAL; if ($topic_type == TOPIC_STICKY && $user['perms'] < get_map($user, 'sticky', 'can_add', array('forum_id' => $forum['id']))) { $topic_type = TOPIC_NORMAL; } else { if ($topic_type == TOPIC_ANNOUNCE && $user['perms'] < get_map($user, 'announce', 'can_add', array('forum_id' => $forum['id']))) { $topic_type = TOPIC_NORMAL; } else { if ($topic_type == TOPIC_GLOBAL && $user['perms'] < get_map($user, 'global', 'can_add', array('forum_id' => $forum['id']))) { $topic_type = TOPIC_NORMAL; } } } $is_feature = isset($request['is_feature']) && $request['is_feature'] == 'yes' ? 1 : 0; if ($is_feature == 1 && $user['perms'] < get_map($user, 'feature', 'can_add', array('forum_id' => $forum['id']))) { $is_feature = 0; } /* If we are submitting or saving a draft */ if ($request['submit'] == $template->getVar('L_SUBMIT') || $request['submit'] == $template->getVar('L_SAVEDRAFT')) { /** * Build the queries to add the draft */ $poster_name = iif($user['id'] <= 0, htmlentities(isset($request['poster_name']) ? $request['poster_name'] : '', ENT_QUOTES), $user['name']); $update_a = $dba->prepareStatement("UPDATE " . INFO . " SET name=?,created=? WHERE id=?"); $update_b = $dba->prepareStatement("UPDATE " . TOPICS . " SET body_text=?,posticon=?,disable_html=?,disable_bbcode=?,disable_emoticons=?,disable_sig=?,disable_areply=?,disable_aurls=?,is_draft=?,topic_type=?,is_feature=? WHERE topic_id=?"); /* Set the informtion */ $update_a->setString(1, htmlentities($request['name'], ENT_QUOTES)); $update_a->setInt(2, $created); $update_a->setInt(3, $draft['id']); /* Set the topic information */ $update_b->setString(1, $body_text); $update_b->setString(2, iif($user['perms'] >= get_map($user, 'posticons', 'can_add', array('forum_id' => $forum['id'])), isset($request['posticon']) ? $request['posticon'] : 'clear.gif', 'clear.gif')); $update_b->setInt(3, iif(isset($request['disable_html']) && $request['disable_html'] == 'on', 1, 0)); $update_b->setInt(4, iif(isset($request['disable_bbcode']) && $request['disable_bbcode'] == 'on', 1, 0)); $update_b->setInt(5, iif(isset($request['disable_emoticons']) && $request['disable_emoticons'] == 'on', 1, 0)); $update_b->setInt(6, iif(isset($request['enable_sig']) && $request['enable_sig'] == 'on', 0, 1)); $update_b->setInt(7, iif(isset($request['disable_areply']) && $request['disable_areply'] == 'on', 1, 0)); $update_b->setInt(8, iif(isset($request['disable_aurls']) && $request['disable_aurls'] == 'on', 1, 0)); $update_b->setInt(9, 0); $update_b->setInt(10, $topic_type); $update_b->setInt(11, $is_feature); $update_b->setInt(12, $draft['id']); /** * Do the queries */ $update_a->executeUpdate(); $update_b->executeUpdate(); $forum_update =& $dba->prepareStatement("UPDATE " . FORUMS . " SET topics=topics+1,posts=posts+1,topic_created=?,topic_name=?,topic_uname=?,topic_id=?,topic_uid=?,topic_posticon=?,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? WHERE forum_id=?"); $datastore_update =& $dba->prepareStatement("UPDATE " . DATASTORE . " SET data=? WHERE varname=?"); if ($request['submit'] == $template->getVar('L_SUBMIT')) { $dba->executeUpdate("UPDATE " . USERINFO . " SET num_posts=num_posts+1 WHERE user_id=" . intval($user['id'])); } /* Set the forum values */ $forum_update->setInt(1, $created); $forum_update->setString(2, htmlentities($request['name'], ENT_QUOTES)); $forum_update->setString(3, $poster_name); $forum_update->setInt(4, $draft['id']); $forum_update->setInt(5, $user['id']); $forum_update->setString(6, iif($user['perms'] >= get_map($user, 'posticons', 'can_add', array('forum_id' => $forum['id'])), isset($request['posticon']) ? $request['posticon'] : 'clear.gif', 'clear.gif')); $forum_update->setInt(7, $created); $forum_update->setString(8, htmlentities($request['name'], ENT_QUOTES)); $forum_update->setString(9, $poster_name); $forum_update->setInt(10, $draft['id']); $forum_update->setInt(11, $user['id']); $forum_update->setString(12, iif($user['perms'] >= get_map($user, 'posticons', 'can_add', array('forum_id' => $forum['id'])), isset($request['posticon']) ? $request['posticon'] : 'clear.gif', 'clear.gif')); $forum_update->setInt(13, $forum['id']); /* Set the datastore values */ $datastore = $_DATASTORE['forumstats']; $datastore['num_topics'] = $dba->getValue("SELECT COUNT(*) FROM " . TOPICS . " WHERE is_draft = 0"); $datastore_update->setString(1, serialize($datastore)); $datastore_update->setString(2, 'forumstats'); /** * Update the forums table and datastore table */ $forum_update->executeUpdate(); $datastore_update->executeUpdate(); if (!@touch(CACHE_FILE, time() - 86460)) { @unlink(CACHE_FILE); } /** * Subscribe this user to the topic */ if (isset($request['disable_areply']) && $request['disable_areply'] == 'on') { $subscribe =& $dba->prepareStatement("INSERT INTO " . SUBSCRIPTIONS . " (user_id,user_name,topic_id,forum_id,email,category_id) VALUES (?,?,?,?,?,?)"); $subscribe->setInt(1, $user['id']); $subscribe->setString(2, $user['name']); $subscribe->setInt(3, $draft['id']); $subscribe->setInt(4, $forum['id']); $subscribe->setString(5, $user['email']); $subscribe->setInt(6, $forum['category_id']); $subscribe->executeUpdate(); } set_send_topic_mail($forum['id'], iif($poster_name == '', $template->getVar('L_GUEST'), $poster_name)); /* Redirect the user */ $template->setInfo('content', sprintf($template->getVar('L_ADDEDTOPIC'), htmlentities($request['name'], ENT_QUOTES), $forum['name'])); $template->setRedirect('viewtopic.php?id=' . $draft['id'], 3); /* If we are previewing */ } else { /** * Post Previewing */ /* Get and set the emoticons and post icons to the template */ $emoticons =& $dba->executeQuery("SELECT * FROM " . EMOTICONS . " WHERE clickable = 1"); $posticons =& $dba->executeQuery("SELECT * FROM " . POSTICONS); /* Add the emoticons and posticons */ $template->setList('emoticons', $emoticons); $template->setList('posticons', $posticons); /* Set some emoticon information */ $template->setVar('emoticons_per_row', $template->getVar('smcolumns')); $template->setVar('emoticons_per_row_remainder', $template->getVar('smcolumns') - 1); $template->setVar('newtopic_action', 'newtopic.php?act=postdraft'); $template = topic_post_options($template, $user, $forum); /* Set topic iterator array elements to be passed to the template */ $topic_preview = array('id' => @$draft['id'], 'name' => htmlentities($request['name'], ENT_QUOTES), 'posticon' => isset($request['posticon']) ? $request['posticon'] : 'clear.gif', 'body_text' => $body_text, 'poster_name' => html_entity_decode($draft['poster_name'], ENT_QUOTES), 'poster_id' => $user['id'], 'row_left' => 0, 'row_right' => 0, 'topic_type' => $topic_type, 'is_feature' => $is_feature, 'posticon' => iif($user['perms'] >= get_map($user, 'posticons', 'can_add', array('forum_id' => $forum['id'])), isset($request['posticon']) ? $request['posticon'] : 'clear.gif', 'clear.gif'), 'disable_html' => iif(isset($request['disable_html']) && $request['disable_html'] == 'on', 1, 0), 'disable_sig' => iif(isset($request['enable_sig']) && $request['enable_sig'] == 'on', 0, 1), 'disable_bbcode' => iif(isset($request['disable_bbcode']) && $request['disable_bbcode'] == 'on', 1, 0), 'disable_emoticons' => iif(isset($request['disable_emoticons']) && $request['disable_emoticons'] == 'on', 1, 0), 'disable_areply' => iif(isset($request['disable_areply']) && $request['disable_areply'] == 'on', 1, 0), 'disable_aurls' => iif(isset($request['disable_aurls']) && $request['disable_aurls'] == 'on', 1, 0)); /* Add the topic information to the template */ $topic_iterator =& new TopicIterator($topic_preview, FALSE); $template->setList('topic', $topic_iterator); /* Assign the topic preview values to the template */ $topic_preview['body_text'] = $request['message']; foreach ($topic_preview as $key => $val) { $template->setVar('topic_' . $key, $val); } /* Assign the forum information to the template */ foreach ($forum as $key => $val) { $template->setVar('forum_' . $key, $val); } /* Set the the button display options */ $template->hide('save_draft'); $template->hide('load_button'); $template->show('edit_topic'); $template->show('topic_id'); /* set the breadcrumbs bit */ $template = BreadCrumbs($template, $template->getVar('L_POSTTOPIC'), $forum['row_left'], $forum['row_right']); /* Set the post topic form */ $template->setFile('preview', 'post_preview.html'); $template->setFile('content', 'newtopic.html'); } return TRUE; }
function execute(&$request) { if (isset($_REQUEST['submit_type']) && ($_REQUEST['submit_type'] == 'post' || $_REQUEST['submit_type'] == 'preview' || $_REQUEST['submit_type'] == 'draft') || (isset($_REQUEST['post']) || isset($_REQUEST['draft']))) { $submit_type = isset($_REQUEST['submit_type']) ? $_REQUEST['submit_type'] : 'post'; $should_submit = isset($_REQUEST['post']) || isset($_REQUEST['draft']); global $_QUERYPARAMS, $_DATASTORE, $_SETTINGS; $this->dba = $request['dba']; /* Prevent post flooding */ $last_topic = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE poster_ip = '" . USER_IP . "' " . ($request['user']->isMember() ? "OR poster_id = " . intval($request['user']->get('id')) : '') . " ORDER BY created DESC LIMIT 1"); $last_reply = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE poster_ip = '" . USER_IP . "' " . ($request['user']->isMember() ? "OR poster_id = " . intval($request['user']->get('id')) : '') . " ORDER BY created DESC LIMIT 1"); k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION'); if (is_array($last_topic) && !empty($last_topic)) { if (intval($last_topic['created']) + POST_IMPULSE_LIMIT > time() && $request['user']->get('perms') < MODERATOR) { $action = new K4InformationAction(new K4LanguageElement('L_MUSTWAITSECSTOPOST'), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_MUSTWAITSECSTOPOST'); } } if (is_array($last_reply) && !empty($last_reply)) { if (intval($last_reply['created']) + POST_IMPULSE_LIMIT > time() && $request['user']->get('perms') < MODERATOR) { $action = new K4InformationAction(new K4LanguageElement('L_MUSTWAITSECSTOPOST'), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_MUSTWAITSECSTOPOST'); } } /** * Error checking */ /* Check the request ID */ if (!isset($_REQUEST['forum_id']) || intval($_REQUEST['forum_id']) == 0) { $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_FORUMDOESNTEXIST'); } $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($_REQUEST['forum_id'])); /* Check the forum data given */ if (!$forum || !is_array($forum) || empty($forum)) { $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_FORUMDOESNTEXIST'); } /* Make sure the we are trying to post into a forum */ if (!($forum['row_type'] & FORUM) || $forum['forum_id'] == GARBAGE_BIN) { $action = new K4InformationAction(new K4LanguageElement('L_CANTPOSTTONONFORUM'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_CANTPOSTTONONFORUM'); } /* Do we have permission to post to this forum? */ if ($request['user']->get('perms') < get_map('topics', 'can_add', array('forum_id' => $forum['forum_id']))) { $action = new K4InformationAction(new K4LanguageElement('L_PERMCANTPOST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_PERMCANTPOST'); } /* General error checking */ if ($this->row_type & TOPIC) { if (!isset($_REQUEST['name']) || $_REQUEST['name'] == '') { $action = new K4InformationAction(new K4LanguageElement('L_INSERTTOPICNAME'), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTTOPICNAME'); } $len = strlen($_REQUEST['name']); if ($len < intval($_SETTINGS['topicminchars']) || $len > intval($_SETTINGS['topicmaxchars'])) { $action = new K4InformationAction(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars']))); } } if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') { $action = new K4InformationAction(new K4LanguageElement('L_INSERTTOPICMESSAGE'), 'content', TRUE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTTOPICMESSAGE'); } /* Initialize the bbcode parser with the topic message */ $body_text = $_REQUEST['message']; if (!isset($_REQUEST['disable_bbcode']) || !$_REQUEST['disable_bbcode']) { $parser =& new BBParser(); Globals::setGlobal('forum_id', $forum['forum_id']); Globals::setGlobal('maxpolloptions', $request['template']->getVar('maxpolloptions') > $forum['maxpolloptions'] ? $forum['maxpolloptions'] : $request['template']->getVar('maxpolloptions')); Globals::setGlobal('maxpollquestions', $request['template']->getVar('maxpollquestions') > $forum['maxpollquestions'] ? $forum['maxpollquestions'] : $request['template']->getVar('maxpollquestions')); if ($submit_type == 'post' || isset($_REQUEST['post'])) { $parser->register('BBPollNode'); } $body_text = $parser->parse($body_text); $is_poll = Globals::getGlobal('is_poll'); } if ($submit_type == 'post' || $submit_type == 'draft' || $should_submit) { /* set the breadcrumbs bit */ k4_bread_crumbs($request['template'], $request['dba'], $this->row_type & TOPIC ? 'L_POSTTOPIC' : 'L_POSTREPLY', $forum); /** * Start building info for the queries */ /* Set this nodes level */ $level = 1; if ($this->row_type & TOPIC) { $row_order = 0; $parent_id = $forum['forum_id']; $name = k4_htmlentities($_REQUEST['name'], ENT_QUOTES); } else { $topic = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id=" . intval(@$_REQUEST['topic_id'])); if (!$topic || !is_array($topic) || empty($topic)) { $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_TOPICDOESNTEXIST'); } $parent_id = $topic['post_id']; $level = $topic['row_level'] + 1; if (isset($_REQUEST['parent_id']) && intval($_REQUEST['parent_id']) != 0) { $parent = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['parent_id'])); if (!$parent || !is_array($parent) || empty($parent)) { $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_POSTDOESNTEXIST'); } $level = $parent['row_level'] + 1; } if (!isset($_REQUEST['name']) || $_REQUEST['name'] == '') { $name = 'Re: ' . k4_htmlentities(isset($parent) ? $parent['name'] : $topic['name']); } $fix_order = FALSE; if ($topic['num_replies'] == 0) { $row_order = 1; } else { if ($parent['row_type'] & TOPIC) { $row_order = $topic['num_replies'] + 1; } else { $row_order = $parent['row_order'] + 1; $fix_order = $parent['post_id'] == $topic['post_id'] ? FALSE : TRUE; } } // fix the order of things below this reply if ($fix_order) { $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET row_order=row_order+1 WHERE row_order >= " . intval($row_order) . " AND parent_id=" . intval($topic['post_id'])); } } /* Set the topic created time */ $created = time(); $_REQUEST['message'] = substr($_REQUEST['message'], 0, $_SETTINGS['postmaxchars']); // permissions are taken into account inside the poller //$poller = &new K4BBPolls($body_text, '', $forum, 0); if ($this->row_type & TOPIC) { /** * Figure out what type of topic type this is */ $post_type = isset($_REQUEST['post_type']) && intval($_REQUEST['post_type']) != 0 ? $_REQUEST['post_type'] : TOPIC_NORMAL; if ($post_type == TOPIC_STICKY && $request['user']->get('perms') < get_map('sticky', 'can_add', array('forum_id' => $forum['forum_id']))) { $post_type = TOPIC_NORMAL; } else { if ($post_type == TOPIC_ANNOUNCE && $request['user']->get('perms') < get_map('announce', 'can_add', array('forum_id' => $forum['forum_id']))) { $post_type = TOPIC_NORMAL; } } $is_feature = isset($_REQUEST['is_feature']) && $_REQUEST['is_feature'] ? 1 : 0; if ($is_feature == 1 && $request['user']->get('perms') < get_map('feature', 'can_add', array('forum_id' => $forum['forum_id']))) { $is_feature = 0; } } else { $post_type = $is_feature = 0; } /* Does this person have permission to post a draft? */ $is_draft = 0; if ($this->row_type & TOPIC && $_REQUEST['submit_type'] == 'draft' || isset($_REQUEST['draft'])) { if ($request['user']->get('perms') < get_map('post_save', 'can_add', array('forum_id' => $forum['forum_id']))) { $action = new K4InformationAction(new K4LanguageElement('L_YOUNEEDPERMS'), 'content', FALSE); return $action->execute($request); } $is_draft = 1; } /** * Build the queries */ $poster_name = $request['user']->get('id') <= 0 ? k4_htmlentities(isset($_REQUEST['poster_name']) ? $_REQUEST['poster_name'] : '', ENT_QUOTES) : $request['user']->get('name'); /* Make sure we're not double-posting */ if (!empty($last_topic) && ($_REQUEST['name'] == $last_topic['name'] && $body_text == $last_topic['body_text'])) { $action = new K4InformationAction(new K4LanguageElement('L_DOUBLEPOSTED'), 'content', TRUE, 'viewtopic.php?id=' . $last_topic['post_id'], 3); return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_DOUBLEPOSTED'); } $request['dba']->beginTransaction(); //post_id,forum_id,poster_name,poster_id,body_text,posticon //disable_html,disable_bbcode,disable_emoticons,disable_sig,disable_areply,disable_aurls,is_draft,is_poll $insert_a = $request['dba']->prepareStatement("INSERT INTO " . K4POSTS . " (name,forum_id,poster_name,poster_id,poster_ip,body_text,posticon,disable_html,disable_bbcode,disable_emoticons,disable_sig,disable_areply,disable_aurls,is_draft,post_type,post_expire,is_feature,is_poll,lastpost_created,row_type,row_level,created,row_order,parent_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $insert_a->setString(1, $name); $insert_a->setInt(2, $forum['forum_id']); $insert_a->setString(3, $poster_name); $insert_a->setInt(4, $request['user']->get('id')); $insert_a->setString(5, USER_IP); $insert_a->setString(6, $body_text); $insert_a->setString(7, $request['user']->get('perms') >= get_map('posticons', 'can_add', array('forum_id' => $forum['forum_id'])) ? isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif' : 'clear.gif'); $insert_a->setInt(8, isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'] ? 1 : 0); $insert_a->setInt(9, isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'] ? 1 : 0); $insert_a->setInt(10, isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'] ? 1 : 0); $insert_a->setInt(11, isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'] ? 0 : 1); $insert_a->setInt(12, isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'] ? 1 : 0); $insert_a->setInt(13, isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'] ? 1 : 0); $insert_a->setInt(14, $is_draft); $insert_a->setInt(15, $post_type); $insert_a->setInt(16, $post_type > TOPIC_NORMAL ? intval(isset($_REQUEST['post_expire']) ? $_REQUEST['post_expire'] : 0) : 0); $insert_a->setInt(17, $is_feature); $insert_a->setInt(18, $is_poll); $insert_a->setInt(19, $created); $insert_a->setInt(20, $this->row_type); $insert_a->setInt(21, $level); $insert_a->setInt(22, $created); $insert_a->setInt(23, $row_order); $insert_a->setInt(24, $parent_id); $insert_a->executeUpdate(); $post_id = $request['dba']->getInsertId(K4POSTS, 'post_id'); /** * Update the forum, and update the datastore */ //topic_name,topic_uname,post_id,post_created,post_name,post_uname,post_id,post_uid $where = "WHERE forum_id=?"; $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET " . ($this->row_type & TOPIC ? 'topics=topics+1,' : '') . " posts=posts+1,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? {$where}"); $datastore_update = $request['dba']->prepareStatement("UPDATE " . K4DATASTORE . " SET data=? WHERE varname=?"); /* If this isn't a draft, update the forums and datastore tables */ if ($is_draft == 0) { /* Set the forum values */ $forum_update->setInt(1, $created); $forum_update->setString(2, $name); $forum_update->setString(3, $poster_name); $forum_update->setInt(4, $post_id); $forum_update->setInt(5, $request['user']->get('id')); $forum_update->setString(6, $request['user']->get('perms') >= get_map('posticons', 'can_add', array('forum_id' => $forum['forum_id'])) ? isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif' : 'clear.gif'); $forum_update->setInt(7, $forum['forum_id']); /** * Update the forums table and datastore table */ $forum_update->executeUpdate(); } // deal with attachments $t_post = array('post_id' => $post_id, 'parent_id' => $parent_id, 'row_type' => $this->row_type); if ($request['template']->getVar('nojs') == 0) { attach_files($request, $forum, $t_post); } attach_limbo_files($request, $forum, $t_post); /* Added the topic */ if ($is_draft == 0) { /* Set the datastore values */ $datastore = $_DATASTORE['forumstats']; // do we change num topics or replies ? if ($this->row_type & TOPIC) { $datastore['num_topics'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND is_draft=0"); } else { $datastore['num_replies'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . REPLY . " AND is_draft=0"); } $datastore_update->setString(1, serialize($datastore)); $datastore_update->setString(2, 'forumstats'); $datastore_update->executeUpdate(); if ($this->row_type & REPLY) { $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET num_replies=num_replies+1 WHERE post_id=" . $parent_id); } /* Update the user post count */ $request['dba']->executeUpdate("UPDATE " . K4USERINFO . " SET num_posts=num_posts+1,total_posts=total_posts+1 WHERE user_id=" . intval($request['user']->get('id'))); reset_cache('datastore'); /** * Subscribe this user to the topic */ if (isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply']) { $subscribe = $request['dba']->prepareStatement("INSERT INTO " . K4SUBSCRIPTIONS . " (user_id,post_id,forum_id,email) VALUES (?,?,?,?)"); $subscribe->setInt(1, $request['user']->get('id')); $subscribe->setInt(2, $post_id); $subscribe->setInt(3, $forum['forum_id']); $subscribe->setString(4, $request['user']->get('email')); $subscribe->executeUpdate(); } set_send_topic_mail($forum['forum_id'], $poster_name == '' ? $request['template']->getVar('L_GUEST') : $poster_name); /* Commit the current transaction */ $request['dba']->commitTransaction(); if (!USE_XMLHTTP || $this->row_type & TOPIC) { /* Redirect the user */ $action = new K4InformationAction(new K4LanguageElement($this->row_type & TOPIC ? 'L_ADDEDTOPIC' : 'L_ADDEDREPLY', k4_htmlentities($_REQUEST['name'], ENT_QUOTES), $forum['name']), 'content', FALSE, 'findpost.php?id=' . $post_id, 3); return $action->execute($request); } else { global $_URL; /** * Now figure out the annoying stuff to pass to the * page for the javascript to interpret */ $page = 1; if (isset($_REQUEST['page'])) { $page = intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']); } $limit = $request['user']->get('postsperpage') <= 0 ? $forum['postsperpage'] : $request['user']->get('postsperpage'); /* Send a javascript redirect to the browser */ if (ceil(($topic['num_replies'] + 1) / $limit) > $page) { $html = '<div style="text-align:center;"><a href="viewtopic.php?id=' . $topic['post_id'] . '&page=' . ceil(($topic['num_replies'] + 1) / $limit) . '&limit=' . $limit . '&p=' . $post_id . '#p' . $reply_id . '" title="' . $request['template']->getVar('L_SEEYOURPOST') . '" style="font-weight: bold;">' . $request['template']->getVar('L_SEEYOURPOST') . '</a></div><br />'; xmlhttp_header(); echo $html; xmlhttp_footer(); /* Display fancy template */ } else { global $_USERGROUPS, $_PROFILEFIELDS; $result = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE post_id=" . intval($post_id) . " LIMIT 1"); $it =& new PostsIterator($request, $result); $reply = $it->next(); $reply['topic_row'] = 1; $reply['reply_row'] = 1; $reply['row_class'] = 'alt1'; foreach ($topic as $key => $val) { $reply['topic_' . $key] = $val; } foreach ($reply as $key => $val) { $request['template']->setVar($key, $val); } $request['template']->setVisibility('in_topicview', FALSE); $request['template']->setVar('row_class', $topic['num_replies'] % 2 == 0 ? 1 : 2); $templateset = $request['user']->isMember() ? $request['user']->get('templateset') : $forum['defaultstyle']; $html = $request['template']->run(BB_BASE_DIR . '/templates/' . $templateset . '/reply' . ($request['user']->get('topic_display') == 0 ? '' : '_linear') . '.html'); xmlhttp_header(); echo $html; xmlhttp_footer(); } } } else { /* Commit the current transaction */ $request['dba']->commitTransaction(); /* Redirect the user */ $action = new K4InformationAction(new K4LanguageElement('L_SAVEDDRAFTTOPIC', $name, $forum['name']), 'content', FALSE, 'viewforum.php?f=' . $forum['forum_id'], 3); return $action->execute($request); } } else { /** * Post Previewing */ if (!USE_XMLHTTP) { $request['template']->setVar('L_TITLETOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars'))); /* Get and set the emoticons and post icons to the template */ $emoticons = $request['dba']->executeQuery("SELECT * FROM " . K4EMOTICONS . " WHERE clickable = 1"); $posticons = $request['dba']->executeQuery("SELECT * FROM " . K4POSTICONS); /* Add the emoticons and the post icons to the template */ $request['template']->setList('emoticons', $emoticons); $request['template']->setList('posticons', $posticons); /* Set some emoticon information */ $request['template']->setVar('emoticons_per_row', $request['template']->getVar('smcolumns')); $request['template']->setVar('emoticons_per_row_remainder', $request['template']->getVar('smcolumns') - 1); topic_post_options($request['template'], $request['user'], $forum); /* Set the forum info to the template */ foreach ($forum as $key => $val) { $request['template']->setVar('forum_' . $key, $val); } /* Create our editor */ create_editor($request, $_REQUEST['message'], 'post', $forum); $request['template']->setVar('newtopic_action', 'newtopic.php?act=posttopic'); } /* Set topic array items to be passed to the iterator */ $post_preview = array('name' => k4_htmlentities($_REQUEST['name'], ENT_QUOTES), 'body_text' => $body_text, 'poster_name' => $request['user']->get('name'), 'poster_id' => $request['user']->get('id'), 'is_poll' => 0, 'row_left' => 0, 'row_right' => 0, 'post_type' => $post_type, 'is_feature' => $is_feature, 'posticon' => $request['user']->get('perms') >= get_map('posticons', 'can_add', array('forum_id' => $forum['forum_id'])) ? isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif' : 'clear.gif', 'disable_html' => isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'] ? 1 : 0, 'disable_sig' => isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'] ? 0 : 1, 'disable_bbcode' => isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'] ? 1 : 0, 'disable_emoticons' => isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'] ? 1 : 0, 'disable_areply' => isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'] ? 1 : 0, 'disable_aurls' => isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'] ? 1 : 0); /* Assign the topic preview values to the template */ //$post_preview['body_text'] = $_REQUEST['message']; foreach ($post_preview as $key => $val) { $request['template']->setVar('post_' . $key, $val); } /* Assign the forum information to the template */ foreach ($forum as $key => $val) { $request['template']->setVar('forum_' . $key, $val); } $request['template']->setVar('is_topic', $this->row_type & TOPIC ? 1 : 0); if (!USE_XMLHTTP) { /* Set the the button display options */ $request['template']->setVisibility('save_draft', TRUE); $request['template']->setVisibility('edit_topic', TRUE); $request['template']->setVisibility('post_topic', TRUE); $request['template']->setVisibility('post_id', TRUE); /* Should she show/hide the 'load draft' button? */ $drafts = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE forum_id=" . intval($forum['forum_id']) . " AND is_draft=1 AND poster_id=" . intval($request['user']->get('id'))); if ($drafts->numrows() > 0) { $request['template']->setVisibility('load_button', TRUE); } else { $request['template']->setVisibility('load_button', FALSE); } /* Set the post topic form */ $request['template']->setVar('forum_forum_id', $forum['forum_id']); $request['template']->setFile('preview', 'post_preview.html'); $request['template']->setFile('content', 'newtopic.html'); } else { $templateset = $request['user']->isMember() ? $request['user']->get('templateset') : $forum['defaultstyle']; $html = $request['template']->run(BB_BASE_DIR . '/templates/' . $templateset . '/post_preview.html'); xmlhttp_header(); echo $html; xmlhttp_footer(); } } } else { no_perms_error($request); } return TRUE; }