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-22-2008, 11:40 AM
raztrip raztrip is offline
 
Join Date: Nov 2007
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Problem adding and using global vars of my own

Hi,

I'm using vB 3.6.8 patch level 2.

I want to add variables for use in any and all templates. To do so, I've created a mytxtfile.txt file with the desired content (in HTML), and added the following lines at the end of global.php:

$mytxtfile = 'mytxtfile.txt';
$mycontent = file_get_contents($mytxtfile);


Then, I added $mycontent inside templates, by writing $mycontent in the template editor.

The problem is that this works with some templates, but not with others. For example, it worked with navbar and with a new template I made, but not with postbit.

1. Why?

2. Is there a better way to do this?

3. Where are custom templates (like the new one I made) stored?


Any help will be appreciated,

Thank you,

R.
Reply With Quote
  #2  
Old 05-22-2008, 11:50 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Add the following line to your plugin:

PHP Code:
global $mycontent 
Reply With Quote
  #3  
Old 05-22-2008, 11:54 AM
raztrip raztrip is offline
 
Join Date: Nov 2007
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

First, thank you. Now, I'm a total newbie. Where is my plugin (do I even have one?) and how do I add this line to it?

Quote:
Originally Posted by Marco van Herwaarden View Post
Add the following line to your plugin:

PHP Code:
global $mycontent 
Reply With Quote
  #4  
Old 05-22-2008, 12:03 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm now see that you don't use a plugin but instead edit global.php (bad choice in my view). Just add it in global.php then, just above the 2 lines you already added.
Reply With Quote
  #5  
Old 05-22-2008, 12:07 PM
raztrip raztrip is offline
 
Join Date: Nov 2007
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you again, Marco.

- Is the global command a vB function?

- What is the better way to do this, in your experience?

Quote:
Originally Posted by Marco van Herwaarden View Post
Hmm now see that you don't use a plugin but instead edit global.php (bad choice in my view). Just add it in global.php then, just above the 2 lines you already added.
Reply With Quote
  #6  
Old 05-22-2008, 12:18 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

"global" is a standard PHP command that will set the variable in the global scope.

I would not do any code edits, but just put this code into a plugin, probably using the 'global_start' hook location.
Reply With Quote
  #7  
Old 05-22-2008, 01:22 PM
raztrip raztrip is offline
 
Join Date: Nov 2007
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've tried this - but it still doesn't work with the postbit template. Why could that be?

Quote:
Originally Posted by Marco van Herwaarden View Post
"global" is a standard PHP command that will set the variable in the global scope.

I would not do any code edits, but just put this code into a plugin, probably using the 'global_start' hook location.
--------------- Added [DATE]1211547826[/DATE] at [TIME]1211547826[/TIME] ---------------

To anyone who's had the same type of problem, I've found a different solution. I am ignorant as to why this worked and the other way didn't, but here it is:

Instead of referencing $mycontent directly, I called it through $GLOBALS, which is a superglobal. It is an array of all global-scope variables, the keys of which are the variables' names. Therefore, I was able to call $mycontent by writing $GLOBALS[mycontent].

This page helped me find this solution.
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 12:15 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.04485 seconds
  • Memory Usage 2,220KB
  • 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_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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