| 1 |
<?php |
| 2 |
/** |
| 3 |
* MIT License |
| 4 |
* =========== |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining |
| 7 |
* a copy of this software and associated documentation files (the |
| 8 |
* "Software"), to deal in the Software without restriction, including |
| 9 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 10 |
* distribute, sublicense, and/or sell copies of the Software, and to |
| 11 |
* permit persons to whom the Software is furnished to do so, subject to |
| 12 |
* the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 |
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
* |
| 25 |
* ----------------------------------------------------------------------- |
| 26 |
* The demo is running all the Mobile_Detect's internal methods. |
| 27 |
* Here you can spot detections errors instantly. |
| 28 |
* ----------------------------------------------------------------------- |
| 29 |
* |
| 30 |
* @author Serban Ghita <serbanghita@gmail.com> |
| 31 |
* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt |
| 32 |
* |
| 33 |
*/ |
| 34 |
|
| 35 |
require_once '../Mobile_Detect.php'; |
| 36 |
$detect = new Mobile_Detect; |
| 37 |
|
| 38 |
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer'); |
| 39 |
$scriptVersion = $detect->getScriptVersion(); |
| 40 |
|
| 41 |
?><!DOCTYPE html> |
| 42 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
| 43 |
<head> |
| 44 |
<meta charset="utf-8"> |
| 45 |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"> |
| 46 |
<title>Mobile Detect Local Demo</title> |
| 47 |
<style type="text/css"> |
| 48 |
html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } |
| 49 |
body { margin: 0; padding: 0 1em; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 1em; color: #333333; background-color: #ffffff; max-width:320px; } |
| 50 |
body, td { font-size: 1em; } |
| 51 |
table th { text-align:left; } |
| 52 |
a { color: #0088cc; text-decoration: underline; } |
| 53 |
a:hover { color: #005580; text-decoration: underline; } |
| 54 |
header h1 small { font-size:small; } |
| 55 |
section { margin-bottom:2em; } |
| 56 |
section h1 { font-size:100%; } |
| 57 |
.infoText { font-size:85%; } |
| 58 |
.response { color:red; } |
| 59 |
.computer { background-color:blue; color:white; } |
| 60 |
.tablet { background-color:yellow; color:black; } |
| 61 |
.phone, .true { background-color:green; color:white; } |
| 62 |
.sendDataButton { border-radius: 1em; -moz-border-radius: 1em; -webkit-border-radius: 1em; padding:0.5em 1em; cursor: pointer; } |
| 63 |
.sendDataButton_yes { |
| 64 |
color:white; |
| 65 |
border: 1px solid #56A00E; |
| 66 |
background: #74B042; |
| 67 |
font-weight: bold; |
| 68 |
color: #ffffff; |
| 69 |
text-shadow: 0 1px 0 #335413; |
| 70 |
background-image: -webkit-gradient(linear, left top, left bottom, from( #74B042 ), to( #56A00E )); /* Saf4+, Chrome */ |
| 71 |
background-image: -webkit-linear-gradient( #74B042 , #56A00E ); /* Chrome 10+, Saf5.1+ */ |
| 72 |
background-image: -moz-linear-gradient( #74B042 , #56A00E ); /* FF3.6 */ |
| 73 |
background-image: -ms-linear-gradient( #74B042 , #56A00E ); /* IE10 */ |
| 74 |
background-image: -o-linear-gradient( #74B042 , #56A00E ); /* Opera 11.10+ */ |
| 75 |
background-image: linear-gradient( #74B042 , #56A00E ); |
| 76 |
} |
| 77 |
.sendDataButton_no { |
| 78 |
color:white; |
| 79 |
border: 1px solid #cd2c24; |
| 80 |
background: red; |
| 81 |
font-weight: bold; |
| 82 |
color: #ffffff; |
| 83 |
text-shadow: 0 1px 0 #444444; |
| 84 |
background-image: -webkit-gradient(linear, left top, left bottom, from( #e13027 ), to( #b82720 )); /* Saf4+, Chrome */ |
| 85 |
background-image: -webkit-linear-gradient( #e13027 , #b82720 ); /* Chrome 10+, Saf5.1+ */ |
| 86 |
background-image: -moz-linear-gradient( #e13027 , #b82720 ); /* FF3.6 */ |
| 87 |
background-image: -ms-linear-gradient( #e13027 , #b82720 ); /* IE10 */ |
| 88 |
background-image: -o-linear-gradient( #e13027 , #b82720 ); /* Opera 11.10+ */ |
| 89 |
background-image: linear-gradient( #e13027 , #b82720 ); |
| 90 |
} |
| 91 |
#feedbackForm fieldset { border:1px dotted #333; } |
| 92 |
#feedbackForm label { font-weight:bold; font-size:85%; } |
| 93 |
#feedbackForm textarea { width: 260px; } |
| 94 |
</style> |
| 95 |
<script src="//code.jquery.com/jquery-1.7.1.min.js"></script> |
| 96 |
<script type="text/javascript"> |
| 97 |
$(document).ready(function(){ |
| 98 |
|
| 99 |
$('.sendDataButton').bind('click.demo', function(e){ |
| 100 |
|
| 101 |
$button = $(this); |
| 102 |
e.preventDefault(); |
| 103 |
|
| 104 |
$.ajax({ |
| 105 |
url: 'http://demo.mobiledetect.net/?page=addItem', |
| 106 |
type: 'POST', |
| 107 |
dataType: 'jsonp', |
| 108 |
data: { |
| 109 |
remoteDetails: $('#remoteDetails').val(), |
| 110 |
remoteAnswer: $(this).attr('data-answer'), |
| 111 |
uaStringFromJS: escape(navigator.userAgent), |
| 112 |
deviceWidth: $(window).width(), |
| 113 |
deviceHeight: $(window).height(), |
| 114 |
source: 'demoFeedback' |
| 115 |
}, |
| 116 |
beforeSend: function(){ |
| 117 |
$button.html('Loading...'); |
| 118 |
}, |
| 119 |
success: function(r){ |
| 120 |
$('#feedbackForm').html('<p class="response">'+r.msg+'</p>'); |
| 121 |
} |
| 122 |
}); |
| 123 |
|
| 124 |
}); |
| 125 |
|
| 126 |
$.ajax({ |
| 127 |
url: 'http://demo.mobiledetect.net/?page=addItem', |
| 128 |
type: 'POST', |
| 129 |
dataType: 'jsonp', |
| 130 |
data: { |
| 131 |
//uaStringFromJS: escape(navigator.userAgent), |
| 132 |
deviceWidth: $(window).width(), |
| 133 |
deviceHeight: $(window).height(), |
| 134 |
devicePixelRatio: (typeof window.devicePixelRatio !== 'undefined' ? window.devicePixelRatio : 0), |
| 135 |
'source': 'demoVisitor' |
| 136 |
}, |
| 137 |
success: function(r){ |
| 138 |
try { console.log(r); } catch (e) { } |
| 139 |
} |
| 140 |
}); |
| 141 |
|
| 142 |
|
| 143 |
}); |
| 144 |
</script> |
| 145 |
|
| 146 |
|
| 147 |
</head> |
| 148 |
<body> |
| 149 |
|
| 150 |
<header> |
| 151 |
<h1><a href="https://github.com/serbanghita/Mobile-Detect">Mobile_Detect</a> <small>v. <?php echo $scriptVersion; ?></small></h1> |
| 152 |
<p class="infoText">The lightweight PHP class for detecting mobile devices.</p> |
| 153 |
</header> |
| 154 |
|
| 155 |
<!-- copy to GitHub with a couple of changes --> |
| 156 |
<section> |
| 157 |
|
| 158 |
<p>This is a <b><?php echo $deviceType; ?></b>. Your UA is <b class="<?php echo $deviceType; ?>"><?php echo htmlentities($_SERVER['HTTP_USER_AGENT']); ?></b></p> |
| 159 |
|
| 160 |
<p class="infoText">Please help us improve the mobile detection by choosing the correct answer.<br> |
| 161 |
Before sending an answer double check if you are using the browser in 'Desktop mode'.<br> |
| 162 |
You can contribute by:<br> |
| 163 |
1. <a href="https://github.com/serbanghita/Mobile-Detect">forking</a> the project<br> |
| 164 |
2. <a href="https://github.com/serbanghita/Mobile-Detect/issues/new?body=Please%20specify%20the%20User-Agent.%20Go%20to%20http://is.gd/mobiletest%20and%20copy-paste%20it%20here.">submiting an issue</a><br> |
| 165 |
3. sending us feedback below |
| 166 |
</p> |
| 167 |
|
| 168 |
<form id="feedbackForm"> |
| 169 |
<fieldset> |
| 170 |
<legend>Contribute</legend> |
| 171 |
|
| 172 |
<h1>Is your device really a <?php echo $deviceType; ?>?</h1> |
| 173 |
|
| 174 |
<p> |
| 175 |
<label for="remoteDetails">Additional feedback:</label><br> |
| 176 |
<textarea name="remoteDetails" id="remoteDetails"></textarea> |
| 177 |
</p> |
| 178 |
<button class="sendDataButton sendDataButton_yes" data-answer="yes">♥ Yes, it's correct.</button> <button class="sendDataButton sendDataButton_no" data-answer="no">No, it's wrong!</button> |
| 179 |
</fieldset> |
| 180 |
</form> |
| 181 |
|
| 182 |
</section> |
| 183 |
|
| 184 |
|
| 185 |
<!-- copy to GitHub demo.php --> |
| 186 |
<section> |
| 187 |
<h1>Supported methods</h1> |
| 188 |
<table cellspacing="0" cellpadding="0"> |
| 189 |
<tbody> |
| 190 |
<tr> |
| 191 |
<th colspan="2">Basic detection methods</th> |
| 192 |
</tr> |
| 193 |
<tr> |
| 194 |
<td>isMobile()</td><td <?php $check = $detect->isMobile(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td> |
| 195 |
</tr> |
| 196 |
<tr> |
| 197 |
<td>isTablet()</td><td <?php $check = $detect->isTablet(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td> |
| 198 |
</tr> |
| 199 |
</tbody> |
| 200 |
<tbody> |
| 201 |
<tr> |
| 202 |
<th colspan="2">Custom detection methods</th> |
| 203 |
</tr> |
| 204 |
<?php foreach($detect->getRules() as $name => $regex): |
| 205 |
$check = $detect->{'is'.$name}(); |
| 206 |
?> |
| 207 |
<tr> |
| 208 |
<td>is<?php echo $name; ?>()</td> |
| 209 |
<td <?php if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td> |
| 210 |
</tr> |
| 211 |
<?php endforeach; ?> |
| 212 |
</tbody> |
| 213 |
<tbody> |
| 214 |
<tr> |
| 215 |
<th colspan="2">Experimental version() method</th> |
| 216 |
</tr> |
| 217 |
<?php |
| 218 |
foreach($detect->getProperties() as $name => $match): |
| 219 |
$check = $detect->version($name); |
| 220 |
if($check!==false): |
| 221 |
?> |
| 222 |
<tr> |
| 223 |
<td>version(<?php echo $name; ?>)</td> |
| 224 |
<td><?php var_dump($check); ?></td> |
| 225 |
</tr> |
| 226 |
<?php endif; ?> |
| 227 |
<?php endforeach; ?> |
| 228 |
</tbody> |
| 229 |
<tbody> |
| 230 |
<tr> |
| 231 |
<th colspan="2">Other tests</th> |
| 232 |
</tr> |
| 233 |
<tr> |
| 234 |
<td>isiphone()</td> |
| 235 |
<td><?php var_dump($detect->isiphone()); ?></td> |
| 236 |
</tr> |
| 237 |
<tr> |
| 238 |
<td>isIphone()</td> |
| 239 |
<td><?php var_dump($detect->isIphone()); ?></td> |
| 240 |
</tr> |
| 241 |
<tr> |
| 242 |
<td>istablet()</td> |
| 243 |
<td><?php var_dump($detect->istablet()); ?></td> |
| 244 |
</tr> |
| 245 |
<tr> |
| 246 |
<td>isIOS()</td> |
| 247 |
<td><?php var_dump($detect->isIOS()); ?></td> |
| 248 |
</tr> |
| 249 |
<tr> |
| 250 |
<td>isWhateverYouWant()</td> |
| 251 |
<td class="randomcrap"><?php var_dump($detect->isWhateverYouWant()); ?></td> |
| 252 |
</tr> |
| 253 |
</tbody> |
| 254 |
<tbody> |
| 255 |
<tr> |
| 256 |
<th colspan="2">Debug</th> |
| 257 |
</tr> |
| 258 |
<tr> |
| 259 |
<td>Matching Regex</td> |
| 260 |
<td><?php var_dump($detect->getMatchingRegex()); ?></td> |
| 261 |
</tr> |
| 262 |
<tr> |
| 263 |
<td>Matching Array</td> |
| 264 |
<td><?php var_dump($detect->getMatchesArray()); ?></td> |
| 265 |
</tr> |
| 266 |
</tbody> |
| 267 |
</table> |
| 268 |
|
| 269 |
</section> |
| 270 |
|
| 271 |
</body> |
| 272 |
</html> |
| 273 |
|