Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2014, 09:24 AM
Black Snow Black Snow is offline
 
Join Date: Jul 2012
Location: Scotland
Posts: 471
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Using vb:raw in templates

Hi, I have create multiple custom pages on my forum. I have a navigation bar on the left of all of said pages. Everytime I add/change a link, I need to go into each and every template to add/change that link.

Is there a way to make a template called "custom_nav", add the links for my nav bar, then call that template from each of the custom pages? If so, can someone help me do it or show me where to start please?

Thanks
Reply With Quote
  #2  
Old 08-27-2014, 09:40 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could use a template. You would need php code to render your template and save the results in a variable, then register that variable to any template where you want to display it. You could do that in a plugin, or if your custom pages are php scripts, you could do it in your custom scripts.

How are your custom pages implemented?
Reply With Quote
Благодарность от:
Black Snow
  #3  
Old 08-27-2014, 10:31 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

See https://vborg.vbsupport.ru/showthread.php?t=228078
Reply With Quote
Благодарность от:
Black Snow
  #4  
Old 08-27-2014, 11:26 AM
Black Snow Black Snow is offline
 
Join Date: Jul 2012
Location: Scotland
Posts: 471
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
You could use a template. You would need php code to render your template and save the results in a variable, then register that variable to any template where you want to display it. You could do that in a plugin, or if your custom pages are php scripts, you could do it in your custom scripts.

How are your custom pages implemented?
The pages are done using templates. I followed an article on here for creating custom pages using templates.

I have this in my php file.
Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT', 'info');
define('CSRF_PROTECTION', true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('siterules');

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits = construct_navbits(array('' => 'Forum'));
$navbar = render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####

//Use as http:/site.com/test.php?do=siterules
if ($_REQUEST['do'] == "siterules") {
$pagetitle = 'Site Rules';
$templater = vB_Template::create('siterules');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
exit;
}


?>
I think this is all I need in the PHP file.

So, I have a template called "siterules", using the PHP file above. I now want to add a navigation bar on this page and a further 4 pages so when I add/change a link, it reflects on all pages. How can I use a plugin to pull the template "navigation" and insert it on each of the custom pages?
Reply With Quote
  #5  
Old 08-27-2014, 02:14 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, since you have custom php files you don't need to use a plugin. You can add code to render your custom template before the "main" page template. So just after the "YOUR CUSTOM CODE GOES HERE", add something like:
Code:
$templater = vB_Template::create('custom_nav');
$custom_nav  = $templater->render();

Then lower down, add a "register" line to your template code:
Code:
$templater->register('custom_nav', $custom_nav);
then you should be able to put {vb:raw custom_nav} in your siterules template where you want it to appear.

One last thing, for efficiency: add custom_nav to the (existing) array of templates to cache ($globaltemplates):
Code:
$globaltemplates = array('siterules', 'custom_nav');
Reply With Quote
  #6  
Old 08-29-2014, 08:26 AM
Black Snow Black Snow is offline
 
Join Date: Jul 2012
Location: Scotland
Posts: 471
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks. I will try that and report back.

--------------- Added [DATE]1409309336[/DATE] at [TIME]1409309336[/TIME] ---------------

Quote:
Originally Posted by kh99 View Post
Well, since you have custom php files you don't need to use a plugin. You can add code to render your custom template before the "main" page template. So just after the "YOUR CUSTOM CODE GOES HERE", add something like:
Code:
$templater = vB_Template::create('custom_nav');
$custom_nav  = $templater->render();

Then lower down, add a "register" line to your template code:
Code:
$templater->register('custom_nav', $custom_nav);
then you should be able to put {vb:raw custom_nav} in your siterules template where you want it to appear.

One last thing, for efficiency: add custom_nav to the (existing) array of templates to cache ($globaltemplates):
Code:
$globaltemplates = array('siterules', 'custom_nav');
Worked a treat! :up: thank you very much.

I have one other question. How do I make a page show if there is no
Code:
if ($_REQUEST['do'] == BLAH
I have my pages now set up:
Code:
if ($_REQUEST['do'] == 1
if ($_REQUEST['do'] == 2
if ($_REQUEST['do'] == 3
if ($_REQUEST['do'] == 4
But how do I get page 1 to show if someone goes to http://site.com/info.php
Reply With Quote
  #7  
Old 08-29-2014, 11:39 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As a rule: You never, ever once address URL parameters directly like that. Opens you up for all kinds of vulnerabilities.

Read and implement: https://vborg.vbsupport.ru/showthread.php?t=119372

After that, you will have your parameter in a nice variable, for example: do.

And to your question - if a variable is not defined, you define it in your code. See PHP man isset. Along the lines of
Code:
if (!isset($do))
{
    $do = 1;
}
Or do
Code:
if (!isset($do) OR $do == 1))
Reply With Quote
  #8  
Old 08-29-2014, 03:43 PM
Black Snow Black Snow is offline
 
Join Date: Jul 2012
Location: Scotland
Posts: 471
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So I could do this:

Code:
if (!isset($do) OR $_REQUEST['do'] == 1)
Reply With Quote
  #9  
Old 08-29-2014, 07:32 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why would you use $_Request again if you have cleaned the input and assigned it to $do? If you havn't done that, $do will not work. And as I said before: Accessing $_REQUEST directly is evil. Do not do it. Read the link I gave you.

This is really basic PHP 101.
Reply With Quote
  #10  
Old 08-30-2014, 12:05 PM
Black Snow Black Snow is offline
 
Join Date: Jul 2012
Location: Scotland
Posts: 471
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
Why would you use $_Request again if you have cleaned the input and assigned it to $do? If you havn't done that, $do will not work. And as I said before: Accessing $_REQUEST directly is evil. Do not do it. Read the link I gave you.

This is really basic PHP 101.
Your link doesn't show how to use $vbulletin->input->clean_array_gpc when requesting a page. Could you show me an example?
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 07:25 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.05035 seconds
  • Memory Usage 2,271KB
  • 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
  • (12)bbcode_code
  • (3)bbcode_quote
  • (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
  • (2)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete