/** * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function postCreate(Request $request) { $form_data = $request->all(); $this->article->fill($form_data); $this->article->save(); return redirect()->to('articles/index'); }
public function beforeRender() { $this->template->articles = $this->article->where('menu IS NOT NULL'); $this->template->DPH = self::DPH; // Sets information for facebook $this->template->og = array(); }
public static function setFieldData() { $fieldData = array(); $article = new Article(); $arr = $article->getFillable(); foreach ($arr as $v) { $fieldData[$v] = Input::get($v); } $fieldData['user_id'] = Auth::user()->id; $fieldData['tags'] = Tag::SetArticleTags($fieldData['tags'], $fieldData['new_tags']); // 文件上传 if (Request::hasFile('pic')) { $pic = Request::file('pic'); if ($pic->isValid()) { $newName = md5(rand(1, 1000) . $pic->getClientOriginalName()) . "." . $pic->getClientOriginalExtension(); $pic->move('uploads', $newName); $fieldData['pic'] = $newName; } } else { unset($fieldData['pic']); } unset($fieldData['new_tags']); unset($arr); unset($article); return $fieldData; }
public function renderArticle($id) { $article = $this->article->get($id); if (!$article) { $this->error('Článek nelze otevřít', 404); } $this->template->article = $article; }
public function renderDefault() { $currentDate = date('Y-m-d H:i:s'); // povolene akce s aktualnim datem platnosti serazene od nejnovejsi $this->template->sales = $this->sale->where("enable != 0 AND ((start IS NULL AND end IS NULL) OR (start < '{$currentDate}' AND end > '{$currentDate}') OR (start IS NULL AND end > '{$currentDate}') OR (start < '{$currentDate}' AND end IS NULL))")->order('created DESC'); $this->template->goodsRecommended = $this->goods->where('recommended != 0')->order('id DESC')->limit(6); $this->template->text = ""; foreach ($this->article->where(['menu' => self::SALE_PAGE_MENU])->limit(1) as $a) { if (strip_tags($a->text)) { $this->template->text = $a->text; } } }
protected function createComponentMenuForm() { $menus = $this->menu->where('menu_id', null)->fetchPairs('id', 'name'); $menus[null] = '-- Není --'; $articles = $this->article->fetchPairs('id', 'name'); $articles[null] = '-- Není --'; $form = new UI\Form(); $form->addSelect('menu_id', 'Nadřazené menu', $menus); $form->addText('name', 'Název:')->setRequired(); $form->addText('url', 'Url:'); $form->addSelect('article_id', 'Článek:', $articles); $form->addSubmit('save', 'Uložit')->setAttribute('class', 'btn btn-primary'); $form->onSuccess[] = array($this, 'menuFormSucceeded'); return $form; }
public function show($id = 0) { if (!preg_match("/^[1-9]\\d*\$/", $id)) { return Redirect::to('/'); } $type = Category::find($id); if (empty($type)) { return Redirect::to('/'); } $keywords = $type->keywords; $description = $type->description; $subs = $type->subs()->get(); if (count($subs) > 0) { $templet = 'sub'; if ($type->templet_all != '') { $templet = $type->templet_all; } return Theme::view('category.' . $templet, compact('type', 'subs', 'keywords', 'description')); } else { $templet = 'show'; if ($type->templet_nosub != '') { $templet = $type->templet_nosub; } $articles = Article::where('category_id', $id)->sortByDesc('id')->paginate(20); return Theme::view('category.' . $templet, compact('type', 'articles', 'keywords', 'description')); } }
/** * Run the database seeds. * * @return void */ public function run() { // 从数据库中获取的ArticleTag集合 $tags = \App\Model\Tag::all(); // 初始化博客的路径 $dir = "/root/blog"; $file_system = new Filesystem(); $files = $file_system->allFiles($dir); foreach ($files as $file) { $file_extension = $file_system->extension($file); if ($file_extension != 'md') { continue; } $create_time_stamp = $file_system->lastModified($file); $create_time = gmdate("Y-m-d", $create_time_stamp); $file_content = $file_system->get($file); $file_name = preg_replace('/^.+[\\\\\\/]/', '', $file); $file_name = explode(".md", $file_name); $blog_name = $file_name[0]; $last_dir = dirname($file); $current_tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir); $article_type_id = 0; foreach ($tags as $tag) { $tag_name = $tag->name; if (strcmp($current_tag_name, $tag_name) == 0) { $article_type_id = $tag->id; break; } } $article_id = \App\Model\Article::create(['cate_id' => $article_type_id, 'user_id' => 1, 'title' => $blog_name, 'content' => $file_content, 'tags' => $article_type_id, 'created_at' => $create_time, 'updated_at' => $create_time])->id; \App\Model\ArticleStatus::create(['art_id' => $article_id, 'view_number' => 0]); } }
public function getTag($id) { $article = Article::getArticleListByTagId($id); $page = new EndaPage($article['page']); viewInit(); return homeView('searchTag', ['articleList' => $article, 'tagName' => Tag::getTagNameByTagId($id), 'page' => $page]); }
public function about(Request $request) { $id = $request->input('id'); $about = Article::find($id); $aboutList = Article::where('cate_id', 3)->orderBy('priority', 'asc')->paginate(20); return view('themes.default.about', ['about' => $about, "aboutList" => $aboutList, 'id' => $id]); }
public function show($id = 0) { if (!preg_match("/^[1-9]\\d*\$/", $id)) { return Redirect::to('/'); } $article = Article::find($id); if (empty($article)) { return Redirect::to('/'); } $type = Category::find($article->category_id); if (empty($type)) { return Redirect::to('/'); } ++$article->views; $article->save(); $keywords = $article->keywords; $description = $article->description; if ($article->url != '') { return Redirect::to($article->url); } $templet = 'show'; if ($type->templet_article != '') { $templet = $type->templet_article; } return Theme::view('article.' . $templet, compact('article', 'type', 'keywords', 'description')); }
public function index() { $article_num = Article::count(); $articles = Article::sortByDesc('id')->take(5)->get(); $user_num = User::count(); $users = User::sortByDesc('id')->take(5)->get(); return Theme::view('admin.dash.index', compact(['article_num', 'user_num', 'articles', 'users'])); }
public function run() { DB::table('articles')->delete(); for ($i = 0; $i < 20; $i++) { Article::create(['title' => '标题标题' . $i, 'content_md' => '文章内容,文章内容' . $i, 'content_html' => 'html内容' . $i]); } $this->command->info('文章表填充数据完成!'); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $article = Article::getArticleModelByArticleId($id); ArticleStatus::updateViewNumber($id); $data = array('article' => $article); viewInit(); return homeView('article', $data); }
public function actionIndex() { $view = new View(); $view->title = 'Blog | Editor'; $where = "author_id=" . 1; $view->items = ModelArticle::getColumn(['id', 'title'], $where); $view->displayPage('articles/editor'); }
public function index() { $article_num = Article::count(); $user_num = User::count(); $person_num = Person::count(); $project_num = Project::count(); $users = User::sortByDesc('id')->take(5)->get(); return Theme::view('admin.dash.index', compact('article_num', 'user_num', 'person_num', 'project_num', 'users')); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $article = Article::getArticleModelByArticleId($id); $tags = Tag::getTagModelByTagIds($article->tags); $authorArticle = Article::getArticleModelByUserId($article->user_id); ArticleStatus::updateViewNumber($id); $data = array('article' => $article, 'tags' => $tags, 'authorArticle' => $authorArticle); viewInit(); return homeView('article', $data); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $article = Article::getArticleModelByArticleId($id); $tags = Tag::getTagModelByTagIds($article->tags); $authorArticle = Article::getArticleModelByUserId($article->user_id); $commentList = Comment::getCommentListModel($id); $data = array('article' => $article, 'tags' => $tags, 'authorArticle' => $authorArticle, 'commentList' => $commentList); viewInit(); return homeView('article', $data); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // viewInit(); $category = Category::getCatInfoModelByAsName($id); if (empty($category)) { return redirect(url(route('article.index'))); } $article = Article::getNewsArticle($category->id, 10); return homeView('category', ['category' => $category, 'article' => $article]); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $article = Article::findOrFail($id); $article->title = $request->input('title'); $article->content_raw = $request->input('editorValue'); $article->content_html = $request->input('editorValue'); $article->page_image = $request->input('coverImage'); $article->save(); return redirect('/admin/article'); }
public function indexAction() { $page = Input::get('p'); $articles = ArticleModel::lists(); $auths = AuthModel::lists(); View::make('index')->with('article', $articles[0])->with('title', $articles[0]->title . 'index')->with('auths', $auths)->with('page', $page)->show(); echo microtime(true) - START_TIME; echo "<br>"; echo memory_get_usage() - START_USAGE_MEMORY; exit; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $userInfo = User::getUserInfoModelByUserId($id); if (empty($userInfo)) { return redirect('/'); } $userArticle = Article::getArticleModelByUserId($id); viewInit(); return homeView('about', ['userInfo' => $userInfo, 'userArticle' => $userArticle]); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // viewInit(); $category = Category::getCatInfoModelByAsName($id); if (empty($category)) { return redirect(url(route('article.index'))); } $article = Article::getArticleListByCatId($category->id, 10); $page = new EndaPage($article['page']); return homeView('category', ['category' => $category, 'articleList' => $article, 'page' => $page]); }
public function actionUpdate() { $httpRequest = $this->context->getService('httpRequest'); if ($this->option->get('cron') != $httpRequest->getQuery('cron')) { throw new \Nette\Application\BadRequestException("Invalid request"); } $feeds = $this->feed->get_all(); foreach ($feeds as $feed) { try { $articles = $this->feed->parse_articles($feed->id); $this->article->add_multiple($articles); // Debugger::dump($articles); // exit; } catch (\Exception $e) { $this->error->save($feed->id, $e); } libxml_clear_errors(); } $this->terminate(); }
public function actionDelete() { $id = $_GET['id']; $article = new ModelArticle(); $article->id = $id; $article->delete(); header('Location: /article/all'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Request $request, $aid) { // $id = $request->input('id'); $article = Article::find($id); if (!empty($article->pic)) { $fileName = public_path() . '/uploads/' . $article->pic; if (file_exists($fileName)) { unlink($fileName); } } $result = "删除失败"; if (Article::destroy($id)) { Notification::success('删除成功'); $result = "删除成功"; Cache::tags(Article::REDIS_ARTICLE_PAGE_TAG)->flush(); Cache::forget(Article::REDIS_ARTICLE_CACHE . $id); } else { Notification::error('主数据删除失败'); } return $result; }
public function actionDelete($id) { $this->article->get($id)->delete(); $this->flashMessage('Článek odstraněn.', 'success'); $this->redirect('default'); }
public function delete() { $id = Input::get('id'); $validator = Validator::make(array('id' => $id), array('id' => 'required|integer|exists:articles,id')); if ($validator->fails()) { return response()->json(['data' => false, 'msg' => json_encode($validator->messages())]); } try { Article::where('id', $id)->delete(); //Todo::delete other about this article!!! } catch (\Exception $e) { return response()->json(['data' => false, 'msg' => json_encode($e->getMessage())]); } return response()->json(['data' => true, 'msg' => '成功删除文章!']); }
//}); Route::get('httpTest', function () { $client = new \GuzzleHttp\Client(['base_uri' => 'http://httpbin.org', 'timeout' => 2.0]); $response = $client->request('GET', 'get', ['query' => ['foo' => 'bar'], 'body' => 'Gavin']); echo $response->getBody(); }); Route::get('duoshuo', function () { $duoshuo = new \App\Services\DuoShuo(); echo $duoshuo->getHotArticles(); }); Route::get('redisTest', function () { $v = RedisGo::get('hello'); return $v; }); Route::get('orm', function () { $data = \App\Model\Article::skip(0)->take(10)->get(); dd($data); }); Route::get('table-edit', function () { Schema::table('articles', function ($table) { $table->string('outline'); }); }); /** * 前台部分 */ Route::group(['namespace' => 'Frontend'], function () { // 前台主页 文章列表 Route::get('/', 'FrontendController@index'); // 文章详细页 Route::get('article/{id}', 'FrontendController@article');
public static function article_data($num, $order = null, $where = null, $type = 0, $offset = 0) { $num = intval($num); $offset = intval($offset); $key = 'article_' . $num . '_' . $order . '_' . $where . '_' . $type . '_' . $offset; if (Cache::store('article')->has($key)) { $date = Cache::store('article')->get($key); return $date; } else { switch ($order) { case byId: $order_str = 'id'; break; case bySort: $order_str = 'sort'; break; case byViews: $order_str = 'views'; break; default: $order_str = 'id'; break; } $type = intval($type); switch ($where) { case findAll: $date = Article::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findRecommend: $date = Article::where('is_recommend', '>', 0)->sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findCategory: $date = Article::where('category_id', $type)->orderBy($order_str, 'desc')->take($num)->Offset($offset)->get(); break; default: $date = Article::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; } $expiresAt = Carbon::now()->addMinutes(60); //设置缓存时间 Cache::store('article')->put($key, $date, $expiresAt); return $date; } }