]> git.quilime.com - clmpr.git/commitdiff
Style and .htaccess
authorGabriel Dunne <gdunne@quilime.com>
Mon, 18 Apr 2011 01:46:10 +0000 (18:46 -0700)
committerGabriel Dunne <gdunne@quilime.com>
Mon, 18 Apr 2011 01:46:10 +0000 (18:46 -0700)
.htaccess [new file with mode: 0644]
bookmarklet.js [new file with mode: 0644]
data.php
error.php [new file with mode: 0644]
get.php
head.html [new file with mode: 0644]
index.php
put.php
signin.php
signup.php
style.css [new file with mode: 0644]

diff --git a/.htaccess b/.htaccess
new file mode 100644 (file)
index 0000000..d5fd0d3
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,7 @@
+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
diff --git a/bookmarklet.js b/bookmarklet.js
new file mode 100644 (file)
index 0000000..9e15d0c
--- /dev/null
@@ -0,0 +1,18 @@
+(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
index f95c57ca92997e7b2ec379519c3dcf6fcea0629c..c445a27a427acf9361adcf5171c92e760f2600c7 100644 (file)
--- a/data.php
+++ b/data.php
@@ -1,5 +1,6 @@
 <?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
diff --git a/error.php b/error.php
new file mode 100644 (file)
index 0000000..a1c2b1c
--- /dev/null
+++ b/error.php
@@ -0,0 +1,7 @@
+<?php
+
+    $code = isset($_GET['error']) ? $_GET['error'] : '404';
+
+    echo '<br/>' . $code;
+
+    exit;
\ No newline at end of file
diff --git a/get.php b/get.php
index d132e309e47f11fb40634089f6a73f5bd2711e74..01578d7de9b1ad7f06cbf9cbd374b0868ee2c152 100644 (file)
--- a/get.php
+++ b/get.php
@@ -1,36 +1,50 @@
 <?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
diff --git a/head.html b/head.html
new file mode 100644 (file)
index 0000000..174073a
--- /dev/null
+++ b/head.html
@@ -0,0 +1,3 @@
+<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
index fbc682de9dc417afc2d4f09f71c36bdba1c9fcf0..e4c0d05511fea983a88b498126212f5b166eee7f 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,12 +1,49 @@
 <?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>
diff --git a/put.php b/put.php
index b39ddc1c957582931d261a2c8eeccb744f095a55..cb7753d6b6216e1d62635e5d26421d56b8f5ee19 100644 (file)
--- a/put.php
+++ b/put.php
 
             echo "clumped.<br/><br/>";
             echo '<a href="javascript:window.close();">ok</a>';
+
+        } else {
+
+            include 'head.html';
+            include 'signin.php';
+
         }
         exit;
     }
index c2bd50a81afdb324a89ebea6f27cac98e3f045e9..4243dbbe4fe6a9fa4e39b1fce0a5a192846b55c1 100644 (file)
                 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;
         }
@@ -40,7 +37,7 @@
     }
     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()
@@ -68,7 +66,7 @@
         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>
index 3beb5ea2c1760fbd901f778f565df4a676ddc80b..b9eb442d65e66d3226b9a90cf7b5e1e8caaadb55 100644 (file)
             $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;
-
-
         }
 
     }
diff --git a/style.css b/style.css
new file mode 100644 (file)
index 0000000..51baa87
--- /dev/null
+++ b/style.css
@@ -0,0 +1,5 @@
+body {
+    font-family: times; 
+    font-size:14px;
+    line-height:1.3em;
+}
\ No newline at end of file