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_reply_post.php < prev    next >
Encoding:
PHP Script  |  2002-08-01  |  11.8 KB  |  360 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. |   > Reply post module
  17. |   > Module written by Matt Mecham
  18. |
  19. +--------------------------------------------------------------------------
  20. */
  21.  
  22.  
  23. class post_functions extends Post {
  24.  
  25.     var $nav = array();
  26.     var $title = "";
  27.     var $post  = array();
  28.     var $topic = array();
  29.     var $upload = array();
  30.     var $mod_topic = array();
  31.     
  32.     var $m_group = "";
  33.  
  34.     function post_functions($class) {
  35.     
  36.         global $ibforums, $std, $DB;
  37.         
  38.         // Lets load the topic from the database before we do anything else.
  39.         
  40.         $DB->query("SELECT * FROM ibf_topics WHERE forum_id='".$class->forum['id']."' AND tid='".$ibforums->input['t']."'");
  41.         $this->topic = $DB->fetch_row();
  42.         
  43.         // Is it legitimate?
  44.         
  45.         if (! $this->topic['tid'])
  46.         {
  47.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  48.         }
  49.         
  50.         //-------------------------------------------------
  51.         // Lets do some tests to make sure that we are
  52.         // allowed to reply to this topic
  53.         //-------------------------------------------------
  54.         
  55.         if ($this->topic['poll_state'] == 'closed' and $ibforums->member['g_is_supadmin'] != 1)
  56.         {
  57.             $std->Error( array( LEVEL => 1, MSG => 'no_replies') );
  58.         }
  59.         
  60.         if ($this->topic['starter_id'] == $ibforums->member['id'])
  61.         {
  62.             if (! $ibforums->member['g_reply_own_topics'])
  63.             {
  64.                 $std->Error( array( LEVEL => 1, MSG => 'no_replies') );
  65.             }
  66.         }
  67.         
  68.         if ($this->topic['starter_id'] != $ibforums->member['id'])
  69.         {
  70.             if (! $ibforums->member['g_reply_own_topics'])
  71.             {
  72.                 $std->Error( array( LEVEL => 1, MSG => 'no_replies') );
  73.             }
  74.         }
  75.         
  76.         $this->m_group = $ibforums->member['mgroup'];
  77.         
  78.         if ($class->forum['reply_perms'] != '*')
  79.         {
  80.             if (! preg_match( "/(^|,)$this->m_group(,|$)/", $class->forum['reply_perms'] ) )
  81.             {
  82.                 $std->Error( array( LEVEL => 1, MSG => 'no_replies') );
  83.             }
  84.         }
  85.         
  86.         // Is the topic locked?
  87.         
  88.         if ($this->topic['state'] != 'open')
  89.         {
  90.             $std->Error( array( LEVEL => 1, MSG => 'locked_topic') );
  91.         }
  92.  
  93.     }
  94.     
  95.     function process($class) {
  96.     
  97.         global $ibforums, $std, $DB, $print;
  98.         
  99.         //-------------------------------------------------
  100.         // Parse the post, and check for any errors.
  101.         //-------------------------------------------------
  102.         
  103.         $this->post   = $class->compile_post();
  104.         
  105.         if ($class->obj['post_errors'] == "")
  106.         {
  107.             $this->upload = $class->process_upload();
  108.         }
  109.         
  110.         if ( ($class->obj['post_errors'] != "") or ($class->obj['preview_post'] != "") )
  111.         {
  112.             // Show the form again
  113.             $this->show_form($class);
  114.         }
  115.         else
  116.         {
  117.             $this->add_reply($class);
  118.         }
  119.     }
  120.     
  121.     
  122.     
  123.     
  124.     
  125.     function add_reply($class) {
  126.         
  127.         global $ibforums, $std, $DB, $print;
  128.         
  129.         //-------------------------------------------------
  130.         // Update the post info with the upload array info
  131.         //-------------------------------------------------
  132.         
  133.         $this->post['attach_id']   = $this->upload['attach_id'];
  134.         $this->post['attach_type'] = $this->upload['attach_type'];
  135.         $this->post['attach_hits'] = $this->upload['attach_hits'];
  136.         $this->post['attach_file'] = $this->upload['attach_file'];
  137.         
  138.         //-------------------------------------------------
  139.         // Insert the post into the database to get the
  140.         // last inserted value of the auto_increment field
  141.         //-------------------------------------------------
  142.         
  143.         $this->post['topic_id'] = $this->topic['tid'];
  144.         
  145.         //-------------------------------------------------
  146.         // Are we a mod, and can we change the topic state?
  147.         //-------------------------------------------------
  148.         
  149.         if ( ($ibforums->input['mod_options'] != "") or ($ibforums->input['mod_options'] != 'nowt') )
  150.         {
  151.             if ($ibforums->input['mod_options'] == 'pin')
  152.             {
  153.                 if ($ibforums->member['g_is_supmod'] == 1 or $class->moderator['pin_topic'] == 1)
  154.                 {
  155.                     $this->topic['pinned'] = 1;
  156.                     
  157.                     $class->moderate_log('Pinned topic from post form', $this->topic['title']);
  158.                 }
  159.             }
  160.             else if ($ibforums->input['mod_options'] == 'close')
  161.             {
  162.                 if ($ibforums->member['g_is_supmod'] == 1 or $class->moderator['close_topic'] == 1)
  163.                 {
  164.                     $this->topic['state'] = 'closed';
  165.                     
  166.                     $class->moderate_log('Closed topic from post form', $this->topic['title']);
  167.                 }
  168.             }
  169.         }
  170.         
  171.         $db_string = $std->compile_db_string( $this->post );
  172.         
  173.         $DB->query("INSERT INTO ibf_posts (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")");
  174.         $this->post['pid'] = $DB->get_insert_id();
  175.         
  176.         if ($class->obj['moderate']) {
  177.             
  178.             $print->redirect_screen( $ibforums->lang['moderate_post'], "act=ST&f={$class->forum['id']}&t={$this->topic['tid']}" );
  179.         }
  180.         
  181.         //-------------------------------------------------
  182.         // If we are still here, lets update the
  183.         // board/forum/topic stats
  184.         //-------------------------------------------------
  185.         
  186.         $class->forum['last_title']       = $this->topic['title'];
  187.         $class->forum['last_id']          = $this->topic['tid'];
  188.         $class->forum['last_post']        = time();
  189.         $class->forum['last_poster_name'] = $ibforums->member['id'] ?  $ibforums->member['name'] : $ibforums->input['UserName'];
  190.         $class->forum['last_poster_id']   = $ibforums->member['id'];
  191.         $class->forum['posts']++;
  192.         
  193.         // Update the database
  194.         
  195.         $DB->query("UPDATE ibf_forums    SET last_title='"      .$class->forum['last_title']       ."', ".
  196.                                             "last_id='"         .$class->forum['last_id']          ."', ".
  197.                                             "last_post='"       .$class->forum['last_post']        ."', ".
  198.                                             "last_poster_name='".$class->forum['last_poster_name'] ."', ".
  199.                                             "last_poster_id='"  .$class->forum['last_poster_id']   ."', ".
  200.                                             "posts='"           .$class->forum['posts']            ."' ".
  201.                                             "WHERE id='"        .$class->forum['id']               ."'");
  202.         
  203.         
  204.         
  205.         
  206.         // Update the database
  207.         
  208.         //+------------------------------------------------------------------------------------------------------
  209.         
  210.         $DB->query("UPDATE ibf_topics     SET last_poster_id='"       .$class->forum['last_poster_id']    ."', ".
  211.                                               "last_poster_name='"    .$class->forum['last_poster_name']  ."', ".
  212.                                               "last_post='"           .$class->forum['last_post']         ."', ".
  213.                                               "pinned='"              .$this->topic['pinned']             ."', ".
  214.                                               "state='"               .$this->topic['state']              ."', ".
  215.                                               "posts=posts+1 ".
  216.                                               "WHERE tid='"           .$this->topic['tid']             ."'");
  217.         
  218.         //+------------------------------------------------------------------------------------------------------
  219.         
  220.         $DB->query("UPDATE ibf_stats SET TOTAL_REPLIES=TOTAL_REPLIES+1");
  221.         
  222.         //-------------------------------------------------
  223.         // If we are a member, lets update thier last post
  224.         // date and increment their post count.
  225.         //-------------------------------------------------
  226.         
  227.         $pcount = "";
  228.         
  229.         if ($ibforums->member['id'])
  230.         {
  231.             if ($class->forum['inc_postcount'])
  232.             {
  233.                 // Increment the users post count
  234.                 
  235.                 $pcount = "posts=posts+1, ";
  236.                 
  237.             }
  238.             
  239.             $ibforums->member['last_post'] = time();
  240.             
  241.             $DB->query("UPDATE ibf_members SET ".$pcount.
  242.                                               "last_post='"    .$ibforums->member['last_post']   ."'".
  243.                                               "WHERE id='"     .$ibforums->member['id']."'");
  244.         }
  245.         
  246.         
  247.         //-------------------------------------------------
  248.         // Check for subscribed topics
  249.         //-------------------------------------------------
  250.         
  251.         $class->topic_tracker( $this->topic['tid'], $this->post['post'], $class->forum['last_poster_name'] );
  252.         
  253.         //-------------------------------------------------
  254.         // Redirect them back to the topic
  255.         //-------------------------------------------------
  256.         
  257.         $page = floor( ($this->topic['posts'] + 1) / $ibforums->vars['display_max_posts']);
  258.         $page = $page * $ibforums->vars['display_max_posts'];
  259.         $std->boink_it($class->base_url."&act=ST&f={$class->forum['id']}&t={$this->topic['tid']}&st=$page&#entry{$this->post['pid']}");
  260.         
  261.     }
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.     function show_form($class) {
  269.     
  270.         global $ibforums, $std, $DB, $print, $HTTP_POST_VARS;
  271.         
  272.         // Sort out the "raw" textarea input and make it safe incase
  273.         // we have a <textarea> tag in the raw post var.
  274.         
  275.         $raw_post    = isset($HTTP_POST_VARS['Post'])       ? $HTTP_POST_VARS['Post']       : "";
  276.  
  277.         if (isset($raw_post)) {
  278.             $raw_post = preg_replace( "/<textarea>/", "<textarea>", $raw_post );
  279.             $raw_post = str_replace( '$', "$", $raw_post );
  280.             $raw_post = str_replace( '<%', "<%"  , $raw_post );
  281.             $raw_post = stripslashes($raw_post);
  282.         }
  283.         
  284.         // Do we have any posting errors?
  285.         
  286.         if ($class->obj['post_errors']) {
  287.             $class->output .= $class->html->errors( $ibforums->lang[ $class->obj['post_errors'] ]);
  288.         }
  289.         
  290.         if ($class->obj['preview_post']) {
  291.             $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']) ) );
  292.         }
  293.         
  294.         $class->check_upload_ability();
  295.         
  296.         $class->output .= $class->html_start_form( array( 1 => array( 'CODE', '03' ),
  297.                                                           2 => array( 't'   , $this->topic['tid'])
  298.                                                         ) );
  299.                                                         
  300.         //---------------------------------------
  301.         // START TABLE
  302.         //---------------------------------------
  303.         
  304.         $class->output .= $class->html->table_structure();
  305.         
  306.         //---------------------------------------
  307.         
  308.         $start_table = $class->html->table_top( "{$ibforums->lang['top_txt_reply']} {$this->topic['title']}");
  309.         
  310.         $name_fields = $class->html_name_field();
  311.         
  312.         $post_box    = $class->html_post_body( $raw_post );
  313.         
  314.         $mod_options = $class->mod_options();
  315.         
  316.         $end_form    = $class->html->EndForm( $ibforums->lang['submit_reply'] );
  317.         
  318.         $post_icons  = $class->html_post_icons();
  319.         
  320.         if ($class->obj['can_upload'])
  321.         {
  322.             $upload_field = $class->html->Upload_field( $ibforums->member['g_attach_max'] * 1024 );
  323.         }
  324.         
  325.         //---------------------------------------
  326.         
  327.         $class->output = preg_replace( "/<!--START TABLE-->/" , "$start_table"  , $class->output );
  328.         $class->output = preg_replace( "/<!--NAME FIELDS-->/" , "$name_fields"  , $class->output );
  329.         $class->output = preg_replace( "/<!--POST BOX-->/"    , "$post_box"     , $class->output );
  330.         $class->output = preg_replace( "/<!--POST ICONS-->/"  , "$post_icons"   , $class->output );
  331.         $class->output = preg_replace( "/<!--UPLOAD FIELD-->/", "$upload_field" , $class->output );
  332.         $class->output = preg_replace( "/<!--MOD OPTIONS-->/" , "$mod_options"  , $class->output );
  333.         $class->output = preg_replace( "/<!--END TABLE-->/"   , "$end_form"     , $class->output );
  334.         
  335.         //---------------------------------------
  336.         
  337.         $class->html_add_smilie_box();
  338.         
  339.         $class->html_topic_summary($this->topic['tid']);
  340.         
  341.         $this->nav = array( "<a href='{$class->base_url}&act=SC&c={$class->forum[cat_id]}'>{$class->forum['cat_name']}</a>",
  342.                             "<a href='{$class->base_url}&act=SF&f={$class->forum['id']}'>{$class->forum['name']}</a>",
  343.                             "<a href='{$class->base_url}&act=ST&f={$class->forum['id']}&t={$this->topic['tid']}'>{$this->topic['title']}</a>",
  344.                           );
  345.                           
  346.         $this->title = $ibforums->lang['replying_in'].' '.$this->topic['title'];
  347.         
  348.         $print->add_output("$class->output");
  349.         
  350.         $print->do_output( array( 'TITLE'    => $ibforums->vars['board_name']." -> ".$this->title,
  351.                                    'JS'       => 1,
  352.                                    'NAV'      => $this->nav,
  353.                               ) );
  354.         
  355.     }
  356.     
  357.  
  358. }
  359.  
  360. ?>