]> git.quilime.com - clmpr.git/commitdiff
clmpr is operational
authorGabriel Dunne <gdunne@quilime.com>
Wed, 16 Mar 2011 08:44:08 +0000 (01:44 -0700)
committerGabriel Dunne <gdunne@quilime.com>
Wed, 16 Mar 2011 08:44:08 +0000 (01:44 -0700)
README [new file with mode: 0644]
clmp.js [new file with mode: 0644]
data.php [new file with mode: 0644]
get.php [new file with mode: 0644]
index.php [new file with mode: 0644]
init.php [new file with mode: 0644]
put.php [new file with mode: 0644]
signin.php [new file with mode: 0644]
signup.php [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/clmp.js b/clmp.js
new file mode 100644 (file)
index 0000000..7841eb6
--- /dev/null
+++ b/clmp.js
@@ -0,0 +1,52 @@
+// clmp.js
+(function()
+{
+    var l = 0; $(window).width() / 2;
+    var t = 0; $(window).height() / 2;
+
+    var c = $([
+        '<div style="font-family:monospace !important;font-size:11px !important;background:#fff;border:5px solid #000;color:#000;padding:30px;position:fixed;left:' +  l + 'px;top:' + t + 'px">'
+    ,   '<form id="clmpr">'
+    ,   'title: <input name="title" value="' + $('title').text() + '" /><br/>'
+    ,   'desc: &nbsp;<textarea name="desc"></textarea><br/>'
+    ,   'tags: &nbsp;<input name="tags" /><br/><br/>'
+    ,   '<input name="submit" type="button" value="save">'
+    ,   '</form>'
+    ,   '</div>'
+    ].join(''));
+
+    $('body').append(c);
+
+    // the following is on click
+        var params = {
+            'title': "test",
+            'referer': location.href,
+            'tags': "tags",
+            'desc': "desc"
+        };
+        var urlb = [];
+        urlb.push('http://clmpr.com/save.php');
+        urlb.push('?');
+        for (var n in params) {
+            urlb.push(encodeURIComponent(n));
+            urlb.push('=');
+            urlb.push(encodeURIComponent(params[n]));
+            urlb.push('&');
+        }
+        // this method does a popup blocker
+        if (true) {
+            window.open(urlb.join(''),
+                    'saved ' + new Date().getTime(),
+                    'status=no,resizable=no,scrollbars=no,personalbar=no,directories=no,location=no,toolbar=no,menubar=no,' +
+                    'width=300,height=50,left=0,top=0');
+        }
+
+}
+)();
+
+/*
+
+javascript:var i,s,ss=['http://kathack.com/js/kh.js','http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'];for(i=0;i!=ss.length;i++){s=document.createElement('script');s.src=ss[i];document.body.appendChild(s);}void(0);
+javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://ffffound.com/bookmarklet.js');document.body.appendChild(e)})());
+
+*/
\ No newline at end of file
diff --git a/data.php b/data.php
new file mode 100644 (file)
index 0000000..f95c57c
--- /dev/null
+++ b/data.php
@@ -0,0 +1,31 @@
+<?php
+
+    function get_db_connection()
+    {
+        try {
+                return $dbh = new PDO(DB_DSN, DB_UNAME, DB_PW);
+        }
+        catch(PDOException $e) {
+                return $e->getMessage();
+        }
+    }
+
+    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();
+            }
+        }
+        return false;
+    }
\ No newline at end of file
diff --git a/get.php b/get.php
new file mode 100644 (file)
index 0000000..d132e30
--- /dev/null
+++ b/get.php
@@ -0,0 +1,36 @@
+<?php
+
+    include '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->execute( array( $user['id'] ));
+            }
+
+        } else
+        {
+            $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();
+    }
+
+
+    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 />';
+    }
diff --git a/index.php b/index.php
new file mode 100644 (file)
index 0000000..fbc682d
--- /dev/null
+++ b/index.php
@@ -0,0 +1,38 @@
+<?php
+    require_once 'init.php';
+?>
+<!DOCTYPE html>
+<head>
+
+<title>clmpr</title>
+
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+
+</head>
+
+<body>
+
+<b>C</b>itation, <b>L</b>ogging and <b>M</b>ulti-<b>P</b>urpose a<b>R</b>chive
+
+<?php include 'signin.php'; ?>
+
+<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
diff --git a/init.php b/init.php
new file mode 100644 (file)
index 0000000..a257800
--- /dev/null
+++ b/init.php
@@ -0,0 +1,22 @@
+<?php
+
+    session_start();
+
+    # timezone
+    putenv('TZ=America/Los_Angeles');
+
+    # include folders
+    ini_set('include_path', dirname(realpath(__FILE__)));
+    define('TMP_DIR', dirname(realpath(__FILE__)) .'/../tmp');
+
+    # database
+    define('DB_DSN',    "mysql:host=<mysql.hostname.com>;dbname=<dbnam>");
+    define('DB_UNAME',  "<user>");
+    define('DB_PW',     "<pass>");
+
+
+    ini_set('display_errors', 1);
+    error_reporting( E_ALL );
+
+
+    include 'data.php';
diff --git a/put.php b/put.php
new file mode 100644 (file)
index 0000000..b39ddc1
--- /dev/null
+++ b/put.php
@@ -0,0 +1,35 @@
+<?php
+
+    include 'init.php';
+
+    $params = array();
+    $params['title'] = isset($_GET['title']) ? $_GET['title'] : null;
+    $params['location']  = isset($_GET['location'])  ? $_GET['location']  : null;
+
+    try {
+
+        $dbh = get_db_connection();
+        $dbh->beginTransaction();
+
+        if ($user = get_user()) {
+
+            $user['user'];
+
+            $sql = "INSERT INTO `clmpr`.`clumps` ( `user_id`, `title` , `location` , `date` )
+                    VALUES ( ?, ?, ?, NOW() ) ";
+            $q = $dbh->prepare($sql);
+            $count = $q->execute( array( $user['id'], $params['title'],$params['location'] ));
+
+            $dbh = null;
+
+            echo "clumped.<br/><br/>";
+            echo '<a href="javascript:window.close();">ok</a>';
+        }
+        exit;
+    }
+    catch(PDOException $e)
+    {
+        echo $e->getMessage();
+    }
+
+    exit;
\ No newline at end of file
diff --git a/signin.php b/signin.php
new file mode 100644 (file)
index 0000000..c2bd50a
--- /dev/null
@@ -0,0 +1,123 @@
+<?php
+
+    require_once 'init.php';
+
+    $params = array();
+    $params['user'] = isset($_POST['user']) ? $_POST['user'] : null;
+    $params['pass'] = isset($_POST['pass']) ? $_POST['pass'] : null;
+    $params['logout'] = isset($_POST['logout']) ? true : false;
+
+    try {
+
+        if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
+
+            if ( $params['logout'] ) {
+                $_SESSION['user'] = null;
+                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']));
+            } 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() ));
+    }
+
+?>
+<script>
+
+    function register()
+    {
+        var user = $('#nuser').val();
+        var pass = $('#npass').val();
+        $('#register').text("creating user...");
+        $.post('signup.php', { user : user, pass : pass }, function(result) {
+            $('#register').html(result.mssg);
+        }, 'json');
+        return false;
+    }
+
+
+    $('#signin_form').submit(function() {
+      alert('Handler for .submit() called.');
+      return false;
+    });
+    function onSignIn()
+    {
+        var user = $('#user').val();
+        var pass = $('#pass').val();
+        $('#signin').text("signing in...");
+        $.post('signin.php', { user : user, pass : pass }, function(result) {
+            $('#signin').html(result.mssg);
+        }, 'json');
+    }
+
+
+    function onLogout()
+    {
+        $.post('signin.php', { logout : 1 }, 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/>
+        <a href="#" onClick="return onLogout();">logout</a>
+
+    <? } else { ?>
+
+        sign in
+        <form id="signin_form" action="javascript:onSignIn();" style="display:inline-block;">
+            <input type="text" id="user" name="u">&nbsp;&nbsp;
+            <input type="password" id="pass" name="p">
+            <input type="submit" value="sign in" />
+        </form>
+
+    <? } ?>
+    </div>
+
+    <br/>
+    <br/>
+
+    <a id="register_link" href="#" onClick="$('#register').toggle(); return false;">register</a>
+
+    <div id="register" style="display:none;">
+        <form>
+            <input id="nuser" type="text" value="user" onFocus="this.select();">
+            <input id="npass" type="password" value="pass" onFocus="this.select();">
+            <input type="submit" value="register" onClick="return register();">
+        </form>
+    </div>
+
+</p>
diff --git a/signup.php b/signup.php
new file mode 100644 (file)
index 0000000..3beb5ea
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+    require_once 'init.php';
+
+    $params = array();
+    $params['user'] = isset($_POST['user']) ? $_POST['user'] : null;
+    $params['pass'] = isset($_POST['pass']) ? $_POST['pass'] : null;
+
+    try {
+
+        if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
+
+            $dbh = get_db_connection();
+            $dbh->beginTransaction();
+
+            $sql = "INSERT INTO `clmpr`.`users` ( `user` , `pass` , `created` )
+                    VALUES ( :user, PASSWORD(:pass), NOW() ) ";
+            $q = $dbh->prepare($sql);
+            $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>' ));
+            } else {
+                echo json_encode(array('exists' => true, 'mssg' => 'user already exists' ));
+            }
+
+            $dbh = null;
+
+
+        }
+
+    }
+    catch(PDOException $e)
+    {
+        echo json_encode(array('success' => true, 'mssg' => $e->getMessage() ));
+    }
+
+    exit;
\ No newline at end of file