From 173a276b6d134eec86918b26b6ae0e306f238edf Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Sun, 18 Dec 2011 13:41:52 -0800 Subject: [PATCH] Updated tagging system --- TODO | 9 ++--- get.php | 102 +++++++++++++++++++++++++++++++++++------------------ index.php | 37 +------------------ style.css | 31 +++++++++------- tags.php | 16 ++++----- update.php | 88 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 183 insertions(+), 100 deletions(-) create mode 100644 update.php diff --git a/TODO b/TODO index 0920b7e..da6f326 100644 --- a/TODO +++ b/TODO @@ -1,13 +1,8 @@ create server variable for bookmarklet evaluate MVC architecture w/ template system -add description field +smart urls +filter by tags 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 - see: http://www.pui.ch/phred/archives/2005/05/tags-with-mysql-fulltext.html \ No newline at end of file diff --git a/get.php b/get.php index a004ff8..e6aa1f7 100644 --- a/get.php +++ b/get.php @@ -4,6 +4,9 @@ require_once 'init.php'; $params = array(); $params['user'] = isset($_GET['user']) ? $_GET['user'] : null; +$params['id'] = isset($_GET['id']) ? $_GET['id'] : null; + +$format = isset($pathinfo['extension']) ? $pathinfo['extension'] : null; $dbh = get_db_connection(); $dbh->beginTransaction(); @@ -21,6 +24,15 @@ try { $q->execute( array( $user['id'] )); } } + 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 = ? + ORDER BY date DESC"); + $q->execute( array( $params['id'] )); + } else { $q = $dbh->prepare("SELECT *, clumps.id as clump_id FROM clumps @@ -36,7 +48,6 @@ catch(PDOException $e) exit; } - switch ($format) { case 'xml' : case 'rss' : @@ -44,19 +55,39 @@ case 'xml' : exit; } + +?> + + +clmpr + + + + + + + + +

+bookmarklet: + ++ +

- + + +
+ + diff --git a/index.php b/index.php index 8539896..e9ac0e7 100644 --- a/index.php +++ b/index.php @@ -45,7 +45,6 @@ switch($endpoint) default : if ($endpoint != '') { - $dbh = get_db_connection(); $dbh->beginTransaction(); $user = get_users($dbh, array( 'user' => $endpoint )); @@ -59,38 +58,4 @@ switch($endpoint) } } -switch ($format) { - case 'rss' : - case 'xml' : - include 'get.php'; - exit; -} - -?> - - -clmpr - - - - - - - - -

-bookmarklet: - -+ -

- - -
- - - -
- - +include 'get.php'; diff --git a/style.css b/style.css index 21f091d..ebdbaee 100644 --- a/style.css +++ b/style.css @@ -60,14 +60,17 @@ ul.links li p.desc { /*display:none;*/ } ul.links li .expand { - display:none; - margin:0 0 1em 1em; + color:#aaa; + margin-bottom:1em; } ul.links li.expand .expand { display:block; } -ul.links li.expand p.desc { - /*display:block;*/ +ul.links li .desc { + display:inline-block; +} +ul.links li .tags { + display:inline-block; } ul.links li .less { display:none; @@ -82,17 +85,19 @@ ul.links li.expand .less { display:inline; } -.delete { - font-weight:bold; - padding:0 3px; - line-height:1em; - background:#eee; - color:#999; +.ui { + + color:#99f; text-decoration:none; } - -.delete:hover { - text-decoration: none; +.ui:hover { + text-decoration: none; +} +.ui.delete { + font-weight:bold; + color:#f9e; +} +.ui.edit { } form.new input[type="text"] { diff --git a/tags.php b/tags.php index 7940149..1ce1df3 100644 --- a/tags.php +++ b/tags.php @@ -19,9 +19,11 @@ try { } else { */ - $q = $dbh->prepare("SELECT * FROM tags - ORDER BY count DESC, tag ASC"); + $q = $dbh->prepare("SELECT * FROM `tags` + WHERE `count` > 0 + ORDER BY `count` DESC, `tag` ASC "); $q->execute(); + //} } @@ -44,22 +46,16 @@ catch(PDOException $e) -

tags

+

- - - diff --git a/update.php b/update.php new file mode 100644 index 0000000..cd1daeb --- /dev/null +++ b/update.php @@ -0,0 +1,88 @@ +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 = ? + ORDER BY date DESC"); + $q->execute( array( $params['id'] )); + } + $clump = $q->fetch(); + $clump['tags'] = explode(" ", $clump['tags']); + + # process tags + $tags = explode(" ", $params['tags']); + $tags = array_unique($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); + + # 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 ) + ON DUPLICATE KEY UPDATE + `count` = `count` + 1"; + $q = $dbh->prepare($sql); + $q->execute( array( $tag )); + } + } + + # decrement old tags + # note: leaves tags in database with count of '0' if not used + if (count($tags_to_delete) > 0) { + foreach($tags_to_delete as $key => $tag) { + $sql = "UPDATE tags + SET count = count - 1 + WHERE tag = ? AND count > 0"; + $q = $dbh->prepare($sql); + $q->execute( array( $tag )); + } + } + + # update clump + $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'])); + + header('Location: /get.php?id=' . $params['id']); + //echo "clumped.

"; + //echo 'ok'; + //echo ''; + + $dbh = null; + $q = null; + + } else { + include 'signin.php'; + } +} +catch(PDOException $e) +{ + echo $e->getMessage(); +} + +exit; -- 2.34.1