PHPBB3 get_username_string() function woes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RoxxorzIt
    New Member
    • Oct 2007
    • 2

    PHPBB3 get_username_string() function woes

    Alright, all I'm trying to do at the moment is display who posted a topic from a page entirely separate from PHPBB. The problem is, it seems no matter what I do, I just can't find a way to do so.

    Then, I heard about the get_username_st ring() function.

    Well, it won't work for me and I don't even know why...

    First of all, I have no idea what parameters need to be passed to it aside from the user_id of the account in question. Here's what I have written, if anyone could help me out I'd REALLY appreciate it, I've been stuck exactly right where I am for at least 15 hours...

    Here's my error:
    faultCode0fault StringFatal error:Call to a member function acl_get() on a non-object in /home/vol1/phpnet.us/g/gfgezpk/www/forums/includes/functions_conte nt.php on line 1119

    And here's my script:[code=php]
    <?php
    define('IN_PHPB B', true);
    include("forums/includes/functions_conte nt.php");

    $connection = mysql_connect(" *****", "*****", "*****");

    if (!$connection) {die ("An error has occured while attempting to access the MySQL database");}

    mysql_selectdb( '*****') or die(mysql_error ());

    $query = mysql_query("SE LECT * FROM `phpbb_posts`") ;

    while ($row = mysql_fetch_arr ay($query)) {
    $username;
    $user = get_username_st ring('username' , $row['poster_id'], $row['post_username']);
    echo "Posted by: " . $user;
    }
    mysql_close();
    ?>

    Also, here's the function:
    /**
    * Get username details for placing into templates.
    *
    * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour), full (for obtaining a html string representing a coloured link to the users profile) or no_profile (the same as full but forcing no profile link)
    * @param int $user_id The users id
    * @param string $username The users name
    * @param string $username_colou r The users colour
    * @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then.
    * @param string $custom_profile _url optional parameter to specify a profile url. The user id get appended to this url as &amp;u={user_id }
    *
    * @return string A string consisting of what is wanted based on $mode.
    */
    function get_username_st ring($mode, $user_id, $username, $username_colou r = '', $guest_username = false, $custom_profile _url = false)
    {
    global $phpbb_root_pat h, $phpEx, $user, $auth;

    $profile_url = '';
    $username_colou r = ($username_colo ur) ? '#' . $username_colou r : '';

    if ($guest_usernam e === false)
    {
    $username = ($username) ? $username : $user->lang['GUEST'];
    }
    else
    {
    $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest _username)) ? $guest_username : $user->lang['GUEST']);
    }

    // Only show the link if not anonymous
    if ($mode != 'no_profile' && $user_id && $user_id != ANONYMOUS)
    {
    // Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly).
    // For all others the link leads to a login page or the profile.
    if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_vie wprofile'))
    {
    $profile_url = '';
    }
    else
    {
    $profile_url = ($custom_profil e_url !== false) ? $custom_profile _url . '&amp;u=' . (int) $user_id : append_sid("{$p hpbb_root_path} memberlist.$php Ex", 'mode=viewprofi le&amp;u=' . (int) $user_id);
    }
    }
    else
    {
    $profile_url = '';
    }

    switch ($mode)
    {
    case 'profile':
    return $profile_url;
    break;

    case 'username':
    return $username;
    break;

    case 'colour':
    return $username_colou r;
    break;

    case 'no_profile':
    case 'full':
    default:

    $tpl = '';
    if (!$profile_url && !$username_colo ur)
    {
    $tpl = '{USERNAME}';
    }
    else if (!$profile_url && $username_colou r)
    {
    $tpl = '<span style="color: {USERNAME_COLOU R};" class="username-coloured">{USER NAME}</span>';
    }
    else if ($profile_url && !$username_colo ur)
    {
    $tpl = '<a href="{PROFILE_ URL}">{USERNAME }</a>';
    }
    else if ($profile_url && $username_colou r)
    {
    $tpl = '<a href="{PROFILE_ URL}" style="color: {USERNAME_COLOU R};" class="username-coloured">{USER NAME}</a>';
    }

    return str_replace(arr ay('{PROFILE_UR L}', '{USERNAME_COLO UR}', '{USERNAME}'), array($profile_ url, $username_colou r, $username), $tpl);
    break;
    }
    }[/code]
    Last edited by pbmods; Oct 28 '07, 01:35 PM. Reason: Added CODE tags.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, RoxxorzIt. Welcome to TSDN!

    Please use CODE tags when posting source code:

    &#91;CODE=ph p]
    PHP code goes here.
    &#91;/CODE]

    get_username_st ring() only works within phpbb (it requires the auth and session classes to be loaded).

    Your best bet is to write a separate query to retrieve this data.

    Comment

    • RoxxorzIt
      New Member
      • Oct 2007
      • 2

      #3
      Originally posted by pbmods
      Heya, RoxxorzIt. Welcome to TSDN!

      Please use CODE tags when posting source code:

      [CODE=php]
      PHP code goes here.
      [/CODE]

      get_username_st ring() only works within phpbb (it requires the auth and session classes to be loaded).

      Your best bet is to write a separate query to retrieve this data.
      Thanks for the tip and welcoming!

      I would like to write a separate query, but for some reason I get an error when attempting to include a variable received from any other query. It says it can't convert it to a string, but shouldn't it already be a string?

      Like if I write a query to compare a poster_id with a user_id, I'd try to first get the poster_id like:

      Code:
      mysql_query("SELECT * FROM `phpbb_posts` WHERE `forum_id` = 4 LIMIT 0,5");
      and pass the $row['poster_id'] variable to another query which says:

      Code:
      mysql_query("SELECT `username` FROM `phpbb_users` WHERE `user_id` = $row['poster_id']");

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, RoxxorzIt.

        Try this:
        [code=php]
        mysql_query("SE LECT `username` FROM `phpbb_users` WHERE `user_id` = '{$row['poster_id']}' LIMIT 1");
        [/code]

        Comment

        Working...