From ffa1931c9dafea385e8f30c53ea079e2425a0786 Mon Sep 17 00:00:00 2001
From: Brion Vibber <brion@pobox.com>
Date: Wed, 3 Mar 2010 09:31:14 -0800
Subject: Avoid warning/notice spew in XRD parser. Not all DOM nodes are
 elements.

---
 plugins/OStatus/lib/xrd.php | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'plugins/OStatus')

diff --git a/plugins/OStatus/lib/xrd.php b/plugins/OStatus/lib/xrd.php
index 85df26c54..f00e1f809 100644
--- a/plugins/OStatus/lib/xrd.php
+++ b/plugins/OStatus/lib/xrd.php
@@ -149,9 +149,11 @@ class XRD
         $link['href'] = $element->getAttribute('href');
         $link['template'] = $element->getAttribute('template');
         foreach ($element->childNodes as $node) {
-            switch($node->tagName) {
-            case 'Title':
-                $link['title'][] = $node->nodeValue;
+            if ($node instanceof DOMElement) {
+                switch($node->tagName) {
+                case 'Title':
+                    $link['title'][] = $node->nodeValue;
+                }
             }
         }
 
-- 
cgit v1.2.3-54-g00ecf


From 1e63fda6695c8ab06f2cd8181de26f03f7f7a5d4 Mon Sep 17 00:00:00 2001
From: Brion Vibber <brion@pobox.com>
Date: Wed, 3 Mar 2010 09:32:25 -0800
Subject: Clean up OStatus mentions finding; separate regexes keeps the code
 paths a bit clearer. Also switched to hitting HTTP profile first; as the
 common case it'll be faster.

---
 plugins/OStatus/OStatusPlugin.php | 86 +++++++++++++++++++--------------------
 1 file changed, 43 insertions(+), 43 deletions(-)

(limited to 'plugins/OStatus')

diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index 7b6d22acf..f435d6283 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -233,70 +233,70 @@ class OStatusPlugin extends Plugin
 
     function onEndFindMentions($sender, $text, &$mentions)
     {
-        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',
+        $matches = array();
+
+        // Webfinger matches: @user@example.com
+        if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
                        $text,
                        $wmatches,
-                       PREG_OFFSET_CAPTURE);
-
-        foreach ($wmatches[1] as $wmatch) {
-            $target = $wmatch[0];
-            $oprofile = null;
-
-            if (strpos($target, '/') === false) {
-                $this->log(LOG_INFO, "Checking Webfinger for address '$target'");
+                       PREG_OFFSET_CAPTURE)) {
+            foreach ($wmatches[1] as $wmatch) {
+                list($target, $pos) = $wmatch;
+                $this->log(LOG_INFO, "Checking webfinger '$target'");
                 try {
                     $oprofile = Ostatus_profile::ensureWebfinger($target);
+                    if ($oprofile && !$oprofile->isGroup()) {
+                        $profile = $oprofile->localProfile();
+                        $matches[$pos] = array('mentioned' => array($profile),
+                                               'text' => $target,
+                                               'position' => $pos,
+                                               'url' => $profile->profileurl);
+                    }
                 } catch (Exception $e) {
                     $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
                 }
-            } else {
-                $schemes = array('https', 'http');
+            }
+        }
+
+        // Profile matches: @example.com/mublog/user
+        if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)!',
+                       $text,
+                       $wmatches,
+                       PREG_OFFSET_CAPTURE)) {
+            foreach ($wmatches[1] as $wmatch) {
+                list($target, $pos) = $wmatch;
+                $schemes = array('http', 'https');
                 foreach ($schemes as $scheme) {
                     $url = "$scheme://$target";
                     $this->log(LOG_INFO, "Checking profile address '$url'");
                     try {
                         $oprofile = Ostatus_profile::ensureProfile($url);
-                        if ($oprofile) {
-                            continue;
+                        if ($oprofile && !$oprofile->isGroup()) {
+                            $profile = $oprofile->localProfile();
+                            $matches[$pos] = array('mentioned' => array($profile),
+                                                   'text' => $target,
+                                                   'position' => $pos,
+                                                   'url' => $profile->profileurl);
+                            break;
                         }
                     } 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 '$target'");
-            } else {
-
-                $this->log(LOG_INFO, "Ostatus_profile found for address '$target'");
-
-                if ($oprofile->isGroup()) {
-                    continue;
-                }
-                $profile = $oprofile->localProfile();
-
-                $pos = $wmatch[1];
-                foreach ($mentions as $i => $other) {
-                    // If we share a common prefix with a local user, override it!
-                    if ($other['position'] == $pos) {
-                        unset($mentions[$i]);
-                    }
-                }
-                $mentions[] = array('mentioned' => array($profile),
-                                    'text' => $target,
-                                    'position' => $pos,
-                                    'url' => $profile->profileurl);
+        foreach ($mentions as $i => $other) {
+            // If we share a common prefix with a local user, override it!
+            $pos = $other['position'];
+            if (isset($matches[$pos])) {
+                $mentions[$i] = $matches[$pos];
+                unset($matches[$pos]);
             }
         }
+        foreach ($matches as $mention) {
+            $mentions[] = $mention;
+        }
 
         return true;
     }
-- 
cgit v1.2.3-54-g00ecf


From f3cea2430497e751bc7776fe3abf0603e2b55f8b Mon Sep 17 00:00:00 2001
From: Brion Vibber <brion@pobox.com>
Date: Wed, 3 Mar 2010 09:36:26 -0800
Subject: Fix for hcard parsing: typo caused notice spew accessing unset array
 index

---
 plugins/OStatus/classes/Ostatus_profile.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'plugins/OStatus')

diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 059c19e7c..7ab031aa5 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -1500,7 +1500,7 @@ class Ostatus_profile extends Memcached_DataObject
         if (array_key_exists('url', $hcard)) {
             if (is_string($hcard['url'])) {
                 $hints['homepage'] = $hcard['url'];
-            } else if (is_array($hcard['adr'])) {
+            } else if (is_array($hcard['url'])) {
                 // HACK get the last one; that's how our hcards look
                 $hints['homepage'] = $hcard['url'][count($hcard['url'])-1];
             }
-- 
cgit v1.2.3-54-g00ecf