File: /var/www/ilya/data/www/kamforum.ru/sources/classes/post/class_post_edit.php
<?php
/*
+--------------------------------------------------------------------------
| Invision Power Board v2.1.5
| =============================================
| by Matthew Mecham
| (c) 2001 - 2004 Invision Power Services, Inc.
| http://www.invisionpower.com
| =============================================
| Web: http://www.invisionboard.com
| Time: Sun, 09 Oct 2005 11:51:26 GMT
| Release: 1a47e28f0443faa9f14d0c0a45151e54
| Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|
| > Post Sub-Class
| > Module written by Matt Mecham
| > Date started: Wednesday 9th March 2005 (15:23)
+--------------------------------------------------------------------------
*/
class post_functions extends class_post
{
var $nav = array();
var $title = "";
var $post = array();
var $upload = array();
var $moderator = array( 'member_id' => 0, 'member_name' => "", 'edit_post' => 0 );
var $orig_post = array();
var $edit_title = 0;
var $post_key = "";
var $class = "";
function main_init()
{
//-----------------------------------------
// Load classes
//-----------------------------------------
$this->load_classes();
$this->build_permissions();
//-----------------------------------------
// Lets load the topic from the database before we do anything else.
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'topics', 'where' => "tid=".intval($this->ipsclass->input['t']) ) );
$this->ipsclass->DB->simple_exec();
$this->topic = $this->ipsclass->DB->fetch_row();
//-----------------------------------------
// Is it legitimate?
//-----------------------------------------
if ( ! $this->topic['tid'] )
{
$this->ipsclass->Error( array( LEVEL => 1, MSG => 'missing_files') );
}
//-----------------------------------------
// Load the old post
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'posts', 'where' => "pid=".intval($this->ipsclass->input['p']) ) );
$this->ipsclass->DB->simple_exec();
$this->orig_post = $this->ipsclass->DB->fetch_row();
if (! $this->orig_post['pid'])
{
$this->ipsclass->Error( array( LEVEL => 1, MSG => 'missing_files') );
}
//-----------------------------------------
// Generate post key (do we have one?)
//-----------------------------------------
if ( ! $this->orig_post['post_key'] )
{
//-----------------------------------------
// Generate one and save back to post and attachment
// to ensure 1.3 < compatibility
//-----------------------------------------
$this->post_key = md5(microtime());
$this->ipsclass->DB->do_update( 'posts', array( 'post_key' => $this->post_key ), 'pid='.$this->orig_post['pid'] );
$this->ipsclass->DB->do_update( 'attachments', array( 'attach_post_key' => $this->post_key ), 'attach_pid='.$this->orig_post['pid'] );
}
else
{
$this->post_key = $this->orig_post['post_key'];
}
//-----------------------------------------
// Load the moderator
//-----------------------------------------
if ($this->ipsclass->member['id'])
{
$this->ipsclass->DB->simple_construct( array( 'select' => 'member_id, member_name, mid, edit_post, edit_topic',
'from' => 'moderators',
'where' => "forum_id=".$this->forum['id']." AND (member_id='".$this->ipsclass->member['id']."' OR (is_group=1 AND group_id='".$this->ipsclass->member['mgroup']."'))" ) );
$this->ipsclass->DB->simple_exec();
$this->moderator = $this->ipsclass->DB->fetch_row();
}
//-----------------------------------------
// Lets do some tests to make sure that we are
// allowed to edit this topic
//-----------------------------------------
$can_edit = 0;
if ($this->ipsclass->member['g_is_supmod'])
{
$can_edit = 1;
}
if ($this->moderator['edit_post'])
{
$can_edit = 1;
}
if ( ($this->orig_post['author_id'] == $this->ipsclass->member['id']) and ($this->ipsclass->member['g_edit_posts']) )
{
//-----------------------------------------
// Have we set a time limit?
//-----------------------------------------
if ($this->ipsclass->member['g_edit_cutoff'] > 0)
{
if ( $this->orig_post['post_date'] > ( time() - ( intval($this->ipsclass->member['g_edit_cutoff']) * 60 ) ) )
{
$can_edit = 1;
}
}
else
{
$can_edit = 1;
}
}
if ( $can_edit != 1 )
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'not_op') );
}
//-----------------------------------------
// Check access
//-----------------------------------------
$this->check_for_edit($this->topic);
//-----------------------------------------
// Do we have edit topic abilities?
//-----------------------------------------
# For edit, this means there is a poll and we have perm to edit
$this->can_add_poll = 0;
if ( $this->orig_post['new_topic'] == 1 )
{
if ( $this->ipsclass->member['g_is_supmod'] == 1 )
{
$this->edit_title = 1;
if ( $this->topic['poll_state'] )
{
$this->can_add_poll = 1;
}
}
else if ( $this->moderator['edit_topic'] == 1 )
{
$this->edit_title = 1;
if ( $this->topic['poll_state'] )
{
$this->can_add_poll = 1;
}
}
else if ( $this->ipsclass->member['g_edit_topic'] == 1 )
{
$this->edit_title = 1;
}
}
}
/*-------------------------------------------------------------------------*/
// MAIN PROCESS FUNCTION
/*-------------------------------------------------------------------------*/
function process_post()
{
//-----------------------------------------
// Convert times...
//-----------------------------------------
$this->convert_open_close_times();
//-----------------------------------------
// Did we remove an attachment?
//-----------------------------------------
if ( $this->ipsclass->input['removeattachid'] )
{
if ( $this->ipsclass->input[ 'removeattach_'. $this->ipsclass->input['removeattachid'] ] )
{
$this->pf_remove_attachment( intval($this->ipsclass->input['removeattachid']), $this->post_key );
$this->show_form();
}
}
//-----------------------------------------
// Did we add an attachment?
//-----------------------------------------
if ( $this->ipsclass->input['attachgo'] )
{
$this->obj['post_errors'] = "";
$this->upload_id = $this->process_upload();
$this->show_form();
}
//-----------------------------------------
// Parse the post, and check for any errors.
// overwrites saved post intentionally
//-----------------------------------------
$this->post = $this->compile_post();
//-----------------------------------------
// Compile the poll
//-----------------------------------------
$this->poll_questions = $this->compile_poll();
//-----------------------------------------
// Check for errors
//-----------------------------------------
if ($this->obj['post_errors'] == "")
{
$this->upload = $this->process_upload();
}
if ( ($this->obj['post_errors'] != "") or ($this->obj['preview_post'] != "") )
{
//-----------------------------------------
// Show the form again
//-----------------------------------------
$this->show_form($class);
}
else
{
$this->save_post($class);
}
}
/*-------------------------------------------------------------------------*/
// COMPLETE EDIT THINGY
/*-------------------------------------------------------------------------*/
function save_post()
{
$time = $this->ipsclass->get_date( time(), 'LONG' );
//-----------------------------------------
// Reset some data
//-----------------------------------------
$this->post['ip_address'] = $this->orig_post['ip_address'];
$this->post['topic_id'] = $this->orig_post['topic_id'];
$this->post['author_id'] = $this->orig_post['author_id'];
$this->post['post_date'] = $this->orig_post['post_date'];
$this->post['author_name'] = $this->orig_post['author_name'];
$this->post['queued'] = $this->orig_post['queued'];
$this->post['edit_time'] = time();
$this->post['edit_name'] = $this->ipsclass->member['members_display_name'];
//-----------------------------------------
// If the post icon has changed, update the topic post icon
//-----------------------------------------
if ($this->orig_post['new_topic'] == 1)
{
if ($this->post['icon_id'] != $this->orig_post['icon_id'])
{
$this->ipsclass->DB->do_update( 'topics', array( 'icon_id' => $this->post['icon_id'] ), 'tid='.$this->topic['tid'] );
}
}
//-----------------------------------------
// Update open and close times
//-----------------------------------------
if ( $this->orig_post['new_topic'] == 1 )
{
$times = array();
if ( $this->can_set_open_time )
{
$times['topic_open_time'] = $this->times['open'];
if( $this->topic['topic_open_time'] AND $this->times['open'] )
{
$times['state'] = "closed";
if( time() > $this->topic['topic_open_time'] )
{
if( time() < $this->topic['topic_close_time'] )
{
$times['state'] = "open";
}
}
}
if ( ! $this->times['open'] AND $this->topic['topic_open_time'] )
{
if ( $this->topic['state'] == 'closed' )
{
$times['state'] = 'open';
}
}
}
if ( $this->can_set_close_time )
{
$times['topic_close_time'] = $this->times['close'];
//-----------------------------------------
// Was a close time, but not now?
//-----------------------------------------
if ( ! $this->times['close'] AND $this->topic['topic_close_time'] )
{
if ( $this->topic['state'] == 'closed' )
{
$times['state'] = 'open';
}
}
}
if ( count( $times ) )
{
$this->ipsclass->DB->do_update( 'topics', $times, "tid=".$this->topic['tid'] );
}
}
//-----------------------------------------
// Update topic title?
//-----------------------------------------
if ( $this->edit_title == 1 )
{
//-----------------------------------------
// Update poll
//-----------------------------------------
if ( $this->can_add_poll )
{
if ( is_array( $this->poll_questions ) AND count( $this->poll_questions ) )
{
$this->ipsclass->DB->do_update( 'polls', array( 'votes' => intval($this->poll_total_votes),
'choices' => addslashes(serialize( $this->poll_questions )),
'poll_question' => $this->ipsclass->input['poll_question'],
), 'tid='.$this->topic['tid'] );
}
else
{
//-----------------------------------------
// Remove the poll
//-----------------------------------------
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'polls' , 'where' => "tid=".$this->topic['tid'] ) );
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'voters', 'where' => "tid=".$this->topic['tid'] ) );
$this->ipsclass->DB->do_update( 'topics', array( 'poll_state' => '', 'last_vote' => '', 'total_votes' => '' ), 'tid='.$this->topic['tid'] );
}
}
//-----------------------------------------
// Update topic title
//-----------------------------------------
$this->ipsclass->input['TopicTitle'] = $this->pf_clean_topic_title( $this->ipsclass->input['TopicTitle'] );
$this->ipsclass->input['TopicTitle'] = trim( $this->parser->bad_words( $this->ipsclass->input['TopicTitle'] ) );
$this->ipsclass->input['TopicDesc'] = trim( $this->parser->bad_words( $this->ipsclass->input['TopicDesc'] ) );
if ( $this->ipsclass->input['TopicTitle'] != "" )
{
if ( ($this->ipsclass->input['TopicTitle'] != $this->topic['title']) or ($this->ipsclass->input['TopicDesc'] != $this->topic['description']) )
{
$this->ipsclass->DB->do_update( 'topics', array( 'title' => $this->ipsclass->input['TopicTitle'],
'description' => $this->ipsclass->input['TopicDesc']
) , "tid=".$this->topic['tid'] );
if ($this->topic['tid'] == $this->forum['last_id'])
{
$this->ipsclass->DB->do_update( 'forums', array( 'last_title' => $this->ipsclass->input['TopicTitle'] ), 'id='.$this->forum['id'] );
$this->ipsclass->update_forum_cache();
}
if ( ($this->moderator['edit_topic'] == 1) OR ( $this->ipsclass->member['g_is_supmod'] == 1 ) )
{
$this->ipsclass->DB->do_insert( 'moderator_logs', array (
'forum_id' => $this->forum['id'],
'topic_id' => $this->topic['tid'],
'post_id' => $this->orig_post['pid'],
'member_id' => $this->ipsclass->member['id'],
'member_name' => $this->ipsclass->member['members_display_name'],
'ip_address' => $this->ip_address,
'http_referer'=> $_SERVER['HTTP_REFERER'],
'ctime' => time(),
'topic_title' => $this->topic['title'],
'action' => "Edited topic title or description '{$this->topic['title']}' to '{$this->ipsclass->input['TopicTitle']}' via post form",
'query_string'=> $_SERVER['QUERY_STRING'],
) );
}
}
}
}
//-----------------------------------------
// Update the database (ib_forum_post)
//-----------------------------------------
$this->post['append_edit'] = 1;
if ( $this->ipsclass->member['g_append_edit'] )
{
if ( $this->ipsclass->input['add_edit'] != 1 )
{
$this->post['append_edit'] = 0;
}
}
$this->ipsclass->DB->do_update( 'posts', $this->post, 'pid='.$this->orig_post['pid'] );
//-----------------------------------------
// Make attachments "permanent"
//-----------------------------------------
$this->pf_make_attachments_permanent($this->post_key, $this->topic['tid'], $this->orig_post['pid']);
//-----------------------------------------
// Make sure paperclip symbol is OK
//-----------------------------------------
$this->pf_recount_topic_attachments($this->topic['tid']);
//-----------------------------------------
// Not XML? Redirect them back to the topic
//-----------------------------------------
if ( $this->ipsclass->input['act'] == 'xmlout' )
{
return TRUE;
}
else
{
$this->ipsclass->print->redirect_screen( $this->ipsclass->lang['post_edited'], "act=ST&f={$this->forum['id']}&t={$this->topic['tid']}&st={$this->ipsclass->input['st']}#entry{$this->orig_post['pid']}");
}
}
/*-------------------------------------------------------------------------*/
// SHOW FORM
/*-------------------------------------------------------------------------*/
function show_form()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$raw_post = "";
//-----------------------------------------
// Unconvert the saved post if required
//-----------------------------------------
if ( ! isset($_POST['Post']) )
{
//-----------------------------------------
// If we're using RTE, then just clean up html
//-----------------------------------------
if ( $this->han_editor->method == 'rte' )
{
$raw_post = $this->parser->convert_ipb_html_to_html( $this->orig_post['post'] );
}
else
{
$this->parser->parse_html = intval($this->orig_post['post_htmlstatus']) AND $this->forum['use_html'] AND $this->ipsclass->member['g_dohtml'] ? 1 : 0;
$this->parser->parse_nl2br = $this->ipsclass->input['post_htmlstatus'] == 2 ? 1 : 0;
$this->parser->parse_smilies = intval($this->orig_post['use_emo']);
$this->parser->parse_bbcode = $this->forum['use_ibc'];
$raw_post = $this->parser->pre_edit_parse( $this->orig_post['post'] );
}
}
else
{
$raw_post = $this->ipsclass->txt_stripslashes( $_POST['Post'] );
}
//-----------------------------------------
// Is this the first post in the topic?
//-----------------------------------------
if ( $this->edit_title == 1 )
{
$topic_title = isset($_POST['TopicTitle']) ? $this->ipsclass->input['TopicTitle'] : $this->topic['title'];
$topic_desc = isset($_POST['TopicDesc']) ? $this->ipsclass->input['TopicDesc'] : $this->topic['description'];
$topic_title = $this->ipsclass->compiled_templates['skin_post']->topictitle_fields( array( 'TITLE' => $topic_title, 'DESC' => $topic_desc ) );
}
//-----------------------------------------
// Do we have any posting errors?
//-----------------------------------------
if ($this->obj['post_errors'])
{
$this->output .= $this->ipsclass->compiled_templates['skin_post']->errors( $this->ipsclass->lang[ $this->obj['post_errors'] ]);
}
if ( $this->obj['preview_post'] )
{
$this->output .= $this->ipsclass->compiled_templates['skin_post']->preview( $this->show_post_preview( $this->post['post'] ) );
}
$this->output .= $this->html_start_form( array( 1 => array( 'CODE', '09' ),
2 => array( 't' , $this->topic['tid']),
3 => array( 'p' , $this->ipsclass->input['p'] ),
4 => array( 'st' , $this->ipsclass->input['st'] ),
5 => array( 'post_key', $this->post_key )
) );
//-----------------------------------------
// START TABLE
//-----------------------------------------
$this->output .= $this->ipsclass->compiled_templates['skin_post']->table_structure();
$start_table = $this->ipsclass->compiled_templates['skin_post']->table_top( "{$this->ipsclass->lang['top_txt_edit']} {$this->topic['title']}");
$name_fields = $this->html_name_field();
$post_box = $this->html_post_body( $raw_post );
if ( $this->edit_title == 1 )
{
$mod_options = $this->mod_options('edit');
}
$end_form = $this->ipsclass->compiled_templates['skin_post']->EndForm( $this->ipsclass->lang['submit_edit'] );
$post_icons = $this->html_post_icons($this->orig_post['icon_id']);
if ( $this->can_upload )
{
$upload_field = $this->html_build_uploads($this->post_key,'edit',$this->orig_post['pid']);
}
//-----------------------------------------
// Still here?
//-----------------------------------------
if ( $this->can_add_poll )
{
//-----------------------------------------
// Did someone hit preview / do we have
// post info?
//-----------------------------------------
$poll_questions = "";
$poll_choices = "";
$poll_votes = "";
$show_open = 0;
$is_mod = 0;
if ( is_array( $_POST['question'] ) and count( $_POST['question'] ) )
{
foreach( $_POST['question'] as $id => $question )
{
$poll_questions .= "\t{$id} : '".str_replace( "'", ''', $question )."',\n";
}
$poll_question = $this->ipsclass->input['poll_question'];
$show_open = 1;
if ( is_array( $_POST['choice'] ) and count( $_POST['choice'] ) )
{
foreach( $_POST['choice'] as $id => $choice )
{
$poll_choices .= "\t'{$id}' : '".str_replace( "'", ''', $choice )."',\n";
}
}
if ( is_array( $_POST['votes'] ) and count( $_POST['votes'] ) )
{
foreach( $_POST['votes'] as $id => $vote )
{
$poll_votes .= "\t'{$id}' : '".$vote."',\n";
}
}
$poll_questions = preg_replace( "#,(\n)?$#", "\\1", $poll_questions );
$poll_choices = preg_replace( "#,(\n)?$#", "\\1", $poll_choices );
$poll_votes = preg_replace( "#,(\n)?$#", "\\1", $poll_votes );
}
else
{
//-----------------------------------------
// Load the poll from the DB
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'polls', 'where' => "tid=".$this->topic['tid'] ) );
$this->ipsclass->DB->simple_exec();
$poll_data = $this->ipsclass->DB->fetch_row();
$poll_answers = unserialize(stripslashes($poll_data['choices']));
//-----------------------------------------
// Lezz go
//-----------------------------------------
foreach( $poll_answers as $question_id => $data )
{
$poll_questions .= "\t{$question_id} : '".str_replace( "'", ''', $data['question'] )."',\n";
foreach( $data['choice'] as $choice_id => $text )
{
$choice = $text;
$votes = intval($data['votes'][ $choice_id ]);
$poll_choices .= "\t'{$question_id}_{$choice_id}' : '".str_replace( "'", ''', $choice )."',\n";
$poll_votes .= "\t'{$question_id}_{$choice_id}' : '".$votes."',\n";
}
}
//-----------------------------------------
// Trim off trailing commas (Safari hates it)
//-----------------------------------------
$poll_questions = preg_replace( "#,(\n)?$#", "\\1", $poll_questions );
$poll_choices = preg_replace( "#,(\n)?$#", "\\1", $poll_choices );
$poll_votes = preg_replace( "#,(\n)?$#", "\\1", $poll_votes );
$poll_question = $poll_data['poll_question'];
$show_open = 1;
$is_mod = 1;
}
//-----------------------------------------
// Print poll box
//-----------------------------------------
$poll_box = $this->ipsclass->compiled_templates['skin_post']->poll_box( $this->max_poll_questions, $this->max_poll_choices_per_question, $poll_questions, $poll_choices, $poll_votes, $show_open, $poll_question, $is_mod );
}
if ($this->ipsclass->member['g_append_edit'])
{
$checked = "";
if ($this->orig_post['append_edit'])
{
$checked = "checked";
}
$edit_option = $this->ipsclass->compiled_templates['skin_post']->add_edit_box($checked);
}
$this->output = str_replace( "<!--START TABLE-->" , $start_table , $this->output );
$this->output = str_replace( "<!--NAME FIELDS-->" , $name_fields , $this->output );
$this->output = str_replace( "<!--POST BOX-->" , $post_box , $this->output );
$this->output = str_replace( "<!--POLL BOX-->" , $poll_box , $this->output );
$this->output = str_replace( "<!--POST ICONS-->" , $post_icons , $this->output );
$this->output = str_replace( "<!--END TABLE-->" , $end_form , $this->output );
$this->output = str_replace( "<!--UPLOAD FIELD-->", $upload_field , $this->output );
$this->output = str_replace( "<!--MOD OPTIONS-->" , $edit_option . $mod_options , $this->output );
$this->output = str_replace( "<!--FORUM RULES-->" , $this->ipsclass->print_forum_rules($this->forum), $this->output );
$this->output = str_replace( "<!--TOPIC TITLE-->" , $topic_title , $this->output );
$this->output = $this->html_add_smilie_box( $this->output );
//-----------------------------------------
// Add in siggy buttons and such
//-----------------------------------------
$this->ipsclass->input['post_htmlstatus'] = $this->orig_post['post_htmlstate'];
$this->ipsclass->input['enablesig'] = $this->orig_post['use_sig'];
$this->ipsclass->input['enableemo'] = $this->orig_post['use_emo'];
$this->html_checkboxes('edit', $this->topic['tid'], $this->forum['id']);
$this->html_topic_summary($this->topic['tid']);
$this->show_post_navigation();
$this->title = $this->ipsclass->lang['editing_post'].' '.$this->topic['title'];
$this->ipsclass->print->add_output( $this->output );
$this->ipsclass->print->do_output( array( 'TITLE' => $this->ipsclass->vars['board_name']." -> ".$this->title,
'JS' => 1,
'NAV' => $this->nav,
) );
}
}
?>