/**
  * Shows stats for the given user
  *
  * @param string nickname to get stats for
  */
 public function user($nick)
 {
     $UserModel = UserModel::getInstance();
     $ChannelModel = ChannelModel::getInstance();
     if ($UserModel->getOnlineStatus($nick)) {
         $isOnline = "yes";
     }
     View::load("userstats", array("online" => $isOnline, "nickname" => $nick, "hour" => array("messages" => $UserModel->getMessageCount($nick, "hour"), "words" => $UserModel->getWordCount($nick, "hour"), "wordsPerMessage" => $UserModel->getAverageWordsPerMessage($nick, "hour")), "day" => array("messages" => $UserModel->getMessageCount($nick, "day"), "words" => $UserModel->getWordCount($nick, "day"), "wordsPerMessage" => $UserModel->getAverageWordsPerMessage($nick, "day")), "week" => array("messages" => $UserModel->getMessageCount($nick, "week"), "words" => $UserModel->getWordCount($nick, "week"), "wordsPerMessage" => $UserModel->getAverageWordsPerMessage($nick, "week")), "latestUserMessages" => $ChannelModel->getLatestMessages(10, $nick)));
 }
 /**
  * AJAX request for 50 messages before
  * the given timestamp
  *
  * @param post-int unix epoch timestamp
  * @return json array of objects with message, timestamp,
  * nickname, target_nick, channel_name, type
  */
 public function ajaxolder()
 {
     if (!$_POST["timestamp"]) {
         echo "Invalid Request";
         return;
     }
     $ChannelModel = ChannelModel::getInstance();
     $olderMessages = $ChannelModel->getMessagesBeforeTimestamp($_POST["timestamp"], 50);
     $returnData = array();
     foreach ($olderMessages as $olderMessage) {
         $split = explode(" ", $olderMessage->message);
         if (strpos($split[0], "ACTION") !== false) {
             $olderMessage->message = $olderMessage->nickname . str_replace("ACTION", "", $olderMessage->message);
             $olderMessage->nickname = " ";
         }
         $data = array("message" => htmlentities($olderMessage->message), "timestamp" => $olderMessage->time, "nickname" => $olderMessage->nickname, "target_nick" => $olderMessage->target_nick, "channel_name" => $olderMessage->channel_name, "type" => $olderMessage->type);
         $returnData[] = $data;
     }
     echo json_encode($returnData);
 }