From 639cf48cc7864ccd224d14498a2a6d4659e893e4 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 19 Apr 2014 22:18:36 +0200 Subject: [PATCH] OStatus onStartNoticeSourceLink to use exceptions --- plugins/OStatus/OStatusPlugin.php | 41 +++++++++++++++++++------------ 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index eeb3fffd28..f32b437f86 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -523,23 +523,32 @@ class OStatusPlugin extends Plugin */ function onStartNoticeSourceLink($notice, &$name, &$url, &$title) { - if ($notice->source == 'ostatus') { - if ($notice->url) { - $bits = parse_url($notice->url); - $domain = $bits['host']; - if (substr($domain, 0, 4) == 'www.') { - $name = substr($domain, 4); - } else { - $name = $domain; - } - - $url = $notice->url; - // TRANS: Title. %s is a domain name. - $title = sprintf(_m('Sent from %s via OStatus'), $domain); - return false; - } + // If we don't handle this, keep the event handler going + if ($notice->source != 'ostatus') { + return true; + } + + try { + $url = $notice->getUrl(); + // If getUrl() throws exception, $url is never set + + $bits = parse_url($url); + $domain = $bits['host']; + if (substr($domain, 0, 4) == 'www.') { + $name = substr($domain, 4); + } else { + $name = $domain; + } + + // TRANS: Title. %s is a domain name. + $title = sprintf(_m('Sent from %s via OStatus'), $domain); + + // Abort event handler, we have a name and URL! + return false; + } catch (InvalidUrlException $e) { + // This just means we don't have the notice source data + return true; } - return true; } /**