/**
  * ЦСКА
  */
 public function actionCskanews()
 {
     $cska = Yii::$app->params['cska'];
     $bot = new BotApi($cska['token']);
     $host = 'https://www.sports.ru';
     $dom = Html::load($cska['html']);
     $divs = $dom->getElementsByTagName('div');
     foreach ($divs as $div) {
         if ($div->getAttribute('class') == 'news') {
             $links = $div->getElementsByTagName('a');
             foreach ($links as $link) {
                 if ($link->getAttribute('class') == 'short-text') {
                     $url = Url::findOne(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]);
                     if ($url === null) {
                         $message = $link->nodeValue . "\n" . $host . $link->getAttribute('href');
                         try {
                             $bot->sendMessage($cska['chat_id'], $message);
                         } catch (Exception $e) {
                             echo $e->getMessage() . "\n";
                         }
                         $url = new Url(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]);
                         $url->save();
                     }
                 }
             }
         }
     }
 }
Example #2
0
 public function save($profile, $urls)
 {
     $user = new User();
     $user->email = $this->email;
     $user->password = $this->password;
     $user->setPassword($user->password);
     $user->generateAuthKey();
     $user->save(false);
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_SHOP), $user->id);
     $profile->user_id = $user->id;
     $profile->host = $profile->getHost($profile->url);
     $profile->status_id = 1;
     $profile->save(false);
     $url = new Url();
     $url->user_id = $user->id;
     $url->link = $profile->url;
     $url->name = 'Главная страница';
     $url->save(false);
     if (is_array($urls)) {
         foreach ($urls as $item) {
             if (is_array($item)) {
                 $url = new Url();
                 $url->user_id = $user->id;
                 $url->link = $item['link'];
                 $url->name = $item['name'];
                 $url->save(false);
             }
         }
     }
     Yii::$app->mailer->compose('registration/shop', ['model' => $user])->setFrom(Yii::$app->params['emailFrom'])->setTo($this->email)->setSubject('Регистрация магазина')->send();
 }
Example #3
0
 private function createUrl($user_id, $link, $name)
 {
     $url = new Url();
     $url->user_id = $user_id;
     $url->link = $link;
     $url->name = $name;
     $url->save(false);
 }
 /**
  * регистрация юзера по имейл
  * если регистрация для покупки, то передаются параметры рекомендатель и урл
  * @param type $affiliate_id
  * @param type $url_id
  * @return type
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionUser($affiliate_id = null, $url_id = null)
 {
     $request = Yii::$app->request;
     $model = new \app\models\registration\UserForm();
     if ($request->isAjax && $model->load($request->post())) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load($request->post()) && $model->validate()) {
         $user = User::findByUsername($model->email);
         if (!$user) {
             $user = $model->save();
         }
         $user->setCookie();
         if ($affiliate_id === null || $url_id === null) {
             Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту');
             return $this->goHome();
         }
         $url = Url::findOne($url_id);
         if (!$url) {
             throw new \yii\web\NotFoundHttpException('Урл не найден');
         }
         $user->purchase($affiliate_id, $url);
         return $this->redirect($url->link);
     }
     return $this->render('user', ['model' => $model]);
 }
 public function addUrl(ShortenUrlRequest $request)
 {
     $actual_url = $request->get('url');
     $a_url = Url::where('url_hash', md5($actual_url))->select('short_url')->first();
     if (!$a_url) {
         $a_url = $this->addUrlToDb($actual_url);
     }
     return Redirect::route('home')->with('short_url', $a_url->short_url)->with('actual_url', $actual_url);
 }
Example #6
0
 public function addUrl($link)
 {
     $shop_id = null;
     $text = '';
     $profile = new Profile();
     $host = $profile->getHost($link);
     /* @var $shop Profile */
     $shop = Profile::find()->where(['host' => $host])->one();
     if ($shop) {
         $shop_id = $shop->user_id;
         $text .= 'магазин ' . $shop->url . '<br>';
         $text .= 'бонус покупателю ' . $shop->buyer_bonus . '<br>';
         $text .= 'бонус рекомендателю ' . $shop->recommender_bonus . '<br>';
         $text .= 'статус ' . $shop->status->name . '<br>';
     } elseif (!ModerateShop::find()->where(['url' => $host])->exists()) {
         $moderateShop = new ModerateShop(['user_id' => Yii::$app->user->identity->id, 'url' => $host]);
         $moderateShop->save();
     }
     $text .= 'Вы можете давать эту ссылку своим друзьям<br>';
     $url = new Url(['user_id' => Yii::$app->user->identity->id, 'link' => $link, 'shop_id' => $shop_id]);
     $url->save();
     return $text . \yii\helpers\Url::to(['purchase/create', 'affiliate_id' => Yii::$app->user->identity->id, 'url_id' => $url->id], true);
 }
Example #7
0
 public function search($params)
 {
     $query = Url::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => []]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'name', $this->name]);
     $dependency = new \yii\caching\DbDependency(['sql' => 'SELECT MAX(updated_at) FROM url', 'reusable' => true]);
     Yii::$app->db->cache(function ($db) use($dataProvider) {
         $dataProvider->prepare();
     }, Yii::$app->params['cacheExpire'], $dependency);
     return $dataProvider;
 }
Example #8
0
 public static function increment($browser, $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');
     }
     $browserUrl = BrowserUrl::findOne(['browser' => $browser, 'id_url' => $url]);
     if (empty($browserUrl)) {
         $browserUrl = new BrowserUrl(['browser' => $browser, 'id_url' => $url, 'counter' => 1]);
     } else {
         $browserUrl->counter++;
     }
     $browserUrl->save();
 }
Example #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUrl()
 {
     return $this->hasOne(Url::className(), ['id' => 'url_id']);
 }
Example #10
0
 public function rules()
 {
     return [[['url'], 'required', 'message' => 'Введите адрес ссылки'], [['url'], 'string', 'max' => 255, 'tooLong' => 'Превышена длина'], [['url'], 'url', 'message' => 'Это не адрес ссылки'], [['short'], 'string', 'max' => 8, 'tooLong' => 'Ссылка должна быть не более 8 символов', 'min' => 3, 'tooShort' => 'Минимум 3 символа'], [['dieable'], 'default', 'value' => 0], [['dieable'], 'number', 'max' => 1], [['short'], 'unique', 'targetClass' => Url::className()]];
 }
Example #11
0
 /**
  * Get the URL to the post.
  *
  * @return string
  */
 public function url()
 {
     return Url::to('blog/' . $this->slug);
 }
 public function index(TranslateUrlRequest $request, $short_url)
 {
     $url = Url::select('actual_url')->findOrFail($short_url);
     //sampai disini url sudah pasti ada
     return redirect($url->actual_url);
 }
Example #13
0
 public function getUrls()
 {
     return $this->hasMany(Url::className(), ['user_id' => 'id']);
 }
Example #14
0
 /**
  * переход покупателя по реф ссылке
  * @param type $affiliate_id рекомендатель
  * @param type $url_id ид ссылки
  * @return type
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionCreate($affiliate_id, $url_id)
 {
     $user_id = null;
     if (!Yii::$app->user->isGuest) {
         $user_id = Yii::$app->user->identity->id;
     } else {
         $user_id = Yii::$app->request->cookies->getValue('user_id');
     }
     if ($user_id === null) {
         return $this->redirect(['registration/user', 'affiliate_id' => $affiliate_id, 'url_id' => $url_id]);
     } else {
         $url = Url::findOne($url_id);
         if (!$url) {
             throw new \yii\web\NotFoundHttpException('Урл не найден');
         }
         $user = User::findOne($user_id);
         $user->purchase($affiliate_id, $url);
         return $this->redirect($url->link);
     }
 }
Example #15
0
 public function actionCleanup()
 {
     Url::deleteAll("DATE_ADD(`date_add`, INTERVAL 1 MONTH) < '" . date('Y-m-d H:i:s') . "' AND `dieable` = 1");
 }
Example #16
0
 public function getBrowsers()
 {
     return Url::hasMany(BrowserUrl::className(), ['id_url' => 'id']);
 }
Example #17
0
 /**
  * Finds the Url model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Url the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Url::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }