parameters
+$params->{fhid}
+$params->{subid}
+
=item $uid
author's uid
=cut
sub create {
- my ($self, $params, $uid) = @_;
- #createStory
+ my ($self, $params, $user, $extra_params, $opts) = @_;
+
+ # check parameters
+ my $msg = "";
+ $msg = "no title" if !$params->{title};
+ $msg = "no title" if !$params->{title};
+ $msg = "no uid" if !$params->{uid};
+ $msg = "no topics" if !defined $params->{topics_chosen};
+
+ if (length($params->{title}) > $self->{options}->{Story}->{title_max_byte}) {
+ $msg = "title too long. max: $self->{options}->{Story}->{title_max_byte} bytes";
+ }
- #my $slash_db = $self->new_instance_of('Newslash::Model::SlashDB');
+ $params->{commentstatus} ||= "enabled";
+ if (!grep /\A$params->{commentstatus}\z/, qw(disabled enabled friends_only friends_fof_only no_foe no_foe_eof logged_in)) {
+ $msg = "invalid commentstatus";
+ }
+
+ # check timestamp. use ISO8601 style timestamp like: 2006-08-14T02:34:56-0600
+ my $rex_timestamp = qr/
+ ^(\d+)-(\d+)-(\d+)\D+(\d+):(\d+):(\d+(?:\.\d+)?) # datetime
+ (?:Z|([+-])(\d+):(\d+))?$ # tz
+ /xi;
+ if ($params->{createtime} =~ $rex_timestamp) {
+ $params->{createtime} = "$1-$2-$3 $4:$5:$6";
+ }
+
+ # check parameters finish
+ if (length($msg) > 0) {
+ $self->set_error($msg, -1);
+ return;
+ }
+
+ $params->{neverdisplay} ||= 0;
my $slash_db = Newslash::Model::SlashDB->new($self->{options});
- #my $slash_db = $self->new_instance_of('SlashDB');
- my $story = $slash_db->createStory($params);
- return $story;
+ my $sid = $slash_db->createStory($params);
+ #my $globj_id = $slash_db->
+
+ # TODO: set tags
+ # my $tags = $self->new_instance_of("Newslash::Model::Tags");
+ for my $tid (keys $params->{topics_chosen}) {
+ $tags->createTag({
+ uid => $user->{uid},
+ name => "",
+ globijd => $globj_id,
+ private => 0,
+ });
+ }
+ return $sid;
}
sub createSid {