X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=src%2FModel%2FTerm.php;h=e5490fa7c6cc731a103d491e26d9bf30c4f2100a;hb=c3a532a9f682d0ceea70e65379018c59cf59efc4;hp=c730bf74499b8914c962c414aa11fcb5d3675aee;hpb=2a5431a59e5f81c797ee2f949e9ebb52b2c9105a;p=friendica.git
diff --git a/src/Model/Term.php b/src/Model/Term.php
index c730bf7449..e5490fa7c6 100644
--- a/src/Model/Term.php
+++ b/src/Model/Term.php
@@ -9,6 +9,7 @@ use Friendica\Database\DBM;
use dba;
require_once 'boot.php';
+require_once 'include/conversation.php';
require_once 'include/dba.php';
class Term
@@ -28,8 +29,7 @@ class Term
}
// Clean up all tags
- dba::e("DELETE FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?)",
- TERM_OBJ_POST, $itemid, TERM_HASHTAG, TERM_MENTION);
+ dba::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]);
if ($message['deleted']) {
return;
@@ -122,19 +122,6 @@ class Term
}
}
- public static function insertFromTagFieldByItemUri($itemuri, $uid)
- {
- $messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
-
- if (DBM::is_result($messages)) {
- while ($message = dba::fetch($messages)) {
- self::insertFromTagFieldByItemId($message['id']);
- }
- dba::close($messages);
- }
- }
-
-
/**
* @param integer $itemid item id
* @return void
@@ -147,11 +134,7 @@ class Term
}
// Clean up all tags
- q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
- intval(TERM_OBJ_POST),
- intval($itemid),
- intval(TERM_FILE),
- intval(TERM_CATEGORY));
+ dba::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_FILE, TERM_CATEGORY]]);
if ($message["deleted"]) {
return;
@@ -183,18 +166,54 @@ class Term
}
/**
- * @param string $itemuri item uri
- * @param integer $uid uid
- * @return void
+ * Sorts an item's tags into mentions, hashtags and other tags. Generate personalized URLs by user and modify the
+ * provided item's body with them.
+ *
+ * @param array $item
+ * @return array
*/
- public static function insertFromFileFieldByItemUri($itemuri, $uid)
+ public static function populateTagsFromItem(&$item)
{
- $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
+ $return = [
+ 'tags' => [],
+ 'hashtags' => [],
+ 'mentions' => [],
+ ];
+
+ $searchpath = System::baseUrl() . "/search?tag=";
+
+ $taglist = dba::select(
+ 'term',
+ ['type', 'term', 'url'],
+ ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION],
+ ['order' => ['tid']]
+ );
+
+ while ($tag = dba::fetch($taglist)) {
+ if ($tag["url"] == "") {
+ $tag["url"] = $searchpath . strtolower($tag["term"]);
+ }
+
+ $orig_tag = $tag["url"];
- if (count($messages)) {
- foreach ($messages as $message) {
- self::insertFromFileFieldByItemId($message["id"]);
+ $tag["url"] = best_link_url($item, $sp, $tag["url"]);
+
+ if ($tag["type"] == TERM_HASHTAG) {
+ if ($orig_tag != $tag["url"]) {
+ $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
+ }
+
+ $return['hashtags'][] = "#" . $tag["term"] . "";
+ $prefix = "#";
+ } elseif ($tag["type"] == TERM_MENTION) {
+ $return['mentions'][] = "@" . $tag["term"] . "";
+ $prefix = "@";
}
+
+ $return['tags'][] = $prefix . "" . $tag["term"] . "";
}
+ dba::close($taglist);
+
+ return $return;
}
}