OSDN Git Service

fix text format-related functions
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Web / Controller / API / Submission.pm
index 928d5ec..480badd 100644 (file)
@@ -82,24 +82,25 @@ sub post {
     }
 
     my $submissions = $c->model('submissions');
-    my $util = $c->model('util');
 
-    my $allowed = $c->app->config->{Editor}->{allowed_tags};
     my $data = $c->req->json;
     my $item = $data->{item};
     my $message = "";
 
     # check body
-    if ($item->{introtext}) {
-        my $text = $item->{introtext};
+    if ($item->{introtext} || $item->{intro_text}) {
+        my $text = $item->{introtext} || $item->{intro_text};
         $text =~ s/\s+\z//m;
-        $params->{introtext} = $util->clean_html($allowed, $text);
+        $params->{introtext} = $c->format_htmltext($text, "submission");
         $params->{introtext} =~ s/\s+\z//m;
     }
+    else {
+        $params->{introtext} = "";
+    }
     $message = "no_content" if (!$params->{introtext} && !$item->{url});
 
     # check title
-    $params->{title} = $util->escape_html({}, $item->{title});
+    $params->{title} = $c->escape_title($item->{title});
     $message = "no_title" if !$params->{title};
 
     # check URL
@@ -107,6 +108,8 @@ sub post {
         my $url = Mojo::URL->new($item->{url});
         if ($url->is_abs) {
             $params->{url} = $item->{url};
+            my $footer = $c->tt2renderer->render("system/submission/footer", {url => $item->{url}});
+            $params->{introtext} = $params->{introtext} . $footer;
         }
         else {
             $message = "invalid_url";
@@ -134,7 +137,7 @@ sub post {
 
     # parse tags
     #$params->{tid} = 49; #mainpage
-    my $tags_string = $item->{tags_string};
+    my $tags_string = $item->{tags_string} || "";
     my @tags = split(/\s+/, $tags_string);
     my $topic = $c->model('topics')->get_primary_topic_from_tags(\@tags) || {};
     $params->{tid} = $topic->{tid} || 49;