Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2008, 12:06 PM
raztrip raztrip is offline
 
Join Date: Nov 2007
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Format question: why is fetch_template surrounded with single quote+period?

Hello,

Can anyone explain why the format for fetching templates includes the template name enclosed in single quotes and periods?

eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('WHOSONLINE') . '");');

Thank you,

R
Reply With Quote
  #2  
Old 05-26-2008, 12:12 PM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

String Concatenation
Reply With Quote
  #3  
Old 05-26-2008, 12:25 PM
nexialys
Guest
 
Posts: n/a
Default

you could also make it this way:
eval(print_output(fetch_template('WHOSONLINE')));

but only if your server is PHP 5.1 and newer... it would not be compatible with older versions, so it would break a lot of vBulletin right now... in the future, this structure will change...
Reply With Quote
  #4  
Old 05-26-2008, 12:25 PM
raztrip raztrip is offline
 
Join Date: Nov 2007
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I thought it might be it, but I still can't see how it works in this case.

Why are there single quotes inside the double quotes?

Which string does this concatenate to?
Why not use the .= format?

Quote:
Originally Posted by Dismounted View Post
String Concatenation
Reply With Quote
  #5  
Old 05-26-2008, 01:51 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Work from the inside out...
  1. [minicode]fetch_template()[/minicode] - fetches the template's HTML data (as a string) and returns it.
  2. The concatanation appends the template data to the string, the [minicode]$navbar =...[/minicode]
  3. Finally the [minicode]eval()[/minicode] evaluates the string as PHP code, so [minicode]$navbar[/minicode] becomes a proper variable instead of just a string. It will also mean that variables in the templates will assume their values assigned to them earlier in the script.

The start of this page shows the differences between single & double quotes and may help to explain why there are double quotes inside single quotes.

Its not hard to understand but if you are not well versed in PHP could take a while to explain it fully.
Reply With Quote
  #6  
Old 05-27-2008, 07:36 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by raztrip View Post
Why not use the .= format?
Because you can't. There isn't a "=" anywhere, so you can't use a ".=".
Reply With Quote
  #7  
Old 05-27-2008, 10:41 AM
raztrip raztrip is offline
 
Join Date: Nov 2007
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

First, thank you all for replying. I've read the guide on single and double quotes, and understood it, including the concatenation examples.

Now, if we take just this part:
$navbar = "' . fetch_template('navbar') . '";

I fail to understand why it isn't written as:
$navbar .= "fetch_template('navbar')";

Also, seeing as how PHP would recognize a function inside quotes as a string (I'm talking about 'fetch_template...'), does eval overcome this by treating everything to the right of it as possible PHP code?

Thank you,

R

Quote:
Originally Posted by Dismounted View Post
Because you can't. There isn't a "=" anywhere, so you can't use a ".=".
Reply With Quote
  #8  
Old 05-27-2008, 10:47 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's different. eval() does indeed parse everything as PHP code. fetch_template() parses templates from the conditionals to proper PHP code which can be understood. We are concatenating fetch_template()'s output to $navbar, what you suggest is concatenating fetch_template()'s output to the end of navbar, and what will be concatenated will be the PHP code that fetch_template() outputs, and that will not be parsed by eval().
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 02:08 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.04550 seconds
  • Memory Usage 2,226KB
  • 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
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)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
  • (8)postbit
  • (7)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_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