Skip to content

Instantly share code, notes, and snippets.

@AmusableLemur
Created August 4, 2012 20:56
Show Gist options
  • Save AmusableLemur/3259874 to your computer and use it in GitHub Desktop.
Save AmusableLemur/3259874 to your computer and use it in GitHub Desktop.
Simple clone of StumbleUpon
<?php
# javascript:window.location = "<LINK TO FILE>?u="+encodeURIComponent(window.location);
require 'rb.php';
function linkExists($url) {
$links = R::findAll('link', '1');
foreach ($links as $link) {
if ($link->url == $url) {
return true;
}
}
return false;
}
R::setup('sqlite:db.txt');
if (isset($_GET['u']) && !linkExists($_GET['u']) && @fopen($_GET['u'], 'r')) {
$link = R::dispense('link');
$link->url = urldecode($_GET['u']);
R::store($link);
echo "Link submitted successfully";
} else {
$links = R::$f->begin()->select('id')->from('link')->get('col');
$link = R::load('link', array_rand($links));
header('Location: ' . $link->url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment