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 &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 . '&u=' . (int) $user_id : append_sid("{$p hpbb_root_path} memberlist.$php Ex", 'mode=viewprofi le&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]
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 &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 . '&u=' . (int) $user_id : append_sid("{$p hpbb_root_path} memberlist.$php Ex", 'mode=viewprofi le&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]
Comment