コード例 #1
0
ファイル: MostView.php プロジェクト: kooler62/liveandlearn
 public function run()
 {
     $posts_model = new Posts();
     $most = $posts_model->most_view();
     //dd($most);
     return view("widgets.most_view", ['most_view_posts' => $most]);
 }
コード例 #2
0
 /**
  * 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++;
             }
         }
     }
 }
コード例 #3
0
 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]);
 }
コード例 #4
0
 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]);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
ファイル: Blog.php プロジェクト: regiss/doctrine-sand
 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');
     //		}
 }
コード例 #9
0
 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;
 }
コード例 #10
0
ファイル: WelcomeController.php プロジェクト: nilsma/agtp
 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);
 }
コード例 #11
0
ファイル: PagesController.php プロジェクト: ronal2do/stq001
 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'));
 }
コード例 #12
0
 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
 }
コード例 #14
0
 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]);
     }
 }
コード例 #16
0
 /**
  * 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);
 }
コード例 #17
0
 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));
 }
コード例 #18
0
 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');
 }
コード例 #19
0
ファイル: Posts.php プロジェクト: steakyfask/ShareStuff
 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();
 }
コード例 #20
0
ファイル: WelcomeController.php プロジェクト: AsepSanjay/blog
 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());
     }
 }
コード例 #21
0
ファイル: NewPost.php プロジェクト: austin43/personal-site
 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);
     }
 }
コード例 #22
0
 /**
  * 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);
 }
コード例 #23
0
ファイル: Home.php プロジェクト: keshavkatwe/advsystem
 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);
 }
コード例 #24
0
 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()));
     }
 }
コード例 #25
0
 /**
  * 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);
 }
コード例 #26
0
 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]);
 }
コード例 #27
0
 /**
  * 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;
 }
コード例 #28
0
ファイル: PagesController.php プロジェクト: ehumps/whiteboard
 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'));
 }
コード例 #29
0
ファイル: PostPresenter.php プロジェクト: rutrader/nette-blog
 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);
 }
コード例 #30
-1
 /**
  * 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('/');
 }