Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2009, 04:00 AM
DJ29Joesph DJ29Joesph is offline
 
Join Date: Jan 2009
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 07-21-2009, 07:21 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 07-21-2009, 03:55 PM
DJ29Joesph DJ29Joesph is offline
 
Join Date: Jan 2009
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there anyway to do this by using a bbcode?
Reply With Quote
  #4  
Old 07-21-2009, 04:04 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could create bbcode for your users to use:
HTML Code:
<a href="/forums/member.php?username={param}">{param}</a>
Reply With Quote
  #5  
Old 07-21-2009, 05:38 PM
DJ29Joesph DJ29Joesph is offline
 
Join Date: Jan 2009
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Also any chance that would be able to mark it up to the usergroup color?
Reply With Quote
  #6  
Old 07-21-2009, 06:48 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 07-21-2009, 06:53 PM
DJ29Joesph DJ29Joesph is offline
 
Join Date: Jan 2009
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 07-21-2009, 07:01 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 07-21-2009, 08:26 PM
DJ29Joesph DJ29Joesph is offline
 
Join Date: Jan 2009
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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);
        } 
Reply With Quote
  #10  
Old 07-22-2009, 01:55 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04124 seconds
  • Memory Usage 2,273KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_html
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete