Tuesday, October 20, 2009, 07:05pm
Integrating phpBB and phpListI’ve been procrastinating on a project because I was waiting for someone to finally make a modification for phpBB that would automatically subscribe a user to a phpList newsletter. I couldn’t wait anymore so I just went ahead and did some tinkering around. Please be warned that this is a rough hack and isn’t validated by the phpBB mod team.
This hack works for phpList 2.10.10 and phpBB 3.0.5.
Download this file and rename it to functions_phplist.php. If you edit the file with notepad or any text editor, you would find this part:
$database_host = "localhost"; $database_name = "database"; $database_user = "username"; $database_password = "password"; $table_prefix = "phplist_"; $usertable_prefix = "phplist_user_";
Fill those in with your phpList credentials which you could get from your phpList config.php file. I didn’t want to include the phpList file as there might be global variables that could be overwritten. That’s the only thing you have to alter in that file. After editing it, upload it to the /includes folder inside your phpBB folder.
Now to integrate that function into phpBB core, you have to edit the /includes/ucp/ucp_register.php file in your phpBB folder. Look for these lines:
$message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
trigger_error($message);
and insert the following lines before it:
//Include phplist functions include($phpbb_root_path . 'includes/functions_phplist.' . $phpEx); //Subscribe user to phplist $phplist_user_id = phplist_subscribeuser($data['email'], 1);
Notice the “1″ in that last line? Change that to the id of the newsletter you want your users to be subscribed to. You could get that from your phpList admin page. After editing, upload it to your server overwriting the original ucp_register.php file. And that’s it!
Once a user registers in your forums, they will be automatically subscribed to your newsletter as well. But take note that this is very limited. For one, it won’t send a welcome message to the user’s email. Also, the subscribing process happens during registration. If you have validation of email addresses in your boards and you want the subscribing process to occur once a user validates his/her email address, you will have to tinker with a different file instead of ucp_register.php. Maybe ucp_activate.php, I’m not sure since I didn’t tinker with anything else. Also, since I didn’t provide the user with an unsubscribe option in their profile, they can only unsubscribe to the newsletter via phpList’s unsubscribe page.
Now, if you already have users in your boards and want to import them to your phpList newsletter, save this file as a php file and edit these lines to reflect the paths to your phpBB and phpList config files.
require("/path/to/phplist/config/config.php");
and
require("/path/to/phpbb/config.php");
Then find this line
phplist_subscribeuser($row['user_email'], 1);
and replace “1″ with the id of the newsletter you want your users to be subscribed to. Upload the file to your server and access it via your browser and wait for the script to finish running. When I imported 16,000 users it roughly took me less than 5 minutes to finish.
That’s it. Feel free to tinker it to your heart’s content. I just wanted to share this because making this work gave me a headache.
tags: phpbb, phplist, scripts
