I like CB alot and I'd like to see it become a common platform for other components that incorporate the user profile. The integration with simpleboard & pms are great steps in that direction. So here's my part in furthering that effort.
YANC 1.4 offered instruction on integrating the Yanc newsletter component with the stock Mambo user registration. Based on that I was able to devise a way for admins using the Community Builder component to enable users to sign up for available newsletters at the time of registration. Confirming their registration in Community Builder also confirms their registration for the newsletter lists.
[Step 1]
Install both the YANC and Community Builder components. In my tests I used Yanc 1.4 beta and CB 1.0 Beta 4. You could also use YAnc 1.32 (since 1.4 seems to have issues with PHP 5) but you'll need to get the file class.dbclasses.php from the 1.4 distribution and copy it to \administrator\components\com_yanc\classes.
[Step 2]
In the file \components\com_comprofiler\comprofiler.php
Search for this code (around line 16)
Code:
require_once ( $mainframe->getPath( 'front_html' ) );
And insert the following code below
PHP Code:
require_once ($mosConfig_absolute_path .'/components/com_yanc/codehacks/cb_integration.php');
[Step 3]
In the file \components\com_comprofiler\comprofiler.php
Search for this code (around line 70)
Code:
case "saveRegistration":
saveRegistration( $option );
break;
And replace with the following
Code:
case "saveRegistration":
saveYancRegistration($ueConfig['name_style']);
saveRegistration( $option );
break;
[Step 4]
In the file \components\com_comprofiler\comprofiler.php
Search for this code (around line 79)
Code:
case "confirm":
confirm($confirmCode);
break;
And replace with the following
Code:
case "confirm":
confirmYancSubscriber($confirmCode);
confirm($confirmCode);
break;
[Step 5]
edit the file \components\com_comprofiler\comprofiler.html.php
Search for this code (around line 1097)
Code:
<tr>
<td colspan="2"> </td>
</tr>
Add the following code below
PHP Code:
<?php showLists(); ?>
[Step 6]
Yanc 1.3 users need to create a directory called codehacks in \components\com_yanc
Create a file called cb_integration.php in this directory and insert the following code in this file.
PHP Code:
<?php
// --------------------------------------------------------------------------------
// YaNC - Yet another Newsletter Component
// Copyright (C) 2003-2004 TIM_online
// http://www.tim-online.nl
//
// All rights reserved. YaNC is a component for Mambo 4.5.
// It allows you to compose various newsletters and send then to subscribers
// to different lists. You can use HTML or text mailings
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html
// --------------------------------------------------------------------------------
// $Id: reg_integration.php,v 1.1 2004/11/04 17:51:29 websmurf Exp $
// modified for Community Builder integration Eric Santiago http://www.ericsantiago.com 2005/02/04
// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
include( $mosConfig_absolute_path . '/administrator/components/com_yanc/classes/class.dbclasses.php' );
function showLists() {
global $letters;
$lists = getLists();
if(count($lists) > 0){
echo '<tr><td colspan="2" class="componentheading">Subscribe yourself to the following mailing
lists:</td></tr>';
//echo '<tr><td colspan="2"> </td></tr>';
echo '<tr><td colspan="2"><blockquote>';
foreach($lists AS $list){
echo '<p><input checked type="checkbox" name="list[]" value="' . $list->id . '" /> ' .
$list->list_desc . '</p>';
}
echo '<blockquote></td></tr>';
echo '<tr><td> </td>
<td><input checked type="checkbox" name="html" value="1" /><i>Receive emails in HTML format?</i></td>
</tr>';
echo '<tr><td colspan="2"><hr></td></tr>';
}
}
function getLists(){
global $database, $my;
$query = "SELECT * FROM #__newsletter_letters WHERE hidden <= ". intval($my->gid) ." ORDER BY list_name";
$database->setQuery($query);
$total = $database->loadObjectList();
echo $database->getErrorMsg();
return $total;
}
function saveYancRegistration($name_style){
global $database;
$lists = mosGetParam($_POST, 'list', array());
//accomodates for various name styles in cb
SWITCH($name_style) {
case 2:
$name = mosGetParam($_POST, 'firstname', '') . " " . mosGetParam($_POST, 'lastname', '');
break;
case 3:
$name = mosGetParam($_POST, 'firstname', '') . " " . mosGetParam($_POST, 'lastname', '');
break;
DEFAULT:
$name = mosGetParam($_POST, 'name', '');
break;
}
$email = mosGetParam($_POST, 'email', '');
$html = mosGetParam($_POST, 'html', 1);
foreach($lists AS $list){
$row = new yancSubscriber( $database );
// load the row from the db table
$row->subscriber_name = $name;
$row->subscriber_email = $email;
$row->receive_html = $html;
$row->list_id = $list;
$row->subscribe_date = date( "Y-m-d H:i:s" );
$row->store();
}
}
function confirmYancSubscriber($confirmCode){
global $database, $log;
//get the email of the user confirming
$query = "SELECT * FROM #__comprofiler c JOIN #__users u ON c.id=u.id WHERE md5(c.id) = '" . $confirmCode .
"'";
$database->setQuery($query);
$user = $database->loadObjectList();
if(mysql_affected_rows() == 0){
//echo $lang->translate("noaccountfound");
}
else{
//subscriber_id is different from user id, use email to match users in the two tables
$email = $user[0]->email;
//set confirmed for all instances of this email in the yanc subscribers table
$query = "UPDATE #__newsletter_subscribers SET confirmed = 1 WHERE subscriber_email = '" . $email .
"'";
$database->setQuery($query);
$database->query();
}
}
?>
That's all. Enjoy.
