Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
agent.php
1
<?php
8
namespace
Bitrix\Sender\Recipient
;
9
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Main\Context
;
12
use
Bitrix\Sender\Internals\ClassConstant
;
13
14
Loc::loadMessages
(__FILE__);
15
20
class
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
}
Bitrix\Main\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sender\Internals\ClassConstant
Definition
classconstant.php:20
Bitrix\Sender\Internals\ClassConstant\getCode
static getCode($id)
Definition
classconstant.php:157
Bitrix\Sender\Recipient\Agent
Definition
agent.php:21
Bitrix\Sender\Recipient\Agent\ANDROID
const ANDROID
Definition
agent.php:26
Bitrix\Sender\Recipient\Agent\IPAD
const IPAD
Definition
agent.php:25
Bitrix\Sender\Recipient\Agent\detect
static detect($string=null)
Definition
agent.php:37
Bitrix\Sender\Recipient\Agent\IPHONE
const IPHONE
Definition
agent.php:24
Bitrix\Sender\Recipient\Agent\getName
static getName($id)
Definition
agent.php:68
Bitrix\Sender\Recipient\Agent\YANDEX
const YANDEX
Definition
agent.php:29
Bitrix\Sender\Recipient\Agent\getRules
static getRules()
Definition
agent.php:80
Bitrix\Sender\Recipient\Agent\THUNDERBIRD
const THUNDERBIRD
Definition
agent.php:28
Bitrix\Sender\Recipient\Agent\UNDEFINED
const UNDEFINED
Definition
agent.php:22
Bitrix\Sender\Recipient\Agent\GMAIL
const GMAIL
Definition
agent.php:23
Bitrix\Sender\Recipient\Agent\OUTLOOK
const OUTLOOK
Definition
agent.php:27
Bitrix\Main\Context
Definition
culture.php:9
Bitrix\Sender\Recipient
Definition
agent.php:8
modules
sender
lib
recipient
agent.php
Создано системой
1.10.0