View Full Version : Auto-creation of threads?
Wired1
02-01-2004, 06:43 AM
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
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 $post['posthash'] = trim($post['posthash']); but I'll leave them for later.
$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:
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, $threadinfo, 0, $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:
// 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.
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:
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:
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
$foruminfo['forumid'] = 10;
with that:
$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:
Invalid SQL:
INSERT INTO post
(threadid, parentid, title, username, userid, dateline, pagetext, allowsmilie,
showsignature, ipaddress, iconid, visible, attach)
VALUES
(0, , '',
'mol', 1, 1076204664,
'This is the message stuff', 1, 0,
'127.0.0.1', 0, 1, 0)
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
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:
Invalid SQL:
SELECT COUNT(*) AS count
FROM attachment
WHERE posthash = 'invalid posthash'
AND userid =
version2
02-08-2004, 12:34 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:
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):
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
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
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
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:
$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
Kirby, thanks! That's solved the posterid prob, but it also auto-subscribes the account to the thread.
$post['emailupdate'] = 9999;
That'll fix the subscribe.
Andreas
02-08-2004, 12:57 AM
@Wired1:
$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?
// 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?
// 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
$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 $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)
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.
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.
version2
02-08-2004, 02:44 PM
>> $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 right. Here is one for ya. I have my script working great on my test machine. I move it to the production server and boom. Nothing. I get no output. No errors. No posts or threads being created. Nada. Changed the userid and forumid correctly. Everything else is the same.
Anyone got any ideas for me to check out?
Wired1
02-08-2004, 06:26 PM
Go back to the last post I made with the full code in it. Does that work on both sites?
version2
02-08-2004, 06:39 PM
Go back to the last post I made with the full code in it. Does that work on both sites?
Actually, I got it working and I have been doing so many other things...I forgot what I did!
version2
02-08-2004, 06:44 PM
Damn. If its not one thing its another. Now, even though I have explicitly names the username and fetched all the bbuserinfo data manually...my script is posting as random members.
Main difference right now is I have vbcron running the script once an hour. Maybe vbcron is the problem.
Wired1
02-09-2004, 04:56 AM
I'd copy the code exactly to a test file, run that a couple of times. If it does it correctly each time, then it's probably vbcron.
version2
02-09-2004, 06:47 PM
I'd copy the code exactly to a test file, run that a couple of times. If it does it correctly each time, then it's probably vbcron.
Using cron has made the user problem disappear. Now my problems are the order in which everything is posted. Here is what I am doing:
Eggdrop bot keeps log of the channel. Every day I am going to pour through that log and post the contents in a specific forum. Now, I didnt want each day to be just one post as that could get quite large, so I am saying every 100 lines post a new post.
Now, the problem is that the posts are not inserted in line! The first post which is the subject post is sometimes located in the middle of the thread created by the script. It should be te first post. Its called before I even start looping through the file and posting the 100 line posts.
I cant figure it out.
Wired1
02-10-2004, 04:39 AM
Not sure, perhaps posting some code would help?
Does anyone know of a way of auto-creating a forum, other than a normal mySQL command? Looking for the vB function, if it exists.
version2
02-10-2004, 02:03 PM
$threadinfo['title'] = 'Chatroom Archive Update';
$post['title'] = 'Chatroom Archive Update - ' . date("F j, Y, g:i a") . ' CST';
$post['message']= 'Chatter from the last hour.';
build_new_post('thread', $foruminfo, $threadinfo, 0, $post, $errors);
$threadinfo['threadid'] = $post['threadid'];
$post['title'] = '';
$post['message'] = '';
$lines = file('/eggs/mols_pet/logs/mols_pet_talk.log');
$i=0;
for($x=0;$x<count($lines);$x++) {
$post['message'] .= $lines[$x];
$i++;
if($i>=100) {
build_new_post('post', $foruminfo, $threadinfo, 0, $post, $errors);
//echo $post['message'];
$post['message'] = "";
$i=0;
}
}
if($post['message'] != "") {
build_new_post('post', $foruminfo, $threadinfo, 0, $post, $errors);
}
//echo $errors[0];
unset($lines);
$clear = fopen('/eggs/mols_pet/logs/mols_pet_talk.log', 'w');
fwrite($clear, '');
fclose($clear);
This is the test code right now that runs through the file. And for the record, the last 24 hours the script has put the posts in correct order. So this problem is very inconsistent.
And dont make fun of my chicken scratch code! It always look horrible before it is refined! :nervous:
Karri
02-11-2004, 04:05 PM
Does any one have a suggestion as to how to use this new method of having an automatic post to a forum to post a welcome message to a new user when the register (preferably after they activate their account)? I was using the hack at https://vborg.vbsupport.ru/showthread.php?s=&threadid=35398 for 2.x but haven't been able to modify it for 3.x
Thanks in advance!!!
Wired1
02-11-2004, 05:23 PM
You could just set it to a Welcome Forum, and have the script be something like "Welcome ".$username." to this site"
Gryphon
11-09-2004, 05:38 PM
This thread has been very helpful, though I am having some trouble. Here is the my current code:
if ($_POST["action"] == 'add') {
query("INSERT INTO psu_news SET author='$user[name]', title='$_POST[title]', date_added='$setting[time]', post_id='$_POST[post_id]'");
$psu_news_id = mysql_insert_id();
if ($_POST["create_post"] == '1' && $_POST["post_id"] == '0') {
// vb functions
chdir('/home/psuwww/wwwroot/site.com/forums');
require('./global.php');
require('./includes/functions_newpost.php');
$userid = 5; // The user creating the thread
$forumid = 2; // The forum where the thread is to be posted
// forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);
// setup the thread
$post[title] = '[News] '.$_POST["title"].'';
$post[message] = 'http://www.site.com/index.php?newsid='.$psu_news_id.'';
$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);
// bome back to working dir
chdir('/home/psuwww/wwwroot/site.com/admin');
query("UPDATE psu_news SET post_id='$post[threadid]' WHERE id='$psu_news_id'");
}
echo '<hr><font size="3"><b>Post Added '.$psu_news_id.'</b><hr>';
}
The Thread title posts correctly and the Message also posts, however, $psu_news_id becomes unset. The message url in the created thread is missing the $psu_news_id and the final echo is blank.
Also, this is all done mid template on our site, and all the variables pre-defined at the top of the script are unset after this.
Any info appreciated.
Gryphon
11-11-2004, 04:00 PM
That is too bad :(
sabret00the
11-11-2004, 04:15 PM
i would love something like this based on
if posts on the forums in XX hours < XX then create thread
zeropaid
11-15-2004, 07:38 PM
I am also having problems creating posts... here is my code:
chdir('/usr/local/www/htdocs/bbs');
// Load vB-Backend
require('./global.php');
require('/includes/functions_newpost.php');
$userid = $_POST[news_user_id]; // The user creating the thread
$forumid = 120; // 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] = $title;
$post[message] = $article;
$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) {
?>There have been errors. <?=$errors?><?
print_r($errors);
die('errors');
}
$ThreadID = $post['threadid'];
$PostID = $post['postid'];
print ("the threadid is $ThreadID and the postid is $PostID");
And I get back these errors:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /usr/local/www/htdocs/bbs/includes/init.php on line 517
Fatal error: Call to a member function query_first() on a non-object in /usr/local/www/htdocs/bbs/includes/functions.php on line 922
Any help is appreciated, kind of lost here.
Thanks!
Gryphon
11-15-2004, 08:13 PM
Might be require('./includes/functions_newpost.php');
zeropaid
11-15-2004, 08:52 PM
yep fixed that and i think it would have complained about not being able to find the file... still not working. Maybe something in the data I am passing to it, hmm
zeropaid
11-15-2004, 11:37 PM
tried passing it vanilla test data, to no avail. I am logged into the forum and that got rid of one of the errors, but now all I get is:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /usr/local/www/htdocs/bbs/includes/init.php on line 517
I checked init.php and it is trying to merge an array it just created and $specialtemplates, which appears to not be defined. This is a dev environment, maybe we are missing some templates?
sabret00the
11-16-2004, 01:27 PM
has this been released properly?
zeropaid
11-16-2004, 03:40 PM
released properly? I upgraded properly if thats what you mean, to 3.0.3
sabret00the
11-16-2004, 05:03 PM
i mean did i get released via the releases forum here at vb.org?
Gryphon
11-16-2004, 05:35 PM
Uhhh...no...
zeropaid
11-16-2004, 07:26 PM
no, I just copied code from earlier in this thread.. still getting that wierd error even with test data.. still workin on it though.
StefanS
11-25-2004, 09:28 AM
Hi,
just tested the following code:
<?
require('./global.php');
require('./includes/functions_newpost.php');
$userid = 10;
$forumid = 100;
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);
$post[title] = 'subject';
$post[message] = 'message';
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']);
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);
?>
works for me with 3.03 without problems ...
sabret00the
11-25-2004, 09:43 AM
Hi,
just tested the following code:
<?
require('./global.php');
require('./includes/functions_newpost.php');
$userid = 10;
$forumid = 100;
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);
$post[title] = 'subject';
$post[message] = 'message';
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']);
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);
?>
works for me with 3.03 without problems ...
is there a form to add the threads you want and create the conditions under which their added?
Wired1
11-30-2004, 12:14 AM
Sorry for the delay guys, never did release this as an official hack due to the lack of interest, seemed everyone except for me knew how to do this at the time. Man trying this stuff in the early RCs was a pain! Just switched to a newer license that won't expire, so I'll get all of the updates on the thread from now on :)
I'll have to re-read through the thread later (in class atm), but it sounds like at least sabret00the would like a variable system to set up to do this?
I'll have to dig up the custom forms/code I made that used this function. Worked well, but the project went to ASP so I haven't looked at it in a while. Would've stayed in PHP if I knew how to radically customize the board templates.
Would you guys want me to work this up and release it as an "official" hack?
Undertoad
12-01-2004, 05:22 PM
That would be great.
Wired1
12-02-2004, 05:41 AM
Ok, just re-read everything and looked at my code. Looks like I made the code at the end of page 2 into a function, as well as a function that auto-creates forums.
To release this as a hack, I'd like to put some safety features in it, e.g. some way of making a simple admin CP module for it (NO CLUE), and a way to enter it into group policies so that to have access to it you have to be in a special group. Perhaps it would show up in the User CP if said user is in this secondary group?
So far, these are the requests for it that I have seen:
if posts on the forums in XX hours < XX then create thread
Don't quite understand that. Do you mean "If user X posts every y amount of hours then create a thread?
A form to add the threads you want and create the conditions under which they are added
What types of conditions would you like, or would you like them to be user editable conditions?
Comments please! :) I'm about to fall asleep, so tomorrow afternoon (EST) I'll post the code as a beta hack.
sabret00the
12-02-2004, 09:49 AM
regarding the last bit, basically you'd have a form with
THREAD TITLE
FORUM ID THREAD TO BE CREATED FOR
THREAD BODY TEXT
CONDITIONS TO CREATE THREAD; __ POST < __ hours
USERID OF THREAD CREATOR
wouldn't that form in the admincp by the safety measure btw?
Don't quite understand that. Do you mean "If user X posts every y amount of hours then create a thread? what that means is that if theirs less than 100 posts on the forums in the past 5 hours then create a new thread in order to stimulate activity.
Wired1
12-02-2004, 02:25 PM
wouldn't that form in the admincp by the safety measure btw?
what that means is that if theirs less than 100 posts on the forums in the past 5 hours then create a new thread in order to stimulate activity.
Gotcha. Think I can release just the functions as a beta hack, then later work on the form code? I'd really only want to release it formally if I could make an admin module though.
sabret00the
12-02-2004, 03:26 PM
what do you mean by admin module?
Wired1
12-02-2004, 09:20 PM
One of the side menus in the admin section, a dropdown accessible only within that area.
sabret00the
12-02-2004, 09:26 PM
One of the side menus in the admin section, a dropdown accessible only within that area.
oh that i thought for the form it would've been admincp based anyway, it's not too hard to add a new page, the hardest bit comes when trying to add something to an existing page.
lowspeed
01-14-2005, 06:00 PM
I used this code, IT actually adds the thread but i get the following warning
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in \global.php on line 329
Warning: Invalid argument supplied for foreach() in \includes\functions.php on line 2177
Also if the subject in the forum ID is send again then it just exits it doesn't flow through the code.
Help :)
Thanks,
LOW LOW.
Hi,
just tested the following code:
<?
require('./global.php');
require('./includes/functions_newpost.php');
$userid = 10;
$forumid = 100;
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);
$post[title] = 'subject';
$post[message] = 'message';
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']);
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);
?>
works for me with 3.03 without problems ...
Xenon
01-14-2005, 11:51 PM
that's a problem with php5
before the require global.php add these lines:
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array();
// pre-cache templates used by specific actions
$actiontemplates = array();
lowspeed
01-15-2005, 01:10 AM
Thanks for the quick help !
I have a small follow up. I know how to get the threadid, but how would i post a reply to that ID ?
Do i put instead of the 0, you put the threadid (lets say 3212) ? example:
build_new_post('thread', $foruminfo, array(), 3212, $post, $errors);
lowspeed
01-16-2005, 09:27 PM
I tried doing something like this ...
build_new_post('reply', $foruminfo, array(), 3212, $post, $errors);
where 3212 is the thread i'm replying to, but it didn't work :(
lowspeed
01-17-2005, 05:20 PM
Ok i found how to do it
You need these added:
$threadid=1091; // the thread you want to reply to
$threadinfo = fetch_threadinfo($threadid);
build_new_post('reply', $foruminfo, $threadinfo, $_POST['postid'], $post, $errors);
lowspeed
01-17-2005, 07:38 PM
Hi Guys,
It works fine when called independently from the rest of my code.
I have a feeling that because my php site uses a database as well it gets confused to which database its refering to.
How can i make sure that when i run the post thread section it looks at the VB db and after it reverts back to my db. ??
Andreas
01-17-2005, 08:58 PM
Use a different dbuser/pass for your application
lowspeed
01-17-2005, 11:00 PM
doesnt work :(
I decided to use URL stream instead.
SnitchSeeker
01-22-2005, 09:39 AM
Is there a way to pass the last thread's id from build_new_post? I currently have this: (just a snippet)
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);
$DB_site->query("
INSERT INTO fp_news_info
(threadid, avatar, summary)
VALUES
($threadinfo[threadid], '$news[avatar]', '$news[summary]')
");
It's not passing the $threadinfo[threadid] variable. I used to insert it directly into the database, but I want a cleaner version. So I modified build_new_post function and added a new variable. So now it would say:
function build_new_post($type = 'thread', $foruminfo, $threadinfo, $parentid, &$post, &$errors, $news)
Then an if news exist check, and my previous sql code. However I'm not very sure if this won't bug current posting? Because previously with build_new_post code it'd post, now it just gives a blank page. I need to add the $news variable or it won't work. Regular posting and topic creating is working as far as I can see, but I want to be sure if this is in fact going to work... (did that make sense? :))
SnitchSeeker
01-23-2005, 11:32 AM
Bump. Anyone?
Wired1
02-16-2005, 06:09 AM
Just checking into my baby ;)
Been busy for forever, but IF I get a chance, I'll try to delve into the code again.
Only way I'll release it as a hack is if I can somehow figure out how to put a module in the admin / mod CP for it, gotta be user friendly and all.
Thanks guys. I set mine up to combine the Contact Us page with this 'hack' so that users could submit news stories to our News admin forum without giving them access to it. Thanks!
Any function and/or example for sending PMs?
Wired1
02-17-2005, 04:29 AM
Thanks guys. I set mine up to combine the Contact Us page with this 'hack' so that users could submit news stories to our News admin forum without giving them access to it. Thanks!
Any function and/or example for sending PMs?
Do the submissions go into a moderation queue or just straight in? Got a link?
Automating sending PMS to one person or a certain amount? Can't see reasoning behind this ATM though, but I'll put it on the list of things to check into.
trafix
02-17-2005, 04:44 AM
WTF .... 85 posts just to try to explain how to auto generate a new thread.
I have used this often .... it only requires like about 6 lines
PS .. i havnt read the thread, there is tooooooooooo much and i dont have that much time
Wired1
02-17-2005, 06:42 AM
Then by all means, post your way of doing it. FYI, this thread is a year old. The first 2 pages are mainly myself and some others working it out, the rest are about others using the code.
Also, counted the lines, it's about 8 after trimming non-essential stuff, so your code would probably look similar.
Hoffi
02-17-2005, 01:19 PM
I just found this Thread. That helps me figuring out how to build a Thread. ;)
Did someone know how to add a Poll to the created Thread?
The threads go straight into the forum. Link to the hackjob is http://uselessforums.com/submitnews.php
And I was talking in the Ucash/Ushop forum yesterday and someone mentioned PMing a member after they were 'theifed'. I liked the idea and tried to poke around and see if there was a function to send PMs like creating threads, but couldn't find one.
Hmmm. Looks like there isn't a function to do it, but these DB queries do:
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pmtext\n\t(fromuserid, fromusername, title, message, touserarray, iconid, dateline, showsignature, allowsmilie)\nVALUES\n\t($bbuserinfo[userid], '" . addslashes($bbuserinfo['username']) . "', '$title', '$message', '" . addslashes(serialize($tostring)) . "', $iconid, " . TIMENOW . ", $signature, $disablesmilies)");
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "pm (pmtextid, userid, folderid, messageread) VALUES ($pmtextid, $bbuserinfo[userid], -1, 1)");
$DB_site->shutdown_query("UPDATE " . TABLE_PREFIX . "user SET pmtotal=pmtotal+1 WHERE userid=$bbuserinfo[userid]");
Can anyone explain how I pass whatever is needed in these queries and/or what the queries are exactly doing?
edit: I should probably start a new thread.
zeropaid
02-23-2005, 06:46 AM
Ok I had this working, but am now trying to implement on a new machine running a version of 3.0.7 and php5. I am getting an odd error,
Fatal error: Call to undefined method stdClass::query_first() in /usr/local/www/htdocs/bbs/includes/functions.php on line 938
Here is my code. As far as I can tell everything is being included fine, no errors there.
# Do forum stuff
chdir('/usr/local/www/htdocs/bbs');
// Load vB-Backend
require('./global.php');
require('./includes/functions_newpost.php');
if ($_POST[news_user_id] == 0 || !$_POST[news_user_id]) {
$userid = 1;
} else {
$userid = 1;
}
//$userid = $_POST[news_user_id]; // The user creating the thread
$forumid = 120; // The forum where the thread should be posted
// Get forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);
print_r($bbuserinfo);
// Setup the thread
$post[title] = $title;
$post[message] = $article;
$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) {
?>There have been errors. <?=$errors?><?
print_r($errors);
die('errors');
}
$ThreadID = $post['threadid'];
$PostID = $post['postid'];
print ("the threadid is $ThreadID and the postid is $PostID");
What's on line 938 of functions.php?
zeropaid
02-23-2005, 05:02 PM
938 $user = $DB_site->query_first("
939 SELECT " .
940 iif(($option & 16), ' administrator.*, ') . "
941 userfield.*, usertextfield.*, user.*, UNIX_TIMESTAMP(passworddate) AS passworddate,
942 IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid" .
943 iif(($option & 1) AND $vboptions['reputationenable'] == 1, ', level') .
944 iif(($option & 2) AND $vboptions['avatarenabled'], ', avatar.avatarpath, NOT ISNULL(customavatar.avatardata) AS hascustomavatar, customavatar.dateline AS avatardateline').
945 iif(($option & 8), ', customprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline') .
946 iif(!isset($vbphrase), fetch_language_fields_sql(), '') . "
947 FROM " . TABLE_PREFIX . "user AS user
948 LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON (user.userid = userfield.userid)
949 LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON (usertextfield.userid = user.userid) " .
950 iif(($option & 1) AND $vboptions['reputationenable'] == 1, "LEFT JOIN " . TABLE_PREFIX . "reputationlevel AS reputationlevel ON (user.reputationlevelid = reputationlevel.re putationlevelid) ").
951 iif(($option & 2) AND $vboptions['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customa vatar AS customavatar ON (customavatar.userid = user.userid) ") .
952 iif(($option & 8), "LEFT JOIN " . TABLE_PREFIX . "customprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid) ") .
953 iif(($option & 16), "LEFT JOIN " . TABLE_PREFIX . "administrator AS administrator ON (administrator.userid = user.userid) ") .
954 iif(!isset($vbphrase), "INNER JOIN " . TABLE_PREFIX . "language AS language ON (language.languageid = IF(user.languageid = 0, " . intval($vboptions['languageid']) . ", user. languageid)) ")."
955 WHERE user.userid = $userid
956 ");
mtrac
03-02-2005, 01:10 AM
Excellent thread. I hooked the auto-creation up to the CaRP RSS parser and a couple of cron jobs and now have this (http://www.07020.com/forums/forumdisplay.php?f=25).
Today's question is how do I create calendar events? I'd be interested in a year at a time; i.e. monthly board meeting schedules. I'm thinking of inserting a text file into vb3_event with PHPMyAdmin but would like something more sophisticated.
Thanks.
Excellent thread. I hooked the auto-creation up to the CaRP RSS parser and a couple of cron jobs and now have this (http://www.07020.com/forums/forumdisplay.php?f=25).
Today's question is how do I create calendar events? I'd be interested in a year at a time; i.e. monthly board meeting schedules. I'm thinking of inserting a text file into vb3_event with PHPMyAdmin but would like something more sophisticated.
Thanks.
Search here for news2vb also...
zeropaid
03-07-2005, 11:03 PM
Ok, I figured out my problem. Has anyone got this code to work inside a function? When I run it normally, it works fine. When I put it inside a function, I get all kinds of errors.
Ok, I figured out my problem. Has anyone got this code to work inside a function? When I run it normally, it works fine. When I put it inside a function, I get all kinds of errors.
Can you post what you're doing?
zeropaid
03-11-2005, 09:09 PM
<?
require_once("../classes/nested.php");
require_once("../classes/form.php");
require_once("../classes/mysql.php");
$nested = new Nested;
$forms = new Forms;
function doforum () {
global $forumcache;
# Do forum stuff
chdir('/usr/local/www/htdocs/bbs');
// Load vB-Backend
$globaltemplates = array();
$specialtemplates = array();
$actiontemplates = array();
#require_once('./includes/db_mysql.php');
require_once('./global.php');
require_once('./includes/functions_newpost.php');
#if ($_POST[news_user_id] == 0 || !$_POST[news_user_id]) {
# $userid = 1;
#} else {
# $userid = 1;
#}
//$userid = $_POST[news_user_id]; // The user creating the thread
$userid = 1;
$forumid = 34; // The forum where the thread should be posted
// Get forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);
#print_r($bbuserinfo);
$title = "this is the title";
$article = "this is the body of the article where the text would go.... need to parse html out, maybe just link to the story";
// Setup the thread
$post[title] = $title;
$post[message] = $article;
$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) {
?>There have been errors. <?=$errors?><?
print_r($errors);
die('errors');
}
$ThreadID = $post['threadid'];
$PostID = $post['postid'];
print ("the threadid is $ThreadID and the postid is $PostID");
}
doforum();
?>
Which returns:
Warning: array_keys() [function.array-keys]: The first argument should be an array in /includes/functions.php on line 3089
Warning: Invalid argument supplied for foreach() in /includes/functions.php on line 3089
Fatal error: Call to a member function query() on a non-object in /usr/local/www/htdocs/bbs/includes/functions.php on line 2298
Fatal error: Call to undefined method stdClass::query() in /usr/local/www/htdocs/bbs/includes/functions.php on line 524
I also have the same code outside a function, which works fine:
<?
require_once("../classes/nested.php");
require_once("../classes/form.php");
require_once("../classes/mysql.php");
$nested = new Nested;
$forms = new Forms;
global $forumcache;
# Do forum stuff
chdir('/usr/local/www/htdocs/bbs');
// Load vB-Backend
$globaltemplates = array();
$specialtemplates = array();
$actiontemplates = array();
#require_once('./includes/db_mysql.php');
require_once('./global.php');
require_once('./includes/functions_newpost.php');
#if ($_POST[news_user_id] == 0 || !$_POST[news_user_id]) {
# $userid = 1;
#} else {
# $userid = 1;
#}
//$userid = $_POST[news_user_id]; // The user creating the thread
$userid = 1;
$forumid = 34; // The forum where the thread should be posted
// Get forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);
#print_r($bbuserinfo);
$title = "this is the title";
$article = "this is the body of the article where the text would go.... need to parse html out, maybe just link to the story";
// Setup the thread
$post[title] = $title;
$post[message] = $article;
$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) {
?>There have been errors. <?=$errors?><?
print_r($errors);
die('errors');
}
$ThreadID = $post['threadid'];
$PostID = $post['postid'];
print ("the threadid is $ThreadID and the postid is $PostID");
?>
It seems like it is missing some data inside that function or something.
Marco van Herwaarden
03-12-2005, 04:45 AM
I didn't really go through your code, but try getting the userinfo before the foruminfo.
zeropaid
03-14-2005, 04:23 AM
yeah the code is pretty long and convoluted, the bottom line is when i run it just in a normal test script it works perfectly, when I put it in any sort of function construct it fails as soon as it tries to execute any vb code.
Lee Wilde
03-17-2005, 01:22 AM
You may be interested in this hack just released by deathemperor:
Calendar Search and Comments for Events
https://vborg.vbsupport.ru/showthread.php?p=626269
zeropaid
03-18-2005, 06:02 PM
So i just wrote a custom workaround so I don't have to have this code in a function.. it is ugly but it works.
I know there is a lot of people using this hack since this thread is so big, but has anyone gotten posts to display on another page? Is there an easy way to get vbulletin to display posts in their format or is the easier way to just grab the postdata from the db and display them myself?
Is there a way to pass the last thread's id from build_new_post? I currently have this: (just a snippet)
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);
$DB_site->query("
INSERT INTO fp_news_info
(threadid, avatar, summary)
VALUES
($threadinfo[threadid], '$news[avatar]', '$news[summary]')
");
It's not passing the $threadinfo[threadid] variable. I used to insert it directly into the database, but I want a cleaner version. So I modified build_new_post function and added a new variable. So now it would say:
function build_new_post($type = 'thread', $foruminfo, $threadinfo, $parentid, &$post, &$errors, $news)
Then an if news exist check, and my previous sql code. However I'm not very sure if this won't bug current posting? Because previously with build_new_post code it'd post, now it just gives a blank page. I need to add the $news variable or it won't work. Regular posting and topic creating is working as far as I can see, but I want to be sure if this is in fact going to work... (did that make sense? :))
Did that end up working? If so, can you post your build_new_post function, as I need a way to get the threadid back out of this...
Andreas
06-01-2005, 11:36 PM
You don't have to modify build_new_post().
If you take a close look at its implementation, you will see that $post['threadid'] contains the threadid :)
$threadinfo can't contain the threadid, as this paramater is call by value instead of call by reference (like $post or $errors)
You don't have to modify build_new_post().
If you take a close look at its implementation, you will see that $post['threadid'] contains the threadid :)
$threadinfo can't contain the threadid, as this paramater is call by value instead of call by reference (like $post or $errors)
Sweet! Thanks man. That was it!
Wired1
06-02-2005, 09:35 PM
Hrm, don't think my subscription is working to this thread, ack!
Anyway, just as an FYI, I'd release this as an official hack if I could find an article or something that would tell me the easiest way to make a menu within the admin panel.
Andreas
06-02-2005, 09:36 PM
What do you mwan with " make a menu within the admin panel."?
Wired1
06-02-2005, 10:55 PM
sry, i'm a bit sleep deprived atm :)
Basically when you look at some hacks, you see that they have added menus to the adminCP / modCP areas. GUIs to make the hack as easy as possible to use. IMHO, someone should make a tutorial on how to do it for newbie vB hackers anyway.
Now that I think of it though, I can't recall WHY I wanted that. IIRC, I had a good reason (someone posted a reason why in this thread), but I'm spacing ATM.
One main reason for the function was for server-side bots/programs to auto-post info (e.g. RSS feeds, whatever). My personal reason for it was similar.
Would you even classify this as a hack? It's more of a collection of vB functions IMHO.
mtrac
08-23-2005, 04:00 AM
Stupid question, but how do I put carriage returns in? \n doesn't work.
mtrac
08-24-2005, 12:03 PM
Never mind. I just discovered the distinction between single and double quotes in PHP.
Wired1
09-02-2005, 01:33 AM
kewlness
Yes, I plan to update this when vB 3.5 comes out if it doesn't work
Rendog
09-16-2005, 06:47 PM
Hey guys, I'm having a very fundamental issue getting this to work.
As soon as I do the require global.php line, my varibles don't work... by that i mean the php page below prints only Test:
$FORUM_ID is blank even though its decalred...
if i remove the require global.php line its fine.... what gives?
<?php
$FORUM_ID = 60;
chdir('/www/data/website/forums');
// Load vB-Backend
require_once ('./global.php');
// require_once ('./includes/functions_newpost.php')
?>
Test: <?php echo $FORUM_ID?>
forum_id ends up blank... if i comment out the global.php, it prints properly... any ideas?
Wired1
09-17-2005, 05:00 AM
1. what version of PHP are you running, 4 or 5?
2. is global.php called from the function?
Andreas
09-17-2005, 05:03 AM
I guess you got register_globals=on
For the sake of security, vBulletin unsets all global variables created by register_globals=on, and there is no way (well ... except changing some basic internal functions would be necessary) to stop it from doing that :)
Best suggestion: Code without relying on register_globals :)
artonex
09-21-2005, 10:05 AM
I need to take this rss feed and use it for auto new threads.
http://news.google.com/news?q=marijuana&hl=en&lr=&c2coff=1&tab=wn&ie=UTF-8&output=rss
I use vb3.5 rc3.
how would i do this?
mtrac
10-02-2005, 03:43 PM
Yes, I plan to update this when vB 3.5 comes out if it doesn't workIt's not working off a cron job any more but does work when called locally. Compared to the other problems I'm having it's not exactly a catastrophe. Any ideas?
Wired1
10-02-2005, 06:41 PM
artonex:
Not a clue if this will work in vB 3.5.0. Gotta get into the code more first.
mtrac:
what vB version?
mtrac
10-03-2005, 09:22 AM
3.5.0 (Gold)
mickmel
07-31-2007, 06:42 PM
Yes, I plan to update this when vB 3.5 comes out if it doesn't work
I was hoping for an update to this. It still creates threads, but:
- They're created under the username of the person that pushes the "create" button, rather than the user specified by the script.
- The threads automatically go into the moderation queue, rather than appearing on the site for other users to respond to.
Thanks.
Wired1
07-31-2007, 07:32 PM
blast from the past :)
Could've sworn there's a couple of plugins now that auto-create threads now, could be wrong. If you can't find them, I'll dig into the code (maybe this weekend) and see what I can come up with. As you can see from this thread, I pretty much grabbed some vBulletin functions and slapped them together. I'm guessing these functions have changed, and so this broke. Probably have to re-smush the vBulletin code together :)
Yeah, that last thought didn't make much sense to me either.
norma-aguilera
12-30-2009, 02:23 AM
OK. In case anyone else needs this code....
This worked for me with vBullentin version 3.5.4
The new thread was created successfully -even when I was not loggin in.
<?php
require_once('./global.php');
require_once('./includes/functions_newpost.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');
require_once('./includes/functions_databuild.php');
$forumid = 19;
$userid = 1;
$title = 'The first autopost!';
$pagetext = 'More details here.';
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$foruminfo = fetch_foruminfo($forumid);
$threaddm->set_info('forum', $foruminfo);
$threaddm->set('forumid', $forumid);
$threaddm->set('userid', $userid);
//$threaddm->set('user', 'SGD DESIGNS');
$threaddm->set('title', $title);
$threaddm->set('pagetext', $pagetext);
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->set('dateline', TIMENOW);
$threaddm->save();
?>
Wired1
12-30-2009, 03:59 AM
Holy bump Batman!
mickmel
12-30-2009, 12:16 PM
OK. In case anyone else needs this code....
This worked for me with vBullentin version 3.5.4
Any idea if it works with the later version of vB3, or with vB4?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.