/**
  * Display a administrator dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $activities = Activity::with('contributor')->paginate(8);
     $statistics = ['ARTICLES' => Article::count(), 'MEMBERS' => Contributor::count(), 'CATEGORIES' => Subcategory::count(), 'MESSAGES' => Message::count(), 'FEEDBACK' => Feedback::count(), 'VISITORS' => (int) Visitor::sum('unique')];
     $visitors = Visitor::take(10)->get();
     return view('admin.dashboard.index', compact('activities', 'statistics', 'visitors'));
 }
Ejemplo n.º 2
0
 public function broadcastArticle($slug)
 {
     $article = Article::whereSlug($slug)->firstOrFail();
     $article->featured_ref = asset('images/featured/' . $article->featured);
     $headers = array('Authorization: key=' . env('GCM_KEY'), 'Content-Type: application/json');
     $data = ["to" => "/topics/article", "notification" => ["title" => "Infogue.id updates", "body" => $article->title, "id" => $article->id, "title" => $article->title, "slug" => $article->slug, "featured_ref" => $article->featured_ref]];
     // Open connection
     $ch = curl_init();
     // Set the url, number of POST vars, POST data
     curl_setopt($ch, CURLOPT_URL, env('GCM_URL'));
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Disabling SSL Certificate support temporarily
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
     // Execute post
     $result = curl_exec($ch);
     if ($result === FALSE) {
         // die('Curl failed: ' . curl_error($ch));
     }
     // Close connection
     curl_close($ch);
     return $result;
 }
 /**
  * Display a listing of the contributor article.
  *
  * @param Request $requests
  * @param $username
  * @return \Illuminate\Http\Response
  */
 public function article(Request $requests, $username)
 {
     $contributor_id = $requests->get('contributor_id');
     $my_article = filter_var($requests->get('my_article'), FILTER_VALIDATE_BOOLEAN);
     if ($my_article) {
         $article = new Article();
         $articles = $article->archive('all-data', 'date', 'desc', $contributor_id);
     } else {
         $articles = $this->contributor->contributorArticle($username);
     }
     $contributor = $this->contributor->profile($username, true, $contributor_id, true);
     return $this->responseData($contributor, 'articles', $articles);
 }
Ejemplo n.º 4
0
 /**
  * Store a newly comment in storage.
  *
  * @param \Illuminate\Http\Request
  * @param $slug
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $slug)
 {
     $rules = ['comment' => 'required|max:2000'];
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $article = Article::whereSlug($slug)->firstOrFail();
     $comment = new Comment();
     $comment->contributor_id = Auth::user()->id;
     $comment->article_id = $article->id;
     $comment->comment = $request->input('comment');
     if ($comment->save()) {
         return redirect(route('article.show', [$slug]) . '#form-comment')->with(['status' => 'success', 'message' => Lang::get('alert.comment.send')]);
     }
     return redirect()->back()->withErrors(['error' => Lang::get('alert.error.database')]);
 }
Ejemplo n.º 5
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $visitor = new Visitor();
     $visitor->checkVisitor();
     $this->app->singleton('site_settings', function () {
         $settings = Setting::all();
         $keys = array();
         foreach ($settings as $setting) {
             $keys[$setting->key] = $setting->value;
         }
         return $keys;
     });
     View::share('site_settings', app('site_settings'));
     $this->app->singleton('site_menus', function () {
         $categories = Category::all();
         return $categories;
     });
     View::share('site_menus', app('site_menus'));
     $this->app->singleton('site_statistic', function () {
         $article = Article::whereStatus('published')->count();
         $member = Contributor::whereStatus('activated')->count();
         return ['article' => $article, 'member' => $member];
     });
     View::share('site_statistic', app('site_statistic'));
     Validator::extend('check_password', function ($attribute, $value, $parameter) {
         if (count($parameter) > 0 && $parameter[0] == 'admin') {
             return Hash::check($value, Auth::guard('admin')->user()->getAuthPassword());
         }
         return Hash::check($value, Auth::user()->getAuthPassword());
     });
     Blade::directive('datetime', function ($expression) {
         return "<?php echo with{$expression}->format('d/m/Y H:i'); ?>";
     });
     Blade::directive('simpledate', function ($expression) {
         return "<?php echo with{$expression}->format('d M Y'); ?>";
     });
     Blade::directive('fulldate', function ($expression) {
         return "<?php echo with{$expression}->format('d F Y'); ?>";
     });
     Blade::directive('datetime', function ($expression) {
         return "<?php echo with{$expression}->format('d F Y h:m A'); ?>";
     });
 }
Ejemplo n.º 6
0
 public function index(Request $request)
 {
     $type = $request->get("type", "rss");
     // create new feed
     $feed = App::make("feed");
     // multiple feeds are supported
     // if you are using caching you should set different cache keys for your feeds
     // cache the feed for 60 minutes (second parameter is optional)
     //$feed->setCache(60, 'infogueFeedKey');
     $feed->title = 'Infogue news feed ' . $type;
     // check if there is cached feed and build new only if is not
     if (true) {
         // creating rss feed with our most recent 20 posts
         $posts = Article::take(20)->published()->get();
         // set your feed's title, description, link, pubdate and language
         $feed->description = 'The most update web portal news. We always provide latest article and information with high integrity and truth.';
         $feed->logo = asset('apple-touch-icon.png');
         $feed->link = url('feed');
         $feed->setDateFormat('datetime');
         // 'datetime', 'timestamp' or 'carbon'
         $feed->pubdate = $posts->first()->created_at;
         $feed->lang = 'en';
         $feed->setShortening(true);
         // true or false
         $feed->setTextLimit(100);
         // maximum length of description text
         foreach ($posts as $post) {
             // use enclosure tag (array)
             $enclosure = ['url' => asset("images/" . $post->featured), 'type' => 'image/jpeg'];
             // set item's title, author, url, pubdate, description, content, enclosure (optional)*
             $feed->add($post->title, $post->contributor->name, URL::to($post->slug), $post->created_at, preg_replace('/\\s\\s+/', ' ', trim(preg_replace("/&#?[a-z0-9]+;/i", " ", strip_tags($post->content)))), $post->content, $enclosure);
         }
     }
     // first param is the feed format
     // optional: second param is cache duration (value of 0 turns off caching)
     // optional: you can set custom cache key with 3rd param as string
     if ($type == "rss") {
         return $feed->render('rss');
     }
     return $feed->render('atom');
     // to return your feed as a string set second param to -1
     // $xml = $feed->render('atom', -1);
 }
Ejemplo n.º 7
0
 /**
  * Retrieve updates newsletter by certain period
  *
  * @param string $range
  * @return Collection
  */
 public function newsletter($range = 'daily')
 {
     $date = Carbon::now()->addDay(-3);
     $take = 5;
     if ($range == 'daily') {
         $date = Carbon::now()->addDay(-1);
     } else {
         if ($range == 'weekly') {
             $date = Carbon::now()->addWeek(-1);
             $take = 10;
         } else {
             if ($range == 'monthly') {
                 $date = Carbon::now()->addMonth(-1);
                 $take = 20;
             }
         }
     }
     $newsletters = Article::where('articles.created_at', '>', $date)->orderBy('view')->take($take)->get();
     return $newsletters;
 }
Ejemplo n.º 8
0
 /**
  * Show the result for finding articles.
  *
  * @return \Illuminate\Http\Response
  */
 public function searchArticle()
 {
     $article = new Article();
     $articles = $article->search(Input::get('query'), 12);
     return response()->json(['request_id' => uniqid(), 'status' => 'success', 'timestamp' => Carbon::now(), 'articles' => $articles]);
 }
Ejemplo n.º 9
0
 /**
  * Remove the specified article from storage.
  *
  * @param $slug
  * @return \Illuminate\Http\Response
  */
 public function destroy($slug)
 {
     $article = Article::whereSlug($slug)->firstOrFail();
     if ($article->delete()) {
         return response()->json(['request_id' => uniqid(), 'status' => 'success', 'message' => 'Article was deleted', 'timestamp' => Carbon::now()]);
     }
     return response()->json(['request_id' => uniqid(), 'status' => 'failure', 'message' => Lang::get('alert.error.generic'), 'timestamp' => Carbon::now()], 500);
 }
Ejemplo n.º 10
0
 /**
  * Retrieve stream by contributor.
  *
  * @param $username
  * @return mixed
  */
 public function stream($username)
 {
     $contributor = $this->whereUsername($username)->first();
     $follow = $contributor->following()->select('following')->pluck('following')->toArray();
     $article = new Article();
     $articles = $article->preArticleQuery()->published()->whereIn('contributor_id', $follow)->paginate(10);
     return $article->preArticleModifier($articles);
 }
Ejemplo n.º 11
0
 /**
  * Retrieve articles by tag.
  *
  * @param $tag
  * @return mixed
  */
 public function tagArticle($tag)
 {
     $article = new Article();
     $articles = $article->preArticleQuery()->join('article_tags', 'articles.id', '=', 'article_tags.article_id')->join('tags', 'tags.id', '=', 'tag_id')->where('tags.tag', 'like', $tag)->where('articles.status', 'published')->orderBy('articles.created_at', 'desc')->paginate(12);
     return $article->preArticleModifier($articles);
 }
Ejemplo n.º 12
0
 /**
  * Remove the specified article from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     /*
      * --------------------------------------------------------------------------
      * Delete article activity
      * --------------------------------------------------------------------------
      * Find and destroy then create new instance of Activity and insert delete
      * article activity, finally redirect to list of articles.
      */
     $article = Article::findOrFail($id);
     if ($article->delete()) {
         Activity::create(['contributor_id' => Auth::user()->id, 'activity' => Activity::deleteArticleActivity(Auth::user()->username, $article->title, $article->slug)]);
         return redirect(route('account.article.index'))->with(['status' => 'warning', 'message' => Lang::get('alert.article.delete', ['title' => $article->title])]);
     }
     return redirect()->back()->withErrors(['error' => Lang::get('alert.error.database')]);
 }
Ejemplo n.º 13
0
 /**
  * Remove the specified article from storage.
  *
  * @param Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     /*
      * --------------------------------------------------------------------------
      * Delete article
      * --------------------------------------------------------------------------
      * Check if selected variable is not empty so user intends to select multiple
      * rows at once, and prepare the feedback message according the type of
      * deletion action.
      */
     if (!empty(trim($request->input('selected')))) {
         $article_ids = explode(',', $request->input('selected'));
         $delete = Article::whereIn('id', $article_ids)->delete();
         $message = Lang::get('alert.article.delete_all', ['count' => $delete]);
     } else {
         $article = Article::findOrFail($id);
         $message = Lang::get('alert.article.delete', ['title' => $article->title]);
         $delete = $article->delete();
     }
     if ($delete) {
         return redirect(route('admin.article.index'))->with(['status' => 'warning', 'message' => $message]);
     } else {
         return redirect()->back()->withErrors(['error' => Lang::get('alert.error.database')]);
     }
 }
Ejemplo n.º 14
0
 /**
  * Retrieve articles by subcategory.
  *
  * @param $id
  * @return mixed
  */
 public function subcategoryArticle($id)
 {
     $article = new Article();
     $articles = $article->preArticleQuery()->where('articles.status', 'published')->where('subcategory_id', $id)->orderBy('articles.created_at', 'desc')->paginate(12);
     return $article->preArticleModifier($articles);
 }
Ejemplo n.º 15
0
 /**
  * Fetch random article.
  *
  * @return mixed
  */
 public function random()
 {
     $article = new Article();
     $random = $article->archive('all-data', 'view', 'random');
     $data = $this->reduceArticleData($random);
     return response()->json(['request_id' => uniqid(), 'status' => 'success', 'articles' => $data, 'timestamp' => Carbon::now()]);
 }
Ejemplo n.º 16
0
 /**
  * Show the result for finding articles.
  *
  * @return \Illuminate\Http\Response
  */
 public function searchArticle()
 {
     $article = new Article();
     $article_result = $article->search(Input::get('query'));
     $total_result = $article_result->total();
     return view('pages.search', compact('article_result', 'total_result'));
 }