Post core module
| > Module written by Matt Mecham
| > Date started: 14th February 2002
|
| > Module Version 1.0.0
| > DBA Checked: Thu 20 May 2004
| > Quality Checked: Wed 15 Sept. 2004
+--------------------------------------------------------------------------
*/
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 {
var $output = "";
var $base_url = "";
var $html = "";
var $parser = "";
var $moderator = array();
var $forum = array();
var $topic = array();
var $category = array();
var $mem_groups = array();
var $mem_titles = array();
var $obj = array();
var $email = "";
var $can_upload = 0;
var $md5_check = "";
var $module = "";
var $attach_sum = -1;
/*-------------------------------------------------------------------------*/
// INIT
/*-------------------------------------------------------------------------*/
function init()
{
global $ibforums, $forums, $DB, $std, $print, $skin_universal;
//-----------------------------------------
// Load and config the post parser
//-----------------------------------------
require_once( ROOT_PATH."sources/lib/post_parser.php" );
$this->parser = new post_parser(1);
$this->parser->bypass_badwords = intval($ibforums->member['g_bypass_badwords']);
//-----------------------------------------
// Load the email libby
//-----------------------------------------
require_once( ROOT_PATH."sources/classes/class_email.php" );
$this->email = new emailer();
//-----------------------------------------
// Compile the language file
//-----------------------------------------
$ibforums->lang = $std->load_words($ibforums->lang, 'lang_post', $ibforums->lang_id);
$this->html = $std->load_template('skin_post');
}
/*-------------------------------------------------------------------------*/
//
// Our constructor, load words, load skin, print the topic listing
//
/*-------------------------------------------------------------------------*/
function auto_run()
{
global $ibforums, $forums, $DB, $std, $print, $skin_universal;
$this->init();
//-----------------------------------------
// Get the sync module
//-----------------------------------------
if ( USE_MODULES == 1 )
{
require ROOT_PATH."modules/ipb_member_sync.php";
$this->modules = new ipb_member_sync();
}
//-----------------------------------------
// Check the input
//-----------------------------------------
$this->md5_check = $std->return_md5_check();
if ($ibforums->input['t'])
{
$ibforums->input['t'] = intval($ibforums->input['t']);
if (! $ibforums->input['t'] )
{
$std->Error( array( LEVEL => 1, MSG => 'missing_files') );
}
}
if ($ibforums->input['p'])
{
$ibforums->input['p'] = intval($ibforums->input['p']);
if (! $ibforums->input['p'] )
{
$std->Error( array( LEVEL => 1, MSG => 'missing_files') );
}
}
$ibforums->input['f'] = intval($ibforums->input['f']);
if (! $ibforums->input['f'] )
{
$std->Error( array( LEVEL => 1, MSG => 'missing_files') );
}
$ibforums->input['st'] = $ibforums->input['st'] ?intval($ibforums->input['st']) : 0;
// Did the user press the "preview" button?
$this->obj['preview_post'] = $ibforums->input['preview'];
//-----------------------------------------
// Get the forum info based
//-----------------------------------------
$this->forum = $forums->forum_by_id[ $ibforums->input['f'] ];
//-----------------------------------------
// Can we upload stuff?
//-----------------------------------------
if ( $std->check_perms($this->forum['upload_perms']) == TRUE )
{
if ( $ibforums->member['g_attach_max'] != -1 )
{
$this->can_upload = 1;
$this->obj['form_extra'] = " enctype='multipart/form-data'";
$this->obj['hidden_field'] = "";
}
}
//-----------------------------------------
// Is this forum switched off?
//-----------------------------------------
if ( ! $this->forum['status'] )
{
$std->Error( array( LEVEL => 1, MSG => 'forum_read_only') );
}
//-----------------------------------------
// Check access
//-----------------------------------------
$forums->forums_check_access( $this->forum['id'], 1 );
//-----------------------------------------
// Get navigation station
//-----------------------------------------
$this->nav = $forums->forums_breadcrumb_nav( $this->forum['id'] );
//-----------------------------------------
// Error out if we can not find the forum
//-----------------------------------------
if (!$this->forum['id'])
{
$std->Error( array( LEVEL => 1, MSG => 'missing_files') );
}
$this->base_url = $ibforums->base_url;
//-----------------------------------------
// Is this forum moderated?
//-----------------------------------------
$this->obj['moderate'] = intval($this->forum['preview_posts']);
// Can we bypass it?
if ($ibforums->member['g_avoid_q'])
{
$this->obj['moderate'] = 0;
}
//-----------------------------------------
// Does this member have mod_posts enabled?
//-----------------------------------------
if ( $ibforums->member['mod_posts'] )
{
if ( $ibforums->member['mod_posts'] == 1 )
{
$this->obj['moderate'] = 1;
}
else
{
$mod_arr = $std->hdl_ban_line( $ibforums->member['mod_posts'] );
if ( time() >= $mod_arr['date_end'] )
{
// Update this member's profile
$DB->simple_construct( array( 'update' => 'members',
'set' => 'mod_posts=0',
'where' => "id=".intval($ibforums->member['id'])
) );
$DB->simple_exec();
$this->obj['moderate'] = intval($this->forum['preview_posts']);
}
else
{
$this->obj['moderate'] = 1;
}
}
}
//-----------------------------------------
// Are we allowed to post at all?
//-----------------------------------------
if ($ibforums->member['id'])
{
if ( $ibforums->member['restrict_post'] )
{
if ( $ibforums->member['restrict_post'] == 1 )
{
$std->Error( array( LEVEL => 1, MSG => 'posting_off') );
}
$post_arr = $std->hdl_ban_line( $ibforums->member['restrict_post'] );
if ( time() >= $post_arr['date_end'] )
{
// Update this member's profile
$DB->simple_construct( array( 'update' => 'members',
'set' => 'restrict_post=0',
'where' => "id=".intval($ibforums->member['id'])
) );
$DB->simple_exec();
}
else
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'posting_off_susp', 'EXTRA' => $std->get_date($post_arr['date_end'], 'LONG') ) );
}
}
// Flood check..
if ( $ibforums->input['CODE'] != "08" and $ibforums->input['CODE'] != "09" and $ibforums->input['CODE'] != "14" and $ibforums->input['CODE'] != "15" )
{
if ( $ibforums->vars['flood_control'] > 0 )
{
if ($ibforums->member['g_avoid_flood'] != 1)
{
if ( time() - $ibforums->member['last_post'] < $ibforums->vars['flood_control'] )
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'flood_control' , 'EXTRA' => $ibforums->vars['flood_control'] ) );
}
}
}
}
}
else if ( $ibforums->is_bot == 1 )
{
$std->Error( array( LEVEL => 1, MSG => 'posting_off') );
}
if ($ibforums->member['id'] != 0 and $ibforums->member['g_is_supmod'] == 0)
{
$DB->cache_add_query('topics_check_for_mod', array( 'fid' => $this->forum['id'], 'mid' => $ibforums->member['id'], 'gid' => $ibforums->member['mgroup'] ) );
$DB->simple_exec();
$this->moderator = $DB->fetch_row();
}
//-----------------------------------------
// Convert the code ID's into something
// use mere mortals can understand....
//-----------------------------------------
$this->obj['action_codes'] = array ( '00' => array( '0' , 'new_post' ),
'01' => array( '1' , 'new_post' ),
'02' => array( '0' , 'reply_post' ),
'03' => array( '1' , 'reply_post' ),
'08' => array( '0' , 'edit_post' ),
'09' => array( '1' , 'edit_post' ),
'10' => array( '0' , 'poll' ),
'11' => array( '1' , 'poll' ),
'14' => array( '0' , 'poll_after' ),
'15' => array( '1' , 'poll_after' ),
);
//-----------------------------------------
// Make sure our input CODE element is legal.
//-----------------------------------------
if (! isset($this->obj['action_codes'][ $ibforums->input['CODE'] ]) )
{
$std->Error( array( LEVEL => 1, MSG => 'missing_files') );
}
//-----------------------------------------
// Require and run our associated library file for this action.
// this imports an extended class for this Post class.
//-----------------------------------------
require ROOT_PATH."sources/lib/post_" . $this->obj['action_codes'][ $ibforums->input['CODE'] ][1] . ".php";
$post_functions = new post_functions(&$this);
//-----------------------------------------
// If the first CODE array bit is set to "0" - show the relevant form.
// If it's set to "1" process the input.
//
// We pass a reference to this classes object so we can manipulate this classes
// data from our sub class.
//-----------------------------------------
if ($this->obj['action_codes'][ $ibforums->input['CODE'] ][0])
{
//-----------------------------------------
// Make sure we have a valid auth key
//-----------------------------------------
if ( $ibforums->input['auth_key'] != $this->md5_check )
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'del_post') );
}
//-----------------------------------------
// Make sure we have a "Guest" Name..
//-----------------------------------------
if (!$ibforums->member['id'])
{
$ibforums->input['UserName'] = trim($ibforums->input['UserName']);
$ibforums->input['UserName'] = str_replace( "
", "", $ibforums->input['UserName']);
$ibforums->input['UserName'] = $ibforums->input['UserName'] ? $ibforums->input['UserName'] : 'Guest';
if ($ibforums->input['UserName'] != 'Guest')
{
$DB->cache_add_query( 'login_getmember', array( 'username' => trim(strtolower($ibforums->input['UserName'])) ) );
$DB->cache_exec_query();
if ( $DB->get_num_rows() )
{
$ibforums->input['UserName'] = $ibforums->vars['guest_name_pre'].$ibforums->input['UserName'].$ibforums->vars['guest_name_suf'];
}
}
}
//-----------------------------------------
// Stop the user hitting the submit button in the hope that multiple topics
// or replies will be added. Or if the user accidently hits the button
// twice.
//-----------------------------------------
if ( $this->obj['preview_post'] == "" )
{
if ( preg_match( "/Post,.*,(01|03|07|11)$/", $ibforums->location ) )
{
if ( time() - $ibforums->lastclick < 2 )
{
if ( $ibforums->input['CODE'] == '01' or $ibforums->input['CODE'] == '11' )
{
//-----------------------------------------
// Redirect to the newest topic in the forum
//-----------------------------------------
$DB->simple_construct( array( 'select' => 'tid',
'from' => 'topics',
'where' => "forum_id='".$this->forum['id']."' AND approved=1",
'order' => 'last_post DESC',
'limit' => array( 0, 1 )
) );
$DB->simple_exec();
$topic = $DB->fetch_row();
$std->boink_it($ibforums->base_url."act=ST&f=".$this->forum['id']."&t=".$topic['tid']);
exit();
}
else
{
//-----------------------------------------
// It's a reply, so simply show the topic...
//-----------------------------------------
$std->boink_it($ibforums->base_url."act=ST&f=".$this->forum['id']."&t=".$ibforums->input['t']."&view=getlastpost");
exit();
}
}
}
}
//-----------------------------------------
$post_functions->process(&$this);
}
else
{
$post_functions->show_form(&$this);
}
}
/*-------------------------------------------------------------------------*/
// Notify new topic mod Q
// ----------------------
/*-------------------------------------------------------------------------*/
function notify_new_topic_approval($tid, $title, $author, $pid=0, $type='new')
{
global $ibforums, $DB, $std;
$tmp = $DB->simple_exec_query( array( 'select' => 'notify_modq_emails', 'from' => 'forums', 'where' => "id=".$this->forum['id']) );
if ( $tmp['notify_modq_emails'] == "" )
{
return;
}
if ( $type == 'new' )
{
$this->email->get_template("new_topic_queue_notify");
}
else
{
$this->email->get_template("new_post_queue_notify");
}
$this->email->build_message( array(
'TOPIC' => $title,
'FORUM' => $this->forum['name'],
'POSTER' => $author,
'DATE' => $std->get_date( time(), 'SHORT' ),
'LINK' => $ibforums->vars['board_url'].'/index.'.$ibforums->vars['php_ext'].'?act=findpost&pid='.$pid,
)
);
foreach( explode( ",", $tmp['notify_modq_emails'] ) as $email )
{
$this->email->to = trim($email);
$this->email->send_mail();
}
}
/*-------------------------------------------------------------------------*/
// topic tracker
// ------------------
// Checks and sends out the emails as needed.
/*-------------------------------------------------------------------------*/
function topic_tracker($tid="", $post="", $poster="", $last_post="" )
{
global $ibforums, $DB, $std;
if ($tid == "")
{
return TRUE;
}
$count = 0;
//-----------------------------------------
// Get the email addy's, topic ids and email_full stuff - oh yeah.
// We only return rows that have a member last_activity of greater than the post itself
// Ergo:
// Last topic post: 8:50am
// Last topic visit: 9:00am
// Next topic reply: 9:10am
// if ( last.activity > last.topic.post ) { send.... }
// Next topic reply: 9:20am
// if ( last.activity > last.topic.post ) { will fail as 9:10 > 8:50 }
//-----------------------------------------
$DB->cache_add_query( 'post_topic_tracker', array( 'tid' => $tid, 'mid' => $ibforums->member['id'], 'last_post' => $last_post ) );
$outer = $DB->simple_exec();
if ( $DB->get_num_rows($outer) )
{
$trids = array();
while ( $r = $DB->fetch_row($outer) )
{
$count++;
$r['language'] = $r['language'] ? $r['language'] : 'en';
if ($r['email_full'] == 1)
{
$this->email->get_template("subs_with_post", $r['language']);
$this->email->build_message( array(
'TOPIC_ID' => $r['topic_id'],
'FORUM_ID' => $r['forum_id'],
'TITLE' => $r['title'],
'NAME' => $r['name'],
'POSTER' => $poster,
'POST' => $post,
)
);
}
else
{
$this->email->get_template("subs_no_post", $r['language']);
$this->email->build_message( array(
'TOPIC_ID' => $r['topic_id'],
'FORUM_ID' => $r['forum_id'],
'TITLE' => $r['title'],
'NAME' => $r['name'],
'POSTER' => $poster,
)
);
}
$trids[] = $r['trid'];
//-----------------------------------------
// Add to mail queue
//-----------------------------------------
$DB->do_insert( 'mail_queue', array( 'mail_to' => $r['email'], 'mail_date' => time(), 'mail_subject' => $ibforums->lang['tt_subject'], 'mail_content' => $this->email->message ) );
}
$ibforums->cache['systemvars']['mail_queue'] += $count;
//-----------------------------------------
// Update cache with remaning email count
//-----------------------------------------
$DB->do_update( 'cache_store', array( 'cs_array' => 1, 'cs_value' => addslashes(serialize($ibforums->cache['systemvars'])) ), "cs_key='systemvars'" );
}
return TRUE;
}
/*-------------------------------------------------------------------------*/
// Forum tracker
// ------------------
// Checks and sends out the new topic notification if
// needed
/*-------------------------------------------------------------------------*/
function forum_tracker($fid="", $this_tid="", $title="", $forum_name="", $post="")
{
global $ibforums, $DB, $std;
if ($this_tid == "")
{
return TRUE;
}
if ($fid == "")
{
return TRUE;
}
//-----------------------------------------
// Work out the time stamp needed to "guess"
// if the user is still active on the board
// We will base this guess on a period of
// non activity of time_now - 30 minutes.
//-----------------------------------------
$time_limit = time() - (30*60);
$count = 0;
$gotem = array();
$DB->cache_add_query( 'post_forum_tracker', array( 'fid' => $fid,
'mid' => $ibforums->member['id'],
'last_post' => $time_limit ) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$gotem[ $r['id'] ] = $r;
}
//-----------------------------------------
// Get "all" groups?
//-----------------------------------------
if ( $ibforums->vars['autoforum_sub_groups'] )
{
$DB->cache_add_query( 'post_forum_tracker_all', array( 'groups' => $ibforums->vars['autoforum_sub_groups'],
'last_post' => $time_limit,
'mid' => $ibforums->member['id'] ) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$gotem[ $r['id'] ] = $r;
}
}
//-----------------------------------------
// Row, row and parse, parse
//-----------------------------------------
if ( count( $gotem ) )
{
foreach( $gotem as $mid => $r )
{
$count++;
$perm_id = ( $r['org_perm_id'] ) ? $r['org_perm_id'] : $r['g_perm_id'];
if ($this->forum['read_perms'] != '*')
{
if ( ! preg_match("/(^|,)".str_replace( ",", '|', $perm_id )."(,|$)/", $this->forum['read_perms'] ) )
{
continue;
}
}
$r['language'] = $r['language'] ? $r['language'] : 'en';
$this->email->get_template("subs_new_topic", $r['language']);
$this->email->build_message( array(
'TOPIC_ID' => $this_tid,
'FORUM_ID' => $fid,
'TITLE' => $title,
'NAME' => $r['name'],
'POSTER' => $ibforums->member['name'],
'FORUM' => $forum_name,
'POST' => $post,
)
);
$DB->do_insert( 'mail_queue', array( 'mail_to' => $r['email'], 'mail_date' => time(), 'mail_subject' => $ibforums->lang['ft_subject'], 'mail_content' => $this->email->message ) );
}
}
$ibforums->cache['systemvars']['mail_queue'] += $count;
//-----------------------------------------
// Update cache with remaning email count
//-----------------------------------------
$DB->do_update( 'cache_store', array( 'cs_array' => 1, 'cs_value' => addslashes(serialize($ibforums->cache['systemvars'])) ), "cs_key='systemvars'" );
return TRUE;
}
/*-------------------------------------------------------------------------*/
// compile post
// ------------------
// Compiles all the incoming information into an array
// which is returned to the accessor
/*-------------------------------------------------------------------------*/
function compile_post()
{
global $ibforums, $std;
$ibforums->vars['max_post_length'] = $ibforums->vars['max_post_length'] ? $ibforums->vars['max_post_length'] : 2140000;
//-----------------------------------------
// Sort out some of the form data, check for posting length, etc.
// THIS MUST BE CALLED BEFORE CHECKING ATTACHMENTS
//-----------------------------------------
$ibforums->input['enablesig'] = $ibforums->input['enablesig'] == 'yes' ? 1 : 0;
$ibforums->input['enableemo'] = $ibforums->input['enableemo'] == 'yes' ? 1 : 0;
$ibforums->input['enabletrack'] = intval($ibforums->input['enabletrack']) != 0 ? 1 : 0;
//-----------------------------------------
// Do we have a valid post?
//-----------------------------------------
if (strlen( trim($_POST['Post']) ) < 1)
{
if ( ! $_POST['preview'] )
{
$std->Error( array( LEVEL => 1, MSG => 'no_post') );
}
}
if (strlen( $_POST['Post'] ) > ($ibforums->vars['max_post_length']*1024))
{
$std->Error( array( LEVEL => 1, MSG => 'post_too_long') );
}
$post = array(
'author_id' => $ibforums->member['id'] ? $ibforums->member['id'] : 0,
'use_sig' => $ibforums->input['enablesig'],
'use_emo' => $ibforums->input['enableemo'],
'ip_address' => $ibforums->input['IP_ADDRESS'],
'post_date' => time(),
'icon_id' => $ibforums->input['iconid'],
'post' => $this->parser->convert( array( 'TEXT' => $ibforums->input['Post'],
'SMILIES' => $ibforums->input['enableemo'],
'CODE' => $this->forum['use_ibc'],
'HTML' => $this->forum['use_html']
)
),
'author_name' => $ibforums->member['id'] ? $ibforums->member['name'] : $ibforums->input['UserName'],
'topic_id' => "",
'queued' => ( $this->obj['moderate'] == 1 || $this->obj['moderate'] == 3 ) ? 1 : 0,
'post_htmlstate' => intval($ibforums->input['post_htmlstatus']),
);
// If we had any errors, parse them back to this class
// so we can track them later.
$this->obj['post_errors'] = $this->parser->error;
return $post;
}
/*-------------------------------------------------------------------------*/
// HTML: mod_options.
// ------------------
// Returns the HTML for the mod options drop down box
/*-------------------------------------------------------------------------*/
function mod_options($is_reply=0)
{
global $ibforums, $DB;
$can_close = 0;
$can_pin = 0;
$can_move = 0;
$html = "