/** * Показываем контент * @param $id * @return string */ public function actionShow($id) { $article = Articles::findOne($id); $comment = new Comments(); $this->title = $article->title; $allArticles = ArticlesContent::find()->where(['articles_id' => $id]); //var_dump($allArticles); exit; $countQuery = clone $allArticles; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]); $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all(); $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title; $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name; return $this->render('view', ['articles' => $allArticles, 'contents' => $models, 'pages' => $pages, 'title' => $this->title, 'source' => $this->source, 'author' => $this->author, 'comment' => $comment]); }
public function deleteContent(Request $request, $id, $aid) { $article = Article::find($id); $content = ArticlesContent::destroy($aid); return response()->json($content); }
/** * Получает массив умных фраз * * @return array */ public function actionGetphrases() { $arr = []; if (__DIR__ == '/home/romanych/public_html/plis/basic/modules/bardzilla/controllers') { $allPhrases = ArticlesContent::find()->joinWith(['articles' => function ($query) { $query->andWhere('cat_id = 35'); }])->all(); // var_dump($allPhrases); exit; } else { $allPhrases = ArticlesContent::find()->joinWith(['articles' => function ($query) { $query->andWhere('cat_id = 5'); }])->all(); // var_dump($allPhrases); exit; } foreach ($allPhrases as $phrase) { $arr[] = $phrase->body; } return json_encode($arr); }
public function actionKlavir() { /* $query = new Query(); // $search_result = $query_search->from('siteSearch')->match($q)->all(); // поиск осуществляется по средством метода match с переданной поисковой фразой. $r = $query->from('items') ->match('шкалика') ->all(); var_dump(Items::findOne($r)); exit; */ $article_id = Articles::find()->select('MAX(id)')->scalar(); if ($article_id) { $article = Articles::findOne($article_id); } else { return $this->redirect(Url::toRoute('articles/index')); } $artContent = new ArticlesContent(); if ($artContent->load(Yii::$app->request->post())) { $artContent->body = Yii::$app->request->post('ArticlesContent')['body']; $artContent->minititle = Yii::$app->request->post('ArticlesContent')['minititle']; $artContent->source_id = 434; $artContent->articles_id = $article_id; if ($this->loadModel($article_id)->site_id == 13) { $act = new DiaryActs(); $act->model_id = 6; $act->mark = 1; $act->user_id = 8; $act->save(false); } $artContent->save(); $content = ArticlesContent::find()->where(['articles_id' => $article_id]); $dataCont = new ActiveDataProvider(['query' => $content]); return $this->render('pages', ['content' => $dataCont, 'model' => $artContent]); } else { return $this->render('klavir', ['model' => $artContent]); } }
/** * @return \yii\db\ActiveQuery */ public function getContart() { return $this->hasOne(ArticlesContent::className(), ['id' => 'cont_art_id']); }
public function edit($id) { $article = Article::find($id); $content = ArticlesContent::where(['article_id' => $article->id])->get(); return view('admin.update-article')->with(['article' => $article, 'content' => $content]); }
/** * Поиск Sphinx в статьях * @return string */ function actionArticleSearch() { if (Yii::$app->getRequest()->getQueryParam('user')) { $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user')); if (!$user) { return 'Доступ запрещен!'; } if (Yii::$app->getRequest()->getQueryParam('text')) { $articles_records = []; $query = new Query(); // $search_result = $query_search->from('siteSearch')->match($q)->all(); // поиск осуществляется по средством метода match с переданной поисковой фразой. $query_articles_ids = $query->from('articles')->match(Yii::$app->getRequest()->getQueryParam('text'))->all(); foreach ($query_articles_ids as $arr_articles_rec) { foreach ($arr_articles_rec as $id) { $articles_records[] = ArticlesContent::findOne((int) $id); } } // var_dump(Items::findOne($r)); exit; return $this->renderPartial('articles_searched', ['articles_rows' => is_array($articles_records) && !empty($articles_records) ? $articles_records : 'Ничего не найдено']); } return $this->renderPartial('article_search_form'); } }
public function index($id) { $article = Article::find($id); $content = ArticlesContent::where('article_id', $article->id)->get(); return view('report')->with(['article' => $article, 'contents' => $content, 'file_url' => '/images/articles/', 'months' => $this->months]); }
/** * Парсер хабрахабра * @param $url */ public function actionHabrParser($url, $title) { $tag_in = ''; $tag_out = ''; $cut = ''; $source = 329; if (strstr($url, 'habrahabr.ru/company')) { $tag_in = 'class="company_post"'; $tag_out = 'class="post__tags"'; } elseif (strstr($url, 'habrahabr') || strstr($url, 'geektimes')) { $tag_in = 'class="post_show"'; $tag_out = 'class="post__tags"'; } elseif (strstr($url, 'wikipedia')) { $tag_in = 'id="mw-content-text"'; $tag_out = 'printfooter'; $source = 394; } elseif (strstr($url, 'highload')) { $tag_in = 'page_wrapper'; $tag_out = 'social-likes social-likes_visible'; $source = 394; } //echo $tag_in; //echo $tag_out; exit; header('Content-Type: text/html; charset=utf-8'); //$head = file_get_contents(Url::to("@app/commands/header.html")); $content = $this->get_page($url); $content = $this->cut_content($content, $tag_in, $tag_out); $allowedTags = '<a><br><b><h1><h2><h3><h4><i>' . '<img><li><ol><p><strong><table><pre>' . '<tr><td><th><u><ul>'; $content = strip_tags($content, $allowedTags); $content = preg_replace('$\\[.*?\\]$', '', $content); $content = str_replace('id="mw-content-text" lang="ru" dir="ltr" class="mw-content-ltr">', '', $content); $artContent = new ArticlesContent(); $artContent->articles_id = (int) Articles::find()->select('MAX(id)')->scalar(); $artContent->source_id = $source; $artContent->body = $content; $artContent->minititle = $title; $artContent->save(false); //var_dump($artContent); }