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.