public function run() { $posts_model = new Posts(); $most = $posts_model->most_view(); //dd($most); return view("widgets.most_view", ['most_view_posts' => $most]); }
/** * Execute the console command. * * @return mixed */ public function handle() { $xml = simplexml_load_file('http://www.buzzfeed.com/index.xml', 'SimpleXMLElement', LIBXML_NOCDATA); $count = 0; foreach ($xml->channel->item as $article) { $title = $article->title; $url = $article->link; $author = $article->author; $start = strpos($article->pubDate, ','); $date = substr($article->pubDate, $start + 2, -15); $date = explode(' ', $date); $day = $date[0]; //day $month = $date[1]; //month $month = substr(Carbon::parse($month), 5, 2); $year = $date[2]; //year $date = substr(Carbon::createFromFormat("Y-m-d", $year . "-" . $month . "-" . $day), 0, 10); $description = $article->description; $imgPos = strpos($description, '<img'); $imgUrl = null; if ($imgPos != null) { $imgString = substr($description, $imgPos); $srcPos = strpos($imgString, 'src='); $src = substr($imgString, $srcPos + 5); $tok = '"'; $endQuotePos = strpos($src, $tok); $imgUrl = substr($src, 0, $endQuotePos); } $id = DB::table('email_articles')->where('post_date', $date)->value('article_id'); if ($count < 5) { if (!isset($imgUrl)) { } else { if (Posts::where('title', '=', $title)->exists()) { echo $title . " already exists"; } else { $post = new Posts(); $post->article_id = $id; $post->author = $author; $post->title = $title; $post->description = 'N/A'; $post->imgUrl = $imgUrl; $post->url = $url; $post->source = 'BuzzFeed'; $post->save(); echo "stored " . $title . "!"; } $count++; } } } }
public function post_year($year) { // возвращаем посты за year # обращаемся к моделе Category $Categories = new Categories(); $categories = $Categories->cats_for_header(); # обращаемся к моделе Page $pages = new Page(); $footer_pages = $pages->footer_pages(); $Posts_model = new Posts(); $posts = $Posts_model->post_of_year($year); return view('layouts.default', ['categories' => $categories, 'pages' => $footer_pages, 'content_layout' => 'posts_content', 'posts' => $posts]); }
public function index() { # обращаемся к моделе Category $vrode_model = new Categories(); $categories = $vrode_model->cats_for_header(); # обращаемся к моделе Page $pages = new Page(); $footer_pages = $pages->footer_pages(); //Получение разбитого на страницы запроса из базы данных: $postsi = new Posts(); $per_page = 10; $posts = $postsi->post_paginate($per_page); return view('layouts.default', ['categories' => $categories, 'pages' => $footer_pages, 'content_layout' => 'posts_content', 'posts' => $posts]); }
public function user_posts_draft(Request $request) { $user = $request->user(); $posts = Posts::where('author_id', $user->id)->where('active', '0')->orderBy('created_at', 'desc')->paginate(5); $title = $user->name; return view('home')->withPosts($posts)->withTitle($title); }
public function userPosts() { $posts = \App\Posts::where('user_id', '=', \Auth::user()->id)->orderBy("created_at", "desc")->get(); $search_info = ""; $data = array('posts' => $posts, 'search_info' => \Auth::user()->name . '\'s posts', 'users' => \App\User::get()); return view('home')->with($data); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show(Request $request, $slug) { $category = Categories::where('slug', $slug)->first(); $posts = Posts::where('category_id', $category->id)->orderBy('created_at', 'desc')->paginate(5); $title = 'Posts from category ' . $category->title; return view('categories.show')->withPosts($posts)->withCategory($category)->withTitle($title); }
public function renderDefault() { $this->template->anyVariable = 'any value'; // $dao = $this->articles; $this->template->articles = $this->articles->getArticles()->findAll(); $posts = $this->EntityManager->getRepository(Posts::getClassName()); $this->template->posts = $posts->findAll(); $this->template->myparametr = $this->context->parameters['first_parametr']; // $this->template->test = $this->doSomeRefactoring('Hello world from blog'); // $post = new Posts(); // $post->title = 'New title'; // $post->text = 'New text New textNew text'; // $post->created_at = new \Nette\Utils\DateTime; // // // $this->EntityManager->persist($post); // $this->EntityManager->flush(); // $dao = $this->EntityManager->getRepository(Posts::getClassName()); // $dao->setTitle('test'); // $dao->__call('set', ['title' => 'my title']); // dump($dao->__isset('title')); // $dao->__set('title', 'test'); try { $this->checkNum(2); \Tracy\Debugger::barDump('If you see this, the number is 1 or below'); } catch (Nette\Application\BadRequestException $e) { Debugger::log('Message: ' . $e->getMessage()); var_dump($e->getMessage()); } // finally { // \Tracy\Debugger::barDump('Got here Finally'); // } }
public function saveScore(Request $request) { if (!auth() || !auth()->user()) { echo 'Kết quả chưa được lưu.'; return; } $UserID = auth()->user()->getAuthIdentifier(); $data = $request->all(); $token = $data['token']; // day by day, no. of record will increase // => maybe there are multiple record with the same value of UserID and token // => pick the newest record $record = Doexams::where('token', 'LIKE', $token)->where('UserID', '=', $UserID)->get()->last(); if (count($record->toArray()) < 1) { echo 'Kết quả chưa được lưu.'; return; } $record->Score = $request['Score'] . '/' . $request['MaxScore']; $record->update(); $oldDateTime = $record->created_at->getTimestamp(); $newDateTime = $record->updated_at->getTimestamp(); $diff = ($newDateTime - $oldDateTime) / 3600.0; $record->Time = $diff; $record->update(); if ($diff > 0) { $course = Courses::find(Posts::find($record->PostID)->CourseID); $course->TotalHours += $diff; $course->update(); } echo 'Kết quả đã được lưu lại.'; return; }
public function index() { $posts = Posts::with('comments')->where('active', 1)->orderBy('created_at', 'desc')->paginate(5); if (Auth::check()) { return view('pages.velkommen', array('currentUser' => Auth::user()))->with('posts', $posts); } return view('pages.velkommen')->with('posts', $posts); }
public function idoso() { $posts = \App\Posts::where('tipo', '=', 'postagem')->where('categoria_id', '!=', 7)->latest()->take(8)->get(); $numero = 4; $programas = \App\Posts::where('tipo', '=', 'programas')->orderBy('id', 'desc')->take(6)->where('grupo_id', '=', $numero)->get(); // dd($posts); return view('persona4', compact('posts', 'numero', 'programas')); }
public function run() { //create post sides DB::table('posts')->delete(); for ($i = 0; $i < 5; $i++) { \App\Posts::create(['title' => "first post {$i}", 'description' => "this is a {$i} post description", "content" => "this is a {$i} post content"]); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $title = 'Dashboard'; $posts = Posts::all()->take(3); $comments = Comments::all()->take(3); return view('dashboard')->withTitle($title)->withPosts($posts)->withComments($comments); //return home.blade.php template from resources/views folder }
public function show($slug) { $post = Posts::where('slug', $slug)->first(); if (!$post) { return redirect('/')->withErrors('Page not found'); } $comments = $post->comments; return view('posts.show')->withPost($post)->withComments($comments); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = \Faker\Factory::create(); //Posts::truncate(); foreach (range(1, 10) as $index) { $user = User::All()->random(1); Posts::create(['author_id' => $user->id, 'title' => $faker->sentence(3), 'body' => $faker->text, 'slug' => $faker->slug(), 'active' => 1]); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { // Info we need to grab. // /////////////////////////// // New users: Today, this week + month. ---> just queery our database with a where->created == today || month || week // Total categories // unread admin messages. $data = array('new_users' => \App\User::all()->orderBy('created_at', 'DES')->limit(10), 'active_nav' => $this->active_nav, 'total_users' => \App\User::all()->count(), 'logged_in' => \App\User::where('logged_in', '=', 1)->count(), 'total_posts' => \App\Posts::all()->count()); return view('includes/admin/home')->with($data); }
public function run() { DB::table('posts')->delete(); Posts::create(array('author_id' => 1, 'slug' => 'post1', 'title' => 'post 1 title ', 'body' => 'post 1 body!', 'active' => true)); Posts::create(array('author_id' => 1, 'slug' => 'post2', 'title' => 'post 2 title', 'body' => 'post 2 body!', 'active' => true)); Posts::create(array('author_id' => 1, 'slug' => 'post3', 'title' => 'post 3 title ', 'body' => 'post 3 body!', 'active' => true)); Posts::create(array('author_id' => 1, 'slug' => 'post4', 'title' => 'post 4 title', 'body' => 'post 4 body!', 'active' => true)); Posts::create(array('author_id' => 1, 'slug' => 'post5', 'title' => 'post 5 title ', 'body' => 'post 5 body!', 'active' => true)); Posts::create(array('author_id' => 1, 'slug' => 'post6', 'title' => 'post 6 title', 'body' => 'post 6 body!', 'active' => true)); }
public function deletePost($deletePostId) { $deletePost = Posts::find($deletePostId); if ($deletePost->photo != 'noImage.jpg') { //delete the image associative with the post \File::Delete('img/Post/' . $deletePost->photo); } $deletePost->delete(); return redirect('admin'); }
public static function getPostByCategory($category_id) { $post_ids = \App\post_categories::where('categorie_id', '=', $category_id)->get(); $posts = new \App\Posts(); $ids = array(); foreach ($post_ids as $id) { $ids[] = $id->post_id; } $posts = \App\Posts::whereIn('id', $ids); return $posts->get(); }
public function showpdf($slug) { $artikel = \App\Posts::where('slug', $slug)->first(); if (!empty($artikel)) { $data = array('data' => $artikel); $pdf = \PDF::loadview('artikel.pdf', $data); return $pdf->stream($slug . 'pdf'); } else { return redirect(url()); } }
public function store(Request $request) { if ($request->ajax()) { $new_header = $request->input('Header'); $new_content = $request->input('Content'); $v = Validator::make($request->all(), ['Header' => 'required|max:32', 'Content' => 'required']); if (!$v->fails()) { $post = new Posts(); $post->Header = $new_header; $post->Content = $new_content; if ($post->save()) { $response = array('status' => 'success', 'msg' => 'Setting created successfully'); } else { $response = array('status' => 'error', 'msg' => 'save failed'); } } else { $response = array('status' => 'error', 'msg' => 'v failed'); } return Response::json($response); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Request $request, $id) { $comment = Comments::find($id); $post = Posts::find($comment->on_post); $slug = $post->slug; if ($comment && ($comment->from_user == $request->user()->id || $request->user()->is_admin() || $request->user()->is_moderator())) { $comment->delete(); $data['message'] = 'Comment deleted Successfully'; } else { $data['errors'] = 'Invalid Operation. You have not sufficient permissions'; } return redirect('/' . $slug)->with($data); }
public function home() { $posts = Posts::all(); $allTxt = array(); $i = 0; foreach ($posts as $post) { if ($post->active == 1 && !$post->expired() && $post->type == 0 && empty($post->image)) { $allTxt[$i] = array('title' => $post->title, 'description' => $post->description, 'uname' => $post->user->userName(), 'dateon' => date('d-M-y h:i a', strtotime($post->created_at)), 'deptname' => $post->deptName->name); $i++; } } return view('newUI')->with('posts', $posts)->with('allTxt', $allTxt); }
public function getPosts() { try { $statusCode = 200; $response = ['posts' => []]; $posts = Posts::all(); } catch (Exception $e) { $statusCode = 400; } finally { // return Response::json($response, $statusCode); return Response::json(array('statuscode' => $statusCode, 'posts' => $posts->toArray())); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // pokazhi post so soodvetniot id, zaedno so site negovi komentari $post = Posts::where('id', $id)->first(); if (!$post) { // ne postoi toj post, vrakja 500 error } $comments = $post->comments; $likes = $post->likes; return response()->json($post, 200); // ->setCallback($request->input('callback')); // return view('posts.show')->withPost($post)->withComments($comments); }
public function index($slug = 0) { # обращаемся к моделе Category $category_model = new Categories(); $categories = $category_model->cats_for_header(); # обращаемся к моделе Page $pages = new Page(); $footer_pages = $pages->footer_pages(); if (isset($slug) && !empty($slug)) { //категория есть, выводим по ней посты //тут нужно сначала проверить категорию и вытащить ее айди $cat_id = $category_model->select_cat($slug); $postsi = new Posts(); $posts = $postsi->post_of_category($slug); return view('layouts.category_lay', ['categories' => $categories, 'pages' => $footer_pages, 'content_layout' => 'posts_content', 'posts' => $posts]); } else { //категория не указана, выводим список категорий // зделаем запрос на категорию с картинкой и количеством постов внем $posts = $category_model->cats_page(); return view('layouts.categories_lay', ['categories' => $categories, 'pages' => $footer_pages, 'content_layout' => 'posts_content', 'posts' => $posts]); } // return view('layouts.default',['categories' => $categories]); }
/** * Delete the specified resource in storage. * * @param int $id * @return Response */ public function delete($id) { $post = \App\Posts::find($id); $user_id = $post->user()->id; $post->delete(); // Send a message to the user. $reason = $_POST['reason']; if (isset($_POST['other_reason']) && $_POST['other_reason'] != "") { $reason = $_POST['other_reason']; } else { $reason = $_POST['reason']; } $message = "Your post has been removed due to the following reason: " . $reason; \App\Message::send((int) $_POST['user_id'], 0, "Your post has been removed", $message); header('Location:' . url('admin/users/edit/' . $user_id)); exit; }
public function dashboard() { // current month name // dd(date("F", mktime(0, 0, 0, Carbon::now()->month, 10))); // dd(Carbon::now()->subMonth()->startOfMonth()); // dd(date("F", mktime(0, 0, 0, Carbon::now()->subMonth()->startOfMonth()->month, 10))); $currentMonthStart = Carbon::now()->startOfMonth(); $subOneMonthStart = Carbon::now()->subMonth()->startOfMonth(); $subTwoMonthsStart = Carbon::now()->subMonth(2)->startOfMonth(); $subThreeMonthsStart = Carbon::now()->subMonth(3)->startOfMonth(); $subFourMonthsStart = Carbon::now()->subMonth(4)->startOfMonth(); $subFiveMonthsStart = Carbon::now()->subMonth(5)->startOfMonth(); $currentMonthEnd = Carbon::now()->endOfMonth(); $subOneMonthEnd = Carbon::now()->subMonth()->endOfMonth(); $subTwoMonthsEnd = Carbon::now()->subMonth(2)->endOfMonth(); $subThreeMonthsEnd = Carbon::now()->subMonth(3)->endOfMonth(); $subFourMonthsEnd = Carbon::now()->subMonth(4)->endOfMonth(); $subFiveMonthsEnd = Carbon::now()->subMonth(5)->endOfMonth(); $currentMonthTitle = date("F", mktime(0, 0, 0, Carbon::now()->startOfMonth()->month, 10)); $subOneMonthTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth()->startOfMonth()->month, 10)); $subTwoMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(2)->startOfMonth()->month, 10)); $subThreeMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(3)->startOfMonth()->month, 10)); $subFourMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(4)->startOfMonth()->month, 10)); $subFiveMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(5)->startOfMonth()->month, 10)); $postsCurrentMonth = Posts::where('created_at', '>=', $currentMonthStart)->count(); $postsSubOneMonth = Posts::where('created_at', '>=', $subOneMonthStart)->where('created_at', '<=', $subOneMonthEnd)->count(); $postsSubTwoMonths = Posts::where('created_at', '>=', $subTwoMonthsStart)->where('created_at', '<=', $subTwoMonthsEnd)->count(); $postsSubThreeMonths = Posts::where('created_at', '>=', $subThreeMonthsStart)->where('created_at', '<=', $subThreeMonthsEnd)->count(); $postsSubFourMonths = Posts::where('created_at', '>=', $subFourMonthsStart)->where('created_at', '<=', $subFourMonthsEnd)->count(); $postsSubFiveMonths = Posts::where('created_at', '>=', $subFiveMonthsStart)->where('created_at', '<=', $subFiveMonthsEnd)->count(); $commentsCurrentMonth = Comments::where('created_at', '>=', $currentMonthStart)->count(); $commentsSubOneMonth = Comments::where('created_at', '>=', $subOneMonthStart)->where('created_at', '<=', $subOneMonthEnd)->count(); $commentsSubTwoMonths = Comments::where('created_at', '>=', $subTwoMonthsStart)->where('created_at', '<=', $subTwoMonthsEnd)->count(); $commentsSubThreeMonths = Comments::where('created_at', '>=', $subThreeMonthsStart)->where('created_at', '<=', $subThreeMonthsEnd)->count(); $commentsSubFourMonths = Comments::where('created_at', '>=', $subFourMonthsStart)->where('created_at', '<=', $subFourMonthsEnd)->count(); $commentsSubFiveMonths = Comments::where('created_at', '>=', $subFiveMonthsStart)->where('created_at', '<=', $subFiveMonthsEnd)->count(); // $posts = Posts::where('active','1')->where('archive','0')->orderBy('created_at','desc')->paginate(10); // $postsPending = Posts::where('active','0')->orderBy('created_at','desc')->get(); // $postsPendingCount = Posts::where('active','0')->count(); $popularPosts = DB::table('comments')->join('posts', 'posts.id', '=', 'comments.on_post')->where('posts.archive', '=', 0)->select(array('posts.title', DB::raw('COUNT(comments.on_post) as totalComments')))->groupBy('on_post')->orderBy('totalComments', 'desc')->take(10)->get(); return view('pages.dashboard', compact('currentMonthTitle', 'subOneMonthTitle', 'subTwoMonthsTitle', 'subThreeMonthsTitle', 'subFourMonthsTitle', 'subFiveMonthsTitle', 'postsCurrentMonth', 'postsSubOneMonth', 'postsSubTwoMonths', 'postsSubThreeMonths', 'postsSubFourMonths', 'postsSubFiveMonths', 'commentsCurrentMonth', 'commentsSubOneMonth', 'commentsSubTwoMonths', 'commentsSubThreeMonths', 'commentsSubFourMonths', 'commentsSubFiveMonths', 'popularPosts')); }
public function actionSave() { $repo = $this->em->getRepository(Posts::getClassName()); $oPost = $repo->find($this->request->getPost('id')); if (is_null($oPost)) { $oPost = new Posts(); } $oPost->title = $this->request->getPost('title'); $oPost->content = $this->request->getPost('content'); $oPost->intro = strip_tags($this->request->getPost('intro')); $oPost->createdAt = $this->request->getPost('created_at') . " 00:00:00"; $postCover = $this->savePostCover(); if ($postCover) { $oPost->postCover = $postCover; } $this->em->persist($oPost); $this->em->flush(); $this->flashMessage('Thank you for your comment', 'success'); $this->redirectUrl('/#/post/' . $oPost->id); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $rules = array('title' => 'required|max:255|min:5|string', 'body' => 'required|max:2000|min:5|string', 'browser' => 'min:1|max:20'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('create')->withErrors($validator); } $data = array('title' => Purifier::clean($request->input('title')), 'body' => Purifier::clean($request->input('body')), 'image' => Purifier::clean($request->input('image')), 'ip' => $request->getClientIp(), 'browser' => Purifier::clean($request->input('browser')), 'country' => UserClients::getCountry($request->getClientIp()), 'date' => time()); Posts::create($data); return Redirect::to('/'); }