Created
December 4, 2012 03:15
-
-
Save kurnias/4200211 to your computer and use it in GitHub Desktop.
Simple YOURLS frontend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple YOURLS frontend | |
// We use native YOURLS API to do so | |
<?php | |
require_once( dirname(__FILE__).'/includes/load-yourls.php' ); | |
//put here how many entries should be displayed | |
$items = yourls_api_stats( 'last', 20 ); | |
foreach( $items['links'] as $item ) { ?> | |
<?php echo $item['title']; ?><br> | |
<?php | |
$long_code = $item['url']; | |
$long_code = preg_replace("#^http://#" , "", $long_code); | |
$long_code = preg_replace("#^www.#" , "", $long_code); | |
$long_code = preg_replace("#/blog(..)#" ,"/$1", $long_code); | |
$long_code = preg_replace("#/archives#", "...", $long_code); | |
$long_code = preg_replace("#/$#" , "", $long_code); | |
// Truncate long URL by give them elipsis | |
if(strlen($long_code) > 80) { | |
$long_code = substr_replace($long_code, "...", 80 - 3); | |
} | |
?> | |
<a href="<?php echo $item['url']; ?>"><?php echo $long_code; ?></a><br> | |
<a href="<?php echo $item['shorturl']; ?>"><?php echo $item['shorturl']; ?></a> | |
<?php echo date('d-m-Y, H:i', strtotime($item['timestamp']) ); ?><br><br> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment