home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / lib / post_edit_post.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  8.8 KB  |  280 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Edit post library
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 19th February 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25.  
  26. class post_functions extends Post {
  27.  
  28.     var $nav               = array();
  29.     var $title             = "";
  30.     var $post              = array();
  31.     var $topic             = array();
  32.     var $upload            = array();
  33.     var $moderator         = array( 'member_id' => 0, 'member_name' => "", 'edit_post' => 0 );
  34.     var $orig_post         = array();
  35.  
  36.     function post_functions($class) {
  37.     
  38.         global $ibforums, $std, $DB;
  39.         
  40.         // Lets load the topic from the database before we do anything else.
  41.         
  42.         $DB->query("SELECT * FROM ibf_topics WHERE tid='".$ibforums->input['t']."'");
  43.         $this->topic = $DB->fetch_row();
  44.         
  45.         // Is it legitimate?
  46.         
  47.         if (! $this->topic['tid'])
  48.         {
  49.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  50.         }
  51.         
  52.         // Load the old post
  53.         
  54.         $DB->query("SELECT * FROM ibf_posts WHERE pid='".$ibforums->input['p']."'");
  55.         $this->orig_post = $DB->fetch_row();
  56.         
  57.         if (! $this->orig_post['pid'])
  58.         {
  59.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  60.         }
  61.         
  62.         // Load the moderator
  63.         
  64.         if ($ibforums->member['id'])
  65.         {
  66.             $DB->query("SELECT member_id, member_name, mid, edit_post FROM ibf_moderators WHERE member_id='".$ibforums->member['id']."' and forum_id='".$class->forum['id']."'");
  67.             $this->moderator = $DB->fetch_row();
  68.         }
  69.         
  70.         //-------------------------------------------------
  71.         // Lets do some tests to make sure that we are
  72.         // allowed to edit this topic
  73.         //-------------------------------------------------
  74.         
  75.         $can_edit = 0;
  76.         
  77.         if ($ibforums->member['g_is_supmod'])
  78.         {
  79.             $can_edit = 1;
  80.         }
  81.         if ($this->moderator['edit_post'])
  82.         {
  83.             $can_edit = 1;
  84.         }
  85.         if ( ($this->orig_post['author_id'] == $ibforums->member['id']) and ($ibforums->member['g_edit_posts']) )
  86.         {
  87.             $can_edit = 1;
  88.         }
  89.         
  90.         if ($can_edit != 1)
  91.         {
  92.             $std->Error( array( LEVEL => 1, MSG => 'not_op') );
  93.         }
  94.         
  95.         // Is the topic locked?
  96.         
  97.         if (($this->topic['state'] != 'open') and (!$ibforums->member['g_is_supmod']))
  98.         {
  99.             $std->Error( array( LEVEL => 1, MSG => 'locked_topic') );
  100.         }
  101.  
  102.     }
  103.     
  104.     function process($class) {
  105.     
  106.         global $ibforums, $std, $DB, $print;
  107.         
  108.         //-------------------------------------------------
  109.         // Parse the post, and check for any errors.
  110.         // overwrites saved post intentionally
  111.         //-------------------------------------------------
  112.         
  113.         $this->post   = $class->compile_post();
  114.         
  115.         if ($class->obj['post_errors'] == "")
  116.         {
  117.             $this->upload = $class->process_upload();
  118.         }
  119.         
  120.         if ( ($class->obj['post_errors'] != "") or ($class->obj['preview_post'] != "") )
  121.         {
  122.             // Show the form again
  123.             $this->show_form($class);
  124.         }
  125.         else
  126.         {
  127.             $this->complete_edit($class);
  128.         }
  129.     }
  130.     
  131.     
  132.     
  133.     
  134.     
  135.     function complete_edit($class) {
  136.         
  137.         global $ibforums, $std, $DB, $print;
  138.         
  139.         $time = $std->get_date( time(), 'LONG' );
  140.         
  141.         //-------------------------------------------------
  142.         // Reset some data
  143.         //-------------------------------------------------
  144.         
  145.         $this->post['attach_id']   = $this->orig_post['attach_id'];
  146.         $this->post['attach_type'] = $this->orig_post['attach_type'];
  147.         $this->post['attach_hits'] = $this->orig_post['attach_hits'];
  148.         $this->post['ip_address']  = $this->orig_post['ip_address'];
  149.         $this->post['topic_id']    = $this->orig_post['topic_id'];
  150.         $this->post['author_id']   = $this->orig_post['author_id'];
  151.         $this->post['pid']         = $this->orig_post['pid'];
  152.         $this->post['post_date']   = $this->orig_post['post_date'];
  153.         $this->post['author_name'] = $this->orig_post['author_name'];
  154.         
  155.         // If the post icon has changed, update the topic post icon
  156.         
  157.         if ($this->orig_post['new_topic'] == 1)
  158.         {
  159.             if ($this->post['icon_id'] != $this->orig_post['icon_id'])
  160.             {
  161.                 $DB->query("UPDATE ibf_topics SET icon_id='".$this->post['icon_id']."' WHERE tid='".$this->topic['tid']."'");
  162.             }
  163.         }
  164.         //-------------------------------------------------
  165.         // Update the database (ib_forum_post)
  166.         //-------------------------------------------------
  167.         
  168.         if ($ibforums->member['g_append_edit'])
  169.         {
  170.             $this->post['post'] .= "\n\n<br><br><!--EDIT|".$ibforums->member['name']."|".$time."-->";
  171.         }
  172.         
  173.         $db_string = $DB->compile_db_update_string( $this->post );
  174.         
  175.         $DB->query("UPDATE ibf_posts SET $db_string WHERE pid='".$this->post['pid']."'");
  176.  
  177.         
  178.         //-------------------------------------------------
  179.         // Redirect them back to the topic
  180.         //-------------------------------------------------
  181.         
  182.         $print->redirect_screen( $ibforums->lang['post_edited'], "act=ST&f={$class->forum['id']}&t={$this->topic['tid']}&st={$ibforums->input['st']}#entry{$this->post['pid']}");
  183.         
  184.     }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.     function show_form($class) {
  192.     
  193.         global $ibforums, $std, $DB, $print, $HTTP_POST_VARS;
  194.         
  195.         //-------------------------------------------------
  196.         // Sort out the "raw" textarea input and make it safe incase
  197.         // we have a <textarea> tag in the raw post var.
  198.         //-------------------------------------------------
  199.         
  200.         $raw_post = isset($HTTP_POST_VARS['Post'])  ? $HTTP_POST_VARS['Post'] : $class->parser->unconvert($this->orig_post['post'], $class->forum['use_ibc'], $class->forum['use_html']);
  201.  
  202.         if (isset($raw_post)) {
  203.             $raw_post = preg_replace( "/<\/textarea>/", "</textarea>", $raw_post );
  204.             $raw_post = str_replace( '$', "$", $raw_post );
  205.             $raw_post = str_replace( '<%', "<%"  , $raw_post );
  206.             $raw_post = stripslashes($raw_post);
  207.         }
  208.         
  209.         //-------------------------------------------------
  210.         // Do we have any posting errors?
  211.         //-------------------------------------------------
  212.         
  213.         if ($class->obj['post_errors'])
  214.         {
  215.             $class->output .= $class->html->errors( $ibforums->lang[ $class->obj['post_errors'] ]);
  216.         }
  217.         
  218.         if ($class->obj['preview_post'])
  219.         {
  220.             $class->output .= $class->html->preview( $class->parser->convert( array( 'TEXT' => $this->post['post'], 'CODE' => $class->forum['use_ibc'], 'SMILIES' => $ibforums->input['enableemo'], 'HTML' => $class->forum['use_html']) ) );
  221.         }
  222.         
  223.         $class->output .= $class->html_start_form( array( 1 => array( 'CODE', '09' ),
  224.                                                           2 => array( 't'   , $this->topic['tid']),
  225.                                                           3 => array( 'p'   , $ibforums->input['p'] ),
  226.                                                           4 => array( 'st'  , $ibforums->input['st'] ),
  227.                                                         ) );
  228.                                                         
  229.         //---------------------------------------
  230.         // START TABLE
  231.         //---------------------------------------
  232.         
  233.         $class->output .= $class->html->table_structure();
  234.         
  235.         //---------------------------------------
  236.         
  237.         $start_table = $class->html->table_top( "{$ibforums->lang['top_txt_edit']} {$this->topic['title']}");
  238.         
  239.         $name_fields = $class->html_name_field();
  240.         
  241.         $post_box    = $class->html_post_body( $raw_post );
  242.         
  243.         $end_form    = $class->html->EndForm( $ibforums->lang['submit_edit'] );
  244.         
  245.         $post_icons  = $class->html_post_icons($this->orig_post['icon_id']);
  246.         
  247.         //---------------------------------------
  248.         
  249.         $class->output = preg_replace( "/<!--START TABLE-->/" , "$start_table"  , $class->output );
  250.         $class->output = preg_replace( "/<!--NAME FIELDS-->/" , "$name_fields"  , $class->output );
  251.         $class->output = preg_replace( "/<!--POST BOX-->/"    , "$post_box"     , $class->output );
  252.         $class->output = preg_replace( "/<!--POST ICONS-->/"  , "$post_icons"   , $class->output );
  253.         $class->output = preg_replace( "/<!--END TABLE-->/"   , "$end_form"     , $class->output );
  254.         
  255.         //---------------------------------------
  256.         
  257.         $class->html_add_smilie_box();
  258.         
  259.         $class->html_topic_summary($this->topic['tid']);
  260.         
  261.         $this->nav = array( "<a href='{$class->base_url}&act=SC&c={$class->forum['cat_id']}'>{$class->forum['cat_name']}</a>",
  262.                             "<a href='{$class->base_url}&act=SF&f={$class->forum['id']}'>{$class->forum['name']}</a>",
  263.                             "<a href='{$class->base_url}&act=ST&f={$class->forum['id']}&t={$this->topic['tid']}'>{$this->topic['title']}</a>",
  264.                           );
  265.                           
  266.         $this->title = $ibforums->lang['editing_post'].' '.$this->topic['title'];
  267.         
  268.         $print->add_output("$class->output");
  269.         
  270.         $print->do_output( array( 'TITLE'    => $ibforums->vars['board_name']." -> ".$this->title,
  271.                                    'JS'       => 1,
  272.                                    'NAV'      => $this->nav,
  273.                               ) );
  274.         
  275.     }
  276.     
  277.  
  278. }
  279.  
  280. ?>