public static function cc($request, $action, $option = []) { $agent = new Agent(); $platform = $agent->platform(); $platform_v = $agent->version($platform); $browser = $agent->browser(); $browser_v = $agent->version($browser); $device = $agent->device(); $charge_fee = 0; $charge_diamond = 0; $charge_datas = ''; $charge_explanation = ''; switch ($action) { case 'charge': $charge_fee = $option['fee']; $charge_diamond = $charge_fee * 1; $charge_explanation = '您于' . date('Y-m-d H:i:s') . '充值了 ¥' . $charge_fee . ' 获得了 ' . $charge_diamond . '颗勤云石'; break; case 'consume:vip': $charge_diamond = -60; $charge_datas = $option['datas']; $charge_explanation = '您于' . date('Y-m-d H:i:s') . '消费了 ' . $charge_diamond . '颗勤云石,购买了VIP会员' . $charge_datas . '个月'; break; case 'bequeath:signup': $charge_diamond = 18; $charge_explanation = '感谢您与' . date('Y-m-d H:i:s') . '注册本网站,系统自动赠送您' . $charge_diamond . '颗宝石'; break; case 'bequeath:invited': $charge_diamond = 18; $charge_explanation = '感谢您分享了本网站的注册链接给好友,好友已经注册本网站,系统自动赠送您' . $charge_diamond . '颗宝石'; break; } return self::create(['charge_cuid' => isset($option['userCreated']) ? $option['userCreated']->user_id : 0, 'charge_ruid' => $option['userRelated']->user_id, 'charge_action' => $action, 'charge_datas' => $charge_datas, 'charge_diamond' => $charge_diamond, 'charge_fee' => $charge_fee, 'charge_explanation' => $charge_explanation, 'charge_ip' => ip2long($request->ip()), 'charge_device' => $device, 'charge_system' => $platform, 'charge_system_v' => $platform_v, 'charge_browser' => $browser, 'charge_browser_v' => $browser_v]); }
public function postAdd(Request $request, Agent $agent) { $data = $request->all(); $validation = Validator::make($data, Poster::getValidationRules()); if ($validation->fails()) { return view('message', ['OKs' => [], 'errors' => $validation->errors()->all()]); } $original_image_dir = 'images/original/'; $small_image_dir = 'images/small/'; $original_image_name = $original_image_dir . "no_image.jpg"; $small_image_name = $small_image_dir . "no_image_sml.jpg"; if ($request->hasFile('image')) { $time = time(); $original_image_name = $original_image_dir . $time . '.jpg'; $small_image_name = $small_image_dir . $time . '.jpg'; Image::make(Input::file('image'))->save($original_image_name)->resize(200, null, function ($constraint) { $constraint->aspectRatio(); })->save($small_image_name); } else { } $data['image'] = $original_image_name; $data['image_sml'] = $small_image_name; $data['author_ip'] = $request->getClientIp(); $data['author_browser'] = $agent->browser(); $data['author_country'] = "Ukraine"; Poster::create($data); return view('message', array('OKs' => ['Poster created'], 'errors' => [''])); }
public static function cc($request, $user, $action) { $agent = new Agent(); $platform = $agent->platform(); $platform_v = $agent->version($platform); $browser = $agent->browser(); $browser_v = $agent->version($browser); $device = $agent->device(); switch ($action) { case 'login': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '进行登录操作'; break; case 'logout': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '进行登出操作'; break; case 'signup': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '注册本网站'; break; case 'user:confirm': $mylog_content = $user->user_email . '于' . date('Y-m-d H:i:s') . '进行用户验证'; break; case 'user:password_update': $mylog_content = date('Y-m-d H:i:s') . ' 修改了账号密码'; break; default: $mylog_content = ''; break; } return self::create(['mylog_cuid' => $user->user_id, 'mylog_action' => $action, 'mylog_content' => $mylog_content, 'mylog_ip' => ip2long($request->ip()), 'mylog_device' => $device, 'mylog_system' => $platform, 'mylog_system_v' => $platform_v, 'mylog_browser' => $browser, 'mylog_browser_v' => $browser_v]); }
public function getUA() { // Initialize UA $agent = new Agent(); $browser = $agent->browser(); // Assemble data $data = ['browser' => $browser, 'browser_version' => $agent->version($browser), 'languages' => array($agent->languages()), 'device' => $agent->device(), 'platform' => $agent->platform(), 'is_mobile' => $agent->isMobile(), 'is_tablet' => $agent->isTablet(), 'is_desktop' => $agent->isDesktop(), 'is_robot' => $agent->isRobot(), 'robot_name' => $agent->robot()]; return $data; }
public function testBrowsers() { $agent = new Agent(); foreach ($this->browsers as $browser => $ua) { $agent->setUserAgent($ua); $this->assertTrue($agent->is($browser), $browser); $this->assertEquals($browser, $agent->browser()); if (!strpos($browser, ' ')) { $method = "is{$browser}"; $this->assertTrue($agent->{$method}()); } } }
public function testVersions() { $agent = new Agent(); foreach ($this->browserVersions as $version => $ua) { $agent->setUserAgent($ua); $browser = $agent->browser(); $this->assertEquals($version, $agent->version($browser)); } foreach ($this->operatingSystemVersions as $version => $ua) { $agent->setUserAgent($ua); $platform = $agent->platform(); $this->assertEquals($version, $agent->version($platform)); } }
public function postFSave(FSavePRequest $request, $user_email, $form_url) { $user = User::where('user_email', base64_decode($user_email))->where('user_active', '1')->firstOrFail(); $form = $user->Form()->where('form_url', $form_url)->where('form_active', 1)->firstOrFail(); if (!$form->canWrite()) { return redirect()->back()->with('msgError', '表单已经超过填写人数的最大限制了'); } $agent = new Agent(); $platform = $agent->platform(); $platform_v = $agent->version($platform); $browser = $agent->browser(); $browser_v = $agent->version($browser); $device = $agent->device(); $result = Result::create(['result_ruid' => Auth::check() ? Auth::id() : 0, 'result_form_id' => $form->form_id, 'result_ip' => ip2long($request->ip()), 'result_device' => $device, 'result_system' => $platform, 'result_system_v' => $platform_v, 'result_browser' => $browser, 'result_browser_v' => $browser_v]); if ($result) { //插入数据 $fields = $form->Field()->orderBy('field_sort', 'ASC')->get(); $splitStr = ':$split$:'; $user_id = Auth::check() ? Auth::id() : 0; foreach ($fields as $field) { $inputs = $request->input($field->field_attr_name); if (is_array($inputs)) { if ($field->field_type == 'group:shop-thumbnail') { $rows = []; foreach ($inputs as $input) { $rows[] = $input['goods_name'] . '(' . $input['goods_preice'] . '):' . $input['goods_num']; } $resultrow_attr_value = implode($splitStr, $rows); } else { $resultrow_attr_value = implode($splitStr, $inputs); } } else { $resultrow_attr_value = $inputs; } ResultRow::create(['resultrow_ruid' => $user_id, 'resultrow_result_id' => $result->result_id, 'resultrow_sort' => $field->field_sort, 'resultrow_type' => $field->field_type, 'resultrow_title' => $field->field_title, 'resultrow_tips' => $field->field_tips, 'resultrow_attr_name' => $field->field_attr_name, 'resultrow_attr_value' => $resultrow_attr_value]); } // 发送邮件提示 if ($form->form_tips_email) { $email = Email::create(['email_cuid' => 0, 'email_ruid' => $user->user_id, 'email_block' => 'form_reply_tips', 'email_target' => $user->user_email, 'email_title' => '[ ' . WEBSITE_NAME . ' ]提示您:您的表单有了新的回复', 'email_datas' => $form->form_code, 'email_is_sent' => 0]); $this->dispatch(new SendReminderEmail($email)); } $res = redirect('/u/' . $user_email . '/f-success')->with('msgSuccess', '您的表单已经成功提交,感谢您的参与。'); } else { $res = redirect()->back()->with('msgError', MSG_FA); } return $res; }
/** * Redirect to long url * @return rediect to long url */ public function redirect(Request $request, $shortUrl) { $agent = new Agent(); $agent->setUserAgent($request->headers); $urls = Url::where('short_url', '=', $shortUrl)->get(); if (!$urls->first()) { echo "Not Found"; return; } $url = $urls[0]; $longUrl = $url['long_url']; $url->clicks = $url['clicks'] + 1; $url->save(); $url->hits()->create(['client_ip' => $_SERVER['REMOTE_ADDR'], 'language' => $agent->languages()[0], 'device' => $agent->device(), 'platform' => $agent->platform(), 'browser' => $agent->browser()]); //$agent->languages()[0],$agent->device(), $agent->platform(),$agent->browser(),$agent->robot();;;; return redirect($url['long_url']); }
public function store($inputs) { $contact = new $this->model(); $contact->name = $inputs['name']; $contact->email = $inputs['email']; $contact->text = $inputs['message']; $contact->ip = \Request::ip(); $agent = new Agent(); $lang = $agent->languages(); $lang = implode(",", $lang); $platform = $agent->platform(); $version_p = $agent->version($platform); $device = $agent->device(); $browser = $agent->browser(); $version_b = $agent->version($browser); $contact->agent = $platform . $version_p . "|" . $device . "|" . $browser . $version_b . "|" . $lang; $contact->save(); }
public function insertUserInformation($ipAddress, $userAgentString, $sapiName, GeocoderResult $geocoderResult = null) { $userAgent = new UserAgent(); $userAgent->setUserAgent($userAgentString); $browser = $userAgent->browser(); $platform = $userAgent->platform(); $data = ['ip_address' => $ipAddress, 'sapi_name' => substr($sapiName, 0, 32), 'user_agent' => substr($userAgentString, 0, 255), 'user_agent_browser' => substr($browser, 0, 32), 'user_agent_device' => substr($userAgent->device(), 0, 32), 'user_agent_browser_version' => substr($userAgent->version($browser), 0, 32), 'user_agent_platform_version' => substr($userAgent->version($platform), 0, 32), 'user_agent_platform' => substr($platform, 0, 32), 'user_agent_robot' => substr($userAgent->robot(), 0, 32)]; if ($geocoderResult) { $region = $geocoderResult->getAdminLevels()->first(); $data['geo_city'] = substr($geocoderResult->getLocality(), 0, 32); $data['geo_region'] = $region ? substr($region->getCode(), 0, 32) : null; $data['geo_country'] = substr($geocoderResult->getCountry(), 0, 32); $data['geo_country_code'] = substr($geocoderResult->getCountryCode(), 0, 6); $data['geo_latitude'] = substr($geocoderResult->getLatitude(), 0, 32); $data['geo_longitude'] = substr($geocoderResult->getLongitude(), 0, 32); } $this->getAdapter()->insert('dewdrop_activity_log_user_information', $data); return $this->getAdapter()->lastInsertId(); }
public static function saveSession() { $session_id = uniqid(); Session::put('session_id', $session_id); $agent = new Agent(); $browser = $agent->browser(); $version = $agent->version($browser); $platform = $agent->platform(); $versionpla = $agent->version($platform); $device = $agent->device(); $session = new SaveSession(); $session->browser = $browser; $session->version = $version; $session->platform = $browser; $session->versionpla = $versionpla; $session->device = $device; //$session->ip = $request->ip; $session->cookie = $session_id; $session->save(); }
public function RegisterVisit() { $agent = new Agent(); $browser = $agent->browser(); $version = $agent->version($browser); $platform = $agent->platform(); $pversion = $agent->version($platform); $browserString = $browser . ' version ' . $version . ' | ' . $platform . ' version ' . $pversion; $visit = $this->getVisitsRepository()->create(['url' => Request::url(), 'ip' => Request::ip(), 'browser' => $browserString]); }
$counters['referrers'][] = array("value" => $item['c'], 'label' => $key); } // get origin $list = $logdb->query("SELECT origin, count(*) as c FROM tracker WHERE origin !='-' GROUP BY origin"); foreach ($list->fetchAll(PDO::FETCH_ASSOC) as $item) { $key = !empty($item['origin']) ? $item['origin'] : 'unkwn'; $counters['origins'][] = array("value" => $item['c'], 'label' => $key); } $br = array(); $os = array(); // get agents $list = $logdb->query("SELECT browser, count(*) as c FROM tracker GROUP BY browser"); foreach ($list->fetchAll(PDO::FETCH_ASSOC) as $item) { // echo $item['browser']; $agent->setUserAgent($item['browser']); $browser = $agent->browser(); $platform = $agent->platform(); // echo $agent->platform(); // echo $agent->browser(); $key = !empty($browser) ? $browser : 'unkwn'; if (!array_key_exists($key, $br)) { $br[$key] = 0; } $br[$key] += $item['c']; $key = !empty($platform) ? $platform : 'unkwn'; if (!array_key_exists($key, $os)) { $os[$key] = 0; } $os[$key] += $item['c']; } foreach ($br as $k => $v) {
/** * Redirects to Original Url */ public function redirect(Request $request, $shortUrl) { // Initiate Agent object for parsing header information $agent = new Agent(); // Setting header to agent $agent->setUserAgent($request->headers); // Query the url object from DB by shortUrl column $urls = Url::where('short_url', '=', config('app.url') . '/' . $shortUrl)->get(); // Check whether Url object exists if (!$urls->first()) { $error = Utility::getError(null, 404, 'Error', 'Url Not Found'); return response()->json($error, 404); } // get the queried url from collection $url = $urls[0]; // Get the long_url value for managing query string $longUrl = $url['long_url']; try { // Generate a version 1 (time-based) UUID object if (!isset($_COOKIE['_id'])) { $cookieUuid1 = Uuid::uuid1(); setcookie('_id', $cookieUuid1->toString(), time() + 10 * 365 * 24 * 3600, "/"); } else { $cookieUuid1 = $_COOKIE['_id']; } if (!isset($_COOKIE['_sid'])) { $sessionUuid1 = Uuid::uuid1(); setcookie('_sid', $sessionUuid1->toString(), 0, "/"); } else { $sessionUuid1 = $_COOKIE['_sid']; } } catch (UnsatisfiedDependencyException $e) { $error = Utility::getError($e, 500, 'Error', 'Please try again...'); return response()->json($error, 500); } // Default value of Http Referrer for saving into db $httpReferrer = 'Undefined'; // If Http referrer exists, replace the default value by it if (!empty($_SERVER['HTTP_REFERER'])) { $httpReferrer = $_SERVER['HTTP_REFERER']; } try { $city = Utility::getCity($_SERVER["REMOTE_ADDR"]); $state = Utility::getState($_SERVER["REMOTE_ADDR"]); $country = Utility::getCountry($_SERVER["REMOTE_ADDR"]); $countryIsoCode = strtolower(Utility::getCountryIsoCode($_SERVER["REMOTE_ADDR"])); } catch (AddressNotFoundException $e) { // Make logging for AddressNotFoundException exception //Utility::log($e); $city = ''; $state = ''; $country = ''; $countryIsoCode = ''; } // Increment clicks column by one $url->clicks = $url['clicks'] + 1; // Save the url instance $url->save(); // create the new Hit instance for the url instance $url->hits()->create(['client_ip' => $_SERVER['REMOTE_ADDR'], 'language' => $agent->languages()[0], 'device' => $agent->device(), 'platform' => $agent->platform(), 'browser' => $agent->browser(), 'cookie_id' => $cookieUuid1, 'session_id' => $sessionUuid1, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrers' => $httpReferrer, 'remote_addr' => $_SERVER["REMOTE_ADDR"], 'remote_port' => $_SERVER["REMOTE_PORT"], 'remote_method' => $_SERVER["REQUEST_METHOD"], 'city' => $city, 'state' => $state, 'country' => $country, 'country_iso_code' => $countryIsoCode]); // Get all query parameter of short url $shortQuery = $request->all(); // Get all url parameter of long url $parsedLongUrl = parse_url($longUrl); // Code for merging query parameter of short Url and long Url keeping the short url as prior // Redirect to the original Url if (isset($parsedLongUrl["query"])) { parse_str($parsedLongUrl["query"], $longQuery); $commonKeys = array_intersect_key($longQuery, $shortQuery); $finalQuery = array_diff($shortQuery, $commonKeys) + array_diff($longQuery, $commonKeys) + $commonKeys; if (isset($parsedLongUrl['port'])) { return redirect($parsedLongUrl['scheme'] . '://' . $parsedLongUrl['host'] . ':' . $parsedLongUrl['port'] . $parsedLongUrl['path'] . '?' . http_build_query($finalQuery)); } else { return redirect($parsedLongUrl['scheme'] . '://' . $parsedLongUrl['host'] . $parsedLongUrl['path'] . '?' . http_build_query($finalQuery)); } } else { if (empty($shortQuery)) { return redirect($longUrl); } else { return redirect($longUrl . '?' . http_build_query($shortQuery)); } } }
public static function parse($userAgentString) { $browser = new UserAgentLib(); $browser->setUserAgent($userAgentString); return array('os' => $browser->platform(), 'name' => $browser->browser(), 'version' => $browser->version($browser->browser())); }
/** * Record the visitation. * * @param Request $request * @author Cali */ public static function visited(Request $request) { $userAgent = new Agent(); $location = Location::get(); static::create(['referer' => url()->previous(), 'uri' => $request->path(), 'browser' => $userAgent->browser(), 'platform' => $userAgent->platform(), 'device' => $userAgent->device(), 'mobile' => !$userAgent->isDesktop(), 'ip' => $location->ip, 'country' => $location->isoCode, 'city' => $location->cityName, 'robot' => $userAgent->isRobot() ? $userAgent->robot() : null, 'user_id' => $request->user() ? $request->user()->id : null]); }
private function getBrowser() { $agent = new Agent(); $browser = $agent->browser(); $platform = $agent->platform(); $data = array('name' => $browser, 'version' => $agent->version($browser), 'platform' => $platform, 'platformVersion' => $agent->version($platform), 'device' => $agent->device()); return $data; }
private function getBodyClass() { $agent = new Agent(); $browser_css_classes = array(); $unsupported = []; if ($mobile = $agent->isMobile()) { $browser_css_classes[] = 'device-mobile'; } if ($tablet = $agent->isTablet()) { $browser_css_classes[] = 'device-tablet'; } if ($iphone = $agent->is('iPhone')) { $browser_css_classes[] = 'device-iphone'; } if ($ipad = $agent->is('iPad')) { $browser_css_classes[] = 'device-ipad'; } $other_browser = $agent->browser(); if ($agent->browser() == "Safari") { $other_browser = false; $browser_css_classes[] = 'browser-safari'; if ($agent->version('Safari') < 5) { $unsupported['browser'] = 'Safari'; } } if ($agent->browser() == "Chrome") { $other_browser = false; $browser_css_classes[] = 'browser-chrome'; $browser_css_classes[] = 'browser-chrome-' . (int) $agent->version('Chrome'); if ($agent->version('Chrome') < 30) { $unsupported['browser'] = 'Chrome'; } } if ($agent->browser() == "Firefox") { $other_browser = false; $browser_css_classes[] = 'browser-firefox'; $browser_css_classes[] = 'browser-firefox-' . (int) $agent->version('Firefox'); if ($agent->version('Firefox') < 25) { $unsupported['browser'] = 'Firefox'; } } if ($browser = $agent->browser() == "IE") { $version = $agent->version("IE"); $version = str_replace('.0', '', $version); $other_browser = false; $browser_css_classes[] = 'browser-ie'; $browser_css_classes[] = 'browser-ie-' . (int) $version; if ((int) $version < 10) { $browser_css_classes[] = 'browser-lt-ie10'; } if ((int) $version < 9) { $unsupported['browser'] = 'Internet Explorer'; } $browser_css_classes[] = 'browser-ie' . $version; } if ($other_browser) { $browser_css_classes[] = 'browser-' . strtolower($other_browser); $version = (int) $agent->version($other_browser); $browser_css_classes[] = 'browser-' . strtolower($other_browser) . '-' . $version; } if ($agent->is('Windows')) { $browser_css_classes[] = 'os-windows'; } if ($agent->is('OS X')) { $browser_css_classes[] = 'os-mac'; } if ($agent->isDesktop()) { $browser_css_classes[] = 'desktop'; } else { //Don't display errors on non-desktop devices $unsupported = []; } $browser_css_classes = implode(' ', $browser_css_classes); return $browser_css_classes; }
/** * Get the browser name. * * @return string * @static */ public static function browser($userAgent = null) { return \Jenssegers\Agent\Agent::browser($userAgent); }
/** * Set the user agent field * * @param string $value * @return string */ public function setUserAgentAttribute($value) { $agent = new Agent(); $agent->setUserAgent($value); $this->browser = $agent->browser(); $this->browser_version = $agent->version($this->browser); $this->platform = $agent->platform(); $this->platform_version = $agent->version($this->platform); $this->device = $agent->device() && !$agent->isDesktop() ? $agent->device() : ''; $this->device_type = $agent->isMobile() ? 'mobile' : ($agent->isTablet() ? 'tablet' : ($agent->isDesktop() ? 'desktop' : '')); $this->attributes['user_agent'] = $value; }