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