From c2d7a08d074fd050ea027f57caa3f290c031aa79 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 23 Jan 2011 12:57:20 -0500 Subject: [PATCH] Bookmark saving robustness fixes First, if the tags box is empty, don't save an empty tag for the notice. Second, if URL shortening fails, just use the regular URL. --- plugins/Bookmark/Bookmark.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/Bookmark/Bookmark.php b/plugins/Bookmark/Bookmark.php index 4ee287fb65..777b50f724 100644 --- a/plugins/Bookmark/Bookmark.php +++ b/plugins/Bookmark/Bookmark.php @@ -214,7 +214,11 @@ class Bookmark extends Memcached_DataObject } if (is_string($rawtags)) { - $rawtags = preg_split('/[\s,]+/', $rawtags); + if (empty($rawtags)) { + $rawtags = array(); + } else { + $rawtags = preg_split('/[\s,]+/', $rawtags); + } } $nb = new Bookmark(); @@ -274,10 +278,15 @@ class Bookmark extends Memcached_DataObject // Use user's preferences for short URLs, if possible - $user = User::staticGet('id', $profile->id); + try { + $user = User::staticGet('id', $profile->id); - $shortUrl = File_redirection::makeShort($url, - empty($user) ? null : $user); + $shortUrl = File_redirection::makeShort($url, + empty($user) ? null : $user); + } catch (Exception $e) { + // Don't let this stop us. + $shortUrl = $url; + } $content = sprintf(_('"%s" %s %s %s'), $title, -- 2.39.5