vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   PHP make thread (https://vborg.vbsupport.ru/showthread.php?t=319314)

Duckface 07-02-2015 03:19 PM

PHP make thread
 
Hi, I've made this today:

http://spawnscape614.co.uk/forums/reportuser.php

And I'm looking to taking these inputs and then make a thread based off this information. I'll obviously validate it so that you must be logged in to see to use the form although , via the SEND button which you see what's the most basic method for this? I've seen the function on VB where you can automatically make a thread when a user reports a thread; so I only assume that it would be similar?

MarkFL 07-02-2015 03:46 PM

One of my products auto-creates a thread, and here is the code that actually handles creating the thread:

PHP Code:

                // Create the report thread.

                // Temporarily override the maximum characters that can be included in a post.
                
$maxchars $vbulletin->options['postmaxchars'];
                
$vbulletin->options['postmaxchars'] = 0;

                
$mthread =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
                
$reportforuminfo fetch_foruminfo($mforumid);
                
$reportthreadinfo = array();
                
$mpostip "";
                
$mallowsmilie '1';
                
$mvisible 1;
                
$showsig 1;
                
$mthread->set_info('forum',    $reportforuminfo);
                
$mthread->set_info('thread',   $reportthreadinfo);
                
$mthread->set_info('skip_floodcheck'true);
                
$mthread->setr('forumid',      $mforumid);
                
$mthread->setr('userid',       $muserid );
                
$mthread->setr('pagetext',     $report);
                if (
$vbulletin->options['markfl_report_prefixes_enabled'])
                {
                    
$mthread->set('prefixid',      'reportthread_unsolved');
                }
                
$mthread->setr('title',        $title);
                
$mthread->set('allowsmilie',   $mallowsmilie);
                
$mthread->set('visible',       $mvisible);
                
$mthread->set('ipaddress',     $mpostip);
                
$mthread->set('showsignature'$showsig);
                
$mthread->pre_save();
                if (
count($mthread->errors) < 1)
                {
                    
$threadid $mthread->save();
                    unset(
$mthread);
                    
build_thread_counters($mthread);
                }
                else 
                {
                    print 
"Error making new thread! " $mthread->errors[0] . $mthread->errors[1] . $mthread->errors[2] ;
                }
                
build_forum_counters($forumid);

                
//Restore setting for maximum characters allowed in posts.
                
$vbulletin->options['postmaxchars'] = $maxchars


Duckface 07-10-2015 11:06 AM

Thanks! Could you help me with configure this. I've pmed you.

MarkFL 07-10-2015 01:07 PM

I failed to mention before that you will need this line before using the data manager:

PHP Code:

require_once(DIR '/includes/functions_databuild.php'); 

Can you post all of your code so far and I may be able to give you some pointers. :D

Duckface 07-10-2015 02:19 PM

Hiya

So far: (relevant part)

PHP Code:

<?php
session_start
();
$formErr "";
$username $when $where "";

            if (isset(
$_GET['submit'])) {
                if (empty(
$_GET["username"]) || empty($_GET["when"]) || empty($_GET["where"])) {
                    
$formErr "<br>You have not completed the entire form - everything must be completed! (*)";
                } else {
                    
$username $_GET["username"];
                    
$when $_GET["when"];
                    
$where $_GET["where"];
                    
//after variables retrieved for inputs:
                    
sendReport();
                }
            }
            
        function 
sendReport() {
                
$maxchars $vbulletin->options['postmaxchars']; 
                
$vbulletin->options['postmaxchars'] = 0

                
$mthread =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
                
$reportforuminfo fetch_foruminfo($mforumid); 
                
$reportthreadinfo = array(); 
                
$mpostip ""
                
$mallowsmilie '1'
                
$mvisible 1
                
$showsig 1
                
$mthread->set_info('forum',    $reportforuminfo); 
                
$mthread->set_info('thread',   $reportthreadinfo); 
                
$mthread->set_info('skip_floodcheck'true); 
                
$mthread->setr('forumid',      33); 
                
$mthread->setr('userid',       $muserid ); 
                
$mthread->setr('pagetext',     $report); 
                if (
$vbulletin->options['markfl_report_prefixes_enabled']) 
                { 
                    
$mthread->set('prefixid',      'reportthread_unsolved'); 
                } 
                
$mthread->setr('title',        $title); 
                
$mthread->set('allowsmilie',   $mallowsmilie); 
                
$mthread->set('visible',       $mvisible); 
                
$mthread->set('ipaddress',     $mpostip); 
                
$mthread->set('showsignature'$showsig); 
                
$mthread->pre_save(); 
                if (
count($mthread->errors) < 1
                { 
                    
$threadid $mthread->save(); 
                    unset(
$mthread); 
                    
build_thread_counters($mthread); 
                } 
                else  
                { 
                    print 
"Error making new thread! " $mthread->errors[0] . $mthread->errors[1] . $mthread->errors[2] ; 
                } 
                
build_forum_counters($forumid); 

                
//Restore setting for maximum characters allowed in posts. 
                
$vbulletin->options['postmaxchars'] = $maxchars;  
        }    
?>


MarkFL 07-10-2015 02:35 PM

Okay, aside from the file you need to require that I posted in #4, it looks to me that you will need to pass the forum and thread information to your sendReport function. Also, you will need to initialize many of the variables being used. You don't need the if block regarding the thread prefix.

It appears you get a username from the form, so you will have to query the user table to get the corresponding userid. Any data needed by the function will either have to be global or passed as parameters (which I recommend).

Duckface 07-10-2015 02:40 PM

Quote:

Originally Posted by MarkFL (Post 2549850)
Okay, aside from the file you need to require that I posted in #4, it looks to me that you will need to pass the forum and thread information to your sendReport function. Also, you will need to initialize many of the variables being used. You don't need the if block regarding the thread prefix.

It appears you get a username from the form, so you will have to query the user table to get the corresponding userid. Any data needed by the function will either have to be global or passed as parameters (which I recommend).

The offender's username is for the "in-game" and nothing to do with the forums.

MarkFL 07-10-2015 02:41 PM

Okay...who will be the author of the auto-created thread?

Duckface 07-10-2015 02:41 PM

^^ the user logged into the forums. I'll make it so the user must be logged in.

So what exactly is the function that sends a request to make a thread?

MarkFL 07-10-2015 02:46 PM

Well, you can use the datamanager (as I did) or you can write directly to the "thread" table to insert a new row. In either case you still want to update the counters.


All times are GMT. The time now is 12:40 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01202 seconds
  • Memory Usage 1,809KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete