<commit_before><?php

/**
 * Copyright (c) 2010 West Virginia University
 * 
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 */

/* This class now supports the following public functions:
 *
 *  classify() - returns one of the 23 supported keys based on the requesting devices user agent string
 *  templates() - returns one of the 3 supported template directories based on the key of the requesting device
 *  is_computer() - returns true or false on if the requesting device is a computer
 *  is_spider() - returns true or false on if the requesting device is a spider
 *
 * The following functions support true/false responses down to major & minor version numbers. major & minor are *not* required.
 * 
 *  is_android( major, minor) - returns true or false on if the requesting device is an android device
 *  is_ios( major, minor) - returns true or false on if the requesting device is an iOS device
 *  is_iphone( major, minor) - returns true or false on if the requesting device is an iPhone
 *  is_ipod( major, minor) - returns true or false on if the requesting device is an iPod
 *
 */

class Device {  

  private static $is_computer;
  private static $is_spider;
  private static $is_android;
  private static $is_iphone;
  private static $is_ipod;
  private static $is_ios;
  private static $major_version;
  private static $minor_version;
  
  // matches device to templates
  private static $phoneTable = array(
	"iphone42" => "webkit",
	"iphone40" => "webkit",
	"iphone30" => "webkit",
	"iphone20" => "touch",
	"ipod42" => "webkit",
	"ipod40" => "webkit",
	"ipod30" => "webkit",
	"ipod20" => "touch",
	"ipad" => "basic",
	"android22" => "webkit",
	"android21"	=> "webkit",
	"android20" => "webkit",
	"android00" => "touch",
	"palm" => "touch",
	"opera_mini" => "touch",
	"opera_mobile" => "touch",
	"blackberry9800" => "touch",
	"blackberry" => "basic",
	"webkit" => "webkit",
	"smart_phone" => "basic",
	"feature_phone" => "basic",
	"computer" => "basic",
	"spider" => "basic"
  );

  // provide the nice looking name for a device & OS for stats
  public static $deviceEnglish = array(
	"iphone42" => "iPhone 4.2",
	"iphone40" => "iPhone 4.0",
	"iphone30" => "iPhone 3",
	"iphone20" => "iPhone 2",
	"ipod42" => "iPod 4.2",
	"ipod40" => "iPod 4",
	"ipod30" => "iPod 3",
	"ipod20" => "iPod 2",
	"ipad" => "iPad",
	"android22" => "Android 2.2",
	"android21"	=> "Android 2.1",
	"android20" => "Android 2.0",
	"android00" => "Android (Generic)",
	"palm" => "Web OS",
	"opera_mini" => "Opera Mini",
	"opera_mobile" => "Opera Mobile",
	"blackberry9800" => "Blackberry 9800 (aka Torch)",
	"blackberry" => "BlackBerry (Generic)",
	"webkit" => "WebKit (Generic)",
	"smart_phone" => "Smart Phone (Generic)",
	"feature_phone" => "Feature Phone (Generic)",
	"computer" => "Computer (Generic)",
	"spider" => "Spider (Generic)"
  );

  // returns the general device type based on user agent string matching. can get very specific depending on usage.
  public static function classify($ua = NULL) {
	
	$majorv = 0;
	$minorv = 0;
	
	if ($ua == NULL) {
		$user_agent = $_SERVER['HTTP_USER_AGENT'];
	    $accept = $_SERVER['HTTP_ACCEPT'];
	} else {
		$user_agent = $ua;
		$accept = $ua; // i don't think this will cause problems... key word being "think"
	}
	

	if (preg_match('/(ipod|iphone)/i',$user_agent,$matches)) {
		if (preg_match('/OS\ 4.2/i',$user_agent)) {
			$majorv = 4;
			$minorv = 2;
		} else if (preg_match('/OS\ 4/i',$user_agent)) {
			$majorv = 4;
		} else if (preg_match('/OS\ 3/i',$user_agent)) {
			$majorv = 3;
		} else {
			$majorv = 2;
		}
		$type = strtolower($matches[1]).$majorv.$minorv;
	} 
	else if (preg_match('/ipad/i',$user_agent)) {
		$type = 'ipad';
	}
	else if (preg_match('/android/i',$user_agent)) {
		if (preg_match('/android\ 2.2/i',$user_agent)) {
			$majorv = 2;
			$minorv = 2;
		} else if (preg_match('/android\ 2.1/i',$user_agent)) {
			$majorv = 2;
			$minorv = 1;
		} else if (preg_match('/android\ 2.0/i',$user_agent)) {
			$majorv = 2;
		}
		$type = 'android'.$majorv.$minorv;
    }
	else if (preg_match('/WebOS/i',$user_agent)) {
		$type = "palm";
	}
	else if (preg_match('/opera mini/i',$user_agent)) {
		$type = "opera_mini";
	} 
	else if (preg_match('/opera mobi/i',$user_agent)) {
		$type = "opera_mobile";
	}
	else if (preg_match('/blackberry/i',$user_agent)) {
		if (preg_match('/9800/i',$user_agent)) {
			$type = "blackberry9800"; // webkit-based browser
		} else {
			$type = "blackberry";
		}
	}<commit_msg>Add Android 2.3 devices to webkit list<commit_after><?php

/**
 * Copyright (c) 2010 West Virginia University
 * 
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 */

/* This class now supports the following public functions:
 *
 *  classify() - returns one of the 23 supported keys based on the requesting devices user agent string
 *  templates() - returns one of the 3 supported template directories based on the key of the requesting device
 *  is_computer() - returns true or false on if the requesting device is a computer
 *  is_spider() - returns true or false on if the requesting device is a spider
 *
 * The following functions support true/false responses down to major & minor version numbers. major & minor are *not* required.
 * 
 *  is_android( major, minor) - returns true or false on if the requesting device is an android device
 *  is_ios( major, minor) - returns true or false on if the requesting device is an iOS device
 *  is_iphone( major, minor) - returns true or false on if the requesting device is an iPhone
 *  is_ipod( major, minor) - returns true or false on if the requesting device is an iPod
 *
 */

class Device {  

  private static $is_computer;
  private static $is_spider;
  private static $is_android;
  private static $is_iphone;
  private static $is_ipod;
  private static $is_ios;
  private static $major_version;
  private static $minor_version;
  
  // matches device to templates
  private static $phoneTable = array(
	"iphone42" => "webkit",
	"iphone40" => "webkit",
	"iphone30" => "webkit",
	"iphone20" => "touch",
	"ipod42" => "webkit",
	"ipod40" => "webkit",
	"ipod30" => "webkit",
	"ipod20" => "touch",
	"ipad" => "basic",
	"android23" => "webkit",
	"android22" => "webkit",
	"android21"	=> "webkit",
	"android20" => "webkit",
	"android00" => "touch",
	"palm" => "touch",
	"opera_mini" => "touch",
	"opera_mobile" => "touch",
	"blackberry9800" => "touch",
	"blackberry" => "basic",
	"webkit" => "webkit",
	"smart_phone" => "basic",
	"feature_phone" => "basic",
	"computer" => "basic",
	"spider" => "basic"
  );

  // provide the nice looking name for a device & OS for stats
  public static $deviceEnglish = array(
	"iphone42" => "iPhone 4.2",
	"iphone40" => "iPhone 4.0",
	"iphone30" => "iPhone 3",
	"iphone20" => "iPhone 2",
	"ipod42" => "iPod 4.2",
	"ipod40" => "iPod 4",
	"ipod30" => "iPod 3",
	"ipod20" => "iPod 2",
	"ipad" => "iPad",
	"android23" => "Android 2.3",
	"android22" => "Android 2.2",
	"android21"	=> "Android 2.1",
	"android20" => "Android 2.0",
	"android00" => "Android (Generic)",
	"palm" => "Web OS",
	"opera_mini" => "Opera Mini",
	"opera_mobile" => "Opera Mobile",
	"blackberry9800" => "Blackberry 9800 (aka Torch)",
	"blackberry" => "BlackBerry (Generic)",
	"webkit" => "WebKit (Generic)",
	"smart_phone" => "Smart Phone (Generic)",
	"feature_phone" => "Feature Phone (Generic)",
	"computer" => "Computer (Generic)",
	"spider" => "Spider (Generic)"
  );

  // returns the general device type based on user agent string matching. can get very specific depending on usage.
  public static function classify($ua = NULL) {
	
	$majorv = 0;
	$minorv = 0;
	
	if ($ua == NULL) {
		$user_agent = $_SERVER['HTTP_USER_AGENT'];
	    $accept = $_SERVER['HTTP_ACCEPT'];
	} else {
		$user_agent = $ua;
		$accept = $ua; // i don't think this will cause problems... key word being "think"
	}
	

	if (preg_match('/(ipod|iphone)/i',$user_agent,$matches)) {
		if (preg_match('/OS\ 4.2/i',$user_agent)) {
			$majorv = 4;
			$minorv = 2;
		} else if (preg_match('/OS\ 4/i',$user_agent)) {
			$majorv = 4;
		} else if (preg_match('/OS\ 3/i',$user_agent)) {
			$majorv = 3;
		} else {
			$majorv = 2;
		}
		$type = strtolower($matches[1]).$majorv.$minorv;
	} 
	else if (preg_match('/ipad/i',$user_agent)) {
		$type = 'ipad';
	}
	else if (preg_match('/android/i',$user_agent)) {
		if (preg_match('/android\ 2.3/i',$user_agent)) {
			$majorv = 2;
			$minorv = 3;
		} else if (preg_match('/android\ 2.2/i',$user_agent)) {
			$majorv = 2;
			$minorv = 2;
		} else if (preg_match('/android\ 2.1/i',$user_agent)) {
			$majorv = 2;
			$minorv = 1;
		} else if (preg_match('/android\ 2.0/i',$user_agent)) {
			$majorv = 2;
		}
		$type = 'android'.$majorv.$minorv;
    }
	else if (preg_match('/WebOS/i',$user_agent)) {
		$type = "palm";
	}
	else if (preg_match('/opera mini/i',$user_agent)) {
		$type = "opera_mini";
	} 
	else if (preg_match('/opera mobi/i',$user_agent)) {
		$type = "opera_mobile";
	}
	else if (preg_match('/blackberry/i',$user_agent)) {
		if (preg_match('/9800/i',$user_agent)) {
			$type = "blackberry9800"; // webkit-based browser
		} else {
			$type = "blackberry";
		}
	}
{'fraction_non_alphanumeric': 0.17140377522239097, 'fraction_numerical': 0.026252983293556086, 'mean_word_length': 3.821652719665272, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7125774', 'n_tokens_mistral': 3704, 'n_tokens_neox': 3336, 'n_words': 959}