name;
$i -= 3;
$color = sprintf("%x", $i) . sprintf("%x", $i) . sprintf("%x", $i);
if ($count) {
$percent = floor(($row->value / $count) * 1000) / 10;
}
else {
$percent = 0;
}
switch (@$group) {
case DB_KEY_COUNTRY : {
//TODO refactor this, looks ugly
$arrayCountryIcon = $this->changeCountry($j, $row, $frontend);
if (@$arrayCountryIcon) {
$countryName = $arrayCountryIcon[0];
$icon = $arrayCountryIcon[1];
}
break;
}
}
if (@ $row->name) {
if ($currentColumn == 0) {
$output .= "";
}
if ($flagsFirst) {
$output .= "" . @ $icon . " | ";
$output .= "$percent% | ";
} else {
$output .= "$percent% | ";
$output .= "" . @ $icon . " | ";
}
if ($countryNamesDisplayed) {
$output .= "" . $countryName . " | ";
} else {
$output .= " | ";
}
if ($currentColumn == $maxColumns-1) {
$output .= "
";
}
}
$j++;
}
}
return $output;
}
function renderNightlyEmail() {
$keysArray = array('goals', 'uri', 'referers', 'keywords', 'keyphrase', 'internal', 'country', 'ip', 'users', 'browser', 'os');
$day = $this->joomlaWatch->helper->jwDateToday();
$output = "";
foreach ($keysArray as $key) {
if ($key == 'ip' && !$this->joomlaWatch->config->getConfigValue('JOOMLAWATCH_IP_STATS')) {
continue;
}
$output .= nl2br($this->renderIntValuesByNameForEmail($key, true, false, $day, 10, false, true ));
$output .= " |
";
}
$output .= "
";
return $output;
}
function sendNightlyEmail() {
$output = $this->renderNightlyEmail();
$domain = $this->joomlaWatch->config->getDomainFromLiveSite();
$email = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_REPORTS_ADDRESS");
$date = joomlaWatchHelper::date("d.m.Y", JoomlaWatchHelper::getLocalTime() - 24*3600); // date of report from yesterday, not today);
JoomlaWatchHelper::sendEmail("$email","$email", "JoomlaWatch report - $domain - $date", $output);
return $output;
}
/* visit */
function renderIntValuesByNameForEmail($groupOriginal, $expanded = false, $total = false, $date = 0, $limit = 5, $frontend = false) {
$truncate = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_NAME_TRUNCATE");
$group = @ constant('DB_KEY_'.strtoupper($groupOriginal));
$groupTranslated = @constant ("_JW_STATS_".strtoupper($groupOriginal));
$output = "";
if (!$date) {
$date = $this->joomlaWatch->helper->jwDateToday();
}
$onlyPercentHigherThan = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_PERCENT_HIGHER_THAN");
$oneDayPositive = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_ONE_DAY_CHANGE_POSITIVE");
$oneDayNegative = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_ONE_DAY_CHANGE_NEGATIVE");
$sevenDayPositive = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_SEVEN_DAY_CHANGE_POSITIVE");
$sevenDayNegative = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_SEVEN_DAY_CHANGE_NEGATIVE");
$thirtyDayPositive = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_THIRTY_DAY_CHANGE_POSITIVE");
$thirtyDayNegative = $this->joomlaWatch->config->getConfigValue("JOOMLAWATCH_EMAIL_THIRTY_DAY_CHANGE_NEGATIVE");
$rows = $this->joomlaWatch->stat->getIntValuesByName($group, $date-1, $expanded, $limit); // -1 because of yesterday
$count = $this->joomlaWatch->stat->getCountByKeyAndDate($group, $date-1); // -1 because of yesterday
$j = 0;
foreach ($rows as $row) {
$origName = $row->name;
$relOneDayDiff = $this->joomlaWatch->stat->getRelDiffOfTwoDays($date -2, $date -1, $group, $row->name); //-2, -1 because we are rendering yesterday
$relSevenDayDiff = $this->joomlaWatch->stat->getRelDiffOfTwoDays($date -8, $date -1, $group, $row->name); //-7, -1 because we are rendering yesterday -7
$relThirtyDayDiff = $this->joomlaWatch->stat->getRelDiffOfTwoDays($date -31, $date -1, $group, $row->name); //-30, -1 because we are rendering yesterday -30
if ($count) {
$percent = floor(($row->value / $count) * 1000) / 10;
}
else {
$percent = 0;
}
if (!$onlyPercentHigherThan || $percent > $onlyPercentHigherThan) {
/** check boundaries */
if (
(
(!$relOneDayDiff || ($relOneDayDiff <= $oneDayNegative)) ||
(!$relOneDayDiff || ($relOneDayDiff >= $oneDayPositive))
)
&&
(
(!$relSevenDayDiff || ($relSevenDayDiff <= $sevenDayNegative)) ||
(!$relSevenDayDiff || ($relSevenDayDiff >= $sevenDayPositive))
)
&&
(
(!$relThirtyDayDiff || ($relThirtyDayDiff <= $thirtyDayNegative)) ||
(!$relThirtyDayDiff || ($relThirtyDayDiff >= $thirtyDayPositive))
)
) {
if ($relOneDayDiff > 0) {
$oneDayDiffColor = "green";
$oneDayDiffSign = "+";
} else {
$oneDayDiffColor = "red";
$oneDayDiffSign = "";
}
if ($relSevenDayDiff > 0) {
$sevenDayDiffColor = "green";
$sevenDayDiffSign = "+";
} else {
$sevenDayDiffColor = "red";
$sevenDayDiffSign = "";
}
if ($relThirtyDayDiff > 0) {
$thirtyDayDiffColor = "green";
$thirtyDayDiffSign = "+";
} else {
$thirtyDayDiffColor = "red";
$thirtyDayDiffSign = "";
}
switch ($group) {
case DB_KEY_GOALS: {
$row->name = $this->joomlaWatch->goal->getGoalNameById($row->name);
break;
}
case DB_KEY_INTERNAL: {
$internal = $this->joomlaWatch->visit->getInternalNameById(@ $row->name);
$from = $this->joomlaWatch->visit->getTitleByUri($internal->from);
$to = $this->joomlaWatch->visit->getTitleByUri($internal->to);
$internal->from = JoomlaWatchHelper::truncate($internal->from, $truncate);
$internal->to = JoomlaWatchHelper::truncate($internal->to, $truncate);
$row->name = "".$internal->from." ->
".$internal->to." " ;
break;
}
default: {
$row->name = JoomlaWatchHelper::truncate($row->name, $truncate);
break;
}
}
if (@ $row->name && $relOneDayDiff != 0) {
$output .= sprintf("%s | %.1f | %.1f%% | $oneDayDiffSign%.1f%% | $sevenDayDiffSign%.1f%% | $thirtyDayDiffSign%.1f%% |
",
$row->name,
$row->value,
$percent,
$relOneDayDiff,
$relSevenDayDiff,
$relThirtyDayDiff
);
$j++;
}
}
}
}
if ($j) {
$output = "$groupTranslated | "._JW_EMAIL_REPORTS_VALUE." | "._JW_EMAIL_REPORTS_PERCENT." | "._JW_EMAIL_REPORTS_1DAY_CHANGE." | "._JW_EMAIL_REPORTS_7DAY_CHANGE." | "._JW_EMAIL_REPORTS_30DAY_CHANGE." |
".$output;
}
return $output;
}
/**
* percent not linear but by sinusoid approaching to 100%
* @param $maxWidth
* @return float
*/
function sinusInsteadOfLinear($maxWidth, $percent) {
$pi = 3.141592653;
return floor($maxWidth*sin($percent/100 * $pi/2));
}
/**
* stats
* upper side visits statistics - unique/loads/hits
* @param unknown_type $week
* @return unknown
*/
function renderVisitsGraph($week = 0) {
$output = "";
// $today = JoomlaWatchHelper::date("d.m.Y", $this->joomlaWatch->helper->getServerTime());
$today = JoomlaWatchHelper::date("d.m.Y", JoomlaWatchHelper::getLocalTime());
$dateExploded = explode('.', $today);
$dayOfWeek = $this->joomlaWatch->helper->dayOfWeek();
$startTimestamp = ($week * 24 * 3600 * 7) - (3*24*3600);
$i = 0xFF;
$dateWeekStart = $this->joomlaWatch->helper->getDayByTimestamp($startTimestamp);
$maxLoads = $this->joomlaWatch->stat->getMaxValueInGroupForWeek(DB_KEY_LOADS, DB_KEY_LOADS, $dateWeekStart);
for ($sec = $startTimestamp; $sec < $startTimestamp+7*3600*24; $sec += 24 * 3600) {
$i -= 3;
$color = sprintf("%x", $i) . sprintf("%x", $i) . sprintf("%x", $i);
if ($i % 2 == 0) {
$color = "#f5f5f5";
}
else {
$color = "#fafafa";
}
$percent = 0;
$count = 0;
/* $date = JoomlaWatchHelper::jwDateBySeconds($sec);
echo("date: $date");
*/
$date = floor($sec / 3600 / 24 + $this->joomlaWatch->config->getConfigValue('JOOMLAWATCH_DAY_OFFSET'));
$stats['unique'] = $this->joomlaWatch->stat->getKeyValueInGroupByDate(DB_KEY_UNIQUE, DB_KEY_UNIQUE, $date);
$stats['loads'] = $this->joomlaWatch->stat->getKeyValueInGroupByDate(DB_KEY_LOADS, DB_KEY_LOADS, $date);
$stats['hits'] = $this->joomlaWatch->stat->getKeyValueInGroupByDate(DB_KEY_HITS, DB_KEY_HITS, $date);
foreach ($stats as $key => $value) {
$count = $stats['loads'];
if ($count)
$percent = floor(($value / $count) * 100);
$progressBarIcon = $this->joomlaWatch->config->getLiveSite()."components/com_joomlawatch/icons/progress_bar_$key.gif";
$output .= "";
$dow = JoomlaWatchHelper::date("D", $sec);
if (@ !$once[$dow]) {
$output .= substr(JoomlaWatchHelper::date("d.m.Y", $sec), 0, 6) . " " . $dow;
$once[$dow] = 1;
}
$output .= " | ";
if ($maxLoads)
$percentWidth = floor( ($percent * $value) / $maxLoads);
else
$percentWidth = $percent;
if (@ $value) {
switch ($key) {
case 'hits' : {
$fontColor = "#aaaaaa";
$output .= "" . $value . " | | ";
break;
}
case 'loads': {
$fontColor = "#00C000";
$output .= "" . $value . " | | ";
break;
}
default: {
$fontColor = "black";
$output .= "" . $value . " |  | $percent% |
| ";
}
}
} else
$output .= " | | ";
$output .= "
";
}
}
$output .= "* " . _JW_STATS_UNIQUE . ", " . _JW_STATS_LOADS . ", " . _JW_STATS_HITS . " |
";
return $output;
}
/* stats */
function renderExpand($element, $total = false) {
$elementSuffix = "";
if (@$total) {
$elementSuffix = "_total";
}
if (@ JoomlaWatchHelper::requestGet($element.$elementSuffix) == "false" || !@ JoomlaWatchHelper::requestGet($element.$elementSuffix)) {
$operation = "expand";
}
else {
$operation = "collapse";
}
$operationTranslated = constant("_JW_STATS_" . strtoupper($operation));
$elementTranslated = constant("_JW_STATS_" . strtoupper($element));
$output = "
$operationTranslated $elementTranslated";
return $output;
}
/* stats */
function renderSwitched($element, $text, $value) {
$output = "";
if ($element != $value) {
$output .= "$text";
} else
$output .= "$text