]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
put tags in items
[friendica.git] / include / text.php
index 6b39868b9a67c9658a9f3cf6e81adffeaf2783b2..c0b716afb238d0aa5ae5cef47135ecf99e6c4164 100644 (file)
@@ -1269,11 +1269,42 @@ if(! function_exists('prepare_body')) {
  * @hook prepare_body ('item'=>item array, 'html'=>body string) after first bbcode to html
  * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
  */
-function prepare_body($item,$attach = false) {
+function prepare_body(&$item,$attach = false) {
 
        $a = get_app();
        call_hooks('prepare_body_init', $item);
 
+       $searchpath = $a->get_baseurl()."/search?tag=";
+
+       $tags=array();
+       $hashtags = array();
+       $mentions = array();
+
+       if (!get_config('system','suppress_tags')) {
+               $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
+                               intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
+
+               foreach($taglist as $tag) {
+
+                       if ($tag["url"] == "")
+                               $tag["url"] = $searchpath.strtolower($tag["term"]);
+
+                       if ($tag["type"] == TERM_HASHTAG) {
+                               $hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
+                               $prefix = "#";
+                       } elseif ($tag["type"] == TERM_MENTION) {
+                               $mentions[] = "@<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
+                               $prefix = "@";
+                       }
+                       $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
+               }
+       }
+
+       $item['tags'] = $tags;
+       $item['hashtags'] = $hashtags;
+       $item['mentions'] = $mentions;
+
+
        //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']));
        $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body']));