-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbff.php
More file actions
198 lines (172 loc) · 7.12 KB
/
bff.php
File metadata and controls
198 lines (172 loc) · 7.12 KB
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
<?php
# paths
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
require 'paths.php';
require PATH_CORE . 'init.php';
class bff extends \bff\base\app
{
static public $userSettings = 0;
/**
* Инициализация приложения
* @return void
*/
public function init()
{
# Инициализируем base\app
parent::init();
static::autoloadEx(array(
'User' => array('app', 'app/user.php'),
)
);
if (static::cron()) {
return;
}
# Yandex Карты 2.1
Geo::$ymapsCoordOrder = 'latlong';
Geo::$ymapsDefaultCoords = '40.178639,44.513479';
Geo::$ymapsJS = Request::scheme().'://api-maps.yandex.ru/2.1/?lang=ru_RU';
# подключаем Javascript + CSS
tpl::includeJS('jquery', true);
tpl::includeJS('bff', true, 3);
tpl::includeJS(array('bootstrap.min'), false);
if (!static::adminPanel()) {
# для фронтенда
js::setDefaultPosition(js::POS_FOOT); # переносим все инициализируемые inline-скрипты в footer
tpl::includeJS('app', false, 13);
self::$userSettings = static::DI('input')->cookie(config::sys('cookie.prefix') . 'usett');
} else {
# для админки
tpl::includeJS(array('admin/bff', 'fancybox'), true);
}
if (($userID = User::id())) {
# актуализируем "Время последней активности" пользователя
if ((BFF_NOW - func::SESSION('last_activity', 0)) >= config::sys('users.activity.timeout')) {
Users::model()->userSave($userID, false, array('last_activity' => static::DI('database')->now()));
func::setSESSION('last_activity', BFF_NOW);
}
# актуализируем счетчики пользователя
static::DI('security')->userCounter(null);
}
}
public static function isIndex()
{
return (self::$event == 'index' && self::$class == 'site');
}
/**
* Устанавливаем активный пункт меню
* @param string $sPath keyword пункта меню (sitemap)
* @param bool $bUpdateMeta обновить meta-данные
* @param mixed $mActiveStateData данные для активного пункта меню
*/
public static function setActiveMenu($sPath, $bUpdateMeta = true, $mActiveStateData = 1)
{
if (Request::isAJAX()) {
return;
}
$sPath = str_replace('//', '/main/', $sPath);
Sitemap::i()->setActiveMenuByPath($sPath, $bUpdateMeta, $mActiveStateData);
}
/**
* Устанавливаем / получаем данные о фильтре
* @param string $sKey ключ фильтра
* @param array|NULL $mData данные или NULL (получаем текущие)
* @return mixed
*/
public static function filter($sKey, $mData = null)
{
if (is_null($mData)) {
return config::get('filter-' . $sKey, array());
} else {
config::set('filter-' . $sKey, $mData);
}
}
/**
* Проверка / сохранение типа текущего устройства:
* > if( bff::device(bff::DEVICE_DESKTOP) ) - проверяем, является ли текущее устройство DESKTOP
* > if( bff::device(array(bff::DEVICE_DESKTOP,bff::DEVICE_TABLET)) ) - проверяем, является ли текущее устройство DESKTOP или TABLET
* > $deviceID = bff::device() - получаем текущий тип устройства
* > bff::device(bff::DEVICE_DESKTOP, true) - сохраняем тип текущего устройства
* @param string|array|bool $device ID устройства (self::DEVICE_), ID нескольких устройств или FALSE
* @param bool $set true - сохраняем тип текущего устройства
* @return bool|int
*/
public static function device($device = 0, $set = false)
{
static $detected;
$cookieKey = config::sys('cookie.prefix') . 'device';
# получаем тип устройства
if (!$set) {
if (!isset($detected)) {
$detected = static::input()->cookie($cookieKey, TYPE_STR);
if (empty($detected)) {
$detected = static::deviceDetector();
}
}
if (!empty($device)) {
# для desktop загружаем весь контент (эмулируем все устройства)
if (static::deviceDetector(self::DEVICE_DESKTOP)) {
return true;
}
return (is_string($device) ? $detected === $device :
(is_array($device) ? in_array($detected, $device, true) :
false));
} else {
return $detected;
}
} # устанавливаем тип устройства
else {
if (empty($device) || is_array($device) || !in_array($device, array(
self::DEVICE_DESKTOP,
self::DEVICE_TABLET,
self::DEVICE_PHONE
)
)
) {
$device = static::deviceDetector();
}
if ($device !== static::input()->cookie($cookieKey, TYPE_STR)) {
unset($detected);
setcookie($cookieKey, $device, time() + 604800, '/', '.' . SITEHOST);
$_COOKIE[$cookieKey] = $device;
}
}
}
public static function shopsEnabled()
{
return !BBS::publisher(BBS::PUBLISHER_USER);
}
public static function servicesEnabled()
{
if (bff::adminPanel()) {
return bff::moduleExists('svc', false);
} else {
return config::sys('services.enabled', false) && bff::moduleExists('svc', false);
}
}
public static function urlAway($sURL)
{
$sURL = str_replace(array('http://', 'https://', 'ftp://'), '', $sURL);
if (empty($sURL) || $sURL == '/') {
return static::urlBase();
}
return static::urlBase(false) . '/away/?url=' . rawurlencode($sURL);
}
public static function routeEx($req)
{
if (Geo::urlType() == Geo::URL_SUBDIR &&
$region = Geo::filterUrl('keyword')
) {
$req = str_replace($region . '/', '', $req);
}
return $req;
}
}
bff::i()->init();
# объявляем константы типа текущего устройства пользователя
define('DEVICE_DESKTOP', bff::device(bff::DEVICE_DESKTOP));
define('DEVICE_TABLET', bff::device(bff::DEVICE_TABLET));
define('DEVICE_PHONE', bff::device(bff::DEVICE_PHONE));
define('DEVICE_DESKTOP_OR_TABLET', DEVICE_DESKTOP || DEVICE_TABLET);
define('DEVICE_TABLET_OR_PHONE', DEVICE_TABLET || DEVICE_PHONE);