Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Change the URL of user profile

XstasyXstasy New
edited October 2014 in Vanilla 2.0 - 2.8

Hey guys! I'm embedding vanillaforums into a website, and we have our own user profile. Page is setup with SSO/jsconnect and users get logged in automatically. The thing is that I want to link the user links (viewable in comments, discussions, etc.) to our websites profile page instead of their vanillaforums user profile.

Havent found a easy way to do this yet, does anyone have any pointers?
Thanks, and best regards.

Comments

  • See this

    http://vanillaforums.org/profile.json/Xstasy

    You would have to redirect the profile link then best use client side scripting to get the forum profile data.

    grep is your friend.

  • x00x00 MVP
    edited October 2014

    Other useful stuff

    http://vanillaforums.org/profile.json/discussions/Xstasy
    http://vanillaforums.org/profile.json/comments/Xstasy

    Very important

    This data is not sanitized (especially discussion/comment Body) so don't treat as such. Strip tags or convert to html entities.

    grep is your friend.

  • XstasyXstasy New
    edited October 2014

    How would I redirect it when it's embedded? The same way it redirects to the dashboard maybe? Don't know if you fully understood my question. I want the user profile links generated by the forums to redirect to my website's internal profile. Not the data it self, even though it was nice to get those useful links, that way I would be able to implement some of that data into the internal profile.

  • x00x00 MVP
    edited October 2014

    Sorry yes i only answered part of your question.

    UserUrl is the function you need to to predefine.

    assuming the username are unique you could do something like so

    create a file conf/bootstrap.before.php put in it

    <?php if (!defined('APPLICATION')) exit();
    
    function UserUrl($User, $Px = '', $Method = '', $Get = FALSE){
        $UserName = GetValue('Name', $User);
        $Result = 'http://yoursite.com/profile/'.$UserName;
        if ($Get)
            $Result .= '?'.http_build_query($Get);
        return $Result;
    }
    

    You need to change the actual Url to suit your needs.

    grep is your friend.

  • XstasyXstasy New
    edited October 2014

    Thanks a bunch, exactly what I was looking for! Only problem is that it opens in a new window (target _blank). It should redirect the current page (not the embedded iframe).

  • That just set the url not the anchor. You might try pre-defining UserAnchor this is the current example

    if (!function_exists('UserAnchor')) {
       function UserAnchor($User, $CssClass = NULL, $Options = NULL) {
          static $NameUnique = NULL;
          if ($NameUnique === NULL)
             $NameUnique = C('Garden.Registration.NameUnique');
    
          if (is_array($CssClass)) {
             $Options = $CssClass;
             $CssClass = NULL;
          } elseif (is_string($Options))
             $Options = array('Px' => $Options);
    
          $Px = GetValue('Px', $Options, '');
    
          $Name = GetValue($Px.'Name', $User, T('Unknown'));
          $UserID = GetValue($Px.'UserID', $User, 0);
            $Text = GetValue('Text', $Options, htmlspecialchars($Name)); // Allow anchor text to be overridden.
    
          $Attributes = array(
              'class' => $CssClass,
              'rel' => GetValue('Rel', $Options)
              );
          $UserUrl = UserUrl($User,$Px);
          return '<a href="'.htmlspecialchars(Url($UserUrl)).'"'.Attribute($Attributes).'>'.$Text.'</a>';
       }
    }
    

    You wan to remove the Rel option. Homework: you try.

    grep is your friend.

  • Sorry I reviewed you question. The reason for new window, is it should not be in the iframe, it is part of the embed code. There is method to switch it back then force to break out of the iframe (which would be on your side). I don't have time now to do the groundwork for you.

    grep is your friend.

  • XstasyXstasy New
    edited October 2014

    Changed the
    return '<a href="'.htmlspecialchars(Url($UserUrl)).'"'.Attribute($Attributes).'>'.$Text.'</a>';

    into

    return '<a href="#"'.Attribute($Attributes).' onclick="parent.redirect(\''.$UserUrl.'\')">'.$Text.'</a>';

    And removed rel, probably not the best solution, but it works.

  • why not do this dynamically with jquery an detection?

    grep is your friend.

  • I realize this discussion is a bit old, but I though I'd share how I integrated SSO/jsconnect and external profiles.

    1) Implement jsConnect as detailed by: https://blog.vanillaforums.com/jsconnect-technical-documentation/
    2) In your applications sso authentication callback (authentication url), when constructing the JSON user resource, simply add an additional property 'Attributes' containing any user attributes you'd like stored in the Attributes column of User table.

        // GET AUTHENTICATED USER
        $authUser = ;
    
        // SETUP ROLES
        $roles[] = 'member';
        if ($authUser->isAdmin())
           $roles[] = 'administrator';
    
        if (!is_null($authUser)) {
           // CHANGE THESE LINES.
           $user['uniqueid'] = $authUser->id;
           $user['name'] = $authUser->username;
           $user['email'] = $authUser->email;
           $user['roles'] = implode(',', $roles);
           $user['photourl'] = $authUser->photoUrl;
    
           $user['Attributes'] = array(
              'fullname' => $authUser->fullname,
              'profileUrl' => $authUser->profileUrl,
           );
    

    3) Override the global UserUrl function in your plugin (we use 'profileUrl' attribute for our external profile URL. You can use whatever you wish.)

    if ( !function_exists('UserUrl')) {
       /**
        * Return the url for a user.
        * @param array|object $User The user to get the url for.
        * @param string $Px The prefix to apply before fieldnames. @since 2.1
        * @param string $Method Optional. ProfileController method to target.
        * @return string The url suitable to be passed into the Url() function.
        */
       function UserUrl($User, $Px = '', $Method = '', $Get = FALSE) {
          $UserModel = Gdn::UserModel();
          $Result = $UserModel->GetAttribute($User->UserID,'profileUrl', FALSE);
          return $Result;
       }
    }
    

    Note: If your site embeds Vanilla Forums, simply detect profile load inside frame and break out. (eg window.self !== window.top)
    Google it if you don't know how.

Sign In or Register to comment.