function updateUserLog($userId, $ip) { if (!$userId) { return; // nothing to do if user is not logged in } $timestamp = ExtraWatchDate::getUTCTimestamp(); $query = sprintf("select id from #__extrawatch_user_log where (`userId` = '%d' and `ip` = '%s') ", (int) $userId, $this->database->getEscaped($ip)); $id = $this->database->resultQuery($query); if (@(!$id)) { $query = sprintf("insert into #__extrawatch_user_log (`userId`, `timestamp`, `ip`, `alertSent`) values ('%d', '%d', '%s', NULL)", (int) $userId, (int) $timestamp, $this->database->getEscaped($ip)); $this->database->executeQuery($query); } else { $query = sprintf("update #__extrawatch_user_log set `timestamp` = '%d' where `ip` = '%s' and userId = '%d'", (int) $timestamp, $this->database->getEscaped($ip), (int) $userId); $this->database->executeQuery($query); } $this->sendAlertEmails($ip); }
protected function setUp() { if (!defined('ENV')) { //setting up only once define('DS', DIRECTORY_SEPARATOR); define('JPATH_BASE', realpath(dirname(__FILE__) . DS . ".." . DS . "..")); define('ENV', 1); define('_EW_PROJECT_ID', ""); } $this->instantiateExtraWatch(); $this->prepareDB(true); $this->day = ExtraWatchDate::jwDateToday(); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYWORDS, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYPHRASE, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_SEARCH_RESULT_NUM, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYWORDS, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYPHRASE, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_REFERERS, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_OS, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_DEVICES, $this->day)); $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_BROWSER, $this->day)); }
private function renderUserList($userLog) { if (@$userLog) { $output = "<table border='0' class='table table-striped tablesorter'><thead><th>time</th><th>username</th><th>name</th><th>ip</th><th>country</th><th>action</th></thead><tbody>"; if (@$userLog) { foreach ($userLog as $user) { $blockingActionOutput = "<a id='" . $user->ip . "' href='" . $this->extraWatch->config->renderLink("antiSpam", "&action=toggleBlocking&ip=" . $user->ip) . "' onclick=\"return confirm('" . _EW_USERS_BLOCK_IP_CONFIRM . "');\"><img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/unpublished.png'/> " . _EW_GOALS_BLOCK . "</a>"; if (@(!$user->countryCode)) { $countryCode = $this->extraWatch->helper->countryByIp($user->ip); $this->extraWatch->user->updateUserCountryByIp($user->ip, $countryCode); } else { $countryCode = $user->countryCode; } $countryName = $this->extraWatch->helper->countryCodeToCountryName($countryCode); $userName = $this->env->getUsernameById($user->userId); if (@$userName) { $output .= "<tr>"; $output .= "<td width='20%'>" . ExtraWatchDate::getDateTimeFromUTC($user->timestamp) . "</td>"; $output .= "<td width='20%'>" . $userName . "</td>"; $userRealName = $this->env->getUserRealNameById($user->userId); $output .= "<td width='20%'>" . $userRealName . "</td>"; $output .= "<td width='20%'>" . $user->ip . "</td>"; $output .= "<td width='20%'>"; if (@$countryCode) { $output .= "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/flags/" . $countryCode . ".png' title='" . $countryName . "'/>"; } $output .= "</td>"; $output .= "<td width='20%'>" . $blockingActionOutput . "</td>"; $output .= "</tr>"; } } } $output .= "</tbody></table>"; return $output; } else { return _EW_NO_DATA . "<br/>"; } }
function renderBadge($badgeForSection) { $today = ExtraWatchDate::jwDateToday(); switch ($badgeForSection) { case 'heatmap': $badgeValue = $this->extraWatch->heatmap->getHeatmapClickCountByDate($today); break; case 'clicks': $badgeValue = $this->extraWatch->heatmap->getTotalMostClickedHTMLElementsForDay($today); break; case 'users': $badgeValue = $this->extraWatch->user->getUserCountForDay($today); break; case 'seo': $badgeValue = $this->extraWatch->seo->getTotalVisitsByKeyphrasesByDay($today); break; case 'download': $badgeValue = $this->extraWatch->downloads->getDownloadCountForDay($today); break; case 'stats': $badgeValue = $this->extraWatch->stat->getCountByKeyAndDate(EW_DB_KEY_UNIQUE, $today); break; case 'visitors': $badgeValue = $this->extraWatch->visit->getActiveUsersCount(); break; case 'antiSpam': $badgeValue = $this->extraWatch->block->getBlockedCountByDate($today); break; // ... } $title = @constant("_EW_BADGE_" . strtoupper($badgeForSection)); if (@$badgeValue) { return "<span class=\"ew_badge\" title='{$title}''> " . $badgeValue . " </span>"; } }
function addIp2GoalId($ip, $goalId) { $query = sprintf("select id from #__extrawatch where `ip` = '%s'", $this->database->getEscaped($ip)); $visitId = $this->database->resultQuery($query); $query = sprintf("insert into #__extrawatch_visit2goal (visitId,goalId,timestamp) values ('%d', '%d', '%d')", (int) $visitId, (int) $goalId, (int) ExtraWatchDate::getUTCTimestamp()); $this->database->executeQuery($query); }
/** * stats/info */ function getIntValueByNameAndValue($name, $value, $date = FALSE) { if ($date == "") { $date = ExtraWatchDate::jwDateToday(); } $query = sprintf("select `value` from #__extrawatch_info where (`group` = '%s' and `date` = '%d' and `name` = '%s') limit 1 ", $this->database->getEscaped($name), (int) $date, $this->database->getEscaped($value)); $count = @$this->database->resultQuery($query); return $count; }
function renderTable($bots = FALSE, $inactive, $ipFilter = FALSE, $renderAsEmail = FALSE, $renderedFromHistory = FALSE) { $output = ""; $rows = $this->getJoinedURIRows($bots, $inactive, $ipFilter); $agentNotPublishedMessage = $this->extraWatch->env->getAgentNotPublishedMsg($this->extraWatch->database); $downloadLog = $this->extraWatch->downloads->getDownloadLogIpTimestampPath(); $countryCodeToCountryNameArray = $this->extraWatch->helper->countryCodeToCountryNameList(); if ($bots == FALSE && $agentNotPublishedMessage != FALSE && sizeof($rows) == 0 && $inactive == 0) { $output .= "<tr><td colspan='10'><span style='color:red; font-weight: bold;'>" . $agentNotPublishedMessage . "</span></td></tr> "; return $output; } else { } if (!$rows) { $noDataHTML = ""; if (!$bots && _EW_CLOUD_MODE && $inactive == FALSE && !$renderedFromHistory) { $noDataHTML = "<table><tr><td>"; $noDataHTML .= "<h2 style='color: #e74c3c; font-weight: bold;'>1. Select the HTML code below and copy it to a clipboard </h2>"; $noDataHTML .= "<i>(Click on text area below, Ctrl+A, Ctrl+C)</i><br/><br/>"; $noDataHTML .= "<textarea cols='90' rows='8'>"; $noDataHTML .= htmlentities($this->extraWatch->helper->renderHTMLCodeSnippet(_EW_PROJECT_ID)); $noDataHTML .= "</textarea><br/><br/>"; $noDataHTML .= "<h2 style='color: #e74c3c; font-weight: bold;'>2. Open editor of your website's front-end</h2><br/>"; $noDataHTML .= "This step may be different for every CMS. <br/>You need to find where's your website frontend saved as HTML and the modify that file. <br/><b>Or ask your webmaster do to it for you!</b>"; $noDataHTML .= "<h2 style='color: #e74c3c; font-weight: bold;'>3. Find the </body> tag</h2>"; $noDataHTML .= "This is a footer of my website ©MyWebsite.com<br/><b></body></b><br/></html>"; $noDataHTML .= "<h2 style='color: #e74c3c; font-weight: bold;'>4. Paste this code before the </body> tag</h2>"; $noDataHTML .= "This is a footer of my website ©MyWebsite.com<br/><i>{code from clipboard}</i><br/><b></body></b><br/></html>"; $noDataHTML .= "</td><td valign='top'>"; $noDataHTML .= "<h2 style='color: #e74c3c; font-weight: bold;'>.. Or Watch the video with instructions:</h2><br/><br/>"; $noDataHTML .= "<iframe width=\"640\" height=\"360\" src=\"//www.youtube.com/embed/tvHNg-X4d8o\" frameborder=\"0\" allowfullscreen></iframe>"; $noDataHTML .= "</td></tr></table>"; } else { if ($inactive == FALSE) { $noDataHTML .= _EW_NO_DATA; } } $output .= "<tr><td colspan='5'>" . $noDataHTML . "</td></tr>"; return $output; } /** if visits are empty */ //$output = ""; $i = 0xff; $decrement = -1; $lastIp = ""; //to be able to hide flags / address for same IP in next rows $lastReferer = ""; $lastColor = ""; $rowNumber = 0; $dateToday = $this->extraWatch->date->jwDateToday(); $uri2HeatmapClicksAssoc = $this->heatmap->heatmapForDayAsAsoc($dateToday); $maxClicksOfDay = $this->heatmap->getMaxClicksForDay($dateToday); if (!$renderAsEmail) { $liveSiteWithSuffix = $this->extraWatch->config->getLiveSiteWithSuffix(); } else { $liveSiteWithSuffix = $this->extraWatch->config->getDomainFromLiveSite(_EW_PROJECT_ID) . $this->extraWatch->config->getLiveSiteWithSuffix(); } if (@$rows) { foreach ($rows as $row) { $rowNumber++; /* reset the values from previous iteration */ $country = "none"; $countryName = ""; $countryUpper = ""; $color = ""; $inactiveClass = ""; $inactiveImageClass = ""; if ($row->inactive) { $inactiveClass = "class='extraWatchInactiveVisit'"; $inactiveImageClass = "class='extraWatchInactiveImage'"; } $flag = "<img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/flags/{$country}.png' title='{$countryName}' alt='{$countryName}' {$inactiveImageClass}/>"; if ($this->extraWatch->block->getBlockedIp($row->ip)) { //TODO optimize whole block $ipString = "<s>" . ExtraWatchHelper::htmlspecialchars($row->ip) . "</s>"; } else { $ipString = ExtraWatchHelper::htmlspecialchars($row->ip); } //TODO optimize whole block if ($i < 0xcc || $i <= 0x0) { $decrement = $decrement * -1; } $i = $i + $decrement; $color = sprintf("%x", $i) . sprintf("%x", $i) . sprintf("%x", $i); if ($bots == TRUE) { $color = "ffffff"; } $country = $row->country; if (!$country) { $country = $this->extraWatch->helper->countryByIp($row->ip); $this->extraWatch->visit->updateCountryForIP($country, $row->ip); } if (@$country) { $countryName = @$countryCodeToCountryNameArray[$country]; $this->extraWatch->helper->countryCodeToCountryName($country); //TODO optimize $flag = "<img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/flags/{$country}.png' title='{$countryName}' alt='{$countryName}' {$inactiveImageClass}/>"; $countryUpper = strtoupper($country); } $userAgent = ExtraWatchHelper::htmlspecialchars($row->browser); $browser = ""; $os = ""; $browserIcon = ""; $osIcon = ""; if (@$userAgent) { $browser = $this->extraWatch->referer->identifyBrowser(@$userAgent); if (@$browser) { $browserIcon = $liveSiteWithSuffix . "components/com_extrawatch/img/icons/" . strtolower($browser) . ".gif"; } if (@$browserIcon) { $browser = "<img src='{$browserIcon}' alt='{$userAgent}' title='{$userAgent}' {$inactiveImageClass}/>"; } $os = json_decode(@$this->extraWatch->referer->identifyOSAsJSON(@$userAgent)); if (@$os->name) { $osIcon = $liveSiteWithSuffix . "components/com_extrawatch/img/icons/" . strtolower($os->icon); } if (@$osIcon) { $os = sprintf("<img src='%s' alt='%s' title='%s' {$inactiveImageClass}/>", $osIcon, $userAgent, $userAgent); } } //$output .= $rowNumber; if ($bots == TRUE && $osIcon) { continue; } // bot icon fix if ($bots == TRUE) { $osIcon = $liveSiteWithSuffix . "components/com_extrawatch/img/icons/blank.gif"; $browserIcon = $liveSiteWithSuffix . "components/com_extrawatch/img/icons/blank.gif"; $browser = sprintf("<img src='%s' alt='%s' title='%s' {$inactiveImageClass}/>", ExtraWatchHelper::htmlspecialchars($browserIcon), ExtraWatchHelper::htmlspecialchars($userAgent), ExtraWatchHelper::htmlspecialchars($userAgent)); $os = sprintf("<img src='%s' alt='%s' title='%s' {$inactiveImageClass}/>", ExtraWatchHelper::htmlspecialchars($osIcon), ExtraWatchHelper::htmlspecialchars($userAgent), ExtraWatchHelper::htmlspecialchars($userAgent)); } $username = ""; if (@$row->username) { if (@get_class($this->extraWatch->env) == "ExtraWatchJoomlaEnv") { $username = "******" . $this->extraWatch->config->getAdministratorIndex() . "?option=com_users&task=view&filter_search={$row->username}' style='color: black; text-decoration:none;'><i>" . @ExtraWatchHelper::htmlspecialchars($row->username) . "</i></a>"; } else { $username = "******" . @ExtraWatchHelper::htmlspecialchars($row->username) . "</i></span>"; } } $ipString = sprintf("<a id='%s' href='javascript:extrawatch_blockIpToggle(\"%s\");extrawatch_sendVisitsReq();' style='color:black;' {$inactiveClass}>%s</a>", ExtraWatchHelper::htmlspecialchars($row->ip), ExtraWatchHelper::htmlspecialchars($row->ip), $ipString); $mapsIcon = "<img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/icons/map_icon.gif' border='0' " . $this->extraWatch->helper->getTooltipOnEvent() . "=\"ajax_showTooltip('" . $this->extraWatch->config->getLiveSite() . $this->extraWatch->env->getEnvironmentSuffix() . $this->extraWatch->env->renderBackendAjaxLink($this->extraWatch->config, 'ajax', 'tooltip') . "&ip={$row->ip}&env=" . $this->extraWatch->config->getEnvironment() . "&projectId=" . _EW_PROJECT_ID . "',this);return FALSE\"/>"; $timeOfVisit = $this->extraWatch->helper->secondsToHumanFormat(@$row->timeDiff); $timeOfVisit = str_replace(" ", " ", $timeOfVisit); $displayCountryFlag = FALSE; if ($lastIp != $row->ip) { $lastTimestamp = $row->timestamp; $displayCountryFlag = TRUE; $lastIp = $row->ip; $rowNumber = 1; } else { $flag = ""; // do not display flag, ip if the IP is same sa previous $ipString = ""; } if (!$displayCountryFlag) { $username = ""; $browser = ""; $os = ""; $mapsIcon = ""; $timeOfVisit = ""; } if ($lastReferer != $row->referer) { $output .= $this->renderRefererRow($lastReferer, $color); $lastReferer = $row->referer; $lastColor = $color; } $dateOfVisit = ExtraWatchDate::date("d.m.Y", $row->timestamp); if (@$this->lastDate != $dateOfVisit) { $output .= "<tr><td ></td><td ></td><td ></td><td ><td ></td></td><td ></td><td ></td><td ></td><td colspan='8' colspan='3'><h3>{$dateOfVisit}</h3></td></tr>"; $this->lastDate = $dateOfVisit; } $output .= "<tr><td valign='top' align='left' ></td> \t \t \t \t\t \t \t \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t \t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t\t \t\t \t \t\t \t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td valign='top' align='left' >" . @$mapsIcon . "</td><td valign='top' align='left' >"; if (!$countryUpper) { $output .= "<a href='" . $this->extraWatch->config->renderLink("goals", "insert&country=" . @$countryUpper) . "' style='color: #999999;' title='" . _EW_VISITS_ADD_GOAL_COUNTRY . "'>" . @$countryUpper . "</a>"; } $onlineString = ""; if ($row->inactive == 0 && $ipString) { $onlineString = "<img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/icons/online.png' valign='top' border='0'/>"; } $output .= "</td><td valign='top' align='left' >" . @$flag . "</td> \t \t \t \t\t \t \t \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t \t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t\t \t\t \t \t\t \t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td valign='top' align='left' ><span {$inactiveClass}>{$ipString}</span>"; $output .= "{$username}</td> \t \t \t \t\t \t \t \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t \t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t\t \t\t \t \t\t \t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td valign='top' align='left' >{$onlineString}</td> \t \t \t \t\t \t \t \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t \t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t\t \t\t \t \t\t \t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td valign='top' align='left' >" . @$browser . "</td> \t \t \t \t\t \t \t \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t \t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t\t \t\t \t \t\t \t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td valign='top' align='left' >" . @$os . "</td> \t \t \t \t\t \t \t \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t \t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t\t \t\t \t \t\t \t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td valign='top' align='left' width='80%'>"; $day = $this->extraWatch->date->jwDateFromTimestamp($row->timestamp); $downloadsForIp = $this->extraWatch->downloads->getDownloadLogForIPBetweenTimestampsFromRef($downloadLog, $rowNumber, $row->ip, $lastTimestamp, $row->timestamp); //TODO optimize $timestampHumanReadable = ExtraWatchDate::date("H:i:s", $row->timestamp); $downloadIcon = "<img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/icons/downloads.png' {$inactiveImageClass} />"; if (@$downloadsForIp) { foreach ($downloadsForIp as $download) { $downloadTimestampHumanReadable = ExtraWatchDate::date("H:i:s", $download['timestamp']); $output .= "<div {$inactiveClass}>" . $downloadTimestampHumanReadable . " {$downloadIcon} " . $download['dname'] . "</div><br/>"; } } $goalsForIp = $this->extraWatch->goal->getGoalsForVisitIdBetweenTimestamps($row->visitId, $lastTimestamp, $row->timestamp); //TODO optimize if (@$goalsForIp) { foreach ($goalsForIp as $goalForIp) { $goalTimestampHumanReadable = ExtraWatchDate::date("H:i:s", $goalForIp->timestamp); $goalLink = "<a href='" . $this->extraWatch->config->renderLink("goals", "edit&goalId=" . (int) $goalForIp->goalId . "") . "' target='_blank'>" . $goalForIp->name . "</a>"; $output .= "<div style='background-color: #FFF9E1;' {$inactiveClass}>" . $goalTimestampHumanReadable . sprintf(_EW_VISITS_GOAL_REACHED, $goalLink) . "</div><br/>"; } } $lastTimestamp = $row->timestamp; $trucateCharLimit = $this->extraWatch->config->getConfigValue('EXTRAWATCH_TRUNCATE_VISITS'); $uriTruncated = $this->extraWatch->helper->truncate(urldecode($row->uri), $trucateCharLimit); $titleOriginal = $row->title; $row->title = $this->extraWatch->helper->truncate($row->title, $trucateCharLimit); $row->title = $this->extraWatch->helper->removeRepetitiveTitle($row->title); $uri2titleId = $this->extraWatch->visit->getUri2TitleId($row->uri, $titleOriginal); //TODO optimize $output .= "<div id='id{$row->id}' style='text-decoration: none;' {$inactiveClass} onmouseout=\"toggleElementVisibility('goal_" . $row->id . "',0);\" onmouseover=\"toggleDiv('" . $row->id . "','" . $row->ip . "',1, " . (int) $uri2titleId . ", {$day});\" >"; if (@_EW_CLOUD_MODE) { $projectSite = $this->extraWatch->config->getDomainFromLiveSite(_EW_PROJECT_ID); if (!ExtraWatchHelper::startsWith($projectSite, "http://")) { //add http prefix $projectSite = "http://" . $projectSite; } } if (!$row->title) { $row->title = $uriTruncated; } $output .= "{$timestampHumanReadable} <a href='" . @$projectSite . $row->uri . "' target='_blank' {$inactiveClass} title='{$uriTruncated}'>{$row->title}</a>"; /* $userHeatmapClicks = $this->heatmap->getHeatmapClickNums($row->ip, $row->uri, ExtraWatchDate::jwDateFromTimestamp($timestampHumanReadable));//TODO optimize if (@$userHeatmapClicks > 0) { if (@$maxClicksOfDay) { $ratio = $userHeatmapClicks / $maxClicksOfDay; } else { $ratio = 1; } $userClicksColor = ExtraWatchHelper::rgbFromRatio($ratio); $output .= $this->heatmapHTML->renderHeatmapLink($row->uri, (int) $uri2titleId, $day, " <img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/icons/click.png' title='" . _EW_HEATMAP_CLICK_OPEN . "'/> <span style='color: " . $userClicksColor . "' title='" . _EW_HEATMAP_CLICK_OPEN . "' $inactiveClass>$userHeatmapClicks</span>", $row->ip); } */ $clicks = @$uri2HeatmapClicksAssoc[$row->uri]; if (@$clicks) { if (@$maxClicksOfDay) { $ratio = $clicks / $maxClicksOfDay; $color = ExtraWatchHelper::rgbFromRatio($ratio); } $heatmapLinkOutput = $this->heatmapHTML->renderHeatmapLink($row->uri, (int) $uri2titleId, $day, "<span style='color: " . $color . "' title='" . _EW_HEATMAP_CLICK_OPEN . "'>{$clicks}</span>"); } $paramData = $this->extraWatch->visit->areParamDataForUri($row->id); //TODO optimize if ($paramData) { $output .= "<img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/icons/submit.png' />"; } if (!$renderAsEmail) { /* ad as goal link */ $output .= "<div id='goal_" . $row->id . "' style='display: none; margin: 0px; padding: 2px; left: 40%;' class='uriDetailDiv'>" . _EW_STATS_LOADING; $output .= "</div>"; } if ($timeOfVisit) { } $output .= "<td>{$heatmapLinkOutput}</td>"; $output .= "<td>"; if (@$timeOfVisit) { $output .= "<td valign='top'><img src='" . $liveSiteWithSuffix . "components/com_extrawatch/img/icons/clock.png' title='" . _EW_LIVE_STATS_SESSION_TIME . "'/></td><td valign='top' style='color: grey'>"; $output .= $timeOfVisit; } $output .= "</td>"; $output .= "</div>"; //TODO handle post data if ($paramData) { $postImage = "<div id='idp{$row->id}' onmouseout=\"toggleDiv('post_" . $row->id . "',0, " . (int) $uri2titleId . ", {$day});\" onmouseover=\"toggleDiv('post_" . $row->id . "',1, " . (int) $uri2titleId . ", {$day});\">"; } else { $postImage = ""; } $output .= $postImage; /* show only last URI, not all by user */ if ($this->extraWatch->config->getCheckboxValue('EXTRAWATCH_ONLY_LAST_URI')) { break; } $output .= "</td>"; $output .= "</tr>"; } } $output .= @$this->renderRefererRow($lastReferer, $lastColor); unset($uri2HeatmapClicksAssoc); unset($downloadLog); unset($countryCodeToCountryNameArray); return $output; }
static function getWeekStartingDay($week = 0) { ExtraWatchLog::debug("getting week starting day: " . $week); if (!$week) { $weekDiff = 0; } else { $currentWeek = ExtraWatchDate::getCurrentWeek(); // OK $weekDiff = $currentWeek - $week; // difference between selected week number since 1.1.1970 and current week number ExtraWatchLog::debug("current week: {$currentWeek} weekDiff: {$weekDiff}"); } $dayOfWeek = ExtraWatchDate::dayOfWeek(); $dateToday = ExtraWatchDate::jwDateToday(); return $dateToday - $dayOfWeek - $weekDiff * 7 + 1; // +1 to make it start on monday }
* @revision 2572 * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU General Public License v3 * @copyright (C) 2015 by CodeGravity.com - All rights reserved! * @website http://www.codegravity.com */ defined('_JEXEC') or die('Restricted access'); ?> <table width='100%'> <tr> <td align='left'><?php echo "<a href='javascript:extrawatch_setDay({$prev})' id='{$prev}'><" . ExtraWatchDate::getDateByDay($prev) . "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/calendar.gif' border='0' align='center' /></a>"; ?> </td> <td class='ewCentered'><?php if ($day != $today) { echo "<a href='javascript:extrawatch_setDay({$today})' id='{$today}'>" . _EW_STATS_TODAY . "</a>"; } ?> </td> <td align='right'><?php if ($next <= $today) { echo "<a href='javascript:extrawatch_setDay({$next})' id='{$next}'><img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/calendar.gif' border='0' align='center' />" . ExtraWatchDate::getDateByDay($next) . "></a>"; } ?> </td> </tr> </table>
<?php } ?> <?php echo $extraWatch->block->checkBlocked(ExtraWatchVisit::getRemoteIPAddress()); ?> <div <?php echo $extraWatch->helper->getTooltipOnEventHide(); ?> > <div id="visits"> <table class="table"> <span style="color: #888"><?php echo ExtraWatchDate::getActualDateTime(); ?> </span> <h2><?php echo _EW_VISITS_PANE_LOADING; ?> </h2> <?php echo $extraWatchVisitHTML->getVisitorsCached(FALSE); echo $extraWatchVisitHTML->getVisitorsCached(TRUE); ?> </table> </div> <!-- <div id="stats" valign='top' align='left'>
function renderBlockedIPs($date = 0, $expanded = FALSE, $displayedInStats = TRUE) { $output = ""; if (!$expanded) { $output .= "<a href='javascript:extrawatch_blockIpManually();'>" . _EW_STATS_IP_BLOCKING_ENTER . "</a><br/>"; } $total = FALSE; if (!@$date) { $total = TRUE; } $count = $this->extraWatch->block->countBlockedIPs($date); if (!$count && !$displayedInStats) { $output = ExtraWatchHelper::renderNoData(); $output .= $this->renderAntispamHowTo(); return $output; } $limit = $this->extraWatch->config->getConfigValue('EXTRAWATCH_STATS_MAX_ROWS'); $output .= "<tr><th></th><th></th><th>IP</th><th>" . strtolower(_EW_STATS_HITS) . "</th>"; if (!$displayedInStats) { $output .= "<th>" . _EW_BLOCKING_BAD_WORD . "</th>"; $output .= "<th>" . _EW_BLOCKING_REASON . "</th>"; } $output .= "</tr>"; if ($count > $limit && !$expanded) { $output = "<tr><td colspan='4'>" . $this->extraWatchStatHTML->renderExpand('ip_blocking_title', $total) . "</td></tr>"; } if (@$expanded) { $rows = $this->extraWatch->block->getBlockedIPs($date, 100); // this cannot be unlimited, because otherwise the page would not open } else { $rows = $this->extraWatch->block->getBlockedIPs($date, $limit); } $lastDate = 0; $i = 0; if (@$rows) { foreach ($rows as $row) { $icon = ""; if (!strstr($row->ip, "*")) { if (@(!$row->country)) { $country = $this->extraWatch->helper->countryByIp($row->ip); $this->extraWatch->block->updateCountryForBlockedIp($row->ip, $country); } else { $country = $row->country; } $countryName = $this->extraWatch->helper->countryCodeToCountryName($country); if (!$country) { $country = "none"; } $icon = "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/flags/" . @strtolower($country) . ".png' title='{$countryName}' alt='{$countryName}'/>"; } $mapsIcon = "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/map_icon.gif' border='0' " . $this->extraWatch->helper->getTooltipOnEvent() . "=\"ajax_showTooltip('" . $this->extraWatch->config->getLiveSite() . $this->extraWatch->env->getEnvironmentSuffix() . $this->extraWatch->env->renderBackendAjaxLink($this->extraWatch->config, 'ajax', 'tooltip') . "&ip=" . @$row->ip . "&env=" . $this->extraWatch->config->getEnvironment() . "&projectId=" . _EW_PROJECT_ID . "',this);return FALSE\"/>"; if (!$displayedInStats && $lastDate != $row->date) { $output .= "<tr><td colspan='4'><u>" . ExtraWatchDate::getDateByDay($row->date) . "</u></td></tr>"; $lastDate = $row->date; } $output .= "<tr class='tableRow" . $i++ % 2 . "'><td class='ewCentered'>" . $mapsIcon . "</td><td class='ewCentered' title='{$row->reason}'>" . $icon . "</td><td align='left' title='{$row->reason}'>" . $row->ip . "</td><td class='ewCentered' title='{$row->reason}'>" . $row->hits . "</td>"; if (!$displayedInStats) { if (!$row->badWord) { $spamWordAffected = $this->extraWatch->block->checkForSpamWord($row->reason); if (@$spamWordAffected) { $this->extraWatch->block->updateSpamWordForBlockedIp($row->ip, $spamWordAffected); $row->badWord = $spamWordAffected; } } $output .= "<td class='ewCentered' title='" . $row->badWord . "'>" . ExtraWatchHelper::truncate($row->badWord, 10) . "</td>"; $output .= "<td title=\"" . ExtraWatchHelper::htmlspecialchars($row->reason) . "\">" . $this->highlightSpamWord($row->badWord, $row->reason) . "</td>"; } $output .= "<td>"; if (!$expanded) { $output .= "<a id='{$row->ip}' href='javascript:extrawatch_blockIpToggle(\"{$row->ip}\");history.go(0);' title='{$row->reason}'>" . _EW_BLOCKING_UNBLOCK . "</a>"; } else { $output .= "<a id='{$row->ip}' href='" . $this->extraWatch->config->renderLink("antiSpam", "&action=toggleBlocking&ip=" . $row->ip) . "' title='{$row->reason}'>" . _EW_BLOCKING_UNBLOCK . "</a>"; } $output .= "</td>"; $output .= "</tr>"; } } return $output; }
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU General Public License v3 * @copyright (C) 2015 by CodeGravity.com - All rights reserved! * @website http://www.codegravity.com */ defined('_JEXEC') or die('Restricted access'); ?> <a name="ewDateControl"></a> <br/> <table width='100%'> <tr> <td align='left'><?php echo "<a href='" . $this->extraWatch->config->renderLink($task, "&day={$prev}#ewDateControl") . "' id='{$prev}'><" . ExtraWatchDate::date("d.m.Y", $prev * 3600 * 24) . "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/calendar.gif' border='0' align='center' /></a>"; ?> </td> <td class='ewCentered'><?php if ($day != $today) { echo "<a href='" . $this->extraWatch->config->renderLink($task, "&day={$today}#ewDateControl") . "' id='{$today}'>" . _EW_STATS_TODAY . "</a>"; } ?> </td> <td align='right'><?php if ($next <= $today) { echo "<a href='" . $this->extraWatch->config->renderLink($task, "&day={$next}#ewDateControl") . "' id='{$next}'><img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/calendar.gif' border='0' align='center' />" . ExtraWatchDate::date("d.m.Y", $next * 3600 * 24) . "></a>"; } ?> </td> </tr> </table>
function renderWeekTrendData($group, $name, $date) { $NUMBER_OF_BARS = 20; $resultsArray = array(); $max = 0; $maxDate = 0; // first day has to be monday $lineArray[] = "{\"period\": \"" . date("Y", ($date - 20) * 3600 * 24) . " W" . date("W", ($date - 20) * 3600 * 24) . "\", \"value\":" . (int) 0 . "}"; $dayOfWeek = ExtraWatchDate::date("N", $date * 24 * 3600) - 1; for ($i = $date - $NUMBER_OF_BARS * 7 - $dayOfWeek + 7; $i <= $date - $dayOfWeek; $i += 7) { $value = $this->extraWatch->stat->getSumOfTwoDays($i + 7, $i, $group, $name); if ($max < $value) { $max = $value; $maxDate = $i; } $lineArray[] = "{\"period\": \"" . date("Y", $i * 3600 * 24) . " W" . date("W", $i * 3600 * 24) . "\", \"value\":" . (int) $value . "}"; } return implode(",", $lineArray); }
function renderPositionChangeDiff($rows, $day) { $output = ""; if ($rows) { $lastAveragePosition = 0; foreach ($rows as $row) { $averagePosition = $row->averagePosition; if ($lastAveragePosition != $averagePosition) { if ($lastAveragePosition) { $diff = (double) ($averagePosition - $lastAveragePosition); $diffColor = ExtraWatchTrendHTML::getDiffColor($diff, TRUE); $diffImg = "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/trend_{$diffColor}.gif' border='0'/>"; if ($day == $row->date || !$day) { $output .= sprintf("<td style='color: {$diffColor}' align='right'>%+.2f</td><td>{$diffImg}</td><td class='ewCentered'>%s</td>", $diff, ExtraWatchDate::getDateByDay($row->date)); } } $lastAveragePosition = $averagePosition; } } } return $output; }
$extraWatch = new ExtraWatchMain(); $extraWatch->helper->setNoindexHttpHeaders(); //setting explicitly for ajax requests $extraWatch->config->initializeTranslations(); $extraWatchHTML = new ExtraWatchHTML(); $extraWatchVisitHTML = new ExtraWatchVisitHTML($extraWatch); $extraWatchBlockHTML = new ExtraWatchBlockHTML($extraWatch); $extraWatchHeatmapHTML = new ExtraWatchHeatmapHTML($extraWatch->database); $extraWatch->block->checkBackendTokenFromUrl(); $t1 = time() + microtime(); $last = $extraWatch->visit->getLastVisitId(); echo "<span style='display: none;'>{$last}</span>\n\n"; $day = $extraWatch->date->jwDateToday(); ExtraWatchLog::debug("<br/>date today: " . $day); ExtraWatchLog::debug("<br/>actual dateTime: " . ExtraWatchDate::getActualDateTime()); ExtraWatchLog::debug("<br/>server time: " . ExtraWatchDate::getUTCTimestamp()); ExtraWatchLog::debug("<br/>date today: " . $extraWatch->date->getDateByDay($day, "d.m.Y H:i:s")); ExtraWatchLog::debug("<br/>"); require_once JPATH_BASE2 . DS . "components" . DS . "com_extrawatch" . DS . "view" . DS . "visits.php"; ?> <br/><br/> <span style='color: #ddd'><?php echo _EW_RENDERED_IN; ?> <?php echo sprintf("%.2f", time() + microtime() - $t1); ?> s</span>
function renderDiffTableCellsAndIcon($group, $origName, $day, $noIcon = FALSE) { if (@(!$day)) { $day = ExtraWatchDate::jwDateToday(); } $oneDayDiff = $this->extraWatch->stat->getRelDiffOfTwoDays($day - 1, $day, $group, $origName); $sevenDayDiff = $this->extraWatch->stat->getRelDiffOfTwoDays($day - 7, $day, $group, $origName); $twentyEightDayDiff = $this->extraWatch->stat->getRelDiffOfTwoDays($day - 28, $day, $group, $origName); $oneDayDiffRendered = $this->renderPercentage($oneDayDiff); $sevenDayDiffRendered = $this->renderPercentage($sevenDayDiff); $twentyEightDayDiffRendered = $this->renderPercentage($twentyEightDayDiff); $trendsIcon = $this->renderTrendsIcon($group, $origName, $day); $output = "<td class='ewCentered'>{$oneDayDiffRendered}</td>" . "<td class='ewCentered'>{$sevenDayDiffRendered}</td>" . "<td class='ewCentered'>{$twentyEightDayDiffRendered}</td>"; if (!$noIcon) { $output .= "<td class='ewCentered'>{$trendsIcon}</td>"; } return $output; }
?> </h2> <i>This section allows you navigate between days and see the differences in percents, charts of most popular clicks by hovering on the blue charts icon</i> <table width='100%' border="0"> <tr> <td colspan="5"> <?php echo $extraWatchHTML->renderDateControlGet('heatmap', $day); ?> </td> </tr> </table> <br/> <?php if ($day == ExtraWatchDate::jwDateToday()) { $extraWatchHeatmap->updateHeatmapStats($day); } ?> <?php echo $extraWatchHeatmapHTML->renderHeatmapTable($day); ?> <i style='color: #ddd'>Displaying only first 20 records</i> <br/><br/> <br/><br/> <table width='100%' border="0"> <tr> <td colspan="5"> <?php
* @website http://www.codegravity.com */ defined('_JEXEC') or die('Restricted access'); ?> <h2><?php echo _EW_ADMINHEADER_GRAPHS; ?> </h2> <?php $group = ExtraWatchHelper::requestPost('group'); if (!$group) { $group = EW_DB_KEY_REFERERS; } $date = ExtraWatchDate::jwDateToday(); //$name = EW_DB_KEY_REFERERS; echo $extraWatchTrendHTML->renderGraphSelectionForm($group); $rows = $extraWatchTrendHTML->findLatestGraphDataRecursively($group, $date, FALSE); $i = 0; if (@$rows) { foreach ($rows as $row) { switch ($group) { case EW_DB_KEY_OS: $osDecoded = @json_decode($row->name); $rowName = $osDecoded->name; break; default: $rowName = $row->name; break; }
/** * @param $ipArray * @param $date */ public function flushIPBulkFromArray($ipArray) { $date = ExtraWatchDate::jwDateToday(); $valuesOutputArray = array(); $i = 0; foreach ($ipArray as $ip) { $valuesOutputArray[] = sprintf(" ('%s','%s', '%s', '%d')", $this->database->getEscaped($ip), "", EXTRAWATCH_UNKNOWN_COUNTRY, (int) $date); //adding reason as empty, to save db space if ($i < sizeof($ipArray)) { if ($i != 0 && $i % self::IP_BULK_IMPORT_SIZE == 0) { $valuesOutput = implode(",", $valuesOutputArray) . ";"; $this->insertIpBulk($valuesOutput); $valuesOutputArray = array(); } $i++; } } $valuesOutput = implode(",", $valuesOutputArray) . ";"; $this->insertIpBulk($valuesOutput); // remaining IP addresses }
function renderPagesWithHighlightedHTMLElementsTable($day = 0, $limit = 20) { if (!$day) { $day = ExtraWatchDate::jwDateToday(); } $rows = $this->extraWatchHeatmap->getTopHeatmapUris($day, 20); $output = sprintf("<table class='tablesorter table table-striped'>\n <thead>\n <tr><th>%s</th> \t \t \t \t\t \t \t \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t \t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t\t \t\t \t \t\t \t\t \n <th>%s</th>\n <th>%s</th>", _EW_HEATMAP_CLICKS, _EW_HEATMAP_TITLE, _EW_URI); $output .= sprintf("<th align='center'>%s</th><th>%s</th><th>%s</th><th></th></tr>", _EW_EMAIL_REPORTS_1DAY_CHANGE, _EW_EMAIL_REPORTS_7DAY_CHANGE, _EW_EMAIL_REPORTS_28DAY_CHANGE); $output .= "</thead><tbody>"; if (!$rows) { $output .= "</table>"; $output .= ExtraWatchHelper::renderNoData(); return $output; } $maxClicksForDay = $this->extraWatchHeatmap->getMaxClicksForDay($day); $i = 0; if ($rows) { foreach ($rows as $row) { if (@$row->uri2titleId) { $output .= $this->renderHeatmapTableRow($row, $day, $maxClicksForDay, $i, TRUE); $i++; } } } $output .= "</tbody></table>"; return $output; }
function getTrialVersionTimeLeft() { return (int) (16 - (ExtraWatchDate::getUTCTimestamp() - $this->getConfigValue("EXTRAWATCH_TRIAL_TIME")) / 3600 / 24 - 0.01); //because it will display 15 days as time left }
/** * visitor */ function increaseUri2TitleCount($uri) { $query = sprintf("update #__extrawatch_uri2title set count = count+1, timestamp = '%d' where (`uri` = '%s')", (int) ExtraWatchDate::getUTCTimestamp(), $this->database->getEscaped($uri)); $this->database->executeQuery($query); }