]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Do mention lookup for Webfinger accounts in OStatusPlugin
authorEvan Prodromou <evan@status.net>
Mon, 22 Feb 2010 02:38:16 +0000 (21:38 -0500)
committerEvan Prodromou <evan@status.net>
Mon, 22 Feb 2010 02:38:16 +0000 (21:38 -0500)
plugins/OStatus/OStatusPlugin.php

index c5a2db3d844cde6f281faeb766dbd940def5f473..60bb144a830c09f7343a03ba6cf02fcab0be0e72 100644 (file)
@@ -136,25 +136,6 @@ class OStatusPlugin extends Plugin
         return true;
     }
 
-    /**
-     * Add the feed settings page to the Connect Settings menu
-     *
-     * @param Action &$action The calling page
-     *
-     * @return boolean hook return
-     */
-    function onEndConnectSettingsNav(&$action)
-    {
-        $action_name = $action->trimmed('action');
-
-        $action->menuItem(common_local_url('feedsubsettings'),
-                          _m('Feeds'),
-                          _m('Feed subscription options'),
-                          $action_name === 'feedsubsettings');
-
-        return true;
-    }
-
     /**
      * Automatically load the actions and libraries used by the plugin
      *
@@ -215,33 +196,16 @@ class OStatusPlugin extends Plugin
      * @fixme push webfinger lookup & sending to a background queue
      * @fixme also detect short-form name for remote subscribees where not ambiguous
      */
+
     function onEndNoticeSave($notice)
     {
-        $count = preg_match_all('/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $notice->content, $matches);
-        if ($count) {
-            foreach ($matches[0] as $webfinger) {
+        $mentioned = $notice->getReplies();
 
-                // FIXME: look up locally first
+        foreach ($mentioned as $profile) {
 
-                // Check to see if we've got an actual webfinger
-                $w = new Webfinger;
+            $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
 
-                $endpoint_uri = '';
-
-                $result = $w->lookup($webfinger);
-                if (empty($result)) {
-                    continue;
-                }
-
-                foreach ($result->links as $link) {
-                    if ($link['rel'] == 'salmon') {
-                        $endpoint_uri = $link['href'];
-                    }
-                }
-
-                if (empty($endpoint_uri)) {
-                    continue;
-                }
+            if (!empty($oprofile) && !empty($oprofile->salmonuri)) {
 
                 // FIXME: this needs to go out in a queue handler
 
@@ -249,9 +213,40 @@ class OStatusPlugin extends Plugin
                 $xml .= $notice->asAtomEntry();
 
                 $salmon = new Salmon();
-                $salmon->post($endpoint_uri, $xml);
+                $salmon->post($oprofile->salmonuri, $xml);
+            }
+        }
+    }
+
+    /**
+     *
+     */
+
+    function onEndFindMentions($sender, $text, &$mentions)
+    {
+        preg_match_all('/(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)/',
+                       $text,
+                       $wmatches,
+                       PREG_OFFSET_CAPTURE);
+
+        foreach ($wmatches[1] as $wmatch) {
+
+            $webfinger = $wmatch[0];
+
+            $oprofile = Ostatus_profile::ensureWebfinger($webfinger);
+
+            if (!empty($oprofile)) {
+
+                $profile = $oprofile->localProfile();
+
+                $mentions[] = array('mentioned' => array($profile),
+                                    'text' => $wmatch[0],
+                                    'position' => $wmatch[1],
+                                    'url' => $profile->profileurl);
             }
         }
+
+        return true;
     }
 
     /**