Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > General Articles
Learn to HELP YOURSELF
rake's Avatar
rake
Join Date: Nov 2002
Posts: 311

 

Show Printable Version Email this Page Subscription
rake rake is offline 09-01-2004, 10:00 PM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
LEARN to HELP YOURSELF
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


I decided to write this after observing the types of questions asked in the General Modification Discussion and PHP/MySQL/JS/HTML forums. If people would know a few simple things, i'm sure the number of questions would be reduced by at least 40-50%.

First of all, they need to know that asking on a forum is NOT an efficient way of getting an aswer, and by no means a fast one. It could be days before a member will give you the right solution to your problem. Secondly, you waste BOTH YOUR TIME, and the TIME OF OTHER MEMBERS.

With that in mind, the best way to find an answer is to search for it yourself...

Golden Rule 1: Use Forum Search - i know this has been said over and over, but i just felt the need to repeat it
Golden Rule 2: Use Google


1. EditPlus2 - It's a program. What special about it is the "Find in Files" feature. It will search for a string in multiple files. Use google to find it. I'll give an example of using this later.

2. When you need to find a certain template, keep in mind there's a vBulletin option which will add the names of templates in HTML comments in the HTML source of the page. Turn it on, refresh your vBulletin page, right click on the page > View Source, and then you can just read the name of your template. Also, don't forget there is a search in templates function within vBulletin.

3. If something is wrong in your code, DEBUG, and then post for help. Let's take an example for this. Let's say you have an if statement, which sets a variable to true/false, and based on this you want to allow a user access to a page or not - and it's just not working...

PHP Code:
if($something == 'x')
{
    
$myvar TRUE;
}
else
{
    
$myvar FALSE;
}

if(
$myvar == FALSE)
{
    
print_no_permission();

Let's say you KNOW the variable should be FALSE, but for some reason it's true... First thing to do, is to check the value of the variable: After the first if, add the following code: echo $myvar; exit; This simple echo-ing method can be used in most cases. I've seen at least 3-4 questions like this in the past couple of days.

4. If something isn't working, and you just can't figure out why, try using alternate methods of getting the same effect.

5. If you need help with a certain php function, don't ask on the forums. I recommend downloading the php manual in Windows Help Format (chm) from php.net. It's very useful as a function reference. If you don't want to download it - again, use google.

6 If you want to find a function that does something, use the manual. Let's say you want to find a function that converts a string to uppercase. You open the manual, click the Search tab, and search for uppercase. There'll be a few items on the list, but the 4th one is what you're looking for: strtoupper.

7. Similarly, if you need to know what a vBulletin function does, first thing to do is to look at it's name, which will in most cases give a pretty big hint on what the function is supposed to do. Look if there are any comments on that function in the code, and finally, try looking the code and figuring out what it's supposed to do.

8. If you want to find a vbulletin function, EditPlus is your friend. Use Find in Files, and you'll have your function.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PRACTICAL EXAMPLE OF USING THE ABOVE TIPS
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

What we want

As an example of using the above tips, i'll use this thread: How do I: Have Links From a Specific Domain Open in Same Window

What we're trying to do is have links (in posts) from certain domains open in the same window. By default, vbulletin opens a new window for all links.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

How We do it

First, let's open EditPlus, Search > Find In Files. We'll want to search in our forum folder, for files of type *.*, and the string we'll search for is [url since we know that is the bbcode tag used to generate html links.

There's be some results, but you can quickly see which are the important ones. In includes/functions_bbcodeparse.php there'll be some regular expressions to match the [url tag, and some very useful comments ( // [URL] ). Now you know you've found what you were searching for. Go to that page.

PHP Code:
        // [URL]
        
$bbcodes['standard']['find']['[url]'] = '#\[url\](.*)\[/url\]#esiU';
        
$bbcodes['standard']['replace']['[url]'] = "handle_bbcode_url('\\1', '', 'url')";
        
$bbcodes['standard']['recurse']['url'][0] = array('handler' => 'handle_bbcode_url');
        
// [URL=XXX]
        
$bbcodes['standard']['find']['[url='] = '#\[url=("|"|\'|)(.*)\\1\](.*)\[/url\]#esiU';
        
$bbcodes['standard']['replace']['[url='] = "handle_bbcode_url('\\3', '\\2', 'url')";
        
$bbcodes['standard']['recurse']['url'][1] = array('handler' => 'handle_bbcode_url'); 
By taking a look at the above code, the first thing your eyes should fall on is the "handle_bbcode_url" function...

Use the find in files function again, to see where that function is... Well, what do you know? It's also in the functions_bbcodeparse file. You won't need to examine the entire function to find what's essential, since it's easy to spot:

PHP Code:
        // standard URL hyperlink
        
return "<a href=\"$rightlink\" target=\"_blank\">$text</a>"
Now you know this is where you have to hack the function. So what you want to do is to see if $rightlink contains the domain you want, mydomain.com, so you open the php manual and take a look at string functions... voila!
Quote:
string stristr ( string haystack, string needle)


Returns all of haystack from the first occurrence of needle to the end. needle and haystack are examined in a case-insensitive manner.

If needle is not found, returns FALSE.
So you transform the portion of code you found into this:

PHP Code:
        if(stristr($rightlink,"domain.com"))
        {
            
// standard URL hyperlink
            
return "<a href=\"$rightlink\" target=\"_self\">$text</a>";
        }
        else
        {
            
// standard URL hyperlink
            
return "<a href=\"$rightlink\" target=\"_blank\">$text</a>";
        } 
So, we check if rightlink contains domain.com, and if it does, we change the target="_blank" portion, with target="self" so the link will be opened in the same window.

So what if we want to do the above for more domains? Here's a demonstration of point 4, alternate methods of doing the same thing...

PHP Code:
        if(stristr($rightlink,"domain.com"))
        {
            
// standard URL hyperlink
            
return "<a href=\"$rightlink\" target=\"_self\">$text</a>";
        }
        elseif(
stristr($rightlink,"seconddomain.com"))
        {
            
// standard URL hyperlink
            
return "<a href=\"$rightlink\" target=\"_self\">$text</a>";
        }
        else
        {
            
// standard URL hyperlink
            
return "<a href=\"$rightlink\" target=\"_blank\">$text</a>";
        } 

PHP Code:
    $domains = array( 
            
'domain.com'
            
'seconddomain.com' 
        
); 

        foreach(
$domains as $domain
        { 
            if(
stristr($rightlink,$domain)) 
            { 
                
// standard URL hyperlink 
                
return "<a href=\"$rightlink\" target=\"_self\">$text</a>"
            } 
            else 
            { 
                
// standard URL hyperlink 
                
return "<a href=\"$rightlink\" target=\"_blank\">$text</a>"
            } 
        } 
To make it easier and less repetitive, we made an array of domains, and then looped through them to compare each of them to $rightlink.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

That's it! It's a lot easier than it seems, believe me. Then again, i'm not that good at explaining things. I hope this helps some of you.

Rake.
Reply With Quote
  #2  
Old 09-02-2004, 12:13 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Some great stuff but to test for a needle in a haystack use strpos
Reply With Quote
  #3  
Old 09-02-2004, 02:04 PM
Infopro Infopro is offline
 
Join Date: May 2003
Location: Pennsylvania
Posts: 267
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good job.
Reply With Quote
  #4  
Old 09-02-2004, 02:09 PM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice work rake. Good posts like that take time.
Reply With Quote
  #5  
Old 09-02-2004, 05:31 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

definitelly a good one!
Reply With Quote
  #6  
Old 09-03-2004, 05:39 AM
deathemperor's Avatar
deathemperor deathemperor is offline
 
Join Date: Jul 2003
Location: HOL
Posts: 1,270
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

very very useful.

Thanks Rake !

the only thing I've done before time was download all links at http://php.net/manual/en ^^. This helped me make my first modification myself and understand vbulletin things.
Reply With Quote
  #7  
Old 09-06-2004, 09:07 PM
zetetic's Avatar
zetetic zetetic is offline
 
Join Date: Apr 2004
Posts: 338
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, rake. #2 is particularly helpful; I had no idea that was there. :up:
Reply With Quote
  #8  
Old 09-08-2004, 04:34 PM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would also add that a common problem when asking questions is that the explanation/question is often too brief, as if the questioner has less time that the people reading the post.

In general, if I read a question-style post that is a couple of vague sentences, I will just ignore it. I do not think I am alone in this behaviour. If one can not take the 15 or 20 minutes to enter a decent post with as much information as is reasonably possible, then one should not expect a reply.

Here are some of the problems with question/request/problem posts:

#1 -- Explain what you are trying to do
Take the time to start your post with an explanation of what you are trying to do. After you have done that, move on to describing the problem.

#2 -- Be as specific as possible
Often, it is difficult to tell if one is referring to a PHP script, a template, or some HTTP/browser issue. Be specific about what objects you are working with.

#3 -- Attach or enter problem output
Now really, what good is it to say "I don't get the right XXX" when I try YYY. Show us the XXX you do get. Attach a screenshot if that is showing the problem. Include the code that is not working if that is applicable. Show the output of the database error. ... you get the idea.

#4 -- Hack requests as implementation questions
Do not pose a request for a hack as an implementation question. Instead of asking "How can I change the XXX to include the YYY as well.", explain the purpose of the hack. There might be a more proper or elegant solution if you posed the request in terms of what you want to accomplish rather than in terms of what you have tried or what you have in mind as a solution.

Cheers, C.C
Reply With Quote
Reply

Thread Tools

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 11:38 AM.


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.05332 seconds
  • Memory Usage 2,294KB
  • Queries Executed 21 (?)
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
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete