public function postSave(Request $request) { if (!empty($this->name) && !empty($this->category) && !empty($this->content) && !empty($this->user_id)) { $table = new Models\News(); $table->name = $this->name; $table->create_time = date("Y-m-d H:i:s"); $table->group_news_id = $this->category; $table->images = $this->images; $table->slug = $this->slug; $table->description = $this->description; $table->content = $this->content; $table->user_id = $this->user_id; $table->keywords = $this->keywords; $table->status = 1; // 2 : không chọn , 1 là được chọn $rs = $table->save(); $LastInsertId = $table->id; $data = ['id' => $LastInsertId, 'name' => $this->name, 'create_time' => date("Y-m-d H:i:s"), 'group_news_id' => $this->category, 'images' => $this->image, 'description' => $this->description, 'content' => $this->content, 'status' => 1]; if ($rs) { return $this->ResponseData($data); } $this->error = true; $this->error_message = "Lỗi truy vấn, vui lòng thử lại sau"; return $this->ResponseData([]); } $this->error = true; $this->error_message = "Dữ liệu gửi lên không đúng, vui lòng thử lại"; return $this->ResponseData([]); }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); $loaded = $model->load(Yii::$app->request->post()); if ($loaded) { if ($model->is_published) { $model->published = date('Y-m-d H:i:s'); } } if ($loaded && $model->save()) { $model->upload(); $category_relations = $_POST['News']['categories']; foreach ($category_relations as $cat_id) { $category_relation = new CategoryRelations(); $category_relation->news_id = $model->id; $category_relation->category_id = $cat_id; $category_relation->save(); } return $this->redirect(['view', 'id' => $model->id]); } else { $categories_arr = Category::find()->asArray()->all(); foreach ($categories_arr as &$cat) { $categories[$cat['id']] = $cat['name']; } $model->is_published = 1; return $this->render('create', compact('model', 'categories')); } }
public function actionUpdatenews() { $data = []; if (!empty($_POST['title']) and !empty($_POST['text']) and isset($_GET[id])) { $data['id'] = $_GET['id']; $data['title'] = $_POST['title']; $data['text'] = $_POST['text']; $data['datatime'] = date('Y-m-d H:i:s'); } else { $error_report = 'Не указано как и какую новость необходимо обновить'; } if (isset($data['title']) && isset($data['text']) && isset($data['datatime']) && !isset($eror_report)) { $news = new NewsModel(); $news->id = $data['id']; $news->title = $data['title']; $news->text = $data['text']; $news->datatime = $data['datatime']; $news->save(); header('Location: /'); die; } else { $view = new View(); $view->error_report = $eror_report; $view->display('second/error.php'); } }
public function actionNews() { for ($i = 1; $i <= 10; $i++) { $model = new News(); $model->attributes = ['name' => 'Bài viết số ' . $i, 'title' => 'Title cua bai viet so ' . $i, 'slug' => 'bai-viet-so-' . $i, 'images' => '3.png', 'type_id' => rand(1, 100), 'user_id' => '1', 'created_at' => time(), 'updated_at' => time()]; $model->save(); } }
public function actionSuggest() { $model = new News(['status' => News::STATUS_DRAFT, 'scenario' => News::SCENARIO_SUGGEST]); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('news.news_successfully_added'); return $this->redirect(['index']); } return $this->render('suggest', ['model' => $model]); }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return Json::encode(['success' => true, 'message' => 'Created!']); } else { return Json::encode(['success' => false, 'content' => $this->renderPartial('_form', ['model' => $model])]); } }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionSave_news() { $news = new News(); $news->title = $_POST['title']; $news->content = $_POST['content']; $news->createTime = date('Y-m-d H:i:s'); $news->tag = 'unnecessary'; $news->save(); echo 1; }
protected function actionCreate() { try { $article = new News(); $article->fill([]); $article->save(); } catch (MultiException $e) { $this->view->errors = $e; } echo $this->view->render(__DIR__ . '/../templates/update.php'); }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); if ($model->load(Yii::$app->request->post())) { $model->addedat = date("Y-m-d H:i:s"); $model->addedby = Yii::$app->user->identity->username; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Действие для добовления новости * */ protected function actionCreate() { if ($this->isPost()) { try { $news = new News(); $news->fill($_POST); $news->save(); $this->redirect('/Admin'); } catch (MultiException $error) { $this->view->errors = $error; } } else { $this->view->errors = null; } $this->view->display(__DIR__ . '/../Templates/News/Create.php'); }
public function createNews() { if (!$this->checkLogin()) { return redirect('login'); } $item = new News(); $item->nTitle = Request::input('title'); $item->catId = Request::input('catId'); if ($item->catId == null) { $item->catId = 1; } $item->nDescrHTML = Request::input('content'); if ($item->nTitle != null && $item->nDescrHTML != null && $item->catId != null) { $item->save(); } return redirect('news'); }
public function create(Request $request) { $clientId = Authorizer::getClientId(); $operatorId = (int) Authorizer::getResourceOwnerId(); $data = $request->all(); $validator = Validator::make($data, ['content' => 'required', 'link_url' => 'url', 'type' => 'in:0,1']); if ($validator->fails() === true) { return response()->json(['error' => $validator->errors()], 400); } if (!isset($data['type'])) { $data['type'] = 0; } $data['app_id'] = $clientId; $data['author_id'] = $operatorId; $data['content'] = preg_replace('/<(.+?)>|<(\\/.+?)>/', '<$1>', $data['content']); $news = new News($data); $news->save(); $news = $this->unfoldNewsInfo($news); return response()->json($news, 201); }
/** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionKhoahoctv() { for ($i = 16655; $i <= 70000; $i++) { $crawler = new Crawl(); $crawler->arr_att_clean = array('script', '.thumblock'); $url = 'http://khoahoc.tv/quan-the-tu-vien-meteora-' . $i; $namepath = '/html/body/div[1]/div[3]/div[1]/h1'; $contentpath = '/html/body/div[1]/div[3]/div[1]/div[3]'; $type_path = '/html/body/div[1]/div[3]/div[1]/div[2]/span[3]/a'; if (!@($name = $crawler->getTitle($url, $namepath))) { echo 'error_' . $i . "\n"; } else { $name = rUrl::utf8($crawler->getTitle($url, $namepath)); $content = $crawler->getTitle($url, $contentpath); $type = $crawler->getTitle($url, $type_path); $content = $crawler->removeLink($content); $images = $crawler->getImagesFromMeta($url); $keywords = $crawler->getKeywords($url); $descriptionmeta = $crawler->getDescriptionmeta($url); $type_slug = rUrl::slug($type); $mType = Type::find()->Where(['LIKE', 'slug', $type_slug])->one(); $id_type = $mType['id']; $slug = rUrl::slug($name); if ($id_type !== null) { $id_type = $mType['id']; } else { $id_type = 22; } $model = new News(); $model->attributes = ['name' => $name, 'slug' => $slug, 'images' => $images, 'description' => $content, 'seo_keywords' => $keywords, 'view_count' => rand(1000, 10000), 'source' => 'kh', 'seo_title' => $descriptionmeta, 'type_id' => $id_type, 'user_id' => 1, 'hot' => 0, 'post_final' => $i, 'created_at' => time(), 'updated_at' => time()]; $model->save(); echo "ok_" . $i . "\n"; // exit(); } } }
/** * Store a newly created resource in storage. * * @param News $news * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, News $news) { $news->fill($request->all()); $news->save(); return redirect()->route('admin.news.index'); }
private function ImportNews($array, $category) { foreach ($array as $item) { if (!$item['active']) { continue; } $save = false; $model = News::findOne($item['id']); // Checking is this ID free for use if ($model === null) { $save = true; $model = new News(); $model->id = $item['id']; } else { // Asking user what he wants $question = 'News with the same id alredy exists in data base:' . PHP_EOL . 'Data from database:' . PHP_EOL . $this->NewsObjToSting($model) . 'New data from file:' . PHP_EOL . $this->NewsArrToString($item) . 'category_id = ' . $category->id . PHP_EOL; $this->stdout($question); $answer = $this->select('What you want to do?' . PHP_EOL . '(a - assign new id and save data, s - keep database data, d - keep id and save data)' . PHP_EOL, ['a' => 'assign new id and save data', 's' => 'keep database data', 'd' => 'keep id and save data']); switch ($answer) { case 'a': $model = new News(); case 'd': $save = true; break; case 's': break; } } // Saving data if it is needed if ($save) { $model->headline = $item['title']; $model->description = $item['description']; $model->date = $item['date']; $model->image = $item['image']; $model->content = $item['text']; $model->link('category', $category); $model->status = $item['active'] ? News::STATUS_ACTIVE : News::STATUS_INACTIVE; if ($model->save()) { $this->stdout($this->NewsObjToSting($model) . 'saved sucesfully' . PHP_EOL); } } } }
<?php use App\Models\User; use App\Models\News; use App\Config; include 'autoload.php'; include 'Assets/backend/head.php'; if (!empty($_POST)) { $news = new News(); $news->title = $_POST['title']; $news->text = $_POST['text']; $news->date = '2016-02-19'; $news->save(); } $articles = News::findAll(); foreach ($articles as $news) { echo '<tr>'; echo '<td>' . $news->id . '</td>'; echo '<td>' . $news->title . '</td>'; echo '<td>' . $news->text . '</td>'; echo '<td><a href="edit.php?id=' . $news->id . '">Редактировать</a></td>'; } include 'Assets/backend/bottom.php';
<?php use App\Models\News; const STATUS_ACTIVE = 1; require __DIR__ . '/../../autoload.php'; $post = $_POST; if (!empty($post)) { $article = new News(); $article->title = trim($post['title']); $article->description = trim($post['description']); $article->published = date("Y-m-d H:i:s"); $article->status = STATUS_ACTIVE; $article->user_id = 1; $article->save(); include __DIR__ . '/../Views/article.php'; } else { header('Location: /'); }
private function sendAppNews($content) { $clientId = Authorizer::getClientId(); $operatorId = (int) Authorizer::getResourceOwnerId(); $news = new News(['type' => 1, 'topic' => '系统通知', 'app_id' => $clientId, 'author_id' => $operatorId, 'content' => $content]); $news->save(); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $results = new News(); $results->title = $request->input('title', 'Article'); $results->slug = strtolower(str_replace(" ", "-", $results->title)) . "-" . date('Ymd'); $results->content = $request->input('content', 'Content'); $results->category = $request->input('category', 'Category'); if ($request->hasFile('image')) { $img = \Image::make($request->file('image'))->fit(960, 480); $name = date('YmdHis') . str_pad(rand(0, 10000), 4, 0, STR_PAD_RIGHT) . "." . str_replace("image/", "", $img->mime()); $img->save($results::UPLOAD_PATH . "/" . $name); $results->image = $name; } if (\Auth::check()) { $results->author = \Auth::user()->id; } else { $results->author = 1; } $results->save(); return redirect()->route('admin.news.index'); }
/** * Imports a specific news entry * @param PHPHtmlParser\Dom $html * @return boolean|null */ private function importNewsEntry($html, $origin) { $dom = new Dom(); $uri = $html->getAttribute('href'); $uid = str_replace('/galnet/uid/', '', $uri); $count = (new \yii\db\Query())->from('news')->where(['uid' => $uid])->count(); if ((int) $count != 0) { $this->stdOut(" - {$uid} :: Already Imported...\n"); return; } $dom->loadFromUrl(Yii::$app->params['galnet']['url'] . $uri); $title = trim(strip_tags($dom->find('h3.galnetNewsArticleTitle a')[0]->innerHtml)); $content = trim(strip_tags(str_replace('<br /><br /> ', "\n", $dom->find('div.article p')[0]->innerHtml))); // Early Galnet posts are empty, so grab the first line from the article if (empty($title)) { $title = strtok($content, "\n"); } $news = new News(); $news->attributes = ['uid' => $uid, 'title' => $title, 'content' => $content, 'created_at' => time(), 'updated_at' => time(), 'published_at_native' => strtotime($origin), 'published_at' => strtotime($origin . "-1286 years")]; $this->stdOut(" - {$uid}\n"); $news->save(); }