![]() |
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. |
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
|
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. |
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 |
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! |
Code:
function build_new_post($type = 'thread', $foruminfo, $threadinfo, $parentid, &$post, &$errors) Code:
$post['posthash'] = trim($post['posthash']); Code:
$foruminfo = verify_id('forum', $_REQUEST['forumid'], 1, 1); |
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 ;) |
Gotcha. They really need better commenting in their code :) Is there a code comment manual I missed or something?
|
not right now, but iirc something like that is planned :)
you have to remember vb3 is not yet released final ;) |
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:
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:
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? |
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. |
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:
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! |
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? |
... ... ... 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: Code:
require_once('./global.php'); 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... |
replace the code
PHP Code:
PHP Code:
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 ;)) |
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:
|
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.
|
Quote:
Now, to fix the userid problem. |
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:
|
Quote:
|
Basic code to post a new thread (as any user you want):
PHP Code:
|
Quote:
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? |
Quote:
$DB_site->insert_id(); |
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? |
Quote:
PHP Code:
|
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.
|
Quote:
PHP Code:
|
@Wired1:
PHP Code:
If you use this function to create the thread you can use $post['threadid'] and $post['postid'] afterwards - the ID's will be there. |
Wahooo!!!!! Now to understand $DB_site->insert_id();
|
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:
|
$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. |
So would this part of the code I edited in to that last post work?
PHP Code:
ThreadID and PostID are columns in a table I have created. |
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:
|
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)...
|
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:
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) |
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. :) |
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! |
> 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. |
Quote:
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. |
>> $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 | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|