/
firehose.pl
executable file
·157 lines (128 loc) · 4.11 KB
/
firehose.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/perl
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2005 by Open Source Technology Group. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id$
use strict;
use warnings;
use Slash 2.003; # require Slash 2.3.x
use Slash::Constants qw(:web);
use Slash::Display;
use Slash::Utility;
use Slash::XML;
use vars qw($VERSION);
($VERSION) = ' $Revision$ ' =~ /\$Revision:\s+([^\s]+)/;
sub main {
my $slashdb = getCurrentDB();
my $constants = getCurrentStatic();
my $user = getCurrentUser();
my $form = getCurrentForm();
my $gSkin = getCurrentSkin();
my $anonval = $constants->{firehose_anonval_param} || "";
my %ops = (
list => [1, \&list, 0, $anonval],
view => [1, \&view, 1, ""],
default => [1, \&list, 0, $anonval],
edit => [1, \&edit, 100, ""],
rss => [1, \&rss, 1, ""]
);
my $op = $form->{op} || "";
my $rss = $op eq "rss" && $form->{content_type} && $form->{content_type} =~ $constants->{feed_types};
if ($form->{logtoken} && !$rss) {
redirect($ENV{SCRIPT_NAME});
}
if (!$op || !exists $ops{$op} || !$ops{$op}[ALLOWED] || $user->{seclev} < $ops{$op}[MINSECLEV] ) {
$op = 'default';
if ($user->{seclev} < 1 && $ops{$op}[3] && $ops{$op}[3] ne $form->{anonval}) {
redirect("$gSkin->{rootdir}/login.pl");
return;
}
}
if ($op ne "rss") {
header("$constants->{sitename} - Firehose", '') or return;
}
$ops{$op}[FUNCTION]->($slashdb, $constants, $user, $form, $gSkin);
if ($op ne "rss") {
footer();
}
}
sub list {
my($slashdb, $constants, $user, $form, $gSkin) = @_;
my $firehose = getObject("Slash::FireHose");
print $firehose->listView();
}
sub view {
my($slashdb, $constants, $user, $form, $gSkin) = @_;
my $firehose = getObject("Slash::FireHose");
my $firehose_reader = getObject("Slash::FireHose", { db_type => 'reader' });
my $options = $firehose->getAndSetOptions();
my $item = $firehose_reader->getFireHose($form->{id});
if ($item && $item->{id} && ($item->{public} eq "yes" || $user->{is_admin}) ) {
if ($user->{is_admin}) {
$firehose->setFireHoseSession($item->{id});
}
my $tags_top = $firehose_reader->getFireHoseTagsTop($item);
my $discussion = $item->{type} eq 'submission' && $item->{discussion};
my $firehosetext = $firehose_reader->dispFireHose($item, {
mode => 'full',
tags_top => $tags_top,
options => $options,
nostorylinkwrapper => $discussion ? 1 : 0
});
slashDisplay("view", {
firehosetext => $firehosetext
});
if ($discussion) {
printComments( $firehose_reader->getDiscussion($discussion) );
}
my $plugins = $slashdb->getDescriptions('plugins');
if (!$user->{is_anon} && $plugins->{Tags}) {
my $tagsdb = getObject('Slash::Tags');
$tagsdb->markViewed($user->{uid}, $item->{globjid});
}
} else {
print getData('notavailable');
}
}
sub edit {
my($slashdb, $constants, $user, $form, $gSkin) = @_;
my $firehose = getObject("Slash::FireHose");
if (!$form->{id}) {
list(@_);
return;
}
my $item = $firehose->getFireHose($form->{id});
my $url;
$url = $slashdb->getUrl($item->{url_id}) if $item->{url_id};
my $the_user = $slashdb->getUser($item->{uid});
slashDisplay('fireHoseForm', { item => $item, url => $url, the_user => $the_user, needformwrap => 1, needjssubmit => 1 });
}
sub rss {
my($slashdb, $constants, $user, $form, $gSkin) = @_;
my $firehose = getObject("Slash::FireHose");
my $options = $firehose->getAndSetOptions({ no_set => 1 });
my ($its, $results) = $firehose->getFireHoseEssentials($options);
my @items;
foreach (@$its) {
my $item = $firehose->getFireHose($_->{id});
push @items, {
title => $item->{title},
time => $item->{createtime},
creator => $slashdb->getUser($item->{uid}, 'nickname'),
'link' => "$gSkin->{absolutedir}/firehose.pl?op=view&id=$item->{id}",
description => $item->{introtext}
};
}
xmlDisplay($form->{content_type} => {
channel => {
title => "$constants->{sitename} Firehose",
'link' => "$gSkin->{absolutedir}/firehose.pl",
descriptions => "$constants->{sitename} Firehose"
},
image => 1,
items => \@items,
});
}
createEnvironment();
main();
1;