Example #1
0
 private function onAjaxUpdate()
 {
     GWF_ChatOnline::onRequest($this->module);
     $times = $this->getAjaxTimes();
     $back = $this->module->getAjaxUpdates($times);
     self::saveAjaxTimes($times);
     return $back;
 }
Example #2
0
 public function execute()
 {
     GWF_ChatOnline::onRequest($this->module);
     GWF_Website::setPageTitle($this->module->lang('pt_chat'));
     GWF_Website::setMetaTags($this->module->lang('mt_chat'));
     GWF_Website::addJavascript(GWF_WEB_ROOT . 'js/module/Chat/gwf_chat.js?v=4');
     if (false !== Common::getPost('post')) {
         return $this->onPost() . $this->templatePage();
     }
     return $this->templatePage();
 }
Example #3
0
 private function stream()
 {
     set_time_limit(0);
     $t = time();
     $times = array($t, $t, $t, $t);
     //		$msgtable = new GWF_ChatMsg(false);
     $channel = '';
     while (true) {
         GWF_ChatOnline::setSessOnline($this->module);
         //			GWF_Session::updateLastActivity();
         $page = $this->module->getAjaxUpdates($times);
         # --- Anything happened?
         if ($page !== '') {
             GWF_Javascript::newSection();
             echo $page;
             GWF_Javascript::endSection();
         }
         usleep(999950);
     }
 }
Example #4
0
 public function getAjaxUpdates(array &$times)
 {
     $msgtable = GDO::table('GWF_ChatMsg');
     $page = '';
     $now = time();
     # Get Kick Messages
     $kicked = GWF_ChatOnline::getKicked($times[0]);
     if (count($kicked) > 0) {
         $page .= $this->getJoinMessages('-', $kicked);
         $times[0] = $now;
     }
     # Get Join Messages
     $joined = GWF_ChatOnline::getJoined($times[1]);
     if (count($joined) > 0) {
         $page .= $this->getJoinMessages('+', $joined);
         $times[1] = $now;
     }
     # Get Public Channel Messages
     $last = $times[2];
     $pubmsg = $msgtable->selectAll('*', "chatmsg_to='' AND chatmsg_time>{$last}", 'chatmsg_time ASC');
     if (count($pubmsg) > 0) {
         $page .= $this->getMessages($pubmsg, false);
         $times[2] = $now;
     }
     # Get Private Messages
     if (false !== ($nick = $this->getNickname())) {
         $last = $times[3];
         $nick = $msgtable->escape($nick);
         $privmsg = $msgtable->selectAll('*', "(chatmsg_to='{$nick}' OR (chatmsg_from='{$nick}' AND chatmsg_to!='')) AND chatmsg_time>{$last}", 'chatmsg_time ASC');
         if (count($privmsg) > 0) {
             $page .= $this->getMessages($privmsg, true);
             $times[3] = $now;
         }
     }
     return $page;
 }
Example #5
0
 private function startStream()
 {
     #GWF_ChatOnline::setSessOnline();
     GWF_Javascript::streamHeader();
     $times = array(time(), time(), time(), time());
     $i = 0;
     while ($i < 10) {
         echo '+Foo' . PHP_EOL;
         flush();
         //			GWF_Javascript::flush();
         sleep(2);
         $i++;
         continue;
         $stuff_sent = false;
         # Get Kick Messages
         $kicked = GWF_ChatOnline::getKicked($times[0]);
         if (count($kicked) > 0) {
             $stuff_sent = true;
             $this->streamMessageJoin('-', $kicked);
             $times[0] = time();
         }
         # Get Join Messages
         $joined = GWF_ChatOnline::getJoined($times[1]);
         if (count($joined) > 0) {
             $stuff_sent = true;
             $this->streamMessageJoin('+', $joined);
             $times[1] = time();
         }
         # Get Public Channel Messages
         $msgs = new GWF_ChatMsg(false);
         $channel = '';
         $last = $times[2];
         $pubmsg = $msgs->selectAll('*', "chatmsg_to='{$channel}' AND chatmsg_time>{$last}", 'chatmsg_time ASC');
         if (count($pubmsg) > 0) {
             $stuff_sent = true;
             $this->echoMessages($pubmsg, false);
             $times[2] = time();
         }
         # Get Private Messages
         if (false !== ($nick = $this->module->getNickname())) {
             $last = $times[3];
             $privmsg = $msgs->selectAll('*', "(chatmsg_to='{$nick}' OR (chatmsg_from='{$nick}' AND chatmsg_to!='')) AND chatmsg_time>{$last}", 'chatmsg_time ASC');
             if (count($privmsg) > 0) {
                 $stuff_sent = true;
                 $this->echoMessages($privmsg, true);
                 $times[3] = time();
             }
         }
         //			if (!$stuff_sent)
         //			{
         //				usleep(1000000);
         GWF_ChatOnline::setSessOnline($this->module);
         //			}
         //			else
         //			{
         //			}
         //			echo '+Foo'.PHP_EOL;
         echo '+Foo' . PHP_EOL;
         //			flush();
         GWF_Javascript::flush();
         //			flush();
         sleep(1);
     }
     GWF_ChatOnline::setSessOffline($this->module);
     die;
 }