示例#1
0
 private function check_streaks()
 {
     $users = ORM::factory('User')->where('current_streak', '>', 0)->find_all();
     if ((bool) $users->count()) {
         foreach ($users as $user) {
             $last = $user->pages->where('type', '=', 'page')->find();
             if ($last->loaded()) {
                 $nextday = site::day_slug(strtotime('+1 day', strtotime($last->day)));
                 $today = site::day_slug($user->timestamp());
                 $tomorrow = site::day_slug(strtotime('+1 day', $user->timestamp()));
                 if ($nextday != $today && $nextday != $tomorrow) {
                     $user->current_streak = 0;
                     $user->validation_required(false)->save();
                     if ($user->doing_challenge()) {
                         $user->fail_challenge();
                     }
                 }
             } else {
                 if ($user->doing_challenge()) {
                     $start = $user->challenge->start;
                     if ($user->timestamp() - $start > 24 * 60 * 60) {
                         $user->fail_challenge();
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public function action_info()
 {
     if (!user::logged()) {
         ajax::error('You must be logged in');
     }
     $user = user::get();
     $today = $user->pages->where('day', '=', site::day_slug($user->timestamp()))->find();
     $wordcount = 0;
     if ($today->loaded()) {
         $wordcount = $today->wordcount;
     }
     $doingChallenge = $user->doing_challenge();
     ajax::success('ok', array('email' => $user->email, 'bio' => $user->bio, 'website' => $user->website, 'wordcount' => $wordcount, 'options' => array('reminder' => (bool) $user->option->reminder, 'reminder_hour' => $user->option->reminder_hour, 'reminder_minute' => $user->option->reminder_minute, 'reminder_meridiem' => $user->option->reminder_meridiem, 'timezone_id' => $user->option->timezone_id, 'theme_id' => $user->option->theme_id, 'privacymode' => (bool) $user->option->privacymode, 'privacymode_minutes' => $user->option->privacymode_minutes, 'hemingwaymode' => (bool) $user->option->hemingwaymode, 'public' => (bool) $user->option->public, 'rtl' => (bool) $user->option->rtl, 'language' => $user->option->language), 'doingChallenge' => $doingChallenge, 'challengeProgress' => $doingChallenge ? $user->challenge->progress : 0));
 }
示例#3
0
            if (!array_key_exists($year, $years)) {
                $years[$year] = array();
            }
            $month = date('F', $stamp);
            if (!array_key_exists($month, $years[$year])) {
                $years[$year][$month] = array();
            }
            $years[$year][$month][] = $p;
        }
    }
    foreach ($years as $year => $month) {
        foreach ($month as $monthname => $days) {
            echo '<optgroup label="' . $monthname . ', ' . $year . '">';
            foreach ($days as $day) {
                $dayname = date('l ', $day->created) . ' the ' . date('jS', $day->created);
                if ($day->day != site::day_slug()) {
                    //$dayname = 'Today';
                    echo '<option value="' . $day->day . '"' . ($dayname == $day->day ? ' selected="selected"' : '') . '>' . $dayname . '</option>';
                }
            }
            echo '<optgroup>';
        }
    }
    ?>
       			</select>
       		<?php 
}
?>
			
<?php 
if (!empty($user->bio)) {
示例#4
0
 public function date()
 {
     if (!$this->day) {
         $this->day = site::day_slug();
     }
     $today = site::day_slug();
     if ($today == $this->day) {
         return 'Today';
     }
     return $this->daystamp();
 }
示例#5
0
 public function today_slug()
 {
     return site::day_slug($this->timestamp());
 }
示例#6
0
 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();
 }
示例#7
0
 public static function count_total_words()
 {
     $numwords = DB::select(DB::expr("SUM(`wordcount`) AS count"))->from('pages')->where('day', '=', site::day_slug())->execute()->as_array();
     $numwords = arr::get($numwords[0], 'count', 0);
     return $numwords;
 }
示例#8
0
 /**
  * Site routes
  */
 public static function find($route, $params, $request)
 {
     visitor::save_update_current();
     maintenance::delete_inactive_visitors();
     extract($params);
     if (!isset($controller)) {
         $controller = 'content';
     }
     $controller = strtolower($controller);
     $guid = $controller . '/' . $action;
     if ($action == 'index') {
         $guid = $controller;
     }
     $controllerfile = ucfirst($controller);
     $action = isset($params['action']) ? $params['action'] : 'index';
     //$action = ucfirst($action);
     $slug = isset($params['slug']) ? $params['slug'] : '';
     $slug2 = isset($params['slug2']) ? $params['slug2'] : '';
     $slug3 = isset($params['slug3']) ? $params['slug3'] : '';
     $slug4 = isset($params['slug4']) ? $params['slug4'] : '';
     $slug5 = isset($params['slug5']) ? $params['slug5'] : '';
     // Homepage
     if ($guid == 'content') {
         return array('controller' => 'Site', 'action' => 'index');
     }
     // Page alias
     if ($controller == 'test') {
         return array('controller' => 'Page', 'action' => 'test');
     }
     if ($controller == 'contact') {
         return array('controller' => 'Page', 'action' => 'contact');
     }
     if ($controller == 'challenge') {
         if ($action == 'wall-of-fame') {
             return array('controller' => 'Games', 'action' => 'walloffame');
         } elseif ($action == 'index') {
             return array('controller' => 'Games', 'action' => 'challenge');
         }
     }
     if ($controller == 'leaderboard') {
         return array('controller' => 'Games', 'action' => 'leaderboard');
     }
     if ($controller == 'write') {
         $todayslug = site::day_slug();
         if (user::logged()) {
             $todayslug = user::get()->today_slug();
         }
         if (empty($action) || $action == 'index') {
             $action = $todayslug;
         }
         $page = false;
         if (user::logged()) {
             $page = ORM::factory('Page')->where('user_id', '=', user::get()->id)->where('type', '=', 'page')->where('day', '=', $action)->find();
             if (!$page->loaded() && $action == $todayslug) {
                 $page = ORM::factory('Page')->where('user_id', '=', user::get()->id)->where('type', '=', 'autosave')->where('day', '=', $action)->find();
                 // It's today, but todays page doesn't exist yet. Create it
                 if (!$page->loaded()) {
                     $page->type = 'autosave';
                     $page->save();
                 }
             }
         }
         if (user::logged() && ($page && $page->loaded()) && $slug == 'stats') {
             return array('controller' => 'Write', 'action' => 'pagestats', 'page' => $page);
         }
         if (user::logged() && ($page && $page->loaded()) || !user::logged()) {
             return array('controller' => 'Write', 'action' => 'write', 'page' => $page, 'daystamp' => $action);
         } else {
             return array('controller' => 'Write', 'action' => 'daynotfound');
         }
     }
     if ($controller == 'read') {
         return array('controller' => 'Page', 'action' => 'read', 'id' => $action);
     }
     if ($controller == 'user') {
         if ($action != '') {
             if ($action == 'password') {
                 return array('controller' => 'User', 'action' => 'password', 'token' => $slug);
             }
             if (in_array($action, user::reservednames())) {
                 return array('controller' => 'User', 'action' => $action);
             }
             // We're either looking at a user's public profile or 404'd
             $user = ORM::factory('User')->where('slug', '=', $action)->find();
             if ($user->loaded()) {
                 if ((bool) $user->option('public') || user::logged('admin')) {
                     return array('controller' => 'Me', 'action' => 'profile', 'user' => $user);
                 } else {
                     return array('controller' => 'Me', 'action' => 'notpublic');
                 }
             } else {
                 return array('controller' => 'Errors', 'action' => '404', 'params' => $params);
             }
         } else {
             return array('controller' => 'User', 'action' => 'options');
         }
     }
     // Pages/Content
     $content = ORM::factory('Content');
     if (!user::logged('admin')) {
         $content = $content->where('status', '=', 'active');
     }
     $content = $content->where('guid', '=', $guid)->find();
     if ($content->loaded()) {
         // Specific content
         $class = 'Content';
         if (class_exists('Controller_' . ucfirst($content->contenttype->type))) {
             $class = ucfirst($content->contenttype->type);
         }
         $action = 'default';
         if ($content->contenttypetype_id != 0) {
             if (method_exists('Controller_' . $class, 'action_' . $content->contenttypetype->key)) {
                 $action = $content->contenttypetype->key;
             }
         }
         $content->hit();
         return array('controller' => $class, 'action' => $action, 'content' => $content);
     } else {
         // Index page for contenttype
         if ($action == 'index') {
             $contenttype = $controller;
             if (class_exists('Controller_' . ucfirst($contenttype))) {
                 $class = ucfirst($contenttype);
                 return array('controller' => $class, 'action' => 'index');
             }
         }
     }
     // "Static" controllers
     $file = 'application/classes/Controller/' . $controllerfile . '.php';
     if (file_exists($file) && method_exists('Controller_' . ucfirst($controllerfile), 'action_' . $action)) {
         $return = array();
         $return['controller'] = $controllerfile;
         $return['action'] = isset($action) ? $action : 'index';
         $return['id'] = isset($slug) ? $slug : '';
         $return['params'] = $params;
         return $return;
     }
     // No matches. 404
     return array('controller' => 'Errors', 'action' => '404', 'params' => $params);
 }