]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Unifying HTML stripping functions to common_strip_html
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 14 Jul 2014 11:52:23 +0000 (13:52 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 14 Jul 2014 11:52:23 +0000 (13:52 +0200)
actions/apitimelineuser.php
classes/Notice.php
lib/activityimporter.php
lib/activityobject.php
lib/util.php
plugins/Blog/classes/Blog_entry.php
plugins/DomainStatusNetwork/lib/domainstatusnetworkinstaller.php
plugins/OStatus/classes/Ostatus_profile.php
plugins/TinyMCE/TinyMCEPlugin.php

index b509def613d29bbb26a9ace44d76375904dc7d07..c0894c5dbaa69491eae1725def746626f66bd477 100644 (file)
@@ -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);
 
index df7105116d9b0f475411ea6076436c783ef179c4..88a1394b88b3a8b7767c0cec73fa7c90c69bc5b7 100644 (file)
@@ -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');
 
index 8846831b9062205532a0cdd65a7a1ae00ff1d73a..4e13419ae7482ccd0aed3eac7ffad9e15e6ca789 100644 (file)
@@ -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);
 
index d0b929245e152e0ecd8a65d568ea39999f905a8b..7fe5c4850ca723105e4bfb82efb56d03450699f7 100644 (file)
@@ -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 <atom:name>
@@ -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);
 
index dd4be87849510dd7027e1d992ae05b8445c7a39b..fd89bb491cd44d2e3351854ae16654029b783ae1 100644 (file)
@@ -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;
+}
index 5e0effcc74e8c2fc7fbc27795bc8291d398e459c..20bf4da83f6f12bdd98dbd16b4ab7cfecb6ab472 100644 (file)
@@ -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);
         }
 
 
index 3780ff9e4fe7a6d4d80618f5e9a356f899941e04..0547a2596f610aacf1ad8029d3af2e367ec6b0cf 100644 (file)
@@ -341,7 +341,7 @@ class DomainStatusNetworkInstaller extends Installer
         $breakout = preg_replace('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
                                  '\2 &lt;\1&gt;',
                                  $html);
-        return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
+        return common_strip_html($breakout);
     }
 
     function databaseize($nickname)
index e6db40c5a8e777704202f0c61f39f39f83b3c2c2..72a0c34b92128b074da408530df2f87debe7b20d 100644 (file)
@@ -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;
             }
index fff313834749c86c5c2f2cb66e612bad171e3eef..08da1048fc12f282fee1cac7988c904bd13b6836 100644 (file)
@@ -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;
     }