Skip to content

Commit

Permalink
Better stats & misc changes from mattwiebe
Browse files Browse the repository at this point in the history
Closes #9
  • Loading branch information
alanhogan committed Apr 8, 2012
1 parent c7e4296 commit 4fec960
Show file tree
Hide file tree
Showing 34 changed files with 431 additions and 80 deletions.
Empty file modified -/banned_words.php 100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions -/config.php
Expand Up @@ -18,6 +18,8 @@
define('COOKIE_SALT', '1a5al-sSXqO[]P83Rfoo'); define('COOKIE_SALT', '1a5al-sSXqO[]P83Rfoo');
define('API_SALT', 'XqO)-O4K2595JMEOQ'); define('API_SALT', 'XqO)-O4K2595JMEOQ');


// Your timezone. Because your server isn't necessarily on your time
// define('TIMEZONE', 'America/Winnipeg');


// How should short URL slugs be generated? // How should short URL slugs be generated?
// 'base36' - Used by the original Lessn. [0-9a-z] // 'base36' - Used by the original Lessn. [0-9a-z]
Expand Down
Empty file modified -/css/admin.css 100644 → 100755
Empty file.
144 changes: 144 additions & 0 deletions -/css/lessn.css
@@ -0,0 +1,144 @@
body {
font: 16px/1.4 'Helvetica Neue', Arial, Helvetica, sans-serif;
margin: 32px 24px;
padding: 0;
color: #333;
background-color: #eee;
}
#wrap {
text-align:center;
}
#stats #wrap {
margin:0 auto;
min-width:600px;
max-width:800px;
text-align:left;
}
p {
margin:1em 0;
}
a,button {
display: inline-block;
border: none;
font-family: inherit;
font-weight: inherit;
font-size: 10px;
line-height: 16px;
height: 16px;
padding: 0 8px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
cursor: pointer;
text-align: left;
text-decoration: none;
text-transform: uppercase;
letter-spacing: 1px;
vertical-align: middle;
color: #fff;
background-color: #333;
}
input {
font-family: inherit;
font-size: inherit;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
border: none;
padding: 4px;
}
#add span {
display: block;
margin: 16px 0 0;
font-size: 9px;
color: #999;
}
span code {
font-size: 10px;
}
#stats #wrap > p:first-child a {
margin-right:9px;
}
#stats #wrap > p:first-child {
margin:1em 0 2em;
}
#tables {
margin:3px 0 0;
}
table {
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
border:1px solid #444;
font-size:14px;
width:100%;
}
th:first-child {
-moz-border-radius:3px 0 0 0;
-webkit-border-top-left-radius:3px;
border-radius:3px 0 0 0;
}
th:last-child {
-moz-border-radius:0 3px 0 0;
-webkit-border-top-right-radius:3px;
border-radius:0 3px 0 0;
}

th,td {
padding:3px 9px;
vertical-align:top;
}
td span {
opacity:.6;
}
tr:hover td span {
opacity:.9;
}
th {
text-align:left;
text-transform:uppercase;
letter-spacing:1px;
background-color:#444;
color:#fff;
font-weight:normal;
padding-bottom:6px;
}

tr:nth-child(2n+2) {
background-color:#ddd;
}

tr:hover {
background-color:#ccc;
color:#000;
}
td:last-child {
text-align:right;
}
h2 {
font-size:21px;
line-height:1;
margin-top:2em;
}
.clicky h2 {
display:inline-block;
margin:0 .5em .5em 0;
cursor:pointer;
}
h2.active {
border-bottom:3px solid #444;
position:relative;
}
h2.active:after {
content:" ";
display:block;
border:5px solid transparent;
border-top-color:#444;
position:absolute;
bottom:-13px;
left:45%;
}




31 changes: 26 additions & 5 deletions -/db.php 100644 → 100755
Expand Up @@ -4,8 +4,29 @@
//error_reporting(1); //error_reporting(1);


// connect // connect
if(DB_DRIVER == 'sqlite') try {
$db = new PDO(DB_DRIVER.':'.DB_NAME); if ( DB_DRIVER == 'sqlite' ) {
else $db = new PDO( DB_DRIVER.':'.DB_NAME );
$db = new PDO(DB_DRIVER.':host='.DB_SERVER.';dbname='.DB_NAME, DB_USERNAME, DB_PASSWORD); }
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); else {
$db = new PDO ( DB_DRIVER.':host='.DB_SERVER.';dbname='.DB_NAME, DB_USERNAME, DB_PASSWORD );
}

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exception $e) {
header( 'HTTP/1.1 503 Service Temporarily Unavailable' );
if ( defined('DISPLAY_ERRORS') && DISPLAY_ERRORS ) {
echo '<h1>PDO connection failed:</h1>';
echo '<pre>';
echo $e->getMessage();
print_r( $e );
echo '</pre>';
}
else {
echo '<h1>Service Currently Unavailable</h1>';
echo '<p><i>Could not connect to the database</i></p>';
}
die();
}

9 changes: 7 additions & 2 deletions -/index.php 100644 → 100755
Expand Up @@ -31,6 +31,7 @@


define('BCURLS_DOMAIN', preg_replace('#^www\.#', '', $_SERVER['SERVER_NAME'])); define('BCURLS_DOMAIN', preg_replace('#^www\.#', '', $_SERVER['SERVER_NAME']));
define('BCURLS_URL', str_replace('-/index.php', '', 'http://'.BCURLS_DOMAIN.$_SERVER['PHP_SELF'])); define('BCURLS_URL', str_replace('-/index.php', '', 'http://'.BCURLS_DOMAIN.$_SERVER['PHP_SELF']));
define('BCURLS_PATH', realpath('.') );


//don't reveal db prefix over HTTP. 16 chars is more than enough to avoid collisions //don't reveal db prefix over HTTP. 16 chars is more than enough to avoid collisions
define('COOKIE_NAME', substr(md5(DB_PREFIX.COOKIE_SALT), 4, 16).'auth'); define('COOKIE_NAME', substr(md5(DB_PREFIX.COOKIE_SALT), 4, 16).'auth');
Expand Down Expand Up @@ -527,11 +528,11 @@ function bc_log($message){


if (isset($_GET['tweet'])) if (isset($_GET['tweet']))
{ {
$_GET['redirect'] = 'http://twitter.com/?status=%l'; $_GET['redirect'] = 'https://twitter.com/?status=%l';
} }
if (isset($_GET['redirect'])) if (isset($_GET['redirect']))
{ {
header('Location:'.str_replace('%l', urlencode($new_url), $_GET['redirect'])); header('Location: '.str_replace('%l', urlencode($new_url), $_GET['redirect']));
exit(); exit();
} }
if (isset($_GET['api'])) if (isset($_GET['api']))
Expand All @@ -546,6 +547,10 @@ function bc_log($message){
{ {
$top_urls = stats_top_urls($db); $top_urls = stats_top_urls($db);
$top_referers = stats_top_referers($db); $top_referers = stats_top_referers($db);
$todays_urls = stats_todays_stats($db);
$weeks_urls = stats_thisweeks_stats($db);
$number_lessnd = stats_total_lessnd($db);
$number_redirected = stats_total_redirects($db);
include('pages/stats.php'); include('pages/stats.php');
} }
elseif(isset($_GET['mark_gone']) && isset($_GET['slug']) && strlen(trim($_GET['slug']))) elseif(isset($_GET['mark_gone']) && isset($_GET['slug']) && strlen(trim($_GET['slug'])))
Expand Down
16 changes: 16 additions & 0 deletions -/js/jquery-1.5.min.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions -/js/jquery-bbq.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions -/js/lessn.js
@@ -0,0 +1,68 @@
jQuery(document).ready(function($) {

var activeClass = "active",
transition = 00;

function init() {
var div = $("<div id='tables'></div>");
div.appendTo("#wrap");

$("h2").each(function(index) {
var self = $(this),
table = self.next("table"),
id = table.attr("id");

self.attr('data-target', id).click(showTable);;
table.attr({id: id}).hide().appendTo(div);
});

$(document).keydown(function(e){
if ( e.keyCode == 37 || e.keyCode == 39) {
var active = $("h2." + activeClass),
left = (e.keyCode == 37),
dir = ( left ) ? 'prev' : 'next',
end = ( left ) ? 'last' : 'first',
target = active[dir]("h2");
if ( ! target.size() ) {
target = $("h2:" + end);
}
target.click();
return false;
}
});

$("body").addClass("clicky");

$(window).bind( 'hashchange', goToHash).trigger('hashchange');
}
if ( $("body").attr("id") === "stats" ) {
init();
}

function goToHash() {
var hash = location.hash,
table = $(hash),
id = hash.replace('#', ''),
h2 = $("h2[data-target="+id+"]");

// if nothing, default to clicking on first h2
if ( ! table.size() ) {
$("h2:first").click();
return false;
}

$("#tables table").hide();
table.fadeIn(transition);

$("h2").removeClass(activeClass);
h2.addClass(activeClass);
}

function showTable(event) {
var self = $(this),
hash = "#" + self.attr("data-target");
$.bbq.pushState(hash);
}


});
13 changes: 13 additions & 0 deletions -/js/loader.php
@@ -0,0 +1,13 @@
<?php
$offset = 60 * 60 * 24 * 30; // 30 days of caching
$expiry = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";

header( 'Content-Type: text/javascript' );
header( 'Cache-Control: public, must-revalidate' );
header( 'Expires: ' . $expiry );
header( 'Content-Encoding: gzip' );

ob_start('ob_gzhandler');
include( 'jquery-1.5.min.js' );
include( 'jquery-bbq.min.js' );
ob_end_flush();
Empty file modified -/library/BaseIntEncoder.php 100644 → 100755
Empty file.
Empty file modified -/library/Migration.php 100644 → 100755
Empty file.
Empty file modified -/library/Migrator.php 100644 → 100755
Empty file.
Empty file modified -/library/QueryTools.php 100644 → 100755
Empty file.
Empty file modified -/migrations/001_createurlstable.php 100644 → 100755
Empty file.
Empty file modified -/migrations/002_createstatstable.php 100644 → 100755
Empty file.
Empty file modified -/migrations/003_addcustomurl.php 100644 → 100755
Empty file.
Empty file modified -/migrations/004_onlyexplicitslugs.php 100644 → 100755
Empty file.
Empty file modified -/migrations/005_create_autoslug_table.php 100644 → 100755
Empty file.
Empty file modified -/migrations/999_test_rollback.php.off 100644 → 100755
Empty file.
14 changes: 13 additions & 1 deletion -/pages/add.php 100644 → 100755
Expand Up @@ -24,12 +24,24 @@
onclick="alert('Drag this bookmarklet onto your browser bar.');return false;"> onclick="alert('Drag this bookmarklet onto your browser bar.');return false;">
Tweetn Tweetn
</a> bookmarklet. </a> bookmarklet.
</p>
<p>Or, non-prompted <a
title="Shrink a link"
href="javascript:location.href='<?php echo BCURLS_URL; ?>-/?url='+encodeURIComponent(location.href)"
onclick="alert('Drag this bookmarklet onto your browser bar.');return false;">
Lessn
</a> / <a
title="Shrink and tweet the shortened link"
href="javascript:location.href='<?php echo BCURLS_URL; ?>-/?tweet&amp;url='+encodeURIComponent(location.href)"
onclick="alert('Drag this bookmarklet onto your browser bar.');return false;">
Tweetn
</a>.
<span>API key: <code><?php echo API_KEY; ?></code></span> <span>API key: <code><?php echo API_KEY; ?></code></span>
</p> </p>
</form> </form>


<p> <p>
<a href="?stats=1">URL Stats</a> <a href="?stats">URL Stats</a>
</p> </p>


<?php if(isset($bc_log) && strlen($bc_log)) : ?> <?php if(isset($bc_log) && strlen($bc_log)) : ?>
Expand Down
3 changes: 2 additions & 1 deletion -/pages/done.php 100644 → 100755
Expand Up @@ -10,7 +10,7 @@
<strong><?php echo htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); ?></strong> <strong><?php echo htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); ?></strong>
</p> </p>
<p> <p>
<a href="http://twitter.com/?status=<?php echo urlencode($new_url); ?>">Tweet</a> <a href="https://twitter.com/?status=<?php echo urlencode(' '.$new_url); ?>">Tweet</a>
</p> </p>


<?php if(isset($bc_log) && strlen($bc_log)) : ?> <?php if(isset($bc_log) && strlen($bc_log)) : ?>
Expand All @@ -21,4 +21,5 @@
input.focus(); input.focus();
input.select(); input.select();
</script> </script>

<?php include('stubs/footer.php'); ?> <?php include('stubs/footer.php'); ?>
Empty file modified -/pages/error.php 100644 → 100755
Empty file.
Empty file modified -/pages/login.php 100644 → 100755
Empty file.

0 comments on commit 4fec960

Please sign in to comment.