�PNG  IHDR��;���IDATx��ܻn�0���K�� �)(�pA��� ���7�LeG{�� �§㻢|��ذaÆ 6lذaÆ 6lذaÆ 6lom��$^�y���ذag�5bÆ 6lذaÆ 6lذa{���� 6lذaÆ �`����}H�Fkm�,�m����Ӫ���ô�ô!� �x�|'ܢ˟;�E:���9�&ᶒ�}�{�v]�n&�6� �h��_��t�ڠ͵-ҫ���Z;��Z$�.�P���k�ž)�!��o���>}l�eQfJ�T��u і���چ��\��X=8��Rن4`Vw�l�>����n�G�^��i�s��"ms�$�u��i��?w�bs[m�6�K4���O���.�4��%����/����b�C%��t ��M�ז� �-l�G6�mrz2���s�%�9��s@���-�k�9�=���)������k�B5����\��+͂�Zsٲ ��Rn��~G���R���C����� �wIcI��n7jJ���hۛNCS|���j0��8y�iHKֶۛ�k�Ɉ+;Sz������L/��F�*\��Ԕ�#"5��m�2��[S��������=�g��n�a�P�e�ғ�L�� lذaÆ 6l�^k��̱aÆ 6lذaÆ 6lذa;���� �_��ذaÆ 6lذaÆ 6lذaÆ ���R���IEND�B` request = $request; $this->config = $config; $this->except = $config['except']; $this->via($this->config['default']); $this->setVisitor($request->user()); } /** * Change the driver on the fly. * * @param $driver * * @return $this * * @throws \Exception */ public function via($driver) { $this->driver = $driver; $this->validateDriver(); return $this; } /** * Retrieve request's data * * @return array */ public function request() : array { return $this->request->all(); } /** * Retrieve user's ip. * * @return string|null */ public function ip() : ?string { return $this->request->ip(); } /** * Retrieve request's url * * @return string */ public function url() : string { return $this->request->fullUrl(); } /** * Retrieve request's referer * * @return string|null */ public function referer() : ?string { return $_SERVER['HTTP_REFERER'] ?? null; } /** * Retrieve request's method. * * @return string */ public function method() : string { return $this->request->getMethod(); } /** * Retrieve http headers. * * @return array */ public function httpHeaders() : array { return $this->request->headers->all(); } /** * Retrieve agent. * * @return string */ public function userAgent() : string { return $this->request->userAgent() ?? ''; } /** * Retrieve device's name. * * @return string * * @throws \Exception */ public function device() : string { return $this->getDriverInstance()->device(); } /** * Retrieve platform's name. * * @return string * * @throws \Exception */ public function platform() : string { return $this->getDriverInstance()->platform(); } /** * Retrieve browser's name. * * @return string * * @throws \Exception */ public function browser() : string { return $this->getDriverInstance()->browser(); } /** * Retrieve languages. * * @return array * * @throws \Exception */ public function languages() : array { return $this->getDriverInstance()->languages(); } /** * Set visitor (user) * * @param Model|null $user * * @return $this */ public function setVisitor(?Model $user) { $this->visitor = $user; return $this; } /** * Retrieve visitor (user) * * @return Model|null */ public function getVisitor() : ?Model { return $this->visitor; } /** * Create a visit log. * * @param Model $model */ public function visit(Model $model = null) { $data = $this->prepareLog(); if(in_array($this->request->path(),$this->except)){ unset($data['request']); } if (null !== $model && method_exists($model, 'visitLogs')) { $visit = $model->visitLogs()->create($data); } else { $visit = Visit::create($data); } return $visit; } /** * Retrieve online visitors. * * @param string $model * @param int $seconds */ public function onlineVisitors(string $model, $seconds = 180) { return app($model)->online()->get(); } /** * Determine if given visitor or current one is online. * * @param Model|null $visitor * @param int $seconds * * @return bool */ public function isOnline(?Model $visitor = null, $seconds = 180) { $time = now()->subSeconds($seconds); $visitor = $visitor ?? $this->getVisitor(); if (empty($visitor)) { return false; } return Visit::whereHasMorph('visitor', get_class($visitor), function ($query) use ($visitor, $time) { $query->where('visitor_id', $visitor->id); })->whereDate('created_at', '>=', $time)->count() > 0; } /** * Prepare log's data. * * @return array * * @throws \Exception */ protected function prepareLog() : array { return [ 'method' => $this->method(), 'request' => $this->request(), 'url' => $this->url(), 'referer' => $this->referer(), 'languages' => $this->languages(), 'useragent' => $this->userAgent(), 'headers' => $this->httpHeaders(), 'device' => $this->device(), 'platform' => $this->platform(), 'browser' => $this->browser(), 'ip' => $this->ip(), 'visitor_id' => $this->getVisitor() ? $this->getVisitor()->id : null, 'visitor_type' => $this->getVisitor() ? get_class($this->getVisitor()): null ]; } /** * Retrieve current driver instance or generate new one. * * @return mixed|object * * @throws \Exception */ protected function getDriverInstance() { if (!empty($this->driverInstance)) { return $this->driverInstance; } return $this->getFreshDriverInstance(); } /** * Get new driver instance * * @return Driver * * @throws \Exception */ protected function getFreshDriverInstance() { $this->validateDriver(); $driverClass = $this->config['drivers'][$this->driver]; return app($driverClass); } /** * Validate driver. * * @throws \Exception */ protected function validateDriver() { if (empty($this->driver)) { throw new DriverNotFoundException('Driver not selected or default driver does not exist.'); } $driverClass = $this->config['drivers'][$this->driver]; if (empty($driverClass) || !class_exists($driverClass)) { throw new DriverNotFoundException('Driver not found in config file. Try updating the package.'); } $reflect = new \ReflectionClass($driverClass); if (!$reflect->implementsInterface(UserAgentParser::class)) { throw new \Exception("Driver must be an instance of Contracts\Driver."); } } }