vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   General Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=189)
-   -   Merge into $show (https://vborg.vbsupport.ru/showthread.php?t=71162)

Michael Morris 10-29-2004 10:00 PM

Merge into $show
 
Hello everyone - here's a quick tip: I'm fond of giving my users a lot of controllable options using user profile fields and then using the phpinclude start template to express those as $show conditionals. I do this because it makes the resultant stylesheets more portable - the user profile field in the $bbuserinfo almost certainly will change from server to server - and if you refer to the same condition multiple times it becomes a pain in the tail to move the style to a new setup.

So I move the $bbuserinfo['fieldX'] stuff over to $show. The reason is that, like $bbuserinfo, $show is declared global in almost every function that deals with data display (the sole exception I know of is the function that parses subforums). You can also choose names for your show variables that are descriptive, which in turn makes your code easier for others to read.

Initialize your custom $show variables in your phpinclude_start template like so...

PHP Code:

$show array_merge($show,
'custom1',
'custom2',
); 

And so on. After you initialize them, you can then assign their values. Changing the $bbuserinfo over into them - that's a lesson for another time (this is supposed to be a "quick tip") :)

Brad 10-30-2004 09:31 AM

I do this to, but as so to prevent some mess:

PHP Code:

$loo_show = array(); // this array holds your custom show info
$show array_merge($show$loo_show); // merges custom show info into regular show array 

Also everyone should be aware that array_merge changed in php version 5:

Quote:

From php.net comments

As you know, guys, because of fixing bug #25494, starting from PHP 5.0.0 Beta2 the function doesn't accept scalar values as secondary arguments. It means if you try to run <? array_merge(array('array'),'scalar'); ?> the function throws a warning and returns <? NULL ?> instead of <? array(0=>'array',1=>'scalar');?>. If you want the old behavior of the merge function, use this instead:

PHP Code:

<?
function array_merge_php4($array1,$array2){
   $return=array();
   foreach(func_get_args() as $arg){
       if(!is_array($arg)){
           $arg=array($arg);
       }
       foreach($arg as $key=>$val){
           if(!is_int($key)){
               $return[$key]=$val;
           }else{
               $return[]=$val;
           }
       }
   }
   return $return;
}
?>


Good stuff Michael. :)


All times are GMT. The time now is 08:12 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.00938 seconds
  • Memory Usage 1,724KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete