]> git.mxchange.org Git - friendica.git/blobdiff - include/tags.php
Better handling of the network field in the item table.
[friendica.git] / include / tags.php
index 6a5728a9ba54115aad3e01eb8cba87658dc18c35..e5bc29cd4f5db6bb13662e4c1a6f35db8dde2935 100644 (file)
@@ -25,7 +25,7 @@ function create_tags_from_item($itemid) {
 
        $searchpath = $a->get_baseurl()."/search?tag=";
 
-       $messages = q("SELECT `uri`, `uid`, `id`, `created`, `edited`, `commented`, `received`, `changed`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
+       $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
 
        if (!$messages)
                return;
@@ -42,6 +42,16 @@ function create_tags_from_item($itemid) {
        if ($message["deleted"])
                return;
 
+       $cachefile = get_cachefile($message["guid"]."-".hash("md5", $message['body']));
+
+       if (($cachefile != '') AND !file_exists($cachefile)) {
+               $s = prepare_text($message['body']);
+               $stamp1 = microtime(true);
+               file_put_contents($cachefile, $s);
+               $a->save_timestamp($stamp1, "file");
+               logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile);
+       }
+
        $taglist = explode(",", $message["tag"]);
 
        $tags = "";
@@ -69,6 +79,12 @@ function create_tags_from_item($itemid) {
        foreach ($tags as $tag=>$link) {
 
                if (substr(trim($tag), 0, 1) == "#") {
+                       // try to ignore #039 or #1 or anything like that
+                       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)))
+                               continue;
                        $type = TERM_HASHTAG;
                        $term = substr($tag, 1);
                } elseif (substr(trim($tag), 0, 1) == "@") {
@@ -96,8 +112,10 @@ function create_tags_from_item($itemid) {
 function create_tags_from_itemuri($itemuri, $uid) {
        $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
 
-       foreach ($messages as $message)
-               create_tags_from_item($message["id"]);
+       if(count($messages)) {
+               foreach ($messages as $message)
+                       create_tags_from_item($message["id"]);
+       }
 }
 
 function update_items() {