$journal->{primary_topic} = $primary_topic;
$journal->{topics} = [$primary_topic,];
$journal->{content_type} = 'journal';
+ $journal->{bodytext} = $self->article_to_bodytext($journal->{article}, $journal->{posttype});
return $journal;
}
sub article_to_introtext {
my ($self, $article, $posttype) = @_;
- my $html;
- my $allowed = {
- 'b' => [],
- 'i' => [],
- 'p' => [],
- 'br' => [],
- 'a' => ['href',],
- 'ol' => ['start',],
- 'ul' => [],
- 'li' => [],
- 'dl' => [],
- 'dt' => [],
- 'dd' => [],
- 'em' => [],
- 'strong' => [],
- 'tt' => [],
- 'blockquote' => ['title', 'cite',],
- 'div' => [],
- 'ecode' => [],
- 'del' => [],
- 'ins' => [],
- 'sub' => [],
- 'sup' => [],
- 'quote' => [],
- 'strike' => [],
- };
-
my $util = $self->new_instance_of("Newslash::Model::Util");
- # posttype: 1: PLAINTEXT, 2: HTML, 3: EXTRANS, 4: CODE, 77: FULLHTML
- if ($posttype == 1) { # PLAINTEXT
- $html = $util->escape_plaintext($allowed, $article);
- }
- if ($posttype == 2) { # HTML
- $html = $util->clean_html($allowed, $article);
- }
- if ($posttype == 3) { # LEGACY HTML (HTML OK)
- my $t = $article;
- $t =~ s/\r\n/<br>/g; # conert CRLF
- $t =~ s/(\r|\n)/<br>/g; # convert CR/LF
- $html = $util->escape_html($allowed, $t);
- }
+ my $html = $self->article_to_fulltext($article, $posttype);
my $min_chars = 50;
my $max_chars = 500;
my $intro_text;
sub article_to_bodytext {
my ($self, $article, $posttype) = @_;
+ my $util = $self->new_instance_of("Newslash::Model::Util");
+ my $html = $self->article_to_fulltext($article, $posttype);
+ my $min_chars = 50;
+ my $max_chars = 500;
+ if (length $html < $min_chars) {
+ return "";
+ }
+ else {
+ my $linebreak = qr{(?:
+ <br>\s*<br> |
+ </?p> |
+ </(?:
+ div | (?:block)?quote | [oud]l
+ )>
+ )}x;
+ my $intro_text = $1 if $html =~ m/^(.{$min_chars,$max_chars})?$linebreak/s;
+ my $body_text = substr $html, length($intro_text);
+ $body_text = $util->tidy_html($body_text);
+ return $body_text;
+ }
+}
+
+sub article_to_fulltext {
+ my ($self, $article, $posttype) = @_;
my $html;
my $allowed = {
'b' => [],