} public static function success($note, $redirect = false) { self::add('success', $note); if ($redirect) { site::redirect($redirect); die; }
public function action_twittercallback() { if (arr::get($_GET, 'denied', false)) { notes::error('Seems like you didn\'t want to log in with Twitter anyway. Feel free to try again if it was a mistake!'); site::redirect(); } $token = arr::get($_GET, 'oauth_token', false); $verifier = arr::get($_GET, 'oauth_verifier', false); if (!$token || !$verifier) { notes::error('Something went wrong in the process, and we didn\'t get the expected data back from Twitter. Please try again'); site::redirect(); } $connection = new TwitterOAuth(arr::get($this->creds, 'key'), arr::get($this->creds, 'secret'), Session::instance()->get_once('twitter_oauth_token'), Session::instance()->get_once('twitter_oauth_token_secret')); $token = $connection->getAccessToken($verifier); $oauth_token = arr::get($token, 'oauth_token', ''); $oauth_token_secret = arr::get($token, 'oauth_token_secret', ''); $user_id = arr::get($token, 'user_id', ''); $screen_name = arr::get($token, 'screen_name', ''); $oauth = ORM::factory('Oauth')->where('type', '=', 'twitter')->where('token', '=', $oauth_token)->find(); if ($oauth->loaded()) { try { $user = $oauth->user; user::force_login($user); } catch (exception $e) { if ($user->loaded()) { if (user::logged()) { // Random error, but user got logged in. We don't care, YOLO! } else { notes::error('Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.'); Kohana::$log->add(Log::ERROR, '1. Couldnt log user in: ' . $e->getMessage()); } } } site::redirect('write'); } else { try { $user = ORM::factory('User'); $user->username = $screen_name; $user->validation_required(false)->save(); $user->add_role('login'); $oauth = ORM::factory('Oauth'); $oauth->user_id = $user->id; $oauth->type = 'twitter'; $oauth->token = $oauth_token; $oauth->token_secret = $oauth_token_secret; $oauth->service_id = $user_id; $oauth->screen_name = $screen_name; $oauth->save(); user::force_login($user); } catch (exception $e) { Kohana::$log->add(Log::ERROR, '2. Couldnt create user: '******'Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.'); } site::redirect('/write'); } }
public function action_show() { $token = $this->request->param('id'); $mail = ORM::factory('Mail')->where('token', '=', $token)->find(); if ($mail->loaded()) { $view = View::factory('templates/mail'); $view->mail = $mail; echo $view; } else { notes::add('error', 'Mail not found!'); site::redirect(''); die; } }
/** * Add a message to the "popnotes" session. * @param String Type of message. * @param String Message * @return void */ public static function add($type, $note, $redirect = false) { $session = Session::instance(); $popnotes = $session->get('popnotes'); if (!$popnotes) { $popnotes = array(); } $content = array('type' => $type, 'note' => $note); $popnotes[] = $content; $session->set('popnotes', $popnotes);
public function require_login($msg = true, $redirect = false) { if ($msg === true) { $msg = 'You must be logged in to see this page'; } if (!user::logged()) { if ($msg) { notes::error($msg); } if ($redirect) { site::redirect($redirect); } else { user::redirect('login'); } } }
public function before() { if (!user::logged('admin') && $this->request->action() !== 'media') { site::redirect(); } if ($this->request->action() === 'media' || $this->request->action() === 'uploads') { // Do not template media files $this->auto_render = FALSE; } else { parent::before(); $this->template->controller = str_replace('cms_', '', $this->request->controller()); $this->template->action = $this->request->action(); $file = $this->template->controller . '/' . $this->template->action; $file = str_replace('_', '/', $file); if (file_exists(Kohana::find_file('views', $file))) { $this->template->view = View::factory($file); } } }
public function action_contact() { $errors = false; if ($_POST) { $val = Validation::factory($_POST); $val->rule('sprot', 'exact_length', array(':value', 1)); $val->rule('email', 'not_empty'); $val->rule('email', 'email'); $val->rule('suggestion', 'not_empty'); if ($val->check()) { notes::success('Your message has been sent and we will get back to you as soon as possible. Thanks!'); $mail = mail::create('suggestion')->to('*****@*****.**')->from(arr::get($_POST, 'email', ''))->content(arr::get($_POST, 'suggestion') . '<br /><br />.E-mail: ' . arr::get($_POST, 'email', ''))->subject('Message to ' . site::option('sitename'))->send(); site::redirect('contact'); } else { $errors = $val->errors('suggestions'); } } $this->bind('errors', $errors); seo::instance()->title("Contact Morning Pages"); seo::instance()->description("Feel free to contact MorningPages.net if you have questions or concerns about your account, the site or for more information regarding your Morning Pages."); }
public function action_talk() { $tag = $this->request->param('tag'); $talk = $this->request->param('talk'); if (user::logged()) { // Iterate views if ($talk->user_id != user::get()->id) { $talk->views = $talk->views + 1; try { $talk->save(); } catch (ORM_Validation_Exception $e) { //var_dump($e->errors()); } } // Set when the user last saw the topic $user = user::get(); $viewed = $user->talkviews->where('talk_id', '=', $talk->id)->find(); if (!$viewed->loaded()) { $viewed->user_id = $user->id; $viewed->talk_id = $talk->id; } $viewed->last = time(); $viewed->save(); } $replies = $talk->replies->where('op', '!=', 1); $counter = $talk->replies->where('op', '!=', 1); $limit = Kohana::$config->load('talk')->get('pagination_limit'); $numreplies = $counter->count_all(); $numpages = ceil($numreplies / $limit); $page = (int) arr::get($_GET, 'page', 0); if ($_POST) { $this->require_login(); $reply = ORM::factory('Talkreply'); $reply->values($_POST); $reply->user_id = user::get()->id; $reply->talk_id = $talk->id; try { $reply->save(); $page = $numpages; $talk->last_reply = time(); $talk->save(); $subscriptions = $talk->subscriptions->find_all(); if ((bool) $subscriptions->count()) { foreach ($subscriptions as $subscription) { if ($subscription->user_id != $reply->user_id) { mail::create('talkreplyposted')->to($subscription->user->email)->tokenize(array('username' => $subscription->user->username, 'sendername' => $reply->user->username, 'title' => $talk->title, 'reply' => $reply->content, 'link' => HTML::anchor(URL::site($talk->url() . '?page=' . $page . '#comment-' . $reply->id, 'http'), $talk->title)))->send(); } } } $vote = ORM::factory('User_Talkvote'); $vote->type = 'talkreply'; $vote->user_id = user::get()->id; $vote->object_id = $reply->id; $vote->save(); notes::success('Your reply has been posted.'); site::redirect($talk->url() . '?page=' . $page . '#comment-' . $reply->id); } catch (ORM_Validation_Exception $e) { notes::error('Whoops! Your submission contained errors. Please review it and submit again'); $errors = $e->errors(); } } if ($page < 1) { $page = 1; } if ($page > $numpages) { $page = $numpages; } $replies = $replies->limit($limit); if ($page - 1 > 0) { $replies = $replies->offset($limit * ($page - 1)); } $replies = $replies->find_all(); $this->bind('tag', $tag); $this->bind('talk', $talk); $this->bind('replies', $replies); $this->bind('tags', ORM::factory('Talktag')->find_all()); $this->bind('numpages', $numpages); $this->bind('currentpage', $page); seo::instance()->title($talk->title); seo::instance()->description("Talk About Morning Pages, or anything else you might find interesting. Use this area to ask questions, make friends, or find out information about Morning Pages."); }
public function action_signup() { $errors = false; $password = false; if ($_POST) { $user = ORM::factory('User'); try { user::create($_POST); notes::add('success', 'You are now signed up. Welcome!'); if (user::logged()) { site::redirect('write'); } else { // should log this error (user wasnt logged in with user::create()) user::redirect('login'); } } catch (ORM_Validation_Exception $e) { $errors = $e->errors('models'); } } $this->bind('errors', $errors); }
// Création de l'objet soap if ($royaume->is_online()) { $soap = new TCSoap(array('soap_user' => $array_soap['soap_user'], 'soap_pass' => $array_soap['soap_pass'], 'soap_port' => $array_soap['soap_port'], 'addr' => $array_soap['addr'])); } function format_post($post) { return htmlentities($post, ENT_QUOTES, 'UTF-8'); } if (count($_POST) < 100) { array_map('format_post', $_POST); } $injection_detect = false; foreach ($_POST as $result) { if ($site->sqlDetect($result)) { $injection_detect = true; } } if ($injection_detect == true) { $site->redirect('index.php?page=home', 0); } require_once 'model/model_header.php'; if (!empty($model)) { require_once $model; // Appel du modele de la page } $sql->deconnexion(); // Déconnexion de la base de données ob_start(); require_once "view/view.php"; // Appel de la vue de la page ob_end_flush();