vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Auto-creation of threads? (https://vborg.vbsupport.ru/showthread.php?t=61030)

Wired1 02-01-2004 06:43 AM

Auto-creation of threads?
 
Hey guys, I'm working on a site where I will have certain admins enter in data into a form, which slaps the data into a couple of tables. What I'd like it to do is to create a new thread in a specific forum based upon certain pre-existing criteria. It will only create a new thread when new data is entered. It would be great if I could have it also create the sub-forums, but I can handle that myself for the time being.

In one of the tables will be a column for the forum ID that the new thread will be created in. I've been looking through the functions_newpost.php and newthread.php, but I'm not quite sure how to set it up so that it will create the thread for me. Yes, I do intend for it to create a first post with relevant info.

Uniquely formatting the first post of these auto-created threads will be my next venture. The problem I'm having is the actual vB stuff, how to get it to make a new thread, the integration stuff. If I'm right, I should just be able to pass values to the title and message variables into the newthread.php file, along with the value of f, which is the forumID, and it will do the rest, but I'm not quite sure.

So, has anyone else done something like this before? Can anyone point me in the right direction? Thanks!

BTW, I've taken a quick look at the talker bot code, and some of it points towards how new posts can be created, but not new threads. Hope that helps anyone else that's interested in a snippet like this.

Xenon 02-01-2004 04:21 PM

in functions_newpost.php there is the build_newpost function, you just have to submit an array to this functions containing all info like forumid, authorid, message.... and type = 'thread' and it will insert the new thread for ya

Wired1 02-02-2004 02:38 AM

Well, that certainly seems easier than submitting info directly to multiple tables like it was seeming I was going to have to do.

I've been thinking of the message portion. For example, in my first post in this thread, I spaced out the paragrahs, but when I check out the table entry for a similar post, it appears as if the paragrahs just run together. In otherwords, is there any secret to get the formatting right?

Also, if I wanted to place an image within the message in a certain place if the pic flag is marked in a table, would it be easier to just have an if statement within the postbit template for this, or is there a way to easily set up the formatting in the afforementioned functions? I already have an if stmt in the postbit to make any post by the bot formatted in a non-default way.

Xenon 02-02-2004 02:05 PM

it's safer to use if statements, especially if you already did something like that already.

i don't get what you mean by getting the formatting right.
When you enter a post directly to the db, it's not different than posting it manually, it will be parsed when you go to showthread, and there it will convert all new lines(\n) into <br /> tags

Wired1 02-02-2004 10:05 PM

Hrm... I'm using the Webmin sw that's on my server (RedHat IIRC) and looking into the post table, I don't see the HTML formatting (i.e. \n, etc.) and the test just runs together... Wait... if I go in to edit an entry, the formatting isn't there (\n) but it looks normal, yippee!

Ok, this is making much more sense now, eheh. Thanks Xenon. I'll report back if everything goes well or not, and if it does, it'll be quite an interesting site!

Wired1 02-04-2004 11:25 PM

Code:

function build_new_post($type = 'thread', $foruminfo, $threadinfo, $parentid, &$post, &$errors)
Ok, I found it and I've been looking into the arguments, i.e. $foruminfo. It looks like it's an array. However, I can't find an easy list on all of the values that I need to pass to it. Same goes for $threadinfo. &$post I think I've got down as the description of the function details it. Somewhat worried about
Code:

        $post['posthash'] = trim($post['posthash']);
but I'll leave them for later.

Code:

$foruminfo = verify_id('forum', $_REQUEST['forumid'], 1, 1);
I did find this snippet pertaining to $foruminfo, but I've seen other array cells referenced throughout the code.

Xenon 02-04-2004 11:26 PM

just look into the forum / thread /post table.

every field you have in these tables can be within the $...info array.
but you don't have to use every entry ;)

Wired1 02-05-2004 03:09 AM

Gotcha. They really need better commenting in their code :) Is there a code comment manual I missed or something?

Xenon 02-05-2004 05:03 PM

not right now, but iirc something like that is planned :)

you have to remember vb3 is not yet released final ;)

Wired1 02-06-2004 02:11 AM

Hehe, I know, but when I was checking out vb2 code, I don't recall seeing any decent amount of comments either. Starting a bit of coding right now, I'll update this with the results.

Update: Grrrr........

Here's my code so far:
PHP Code:

require_once('./forums/includes/functions_newpost.php');
require_once(
'./forums/includes/functions.php');
require_once(
'./forums/includes/functions_login.php'); 

$foruminfo['forumid'] = 8;
$threadinfo['open'] = 1;
$threadinfo['visible'] = 1;

//$threadinfo['title'] = 'This is the test title';
//$threadinfo['forumid'] = 8;
//$threadinfo['postusername'] = 'Poster';
//$threadinfo['postuserid'] = 5;


$post['title'] = 'This is the test title';
$post['username'] = 'Poster';
$post['userid'] = 5;
$post['pagetext'] = 'This is the message stuff\n    Hope this words\n\n\n\n TESTTTTTTT\n';
$post['preview'] = 0;

build_new_post('thread'$foruminfo$threadinfo0$post$errors); 

I'm getting this error:
Warning: build_new_post(./includes/functions_login.php): failed to open stream: No such file or directory in .../includes/functions_newpost.php on line 212

Fatal error: build_new_post(): Failed opening required './includes/functions_login.php' (include_path='.:/usr/share/pear') in .../includes/functions_newpost.php on line 212
Line 211-213:
PHP Code:

// remove sessionhash from urls:
require_once('./includes/functions_login.php');
$post['message'] = fetch_removed_sessionhash($post['message']); 

After I got that error, I added the require into the page, but with no effect. Any suggestions?

BTW, after this darn thing gets functional, I think I'll slap the good stuff from this thread and post a basic tutorial about this so it can help others. That ok with you? If so, what sub-forum would you recommend it be placed in?

Xenon 02-06-2004 01:01 PM

the subforum would be modification hints and tips :)

as for your problem: hmm, wierd, it seems like you are calling the function files out of the wrong directory.

isn't your script located within the forum directory?

you may want to add a chdir('..'); before the first require once of your script above.

Wired1 02-06-2004 07:53 PM

Yes, the test file was outside the directory. Moving it inside did get rid of that, but more have come :)

Fatal error: Call to a member function on a non-object in ...forums/includes/functions.php on line 259

That line is within the function fetch_phrase, which is used in function verify_post_errors, which is used in this snippet within functions_new_post.
PHP Code:

    if ($_REQUEST['fromquickreply'] AND $post['preview'])
    {
        
$errors = array();
    }
    else
    {
        
verify_post_errors($type$post$errors);
    } 

Tracing code use is fun kids! lol
Ok, so $post['preview'] has already been set to 0 in the code I listed in the test file a couple of posts back. Not real sure how to set $_REQUEST['fromquickreply'] to the correct value though. Tracing it back, I think that's a default setting. I'm starting to get the feeling that a manual INSERT might work better, but I'm not giving up yet!

Xenon 02-06-2004 11:19 PM

wierd, i haven't had any problems, i added the build_newpost to a script of mine myself and it worked flawless (ok not creating a new thread, just post...)

the errormessage you have sounds like you have to add a global $DB_site; at the correct part of your script ;)

or better said, does your script include the global.php so the connection to the DB is set up already?

Wired1 02-07-2004 01:00 AM

... ... ... nope... LMAO! It was there at one point, must've deleted it accidentally! Added that, then re-ran it, got an odd vB error, refreshed, and it went in! Getting an odd error though:
Code:

Database error in vBulletin 3.0.0 Release Candidate 3:

Invalid SQL:
SELECT CONCAT(newthreademail ,' ', newpostemail) AS newpostemail
FROM forum WHERE forumid IN ()
               
mysql error: You have an error in your SQL syntax near ') ' at line 4
mysql error number: 1064

Now the data is getting into the thread in the right place. Also just found out that every time that happens, I get a DB error email lol! 2 odd things though, which I'll cover after this code, which is the latest incarnation of the test code:
Code:

require_once('./global.php');
require_once('./includes/functions_newpost.php');
require_once('./includes/functions.php');
require_once('./includes/functions_login.php');

$foruminfo['forumid'] = 10;
$threadinfo['open'] = 1;
$threadinfo['visible'] = 1;

$threadinfo['title'] = '3rd';

$post['title'] = 'sdfsdfsdf';
$post['message'] = 'This is the message stuff';

build_new_post('thread', $foruminfo, $threadinfo, 0, $post, $errors);
verify_post_errors($type, $post, $errors);

the threadinfo['title'] doesn't do diddly, even when the post['title'] is commented out. Also, I'd like the post specific title to be nothing, but I can always remove it in the postbit.

I've also found out that it uses the cookie's session to use my username/id, not the one in the test file. I was wondering if there's a way to have it log out the user, log in with the Bot's Username/PW, then after it's done, log out. Would probably be easier for the poster to just log out of their user name and login to the bot's acct.

BTW, I take it back about what I said about their code comments, was looking around the vb.com site, and found the pdf with the ERD for the database... WOAH! I'll wait to see vB3 final to see what code comments they say...

Xenon 02-07-2004 10:35 PM

replace the code
PHP Code:

$foruminfo['forumid'] = 10

with that:
PHP Code:

$forumid 10;
$foruminfo fetch_foruminfo($forumid); 

that should avoid the db error i think.

as for your second question.
if you just use the init.php instead of global.php i think it doesn't use your account, but does create the thread as well. (but i don't give guarantee for that ;))

version2 02-07-2004 11:46 PM

I am glad to see this thread because I am working on a hack that will be posting new threads and posts as well. Right now I am looking at your code and upon testing it out for myself I have two problems I can see. First I get a dberror:

PHP Code:

Invalid SQL
            
INSERT INTO post
                
(threadidparentidtitleusernameuseriddatelinepagetextallowsmilie,
                 
showsignatureipaddressiconidvisibleattach)
            
VALUES
                
(0, , '',
                 
'mol'11076204664,
                 
'This is the message stuff'10,
                 
'127.0.0.1'010

Now, the second this I see is that I passed a different username and id than the one that is being used. I assume its going off cookie info! As for using init.php, well...that didnt help much except for getting rid of the dberror. Still no thread being created.

version2 02-08-2004 12:11 AM

Ok. I have created a thread! Woot. Now, I have to figure out how to go around the cookie problem. It is still posting as a different user than what I have hardcoded into it. The next step is how to post a new post in the thread that was just created.

version2 02-08-2004 12:20 AM

Quote:

Originally Posted by version2
Ok. I have created a thread! Woot. Now, I have to figure out how to go around the cookie problem. It is still posting as a different user than what I have hardcoded into it. The next step is how to post a new post in the thread that was just created.

Well, ok. I got it. It was $threadinfo['iconid'] giving me fits of all things. I am now creating new threads and follow up posts.

Now, to fix the userid problem.

version2 02-08-2004 12:23 AM

Ok. Update. When using the init.php and bypassing global in hopes of the bbuserinfo not taking over I am getting an invalid posthash as a result:

PHP Code:

Invalid SQL
            
SELECT COUNT(*) AS count
            FROM attachment
            WHERE posthash 
'invalid posthash'
                
AND userid 


version2 02-08-2004 12:34 AM

Quote:

Originally Posted by version2
Ok. Update. When using the init.php and bypassing global in hopes of the bbuserinfo not taking over I am getting an invalid posthash as a result:

PHP Code:

Invalid SQL
            
SELECT COUNT(*) AS count
            FROM attachment
            WHERE posthash 
'invalid posthash'
                
AND userid 


All right. I am done talking to myself. Hopefully this will help someone in the future. I got around the cookie problem by declaring the username and then grabbing the bbuserinfo using that username. I am also using init.php and not global.php. Everything seems to be working. All counts are being update, etc.

Andreas 02-08-2004 12:45 AM

Basic code to post a new thread (as any user you want):

PHP Code:

chdir('/path/to/forum/root');

// Load vB-Backend
require('./global.php');
require(./
includes/functions_newpost.php');

$userid = 1234; // The user creating the thread
$forumid = 12; // The forum where the thread should be posted

// Get forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);

// Setup the thread
$post[title] = '
Some foobar title';
$post[message] = '
Some foobar message text';
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['
userid'] . $bbuserinfo['salt']);

// build the thread
build_new_post('
thread', $foruminfo, array(), 0, $post, $errors);

// Errors?
if (sizeof($errors) > 0)) {
  // error processing



Wired1 02-08-2004 12:47 AM

Quote:

Originally Posted by version2
All right. I am done talking to myself. Hopefully this will help someone in the future. I got around the cookie problem by declaring the username and then grabbing the bbuserinfo using that username. I am also using init.php and not global.php. Everything seems to be working. All counts are being update, etc.

Mind sharing that bit of code? That'll save tons of work for me, eheh.

As for the rest, Finally no errors! Wait.... yep, found one! This one's minor though, can be taken care of with the bot account. For some reason, it auto subscribes me to the threads created with that script, yet not when I make one normally. Are you being auto subscribed to your threads?

Then again, not sure I want massive amounts of subscriptions in the bot's acct. Yes, auto subscribe for the acct is turned off.

Next thing to tackle is an if stmt in the postbit that if picture is part of data, pic will be displayed in the thread. That's cake, but I've been experimenting with pics and text in a post. Only way I can figure out a way to wrap the text around the pic is with table cells. Crude, but should work just fine.

Next thing I'm going to be working on is how to grab the newly created threadID (maybe even post ID) after the thread/post is made.

I'm also looking into how to auto create a forum/sub forum, but for security reasons, I think I might not let the bot have this access, and find out how to do it with normal mySQL statements. Any suggestions/tips?

Andreas 02-08-2004 12:50 AM

Quote:

Originally Posted by Wired1
Next thing I'm going to be working on is how to grab the newly created threadID (maybe even post ID) after the thread/post is made.

If you are manually dealing with the database:
$DB_site->insert_id();

Wired1 02-08-2004 12:52 AM

Kirby, thanks! That's solved the posterid prob, but it also auto-subscribes the account to the thread.

$DB_site->insert_id();

hhmm.... not quite sure how that's supposed to be used. Mind giving me an example, or a place in the vB code (or a thread here) that explains that?

version2 02-08-2004 12:53 AM

Quote:

Originally Posted by Wired1
Mind sharing that bit of code? That'll save tons of work for me, eheh.?

Dont mind at all! But, I think I have been beaten to the punch. Kirby already posted it:

PHP Code:

$userid 2;
$bbuserinfo fetch_userinfo($userid); 

Kirby's code is about what I ended up with.

Wired1 02-08-2004 12:54 AM

Thanks as well version2! BTW, I'm grabbing the threadID after it is created automatically so that I can place it into another table I created, so that another page will auto-create links to certain threads based on other criteria.

version2 02-08-2004 12:55 AM

Quote:

Originally Posted by Wired1
Kirby, thanks! That's solved the posterid prob, but it also auto-subscribes the account to the thread.

PHP Code:

$post['emailupdate'] = 9999

That'll fix the subscribe.

Andreas 02-08-2004 12:57 AM

@Wired1:

PHP Code:

$post['emailupdate'] = 9999

before calling build_new_post() should avoid subscribing the thread.

If you use this function to create the thread you can use
$post['threadid'] and $post['postid'] afterwards - the ID's will be there.

Wired1 02-08-2004 12:58 AM

Wahooo!!!!! Now to understand $DB_site->insert_id();

Wired1 02-08-2004 01:00 AM

But I can only use $post['threadid'] and $post['postid'] after the build_new_post is hit in the code, correct? I think that'll save me 1 query :)

This look right?
PHP Code:

// Load vB-Backend 
require('./global.php'); 
require(
'./includes/functions_newpost.php'); 

$userid 5// The user creating the thread 
$forumid 10// The forum where the thread should be posted 

// Get forum & user info 
$foruminfo fetch_foruminfo($forumid); 
$bbuserinfo fetch_userinfo($userid); 

// Setup the thread 
$post[title] = 'Some foobar sssstitle'
$post[message] = 'Some foobar message text'
$post[poststarttime] = TIMENOW
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']); 
$post['emailupdate'] = 9999

// build the thread 
build_new_post('thread'$foruminfo, array(), 0$post$errors); 

// Errors? 
if (sizeof($errors) > 0) { 
  
// error processing 
}
ThreadID $post['threadid']; 
PostID $post['postid']; 

ThreadID and PostID are columns in a table I have created.

Andreas 02-08-2004 01:02 AM

$DB_site->insert_id() gives you the id generated by the last mySQL INSERT statement (if inserting into a table with an auto-increment column like postid, threadid, etc.).

But you don't need that (see my previous post) if you are using vB functions to create threads/posts - only if you are manually dealing with the database.

> But I can only use $post['threadid'] and $post['postid'] after the build_new_post is hit in the code, correct?
Yes, that's correct.

Wired1 02-08-2004 01:03 AM

So would this part of the code I edited in to that last post work?
PHP Code:

// build the thread 
build_new_post('thread'$foruminfo, array(), 0$post$errors); 

// Errors? 
if (sizeof($errors) > 0) { 
  
// error processing 

ThreadID $post['threadid']; 
PostID $post['postid']; 


ThreadID and PostID are columns in a table I have created.

Andreas 02-08-2004 01:06 AM

Not really, as there are $-signs missing before ThreadID and PostID and thus it won't compile ;)
But the concept is right.

I don't know what you want to do with your table but you could call

PHP Code:

$DB_site->query("INSERT INTO yourtbl (ThreadID,PostID) VALUES ($post[threadid]$post[postid])"); 

to get the IDs into your table. Or make an update or whatever you want to to with the values.

Wired1 02-08-2004 01:09 AM

Lol yeah. Conceptually it's kewl. That definitely just solved like 5 potential SNAFUs! Trying to think if there were any other questions I had... (re-reading the thread quickly)...

Wired1 02-08-2004 01:16 AM

Ok, this is a minor one. If you look at the original post that started this thread, it has the title of the thread within the top of the post. I know that with proper use of templates an postbit this can be removed, but is there a way to prevent it from getting into the DB at all?

Also, with
PHP Code:

$DB_site->query("INSERT INTO yourtbl (ThreadID,PostID) VALUES ($post[threadid]$post[postid])"); 

$post[postid] is supposed to be $post['postid'] (quotes) correct? Also, $DB_site->query is just vB's way of doing $result = mysql_query($sql, $connection); right?

Also, what do you guys think about this comment I made earlier:

I'm also looking into how to auto create a forum/sub forum, but for security reasons, I think I might not let the bot have this access, and find out how to do it with normal mySQL statements (or $DB_site->query now that you've shown me its wonders)

M1th 02-08-2004 01:21 AM

Wow... this is almost the thing I need too!!

Er.. I want to create a thread automatically when a member reaches xth number of posts. I want to be able to exclude some forums from their post counts (that i know how to do). What I'm having trouble with is the actual conditional for this and also WHERE to put the code (which php file).

appreciate any help. :)

Wired1 02-08-2004 01:26 AM

That might boil down to a cron job, as they could hit that number at any time. There might be a way though for the vB admin system to PM or email you when members hit x # of posts, and you create it manually. then again, if it can notify u, it can make a thread :)

This will turn into one kickass tutorial for others! Much props goes to you all!

Andreas 02-08-2004 01:28 AM

> but is there a way to prevent it from getting into the DB at all?
AFAIK not. This would require a modification of build_new_post().

> $post[postid] is supposed to be $post['postid'] (quotes) correct?
You can ommit the quotes.

> Also, $DB_site->query is just vB's way of doing $result = mysql_query($sql, $connection); right?
Yes. vB uses a class (DB_sql_vb) the wraps mysql_ functions and thus makes database-handling easier.

M1th 02-08-2004 01:34 AM

Quote:

Originally Posted by Wired1
That might boil down to a cron job, as they could hit that number at any time. There might be a way though for it to PM or email you when members hit x # of posts, and you creat it manually. then again, if it can notify u, it can make a thread :)

This will turn into one kickass tutorial for others! Much props goes to you all!

Ah, thats a good way too, though, im not sure how that differs from creating a new thread/post?



Hmm, what I was thinking is, a way to do a check on members post count after they've done a new post. So the code has to go kinda after all that. Question is, where is the best place to put such a code.

Wired1 02-08-2004 01:34 AM

>> $post[postid] is supposed to be $post['postid'] (quotes) correct?
>You can ommit the quotes.

Everywhere, or just within $DB_site->query?

> Hmm, what I was thinking is, a way to do a check on members post count after
> they've done a new post. So the code has to go kinda after their own post sql > query or new post function. Question is, where is the best place to put such a
> code.

oooohhhh I get it now. Hrm... I suppose you'd slap that into the build_new_post function, or right after a call to that function. beats me where the best place would be though.


All times are GMT. The time now is 04:45 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.01527 seconds
  • Memory Usage 1,920KB
  • 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
  • (5)bbcode_code_printable
  • (16)bbcode_php_printable
  • (7)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
  • (40)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