I have been using Yourls for over a year now with Gkurl.us, so I thought I would share the code for some of the modifications I have made.

Popular Page

This page shows the top links for day/week/month, and year, etc.

Note that you will need to change the website URL, and possibly the table name (mine is url). Save as popular.php and upload to the pages directory.

<?php

require( ‘includes/load-yourls.php’ );

// TOP TODAY

$urlt2  = ”;

$sqlcode = “SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE timestamp >= SUBDATE(CURDATE(), 1) “;

$sqlcode .= “order by clicks desc limit 1″;

$query = $ydb->get_results($sqlcode);

if ($query) {

foreach( $query as $query_result ) {

$thisURLArray  = parse_url(stripslashes($query_result->url));

$urlt2  .= ‘<a href=”http://gkurl.us/’ . $query_result->keyword .’” target=”blank”>’;

$urlt2  .= str_replace(‘www.’, ”, $query_result->title) . ‘</a> <a href=”http://gkurl.us/’ . $query_result->keyword .’+” target=”blank”>(‘ . $query_result->clicks . ‘) </a> – ‘ .$thisURLArray[host] .’ Submitted ‘ . $query_result->timestamp . ‘<br/>’;

}

}

echo ‘<h3><b>Trending Today:</b></h3><br/> ‘ . $urlt2 . “<br><br>\n\r”;

?>

<?php

// THIS WEEKS TOP LINKS

$urlt2  = ”;

$sqlcode = “SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE timestamp >= SUBDATE(CURDATE(), 7) “;

$sqlcode .= “order by clicks desc limit 10″;

$query = $ydb->get_results($sqlcode);

if ($query) {

foreach( $query as $query_result ) {

$thisURLArray  = parse_url(stripslashes($query_result->url));

$urlt2  .= ‘<a href=”http://gkurl.us/’ . $query_result->keyword .’” target=”blank”>’;

$urlt2  .= str_replace(‘www.’, ”, $query_result->title) . ‘</a> <a href=”http://gkurl.us/’ . $query_result->keyword .’+” target=”blank”>(‘ . $query_result->clicks . ‘) </a> – ‘ .$thisURLArray[host] .’ Submitted ‘ . $query_result->timestamp . ‘<br/>’;

}

}

echo ‘<h3><b>This Week\’s Top links:</b></h3><br/> ‘ . $urlt2 . “<br><br>\n\r”;

?>

<?php

// THIS MONTHS TOP LINKS

$urlt4  = ”;

$sqlmonth = “SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE timestamp >= SUBDATE(CURDATE(), 31) “;

$sqlmonth .= “order by clicks desc limit 10″;

$query = $ydb->get_results($sqlmonth);

if ($query) {

foreach( $query as $query_result ) {

$thisURLArray  = parse_url(stripslashes($query_result->url));

$urlt4  .= ‘<a href=”http://gkurl.us/’ . $query_result->keyword .’” target=”blank”>’;

$urlt4  .= str_replace(‘www.’, ”, $query_result->title) . ‘</a> <a href=”http://gkurl.us/’ . $query_result->keyword .’+” target=”blank”>(‘ . $query_result->clicks . ‘) </a> – ‘ .$thisURLArray[host] .’ Submitted ‘ . $query_result->timestamp . ‘<br/>’;

}

}

echo ‘<h3><b> This Months\’s Top links:</b></h3><br/>’ . $urlt4 . “<br><br>\n\r”;

?>

<?php

//THIS YEAR

$urlt5  = ”;

// This year

$sqlyear = “SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE timestamp >= SUBDATE(CURDATE(), 366) “;

$sqlyear .= “order by clicks desc limit 10″;

$query = $ydb->get_results($sqlyear);

if ($query) {

foreach( $query as $query_result ) {

$thisURLArray  = parse_url(stripslashes($query_result->url));

$urlt5 .= ‘<a href=”http://gkurl.us/’ . $query_result->keyword .’” target=”blank”>’;

$urlt5  .= str_replace(‘www.’, ”, $query_result->title) . ‘</a> <a href=”http://gkurl.us/’ . $query_result->keyword .’+” target=”blank”>(‘ . $query_result->clicks . ‘) </a> – ‘ .$thisURLArray[host] .’ Submitted ‘ . $query_result->timestamp . ‘<br/>’;

}

}

echo ‘<h3><b> All Time Top links:</b></h3><br/> ‘ . $urlt5 . “<br><br>\n\r”;

?>

 

Top Pics Page

This code shows the top images (urls with gif, jpg, jpeg, or png).

Again, you will have to change the URL and table name.


<?php
require( 'includes/load-yourls.php' );
?>
<?php
$urlt5 = ”;
// This month
$sqlyear = "SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE timestamp >= SUBDATE(CURDATE(), 1)  AND url like '%.jpg%' OR  timestamp >= SUBDATE(CURDATE(), 1)  AND url like '%.gif%' OR  timestamp >= SUBDATE(CURDATE(), 1)  AND url like '%.png%'  ";
$sqlyear .= "order by clicks desc limit 5";
$query = $ydb->get_results($sqlyear);
if ($query) {
$i = 0;
foreach( $query as $query_result ) {
$i++;
$thisURLArray = parse_url(stripslashes($query_result->url));
$url = $query_result->url;
$urlt5 .= '<a href="http://gkurl.us/' .$query_result->keyword. '"  title="' . $query_result->title . ' ( ' . $query_result->clicks . ') "><img align="center" src="' .$url. '" width="20%" height="20%" alt="" /></a>';
}
}
echo '<h3><b> Top Pictures Today:</b></h3><br/> ' . $urlt5 . "<br><br>\n\r";
?>
<?php
//THIS week
$urlt5 = '';
// This weel
$sqlyear = "SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE timestamp >= SUBDATE(CURDATE(), 7)  AND url like '%jpg%' OR  timestamp >= SUBDATE(CURDATE(), 7) AND url like '%.gif%' OR  timestamp >= SUBDATE(CURDATE(), 7) AND url like '%.png%'  ";
$sqlyear .= "order by clicks desc limit 5";
$query = $ydb->get_results($sqlyear);
if ($query) {
$i = 0;
foreach( $query as $query_result ) {
$i++;
$thisURLArray = parse_url(stripslashes($query_result->url));
$url = $query_result->url;
$urlt5 .= '<a href="http://gkurl.us/' .$query_result->keyword. '"  title="' . $query_result->title . ' ( ' . $query_result->clicks . ') "><img src="' .$url. '" width="20%" height="20%" alt="" /></a>';
}
}
echo '<h3><b> This Weeks Top Pics:</b></h3><br/> ' . $urlt5 . "<br><br>\n\r";
?>
<?php
//THIS month
$urlt5 = '';
// This month
$sqlyear = "SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE timestamp >= SUBDATE(CURDATE(), 31) AND url like '%.jpg%' OR timestamp >= SUBDATE(CURDATE(), 31) AND url like '%.gif%' OR timestamp >= SUBDATE(CURDATE(), 31) AND  url like '%.png%'   ";
$sqlyear .= "order by clicks desc limit 5";
$query = $ydb->get_results($sqlyear);
if ($query) {
$i = 0;
foreach( $query as $query_result ) {
$i++;
$thisURLArray = parse_url(stripslashes($query_result->url));
$url = $query_result->url;
$urlt5 .= '<a href="http://gkurl.us/' .$query_result->keyword. '"  title="' . $query_result->title . ' ( ' . $query_result->clicks . ') "><img src="' .$url. '" width="20%" height="20%" alt="" /></a>';
}
}
echo '<h3><b> This Months Top Pics:</b></h3><br/> ' . $urlt5 . "<br><br>\n\r";
?>
<?php
//THIS YEAR
$urlt5 = '';
// This year
$sqlyear = "SELECT title, timestamp, url, keyword, clicks FROM `url` WHERE url like '%jpg%' OR url like '%.gif%' OR url like '%.png%' ";
$sqlyear .= "order by clicks desc limit 5";
$query = $ydb->get_results($sqlyear);
if ($query) {
$i = 0;
foreach( $query as $query_result ) {
$i++;
$thisURLArray = parse_url(stripslashes($query_result->url));
$url = $query_result->url;
$urlt5 .= '<a href="http://gkurl.us/' .$query_result->keyword. '"  title="' . $query_result->title . ' ( ' . $query_result->clicks . ') "><img src="' .$url. '" width="20%" height="20%" alt="" /></a>';
}
}
echo '<h3><b> All Time Top Pics:</b></h3><br/> ' . $urlt5 . "<br><br>\n\r";
?>

More Coming Soon
As I make more mods and pages, I’ll add them here.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
Stop SOPA