--- /dev/null
+Options +FollowSymLinks
+RewriteEngine On
+
+# redirect every other request to the index
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule . index.php [L]
\ No newline at end of file
--- /dev/null
+(function()
+{
+ var w = window,
+ b = document,
+ c = encodeURIComponent,
+ d = w.open(
+ 'http://clmpr.com/put.php?'
+ + 'location=' + c(b.location)
+ + '&title=' + c(b.title)
+ , 'clmpr_popup'
+ , 'left=' + (( w.screenX || w.screenLeft ) + 10)
+ + ',top=' + (( w.screenY || w.screenTop) + 10 )
+ + ',height=420px, width=550px, resizable=1, alwaysRaised=1');
+ w.setTimeout(function() {
+ d.focus()
+ } , 300)
+}
+)();
\ No newline at end of file
<?php
+
function get_db_connection()
{
try {
}
}
+
function get_user()
{
return isset($_SESSION['user']) ? $_SESSION['user'] : false;
}
+
function get_users(&$dbh, $args)
{
$user = isset($args['user']) ? $args['user'] : false;
- if ($user) {
- $sql = "SELECT * FROM `clmpr`.`users` WHERE `user` = ?";
- $q = $dbh->prepare($sql);
- $q->execute( array( $user ));
- if ($q->rowCount() == 1) {
- return $q->fetch();
+ try {
+ if ($user) {
+ $sql = "SELECT * FROM users WHERE user = ?";
+ $q = $dbh->prepare($sql);
+ $q->execute( array( $user ));
+ if ($q->rowCount() == 1) {
+ return $q->fetch();
+ }
}
+ throw( new PDOException(sprintf("user %s doesn't exist", $args['user'])));
+ }
+ catch (PDOException $e) {
+ echo $e->getMessage();
}
+
return false;
}
\ No newline at end of file
--- /dev/null
+<?php
+
+ $code = isset($_GET['error']) ? $_GET['error'] : '404';
+
+ echo '<br/>' . $code;
+
+ exit;
\ No newline at end of file
<?php
- include 'init.php';
+ require_once 'init.php';
$params = array();
$params['user'] = isset($_GET['user']) ? $_GET['user'] : null;
+
$dbh = get_db_connection();
$dbh->beginTransaction();
try {
-
if ($params['user']) {
-
$user = get_users($dbh, array('user' => $params['user'] ));
-
if ($user) {
- $q = $dbh->prepare(" SELECT * FROM `clumps` JOIN users ON users.id = clumps.user_id WHERE `user_id` = ? ORDER BY date DESC ");
+ $q = $dbh->prepare(" SELECT * FROM clumps JOIN users ON users.id = clumps.user_id WHERE user_id = ? ORDER BY date DESC ");
$q->execute( array( $user['id'] ));
}
-
- } else
+ else {
+ throw( new PDOException(sprintf("user %s doesn't exist", $params['user'])));
+ }
+ }
+ else
{
- $q = $dbh->prepare("SELECT * FROM `clumps` JOIN users ON users.id = clumps.user_id ORDER BY date DESC");
+ $q = $dbh->prepare("SELECT * FROM clumps JOIN users ON users.id = clumps.user_id ORDER BY date DESC");
$q->execute();
}
}
catch(PDOException $e)
{
echo $e->getMessage();
+ exit;
}
+ include 'head.html';
+ echo '<ul>';
for($i = 0; $row = $q->fetch(); $i++ ) {
- echo $row['date'] . ' - <a href="/get.php?user='.$row['user'].'">' . $row['user'] . '</a>: <a href="' . $row['location'] . '">' . $row['title'] . '</a><br />';
+ echo '<li>';
+ echo sprintf(
+ '%s - <a href="/get.php?user=%s">%s</a> : <a href="%s">%s</a>'
+ , $row['date']
+ , $row['user']
+ , $row['user']
+ , $row['location']
+ , $row['title']);
+ echo $row['tags'] ? '<span class="">' . $row['tags'] . '</span>' : '';
+ echo '</li>';
}
+ echo '</ul>';
\ No newline at end of file
--- /dev/null
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+
+<LINK REL=StyleSheet HREF="/style.css" TYPE="text/css" MEDIA=screen>
\ No newline at end of file
<?php
+
require_once 'init.php';
-?>
-<!DOCTYPE html>
-<head>
+ $dbh = get_db_connection();
+ $dbh->beginTransaction();
+
+ $switch = explode("/", $_SERVER['SCRIPT_URL']);
+
+ switch($section = $switch[1])
+ {
+ case 'get' :
+ include 'get.php';
+ exit;
+
+ case 'put' :
+ exit;
+
+ default :
+ if ($section != '') {
+ $user = get_users($dbh, array( 'user' => $section ));
+ if ( isset($user['user']) ) {
+ $get = function( $user ) {
+ $_GET['user'] = $user;
+ include 'get.php';
+ exit;
+ };
+ $get( $user['user'] );
+ } else {
+ // else 404
+ $_GET['error'] = '404';
+ include 'error.php';
+ exit;
+ }
+ }
+ }
+
+ $dbh = null;
+
+
+?><!DOCTYPE html>
+
+<head>
<title>clmpr</title>
-<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+<?php include 'head.html'; ?>
</head>
<p>
bookmarklet:
-<a href="javascript:(function()
-{
- var w = window,
- b = document,
- c = encodeURIComponent,
- d = w.open(
- 'http://clmpr.com/put.php?'
- + 'location=' + c(b.location)
- + '&title=' + c(b.title)
- , 'clmpr_popup'
- , 'left=' + (( w.screenX || w.screenLeft ) + 10)
- + ',top=' + (( w.screenY || w.screenTop) + 10 )
- + ',height=420px,width=550px,resizable=1,alwaysRaised=1');
- w.setTimeout(function() {
- d.focus()
- } , 300)
-}
-)();">clmpr</a>
\ No newline at end of file
+<?php
+$js = file_get_contents('bookmarklet.js');
+?>
+<br />
+<a href="javascript:<?=$js?>">+</a>
echo "clumped.<br/><br/>";
echo '<a href="javascript:window.close();">ok</a>';
+
+ } else {
+
+ include 'head.html';
+ include 'signin.php';
+
}
exit;
}
echo json_encode(array('mssg' => 'logged out'));
exit;
}
-
$dbh = get_db_connection();
$dbh->beginTransaction();
$sql = "SELECT * FROM `clmpr`.`users` WHERE `user` = ? AND `pass` = PASSWORD(?)";
$q = $dbh->prepare($sql);
$q->execute( array( $params['user'], $params['pass'] ));
-
if ($q->rowCount() == 1) {
$res = $q->fetch();
$_SESSION['user'] = array( 'user' => $res['user'], 'id' => $res['id'] );
- echo json_encode(array('success'=>true, 'mssg' => 'welcome, ' . $params['user']));
+ echo json_encode(array('success'=>true, 'res' => $res));
} else {
$_SESSION['user'] = null;
echo json_encode(array('error'=>true, 'mssg' => 'invalid login'));
}
-
$dbh = null;
exit;
}
}
catch(PDOException $e)
{
- echo json_encode(array('success' => true, 'mssg' => $e->getMessage() ));
+ echo json_encode(array('error' => true, 'mssg' => $e->getMessage() ));
}
?>
var pass = $('#npass').val();
$('#register').text("creating user...");
$.post('signup.php', { user : user, pass : pass }, function(result) {
- $('#register').html(result.mssg);
+ if (result.success = 'true') {
+ window.location.reload();
+ }
}, 'json');
return false;
}
$('#signin_form').submit(function() {
- alert('Handler for .submit() called.');
return false;
});
function onSignIn()
var pass = $('#pass').val();
$('#signin').text("signing in...");
$.post('signin.php', { user : user, pass : pass }, function(result) {
- $('#signin').html(result.mssg);
+ window.location.reload();
}, 'json');
}
return false;
}
-
</script>
<p>
-
-
<div id="signin">
<?php if ($user = get_user()) { ?>
- hi, <?php echo $user['user']; ?><br/>
+ hi, <a href="/<?php echo $user['user']; ?>"><?php echo $user['user']; ?></a>
+ <br/>
<a href="#" onClick="return onLogout();">logout</a>
<? } else { ?>
<? } ?>
</div>
+ <?php if (!$user = get_user()) { ?>
+
<br/>
<br/>
</form>
</div>
+ <?php } ?>
+
</p>
$count = $q->execute( array( ':user' => $params['user'], ':pass' => $params['pass'] ));
if ($count == 1) {
- echo json_encode(array('success' => true, 'mssg' => 'welcome, ' . $params['user'] . '. your password is <b>' . $params['pass'] . '</b>' ));
+ // login newly registered user
+ $sql = "SELECT * FROM `clmpr`.`users` WHERE `user` = ? AND `pass` = PASSWORD(?)";
+ $q = $dbh->prepare($sql);
+ $q->execute( array( $params['user'], $params['pass'] ));
+ if ($q->rowCount() == 1) {
+ $res = $q->fetch();
+ $_SESSION['user'] = array( 'user' => $res['user'], 'id' => $res['id'] );
+ echo json_encode(array('success'=>true, 'res' => $res));
+ } else {
+ $_SESSION['user'] = null;
+ echo json_encode(array('error'=>true, 'mssg' => 'invalid login'));
+ }
} else {
echo json_encode(array('exists' => true, 'mssg' => 'user already exists' ));
}
-
$dbh = null;
-
-
}
}
--- /dev/null
+body {
+ font-family: times;
+ font-size:14px;
+ line-height:1.3em;
+}
\ No newline at end of file