Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agent.php
1<?php
9
13
14Loc::loadMessages(__FILE__);
15
20class Agent extends ClassConstant
21{
22 const UNDEFINED = 0;
23 const GMAIL = 1;
24 const IPHONE = 2;
25 const IPAD = 3;
26 const ANDROID = 4;
27 const OUTLOOK = 5;
28 const THUNDERBIRD = 6;
29 const YANDEX = 7;
30
37 public static function detect($string = null)
38 {
39 if (!$string)
40 {
41 $string = Context::getCurrent()->getRequest()->getUserAgent();
42 }
43
44 $string = mb_strtolower($string);
45 $rules = self::getRules();
46 foreach ($rules as $id => $searchList)
47 {
48 foreach ($searchList as $search)
49 {
50 if (mb_strpos($string, $search) === false)
51 {
52 continue;
53 }
54
55 return $id;
56 }
57 }
58
59 return self::UNDEFINED;
60 }
61
68 public static function getName($id)
69 {
70 $code = self::getCode($id);
71 $name = Loc::getMessage('SENDER_AGENT_CAPTION_' . $code) ?: $code;
72 return $name;
73 }
74
80 protected static function getRules()
81 {
82 $rules = array(
83 self::GMAIL => array('googleimageproxy'),
84 self::IPHONE => array('iphone'),
85 self::IPAD => array('ipad'),
86 self::ANDROID => array('android'),
87 self::OUTLOOK => array('outlook'),
88 self::THUNDERBIRD => array('thunderbird'),
89 self::YANDEX => array('yandex'),
90 );
91
92 return $rules;
93 }
94}
static getCurrent()
Definition context.php:241
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static detect($string=null)
Definition agent.php:37