phpBB Joomla Comments - Using submit_post outside of phpBB

Discussion forum for MOD Writers regarding MOD Development.
User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

phpBB Joomla Comments - Using submit_post outside of phpBB

Post by boylan » Wed Nov 12, 2008 2:17 am

EDIT: For those who are just looking for the plugin, you can skip the development discussion and go straight to the release post:

phpBB Joomla Comments plugin - alpha release

--------------------------------------------------------------------

Formerly: Using submit_post outside of phpBB

I am writing a plugin for Joomla that will auto-create a comments thread for each article. I did this for phpBB 2.0 using the insert_post MOD a couple years back, but I'm trying to do it now with a stock phpBB installation and submit_post.

I've seen great info on submit_post in the documentation and another article at phpbbmodders.

However, both of those seem to presume you are writing a script inside of phpBB, and I'm looking at how to do this outside. Basically, I have created a "CommentBot" user and want to start a thread for each article in Joomla which contains a first post of a link back to the article.

My problem stems from following the submit_post example. I don't know what dependencies I need to include or what I need to set up to get it working. This is what I have now, but it doesn't work:

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = '/home/{myusername}/www/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
I wouldn't think the last two are necessary, but I get function not found errors if they are not. So, my basic question is what do I need to include in my script before I get started here? Are there any other examples of what I'm trying to do? Also, once that is set up, how do I set up the $user array with the details of my CommentBot?

Thanks, Chris.
Last edited by boylan on Wed Jan 07, 2009 10:48 am, edited 1 time in total.

User avatar
ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: Using submit_post outside of phpBB

Post by ameeck » Wed Nov 12, 2008 2:31 pm

These includes at the top of file should do:

Code: Select all

include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx); 
As for changing the poster's identity, A_Jelly_Doughnut has described it here, in the middle of the topic:
http://www.phpbb.com/community/viewtopi ... 1&t=574199

Here is an example of posting with this API in the docs: http://www.phpbb.com/mods/documentation ... nsert-post

User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

Re: Using submit_post outside of phpBB

Post by boylan » Sat Nov 15, 2008 3:39 am

OK, I used those includes, but got this error on attempting to submit_post:

Code: Select all

[phpBB Debug] PHP Notice: in file /forum/includes/utf/utf_tools.php on line 1776: include(includes/utf/utf_normalizer.) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /forum/includes/utf/utf_tools.php on line 1776: include() [function.include]: Failed opening 'includes/utf/utf_normalizer.' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')

Fatal error: Class 'utf_normalizer' not found in /home/{myusername}/public_html/forum/includes/utf/utf_tools.php on line 1781
The file, utf_tools.php is in that location. What am I doing wrong?

User avatar
3Di
Former Team Member
Posts: 14235
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Using submit_post outside of phpBB

Post by 3Di » Sat Nov 15, 2008 2:51 pm

probably something to do with $phpbb_root_path .. IMO.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

Re: Using submit_post outside of phpBB

Post by boylan » Sat Nov 15, 2008 8:14 pm

3Di wrote:probably something to do with $phpbb_root_path .. IMO.
That was it - I had not declared $phpbb_root_path and $phpEx to be global. Once I did that, the errors went away and now I'm back to my problem of getting user information for my commentbot. I'll reply back here if I figure it out or have more questions.

User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

Re: Using submit_post outside of phpBB

Post by boylan » Sun Nov 16, 2008 8:18 am

Okay, I'm 95% of the way there. Here is the code necessary to include and globals to declare just to get the submit_post() to work.

Code: Select all

global $db, $user, $cache, $phpEx, $config, $phpbb_root_path, $template, $language, $auth;
			 
define('IN_PHPBB', true);
$phpbb_root_path = '/home/{my_username}/www/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'config.' . $phpEx);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
//include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

$user->session_begin();
$auth->acl($user->data);
$user->setup();	
After that I have to fill out $user->data to prevent errors and choose the user who will start the topic:

Code: Select all

			    $user->data['user_id']					= 26;
				$user->data['user_type']				= '';
				$user->data['group_id']					= '';
				$user->data['user_ip']					= '';
				$user->data['user_regdate']				= '';
				$user->data['username']					= 'CommentBot';
				$user->data['username_clean']			= 'commentbot';
				$user->data['user_email']				= '';
				$user->data['user_email_hash']			= '';
				$user->data['user_birthday']			= '';
				$user->data['user_lastvisit']			= '';
				$user->data['user_lastmark']			= '';
				$user->data['user_lastpost_time']		= '';
				$user->data['user_lastpage']			= '';
				$user->data['user_last_confirm_key']	= '';
				$user->data['user_last_search']			= '';
				$user->data['user_warnings']			= '';
				$user->data['user_last_warning']		= '';
				$user->data['user_login_attempts']		= '';
				$user->data['user_inactive_reason']		= '';
				$user->data['user_inactive_time']		= '';
				$user->data['user_posts']				= '';
				$user->data['user_lang']				= '';
				$user->data['user_timezone']			= '';
				$user->data['user_dateformat']			= '';
				$user->data['user_style']				= '';
				$user->data['user_rank']				= '';
				$user->data['user_colour']				= '';
				$user->data['user_message_rules']		= '';
				$user->data['user_full_folder']			= '';
				$user->data['user_emailtime']			= '';
				$user->data['user_topic_show_days']		= '';
				$user->data['user_topic_sortby_type']	= '';
				$user->data['user_topic_sortby_dir']	= '';
				$user->data['user_post_show_days']		= '';
				$user->data['user_post_sortby_type']	= '';
			 	$user->data['user_post_sortby_dir']		= '';
				$user->data['user_notify']				= '';
				$user->data['user_notify_pm']			= '';
				$user->data['user_notify_type']			= '';
				$user->data['user_allow_pm']			= '';
				$user->data['user_allow_viewonline']	= '';
				$user->data['user_allow_viewemail']		= '';
				$user->data['user_allow_massemail']		= '';
				$user->data['user_options']				= '';
				$user->data['user_avatar']				= '';
				$user->data['user_avatar_type']			= '';
				$user->data['user_avatar_width']		= '';
				$user->data['user_avatar_height']		= '';
				$user->data['user_sig']					= '';
				$user->data['user_sig_bbcode_uid']		= '';
				$user->data['user_sig_bbcode_bitfield']	= '';
				$user->data['user_from']				= '';
				$user->data['user_icq']					= '';
				$user->data['user_aim']					= '';
				$user->data['user_yim']					= '';
				$user->data['user_msnm'	]				= '';
				$user->data['user_jabber']				= '';
				$user->data['user_website']				= '';
				$user->data['user_occ']					= '';
				$user->data['user_interests']			= '';
				$user->data['user_actkey']				= '';
				$user->data['user_newpasswd']			= '';
				$user->data['is_registered']			= true;
				$user->data['is_bot']					= '';
				$user->data['session_admin']			= '';
				$user->data['session_page']				= ''; 	
Finally, I submit the post:

Code: Select all

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

//The next two lines are for getting the article's title and link from Joomla			
$articleTitle = $article->title;
$articleLink = $article->readmore_link;
$articleMessage = "Comments thread for [url=http://chrisboylan.com" . $articleLink . "]" . $articleTitle . "[/url]";

// note that multibyte support is enabled here 
$articleTitleNormalized = utf8_normalize_nfc($articleTitle);
$articleMessageNormalized = utf8_normalize_nfc($articleMessage);

generate_text_for_storage($articleTitleNormalized, $uid, $bitfield, $options, false, false, false);
generate_text_for_storage($articleMessageNormalized, $uid, $bitfield, $options, true, true, true);

$data = array( 
	'forum_id'		=> 4,
	'icon_id'		=> false,
	'enable_bbcode'		=> true,
	'enable_smilies'	=> true,
	'enable_urls'		=> true,
	'enable_sig'		=> true,
	'message'		=> $articleMessageNormalized,
	'message_md5'	=> md5($articleMessageNormalized),	
	'bbcode_bitfield'	=> $bitfield,
	'bbcode_uid'		=> $uid,
	'post_edit_locked'	=> 0,
	'topic_title'		=> $articleTitleNormalized,
	'notify_set'		=> false,
	'notify'			=> false,
	'post_time' 		=> 0,
	'forum_name'		=> '',
	'enable_indexing'	=> true,
);

submit_post('post', $articleTitleNormalized, 'CommentBot', POST_NORMAL, $poll, $data);
OK -- so after all that, the topic gets inserted and the first post contains a link back to the article - but I get a MySQL error (even though the post was submitted):

Code: Select all

SQL ERROR [ mysqli ]

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND t.topic_moved_id = 0 AND (tt.topic_id IS NULL OR tt.mark_time < t.topic' at line 5 [1064]

SQL

SELECT t.forum_id FROM phpbb_topics t LEFT JOIN phpbb_topics_track tt ON (tt.topic_id = t.topic_id AND tt.user_id = 26) WHERE t.forum_id = 4 AND t.topic_last_post_time > AND t.topic_moved_id = 0 AND (tt.topic_id IS NULL OR tt.mark_time < t.topic_last_post_time) GROUP BY t.forum_id LIMIT 1
I don't think the code I've created is really best practice and that may be the source of all the trouble. Does anyone have any suggestions of what i can do to fix this last error? Most of the threads and documentation on this subject seem to presume using submit_post() inside of phpBB, so they skip over large pieces of information I need.

Also, I need to get the topic_id after the post is submitted to create the link for the article. How do I get that? Is it simply $post_data['topic_id'] after submit_post is successful?

Much thanks.

User avatar
3Di
Former Team Member
Posts: 14235
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Using submit_post outside of phpBB

Post by 3Di » Sun Nov 16, 2008 11:42 am

would you mind to post the PHP code related to the query?

also this bit looks weird, > of what?

Code: Select all

AND t.topic_last_post_time > AND
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

Re: Using submit_post outside of phpBB

Post by boylan » Sun Nov 16, 2008 12:35 pm

The above code is all I have related to this - I don't have any code for that query, I presume its related to submit_post() - I have never seen that query before.

I'm guessing the query is generated by submit_post() somewhere in functions_posting.php - but I couldn't find it at first glance.

I'm guessing it has something to do with notifications maybe? Is it a problem that most of $user->data was left mostly empty? I set notify to false in the data arrary for submit_post().

Thanks.

User avatar
3Di
Former Team Member
Posts: 14235
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Using submit_post outside of phpBB

Post by 3Di » Sun Nov 16, 2008 2:58 pm

Well, I never tested a such modification before, so my knowledge it is quite null about that, I know somebody else made a similar code for its own uses, perhaps him will chime on this.

The one thing I don't see that right it is the 'global thinghy' you did put in first place there into your php, also because the function submit_post() already does that IMO.

Code: Select all

function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
{
	global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path;
Adding_pages will give you more details about the parts you feel you are missing, I guess.

Finally, as I already said "$phpbb_root_path = '/home/{my_username}/www/forum/';" should be changed there..
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

Re: Using submit_post outside of phpBB

Post by boylan » Sun Nov 16, 2008 6:03 pm

Nice avatar - I got started on a Commodore 64 back in the day as well. My Dad wouldn't buy a PC for the longest time because we had multiple Commodore 128's and "they were just fine".

As for the php_root_path - what's wrong with it? The absolute path instead of relative? I swap out {my username} with my actual username in the script.

I changed it to

Code: Select all

$phpbb_root_path = './forum/';
and still get the same errors. I'll look at the globals in a few hours, now it's kickoff for the Giants game.

User avatar
3Di
Former Team Member
Posts: 14235
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Using submit_post outside of phpBB

Post by 3Di » Sun Nov 16, 2008 7:24 pm

boylan wrote:Nice avatar - I got started on a Commodore 64 back in the day as well.
Thanks, so do I but with Commodore Vic-20, what a days those... ;)

About the rest: I subscribed to this topic because me too I do want to have a such MOD for my own uses, that's why I'll try to help you out as more as I can.

As I said though, I think Highway of Life could help out here for sure. IMHO. :geek:

Best regards. :)
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

Re: Using submit_post outside of phpBB

Post by boylan » Sun Nov 16, 2008 10:05 pm

Vic-20 - That's Hardcore.

I'll post any updates or breakthroughs I get here. Now that the Giants won decisively - again - I'll be working on this the rest of the evening.

Should I PM Highway of Life? Or have you already?

User avatar
3Di
Former Team Member
Posts: 14235
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Using submit_post outside of phpBB

Post by 3Di » Sun Nov 16, 2008 10:09 pm

I know him will read this post. Be patient and we'll see. ;)
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
boylan
Registered User
Posts: 23
Joined: Fri Jan 09, 2004 4:23 am
Location: Gillette, NJ
Contact:

Re: Using submit_post outside of phpBB

Post by boylan » Sun Nov 16, 2008 11:54 pm

Ok, I at least found the query - it's at line 1361 of includes/functions.php in the function update_forum_tracking_info. The problem comes at line 1364:

Code: Select all

AND t.topic_last_post_time > ' . $mark_time_forum . '
$mark_time_forum is apparently empty, which is bad. I have no idea what is causing this error.

rippededge
Registered User
Posts: 209
Joined: Tue Dec 04, 2007 1:55 am

Re: Using submit_post outside of phpBB

Post by rippededge » Mon Nov 17, 2008 5:16 am

boylan wrote:Ok, I at least found the query - it's at line 1361 of includes/functions.php in the function update_forum_tracking_info. The problem comes at line 1364:

Code: Select all

AND t.topic_last_post_time > ' . $mark_time_forum . '
$mark_time_forum is apparently empty, which is bad. I have no idea what is causing this error.

I would love this mod! I run joomla 1.5x and I have phpbb3 and this mod is something I have been dying to have!

Locked

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