From 11d1c1ae8eaf9b91fd2478abc7b089f9c0877845 Mon Sep 17 00:00:00 2001 From: Fabrixxm Date: Sat, 3 Aug 2013 15:12:50 -0400 Subject: [PATCH 1/4] add tag to term table. fix "#xNNNN" tag filter. --- include/tags.php | 4 ++-- mod/tagger.php | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/include/tags.php b/include/tags.php index a06504fbe3..c4aba400f3 100644 --- a/include/tags.php +++ b/include/tags.php @@ -83,7 +83,7 @@ function create_tags_from_item($itemid) { if(ctype_digit(substr(trim($tag),1))) continue; // try to ignore html hex escapes, e.g. #x2317 - if((substr(trim($tag),1,1) == 'x' || substr(trim($tag),1,1) == 'X') && ctype_digit(substr(trim($tag,2)))) + if((substr(trim($tag),1,1) == 'x' || substr(trim($tag),1,1) == 'X') && ctype_digit(substr(trim($tag),2,1))) continue; $type = TERM_HASHTAG; $term = substr($tag, 1); @@ -92,7 +92,7 @@ function create_tags_from_item($itemid) { $term = substr($tag, 1); } else { // This shouldn't happen $type = TERM_HASHTAG; - $term = $tag; + $term = $tag."-oh"; } $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')", diff --git a/mod/tagger.php b/mod/tagger.php index 6ae0cebf71..3f470a1797 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -151,13 +151,27 @@ EOT; ); } - if((! $blocktags) && (! stristr($item['tag'], ']' . $term . '[' ))) { - q("update item set tag = '%s' where id = %d limit 1", + $term_objtype = (($item['resource-id']) ? TERM_OBJ_PHOTO : TERM_OBJ_POST ); + $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'", + intval($item['id']), + dbesc($term) + ); + if((! $blocktags) && $t[0]['tcount']==0 ) { + /*q("update item set tag = '%s' where id = %d limit 1", dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'), intval($item['id']) + );*/ + + q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)", + intval($item['id']), + $term_objtype, + TERM_HASHTAG, + dbesc($term), + dbesc($a->get_baseurl() . '/search?tag=' . $term), + intval($owner_uid) ); } - + // if the original post is on this site, update it. $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1", @@ -167,12 +181,29 @@ EOT; $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1", intval($r[0]['uid']) ); - if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) { + $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'", + intval($r[0]['id']), + dbesc($term) + ); + echo "
"; var_dump($t); killme();
+		// not really sure about this...
+		if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
+			q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
+	                   intval($r[0]['id']),
+	                   $term_objtype,
+	                   TERM_HASHTAG,
+	                   dbesc($term),
+	                   dbesc($a->get_baseurl() . '/search?tag=' . $term),
+	                   intval($owner_uid)
+	                );
+		}
+
+		/*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
 			q("update item set tag = '%s' where id = %d limit 1",
 				dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
 				intval($r[0]['id'])
 			);
-		}
+		}*/
 
 	}
 		
@@ -188,4 +219,4 @@ EOT;
 	return; // NOTREACHED
 
 
-}
\ No newline at end of file
+}

From 50233ba290c2b48c3e67093f5862db1cc21c8f42 Mon Sep 17 00:00:00 2001
From: Fabrixxm 
Date: Sat, 3 Aug 2013 15:18:41 -0400
Subject: [PATCH 2/4] remove debug code

---
 include/tags.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/tags.php b/include/tags.php
index c4aba400f3..ba61f448e0 100644
--- a/include/tags.php
+++ b/include/tags.php
@@ -92,7 +92,7 @@ function create_tags_from_item($itemid) {
 			$term = substr($tag, 1);
 		} else { // This shouldn't happen
 			$type = TERM_HASHTAG;
-			$term = $tag."-oh";
+			$term = $tag;
 		}
 
 		$r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')",

From 2f6333c7516220553352889ac4c0527102e91780 Mon Sep 17 00:00:00 2001
From: Fabrixxm 
Date: Sun, 4 Aug 2013 03:11:01 -0400
Subject: [PATCH 3/4] remove debug code. again.

---
 mod/tagger.php | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mod/tagger.php b/mod/tagger.php
index 3f470a1797..e502353420 100644
--- a/mod/tagger.php
+++ b/mod/tagger.php
@@ -185,8 +185,6 @@ EOT;
 			intval($r[0]['id']),
 			dbesc($term)
 		);
-		echo "
"; var_dump($t); killme();
-		// not really sure about this...
 		if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
 			q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
 	                   intval($r[0]['id']),

From 3f36d375e235b5bad584afe0d90acb35ca25bffa Mon Sep 17 00:00:00 2001
From: Fabrixxm 
Date: Sun, 4 Aug 2013 03:12:17 -0400
Subject: [PATCH 4/4] hex tag filter: look at entire string

---
 include/tags.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/tags.php b/include/tags.php
index ba61f448e0..e5bc29cd4f 100644
--- a/include/tags.php
+++ b/include/tags.php
@@ -83,7 +83,7 @@ function create_tags_from_item($itemid) {
 			if(ctype_digit(substr(trim($tag),1)))
 				continue;
 			// try to ignore html hex escapes, e.g. #x2317
-			if((substr(trim($tag),1,1) == 'x' || substr(trim($tag),1,1) == 'X') && ctype_digit(substr(trim($tag),2,1)))
+			if((substr(trim($tag),1,1) == 'x' || substr(trim($tag),1,1) == 'X') && ctype_digit(substr(trim($tag),2)))
 				continue;
 			$type = TERM_HASHTAG;
 			$term = substr($tag, 1);