$Date: 2008-10-02 12:04:59 -0400 (Thu, 02 Oct 2008) $
| > $Revision: 2573 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > Post Sub-Class
| > Module written by Matt Mecham
| > Date started: Wednesday 9th March 2005 (15:23)
|
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_IPB' ) )
{
print "
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class post_functions extends class_post
{
var $nav = array();
var $title = "";
var $post = array();
var $upload = array();
var $mod_topic = array();
var $class = "";
var $m_group = "";
var $post_key = "";
var $has_poll = 0;
var $poll_questions = array();
var $orig_post;
/*-------------------------------------------------------------------------*/
// Sub class init
/*-------------------------------------------------------------------------*/
function main_init()
{
//-----------------------------------------
// Load classes
//-----------------------------------------
$this->load_classes();
$this->build_permissions();
//-----------------------------------------
// Check permissions
//-----------------------------------------
$this->post_key = ( isset($this->ipsclass->input['attach_post_key']) AND $this->ipsclass->input['attach_post_key'] != "" ) ? $this->ipsclass->input['attach_post_key'] : md5( microtime() );
$this->check_for_new_topic();
}
/*-------------------------------------------------------------------------*/
// MAIN PROCESS FUNCTION
/*-------------------------------------------------------------------------*/
function process_post()
{
//-----------------------------------------
// Convert times...
//-----------------------------------------
$this->convert_open_close_times();
//-----------------------------------------
// Parse the post, and check for any errors.
//-----------------------------------------
$this->post = $this->compile_post();
//-----------------------------------------
// check to make sure we have a valid topic title
//-----------------------------------------
$this->ipsclass->input['TopicTitle'] = str_replace( "
", "", $this->ipsclass->input['TopicTitle'] );
$this->ipsclass->input['TopicTitle'] = trim($this->ipsclass->input['TopicTitle']);
//-----------------------------------------
// More unicode..
//-----------------------------------------
$temp = $this->ipsclass->txt_stripslashes($_POST['TopicTitle']);
if ( $this->ipsclass->txt_mb_strlen($_POST['TopicTitle']) > $this->ipsclass->vars['topic_title_max_len'] )
{
$this->obj['post_errors'] = 'topic_title_long';
}
if ( (strlen($temp) < 2) or (!$this->ipsclass->input['TopicTitle']) )
{
$this->obj['post_errors'] = 'no_topic_title';
}
//-----------------------------------------
// Compile the poll
//-----------------------------------------
$this->poll_questions = $this->compile_poll();
if ( ($this->obj['post_errors'] != "") or ( $this->obj['preview_post'] != "" ) )
{
//-----------------------------------------
// Show the form again
//-----------------------------------------
$this->show_form();
}
else
{
//-----------------------------------------
// Guest w/ CAPTCHA?
//-----------------------------------------
if( $this->ipsclass->member['id'] == 0 AND $this->ipsclass->vars['guest_captcha'] )
{
if ($this->ipsclass->vars['bot_antispam'])
{
// Validate CAPTCHA
require_once( KERNEL_PATH . 'class_captcha.php' );
$captchaClass = new class_captcha( $this->ipsclass, $this->ipsclass->vars['bot_antispam_type'] );
if ( $captchaClass->validate() !== TRUE )
{
$this->obj['post_errors'] = 'err_reg_code';
$this->show_form();
return;
}
}
}
$this->save_post();
}
}
/*-------------------------------------------------------------------------*/
// ADD TOPIC FUNCTION
/*-------------------------------------------------------------------------*/
function save_post()
{
//-----------------------------------------
// Fix up the topic title
//-----------------------------------------
$this->ipsclass->input['TopicTitle'] = $this->pf_clean_topic_title( $this->ipsclass->input['TopicTitle'] );
$this->ipsclass->input['TopicTitle'] = $this->parser->bad_words( $this->ipsclass->input['TopicTitle'] );
$this->ipsclass->input['TopicDesc'] = trim( $this->parser->bad_words( $this->ipsclass->input['TopicDesc'] ) );
$this->ipsclass->input['TopicDesc'] = $this->ipsclass->txt_mbsubstr( $this->ipsclass->input['TopicDesc'], 0, 70 );
$pinned = 0;
$state = 'open';
$this->ipsclass->input['mod_options'] = isset($this->ipsclass->input['mod_options']) ? $this->ipsclass->input['mod_options'] : '';
if ( ($this->ipsclass->input['mod_options'] != "") or ($this->ipsclass->input['mod_options'] != 'nowt') )
{
if ($this->ipsclass->input['mod_options'] == 'pin')
{
if ($this->ipsclass->member['g_is_supmod'] == 1 or $this->moderator['pin_topic'] == 1)
{
$pinned = 1;
$this->moderate_log( $this->ipsclass->lang['modlogs_pinned'], $this->ipsclass->input['TopicTitle']);
}
}
else if ($this->ipsclass->input['mod_options'] == 'close')
{
if ($this->ipsclass->member['g_is_supmod'] == 1 or $this->moderator['close_topic'] == 1)
{
$state = 'closed';
$this->moderate_log( $this->ipsclass->lang['modlogs_closed'], $this->ipsclass->input['TopicTitle']);
}
}
else if ($this->ipsclass->input['mod_options'] == 'pinclose')
{
if ($this->ipsclass->member['g_is_supmod'] == 1 or ( $this->moderator['pin_topic'] == 1 AND $this->moderator['close_topic'] == 1 ) )
{
$pinned = 1;
$state = 'closed';
$this->moderate_log( $this->ipsclass->lang['modlogs_pinclose'], $this->ipsclass->input['TopicTitle']);
}
}
}
//-----------------------------------------
// Check close times...
//-----------------------------------------
if ( $state == 'open' AND ( $this->times['open'] OR $this->times['close'] )
AND ( $this->times['close'] <= time() OR ( $this->times['open'] > time() AND !$this->times['close'] ) ) )
{
$state = 'closed';
}
//-----------------------------------------
// Build the master array
//-----------------------------------------
$this->topic = array(
'title' => $this->ipsclass->input['TopicTitle'],
'description' => $this->ipsclass->input['TopicDesc'] ,
'state' => $state,
'posts' => 0,
'starter_id' => $this->ipsclass->member['id'],
'starter_name' => $this->ipsclass->member['id'] ? $this->ipsclass->member['members_display_name'] : $this->ipsclass->input['UserName'],
'start_date' => time(),
'last_poster_id' => $this->ipsclass->member['id'],
'last_poster_name' => $this->ipsclass->member['id'] ? $this->ipsclass->member['members_display_name'] : $this->ipsclass->input['UserName'],
'last_post' => time(),
'icon_id' => intval($this->ipsclass->input['iconid']),
'author_mode' => $this->ipsclass->member['id'] ? 1 : 0,
'poll_state' => ( count( $this->poll_questions ) AND $this->can_add_poll ) ? 1 : 0,
'last_vote' => 0,
'views' => 0,
'forum_id' => $this->forum['id'],
'approved' => ( $this->obj['moderate'] == 1 || $this->obj['moderate'] == 2 ) ? 0 : 1,
'pinned' => $pinned,
'topic_open_time' => intval( $this->times['open'] ),
'topic_close_time' => intval( $this->times['close'] ),
);
//-----------------------------------------
// Insert the topic into the database to get the
// last inserted value of the auto_increment field
// follow suit with the post
//-----------------------------------------
$this->ipsclass->DB->force_data_type = array( 'title' => 'string',
'description' => 'string',
'starter_name' => 'string',
'last_poster_name' => 'string' );
$this->ipsclass->DB->do_insert( 'topics', $this->topic );
$this->post['topic_id'] = $this->ipsclass->DB->get_insert_id();
$this->topic['tid'] = $this->post['topic_id'];
//-----------------------------------------
// Update the post info with the upload array info
//-----------------------------------------
$this->post['post_key'] = $this->post_key;
$this->post['new_topic'] = 1;
//-----------------------------------------
// Unqueue the post if we're starting a new topic
//-----------------------------------------
$this->post['queued'] = 0;
//-----------------------------------------
// Add post to DB
//-----------------------------------------
$this->ipsclass->DB->do_insert( 'posts', $this->post );
$this->post['pid'] = $this->ipsclass->DB->get_insert_id();
//-----------------------------------------
// Update topic with firstpost ID
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'update' => 'topics',
'set' => "topic_firstpost=".$this->post['pid'],
'where' => "tid=".$this->topic['tid']
) );
$this->ipsclass->DB->simple_exec();
//-----------------------------------------
// Add the poll to the polls table
//-----------------------------------------
if ( count( $this->poll_questions ) AND $this->can_add_poll )
{
$poll_only = 0;
if( $this->ipsclass->vars['ipb_poll_only'] AND $this->ipsclass->input['poll_only'] == 1 )
{
$poll_only = 1;
}
$this->ipsclass->DB->do_insert( 'polls',
array (
'tid' => $this->topic['tid'],
'forum_id' => $this->forum['id'],
'start_date' => time(),
'choices' => addslashes(serialize( $this->poll_questions )),
'starter_id' => $this->ipsclass->member['id'],
'votes' => 0,
'poll_question' => $this->ipsclass->input['poll_question'],
'poll_only' => $poll_only,
) );
}
//-----------------------------------------
// If we are still here, lets update the
// board/forum stats
//-----------------------------------------
$this->pf_update_forum_and_stats($this->topic['tid'], $this->topic['title'], 'new');
//-----------------------------------------
// Make attachments "permanent"
//-----------------------------------------
$this->pf_make_attachments_permanent( $this->post_key, $this->post['pid'], 'post', array( 'topic_id' => $this->topic['tid'] ) );
//-----------------------------------------
// If we are a member, lets update thier last post
// date and increment their post count.
//-----------------------------------------
$this->pf_increment_user_post_count();
//-----------------------------------------
// Are we tracking new topics we start 'auto_track'?
//-----------------------------------------
$this->pf_add_tracked_topic($this->topic['tid']);
//-----------------------------------------
// Moderating?
//-----------------------------------------
if ( $this->obj['moderate'] == 1 OR $this->obj['moderate'] == 2 )
{
//-----------------------------------------
// Redirect them with a message telling them the
// post has to be previewed first
//-----------------------------------------
$this->notify_new_topic_approval( $this->topic['tid'], $this->topic['title'], $this->topic['starter_name'], $this->post['pid'] );
$this->ipsclass->print->redirect_screen( $this->ipsclass->lang['moderate_topic'], "act=SF&f={$this->forum['id']}" );
}
//-----------------------------------------
// Are we tracking this forum? If so generate some mailies - yay!
//-----------------------------------------
$this->forum_tracker($this->forum['id'], $this->topic['tid'], $this->topic['title'], $this->forum['name'], $this->post['post'] );
//-----------------------------------------
// Redirect them back to the topic
//-----------------------------------------
$this->ipsclass->boink_it($this->ipsclass->base_url."showtopic={$this->topic['tid']}");
}
/*-------------------------------------------------------------------------*/
// SHOW FORM
/*-------------------------------------------------------------------------*/
function show_form()
{
//-----------------------------------------
// Are we quoting posts?
//-----------------------------------------
if ( $this->han_editor->method != 'rte' )
{
$_POST['Post'] = str_replace( '&', '&', $_POST['Post'] );
}
$raw_post = $this->check_multi_quote();
//-----------------------------------------
// RTE? Convert RIGHT tags that QUOTE would
// have put there
//-----------------------------------------
if ( $this->han_editor->method == 'rte' )
{
$raw_post = $this->parser->convert_ipb_html_to_html( $raw_post );
}
//-----------------------------------------
// Sort out the "raw" textarea input and make it safe incase
// we have a