Topic: PHP-Script to post on the forums
As the subject say, I wonder if it's possible to write a PHP-script to post a thread in my forums - and how it's done.
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → PHP-Script to post on the forums
As the subject say, I wonder if it's possible to write a PHP-script to post a thread in my forums - and how it's done.
Take a look at how post.php handles new topics
I forgot to say that I'm newb when it comes to PHP. :)
I want a function to simply call when I want to post a thread! Well I'll look more into that file, thanks.
Edit: Disabled smilies.
Are you talking about rss?
Are you talking about rss?
No. I want a PHP-function to post a thread in my punBB forum.
Oh, well, you would have to convince someone to write it for you then
Create a function that posts then. Examine post.php like smartys said.
i guess this guy doesnt know any php, he would like a script/mod, that would post to the forum without actually pressing the post new topic link.
i myself dont see any sense to that, cause you have to pick which forum and thread topic you want to post in first.
I've done something like this for my website, users fill a form and it's submitted as forums thread + first topic.
What kind of form do you need?
i myself dont see any sense to that, cause you have to pick which forum and thread topic you want to post in first.
Actually, (and it will probably be a rarity that I say this), this is one request I can actually see a valid point for. For example, an info/update/announce forum could have a message parsed from some other source and inserted into the forum, (one or more predefined in the script), as the latest topic in that/those forum(s).
It makes sense in general for integration. You would have a function that takes the necessary parameters (eg: forum ID, topic title, poster, etc) and inserts the information into the database
I do know some PHP, I can write some simple sites wich gets data from HTML-forms. Now all I need is a function to post the data I can retrive from these HTML-forms to my forum.
I'm not asking you to write this function for me, but maybe explain abit more to me how this is done(since I'm new to PHP).
I'm not asking you to write this function for me, but maybe explain abit more to me how this is done(since I'm new to PHP).
As was mentioned previously, having a ganders at the post.php script is a good place to start. It obviously contains the code that's already used for inserting topics/posts into the DB. This page describes what all the default db fields are:
http://punbb.org/docs/dev.html#dbtables
The way I personally would do it is to try and get a basic script running from the above, and if you have problems ask a question about the problem(s) encountered. That's the way I've been doing it since my first dip into php.
Here's what I use.
This is the function.
require PUN_ROOT.'include/search_idx.php';
$now = time();
// Create the topic
$db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(\''.$db->escape($username).'\', \''.$db->escape($subject).'\', '.$now.', '.$now.', \''.$db->escape($username).'\', '.$fid.')') or error('Unable to create topic', __FILE__, __LINE__, $db->error());
$new_tid = $db->insert_id();
if (!$pun_user['is_guest'])
{
// To subscribe or not to subscribe, that ...
if ($pun_config['o_subscriptions'] == '1' && (isset($_POST['subscribe']) && $_POST['subscribe'] == '1'))
$db->query('INSERT INTO '.$db->prefix.'subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$new_tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
// Create the post ("topic post")
$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.get_remote_address().'\', \''.$db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
}
else
{
// Create the post ("topic post")
$email_sql = ($pun_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$email.'\'' : 'NULL';
$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', \''.get_remote_address().'\', '.$email_sql.', \''.$db->escape($message).'\', \''.$hide_smilies.'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
}
$new_pid = $db->insert_id();
// Update the topic with last_post_id
$db->query('UPDATE '.$db->prefix.'topics SET last_post_id='.$new_pid.' WHERE id='.$new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
update_search_index('post', $new_pid, $message, $subject);
update_forum($fid);
redirect('YOUR URL', ' ');
}
Before of that you must define the $fid with the ID of the forum you want to add this topic
Then, $message will be the message posted in the topic, you can merge all the form fields in $message like this
<?php
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3'];
$message = "[quote][b]field1:[/b] $field1
[b]field2:[/b] $field2
[b]field3:[/b] $field3[/quote]
";
Finally: build your form at the end of the file.
Hope it helps.
Strofanto: keep in mind you took out a lot of the sanitizing code (but kept in the $pun_user['is_guest'] check).
I know Smartys, in the beginning the form was open to guests to fill it too but due to spam I remove that feature, hastely, so I forgot to remove some unnecessary stuff. Thanks for the heads up though.
Thanks alot guys! I love you. :)
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → PHP-Script to post on the forums
Powered by PunBB, supported by Informer Technologies, Inc.