Page 1 of 1

[SOLVED] Simple: Post reply from main-page

Posted: Wed Sep 08, 2010 6:57 pm
by ioScream
I'm sure this has been covered before, but every time I search for it I get unrelated results.

I have a hidden forum setup so that people can post to it like a "shout-box". What I want is a highly simplified post reply form on my main page (where all posts are/will be displayed). I already have a sample topic setup to accept replies. Just need to know what needs to be submitted to the posting.php file. I'm sure there are also some variables that need to be grabbed and submitted.

I am capable of finding the forum and post ids, and handling the majority of the php/html. Just need to know variable names (already have an include file handling session-data). Even a point in the right direction would be nice. Thanks.

Re: Simple: Post reply from main-page

Posted: Wed Sep 08, 2010 7:33 pm
by Drummer
I don't think you need to call posting.php. You need to call submit_post() (/includes/functions_posting.php).
posting.php also calls submit_post() and you can see there what's needed to call this function. In a "fresh" file this call happens at the line 1108.
I think that if you're using posting_editor.html (or its structure, field names...) you can simply paste the desired part from posting.php.

Re: Simple: Post reply from main-page

Posted: Wed Sep 08, 2010 8:24 pm
by ioScream
That seems like it might make it more complicated than it can already be. The main problem I'm having is weeding through the posting_editor.html template vars/logic to find which variables MUST be passed. I was actually just trying to hack down the reply to post page to have nothing more than a submit button and a text-box.

If I have to, I'll continue looking through those 2 php files to try create my own shoutbox_submit.php file, but I'm thinking/hoping I can just chop down the posting_editor.html file to my minimalist needs and have it submit to "/posting.php?mode=post&f=5&sid=a1dda1fce1575f766c9e10fc93765f3c", as a regular post reply is done. Though, it would help to know what is REQUIRED and the php variable names rather than the template var names.

Re: Simple: Post reply from main-page

Posted: Thu Sep 09, 2010 2:42 am
by ioScream
I take it back. I've been looking at the documentation here, and it seems it (using submit_post) will be pretty straight forward. I hope. I will post results in hopes that it will help someone else, or so I can find it later if I somehow lose it.

Re: Simple: Post reply from main-page

Posted: Thu Sep 09, 2010 5:23 am
by ioScream
How do I generate the bbcode_bitfield, and are there more variables I need to look out for?

Re: Simple: Post reply from main-page

Posted: Thu Sep 09, 2010 6:28 am
by ioScream
Issue resolved with this code:

Code: Select all

<?php
require_once('./includes/phpbb-header.php');

$randomMsg 		= request_var('randomMsg', '');
$msg			        = "$randomMsg";
$subj			= "Posted by: " . $user->data['username'];
$forum			= 18;
$topic			= 21;
$time			= time();
$message_enc	= utf8_normalize_nfc($msg, '', true);
$subject_enc	= utf8_normalize_nfc($subj, '', true);

$poll = $uid = $bitfield = $options = '';

generate_text_for_storage($subject_enc, $uid, $bitfield, $options, false, false, false);
generate_text_for_storage($message_enc, $uid, $bitfield, $options, true, true, true);

$data = array(
	'forum_id'			=> $forum,
	'topic_id'			=> $topic,
	'icon_id'			=> false,

	'enable_bbcode'		=> true,
	'enable_smilies'		=> true,
	'enable_urls'		=> true,
	'enable_sig'		=> false,

	'message'			=> $message_enc,
	'topic_title'		=> $subject_enc,
	'message_md5'		=> md5($message_enc),
			
	'bbcode_bitfield'	=> $bitfield,
	'bbcode_uid'			=> $uid,

	'post_edit_locked'	=> 0,
	'notify_set'			=> false,
	'notify'				=> false,
	'post_time'			=> 0,
	'forum_name'			=> '',
	'enable_indexing'	=> true,
);

submit_post('reply', $subject_enc, $user->data['username'], POST_NORMAL, $poll, $data);
?>
I use phpbb-header.php a lot, so it looks like this:

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');

define('IN_PHPBB', true);

# Replace '../forums/' with the appropriate path information. 
# Example: This file's path is './test_dir/newsfunc.php'. The forums are outside of the ./test_dir, so the string would read '../forums/'
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forums/';
$redirect_path = "../news_test/";
 
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require_once($phpbb_root_path . 'common.' . $phpEx);
require_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
require_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
require_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
require_once($phpbb_root_path . 'phpBBFunctions.php');
require_once('functions.' . $phpEx);

# Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
Now all I need to do is setup the form, fix the redirect, and turn this file into a function. Thanks for the help.