From d29df150816f4f11bed94a6e5a7518341b722922 Mon Sep 17 00:00:00 2001
From: Gabriel Dunne
Date: Wed, 21 Dec 2011 01:13:26 -0800
Subject: [PATCH] progress on comma delimiter
---
TODO | 3 ++-
data.php | 27 +++++++++++++++++++++++++++
new.php | 2 +-
put.php | 35 ++++++++++++++++++++++++-----------
update.php | 9 ++++-----
5 files changed, 58 insertions(+), 18 deletions(-)
diff --git a/TODO b/TODO
index 2645185..fa0a6fa 100644
--- a/TODO
+++ b/TODO
@@ -1,12 +1,13 @@
evaluate MVC architecture w/ template system
templates for rss, xml
clean urls
-filter by tags
preview media when embedding videos from youtube, images, etc
private saving
import/export
pagination
+allow commas or space delimited
+
pages
help - explain bookmarklet
about
diff --git a/data.php b/data.php
index fb59b3d..5b9baa2 100644
--- a/data.php
+++ b/data.php
@@ -38,3 +38,30 @@ 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 pluses
+ $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/new.php b/new.php
index f9c65e2..165980c 100644
--- a/new.php
+++ b/new.php
@@ -28,7 +28,7 @@ try {
-
+
diff --git a/put.php b/put.php
index b874a95..942cd00 100644
--- a/put.php
+++ b/put.php
@@ -18,24 +18,37 @@ try {
$dbh->beginTransaction();
# process tags
- $tags = explode(" ", $params['tags']);
- $tags = array_unique($tags);
+ $tags = filter_tags($params['tags']);
+ print_r($tags);
+ echo '
TODO: figure out delimiter for spaces for database';
+ exit;
+
+ #insert tags
if (count($tags) > 0) {
foreach($tags as $key => $tag) {
- $sql = "INSERT INTO `clmpr`.`tags` ( `tag`, `count` )
- VALUES ( ?, 1 )
- ON DUPLICATE KEY UPDATE
- `count` = `count` + 1";
- $q = $dbh->prepare($sql);
+ $q = $dbh->prepare("INSERT INTO `clmpr`.`tags` (`tag`, `count`)
+ VALUES ( ?, 1 )
+ ON DUPLICATE KEY
+ UPDATE `count` = `count` + 1");
$q->execute( array( $tag ));
}
}
# insert clump
- $sql = "INSERT INTO `clmpr`.`clumps` ( `user_id`, `title` , `url` , `tags`, `description`, `date` )
- VALUES ( ?, ?, ?, ?, ?, NOW() ) ";
- $q = $dbh->prepare($sql);
- $insert = $q->execute( array( $user['id'], $params['title'], $params['url'], implode(" ", $tags), htmlentities($params['description']) ));
+ $q = $dbh->prepare("INSERT INTO `clmpr`.`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'])));
echo "clumped.
";
echo 'ok';
diff --git a/update.php b/update.php
index 56ce786..abce529 100644
--- a/update.php
+++ b/update.php
@@ -29,11 +29,10 @@ try {
$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);
+ $tags = filter_tags($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