Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 06-03-2010, 09:11 PM
bleavitt bleavitt is offline
 
Join Date: Jun 2010
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default calling a $_SERVER['REQUEST_URI'] within a template

I'm in the process of migrating from 3.0 to 4.0 setup of vBulletin. I've noticed that in 4.0, php tags do not work within the template files themselves. Hence it would seem that something like {vb:var variable_name} is the format I need to employ for what I'm trying to accomplish. I've got a custom login redirect that I'm working to implement. To do so, I need to call the equivalent of $_SERVER['REQUEST_URI'] within the template.

My question is does such a predefined variable exist? If not, is there an easy way to create this variable? Basically, what I am doing is sending a call to a login page which needs to know which page the user was on when the call was initiated.

I've already spent several hours searching the forums and Google for a solution to no avail. I've also read through the Template Tags and Languages and Phrases section without much success.

I'm completely new to the vBulletin environment, so any help would be appreciated.
Reply With Quote
  #2  
Old 06-03-2010, 09:17 PM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here is a general solution:

Add this plugin code to init_startup (or any other plugin location occurring before your template is registered.)
PHP Code:
$myarray=array();
$myarray['variable_name']='variable content';
vB_Template::preRegister('template_name'$myarray); 
The result is that {vb:var variable_name} will now take on the value 'variable content' in the template 'template_name'.
Reply With Quote
  #3  
Old 06-03-2010, 09:26 PM
bleavitt bleavitt is offline
 
Join Date: Jun 2010
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Attilitus for your response,

However, I'm not seeing how this will allow me to use the php global variable $_SERVER['REQUEST_URI'] within a vBulletin template. Maybe, I'm missing something?

Thank you.
Reply With Quote
  #4  
Old 06-03-2010, 09:27 PM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your problem's solution is a special case of my general solution.

PHP Code:
$myarray=array();
$myarray['variable_name']=$_SERVER['REQUEST_URI'];
vB_Template::preRegister('template_name'$myarray); 
Reply With Quote
  #5  
Old 06-03-2010, 09:39 PM
bleavitt bleavitt is offline
 
Join Date: Jun 2010
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, that makes more sense. This leads to two more questions then. Where do I go to find a suitable plugin to tack this bit of code on to? I've got FTP access, I wouldn't even know wher to begin looking. Or, is this something that can be achieved from the control panel?

And then just to make sure I understand the syntax, in my template file, I'd use something like:

{vb:raw $myarray['variable_name'] }

Is that correct?

Thanks again.
Reply With Quote
  #6  
Old 06-03-2010, 09:44 PM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No. As I explained in the first post:

Quote:
The result is that {vb:var variable_name} will now take on the value 'variable content' in the template 'template_name'.
In words: The keys of the array are the names of the variables to be accessed inside your template.

To add this: go into your admincp, and Add New Plugin. The location of the plugin should be init_start, and the plugin code should be what I posted here.

Alternatively, since it sounds as if you have limited experience: you might wait for someone else to come along with alternative advice on how to solve your problem. (vBulletin might provide you server variables in templates already, I'm not sure.)

~Tim
Reply With Quote
  #7  
Old 06-04-2010, 03:38 PM
bleavitt bleavitt is offline
 
Join Date: Jun 2010
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Tim again for your help,

I apologize for overlooking the second part of your first post. I think I've followed your instructions. However, I'm still in the dark. I've not been able to make your suggestion work, as far as I can tell.

In the Add a New plugin section, I've followed your instruction as explained above, Here's the code that I created based off of what you suggested above:

Code:
$server_vars=array();
$server_vars['request_uri']=$_SERVER['REQUEST_URI'];
vB_Template::preRegister('TestSite_Beta', $server_vars);
I've associated it with init_startup hook and gave it a title/name of "Request URI variable" (though that seems irrelevant). Then in the template file "header" for the "TestSite_Beta" template, where we're replacing the standard in-page login with a link to another login page -- the link that is going in place of the login form is needing to have a "Requesting URI" variable embedded into it. So I've used {vb:var request_uri} where I want the requesting URI to appear.

The full line of html looks like this:
Code:
<a rel="nofollow" href="/login/icslogin.php?destination={vb:var request_uri}">Register | Login</a>
When it is tested however, I cannot get it display any sort of variable for the requesting URI. This is where I'm stuck. It comes out blank in the generated html.
Reply With Quote
  #8  
Old 06-04-2010, 07:13 PM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Then in the template file "header" for the "TestSite_Beta" template
I do not understand what this means.

My provided code will make the variable {vb:var variable_name} available in the template with name 'template_name'. If the template in which you are adding the variable is not named exactly 'template_name' then the variable will not be accessible from that template.

Perhaps this is your problem:

Note that once a template is parsed, all non-registered variables are removed from the template string. That is: If you have two templates: template1 and template2. Then suppose you render template1 and store it in variable var_template1, then put {vb:raw var_template1} in template2. Registering a variable for template2, will not allow you to use that variable in template1.
Reply With Quote
  #9  
Old 06-14-2010, 05:25 PM
bleavitt bleavitt is offline
 
Join Date: Jun 2010
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just to conclude this thread, here's the solution that worked for me. Attilitus was right on with his suggestions above below is the specific solution that worked for me:

In the Plugins Manager under the Plugins/Products menu, I created a new plugin, set the hook to init_startup and then used this line of code:

PHP Code:
$server_varis=array();
$server_varis['request_uri']=$_SERVER['REQUEST_URI'];
vB_Template::preRegister('header'$server_varis); 
The confusion was in the name of the template file that I was pre-registering the variable for. 'header' refers to the specific template file within the whole template theme package.

Thanks again for your help, Tim.

-Brent
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:17 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.04150 seconds
  • Memory Usage 2,243KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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_postinfo_query
  • fetch_postinfo
  • 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