]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
better management of HTML input
authorEvan Prodromou <evan@status.net>
Mon, 20 Jun 2011 15:01:50 +0000 (11:01 -0400)
committerEvan Prodromou <evan@status.net>
Mon, 20 Jun 2011 15:01:50 +0000 (11:01 -0400)
plugins/Blog/Blog_entry.php
plugins/Blog/blogentrylistitem.php

index 54bd445930069bd2f75f57e10742888b04dc7347..72cee91a792f29e31a1351bae19a823ef9e965c5 100644 (file)
@@ -118,12 +118,13 @@ class Blog_entry extends Managed_DataObject
         $be             = new Blog_entry();
         $be->id         = (string) new UUID();
         $be->profile_id = $profile->id;
-        $be->title      = htmlspecialchars($title);
-        $be->content    = $content;
+        $be->title      = $title; // Note: not HTML-protected
+        $be->content    = self::purify($content);
         
         if (array_key_exists('summary', $options)) {
-            $be->summary = $options['summary'];
+            $be->summary = self::purify($options['summary']);
         } else {
+            // Already purified
             $be->summary = self::summarize($content);
         }
 
@@ -175,13 +176,10 @@ class Blog_entry extends Managed_DataObject
                 XMLStringer::estring('a', array('href' => $url,
                                                 'class' => 'blog-entry'),
                                      _('More...'));
-            $content = html_entity_decode(strip_tags($text), ENT_QUOTES, 'UTF-8');
-
+            $content = html_entity_decode(strip_tags($be->summary), ENT_QUOTES, 'UTF-8');
         } else {
-            $options['rendered'] = $be->content . ' ' . 
-                XMLStringer::estring('a', array('href' => $url,
-                                                'class' => 'blog-entry'),
-                                     _('More...'));
+            $options['rendered'] = $be->content;
+            $content = html_entity_decode(strip_tags($be->content), ENT_QUOTES, 'UTF-8');
         }
 
 
@@ -244,4 +242,15 @@ class Blog_entry extends Managed_DataObject
 
         return $obj;
     }
+
+    /**
+     * Clean up input HTML
+     */
+    static function purify($html)
+    {
+        require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
+        $config = array('safe' => 1,
+                        'deny_attribute' => 'id,style,on*');
+        return htmLawed($html, $config);
+    }
 }
index ee937daa7728e7cdbba331636de88f5c32e270f7..374c4560284be4f6d9955a8084472dd9d864e299 100644 (file)
@@ -72,10 +72,14 @@ class BlogEntryListItem extends NoticeListItemAdapter
         $out->elementEnd('h4');
 
         if (!empty($entry->summary)) {
-            $out->element('div', 'blog-entry-summary', $entry->summary);
+            $out->elementStart('div', 'blog-entry-summary');
+            $out->raw($entry->summary);
+            $out->elementEnd('div');
         } else {
             // XXX: hide content initially; click More... for full text.
-            $out->element('div', 'blog-entry-content', $entry->content);
+            $out->elementStart('div', 'blog-entry-content');
+            $out->raw($entry->content);
+            $out->elementEnd('div');
         }
     }
 }