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); }
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); }
/** * 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 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 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); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $allUserPosts = Posts::where('user_id', \Auth::user()->id)->orderBy('created_at', 'DESC')->get(); // $UAI = UserAdditionalInfo::findOrFail($UAI_id); // $userInfo = UserAdditionalInfo::where('user_id', \Auth::user()->id)->first(); $userInfo = \Auth::user(); $allEvents = Events::orderBy('created_at', 'DESC')->take(2)->get(); $allUserPhotos = PhotoMapImageUploader::where('userId', \Auth::user()->id)->orderBy('photoMapId', 'DESC')->take(6)->get(); return view('profilePage.index', compact('allUserPosts', 'userInfo', 'allEvents', 'allUserPhotos')); }
public function managePost() { $user_id = Auth::user()->id; if ($user_id == 1) { $arrPost = Posts::all(); } else { $arrPost = Posts::where('user_id', '=', $user_id)->get(); } return view('pages.managePost', array('arrPost' => $arrPost)); }
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()); } }
/** * 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++; } } } }
/** * 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 show($slug) { $post = Posts::where('slug', $slug)->first(); if ($post) { if ($post->active == false) { return redirect('/'); } $comments = $post->comments; } else { return redirect('/'); } return view('posts.show')->withPost($post)->withComments($comments); }
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')); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request) { // $post_id = $request->input('post_id'); $post = Posts::find($post_id); if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) { $title = $request->input('title'); $subtitle = $request->input('subtitle'); $slug = str_slug($title); $duplicate = Posts::where('slug', $slug)->first(); if ($duplicate) { if ($duplicate->id != $post_id) { return redirect('edit/' . $post->slug)->withErrors('Title already exists.')->withInput(); } else { $post->slug = $slug; } } $post->title = $title; $post->subtitle = $subtitle; $post->body = $request->input('body'); if ($request->has('save')) { $post->active = 0; $message = 'Post saved successfully'; $landing = 'edit/' . $post->slug; } else { $post->active = 1; $message = 'Post updated successfully'; $landing = $post->slug; } $post->save(); return redirect($landing)->withMessage($message); } else { return redirect('/')->withErrors('you have not sufficient permissions'); } }
public function viewPost($postID) { if (!auth() || !auth()->user()) { $browser = get_browser(null, true); // Allow crawler && Facebook Bot view post without logging in. if ($browser['crawler'] != 1 && stripos($_SERVER["HTTP_USER_AGENT"], 'facebook') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'face') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'google') === false) { $redirectPath = '/post/' . $postID; return redirect('/login')->with('redirectPath', $redirectPath); } $token = md5(rand(), false); $DisplayedQuestions = ConstsAndFuncs::$FreeQuestionsForCrawler; } $post = Posts::find($postID); if (count($post) < 1) { return view('errors.404'); } $courseID = $post['CourseID']; $course = Courses::find($courseID); $post->visited++; $post->update(); $post = $post->toArray(); if (auth() && auth()->user()) { $userID = auth()->user()->getAuthIdentifier(); if (User::find($userID)['admin'] < ConstsAndFuncs::PERM_ADMIN) { if ($course['Hidden'] == 1 || $post['Hidden'] == 1) { return view('errors.404'); } } $tmp = Learnings::where('UserID', '=', $userID)->where('CourseID', '=', $courseID)->get()->toArray(); if (count($tmp) < 1) { $learnings = new Learnings(); $learnings->UserID = $userID; $learnings->CourseID = $courseID; $learnings->save(); $course->NoOfUsers++; $course->update(); } // Insert a new record into DoExams Table to mark the time user start answering questions in post. $exam = new Doexams(); $exam->UserID = $userID; $exam->PostID = $postID; $token = md5($userID . rand(), false) . md5($postID . rand(), false); $exam->token = $token; $exam->save(); // Check if user is vip or not $user = User::find(auth()->user()->getAuthIdentifier()); if ($user['vip'] == 0) { $DisplayedQuestions = $post['NoOfFreeQuestions']; } else { $DisplayedQuestions = new \DateTime($user['expire_at']) >= new \DateTime() ? -1 : $post['NoOfFreeQuestions']; } if ($user['admin'] >= ConstsAndFuncs::PERM_ADMIN) { $DisplayedQuestions = -1; } // If web hasn't provide some VIP package // every user will be able to see full post if (ConstsAndFuncs::IS_PAID == 0) { $DisplayedQuestions = -1; } } $photo = $post['Photo']; if ($DisplayedQuestions > 0) { $questions = Questions::where('PostID', '=', $postID)->take($DisplayedQuestions)->get()->toArray(); } else { $questions = Questions::where('PostID', '=', $postID)->get()->toArray(); } $AnswersFor1 = array(); $TrueAnswersFor1 = array(); $AnswersFor2 = array(); $Spaces = array(); $SetOfSpaceIDs = array(); $Subquestions = array(); $AnswersFor5 = array(); $QuestionFor5IDs = array(); $AnswersFor6 = array(); $DragDropIDs = array(); $CompleteAnswersFor6 = array(); $AnswersFor3 = array(); $AnswersFor4 = array(); $FillCharacterIDs = array(); $ArrangedIDs = array(); $maxscore = 0; foreach ($questions as $q) { switch ($q['FormatID']) { case 1: // Trắc nghiệm $answers = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); foreach ($answers as $a) { if ($a['Logical'] == 1) { $TrueAnswersFor1 += [$q['id'] => $a['id']]; break; } } $info = [$q['id'] => $answers]; if (count($answers) > 0) { $maxscore++; } $AnswersFor1 += $info; continue; case 2: // Điền từ $spaces = Spaces::where('QuestionID', '=', $q['id'])->get()->toArray(); $Spaces += [$q['id'] => $spaces]; foreach ($spaces as $s) { $SetOfSpaceIDs = array_merge($SetOfSpaceIDs, [$s['id']]); $a = Answers::where('SpaceID', '=', $s['id'])->get()->toArray(); shuffle($a); $AnswersFor2 += [$s['id'] => $a]; } $maxscore += count($spaces); continue; case 3: $answer = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); $AnswersFor3 += [$q['id'] => $answer[0]]; $ArrangedIDs = array_merge($ArrangedIDs, [$q['id']]); $maxscore++; continue; case 4: $answer = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); $AnswersFor4 += [$q['id'] => $answer[0]]; $FillCharacterIDs = array_merge($FillCharacterIDs, [$q['id']]); $maxscore++; continue; case 5: // Nối $subquestions = Subquestions::where('QuestionID', '=', $q['id'])->get()->toArray(); $answer = array(); foreach ($subquestions as $s) { $a = Answers::where('SubQuestionID', '=', $s['id'])->get()->toArray(); $answer += [$s['id'] => $a[0]]; } $AnswersFor5 += [$q['id'] => $answer]; $maxscore += count($subquestions); $Subquestions += [$q['id'] => $subquestions]; $QuestionFor5IDs = array_merge($QuestionFor5IDs, [$q['id']]); continue; case 6: // Kéo thả $DragDropIDs = array_merge($DragDropIDs, [$q['id']]); $answers = Answers::where('QuestionID', '=', $q['id'])->get()->toArray(); $AnswersFor6 += [$q['id'] => $answers]; $s = ''; foreach ($answers as $a) { $s .= $a['Detail'] . ' '; } $CompleteAnswersFor6 += [$q['id'] => $s]; // $CompleteAnswersFor6 = array_merge($CompleteAnswersFor6, [$s]); $maxscore++; continue; } } $Comments = Comments::all()->toArray(); $result = array('Comments' => json_encode($Comments), 'Questions' => $questions, 'Post' => $post, 'MaxScore' => $maxscore, 'NumOfQuestions' => count($questions = Questions::where('PostID', '=', $postID)->get()->toArray()), 'Token' => $token, 'DisplayedQuestions' => $DisplayedQuestions); if (auth() && auth()->user() && User::find(auth()->user()->getAuthIdentifier())['admin'] >= ConstsAndFuncs::PERM_ADMIN) { $nextPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '>=', $post['id'])->get()->toArray(); $previousPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '<', $post['id'])->get()->toArray(); $result += ['NextPost' => count($nextPost) > 1 ? $nextPost[1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->first()->toArray()['id']]; $result += ['PreviousPost' => count($previousPost) > 0 ? $previousPost[count($previousPost) - 1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->orderBy('created_at', 'desc')->first()->toArray()['id']]; } else { $nextPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '>=', $post['id'])->where('Hidden', '=', 0)->get()->toArray(); $previousPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '<', $post['id'])->where('Hidden', '=', 0)->get()->toArray(); $result += ['NextPost' => count($nextPost) > 1 ? $nextPost[1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->where('Hidden', '=', 0)->first()->toArray()['id']]; $result += ['PreviousPost' => count($previousPost) > 0 ? $previousPost[count($previousPost) - 1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->where('Hidden', '=', 0)->orderBy('created_at', 'desc')->first()->toArray()['id']]; } $newpost = array_merge($nextPost, $previousPost); $result += ['newpost' => $newpost]; // dd($newpost); // dd($post); $ahtk = Tags::where('PostID', '=', $postID)->get()->toArray(); $Hashtag = array(); foreach ($ahtk as $k) { $ht = Hashtags::find($k['HashtagID'])['Hashtag']; if (strlen($ht) > 0) { $Hashtag = array_merge($Hashtag, [$ht]); } } return view('viewpost')->with($result)->with(compact(['result', 'newpost', 'Hashtag', 'AnswersFor1', 'TrueAnswersFor1', 'AnswersFor3', 'ArrangedIDs', 'Spaces', 'AnswersFor2', 'SetOfSpaceIDs', 'AnswersFor4', 'FillCharacterIDs', 'subquestions', 'AnswersFor5', 'Subquestions', 'QuestionFor5IDs', 'AnswersFor6', 'DragDropIDs', 'CompleteAnswersFor6'])); }
public function show($id) { $posts = Posts::where('id', '=', $id)->get(); $comments = Comments::where('post_id', '=', $id)->orderBy('created_at', 'desc')->get(); return view('view')->with('posts', $posts)->with('comments', $comments); }
public function removePost(Request $request) { $post = Posts::where('id', $request->id); $post->delete(); return "The post was deleted"; }
<div class="content"> <div class="input-control textarea full-size"> <textarea @if(Auth::check()) @if(Auth::user()->id<>$profile->id) readonly @endif @else readonly @endif id="info" name="info">{{ $profile->info }}</textarea> </div> @if(Auth::check()) @if(Auth::user()->id==$profile->id) <a onclick="update_status()" class="button place-right">Update</a> <div> </div> <div> </div> @endif @endif </div> </div> </div> <?php $prof = \App\Posts::where('idpengguna', $profile->id)->orderBy('id', 'desc')->paginate(3); ?> @foreach($prof as $data) @include('utils.datapost') @endforeach <span class="place-right">{!!$prof->render()!!}</span> </div> </div> </div> @endsection @section('footer') <div data-windows-style="true" data-close-button="true" data-role="dialog" id="dialog" data-overlay="true" data-overlay-color="op-gray" class="padding20 info" style="width: auto; height: auto; display: none;"> <div class="container">
public function sort(Request $request) { $criterion = $request->get('criterion'); $order = $request->get('order'); $posts = Posts::where('active', 1)->orderBy($criterion, $order)->paginate(5); $titlepost = 'News'; $titlecategory = 'Categories'; $categories = Categories::all(); return view('home')->withPosts($posts)->withCategories($categories)->withTitlepost($titlepost)->withTitlecategory($titlecategory)->withCriterion($criterion)->withOrder($order); // var_dump($posts[0]->title); // die(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } $course = Courses::find($id); $posts = Posts::where('CourseID', '=', $id)->get()->toArray(); // dd($posts); foreach ($posts as $post) { PostsController::destroy($post['id']); // dd($post['id']); } $course->delete(); return redirect(route('admin')); }
public function singlePost($slug) { $post = Posts::where('url', $slug)->first(); return view('page.single')->with('post', $post); }
public function scrapeForum() { $client = new Client(); $crawler = $client->request('GET', 'http://cmcforum.com/'); $status_code = $client->getResponse()->getStatus(); if ($status_code == 200) { echo '200 OK<br>'; } $count = 0; $crawler->filter('div.td-big-grid-wrapper div.td-big-grid-post')->each(function ($node, $count) { if ($count == 0) { $url = $node->filter('div.td-module-thumb a')->attr('href'); //url no clean $imgUrl = $node->filter('a img')->attr('src'); //imgUrl no clean $title = $node->filter('div.td-big-grid-meta h3 a')->text(); //clean title $date = substr($node->filter('div.td-big-grid-meta div.td-module-meta-info div.td-post-date time')->attr('datetime'), 0, 10); //date clean $author = $node->filter('div.td-big-grid-meta div.td-module-meta-info div.td-post-author-name a')->text(); //author clean $client2 = new Client(); $crawler2 = $client2->request('GET', $url); $description = $crawler2->filter('div.td-post-content p')->text(); $id = DB::table('email_articles')->where('post_date', $date)->value('article_id'); 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 = $description; $post->imgUrl = $imgUrl; $post->url = $url; $post->source = 'The Forum'; $post->save(); echo "stored " . $title . "!"; } } $count++; }); }
public static function getFromDate($date) { return \App\Posts::where('created_at', '>', $date)->get(); }
$arr[] = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'sampul' => url('images/' . $key['sampul']), 'judul' => $key['judul']); } echo json_encode($arr); }); Route::get('api/artikel/detail/{slug}', function ($slug) { $key = \App\Posts::where('slug', $slug)->first(); $arr = array(); $arr = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'sampul' => url('images/' . $key['sampul']), 'judul' => $key['judul']); if (sizeof($key) == 0) { $data = array('status' => "Error", 'error_code' => 1, 'name' => 'artikel_notfound', 'msg' => 'Artikel_NotFound'); echo json_encode($data); } else { echo json_encode($key); } echo json_encode($arr); }); Route::get('api/artikel/detail/{type}/{cari}', function ($type, $cari) { $data = \App\Posts::where($type, $slug)->first(); $arr = array(); foreach ($data as $key) { $arr = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'sampul' => url('images/' . $key['sampul']), 'judul' => $key['judul']); } if (sizeof($data) == 0) { $data = array('status' => "Error", 'error_code' => 1, 'name' => 'artikel_notfound', 'msg' => 'Artikel_NotFound'); echo json_encode($data); } else { echo json_encode($key); } echo json_encode($arr); }); Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController']);
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Posts::where('id', $id)->delete(); return back(); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function update(Request $request) { $post_id = $request->input('post_id'); $post = Posts::find($post_id); if ($post && ($request->user()->role == 'author' || $request->user()->is_admin())) { $title = $request->input('title'); $slug = str_slug($title); $duplicate = Posts::where('slug', $slug)->first(); if ($duplicate) { if ($duplicate->id != $post_id) { return redirect('/admin/poster/rediger/' . $post->slug)->withErrors('Title already exists.')->withInput(); } else { $post->slug = $slug; } } $post->title = $title; $post->body = $request->input('body'); if ($request->has('save')) { $post->active = 0; $message = 'Posten ble lagret!'; $message_type = 'alert alert-success'; } else { $post->active = 1; $message = 'Posten ble oppdatert!'; $message_type = 'alert alert-success'; } $post->save(); return Redirect::to('/admin/poster/alle')->with(array('alert-message' => $message, 'alert-type' => $message_type)); } else { return redirect('/')->withErrors('you have not sufficient permissions'); } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($slug) { $data = array('data' => Posts::where('slug', $slug)->first()); return view('artikel.show')->with($data); }
$data = \App\Posts::all(); $arr = array(); foreach ($data as $key) { $arr[] = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'judul' => $key['judul']); } echo json_encode($arr); // echo "<pre>".json_encode($data)."<pre>"; }); Route::get('api/artikel/detail/{slug}', function ($slug) { $key = \App\Posts::where('slug', $slug)->first(); $arr = array(); $arr[] = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'sampul' => url('images/' . $key['sampul']), 'judul' => $key['judul']); echo json_encode($arr); }); Route::get('api/artikel/{type}/{cari}', function ($type, $cari) { $data = \App\Posts::where($type, $cari)->get(); $arr = array(); foreach ($data as $key) { $arr[] = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'sampul' => url('images/' . $key['sampul']), 'judul' => $key['judul']); } if (sizeof($data) == 0) { $data = array('status' => "Error", 'error_code' => 1, 'name' => 'artikel_notfound', 'msg' => 'Artikel Not Found'); echo json_encode($data); } else { echo json_encode($arr); } }); Route::get('/', 'WelcomeController@index'); Route::get('home', 'HomeController@index'); Route::get('artikel', 'ArtikelController@index'); Route::get('artikel/add', 'ArtikelController@create');
public function emailThread(Request $request, $slug) { // dd($request->get('email')); $post = Posts::where('slug', $slug)->first(); $comments = $post->comments->where('active', '1'); $to_email = $request->get('email'); $from_name = $request->get('name'); $from_message = $request->get('body'); // enable this if you want to restrict email to a specific domain // edit the preg_match domain // // if(env('APP_ENV') == 'production') // { // if(!preg_match('/^\w+@example\.com$/i', $to_email) > 0) // { // $message = 'Please enter a work email address.'; // return redirect()->back()->withMessage($message); // } // } $data['to_email'] = $to_email; $data['post'] = $post; $data['comments'] = $comments; $data['from_name'] = $from_name; $data['from_message'] = $from_message; // return view('emails.sendThread', compact('post', 'comments', 'data', 'from_name', 'from_message')); Mail::send('emails.sendthread', $data, function ($message) use($to_email, $post, $comments, $from_name, $from_message) { $message->from(Config::get('services.email.from'), 'Whiteboard'); $message->to($to_email, 'Thread Preview')->subject('Whiteboard - Thread Preview'); }); $message = 'Email sent successfully to ' . $to_email; return redirect()->back()->withMessage($message); }
/** * Execute the console command. * * @return mixed */ public function handle() { $client = new Client(); $crawler = $client->request('GET', 'http://claremontindependent.com/category/campus-news/'); $status_code = $client->getResponse()->getStatus(); if ($status_code == 200) { echo '200 OK<br>'; } $crawler->filter('div.site-content article')->each(function ($node) { $url = $node->filter('a.post-thumbnail')->attr('href'); //url $imgUrl = $node->filter('a.post-thumbnail img')->attr('src'); //imgUrl $title = $node->filter('header h1')->text(); //title $date = substr($node->filter('header div.entry-meta span.entry-date time')->attr('datetime'), 0, 10); //date $author = $node->filter('header div.entry-meta span.byline span.author a')->text(); //author $description = substr(mb_convert_encoding($node->filter('div.entry-content p')->text(), "HTML-ENTITIES", "UTF-8"), 0, 500); //description $id = getArticleId($date); 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 = $description; $post->imgUrl = $imgUrl; $post->url = $url; $post->source = 'Claremont Independent'; $post->save(); echo "stored " . $title . "!"; } }); $client = new Client(); $crawler = $client->request('GET', 'http://www.thegoldenantlers.com/'); $status_code = $client->getResponse()->getStatus(); if ($status_code == 200) { echo '200 OK<br>'; } $count = 0; $crawler->filter('div.bl_posts_information')->each(function ($node, $count) { if ($count == 0) { $node->filter('article')->each(function ($node1) { $author = ucwords(str_replace('-', ' ', $node1->attr('data-categoryslug'))); //author $url = $node1->filter('div.post-image a')->attr('href'); //url $imgUrl = $node1->filter('div.post-image img')->attr('src'); //imgUrl $date = $node1->filter('div.post-image div.meta-info div.info-date time')->attr('datetime'); //date $date = substr(createDateAntlers($date), 0, 10); $title = $node1->filter('div.post-body h3')->text(); //title $description = str_replace("CONTINUE READING", "", trimWhiteSpace(str_replace(" ", "", mb_convert_encoding($node1->filter('div.post-body div.post-content p')->text(), "HTML-ENTITIES", "UTF-8")))); //description $id = getArticleId($date); 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 = $description; $post->imgUrl = $imgUrl; $post->url = $url; $post->source = 'The Golden Antlers'; $post->save(); echo "stored " . $title . "!"; } }); } $count++; }); $client = new Client(); $crawler = $client->request('GET', 'http://cmcforum.com/'); $status_code = $client->getResponse()->getStatus(); if ($status_code == 200) { echo '200 OK<br>'; } $count = 0; $crawler->filter('div.td-big-grid-wrapper div.td-big-grid-post')->each(function ($node, $count) { if ($count == 0) { $url = $node->filter('div.td-module-thumb a')->attr('href'); //url no clean $imgUrl = $node->filter('a img')->attr('src'); //imgUrl no clean $title = $node->filter('div.td-big-grid-meta h3 a')->text(); //clean title $date = substr($node->filter('div.td-big-grid-meta div.td-module-meta-info div.td-post-date time')->attr('datetime'), 0, 10); //date clean $author = $node->filter('div.td-big-grid-meta div.td-module-meta-info div.td-post-author-name a')->text(); //author clean $client2 = new Client(); $crawler2 = $client2->request('GET', $url); $description = $crawler2->filter('div.td-post-content p')->text(); $id = DB::table('email_articles')->where('post_date', $date)->value('article_id'); 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 = $description; $post->imgUrl = $imgUrl; $post->url = $url; $post->source = 'The Forum'; $post->save(); echo "stored " . $title . "!"; } } $count++; }); }
public function dashboard() { if ($this->checkauth(1)['err'] == 1) { return $this->checkauth(1)['view']; } Session::put('key', ""); //$this->is_open(1); $data = array(); if (Auth::check()) { $data = array('ranks' => Posts::where(array('deleted_at' => NULL, 'idpengguna' => Auth::user()->id))->orderBy('lihat', 'desc')->limit(10)->get()); } return view('admin.dashboard')->with($data); }