public function action_login() { if ((bool) arr::get($_GET, 'return', false)) { site::set_last_url($this->request->referrer()); } $error = false; if ($_POST) { $email = arr::get($_POST, 'email', ''); $password = arr::get($_POST, 'password', ''); $remember = arr::get($_POST, 'remember', '') == 'yes'; if (user::login($email, $password, $remember)) { $user = user::get(); notes::success('You have been logged in. Welcome back!'); $lasturl = site::get_last_url(); if ($lasturl) { site::redirect($lasturl); } site::redirect('write'); } else { //notes::error('Wrong username or password. Please try again.'); $error = true; } } $this->bind('error', $error); }
public function action_write() { $errors = false; $page = false; if (user::logged()) { $page = $this->request->param('page'); if ($_POST && strlen(arr::get($_POST, 'content', '')) > 0) { $content = arr::get($_POST, 'content', ''); if ($page->type == 'page') { $raw = $page->rawcontent(); if ($raw != "") { $content = $raw . "\n" . $content; } } else { if ($page->type == 'autosave') { $page->type = 'page'; } } try { $page->wordcount = site::count_words($content); $page->content = $content; if ($page->wordcount >= 750 && !(bool) $page->counted) { user::update_stats($page); $page->counted = 1; } $page->duration = $page->duration + (time() - arr::get($_POST, 'start', 999)); $page->update(); $oldsaves = ORM::factory('Page')->where('type', '=', 'autosave')->where('user_id', '=', user::get()->id)->find_all(); if ((bool) $oldsaves->count()) { foreach ($oldsaves as $old) { $old->delete(); } } achievement::check_all(user::get()); notes::success('Your page has been saved!'); //site::redirect('write/'.$page->day); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('models'); } } } else { if ($_POST) { notes::error('You must be logged in to save your page. Please log in and submit again.'); } } $this->bind('errors', $errors); $this->bind('page', $page); $this->template->daystamp = $this->request->param('daystamp'); $this->template->page = $page; seo::instance()->title("Write Your Morning Pages"); seo::instance()->description("Morning Pages is about writing three pages of stream of consciousness thought every day. Become a better person by using MorninPages.net"); }
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 static function update_stats($page) { if (!user::logged()) { return; } $user = self::get(); $yesterdayslug = site::day_slug(strtotime('-1 day', $user->timestamp())); $yesterday = ORM::factory('Page')->where('user_id', '=', $user->id)->where('day', '=', $yesterdayslug)->where('type', '=', 'page')->find(); if ($yesterday->loaded()) { $user->current_streak += 1; if ($user->doing_challenge()) { $challenge = $user->challenge; $challenge->progress += 1; if ($challenge->progress >= 30) { if ($user->option('completedchallenge') == 0) { notes::success('You have completed the 30 day challenge and have been added to our ' . HTML::anchor('challenge/wall-of-fame', 'wall of fame') . '! Congratulations!'); $options = $user->option; $options->completedchallenge = $user->timestamp(); $options->save(); } else { notes::success('You have completed the 30 day challenge! Congratulations!'); } user::award_points(100, 'Completed the 30 day challenge! (+100 points)', $user); $challenge->delete(); } else { $challenge->save(); } } if ($user->current_streak > $user->longest_streak) { $user->longest_streak = $user->current_streak; } } else { $user->current_streak = 1; if ($user->doing_challenge()) { $challenge = $user->challenge; $challenge->progress = 1; $challenge->save(); } } $user->all_time_words += $page->wordcount; if ($page->wordcount > $user->most_words) { notes::success('You have written more today than you ever have before! Good job!'); $user->most_words = $page->wordcount; } $user->save(); }