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()
'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')
),
);
}
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));
// 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;
$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;
}
/**
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;
+ }
}