[Function] Insert Post

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Hans Kamp
Registered User
Posts: 53
Joined: Wed Mar 10, 2004 9:07 am
Location: Enschede, Netherlands
Contact:

Post by Hans Kamp »

<Can be removed>
cheesypeanut
Registered User
Posts: 121
Joined: Mon May 05, 2003 12:51 am
Location: England

Post by cheesypeanut »

Just to say thanks to netclectic for this. Great mod, very useful and just what i needed.
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

Yes, this already supports the attachment mod.



Netclectic, do you have any documentation on this ?

Thank You.
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
User avatar
webmedic
Registered User
Posts: 323
Joined: Tue May 28, 2002 2:37 am
Contact:

Post by webmedic »

netclectic wrote:
Shooters wrote:Is it possible to update a post, and if so, how do I do it?

Not currently, that's something i might consider adding in the future though.


how soon possibly as I'm working on something that really needs this and learning mysql by looking though phpbb code is not as easy as I thought it would be.

I've been coding php for many years but database stuff is not my strong point.
tommyhaych
Registered User
Posts: 15
Joined: Sun Jun 13, 2004 6:14 pm

Post by tommyhaych »

WARNING: Php newbie here...


This would be sooo much easier with a readme of some sort to help me set up the damn thing..

Im looking to integrate it with another module so i can post both a news-post on my website and a news post on my forum so people can discuss it.
j0sh
Registered User
Posts: 11
Joined: Wed May 19, 2004 1:16 pm

Post by j0sh »

thank you, that's exactly what i needed. :)
triwda
Registered User
Posts: 1
Joined: Wed Jun 16, 2004 8:08 am

undefined function attach_sql_query with Attach Mod 2.3.9

Post by triwda »

Hi there.

i just installed the insert post function. The test_insert_post.php runs fine just to the point where the attachment should be inserted.

I get the following error message:
Fatal error: Call to undefined function: attach_sql_query() in /usr/local/www/data/phpBB2/mods/netclectic/includes/functions_insert_post.php on line 348

And yes, the attachment mod is working perfectly!

Investigation led to the conclusion that in version 2.3.9 of the attachment mod the missing function has been removed :(

I tried and copied the attach_sql_query()-part from attach_mod 2.3.7 into the appropriate file. Result is that test_insert_post runs without errors, the attachment box gets displayed in the posting but the actual file is not uploaded into the filesystem.

Is there any workaround?

Looking through the attachment-Mod thread did not help as the only answer one gets there is "reinstall" ;)

Any help would be greatly appreciated.

T.
juliekate
Registered User
Posts: 779
Joined: Sun May 05, 2002 5:32 pm
Location: Philadelphia
Contact:

Post by juliekate »

Adrian...

So, I really didn't understand your mod here earlier...but now I do. I've used it to hook on to the Lottery mod, so that when the lottery is drawn, it replies to a set topic to announce the latest winner.

I've got it working, but there seem to be three problems.

First, it's not grabbing the $winnername var that is within the same IF statement right before it.

Code: Select all

// check if lottery should be drawn
$timeleft = $board_config['lottery_start'] + $board_config['lottery_length'];
$timeleft = $timeleft - time();
$thetime = time();
if ($timeleft < 1)
{
	if ( !($result = $db->sql_query("SELECT * FROM " . LOTTERY_TABLE)) ) 
	{ 
		message_die(GENERAL_ERROR, 'Could not obtain lottery draw information', '', __LINE__, __FILE__, $sql);
	}
	if (mysql_num_rows($result) > 0) 
	{
		// get prizepool
		$lotteryentries = mysql_num_rows($result);
		$poola = $lotteryentries * $board_config['lottery_cost'];
		$pool = $board_config['lottery_base'] + $poola;

		// select winner
		$randnum = rand(1, mysql_num_rows($result));
		$randnum = $randnum-1;
		for ($x = 0; $x < mysql_num_rows($result); $x++) 
		{
			$entries = mysql_fetch_array($result);
			if ($x == $randnum)
			{
				$winner = $entries['user_id'];
			}
		}

		// get winner's AI Bucks
		$sql = "SELECT user_bucks, username 
				FROM " . USERS_TABLE . " 
				WHERE user_id='$winner'";
		if ( !($nresult = $db->sql_query($sql)) ) 
		{ 
			message_die(GENERAL_ERROR, 'Could not obtain winners AI Bucks information', '', __LINE__, __FILE__, $sql);
		}
		$userinformation = mysql_fetch_array($nresult);
		$winnername = addslashes($userinformation['username']);

		// add up new total & insert into database
		$newpoints = $userinformation['user_bucks'] + $pool;
		$sql = "UPDATE " . USERS_TABLE . " 
				SET user_bucks = '$newpoints' 
				WHERE user_id = '$winner'";
		if ( !($db->sql_query($sql)) ) 
		{ 
			message_die(GENERAL_ERROR, 'Could not update winners AI Bucks information', '', __LINE__, __FILE__, $sql);
		}

		if( $winner != 0 )
		{
			$sql = "UPDATE " . CONFIG_TABLE . " 
					SET config_value = '$winnername' 
					WHERE config_name = 'lottery_lastwon'";
			if ( !($db->sql_query($sql)) ) 
			{ 
				message_die(GENERAL_ERROR, 'Could not update last winner information', '', __LINE__, __FILE__, $sql);
			}

			$sql = "INSERT INTO " . LOTTERY_WINNER_TABLE . " (win_date, winner_name, prize_amount)
					VALUES ( " . time() . ", '" . $winnername . "', '" . $pool . "')";
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, 'Could not insert data into lottery winners table', '', __LINE__, __FILE__, $sql);
			}
And here's the code I put in:

Code: Select all

// Inserting a post in a pre-defined forum to announce lottery winner.
			include($phpbb_root_path . 'includes/functions_insert_post.'.$phpEx);

			// choose a user
			$user_id = 518;

			// initialise the userdata
			$sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = $user_id";
			if ( !($result = $db->sql_query($sql)) )
			{
				message_die(CRITICAL_ERROR, 'Could not obtain lastvisit data from user table', '', __LINE__, __FILE__, $sql);
			}
			// update the users last visit time
			$current_time = time();
			$sql = "UPDATE " . USERS_TABLE . " 
				SET user_session_time = $current_time, user_session_page = " . PAGE_INDEX . ", user_lastvisit = $current_time
				WHERE user_id = $user_id";
			if ( !$db->sql_query($sql) )
			{
				message_die(CRITICAL_ERROR, 'Error updating last visit time', '', __LINE__, __FILE__, $sql);
			}
			// pick a forum to add out post to
			$forum_id = 20;
			$topic_id = 2718;
			// Add specifics
			$userdata['user_lastvisit'] = $last_visit;
			$subject = 'New Lottery Winner!';
			$message = stripslashes('Congrats to \'" . $winnername . "\' for winning the ability to choose the next Song of the Week! Please check the official rules for the format in which you will submit your choice. WAY TO GO!');
			$post_details = insert_post($message, $subject, $forum_id, $userdata['user_id'], $userdata['username'], $userdata['user_attachsig'], $topic_id, POST_NORMAL, true);
Issue #2 isn't related directly to your mod, thought I'd pick your brain and ask how I can set the Lottery to automatically post this. See, as it works now, someone has to actually open lottery.php in order for the code to be executed, and therefore, for the post to show up. The mod seems to have been written that way. Any suggestions?

Issue #3 => It's not updating the view count in viewtopic.php.

Kate
leoz
Registered User
Posts: 35
Joined: Wed Nov 12, 2003 6:35 am
Location: Nashville, TN, USA.
Contact:

Small Problems?

Post by leoz »

GREAT MOD! Thanks for sharing it with us.

(Message EDITED) Previous problem has been fixed!

Thanks again for a great MOD!
RickH
Registered User
Posts: 3
Joined: Wed Sep 01, 2004 11:33 pm

Post by RickH »

Am I missing something. The posts are being inserted but the page ends with this error:


Unable to locate attachment functions.

DEBUG MODE

Line : 316
File : C:\Webs\MAJGADGET\phpbb2\mods\netclectic\includes\functions_insert_post.php

UPDATE:
Never mind I found out what was wrong. I do not have the mod installed for the call to insert_post_with_attach to succeed. I commented out the fifth example and everything is working fine.
murphyz
Registered User
Posts: 207
Joined: Wed Dec 04, 2002 12:42 pm
Location: London, UK
Contact:

Post by murphyz »

Hello,

I'm having trouble getting this to work with the blank pages mod.

the test_insert_post.php works fine on it's own, but I want to have it on one of the 'blank pages' and take the user_id from whoever is logged in at the present time.

The pages I'm working on are called 'userreviews' and set up as thus:

userreviews.php

Code: Select all

<?php 
// standard hack prevent 

define('IN_PHPBB', true); 

$phpbb_root_path = './'; 

include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 
include($phpbb_root_path . 'mods/netclectic/includes/functions_insert_post.'.$phpEx);

// Retrieve the script path (from board config) where phpBB2 is located relative to the domain name 

$sql="SELECT * FROM " . $table_prefix . "config WHERE config_name = 'script_path'"; 

if ( !($result = $db->sql_query($sql)) ) 

{ 

        die("<B>Error:</B> Could not query script_name information<BR>SQL: $sql"); 

} 

if ($db->sql_numrows($result) == 0) 

{ 

        die("<B>Error:</B> script_name information does not exist.<BR>SQL: $sql"); 

} 

$row = $db->sql_fetchrow($result); 

$phpbb_script_path = $row[config_value]; 

// standard session management 
$userdata = session_pagestart($user_ip, PAGE_userreviews); 
init_userprefs($userdata); 

// If user is not logged in - redirect to the login page with this scriptname as a redirect to... 

if( !$userdata['session_logged_in'] ) 

{ 

        header("Location: " . append_sid($phpbb_script_path . "login." . $phpEx . "?redirect=userreviews.php" )); 

} 

// User is a registered user and have been logged in! - continue.. 

// set page title 

$page_title = 'userreviews'; 

// standard page header 

include($phpbb_root_path . 'includes/page_header.'.$phpEx); 

// assign template 

$template->set_filenames(array( 

        'body' => 'userreviews.tpl') 

); 

$template->pparse('body'); 

// standard page footer 
include($phpbb_root_path . 'includes/page_tail.'.$phpEx); 
?>
This ensures the user is logged in and has the appropriate header and footers.

userreviews.tpl

Code: Select all

<?php
// pick a forum to add out post to

$forum_id = 3;

$message = stripslashes($HTTP_POST_VARS['message']);

if ( $message != '' )

{
      
    $subject = stripslashes($HTTP_POST_VARS['subject']);

    $post_details = insert_post($message, $subject, $forum_id, $userdata['user_id'], $userdata['username'], $userdata['user_attachsig']);

    $url = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx . '?' . POST_TOPIC_URL . '=' . $post_details['topic_id']);

    echo '<a href="' . $url . '">new topic, id: ' . $post_details['topic_id'] . '</a><br/>';

}

else

{

    echo '<form method="post"><input type="Text" size="50" name="subject" id="subject"/><br/><textarea cols="50" rows="10" name="message" id="message"></textarea><br/><input type="Submit"/></form>';

}
?>
This just chooses the forum and has the input boxes.

If I attempt to fill in the forms, it just refreshes the page with the input box again, instead of making the post and showing the url.

Any suggestions on where my ineptitude lies?

Mxx
User avatar
jjjjan
Registered User
Posts: 2
Joined: Wed Sep 22, 2004 9:43 am
Location: .eu
Contact:

New here

Post by jjjjan »

Hi,

i'm new here... phpBB is great (and very easy to install) and with the insert_post module it does exactly what i needed! Thanks for developing all this, folks!
Greetings
jjjjan @ Schwedenforum
User avatar
webmedic
Registered User
Posts: 323
Joined: Tue May 28, 2002 2:37 am
Contact:

Post by webmedic »

murphyz wrote: Hello,

I'm having trouble getting this to work with the blank pages mod.

the test_insert_post.php works fine on it's own, but I want to have it on one of the 'blank pages' and take the user_id from whoever is logged in at the present time.

The pages I'm working on are called 'userreviews' and set up as thus:

userreviews.php

Code: Select all

<?php 
// standard hack prevent 

define('IN_PHPBB', true); 

$phpbb_root_path = './'; 

include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 
include($phpbb_root_path . 'mods/netclectic/includes/functions_insert_post.'.$phpEx);

// Retrieve the script path (from board config) where phpBB2 is located relative to the domain name 

$sql="SELECT * FROM " . $table_prefix . "config WHERE config_name = 'script_path'"; 

if ( !($result = $db->sql_query($sql)) ) 

{ 

        die("<B>Error:</B> Could not query script_name information<BR>SQL: $sql"); 

} 

if ($db->sql_numrows($result) == 0) 

{ 

        die("<B>Error:</B> script_name information does not exist.<BR>SQL: $sql"); 

} 

$row = $db->sql_fetchrow($result); 

$phpbb_script_path = $row[config_value]; 

// standard session management 
$userdata = session_pagestart($user_ip, PAGE_userreviews); 
init_userprefs($userdata); 

// If user is not logged in - redirect to the login page with this scriptname as a redirect to... 

if( !$userdata['session_logged_in'] ) 

{ 

        header("Location: " . append_sid($phpbb_script_path . "login." . $phpEx . "?redirect=userreviews.php" )); 

} 

// User is a registered user and have been logged in! - continue.. 

// set page title 

$page_title = 'userreviews'; 

// standard page header 

include($phpbb_root_path . 'includes/page_header.'.$phpEx); 

// assign template 

$template->set_filenames(array( 

        'body' => 'userreviews.tpl') 

); 

$template->pparse('body'); 

// standard page footer 
include($phpbb_root_path . 'includes/page_tail.'.$phpEx); 
?>
This ensures the user is logged in and has the appropriate header and footers.

userreviews.tpl

Code: Select all

<?php
// pick a forum to add out post to

$forum_id = 3;

$message = stripslashes($HTTP_POST_VARS['message']);

if ( $message != '' )

{
      
    $subject = stripslashes($HTTP_POST_VARS['subject']);

    $post_details = insert_post($message, $subject, $forum_id, $userdata['user_id'], $userdata['username'], $userdata['user_attachsig']);

    $url = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx . '?' . POST_TOPIC_URL . '=' . $post_details['topic_id']);

    echo '<a href="' . $url . '">new topic, id: ' . $post_details['topic_id'] . '</a><br/>';

}

else

{

    echo '<form method="post"><input type="Text" size="50" name="subject" id="subject"/><br/><textarea cols="50" rows="10" name="message" id="message"></textarea><br/><input type="Submit"/></form>';

}
?>
This just chooses the forum and has the input boxes.

If I attempt to fill in the forms, it just refreshes the page with the input box again, instead of making the post and showing the url.

Any suggestions on where my ineptitude lies?

Mxx


I'm not exactly sure waht your issue is but I can tell you for a fact that you dont even pass any information to the insert post function so whatever issue you are having is not related in any way to the insert post. It's an issue with your code and at the very least you need to pass some information ot the insert post function if you want it to work.

By the way I have updated this function to work with the cmx slashdot news mod if anybody is interested.
murphyz
Registered User
Posts: 207
Joined: Wed Dec 04, 2002 12:42 pm
Location: London, UK
Contact:

Post by murphyz »

Hi webmedic, thanks for your reply.

The only code I've taken out is for the initialising of the userdata and the updating of the users last visit, both of which are taken care of in my php file.

The issue I find is that I can't get it to work with splitting the information between two files, the functions_insert_post.php being included in my php file and most of the other information being in the tpl file (which the php files pulls in, as with the blank page mod).

In theory, I assume the submit button still passes the information to the functions_insert_post file - in practice however, nope.

Has anyone else had this working with the blank page mod?

cheers

Mxx
User avatar
webmedic
Registered User
Posts: 323
Joined: Tue May 28, 2002 2:37 am
Contact:

Post by webmedic »

You need to have a page setup(not the functions_insert_post file) that will collect the data, make sure it is correct, make sure it is not a hack attempt, and then call the function to insert the post. For the last part you will need to make sure to include the functions_insert_post file in your file that does all this work and then you need to make sure to call the function

the syntax for calling the function will look something like this.

Code: Select all

						$insert_post = insert_post(
							$message, 
							$subject, 
							$forum_id, 
							$user_id, 
							$userdata['username'], 
							$userdata['user_attachsig'],
							NULL,                   // $topic_id
							POST_NORMAL,            // $topic_type 
							false,                  // $do_notification 
							false,                  // $notify_user
							0,                  // $current_time
							'',                     // $error_die_function
							$html_on, 
							$bbcode_on, 
							$smilies_on 
							);
this will return the topic id and post id of the message posted as $insert_post.

That way you can use the topic id in another way if you wish to manipulate your db in another way with the data retrieved.

the data would be accessible in these

$insert_post['topic_id']
$insert_post['post_id']

other than this unless you know what you are doing the blank pages mod will be more of a problem than a help I would suspect. It would probably be better for you to make it into a real mod it would most likely be done faster also.
Post Reply

Return to “[2.0.x] MOD Writers Discussion”