Skip to content

Commit

Permalink
new story saving scheme to be tested
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptTofu committed Mar 29, 2002
1 parent ecfd7e8 commit f0227f2
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 59 deletions.
63 changes: 31 additions & 32 deletions Slash/DB/MySQL/MySQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ my %descriptions = (
'generic'
=> sub { $_[0]->sqlSelectMany('code,name', 'code_param', "type='$_[2]'") },

'genericstring'
=> sub { $_[0]->sqlSelectMany('code,name', 'string_param', "type='$_[2]'") },

'statuscodes'
=> sub { $_[0]->sqlSelectMany('code,name', 'code_param', "type='statuscodes'") },

Expand Down Expand Up @@ -610,9 +613,9 @@ sub getSectionExtras {
return unless $section;

my $answer = $self->sqlSelectAll(
'name,value',
'name,value,type,section',
'section_extras',
'section=' . $self->sqlQuote($section)
'section ='. $self->sqlQuote($section)
);

return $answer;
Expand Down Expand Up @@ -778,7 +781,7 @@ sub getDiscussionsUserCreated {
unless $all;

if ($section) {
$where .= " AND discussions.section = '$section'"
$where .= " AND discussions.section = '$section'";
} else {
$tables .= ", sections";
$where .= " AND sections.section = discussions.section AND sections.isolate != 1 ";
Expand Down Expand Up @@ -1968,6 +1971,7 @@ sub setStory {
}

for (@param) {
print STDERR "saving param name $_->[0] value $_->[1] into $param_table\n";
$self->sqlReplace($param_table, {
sid => $sid,
name => $_->[0],
Expand Down Expand Up @@ -4029,17 +4033,23 @@ sub createDiscussion {
$discussion->{uid} ||= getCurrentUser('uid');
# commentcount and flags set to defaults

print STDERR "getting ready to create discussion \n";
$self->sqlInsert('discussions', $discussion);

my $discussion_id = $self->getLastInsertId();
print STDERR "inserted discussion $discussion_id\n";

return $discussion_id;
}

########################################################
sub createStory {
my($self, $story) = @_;

my $constants = getCurrentStatic();

$story ||= getCurrentForm();

# Create a sid
my($sec, $min, $hour, $mday, $mon, $year) = localtime;
$year = $year % 100;
Expand Down Expand Up @@ -4080,32 +4090,13 @@ sub createStory {
if ($isolate);
}

my $data = {
sid => $sid,
uid => $story->{uid},
tid => $story->{tid},
dept => $story->{dept},
'time' => $story->{'time'},
day_published => $story->{'time'},
title => $story->{title},
section => $story->{section},
displaystatus => $story->{displaystatus},
commentstatus => $story->{commentstatus},
submitter => $story->{submitter} ?
$story->{submitter} : $story->{uid},
writestatus => 'dirty',
};

my $text = {
sid => $sid,
bodytext => $story->{bodytext},
introtext => $story->{introtext},
relatedtext => $story->{relatedtext},
};
$story->{submitter} = $story->{submitter} ?
$story->{submitter} : $story->{uid};
$story->{writestatus} = 'dirty',

$self->sqlInsert('stories', $data);
$self->sqlInsert('story_text', $text);
$self->_saveExtras($story);
$self->sqlInsert('stories', { sid => $story->{sid}});
$self->sqlInsert('story_text', { sid => $story->{sid}});
$self->setStory($story->{sid}, $story);

return $sid;
}
Expand All @@ -4126,17 +4117,22 @@ sub updateStory {
if ($isolate);
}

$self->sqlUpdate('discussions', {
my $data = {
sid => $story->{sid},
title => $story->{title},
section => $story->{section},
url => "$constants->{rootdir}/article.pl?sid=$story->{sid}",
ts => $time,
topic => $story->{tid},
}, 'sid = ' . $self->sqlQuote($story->{sid}));
};


$self->sqlUpdate('discussions', $data,
'sid = ' . $self->sqlQuote($story->{sid}));

$data = {};

$self->sqlUpdate('stories', {
$data = {
uid => $story->{uid},
tid => $story->{tid},
dept => $story->{dept},
Expand All @@ -4147,7 +4143,10 @@ sub updateStory {
displaystatus => $story->{displaystatus},
commentstatus => $story->{commentstatus},
writestatus => $story->{writestatus},
}, 'sid=' . $self->sqlQuote($story->{sid}));
};

$self->sqlUpdate('stories', $data,
'sid=' . $self->sqlQuote($story->{sid}));

$self->sqlUpdate('story_text', {
bodytext => $story->{bodytext},
Expand Down
107 changes: 88 additions & 19 deletions plugins/Admin/admin.pl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ sub blockEdit {

$blockref->{rss_template} ||= $constants->{default_rss_template};
my $rss_select = createSelect('rss_template', $rss_ref, $blockref->{rss_template}, 1);
my $template_ref = $slashdb->getTemplateByName($blockref->{rss_template}, [ 'template' ], 1 , 'portald', 'default');
my $template_ref = $slashdb->getTemplateByName($blockref->{rss_template}, [ 'template' ], 1 , 'portald', $blockref->{section});
my $rss_template_code = $template_ref->{template};

if ($form->{blockdelete} || $form->{blockdelete1} || $form->{blockdelete2}) {
Expand Down Expand Up @@ -900,14 +900,16 @@ sub editStory {
}

my($authoredit_flag, $extracolumn_flag) = (0, 0);
my($storyref, $story, $author, $topic, $storycontent, $storybox, $locktest,
my($storyref, $story, $author, $topic, $storycontent, $locktest,
$sections, $topic_select, $section_select, $author_select,
$extracolumns, $displaystatus_select, $commentstatus_select, $description);
my $extracolref = {};
my($fixquotes_check, $autonode_check,
$fastforward_check, $shortcuts_check, $feature_story_check) =
('','','','','');
my($multi_topics, $story_topics);
my $page = 'index';
my $section = $user->{section} ? $user->{section} : '';

for (keys %{$form}) { $storyref->{$_} = $form->{$_} }

Expand Down Expand Up @@ -961,28 +963,28 @@ sub editStory {
$storyref->{relatedtext} = getRelated("$storyref->{title} $storyref->{bodytext} $storyref->{introtext}")
. otherLinks($slashdb->getAuthor($storyref->{uid}, 'nickname'), $storyref->{tid}, $storyref->{uid});

$storybox = fancybox($constants->{fancyboxwidth}, 'Related Links', $storyref->{relatedtext}, 0, 1);
# Get wordcounts
$storyref->{introtext_wordcount} = countWords($storyref->{introtext});
$storyref->{bodytext_wordcount} = countWords($storyref->{bodytext});
$feature_story_check = 'CHECKED' if ($slashdb->getSection($storyref->{section}, 'feature_story') eq $storyref->{sid} && $storyref->{sid} ne '');

} elsif (defined $sid) { # Loading an existing SID
my $tmp = $user->{currentSection};
$user->{currentSection} = $slashdb->getStory($sid, 'section', 1);
($story, $storyref, $author, $topic) = displayStory($sid, 'Full');
$extracolumns = $slashdb->getSectionExtras($user->{currentSection}) || [ ];
$user->{currentSection} = $tmp;
$storybox = fancybox($constants->{fancyboxwidth}, 'Related Links', $storyref->{relatedtext}, 0, 1);
# Get wordcounts
$storyref->{introtext_wordcount} = countWords($storyref->{introtext});
$storyref->{bodytext_wordcount} = countWords($storyref->{bodytext});
$feature_story_check = 'CHECKED' if ($slashdb->getSection($storyref->{section}, 'feature_story') eq $storyref->{sid} && $storyref->{sid} ne '');

} else { # New Story
$extracolumns = $slashdb->getSectionExtras($storyref->{section}) || [ ];
$storyref->{displaystatus} = $slashdb->getVar('defaultdisplaystatus', 'value');
$storyref->{commentstatus} = $slashdb->getVar('defaultcommentstatus', 'value');
$storyref->{tid} = $slashdb->getVar('defaulttopic', 'value');
$storyref->{section} = $slashdb->getVar('defaultsection', 'value');
$extracolumns = $slashdb->getSectionExtras($storyref->{section}) || [ ];
$storyref->{displaystatus} = $slashdb->getVar('defaultdisplaystatus', 'value');
$storyref->{commentstatus} = $slashdb->getVar('defaultcommentstatus', 'value');
$storyref->{tid} = $slashdb->getVar('defaulttopic', 'value');
$storyref->{section} = $user->{section} ? $user->{section} : $slashdb->getVar('defaultsection', 'value');

$storyref->{'time'} = $slashdb->getTime();
$storyref->{uid} = $user->{uid};
Expand Down Expand Up @@ -1028,8 +1030,6 @@ sub editStory {
$autonode_check = 'CHECKED' if $form->{autonode};
$fastforward_check = 'CHECKED' if $form->{fastforward};
$shortcuts_check = 'CHECKED' if $form->{shortcuts};
# $feature_story_check = 'CHECKED' if $form->{feature_story};
$feature_story_check = 'CHECKED' if ($slashdb->getSection($storyref->{section}, 'feature_story') eq $storyref->{sid});

$slashdb->setSession($user->{uid}, { lasttitle => $storyref->{title} });

Expand All @@ -1047,14 +1047,12 @@ sub editStory {
future => $future,
}, { Return => 1 });

my $authorbox = fancybox($constants->{fancyboxwidth}, 'Story Admin', $authortext, 0, 1);
slashDisplay('editStory', {
storyref => $storyref,
story => $story,
storycontent => $storycontent,
storybox => $storybox,
sid => $sid,
authorbox => $authorbox,
authortext => $authortext,
newarticle => $newarticle,
topic_select => $topic_select,
section_select => $section_select,
Expand Down Expand Up @@ -1293,6 +1291,7 @@ sub updateStory {

my $tid_ref;
my $default_set = 0;

# Some users can only post to a fixed section
if (my $section = getCurrentUser('section')) {
$form->{section} = $section;
Expand All @@ -1310,26 +1309,66 @@ sub updateStory {
if ($constants->{feature_story_enabled}) {
if ($form->{feature_story}) {
$slashdb->setSection($form->{section}, { feature_story => $form->{sid} });
} elsif ($slashdb->getSection($form->{section}, 'sid') eq $form->{sid}) {
} elsif ($slashdb->getSection($form->{section}, 'feature_story') eq $form->{sid}) {
$slashdb->setSection($form->{section}, { feature_story => '' });
}
}

my $time = ($form->{fastforward})
? $slashdb->getTime()
: $form->{'time'};

if ($constants->{multitopics_enabled}) {
for my $k (keys %$form) {
if ($k =~ /tid_(.*)/) {
push @$tid_ref, $1;
}
}
for (@{$tid_ref}) {
$default_set++ if $_ eq $form->{tid};
$default_set++ if ($_ eq $form->{tid} && $form->{tid});
}
push @$tid_ref, $form->{tid} if !$default_set;

$slashdb->setStoryTopics($form->{sid}, $tid_ref);
}

$slashdb->updateStory($form);
my $data = {
uid => $form->{uid},
sid => $form->{sid},
title => $form->{title},
section => $form->{section},
tid => $form->{tid},
dept => $form->{dept},
'time' => $time,
displaystatus => $form->{displaystatus},
commentstatus => $form->{commentstatus},
writestatus => $form->{writestatus},
bodytext => $form->{bodytext},
introtext => $form->{introtext},
relatedtext => $form->{relatedtext},
};
my $extras = $slashdb->getSectionExtras($data->{section});
if ($extras && @$extras) {
for (@$extras) {
my $key = $_->[1];
$data->{$key} = $form->{$key}
if $form->{$key};
}
}

$slashdb->setStory($form->{sid}, $data);
my $dis_data = {
sid => $data->{sid},
title => $data->{title},
section => $data->{section},
url => "$constants->{rootdir}/article.pl?sid=$data->{sid}",
ts => $data->{'time'},
topic => $data->{tid},
};


$slashdb->setDiscussionBySid($data->{sid}, $dis_data);
$slashdb->setVar('writestatus', 'dirty') if $data->{displaystatus} < 1;
titlebar('100%', getTitle('updateStory-title'));
# make sure you pass it the goods
listStories(@_);
Expand Down Expand Up @@ -1357,12 +1396,42 @@ sub saveStory {
"$form->{title} $form->{bodytext} $form->{introtext}"
) . otherLinks($edituser->{nickname}, $form->{tid}, $edituser->{uid});

my $sid = $slashdb->createStory($form);
my $time = ($form->{fastforward})
? $slashdb->getTime()
: $form->{'time'};

# used to just pass $form to createStory, which is not
# a good idea because you end up getting form values
# such as op and apache_request saved into story_param
my $data = {
uid => $form->{uid},
sid => $form->{sid},
title => $form->{title},
section => $form->{section},
tid => $form->{tid},
dept => $form->{dept},
'time' => $time,
displaystatus => $form->{displaystatus},
commentstatus => $form->{commentstatus},
writestatus => $form->{writestatus},
bodytext => $form->{bodytext},
introtext => $form->{introtext},
relatedtext => $form->{relatedtext},
};
my $extras = $slashdb->getSectionExtras($data->{section});
if ($extras && @$extras) {
for (@$extras) {
my $key = $_->[1];
$data->{$key} = $form->{$key}
if $form->{$key};
}
}
my $sid = $slashdb->createStory($data);

if ($constants->{feature_story_enabled}) {
if ($form->{feature_story}) {
$slashdb->setSection($form->{section}, { feature_story => $sid });
} elsif ($slashdb->getSection($form->{section}, 'sid') eq $sid) {
} elsif ($slashdb->getSection($form->{section}, 'feature_story') eq $sid) {
$slashdb->setSection($form->{section}, { feature_story => '' });
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/Admin/templates/colorEdit;admin;default
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ change in the color scheme. <BR>
If you can restart the webserver, that's the quickest way to
see your changes.</P>

[% PROCESS titlebar %]
[% PROCESS titlebar width="100%" %]

<FORM ACTION="[% env.script_name %]" METHOD="POST">
<INPUT TYPE="hidden" name="op" value="colors">
Expand Down
Loading

0 comments on commit f0227f2

Please sign in to comment.