]> git.quilime.com - clmpr.git/commitdiff
progress on comma delimiter
authorGabriel Dunne <gdunne@quilime.com>
Wed, 21 Dec 2011 09:13:26 +0000 (01:13 -0800)
committerGabriel Dunne <gdunne@quilime.com>
Wed, 21 Dec 2011 09:13:26 +0000 (01:13 -0800)
TODO
data.php
new.php
put.php
update.php

diff --git a/TODO b/TODO
index 26451859bd3174bf973834877fd685093ff9374c..fa0a6fa05e38995a7ad8252591fabdd300f0b837 100644 (file)
--- 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
index fb59b3dd75b4a3e35f9531e8917c5fb785e3e3ed..5b9baa2ea0cd22f1d10cb47491ef9120b3f9b57d 100644 (file)
--- 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 f9c65e2ea21995ac6fce13f7d09fab54629d11e5..165980c1f236476cbb18bac07c69073413e70c6c 100644 (file)
--- a/new.php
+++ b/new.php
@@ -28,7 +28,7 @@ try {
             </p>
                
             <p>
-               <label>tags (SPACEBAR delimited)</label>
+               <label>tags <span style="font-weight:normal">(space " " or comma "," delimited)</span></label>
                <input type="text" name="tags" value="">                                
             </p>
 
diff --git a/put.php b/put.php
index b874a95de5d997405624637bde3718e188a9a081..942cd00010b0d06484c85edb1ad8dca49cfcd8c2 100644 (file)
--- 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 '<br />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.<br/><br/>";
         echo '<a href="javascript:window.close();">ok</a>';
index 56ce786097ed42ea5d16481bcbc5bc5a87debd01..abce52900df2837dca9051ff0580db7f50d779a6 100644 (file)
@@ -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) {