Kunena 6.2.6 released

The Kunena team has announce the arrival of Kunena 6.2.6 [K 6.2.6] which is now available for download as a native Joomla extension for J! 4.4.x/5.0.x. This version addresses most of the issues that were discovered in K 6.1 / K 6.2 and issues discovered during the last development stages of K 6.2

Question Create Kunena user in Kunena database upon joomla registration

More
13 years 3 months ago - 13 years 3 months ago #1 by Dalandau
Hi,

I would like to automaticly create a user in kunenas database upon user registration.
As I see the user is only created upon his first visit to the forum.

The reason I would need the database row to be created upon registration is because I am using a Janrain RPX registration to my website and I would like it to update kunena avatar upon registration, but I am not able to insert the avatar filename in the database because the user row does not yet exist.

For example this is how it works for jomsocial:

Code:
// check if the Jomsocial tables are there, then set avatar $query = "SHOW TABLES LIKE '%__community_users'"; $db->setQuery($query); $Jomtableexists = $db->loadResult(); if (isset($Jomtableexists) && $auth_info['profile']['photo']) { jimport('joomla.filesystem.file'); jimport('joomla.utilities.utility'); require_once(JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'helpers'.DS.'image.php'); $fileName = JUtility::getHash( $auth_info['profile']['photo'] . time() ); $fileName = JString::substr( $fileName , 0 , 24 ); $avatarimage = 'images/avatar/' . $fileName.'.jpg' ; $thumbavatar = 'images/avatar/' . 'thumb_' . $fileName.'.jpg' ; $st = JPATH_ROOT; $jPath = split('\administrator',$st); $storage = $jPath[0] . DS . 'images' . DS . 'avatar'. DS . $fileName.'.jpg'; $storageThumbnail = $jPath[0] . DS .'images'.DS . 'avatar'. DS . 'thumb_' . $fileName.'.jpg' ; $destType = 'image/jpg'; $imageMaxWidth = 140; // Only resize when the width exceeds the max. if( !cImageResizePropotional( $auth_info['profile']['photo'] , $storage , $destType , $imageMaxWidth ) ) { global $option,$mainframe; $msg = JText::sprintf( 'Image Upload Error '); } // Generate thumbnail if(!cImageCreateThumb( $auth_info['profile']['photo'] , $storageThumbnail , $destType )) { global $option,$mainframe; $msg = JText::sprintf( 'Image Upload Error '); } $query = "SELECT `userid` FROM `#__community_users` WHERE `userid`='" . $user->get('id') . "'"; $db->setQuery( $query ); if($db->loadResult()) { $query = "UPDATE `#__community_users` SET `avatar` = '" . $avatarimage . "', `thumb` = '" .$thumbavatar . "' WHERE `userid`='" . $user->get('id') . "'"; } else { $query = "INSERT INTO `#__community_users` SET `userid`='" . $user->get('id') . "', `avatar` = '" . $avatarimage . "', `thumb` = '" .$thumbavatar . "'"; } $db->setQuery( $query ); $db->query(); } }

What should I do inorder to make it work with kunena 1.6? (im very new at php)

Thank you for the help
Last edit: 13 years 3 months ago by Dalandau.

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #2 by Dalandau
Do you think it is possible to edit this code to do the same for Kunena 1.6?

Thank you

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #3 by Dalandau
Hi,

I still havent figured it out.

Any suggestions?

Thanks,

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #4 by sozzled

Dalandau wrote: I would like to automaticly create a user in kunenas database upon user registration.
As I see the user is only created upon his first visit to the forum.

That pretty well sums it up.

Possible helpful further reading on this subject: Kunena is not "registering" all my Joomla users

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #5 by Dalandau
Thanks,

I had read that before.
But what function registers the user into the Kunena DB upon his first visit ?
And how can I initialize that function?

Thank you

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #6 by sozzled

Dalandau wrote: But what function registers the user into the Kunena DB upon his first visit ?
And how can I initialize that function?

I've never bothered to find out. I don't know the answer. In what way does knowing this information help you with some problem that you might be having? Perhaps if we knew what problem you are having we would know how to answer this question better.

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #7 by Dalandau
Its not a problem,

I have a module, its purpose is to authenticate users against various social networks to create a joomla user and to import their profile or to Jomsocial or to Community builder.

The profile page of Community builder is ugly and not practical and Kunena 1.6 profile page looks real cool.

So Im trying to make it import the profile picture to kunena avatar instead of community builder avatar.

This is how the original works, and its not updated to community builder 1.3
Code:
<?php /** * @package Janrain Engage SignIn * @copyright Copyright (C) 2010 Thakkertech - All rights reserved. * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html, see license.txt */ // Dont allow direct linking ( defined('_JEXEC') || defined( '_VALID_MOS' ) ) or die('Restricted access'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); // Include the syndicate functions only once require_once (dirname(__FILE__).DS.'helper.php'); $redirectType = modJanrainengageHelper::getType(); $redirectUrl = modJanrainengageHelper::getReturnURL($params, $redirectType); $GLOBALS["redirectUrl"] = $redirectUrl; $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $my =& JFactory::getUser(); $rpx_imageurl = JURI::base().'modules/mod_janrainengage/images/rpxIcons.png'; $rpx_image_width = ''; $rpx_image_height = ''; $rpx_api_key = $params->get( 'rpx_api_key', "" ); $rpx_application_name = $params->get( 'rpx_application_domain', ""); $rpx_show_type = $params->get( 'rpx_show_type', "popup" ); $rpx_imagepath = $params->get( 'rpx_imagepath', "" ); $rpx_image_width = $params->get( 'rpx_image_width', "" ); $rpx_image_height = $params->get( 'rpx_image_height', "" ); $appy_image_width_height= $params->get( 'appy_image_width_height', 0 ); $rpx_image_width = ( intval($rpx_image_width) > 0 && ( $appy_image_width_height == 1 ) ) ? 'width:'.$rpx_image_width.'px;' : ''; $rpx_image_height = ( intval($rpx_image_height) > 0 && ( $appy_image_width_height == 1 ) ) ? 'height:'.$rpx_image_height.'px;' :''; $rpx_imagepath = trim($rpx_imagepath); if( @GetImageSize($rpx_imagepath) ) { $rpx_imageurl = $rpx_imagepath; } $juri =& JURI::getInstance(); $base = $juri->toString( array('scheme', 'host', 'port')); $token_url = $base.$_SERVER['REQUEST_URI']; // Future-friendly json_encode if( !function_exists('json_encode') ) { require_once( JPATH_ROOT.DS.'modules'.DS.'mod_janrainengage'.DS.'JSON.php'); function json_encode($data) { $json = new Services_JSON(); return( $json->encode($data) ); } } // Future-friendly json_decode if( !function_exists('json_decode') ) { require_once( JPATH_ROOT.DS.'modules'.DS.'mod_janrainengage'.DS.'JSON.php'); function json_decode($data, $bool) { if ($bool) { $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); } else { $json = new Services_JSON(); } return( $json->decode($data) ); } } if(isset($_REQUEST['token'])) { $token = $_REQUEST['token']; $post_data = array( 'token' => $_REQUEST['token'], 'apiKey' => $rpx_api_key, 'format' => 'json' ); $post_url = 'https://rpxnow.com/api/v2/auth_info/?token='.$token.'&apiKey='.$rpx_api_key.'&format=json'; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, $post_url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $raw_json = curl_exec($curl); curl_close($curl); // parse the json response into an associative array $auth_info = json_decode($raw_json, true); // process the auth_info response if ($auth_info['stat'] == 'ok') { saveJanrainEngageUser($auth_info); } else { echo '<b>Error:</b> ' . $auth_info['err']['msg']; } } else { $userParams = &JComponentHelper::getParams( 'com_users' ); if( $user->id ) { $welcome = JText::_('Welcome').' '.$user->get('name'); $LogoutRedirect = 'index.php?option=com_user&task=logout&return='.$redirectUrl; $LogoutRedirect = JRoute::_($LogoutRedirect); ?> <div class="janiainengage_main"><?php echo $welcome;?> <input type="submit" onclick="document.location.href='<?php echo $LogoutRedirect;?>'" value="<?php echo JText::_('Log out');?>" class="button" name="Submit"> </div> <?php } else { if( $rpx_show_type == 'popup') { $post_token_url = 'https://'.$rpx_application_name.'.rpxnow.com/openid/v2/signin?token_url='.$token_url; ?> <a class="rpxnow janiainengage_a" onclick="return false;" href="<?php echo $post_token_url;?>"> <img class="janiainengage_img" style="border:solid 0px #eeeeee;<?php echo $rpx_image_width.$rpx_image_height;?>" src="<?php echo $rpx_imageurl;?>" alt="<?php echo JText::_('SighIn Here');?>"/> </a> <script src="https://rpxnow.com/openid/v2/widget" type="text/javascript"></script> <script type="text/javascript"> RPXNOW.token_url = "<?php echo $token_url ?>"; RPXNOW.realm = "<?php echo $rpx_application_name; ?>.rpxnow.com"; RPXNOW.overlay = true; RPXNOW.language_preference = 'en'; </script> <?php } else { $post_token_url = 'https://'.$rpx_application_name.'.rpxnow.com/openid/embed?token_url='.urlencode($token_url); ?> <iframe class="janiainengage_iframe" src="<?php echo $post_token_url;?>" scrolling="no" frameBorder="no" style="width:400px;height:240px;"></iframe> <?php } } } function saveJanrainEngageUser($auth_info) { global $mainframe; jimport('joomla.user.helper'); $db =& JFactory::getDBO(); $my =& JFactory::getUser(); $uri =& JFactory::getURI(); $host = $uri->getHost(); // process the auth_info response $profileValues = $auth_info['profile']; $identifier = $profileValues['identifier']; if( !isset($auth_info['profile']['email'] )) { $nameDisp = str_replace(' ','_',$auth_info['profile']['displayName']); $auth_info['profile']['email'] = $nameDisp.'@'.$host; } $query = "SELECT `id` FROM #__users WHERE `email`='".$auth_info['profile']['email']."'"; $db->setQuery($query); $userid = $db->loadResult(); $newuser = true; if( isset($userid) ) { $user =& JFactory::getUser($userid); if ($user->id == $userid) { $newuser = false; } } if($newuser == true) { //save the user $user = new JUser(); $authorize =& JFactory::getACL(); $date =& JFactory::getDate(); $uriInfo = JFactory::getURI(); $host = $uriInfo->getHost(); $usersConfig =& JComponentHelper::getParams( 'com_users' ); $newUsertype = $usersConfig->get( 'new_usertype' ); $user->set('id', 0); $user->set('usertype', $newUsertype); $user->set('gid', $authorize->get_group_id('',$newUsertype, 'ARO')); $user->set('registerDate', $date->toMySQL()); if(isset($auth_info['profile']['displayName'])) { $displayName = $auth_info['profile']['displayName']; } elseif(isset($auth_info['profile']['name']['displayName'])) { $displayName = $auth_info['profile']['name']['displayName']; } if(isset($auth_info['profile']['preferredUsername'])) { $preferredUsername = $auth_info['profile']['preferredUsername']; } elseif(isset($auth_info['profile']['name']['preferredUsername'])) { $preferredUsername = $auth_info['profile']['name']['preferredUsername']; } $user->set('name', $displayName); // if username already exists, just add an index to it $nameexists = true; $index = 0; $userName = $preferredUsername; while ($nameexists == true) { if(JUserHelper::getUserId($userName) != 0) { $index++; $userName = $preferredUsername.$index; } else { $nameexists = false; } } $user->set('username', $userName); $sEmail = ''; if(isset($auth_info['profile']['email'])) { $sEmail = $auth_info['profile']['email']; $user->set('email', $auth_info['profile']['email']); } elseif (isset($auth_info['profile']['name']['email'])) { $sEmail = $auth_info['profile']['email']; $user->set('email', $auth_info['profile']['email']); } $pwd = JUserHelper::genRandomPassword(); $user->set('password', $pwd); if (!$user->save()) { echo "ERROR: "; echo $user->getError(); } // admin users gid $gid = 25; $query = "SELECT `email`, `name` FROM `#__users` WHERE `gid` = '".$gid."'"; $db->setQuery( $query ); $adminRows = $db->loadObjectList(); // send email notification to admins if( !empty($adminRows) ) { foreach($adminRows as $adminRow) { $sitename = $mainframe->getCfg( 'sitename' ); $siteRoot = JURI::base(); $userName = $user->get('username'); $userID = $user->get('id'); $userTupe = $user->get('usertype'); $userEmail = $user->get('email'); $adminName = $adminRow->name; $adminEmail = $adminRow->email; $subject = JText::_('New user registered via JAINARAIN ENGANGE at')." ".$sitename; $subject = html_entity_decode($subject, ENT_QUOTES); $message = JText::_('Hello')." ".$adminName."\n"; $message .= JText::_('New user registered via JAINARAIN ENGANGE at')." ".$siteRoot."\n\n"; $message .= JText::_('User Detail:')."\n"; $message .= JText::_('User ID :')." ".$userID."\n"; $message .= JText::_('Usertype :')." ".$userTupe."\n"; $message .= JText::_('Name :')." ".$displayName."\n"; $message .= JText::_('Username :')." ".$userName."\n"; $message .= JText::_('Email :')." ".$sEmail."\n"; $message = html_entity_decode($message, ENT_QUOTES); JUtility::sendMail( $userName, $userEmail, $adminEmail, $subject, $message ); } }

It continues here with the part of making the avatar
Code:
// check if the community builder tables are there $query = "SHOW TABLES LIKE '%__comprofiler'"; $db->setQuery($query); $tableexists = $db->loadResult(); if( isset($tableexists) ) { $cbquery = "INSERT IGNORE INTO #__comprofiler(id,user_id,firstname,lastname) VALUES ('".$user->get('id')."','".$user->get('id')."','".$auth_info['profile']['name']['givenName']."','".$auth_info['profile']['name']['familyName']."')"; $db->setQuery($cbquery); if (!$db->query()) { JERROR::raiseError(500, $db->stderror()); } else { if($auth_info['profile']['photo']) { global $_CB_database, $_CB_framework, $ueConfig, $_PLUGINS ; if ( defined( 'JPATH_ADMINISTRATOR' ) ) { include_once JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php'; require_once $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/comprofiler.html.php'; } else { include_once $mainframe->getCfg( 'absolute_path' ). '/administrator/components/com_comprofiler/plugin.foundation.php'; require_once $mainframe->getPath( 'front_html' ); } $filename = urldecode(uniqid($user->get('id')."_")); // replace every space-character with a single "_" $filename = preg_replace( "/ /", "_", $filename ); // Get rid of extra underscores $filename = preg_replace( "/_+/", "_", $filename ); $filename = preg_replace( "/(^_|_$)/", "", $filename ); $tag = preg_replace( "/^.*\\.([^\\.]*)$/", "\\1", $auth_info['profile']['photo'] ); $tag = strtolower( $tag ); $newFileName = $filename . ".jpg"; $file = $_CB_framework->getCfg('absolute_path') . '/images/comprofiler/' . $newFileName; copy( $auth_info['profile']['photo'], $file ); $db->setQuery("UPDATE #__comprofiler SET avatar='" .$newFileName . "', avatarapproved=1, lastupdatedate='".date('Y-m-d\TH:i:s')."' WHERE id=" . (int) $user->get('id')); $db->query(); } } } // check if the Jomsocial tables are there, then set avatar $query = "SHOW TABLES LIKE '%__community_users'"; $db->setQuery($query); $Jomtableexists = $db->loadResult(); if (isset($Jomtableexists) && $auth_info['profile']['photo']) { jimport('joomla.filesystem.file'); jimport('joomla.utilities.utility'); require_once(JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'helpers'.DS.'image.php'); $fileName = JUtility::getHash( $auth_info['profile']['photo'] . time() ); $fileName = JString::substr( $fileName , 0 , 24 ); $avatarimage = 'images/avatar/' . $fileName.'.jpg' ; $thumbavatar = 'images/avatar/' . 'thumb_' . $fileName.'.jpg' ; $st = JPATH_ROOT; $jPath = split('\administrator',$st); $storage = $jPath[0] . DS . 'images' . DS . 'avatar'. DS . $fileName.'.jpg'; $storageThumbnail = $jPath[0] . DS .'images'.DS . 'avatar'. DS . 'thumb_' . $fileName.'.jpg' ; $destType = 'image/jpg'; $imageMaxWidth = 140; // Only resize when the width exceeds the max. if( !cImageResizePropotional( $auth_info['profile']['photo'] , $storage , $destType , $imageMaxWidth ) ) { global $option,$mainframe; $msg = JText::sprintf( 'Image Upload Error '); } // Generate thumbnail if(!cImageCreateThumb( $auth_info['profile']['photo'] , $storageThumbnail , $destType )) { global $option,$mainframe; $msg = JText::sprintf( 'Image Upload Error '); } $query = "SELECT `userid` FROM `#__community_users` WHERE `userid`='" . $user->get('id') . "'"; $db->setQuery( $query ); if($db->loadResult()) { $query = "UPDATE `#__community_users` SET `avatar` = '" . $avatarimage . "', `thumb` = '" .$thumbavatar . "' WHERE `userid`='" . $user->get('id') . "'"; } else { $query = "INSERT INTO `#__community_users` SET `userid`='" . $user->get('id') . "', `avatar` = '" . $avatarimage . "', `thumb` = '" .$thumbavatar . "'"; } $db->setQuery( $query ); $db->query(); } } // Get an ACL object $acl =& JFactory::getACL(); // Get the user group from the ACL if ($user->get('tmp_user') == 1) { $grp = new JObject; // This should be configurable at some point $grp->set('name', 'Registered'); } else { $grp = $acl->getAroGroup($user->get('id')); } //Mark the user as logged in $user->set( 'guest', 0 ); $user->set( 'aid', 1 ); // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) { $user->set('aid', 2); } //Set the usertype based on the ACL group name $user->set('usertype', $grp->name); // Register the needed session variables $session =& JFactory::getSession(); $session->set('user', $user); // Get the session object $table =& JTable::getInstance('session'); $table->load( $session->getId() ); $table->guest = $user->get('guest'); $table->username = $user->get('username'); $table->userid = intval($user->get('id')); $table->usertype = $user->get('usertype'); $table->gid = intval($user->get('gid')); $table->update(); // Hit the user last visit field $user->setLastVisit(); // redirect global $redirectUrl; $returnURL = $redirectUrl; $mainframe->redirect($returnURL); } ?>

I am looking at a way to adapt this code to work with kunena 1.6

Thanks for your responce

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #8 by Dalandau
Or do you know about a pretty community builder template?

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago #9 by sozzled
I don't know that much about Community Builder templates and I don't think it really matters. Let's just try to stay on one problem at a time.

So, let me see if I understand the situation.

Currently you have people who register with your website. OK, that's easy to understand.

These new people haven't written anything on the forum. OK, I understand that part, too.

So how or why would people want to look at their forum user profiles if they have not contributed anything to the forum? I think that's really the question that I'm trying to understand in my mind.

If someone has registered at your site, and they haven't (a) completed the registration procedure or (b) contributed anything to the forum, why are you concerned about their Kunena user profile? There won't be anything in their Kunena user profile to see, will there? Doesn't that seem to make logical sense to you?

Please Log in or Create an account to join the conversation.

More
13 years 3 months ago - 13 years 3 months ago #10 by Dalandau
No, I want their avatar to be stored so that when they post something on the forum their avatar will be there already. (inserted from their facebook linkdin google hotmail,... have a look at www.janrain.com/products/engage/social-login )



The module I have does it for Jomsocial an Community builder avatar and I want to upgrade the code to make it work with Kunena 1.6

Thanks
Last edit: 13 years 3 months ago by Dalandau.

Please Log in or Create an account to join the conversation.

Time to create page: 0.456 seconds