vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Display images based on browser (https://vborg.vbsupport.ru/showthread.php?t=249930)

NakedCrook 09-04-2010 08:44 PM

Display images based on browser
 
Alright...I am working on a bit of code for my forum style and this is the general premis.

In my postbit legacy, I give my users the ability to display their PSN and XBL gamercards. Now...this causes a bit of lag with mobile browsers so I want the ability to not show certain images or certain things for mobile browsers to improve load times. I have a bit of code in mind to do this but I am having difficulty with it.

In my style template, I have something like this:

<if condition="$_SERVER['HTTP_USER_AGENT'] == SOMETHING">
DO STUFF
</if>

that SOMETHING is supposed to be, say for example, the mobile safari user agent. I could turn that something into 'iPhone' but I would need an equivalent to a contains comparison as opposed to an ==.does anyone know the comparator for "contains"? I want to change the == to something that represents "contains" or "string contains"

kh99 09-04-2010 09:04 PM

Looking at the list of allowed functions in the vBulletin manual, I don't think there's a "string contains" function you can call from a template conditional, so you'd have to do that in a plugin somewhere. There is a function called "is_browser" you can call to check the browser, but it only recongnizes a certain set of browsers and iPhone isn't one of them. (The list seems to be "opera, ie, mozilla, firebird, firefox, camino, konqueror, safari, webkit, webtv, netscape, mac").

So, you could probably just use the "global_start" and set an "is_mobile" variable or something. I'll bet if you searched the web (or maybe the mods here) you can find code for checking the browser string so that you don't have to figure all that out.

BirdOPrey5 09-05-2010 10:28 PM

The 'right' way to do this is to just make a new or child style of your current style that is optimized for mobile browsers and have your mobile users use that.


All times are GMT. The time now is 11:23 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.02812 seconds
  • Memory Usage 1,709KB
  • 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
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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