Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 07-16-2006, 06:36 PM
Yorixz Yorixz is offline
 
Join Date: Jun 2005
Location: Netherlands
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Display banner depending on browser setting?

Because of the requirements of one of my ad providers (50% of the impressions have to be to people from Canada, the USA or UK) I'm trying to figure out the best way to display these ads to the right visitors (and display alternative ads to the others).

I've noticed vBulletin allows (a few) PHP functions to be used in templates, sadly there is no function available to check for the browser language.

I've found the following code on php.net (and changed it a bit)
PHP Code:
function chooseLang($availableLangs){
   
$pref=array();
   foreach(
split(','$_SERVER["HTTP_ACCEPT_LANGUAGE"]) as $lang) {
       if (
preg_match('/^([a-z]+).*?(?:;q=([0-9.]+))?/i'$lang.';q=1.0'$split)) {
           
$pref[sprintf("%f%d"$split[2], rand(0,9999))]=strtolower($split[1]);       
       }
   }
   
krsort($pref);
   return 
array_shift(array_merge(array_intersect($pref$availableLangs), $availableLangs));
}
 
if(
chooseLang(array('en''sv''en''nl')) == 'en'){
echo 
1;
} else {
echo 
2;

And I'm a bit wondering how to use this, I haven't got too much experience with plugins, I wouldn't know how to return a value to one of the templates so a little help or a pointing in the right direction would be very appreciated.

Yours,

Yorixz

Alright, I got a PM with some info about it on vB.com, but anyway, I managed to get the code working, it selected the right language, until I changed it some and now all it does is complaining that my field isn't found.
i'm using this code:
PHP Code:
function favoriteLang($availableLangs){
   
$pref=array();
   foreach(
split(','$_SERVER["HTTP_ACCEPT_LANGUAGE"]) as $lang) {
       if (
preg_match('/^([a-z]+).*?(?:;q=([0-9.]+))?/i'$lang.';q=1.0'$split)) {
           
$pref[sprintf("%f%d"$split[2], rand(0,9999))]=strtolower($split[1]);       
       }
   }
   
krsort($pref);
   return 
array_shiftarray_mergearray_intersect$pref$availableLangs), $availableLangs) );
}

if ( !isset( 
$vbulletin->session->vars['adlang'] ) ) {
    
$lang favoriteLang( array( 'en''sv''nl''fr''pt''es''pl''no''de' ) );
    
//$_SESSION['adlang'] = $lang;
    
$vbulletin->session->db_fields['adlang'] = type_char;
    
$vbulletin->session->set('adlang'$lang);  
    
$adcode2 'session now set';
} else {
    
$lang $vbulletin->session->vars['adlang'];
    
$adcode2 'session already set!';
}

switch(
$lang)
{
    case 
'en':
    case 
'fr':
        
$adcode 'adcode clicksor, ';
        break;
    default:
        
$adcode 'adremedy, ';
        break;

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 05:21 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.12984 seconds
  • Memory Usage 2,178KB
  • 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
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)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