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.

Duckface 07-10-2015 02:58 PM

I tried your script and I got an error.

I tried using this:

PHP Code:

session_start();
$formErr "";
$username $when $where $offence "";

            if (isset(
$_GET['submit'])) {
                if (empty(
$_GET["username"]) || empty($_GET["when"]) || empty($_GET["where"]) || empty($_GET["offence"])) {
                    
$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() {
            require_once(
'./includes/functions_databuild.php');             
            
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');

            
$forumid 33;//$vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;

            
$foruminfo fetch_foruminfo($forumid);
            
$threaddm->set_info('forum'$foruminfo);

            
$threaddm->set('forumid'$foruminfo['forumid']);
            
$threaddm->set('userid'19);
            
$threaddm->set('title''PHP MAKE THREAD TEST');
            
$threaddm->set('pagetext''PHP MAKE THREAD TEST');
            
$threaddm->set('allowsmilie'1);
            
$threaddm->set('visible'1);
            
$threaddm->set('dateline'TIMENOW);
            
$threaddm->save(); 
        } 

And still an error.

MarkFL 07-10-2015 03:01 PM

You need to pass parameters to the function...for starters, try passing $foruminfo to the function...

Duckface 07-10-2015 03:15 PM

Ok I tried without a function and purely tried on the else statement:

PHP Code:

            if (isset($_GET['submit'])) {
                if (empty(
$_GET["username"]) || empty($_GET["when"]) || empty($_GET["where"]) || empty($_GET["offence"])) {
                    
$formErr "<br>You have not completed the entire form - everything must be completed! (*)";
                } else {
                    
$username $_GET["username"];
                    
$when $_GET["when"];
                    
$where $_GET["where"];
                    
$forumid "33";
                    
$threadinfo = array();
                    
$foruminfo fetch_foruminfo($forumid);
                    
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
                    
$threaddm->set('forumid'$forumid);
                    
$threaddm->set('userid'"1");
                    
$threaddm->set('pagetext''textul meu');
                    
$threaddm->set('title''titlul meu');
                    
$threaddm->set('allowsmilie''1');
                    
$threaddm->set('visible''1');
                    
$threaddm->set_info('forum'$foruminfo);
                    
$threadid $threaddm->save();
                    
build_forum_counters($forumid);                    
                }
            } 

And still receiving a blank page (assuming error).

MarkFL 07-10-2015 03:25 PM

You need the required file for the datamanager, but you should have gotten an explicitly stated error.

Duckface 07-10-2015 06:05 PM

SOLVED.

MarkFL 07-10-2015 06:31 PM

Perhaps try $vbulletin->userinfo['userid']...:D

Duckface 07-10-2015 07:02 PM

Quote:

Originally Posted by MarkFL (Post 2549875)
Perhaps try $vbulletin->userinfo['userid']...:D

Ah thanks that worked.

I'm trying to get strings on the same line as a string and it's not working...

PHP Code:

$threaddm->set('title''CASE: ',$username' - '$offence); 


MarkFL 07-10-2015 07:07 PM

In PHP you add strings with a period, so use:

PHP Code:

$threaddm->set('title''CASE: ' $username ' - ' $offence); 


Duckface 07-10-2015 07:11 PM

Ahh, it's in some ways similar to java so I forget. Thank you.

MarkFL 07-10-2015 07:14 PM

Yeah, that threw me for a loop not that long ago...:D

Duckface 07-10-2015 07:15 PM

Quote:

Originally Posted by Duckface (Post 2549881)
Ahh, it's in some ways similar to java so I forget. Thank you.

How do you break a string to put it on two lines? So

PHP Code:

$threaddm->set('pagetext''Username Reporting: ' $username); //THEN ADD SOMETHING TO THE NEXT LINE 


MarkFL 07-10-2015 07:19 PM

What I suggest doing for clarity, is to build all of your strings first and then set the values.

Duckface 07-10-2015 07:24 PM

Quote:

Originally Posted by MarkFL (Post 2549885)
What I suggest doing for clarity, is to build all of your strings first and then set the values.

Hmm. Good tip.

I've tried using /n and /r but:

https://vborg.vbsupport.ru/external/2015/07/23.png

MarkFL 07-10-2015 09:09 PM

I misunderstood what you were wanting to do...try something like:

PHP Code:

$pagetext $line1 PHP_EOL $line2 PHP_EOL $line3 

The constant "PHP_EOL" (End Of Line) is cross-platform compatible too.

Duckface 07-10-2015 11:59 PM

Quote:

Originally Posted by MarkFL (Post 2549894)
I misunderstood what you were wanting to do...try something like:

PHP Code:

$pagetext $line1 PHP_EOL $line2 PHP_EOL $line3 

The constant "PHP_EOL" (End Of Line) is cross-platform compatible too.

Thank you so much for your assistance today, you've truly helped my PHP development as well; which was atrocious :).

MarkFL 07-11-2015 12:05 AM

I'm glad I was able to help you out. :D

Duckface 07-12-2015 05:06 PM

PHP Code:

$threaddm->set('parseurl''1'); 

I tried that to ensure that the links are parsed; but it isn't finding that method.

What's the method name for parsing the links?

Duckface 07-14-2015 06:03 PM

How do I make the thread automatically parse the links?

I've tried:

PHP Code:

//$threaddm->set('parselinks', true);        //Not working 

And it doesn't work :/.

kh99 07-14-2015 06:14 PM

I think it might be:
PHP Code:

$threaddm->set_info('parseurl'true); 

ETA: And I think you might need to do that before pagetext is set.

Duckface 07-15-2015 02:24 PM

Quote:

Originally Posted by kh99 (Post 2550222)
I think it might be:
PHP Code:

$threaddm->set_info('parseurl'true); 

ETA: And I think you might need to do that before pagetext is set.

Yea I'll give that a try thanks.

Duckface 07-16-2015 04:02 PM

I have this plugin my forum:

https://vborg.vbsupport.ru/showthread.php?t=240772

I have already put the section id into the block from seeing in chatbox section. Altough because it's sending a thread via the php file; it's being displayed in the chatbox.

I found this within the XML file:

Code:

                <plugin active="1" executionorder="5">
                        <title>VSA New Thread</title>
                        <hookname>threadfpdata_postsave</hookname>
                        <phpcode><![CDATA[global $vbulletin;
if ($vbulletin->options['vsaaddon_enable_product'] AND $vbulletin->options['vsaaddon_enable_threadplugin'])
{
if (trim($vbulletin->options['vsaaddon_blockedforums']) != '')
{
$vsaforumids = preg_split('#\s+#s', $vbulletin->options['vsaaddon_blockedforums'], -1, PREG_SPLIT_NO_EMPTY);
} else { $vsaforumids = Array('0'); }
if (!in_array($this->info['forum']['forumid'], $vsaforumids)) {
$username = $vbulletin->db->escape_string($vbulletin->userinfo['username']);
if ($username == Unregistered) {
$username = $vbulletin->options['vsaaddon_rsspost'];
}
$usergroup = $vbulletin->userinfo['usergroupid'];
$usernamecolor = $vbulletin->db->query_first("SELECT opentag FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = ". $usergroup . "");
$usernameopen = $usernamecolor['opentag'];
preg_match("#<span[^style|>]?style=['|\"]?[^color:]color:[\s+]?(.*?)[;]?['|\"]?['|\"]?>#",$usernameopen,$newcolor);
if ($newcolor[1] == '')
{
$newcolor[1] = $vbulletin->options['vsaaddon_useridcolor'];
}
$message = '[color=' .$newcolor[1]. ']' . $username . '[/color][color=' .$vbulletin->options['vsaaddon_threadcolor']. '] has posted the thread[/color] [thread=' . $this->thread['threadid'] . ']'  . $titleprefix . unhtmlspecialchars($this->thread['title']) . $titlesuffix . '[/thread]';
$message = str_replace("'", "", $message);

                    $vbulletin->db->query_write("
                        INSERT INTO ".TABLE_PREFIX."vsa_chatbox
                            (userid, userip, message, dateline, textprop)
                        VALUES ('".$vbulletin->options['vsaaddon_userid']."', '".$_SERVER['REMOTE_ADDR']."', '".$message."', ".TIMENOW.", '')
                    ");
}
}]]></phpcode>
                </plugin>

I'm wondering whether I could add something that will block the notification from displaying on the chatbox.


All times are GMT. The time now is 01:26 AM.

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.01402 seconds
  • Memory Usage 1,926KB
  • 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
  • (1)bbcode_code_printable
  • (14)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (31)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete