public function render() { $statisticMapper = new \Modules\Statistic\Mappers\Statistic(); $allCount = $statisticMapper->getVisitsCountOnline(); $users = $statisticMapper->getVisitsOnlineUser(); $this->getView()->set('usersOnline', $users); $this->getView()->set('guestOnline', $allCount - count($users)); }
public function render() { $date = new \Ilch\Date(); $statisticMapper = new \Modules\Statistic\Mappers\Statistic(); $this->getView()->set('visitsToday', $statisticMapper->getVisitsCount($date->format('Y-m-d', true))); $this->getView()->set('visitsOnline', $statisticMapper->getVisitsCountOnline()); $date->modify('-1 day'); $this->getView()->set('visitsYesterday', $statisticMapper->getVisitsCount($date->format('Y-m-d', true))); $this->getView()->set('visitsMonth', $statisticMapper->getVisitsMonthCount()); $this->getView()->set('visitsYear', $statisticMapper->getVisitsYearCount()); $this->getView()->set('visitsRegistUser', $statisticMapper->getRegistUserCount()); $this->getView()->set('visitsTotal', $statisticMapper->getVisitsCount()); }
/** * Checks if a user id was given in the request and sets the user. * * If no user id is given a default user will be created. * * @param array $pluginData */ public function __construct(array $pluginData) { if (!isset($pluginData['config'])) { return; } $userId = null; if (isset($_SESSION['user_id'])) { $userId = (int) $_SESSION['user_id']; } $mapper = new UserMapper(); $user = $mapper->getUserById($userId); \Ilch\Registry::set('user', $user); if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && preg_match("/^[0-9a-zA-Z\\/.:]{7,}\$/", $_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (preg_match("/^[0-9a-zA-Z\\/.:]{7,}\$/", $_SERVER["REMOTE_ADDR"])) { $ip = $_SERVER["REMOTE_ADDR"]; } else { $ip = '128.0.0.1'; } if (empty($_SERVER['PATH_INFO']) or strpos($_SERVER['PATH_INFO'], 'admin', 1)) { $site = ''; } else { $site = $_SERVER['PATH_INFO']; } function statisticOS($useragent) { $osArray = array('Windows XP' => '=Windows NT 5.1|Windows XP=', 'Windows Vista' => '=Windows NT 6.0|Windows Vista=', 'Windows 7' => '=Windows NT 6.1|Windows 7=', 'Windows 8' => '=Windows NT 6.2|Windows 8=', 'Windows 8.1' => '=Windows NT 6.3|Windows 8.1=', 'Windows 10' => '=Windows NT 10.0|Windows 10=', 'Windows 2000' => '=Windows NT 5.0|Windows 2000=', 'Windows Server 2003\\Windows XP x64' => '=Windows NT 5\\.2|Windows Server 2003|Windows XP x64=', 'Windows NT' => '=Windows NT 4|WinNT4=', 'Windows 98' => '=Windows 98=', 'Windows 95' => '=Windows 95=', 'Android' => '=Android=', 'Linux' => '=Linux|Ubuntu|X11=', 'SunOs' => '=SunOS=', 'iPhone' => '=iPhone=', 'iPad' => '=iPad=', 'Mac OS' => '=Mac OS X=', 'Macintosh' => '=Mac_PowerPC|Macintosh='); foreach ($osArray as $os => $regex) { if (preg_match($regex, $useragent)) { return $os; } } return 0; } $os = statisticOS($_SERVER['HTTP_USER_AGENT']); function statisticBrowser($useragent) { if (preg_match("=Firefox/([\\.a-zA-Z0-9]*)=", $useragent, $browser)) { return "Firefox " . $browser[1]; } elseif (preg_match("=MSIE ([0-9]{1,2})\\.[0-9]{1,2}=", $useragent, $browser)) { return "Internet Explorer " . $browser[1]; } elseif (preg_match("=rv:([0-9]{1,2})\\.[0-9]{1,2}=", $useragent, $browser)) { return "Internet Explorer " . $browser[1]; } elseif (preg_match("=Opera[/ ]([0-9\\.]+)=", $useragent, $browser)) { return "Opera " . $browser[1]; } elseif (preg_match("=OPR\\/([0-9\\.]*)=", $useragent, $browser)) { $tmp = explode('.', $browser[1]); if (count($tmp) > 2) { $browser[1] = $tmp[0] . '.' . $tmp[1]; } return "Opera " . $browser[1]; } elseif (preg_match("=Edge/([0-9\\.]*)=", $useragent, $browser)) { $tmp = explode('.', $browser[1]); if (count($tmp) > 2) { $browser[1] = $tmp[0] . '.' . $tmp[1]; } return "Edge " . $browser[1]; } elseif (preg_match("=Chrome/([0-9\\.]*)=", $useragent, $browser)) { $tmp = explode('.', $browser[1]); if (count($tmp) > 2) { $browser[1] = $tmp[0] . '.' . $tmp[1]; } return "Chrome " . $browser[1]; } elseif (preg_match('=Safari/=', $useragent)) { if (preg_match('=Version/([\\.0-9]*)=', $useragent, $browser)) { $version = ' ' . $browser[1]; } else { $version = ''; } return "Safari" . $version; } elseif (preg_match("=Konqueror=", $useragent)) { return "Konqueror"; } elseif (preg_match("=Netscape|Navigator=", $useragent)) { return "Netscape"; } else { return 0; } } $browser = statisticBrowser($_SERVER['HTTP_USER_AGENT']); if (empty($_SERVER["HTTP_REFERER"])) { $referer = ''; } else { $referer = $_SERVER["HTTP_REFERER"]; } $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2); $statisticMapper = new \Modules\Statistic\Mappers\Statistic(); $statisticMapper->saveVisit(array('user_id' => $userId, 'site' => $site, 'referer' => $referer, 'os' => $os, 'browser' => $browser, 'ip' => $ip, 'lang' => $lang)); if ($pluginData['request']->getParam('language')) { $_SESSION['language'] = $pluginData['request']->getParam('language'); } if ($pluginData['request']->getParam('ilch_layout')) { $_SESSION['layout'] = $pluginData['request']->getParam('ilch_layout'); } $pluginData['translator']->setLocale($pluginData['config']->get('locale')); if (!empty($_SESSION['language'])) { $pluginData['translator']->setLocale($_SESSION['language']); } }
<link href="<?php echo $this->getModuleUrl('static/css/statistic.css'); ?> " rel="stylesheet"> <link href="<?php echo $this->getStaticUrl('css/bootstrap-progressbar-3.3.4.css'); ?> " rel="stylesheet"> <script type="text/javascript" src="<?php echo $this->getStaticUrl('js/bootstrap-progressbar.js'); ?> "></script> <?php $statisticMapper = new \Modules\Statistic\Mappers\Statistic(); $languageCodes = new \Modules\Statistic\Plugins\languageCodes(); $month = $this->getRequest()->getParam('month'); $year = $this->getRequest()->getParam('year'); ?> <?php if ($this->get('statisticYearMonthDayList') != '' and $year != '' and $month != '') { ?> <?php $date = new \Ilch\Date($year . '-' . $month . '-01'); ?> <legend><?php echo $this->getTrans('menuStatistic'); ?> : <i><?php echo $date->format('F Y', true);