本文整理汇总了PHP中core_useragent::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP core_useragent::instance方法的具体用法?PHP core_useragent::instance怎么用?PHP core_useragent::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_useragent
的用法示例。
在下文中一共展示了core_useragent::instance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_content
public function get_content()
{
global $CFG;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass();
$obj = new login_msg_lib();
$baseurl = $obj->get_base();
$welcomepage = $obj->get_welcome();
$jquerycdn = 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js';
$databaseobj = core_useragent::instance();
$device = $databaseobj->get_device_type();
$jquery = <<<JQ
<script type="text/javascript" src="{$jquerycdn}"></script>
JQ;
if ($device == 'mobile' || $device == 'tablet') {
$jquery = '';
}
if (empty($welcomepage)) {
$popupjs = <<<HTML
{$jquery}
HTML;
} else {
$popupjs = <<<HTML
{$jquery}
<!--ThickBox 3-->
<script>
// Add popup fade?
function welcome() {
var win_width = 600;
var win_height = 400;
var left = screen.width / 2 - win_width/2;
var top = screen.height /2 - win_height/2;
var winoptions = "width="+win_width+", height="+win_height+", top="+top+", left="+left;
var popup = window.open("{$welcomepage}", "Welcome", winoptions );
}
setTimeout( function(){welcome();}, 3000);
</script>
HTML;
}
$this->content->text = <<<HTML
{$popupjs}
<script type="text/javascript" src="{$baseurl}js/thickbox/thickbox.js"></script>
<link rel="stylesheet" href="{$baseurl}js/thickbox/thickbox.css" type="text/css" media="screen" />
<!-- /ThickBox 3 -->
<div id="log_meg_small">
<!-- link to reopen message --!>
<p> <a href="{$welcomepage}" target="_blank">Welcome</a> </p>
<p> <a href="https://www.youtube.com/watch?v=GDk1YOP2f4A"
\ttarget="_blank">Why Durabuilt?</a> </p>
</div>
HTML;
$this->content->footer = '';
return $this->content;
}
示例2: setUp
/**
* Pre-test setup. Preserves $CFG.
*/
public function setUp()
{
parent::setUp();
// Reset $CFG and $SERVER.
$this->resetAfterTest();
// Consistent initial setup: all players disabled.
\core\plugininfo\media::set_enabled_plugins('videojs');
// Pretend to be using Firefox browser (must support ogg for tests to work).
core_useragent::instance(true, 'Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0 ');
}
示例3: test_svg_image_use
/**
* This function will test directives used to serve SVG images to make sure
* this are making the right decisions.
*/
public function test_svg_image_use()
{
global $CFG;
$this->resetAfterTest();
// The two required tests.
$this->assertTrue(file_exists($CFG->dirroot . '/pix/i/test.svg'));
$this->assertTrue(file_exists($CFG->dirroot . '/pix/i/test.png'));
$theme = theme_config::load(theme_config::DEFAULT_THEME);
// First up test the forced setting.
$imagefile = $theme->resolve_image_location('i/test', 'moodle', true);
$this->assertSame('test.svg', basename($imagefile));
$imagefile = $theme->resolve_image_location('i/test', 'moodle', false);
$this->assertSame('test.png', basename($imagefile));
// Now test the use of the svgicons config setting.
// We need to clone the theme as usesvg property is calculated only once.
$testtheme = clone $theme;
$CFG->svgicons = true;
$imagefile = $testtheme->resolve_image_location('i/test', 'moodle', null);
$this->assertSame('test.svg', basename($imagefile));
$CFG->svgicons = false;
// We need to clone the theme as usesvg property is calculated only once.
$testtheme = clone $theme;
$imagefile = $testtheme->resolve_image_location('i/test', 'moodle', null);
$this->assertSame('test.png', basename($imagefile));
unset($CFG->svgicons);
// Finally test a few user agents.
$useragents = array('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)' => false, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)' => false, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)' => false, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)' => false, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)' => true, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)' => false, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)' => true, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)' => true, 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0)' => true, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)' => true, 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/534.17 (KHTML, like Gecko) Chrome/11.0.652.0 Safari/534.17' => true, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1' => true, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1' => true, 'Mozilla/5.0 (Windows NT 6.1; rv:1.9) Gecko/20100101 Firefox/4.0' => true, 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0.1' => true, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1' => true, 'Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.10.289 Version/12.02' => false, 'Mozilla/5.0 (Linux; U; Android 0.5; en-us) AppleWebKit/522+ (KHTML, like Gecko) Safari/419.3' => false, 'Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => false, 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' => true, 'Mozilla/5.0 (Linux; Android 4.3; it-it; SAMSUNG GT-I9505/I9505XXUEMJ7 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36' => true);
foreach ($useragents as $agent => $expected) {
core_useragent::instance(true, $agent);
// We need to clone the theme as usesvg property is calculated only once.
$testtheme = clone $theme;
$imagefile = $testtheme->resolve_image_location('i/test', 'moodle', null);
if ($expected) {
$this->assertSame('test.svg', basename($imagefile), 'Incorrect image returned for user agent `' . $agent . '`');
} else {
$this->assertSame('test.png', basename($imagefile), 'Incorrect image returned for user agent `' . $agent . '`');
}
}
}
示例4: instance
/**
* Get an instance of the user agent object.
*
* @param bool $reload If set to true the user agent will be reset and all ascertations remade.
* @param string $forceuseragent The string to force as the user agent, don't use unless absolutely unavoidable.
* @return core_useragent
*/
public static function instance($reload = false, $forceuseragent = null)
{
if (!self::$instance || $reload) {
self::$instance = new core_useragent($forceuseragent);
}
return self::$instance;
}
示例5: pretend_to_be_firefox
/**
* Sets user agent to Firefox.
*/
private function pretend_to_be_firefox()
{
// Pretend to be using Firefox browser (must support ogg for tests to work).
core_useragent::instance(true, 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0');
}
示例6: test_get_device_type
/**
* Test device type detection.
*/
public function test_get_device_type()
{
// IE8 (common pattern ~1.5% of IE7/8 users have embedded IE6 agent).
$ie8 = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BT Openworld BB; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; Hotbar 10.2.197.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)';
core_useragent::instance(true, $ie8);
$this->assertEquals('default', core_useragent::get_device_type());
// Genuine IE6.
$ie6 = 'Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.0.3705; Media Center PC 2.8)';
core_useragent::instance(true, $ie6);
$this->assertEquals('legacy', core_useragent::get_device_type());
core_useragent::instance(true);
}
示例7: test_useragent_web_crawler
/**
* @dataProvider user_agents_providers
*/
public function test_useragent_web_crawler($useragent, $tests)
{
// Setup the core_useragent instance.
core_useragent::instance(true, $useragent);
$expectation = isset($tests['is_web_crawler']) ? $tests['is_web_crawler'] : false;
$this->assertSame($expectation, core_useragent::is_web_crawler());
}
示例8: test_deprecated_is_web_crawler
/**
* Regression tests for the deprecated is_web_crawler() function
*/
public function test_deprecated_is_web_crawler()
{
$browsers = array('Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0', 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10', 'Opera/9.0 (Windows NT 5.1; U; en)', 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 –Nexus', 'Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5');
$crawlers = array('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)', 'Googlebot-Image/1.0', 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)', 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)', 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)', 'msnbot/2.1', 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)', 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)', 'AltaVista V2.0B crawler@evreka.com', 'ZoomSpider - wrensoft.com [ZSEBOT]', 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)', 'Baiduspider+(+http://www.baidu.com/search/spider.htm)', 'BaiDuSpider', 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)');
foreach ($browsers as $agent) {
core_useragent::instance(true, $agent);
$this->assertSame($agent, core_useragent::get_user_agent_string());
$this->assertFalse(is_web_crawler());
$this->assertDebuggingCalled('is_web_crawler() has been deprecated, please use core_useragent::is_web_crawler() instead.', DEBUG_DEVELOPER);
}
foreach ($crawlers as $agent) {
core_useragent::instance(true, $agent);
$this->assertSame($agent, core_useragent::get_user_agent_string());
$this->assertTrue(is_web_crawler(), "{$agent} should be considered a search engine");
$this->assertDebuggingCalled('is_web_crawler() has been deprecated, please use core_useragent::is_web_crawler() instead.', DEBUG_DEVELOPER);
}
}
示例9: test_get_browser_version_classes
/**
* @dataProvider user_agents_providers
*/
public function test_get_browser_version_classes($useragent, $tests)
{
// Setup the core_useragent instance.
core_useragent::instance(true, $useragent);
$actual = core_useragent::get_browser_version_classes();
foreach ($tests['versionclasses'] as $expectedclass) {
$this->assertContains($expectedclass, $actual);
}
$this->assertCount(count($tests['versionclasses']), $actual);
}
示例10: test_devicedetectregex
/**
* This function will test custom device detection regular expression setting.
*/
public function test_devicedetectregex()
{
global $CFG;
$this->resetAfterTest();
// Check config currently empty.
$this->assertEmpty(json_decode($CFG->devicedetectregex));
$this->assertTrue(core_useragent::set_user_device_type('tablet'));
$exceptionoccured = false;
try {
core_useragent::set_user_device_type('featurephone');
} catch (moodle_exception $e) {
$exceptionoccured = true;
}
$this->assertTrue($exceptionoccured);
// Set config and recheck.
$config = array('featurephone' => '(Symbian|MIDP-1.0|Maemo|Windows CE)');
$CFG->devicedetectregex = json_encode($config);
core_useragent::instance(true);
// Clears singleton cache.
$this->assertTrue(core_useragent::set_user_device_type('tablet'));
$this->assertTrue(core_useragent::set_user_device_type('featurephone'));
}