]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
OStatus: support @example.com/path/to/profile mentions as well as @profile@example...
authorBrion Vibber <brion@pobox.com>
Tue, 2 Mar 2010 00:36:33 +0000 (16:36 -0800)
committerBrion Vibber <brion@pobox.com>
Tue, 2 Mar 2010 00:43:36 +0000 (16:43 -0800)
Plus misc warnings/notices cleanup in the submission path.

actions/newnotice.php
plugins/OStatus/OStatusPlugin.php
plugins/OStatus/classes/Ostatus_profile.php
plugins/OStatus/lib/discovery.php
plugins/OStatus/lib/xrd.php

index 78480ababb069849508550141ee4c5df9862b78c..ed0fa1b2b5768026e486196d0112a2c46af3f54e 100644 (file)
@@ -294,6 +294,9 @@ class NewnoticeAction extends Action
             if ($profile) {
                 $content = '@' . $profile->nickname . ' ';
             }
+        } else {
+            // @fixme most of these bits above aren't being passed on above
+            $inreplyto = null;
         }
 
         $notice_form = new NoticeForm($this, '', $content, null, $inreplyto);
index 720dedd0a0e67733349288b032605b7ca2e5185a..4ffbba45b96c093574c1a2809fdb88037fba938b 100644 (file)
@@ -222,31 +222,62 @@ class OStatusPlugin extends Plugin
     }
 
     /**
-     *
+     * Find any explicit remote mentions. Accepted forms:
+     *   Webfinger: @user@example.com
+     *   Profile link: @example.com/mublog/user
+     * @param Profile $sender (os user?)
+     * @param string $text input markup text
+     * @param array &$mention in/out param: set of found mentions
+     * @return boolean hook return value
      */
 
     function onEndFindMentions($sender, $text, &$mentions)
     {
-        preg_match_all('/(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)/',
+        preg_match_all('!(?:^|\s+)
+                        @(                                # Webfinger:
+                          (?:\w+\.)*\w+                   #   user
+                          @                               #   @
+                          (?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+ #   domain
+                         |                                # Profile:
+                          (?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+ #   domain
+                          (?:/\w+)+                       #   /path1(/path2...)
+                         )!x',
                        $text,
                        $wmatches,
                        PREG_OFFSET_CAPTURE);
 
         foreach ($wmatches[1] as $wmatch) {
-
-            $webfinger = $wmatch[0];
-
-            $this->log(LOG_INFO, "Checking Webfinger for address '$webfinger'");
-
-            $oprofile = Ostatus_profile::ensureWebfinger($webfinger);
+            $target = $wmatch[0];
+            $oprofile = null;
+
+            if (strpos($target, '/') === false) {
+                $this->log(LOG_INFO, "Checking Webfinger for address '$target'");
+                try {
+                    $oprofile = Ostatus_profile::ensureWebfinger($target);
+                } catch (Exception $e) {
+                    $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
+                }
+            } else {
+                $schemes = array('https', 'http');
+                foreach ($schemes as $scheme) {
+                    $url = "$scheme://$target";
+                    $this->log(LOG_INFO, "Checking profile address '$url'");
+                    try {
+                        $oprofile = Ostatus_profile::ensureProfile($url);
+                        if ($oprofile) {
+                            continue;
+                        }
+                    } catch (Exception $e) {
+                        $this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
+                    }
+                }
+            }
 
             if (empty($oprofile)) {
-
-                $this->log(LOG_INFO, "No Ostatus_profile found for address '$webfinger'");
-
+                $this->log(LOG_INFO, "No Ostatus_profile found for address '$target'");
             } else {
 
-                $this->log(LOG_INFO, "Ostatus_profile found for address '$webfinger'");
+                $this->log(LOG_INFO, "Ostatus_profile found for address '$target'");
 
                 if ($oprofile->isGroup()) {
                     continue;
@@ -261,7 +292,7 @@ class OStatusPlugin extends Plugin
                     }
                 }
                 $mentions[] = array('mentioned' => array($profile),
-                                    'text' => $wmatch[0],
+                                    'text' => $target,
                                     'position' => $pos,
                                     'url' => $profile->profileurl);
             }
index 7b1aec76baa7eac9b73879b108b7e10a8eee85ff..668a31df4c7d8386ba13f0149a5190d0f0b8b02b 100644 (file)
@@ -698,7 +698,7 @@ class Ostatus_profile extends Memcached_DataObject
     {
         // Get the canonical feed URI and check it
         $discover = new FeedDiscovery();
-        if ($hints['feedurl']) {
+        if (isset($hints['feedurl'])) {
             $feeduri = $hints['feedurl'];
             $feeduri = $discover->discoverFromFeedURL($feeduri);
         } else {
index 388df0a28feed184d48df8a1887fb7bc0c5a3044..f8449b309ec11bda481710af91b803118921f89c 100644 (file)
@@ -94,7 +94,7 @@ class Discovery
             $links = call_user_func(array($class, 'discover'), $uri);
             if ($link = Discovery::getService($links, Discovery::LRDD_REL)) {
                 // Load the LRDD XRD
-                if ($link['template']) {
+                if (!empty($link['template'])) {
                     $xrd_uri = Discovery::applyTemplate($link['template'], $uri);
                 } else {
                     $xrd_uri = $link['href'];
index 16d27f8eb7f66072d24f1f5b98ba8606d85c9563..48c1c88e15b3ae850853eee3349444d6ded1a18d 100644 (file)
@@ -156,20 +156,20 @@ class XRD
     function saveLink($doc, $link)
     {
         $link_element = $doc->createElement('Link');
-        if ($link['rel']) {
+        if (!empty($link['rel'])) {
             $link_element->setAttribute('rel', $link['rel']);
         }
-        if ($link['type']) {
+        if (!empty($link['type'])) {
             $link_element->setAttribute('type', $link['type']);
         }
-        if ($link['href']) {
+        if (!empty($link['href'])) {
             $link_element->setAttribute('href', $link['href']);
         }
-        if ($link['template']) {
+        if (!empty($link['template'])) {
             $link_element->setAttribute('template', $link['template']);
         }
 
-        if (is_array($link['title'])) {
+        if (!empty($link['title']) && is_array($link['title'])) {
             foreach($link['title'] as $title) {
                 $title = $doc->createElement('Title', $title);
                 $link_element->appendChild($title);