config('banners.enabled', true, TYPE_BOOL)) { return ''; } return $this->viewByPosition($positionKey, $settings); } /** * Переход по ссылке (клик на баннер) * @param int $id * @return \bff\http\Response */ public function click($id) { do { if (!$id) { break; } $banner = $this->model->banner($id); if (empty($banner)) { break; } $banner->clicked(); return $this->redirect($banner['click_url']); } while (false); return $this->redirect('/'); } /** * Показ баннера * @param int $id * @return \bff\http\Response */ public function show($id) { $filePath = ''; do { if (! $id) { break; } $banner = $this->model->banner($id); if (empty($banner)) { $id = 0; break; } if (in_array($banner['type'], [static::TYPE_CODE])) { $filePath = $this->defaultImagePath; } else { if ($banner['type'] == static::TYPE_IMAGE) { $device = bff::device(); $d = $this->deviceData($device); $img = $this->typeDataImg($banner, $d['id']); if (!empty($img)) { $filePath = $this->buildPath($id, $img, static::szView); if (!file_exists($filePath)) { $filePath = $this->buildPath($id, $img, static::szThumbnail); if (!file_exists($filePath)) { $filePath = $this->defaultImagePath; } } } } } } while (false); if (empty($filePath)) { $filePath = $this->defaultImagePath; } if ($id && $banner) { $banner->showed(); } return Response::image($filePath, 200, [ 'Expires' => 'Fri, 29 Jun 2000 14:30:00 GMT', 'Last-Modified' => date('r', filectime($filePath)), # always modified ]); } }