Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Use short variable system
Shane's Avatar
Shane
Join Date: Nov 2001
Posts: 108

 

Show Printable Version Email this Page Subscription
Shane Shane is offline 03-10-2008, 10:00 PM

There is a more detailed article of what happens here.
Welcome! With 3.7.x there is now the ability to use short variables when passing through files. This allows you not to have an "ugly" name in the URL and allows everything to be easier read and created. Which means you don't have to memorize 100 possible larger variables to memory when using forms and redirect.

Since I haven't coded a thing for vB since 3.0.0, I figure I show this to those who are trying to make their programs be more effective, as I am basically re-learning as I go. This article shows you how the system works!

The Script

PHP Code:
<?php

error_reporting
(E_ALL & ~E_NOTICE);

define('THIS_SCRIPT''test');

require_once(
'./global.php');

//    Create our short ID to a standard name so we can use them where ever we go.
$temp $vbulletin->input->shortvars;
$vbulletin->input->shortvars = array(
    
't'      =>    'testid',
);
foreach (array(
'_GET''_POST') AS $arrayname)
{
    
$vbulletin->input->convert_shortvars($GLOBALS["$arrayname"]);
}
$vbulletin->input->shortvars array_merge($temp$vbulletin->input->shortvars);

$vbulletin->input->clean_array_gpc('r', array(
    
'testid'     => TYPE_INT,
));

//    This var can be now anything I set inside my program so it can be identified easier!
$testid $vbulletin->GPC['testid'];

echo 
"This should output <strong>1</strong>: " $testid "<br/>";

?>


Summary


Basically using the built in features in class_core.php inside your includes directory which gets initialized through your global.php file, has a "regiester" area where it takes my input of "t" from the URL (test.php?t=1) and makes $testid (which I would use through out the script) to get the input.

Now the most important thing is specifying what type of value it will be. In this case, "t" will always be an integer (TYPE_INT). If I were to do (test.php?t=This is a test) it would not output at all. This is a nice security feature built into vB and doesn't allow people to directly "test" the system to find vulnerabilities in your vB installation and your product (add-on). However, if I specified TYPE_STR then it would work both ways because a number can be a string.

Usually you would place this in a file that is always read by your product. Mine is in my "catch" all file loading after global.php is included. This makes it so all your pages uses the same data and you don't have to re-type this code anywhere else.

I hope this helps you! Enjoy!
Reply With Quote
  #2  
Old 03-12-2008, 12:19 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

interesting ..

these are like easter eggs - it's exciting when finding new built-in functions that are useful

thanks for sharing :up:
Reply With Quote
  #3  
Old 03-12-2008, 02:57 PM
Shane's Avatar
Shane Shane is offline
 
Join Date: Nov 2001
Posts: 108
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah. I didn't want to have to type in a 8 to 12 character varabile name anymore so I was trying to figure out how vB did it. Much easier to remember at least 2 or 1 letters for passing data around.
Reply With Quote
Reply


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:22 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.03384 seconds
  • Memory Usage 2,212KB
  • Queries Executed 16 (?)
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)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (2)postbit
  • (3)postbit_onlinestatus
  • (3)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