× Joomla Facebook Connect support forum

Topic-icon CB PROBLEMS

Active Subscriptions:

None
14 years 9 months ago #1771 by funkydimensions
CB PROBLEMS was created by funkydimensions
Ok since installing this component I have had several issues...

1. The redirect wasn't working which was easily fixed by:
a) making sh404sef skip jfbconnect
b) making the redirect url in jfbc config go to on a non sef url

2. The ajax popup doesn't seem to work, i thought it was a mootools issue for a while so i checked my template etc with no success then i discovered after reading a post in the forum the popup only seems to work when you are already logged into facebook.

3. In jfbc I had it set to 'yes' to make a joomla account, but i didn't like that middle step where the user had to make a joomla account anyway, so i switched it to 'no' and redirected to cb edit profile page, which would be fine except....

4. The user data is not importing, so when they arrive on the cb edit profile page none of the fields are filled in except the dodgey email and username essentially the 2 fields I would like to see blank. Also the avatar is not importing into cb, however it is going into the correct folder and showing on the jfbc login module.

5. Even if i ignore the fact that data and avatar are not being imported and fill in the fields manually and hit save. Rather than been taken to my profile page in cb it shows:

This user has not yet confirmed his email address and account!
This user has not yet been approved by a moderator!

But I have everything set to not have to confirm or be moderated?


I have thoroughly read through the forum and found no hints as to how to get the data to import properly, any help would be so greatly appreciated. I cannot post a link because my site is offline at the moment.
The topic has been locked.
Active Subscriptions:

None
14 years 9 months ago #1772 by funkydimensions
Replied by funkydimensions on topic CB PROBLEMS
GRRRRR just wrote a decent sized post and it says its a draft and now i can't find that draft so...

After many hours of trial and error I have got everything working

Attached is my new components/helpers/communitybuilderhelper.php

It will only be suitable if you want your system setup as mine is ie, jfbc config new user is set to 'no' (even though it actually makes a new user) and cos of my coding it will only work if your joomla db prefix is jos_

The outcome is that a user signs up via facebook and everything gets imported then it redirects straight to the cb edit profile page with blank email and username fields so they are forced to enter them :)
The topic has been locked.
Active Subscriptions:

None
14 years 9 months ago #1773 by funkydimensions
Replied by funkydimensions on topic CB PROBLEMS
GRRR attachment didn't stick...

<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');


class JFBConnectCommunityBuilderHelper
{
function importFBProfile()
{
$configModel = JModel::getInstance('JFBConnectModelConfig');
if ($configModel->getSetting('cb_enable'))
{

require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_comprofiler'.DS.'plugin.foundation.php' );
require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_comprofiler'.DS.'plugin.class.php' );
require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_comprofiler'.DS.'comprofiler.class.php' );
require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_comprofiler'.DS.'library'.DS.'cb'.DS.'cb.database.php' );
require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_comprofiler'.DS.'library'.DS.'cb'.DS.'cb.tables.php' );
include_once(JPATH_SITE.DS.'components'.DS.'com_comprofiler'.DS.'plugin'.DS.'language'.DS.'default_language'.DS.'default_language.php');

require_once(JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'helpers'.DS.'facebookhelper.php');
$fbClient = JFBConnectFacebookHelper::getFbClient();
$fbUserInfo = JFBConnectFacebookHelper::_getUserInfo(JFBConnectFacebookHelper::$_OrigFbUser);

$jUser = JFactory::getUser();

$test = $jUser->id;
$test2 = $fbUserInfo;


$array = array(
'id' => $jUser->id,
'name' => $jUser->name,
'firstname' => $fbUserInfo,
'lastname' => $fbUserInfo,
'username' => $jUser->username,
'email' => $jUser->email
//'password' => 'h',
//'password__verify' => 'blahblah'
);




global $_CB_database;
$user = new moscomprofilerUser($_CB_database);
$user->load($jUser->id);
$ui = "1";
$reason = "edit";
$user->saveSafely( $array, $ui, $reason );


//Copy over the FB Avatar to CB...
####### REMOVED THIS COS I WANT TO IMPORT ALWAYS AND I NEED TO MOVE THIS BELOW THE DB STUFF
//if ($configModel->getSetting('cb_import_avatar'))


// Wish I could use CB's changeUsersStatus call, but it has a redirect at the end :(
$dbo = JFactory::getDBO();
$dbo->execute("UPDATE #__comprofiler SET approved=1,confirmed=1,cbactivation='' WHERE user_id = ".$jUser->id);
// Reload user again. Could just set the values written above directly, but it's nice to know the db txn succeeeded.
$user->load($jUser->id);
$test = $jUser->id;


// Trigger OnBeforeActivate/onUserActive plugins.
// Send Welcome email and notify admins of new user.
activateUser($user, 0, "UserRegistration", true, true, true);

JFBConnectCommunityBuilderHelper::migrateFBFieldsToCB();

#### REPLACED THIS HERE COS IT MUST GO AFTER THE FUNCTION ABOVE
JFBConnectCommunityBuilderHelper::migrateFBAvatarToCB();

}

}

function migrateFBFieldsToCB()
{
$user = JFactory::getUser();
$userId = $user->get('id');
$dbo = JFactory::getDBO();
require_once (JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'helpers'.DS.'facebookhelper.php');
$fbClient = JFBConnectFacebookHelper::getFbClient();

$configModel = JModel::getInstance('JFBConnectModelConfig');
$fbFieldMap = $configModel->getSetting('cbFieldMap');

$fbFields = array();
foreach($fbFieldMap as $fbField)
{
$fbFieldArray = explode('.', $fbField);
$fbFields[] = $fbFieldArray[0];
}
if (empty($fbFields))
return;

$fbProfileFields = $fbClient->users_getInfo($fbClient->user, $fbFields);

$sql = "";
foreach($fbFieldMap as $fieldId=>$fbField)
{
$addRow = true;

$fbFieldArray = explode('.', $fbField);

if (count($fbFieldArray) == 1)
{
if (isset($fbProfileFields[0][$fbFieldArray[0]]))
$value = $fbProfileFields[0][$fbFieldArray[0]];
else
$addRow = false;
}
else if (count($fbFieldArray) == 2)
{
if (isset($fbProfileFields[0][$fbFieldArray[0]][$fbFieldArray[1]]))
$value = $fbProfileFields[0][$fbFieldArray[0]][$fbFieldArray[1]];
else
$addRow = false;
}
else if (count($fbFieldArray) == 3)
{
if (isset($fbProfileFields[0][$fbFieldArray[0]][$fbFieldArray[1]][$fbFieldArray[2]]))
$value = $fbProfileFields[0][$fbFieldArray[0]][$fbFieldArray[1]][$fbFieldArray[2]];
else
$addRow = false;
}

if ($addRow)
{
//query the com_profiler_fields to get the column names
$query = 'SELECT name FROM #__comprofiler_fields WHERE fieldid='.$fieldId;
$dbo->setQuery($query);
$colName = $dbo->loadResult();

$userValue = $dbo->quote($value);

//Update jos_comprofiler for value for each column by id=$userId ### tweaked this a bit
$sql .= "UPDATE jos_comprofiler SET `$colName` = $userValue WHERE id = '$userId' ;";



}

}
// this removes the dodgey username and email forcing them to enter a new one
$userQuery = "UPDATE jos_users SET `username` = '', `email` = '' WHERE id = '$userId' ;";
// this creates the comprofiler profile so that it can be mapped with data by the $sql query
$userQuery .= " INSERT INTO jos_comprofiler (`id`, `user_id`) VALUES ('$userId', '$userId');";
$sql = $userQuery." ".$sql;
//this gets appended to the end instead of looping every time in the loop above
$sql .= " UPDATE jos_comprofiler SET approved = 1, confirmed = 1 WHERE id = '$userId';";
$dbo->setQuery($sql);
$dbo->queryBatch();


}

function migrateFBAvatarToCB()
{
require_once (JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'helpers'.DS.'facebookhelper.php');
$fbClient = JFBConnectFacebookHelper::getFbClient();
$avatarField = array(0=>'pic_big');
$avatarUrlArray = $fbClient->users_getInfo($fbClient->user, $avatarField);
$avatarUrl = $avatarUrlArray[0];

$fbImgPath = 'jfbc_'.$fbClient->user.'pic_tmp.jpg';


if (function_exists('curl_init'))
{
$fp = fopen (JPATH_SITE.DS.'images'.DS.'comprofiler'.DS.$fbImgPath, 'w+'); // Save location
$ch = curl_init($avatarUrl); // Download location
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
else
copy($avatarUrl, JPATH_SITE.DS.'images'.DS.$fbImgPath);

jimport('joomla.filesystem.file');
jimport('joomla.utilities.utility');

global $mainframe;
$user = JFactory::getUser();
$userId = $user->get('id');
$dbo = JFactory::getDBO();

//require_once(JPATH_SITE.DS.'components'.DS.'com_comprofiler'.'comprofiler.php');
if (JFBConnectCommunityBuilderHelper::_addCBImage($fbImgPath, $userId))
{
$mainframe->enqueueMessage("Successfully imported avatar from Facebook.");
}
else
{ # there was a problem adding the image, use the default
$query = "UPDATE #__comprofiler SET `avatar`=NULL WHERE id = ".$userId;
$dbo->execute($query);
$mainframe->enqueueMessage("There was an issue importing your Facebook avatar. The default avatar will be used.", 'error');
}

return true;
}

function _addCBImage($fbAvatar, $userId)
{
global $mainframe;
global $ueConfig;

require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_comprofiler'.DS.'imgToolbox.class.php');

$dbo = JFactory::getDBO();
$errorDetected = false;
// Get a hash for the file name.
$fbAvatarFileName = substr( $fbAvatar, 0, strpos($fbAvatar, '.') );
//@todo: configurable path for avatar storage?
$fbExtension = substr($fbAvatar, strpos($fbAvatar, '.'));

$storage = JPATH_ROOT . DS . 'images' . DS . 'comprofiler' . DS;
$storageImage = $storage . DS . $fbExtension ;
$storageThumbnail = $storage . DS . 'tn' . $fbExtension ;
$image = $fbExtension ;
$thumbnail = 'tn' . $fbExtension ;


$imgToolBox = new imgToolBox();
$imgToolBox->_conversiontype = $ueConfig;
$imgToolBox->_IM_path = $ueConfig;
$imgToolBox->_NETPBM_path = $ueConfig;
$imgToolBox->_maxsize = $ueConfig;
$imgToolBox->_maxwidth = $ueConfig;
$imgToolBox->_maxheight = $ueConfig;
$imgToolBox->_thumbwidth = $ueConfig;
$imgToolBox->_thumbheight = $ueConfig;
$imgToolBox->_debug = 0;
$allwaysResize = ( isset( $ueConfig ) ? $ueConfig : 1 );

$imageArray = array();
$imageArray = $fbAvatar;
$imageArray = $fbAvatarFileName;
$imageArray = $fbExtension;

$newFileName = $imgToolBox->processImage( $imageArray, $fbAvatarFileName, $storage, 0, 0, 29, $allwaysResize );

//tweaked the sytax here
$query = "UPDATE jos_comprofiler SET `avatar` = '$newFileName' WHERE `id`= '$userId'";

$dbo->execute($query);

return true;
}



}
The topic has been locked.
Support Specialist
14 years 9 months ago #1788 by alzander
Replied by alzander on topic CB PROBLEMS
Thank you for your post, and we're sorry you had these issues. We'll look to test and include your changes in the next release to ensure things continue to run happily for you.
The topic has been locked.
Active Subscriptions:

None
14 years 3 months ago #2793 by adub84
Replied by adub84 on topic CB PROBLEMS
This was for version 2.1 correct? I copied and pasted that file into my helpers folder with no luck. It seems this issue is still in version 2.5. Anyone have any luck with being able to view their user profiles after registering using fbconnect?
The topic has been locked.
Support Specialist
14 years 2 months ago #2894 by alzander
Replied by alzander on topic CB PROBLEMS
If you copied it wholesale into the 2.5 rev, it probably won't work at all. There's a ton of changes between 2.1 and 2.5.

What are you trying to accomplish, and what's going wrong? You should be able to see your profile after registration now as we use the CB admin settings for approving/moderating a user.. so if you have auto-approvals set up, we respect that.
The topic has been locked.