public static function logView($service, $id, $page, $data, $dataLabel, $size = 0) { switch ($service) { case 'web': case 'api': break; default: throw new Exception("Invalid service {$service}"); break; } $deviceClassifier = Kurogo::deviceClassifier(); $ip = Kurogo::determineIP(); $requestURI = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $visitID = self::getVisitID($service); if (Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) { $session = Kurogo::getSession(); $user = $session->getUser(); } else { $user = false; } $logData = array('timestamp' => time(), 'date' => date('Y-m-d H:i:s'), 'site' => SITE_KEY, 'service' => $service, 'requestURI' => $requestURI, 'referrer' => $referrer, 'referredSite' => intval(self::isFromThisSite($referrer)), 'referredModule' => intval(self::isFromModule($referrer, $id)), 'userAgent' => $userAgent, 'ip' => $ip, 'user' => $user ? $user->getUserID() : '', 'authority' => $user ? $user->getAuthenticationAuthorityIndex() : '', 'visitID' => $visitID, 'pagetype' => $deviceClassifier->getPageType(), 'platform' => $deviceClassifier->getPlatform(), 'moduleID' => $id, 'page' => $page, 'data' => $data, 'dataLabel' => $dataLabel, 'size' => $size, 'elapsed' => Kurogo::getElapsed()); try { $conn = self::connection(); } catch (KurogoDataServerException $e) { throw new KurogoConfigurationException("Database not configured for statistics. To disable stats, set STATS_ENABLED=0 in site.ini"); } $sql = sprintf("INSERT INTO %s (%s) VALUES (%s)", Kurogo::getOptionalSiteVar("KUROGO_STATS_TABLE", "kurogo_stats_v1"), implode(",", array_keys($logData)), implode(",", array_fill(0, count($logData), '?'))); if (!($result = $conn->query($sql, array_values($logData), db::IGNORE_ERRORS))) { self::createStatsTables(); $result = $conn->query($sql, array_values($logData)); } return $result; }
public static function logView($service, $id, $page, $data, $dataLabel, $size = 0) { switch ($service) { case 'web': case 'api': break; default: throw new Exception("Invalid service {$service}"); break; } $deviceClassifier = Kurogo::deviceClassifier(); $ip = Kurogo::determineIP(); $requestURI = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $visitID = self::getVisitID($service); if (Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) { $session = Kurogo::getSession(); $user = $session->getUser(); } else { $user = false; } $statsLogFilename = Kurogo::getOptionalSiteVar('KUROGO_STATS_LOG_FILENAME', "kurogo_stats_log_v1"); $statsLogFile = LOG_DIR . DIRECTORY_SEPARATOR . $statsLogFilename; $current = time(); $logData = array('timestamp' => time(), 'date' => date('Y-m-d H:i:s', $current), 'service' => $service, 'site' => SITE_KEY, 'requestURI' => $requestURI, 'referrer' => $referrer, 'referredSite' => intval(self::isFromThisSite($referrer)), 'referredModule' => intval(self::isFromModule($referrer, $id)), 'userAgent' => $userAgent, 'ip' => $ip, 'user' => $user ? $user->getUserID() : '', 'authority' => $user ? $user->getAuthenticationAuthorityIndex() : '', 'visitID' => $visitID, 'pagetype' => $deviceClassifier->getPageType(), 'platform' => $deviceClassifier->getPlatform(), 'moduleID' => $id, 'page' => $page, 'data' => $data, 'dataLabel' => $dataLabel, 'size' => $size, 'elapsed' => Kurogo::getElapsed()); $fields = array_fill(0, count($logData), '%s'); $data = array_merge(array(implode("\t", $fields)), array_values($logData)); $content = call_user_func_array('sprintf', $data) . PHP_EOL; self::fileAppend($statsLogFile, $content); return true; }