]> git.mxchange.org Git - friendica.git/commitdiff
linkify @person and @person@domain.com tags
authorMike Macgirvin <mike@macgirvin.com>
Fri, 29 Oct 2010 01:18:20 +0000 (18:18 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Fri, 29 Oct 2010 01:18:20 +0000 (18:18 -0700)
boot.php
mod/item.php

index 07810a50eb4cfc3773337705dded272855a66532..870a4c33b7f55276e9315eac5a99af2728a520b2 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1300,8 +1300,17 @@ function activity_match($haystack,$needle) {
 
 if(! function_exists('get_tags')) {
 function get_tags($s) {
-       if(preg_match_all('/([@#][^ ,.:?\-]*)[ ,.:?\-]/',$s,$match))
-               return $match[1];
+       $ret = array();
+       if(preg_match_all('/([@#][^ ,:?]*)[ ,:?]/',$s,$match)) {
+               foreach($match[1] as $match) {
+                       if(substr($match,-1,1) === '.')
+                               $ret[] = substr($match,0,-1);
+                       else
+                               $ret[] = $match;
+               }
+       }
+
+       return $ret;
 }}
 
 
index 4ebb1e978157edb0d6b06822f033a9cd72539904..64a23e7fb1ad6f1f8ff8a8ce92018317cbf60228 100644 (file)
@@ -114,6 +114,49 @@ function item_post(&$a) {
                }
        }
 
+       $str_tags = '';
+       $tagged = array();
+
+       $tags = get_tags($body);
+
+
+       if($tags) {
+               foreach($tags as $tag) {
+                       if(strpos($tag,'@') === 0) {
+                               $name = substr($tag,1);
+                               if(strpos($name,'@')) {
+
+                                       $links = @webfinger($name);
+                                       if(count($links)) {
+                                               foreach($links as $link) {
+                                                       if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
+                                       $profile = $link['@attributes']['href'];
+                                                       if($link['@attributes']['rel'] === 'salmon')
+                                       $salmon = $link['@attributes']['href'];
+                                               }
+                                       }
+                               }
+                               else {
+                                       $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
+                                               dbesc($name),
+                                               intval($profile_uid)
+                                       );
+                                       if(count($r)) {
+                                               $profile = $r[0]['url'];
+                                               $salmon = $r[0]['notify'];
+                                       }
+                               }
+                               if($profile) {
+                                       $profile = str_replace(',','%2c',$profile);
+                                       $body = str_replace($name,'[url=' . $profile . ']' . $name      . '[/url]', $body);
+                                       if(strlen($str_tags))
+                                               $str_tags .= ',';
+                                       $str_tags .= '[url=' . $profile . ']' . $name   . '[/url]';
+                               }
+                       }
+               }
+       }
+
        $wall = 0;
        if($post_type === 'wall' || $post_type === 'wall-comment')
                $wall = 1;
@@ -345,7 +388,7 @@ function item_content(&$a) {
                else {
                        notice( t('Permission denied.') . EOL);
                        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
-                       return; //NOTREACHED
+                       //NOTREACHED
                }
        }
 }
\ No newline at end of file