]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Blog/Blog_entry.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / Blog / Blog_entry.php
index 34e4ea294ec3d1cb01dec3206740fe9e383d8a4d..b40039b2d78677e20460be045cb6b427c63e4c48 100644 (file)
@@ -59,11 +59,11 @@ class Blog_entry extends Managed_DataObject
     public $created; // datetime
     public $modified; // datetime
 
-    const TYPE = 'http://activitystrea.ms/schema/1.0/blog-entry';
+    const TYPE = ActivityObject::ARTICLE;
     
     function staticGet($k, $v=null)
     {
-        return Managed_DataObject::staticGet('blog_entry', $k, $v);
+        return Managed_DataObject::staticGet('Blog_entry', $k, $v);
     }
 
     static function schemaDef()
@@ -99,12 +99,14 @@ class Blog_entry extends Managed_DataObject
                                     'description' => 'date this record was created'),
             ),
             'primary key' => array('id'),
+            'unique keys' => array(
+                'blog_entry_uri_key' => array('uri'),
+            ),
             'foreign keys' => array(
                 'blog_entry_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
             ),
             'indexes' => array(
-                'blog_entry_created_idx' => array('created'),
-                'blog_entry_uri_idx' => array('uri'),
+                'blog_entry_created_idx' => array('created')
             ),
         );
     }
@@ -114,17 +116,24 @@ class Blog_entry extends Managed_DataObject
         if (is_null($options)) {
             $options = array();
         }
-        
+
         $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 {
-            $be->summary = self::summarize($content);
+            // Already purified
+            $be->summary = self::summarize($be->content);
+        }
+
+        // Don't save an identical summary
+
+        if ($be->summary == $be->content) {
+            $be->summary = null;
         }
 
         $url = common_local_url('showblogentry', array('id' => $be->id));
@@ -164,20 +173,23 @@ class Blog_entry extends Managed_DataObject
 
         // XXX: this might be too long.
 
-        $options['rendered'] = $be->summary . ' ' . 
-            XMLStringer::estring('a', array('href' => $shortUrl,
-                                            'class' => 'blog-entry'),
-                                 _('More...'));
+        if (!empty($be->summary)) {
+            $options['rendered'] = $be->summary . ' ' . 
+                XMLStringer::estring('a', array('href' => $url,
+                                                'class' => 'blog-entry'),
+                                     _('More...'));
+            $text = html_entity_decode(strip_tags($be->summary), ENT_QUOTES, 'UTF-8');
+        } else {
+            $options['rendered'] = $be->content;
+            $text = html_entity_decode(strip_tags($be->content), ENT_QUOTES, 'UTF-8');
+        }
 
-        $summaryText = html_entity_decode(strip_tags($summary), ENT_QUOTES, 'UTF-8');
 
-        if (Notice::contentTooLong($summaryText)) {
-            $summaryText = substr($summaryText, 0, Notice::maxContent() - mb_strlen($shortUrl) - 2) .
+        if (Notice::contentTooLong($text)) {
+            $text = substr($text, 0, Notice::maxContent() - mb_strlen($shortUrl) - 2) .
                 '… ' . $shortUrl;
         }
 
-        $content = $summaryText;
-
         // Override this no matter what.
         
         $options['object_type'] = self::TYPE;
@@ -185,7 +197,9 @@ class Blog_entry extends Managed_DataObject
         $source = array_key_exists('source', $options) ?
                                     $options['source'] : 'web';
         
-        Notice::saveNew($profile->id, $content, $source, $options);
+        $saved = Notice::saveNew($profile->id, $text, $source, $options);
+
+        return $saved;
     }
 
     /**
@@ -230,4 +244,18 @@ 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*');
+        $pure = htmLawed($html, $config);
+
+        return $pure;
+    }
 }