From: Gabriel Dunne Date: Wed, 21 Dec 2011 21:41:55 +0000 (-0800) Subject: allow spaces in tags X-Git-Tag: v0.1~1 X-Git-Url: https://git.quilime.com/?a=commitdiff_plain;h=34f6a13273600081bff8639f09e507cc49ebbcdd;p=clmpr.git allow spaces in tags --- diff --git a/data.php b/data.php index 3cb5b93..fb59b3d 100644 --- 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); -} diff --git a/delete.php b/delete.php index f37b26f..05b0449 100644 --- a/delete.php +++ b/delete.php @@ -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) { diff --git a/edit.php b/edit.php index d7c4a84..d4e787c 100644 --- a/edit.php +++ b/edit.php @@ -81,19 +81,25 @@ function deleteClump( id ) {

-

- - -

+ + + + +

- +

- saved by - + + saved ago by + +


diff --git a/get.php b/get.php index 057b13c..3fdfe1c 100644 --- 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 ) { - - ago by + ago by diff --git a/lib/tag-it/js/tag-it.js b/lib/tag-it/js/tag-it.js index 6b4b8d1..f99d271 100644 --- a/lib/tag-it/js/tag-it.js +++ b/lib/tag-it/js/tag-it.js @@ -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, @@ -238,12 +235,7 @@ _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 bf739c6..8470f1a 100644 --- 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 {

- -

diff --git a/put.php b/put.php index 080ef1b..c470409 100644 --- 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.

"; echo 'ok'; diff --git a/style.css b/style.css index 5873367..318390b 100644 --- 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; diff --git a/update.php b/update.php index abce529..0cdce50 100644 --- a/update.php +++ b/update.php @@ -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.

"; @@ -71,7 +74,7 @@ try { //echo ''; $dbh = null; - $q = null; + $q = null; } else { include 'signin.php';