diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php index b509def613..c0894c5dba 100644 --- a/actions/apitimelineuser.php +++ b/actions/apitimelineuser.php @@ -384,7 +384,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction // Get (safe!) HTML and text versions of the content $rendered = $this->purify($sourceContent); - $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8'); + $content = common_strip_html($rendered); $shortened = $this->auth_user->shortenLinks($content); diff --git a/classes/Notice.php b/classes/Notice.php index df7105116d..88a1394b88 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -769,9 +769,10 @@ class Notice extends Managed_DataObject $stored->verb = $act->verb; // Use the local user's shortening preferences, if applicable. - $stored->content = $actor->isLocal() + $stored->rendered = $actor->isLocal() ? $actor->shortenLinks($act->content) : $act->content; + $stored->content = common_strip_html($stored->rendered); $autosource = common_config('public', 'autosource'); diff --git a/lib/activityimporter.php b/lib/activityimporter.php index 8846831b90..4e13419ae7 100644 --- a/lib/activityimporter.php +++ b/lib/activityimporter.php @@ -214,7 +214,7 @@ class ActivityImporter extends QueueHandler // Get (safe!) HTML and text versions of the content $rendered = $this->purify($sourceContent); - $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8'); + $content = common_strip_html($rendered); $shortened = $user->shortenLinks($content); diff --git a/lib/activityobject.php b/lib/activityobject.php index d0b929245e..7fe5c4850c 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -200,7 +200,7 @@ class ActivityObject $title = ActivityUtils::childHtmlContent($element, self::TITLE); if (!empty($title)) { - $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8'); + $this->title = common_strip_html($title); } // fall back to @@ -251,10 +251,7 @@ class ActivityObject $this->content = ActivityUtils::getContent($element); // We don't like HTML in our titles, although it's technically allowed - - $title = ActivityUtils::childHtmlContent($element, self::TITLE); - - $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8'); + $this->title = common_strip_html(ActivityUtils::childHtmlContent($element, self::TITLE)); $this->source = $this->_getSource($element); diff --git a/lib/util.php b/lib/util.php index dd4be87849..fd89bb491c 100644 --- a/lib/util.php +++ b/lib/util.php @@ -2360,3 +2360,12 @@ function common_log_delta($comment=null) common_debug(sprintf("%s: %d %d", $comment, $mtotal, round($ttotal * 1000000))); } + +function common_strip_html($html, $trim=true, $save_whitespace=false) +{ + if (!$save_whitespace) { + $html = preg_replace('/\s+/', ' ', $html); + } + $text = html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8'); + return $trim ? trim($text) : $text; +} diff --git a/plugins/Blog/classes/Blog_entry.php b/plugins/Blog/classes/Blog_entry.php index 5e0effcc74..20bf4da83f 100644 --- a/plugins/Blog/classes/Blog_entry.php +++ b/plugins/Blog/classes/Blog_entry.php @@ -174,10 +174,10 @@ class Blog_entry extends Managed_DataObject XMLStringer::estring('a', array('href' => $url, 'class' => 'blog-entry'), _('More...')); - $text = html_entity_decode(strip_tags($be->summary), ENT_QUOTES, 'UTF-8'); + $text = common_strip_html($be->summary); } else { $options['rendered'] = $be->content; - $text = html_entity_decode(strip_tags($be->content), ENT_QUOTES, 'UTF-8'); + $text = common_strip_html($be->content); } diff --git a/plugins/DomainStatusNetwork/lib/domainstatusnetworkinstaller.php b/plugins/DomainStatusNetwork/lib/domainstatusnetworkinstaller.php index 3780ff9e4f..0547a2596f 100644 --- a/plugins/DomainStatusNetwork/lib/domainstatusnetworkinstaller.php +++ b/plugins/DomainStatusNetwork/lib/domainstatusnetworkinstaller.php @@ -341,7 +341,7 @@ class DomainStatusNetworkInstaller extends Installer $breakout = preg_replace('/+]\bhref="(.*)"[^>]*>(.*)<\/a>/', '\2 <\1>', $html); - return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8'); + return common_strip_html($breakout); } function databaseize($nickname) diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index e6db40c5a8..72a0c34b92 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -607,7 +607,7 @@ class Ostatus_profile extends Managed_DataObject // Get (safe!) HTML and text versions of the content $rendered = $this->purify($sourceContent); - $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8'); + $content = common_strip_html($rendered); $shortened = common_shorten_links($content); @@ -618,7 +618,7 @@ class Ostatus_profile extends Managed_DataObject if (Notice::contentTooLong($shortened)) { $attachment = $this->saveHTMLFile($activity->title, $rendered); - $summary = html_entity_decode(strip_tags($activity->summary), ENT_QUOTES, 'UTF-8'); + $summary = common_strip_html($activity->summary); if (empty($summary)) { $summary = $content; } @@ -774,7 +774,7 @@ class Ostatus_profile extends Managed_DataObject // Get (safe!) HTML and text versions of the content $rendered = $this->purify($sourceContent); - $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8'); + $content = common_strip_html($rendered); $shortened = common_shorten_links($content); @@ -785,7 +785,7 @@ class Ostatus_profile extends Managed_DataObject if (Notice::contentTooLong($shortened)) { $attachment = $this->saveHTMLFile($note->title, $rendered); - $summary = html_entity_decode(strip_tags($note->summary), ENT_QUOTES, 'UTF-8'); + $summary = common_strip_html($note->summary); if (empty($summary)) { $summary = $content; } diff --git a/plugins/TinyMCE/TinyMCEPlugin.php b/plugins/TinyMCE/TinyMCEPlugin.php index fff3138347..08da1048fc 100644 --- a/plugins/TinyMCE/TinyMCEPlugin.php +++ b/plugins/TinyMCE/TinyMCEPlugin.php @@ -104,17 +104,6 @@ class TinyMCEPlugin extends Plugin return htmLawed($raw, $config); } - /** - * Strip HTML to plaintext string - * - * @param string $html HTML - * @return string plaintext, single line - */ - private function stripHtml($html) - { - return str_replace("\n", " ", html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8')); - } - /** * Hook for new-notice form processing to take our HTML goodies; * won't affect API posting etc. @@ -130,7 +119,7 @@ class TinyMCEPlugin extends Plugin if ($action->arg('richedit') && $this->isAllowedRichEdit()) { $html = $this->sanitizeHtml($content); $options['rendered'] = $html; - $content = $this->stripHtml($html); + $content = common_strip_html($html); } return true; }