Пример #1
0
 public function __construct()
 {
     parent::__construct();
     $this->db->where('remember_me', FALSE)->where('UNIX_TIMESTAMP(last_activity) <', time() - strtoseconds($this->config->nf_cookie_expire))->delete('nf_sessions');
     $this->_ip_address = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER['REMOTE_ADDR'];
     $this->_host_name = utf8_string(gethostbyaddr($this->_ip_address));
     if (isset($_COOKIE[$this->config->nf_cookie_name]) && $this->_check_cookie($cookie = $_COOKIE[$this->config->nf_cookie_name], $last_activity)) {
         if (strtotime($this->config->nf_cookie_expire, $last_activity) < time()) {
             $this->_session_id();
         } else {
             $this->_session_id = $cookie;
         }
         $this->db->where('session_id', $cookie)->update('nf_sessions', array('session_id' => $this->_session_id, 'ip_address' => $this->_ip_address, 'host_name' => $this->_host_name, 'last_activity' => now()));
         if (!is_null($time_zone = $this('session', 'time_zone'))) {
             set_time_zone($time_zone);
             $this->db->update_time_zone();
         }
     } else {
         if (!is_asset() && !$this->config->ajax_url && !$this->config->ajax_header && $_SERVER['REQUEST_METHOD'] != 'OPTIONS') {
             $this->_session_id();
             $crawler = is_crawler();
             if ($crawler !== FALSE) {
                 $this->db->insert('nf_crawlers', array('name' => $crawler, 'path' => $this->config->request_url));
             }
             $this->db->insert('nf_sessions', array('session_id' => $this->_session_id, 'ip_address' => $this->_ip_address, 'host_name' => $this->_host_name, 'is_crawler' => $crawler !== FALSE));
             $this->_user_data['session']['date'] = time();
             $this->_user_data['session']['javascript'] = FALSE;
             $this->_user_data['session']['referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
             $this->_user_data['session']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
         }
     }
     statistics('nf_sessions_max_simultaneous', $this->_sessions = $this->db->select('COUNT(DISTINCT IFNULL(user_id, session_id))')->from('nf_sessions')->where('last_activity > DATE_SUB(NOW(), INTERVAL 5 MINUTE)')->where('is_crawler', FALSE)->row(), function ($a, $b) {
         return $a > $b;
     });
 }
Пример #2
0
 public function get_online_users()
 {
     $users = array();
     if ($this()) {
         $users[] = $this('user_id');
     }
     $users = array_merge($users, $this->db->select('user_id')->from('nf_sessions')->where('UNIX_TIMESTAMP(last_activity) >=', time() - strtoseconds('5 minutes'))->get());
     return array_unique($users);
 }
Пример #3
0
function time_span($timestamp)
{
    if (!is_numeric($timestamp)) {
        $timestamp = strtotime($timestamp);
    }
    $diff = time() - $timestamp;
    if (!$diff) {
        return NeoFrag::loader()->lang('now');
    } else {
        if ($diff == strtoseconds('1 seconds')) {
            return NeoFrag::loader()->lang('seconds_ago', 1);
        } else {
            if ($diff <= strtoseconds('30 seconds')) {
                return NeoFrag::loader()->lang('seconds_ago', $diff, $diff);
            } else {
                if ($diff < strtoseconds('45 seconds')) {
                    return NeoFrag::loader()->lang('seconds_ago', 30, 30);
                } else {
                    if ($diff < strtoseconds('50 seconds')) {
                        return NeoFrag::loader()->lang('seconds_ago', 45, 45);
                    } else {
                        if ($diff < strtoseconds('55 seconds')) {
                            return NeoFrag::loader()->lang('seconds_ago', 50, 50);
                        } else {
                            if ($diff < strtoseconds('2 minutes')) {
                                return NeoFrag::loader()->lang('minutes_ago', 1);
                            } else {
                                if ($diff <= strtoseconds('59 minutes')) {
                                    return NeoFrag::loader()->lang('minutes_ago', $diff = floor($diff / 60), $diff);
                                } else {
                                    if ($diff < strtoseconds('2 hours')) {
                                        return NeoFrag::loader()->lang('hours_ago', 1);
                                    } else {
                                        if ($diff <= strtoseconds('23 hours')) {
                                            return NeoFrag::loader()->lang('hours_ago', $diff = floor($diff / 3660), $diff);
                                        } else {
                                            if ($timestamp >= strtotime('yesterday')) {
                                                return NeoFrag::loader()->lang('yesterday_at', timetostr(NeoFrag::loader()->lang('time_short'), $timestamp));
                                            } else {
                                                if ($timestamp >= strtotime('6 days ago midnight')) {
                                                    return NeoFrag::loader()->lang('day_at', ucfirst(timetostr('%A', $timestamp)), timetostr(NeoFrag::loader()->lang('time_short'), $timestamp));
                                                } else {
                                                    return timetostr(NeoFrag::loader()->lang('date_time_short'), $timestamp);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}