本文整理匯總了PHP中core_useragent::is_msword方法的典型用法代碼示例。如果您正苦於以下問題:PHP core_useragent::is_msword方法的具體用法?PHP core_useragent::is_msword怎麽用?PHP core_useragent::is_msword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core_useragent
的用法示例。
在下文中一共展示了core_useragent::is_msword方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_useragent_msword
/**
* @dataProvider user_agents_providers
*/
public function test_useragent_msword($useragent, $tests)
{
// Setup the core_useragent instance.
core_useragent::instance(true, $useragent);
// MSWord Tests.
if (isset($tests['is_msword']) && $tests['is_msword']) {
$this->assertTrue(core_useragent::is_msword());
} else {
$this->assertFalse(core_useragent::is_msword());
}
}
示例2: redirect
/**
* Redirects the user to another page, after printing a notice.
*
* This function calls the OUTPUT redirect method, echo's the output and then dies to ensure nothing else happens.
*
* <strong>Good practice:</strong> You should call this method before starting page
* output by using any of the OUTPUT methods.
*
* @param moodle_url|string $url A moodle_url to redirect to. Strings are not to be trusted!
* @param string $message The message to display to the user
* @param int $delay The delay before redirecting
* @throws moodle_exception
*/
function redirect($url, $message = '', $delay = -1)
{
global $OUTPUT, $PAGE, $CFG;
if (CLI_SCRIPT or AJAX_SCRIPT) {
// This is wrong - developers should not use redirect in these scripts but it should not be very likely.
throw new moodle_exception('redirecterrordetected', 'error');
}
// Prevent debug errors - make sure context is properly initialised.
if ($PAGE) {
$PAGE->set_context(null);
$PAGE->set_pagelayout('redirect');
// No header and footer needed.
$PAGE->set_title(get_string('pageshouldredirect', 'moodle'));
}
if ($url instanceof moodle_url) {
$url = $url->out(false);
}
$debugdisableredirect = false;
do {
if (defined('DEBUGGING_PRINTED')) {
// Some debugging already printed, no need to look more.
$debugdisableredirect = true;
break;
}
if (core_useragent::is_msword()) {
// Clicking a URL from MS Word sends a request to the server without cookies. If that
// causes a redirect Word will open a browser pointing the new URL. If not, the URL that
// was clicked is opened. Because the request from Word is without cookies, it almost
// always results in a redirect to the login page, even if the user is logged in in their
// browser. This is not what we want, so prevent the redirect for requests from Word.
$debugdisableredirect = true;
break;
}
if (empty($CFG->debugdisplay) or empty($CFG->debug)) {
// No errors should be displayed.
break;
}
if (!function_exists('error_get_last') or !($lasterror = error_get_last())) {
break;
}
if (!($lasterror['type'] & $CFG->debug)) {
// Last error not interesting.
break;
}
// Watch out here, @hidden() errors are returned from error_get_last() too.
if (headers_sent()) {
// We already started printing something - that means errors likely printed.
$debugdisableredirect = true;
break;
}
if (ob_get_level() and ob_get_contents()) {
// There is something waiting to be printed, hopefully it is the errors,
// but it might be some error hidden by @ too - such as the timezone mess from setup.php.
$debugdisableredirect = true;
break;
}
} while (false);
// Technically, HTTP/1.1 requires Location: header to contain the absolute path.
// (In practice browsers accept relative paths - but still, might as well do it properly.)
// This code turns relative into absolute.
if (!preg_match('|^[a-z]+:|', $url)) {
// Get host name http://www.wherever.com.
$hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot);
if (preg_match('|^/|', $url)) {
// URLs beginning with / are relative to web server root so we just add them in.
$url = $hostpart . $url;
} else {
// URLs not beginning with / are relative to path of current script, so add that on.
$url = $hostpart . preg_replace('|\\?.*$|', '', me()) . '/../' . $url;
}
// Replace all ..s.
while (true) {
$newurl = preg_replace('|/(?!\\.\\.)[^/]*/\\.\\./|', '/', $url);
if ($newurl == $url) {
break;
}
$url = $newurl;
}
}
// Sanitise url - we can not rely on moodle_url or our URL cleaning
// because they do not support all valid external URLs.
$url = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $url);
$url = str_replace('"', '%22', $url);
$encodedurl = preg_replace("/\\&(?![a-zA-Z0-9#]{1,8};)/", "&", $url);
$encodedurl = preg_replace('/^.*href="([^"]*)".*$/', "\\1", clean_text('<a href="' . $encodedurl . '" />', FORMAT_HTML));
$url = str_replace('&', '&', $encodedurl);
if (!empty($message)) {
//.........這裏部分代碼省略.........
示例3: test_check_browser_version
/**
* Modifies $_SERVER['HTTP_USER_AGENT'] manually to check if check_browser_version
* works as expected.
*/
public function test_check_browser_version()
{
core_useragent::instance(true, $this->user_agents['Safari']['412']['Mac OS X']);
$this->assertTrue(core_useragent::is_safari());
$this->assertTrue(core_useragent::check_safari_version());
$this->assertTrue(core_useragent::is_webkit());
$this->assertTrue(core_useragent::check_webkit_version());
$this->assertTrue(core_useragent::check_safari_version('312'));
$this->assertFalse(core_useragent::check_safari_version('500'));
$this->assertFalse(core_useragent::is_chrome());
$this->assertFalse(core_useragent::check_chrome_version());
$this->assertFalse(core_useragent::is_safari_ios());
$this->assertFalse(core_useragent::check_safari_ios_version());
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['Safari iOS']['528']['iPhone']);
$this->assertTrue(core_useragent::is_safari_ios());
$this->assertTrue(core_useragent::check_safari_ios_version());
$this->assertTrue(core_useragent::is_webkit());
$this->assertTrue(core_useragent::check_webkit_version());
$this->assertTrue(core_useragent::check_safari_ios_version('527'));
$this->assertFalse(core_useragent::check_safari_ios_version(590));
$this->assertFalse(core_useragent::check_safari_version('312'));
$this->assertFalse(core_useragent::check_safari_version('500'));
$this->assertFalse(core_useragent::is_chrome());
$this->assertFalse(core_useragent::check_chrome_version());
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['WebKit Android']['530']['Nexus']);
$this->assertTrue(core_useragent::is_webkit());
$this->assertTrue(core_useragent::check_webkit_version());
$this->assertTrue(core_useragent::check_webkit_android_version('527'));
$this->assertFalse(core_useragent::check_webkit_android_version(590));
$this->assertFalse(core_useragent::is_safari());
$this->assertFalse(core_useragent::check_safari_version());
$this->assertFalse(core_useragent::is_chrome());
$this->assertFalse(core_useragent::check_chrome_version());
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['WebKit Android']['537']['Samsung GT-9505']);
$this->assertTrue(core_useragent::is_webkit());
$this->assertTrue(core_useragent::check_webkit_version());
$this->assertTrue(core_useragent::check_webkit_android_version('527'));
$this->assertTrue(core_useragent::is_chrome());
$this->assertTrue(core_useragent::check_chrome_version());
$this->assertFalse(core_useragent::check_webkit_android_version(590));
$this->assertFalse(core_useragent::is_safari());
$this->assertFalse(core_useragent::check_safari_version());
core_useragent::instance(true, $this->user_agents['WebKit Android']['537']['Nexus 5']);
$this->assertTrue(core_useragent::is_webkit());
$this->assertTrue(core_useragent::check_webkit_version());
$this->assertTrue(core_useragent::check_webkit_android_version('527'));
$this->assertTrue(core_useragent::is_chrome());
$this->assertTrue(core_useragent::check_chrome_version());
$this->assertFalse(core_useragent::check_webkit_android_version(590));
$this->assertFalse(core_useragent::is_safari());
$this->assertFalse(core_useragent::check_safari_version());
core_useragent::instance(true, $this->user_agents['Chrome']['8']['Mac OS X']);
$this->assertTrue(core_useragent::is_chrome());
$this->assertTrue(core_useragent::check_chrome_version());
$this->assertTrue(core_useragent::is_webkit());
$this->assertTrue(core_useragent::check_webkit_version());
$this->assertTrue(core_useragent::check_chrome_version(8));
$this->assertFalse(core_useragent::check_chrome_version(10));
$this->assertFalse(core_useragent::check_safari_version('1'));
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['Opera']['9.0']['Windows XP']);
$this->assertTrue(core_useragent::is_opera());
$this->assertTrue(core_useragent::check_opera_version());
$this->assertTrue(core_useragent::check_opera_version('8.0'));
$this->assertFalse(core_useragent::check_opera_version('10.0'));
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['MSIE']['6.0']['Windows XP SP2']);
$this->assertTrue(core_useragent::is_ie());
$this->assertTrue(core_useragent::check_ie_version());
$this->assertTrue(core_useragent::check_ie_version('5.0'));
$this->assertFalse(core_useragent::check_ie_compatibility_view());
$this->assertFalse(core_useragent::check_ie_version('7.0'));
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['MSIE']['5.0']['Windows 98']);
$this->assertFalse(core_useragent::is_ie());
$this->assertFalse(core_useragent::check_ie_version());
$this->assertTrue(core_useragent::check_ie_version(0));
$this->assertTrue(core_useragent::check_ie_version('5.0'));
$this->assertFalse(core_useragent::check_ie_compatibility_view());
$this->assertFalse(core_useragent::check_ie_version('7.0'));
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['MSIE']['7.0']['Windows XP SP2']);
$this->assertTrue(core_useragent::is_ie());
$this->assertTrue(core_useragent::check_ie_version());
$this->assertTrue(core_useragent::check_ie_version('7.0'));
$this->assertFalse(core_useragent::check_ie_compatibility_view());
$this->assertFalse(core_useragent::check_ie_version('8.0'));
$this->assertFalse(core_useragent::is_msword());
core_useragent::instance(true, $this->user_agents['MSIE']['7.0b']['Windows XP']);
$this->assertTrue(core_useragent::is_ie());
$this->assertTrue(core_useragent::check_ie_version());
$this->assertTrue(core_useragent::check_ie_version('7.0'));
$this->assertFalse(core_useragent::check_ie_compatibility_view());
//.........這裏部分代碼省略.........