File: topics.pl

package info (click to toggle)
slash 2.2.6-8etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,672 kB
  • ctags: 1,915
  • sloc: perl: 23,113; sql: 1,878; sh: 433; makefile: 233
file content (98 lines) | stat: -rwxr-xr-x 2,439 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2001 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id: topics.pl,v 1.4.2.10 2001/10/19 09:05:55 brian Exp $

use strict;
use Slash;
use Slash::Display;
use Slash::Utility;

#################################################################
sub main {
	my $slashdb = getCurrentDB();
	my $form    = getCurrentForm();
	my $section = $slashdb->getSection($form->{section});

	header(getData('head'), $section->{section});
	print createMenu('topics');

	if ($form->{op} eq 'toptopics') {
		topTopics($section);
	} else {
		listTopics();
	}

	footer($form->{ssi});
}

#################################################################
sub topTopics {
	my($section) = @_;
	my $slashdb = getCurrentDB();
	my $form = getCurrentForm();
	my $constants = getCurrentStatic();

	$section->{issue} = 0;  # should this be local() ?  -- pudge

	my(@topics, $topics);
	$topics = $slashdb->getTopNewsstoryTopics($form->{all});

	for (@$topics) {
		my $top = $topics[@topics] = {};
		@{$top}{qw(tid alttext image width height cnt)} = @$_;
		$top->{count} = $slashdb->countStory($top->{tid});

		my $limit = $top->{cnt} > 10
			? 10 : $top->{cnt} < 3 || $form->{all}
			? 3 : $top->{cnt};

		$top->{stories} = getOlderStories(
			$slashdb->getStoriesEssentials($limit, $section->{section}, $top->{tid}),
			$section
		);
		if ($top->{image} =~ /^\w+\.\w+$/) {
			$top->{imageclean} = "$constants->{imagedir}/topics/$top->{image}";
		} else {
			$top->{imageclean} = $top->{image};
		}
	}

	slashDisplay('topTopics', {
		title		=> 'Recent Topics',
		width		=> '90%',
		topics		=> \@topics,
		currtime	=> timeCalc(scalar localtime),
	});
}

#################################################################
sub listTopics {
	my $slashdb = getCurrentDB();
	my $constants = getCurrentStatic();

	my $topics = $slashdb->getTopics();

	for (values %$topics) {
		if ($_->{image} =~ /^\w+\.\w+$/) {
			$_->{imageclean} = "$constants->{imagedir}/topics/$_->{image}";
		} else {
			$_->{imageclean} = $_->{image};
		}
	}

	slashDisplay('listTopics', {
		title		=> 'Current Topic Categories',
		width		=> '90%',
		topic_admin	=> getCurrentUser('seclev') >= 500,
		topics		=> [ values %$topics ],
	});

}

#################################################################
createEnvironment();
main();

1;