more metadata generalization and modification
[bse.git] / site / cgi-bin / modules / BSE / TB / ArticleFiles.pm
CommitLineData
6430ee52
TC
1package BSE::TB::ArticleFiles;
2use strict;
3use Squirrel::Table;
4use vars qw(@ISA $VERSION);
5@ISA = qw(Squirrel::Table);
6use BSE::TB::ArticleFile;
7use Carp qw(confess);
8
4029e8ab 9our $VERSION = "1.002";
cb7fd78d 10
6430ee52
TC
11sub rowClass {
12 return 'BSE::TB::ArticleFile';
13}
14
15sub file_storages {
16 my $self = shift;
17 return map [ $_->{filename}, $_->{storage}, $_ ], $self->all;
18}
19
20sub categories {
21 my ($class, $cfg) = @_;
22
23 my @cat_ids = split /,/, $cfg->entry("article file categories", "ids", "");
24 grep $_ eq "", @cat_ids
25 or unshift @cat_ids, "";
26
27 my @cats;
28 for my $id (@cat_ids) {
29 my $section = length $id ? "file category $id" : "file category empty";
30 my $def_name = length $id ? ucfirst $id : "(None)";
31 my $name = $cfg->entry($section, "name", $def_name);
32 push @cats, +{ id => $id, name => $name };
33 }
34
35 return @cats;
36}
37
38sub file_handlers {
39 my ($self, $cfg) = @_;
40
41 $cfg or confess "Missing cfg option";
42
43 my @handlers = split /[;,]/, $cfg->entry('basic', 'file_handlers');
44 push @handlers, "";
45
46 return map [ $_, $self->handler($_, $cfg) ], @handlers;
47}
48
49sub handler {
50 my ($self, $id, $cfg) = @_;
51
52 my $key = $id || "default";
53 my $class = $id ? $cfg->entry("file handlers", $id) : "BSE::FileHandler::Default";
54
55 (my $file = $class . ".pm") =~ s(::)(/)g;
56 require $file;
57 return $class->new($cfg);
58}
59
60sub download_path {
61 my ($class, $cfg) = @_;
62
63 return $cfg->entryVar('paths', 'downloads');
64}
65
7646d96e
TC
66sub file_manager {
67 my ($self, $cfg) = @_;
68
69 require BSE::StorageMgr::Files;
70
71 return BSE::StorageMgr::Files->new(cfg => $cfg);
72}
73
7c6f563b
TC
74sub downloads_must_be_paid {
75 return BSE::Cfg->single->entryBool('downloads', 'must_be_paid', 0);
76}
77
78sub downloads_must_be_filled {
79 return BSE::Cfg->single->entryBool('downloads', 'must_be_filled', 0);
80}
81
6430ee52 821;