PDA

View Full Version : Converting username text to url


DJ29Joesph
07-21-2009, 04:00 AM
I created a function I was wondering if I could have someone look it over. It pretty much takes the text in a post and looks for a username, and if there is one, it will mark it up as url and usergroup color. Anyway heres the code.


function convert_username_to_url($text1)
{
global $vbulletin;

if ($vbulletin->$bbuserinfo[userid] > 0)
{
$userSearchQuery = $vbulletin->db->query_read("
SELECT userid, usergroupid, displaygroupid, username
FROM' . TABLE_PREFIX . 'user
");

While ($customuser = $vbulletin->db->fetch_array($userSearchQuery))
{
fetch_musername($customuser);
$userSearch = array($customuser[username]);
$userReplace = '<a href="member.php?' . $vbulletin->session->vars['sessionurl'] . "u=$customuser[userid]\">$customuser[musername]</a>";
}

}
$text = str_replace($userSearch, $userReplace, $text1);

return $text;
}


Again if you could take a look that would be awesome. I know html, I'm trying to learn php. Thanks

Dismounted
07-21-2009, 07:21 AM
That will potentially fail miserably on a forum with a lot of users. There is really no practical way to do this on a large scale.

DJ29Joesph
07-21-2009, 03:55 PM
Is there anyway to do this by using a bbcode?

Lynne
07-21-2009, 04:04 PM
You could create bbcode for your users to use:

<a href="/forums/member.php?username={param}">{param}</a>

DJ29Joesph
07-21-2009, 05:38 PM
Also any chance that would be able to mark it up to the usergroup color? :)

Lynne
07-21-2009, 06:48 PM
What I wrote is just a simple bbcode to do the username. If you want the usergroup color, you'd have to write some actual code to get it.

DJ29Joesph
07-21-2009, 06:53 PM
just one more question.... to do the color, the code I would create, would I put the code in the replacement box or would I have to create a function or hook? I know you can only use html in the replacement box so I guess I couldn't use any variables correct?

Sorry im a noob. I just don't know how the whole bbcode replacement box works for vbulletin.

Lynne
07-21-2009, 07:01 PM
You would have to write a plugin, I believe. I've never done anything with the bbcode, so I'm not exactly sure how you would go about it. I've seen threads here about it though, so just do a search and you should find some info.

DJ29Joesph
07-21-2009, 08:26 PM
Please tell me I'm close:


$custom_bbcode = 'user';

$this->tag_list['no_option'][$user_bbcode] = array ();
$this->tag_list['no_option'][$user_bbcode]['callback'] = 'handle_external';
$this->tag_list['no_option'][$user_bbcode]['external_callback'] = 'handle_my_user_bbcode';

if (!function_exists ('handle_my_user_bbcode')) {
function handle_my_user_bbcode (&$theobj, &$value, &$option) {

$fetchuser = $db->query("
SELECT userid, usergroupid, displaygroupid
FROM " . TABLE_PREFIX . "user
WHERE username = $value
");
$name = array();
while ($user = $db->fetch_array($fetchuser))
{
fetch_musername($user);
$name = '<a href="member.php?' . $vbulletin->session->vars['sessionurl'] . "u=$user[userid]\">$user[musername]</a>";

return $name;
}
}


:)

Keep getting this in my shoutbox:


Parse error: parse error, unexpected $end in W:\Forums\includes\class_bbcode.php(360) : eval()'d code on line 33

Parse error: parse error, unexpected $end in W:\Forums\includes\class_bbcode.php(360) : eval()'d code on line 33

Parse error: parse error, unexpected $end in W:\Forums\includes\class_bbcode.php(360) : eval()'d code on line 33


line 360 and down


($hook = vBulletinHook::fetch_hook('bbcode_parse_start')) ? eval($hook) : false;

if (!empty($parsedtext))
{
if ($parsedhasimages)
{
return $this->handle_bbcode_img($parsedtext, $dobbimagecode, $parsedhasimages);
}
else
{
return $parsedtext;
}
}
else
{
return $this->do_parse($text, $dohtml, $dosmilies, $dobbcode, $dobbimagecode, $donl2br, $cachable);
}

Lynne
07-22-2009, 01:55 AM
I don't know if it's correct or not, but I do see that you have three beginning and two end parenthesis in the first code box you posted and that will cause an error (they don't add up correctly).

Dismounted
07-22-2009, 06:58 AM
There are a couple of other threads talking about implementing BB codes via PHP - I have previously posted in them with examples.

DJ29Joesph
07-22-2009, 09:56 PM
Dismounted I saw some of your post like you said including this (https://vborg.vbsupport.ru/showthread.php?t=202582)
Anyway this is what I have so far.

Dropped into "bbcode_create"

require_once(DIR . '/includes/bbcode_user.php');


Dropped into "bbcode_fetch_tags"

$tag_list['no_option'][user] = array(
'callback' => 'handle_external',
'strip_empty' => true,
'external_callback' => 'bbcode_user'
);


and this is the php file

EDIT*****

<?php
require_once('./global.php');
require_once(DIR . '/includes/class_bbcode.php');
require_once(DIR . '/includes/functions_user.php');
function bbcode_user(&$parser, $value)
{
$fetchuser = $db->query('
SELECT displaygroupid, username, userid
FROM ' . TABLE_PREFIX . 'user
WHERE username = '$value'
');

if ($user = $db->fetch_array($fetchuser))
{
fetch_musername($user);
$name = '<a href="member.php?' . $vbulletin->session->vars['sessionurl'] . "u=$user[userid]\">$user[musername]</a>";
return $name;
}
}
?>


I am getting error when I click "BB code Manager"


Fatal error: Call to a member function clean_array_gpc() on a non-object in *****\www\Forums\global.php on line 22


and I get this when I use the bbcode in a post:
EDIT**********


Parse error: parse error, unexpected T_VARIABLE in ****\www\Forums\includes\bbcode_user.php on line 10

Any help would be awesome!

Dismounted
07-23-2009, 06:06 AM
Remember that you are in function scope, and therefore, variables such as $vbulletin and $db will not exist - unless allowed to exist through the global keyword. Also, you may want to use query_first(), which will automatically fetch the first result and place it is an associative array.

DJ29Joesph
07-23-2009, 04:53 PM
Nevermind

http://vbenhancer.com/vbe-complimentaries/user-musername-profile-link/4837/

Thanks anyway ;)