]> git.quilime.com - clmpr.git/commitdiff
allow spaces in tags
authorGabriel Dunne <gdunne@quilime.com>
Wed, 21 Dec 2011 21:41:55 +0000 (13:41 -0800)
committerGabriel Dunne <gdunne@quilime.com>
Wed, 21 Dec 2011 21:41:55 +0000 (13:41 -0800)
data.php
delete.php
edit.php
get.php
lib/tag-it/js/tag-it.js
new.php
put.php
style.css
update.php

index 3cb5b93ceedeacf50c76fcefeb69a7285535aa51..fb59b3dd75b4a3e35f9531e8917c5fb785e3e3ed 100644 (file)
--- a/data.php
+++ b/data.php
@@ -38,30 +38,3 @@ function get_users(&$dbh, $args)
 
     return false;
 }
-
-
-function filter_tags($tagstr) {
-
-    $tags = array();
-
-    # split on commas if using commas
-    if (strstr($tagstr, ',')) {
-        $tags = explode(",", $tagstr);
-        # replace spaces with dashes
-        $tags = array_map(function ($tag) {
-            $tag = trim($tag);
-            return strpos($tag, " ") ? str_replace(" ", "-", $tag) : $tag;
-        }, $tags);
-    }
-
-    # else, split on spaces
-    else {
-        $tags = explode(" ", $tagstr);
-        $tags = array_map(function ($tag) {
-            return trim($tag);
-        }, $tags);
-    }
-
-    #filter tag dupes
-    return array_unique($tags);
-}
index f37b26f29e545e52ff1ce25caa565f7464da3ea4..05b0449a570a531eef312bca65aeb74a10b98ec7 100644 (file)
@@ -14,17 +14,17 @@ try {
     if ($user && $params['clump_id']) {
 
         # get current clump
-        $q = $dbh->prepare("SELECT * 
+        $q = $dbh->prepare("SELECT *
                             FROM clumps
-                            JOIN users ON users.id = clumps.user_id 
-                            WHERE user_id = ? AND clumps.id = ? 
+                            JOIN users ON users.id = clumps.user_id
+                            WHERE user_id = ? AND clumps.id = ?
                             LIMIT 1");
         $q->execute( array( $user['id'], $params['clump_id'] ));
         $row = $q->fetch();
 
         # decrement tag count in DB
         # note: leaves tags in database with count of '0' if not used
-        $tags = explode(" ", $row['tags']);
+        $tags = explode(",", $row['tags']);
         if (count($tags) > 0) {
             foreach($tags as $key => $tag) {
                 $sql = "UPDATE tags
@@ -33,20 +33,20 @@ try {
                 $q = $dbh->prepare($sql);
                 $q->execute( array( $tag ));
             }
-        }            
+        }
 
         # delete clump
         $sql = "DELETE FROM clumps WHERE id = ? AND user_id = ?";
         $q = $dbh->prepare($sql);
         $count = $q->execute( array( $params['clump_id'], $user['id'] ));
-        echo json_encode(array('deleted' => true));        
+        echo json_encode(array('deleted' => true));
     } else {
         echo json_encode(array('mssg' => 'must be logged in'));
     }
 
     $dbh = null;
-    $q = null;    
-    
+    $q = null;
+
 }
 catch(PDOException $e)
 {
index d7c4a843191df587800683330e4bed1e594bfb59..d4e787c0e8611851366288eced8bd6c30252352b 100644 (file)
--- a/edit.php
+++ b/edit.php
@@ -81,19 +81,25 @@ function deleteClump( id ) {
     <input type="text" name="url" value="<?php echo $clump['url']; ?>">
     </p>
 
-    <p>
-    <label>tags</label>
-    <input type="text" id="tag-input" name="tags" value="<?php echo str_replace(' ', ',', $clump['tags']); ?>">
-    </p>
+
+    <label>tags <a href="#" class="ui tag-help" onClick="$('#tag-help').toggle();return false;">how to tag &raquo;</a></label>
+    <ul id="tag-help" style="display:none">
+        <li><span class="bull">&bull;</span>combine "multiple words" with quotes</li>
+        <li><span class="bull">&bull;</span>separate tags by space, comma, semicolon, or enter</li>
+    </ul>
+    <input type="text" id="tag-input" name="tags" value="<?php echo $clump['tags']; ?>">
+
 
     <p>
     <label>description</label>
-    <input type="text" name="description" value="<?php echo $clump['description']; ?>">
+    <input type="text" name="description" value="<?php echo htmlentities($clump['description']); ?>">
     </p>
 
     <p>
-        saved <?php echo date("Y-m-d", strtotime($clump['date'])) ?> by
-        <a class="uname" href="/?user=<?php echo $clump['user'] ?>"><?php echo $clump['user'] ?></a>
+        <span class="meta" title="<?php echo date('r', strtotime($clump['date'])); ?>">
+            saved <?php echo approximate_time(date('U') - strtotime($clump['date'])) ?> ago</a> by
+            <a class="uname" href="/<?php echo $clump['user'] ?>"><?php echo $clump['user'] ?></a>
+        </span>
     </p>
 
     <br />
diff --git a/get.php b/get.php
index 057b13c877c16934c3adb1a587dc63a1bb402118..3fdfe1cbd2a3f00b0835629e1e4855b1bdf22b83 100644 (file)
--- a/get.php
+++ b/get.php
@@ -20,39 +20,39 @@ try {
     if ($params['user']) {
         $user = get_users($dbh, array('user' => $params['user'] ));
         if ($user) {
-            $q = $dbh->prepare("SELECT *, clumps.id as clump_id 
-                                FROM clumps 
-                                JOIN users 
-                                    ON users.id = clumps.user_id 
-                                WHERE user_id = ? 
+            $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+                                FROM clumps
+                                JOIN users
+                                    ON users.id = clumps.user_id
+                                WHERE user_id = ?
                                 ORDER BY date DESC");
             $q->execute( array( $user['id'] ));
         }
     }
     else if ($params['id']) {
-        $q = $dbh->prepare("SELECT *, clumps.id as clump_id 
-                            FROM clumps 
-                            JOIN users 
-                                ON users.id = clumps.user_id 
-                            WHERE clumps.id = ? 
+        $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+                            FROM clumps
+                            JOIN users
+                                ON users.id = clumps.user_id
+                            WHERE clumps.id = ?
                             ORDER BY date DESC");
-        $q->execute( array( $params['id'] ));        
+        $q->execute( array( $params['id'] ));
     }
     else if ($endpoint == 'tag' && isset($urlparts[1])) {
         $tag = $urlparts[1];
-        $q = $dbh->prepare("SELECT *, clumps.id as clump_id 
-                            FROM clumps 
-                            JOIN users 
-                                ON users.id = clumps.user_id 
-                            WHERE tags LIKE ?  
+        $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+                            FROM clumps
+                            JOIN users
+                                ON users.id = clumps.user_id
+                            WHERE tags LIKE ?
                             ORDER BY date DESC");
         $q->execute( array('%'.$tag.'%') );
     }
     else {
-        $q = $dbh->prepare("SELECT *, clumps.id as clump_id 
-                            FROM clumps 
-                            JOIN users 
-                                ON users.id = clumps.user_id 
+        $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+                            FROM clumps
+                            JOIN users
+                                ON users.id = clumps.user_id
                             ORDER BY date DESC");
         $q->execute();
     }
@@ -114,7 +114,7 @@ function deleteClump( id, elem ) {
 
 
 <ul class="links">
-<?php if ($q) : for($i = 0; $row = $q->fetch(); $i++ ): 
+<?php if ($q) : for($i = 0; $row = $q->fetch(); $i++ ):
 
     # process description
     $hasDescription = $row['description'] || false;
@@ -123,38 +123,37 @@ function deleteClump( id, elem ) {
     if ($row['tags'] == '')
         $row['tags'] = array();
     else
-        $row['tags'] = explode(" ", $row['tags']);
+        $row['tags'] = explode(",", $row['tags']);
 
 ?>
-    
+
     <li>
-            
+
         <span class="url">
             <a href="<?php echo $row['url'] ?>">
                 <?php echo $row['title'] ? $row['title'] : "&lt;title&gt;" ?>
             </a>
-        </span>     
+        </span>
 
         <div class="expand">
             <?php if ($hasDescription) : ?>
                 <span class="desc">
-                <?php echo $row['description']; ?>
+                <?php echo htmlentities($row['description']); ?>
                 </span>
-            <?php endif; ?>  
-            <?php if (count($row['tags']) > 0) : ?>                
+            <?php endif; ?>
+            <?php if (count($row['tags']) > 0) : ?>
             <ul class="tags">
                 <?php foreach($row['tags'] as $tag) : ?>
                 <li><a href="/tag/<?=$tag?>"><?=$tag?></a></li>
                 <? endforeach; ?>
-            </ul>            
+            </ul>
             <?php endif; ?>
         </div>
 
-
         <span class="meta">
 
             <span title="<?php echo date('r', strtotime($row['date'])); ?>">
-                <?php echo approximate_time(date('U') - strtotime($row['date'])) ?> ago</a> by 
+                <?php echo approximate_time(date('U') - strtotime($row['date'])) ?> ago</a> by
                 <a class="uname" href="/<?php echo $row['user'] ?>"><?php echo $row['user'] ?></a>
             </span>
 
index 6b4b8d1267abbcd218e2f0e5c59b109b0b973c10..f99d2718e2db0b33acff36ef07158cc8274ff1dc 100644 (file)
@@ -39,9 +39,6 @@
             // for inputting multi-word tags.
             allowSpaces: false,
 
-            // replace spaces with this string if set to something other than space in _cleanedInput()
-            spaceChar: " ",
-
             // Whether to animate tag removals or not.
             animate: true,
 
 
         _cleanedInput: function() {
             // Returns the contents of the tag input, cleaned and ready to be passed to createTag
-
-            // replace spaces with spacechar if set
-            var _tval = this.options.spaceChar != ' ' ?
-                this._tagInput.val().replace(/\ /g, this.options.spaceChar) : this._tagInput.val();
-
-            return $.trim(_tval.replace(/^"(.*)"$/, '$1'));
+            return $.trim(this._tagInput.val().replace(/^"(.*)"$/, '$1'));
         },
 
         _lastTag: function() {
diff --git a/new.php b/new.php
index bf739c6b76fb96b64f67548b1e5e153a61cc28fc..8470f1a4739265c240e81966497a5a0b96cff84b 100644 (file)
--- a/new.php
+++ b/new.php
@@ -29,7 +29,6 @@ try {
         $("#tag-input").tagit({
             availableTags : userTags,
             animate : false,
-            spaceChar : '-',
             tabIndex : 3
         });
         $('.tagit input')[0].focus();
@@ -56,14 +55,11 @@ try {
                <input type="text" name="url" tabindex="2" value="<?=$params['url']?>">
             </p>
 
-               <label>tags <!-- <a href="#" class="tag-help" onClick="$('#tag-help').toggle();return false;">how to tag &raquo;</a> --></label>
-            <!--
+               <label>tags <a href="#" class="ui tag-help" onClick="$('#tag-help').toggle();return false;">how to tag &raquo;</a></label>
             <ul id="tag-help" style="display:none">
-                <li><span class="bull">&bull;</span>tag characters: [a-z 0-9 + # - .]</li>
-                <li><span class="bull">&bull;</span>combine multiple words into single-words with dashes</li>
-                <li><span class="bull">&bull;</span>delimit tags by space, comma, semicolon, or the enter key</li>
+                <li><span class="bull">&bull;</span>combine "multiple words" with quotes</li>
+                <li><span class="bull">&bull;</span>separate tags by space, comma, semicolon, enter</li>
             </ul>
-            -->
                <input type="text" id="tag-input" name="tags" tabindex="3" value="">
 
             <p>
diff --git a/put.php b/put.php
index 080ef1b254541721c54a49af2fb8231f7f651819..c4704095bb0d795df665f2c08752df0e07fe7131 100644 (file)
--- a/put.php
+++ b/put.php
@@ -4,9 +4,9 @@ include 'init.php';
 
 $params = array();
 $params['title'] = isset($_POST['title']) ? $_POST['title'] : null;
-$params['url']   = isset($_POST['url'])  ? $_POST['url']  : null;
-$params['tags']  = isset($_POST['tags'])  ? $_POST['tags']  : null;
-$params['description']  = isset($_POST['description'])  ? $_POST['description']  : null;
+$params['url'] = isset($_POST['url']) ? $_POST['url'] : null;
+$params['tags'] = isset($_POST['tags']) ? $_POST['tags'] : null;
+$params['description'] = isset($_POST['description']) ? $_POST['description'] : null;
 
 include 'head.html';
 
@@ -17,35 +17,26 @@ try {
         $dbh = get_db_connection();
         $dbh->beginTransaction();
 
-        # filter tags
-        $tags = filter_tags($params['tags']);
-
-        #insert tags
+        # process tags
+        $tags = explode(',', $params['tags']);
         if (count($tags) > 0) {
             foreach($tags as $key => $tag) {
-                $q = $dbh->prepare("INSERT INTO `clmpr`.`tags` (`tag`, `count`)
+                $q = $dbh->prepare("INSERT INTO `tags` (`tag`, `count`)
                                     VALUES ( ?, 1 )
                                     ON DUPLICATE KEY
-                                        UPDATE `count` = `count` + 1");
+                                    UPDATE `count` = `count` + 1");
                 $q->execute(array($tag));
             }
         }
 
         # insert clump
-        $q = $dbh->prepare("INSERT INTO `clmpr`.`clumps`
-                          ( `user_id`,
-                            `title`,
-                            `url`,
-                            `tags`,
-                            `description`,
-                            `date` )
-                        VALUES ( ?, ?, ?, ?, ?, NOW() ) ");
+        $q = $dbh->prepare("INSERT INTO `clumps`
+                          ( `user_id`, `title`, `url`,
+                            `tags`, `description`, `date` )
+                            VALUES ( ?, ?, ?, ?, ?, NOW() ) ");
         $insert = $q->execute( array(
-                    $user['id'],
-                    $params['title'],
-                    $params['url'],
-                    implode(" ", $tags),
-                    htmlentities($params['description'])));
+                    $user['id'], $params['title'], $params['url'],
+                    $params['tags'], $params['description']));
 
         echo "clumped.<br/><br/>";
         echo '<a href="javascript:window.close();">ok</a>';
index 5873367479882accd607dbcc443c3bf3ae2b0470..318390b75a04df9450296d13f2792460c7e21b7a 100644 (file)
--- a/style.css
+++ b/style.css
@@ -63,14 +63,6 @@ ul.links li span.url a {
 ul.links li span.url a:hover {
     text-decoration:none;
 }
-ul.links li span.meta {
-    color:#bbb;
-    font-style:italic;
-    font-size:12px;
-}
-ul.links li span.meta a {
-    color:#999;
-}
 ul.links li .desc {
     color:#00d;
 }
@@ -84,6 +76,15 @@ ul.links li .tags {
     display:block;
 }
 
+.meta {
+    color:#bbb;
+    font-style:italic;
+    font-size:12px;
+}
+.meta a {
+    color:#999;
+}
+
 
 .ui {
     font-size:12px;
index abce52900df2837dca9051ff0580db7f50d779a6..0cdce50c7833ed98094c9d7d97b424f8865e4097 100644 (file)
@@ -9,6 +9,9 @@ $params['url']   = isset($_POST['url'])   ? $_POST['url']  : null;
 $params['tags']  = isset($_POST['tags'])  ? $_POST['tags']  : null;
 $params['description']  = isset($_POST['description'])  ? $_POST['description']  : null;
 
+//print_r($_POST);
+//exit;
+
 try {
 
     if ($user = get_user() && $params['id']) {
@@ -17,19 +20,19 @@ try {
         $dbh->beginTransaction();
 
         if ($params['id']) {
-            $q = $dbh->prepare("SELECT *, clumps.id as clump_id 
-                                FROM clumps 
-                                JOIN users 
-                                    ON users.id = clumps.user_id 
-                                WHERE clumps.id = ? 
+            $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+                                FROM clumps
+                                JOIN users
+                                    ON users.id = clumps.user_id
+                                WHERE clumps.id = ?
                                 ORDER BY date DESC");
-            $q->execute( array( $params['id'] ));        
+            $q->execute( array( $params['id'] ));
         }
         $clump = $q->fetch();
-        $clump['tags'] = explode(" ", $clump['tags']);
+        $clump['tags'] = explode(",", $clump['tags']);
+
         # process tags
-        $tags = filter_tags($params['tags']);
+        $tags = explode(',', $params['tags']);
         $tags_to_keep   = array_intersect ($tags,          $clump['tags']);
         $tags_to_delete = array_diff      ($clump['tags'], $tags_to_keep);
         $tags_to_add    = array_diff      ($tags,          $tags_to_keep);
@@ -37,8 +40,8 @@ try {
         # add/increment new tags
         if (count($tags_to_add) > 0) {
             foreach($tags_to_add as $key => $tag) {
-                $sql = "INSERT INTO `clmpr`.`tags` ( `tag`, `count` ) 
-                        VALUES ( ?, 1 ) 
+                $sql = "INSERT INTO `clmpr`.`tags` ( `tag`, `count` )
+                        VALUES ( ?, 1 )
                         ON DUPLICATE KEY UPDATE
                             `count` = `count` + 1";
                 $q = $dbh->prepare($sql);
@@ -56,14 +59,14 @@ try {
                 $q = $dbh->prepare($sql);
                 $q->execute( array( $tag ));
             }
-        }               
+        }
 
         # update clump
-        $sql = "UPDATE `clumps` 
-                SET `url` = ?, `tags` = ?, `title` = ?, `description` = ? 
+        $sql = "UPDATE `clumps`
+                SET `url` = ?, `tags` = ?, `title` = ?, `description` = ?
                 WHERE `id` = ?";
         $q = $dbh->prepare($sql);
-        $insert = $q->execute( array( $params['url'], implode(" ", $tags), $params['title'], $params['description'], $params['id']));
+        $insert = $q->execute( array( $params['url'], implode(",", $tags), $params['title'], $params['description'], $params['id']));
 
         header('Location: /get.php?id=' . $params['id']);
         //echo "clumped.<br/><br/>";
@@ -71,7 +74,7 @@ try {
         //echo '<script>window.close();</script>';
 
         $dbh = null;
-        $q = null;    
+        $q = null;
 
     } else {
         include 'signin.php';