vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Converting username text to url (https://vborg.vbsupport.ru/showthread.php?t=219068)

DJ29Joesph 07-21-2009 04:00 AM

Converting username text to url
 
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.

PHP 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:
HTML Code:

<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:

PHP Code:

$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:

Code:

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

PHP Code:

($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
Anyway this is what I have so far.

Dropped into "bbcode_create"
PHP Code:

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

Dropped into "bbcode_fetch_tags"
PHP Code:

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

and this is the php file

EDIT*****
PHP Code:

<?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"

Quote:

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**********
Quote:


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-compliment...ile-link/4837/

Thanks anyway ;)


All times are GMT. The time now is 07:23 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01198 seconds
  • Memory Usage 1,787KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (14)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete