Пример #1
0
 public static function increment($country, $url)
 {
     if (is_a($url, Url::className())) {
         $url = $url->id;
     }
     if (!is_numeric($url)) {
         throw new InvalidParamException('Url must be a number or object of app\\models\\Url with id');
     }
     $countryUrl = CountryUrl::findOne(['country_name' => $country, 'id_url' => $url]);
     if (empty($countryUrl)) {
         $countryUrl = new CountryUrl(['country_name' => $country, 'id_url' => $url, 'counter' => 1]);
     } else {
         $countryUrl->counter++;
     }
     $countryUrl->save();
 }
Пример #2
0
 public function actionUrlRedirect($url)
 {
     $url = Url::getByUrl($url);
     if (empty($url)) {
         throw new NotFoundHttpException('Url not found');
     }
     try {
         $geodata = Json::decode(Yii::$app->geolocation->getInfo(), true);
         CountryUrl::increment(empty($geodata['country_name']) ? 'Undefined' : $geodata['country_name'], $url);
     } catch (Exception $e) {
         CountryUrl::increment('Undefined', $url);
     }
     preg_match("/(MSIE|Opera|Firefox|Chrome|Version|Opera Mini|Netscape|Konqueror|SeaMonkey|Camino|Minefield|Iceweasel|K-Meleon|Maxthon)(?:\\/| )([0-9.]+)/", Yii::$app->request->userAgent, $browser_info);
     list(, $browser, $version) = $browser_info;
     if (preg_match("/Opera ([0-9.]+)/i", Yii::$app->request->userAgent, $opera)) {
         $browser = 'Opera ' . $opera[1];
     }
     if ($browser == 'MSIE') {
         preg_match("/(Maxthon|Avant Browser|MyIE2)/i", Yii::$app->request->userAgent, $ie);
         if ($ie) {
             $browser = $ie[1] . ' based on IE ' . $version;
         }
         $browser = 'IE ' . $version;
     }
     if ($browser == 'Firefox') {
         preg_match("/(Flock|Navigator|Epiphany)\\/([0-9.]+)/", Yii::$app->request->userAgent, $ff);
         if ($ff) {
             $browser = $ff[1] . ' ' . $ff[2];
         }
     }
     if ($browser == 'Opera' && $version == '9.80') {
         $browser = 'Opera ' . substr(Yii::$app->request->userAgent, -5);
     }
     if ($browser == 'Version') {
         $browser = 'Safari ' . $version;
     }
     if (!$browser && strpos(Yii::$app->request->userAgent, 'Gecko')) {
         $browser = 'Browser based on Gecko';
     }
     $browser = $browser . ' ' . $version;
     BrowserUrl::increment($browser, $url);
     $this->redirect($url->origin);
 }
Пример #3
0
 public function getCountries()
 {
     return Url::hasMany(CountryUrl::className(), ['id_url' => 'id']);
 }