New Post module | > Module written by Matt Mecham | +-------------------------------------------------------------------------- */ class post_functions extends Post { var $nav = array(); var $title = ""; var $post = array(); var $topic = array(); var $upload = array(); var $mod_topic = array(); var $poll_count = 0; var $poll_choices = ""; var $m_group = ""; function post_functions($class) { global $ibforums, $std, $DB; //------------------------------------------------------------------------- // Sort out maximum number of poll choices allowed //------------------------------------------------------------------------- $ibforums->vars['max_poll_choices'] = $ibforums->vars['max_poll_choices'] ? $ibforums->vars['max_poll_choices'] : 10; $ibforums->lang['poll_choices'] = sprintf( $ibforums->lang['poll_choices'], $ibforums->vars['max_poll_choices'] ); //------------------------------------------------------------------------- // Lets do some tests to make sure that we are allowed to start a new topic //------------------------------------------------------------------------- if (! $ibforums->member['g_post_polls']) { $std->Error( array( LEVEL => 1, MSG => 'no_start_polls') ); } if ( ! $class->forum['allow_poll'] ) { $std->Error( array( LEVEL => 1, MSG => 'no_start_polls') ); } $this->m_group = $ibforums->perm_id; if ( $std->check_perms($class->forum['start_perms']) != TRUE ) { $std->Error( array( LEVEL => 1, MSG => 'no_start_polls') ); } } function process($class) { global $ibforums, $std, $DB, $print; //------------------------------------------------- // Parse the post, and check for any errors. //------------------------------------------------- $this->post = $class->compile_post(); //------------------------------------------------- // check to make sure we have a valid topic title //------------------------------------------------- if ( (strlen($ibforums->input['TopicTitle']) < 2) or (!$ibforums->input['TopicTitle']) ) { $class->obj['post_errors'] = 'no_topic_title'; } //------------------------------------------------- // More unicode.. //------------------------------------------------- $temp = $std->txt_stripslashes($HTTP_POST_VARS['TopicTitle']); $temp = preg_replace("/&#([0-9]+);/", "-", $temp ); if ( strlen($temp) > 64 ) { $class->obj['post_errors'] = 'topic_title_long'; } //------------------------------------------------- // check to make sure we have a correct # of choices //------------------------------------------------- $this->poll_choices = $ibforums->input['PollAnswers']; $this->poll_choices = preg_replace( "/

/" , "" , $this->poll_choices ); $this->poll_choices = preg_replace( "/
/e" , "\$this->regex_count_choices()" , $this->poll_choices ); if ($this->poll_count > $ibforums->vars['max_poll_choices']) { $class->obj['post_errors'] = 'poll_to_many'; } if ($this->poll_count < 1) { $class->obj['post_errors'] = 'poll_not_enough'; } //------------------------------------------------- // If we don't have any errors yet, parse the upload //------------------------------------------------- if ($class->obj['post_errors'] == "") { $this->upload = $class->process_upload(); } if ( ($class->obj['post_errors'] != "") or ($class->obj['preview_post'] != "") ) { // Show the form again $this->show_form($class); } else { $this->add_new_poll($class); } } function add_new_poll($class) { global $ibforums, $std, $DB, $print; //------------------------------------------------- // Sort out the poll stuff // This is somewhat contrived, but it has to be // compatible with the current perl version. //------------------------------------------------- $poll_array = array(); $count = 0; $polls = explode( "
", $this->poll_choices ); foreach ($polls as $polling) { if ( $polling == "" ) { continue; } $poll_array[] = array( $count , $class->parser->bad_words($polling), 0 ); $count++; } //------------------------------------------------- // Fix up the topic title //------------------------------------------------- if ($ibforums->vars['etfilter_punct']) { $ibforums->input['TopicTitle'] = preg_replace( "/\?{1,}/" , "?" , $ibforums->input['TopicTitle'] ); $ibforums->input['TopicTitle'] = preg_replace( "/(!){1,}/", "!" , $ibforums->input['TopicTitle'] ); } if ($ibforums->vars['etfilter_shout']) { $ibforums->input['TopicTitle'] = ucwords($ibforums->input['TopicTitle']); } $ibforums->input['TopicTitle'] = $class->parser->bad_words( $ibforums->input['TopicTitle'] ); $ibforums->input['TopicDesc'] = $class->parser->bad_words( $ibforums->input['TopicDesc'] ); if ( $ibforums->vars['poll_disable_noreply'] != 1 ) { $poll_state = $ibforums->input['allow_disc'] == 0 ? 'open' : 'closed'; } else { $poll_state = 'open'; } //------------------------------------------------- // Build the master array //------------------------------------------------- $this->topic = array( 'title' => $ibforums->input['TopicTitle'], 'description' => $ibforums->input['TopicDesc'] , 'state' => 'open', 'posts' => 0, 'starter_id' => $ibforums->member['id'], 'starter_name' => $ibforums->member['id'] ? $ibforums->member['name'] : $ibforums->input['UserName'], 'start_date' => time(), 'last_poster_id' => $ibforums->member['id'], 'last_poster_name' => $ibforums->member['id'] ? $ibforums->member['name'] : $ibforums->input['UserName'], 'last_post' => time(), 'icon_id' => $ibforums->input['iconid'], 'author_mode' => $ibforums->member['id'] ? 1 : 0, 'poll_state' => $poll_state, 'last_vote' => 0, 'views' => 0, 'forum_id' => $class->forum['id'], 'approved' => $class->obj['moderate'] ? 0 : 1, 'pinned' => 0, ); //------------------------------------------------- // Insert the topic into the database to get the // last inserted value of the auto_increment field // follow suit with the post //------------------------------------------------- $db_string = $DB->compile_db_insert_string( $this->topic ); $DB->query("INSERT INTO ibf_topics (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")"); $this->post['topic_id'] = $DB->get_insert_id(); $this->topic['tid'] = $this->post['topic_id']; /*---------------------------------------------------*/ // Update the post info with the upload array info $this->post['attach_id'] = $this->upload['attach_id']; $this->post['attach_type'] = $this->upload['attach_type']; $this->post['attach_hits'] = $this->upload['attach_hits']; $this->post['new_topic'] = 1; //------------------------------------------------- // Unqueue the post if we're starting a new topic //------------------------------------------------- if ( $class->obj['moderate'] == 3 ) { $this->post['queued'] = 0; } $db_string = $DB->compile_db_insert_string( $this->post ); $DB->query("INSERT INTO ibf_posts (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")"); $this->post['pid'] = $DB->get_insert_id(); //------------------------------------------------- // Add the poll to the forum_polls table // if we are moderating this post //------------------------------------------------- $db_string = $std->compile_db_string( array ( 'tid' => $this->topic['tid'], 'forum_id' => $class->forum['id'], 'start_date' => time(), 'choices' => addslashes(serialize($poll_array)), 'starter_id' => $ibforums->member['id'], 'votes' => 0, 'poll_question' => $class->parser->bad_words($ibforums->input['pollq']), ) ); $DB->query("INSERT INTO ibf_polls (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")"); if ( $class->obj['moderate'] == 1 OR $class->obj['moderate'] == 2 ) { // Redirect them with a message telling them the post has to be previewed first $DB->query("UPDATE ibf_forums SET has_mod_posts=1 WHERE id=".$class->forum['id']); $class->notify_new_topic_approval( $this->topic['tid'], $this->topic['title'], $this->topic['starter_name'] ); $print->redirect_screen( $ibforums->lang['moderate_topic'], "act=SF&f={$class->forum['id']}" ); } //------------------------------------------------- // If we are still here, lets update the // board/forum stats //------------------------------------------------- $class->forum['last_title'] = $this->topic['title']; $class->forum['last_id'] = $this->topic['tid']; $class->forum['last_post'] = time(); $class->forum['last_poster_name'] = $ibforums->member['id'] ? $ibforums->member['name'] : $ibforums->input['UserName']; $class->forum['last_poster_id'] = $ibforums->member['id']; $class->forum['topics']++; // Update the database $DB->query("UPDATE ibf_forums SET last_title='" .$class->forum['last_title'] ."', ". "last_id='" .$class->forum['last_id'] ."', ". "last_post='" .$class->forum['last_post'] ."', ". "last_poster_name='".$class->forum['last_poster_name'] ."', ". "last_poster_id='" .$class->forum['last_poster_id'] ."', ". "topics='" .$class->forum['topics'] ."' ". "WHERE id='" .$class->forum['id'] ."'"); // At this point in time, we'll scan the database for the correct number // of topics - if this proves to database intensive, we'll simply increment // the value stored in the ibf_stats database. $DB->query("SELECT COUNT(tid) as topic_cnt FROM ibf_topics"); $stats = $DB->fetch_row(); $DB->query("UPDATE ibf_stats SET TOTAL_TOPICS='".$stats['topic_cnt']."'"); //------------------------------------------------- // If we are a member, lets update thier last post // date and increment their post count. //------------------------------------------------- $pcount = ""; if ($ibforums->member['id']) { if ($class->forum['inc_postcount']) { // Increment the users post count $pcount = "posts=posts+1, "; } // Are we checking for auto promotion? if ($ibforums->member['g_promotion'] != '-1&-1') { list($gid, $gposts) = explode( '&', $ibforums->member['g_promotion'] ); if ( $gid > 0 and $gposts > 0 ) { if ( $ibforums->member['posts'] + 1 >= $gposts ) { $mgroup = "mgroup='$gid', "; if ( USE_MODULES == 1 ) { $class->modules->register_class(&$class); $class->modules->on_group_change($ibforums->member['id'], $gid); } } } } $ibforums->member['last_post'] = time(); $DB->query("UPDATE ibf_members SET ".$pcount.$mgroup. "last_post='" .$ibforums->member['last_post'] ."'". "WHERE id='" .$ibforums->member['id']."'"); } //------------------------------------------------- // Set a last post time cookie //------------------------------------------------- $std->my_setcookie( "LPid", time() ); //------------------------------------------------- // Redirect them back to the topic //------------------------------------------------- $std->boink_it($class->base_url."act=ST&f={$class->forum['id']}&t={$this->topic['tid']}"); } function show_form($class) { global $ibforums, $std, $DB, $print, $HTTP_POST_VARS; // Sort out the "raw" textarea input and make it safe incase // we have a