Ejemplo n.º 1
0
        if (array_key_exists($ip, $stats['writers']) && !$writing) {
            unset($stats['writers'][$ip]);
        } elseif ($writing) {
            $stats['writers'][$ip] = time();
        }
        foreach ($stats['writers'] as $ip => $time) {
            if (time() - $time > 20) {
                unset($stats['writers'][$ip]);
            }
        }
        $cache->set(__CLASS__, $board . ':' . $id, 'stats', serialize($stats));
        EventModel::getInstance()->Broadcast('board_stats_updated', array($board, $id));
        return true;
    }
    /**
     * Статистика поста:
     */
    public static function getPostStats($board, $id)
    {
        $cache = KVS::getInstance();
        $stats = unserialize($cache->get(__CLASS__, $board . ':' . $id, 'stats'));
        return array('online' => max(1, sizeof($stats['online']) == 3 ? 3.5 : sizeof($stats['online'])), 'writers' => sizeof($stats['writers']));
    }
}
/**
 * Обработчики событий:
 */
EventModel::getInstance()->AddEventListener('board_stats_updated', function ($data) {
    $stats = Board_StatisticsModel::getPostStats($data[0], $data[1]);
    EventModel::getInstance()->ClientBroadcast('boardpost_' . $data[0] . '_' . $data[1], 'stats_updated', array('online' => $stats['online'], 'writers' => $stats['writers']));
});
Ejemplo n.º 2
0
 /**
  * Просмотр треда:
  */
 public function viewThreadAction(Application $application, Template $template)
 {
     $board = new Board_BoardModel($_GET['board']);
     $session = Session::getInstance();
     $settings = $board->getSettings();
     $template->setParameter('title', $settings['title']);
     $template->setParameter('description', $settings['description']);
     $template->setParameter('board_id', $board->getId());
     $thread = $board->getThread($_GET['thread_id']);
     if ($thread === false) {
         $template->headerNotFound();
     }
     $this['form_errors'] = $session->instantGet('board_post_errors', array());
     $this['board_form'] = $session->instantGet('board_post_form', array());
     $stats = Board_StatisticsModel::getPostStats($thread['board_id'], $thread['id']);
     $template->setParameter('total_read', $stats['online']);
     $template->setParameter('total_write', $stats['writers']);
     $template->setParameter('total_unique', $stats['unique']);
     $session->instantSet('captcha_board_comment', true);
     $this['post'] = $thread;
     EventModel::getInstance()->Broadcast('view_board_thread', array($_GET['board'], $_GET['thread_id']));
     return true;
 }