]> git.quilime.com - clmpr.git/commitdiff
Updated tagging system
authorGabriel Dunne <gdunne@quilime.com>
Sun, 18 Dec 2011 10:39:46 +0000 (02:39 -0800)
committerGabriel Dunne <gdunne@quilime.com>
Sun, 18 Dec 2011 10:39:46 +0000 (02:39 -0800)
13 files changed:
TODO
bookmarklet.js
clmpr.sql
footer.html [new file with mode: 0644]
get.php
head.html
header.html [new file with mode: 0644]
index.php
new.php [new file with mode: 0644]
put.php
script.js [new file with mode: 0644]
style.css
tags.php [new file with mode: 0644]

diff --git a/TODO b/TODO
index 1026d9a0e9ecc153d2cd037c17676500f9315cbe..135f3329bb4afb4c0f37fab69697957a4ab45d35 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1 +1,10 @@
-- create server variable for bookmarklet
+create server variable for bookmarklet
+evaluate MVC architecture w/ template system
+add description field
+
+tags:
+       delimit tags with commas in db (?)
+       need UNIQUE field in tags
+       increment tag count on insert
+       decrement tag count on delete 
+               if zero delete row
\ No newline at end of file
index 290d99abbdaddbb2890d39613ac73a9f93ddf7d0..ff9b7de97b75941088f22a27a58cd1f80ca0bcdb 100644 (file)
@@ -4,7 +4,7 @@
     b = document,
     c = encodeURIComponent,
     d = w.open(
-        'http://clmpr/put.php?'
+        'http://clmpr/new.php?'
         + 'url='  + c(b.location)
         + '&title=' + c(b.title)
     ,   'clmpr_popup'
@@ -15,4 +15,4 @@
         d.focus()
     } , 300)
 }
-)();
\ No newline at end of file
+)();
index afecfa667eedadf59ca95c10287648b3b9fe9a82..4fd7446a2d274a459fef9162f01a5c9dea91234e 100644 (file)
--- a/clmpr.sql
+++ b/clmpr.sql
@@ -9,11 +9,11 @@ CREATE TABLE IF NOT EXISTS `clumps` (
   `id` int(9) NOT NULL AUTO_INCREMENT,
   `user_id` int(9) NOT NULL,
   `title` varchar(255) NOT NULL,
-  `url` varchar(255) NOT NULL,
-  `tags` varchar(255) NOT NULL,
+  `url` varchar(255) NOT NULL DEFAULT '',
+  `tags` text NOT NULL,
   `date` datetime NOT NULL,
   PRIMARY KEY (`id`)
-) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=239 ;
+) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 
 
 -- Table structure for table `users`
@@ -25,4 +25,6 @@ CREATE TABLE IF NOT EXISTS `users` (
   `created` datetime NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `user` (`user`)
-) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+
+
diff --git a/footer.html b/footer.html
new file mode 100644 (file)
index 0000000..6782d80
--- /dev/null
@@ -0,0 +1,7 @@
+<div id="footer">
+<p>
+      <a class="about" href="/about">about</a> | <a href="https://github.com/quilime/clmpr">source on github</a>
+</p>
+</div>
+
+<script src="/script.js" language="javascript"></script>
diff --git a/get.php b/get.php
index 1836133513ea09c33e19f4231e0c5b0a79856b98..d14dea182f3e32571a087b7ff1dc75fe819fc310 100644 (file)
--- a/get.php
+++ b/get.php
@@ -49,7 +49,7 @@ case 'xml' :
 <script>
 
     function deleteClump( id, elem ) {
-        if (confirm("delete clump?")) {
+        if (confirm("confirm delete")) {
             $.post('delete.php', { clump_id : id }, function(result) {
                 $(elem).hide();
             }, 'json');
@@ -60,7 +60,17 @@ case 'xml' :
 </script>
 
 <ul class="links">
-<?php for($i = 0; $row = $q->fetch(); $i++ ): ?>
+<?php for($i = 0; $row = $q->fetch(); $i++ ): 
+
+
+    # process tags
+    if ($row['tags'] == '')
+        $row['tags'] = array();
+    else
+        $row['tags'] = explode(" ", $row['tags']);
+
+
+?>
     
     <li>
         <span class="url">
@@ -68,18 +78,17 @@ case 'xml' :
             <?php echo $row['title'] ? $row['title'] : "&lt;title&gt;" ?>
         </a>
         </span>
-
         <span class="meta">
-
-        <span>
             <?php echo date("Y-m-d", strtotime($row['date'])) ?> by 
             <a class="uname" href="/?user=<?php echo $row['user'] ?>"><?php echo $row['user'] ?></a>
         </span>
-    
+        
+        <ul class="tags">
 
-        <span class="tags">
-        <?php echo $row['tags'] ?>
-        </span>
+        <?php foreach($row['tags'] as $tag) : ?>
+        <li><a href="/tags.php?tag=<?=$tag?>"><?=$tag?></a></li>
+        <? endforeach; ?>
+        </ul>
 
         <?php if ($user = get_user()):
                 if ($user['user'] == $row['user']): ?>
@@ -88,7 +97,6 @@ case 'xml' :
                 <a href="#" title="Delete" onClick="return deleteClump(<?php echo $row['clump_id']; ?>, this.parentNode);" class="delete">&times;</a>
         <?php   endif;
         endif; ?>
-        </span>
 
     </li>
 
index 5c06012aa9ca3ed93c7202a34998cd263d76013b..557f7f1b9efd42d413e3a321a89cf7a47bde0c45 100644 (file)
--- a/head.html
+++ b/head.html
@@ -1,4 +1,4 @@
 
 <script src="/jquery-1.3.2.min.js" language="javascript"></script>
 <link href="/style.css" rel="styleSheet" type="text/css" media="screen" />
-<link rel="shortcut icon" type="image/x-icon"  href="/favicon.ico" /> 
\ No newline at end of file
+<link rel="shortcut icon" type="image/x-icon"  href="/favicon.ico" /> 
diff --git a/header.html b/header.html
new file mode 100644 (file)
index 0000000..801d18c
--- /dev/null
@@ -0,0 +1,3 @@
+<div class="header"><a href="/"><b>c</b>itation, <b>l</b>ogging and <b>m</b>ulti-<b>p</b>urpose a<b>r</b>chive</div></a>
+
+<?php include 'signin.php'; ?>
index dd3428f96eb8f7b0b5ca3ad2d2e0acaa4028b27b..3d8fe14c336296fb313fe6cb229cdf8adb06867e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -15,9 +15,11 @@ switch($endpoint)
 {
     case 'about' :
         include 'head.html';
-        echo "clmpr is a place to save hyperlinks";
-        echo '<br /><a href="https://github.com/quilime/clmpr">source on github</a>';
-        echo '<br />&copy; 2011 <a href="http://quilime.com">quilime</a>';
+        include 'header.html';
+        echo '<hr />';
+        echo '&copy; 2011 <a href="http://quilime.com">gabriel dunne</a>';
+        echo '<hr />';
+        include 'footer.html';
         exit;
 
     default :
@@ -51,12 +53,9 @@ switch ($format) {
 <?php include 'head.html'; ?>
 
 </head>
-
 <body>
 
-<div class="header"><b>c</b>itation, <b>l</b>ogging and <b>m</b>ulti-<b>p</b>urpose a<b>r</b>chive</div>
-
-<?php include 'signin.php'; ?>
+<?php include 'header.html'; ?>
 
 <p>
 bookmarklet:
@@ -66,11 +65,11 @@ bookmarklet:
 <a href="javascript:<?=$js?>">+</a>
 </p>
 
+
 <hr />
 
 <?php include 'get.php'; ?>
 
 <hr />
-<div id="footer">
-      <a class="about" href="/about">about</a> | <a href="https://github.com/quilime/clmpr">source on github</a>
-</div>
+
+<?php include 'footer.html' ?>
diff --git a/new.php b/new.php
new file mode 100644 (file)
index 0000000..5104027
--- /dev/null
+++ b/new.php
@@ -0,0 +1,72 @@
+<?php
+
+include 'init.php';
+
+$params = array();
+$params['title'] = isset($_GET['title']) ? $_GET['title'] : null;
+$params['url']  = isset($_GET['url'])  ? $_GET['url']  : null;
+
+
+try {
+
+       include 'head.html';
+
+    if ($user = get_user()) {
+
+       ?>
+
+       <form method="POST" action="put.php" class="new">
+
+               <label>title</label>
+               <input type="text" name="title" value="<?=htmlentities($params['title'])?>">
+
+               <br /><br />
+
+               <label>url</label>
+               <input type="text" name="url" value="<?=$params['url']?>">              
+
+               <br /><br />
+
+               <label>tags (space delimited)</label>
+               <input type="text" name="tags" value="">                                
+
+               <br /><br /><br />
+
+               <input type="submit" value="save">
+               <a href="javascript:window.close();">cancel</a>
+
+               <br />
+               <br />
+
+       </form>
+
+       <!-- <hr /> -->
+
+       <?php // include 'footer.html'; ?>
+
+       <script>
+
+               window.onload = function() {
+                       document.forms[0].tags.focus();
+               }
+
+               </script>       
+
+
+
+       <?php
+
+    } else {
+
+        include 'signin.php';
+
+    }
+
+
+}
+catch(PDOException $e)
+{
+    echo $e->getMessage();
+}
+
+exit;
diff --git a/put.php b/put.php
index c96cc2c069182effc4e06cd7e4e17a50add29a74..296652fe6b36d2825a5e27dfb9adb5d5afb4dbfe 100644 (file)
--- a/put.php
+++ b/put.php
@@ -3,29 +3,45 @@
 include 'init.php';
 
 $params = array();
-$params['title'] = isset($_GET['title']) ? $_GET['title'] : null;
-$params['url']  = isset($_GET['url'])  ? $_GET['url']  : null;
+$params['title'] = isset($_POST['title']) ? $_POST['title'] : null;
+$params['url']   = isset($_POST['url'])  ? $_POST['url']  : null;
+$params['tags']  = isset($_POST['tags'])  ? $_POST['tags']  : null;
 
-try {
+include 'head.html';
 
-    $dbh = get_db_connection();
-    $dbh->beginTransaction();
+try {
 
     if ($user = get_user()) {
 
-        $sql = "INSERT INTO `clmpr`.`clumps` ( `user_id`, `title` , `url` , `date` )
-                VALUES ( ?, ?, ?, NOW() ) ";
+        $dbh = get_db_connection();
+        $dbh->beginTransaction();
+
+        # insert clump
+        $sql = "INSERT INTO `clmpr`.`clumps` ( `user_id`, `title` , `url` , `tags`, `date` )
+                VALUES ( ?, ?, ?, ?, NOW() ) ";
         $q = $dbh->prepare($sql);
-        $count = $q->execute( array( $user['id'], $params['title'],$params['url'] ));
+        $insert = $q->execute( array( $user['id'], $params['title'], $params['url'], $params['tags'] ));
+
+        # process tags
+        $tags = explode(" ", $params['tags']);
+        if (count($tags) > 0) {
+            foreach($tags as $tag) {
+                $sql = "INSERT INTO `clmpr`.`tags` ( `tag` ) VALUES ( ? ) ";
+                $q = $dbh->prepare($sql);
+                $q->execute( array( $tag ));
+            }
+        }
 
         $dbh = null;
 
         echo "clumped.<br/><br/>";
-        echo '<a href="javascript:window.close();">ok</a>';
+        //echo '<a href="javascript:window.close();">ok</a>';
+        echo '<script>window.close();</script>';
+
+        include 'foot.html';
 
     } else {
 
-        include 'head.html';
         include 'signin.php';
 
     }
diff --git a/script.js b/script.js
new file mode 100644 (file)
index 0000000..0ee8888
--- /dev/null
+++ b/script.js
@@ -0,0 +1,8 @@
+// clmpr js
+(function()
+{
+
+       
+
+}
+)();
\ No newline at end of file
index 39b70a79d11f85641f9563f00b43fb326e9c4a79..a6977eeb5972f626c0b06abc718e3d09beecc08c 100644 (file)
--- a/style.css
+++ b/style.css
@@ -22,7 +22,12 @@ li {
      list-style-type: none;
 }
 
-.header {
+hr {
+    border:0;
+    border-bottom:1px dotted #888;
+}
+
+.header, .header a {
      color: #888888;
 }
 
@@ -40,7 +45,7 @@ li {
 }
 
 ul.links li {
-    margin-bottom:1.2em;
+    margin-bottom:0.75em;
 }
 ul.links li span.url {
     display:block;
@@ -49,16 +54,37 @@ ul.links li span.meta {
     color:#bbb;
 }
 ul.links li span.meta a {
-    color:#bbb;
+    color:#999;
 }
 .delete {
     font-weight:bold;
     padding:0 3px; 
     line-height:1em;
     background:#eee;
+    color:#999;
     text-decoration:none;
 }
 
 .delete:hover {
      text-decoration: none;
 }
+
+form.new input[type="text"] {
+    width:100%;
+}
+label {
+    font-weight:bold;
+}
+
+ul.tags, ul.tags li {
+    display:inline;
+}
+ul.tags li {
+    background:#eee;
+    padding:0 4px;
+    margin:0 1px;
+}
+ul.tags li a {
+    color:#aaa;
+}
+
diff --git a/tags.php b/tags.php
new file mode 100644 (file)
index 0000000..6ac037f
--- /dev/null
+++ b/tags.php
@@ -0,0 +1,65 @@
+<?php
+
+require_once 'init.php';
+
+$params = array();
+$params['tag'] = isset($_GET['tag']) ? $_GET['tag'] : null;
+
+$dbh = get_db_connection();
+$dbh->beginTransaction();
+
+try {
+       /*
+    if ($params['tag']) {
+        $q = $dbh->prepare("SELECT *, tags.id as tag_id 
+                            FROM tags 
+                            WHERE tag = ? 
+                            ORDER BY tag DESC");
+        $q->execute( array( $params['tag'] ));
+    }
+    else {
+       */
+        $q = $dbh->prepare("SELECT * FROM tags 
+                            ORDER BY tag DESC");
+        $q->execute();
+    //}
+
+}
+catch(PDOException $e)
+{
+    echo $e->getMessage();
+    exit;
+}
+
+
+?><!DOCTYPE html>
+
+<head>
+<title>clmpr</title>
+
+<?php include 'head.html'; ?>
+
+</head>
+<body>
+
+<?php include 'header.html'; ?>
+
+
+<p>tags</p>
+<hr />
+
+<ul class="tags">
+<?php for($i = 0; $row = $q->fetch(); $i++ ): 
+?>
+    
+    <li><span class="tag"><a href="<?php echo $row['tag'] ?>"><?php echo $row['tag'] ?></a></span></li>
+
+<?php endfor; ?>
+</ul>
+
+<hr />
+
+<?php include 'footer.html' ?>
+
+
+