Exemple #1
0
     // child = room id
     $page->setMimeType('text/plain');
     if (!$this->child || !is_numeric($this->child)) {
         die('hey');
     }
     $ts = 0;
     if (isset($_GET['ts']) && is_numeric($_GET['ts'])) {
         $ts = $_GET['ts'];
         $max_age = parse_duration('7d');
         // empty json string on old queries
         if ($ts < microtime(true) - $max_age) {
             echo '[]';
             return;
         }
     }
     $res = ChatMessage::getRecent($this->child, $ts, 25);
     $out = array();
     foreach ($res as $r) {
         $out[] = array('name' => User::get($r->from)->name, 'from' => $r->from, 'msg' => $r->msg, 'ts' => $r->microtime);
     }
     echo json_encode($out);
     break;
 case 'send':
     // XHR - writes a message to chatroom
     // child = room id
     // $_GET['m'] = message
     if (!$this->child || !is_numeric($this->child) || empty($_GET['m'])) {
         die('hey');
     }
     $cr = ChatRoom::get($this->child);
     if ($cr->locked_by) {