Joomla Forum

Joomla Hacks => Joomla-SMF 2.0.x => Topic started by: p9939068 on November 05, 2006, 02:18:27 AM



Title: Change SMF's user information through CB interface
Post by: p9939068 on November 05, 2006, 02:18:27 AM
I made this post on another thread, but lots of people are still asking for it on other threads, so i'm giving this it's own thread, at least until the original plugin does this.

To fully control SMF information (including signature that everyone wishes so much ;D) purely from CB, this is what you do:

go to com_comprofiler/plugin/user/plug_smfcbplugin/smf_cb.php (this is the SMF-CB plugin that comes with JSMF, not one of brat's plugins), go to the function updateUser and add these lines just above the "return true" at the last line of the function so that the whole function looks like this:
Code:
    function updateUser($data, $extras, $status)
    {
        global $_PLUGINS;
        global $jsmfConfig;
global $_POST, $database;
global $user;
        $jsmf = new jsmfFrontend();

        /*
        Row::id => 76
        Row::name => test
        Row::username => test
        Row::email => test@test.com
        Row::password =>
        Row::usertype => Registered
        Row::block => 0
        Row::sendEmail => 0
        Row::gid => 18
        Row::registerDate =>
        Row::lastvisitDate =>
        Row::activation =>
        Row::params =>
        Row::_tbl => #__users
        Row::_tbl_key => id
        Row::_error =>
        Row::_db => Object id #2
        Extras::id => 76
        Extras::user_id => 76
        Extras::avatar =>
        Extras::avatarapproved =>
        Extras::approved => 1
        Extras::confirmed => 1
        Extras::hits =>
        Extras::_tbl => #__comprofiler
        Extras::_tbl_key => id
        Extras::_error =>
        Extras::_db => Object id #2
        Extras::firstname =>
        Extras::middlename =>
        Extras::lastname =>
         */
         if (!$jsmf->updateMember($data, $extras)) {
            $_PLUGINS->raiseError(0);
            $_PLUGINS->_setErrorMSG("JSMF CB Plugin error::Failed to synchronize user updates to SMF:: ".$jsmf->err);
            return false;
         }

//Mike's hack
//Update smf_members with optional info like gender, MSN, website, location etc
$sql = "SELECT * FROM #__comprofiler WHERE `id` = '".$data->id."'";
$database->setQuery($sql);
$cbData = null;
$database->loadObject( $cbData );
if (!empty($cbData->cb_website)) {
$website = explode("|*|", $cbData->cb_website);
if (substr(htmlspecialchars($website[0], ENT_QUOTES),0,7) != "http://")
$websiteUrl .= "http://";
$websiteUrl .= htmlspecialchars($website[0], ENT_QUOTES);
$websiteTitle = ($website[1] != "") ? htmlspecialchars($website[1], ENT_QUOTES) : $websiteUrl;
}
        $uid = $jsmf->getSMFid($data->id, $data->username);

$query =
"UPDATE {$jsmfConfig->smf_prefix}members SET " .
"\n `personalText` = '".htmlspecialchars($cbData->cb_personaltext, ENT_QUOTES)."', " .
"\n `gender` = '".(($cbData->cb_gender == 'Male') ? '1' : '2')."', " .
"\n `birthdate` = '".$cbData->cb_birthdate."', " .
"\n `websiteTitle` = '".$websiteTitle."', " .
"\n `websiteUrl` = '".$websiteUrl."', " .
"\n `location` = '".htmlspecialchars($cbData->cb_location, ENT_QUOTES)."', " .
"\n `ICQ` = '".htmlspecialchars($cbData->cb_icq, ENT_QUOTES)."', " .
"\n `AIM` = '".htmlspecialchars($cbData->cb_aim, ENT_QUOTES)."', " .
"\n `YIM` = '".htmlspecialchars($cbData->cb_yim, ENT_QUOTES)."', " .
"\n `MSN` = '".htmlspecialchars($cbData->cb_msn, ENT_QUOTES)."', " .
"\n `signature` = '".htmlspecialchars($cbData->cb_signature, ENT_QUOTES)."', " .
"\n `usertitle` = '".htmlspecialchars($cbData->cb_usertitle, ENT_QUOTES)."' " .
"\n WHERE `ID_MEMBER` = '".$uid."'";
$database->setQuery($query);
if (!$database->query()) {
$jsmf->err = $database->getErrorMsg().' ~~~ FROM::'.__FILE__.' || '.__FUNCTION__.' || '.__LINE__;
return false;
}

         return true;
    }
Obviously, you will need to create these fields using CB's field manager: cb_personaltext, cb_gender, cb_birthdate, cb_website (note: cb_website must be of type "Web Address", and select "Hypertext and URL" at the bottom), cb_location, cb_icq, cb_aim, cb_yim, cb_msn, cb_signature, and cb_usertitle.

You should create these fields inside the "Forum Profile" tab created when you installed brat's forum profile plugin (or joomlahack's version of it). If don't see Forum Profile as a valid selection for Tab when you're creating the fields, this is what you need to do: go to your phpmyadmin (or whatever you use to edit mysql), go to jos_comprofiler_tabs, look for Forum Profile under title, and change the fields column to 1. (Note: for users who enable Nest Tabs under CB's configuration > User Profile, this will result in the Forum Profile tab appearing under the Profile tab!)

All the extra fields created should be UNrequired (to suit SMF's conditions), NOT shown in profile (since we're going to use brat's profile plugin to output the result), NOT required during registration (cus the way i hacked the plugin, it only works when users UPDATE their profile, NOT during registration), and of course Published.

Next, remember to go to JSMF's configuration and enable Redirect Profile Links so that SMF's profile will not be viewable through SMF itself.

I have also included an edited copy of brat's plugin's smf_profile.php and smf_profile.html.php (unzip first. it's not the full plugin) which you should probably replace the one you have now. All my edits were commented with "//Mike's hack" at the top so you can easily find where the changes were made.
 
What my hacks do is to hide the Forum Profile tab totally from users who are either not the owner or admin (I think this is sensible, but if you want forum profile to be viewable to everyone, simply edit a line that i've added. Search for the first "Mike's hack" in smf_profile.php), hide the forum profile and settings links from ALL non-admin (including profile owner), hide the "Sync avatar" button from ALL non-admin (including profile owner), re-position the avatar and Personal Text position, and show fields that are NOT empty only.

Remember to backup all files before doing anything! If you wish to change the layout, simply look for all the "Mike's hack"s. Some knowledge of php is required for that. If not, using the files "as is" will work too. This is a pretty "unelegant" hack (as my hacks mostly are ::)) since i use it for my own purpose only. Hope it helps :)

Regards, Mike


Title: Re: Change SMF's user information through CB interface
Post by: Bob Gordon on November 05, 2006, 05:28:24 PM
could u please give me a link to plug in - I can't find it

thx


Title: Re: Change SMF's user information through CB interface
Post by: p9939068 on November 06, 2006, 05:34:36 PM
could u please give me a link to plug in - I can't find it

thx
the smf-cb plugin comes together with the jsmf zip file which you're supposed to unzip first.

the smf-profile plugin can be found here: http://www.joomlahacks.com/component/option,com_smf/Itemid,94/topic,2554.0


Title: Re: Change SMF's user information through CB interface
Post by: james on November 08, 2006, 03:35:45 PM
Awesome! Just what I was looking for.

I replaced the 2 profile files with yours, but left some of the new fields visible on the profile which works great.

Thanks for the hack!


Title: Re: Change SMF's user information through CB interface
Post by: p9939068 on November 10, 2006, 01:28:30 PM
I just discovered that this hack will only work with smf_cb_plugin_2_0 found in the JSMF RC1 package. The change made in smf_cb_plugin_2_0_1 will trigger the hack before the profile is actually updated in CB, so the values remain unchanged. This means updating of SMF fields take precedence, whereas for the hack to work, updating CB fields must take precedence :)

Rgds, Mike


Title: Re: Change SMF's user information through CB interface
Post by: -Wolverine on November 10, 2006, 02:10:59 PM
in 2.0.1 the change was made because of the ability of a user to change their username via CB.  When they attempt to change their username in CB we try to correlate this change through several different methods and if they fail then we need to make sure CB fails.  Because if CB succeeds and SMF fails then there is no way to correlate the users going forward and they are viewed as separate users.  Basically you lose all SMF information for that user *and* a new SMF user is created for the new CB username. 

Very, very, very bad.  Suggested workaround is to disable the ability to change usernames.  Or use the plugin as it is distributed.


Title: Re: Change SMF's user information through CB interface
Post by: Denney on November 11, 2006, 08:43:56 AM
To fix this so it works with RC2, instead of using the above code, use this code:

Find:
Code:
$_PLUGINS->registerFunction( 'onBeforeUserUpdate', 'updateUser', 'jsmfCB');

Add After:
Code:
$_PLUGINS->registerFunction( 'onAfterUserUpdate', 'updateAfterUser', 'jsmfCB');

Find:
Code:
function updateUser($data, $extras, $status) {

Add After END OF FUNCTION!:
Code:
function updateAfterUser($data, $extras, $status) {
global $_PLUGINS;
        global $jsmfConfig;
        $jsmf = new jsmfFrontend();
        $jsmfConfig = $jsmf->loadParams();

//Mike's hack
//Update smf_members with optional info like gender, MSN, website, location etc
global $database, $user;
$sql = "SELECT * FROM #__comprofiler WHERE `id` = '".$data->id."'";
$database->setQuery($sql);
$cbData = null;
$database->loadObject( $cbData );
if (!empty($cbData->cb_website)) {
$website = explode("|*|", $cbData->cb_website);
if (substr(htmlspecialchars($website[0], ENT_QUOTES),0,7) != "http://")
$websiteUrl .= "http://";
$websiteUrl .= htmlspecialchars($website[0], ENT_QUOTES);
$websiteTitle = ($website[1] != "") ? htmlspecialchars($website[1], ENT_QUOTES) : $websiteUrl;
}
        $uid = $jsmf->getSMFid($data->id, $data->username);

$query =
"UPDATE {$jsmfConfig->smf_prefix}members SET " .
"\n `personalText` = '".htmlspecialchars($cbData->cb_personaltext, ENT_QUOTES)."', " .
"\n `gender` = '".(($cbData->cb_gender == 'Female') ? '2' : '1')."', " .
"\n `birthdate` = '".$cbData->cb_birthdate."', " .
"\n `websiteTitle` = '".$websiteTitle."', " .
"\n `websiteUrl` = '".$websiteUrl."', " .
"\n `location` = '".htmlspecialchars($cbData->cb_location, ENT_QUOTES)."', " .
"\n `ICQ` = '".htmlspecialchars($cbData->cb_icq, ENT_QUOTES)."', " .
"\n `AIM` = '".htmlspecialchars($cbData->cb_aim, ENT_QUOTES)."', " .
"\n `YIM` = '".htmlspecialchars($cbData->cb_yim, ENT_QUOTES)."', " .
"\n `MSN` = '".htmlspecialchars($cbData->cb_msn, ENT_QUOTES)."', " .
"\n `signature` = '".htmlspecialchars($cbData->cb_signature, ENT_QUOTES)."', " .
"\n `usertitle` = '".htmlspecialchars($cbData->cb_usertitle, ENT_QUOTES)."' " .
"\n WHERE `ID_MEMBER` = '".$uid."'";
$database->setQuery($query);

if (!$database->query()) {
$jsmf->err = $database->getErrorMsg().' ~~~ FROM::'.__FILE__.' || '.__FUNCTION__.' || '.__LINE__;
return false;
}

return true;
}


Title: Re: Change SMF's user information through CB interface
Post by: p9939068 on November 11, 2006, 11:02:16 AM
Wow, thanks! I think i just got a much clearer picture of how CB plugins work :P

Anyway, i just added a new parameter to allow users to hide their email in their smf profile. Create another CB field cb_hideemail (radio button: Yes/No), and use the following function inside smf_cb.php
Code:
/**
* Update smf_members with optional info (field names below):
* personalText, gender, birthdate, websiteTitle, websiteUrl,
* location, hideEmail, ICQ, AIM, YIM, MSN,
* signature, and usertitle
*/
function updateAfterUser($data, $extras, $status) {
        global $_PLUGINS;
        global $jsmfConfig;
global $_POST, $database;
        $jsmf = new jsmfFrontend();
        $jsmfConfig = $jsmf->loadParams();
$sql = "SELECT * FROM #__comprofiler WHERE `id` = '".$data->id."'";
$database->setQuery($sql);
$cbData = null;
$database->loadObject( $cbData );
//Get webpage values
if (!empty($cbData->cb_website)) {
$website = explode("|*|", $cbData->cb_website);
if (substr(htmlspecialchars($website[0], ENT_QUOTES),0,7) != "http://")
$websiteUrl .= "http://";
$websiteUrl .= htmlspecialchars($website[0], ENT_QUOTES);
$websiteTitle = ($website[1] != "") ? htmlspecialchars($website[1], ENT_QUOTES) : $websiteUrl;
}
//Get hideEmail value
if ($cbData->cb_hideemail == "Yes")
$hideEmail = '1';
else
$hideEmail = '0';

        $uid = $jsmf->getSMFid($data->id, $data->username);

$query =
"UPDATE {$jsmfConfig->smf_prefix}members SET " .
"\n `personalText` = '".htmlspecialchars($cbData->cb_personaltext, ENT_QUOTES)."', " .
"\n `gender` = '".(($cbData->cb_gender == 'Male') ? '1' : '2')."', " .
"\n `birthdate` = '".$cbData->cb_birthdate."', " .
"\n `websiteTitle` = '".$websiteTitle."', " .
"\n `websiteUrl` = '".$websiteUrl."', " .
"\n `location` = '".htmlspecialchars($cbData->cb_location, ENT_QUOTES)."', " .
"\n `hideEmail` = '".$hideEmail."', " .
"\n `ICQ` = '".htmlspecialchars($cbData->cb_icq, ENT_QUOTES)."', " .
"\n `AIM` = '".htmlspecialchars($cbData->cb_aim, ENT_QUOTES)."', " .
"\n `YIM` = '".htmlspecialchars($cbData->cb_yim, ENT_QUOTES)."', " .
"\n `MSN` = '".htmlspecialchars($cbData->cb_msn, ENT_QUOTES)."', " .
"\n `signature` = '".htmlspecialchars($cbData->cb_signature, ENT_QUOTES)."', " .
"\n `usertitle` = '".htmlspecialchars($cbData->cb_usertitle, ENT_QUOTES)."' " .
"\n WHERE `ID_MEMBER` = '".$uid."'";
$database->setQuery($query);
if (!$database->query()) {
$jsmf->err = $database->getErrorMsg().' ~~~ FROM::'.__FILE__.' || '.__FUNCTION__.' || '.__LINE__;
return false;
}
}

Rgds, Mike


Title: Re: Change SMF's user information through CB interface
Post by: asteroidjay on December 02, 2006, 10:30:11 AM
This works great for me. For RC3, it's necessary to add the
Code:
$_PLUGINS->registerFunction( 'onBeforeUserUpdate', 'updateUser', 'jsmfCB');
as well.

I really hope this hack isn't abandoned in further releases, because it's the only thing that works for me. :(


Title: Re: Change SMF's user information through CB interface
Post by: Jordan on January 05, 2007, 11:57:04 AM
wait, where to post that line??

Ok, so wait, does this work on CB 1.0.2, JSMF 2.0 Final, smf_cb_plugin 2.0.1?


Title: Re: Change SMF's user information through CB interface
Post by: Jordan on January 08, 2007, 05:42:49 AM
Bump  :-[


Title: Re: Change SMF's user information through CB interface
Post by: Gordon on February 05, 2007, 07:17:46 AM
@ p9939068

You are a god. Thanks a alot.

Know the smf is 90% perfect for joomla.

On thing is missing.

I´m an old xoopser. And in the xoops newbb boards is the funktion to show all the polls in the normal poll modul.

I have found the ajax modul at your site. But this shows only one poll. I would like to integrate the polls in the poll component of joomla.

Do you know a way to realize this?

Thanks for this perfect mad, that what I searched a long time for.

best regards


Title: Re: Change SMF's user information through CB interface
Post by: sm8417 on February 06, 2007, 02:12:06 PM
This works like a charm... even with the current release of the bridge. I have one question though. How would one modify it so that it would update upon new user signup?

-sm8417


Title: Re: Change SMF's user information through CB interface
Post by: fabs on February 14, 2007, 01:40:07 AM
for some reason the hide email hack does not really accomplish to hide entirely as the email button is still shown in posts on the forum. is it supposed to be like that?


Title: Re: Change SMF's user information through CB interface
Post by: -Wolverine on February 14, 2007, 12:56:18 PM
hide_email only controls the visibility of your email address when viewing a user's profile in SMF.  A separate configuration is used to allow board members to email you, which is more than likely the email button you are seeing.


Title: Re: Change SMF's user information through CB interface
Post by: Peter on February 16, 2007, 07:15:00 AM
Sorry,

I find these instructions too cryptic.

p9939068 & Denney...Your alterations - The examples you put to locate in CB file, they are different in my own.

Does this work with the latest version of JSMF?  I'd appreciate if it does, if you could attach the modified file so I can compate.

Thanks for the instructions though...I'd love to get this working.

P.


Title: Re: Change SMF's user information through CB interface
Post by: herbsie on February 20, 2007, 04:29:24 AM
Excuse me for being a bit dumb, but should the signature be a text field?  When I do this it only displays the url and not the sig?

thanks


Title: Re: Change SMF's user information through CB interface
Post by: herbsie on February 20, 2007, 02:21:35 PM
Ok seem to of fixed that.

The Forum Profile tab is not listed in drop down menu when creating a new field, only contact info,additional info and online status.

Any ideas guys?

thanks


EDIT: Found the problem,  needed to change a line in smf_profile.xml (before installing),

from this:
Code:
<tab name="Forum Profile" description="" class="getSMFProfileTab" fields="1" position="cb_tabmain" displaytype="tab">

to this:
Code:
<tab name="Forum Profile" description="" class="getSMFProfileTab" fields="0" position="cb_tabmain" displaytype="tab">

So the Forum Profile tab is shown when creating a new cb field.


Title: Re: Change SMF's user information through CB interface
Post by: Ryan on April 12, 2007, 03:15:50 PM
Just kinda of trying to help lol but line 332 is where you want to put this correct? and why not accauly make the file and distrubute to make a bit eaiser i think i will do it once i get it working


Title: Re: Change SMF's user information through CB interface
Post by: Ryan on April 19, 2007, 08:32:25 PM
Ok i NEED to know will this work with 1.0.2 CB? becasue that is what im using and honestly ive put alot of work in to the site and i really dont want to have to do the people's sig input for them that would just SUX

CB= 1.0.2
CB_SMF_plug= 2.0.3
SMF= 1.1.2
Joomla= newest one
Website: WWW.LOSCLAN.COM
AIM: IG88L0S
MSN: Ryan_Griffeth@Charter.net
Yahoo: IG88L0S


Title: Re: Change SMF's user information through CB interface
Post by: asteroidjay on April 20, 2007, 09:06:18 AM
Here's the modified smf_cb.php that works for me. (2.0.2)

To get the forum tab to show up in your Field drop down menu, go into your MySQL database and go to jos_comprofiler_tabs and find "Forum Profile" and change the "fields" table from 0 to 1.


Title: Re: Change SMF's user information through CB interface
Post by: RJ on April 20, 2007, 03:34:18 PM
I may have missed this bit.... however- does anyone know what/where Brat's plugin is that Mike is speaking of in his beginning post?


Title: Re: Change SMF's user information through CB interface
Post by: Ryan on April 20, 2007, 06:26:51 PM
Alright much thanks im getting stoked im in to the socom community and we are the first to use joomla i think this will put us above the rest as having a well orginized user interface to bad that you know the people on your site most will never understand the flustrations of making one


Title: Re: Change SMF's user information through CB interface
Post by: Berkant Akarcan on September 29, 2007, 06:11:39 PM
Thanks for the hack, but I've got a problem with it.

I add the code to my smf_cb.php file as described (everything's correct). But when a member tries to update his profile, this error message appears:

Code:
Fatal error: Call to a member function on a non-object in /public_html/components/com_comprofiler/plugin/user/plug_smfcbplugin/smf_cb.php on line 668

And this is what I got on the line 668:

Code:
$database->setQuery($sql);

So, how can I fix this problem?

Thanks.

Versions of things on my site
CB = 1.1
SMF = 1.1.2
JSMF = 2.0.2
Joomla = 1.0.13


Title: Re: Change SMF's user information through CB interface
Post by: YT! on March 09, 2008, 11:45:42 AM
After i have sync all tables from CB to SMF
i have  311 queries executed

This one reapet all the time
SELECT memberName FROM smf_members WHERE ID_MEMBER = '0' LIMIT 1

What i have to do?


Joomla Forum | Powered by SMF 1.1 RC1.
© 2001-2005, Lewis Media. All Rights Reserved.
Joomla Bridge by JoomlaHacks.com