This feature i described above now works. I have a box that displayes currently featured stories from one or more sections. These sections, such as "Terri's book of the month" are most useful when they autopost and are restricted to a particular group.
I first had to add two fields of type "date" to the stories table.
There's also a new perm "features_stories".
So you only see the input boxes on the submitstory page when you have this perm.
if anyone wants to see the boxes i made just ask.
And here's the diff with the current cvs Admin/AdminStories.pm
--- AdminStories.orig Tue Sep 3 20:53:47 2002
+++ AdminStories.features Tue Sep 3 20:55:29 2002
@@ -480,6 +480,17 @@
my $section = $S->{DBH}->quote($params{section});
my $q_sid = $S->{DBH}->quote($sid);
+
+ my ($feature_start,$feature_end);
+ if ($params{feature} && $S->have_perm('feature_stories')) {
+ $feature_start = $S->{DBH}->quote("$params{starty}-$params{startm}-$params{startd}");
+ $feature_end = $S->{DBH}->quote("$params{endy}-$params{endm}-$params{endd}");
+ warn "featured story during $feature_start - $feature_end" if $DEBUG;
+ } else {
+ $feature_start = $feature_end = 'NULL';
+ }
+
+
my $time = $params{time};
if ($params{timeupdate} eq 'now' || $time eq '') {
$time = $currtime;
@@ -499,7 +510,9 @@
writestatus=$params{writestatus},
section=$section,
displaystatus=$params{displaystatus},
- commentstatus=$params{commentstatus}|,
+ commentstatus=$params{commentstatus},
+ feature_start=$feature_start,
+ feature_end=$feature_end|,
WHERE => qq|sid = $q_sid|});
$S->run_hook('story_update', $sid);
@@ -524,8 +537,8 @@
($rv, $sth) = $S->db_insert({
DEBUG => 0,
INTO => 'stories',
- COLS => 'sid, tid, aid, title, dept, time, introtext, bodytext, writestatus, section, displaystatus, commentstatus',
- VALUES => qq|"$sid", "$params{tid}", "$params{aid}", $title, $dept, "$time", $introtext, $bodytext, $params{writestatus}, $section, $params{displaystatus}, $params{commentstatus}|});
+ COLS => 'sid, tid, aid, title, dept, time, introtext, bodytext, writestatus, section, displaystatus, commentstatus, feature_start, feature_end',
+ VALUES => qq|"$sid", "$params{tid}", "$params{aid}", $title, $dept, "$time", $introtext, $bodytext, $params{writestatus}, $section, $params{displaystatus}, $params{commentstatus}, $feature_start, $feature_end|});
$S->run_hook('story_new', $sid);
}
@@ -668,6 +681,11 @@
$story_data->{title} = $S->comment_text($story_data->{title});
$story_data->{title} =~ s/"/"/g;
+
+ if ( $S->have_perm('feature_stories') ) {
+ $content .= '<TR><TD>%%norm_font%%' . $S->feature_inputs($story_data) . '%%norm_font_end%%</TD></TR>';
+ }
+
$content .= qq|
<TR>
<TD>%%norm_font%%
@@ -1799,4 +1817,84 @@
return 1;
}
+sub datepart_select {
+ my ($S,$name,$unit,$default) = @_;
+ my ($first,$last,@label);
+ my $content = '';
+
+ if ($unit eq 'month') {
+ $first = 1;
+ $last = 12;
+ if ($S->{UI}->{BLOCKS}->{months_label}) {
+ @label = split(/,?\s*\n/, $S->{UI}->{BLOCKS}->{months_label});
+ } else {
+ @label = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
+ }
+
+ } elsif ($unit eq 'day') {
+ $first = 1;
+ $last = 31;
+
+ } elsif ($unit eq 'year') {
+ ## how many years ahead to offer
+ $first = '2000';
+ $last = $default? $default + 3 : $first;
+
+ } else {
+ warn "Invalid args to datepart_select function" if $DEBUG;
+ return;
+ }
+
+ foreach my $num ($first..$last) { ## each day, month, or year
+ my $label = @label? $label[$num-1] : $num;
+ $content .= qq|<option value="$num"|;
+ $content .= ' selected="selected"' if ($num == $default);
+ $content .= qq|>$label</option>|;
+ }
+ return qq|<select name="$name" size="1">$content</select>|;
+}
+
+
+sub feature_inputs {
+ ## make a checkbox and selects to control start and end dates
+ my ($S,$story_data) = @_;
+ my $c;
+
+ ## default to today...
+
+ my ($d_now,$m_now,$y_now) = (localtime)[3,4,5];
+ $m_now ++;
+ $y_now += 1900;
+
+ foreach (qw(start end)) {
+ ## split each date field into 3 parts
+ if ($story_data->{"feature_$_"} =~ /^(\d\d\d\d)\-(\d\d)\-(\d\d)$/) {
+ my ($y,$m,$d) = ($1,$2,$3);
+ ( $story_data->{"${_}y"} = $y ) =~ s/^0//;
+ ( $story_data->{"${_}m"} = $m ) =~ s/^0//;
+ ( $story_data->{"${_}d"} = $d ) =~ s/^0//;
+ }
+ }
+
+ my $checked = $story_data->{feature}? 'checked="checked"' : '';
+
+ $c .= qq|<input type="checkbox" name="feature" value="1"$checked />
+ Feature story from |;
+
+ $c .= $S->datepart_select('startm','month',
+ $story_data->{startm}||$m_now).' ';
+ $c .= $S->datepart_select('startd','day',
+ $story_data->{startd}||$d_now).' ';
+ $c .= $S->datepart_select('starty','year',
+ $story_data->{starty}||$y_now);
+ $c .= ' to ';
+ $c .= $S->datepart_select('endm', 'month',
+ $story_data->{endm} ||$m_now).' ';
+ $c .= $S->datepart_select('endd', 'day',
+ $story_data->{endd} ||$d_now).' ';
+ $c .= $S->datepart_select('endy', 'year',
+ $story_data->{endy} ||$y_now);
+ return $c;
+}
+
1;
--
babelguides.com <<world literature in translation>>