public static function handleRequest($paramsHandle = array())
 {
     if (isset($_SERVER['HTTP_USER_AGENT']) && !self::isBot($_SERVER['HTTP_USER_AGENT'])) {
         $newVisitor = false;
         if (isset($paramsHandle['vid']) && !empty($paramsHandle['vid'])) {
             $items = erLhcoreClassModelChatOnlineUser::getList(array('filter' => array('vid' => $paramsHandle['vid'])));
             if (!empty($items)) {
                 $item = array_shift($items);
                 // Visit duration les than 30m. Same as google analytics
                 // See: https://support.google.com/analytics/answer/2731565?hl=en
                 if (time() - $item->last_visit <= 30 * 60) {
                     $item->time_on_site += time() - $item->last_visit;
                     $item->tt_time_on_site += time() - $item->last_visit;
                 } else {
                     $item->time_on_site = 0;
                     $item->total_visits++;
                     $item->last_visit = time();
                     $item->pages_count = 0;
                     // Reset chat_id only if chat is not active or pending
                     if ($item->chat_id > 0) {
                         if ($item->chat === false || !in_array($item->chat->status, array(erLhcoreClassModelChat::STATUS_ACTIVE_CHAT, erLhcoreClassModelChat::STATUS_PENDING_CHAT))) {
                             $item->chat_id = 0;
                         }
                     }
                     if ($item->message_seen == 1 && $item->message_seen_ts < time() - (int) $paramsHandle['message_seen_timeout'] * 3600) {
                         $item->message_seen = 0;
                         $item->message_seen_ts = 0;
                         $item->operator_message = '';
                     }
                 }
                 $item->identifier = isset($paramsHandle['identifier']) && !empty($paramsHandle['identifier']) ? $paramsHandle['identifier'] : $item->identifier;
                 if (isset($paramsHandle['department']) && is_array($paramsHandle['department']) && count($paramsHandle['department']) == 1) {
                     $item->dep_id = array_shift($paramsHandle['department']);
                 } elseif (isset($paramsHandle['department']) && is_numeric($paramsHandle['department'])) {
                     $item->dep_id = (int) $paramsHandle['department'];
                 }
             } else {
                 $item = new erLhcoreClassModelChatOnlineUser();
                 $item->ip = erLhcoreClassIPDetect::getIP();
                 $item->vid = $paramsHandle['vid'];
                 $item->identifier = isset($paramsHandle['identifier']) && !empty($paramsHandle['identifier']) ? $paramsHandle['identifier'] : '';
                 $item->referrer = isset($_GET['r']) ? rawurldecode($_GET['r']) : '';
                 $item->total_visits = 1;
                 if (isset($paramsHandle['department']) && is_array($paramsHandle['department']) && count($paramsHandle['department']) == 1) {
                     $item->dep_id = array_shift($paramsHandle['department']);
                 } elseif (isset($paramsHandle['department']) && is_numeric($paramsHandle['department'])) {
                     $item->dep_id = (int) $paramsHandle['department'];
                 }
                 if (isset($paramsHandle['tz']) && is_numeric($paramsHandle['tz'])) {
                     $timezone_name = timezone_name_from_abbr(null, (int) $paramsHandle['tz'] * 3600, true);
                     if ($timezone_name !== false) {
                         $item->visitor_tz = $timezone_name;
                     }
                 }
                 self::detectLocation($item);
                 // Cleanup database then new user comes
                 self::cleanupOnlineUsers();
                 $item->store_chat = true;
                 $newVisitor = true;
             }
         } else {
             self::cleanupOnlineUsers();
             return false;
         }
         if (isset($paramsHandle['pages_count']) && $paramsHandle['pages_count'] == true) {
             $item->pages_count++;
             $item->tt_pages_count++;
             $item->store_chat = true;
             if (isset($_GET['onattr']) && is_array($_GET['onattr']) && !empty($_GET['onattr'])) {
                 $item->online_attr = json_encode($_GET['onattr']);
             }
             if ($item->has_message_from_operator == true) {
                 $item->invitation_seen_count++;
             }
             if (isset($paramsHandle['tz']) && is_numeric($paramsHandle['tz']) && $item->visitor_tz == '') {
                 $timezone_name = timezone_name_from_abbr(null, (int) $paramsHandle['tz'] * 3600, true);
                 if ($timezone_name !== false) {
                     $item->visitor_tz = $timezone_name;
                 }
             }
             // Hide invitation message after n times if required
             if ($item->has_message_from_operator == true && $item->invitation !== false && $item->invitation->hide_after_ntimes > 0 && $item->invitation_seen_count > $item->invitation->hide_after_ntimes) {
                 $item->message_seen = 1;
                 $item->message_seen_ts = time();
             }
         }
         $logPageView = false;
         // Update variables only if it's not JS to check for operator message
         if (!isset($paramsHandle['check_message_operator']) || isset($paramsHandle['pages_count']) && $paramsHandle['pages_count'] == true) {
             $item->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
             $item->current_page = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
             $item->page_title = isset($_GET['dt']) ? (string) rawurldecode($_GET['dt']) : '';
             $item->last_visit = time();
             $item->store_chat = true;
             $logPageView = true;
         }
         if ((!isset($paramsHandle['wopen']) || $paramsHandle['wopen'] == 0) && $item->operator_message == '' && isset($paramsHandle['pro_active_invite']) && $paramsHandle['pro_active_invite'] == 1 && isset($paramsHandle['pro_active_limitation']) && ($paramsHandle['pro_active_limitation'] == -1 || erLhcoreClassChat::getPendingChatsCountPublic($item->dep_id > 0 ? $item->dep_id : false) <= $paramsHandle['pro_active_limitation'])) {
             //Process pro active chat invitation if this visitor matches any rules
             erLhAbstractModelProactiveChatInvitation::processProActiveInvitation($item);
         }
         $activityChanged = false;
         if (isset($paramsHandle['uactiv'])) {
             $activityChanged = $item->user_active != (int) $paramsHandle['uactiv'] && $newVisitor == false;
             $item->user_active = (int) $paramsHandle['uactiv'];
         }
         // Save only then we have to, in general only then page view appears
         if ($item->store_chat == true) {
             $item->last_check_time = time();
             $item->saveThis();
             if ($newVisitor == true) {
                 erLhcoreClassChatEventDispatcher::getInstance()->dispatch('onlineuser.created', array('tpl' => isset($paramsHandle['tpl']) ? $paramsHandle['tpl'] : false, 'ou' => &$item));
             } elseif ($logPageView == true) {
                 erLhcoreClassChatEventDispatcher::getInstance()->dispatch('onlineuser.pageview_logged', array('tpl' => isset($paramsHandle['tpl']) ? $paramsHandle['tpl'] : false, 'ou' => &$item));
             }
             if ($activityChanged == true && $item->chat_id > 0) {
                 erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.data_changed_chat', array('chat_id' => $item->chat_id));
             }
         }
         return $item;
     } else {
         // Stop execution on google bot
         exit;
     }
 }