Example #1
0
 public function getThumbsDown($id)
 {
     try {
         $valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 5)->where('object_id', '=', $id)->first();
         if ($valid_ip != null) {
             throw new Exception("Error valid IP", 1);
         }
         $news = News::findOrFail($id);
         $news->thumbs_down++;
         $news->save();
         $thumb = new Thumb();
         $thumb->ip = Puskice::getIP();
         $thumb->object_id = $news->id;
         $thumb->object_type = 5;
         $thumb->save();
         $thumbs = array();
         if (Cookie::get('ps_thumbs')) {
             $cookie = Cookie::get('ps_thumbs');
             $thumbs = unserialize($cookie);
             if (isset($thumbs['page'][$news->id])) {
                 return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили ову вест")));
             }
         }
         $thumbs['page'][$news->id] = 'down';
         Cookie::queue('ps_thumbs', serialize($thumbs), 2628000);
         return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $news->thumbs_up, 'thumbsDown' => $news->thumbs_down));
     } catch (Exception $e) {
         return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили ову страницу")));
     }
 }
Example #2
0
 /**
  * Show the form for editing the specified resource.
  * GET /api/apipoll/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function postCastVote()
 {
     $this->googleAnalytics('/polls/cast-vote/');
     $rules = array('poll_id' => 'Required', 'option_id' => 'Required');
     $v = Validator::make(Input::all(), $rules);
     if ($v->passes()) {
         $ip = Puskice::getIP();
         $vote = PollVote::where('poll_id', '=', Input::get("poll_id"))->where('ip_address', '=', $ip)->first();
         if ($vote != null) {
             return Response::json(array('status' => 'fail', 'text' => __("Већ сте гласали на овој анкети. Хвала :)")));
         }
         $vote = new PollVote();
         $vote->poll_id = strip_tags(Input::get("poll_id"));
         $vote->option_id = strip_tags(Input::get("option_id"));
         $vote->ip_address = $ip;
         $vote->save();
         $option = PollOption::find(Input::get("option_id"));
         $poll = Poll::find($option->poll_id);
         if ($poll->published == 1) {
             $option->vote_count = $option->vote_count + 1;
             $option->save();
             return Response::json(array('status' => 'success', 'text' => __("Хвала што сте гласали")));
         }
         return Response::json(array('status' => 'fail', 'text' => __("Хвала што покушавате да хакујете анкету :)")));
     } else {
         return Response::json(array('status' => 'fail', 'text' => __("Десила се грешка")));
     }
 }
 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'));
     }
 }
Example #4
0
 public static function getFacebookLoginFormLink()
 {
     // Checking Session
     $object = "";
     if (Session::get('fb_token')) {
         try {
             $session = new FacebookSession(Session::get('fb_token'));
             $response = (new FacebookRequest($session, 'GET', '/me'))->execute();
             $object = $response->getGraphObject();
         } catch (FacebookRequestException $ex) {
             return $ex->getMessage();
         } catch (\Exception $ex) {
             return $ex->getMessage();
         }
         return "<span class='skills'>" . $object->getProperty('name') . '</span>';
     } else {
         // Requested permissions - optional
         $permissions = array('email', 'publish_actions');
         // Login Healper with reditect URI
         if (Input::get('ref')) {
             $helper = new FacebookRedirectLoginHelper('http://www.puskice.org/login/redirect-here');
         }
         if (Input::get('subdomain') && Input::get('subdomain') == 'bazaznanja') {
             $helper = new FacebookRedirectLoginHelper('http://www.puskice.org/login/redirect-here');
         } else {
             $helper = new FacebookRedirectLoginHelper('http://www.puskice.org/login/redirect-here');
         }
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // Exception
             return Lang::get('frontend.fb_problem');
         } catch (Exception $ex) {
             // When validation fails or other local issues
             return Lang::get('frontend.fb_our_problem');
         }
         if (isset($session)) {
             Session::put('fb_token', $session->getToken());
             // Request for user data
             $request = new FacebookRequest($session, 'GET', '/me');
             $response = $request->execute();
             // Responce
             $object = $response->getGraphObject();
             Session::put('facebook_id', $object->getProperty('id'));
             try {
                 $user = User::where('facebook_id', '=', $object->getProperty('id'))->orWhere('email', 'LIKE', $object->getProperty('email'))->firstOrFail();
                 $user->first_name = $object->getProperty('first_name');
                 $user->last_name = $object->getProperty('last_name');
                 $user->last_login = date("Y-m-d H:i:s", strtotime('now'));
                 $user->last_login_ip = Puskice::getIP();
                 $user->loginhash = md5(strtotime('now') . $user->username);
                 $user->facebook_id = $object->getProperty('id');
                 $user->email = $object->getProperty('email');
                 $user->fb_token = $session->getToken();
                 //$user->gender = $object->getProperty('gender');
                 $user->save();
                 Session::put('id', $user->id);
             } catch (Exception $e) {
                 $user = new User();
                 $user->first_name = $object->getProperty('first_name');
                 $user->last_name = $object->getProperty('last_name');
                 $password = rand(100000, 999999);
                 $i = 0;
                 while (!isset($user->username) || $user->username == "") {
                     if ($i != 0) {
                         $username .= '' . $i;
                     }
                     try {
                         $testuser = User::where('username', '=', $username)->firstOrFail();
                         $i++;
                         continue;
                     } catch (Exception $e) {
                         $user->username = $username;
                     }
                 }
                 $user->password = sha1($password);
                 $user->user_level = 1;
                 $user->published = 1;
                 $user->last_login = date("Y-m-d H:i:s", strtotime('now'));
                 $user->last_login_ip = Puskice::getIP();
                 $user->loginhash = md5(strtotime('now') . $user->username);
                 $user->facebook_id = $object->getProperty('id');
                 $user->email = $object->getProperty('email');
                 $user->fb_token = $session->getToken();
                 $user->gender = $object->getProperty('gender');
                 $user->save();
                 $sender = array('email' => '*****@*****.**', 'name' => 'Puškice nalog', 'user_email' => $user->email, 'user_name' => $user->username);
                 // the data that will be passed into the mail view blade template
                 $data = array('username' => $user->username, 'password' => $password);
                 // use Mail::send function to send email passing the data and using the $user variable in the closure
                 Mail::send('emails.fbnewuser', $data, function ($message) use($sender) {
                     $message->from('*****@*****.**', 'Info tim Puškice');
                     $message->to($sender['user_email'], $sender['user_name'])->subject('Puškice nalog');
                 });
                 Session::put('id', $user->id);
             }
             return "<li>" . $object->getProperty('name') . '</li>';
         } else {
             // Login URL if session not found
             //return '<div class="fb-login-button" data-max-rows="1" data-scope="public_profile,email" data-size="medium" data-show-faces="false" data-auto-logout-link="false"></div>';
             return '<a href="' . $helper->getLoginUrl($permissions) . '"><img src="' . Request::root() . '/assets/frontend/img/facebook_login.png" alt="Facebook login" width="200px"/></a>';
         }
     }
 }