vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Mobile login conditional? (https://vborg.vbsupport.ru/showthread.php?t=281212)

Boofo 04-06-2012 05:59 PM

Mobile login conditional?
 
Is there a conditon for checking to see if a login is done via Mobile device?

SEOvB 04-06-2012 10:38 PM

You mean a template conditional? What do you want to use it for?

-Nick, SEOvB Developer

Boofo 04-06-2012 10:43 PM

Yes, a template conditional. I want to use it to not use the IP they are loggedin with if they are on a mobile.

SEOvB 04-06-2012 10:59 PM

AFAIK, there is no such conditional by default. The closest thing you could maybe access in a template is the useragent (e.g. Mozilla Firefox) with user.useragent, depending on which template you're dealing with, but that would be an awful mess of code.

If you just want to display different templates based on whether or not the user is on a mobile device, just edit the "Default Mobile Device" theme, editable from the Settings->Style & Language Settings AdminCP panel.

-Nick, SEOvB Developer

Boofo 04-06-2012 11:10 PM

How does vb know to display the mobile style if a mobile logs in?

Actually, what I need is the PHP conditional, not the template.

SEOvB 04-06-2012 11:29 PM

Hmmm... no idea. That feature is relatively new, and I haven't worked with it yet. It's probably PHP based, but that's not much help. If you're comfortable digging through code, you could check the code surrounding the init_start, global_start, and parse_template hooks.

Also, try asking over in the programming discussion forum. That would probably be a more appropriate forum for your question.

-Nick, SEOvB Developer

Boofo 04-07-2012 08:46 AM

Thanks for trying to help, anyway. ;)

croportal 04-07-2012 09:53 AM

Default Style for Old Mobile Browsers
Select the default mobile style for old mobile browsers. This style will be used if user is browsing your forum with an older mobile browser. Set to 'None' to use desktop browser style.

Default Style for Modern Mobile Browsers
Select the default mobile style for modern mobile browsers. This style will be used if user is browsing your forum with a modern mobile browser. Set to 'None' to use desktop browser style.

you have this option in admincp

Boofo 04-07-2012 10:16 AM

That still doesn't explain how they are selected on login.

Pandemikk 04-07-2012 01:11 PM

There was some merit in checking around init_start. ;)

Code:

// Test mobile browser
$mobile_browser = false;
$mobile_browser_advanced = false;
if ($vbulletin->options['mobilestyleid_advanced'] OR $vbulletin->options['mobilestyleid_basic'])
{
    if (stripos($_SERVER['HTTP_USER_AGENT'], 'windows') === false OR preg_match('/(Windows Phone OS)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
    {
        if (
            preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android|Windows Phone OS)/i', strtolower($_SERVER['HTTP_USER_AGENT']))
            OR
            stripos($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml') !== false
            OR
            ((isset($_SERVER['HTTP_X_WAP_PROFILE']) OR isset($_SERVER['HTTP_PROFILE'])))
            OR
            stripos($_SERVER['ALL_HTTP'],'OperaMini') !== false
        )
        {
            $mobile_browser = true;
        }
        // This array is big and may be bigger later on. So we move it to a second if.
        else if (in_array(
                    strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4)),
                    array(
                    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
                    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
                    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
                    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
                    'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
                    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
                    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
                    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
                    'wapr','webc','winw','winw','xda ','xda-')
                )
            )
        {
            $mobile_browser = true;
            if(strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4)) == 'oper' AND  preg_match('/(linux|mac)/i', $_SERVER['HTTP_USER_AGENT']))
            {
                $mobile_browser = false;
            }
        }
    }

    if (
        $mobile_browser
            AND
        preg_match('/(ipad|ipod|iphone|blackberry|android|pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine|Windows Phone OS)/i', strtolower($_SERVER['HTTP_USER_AGENT']))
    )
    {
        $mobile_browser_advanced = true;
    }
}


Boofo 04-07-2012 04:54 PM

I wonder if it would be possible to use these:

Code:

if ($mobile_browser == false)
if ($mobile_browser_advanced == false)


Pandemikk 04-08-2012 01:19 AM

If they're in scope and haven't been unset I don't see why not.

Boofo 04-08-2012 06:21 AM

Okay, I entered the following test code in the global_bootstrap_init_start hook. It works but it throws the following error after it displays the userid:

Quote:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at [path]/includes/class_bootstrap.php(98) : eval()'d code:26) in [path]/includes/facebook/facebook.php on line 37
What am I missing?

Pandemikk 04-08-2012 09:53 AM

Whats' the code you're using? ;)

Boofo 04-08-2012 10:55 AM

Quote:

Originally Posted by Pandemikk (Post 2317944)
Whats' the code you're using? ;)

Sorry about that. I thought I posted it. ;)

This is what I used for testing:

PHP Code:

if ($mobile_browser == false && $mobile_browser_advanced == false)
{
    
print_r($vbulletin->userinfo['userid']);



Pandemikk 04-08-2012 11:28 AM

That error means PHP already sent headers and so you can't change them now. I'm not completely sure when this applies and when it doesn't (I believe it's okay once session_start() has been called), but it's because of your print_r. I suggest storing the value of the expression in your if condition and then use it later.


All times are GMT. The time now is 03:58 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.01421 seconds
  • Memory Usage 1,754KB
  • 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
  • (2)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (16)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