473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHPBB3 get_username_string() function woes

2 New Member
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_string() 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:
faultCode0faultStringFatal error:Call to a member function acl_get() on a non-object in /home/vol1/phpnet.us/g/gfgezpk/www/forums/includes/functions_content.php on line 1119

And here's my script:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. define('IN_PHPBB', true);
  3. include("forums/includes/functions_content.php");
  4.  
  5. $connection = mysql_connect("*****", "*****", "*****");
  6.  
  7. if (!$connection) {die ("An error has occured while attempting to access the MySQL database");}
  8.  
  9. mysql_selectdb('*****') or die(mysql_error());
  10.  
  11. $query = mysql_query("SELECT * FROM `phpbb_posts`");
  12.  
  13. while ($row = mysql_fetch_array($query)) {
  14.     $username;
  15.     $user = get_username_string('username', $row['poster_id'], $row['post_username']);
  16.     echo "Posted by: " . $user;
  17. }
  18. mysql_close();
  19. ?>
  20.  
  21. Also, here's the function:
  22. /**
  23. * Get username details for placing into templates.
  24. *
  25. * @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)
  26. * @param int $user_id The users id
  27. * @param string $username The users name
  28. * @param string $username_colour The users colour
  29. * @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then.
  30. * @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}
  31. *
  32. * @return string A string consisting of what is wanted based on $mode.
  33. */
  34. function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false)
  35. {
  36.     global $phpbb_root_path, $phpEx, $user, $auth;
  37.  
  38.     $profile_url = '';
  39.     $username_colour = ($username_colour) ? '#' . $username_colour : '';
  40.  
  41.     if ($guest_username === false)
  42.     {
  43.         $username = ($username) ? $username : $user->lang['GUEST'];
  44.     }
  45.     else
  46.     {
  47.         $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']);
  48.     }
  49.  
  50.     // Only show the link if not anonymous
  51.     if ($mode != 'no_profile' && $user_id && $user_id != ANONYMOUS)
  52.     {
  53.         // Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly).
  54.         // For all others the link leads to a login page or the profile.
  55.         if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
  56.         {
  57.             $profile_url = '';
  58.         }
  59.         else
  60.         {
  61.             $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&amp;u=' . (int) $user_id : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . (int) $user_id);
  62.         }
  63.     }
  64.     else
  65.     {
  66.         $profile_url = '';
  67.     }
  68.  
  69.     switch ($mode)
  70.     {
  71.         case 'profile':
  72.             return $profile_url;
  73.         break;
  74.  
  75.         case 'username':
  76.             return $username;
  77.         break;
  78.  
  79.         case 'colour':
  80.             return $username_colour;
  81.         break;
  82.  
  83.         case 'no_profile':
  84.         case 'full':
  85.         default:
  86.  
  87.             $tpl = '';
  88.             if (!$profile_url && !$username_colour)
  89.             {
  90.                 $tpl = '{USERNAME}';
  91.             }
  92.             else if (!$profile_url && $username_colour)
  93.             {
  94.                 $tpl = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
  95.             }
  96.             else if ($profile_url && !$username_colour)
  97.             {
  98.                 $tpl = '<a href="{PROFILE_URL}">{USERNAME}</a>';
  99.             }
  100.             else if ($profile_url && $username_colour)
  101.             {
  102.                 $tpl = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
  103.             }
  104.  
  105.             return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl);
  106.         break;
  107.     }
  108. }
Oct 28 '07 #1
3 8094
pbmods
5,821 Recognized Expert Expert
Heya, RoxxorzIt. Welcome to TSDN!

Please use CODE tags when posting source code:

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

get_username_string() 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.
Oct 28 '07 #2
RoxxorzIt
2 New Member
Heya, RoxxorzIt. Welcome to TSDN!

Please use CODE tags when posting source code:

Expand|Select|Wrap|Line Numbers
  1. PHP code goes here.
  2.  
get_username_string() 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:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. mysql_query("SELECT `username` FROM `phpbb_users` WHERE `user_id` = $row['poster_id']");
Oct 29 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, RoxxorzIt.

Try this:
Expand|Select|Wrap|Line Numbers
  1. mysql_query("SELECT `username` FROM `phpbb_users` WHERE `user_id` = '{$row['poster_id']}' LIMIT 1");
  2.  
Oct 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1705
by: Mark | last post by:
O, woe is me, to have seen what I have seen, see what I see! (That's Shakespeare for those who were wondering what I'm on about) I am "having fun" with cookies. And I wonder if I have...
0
1501
by: Cedric | last post by:
This is a 3 weeks old problem, but having found a solution (and having looked for one here, finding only this message), I'm replying now. From: Jive (someone@microsoft.com) Subject: Upgrade...
3
3439
by: Angel Cat | last post by:
Trying to get my jobs to send mail when job fails. Should be easy but it's giving me headache Had a whole slew of issues. Outlook is installed with a n outlook mail profile set up that can...
2
1818
by: Andrew Thompson | last post by:
- NN 4.78 rendering woes, links at far left - I am trying to rework an old site, make it valid html and css, improving the x-browser and 'older browser' compatibility. My efforts so far, have...
15
3461
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here...
1
1125
by: DennyLoi | last post by:
Hi Everyone, I have a problem with my javascript code. I am trying to pass a parameter to the checkAnswer function during using the onClick event handler. I wrote the following lines of code:...
0
1944
by: emalcolm_FLA | last post by:
Hello and TIA for your consideration. I have created several db's for a non-profit and they want custom navigation buttons to display "You are on the first record, last record, etc". With this...
3
1517
by: willo | last post by:
Greetings all, I have run into a small problem with my understanding of some C++ language syntax, and seek some clarification. Below is a condensed version of some code I'm having difficulty...
0
1160
by: daemonsvk | last post by:
Hi, I have an c# app and I want the app to connect to the phpbb3 forum, login in, and download the list of topics. And here's my problem, I tried to connect to the forum with HttpWebRequest....
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.