forked from IDT-media/mobiledetect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.mobiledetect.php
2217 lines (2000 loc) · 97.5 KB
/
function.mobiledetect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
*
* Copyright:
*
* IDT Media - Goran Ilic & Tapio Löytty
* Web: www.i-do-this.com
* Email: hi@i-do-this.com
*
*
* Author:
*
* Goran Ilic, <ja@ich-mach-das.at>
* Web: www.ich-mach-das.at
*
* License:
*-------------------------------------------------------------------------
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
*
* ------------------------------------------------------------------------- */
/**
* @package CMSMS
* Smarty {mobiledetect} function plugin
*
* Type: function
* Name: mobiledetect
* Purpose: Detect mobile devices based on results of Mobile_Detect Class
*
* @author Goran Ilic <ja@ich-mach-das.at>
* @param array $params parameters
* @param $smarty
* @return mixed
*/
function smarty_function_mobiledetect($params, &$smarty)
{
/* ---------------------------------------------
* Initial settings
* --------------------------------------------- */
// include devices
$includes = array();
if (isset($params['include'])) {
$includes = explode(',', $params['include']);
}
// exclude devices
$excludes = array();
if (isset($params['exclude'])) {
$excludes = explode(',', $params['exclude']);
}
$return = false;
// init detection classes
$detect = new Mobile_Detect();
$platform = new PlatformDetect();
/* ---------------------------------------------
* Run necessary checks
* --------------------------------------------- */
// it is mobile device
if ($detect->isMobile()) {
$return = true;
}
// switcher link was clicked, set session
if (isset($_GET['layout'])) {
$_SESSION['cmsms_layout'] = $_GET['layout'];
}
if (isset($_SESSION['cmsms_layout']) && $_SESSION['cmsms_layout'] == 'desktop') {
$return = false;
}
// check for excluded devices
foreach ($excludes as $exclude) {
$method = 'is' . ucfirst(strtolower(trim($exclude)));
if ($detect->$method()) {
$return = false;
}
}
// check for included devices
foreach ($includes as $include) {
$method = 'is' . ucfirst(strtolower(trim($include)));
if ($detect->$method()) {
$return = true;
break;
}
}
/* ---------------------------------------------
* Give available information to object
* --------------------------------------------- */
$device = new stdClass;
$device->ua = $detect->getUserAgent(); // user agent string
$device->grade = $detect->mobileGrade(); // grade string
$device->browser = $platform->getBrowser(); // browsername string
$device->os = $platform->getOperatingSystem(); // OS string
// get software version information - array
$device->version = array();
foreach ($detect->getProperties() as $name => $match) {
$check = $detect->version($name);
if ($check !== false) {
$device->version[] = $name . ' ' . $check;
}
}
if ($return == true) {
$device->type = $detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer'; // string
$device->isMobile = $detect->isMobile(); // it's mobile phone or tablet - bool (true|false)
$device->isTablet = $detect->isTablet(); // it's tablet - bool (true|false)
$device->isPhone = $detect->isMobile() ? ($detect->isTablet() ? false : true) : false; // it's phone - bool (true|false)
} else {
// it's not mobile device or user wants desktop version, reset everything to false
$device->type = 'computer';
$device->isMobile = false;
$device->isTablet = false;
$device->isPhone = false;
}
foreach ($detect->getRules() as $name => $regex) {
if ($return == true) {
$device->{'is' . $name} = $detect->{'is' . $name}(); // do dynamic checks - bool (true|false)
} else {
// user wants desktop version, reset everything to false
$device->{'is' . $name} = false;
}
}
/* ---------------------------------------------
* Smarty processing
* --------------------------------------------- */
// give object to smarty - mixed
$smarty->assign('device', $device);
}
/**
* @package CMSMS
* Smarty {mobileswitcher} function plugin
*
* Type: function
* Name: mobileswitcher
* Purpose: Creates a link or url based on Device detection and session depending on {mobiledetection} plugin
*
* @author Goran Ilic <ja@ich-mach-das.at>
* @param array $params parameters
* @param $smarty
* @return string
*/
function smarty_function_mobileswitcher($params, &$smarty)
{
/* ---------------------------------------------
* Initial settings
* --------------------------------------------- */
$detect = new Mobile_Detect();
$query_string = 'desktop';
$return = null;
// smarty params
$hrefonly = isset($params['hrefonly']) ? $params['hrefonly'] : 0;
$class = isset($params['class']) ? ' class="' . $params['class'] . '"' : 0;
$title = isset($params['title']) ? ' title="' . $params['title'] . '"' : 0;
$tabindex = isset($params['tabindex']) ? ' tabindex="' . $params['tabindex'] . '"' : 0;
$accesskey = isset($params['accesskey']) ? ' accesskey="' . $params['accesskey'] . '"' : 0;
$desktoptext = isset($params['desktoptext']) ? $params['desktoptext'] : 'Desktop version';
$mobiletext = isset($params['mobiletext']) ? $params['mobiletext'] : 'Mobile version';
/* ---------------------------------------------
* Check device and sessions and build url
* --------------------------------------------- */
$linktext = $desktoptext;
if (isset($_SESSION['cmsms_layout']) && $_SESSION['cmsms_layout'] == 'desktop') {
$query_string = 'mobile';
$linktext = $mobiletext;
}
$parms = array(
'layout' => $query_string
);
// show link only for mobile devices
if ($detect->isMobile() == true) {
if ($hrefonly) {
$return = switcherCreateURL($parms, $smarty);
} else {
$return = '<a href="' . switcherCreateURL($parms, $smarty) . '"' . $class . $title . $tabindex . $accesskey .'>' . $linktext . '</a>';
}
}
/* ---------------------------------------------
* Smarty processing
* --------------------------------------------- */
if (isset($params['assign'])) {
$smarty->assign($params['assign'], $return);
return;
}
$smarty->assign('linktext', $linktext);
return $return;
}
function smarty_cms_help_function_mobiledetect()
{
?>
<div id="page_tabs">
<div id="mobiledetect">
{mobiledetect}
</div>
<div id="mobileswitcher">
{mobileswitcher}
</div>
</div>
<div class="clearb"></div>
<div id="page_content">
<div id="mobiledetect_c">
<h3>Mobiledetect Plugin</h3>
<p>Mobiledetect plugin will perform a device detection based on Browser User Agent.</p>
<p>The plugin uses Mobile_Detect PHP class written by Serban Ghita for device detection. <br />
For more information about Mobile_Detect class you can visit <a rel="external" href="http://mobiledetect.net">mobiledetect.net</a> and
if you feel there is some detection missing, find a bug or would like to contribute to Mobile_Detect project, you can find
it on <a rel="external" href="https://github.com/serbanghita/Mobile-Detect">Github</a>.
</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like:</p>
<pre><code>{mobiledetect}</code></pre>
<p>Once <code>{mobiledetect}</code> tag has been placed in your Template or Page, various $device Smarty Object attributes will become available.<br />
With help of these Object attributes you can easily build a Template logic based on detected device.
</p>
<br />
<p><strong>Example:</strong></p>
<pre><code>{mobiledetect}
{if $device->isMobile}
<div class="mobile-class">
<p>We have found a Mobile device</p>
{if $device->isTablet}
<div class="only-tablet">
<p>This is a Tablet device</p>
</div>
{elseif $device->isPhone}
<div class="only-phone">
<p>This is Phone device and not Tablet</p>
</div>
{/if}
</div>
{/if}
</code></pre>
<br />
<h3>What parameters does it take?</h3>
<p>You can also use include or exclude parameters listed below. Don't use both at the same time.</p>
<ul>
<li><em>(optional)</em> <tt>include</tt> - A comma-separated list of mobile devices the data is intended for.</li>
<li><em>(optional)</em> <tt>exclude</tt> - A comma-separated list of mobile devices the data is not intended for. (Example exclude='tablet, asus')</li>
<li><em>(optional)</em> <tt>assign</tt> - Assign to a variable.</li>
</ul>
<h3>Available Smarty Object attributes</h3>
<table class="pagetable">
<thead>
<tr>
<th>Object attribute</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>{$device->type}</td>
<td>string (phone, tablet, computer)</td>
</tr>
<tr>
<td>{$device->ua}</td>
<td> string (User Agent information, Example: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36)</td>
</tr>
<tr>
<td>{$device->grade}</td>
<td>string (A, B or C)</td>
</tr>
<tr>
<td>{$device->browser}</td>
<td>string (Example: Chrome)</td>
</tr>
<tr>
<td>{$device->os}</td>
<td>string (Example: Windows 8)</td>
</tr>
<tr>
<td>{$device->version}</td>
<td>array (Example: Array ( [0] => Chrome 28.0.1500.72 [1] => Safari 537.36 [2] => Webkit 537.36 [3] => Windows NT 6.1))</td>
</tr>
<tr>
<td>{$device->isMobile}</td>
<td>bool (true/false)</td>
</tr>
<tr>
<td>{$device->isTablet}</td>
<td>bool (true/false)</td>
</tr>
<tr>
<td>{$device->isPhone}</td>
<td>bool (true/false)</td>
</tr>
<tr>
<td>{$device->isiPhone}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isBlackBerry}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isHTC}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isNexus}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isDell}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isMotorola}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSamsung}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isLG}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSony}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isAsus}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPalm}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isVertu}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPantech}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isFly}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSimValley}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isGenericPhone}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isiPad}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isNexusTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSamsungTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isKindle}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSurfaceTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isAsusTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isBlackBerryTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isHTCtablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isMotorolaTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isNookTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isAcerTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isToshibaTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isLGTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPrestigioTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isYarvikTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isMedionTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isArnovaTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isArchosTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isAinolTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSonyTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isCubeTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isCobyTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSMiTTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isRockChipTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isTelstraTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isFlyTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isbqTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isHuaweiTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isNecTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPantechTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isBronchoTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isVersusTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isZyncTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPositivoTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isNabiTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isKoboTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isDanewTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isTexetTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPlaystationTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isGalapadTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isGenericTablet}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isAndroidOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isBlackBerryOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPalmOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSymbianOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isWindowsMobileOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isWindowsPhoneOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isiOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isMeeGoOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isMaemoOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isJavaOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->iswebOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isbadaOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isBREWOS}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isChrome}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isDolfin}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isOpera}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSkyfire}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isIE}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isFirefox}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isBolt}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isTeaShark}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isBlazer}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isSafari}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isTizen}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isUCBrowser}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isDiigoBrowser}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isPuffin}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isMercury}</td>
<td>bool (true/false) </td>
</tr>
<tr>
<td>{$device->isGenericBrowser}</td>
<td>bool (true/false) </td>
</tr>
</tbody>
</table>
</div>
<div id="mobileswitcher_c">
<h3>What does this do?</h3>
<p>Mobileswitcher plugin will return a link or URL based on Device detection from Mobile_Detect php class, link is only shown if detected device is truly mobile device.<br />
Once link was clicked a session is created and $device Smarty Object attributes will be reset.</p>
<p>For exmaple if visitor visits your website with a mobile device and in your template you would be using<br />
a Object attribute <code>{$device->isMobile}</code> which in case of a mobile device would return <span style="color:red;">true</span>,<br />
after clicking on switcher link <code>{$device->isMobile}</code> would be reset to <span style="color:red;">false</span>.
</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like:</p>
<pre><code>{mobileswitcher}</code></pre><br />
<p>With assign parameter you can assign output of this plugin to a Smarty variable, which can be usefull if you want to apply some special layout around switching link<br />
but it does not apply to a desktop device, offcourse you could also simply use <code>{$device->isMobile}</code>, but there are many ways to skin the cat and there is also<br />
a <code>{$linktext}</code> Smarty variable available which can be usefull if you are using "hrefonly" parameter but still want to be able to control output of link text.
</p>
<pre><code>{mobileswitcher assign='switcher' hrefonly='1' desktoptext='Go to desktop layout' mobiletext='Go to mobile layout'}
{if $switcher}
<div class="switcher-wrapper">
<div class="some-nice-style">
<a class="my-switcher-link" href="{$switcher}">{$linktext}</a>
</div>
</div>
{/if}</code></pre>
<h3>What parameters does it take?</h3>
<ul>
<li><em>(optional)</em> <tt>hrefonly</tt> - Will return only URL instead of link. (Example hrefonly='1')</li>
<li><em>(optional)</em> <tt>class</tt> - Class that should be applied to link.</li>
<li><em>(optional)</em> <tt>title</tt> - Value for link title attribute.</li>
<li><em>(optional)</em> <tt>tabindex</tt> - Value for link tabindex attribute.</li>
<li><em>(optional)</em> <tt>accesskey</tt> - Value for link accesskey attribute.</li>
<li><em>(optional)</em> <tt>desktoptext</tt> - Link text that should be displayed for mobile devices. Example: desktoptext='Switch to desktop version'. (Default: Desktop version)</li>
<li><em>(optional)</em> <tt>mobiletext</tt> - Link text that should be displayed for desktop. Example: mobiletext='Switch to mobile version'. (Default: Mobile version)</li>
<li><em>(optional)</em> <tt>assign</tt> - Assign this tag to a Smarty variable.</li>
</ul>
</div>
<?php
}
function smarty_cms_about_function_mobiledetect()
{
?>
<p>Author: Goran Ilic <ja@ich-mach-das.at></p>
<p>Version: 1.0</p>
<p>
Change History:<br/>
None
</p>
<?php
}
/* ---------------------------------------------
* Functions
* --------------------------------------------- */
/**
* @package CMSMS
* Purpose: Creates a page url based on params
* @author Tapio Löytty tapsa@blackmilk.fi
* @param array $params parameters
* @param $smarty
* @return string
*/
function switcherCreateURL($params, &$smarty)
{
$config = cmsms()->GetConfig();
$page_url = '';
$_ignore_params = array(
$config['query_var']
);
$content_obj = cmsms()->get_variable('content_obj');
if (is_object($content_obj))
$page_url = $content_obj->GetURL();
if (count($params)) {
foreach ((array) $params as $key => $value) {
// Check against ignore list
if (in_array($key, $_ignore_params) || empty($value))
continue;
// Clean out key and value
$key = cms_htmlentities($key);
$value = cms_htmlentities($value);
// Add to URI
$query_string = strlen($_SERVER['QUERY_STRING']) > 0 ? '&' : '?';
$page_url .= $query_string . $key . '=' . rawurlencode($value);
}
}
return $page_url;
}
/** ---------------------------------------------
* PlatformDetect Class
* --------------------------------------------- */
/**
* @author Goran Ilic <ja@ich-mach-das.at>
*/
class PlatformDetect
{
private static $browser_names = array(
'/msie/i' => 'Internet Explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
'/chrome/i' => 'Chrome',
'/opera/i' => 'Opera',
'/netscape/i' => 'Netscape',
'/maxthon/i' => 'Maxthon',
'/konqueror/i' => 'Konqueror',
'/mobile/i' => 'Handheld Browser'
);
private static $operating_systems = array(
'/windows nt 6.2/i' => 'Windows 8',
'/windows nt 6.1/i' => 'Windows 7',
'/windows nt 6.0/i' => 'Windows Vista',
'/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
'/windows nt 5.1/i' => 'Windows XP',
'/windows xp/i' => 'Windows XP',
'/windows phone os|xblwp7|zunewp7/i' => 'Windows Phone',
'/macintosh|mac os x/i' => 'Mac OS X',
'/mac_powerpc/i' => 'Mac OS 9',
'/linux/i' => 'Linux',
'/ubuntu/i' => 'Ubuntu',
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
function getOperatingSystem($agent = null)
{
$agent = $_SERVER['HTTP_USER_AGENT'];
$operating_system = self::$operating_systems;
$os = null;
foreach ($operating_system as $regex => $value) {
// if UA matches return value
if (preg_match($regex, $agent)) {
$os = $value;
}
}
return $os;
}
function getBrowser($agent = null)
{
$agent = $_SERVER['HTTP_USER_AGENT'];
$browser = self::$browser_names;
$b = null;
foreach ($browser as $regex => $value) {
// if UA matches return value
if (preg_match($regex, $agent)) {
$b = $value;
}
}
return $b;
}
}
/**
* Mobile Detect Library
* =====================
*
* Motto: "Every business should have a mobile detection script to detect mobile readers"
*
* Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets).
* It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
*
* @author Current authors: Serban Ghita <serbanghita@gmail.com>
* Nick Ilyin <nick.ilyin@gmail.com>
*
* Original author: Victor Stanciu <vic.stanciu@gmail.com>
*
* @license Code and contributions have 'MIT License'
* More details: https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
*
* @link Homepage: http://mobiledetect.net
* GitHub Repo: https://github.com/serbanghita/Mobile-Detect
* Google Code: http://code.google.com/p/php-mobile-detect/
* README: https://github.com/serbanghita/Mobile-Detect/blob/master/README.md
* HOWTO: https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples
*
* @version 2.8.14
*/
class Mobile_Detect
{
/**
* Mobile detection type.
*
* @deprecated since version 2.6.9
*/
const DETECTION_TYPE_MOBILE = 'mobile';
/**
* Extended detection type.
*
* @deprecated since version 2.6.9
*/
const DETECTION_TYPE_EXTENDED = 'extended';
/**
* A frequently used regular expression to extract version #s.
*
* @deprecated since version 2.6.9
*/
const VER = '([\w._\+]+)';
/**
* Top-level device.
*/
const MOBILE_GRADE_A = 'A';
/**
* Mid-level device.
*/
const MOBILE_GRADE_B = 'B';
/**
* Low-level device.
*/
const MOBILE_GRADE_C = 'C';
/**
* Stores the version number of the current release.
*/
const VERSION = '2.8.14';
/**
* A type for the version() method indicating a string return value.
*/
const VERSION_TYPE_STRING = 'text';
/**
* A type for the version() method indicating a float return value.
*/
const VERSION_TYPE_FLOAT = 'float';
/**
* A cache for resolved matches
* @var array
*/
protected $cache = array();
/**
* The User-Agent HTTP header is stored in here.
* @var string
*/
protected $userAgent = null;
/**
* HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE.
* @var array
*/
protected $httpHeaders = array();
/**
* The matching Regex.
* This is good for debug.
* @var string
*/
protected $matchingRegex = null;
/**
* The matches extracted from the regex expression.
* This is good for debug.
* @var string
*/
protected $matchesArray = null;
/**
* The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED.
*
* @deprecated since version 2.6.9
*
* @var string
*/
protected $detectionType = self::DETECTION_TYPE_MOBILE;
/**
* HTTP headers that trigger the 'isMobile' detection
* to be true.
*
* @var array
*/
protected static $mobileHeaders = array(
'HTTP_ACCEPT' => array('matches' => array(
// Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/
'application/x-obml2d',
// BlackBerry devices.
'application/vnd.rim.html',
'text/vnd.wap.wml',
'application/vnd.wap.xhtml+xml'
)),
'HTTP_X_WAP_PROFILE' => null,
'HTTP_X_WAP_CLIENTID' => null,
'HTTP_WAP_CONNECTION' => null,