From e4f45240e42a6eebadf654a3868781c91dd32a39 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Fri, 23 Dec 2011 10:14:45 -0800 Subject: [PATCH] working on minimal tags --- TODO | 6 +++++- admin/_migrate.php | 31 +++++++++++++++++++++++++++++++ data.php | 9 +++++++++ edit.php | 26 +++----------------------- new.php | 28 ---------------------------- put.php | 4 ++-- update.php | 12 ++++++------ 7 files changed, 56 insertions(+), 60 deletions(-) create mode 100644 admin/_migrate.php diff --git a/TODO b/TODO index dc176c7..102859f 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ +// TODO evaluate MVC architecture w/ template system templates for rss, xml clean urls @@ -6,14 +7,17 @@ private saving import/export pagination tag autocomplete from user tags +check for quotes (for "multiple words") + -allow commas or space delimited pages help - explain bookmarklet about + ref + pinterest.in http://www.pui.ch/phred/archives/2005/05/tags-with-mysql-fulltext.html http://code.google.com/p/mysqlicious/ diff --git a/admin/_migrate.php b/admin/_migrate.php new file mode 100644 index 0000000..87c99a1 --- /dev/null +++ b/admin/_migrate.php @@ -0,0 +1,31 @@ +beginTransaction(); + +$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(); + +$clumps = array(); +for($i = 0; $row = $q->fetch(); $i++ ): + $clumps[] = $row; +endfor; + +foreach($clumps as $clump) : + #update tags + $tags = str_replace(" ", ',', $clump['tags']); + # update clump + $update = $dbh->prepare("UPDATE `clumps` SET `tags` = '".$tags."' WHERE `id` = '".$clump['clump_id']."'"); + $update->execute(); +endforeach; + +exit; + +$dbh = null; +$q = null; diff --git a/data.php b/data.php index fb59b3d..b80dbcc 100644 --- a/data.php +++ b/data.php @@ -38,3 +38,12 @@ function get_users(&$dbh, $args) return false; } + + +function tag_string_to_array($tagstr) { + # if has commas, split on commas + # else split on spaces + // TODO + # check for quotes (for "multiple words") + return strpos($tagstr, ',') ? explode(',', $tagstr) : explode(' ', $tagstr); +} diff --git a/edit.php b/edit.php index d92f6d5..6f4d082 100644 --- a/edit.php +++ b/edit.php @@ -32,27 +32,8 @@ catch(PDOException $e) ?> - clmpr - <?=$clump['title']?> - - - - - - - - - @@ -82,13 +62,13 @@ function deleteClump( id ) {

- - + +

- +

diff --git a/new.php b/new.php index d62e432..203ebad 100644 --- a/new.php +++ b/new.php @@ -12,30 +12,6 @@ try { ?> - - - - - - - - - - beginTransaction(); # process tags - $tags = explode(',', $params['tags']); + $tags = tag_string_to_array( $params['tags'] ); if (count($tags) > 0) { foreach($tags as $key => $tag) { $q = $dbh->prepare("INSERT INTO `tags` (`tag`, `count`) @@ -36,7 +36,7 @@ try { VALUES ( ?, ?, ?, ?, ?, NOW() ) "); $insert = $q->execute( array( $user['id'], $params['title'], $params['url'], - $params['tags'], $params['description'])); + implode(',', $params['tags']), $params['description'])); echo "clumped.

"; echo 'ok'; diff --git a/update.php b/update.php index 0cdce50..67ff706 100644 --- a/update.php +++ b/update.php @@ -5,8 +5,8 @@ include 'init.php'; $params = array(); $params['id'] = isset($_POST['id']) ? $_POST['id'] : 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; +$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); @@ -32,10 +32,10 @@ try { $clump['tags'] = explode(",", $clump['tags']); # process 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); + $tags = tag_string_to_array( $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); # add/increment new tags if (count($tags_to_add) > 0) { -- 2.34.1