Location: PHPKode > projects > Mocovie web framework > mocovi/library/ClientDetermination.php
<?php
/**
 *  Copyright (C) 2010  Kai Dorschner
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Kai Dorschner <the-hide@address.com>
 * @copyright Copyright 2010, Kai Dorschner
 * @license http://www.gnu.org/licenses/gpl.html GPLv3
 * @package mocovi
 * @subpackage helpers
 */

class ClientDetermination
{
	protected static $types = array
	( 'mobile' => array
		( 'iphone'
		, 'smartphone'
		, 'opera mini'
		, 'htc'
		, 'vodafone'
		, 'nokia'
		, 'windows ce'
		, 'pocket'
		, 'mobile'
		, 'mobil'
		, 'portable'
		, 'sda'
		, 'pda'
		, 'handheld'
		, 'symbian'
		, 'wap'
		, 'palm'
		, 'avantgo'
		, 'chtml'
		, 'blackberry'
		, 'psp'
		)
	, 'pc' => array
		( 'firefox'
		, 'opera'
		, 'chrome'
		, 'chromium'
		, 'safari'
		)
	, 'gecko-based' => array
		( 'firefox'
		)
	, 'webkit-based' => array
		( 'chrome'
		, 'chromium'
		, 'safari'
		, 'iphone'
		)
	, 'presto-based' => array
		( 'opera'
		, 'opera mini'
		)
	, 'netbook' => array
		(
			// ...
		)
	);

	public static function is($type)
	{
		$type = strtolower($type);
		if(isset($_SERVER["HTTP_USER_AGENT"]))
		{
			if(array_key_exists($type, self::$types))
			{
				foreach(self::$types[$type] as $agent)
					if(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), $agent) !== false)
						return true;
			}
			else
				throw new Exception($type.' not found in ClientDetermination::$types array. Please provide one of these types: '.implode(', ', array_keys(self::$types)));
		}
		return false;
	}
}
Return current item: Mocovie web framework