Skip to content

Instantly share code, notes, and snippets.

@kurnias
Created December 4, 2012 03:15
Show Gist options
  • Save kurnias/4200211 to your computer and use it in GitHub Desktop.
Save kurnias/4200211 to your computer and use it in GitHub Desktop.
Simple YOURLS frontend
// 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