Creating a New Thread using vBulletins API
I really hope this will help some of you, as I spent ages searching the Internet tring to find something to do this, and ended up having to write my own.
This basically does exactly what the title says. It creates a new thread in a forum on your vbulletin forum. It works for me in the latest version of vBulletin, but I'm not sure how far back it will work. But you should have your vBulletin up to date anyway. If you notice any bugs/problems or anything I have done wrong, please correct me. PHP Code:
|
When would you use this? Like in a cron job (scheduled task) to create a new thread?
|
Quote:
This is just a handy piece of code that should let anyone create a script around it (if they know a bit of PHP) to create threads for whatever reason they may have! |
1. you don't need to inlcude this files:
PHP Code:
2. why you eval this part?: PHP Code:
|
Thanks ragtek, have edited my code and post. I evaled it because I thought to make it secure from SQL exploits you had to. Maybe it was something in a previous vB version, I'm not sure. I've removed it and it's still working fine, and the addslashes still works.
Thanks! |
Thanks for making it painless. :)
You might want to replace the addslashes() calls with mysql_real_escape_string() though. Thanks again! --------------- Added [DATE]1262068851[/DATE] at [TIME]1262068851[/TIME] --------------- I spoke too soon (about it being painless)... I have a site where the forums are secondary to the rest of the site, which is also database driven. What I first tried to do was incorporate the above code into my admin interface so that when I added or edited a record in the database, the details of that record would be posted as a new thread. It almost worked, but I was getting an error that I couldn't get around, and googling it led me to believe that it had to me having an existing database connection when I tried to load the vB includes. No big deal, right? I'll just put the code into a separate script, and POST a request to that script, so it'll be completely independent of my own stuff. Kind of clunky, but whatever - as long as it works. :) It didn't. :( Sort of. I'm able to create a new thread, and the title & content are there, but the body of the post is showing the \n (carriage returns) instead of converting them to.. carriage returns. So instead of this: Quote:
Quote:
I added some debugging code to make sure that I'm POSTing the data correctly and that it's coming through on the other side properly, and everything seems hunky dory. I also tried running nl2br() on the content data, but then I just get: Quote:
It seems like it should be totally trivial - and maybe it is (I've been coding all day with very little sleep last night) - but I can't figure it out. What am I missing? (And before anyone asks, yes, I'm enclosing the \n's in double quotes. ;) ) --------------- Added [DATE]1262108422[/DATE] at [TIME]1262108422[/TIME] --------------- Ok, after some sleep, I realized what was happening. Don't use my suggestion of replacing addslashes() with mysql_real_escape_string() - it was escaping the carriage returns and literally inserting a \n into the text. All is right in the universe now. :) |
Very nice script!
One question: once created, how can I retrieve the newly created thread id? |
PHP Code:
|
Why I have never spotted this thread is a riddle to me. I ploughed through dozens of them and ended up doing roughly the same thing as you. Even posted a question if my working code was complete like that in the vb3 programming discussion forum. *sigh*..
|
Quote:
|
Is there a way to add:
1. The signature of the 'set' poster? 2. a Prefix to a title? |
works perfectly
thanks a bunch /gibigbig |
thanks for this, now to think of how I can use it :)
|
Is there a way to have the code outside of the vB-directory?
e.g. [root] _[non-public] ___create_thread_external.php _[folder1] _[folder2] _[vB] I've tried to change thoose two lines: PHP Code:
PHP Code:
Thansk in advance Kesandal Edit I could fix the problem. For thoose who are getting the same problem; Just add thoose few lines above your page: PHP Code:
|
Sorry to bump an old thread....
is addslashes() for title & content necessary? I'm just curious if it's redundant. When I use the above, in my posts I get slashes along with my quotes :( Thanks! |
Can a similar approach be used to create CMS articles in 4+?
|
Thank you very much for this thread. Worked perfectly.
|
Quote:
|
Thanks! You helped me a ton!
|
i try it on version 4.1.12 and it create new thread, so it works on 4+.
thx for the script:) |
I've got error
Quote:
Quote:
|
Could this be used to create a new thread from a Microsoft Excel VBA module?
|
This works great, 5 years later hah..
Thanks |
Where would you place this script?
|
Thanks.
|
All times are GMT. The time now is 02:29 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|