'."\n", ''."\n", ''."\n", ' '."\n", '', ''."\n" ); # content types that can have an xml declaration $mime["xml"] = array (1,3,4); # content types for mobile devices $mime["mobis"] = array (3,4,5); # actual XHTML MP device $mime["mhtml"] = 3; # old style phone (WAP) $mime["wml"] = 4; # imode type browser $mime["chtml"] = 5; global $imode; $imode = array ("doco", "j-pho", "up.b", "ddip", "port"); global $extra; $extra = array ("MIDP", "PPC", "symbian", "phone", "palm", "ipaq", "Googlebot-Mobile"); global $xml; $xml = ''."\n"; global $dir; $dir = dirname(__FILE__) .'/browser.inc'; //~ Extra function to catch additional mobi parameters: returns > 0 if TRUE function extra(&$extra) { $count = 0; if (is_array($extra)) { foreach($extra as $findme) { if ( @stripos(@$_SERVER["HTTP_USER_AGENT"], $findme) !== FALSE ) { $count++; } } } else { if ( @stripos(@$_SERVER["HTTP_USER_AGENT"], $extra) !== FALSE ) { $count++; } } return $count; } //~ Is the device a mobile ? function is_mobi($override = FALSE) { global $imode, $extra, $dir; // extra trimming of the 4 character strings in the file $browsers = file( $dir ); foreach ($browsers as $dev) { $browserlist [] = trim($dev); } if ($override == TRUE) { // (5) return $override; } elseif ( // (6) @in_array(strtolower(substr(trim(@$_SERVER["HTTP_USER_AGENT"]),0,4)), $browserlist) OR @in_array(strtolower(substr(trim(@$_SERVER["HTTP_USER_AGENT"]),0,4)), $imode) OR extra($extra) > 0 ) { return TRUE; } else { return FALSE; } } /* 5: Override variable allows you to set the device to a mobile is_mobi(1) or PC is_mobi(0) 6: Is the agent string in the file, or the $imode array or in the $extra array? */ //~ Establish best suited content type function content_type () { // $accessibility is module related and can be ignored, see snippet 1 for $is_device global $mime, $accessibility, $is_device; $is_mobi = (isset($accessibility['is_mobi'])) ? $accessibility['is_mobi'] : $is_device; // create array matching $mime['types'] to $mime['content'] $accept = array(); foreach ($mime['types'] as $lang => $val){ $accept[$val] = $mime['content'][$lang]; } //~ remove unwanted elements $unused = array_shift($accept); $unused = array_pop($accept); // set the $c (content type variable as an array) $c = array(); // If there is no $_SERVER["HTTP_ACCEPT"] then server text/html if ( !isset($_SERVER["HTTP_ACCEPT"]) OR empty($_SERVER["HTTP_ACCEPT"]) ) { $c['html'] = 1; } else { // loop the the accept types and look for it in the UA string foreach ($accept as $mime_lang => $mime_type) { $esc_type = '/'. str_replace( array ('/','.','+'), array('\/','\.','\+'), $mime_type) .";q=0(\.[1-9]+)/i"; $c[$mime_lang] = 1; if ( @stristr(@$_SERVER["HTTP_ACCEPT"], $mime_type) ) { $c[$mime_lang] = $c[$mime_lang] + 1; if (preg_match($esc_type, @$_SERVER["HTTP_ACCEPT"], $matches)) { $c[$mime_lang] = $c[$mime_lang] - (float)$matches[1]; } // end if pregmatch } // end if stristr } // end foreach accept } arsort ($c, SORT_NUMERIC); if ( array_sum($c) == count($c) ){ unset ( $c ); $c['html'] = 1; } // end array_sum // If HTML and a.n.other exist, get rid of anything below max value $max = max($c); foreach ($c as $type => $val) { if ($val != $max) { unset ( $c[$type] ); } } // end foreach // eliminate unneeded content types as seen fit if ( array_key_exists('xhtml', $c) ) { unset ( $c ); $c['xhtml'] = 1; } if ( array_key_exists('html', $c) ) { unset ( $c ); $c['html'] = 1;} if ( array_key_exists('html', $c) AND $is_mobi === TRUE ) { unset ( $c ); $c['chtml'] = 1;} if ( array_key_exists('wml', $c) ) { unset ( $c ); $c['wml'] = 1; } if ( array_key_exists('mhtml', $c) ) { unset ( $c ); $c['mhtml'] = 1; } if ( stristr(@$_SERVER["HTTP_USER_AGENT"], 'W3C_Validator') ) { unset ( $c ); $c['xhtml'] = 1; } // return the actual key value (eg [1]) return array_search(key($c), $mime['types']); }