.popular-links {
border-color: #313131;
border-collapse: collapse;
width: auto;
}
.popular-links th {
font-size: 12px;
color: white;
}
.popular-links td, th {
padding: 8px;
border-color: #313131;
text-align: center;
word-break: break-all;
}
.popular-links thead {
background-color: #007bff;
}
.popular-links td:nth-child(1) {
font-weight: 700;
background: -webkit-linear-gradient(left, #2db86cba var(--percentage), transparent var(--percentage));
background: -moz-linear-gradient(left, #2db86cba var(--percentage), transparent var(--percentage));
background: -ms-linear-gradient(left, #2db86cba var(--percentage), transparent var(--percentage));
background: -o-linear-gradient(left, #2db86cba var(--percentage), transparent var(--percentage));
background: linear-gradient(to right, #2db86cba var(--percentage), transparent var(--percentage));
}
.popular-links tbody tr:hover {
background: rgb(90, 90, 90); /* fallback */
background: rgba(90, 90, 90, 0.1);
}
.url {
display: inline-grid;
}
Popular Links
';
function show_top($numdays,$numlinks) {
global $ydb;
$table_url = YOURLS_DB_TABLE_URL;
$base = YOURLS_SITE;
$links = '';
// Check if YOURLS_HOURS_OFFSET constant is defined and parse it
$offset_hours = defined('YOURLS_HOURS_OFFSET') ? (float)YOURLS_HOURS_OFFSET : 0;
$offset_seconds =$offset_hours * 3600;
// Prepare MySQL interval string for timestamp adjustment in query
if ($offset_hours != 0) {
$interval_op =$offset_hours >= 0 ? '+' : '-';
$abs_hours = abs($offset_hours);
$mysql_offset = "DATE_ADD(NOW(), INTERVAL {$offset_hours} HOUR)";
} else {
$mysql_offset = "NOW()";
}
$query =$ydb->fetchObjects(
"SELECT `title`, `timestamp`, `url`, `keyword`, `clicks` FROM `$table_url`
WHERE `timestamp` >= SUBDATE({$mysql_offset},$numdays)
ORDER BY `clicks` DESC
LIMIT $numlinks"
);
if ($query) {
$maxClicks = max(array_column($query, 'clicks'));
foreach ($query as$query_result) {
if ($query_result->clicks > 0) {
$thisURLArray = parse_url(stripslashes($query_result->url));
// Calculate time difference including the offset adjustment
$now_with_offset = time() +$offset_seconds;
$diff = abs($now_with_offset - strtotime($query_result->timestamp));
$days = floor($diff / (60 * 60 * 24));
if ($days < 1) {$created = 'today';
} else if ($days < 2) {$created = ' 1 day ago';
} else {
$created =$days . ' days ago';
}
$percentage = ($query_result->clicks / $maxClicks) * 100 + 1;
$links .= '
| ' . $percentage_display . '' .$query_result->clicks . ' |
' . $created . ' |
' . $query_result->keyword . ' |
|
' . $thisURLArray['host'] . ' |
';
}
}
}
echo 'Last ' . $numdays . ' Days:
| Clicks |
Created |
Short Url (Keyword) |
Original Url |
Host |
'
. $links .
'
'
. "
\n\r";
}
// Edit these if you want to show a different number of days/number of links! i.e. 1,5 means the 5 most popular links created in the last 1 day.
show_top(1, 5);
show_top(7, 5);
show_top(30, 5);
show_top(365, 5);
}