]> git.quilime.com - clmpr.git/commitdiff
cleaned tag input style
authorGabriel Dunne <gdunne@quilime.com>
Fri, 23 Dec 2011 19:21:25 +0000 (11:21 -0800)
committerGabriel Dunne <gdunne@quilime.com>
Fri, 23 Dec 2011 19:21:25 +0000 (11:21 -0800)
data.php
get.php

index 6dad9858443fab7bea1e88ea1e4d6ddc4de18d8e..0425bc4f0df70cdd6361c0f058436d543f866dc8 100644 (file)
--- a/data.php
+++ b/data.php
@@ -41,11 +41,23 @@ function get_users(&$dbh, $args)
 function tag_string_to_array($tagstr) {
     # if has commas, split on commas
     # else split on spaces
-        // TODO
-        # check for quotes (for "multiple words")
-    $tags = array_filter(strpos($tagstr, ',') ? explode(',', $tagstr) : explode(' ', $tagstr));
+    $tags = array();
+    if (strpos($tagstr, ',')) {
+        $tags = explode(',', $tagstr);
+    } else {
+        # match all quoted strings
+        preg_match_all('/"(.*?)"/', $tagstr, $quoted_tags);
+        # strip quoted strings from tag string
+        $tagstr_noquotes = str_replace($quoted_tags[0], '', $tagstr);
+        # split new string on spaces
+        $tags_woutquotes = explode(' ', $tagstr_noquotes);
+        # merge arrays
+        $tags = array_merge($tags_woutquotes, $quoted_tags[1]);
+    }
+    # trim all values
     array_walk($tags, function(&$item, $key) {
              $item = trim($item);
-         });
-    return $tags;
+    });
+
+    return array_filter($tags);
 }
diff --git a/get.php b/get.php
index 83fc234388b47344c3c98f5a4d597f15390f8d97..0cbcdcca97405c5e7aa0971afdacd124ff4990cc 100644 (file)
--- a/get.php
+++ b/get.php
@@ -121,10 +121,7 @@ function deleteClump( id, elem ) {
     $hasDescription = $row['description'] || false;
 
     # process tags
-    if ($row['tags'] == '')
-        $row['tags'] = array();
-    else
-        $row['tags'] = tag_string_to_array( $row['tags'] );
+    $row['tags'] = tag_string_to_array( $row['tags'] );
 
 ?>