function ($key, $params, $settings) { if (! isset($settings[$key])) { $settings[$key] = Geo::filterUrl('keyword'); } return $settings[$key]; }, 'position' => 2, ]; } }); if ($this->cron()) { return; } $this->initDevice(); if ($this->frontend()) { $this->middlewareAdd(\app\middleware\SubdomainsValidation::class, ['priority' => 20]); $this->middlewareAdd(\bff\middleware\Offline::class, ['priority' => 25]); $this->middlewareAdd(\bff\middleware\LoginAuto::class, ['priority' => 30]); $this->middlewareAdd(\bff\middleware\UserLastActivity::class, ['priority' => 35]); } } public function isIndex(): bool { return $this->router()->isCurrent('index'); } /** * Устанавливаем / получаем данные о фильтре * @param string $key ключ фильтра * @param array|NULL $data данные или NULL (получаем текущие) * @return mixed|void */ public function filterData(string $key, $data = null) { if (is_null($data)) { return config::get('filter-' . $key, []); } else { config::temp('filter-' . $key, $data); } } /** * Проверка / сохранение типа текущего устройства: * > if( bff::device(bff::DEVICE_DESKTOP) ) - проверяем текущее устройство = DESKTOP * > if( bff::device([bff::DEVICE_DESKTOP,bff::DEVICE_TABLET]) ) - проверяем текущее устройство = DESKTOP или TABLET * > $deviceID = bff::device() - получаем текущий тип устройства * > bff::device(bff::DEVICE_DESKTOP, true) - сохраняем тип текущего устройства * @param mixed $device ID устройства (self::DEVICE_), ID нескольких устройств или FALSE * @param bool $set true - сохраняем тип текущего устройства * @return bool|int|void */ public function device($device = 0, $set = false) { static $detected; $cookieKey = $this->cookieKey('device'); if (!$set) { # получаем тип устройства if (!isset($detected)) { $detected = $this->input()->cookie($cookieKey); if ( empty($detected) || !in_array($detected, [self::DEVICE_DESKTOP, self::DEVICE_TABLET, self::DEVICE_PHONE], true) ) { $detected = $this->deviceDetector(); } } if (!empty($device)) { 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, [self::DEVICE_DESKTOP, self::DEVICE_TABLET, self::DEVICE_PHONE], true) ) { $device = $this->deviceDetector(); } if ($device !== $this->input()->cookie($cookieKey)) { unset($detected); Response::setCookie($cookieKey, $device, 7/* days */); } } } public function businessEnabled(bool $onlyPublisher = false): bool { return $this->moduleExists('business') && ( ! Listings::publisher(Listings::PUBLISHER_USER) || (! $onlyPublisher && Business::categoriesEnabled()) ); } public function ordersEnabled() { return $this->pluginExists('orders') && $this->plugin('orders')->isEnabled(); } public function servicesEnabled(?string $moduleName = null): bool { # Enabled globally $setting = config::sysAdmin('services.enabled', true, TYPE_BOOL); if (! $setting) { return false; } $module = $this->moduleExists('svc'); if ($this->adminPanel()) { if ($module) { if ($moduleName) { # Any module active service registered return $this->filter('svc.service.active', false, $moduleName); } } return $module; } else { # Any module active service registered $active = $this->filter('svc.service.active', false, $moduleName); if ($module && $active) { # Any payway registered $list = Bills::getPayWaysList(false); return ! empty($list); } return false; } } /** * Подмена общих URL префиксов модулей * @param string $module название модуля * @param string $section дополнительное название секции * @param string $default значение по умолчанию * @return string */ public function urlPrefix($module, $section, $default) { return trim(config::sysAdmin($module . '.url.prefix.' . $section, $default), "/ \t\n\r\0\x0B"); } }