Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-11-2005, 10:34 PM
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Location: Barefoot Bay Fl
Posts: 473
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default A function like is_broswer, but for Operating System Ident.

I was wondering if anyone could find a small amount of time to do this.

We have the built in function of is_browser, to select specific browsers, I was wondering if someone could code something similar for a browser conditional.

I use a plugin for grabbing game server info, called q3px, and it currently does not support Linux. So i'd like to have something that can exclude Operating systems that are not compatible with what I may install to add to the already existing scripts.

Thanks for anyone that can take the time to do this.
Reply With Quote
  #2  
Old 03-11-2005, 11:30 PM
why-not why-not is offline
 
Join Date: Feb 2004
Posts: 218
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi


Something like this...

Code:
<?

// usage

$out = this_system ();

// good systems! (example)

$good = array ( 'windows', 'mac' );

// test it!

if ( ! in_array ( $out, $good ) )
{
	echo 'Sorry this service does not support your system type';

	exit ();
}

// keep processing script, system OK!

echo 'You are using ' . $out . ' for your OS!';

function this_system ()
{
	$ua = $_SERVER['HTTP_USER_AGENT'];
	$sta = stristr ( $ua, 'x11' );
	$stb = stristr ( $ua, 'linux' );
	$stc = stristr ( $ua, 'sunos' );
	$std = stristr ( $ua, 'os/2' );
	$ste = stristr ( $ua, 'mac' );
	$stf = stristr ( $ua, 'ppc' );
	$stg = stristr ( $ua, '32bit' );
	$sth = stristr ( $ua, 'winnt' );
	$sti = stristr ( $ua, 'win95' );
	$stj = stristr ( $ua, 'win32' );
	$stk = stristr ( $ua, 'windows' );

	if ( $stk !== false )
	{
		$system = 'windows';
	}
	else if ( $stj !== false )
	{
		$system = 'windows';
	}
	else if ( $sti !== false )
	{
		$system = 'windows';
	}
	else if ( $sth !== false )
	{
		$system = 'windows';
	}
	else if ( $stg !== false )
	{
		$system = 'windows';
	}
	else
	{
		if ( $stf !== false )
		{
			$system = 'mac';
		}
		else if ( $ste !== false )
		{
			$system = 'mac';
		}
		else
		{
			if ( $std !== false )
			{
				$system = 'os2';
			}
			else
			{
				if ( $stc !== false )
				{
					$system = 'unix';
				}
				else if ( $stb !== false )
				{
					$system = 'linux';
				}
				else if ( $sta !== false )
				{
					$system = 'unix';
				}
				else
				{
					$system = 'unknown';
				}
			}
		}
	}

	return ( $system );
}

?>
Sonia
Reply With Quote
  #3  
Old 03-12-2005, 08:32 AM
neocorteqz's Avatar
neocorteqz neocorteqz is offline
 
Join Date: May 2002
Location: Barefoot Bay Fl
Posts: 473
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was thinking of something based off of the existing code for is_browser

PHP Code:
// #################### Start is browser ##########################
// browser detection script
function is_browser($browser$version 0)
{
    global 
$_SERVER;
    static 
$is;
    if (!
is_array($is))
    {
        
$useragent strtolower($_SERVER['HTTP_USER_AGENT']);
        
$is = array(
            
'opera' => 0,
            
'ie' => 0,
            
'mozilla' => 0,
            
'firebird' => 0,
            
'firefox' => 0,
            
'camino' => 0,
            
'konqueror' => 0,
            
'safari' => 0,
            
'webkit' => 0,
            
'webtv' => 0,
            
'netscape' => 0,
            
'mac' => 0
        
);

        
// detect opera
            # Opera/7.11 (Windows NT 5.1; U) [en]
            # Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 7.02 Bork-edition [en]
            # Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 4.0) Opera 7.0 [en]
            # Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.0 [en]
            # Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC) Opera 5.0 [en]
        
if (strpos($useragent'opera') !== false)
        {
            
preg_match('#opera(/| )([0-9\.]+)#'$useragent$regs);
            
$is['opera'] = $regs[2];
        }

        
// detect internet explorer
            # Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)
            # Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
            # Mozilla/4.0 (compatible; MSIE 5.22; Mac_PowerPC)
            # Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC; e504460WanadooNL)
        
if (strpos($useragent'msie ') !== false AND !$is['opera'])
        {
            
preg_match('#msie ([0-9\.]+)#'$useragent$regs);
            
$is['ie'] = $regs[1];
        }

        
// detect macintosh
        
if (strpos($useragent'mac') !== false)
        {
            
$is['mac'] = 1;
        }

        
// detect safari
            # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/74 (KHTML, like Gecko) Safari/74
            # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51
        
if (strpos($useragent'applewebkit') !== false AND $is['mac'])
        {
            
preg_match('#applewebkit/(\d+)#'$useragent$regs);
            
$is['webkit'] = $regs[1];

            if (
strpos($useragent'safari') !== false)
            {
                
preg_match('#safari/([0-9\.]+)#'$useragent$regs);
                
$is['safari'] = $regs[1];
            }
        }

        
// detect konqueror
            # Mozilla/5.0 (compatible; Konqueror/3.1; Linux; X11; i686)
            # Mozilla/5.0 (compatible; Konqueror/3.1; Linux 2.4.19-32mdkenterprise; X11; i686; ar, en_US)
            # Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)
        
if (strpos($useragent'konqueror') !== false)
        {
            
preg_match('#konqueror/([0-9\.-]+)#'$useragent$regs);
            
$is['konqueror'] = $regs[1];
        }

        
// detect mozilla
            # Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4b) Gecko/20030504 Mozilla
            # Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2a) Gecko/20020910
            # Mozilla/5.0 (X11; U; Linux 2.4.3-20mdk i586; en-US; rv:0.9.1) Gecko/20010611
        
if (strpos($useragent'gecko') !== false AND !$is['safari'] AND !$is['konqueror'])
        {
            
preg_match('#gecko/(\d+)#'$useragent$regs);
            
$is['mozilla'] = $regs[1];

            
// detect firebird / firefox
                # Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5
                # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6
                # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4a) Gecko/20030423 Firebird Browser/0.6
                # Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8
            
if (strpos($useragent'firefox') !== false OR strpos($useragent'firebird') !== false OR strpos($useragent'phoenix') !== false)
            {
                
preg_match('#(phoenix|firebird|firefox)( browser)?/([0-9\.]+)#'$useragent$regs);
                
$is['firebird'] = $regs[3];

                if (
$regs[1] == 'firefox')
                {
                    
$is['firefox'] = $regs[3];
                }
            }

            
// detect camino
                # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021104 Chimera/0.6
            
if (strpos($useragent'chimera') !== false OR strpos($useragent'camino') !== false)
            {
                
preg_match('#(chimera|camino)/([0-9\.]+)#'$useragent$regs);
                
$is['camino'] = $regs[2];
            }
        }

        
// detect web tv
        
if (strpos($useragent'webtv') !== false)
        {
            
preg_match('#webtv/([0-9\.]+)#'$useragent$regs);
            
$is['webtv'] = $regs[1];
        }

        
// detect pre-gecko netscape
        
if (preg_match('#mozilla/([1-4]{1})\.([0-9]{2}|[1-8]{1})#'$useragent$regs))
        {
            
$is['netscape'] = "$regs[1].$regs[2]";
        }
    }

    
// sanitize the incoming browser name
    
$browser strtolower($browser);
    if (
substr($browser03) == 'is_')
    {
        
$browser substr($browser3);
    }

    
// return the version number of the detected browser if it is the same as $browser
    
if ($is["$browser"])
    {
        
// $version was specified - only return version number if detected version is >= to specified $version
        
if ($version)
        {
            if (
$is["$browser"] >= $version)
            {
                return 
$is["$browser"];
            }
        }
        else
        {
            return 
$is["$browser"];
        }
    }

    
// if we got this far, we are not the specified browser, or the version number is too low
    
return 0;

So I can add it to functions php and make it usable forum wide.

But the code you posted works fine. Just i need to integrate it into vB for a conditional i can use anywhere.

like
HTML Code:
<if condition="!is_os('win,mac')>
You must be using Windows or Mac to view the q3px plugin.
<else />
<code here>
</if>
Thanks.



Edit:
will this work?

PHP Code:
// #################### Start is os ##########################
// os detection script
function is_os($os)
{
    global 
$_SERVER;
    static 
$is;
    if (!
is_array($is))
    {
        
$useragent strtolower($_SERVER['HTTP_USER_AGENT']);
        
$is = array(
            
'linux' => 0,
            
'mac' => 0,
            
'windows' => 0,
            
'webtv' => 0
        
);

        
// detect windows
        
if (strpos($useragent'winnt,win32,windows,32bit') !== false)
        {
            
$is['windows'] = 1;
        }
        
        
// detect macintosh
        
if (strpos($useragent'mac') !== false)
        {
            
$is['mac'] = 1;
        }

        
        
// detect linux
        
if (strpos($useragent'linux,x11,u,i686') !== false)
        {
            
$is['linux'] = 1;
        }

        
        
// detect web tv
        
if (strpos($useragent'webtv') !== false)
        {
            
preg_match('#webtv/([0-9\.]+)#'$useragent$regs);
            
$is['webtv'] = $regs[1];
        }

    }

    
// sanitize the incoming os name
    
$os strtolower($os);
    if (
substr($os03) == 'is_')
    {
        
$os substr($os3);
    }

}
// #################### End is os ########################## 
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 10:57 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.05424 seconds
  • Memory Usage 2,274KB
  • 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
  • (1)bbcode_code
  • (1)bbcode_html
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)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