Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Fixed #1

* Support for api and redirect URL arguments thanks to Lessn 1.0.5
* Added new configuration option HOMEPAGE_URL for redirecting somewhere if no short url is given
  • Loading branch information...
commit e5e6053770000b81e79c88731ee6bae7bed9adbc 1 parent 6b04044
@jfro jfro authored
View
4 -/config.php
@@ -17,3 +17,7 @@
define('DB_SERVER', 'localhost');
define('DB_PREFIX', 'bcurls_');
define('COOKIE_SALT', 'B75sS4L7T0R3PEPp3R');
+define('API_SALT', 'B75jk4K25M5U7hTAP1');
+
+// URL to hit if someone visits your site without a short url, set to null for just a blank page
+define('HOMEPAGE_URL', 'http://example.com');
View
35 -/index.php
@@ -4,7 +4,7 @@
include('db.php');
include('stats.php');
-define('BCURLS_VERSION', '1.1');
+define('BCURLS_VERSION', '1.1.1');
define('BCURLS_DOMAIN', preg_replace('#^www\.#', '', $_SERVER['SERVER_NAME']));
define('BCURLS_URL', str_replace('-/index.php', '', 'http://'.BCURLS_DOMAIN.$_SERVER['PHP_SELF']));
@@ -13,6 +13,9 @@
define('COOKIE_VALUE', md5(USERNAME.PASSWORD.COOKIE_SALT));
define('COOKIE_DOMAIN', '.'.BCURLS_DOMAIN);
+if (!defined('API_SALT')) define('API_SALT', 'B75jk4K25M5U7hTAP1'); // added in lessn 1.0.5
+define('API_KEY', md5(USERNAME.PASSWORD.API_SALT));
+
define('NOW', time());
define('YEAR', 365 * 24 * 60 * 60);
@@ -25,6 +28,15 @@
$_COOKIE[COOKIE_NAME] = COOKIE_VALUE;
}
}
+// API login
+else if (isset($_GET['api']) && $_GET['api'] == API_KEY)
+{
+ $_COOKIE[COOKIE_NAME] = COOKIE_VALUE;
+}
+else if (isset($_GET['api'])) // spit out a nicer failure for API attempts
+{
+ exit('Invalid API key');
+}
// handle logout
if (isset($_GET['logout']))
@@ -40,8 +52,8 @@
include('pages/login.php');
exit();
}
-// prolong login for another year
-else
+// prolong login for another year, unless this is an API request
+else if (!isset($_GET['api']))
{
setcookie(COOKIE_NAME, COOKIE_VALUE, NOW + YEAR, '/', COOKIE_DOMAIN);
}
@@ -54,6 +66,11 @@
{
$url = 'http://'.$url;
}
+ if(strpos($url, BCURLS_URL) === 0)
+ {
+ include('pages/error.php');
+ exit;
+ }
$checksum = sprintf('%u', crc32($url));
$escaped_url = $url;
$result = $db->prepare('SELECT id FROM '.DB_PREFIX.'urls WHERE checksum=? AND url=? LIMIT 1');
@@ -86,9 +103,19 @@
if (isset($_GET['tweet']))
{
- header('Location:http://twitter.com/?status='.urlencode($new_url));
+ $_GET['redirect'] = 'http://twitter.com/?status=%l';
+ }
+ if (isset($_GET['redirect']))
+ {
+ header('Location:'.str_replace('%l', urlencode($new_url), $_GET['redirect']));
exit();
}
+ if (isset($_GET['api']))
+ {
+ echo $new_url;
+ exit();
+ }
+
include('pages/done.php');
}
else if(isset($_GET['stats']))
View
8 -/pages/add.php
@@ -5,16 +5,18 @@
<input type="text" name="custom_url" value="" placeholder="custom short url" /> (optional)
<p>Grab the <a
- title="Lessn a link"
+ 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;">
Shrinkn
</a> or <a
- title="Lessn and tweet the Lessn'd link"
+ 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> bookmarklet.</p>
+ </a> bookmarklet.
+ <span>API key: <code><?php echo API_KEY; ?></code></span>
+ </p>
</form>
<p>
View
9 -/pages/error.php
@@ -0,0 +1,9 @@
+<?php include('stubs/header.php'); ?>
+<h1>Error</h1>
+<p>
+ You tried to shorten a URL on this domain which should already be short!
+</p>
+<p>
+ <a href="/-/">Back</a>
+</p>
+<?php include('stubs/footer.php'); ?>
View
11 -/stubs/header.php
@@ -47,6 +47,17 @@
border: none;
padding: 4px;
}
+span
+{
+ display: block;
+ margin: 16px 0 0;
+ font-size: 9px;
+ color: #999;
+}
+span code
+{
+ font-size: 10px;
+}
</style>
</head>
<body>
View
5 CHANGES.txt
@@ -1,3 +1,8 @@
+1.1.1
+- Fix for #1
+- Support for api and redirect URL arguments thanks to Lessn 1.0.5
+- Added new configuration option HOMEPAGE_URL for redirecting somewhere if no short url is given
+
1.1 (butteredurls fork)
- modified query calls to use PDO to allow PostgreSQL/SQLite support
- created an install.php to handle execution of installation queries
View
12 index.php
@@ -35,10 +35,18 @@
}
}
else if($_GET['token'] == '')
- exit('<h1>jfro.me</h1>');
+ {
+ if(defined('HOMEPAGE_URL') && HOMEPAGE_URL)
+ header("Location: ".HOMEPAGE_URL);
+ exit;
+ }
}
else
- exit('<h1>jfro.me</h1>');
+{
+ if(defined('HOMEPAGE_URL') && HOMEPAGE_URL)
+ header("Location: ".HOMEPAGE_URL);
+ exit;
+}
// no redirect
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
Please sign in to comment.
Something went wrong with that request. Please try again.