public function actionGrab() { // Yii::$app->response->format = Response::FORMAT_JSON; $success = true; $source = Source::find()->joinWith('logs')->where(['enable' => true])->orderBy(['updated' => SORT_ASC])->one(); if ($source) { $grabber = new Grabber($source); $newPosts = $grabber->execute(); if (!empty($newPosts)) { foreach ($newPosts as $post) { $hashPost = md5($post); // есть ли в базе Post или Moderation $doubling = Post::findOne(['hash' => $hashPost]) || Moderation::findOne(['hash' => $hashPost]); if ($doubling) { continue; } // добавляем новый пост на модерацию $model = new Moderation(); $model->text = $post; $model->hash = $hashPost; $model->ip = "127.0.0.1"; //Yii::$app->request->getUserIP(); $model->user_agent = "Auto Grabber"; //Yii::$app->request->getUserAgent(); $success = $model->save() && $success; } } $source->updateLog(); } return $success; }
echo Html::encode($this->context->query); ?> " placeholder="Поиск поста по фразе или тегу..."> </form> <span class="text-nowrap"> Всего <b><?php echo \app\models\Post::find()->where('visible=1')->count(); ?> </b>, сегодня <b><?php echo \app\models\Post::find()->where('visible=1 and created like :d', [':d' => date("Y-m-d") . "%"])->count(); ?> </b>, на модерации <b><?php echo ($count = \app\models\Moderation::find()->count()) ? Html::a($count, '/moderate') : $count; ?> </b> </span> <div class="text-left"> <b>Популярные теги:</b> <?php $tagWeights = \app\models\Tag::getTagWeights(10); foreach ($tagWeights as $tag => $weight) { echo Html::a("#" . $tag, Url::toRoute(['/', 'query' => "#" . $tag]), ['style' => "display: inline-block; padding:0 4px; font-size:{$weight}pt;"]); } ?> </div> </div> <div class="col-xs-6"><?php