Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postStore()
 {
     if (Session::get('user_level') < Config::get('cms.editComments')) {
         return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
     }
     $rules = array('commentContent' => 'Required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to(_l(URL::action('MemeCommentController@getCreate') . '/' . Input::get('newsId')))->withErrors($validator)->withInput();
     } else {
         try {
             $comment = new MemeComment();
             if (Input::get('createdAt')) {
                 $comment->created_at = date("Y-m-d H:i:s", strtotime(Input::get('createdAt')));
             } else {
                 $comment->created_at = date("Y-m-d H:i:s", strtotime('now'));
             }
             $comment->comment_content = Input::get('commentContent');
             $comment->published = Input::get('published');
             $comment->username = Config::get('settings.commentSignature');
             $comment->email = Config::get('settings.generalEmail');
             $comment->user_id = 1;
             $comment->news_id = Input::get('newsId');
             $comment->save();
             return Redirect::to(_l(URL::action('MemeCommentController@getEdit') . "/" . $comment->id))->with('message', Lang::get('admin.commentSaved'))->with('notif', 'success');
         } catch (Exception $e) {
             return Redirect::to(_l(URL::action('MemeCommentController@getIndex')))->with('message', Lang::get('admin.noSuchComment'))->with('notif', 'danger');
         }
     }
 }
Exemplo n.º 2
0
 public function postCreateMemeComment($id)
 {
     try {
         $comment = new MemeComment();
         $news = MemeInstance::findOrFail($id);
         if (Input::get('createdAt')) {
             $comment->created_at = date("Y-m-d H:i:s", strtotime(Input::get('createdAt')));
         } else {
             $comment->created_at = date("Y-m-d H:i:s", strtotime('now'));
         }
         $comment->comment_content = Input::get('commentContent');
         $akismet = new Akismet('http://www.puskice.org/', '5fa6e0236f7b');
         $akismet->setCommentAuthor($comment->username);
         $akismet->setCommentAuthorEmail($comment->email);
         $akismet->setCommentAuthorURL("");
         $akismet->setCommentContent($comment->comment_content);
         $akismet->setPermalink('http://www.puskice.org/meme/' . $news->id . '-' . $news->permalink);
         if ($akismet->isCommentSpam()) {
             $comment->deleted_at = date('Y-m-d H:i:s', strtotime('now'));
         }
         if (Input::get('user_id')) {
             $comment->published = 1;
         } else {
             $comment->published = 0;
         }
         if (Input::get('user_id')) {
             $user = User::find(Input::get('user_id'));
             $comment->username = $user->username;
             $comment->email = $user->email;
         } else {
             $comment->username = Input::get('username');
             $comment->email = Input::get('email');
         }
         if (Input::get('user_id')) {
             $comment->user_id = Input::get('user_id');
         } else {
             $comment->user_id = 0;
         }
         $comment->news_id = $id;
         $comment->ip_address = Puskice::getIP();
         $comment->save();
         if ($comment->deleted_at == null) {
             $user = array('email' => '*****@*****.**', 'name' => 'Info tim');
             // the data that will be passed into the mail view blade template
             $data = array('url' => "http://www.puskice.org//" . Config::get('settings.admin_url') . "/meme-comments/edit/" . $comment->id, 'approve_url' => "http://www.puskice.org//" . Config::get('settings.admin_url') . "/meme-comments/publish/" . $comment->id, 'delete_url' => "http://www.puskice.org//" . Config::get('settings.admin_url') . "/meme-comments/trash/" . $comment->id, 'username' => $comment->username, 'email' => $comment->email, 'title' => $news->title, 'news' => 1, 'news_id' => $news->id, 'content' => $comment->comment_content);
             // use Mail::send function to send email passing the data and using the $user variable in the closure
             Mail::send('emails.new_comment', $data, function ($message) use($user) {
                 $message->from('*****@*****.**', "Puškice cenzura");
                 $message->to('*****@*****.**', 'Info tim Puškice')->subject('Novi meme komentar čeka moderaciju');
             });
         }
         return Response::json(array('status' => 'success', 'message' => __("Ваш коментар је успешно прослеђен")));
     } catch (Exception $e) {
         return Response::json(array('status' => 'fail'));
     }
 }