Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
Creating a New Thread using vBulletins API
megamoose
Join Date: Feb 2007
Posts: 19

Northern Ireland
by megamoose megamoose is offline 06 Dec 2009
Rating: (1 vote - 4.00 average)

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.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Thanks to ragtek for the revised code!

Last edited by megamoose; 26 May 2013 at 20:01.. Reason: Removed link back to blog as now dead
Views: 14601
Reply With Quote
Comments
  #2  
Old 06 Dec 2009, 20:46
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Real name: Lynne
When would you use this? Like in a cron job (scheduled task) to create a new thread?
__________________
Former vBulletin.org Staff Member

Try a search before posting for help. Many users won't, and don't, help if the question has been answered several times before.
W3Schools -
Online vBulletin Manual
If I post some CSS and don't say where it goes, put it in the additional.css template.
I will NOT help via PM (you will be directed to post in the forums for help.)
Reply With Quote
  #3  
Old 06 Dec 2009, 21:05
megamoose's Avatar
megamoose megamoose is offline
 
Join Date: Feb 2007
Real name: Mark Wylde
Originally Posted by Lynne View Post
When would you use this? Like in a cron job (scheduled task) to create a new thread?
You can use this for a number of things like I have a database of jokes so I am going to run a cron every X hours to create new threads with the jokes in it. There are loads of uses for it like you can use it to let an external script (like a blog) create a new thread.

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!
__________________
.
Reply With Quote
  #4  
Old 07 Dec 2009, 08:33
ragtek's Avatar
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
1. you don't need to inlcude this files:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

it's happening automatic
2.
why you eval this part?:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
my addons: http://ragtek.github.com
Reply With Quote
  #5  
Old 07 Dec 2009, 17:13
megamoose's Avatar
megamoose megamoose is offline
 
Join Date: Feb 2007
Real name: Mark Wylde
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!
__________________
.
Reply With Quote
  #6  
Old 29 Dec 2009, 01:22
tms1791 tms1791 is offline
 
Join Date: Mar 2007
Thanks for making it painless.

You might want to replace the addslashes() calls with mysql_real_escape_string() though.

Thanks again!

--------------- Added 29 Dec 2009 at 05:40 ---------------

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:
The quick brown
fox jumped over
the slow
lazy dog.
I get this:
The quick brown\nfox jumped over\nthe slow\nlazy dog.
in the post.

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:
The quick brown<br />fox jumped over<br />the slow<br />lazy dog.
in the body of the post.

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 29 Dec 2009 at 16:40 ---------------

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.

Last edited by tms1791; 29 Dec 2009 at 16:40. Reason: Auto-Merged DoublePost
Reply With Quote
  #7  
Old 21 Apr 2010, 12:41
NolanChart NolanChart is offline
 
Join Date: Apr 2010
retrieve the thread id?

Very nice script!

One question: once created, how can I retrieve the newly created thread id?
Reply With Quote
  #8  
Old 21 Apr 2010, 12:50
ragtek's Avatar
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
my addons: http://ragtek.github.com
Reply With Quote
  #9  
Old 21 Apr 2010, 12:59
Digma Digma is offline
 
Join Date: Nov 2004
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*..
Reply With Quote
  #10  
Old 21 Apr 2010, 13:20
NolanChart NolanChart is offline
 
Join Date: Apr 2010
Originally Posted by ragtek View Post
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
Boy, do I feel dumb!
Reply With Quote
  #11  
Old 21 Apr 2010, 18:05
Digma Digma is offline
 
Join Date: Nov 2004
Is there a way to add:
1. The signature of the 'set' poster?
2. a Prefix to a title?
Reply With Quote
  #12  
Old 20 May 2010, 15:54
pein87's Avatar
pein87 pein87 is offline
 
Join Date: Sep 2008
works perfectly
thanks a bunch

/gibigbig
__________________


Were your Naruto Soul comes to place..

Reply With Quote
  #13  
Old 20 May 2010, 15:56
Brandon Sheley's Avatar
Brandon Sheley Brandon Sheley is offline
 
Join Date: Mar 2005
Real name: Brandon
thanks for this, now to think of how I can use it
__________________

Email me for website help: brandon[at]sheley[dot]org
Reply With Quote
  #14  
Old 24 Oct 2010, 14:45
kesandal kesandal is offline
 
Join Date: Oct 2010
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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The result:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Any ideas?
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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Last edited by kesandal; 25 Oct 2010 at 09:39. Reason: Solution found
Reply With Quote
  #15  
Old 27 Oct 2010, 16:02
FortressGamers FortressGamers is offline
 
Join Date: Oct 2010
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!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 19:16.

Layout Options | Width: Wide Color: