PluginProbe
Team Showcase / 1.13
Team Showcase v1.13
trunk 1.0 1.1 1.11 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.21 1.21.1 1.21.2 1.21.3 1.21.4 1.21.5 1.22.0 1.22.1 1.22.10 1.22.12 1.22.13 1.22.14 All 49 releases
team / includes / mobble.php

mobble.php in Team Showcase 1.13, at includes/mobble.php

438 lines 14.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 mobble
4 ------
5
6
7 Copyright (c) 2013 Scott Evans <http://scott.ee>
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT
15 HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
16 INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR
17 FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE
18 OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS,
19 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.COPYRIGHT HOLDERS WILL NOT
20 BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL
21 DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
22
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://gnu.org/licenses/>.
25
26 */
27
28
29
30 $useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : "";
31 $mobble_detect = new Mobile_Detect();
32 $mobble_detect->setDetectionType( 'extended' );
33
34 /***************************************************************
35 * Function is_iphone
36 * Detect the iPhone
37 ***************************************************************/
38
39 function is_iphone() {
40 global $mobble_detect;
41 return $mobble_detect->isIphone();
42 }
43
44 /***************************************************************
45 * Function is_ipad
46 * Detect the iPad
47 ***************************************************************/
48
49 function is_ipad() {
50 global $mobble_detect;
51 return $mobble_detect->isIpad();
52 }
53
54 /***************************************************************
55 * Function is_ipod
56 * Detect the iPod, most likely the iPod touch
57 ***************************************************************/
58
59 function is_ipod() {
60 global $mobble_detect;
61 return $mobble_detect->is( 'iPod' );
62 }
63
64 /***************************************************************
65 * Function is_android
66 * Detect an android device.
67 ***************************************************************/
68
69 function is_android() {
70 global $mobble_detect;
71 return $mobble_detect->isAndroidOS();
72 }
73
74 /***************************************************************
75 * Function is_blackberry
76 * Detect a blackberry device
77 ***************************************************************/
78
79 function is_blackberry() {
80 global $mobble_detect;
81 return $mobble_detect->isBlackBerry();
82 }
83
84 /***************************************************************
85 * Function is_opera_mobile
86 * Detect both Opera Mini and hopefully Opera Mobile as well
87 ***************************************************************/
88
89 function is_opera_mobile() {
90 global $mobble_detect;
91 return $mobble_detect->isOpera();
92 }
93
94 /***************************************************************
95 * Function is_palm - to be phased out as not using new detect library?
96 * Detect a webOS device such as Pre and Pixi
97 ***************************************************************/
98
99 function is_palm() {
100 _deprecated_function( 'is_palm', '1.2', 'is_webos' );
101 global $mobble_detect;
102 return $mobble_detect->is( 'webOS' );
103 }
104
105 /***************************************************************
106 * Function is_webos
107 * Detect a webOS device such as Pre and Pixi
108 ***************************************************************/
109
110 function is_webos() {
111 global $mobble_detect;
112 return $mobble_detect->is( 'webOS' );
113 }
114
115 /***************************************************************
116 * Function is_symbian
117 * Detect a symbian device, most likely a nokia smartphone
118 ***************************************************************/
119
120 function is_symbian() {
121 global $mobble_detect;
122 return $mobble_detect->is( 'Symbian' );
123 }
124
125 /***************************************************************
126 * Function is_windows_mobile
127 * Detect a windows smartphone
128 ***************************************************************/
129
130 function is_windows_mobile() {
131 global $mobble_detect;
132 return $mobble_detect->is( 'WindowsMobileOS' ) || $mobble_detect->is( 'WindowsPhoneOS' );
133 }
134
135 /***************************************************************
136 * Function is_lg
137 * Detect an LG phone
138 ***************************************************************/
139
140 function is_lg() {
141 _deprecated_function( 'is_lg', '1.2' );
142 global $useragent;
143 return preg_match( '/LG/i', $useragent );
144 }
145
146 /***************************************************************
147 * Function is_motorola
148 * Detect a Motorola phone
149 ***************************************************************/
150
151 function is_motorola() {
152 global $mobble_detect;
153 return $mobble_detect->is( 'Motorola' );
154 }
155
156 /***************************************************************
157 * Function is_nokia
158 * Detect a Nokia phone
159 ***************************************************************/
160
161 function is_nokia() {
162 _deprecated_function( 'is_nokia', '1.2' );
163 global $useragent;
164 return preg_match( '/Series60/i', $useragent ) || preg_match( '/Symbian/i', $useragent ) || preg_match( '/Nokia/i', $useragent );
165 }
166
167 /***************************************************************
168 * Function is_samsung
169 * Detect a Samsung phone
170 ***************************************************************/
171
172 function is_samsung() {
173 global $mobble_detect;
174 return $mobble_detect->is( 'Samsung' );
175 }
176
177 /***************************************************************
178 * Function is_samsung_galaxy_tab
179 * Detect the Galaxy tab
180 ***************************************************************/
181
182 function is_samsung_galaxy_tab() {
183 _deprecated_function( 'is_samsung_galaxy_tab', '1.2', 'is_samsung_tablet' );
184 return is_samsung_tablet();
185 }
186
187 /***************************************************************
188 * Function is_samsung_tablet
189 * Detect the Galaxy tab
190 ***************************************************************/
191
192 function is_samsung_tablet() {
193 global $mobble_detect;
194 return $mobble_detect->is( 'SamsungTablet' );
195 }
196
197 /***************************************************************
198 * Function is_kindle
199 * Detect an Amazon kindle
200 ***************************************************************/
201
202 function is_kindle() {
203 global $mobble_detect;
204 return $mobble_detect->is( 'Kindle' );
205 }
206
207 /***************************************************************
208 * Function is_sony_ericsson
209 * Detect a Sony Ericsson
210 ***************************************************************/
211
212 function is_sony_ericsson() {
213 global $mobble_detect;
214 return $mobble_detect->is( 'Sony' );
215 }
216
217 /***************************************************************
218 * Function is_nintendo
219 * Detect a Nintendo DS or DSi
220 ***************************************************************/
221
222 function is_nintendo() {
223 global $useragent;
224 return preg_match( '/Nintendo DSi/i', $useragent ) || preg_match( '/Nintendo DS/i', $useragent );
225 }
226
227
228 /***************************************************************
229 * Function is_smartphone
230 * Grade of phone A = Smartphone - currently testing this
231 ***************************************************************/
232
233 function is_smartphone() {
234 global $mobble_detect;
235 $grade = $mobble_detect->mobileGrade();
236 if ( $grade == 'A' || $grade == 'B' ) {
237 return true;
238 } else {
239 return false;
240 }
241 }
242
243 /***************************************************************
244 * Function is_handheld
245 * Wrapper function for detecting ANY handheld device
246 ***************************************************************/
247
248 function is_handheld() {
249 return is_mobile() || is_iphone() || is_ipad() || is_ipod() || is_android() || is_blackberry() || is_opera_mobile() || is_webos() || is_symbian() || is_windows_mobile() || is_motorola() || is_samsung() || is_samsung_tablet() || is_sony_ericsson() || is_nintendo();
250 }
251
252 /***************************************************************
253 * Function is_mobile
254 * For detecting ANY mobile phone device
255 ***************************************************************/
256
257 function is_mobile() {
258 global $mobble_detect;
259 if ( is_tablet() ) return false;
260 return $mobble_detect->isMobile();
261 }
262
263 /***************************************************************
264 * Function is_ios
265 * For detecting ANY iOS/Apple device
266 ***************************************************************/
267
268 function is_ios() {
269 global $mobble_detect;
270 return $mobble_detect->isiOS();
271 }
272
273 /***************************************************************
274 * Function is_tablet
275 * For detecting tablet devices (needs work)
276 ***************************************************************/
277
278 function is_tablet() {
279 global $mobble_detect;
280 return $mobble_detect->isTablet();
281 }
282
283 /***************************************************************
284 * Function mobble_defaults
285 * Setup default settings on theme activation
286 ***************************************************************/
287
288 register_activation_hook( __FILE__, 'mobble_defaults' );
289
290 function mobble_defaults() {
291
292 $tmp = get_option( 'mobble_body_class' );
293 if ( ! $tmp ) { update_option( 'mobble_body_class', 1 ); }
294 }
295
296 /***************************************************************
297 * Function mobble_clean
298 * Remove options from WordPress table on deactivation
299 ***************************************************************/
300
301 register_deactivation_hook( __FILE__, 'mobble_clean' );
302
303 function mobble_clean() {
304 delete_option( 'mobble_body_class' );
305 }
306
307 /***************************************************************
308 * Functions mobble_menu, mobble_settings, mobble_register_settings
309 * Create an administration settings page within WordPress
310 ***************************************************************/
311
312 if ( is_admin() ) {
313 add_action( 'admin_menu', 'mobble_menu' );
314 add_action( 'admin_init', 'mobble_register_settings' );
315 }
316
317 function mobble_menu() {
318 add_options_page( 'mobble', 'mobble', 'administrator', __FILE__, 'mobble_settings' );
319 }
320
321 function mobble_settings() {
322
323 define( 'MOBBLE_IMAGES_URL', plugins_url( '/', __FILE__ ) );
324 ?>
325
326 <!-- flattr js -->
327 <script type="text/javascript">
328 /* <![CDATA[ */
329 (function() {
330 var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
331 s.type = 'text/javascript';
332 s.async = true;
333 s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
334 t.parentNode.insertBefore(s, t);
335 })();
336 /* ]]> */
337 </script>
338
339 <style type="text/css">
340 .FlattrButton { position: relative; top: 3px !important; }
341 .scottsweb-credit { padding: 10px 10px 10px 10px; background: #fff; border-bottom: 1px solid #e3e3e3; overflow: hidden; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px; }
342 .scottsweb-credit img { float: left; padding: 10px 11px 10px 5px; margin: 5px 5px 0 0; border-right: 1px solid #aaaaaa; }
343 .scottsweb-credit p { float: left; padding: 5px 0; margin: 0 0 0 8px;}
344 </style>
345
346 <div class="wrap">
347
348 <div class="icon32" id="icon-options-general"></div>
349
350 <h2>mobble</h2>
351
352 <form method="post" action="options.php">
353 <?php settings_fields( 'mobble-settings-group' ); ?>
354
355 <table class="form-table">
356 <tr valign="top">
357 <th scope="row"><?php _e( 'Mobify body class?', 'mobble' ); ?></th>
358 <td><label for="users_can_register"><input name="mobble_body_class" type="checkbox" id="mobble_body_class" value="1" <?php echo checked( 1, get_option( 'mobble_body_class' ), false ); ?> /><?php _e( '&nbsp;Add mobile information to your theme body class? e.g. &lt;body class="handheld android tablet"&gt;', 'mobble' ); ?></label> </td>
359 </tr>
360 </table>
361
362 <p class="submit">
363 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'mobble' ) ?>" />
364 </p>
365 </form>
366
367 <div class="scottsweb-credit">
368 <a href="http://scott.ee" title="Scott Evans - Web Designer &amp; WordPress developer"><img src="<?php echo MOBBLE_URL; ?>/scott.ee.png" alt="scott logo"/></a>
369 <p>Developed by <a href="http://scott.ee" title="Scott Evans - Web Designer and WordPress developer">Scott Evans</a>.<?php _e( "If you find this plugin useful I'd be flattered to be Flattr'd:", 'mobble' ); ?><br/><a class="FlattrButton" style="display:none; " rev="flattr;button:compact;" href="http://scott.ee/journal/mobble/"></a></p>
370 </div>
371
372 </div>
373 <?php
374 }
375
376 function mobble_register_settings() {
377 register_setting( 'mobble-settings-group', 'mobble_body_class' );
378 }
379
380 /***************************************************************
381 * Function mobble_body_class
382 * Add mobble info to the body class if activated in settings
383 ***************************************************************/
384
385 if ( ! is_admin() && get_option( 'mobble_body_class' ) ) {
386 add_filter( 'body_class', 'mobble_body_class' );
387 }
388
389 function mobble_body_class( $classes ) {
390
391 global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $mobble_detect;
392
393 // top level
394 if ( is_handheld() ) { $classes[] = "handheld"; };
395 if ( is_mobile() ) { $classes[] = "mobile"; };
396 if ( is_ios() ) { $classes[] = "ios"; };
397 if ( is_tablet() ) { $classes[] = "tablet"; };
398
399 // specific
400 if ( is_iphone() ) { $classes[] = "iphone"; };
401 if ( is_ipad() ) { $classes[] = "ipad"; };
402 if ( is_ipod() ) { $classes[] = "ipod"; };
403 if ( is_android() ) { $classes[] = "android"; };
404 if ( is_blackberry() ) { $classes[] = "blackberry"; };
405 if ( is_opera_mobile() ) { $classes[] = "opera-mobile";}
406 if ( is_webos() ) { $classes[] = "webos";}
407 if ( is_symbian() ) { $classes[] = "symbian";}
408 if ( is_windows_mobile() ) { $classes[] = "windows-mobile"; }
409 //if (is_lg()) { $classes[] = "lg"; }
410 if ( is_motorola() ) { $classes[] = "motorola"; }
411 //if (is_smartphone()) { $classes[] = "smartphone"; }
412 //if (is_nokia()) { $classes[] = "nokia"; }
413 if ( is_samsung() ) { $classes[] = "samsung"; }
414 if ( is_samsung_tablet() ) { $classes[] = "samsung-tablet"; }
415 if ( is_sony_ericsson() ) { $classes[] = "sony-ericsson"; }
416 if ( is_nintendo() ) { $classes[] = "nintendo"; }
417
418 // bonus
419 if ( ! is_handheld() ) { $classes[] = "desktop"; }
420
421 if ( $is_lynx ) { $classes[] = "lynx"; }
422 if ( $is_gecko ) { $classes[] = "gecko"; }
423 if ( $mobble_detect->is( 'Gecko' ) ) { $classes[] = "gecko"; }
424 if ( $is_opera ) { $classes[] = "opera"; }
425 if ( $mobble_detect->is( 'Opera' ) ) { $classes[] = "opera"; }
426 if ( $is_NS4 ) { $classes[] = "ns4"; }
427 if ( $is_safari ) { $classes[] = "safari"; }
428 if ( $mobble_detect->is( 'Safari' ) ) { $classes[] = "safari"; }
429 if ( $is_chrome ) { $classes[] = "chrome"; }
430 if ( $mobble_detect->is( 'Chrome' ) ) { $classes[] = "chrome"; }
431 if ( $is_IE ) { $classes[] = "ie"; }
432 if ( $mobble_detect->is( 'IE' ) ) { $classes[] = "ie"; }
433
434 return $classes;
435 }
436
437 /* fin */
438