Permalink
Browse files

Better stats & misc changes from mattwiebe

Closes #9
  • Loading branch information...
alanhogan committed Apr 8, 2012
1 parent c7e4296 commit 4fec960dced59d083e6ba8bf486f2aa06c9aed56
View
0 -/banned_words.php 100644 → 100755
No changes.
View
@@ -18,6 +18,8 @@
define('COOKIE_SALT', '1a5al-sSXqO[]P83Rfoo');
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?
// 'base36' - Used by the original Lessn. [0-9a-z]
View
0 -/css/admin.css 100644 → 100755
No changes.
View
@@ -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%;
+}
+
+
+
+
View
31 -/db.php 100644 → 100755
@@ -4,8 +4,29 @@
//error_reporting(1);
// connect
-if(DB_DRIVER == 'sqlite')
- $db = new PDO(DB_DRIVER.':'.DB_NAME);
-else
- $db = new PDO(DB_DRIVER.':host='.DB_SERVER.';dbname='.DB_NAME, DB_USERNAME, DB_PASSWORD);
-$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+try {
+ if ( DB_DRIVER == 'sqlite' ) {
+ $db = new PDO( DB_DRIVER.':'.DB_NAME );
+ }
+ 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();
+}
+
View
9 -/index.php 100644 → 100755
@@ -31,6 +31,7 @@
define('BCURLS_DOMAIN', preg_replace('#^www\.#', '', $_SERVER['SERVER_NAME']));
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
define('COOKIE_NAME', substr(md5(DB_PREFIX.COOKIE_SALT), 4, 16).'auth');
@@ -527,11 +528,11 @@ function bc_log($message){
if (isset($_GET['tweet']))
{
- $_GET['redirect'] = 'http://twitter.com/?status=%l';
+ $_GET['redirect'] = 'https://twitter.com/?status=%l';
}
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();
}
if (isset($_GET['api']))
@@ -546,6 +547,10 @@ function bc_log($message){
{
$top_urls = stats_top_urls($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');
}
elseif(isset($_GET['mark_gone']) && isset($_GET['slug']) && strlen(trim($_GET['slug'])))
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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);
+ }
+
+
+});
View
@@ -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();
View
0 -/library/BaseIntEncoder.php 100644 → 100755
No changes.
View
0 -/library/Migration.php 100644 → 100755
No changes.
View
0 -/library/Migrator.php 100644 → 100755
No changes.
View
0 -/library/QueryTools.php 100644 → 100755
No changes.
View
No changes.
View
No changes.
View
0 -/migrations/003_addcustomurl.php 100644 → 100755
No changes.
View
No changes.
View
No changes.
View
No changes.
View
14 -/pages/add.php 100644 → 100755
@@ -24,12 +24,24 @@
onclick="alert('Drag this bookmarklet onto your browser bar.');return false;">
Tweetn
</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>
</p>
</form>
<p>
- <a href="?stats=1">URL Stats</a>
+ <a href="?stats">URL Stats</a>
</p>
<?php if(isset($bc_log) && strlen($bc_log)) : ?>
View
3 -/pages/done.php 100644 → 100755
@@ -10,7 +10,7 @@
→ <strong><?php echo htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); ?></strong>
</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>
<?php if(isset($bc_log) && strlen($bc_log)) : ?>
@@ -21,4 +21,5 @@
input.focus();
input.select();
</script>
+
<?php include('stubs/footer.php'); ?>
View
0 -/pages/error.php 100644 → 100755
No changes.
View
0 -/pages/login.php 100644 → 100755
No changes.
Oops, something went wrong.

0 comments on commit 4fec960

Please sign in to comment.