public function addContent(Request $request, $id) { $article = Article::find($id); $content = new ArticlesContent(); $content->content = $request->input('content'); $content->type = $request->input('type'); $content->article_id = $article->id; $content->save(); return response()->json($content); }
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]); } }
/** * Парсер хабрахабра * @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); }