#!/usr/bin/perl -w
###############################################################################
# index.pl - this code displays the index page
#
# Copyright (C) 1997 Rob "CmdrTaco" Malda
# malda@slashdot.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# $Id: newswire.pl,v 1.1.1.1 2001/08/07 09:42:20 maldoror Exp $
###############################################################################
# pre stories cache update
#use strict;
use lib '../';
use vars '%I';
use POSIX qw(ceil);
use imcSlash;
#################################################################
sub main {
*I = getimcSlashConf();
getimcSlash();
my $currentview = 'newswire';
$currentview = $I{F}{currentview} if $I{F}{currentview};
$I{F}{page} = 1 unless $I{F}{page};
my $article_threshold=5.99;
if ($I{F}{op} eq 'userlogin' && $I{F}{upasswd} && $I{F}{unickname}) {
redirect($ENV{SCRIPT_NAME});
return;
}
# $I{F}{mode} = $I{U}{mode}="dynamic" if $ENV{SCRIPT_NAME};
for ($I{F}{op}) {
/^u$/ and upBid($I{F}{bid});
/^d$/ and dnBid($I{F}{bid});
/^x$/ and rmBid($I{F}{bid});
}
my $SECT = getSection($I{F}{section});
$SECT->{mainsize} = int($SECT->{artcount} / 3);
#my $title = $SECT->{title};
my $title = $I{views_navbar_items}{$currentview}{text};
#$title = "$I{sitename}: $title" unless $SECT->{isolate};
# $I{top_navbar_items}{newswire}{selected} = 1;
header($title, $SECT->{section});
# $I{top_navbar_items}{newswire}{selected} = 0;
checkForM2(); # if $I{U}{uid}==1;
# if test here and make 4 "newswire" blocks
# currentview isn't getting passed!
# jowaxman: If currentview isn't passed, could be that section is passed - now we ignore section...
my $dispfunction = $I{views_navbar_items}{$currentview}{functionname};
my $viewtext = $I{views_navbar_items}{$currentview}{description};
$I{views_navbar_items}{$currentview}{selected} = 1;
my $views_navbar = createNavigationBar ($I{views_navbar_items}, 0);
$I{views_navbar_items}{$currentview}{selected} = 0;
my $block = getEvalBlock("newswire_gr");
my $execme = prepEvalBlock($block);
eval $execme;
print "\n
Error:$@
\n" if $@;
footer();
# zero the refresh flag
# and undef sid sequence array
if ($I{story_refresh}) {
$I{story_refresh} = 0;
# garbage collection
undef $I{sid_array};
}
# zero the order count
$I{StoryCount} = 0;
writelog('index', $I{F}{section} || 'index') unless $I{F}{ssi};
}
#################################################################
#sub headerviews {
#
# print< $I{U}{exboxes} },
"uid=$I{U}{uid}", 1) if $I{U}{uid} > 0;
}
#################################################################
sub getUserBoxes {
my $boxes = $I{U}{exboxes};
$boxes =~ s/'//g;
return split m/,/, $boxes;
}
#################################################################
sub upBid {
my($bid) = @_;
my @a = getUserBoxes();
if ($a[0] eq $bid) {
($a[0], $a[@a-1]) = ($a[@a-1], $a[0]);
} else {
for (my $x = 1; $x < @a; $x++) {
($a[$x-1], $a[$x]) = ($a[$x], $a[$x-1]) if $a[$x] eq $bid;
}
}
saveUserBoxes(@a);
}
#################################################################
sub dnBid {
my($bid) = @_;
my @a = getUserBoxes();
if ($a[@a-1] eq $bid) {
($a[0], $a[@a-1]) = ($a[@a-1], $a[0]);
} else {
for(my $x = @a-1; $x > -1; $x--) {
($a[$x], $a[$x+1]) = ($a[$x+1], $a[$x]) if $a[$x] eq $bid;
}
}
saveUserBoxes(@a);
}
#################################################################
sub rmBid {
my($bid) = @_;
my @a = getUserBoxes();
foreach (my $x = @a; $x >= 0; $x--) {
splice @a, $x, 1 if $a[$x] eq $bid;
}
saveUserBoxes(@a);
}
#################################################################
sub getAllimcSlashBoxes {
return if defined $I{boxBank};
undef $I{sectionBoxes};
my $c = sqlSelectMany(
'blocks.bid as bid,title,url,section,portal,ordernum',
'sectionblocks,blocks',
'sectionblocks.bid=blocks.bid ORDER BY ordernum ASC'
);
my %tmp;
while (my $SB = $c->fetchrow_hashref) {
$I{boxBank}{$SB->{bid}} = $SB; # Set the imcSlashbox
next unless $SB->{ordernum} > 0; # Set the index if applicable
push @{$tmp{$SB->{section}}}, $SB->{bid};
# push @{$I{sectionBoxes}{$SB->{section}}}, $SB->{bid};
}
$I{sectionBoxes} = {%tmp};
$c->finish;
}
#################################################################
sub displayStandardBlocks {
my ($SECT, $olderStuff) = @_;
return if $I{U}{noboxes};
my $getblocks = $SECT->{section} || 'index';
my @boxes;
getAllimcSlashBoxes();
if ($I{U}{exboxes} && $getblocks eq 'index') {
$I{U}{exboxes} =~ s/'//g;
@boxes = split m/,/, $I{U}{exboxes};
} else {
@boxes = @{$I{sectionBoxes}{$getblocks}} if ref $I{sectionBoxes}{$getblocks};
}
foreach my $bid (@boxes) {
if ($bid eq 'mysite') {
print portalbox(
200, "$I{U}{nickname}'s imcSlashbox",
$I{U}{mylinks} || 'This is your user space. Love it.',
$bid
);
} elsif ($bid =~ /_more$/) {
print portalbox("100%","Older Stuff",
getOlderStories($olderStuff, $SECT),
$bid) if $olderStuff;
} elsif ($bid eq "userlogin" && $I{U}{uid} > 0) {
# Don't do nuttin'
} elsif ($bid eq "userlogin") {
my $SB = $I{boxBank}{$bid};
my $B = eval prepBlock $I{blockBank}{$bid};
print portalbox(200, $SB->{title}, $B, $SB->{bid}, $SB->{url});
} else {
my $SB = $I{boxBank}{$bid};
my $B = $I{blockBank}{$bid};
print portalbox(200, $SB->{title}, $B, $SB->{bid}, $SB->{url});
}
}
}
#################################################################
# pass it how many, and what.
sub displayStories {
my $cursor = shift;
my($today, $x) = ('', 1);
my $cnt = $I{stories_per_page}; # int($I{U}{maxstories} / 3);
while (my($sid, $thissection, $title, $time, $cc, $d, $hp,$rating,$num_ratings) = $cursor->fetchrow) {
my @threshComments = split m/,/, $hp;
# Prefix story with section if section != this section and no
# colon
my($S) = displayStory($sid, '', 'index');
my $execme = getEvalBlock('story_link');
print eval $execme;
if ($@) {
print "\n";
}
my $uid = "$I{U}{uid}";
my($mode) = sqlSelect("mode", "users_comments", "uid=$uid");
print linkStory({
'link' => "Lee más...",
sid => $sid,
section => $thissection,
mode => $mode,
threshold => $I{U}{threshold}
});
# 7/14/00 jowaxman
# Print rating.
if ($I{story_moderation_type} eq 'rating') {
if ($num_ratings == 0) {
print ' | Sin puntuar';
} else {
print qq! | Promedio: $rating!;
# dropped num Ratings from newswire -- jdm
# print qq! | Rating: $rating ($num_ratings Rating!;
# print 's' if ($num_ratings > 1);
# print ')';
}
}
# print " | $cc Comentarios";
if ($S->{bodytext} || $cc) {
if ($I{print_story_bytes}) {
print ' | ', linkStory({
'link' => length($S->{bodytext}) . ' bytes en el cuerpo',
sid => $sid,
mode => 'nocomment'
}) if $S->{bodytext};
}
$cc = $threshComments[0];
print ' | ' if $cc;
if ($cc && $I{U}{threshold} > -1
&& $cc ne $threshComments[$I{U}{threshold}]+1) {
print linkStory({
sid => $sid,
threshold => $I{U}{threshold},
mode => $mode,
'link' => $threshComments[$I{U}{threshold} + 1]
});
print ' de ';
}
print linkStory({
sid => $sid,
threshold => '-1',
mode => $mode,
'link' => $cc
}) if $cc;
print ' comentario', $cc > 1 ? 's' : '' if $cc;
}
# Print multimedia info.
my $num_images = selectCount ('mid2sid', "where sid='$sid' and category='image'");
if ($num_images > 1) {
my ($mid) = sqlSelect ('mid', 'mid2sid', "sid='$sid' and category='image' and number=1");
print qq! | $num_images Imágenes!;
}
# Print Edit for admin.
print qq' | Editar'
if $I{U}{aseclev} > 100;
$execme = getEvalBlock('story_trailer');
print eval $execme;
if ($@) {
print "\n";
}
my($w) = join ' ', (split m/ /, $time)[0 .. 2];
$today ||= $w;
# print "\n";
last if ++$x > $cnt; #&& $today ne $w;
}
}
#################################################################
sub checkForM2 {
return unless $I{U}{willing};
return if $I{U}{uid} < 1;
return if $I{U}{karma} < 0;
my($d) = sqlSelect('to_days(now()) - to_days(lastmm)',
'users_info', "uid=$I{U}{uid}");
return unless $d;
# print qq'Have you Meta Moderated Today?
';
}
#################################################################
main();
#################################################################